sl811.h 6.3 KB

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