sl811.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * SL811HS register declarations and HCD data structures
  4. *
  5. * Copyright (C) 2004 Psion Teklogix
  6. * Copyright (C) 2004 David Brownell
  7. * Copyright (C) 2001 Cypress Semiconductor Inc.
  8. */
  9. /*
  10. * SL811HS has transfer registers, and control registers. In host/master
  11. * mode one set of registers is used; in peripheral/slave mode, another.
  12. * - SL11H only has some "A" transfer registers from 0x00-0x04
  13. * - SL811HS also has "B" registers from 0x08-0x0c
  14. * - SL811S (or HS in slave mode) has four A+B sets, at 00, 10, 20, 30
  15. */
  16. #define SL811_EP_A(base) ((base) + 0)
  17. #define SL811_EP_B(base) ((base) + 8)
  18. #define SL811_HOST_BUF 0x00
  19. #define SL811_PERIPH_EP0 0x00
  20. #define SL811_PERIPH_EP1 0x10
  21. #define SL811_PERIPH_EP2 0x20
  22. #define SL811_PERIPH_EP3 0x30
  23. /* TRANSFER REGISTERS: host and peripheral sides are similar
  24. * except for the control models (master vs slave).
  25. */
  26. #define SL11H_HOSTCTLREG 0
  27. # define SL11H_HCTLMASK_ARM 0x01
  28. # define SL11H_HCTLMASK_ENABLE 0x02
  29. # define SL11H_HCTLMASK_IN 0x00
  30. # define SL11H_HCTLMASK_OUT 0x04
  31. # define SL11H_HCTLMASK_ISOCH 0x10
  32. # define SL11H_HCTLMASK_AFTERSOF 0x20
  33. # define SL11H_HCTLMASK_TOGGLE 0x40
  34. # define SL11H_HCTLMASK_PREAMBLE 0x80
  35. #define SL11H_BUFADDRREG 1
  36. #define SL11H_BUFLNTHREG 2
  37. #define SL11H_PKTSTATREG 3 /* read */
  38. # define SL11H_STATMASK_ACK 0x01
  39. # define SL11H_STATMASK_ERROR 0x02
  40. # define SL11H_STATMASK_TMOUT 0x04
  41. # define SL11H_STATMASK_SEQ 0x08
  42. # define SL11H_STATMASK_SETUP 0x10
  43. # define SL11H_STATMASK_OVF 0x20
  44. # define SL11H_STATMASK_NAK 0x40
  45. # define SL11H_STATMASK_STALL 0x80
  46. #define SL11H_PIDEPREG 3 /* write */
  47. # define SL_SETUP 0xd0
  48. # define SL_IN 0x90
  49. # define SL_OUT 0x10
  50. # define SL_SOF 0x50
  51. # define SL_PREAMBLE 0xc0
  52. # define SL_NAK 0xa0
  53. # define SL_STALL 0xe0
  54. # define SL_DATA0 0x30
  55. # define SL_DATA1 0xb0
  56. #define SL11H_XFERCNTREG 4 /* read */
  57. #define SL11H_DEVADDRREG 4 /* write */
  58. /* CONTROL REGISTERS: host and peripheral are very different.
  59. */
  60. #define SL11H_CTLREG1 5
  61. # define SL11H_CTL1MASK_SOF_ENA 0x01
  62. # define SL11H_CTL1MASK_FORCE 0x18
  63. # define SL11H_CTL1MASK_NORMAL 0x00
  64. # define SL11H_CTL1MASK_SE0 0x08 /* reset */
  65. # define SL11H_CTL1MASK_J 0x10
  66. # define SL11H_CTL1MASK_K 0x18 /* resume */
  67. # define SL11H_CTL1MASK_LSPD 0x20
  68. # define SL11H_CTL1MASK_SUSPEND 0x40
  69. #define SL11H_IRQ_ENABLE 6
  70. # define SL11H_INTMASK_DONE_A 0x01
  71. # define SL11H_INTMASK_DONE_B 0x02
  72. # define SL11H_INTMASK_SOFINTR 0x10
  73. # define SL11H_INTMASK_INSRMV 0x20 /* to/from SE0 */
  74. # define SL11H_INTMASK_RD 0x40
  75. # define SL11H_INTMASK_DP 0x80 /* only in INTSTATREG */
  76. #define SL11S_ADDRESS 7
  77. /* 0x08-0x0c are for the B buffer (not in SL11) */
  78. #define SL11H_IRQ_STATUS 0x0D /* write to ack */
  79. #define SL11H_HWREVREG 0x0E /* read */
  80. # define SL11H_HWRMASK_HWREV 0xF0
  81. #define SL11H_SOFLOWREG 0x0E /* write */
  82. #define SL11H_SOFTMRREG 0x0F /* read */
  83. /* a write to this register enables SL811HS features.
  84. * HOST flag presumably overrides the chip input signal?
  85. */
  86. #define SL811HS_CTLREG2 0x0F
  87. # define SL811HS_CTL2MASK_SOF_MASK 0x3F
  88. # define SL811HS_CTL2MASK_DSWAP 0x40
  89. # define SL811HS_CTL2MASK_HOST 0x80
  90. #define SL811HS_CTL2_INIT (SL811HS_CTL2MASK_HOST | 0x2e)
  91. /* DATA BUFFERS: registers from 0x10..0xff are for data buffers;
  92. * that's 240 bytes, which we'll split evenly between A and B sides.
  93. * Only ISO can use more than 64 bytes per packet.
  94. * (The SL11S has 0x40..0xff for buffers.)
  95. */
  96. #define H_MAXPACKET 120 /* bytes in A or B fifos */
  97. #define SL11H_DATA_START 0x10
  98. #define SL811HS_PACKET_BUF(is_a) ((is_a) \
  99. ? SL11H_DATA_START \
  100. : (SL11H_DATA_START + H_MAXPACKET))
  101. /*-------------------------------------------------------------------------*/
  102. #define LOG2_PERIODIC_SIZE 5 /* arbitrary; this matches OHCI */
  103. #define PERIODIC_SIZE (1 << LOG2_PERIODIC_SIZE)
  104. struct sl811 {
  105. spinlock_t lock;
  106. void __iomem *addr_reg;
  107. void __iomem *data_reg;
  108. struct sl811_platform_data *board;
  109. struct dentry *debug_file;
  110. unsigned long stat_insrmv;
  111. unsigned long stat_wake;
  112. unsigned long stat_sof;
  113. unsigned long stat_a;
  114. unsigned long stat_b;
  115. unsigned long stat_lost;
  116. unsigned long stat_overrun;
  117. /* sw model */
  118. struct timer_list timer;
  119. struct sl811h_ep *next_periodic;
  120. struct sl811h_ep *next_async;
  121. struct sl811h_ep *active_a;
  122. unsigned long jiffies_a;
  123. struct sl811h_ep *active_b;
  124. unsigned long jiffies_b;
  125. u32 port1;
  126. u8 ctrl1, ctrl2, irq_enable;
  127. u16 frame;
  128. /* async schedule: control, bulk */
  129. struct list_head async;
  130. /* periodic schedule: interrupt, iso */
  131. u16 load[PERIODIC_SIZE];
  132. struct sl811h_ep *periodic[PERIODIC_SIZE];
  133. unsigned periodic_count;
  134. };
  135. static inline struct sl811 *hcd_to_sl811(struct usb_hcd *hcd)
  136. {
  137. return (struct sl811 *) (hcd->hcd_priv);
  138. }
  139. static inline struct usb_hcd *sl811_to_hcd(struct sl811 *sl811)
  140. {
  141. return container_of((void *) sl811, struct usb_hcd, hcd_priv);
  142. }
  143. struct sl811h_ep {
  144. struct usb_host_endpoint *hep;
  145. struct usb_device *udev;
  146. u8 defctrl;
  147. u8 maxpacket;
  148. u8 epnum;
  149. u8 nextpid;
  150. u16 error_count;
  151. u16 nak_count;
  152. u16 length; /* of current packet */
  153. /* periodic schedule */
  154. u16 period;
  155. u16 branch;
  156. u16 load;
  157. struct sl811h_ep *next;
  158. /* async schedule */
  159. struct list_head schedule;
  160. };
  161. /*-------------------------------------------------------------------------*/
  162. /* These register utilities should work for the SL811S register API too
  163. * NOTE: caller must hold sl811->lock.
  164. */
  165. static inline u8 sl811_read(struct sl811 *sl811, int reg)
  166. {
  167. writeb(reg, sl811->addr_reg);
  168. return readb(sl811->data_reg);
  169. }
  170. static inline void sl811_write(struct sl811 *sl811, int reg, u8 val)
  171. {
  172. writeb(reg, sl811->addr_reg);
  173. writeb(val, sl811->data_reg);
  174. }
  175. static inline void
  176. sl811_write_buf(struct sl811 *sl811, int addr, const void *buf, size_t count)
  177. {
  178. const u8 *data;
  179. void __iomem *data_reg;
  180. if (!count)
  181. return;
  182. writeb(addr, sl811->addr_reg);
  183. data = buf;
  184. data_reg = sl811->data_reg;
  185. do {
  186. writeb(*data++, data_reg);
  187. } while (--count);
  188. }
  189. static inline void
  190. sl811_read_buf(struct sl811 *sl811, int addr, void *buf, size_t count)
  191. {
  192. u8 *data;
  193. void __iomem *data_reg;
  194. if (!count)
  195. return;
  196. writeb(addr, sl811->addr_reg);
  197. data = buf;
  198. data_reg = sl811->data_reg;
  199. do {
  200. *data++ = readb(data_reg);
  201. } while (--count);
  202. }
  203. /*-------------------------------------------------------------------------*/
  204. #ifdef PACKET_TRACE
  205. # define PACKET pr_debug("sl811: "stuff)
  206. #else
  207. # define PACKET(stuff...) do{}while(0)
  208. #endif