isp116x.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * ISP116x register declarations and HCD data structures
  4. *
  5. * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
  6. * Portions:
  7. * Copyright (C) 2004 Lothar Wassmann
  8. * Copyright (C) 2004 Psion Teklogix
  9. * Copyright (C) 2004 David Brownell
  10. */
  11. /* us of 1ms frame */
  12. #define MAX_LOAD_LIMIT 850
  13. /* Full speed: max # of bytes to transfer for a single urb
  14. at a time must be < 1024 && must be multiple of 64.
  15. 832 allows transferring 4kiB within 5 frames. */
  16. #define MAX_TRANSFER_SIZE_FULLSPEED 832
  17. /* Low speed: there is no reason to schedule in very big
  18. chunks; often the requested long transfers are for
  19. string descriptors containing short strings. */
  20. #define MAX_TRANSFER_SIZE_LOWSPEED 64
  21. /* Bytetime (us), a rough indication of how much time it
  22. would take to transfer a byte of useful data over USB */
  23. #define BYTE_TIME_FULLSPEED 1
  24. #define BYTE_TIME_LOWSPEED 20
  25. /* Buffer sizes */
  26. #define ISP116x_BUF_SIZE 4096
  27. #define ISP116x_ITL_BUFSIZE 0
  28. #define ISP116x_ATL_BUFSIZE ((ISP116x_BUF_SIZE) - 2*(ISP116x_ITL_BUFSIZE))
  29. #define ISP116x_WRITE_OFFSET 0x80
  30. /*------------ ISP116x registers/bits ------------*/
  31. #define HCREVISION 0x00
  32. #define HCCONTROL 0x01
  33. #define HCCONTROL_HCFS (3 << 6) /* host controller
  34. functional state */
  35. #define HCCONTROL_USB_RESET (0 << 6)
  36. #define HCCONTROL_USB_RESUME (1 << 6)
  37. #define HCCONTROL_USB_OPER (2 << 6)
  38. #define HCCONTROL_USB_SUSPEND (3 << 6)
  39. #define HCCONTROL_RWC (1 << 9) /* remote wakeup connected */
  40. #define HCCONTROL_RWE (1 << 10) /* remote wakeup enable */
  41. #define HCCMDSTAT 0x02
  42. #define HCCMDSTAT_HCR (1 << 0) /* host controller reset */
  43. #define HCCMDSTAT_SOC (3 << 16) /* scheduling overrun count */
  44. #define HCINTSTAT 0x03
  45. #define HCINT_SO (1 << 0) /* scheduling overrun */
  46. #define HCINT_WDH (1 << 1) /* writeback of done_head */
  47. #define HCINT_SF (1 << 2) /* start frame */
  48. #define HCINT_RD (1 << 3) /* resume detect */
  49. #define HCINT_UE (1 << 4) /* unrecoverable error */
  50. #define HCINT_FNO (1 << 5) /* frame number overflow */
  51. #define HCINT_RHSC (1 << 6) /* root hub status change */
  52. #define HCINT_OC (1 << 30) /* ownership change */
  53. #define HCINT_MIE (1 << 31) /* master interrupt enable */
  54. #define HCINTENB 0x04
  55. #define HCINTDIS 0x05
  56. #define HCFMINTVL 0x0d
  57. #define HCFMREM 0x0e
  58. #define HCFMNUM 0x0f
  59. #define HCLSTHRESH 0x11
  60. #define HCRHDESCA 0x12
  61. #define RH_A_NDP (0x3 << 0) /* # downstream ports */
  62. #define RH_A_PSM (1 << 8) /* power switching mode */
  63. #define RH_A_NPS (1 << 9) /* no power switching */
  64. #define RH_A_DT (1 << 10) /* device type (mbz) */
  65. #define RH_A_OCPM (1 << 11) /* overcurrent protection
  66. mode */
  67. #define RH_A_NOCP (1 << 12) /* no overcurrent protection */
  68. #define RH_A_POTPGT (0xff << 24) /* power on -> power good
  69. time */
  70. #define HCRHDESCB 0x13
  71. #define RH_B_DR (0xffff << 0) /* device removable flags */
  72. #define RH_B_PPCM (0xffff << 16) /* port power control mask */
  73. #define HCRHSTATUS 0x14
  74. #define RH_HS_LPS (1 << 0) /* local power status */
  75. #define RH_HS_OCI (1 << 1) /* over current indicator */
  76. #define RH_HS_DRWE (1 << 15) /* device remote wakeup
  77. enable */
  78. #define RH_HS_LPSC (1 << 16) /* local power status change */
  79. #define RH_HS_OCIC (1 << 17) /* over current indicator
  80. change */
  81. #define RH_HS_CRWE (1 << 31) /* clear remote wakeup
  82. enable */
  83. #define HCRHPORT1 0x15
  84. #define RH_PS_CCS (1 << 0) /* current connect status */
  85. #define RH_PS_PES (1 << 1) /* port enable status */
  86. #define RH_PS_PSS (1 << 2) /* port suspend status */
  87. #define RH_PS_POCI (1 << 3) /* port over current
  88. indicator */
  89. #define RH_PS_PRS (1 << 4) /* port reset status */
  90. #define RH_PS_PPS (1 << 8) /* port power status */
  91. #define RH_PS_LSDA (1 << 9) /* low speed device attached */
  92. #define RH_PS_CSC (1 << 16) /* connect status change */
  93. #define RH_PS_PESC (1 << 17) /* port enable status change */
  94. #define RH_PS_PSSC (1 << 18) /* port suspend status
  95. change */
  96. #define RH_PS_OCIC (1 << 19) /* over current indicator
  97. change */
  98. #define RH_PS_PRSC (1 << 20) /* port reset status change */
  99. #define HCRHPORT_CLRMASK (0x1f << 16)
  100. #define HCRHPORT2 0x16
  101. #define HCHWCFG 0x20
  102. #define HCHWCFG_15KRSEL (1 << 12)
  103. #define HCHWCFG_CLKNOTSTOP (1 << 11)
  104. #define HCHWCFG_ANALOG_OC (1 << 10)
  105. #define HCHWCFG_DACK_MODE (1 << 8)
  106. #define HCHWCFG_EOT_POL (1 << 7)
  107. #define HCHWCFG_DACK_POL (1 << 6)
  108. #define HCHWCFG_DREQ_POL (1 << 5)
  109. #define HCHWCFG_DBWIDTH_MASK (0x03 << 3)
  110. #define HCHWCFG_DBWIDTH(n) (((n) << 3) & HCHWCFG_DBWIDTH_MASK)
  111. #define HCHWCFG_INT_POL (1 << 2)
  112. #define HCHWCFG_INT_TRIGGER (1 << 1)
  113. #define HCHWCFG_INT_ENABLE (1 << 0)
  114. #define HCDMACFG 0x21
  115. #define HCDMACFG_BURST_LEN_MASK (0x03 << 5)
  116. #define HCDMACFG_BURST_LEN(n) (((n) << 5) & HCDMACFG_BURST_LEN_MASK)
  117. #define HCDMACFG_BURST_LEN_1 HCDMACFG_BURST_LEN(0)
  118. #define HCDMACFG_BURST_LEN_4 HCDMACFG_BURST_LEN(1)
  119. #define HCDMACFG_BURST_LEN_8 HCDMACFG_BURST_LEN(2)
  120. #define HCDMACFG_DMA_ENABLE (1 << 4)
  121. #define HCDMACFG_BUF_TYPE_MASK (0x07 << 1)
  122. #define HCDMACFG_CTR_SEL (1 << 2)
  123. #define HCDMACFG_ITLATL_SEL (1 << 1)
  124. #define HCDMACFG_DMA_RW_SELECT (1 << 0)
  125. #define HCXFERCTR 0x22
  126. #define HCuPINT 0x24
  127. #define HCuPINT_SOF (1 << 0)
  128. #define HCuPINT_ATL (1 << 1)
  129. #define HCuPINT_AIIEOT (1 << 2)
  130. #define HCuPINT_OPR (1 << 4)
  131. #define HCuPINT_SUSP (1 << 5)
  132. #define HCuPINT_CLKRDY (1 << 6)
  133. #define HCuPINTENB 0x25
  134. #define HCCHIPID 0x27
  135. #define HCCHIPID_MASK 0xff00
  136. #define HCCHIPID_MAGIC 0x6100
  137. #define HCSCRATCH 0x28
  138. #define HCSWRES 0x29
  139. #define HCSWRES_MAGIC 0x00f6
  140. #define HCITLBUFLEN 0x2a
  141. #define HCATLBUFLEN 0x2b
  142. #define HCBUFSTAT 0x2c
  143. #define HCBUFSTAT_ITL0_FULL (1 << 0)
  144. #define HCBUFSTAT_ITL1_FULL (1 << 1)
  145. #define HCBUFSTAT_ATL_FULL (1 << 2)
  146. #define HCBUFSTAT_ITL0_DONE (1 << 3)
  147. #define HCBUFSTAT_ITL1_DONE (1 << 4)
  148. #define HCBUFSTAT_ATL_DONE (1 << 5)
  149. #define HCRDITL0LEN 0x2d
  150. #define HCRDITL1LEN 0x2e
  151. #define HCITLPORT 0x40
  152. #define HCATLPORT 0x41
  153. /* Philips transfer descriptor */
  154. struct ptd {
  155. u16 count;
  156. #define PTD_COUNT_MSK (0x3ff << 0)
  157. #define PTD_TOGGLE_MSK (1 << 10)
  158. #define PTD_ACTIVE_MSK (1 << 11)
  159. #define PTD_CC_MSK (0xf << 12)
  160. u16 mps;
  161. #define PTD_MPS_MSK (0x3ff << 0)
  162. #define PTD_SPD_MSK (1 << 10)
  163. #define PTD_LAST_MSK (1 << 11)
  164. #define PTD_EP_MSK (0xf << 12)
  165. u16 len;
  166. #define PTD_LEN_MSK (0x3ff << 0)
  167. #define PTD_DIR_MSK (3 << 10)
  168. #define PTD_DIR_SETUP (0)
  169. #define PTD_DIR_OUT (1)
  170. #define PTD_DIR_IN (2)
  171. #define PTD_B5_5_MSK (1 << 13)
  172. u16 faddr;
  173. #define PTD_FA_MSK (0x7f << 0)
  174. #define PTD_FMT_MSK (1 << 7)
  175. } __attribute__ ((packed, aligned(2)));
  176. /* PTD accessor macros. */
  177. #define PTD_GET_COUNT(p) (((p)->count & PTD_COUNT_MSK) >> 0)
  178. #define PTD_COUNT(v) (((v) << 0) & PTD_COUNT_MSK)
  179. #define PTD_GET_TOGGLE(p) (((p)->count & PTD_TOGGLE_MSK) >> 10)
  180. #define PTD_TOGGLE(v) (((v) << 10) & PTD_TOGGLE_MSK)
  181. #define PTD_GET_ACTIVE(p) (((p)->count & PTD_ACTIVE_MSK) >> 11)
  182. #define PTD_ACTIVE(v) (((v) << 11) & PTD_ACTIVE_MSK)
  183. #define PTD_GET_CC(p) (((p)->count & PTD_CC_MSK) >> 12)
  184. #define PTD_CC(v) (((v) << 12) & PTD_CC_MSK)
  185. #define PTD_GET_MPS(p) (((p)->mps & PTD_MPS_MSK) >> 0)
  186. #define PTD_MPS(v) (((v) << 0) & PTD_MPS_MSK)
  187. #define PTD_GET_SPD(p) (((p)->mps & PTD_SPD_MSK) >> 10)
  188. #define PTD_SPD(v) (((v) << 10) & PTD_SPD_MSK)
  189. #define PTD_GET_LAST(p) (((p)->mps & PTD_LAST_MSK) >> 11)
  190. #define PTD_LAST(v) (((v) << 11) & PTD_LAST_MSK)
  191. #define PTD_GET_EP(p) (((p)->mps & PTD_EP_MSK) >> 12)
  192. #define PTD_EP(v) (((v) << 12) & PTD_EP_MSK)
  193. #define PTD_GET_LEN(p) (((p)->len & PTD_LEN_MSK) >> 0)
  194. #define PTD_LEN(v) (((v) << 0) & PTD_LEN_MSK)
  195. #define PTD_GET_DIR(p) (((p)->len & PTD_DIR_MSK) >> 10)
  196. #define PTD_DIR(v) (((v) << 10) & PTD_DIR_MSK)
  197. #define PTD_GET_B5_5(p) (((p)->len & PTD_B5_5_MSK) >> 13)
  198. #define PTD_B5_5(v) (((v) << 13) & PTD_B5_5_MSK)
  199. #define PTD_GET_FA(p) (((p)->faddr & PTD_FA_MSK) >> 0)
  200. #define PTD_FA(v) (((v) << 0) & PTD_FA_MSK)
  201. #define PTD_GET_FMT(p) (((p)->faddr & PTD_FMT_MSK) >> 7)
  202. #define PTD_FMT(v) (((v) << 7) & PTD_FMT_MSK)
  203. /* Hardware transfer status codes -- CC from ptd->count */
  204. #define TD_CC_NOERROR 0x00
  205. #define TD_CC_CRC 0x01
  206. #define TD_CC_BITSTUFFING 0x02
  207. #define TD_CC_DATATOGGLEM 0x03
  208. #define TD_CC_STALL 0x04
  209. #define TD_DEVNOTRESP 0x05
  210. #define TD_PIDCHECKFAIL 0x06
  211. #define TD_UNEXPECTEDPID 0x07
  212. #define TD_DATAOVERRUN 0x08
  213. #define TD_DATAUNDERRUN 0x09
  214. /* 0x0A, 0x0B reserved for hardware */
  215. #define TD_BUFFEROVERRUN 0x0C
  216. #define TD_BUFFERUNDERRUN 0x0D
  217. /* 0x0E, 0x0F reserved for HCD */
  218. #define TD_NOTACCESSED 0x0F
  219. /* map PTD status codes (CC) to errno values */
  220. static const int cc_to_error[16] = {
  221. /* No Error */ 0,
  222. /* CRC Error */ -EILSEQ,
  223. /* Bit Stuff */ -EPROTO,
  224. /* Data Togg */ -EILSEQ,
  225. /* Stall */ -EPIPE,
  226. /* DevNotResp */ -ETIME,
  227. /* PIDCheck */ -EPROTO,
  228. /* UnExpPID */ -EPROTO,
  229. /* DataOver */ -EOVERFLOW,
  230. /* DataUnder */ -EREMOTEIO,
  231. /* (for hw) */ -EIO,
  232. /* (for hw) */ -EIO,
  233. /* BufferOver */ -ECOMM,
  234. /* BuffUnder */ -ENOSR,
  235. /* (for HCD) */ -EALREADY,
  236. /* (for HCD) */ -EALREADY
  237. };
  238. /*--------------------------------------------------------------*/
  239. #define LOG2_PERIODIC_SIZE 5 /* arbitrary; this matches OHCI */
  240. #define PERIODIC_SIZE (1 << LOG2_PERIODIC_SIZE)
  241. struct isp116x {
  242. spinlock_t lock;
  243. void __iomem *addr_reg;
  244. void __iomem *data_reg;
  245. struct isp116x_platform_data *board;
  246. struct dentry *dentry;
  247. unsigned long stat1, stat2, stat4, stat8, stat16;
  248. /* HC registers */
  249. u32 intenb; /* "OHCI" interrupts */
  250. u16 irqenb; /* uP interrupts */
  251. /* Root hub registers */
  252. u32 rhdesca;
  253. u32 rhdescb;
  254. u32 rhstatus;
  255. /* async schedule: control, bulk */
  256. struct list_head async;
  257. /* periodic schedule: int */
  258. u16 load[PERIODIC_SIZE];
  259. struct isp116x_ep *periodic[PERIODIC_SIZE];
  260. unsigned periodic_count;
  261. u16 fmindex;
  262. /* Schedule for the current frame */
  263. struct isp116x_ep *atl_active;
  264. int atl_buflen;
  265. int atl_bufshrt;
  266. int atl_last_dir;
  267. atomic_t atl_finishing;
  268. };
  269. static inline struct isp116x *hcd_to_isp116x(struct usb_hcd *hcd)
  270. {
  271. return (struct isp116x *)(hcd->hcd_priv);
  272. }
  273. static inline struct usb_hcd *isp116x_to_hcd(struct isp116x *isp116x)
  274. {
  275. return container_of((void *)isp116x, struct usb_hcd, hcd_priv);
  276. }
  277. struct isp116x_ep {
  278. struct usb_host_endpoint *hep;
  279. struct usb_device *udev;
  280. struct ptd ptd;
  281. u8 maxpacket;
  282. u8 epnum;
  283. u8 nextpid;
  284. u16 error_count;
  285. u16 length; /* of current packet */
  286. unsigned char *data; /* to databuf */
  287. /* queue of active EP's (the ones scheduled for the
  288. current frame) */
  289. struct isp116x_ep *active;
  290. /* periodic schedule */
  291. u16 period;
  292. u16 branch;
  293. u16 load;
  294. struct isp116x_ep *next;
  295. /* async schedule */
  296. struct list_head schedule;
  297. };
  298. /*-------------------------------------------------------------------------*/
  299. #define DBG(stuff...) pr_debug("116x: " stuff)
  300. #ifdef VERBOSE
  301. # define VDBG DBG
  302. #else
  303. # define VDBG(stuff...) do{}while(0)
  304. #endif
  305. #define ERR(stuff...) printk(KERN_ERR "116x: " stuff)
  306. #define WARNING(stuff...) printk(KERN_WARNING "116x: " stuff)
  307. #define INFO(stuff...) printk(KERN_INFO "116x: " stuff)
  308. /* ------------------------------------------------- */
  309. #if defined(USE_PLATFORM_DELAY)
  310. #if defined(USE_NDELAY)
  311. #error USE_PLATFORM_DELAY and USE_NDELAY simultaneously defined.
  312. #endif
  313. #define isp116x_delay(h,d) (h)->board->delay( \
  314. isp116x_to_hcd(h)->self.controller,d)
  315. #define isp116x_check_platform_delay(h) ((h)->board->delay == NULL)
  316. #elif defined(USE_NDELAY)
  317. #define isp116x_delay(h,d) ndelay(d)
  318. #define isp116x_check_platform_delay(h) 0
  319. #else
  320. #define isp116x_delay(h,d) do{}while(0)
  321. #define isp116x_check_platform_delay(h) 0
  322. #endif
  323. static inline void isp116x_write_addr(struct isp116x *isp116x, unsigned reg)
  324. {
  325. writew(reg & 0xff, isp116x->addr_reg);
  326. isp116x_delay(isp116x, 300);
  327. }
  328. static inline void isp116x_write_data16(struct isp116x *isp116x, u16 val)
  329. {
  330. writew(val, isp116x->data_reg);
  331. isp116x_delay(isp116x, 150);
  332. }
  333. static inline void isp116x_raw_write_data16(struct isp116x *isp116x, u16 val)
  334. {
  335. __raw_writew(val, isp116x->data_reg);
  336. isp116x_delay(isp116x, 150);
  337. }
  338. static inline u16 isp116x_read_data16(struct isp116x *isp116x)
  339. {
  340. u16 val;
  341. val = readw(isp116x->data_reg);
  342. isp116x_delay(isp116x, 150);
  343. return val;
  344. }
  345. static inline u16 isp116x_raw_read_data16(struct isp116x *isp116x)
  346. {
  347. u16 val;
  348. val = __raw_readw(isp116x->data_reg);
  349. isp116x_delay(isp116x, 150);
  350. return val;
  351. }
  352. static inline void isp116x_write_data32(struct isp116x *isp116x, u32 val)
  353. {
  354. writew(val & 0xffff, isp116x->data_reg);
  355. isp116x_delay(isp116x, 150);
  356. writew(val >> 16, isp116x->data_reg);
  357. isp116x_delay(isp116x, 150);
  358. }
  359. static inline u32 isp116x_read_data32(struct isp116x *isp116x)
  360. {
  361. u32 val;
  362. val = (u32) readw(isp116x->data_reg);
  363. isp116x_delay(isp116x, 150);
  364. val |= ((u32) readw(isp116x->data_reg)) << 16;
  365. isp116x_delay(isp116x, 150);
  366. return val;
  367. }
  368. /* Let's keep register access functions out of line. Hint:
  369. we wait at least 150 ns at every access.
  370. */
  371. static u16 isp116x_read_reg16(struct isp116x *isp116x, unsigned reg)
  372. {
  373. isp116x_write_addr(isp116x, reg);
  374. return isp116x_read_data16(isp116x);
  375. }
  376. static u32 isp116x_read_reg32(struct isp116x *isp116x, unsigned reg)
  377. {
  378. isp116x_write_addr(isp116x, reg);
  379. return isp116x_read_data32(isp116x);
  380. }
  381. static void isp116x_write_reg16(struct isp116x *isp116x, unsigned reg,
  382. unsigned val)
  383. {
  384. isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET);
  385. isp116x_write_data16(isp116x, (u16) (val & 0xffff));
  386. }
  387. static void isp116x_write_reg32(struct isp116x *isp116x, unsigned reg,
  388. unsigned val)
  389. {
  390. isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET);
  391. isp116x_write_data32(isp116x, (u32) val);
  392. }
  393. #define isp116x_show_reg_log(d,r,s) { \
  394. if ((r) < 0x20) { \
  395. DBG("%-12s[%02x]: %08x\n", #r, \
  396. r, isp116x_read_reg32(d, r)); \
  397. } else { \
  398. DBG("%-12s[%02x]: %04x\n", #r, \
  399. r, isp116x_read_reg16(d, r)); \
  400. } \
  401. }
  402. #define isp116x_show_reg_seq(d,r,s) { \
  403. if ((r) < 0x20) { \
  404. seq_printf(s, "%-12s[%02x]: %08x\n", #r, \
  405. r, isp116x_read_reg32(d, r)); \
  406. } else { \
  407. seq_printf(s, "%-12s[%02x]: %04x\n", #r, \
  408. r, isp116x_read_reg16(d, r)); \
  409. } \
  410. }
  411. #define isp116x_show_regs(d,type,s) { \
  412. isp116x_show_reg_##type(d, HCREVISION, s); \
  413. isp116x_show_reg_##type(d, HCCONTROL, s); \
  414. isp116x_show_reg_##type(d, HCCMDSTAT, s); \
  415. isp116x_show_reg_##type(d, HCINTSTAT, s); \
  416. isp116x_show_reg_##type(d, HCINTENB, s); \
  417. isp116x_show_reg_##type(d, HCFMINTVL, s); \
  418. isp116x_show_reg_##type(d, HCFMREM, s); \
  419. isp116x_show_reg_##type(d, HCFMNUM, s); \
  420. isp116x_show_reg_##type(d, HCLSTHRESH, s); \
  421. isp116x_show_reg_##type(d, HCRHDESCA, s); \
  422. isp116x_show_reg_##type(d, HCRHDESCB, s); \
  423. isp116x_show_reg_##type(d, HCRHSTATUS, s); \
  424. isp116x_show_reg_##type(d, HCRHPORT1, s); \
  425. isp116x_show_reg_##type(d, HCRHPORT2, s); \
  426. isp116x_show_reg_##type(d, HCHWCFG, s); \
  427. isp116x_show_reg_##type(d, HCDMACFG, s); \
  428. isp116x_show_reg_##type(d, HCXFERCTR, s); \
  429. isp116x_show_reg_##type(d, HCuPINT, s); \
  430. isp116x_show_reg_##type(d, HCuPINTENB, s); \
  431. isp116x_show_reg_##type(d, HCCHIPID, s); \
  432. isp116x_show_reg_##type(d, HCSCRATCH, s); \
  433. isp116x_show_reg_##type(d, HCITLBUFLEN, s); \
  434. isp116x_show_reg_##type(d, HCATLBUFLEN, s); \
  435. isp116x_show_reg_##type(d, HCBUFSTAT, s); \
  436. isp116x_show_reg_##type(d, HCRDITL0LEN, s); \
  437. isp116x_show_reg_##type(d, HCRDITL1LEN, s); \
  438. }
  439. /*
  440. Dump registers for debugfs.
  441. */
  442. static inline void isp116x_show_regs_seq(struct isp116x *isp116x,
  443. struct seq_file *s)
  444. {
  445. isp116x_show_regs(isp116x, seq, s);
  446. }
  447. /*
  448. Dump registers to syslog.
  449. */
  450. static inline void isp116x_show_regs_log(struct isp116x *isp116x)
  451. {
  452. isp116x_show_regs(isp116x, log, NULL);
  453. }
  454. #if defined(URB_TRACE)
  455. #define PIPETYPE(pipe) ({ char *__s; \
  456. if (usb_pipecontrol(pipe)) __s = "ctrl"; \
  457. else if (usb_pipeint(pipe)) __s = "int"; \
  458. else if (usb_pipebulk(pipe)) __s = "bulk"; \
  459. else __s = "iso"; \
  460. __s;})
  461. #define PIPEDIR(pipe) ({ usb_pipein(pipe) ? "in" : "out"; })
  462. #define URB_NOTSHORT(urb) ({ (urb)->transfer_flags & URB_SHORT_NOT_OK ? \
  463. "short_not_ok" : ""; })
  464. /* print debug info about the URB */
  465. static void urb_dbg(struct urb *urb, char *msg)
  466. {
  467. unsigned int pipe;
  468. if (!urb) {
  469. DBG("%s: zero urb\n", msg);
  470. return;
  471. }
  472. pipe = urb->pipe;
  473. DBG("%s: FA %d ep%d%s %s: len %d/%d %s\n", msg,
  474. usb_pipedevice(pipe), usb_pipeendpoint(pipe),
  475. PIPEDIR(pipe), PIPETYPE(pipe),
  476. urb->transfer_buffer_length, urb->actual_length, URB_NOTSHORT(urb));
  477. }
  478. #else
  479. #define urb_dbg(urb,msg) do{}while(0)
  480. #endif /* ! defined(URB_TRACE) */
  481. #if defined(PTD_TRACE)
  482. #define PTD_DIR_STR(ptd) ({char __c; \
  483. switch(PTD_GET_DIR(ptd)){ \
  484. case 0: __c = 's'; break; \
  485. case 1: __c = 'o'; break; \
  486. default: __c = 'i'; break; \
  487. }; __c;})
  488. /*
  489. Dump PTD info. The code documents the format
  490. perfectly, right :)
  491. */
  492. static inline void dump_ptd(struct ptd *ptd)
  493. {
  494. printk(KERN_WARNING "td: %x %d%c%d %d,%d,%d %x %x%x%x\n",
  495. PTD_GET_CC(ptd), PTD_GET_FA(ptd),
  496. PTD_DIR_STR(ptd), PTD_GET_EP(ptd),
  497. PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd),
  498. PTD_GET_TOGGLE(ptd), PTD_GET_ACTIVE(ptd),
  499. PTD_GET_SPD(ptd), PTD_GET_LAST(ptd));
  500. }
  501. static inline void dump_ptd_out_data(struct ptd *ptd, u8 * buf)
  502. {
  503. int k;
  504. if (PTD_GET_DIR(ptd) != PTD_DIR_IN && PTD_GET_LEN(ptd)) {
  505. printk(KERN_WARNING "-> ");
  506. for (k = 0; k < PTD_GET_LEN(ptd); ++k)
  507. printk("%02x ", ((u8 *) buf)[k]);
  508. printk("\n");
  509. }
  510. }
  511. static inline void dump_ptd_in_data(struct ptd *ptd, u8 * buf)
  512. {
  513. int k;
  514. if (PTD_GET_DIR(ptd) == PTD_DIR_IN && PTD_GET_COUNT(ptd)) {
  515. printk(KERN_WARNING "<- ");
  516. for (k = 0; k < PTD_GET_COUNT(ptd); ++k)
  517. printk("%02x ", ((u8 *) buf)[k]);
  518. printk("\n");
  519. }
  520. if (PTD_GET_LAST(ptd))
  521. printk(KERN_WARNING "-\n");
  522. }
  523. #else
  524. #define dump_ptd(ptd) do{}while(0)
  525. #define dump_ptd_in_data(ptd,buf) do{}while(0)
  526. #define dump_ptd_out_data(ptd,buf) do{}while(0)
  527. #endif /* ! defined(PTD_TRACE) */