isp116x.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /*
  2. * ISP116x register declarations and HCD data structures
  3. *
  4. * Copyright (C) 2007 Rodolfo Giometti <giometti@linux.it>
  5. * Copyright (C) 2007 Eurotech S.p.A. <info@eurotech.it>
  6. * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
  7. * Portions:
  8. * Copyright (C) 2004 Lothar Wassmann
  9. * Copyright (C) 2004 Psion Teklogix
  10. * Copyright (C) 2004 David Brownell
  11. *
  12. * SPDX-License-Identifier: GPL-2.0+
  13. */
  14. #ifdef DEBUG
  15. #define DBG(fmt, args...) \
  16. printf("isp116x: %s: " fmt "\n" , __FUNCTION__ , ## args)
  17. #else
  18. #define DBG(fmt, args...) do {} while (0)
  19. #endif
  20. #ifdef VERBOSE
  21. # define VDBG DBG
  22. #else
  23. # define VDBG(fmt, args...) do {} while (0)
  24. #endif
  25. #define ERR(fmt, args...) \
  26. printf("isp116x: %s: " fmt "\n" , __FUNCTION__ , ## args)
  27. #define WARN(fmt, args...) \
  28. printf("isp116x: %s: " fmt "\n" , __FUNCTION__ , ## args)
  29. #define INFO(fmt, args...) \
  30. printf("isp116x: " fmt "\n" , ## args)
  31. /* ------------------------------------------------------------------------- */
  32. /* us of 1ms frame */
  33. #define MAX_LOAD_LIMIT 850
  34. /* Full speed: max # of bytes to transfer for a single urb
  35. at a time must be < 1024 && must be multiple of 64.
  36. 832 allows transfering 4kiB within 5 frames. */
  37. #define MAX_TRANSFER_SIZE_FULLSPEED 832
  38. /* Low speed: there is no reason to schedule in very big
  39. chunks; often the requested long transfers are for
  40. string descriptors containing short strings. */
  41. #define MAX_TRANSFER_SIZE_LOWSPEED 64
  42. /* Bytetime (us), a rough indication of how much time it
  43. would take to transfer a byte of useful data over USB */
  44. #define BYTE_TIME_FULLSPEED 1
  45. #define BYTE_TIME_LOWSPEED 20
  46. /* Buffer sizes */
  47. #define ISP116x_BUF_SIZE 4096
  48. #define ISP116x_ITL_BUFSIZE 0
  49. #define ISP116x_ATL_BUFSIZE ((ISP116x_BUF_SIZE) - 2*(ISP116x_ITL_BUFSIZE))
  50. #define ISP116x_WRITE_OFFSET 0x80
  51. /* --- ISP116x registers/bits ---------------------------------------------- */
  52. #define HCREVISION 0x00
  53. #define HCCONTROL 0x01
  54. #define HCCONTROL_HCFS (3 << 6) /* host controller
  55. functional state */
  56. #define HCCONTROL_USB_RESET (0 << 6)
  57. #define HCCONTROL_USB_RESUME (1 << 6)
  58. #define HCCONTROL_USB_OPER (2 << 6)
  59. #define HCCONTROL_USB_SUSPEND (3 << 6)
  60. #define HCCONTROL_RWC (1 << 9) /* remote wakeup connected */
  61. #define HCCONTROL_RWE (1 << 10) /* remote wakeup enable */
  62. #define HCCMDSTAT 0x02
  63. #define HCCMDSTAT_HCR (1 << 0) /* host controller reset */
  64. #define HCCMDSTAT_SOC (3 << 16) /* scheduling overrun count */
  65. #define HCINTSTAT 0x03
  66. #define HCINT_SO (1 << 0) /* scheduling overrun */
  67. #define HCINT_WDH (1 << 1) /* writeback of done_head */
  68. #define HCINT_SF (1 << 2) /* start frame */
  69. #define HCINT_RD (1 << 3) /* resume detect */
  70. #define HCINT_UE (1 << 4) /* unrecoverable error */
  71. #define HCINT_FNO (1 << 5) /* frame number overflow */
  72. #define HCINT_RHSC (1 << 6) /* root hub status change */
  73. #define HCINT_OC (1 << 30) /* ownership change */
  74. #define HCINT_MIE (1 << 31) /* master interrupt enable */
  75. #define HCINTENB 0x04
  76. #define HCINTDIS 0x05
  77. #define HCFMINTVL 0x0d
  78. #define HCFMREM 0x0e
  79. #define HCFMNUM 0x0f
  80. #define HCLSTHRESH 0x11
  81. #define HCRHDESCA 0x12
  82. #define RH_A_NDP (0x3 << 0) /* # downstream ports */
  83. #define RH_A_PSM (1 << 8) /* power switching mode */
  84. #define RH_A_NPS (1 << 9) /* no power switching */
  85. #define RH_A_DT (1 << 10) /* device type (mbz) */
  86. #define RH_A_OCPM (1 << 11) /* overcurrent protection
  87. mode */
  88. #define RH_A_NOCP (1 << 12) /* no overcurrent protection */
  89. #define RH_A_POTPGT (0xff << 24) /* power on -> power good
  90. time */
  91. #define HCRHDESCB 0x13
  92. #define RH_B_DR (0xffff << 0) /* device removable flags */
  93. #define RH_B_PPCM (0xffff << 16) /* port power control mask */
  94. #define HCRHSTATUS 0x14
  95. #define RH_HS_LPS (1 << 0) /* local power status */
  96. #define RH_HS_OCI (1 << 1) /* over current indicator */
  97. #define RH_HS_DRWE (1 << 15) /* device remote wakeup
  98. enable */
  99. #define RH_HS_LPSC (1 << 16) /* local power status change */
  100. #define RH_HS_OCIC (1 << 17) /* over current indicator
  101. change */
  102. #define RH_HS_CRWE (1 << 31) /* clear remote wakeup
  103. enable */
  104. #define HCRHPORT1 0x15
  105. #define RH_PS_CCS (1 << 0) /* current connect status */
  106. #define RH_PS_PES (1 << 1) /* port enable status */
  107. #define RH_PS_PSS (1 << 2) /* port suspend status */
  108. #define RH_PS_POCI (1 << 3) /* port over current
  109. indicator */
  110. #define RH_PS_PRS (1 << 4) /* port reset status */
  111. #define RH_PS_PPS (1 << 8) /* port power status */
  112. #define RH_PS_LSDA (1 << 9) /* low speed device attached */
  113. #define RH_PS_CSC (1 << 16) /* connect status change */
  114. #define RH_PS_PESC (1 << 17) /* port enable status change */
  115. #define RH_PS_PSSC (1 << 18) /* port suspend status
  116. change */
  117. #define RH_PS_OCIC (1 << 19) /* over current indicator
  118. change */
  119. #define RH_PS_PRSC (1 << 20) /* port reset status change */
  120. #define HCRHPORT_CLRMASK (0x1f << 16)
  121. #define HCRHPORT2 0x16
  122. #define HCHWCFG 0x20
  123. #define HCHWCFG_15KRSEL (1 << 12)
  124. #define HCHWCFG_CLKNOTSTOP (1 << 11)
  125. #define HCHWCFG_ANALOG_OC (1 << 10)
  126. #define HCHWCFG_DACK_MODE (1 << 8)
  127. #define HCHWCFG_EOT_POL (1 << 7)
  128. #define HCHWCFG_DACK_POL (1 << 6)
  129. #define HCHWCFG_DREQ_POL (1 << 5)
  130. #define HCHWCFG_DBWIDTH_MASK (0x03 << 3)
  131. #define HCHWCFG_DBWIDTH(n) (((n) << 3) & HCHWCFG_DBWIDTH_MASK)
  132. #define HCHWCFG_INT_POL (1 << 2)
  133. #define HCHWCFG_INT_TRIGGER (1 << 1)
  134. #define HCHWCFG_INT_ENABLE (1 << 0)
  135. #define HCDMACFG 0x21
  136. #define HCDMACFG_BURST_LEN_MASK (0x03 << 5)
  137. #define HCDMACFG_BURST_LEN(n) (((n) << 5) & HCDMACFG_BURST_LEN_MASK)
  138. #define HCDMACFG_BURST_LEN_1 HCDMACFG_BURST_LEN(0)
  139. #define HCDMACFG_BURST_LEN_4 HCDMACFG_BURST_LEN(1)
  140. #define HCDMACFG_BURST_LEN_8 HCDMACFG_BURST_LEN(2)
  141. #define HCDMACFG_DMA_ENABLE (1 << 4)
  142. #define HCDMACFG_BUF_TYPE_MASK (0x07 << 1)
  143. #define HCDMACFG_CTR_SEL (1 << 2)
  144. #define HCDMACFG_ITLATL_SEL (1 << 1)
  145. #define HCDMACFG_DMA_RW_SELECT (1 << 0)
  146. #define HCXFERCTR 0x22
  147. #define HCuPINT 0x24
  148. #define HCuPINT_SOF (1 << 0)
  149. #define HCuPINT_ATL (1 << 1)
  150. #define HCuPINT_AIIEOT (1 << 2)
  151. #define HCuPINT_OPR (1 << 4)
  152. #define HCuPINT_SUSP (1 << 5)
  153. #define HCuPINT_CLKRDY (1 << 6)
  154. #define HCuPINTENB 0x25
  155. #define HCCHIPID 0x27
  156. #define HCCHIPID_MASK 0xff00
  157. #define HCCHIPID_MAGIC 0x6100
  158. #define HCSCRATCH 0x28
  159. #define HCSWRES 0x29
  160. #define HCSWRES_MAGIC 0x00f6
  161. #define HCITLBUFLEN 0x2a
  162. #define HCATLBUFLEN 0x2b
  163. #define HCBUFSTAT 0x2c
  164. #define HCBUFSTAT_ITL0_FULL (1 << 0)
  165. #define HCBUFSTAT_ITL1_FULL (1 << 1)
  166. #define HCBUFSTAT_ATL_FULL (1 << 2)
  167. #define HCBUFSTAT_ITL0_DONE (1 << 3)
  168. #define HCBUFSTAT_ITL1_DONE (1 << 4)
  169. #define HCBUFSTAT_ATL_DONE (1 << 5)
  170. #define HCRDITL0LEN 0x2d
  171. #define HCRDITL1LEN 0x2e
  172. #define HCITLPORT 0x40
  173. #define HCATLPORT 0x41
  174. /* PTD accessor macros. */
  175. #define PTD_GET_COUNT(p) (((p)->count & PTD_COUNT_MSK) >> 0)
  176. #define PTD_COUNT(v) (((v) << 0) & PTD_COUNT_MSK)
  177. #define PTD_GET_TOGGLE(p) (((p)->count & PTD_TOGGLE_MSK) >> 10)
  178. #define PTD_TOGGLE(v) (((v) << 10) & PTD_TOGGLE_MSK)
  179. #define PTD_GET_ACTIVE(p) (((p)->count & PTD_ACTIVE_MSK) >> 11)
  180. #define PTD_ACTIVE(v) (((v) << 11) & PTD_ACTIVE_MSK)
  181. #define PTD_GET_CC(p) (((p)->count & PTD_CC_MSK) >> 12)
  182. #define PTD_CC(v) (((v) << 12) & PTD_CC_MSK)
  183. #define PTD_GET_MPS(p) (((p)->mps & PTD_MPS_MSK) >> 0)
  184. #define PTD_MPS(v) (((v) << 0) & PTD_MPS_MSK)
  185. #define PTD_GET_SPD(p) (((p)->mps & PTD_SPD_MSK) >> 10)
  186. #define PTD_SPD(v) (((v) << 10) & PTD_SPD_MSK)
  187. #define PTD_GET_LAST(p) (((p)->mps & PTD_LAST_MSK) >> 11)
  188. #define PTD_LAST(v) (((v) << 11) & PTD_LAST_MSK)
  189. #define PTD_GET_EP(p) (((p)->mps & PTD_EP_MSK) >> 12)
  190. #define PTD_EP(v) (((v) << 12) & PTD_EP_MSK)
  191. #define PTD_GET_LEN(p) (((p)->len & PTD_LEN_MSK) >> 0)
  192. #define PTD_LEN(v) (((v) << 0) & PTD_LEN_MSK)
  193. #define PTD_GET_DIR(p) (((p)->len & PTD_DIR_MSK) >> 10)
  194. #define PTD_DIR(v) (((v) << 10) & PTD_DIR_MSK)
  195. #define PTD_GET_B5_5(p) (((p)->len & PTD_B5_5_MSK) >> 13)
  196. #define PTD_B5_5(v) (((v) << 13) & PTD_B5_5_MSK)
  197. #define PTD_GET_FA(p) (((p)->faddr & PTD_FA_MSK) >> 0)
  198. #define PTD_FA(v) (((v) << 0) & PTD_FA_MSK)
  199. #define PTD_GET_FMT(p) (((p)->faddr & PTD_FMT_MSK) >> 7)
  200. #define PTD_FMT(v) (((v) << 7) & PTD_FMT_MSK)
  201. /* Hardware transfer status codes -- CC from ptd->count */
  202. #define TD_CC_NOERROR 0x00
  203. #define TD_CC_CRC 0x01
  204. #define TD_CC_BITSTUFFING 0x02
  205. #define TD_CC_DATATOGGLEM 0x03
  206. #define TD_CC_STALL 0x04
  207. #define TD_DEVNOTRESP 0x05
  208. #define TD_PIDCHECKFAIL 0x06
  209. #define TD_UNEXPECTEDPID 0x07
  210. #define TD_DATAOVERRUN 0x08
  211. #define TD_DATAUNDERRUN 0x09
  212. /* 0x0A, 0x0B reserved for hardware */
  213. #define TD_BUFFEROVERRUN 0x0C
  214. #define TD_BUFFERUNDERRUN 0x0D
  215. /* 0x0E, 0x0F reserved for HCD */
  216. #define TD_NOTACCESSED 0x0F
  217. /* ------------------------------------------------------------------------- */
  218. #define LOG2_PERIODIC_SIZE 5 /* arbitrary; this matches OHCI */
  219. #define PERIODIC_SIZE (1 << LOG2_PERIODIC_SIZE)
  220. /* Philips transfer descriptor */
  221. struct ptd {
  222. u16 count;
  223. #define PTD_COUNT_MSK (0x3ff << 0)
  224. #define PTD_TOGGLE_MSK (1 << 10)
  225. #define PTD_ACTIVE_MSK (1 << 11)
  226. #define PTD_CC_MSK (0xf << 12)
  227. u16 mps;
  228. #define PTD_MPS_MSK (0x3ff << 0)
  229. #define PTD_SPD_MSK (1 << 10)
  230. #define PTD_LAST_MSK (1 << 11)
  231. #define PTD_EP_MSK (0xf << 12)
  232. u16 len;
  233. #define PTD_LEN_MSK (0x3ff << 0)
  234. #define PTD_DIR_MSK (3 << 10)
  235. #define PTD_DIR_SETUP (0)
  236. #define PTD_DIR_OUT (1)
  237. #define PTD_DIR_IN (2)
  238. #define PTD_B5_5_MSK (1 << 13)
  239. u16 faddr;
  240. #define PTD_FA_MSK (0x7f << 0)
  241. #define PTD_FMT_MSK (1 << 7)
  242. } __attribute__ ((packed, aligned(2)));
  243. struct isp116x_ep {
  244. struct usb_device *udev;
  245. struct ptd ptd;
  246. u8 maxpacket;
  247. u8 epnum;
  248. u8 nextpid;
  249. u16 length; /* of current packet */
  250. unsigned char *data; /* to databuf */
  251. u16 error_count;
  252. };
  253. /* URB struct */
  254. #define N_URB_TD 48
  255. #define URB_DEL 1
  256. typedef struct {
  257. struct isp116x_ep *ed;
  258. void *transfer_buffer; /* (in) associated data buffer */
  259. int actual_length; /* (return) actual transfer length */
  260. unsigned long pipe; /* (in) pipe information */
  261. #if 0
  262. int state;
  263. #endif
  264. } urb_priv_t;
  265. struct isp116x_platform_data {
  266. /* Enable internal resistors on downstream ports */
  267. unsigned sel15Kres:1;
  268. /* On-chip overcurrent detection */
  269. unsigned oc_enable:1;
  270. /* Enable wakeup by devices on usb bus (e.g. wakeup
  271. by attachment/detachment or by device activity
  272. such as moving a mouse). When chosen, this option
  273. prevents stopping internal clock, increasing
  274. thereby power consumption in suspended state. */
  275. unsigned remote_wakeup_enable:1;
  276. };
  277. struct isp116x {
  278. u16 *addr_reg;
  279. u16 *data_reg;
  280. struct isp116x_platform_data *board;
  281. struct dentry *dentry;
  282. unsigned long stat1, stat2, stat4, stat8, stat16;
  283. /* Status flags */
  284. unsigned disabled:1;
  285. unsigned sleeping:1;
  286. /* Root hub registers */
  287. u32 rhdesca;
  288. u32 rhdescb;
  289. u32 rhstatus;
  290. u32 rhport[2];
  291. /* Schedule for the current frame */
  292. struct isp116x_ep *atl_active;
  293. int atl_buflen;
  294. int atl_bufshrt;
  295. int atl_last_dir;
  296. int atl_finishing;
  297. };
  298. /* ------------------------------------------------- */
  299. /* Inter-io delay (ns). The chip is picky about access timings; it
  300. * expects at least:
  301. * 150ns delay between consecutive accesses to DATA_REG,
  302. * 300ns delay between access to ADDR_REG and DATA_REG
  303. * OE, WE MUST NOT be changed during these intervals
  304. */
  305. #if defined(UDELAY)
  306. #define isp116x_delay(h,d) udelay(d)
  307. #else
  308. #define isp116x_delay(h,d) do {} while (0)
  309. #endif
  310. static inline void isp116x_write_addr(struct isp116x *isp116x, unsigned reg)
  311. {
  312. writew(reg & 0xff, isp116x->addr_reg);
  313. isp116x_delay(isp116x, UDELAY);
  314. }
  315. static inline void isp116x_write_data16(struct isp116x *isp116x, u16 val)
  316. {
  317. writew(val, isp116x->data_reg);
  318. isp116x_delay(isp116x, UDELAY);
  319. }
  320. static inline void isp116x_raw_write_data16(struct isp116x *isp116x, u16 val)
  321. {
  322. __raw_writew(val, isp116x->data_reg);
  323. isp116x_delay(isp116x, UDELAY);
  324. }
  325. static inline u16 isp116x_read_data16(struct isp116x *isp116x)
  326. {
  327. u16 val;
  328. val = readw(isp116x->data_reg);
  329. isp116x_delay(isp116x, UDELAY);
  330. return val;
  331. }
  332. static inline u16 isp116x_raw_read_data16(struct isp116x *isp116x)
  333. {
  334. u16 val;
  335. val = __raw_readw(isp116x->data_reg);
  336. isp116x_delay(isp116x, UDELAY);
  337. return val;
  338. }
  339. static inline void isp116x_write_data32(struct isp116x *isp116x, u32 val)
  340. {
  341. writew(val & 0xffff, isp116x->data_reg);
  342. isp116x_delay(isp116x, UDELAY);
  343. writew(val >> 16, isp116x->data_reg);
  344. isp116x_delay(isp116x, UDELAY);
  345. }
  346. static inline u32 isp116x_read_data32(struct isp116x *isp116x)
  347. {
  348. u32 val;
  349. val = (u32) readw(isp116x->data_reg);
  350. isp116x_delay(isp116x, UDELAY);
  351. val |= ((u32) readw(isp116x->data_reg)) << 16;
  352. isp116x_delay(isp116x, UDELAY);
  353. return val;
  354. }
  355. /* Let's keep register access functions out of line. Hint:
  356. we wait at least 150 ns at every access.
  357. */
  358. static u16 isp116x_read_reg16(struct isp116x *isp116x, unsigned reg)
  359. {
  360. isp116x_write_addr(isp116x, reg);
  361. return isp116x_read_data16(isp116x);
  362. }
  363. static u32 isp116x_read_reg32(struct isp116x *isp116x, unsigned reg)
  364. {
  365. isp116x_write_addr(isp116x, reg);
  366. return isp116x_read_data32(isp116x);
  367. }
  368. static void isp116x_write_reg16(struct isp116x *isp116x, unsigned reg,
  369. unsigned val)
  370. {
  371. isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET);
  372. isp116x_write_data16(isp116x, (u16) (val & 0xffff));
  373. }
  374. static void isp116x_write_reg32(struct isp116x *isp116x, unsigned reg,
  375. unsigned val)
  376. {
  377. isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET);
  378. isp116x_write_data32(isp116x, (u32) val);
  379. }
  380. /* --- USB HUB constants (not OHCI-specific; see hub.h) -------------------- */
  381. /* destination of request */
  382. #define RH_INTERFACE 0x01
  383. #define RH_ENDPOINT 0x02
  384. #define RH_OTHER 0x03
  385. #define RH_CLASS 0x20
  386. #define RH_VENDOR 0x40
  387. /* Requests: bRequest << 8 | bmRequestType */
  388. #define RH_GET_STATUS 0x0080
  389. #define RH_CLEAR_FEATURE 0x0100
  390. #define RH_SET_FEATURE 0x0300
  391. #define RH_SET_ADDRESS 0x0500
  392. #define RH_GET_DESCRIPTOR 0x0680
  393. #define RH_SET_DESCRIPTOR 0x0700
  394. #define RH_GET_CONFIGURATION 0x0880
  395. #define RH_SET_CONFIGURATION 0x0900
  396. #define RH_GET_STATE 0x0280
  397. #define RH_GET_INTERFACE 0x0A80
  398. #define RH_SET_INTERFACE 0x0B00
  399. #define RH_SYNC_FRAME 0x0C80
  400. /* Our Vendor Specific Request */
  401. #define RH_SET_EP 0x2000
  402. /* Hub port features */
  403. #define RH_PORT_CONNECTION 0x00
  404. #define RH_PORT_ENABLE 0x01
  405. #define RH_PORT_SUSPEND 0x02
  406. #define RH_PORT_OVER_CURRENT 0x03
  407. #define RH_PORT_RESET 0x04
  408. #define RH_PORT_POWER 0x08
  409. #define RH_PORT_LOW_SPEED 0x09
  410. #define RH_C_PORT_CONNECTION 0x10
  411. #define RH_C_PORT_ENABLE 0x11
  412. #define RH_C_PORT_SUSPEND 0x12
  413. #define RH_C_PORT_OVER_CURRENT 0x13
  414. #define RH_C_PORT_RESET 0x14
  415. /* Hub features */
  416. #define RH_C_HUB_LOCAL_POWER 0x00
  417. #define RH_C_HUB_OVER_CURRENT 0x01
  418. #define RH_DEVICE_REMOTE_WAKEUP 0x00
  419. #define RH_ENDPOINT_STALL 0x01
  420. #define RH_ACK 0x01
  421. #define RH_REQ_ERR -1
  422. #define RH_NACK 0x00