isp116x.h 18 KB

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