bfin_sir.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Blackfin Infra-red Driver
  3. *
  4. * Copyright 2006-2009 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 <linux/module.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/delay.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/dma-mapping.h>
  18. #include <net/irda/irda.h>
  19. #include <net/irda/wrapper.h>
  20. #include <net/irda/irda_device.h>
  21. #include <asm/irq.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/dma.h>
  24. #include <asm/portmux.h>
  25. #ifdef CONFIG_SIR_BFIN_DMA
  26. struct dma_rx_buf {
  27. char *buf;
  28. int head;
  29. int tail;
  30. };
  31. #endif
  32. struct bfin_sir_port {
  33. unsigned char __iomem *membase;
  34. unsigned int irq;
  35. unsigned int lsr;
  36. unsigned long clk;
  37. struct net_device *dev;
  38. #ifdef CONFIG_SIR_BFIN_DMA
  39. int tx_done;
  40. struct dma_rx_buf rx_dma_buf;
  41. struct timer_list rx_dma_timer;
  42. int rx_dma_nrows;
  43. #endif
  44. unsigned int tx_dma_channel;
  45. unsigned int rx_dma_channel;
  46. };
  47. struct bfin_sir_port_res {
  48. unsigned long base_addr;
  49. int irq;
  50. unsigned int rx_dma_channel;
  51. unsigned int tx_dma_channel;
  52. };
  53. struct bfin_sir_self {
  54. struct bfin_sir_port *sir_port;
  55. spinlock_t lock;
  56. unsigned int open;
  57. int speed;
  58. int newspeed;
  59. struct sk_buff *txskb;
  60. struct sk_buff *rxskb;
  61. struct net_device_stats stats;
  62. struct device *dev;
  63. struct irlap_cb *irlap;
  64. struct qos_info qos;
  65. iobuff_t tx_buff;
  66. iobuff_t rx_buff;
  67. struct work_struct work;
  68. int mtt;
  69. };
  70. #define DRIVER_NAME "bfin_sir"
  71. #define SIR_UART_GET_CHAR(port) bfin_read16((port)->membase + OFFSET_RBR)
  72. #define SIR_UART_GET_DLL(port) bfin_read16((port)->membase + OFFSET_DLL)
  73. #define SIR_UART_GET_DLH(port) bfin_read16((port)->membase + OFFSET_DLH)
  74. #define SIR_UART_GET_LCR(port) bfin_read16((port)->membase + OFFSET_LCR)
  75. #define SIR_UART_GET_GCTL(port) bfin_read16((port)->membase + OFFSET_GCTL)
  76. #define SIR_UART_PUT_CHAR(port, v) bfin_write16(((port)->membase + OFFSET_THR), v)
  77. #define SIR_UART_PUT_DLL(port, v) bfin_write16(((port)->membase + OFFSET_DLL), v)
  78. #define SIR_UART_PUT_DLH(port, v) bfin_write16(((port)->membase + OFFSET_DLH), v)
  79. #define SIR_UART_PUT_LCR(port, v) bfin_write16(((port)->membase + OFFSET_LCR), v)
  80. #define SIR_UART_PUT_GCTL(port, v) bfin_write16(((port)->membase + OFFSET_GCTL), v)
  81. #ifdef CONFIG_BF54x
  82. #define SIR_UART_GET_LSR(port) bfin_read16((port)->membase + OFFSET_LSR)
  83. #define SIR_UART_GET_IER(port) bfin_read16((port)->membase + OFFSET_IER_SET)
  84. #define SIR_UART_SET_IER(port, v) bfin_write16(((port)->membase + OFFSET_IER_SET), v)
  85. #define SIR_UART_CLEAR_IER(port, v) bfin_write16(((port)->membase + OFFSET_IER_CLEAR), v)
  86. #define SIR_UART_PUT_LSR(port, v) bfin_write16(((port)->membase + OFFSET_LSR), v)
  87. #define SIR_UART_CLEAR_LSR(port) bfin_write16(((port)->membase + OFFSET_LSR), -1)
  88. #define SIR_UART_SET_DLAB(port)
  89. #define SIR_UART_CLEAR_DLAB(port)
  90. #define SIR_UART_ENABLE_INTS(port, v) SIR_UART_SET_IER(port, v)
  91. #define SIR_UART_DISABLE_INTS(port) SIR_UART_CLEAR_IER(port, 0xF)
  92. #define SIR_UART_STOP_TX(port) do { SIR_UART_PUT_LSR(port, TFI); SIR_UART_CLEAR_IER(port, ETBEI); } while (0)
  93. #define SIR_UART_ENABLE_TX(port) do { SIR_UART_SET_IER(port, ETBEI); } while (0)
  94. #define SIR_UART_STOP_RX(port) do { SIR_UART_CLEAR_IER(port, ERBFI); } while (0)
  95. #define SIR_UART_ENABLE_RX(port) do { SIR_UART_SET_IER(port, ERBFI); } while (0)
  96. #else
  97. #define SIR_UART_GET_IIR(port) bfin_read16((port)->membase + OFFSET_IIR)
  98. #define SIR_UART_GET_IER(port) bfin_read16((port)->membase + OFFSET_IER)
  99. #define SIR_UART_PUT_IER(port, v) bfin_write16(((port)->membase + OFFSET_IER), v)
  100. #define SIR_UART_SET_DLAB(port) do { SIR_UART_PUT_LCR(port, SIR_UART_GET_LCR(port) | DLAB); } while (0)
  101. #define SIR_UART_CLEAR_DLAB(port) do { SIR_UART_PUT_LCR(port, SIR_UART_GET_LCR(port) & ~DLAB); } while (0)
  102. #define SIR_UART_ENABLE_INTS(port, v) SIR_UART_PUT_IER(port, v)
  103. #define SIR_UART_DISABLE_INTS(port) SIR_UART_PUT_IER(port, 0)
  104. #define SIR_UART_STOP_TX(port) do { SIR_UART_PUT_IER(port, SIR_UART_GET_IER(port) & ~ETBEI); } while (0)
  105. #define SIR_UART_ENABLE_TX(port) do { SIR_UART_PUT_IER(port, SIR_UART_GET_IER(port) | ETBEI); } while (0)
  106. #define SIR_UART_STOP_RX(port) do { SIR_UART_PUT_IER(port, SIR_UART_GET_IER(port) & ~ERBFI); } while (0)
  107. #define SIR_UART_ENABLE_RX(port) do { SIR_UART_PUT_IER(port, SIR_UART_GET_IER(port) | ERBFI); } while (0)
  108. static inline unsigned int SIR_UART_GET_LSR(struct bfin_sir_port *port)
  109. {
  110. unsigned int lsr = bfin_read16(port->membase + OFFSET_LSR);
  111. port->lsr |= (lsr & (BI|FE|PE|OE));
  112. return lsr | port->lsr;
  113. }
  114. static inline void SIR_UART_CLEAR_LSR(struct bfin_sir_port *port)
  115. {
  116. port->lsr = 0;
  117. bfin_read16(port->membase + OFFSET_LSR);
  118. }
  119. #endif
  120. static const unsigned short per[][4] = {
  121. /* rx pin tx pin NULL uart_number */
  122. {P_UART0_RX, P_UART0_TX, 0, 0},
  123. {P_UART1_RX, P_UART1_TX, 0, 1},
  124. {P_UART2_RX, P_UART2_TX, 0, 2},
  125. {P_UART3_RX, P_UART3_TX, 0, 3},
  126. };