bfin_sir.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Blackfin Infra-red Driver
  3. *
  4. * Copyright 2006-2008 Analog Devices Inc.
  5. *
  6. * Enter bugs at http://blackfin.uclinux.org/
  7. *
  8. * Licensed under the GPL-2 or later.
  9. *
  10. */
  11. #include <linux/serial.h>
  12. #include <asm/dma.h>
  13. #include <asm/portmux.h>
  14. #define SIR_UART_GET_CHAR(port) bfin_read16((port)->membase + OFFSET_RBR)
  15. #define SIR_UART_GET_DLL(port) bfin_read16((port)->membase + OFFSET_DLL)
  16. #define SIR_UART_GET_IER(port) bfin_read16((port)->membase + OFFSET_IER)
  17. #define SIR_UART_GET_DLH(port) bfin_read16((port)->membase + OFFSET_DLH)
  18. #define SIR_UART_GET_IIR(port) bfin_read16((port)->membase + OFFSET_IIR)
  19. #define SIR_UART_GET_LCR(port) bfin_read16((port)->membase + OFFSET_LCR)
  20. #define SIR_UART_GET_GCTL(port) bfin_read16((port)->membase + OFFSET_GCTL)
  21. #define SIR_UART_PUT_CHAR(port, v) bfin_write16(((port)->membase + OFFSET_THR), v)
  22. #define SIR_UART_PUT_DLL(port, v) bfin_write16(((port)->membase + OFFSET_DLL), v)
  23. #define SIR_UART_PUT_IER(port, v) bfin_write16(((port)->membase + OFFSET_IER), v)
  24. #define SIR_UART_PUT_DLH(port, v) bfin_write16(((port)->membase + OFFSET_DLH), v)
  25. #define SIR_UART_PUT_LCR(port, v) bfin_write16(((port)->membase + OFFSET_LCR), v)
  26. #define SIR_UART_PUT_GCTL(port, v) bfin_write16(((port)->membase + OFFSET_GCTL), v)
  27. #ifdef CONFIG_SIR_BFIN_DMA
  28. struct dma_rx_buf {
  29. char *buf;
  30. int head;
  31. int tail;
  32. };
  33. #endif /* CONFIG_SIR_BFIN_DMA */
  34. struct bfin_sir_port {
  35. unsigned char __iomem *membase;
  36. unsigned int irq;
  37. unsigned int lsr;
  38. unsigned long clk;
  39. struct net_device *dev;
  40. #ifdef CONFIG_SIR_BFIN_DMA
  41. int tx_done;
  42. struct dma_rx_buf rx_dma_buf;
  43. struct timer_list rx_dma_timer;
  44. int rx_dma_nrows;
  45. #endif /* CONFIG_SIR_BFIN_DMA */
  46. unsigned int tx_dma_channel;
  47. unsigned int rx_dma_channel;
  48. };
  49. struct bfin_sir_port sir_ports[BFIN_UART_NR_PORTS];
  50. struct bfin_sir_port_res {
  51. unsigned long base_addr;
  52. int irq;
  53. unsigned int rx_dma_channel;
  54. unsigned int tx_dma_channel;
  55. };
  56. struct bfin_sir_port_res bfin_sir_port_resource[] = {
  57. #ifdef CONFIG_BFIN_SIR0
  58. {
  59. 0xFFC00400,
  60. IRQ_UART0_RX,
  61. CH_UART0_RX,
  62. CH_UART0_TX,
  63. },
  64. #endif
  65. #ifdef CONFIG_BFIN_SIR1
  66. {
  67. 0xFFC02000,
  68. IRQ_UART1_RX,
  69. CH_UART1_RX,
  70. CH_UART1_TX,
  71. },
  72. #endif
  73. };
  74. int nr_sirs = ARRAY_SIZE(bfin_sir_port_resource);
  75. struct bfin_sir_self {
  76. struct bfin_sir_port *sir_port;
  77. spinlock_t lock;
  78. unsigned int open;
  79. int speed;
  80. int newspeed;
  81. struct sk_buff *txskb;
  82. struct sk_buff *rxskb;
  83. struct net_device_stats stats;
  84. struct device *dev;
  85. struct irlap_cb *irlap;
  86. struct qos_info qos;
  87. iobuff_t tx_buff;
  88. iobuff_t rx_buff;
  89. struct work_struct work;
  90. int mtt;
  91. };
  92. static inline unsigned int SIR_UART_GET_LSR(struct bfin_sir_port *port)
  93. {
  94. unsigned int lsr = bfin_read16(port->membase + OFFSET_LSR);
  95. port->lsr |= (lsr & (BI|FE|PE|OE));
  96. return lsr | port->lsr;
  97. }
  98. static inline void SIR_UART_CLEAR_LSR(struct bfin_sir_port *port)
  99. {
  100. port->lsr = 0;
  101. bfin_read16(port->membase + OFFSET_LSR);
  102. }
  103. #define DRIVER_NAME "bfin_sir"
  104. static int bfin_sir_hw_init(void)
  105. {
  106. int ret = -ENODEV;
  107. #ifdef CONFIG_BFIN_SIR0
  108. ret = peripheral_request(P_UART0_TX, DRIVER_NAME);
  109. if (ret)
  110. return ret;
  111. ret = peripheral_request(P_UART0_RX, DRIVER_NAME);
  112. if (ret)
  113. return ret;
  114. #endif
  115. #ifdef CONFIG_BFIN_SIR1
  116. ret = peripheral_request(P_UART1_TX, DRIVER_NAME);
  117. if (ret)
  118. return ret;
  119. ret = peripheral_request(P_UART1_RX, DRIVER_NAME);
  120. if (ret)
  121. return ret;
  122. #endif
  123. return ret;
  124. }