isp1362.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. /*
  2. * ISP1362 HCD (Host Controller Driver) for USB.
  3. *
  4. * COPYRIGHT (C) by L. Wassmann <LW@KARO-electronics.de>
  5. */
  6. /* ------------------------------------------------------------------------- */
  7. /*
  8. * Platform specific compile time options
  9. */
  10. #if defined(CONFIG_BLACKFIN)
  11. #include <linux/io.h>
  12. #define USE_32BIT 0
  13. #define MAX_ROOT_PORTS 2
  14. #define USE_PLATFORM_DELAY 0
  15. #define USE_NDELAY 1
  16. #define DUMMY_DELAY_ACCESS \
  17. do { \
  18. bfin_read16(ASYNC_BANK0_BASE); \
  19. bfin_read16(ASYNC_BANK0_BASE); \
  20. bfin_read16(ASYNC_BANK0_BASE); \
  21. } while (0)
  22. #undef insw
  23. #undef outsw
  24. #define insw delayed_insw
  25. #define outsw delayed_outsw
  26. static inline void delayed_outsw(unsigned int addr, void *buf, int len)
  27. {
  28. unsigned short *bp = (unsigned short *)buf;
  29. while (len--) {
  30. DUMMY_DELAY_ACCESS;
  31. outw(*bp++, addr);
  32. }
  33. }
  34. static inline void delayed_insw(unsigned int addr, void *buf, int len)
  35. {
  36. unsigned short *bp = (unsigned short *)buf;
  37. while (len--) {
  38. DUMMY_DELAY_ACCESS;
  39. *bp++ = inw(addr);
  40. }
  41. }
  42. #else
  43. #define MAX_ROOT_PORTS 2
  44. #define USE_32BIT 0
  45. /* These options are mutually eclusive */
  46. #define USE_PLATFORM_DELAY 0
  47. #define USE_NDELAY 0
  48. #define DUMMY_DELAY_ACCESS do {} while (0)
  49. #endif
  50. /* ------------------------------------------------------------------------- */
  51. #define USB_RESET_WIDTH 50
  52. #define MAX_XFER_SIZE 1023
  53. /* Buffer sizes */
  54. #define ISP1362_BUF_SIZE 4096
  55. #define ISP1362_ISTL_BUFSIZE 512
  56. #define ISP1362_INTL_BLKSIZE 64
  57. #define ISP1362_INTL_BUFFERS 16
  58. #define ISP1362_ATL_BLKSIZE 64
  59. #define ISP1362_REG_WRITE_OFFSET 0x80
  60. #define REG_WIDTH_16 0x000
  61. #define REG_WIDTH_32 0x100
  62. #define REG_WIDTH_MASK 0x100
  63. #define REG_NO_MASK 0x0ff
  64. #ifdef ISP1362_DEBUG
  65. typedef const unsigned int isp1362_reg_t;
  66. #define REG_ACCESS_R 0x200
  67. #define REG_ACCESS_W 0x400
  68. #define REG_ACCESS_RW 0x600
  69. #define REG_ACCESS_MASK 0x600
  70. #define ISP1362_REG_NO(r) ((r) & REG_NO_MASK)
  71. #define ISP1362_REG(name, addr, width, rw) \
  72. static isp1362_reg_t ISP1362_REG_##name = ((addr) | (width) | (rw))
  73. #define REG_ACCESS_TEST(r) BUG_ON(((r) & ISP1362_REG_WRITE_OFFSET) && !((r) & REG_ACCESS_W))
  74. #define REG_WIDTH_TEST(r, w) BUG_ON(((r) & REG_WIDTH_MASK) != (w))
  75. #else
  76. typedef const unsigned char isp1362_reg_t;
  77. #define ISP1362_REG_NO(r) (r)
  78. #define ISP1362_REG(name, addr, width, rw) \
  79. static isp1362_reg_t ISP1362_REG_##name = addr
  80. #define REG_ACCESS_TEST(r) do {} while (0)
  81. #define REG_WIDTH_TEST(r, w) do {} while (0)
  82. #endif
  83. /* OHCI compatible registers */
  84. /*
  85. * Note: Some of the ISP1362 'OHCI' registers implement only
  86. * a subset of the bits defined in the OHCI spec.
  87. *
  88. * Bitmasks for the individual bits of these registers are defined in "ohci.h"
  89. */
  90. ISP1362_REG(HCREVISION, 0x00, REG_WIDTH_32, REG_ACCESS_R);
  91. ISP1362_REG(HCCONTROL, 0x01, REG_WIDTH_32, REG_ACCESS_RW);
  92. ISP1362_REG(HCCMDSTAT, 0x02, REG_WIDTH_32, REG_ACCESS_RW);
  93. ISP1362_REG(HCINTSTAT, 0x03, REG_WIDTH_32, REG_ACCESS_RW);
  94. ISP1362_REG(HCINTENB, 0x04, REG_WIDTH_32, REG_ACCESS_RW);
  95. ISP1362_REG(HCINTDIS, 0x05, REG_WIDTH_32, REG_ACCESS_RW);
  96. ISP1362_REG(HCFMINTVL, 0x0d, REG_WIDTH_32, REG_ACCESS_RW);
  97. ISP1362_REG(HCFMREM, 0x0e, REG_WIDTH_32, REG_ACCESS_RW);
  98. ISP1362_REG(HCFMNUM, 0x0f, REG_WIDTH_32, REG_ACCESS_RW);
  99. ISP1362_REG(HCLSTHRESH, 0x11, REG_WIDTH_32, REG_ACCESS_RW);
  100. ISP1362_REG(HCRHDESCA, 0x12, REG_WIDTH_32, REG_ACCESS_RW);
  101. ISP1362_REG(HCRHDESCB, 0x13, REG_WIDTH_32, REG_ACCESS_RW);
  102. ISP1362_REG(HCRHSTATUS, 0x14, REG_WIDTH_32, REG_ACCESS_RW);
  103. ISP1362_REG(HCRHPORT1, 0x15, REG_WIDTH_32, REG_ACCESS_RW);
  104. ISP1362_REG(HCRHPORT2, 0x16, REG_WIDTH_32, REG_ACCESS_RW);
  105. /* Philips ISP1362 specific registers */
  106. ISP1362_REG(HCHWCFG, 0x20, REG_WIDTH_16, REG_ACCESS_RW);
  107. #define HCHWCFG_DISABLE_SUSPEND (1 << 15)
  108. #define HCHWCFG_GLOBAL_PWRDOWN (1 << 14)
  109. #define HCHWCFG_PULLDOWN_DS2 (1 << 13)
  110. #define HCHWCFG_PULLDOWN_DS1 (1 << 12)
  111. #define HCHWCFG_CLKNOTSTOP (1 << 11)
  112. #define HCHWCFG_ANALOG_OC (1 << 10)
  113. #define HCHWCFG_ONEINT (1 << 9)
  114. #define HCHWCFG_DACK_MODE (1 << 8)
  115. #define HCHWCFG_ONEDMA (1 << 7)
  116. #define HCHWCFG_DACK_POL (1 << 6)
  117. #define HCHWCFG_DREQ_POL (1 << 5)
  118. #define HCHWCFG_DBWIDTH_MASK (0x03 << 3)
  119. #define HCHWCFG_DBWIDTH(n) (((n) << 3) & HCHWCFG_DBWIDTH_MASK)
  120. #define HCHWCFG_INT_POL (1 << 2)
  121. #define HCHWCFG_INT_TRIGGER (1 << 1)
  122. #define HCHWCFG_INT_ENABLE (1 << 0)
  123. ISP1362_REG(HCDMACFG, 0x21, REG_WIDTH_16, REG_ACCESS_RW);
  124. #define HCDMACFG_CTR_ENABLE (1 << 7)
  125. #define HCDMACFG_BURST_LEN_MASK (0x03 << 5)
  126. #define HCDMACFG_BURST_LEN(n) (((n) << 5) & HCDMACFG_BURST_LEN_MASK)
  127. #define HCDMACFG_BURST_LEN_1 HCDMACFG_BURST_LEN(0)
  128. #define HCDMACFG_BURST_LEN_4 HCDMACFG_BURST_LEN(1)
  129. #define HCDMACFG_BURST_LEN_8 HCDMACFG_BURST_LEN(2)
  130. #define HCDMACFG_DMA_ENABLE (1 << 4)
  131. #define HCDMACFG_BUF_TYPE_MASK (0x07 << 1)
  132. #define HCDMACFG_BUF_TYPE(n) (((n) << 1) & HCDMACFG_BUF_TYPE_MASK)
  133. #define HCDMACFG_BUF_ISTL0 HCDMACFG_BUF_TYPE(0)
  134. #define HCDMACFG_BUF_ISTL1 HCDMACFG_BUF_TYPE(1)
  135. #define HCDMACFG_BUF_INTL HCDMACFG_BUF_TYPE(2)
  136. #define HCDMACFG_BUF_ATL HCDMACFG_BUF_TYPE(3)
  137. #define HCDMACFG_BUF_DIRECT HCDMACFG_BUF_TYPE(4)
  138. #define HCDMACFG_DMA_RW_SELECT (1 << 0)
  139. ISP1362_REG(HCXFERCTR, 0x22, REG_WIDTH_16, REG_ACCESS_RW);
  140. ISP1362_REG(HCuPINT, 0x24, REG_WIDTH_16, REG_ACCESS_RW);
  141. #define HCuPINT_SOF (1 << 0)
  142. #define HCuPINT_ISTL0 (1 << 1)
  143. #define HCuPINT_ISTL1 (1 << 2)
  144. #define HCuPINT_EOT (1 << 3)
  145. #define HCuPINT_OPR (1 << 4)
  146. #define HCuPINT_SUSP (1 << 5)
  147. #define HCuPINT_CLKRDY (1 << 6)
  148. #define HCuPINT_INTL (1 << 7)
  149. #define HCuPINT_ATL (1 << 8)
  150. #define HCuPINT_OTG (1 << 9)
  151. ISP1362_REG(HCuPINTENB, 0x25, REG_WIDTH_16, REG_ACCESS_RW);
  152. /* same bit definitions apply as for HCuPINT */
  153. ISP1362_REG(HCCHIPID, 0x27, REG_WIDTH_16, REG_ACCESS_R);
  154. #define HCCHIPID_MASK 0xff00
  155. #define HCCHIPID_MAGIC 0x3600
  156. ISP1362_REG(HCSCRATCH, 0x28, REG_WIDTH_16, REG_ACCESS_RW);
  157. ISP1362_REG(HCSWRES, 0x29, REG_WIDTH_16, REG_ACCESS_W);
  158. #define HCSWRES_MAGIC 0x00f6
  159. ISP1362_REG(HCBUFSTAT, 0x2c, REG_WIDTH_16, REG_ACCESS_RW);
  160. #define HCBUFSTAT_ISTL0_FULL (1 << 0)
  161. #define HCBUFSTAT_ISTL1_FULL (1 << 1)
  162. #define HCBUFSTAT_INTL_ACTIVE (1 << 2)
  163. #define HCBUFSTAT_ATL_ACTIVE (1 << 3)
  164. #define HCBUFSTAT_RESET_HWPP (1 << 4)
  165. #define HCBUFSTAT_ISTL0_ACTIVE (1 << 5)
  166. #define HCBUFSTAT_ISTL1_ACTIVE (1 << 6)
  167. #define HCBUFSTAT_ISTL0_DONE (1 << 8)
  168. #define HCBUFSTAT_ISTL1_DONE (1 << 9)
  169. #define HCBUFSTAT_PAIRED_PTDPP (1 << 10)
  170. ISP1362_REG(HCDIRADDR, 0x32, REG_WIDTH_32, REG_ACCESS_RW);
  171. #define HCDIRADDR_ADDR_MASK 0x0000ffff
  172. #define HCDIRADDR_ADDR(n) (((n) << 0) & HCDIRADDR_ADDR_MASK)
  173. #define HCDIRADDR_COUNT_MASK 0xffff0000
  174. #define HCDIRADDR_COUNT(n) (((n) << 16) & HCDIRADDR_COUNT_MASK)
  175. ISP1362_REG(HCDIRDATA, 0x45, REG_WIDTH_16, REG_ACCESS_RW);
  176. ISP1362_REG(HCISTLBUFSZ, 0x30, REG_WIDTH_16, REG_ACCESS_RW);
  177. ISP1362_REG(HCISTL0PORT, 0x40, REG_WIDTH_16, REG_ACCESS_RW);
  178. ISP1362_REG(HCISTL1PORT, 0x42, REG_WIDTH_16, REG_ACCESS_RW);
  179. ISP1362_REG(HCISTLRATE, 0x47, REG_WIDTH_16, REG_ACCESS_RW);
  180. ISP1362_REG(HCINTLBUFSZ, 0x33, REG_WIDTH_16, REG_ACCESS_RW);
  181. ISP1362_REG(HCINTLPORT, 0x43, REG_WIDTH_16, REG_ACCESS_RW);
  182. ISP1362_REG(HCINTLBLKSZ, 0x53, REG_WIDTH_16, REG_ACCESS_RW);
  183. ISP1362_REG(HCINTLDONE, 0x17, REG_WIDTH_32, REG_ACCESS_R);
  184. ISP1362_REG(HCINTLSKIP, 0x18, REG_WIDTH_32, REG_ACCESS_RW);
  185. ISP1362_REG(HCINTLLAST, 0x19, REG_WIDTH_32, REG_ACCESS_RW);
  186. ISP1362_REG(HCINTLCURR, 0x1a, REG_WIDTH_16, REG_ACCESS_R);
  187. ISP1362_REG(HCATLBUFSZ, 0x34, REG_WIDTH_16, REG_ACCESS_RW);
  188. ISP1362_REG(HCATLPORT, 0x44, REG_WIDTH_16, REG_ACCESS_RW);
  189. ISP1362_REG(HCATLBLKSZ, 0x54, REG_WIDTH_16, REG_ACCESS_RW);
  190. ISP1362_REG(HCATLDONE, 0x1b, REG_WIDTH_32, REG_ACCESS_R);
  191. ISP1362_REG(HCATLSKIP, 0x1c, REG_WIDTH_32, REG_ACCESS_RW);
  192. ISP1362_REG(HCATLLAST, 0x1d, REG_WIDTH_32, REG_ACCESS_RW);
  193. ISP1362_REG(HCATLCURR, 0x1e, REG_WIDTH_16, REG_ACCESS_R);
  194. ISP1362_REG(HCATLDTC, 0x51, REG_WIDTH_16, REG_ACCESS_RW);
  195. ISP1362_REG(HCATLDTCTO, 0x52, REG_WIDTH_16, REG_ACCESS_RW);
  196. ISP1362_REG(OTGCONTROL, 0x62, REG_WIDTH_16, REG_ACCESS_RW);
  197. ISP1362_REG(OTGSTATUS, 0x67, REG_WIDTH_16, REG_ACCESS_R);
  198. ISP1362_REG(OTGINT, 0x68, REG_WIDTH_16, REG_ACCESS_RW);
  199. ISP1362_REG(OTGINTENB, 0x69, REG_WIDTH_16, REG_ACCESS_RW);
  200. ISP1362_REG(OTGTIMER, 0x6A, REG_WIDTH_16, REG_ACCESS_RW);
  201. ISP1362_REG(OTGALTTMR, 0x6C, REG_WIDTH_16, REG_ACCESS_RW);
  202. /* Philips transfer descriptor, cpu-endian */
  203. struct ptd {
  204. u16 count;
  205. #define PTD_COUNT_MSK (0x3ff << 0)
  206. #define PTD_TOGGLE_MSK (1 << 10)
  207. #define PTD_ACTIVE_MSK (1 << 11)
  208. #define PTD_CC_MSK (0xf << 12)
  209. u16 mps;
  210. #define PTD_MPS_MSK (0x3ff << 0)
  211. #define PTD_SPD_MSK (1 << 10)
  212. #define PTD_LAST_MSK (1 << 11)
  213. #define PTD_EP_MSK (0xf << 12)
  214. u16 len;
  215. #define PTD_LEN_MSK (0x3ff << 0)
  216. #define PTD_DIR_MSK (3 << 10)
  217. #define PTD_DIR_SETUP (0)
  218. #define PTD_DIR_OUT (1)
  219. #define PTD_DIR_IN (2)
  220. u16 faddr;
  221. #define PTD_FA_MSK (0x7f << 0)
  222. /* PTD Byte 7: [StartingFrame (if ISO PTD) | StartingFrame[0..4], PollingRate[0..2] (if INT PTD)] */
  223. #define PTD_SF_ISO_MSK (0xff << 8)
  224. #define PTD_SF_INT_MSK (0x1f << 8)
  225. #define PTD_PR_MSK (0x07 << 13)
  226. } __attribute__ ((packed, aligned(2)));
  227. #define PTD_HEADER_SIZE sizeof(struct ptd)
  228. /* ------------------------------------------------------------------------- */
  229. /* Copied from ohci.h: */
  230. /*
  231. * Hardware transfer status codes -- CC from PTD
  232. */
  233. #define PTD_CC_NOERROR 0x00
  234. #define PTD_CC_CRC 0x01
  235. #define PTD_CC_BITSTUFFING 0x02
  236. #define PTD_CC_DATATOGGLEM 0x03
  237. #define PTD_CC_STALL 0x04
  238. #define PTD_DEVNOTRESP 0x05
  239. #define PTD_PIDCHECKFAIL 0x06
  240. #define PTD_UNEXPECTEDPID 0x07
  241. #define PTD_DATAOVERRUN 0x08
  242. #define PTD_DATAUNDERRUN 0x09
  243. /* 0x0A, 0x0B reserved for hardware */
  244. #define PTD_BUFFEROVERRUN 0x0C
  245. #define PTD_BUFFERUNDERRUN 0x0D
  246. /* 0x0E, 0x0F reserved for HCD */
  247. #define PTD_NOTACCESSED 0x0F
  248. /* map OHCI TD status codes (CC) to errno values */
  249. static const int cc_to_error[16] = {
  250. /* No Error */ 0,
  251. /* CRC Error */ -EILSEQ,
  252. /* Bit Stuff */ -EPROTO,
  253. /* Data Togg */ -EILSEQ,
  254. /* Stall */ -EPIPE,
  255. /* DevNotResp */ -ETIMEDOUT,
  256. /* PIDCheck */ -EPROTO,
  257. /* UnExpPID */ -EPROTO,
  258. /* DataOver */ -EOVERFLOW,
  259. /* DataUnder */ -EREMOTEIO,
  260. /* (for hw) */ -EIO,
  261. /* (for hw) */ -EIO,
  262. /* BufferOver */ -ECOMM,
  263. /* BuffUnder */ -ENOSR,
  264. /* (for HCD) */ -EALREADY,
  265. /* (for HCD) */ -EALREADY
  266. };
  267. /*
  268. * HcControl (control) register masks
  269. */
  270. #define OHCI_CTRL_HCFS (3 << 6) /* host controller functional state */
  271. #define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */
  272. #define OHCI_CTRL_RWE (1 << 10) /* remote wakeup enable */
  273. /* pre-shifted values for HCFS */
  274. # define OHCI_USB_RESET (0 << 6)
  275. # define OHCI_USB_RESUME (1 << 6)
  276. # define OHCI_USB_OPER (2 << 6)
  277. # define OHCI_USB_SUSPEND (3 << 6)
  278. /*
  279. * HcCommandStatus (cmdstatus) register masks
  280. */
  281. #define OHCI_HCR (1 << 0) /* host controller reset */
  282. #define OHCI_SOC (3 << 16) /* scheduling overrun count */
  283. /*
  284. * masks used with interrupt registers:
  285. * HcInterruptStatus (intrstatus)
  286. * HcInterruptEnable (intrenable)
  287. * HcInterruptDisable (intrdisable)
  288. */
  289. #define OHCI_INTR_SO (1 << 0) /* scheduling overrun */
  290. #define OHCI_INTR_WDH (1 << 1) /* writeback of done_head */
  291. #define OHCI_INTR_SF (1 << 2) /* start frame */
  292. #define OHCI_INTR_RD (1 << 3) /* resume detect */
  293. #define OHCI_INTR_UE (1 << 4) /* unrecoverable error */
  294. #define OHCI_INTR_FNO (1 << 5) /* frame number overflow */
  295. #define OHCI_INTR_RHSC (1 << 6) /* root hub status change */
  296. #define OHCI_INTR_OC (1 << 30) /* ownership change */
  297. #define OHCI_INTR_MIE (1 << 31) /* master interrupt enable */
  298. /* roothub.portstatus [i] bits */
  299. #define RH_PS_CCS 0x00000001 /* current connect status */
  300. #define RH_PS_PES 0x00000002 /* port enable status*/
  301. #define RH_PS_PSS 0x00000004 /* port suspend status */
  302. #define RH_PS_POCI 0x00000008 /* port over current indicator */
  303. #define RH_PS_PRS 0x00000010 /* port reset status */
  304. #define RH_PS_PPS 0x00000100 /* port power status */
  305. #define RH_PS_LSDA 0x00000200 /* low speed device attached */
  306. #define RH_PS_CSC 0x00010000 /* connect status change */
  307. #define RH_PS_PESC 0x00020000 /* port enable status change */
  308. #define RH_PS_PSSC 0x00040000 /* port suspend status change */
  309. #define RH_PS_OCIC 0x00080000 /* over current indicator change */
  310. #define RH_PS_PRSC 0x00100000 /* port reset status change */
  311. /* roothub.status bits */
  312. #define RH_HS_LPS 0x00000001 /* local power status */
  313. #define RH_HS_OCI 0x00000002 /* over current indicator */
  314. #define RH_HS_DRWE 0x00008000 /* device remote wakeup enable */
  315. #define RH_HS_LPSC 0x00010000 /* local power status change */
  316. #define RH_HS_OCIC 0x00020000 /* over current indicator change */
  317. #define RH_HS_CRWE 0x80000000 /* clear remote wakeup enable */
  318. /* roothub.b masks */
  319. #define RH_B_DR 0x0000ffff /* device removable flags */
  320. #define RH_B_PPCM 0xffff0000 /* port power control mask */
  321. /* roothub.a masks */
  322. #define RH_A_NDP (0xff << 0) /* number of downstream ports */
  323. #define RH_A_PSM (1 << 8) /* power switching mode */
  324. #define RH_A_NPS (1 << 9) /* no power switching */
  325. #define RH_A_DT (1 << 10) /* device type (mbz) */
  326. #define RH_A_OCPM (1 << 11) /* over current protection mode */
  327. #define RH_A_NOCP (1 << 12) /* no over current protection */
  328. #define RH_A_POTPGT (0xff << 24) /* power on to power good time */
  329. #define FI 0x2edf /* 12000 bits per frame (-1) */
  330. #define FSMP(fi) (0x7fff & ((6 * ((fi) - 210)) / 7))
  331. #define LSTHRESH 0x628 /* lowspeed bit threshold */
  332. /* ------------------------------------------------------------------------- */
  333. /* PTD accessor macros. */
  334. #define PTD_GET_COUNT(p) (((p)->count & PTD_COUNT_MSK) >> 0)
  335. #define PTD_COUNT(v) (((v) << 0) & PTD_COUNT_MSK)
  336. #define PTD_GET_TOGGLE(p) (((p)->count & PTD_TOGGLE_MSK) >> 10)
  337. #define PTD_TOGGLE(v) (((v) << 10) & PTD_TOGGLE_MSK)
  338. #define PTD_GET_ACTIVE(p) (((p)->count & PTD_ACTIVE_MSK) >> 11)
  339. #define PTD_ACTIVE(v) (((v) << 11) & PTD_ACTIVE_MSK)
  340. #define PTD_GET_CC(p) (((p)->count & PTD_CC_MSK) >> 12)
  341. #define PTD_CC(v) (((v) << 12) & PTD_CC_MSK)
  342. #define PTD_GET_MPS(p) (((p)->mps & PTD_MPS_MSK) >> 0)
  343. #define PTD_MPS(v) (((v) << 0) & PTD_MPS_MSK)
  344. #define PTD_GET_SPD(p) (((p)->mps & PTD_SPD_MSK) >> 10)
  345. #define PTD_SPD(v) (((v) << 10) & PTD_SPD_MSK)
  346. #define PTD_GET_LAST(p) (((p)->mps & PTD_LAST_MSK) >> 11)
  347. #define PTD_LAST(v) (((v) << 11) & PTD_LAST_MSK)
  348. #define PTD_GET_EP(p) (((p)->mps & PTD_EP_MSK) >> 12)
  349. #define PTD_EP(v) (((v) << 12) & PTD_EP_MSK)
  350. #define PTD_GET_LEN(p) (((p)->len & PTD_LEN_MSK) >> 0)
  351. #define PTD_LEN(v) (((v) << 0) & PTD_LEN_MSK)
  352. #define PTD_GET_DIR(p) (((p)->len & PTD_DIR_MSK) >> 10)
  353. #define PTD_DIR(v) (((v) << 10) & PTD_DIR_MSK)
  354. #define PTD_GET_FA(p) (((p)->faddr & PTD_FA_MSK) >> 0)
  355. #define PTD_FA(v) (((v) << 0) & PTD_FA_MSK)
  356. #define PTD_GET_SF_INT(p) (((p)->faddr & PTD_SF_INT_MSK) >> 8)
  357. #define PTD_SF_INT(v) (((v) << 8) & PTD_SF_INT_MSK)
  358. #define PTD_GET_SF_ISO(p) (((p)->faddr & PTD_SF_ISO_MSK) >> 8)
  359. #define PTD_SF_ISO(v) (((v) << 8) & PTD_SF_ISO_MSK)
  360. #define PTD_GET_PR(p) (((p)->faddr & PTD_PR_MSK) >> 13)
  361. #define PTD_PR(v) (((v) << 13) & PTD_PR_MSK)
  362. #define LOG2_PERIODIC_SIZE 5 /* arbitrary; this matches OHCI */
  363. #define PERIODIC_SIZE (1 << LOG2_PERIODIC_SIZE)
  364. struct isp1362_ep {
  365. struct usb_host_endpoint *hep;
  366. struct usb_device *udev;
  367. /* philips transfer descriptor */
  368. struct ptd ptd;
  369. u8 maxpacket;
  370. u8 epnum;
  371. u8 nextpid;
  372. u16 error_count;
  373. u16 length; /* of current packet */
  374. s16 ptd_offset; /* buffer offset in ISP1362 where
  375. PTD has been stored
  376. (for access thru HCDIRDATA) */
  377. int ptd_index;
  378. int num_ptds;
  379. void *data; /* to databuf */
  380. /* queue of active EPs (the ones transmitted to the chip) */
  381. struct list_head active;
  382. /* periodic schedule */
  383. u8 branch;
  384. u16 interval;
  385. u16 load;
  386. u16 last_iso;
  387. /* async schedule */
  388. struct list_head schedule; /* list of all EPs that need processing */
  389. struct list_head remove_list;
  390. int num_req;
  391. };
  392. struct isp1362_ep_queue {
  393. struct list_head active; /* list of PTDs currently processed by HC */
  394. atomic_t finishing;
  395. unsigned long buf_map;
  396. unsigned long skip_map;
  397. int free_ptd;
  398. u16 buf_start;
  399. u16 buf_size;
  400. u16 blk_size; /* PTD buffer block size for ATL and INTL */
  401. u8 buf_count;
  402. u8 buf_avail;
  403. char name[16];
  404. /* for statistical tracking */
  405. u8 stat_maxptds; /* Max # of ptds seen simultaneously in fifo */
  406. u8 ptd_count; /* number of ptds submitted to this queue */
  407. };
  408. struct isp1362_hcd {
  409. spinlock_t lock;
  410. void __iomem *addr_reg;
  411. void __iomem *data_reg;
  412. struct isp1362_platform_data *board;
  413. struct dentry *debug_file;
  414. unsigned long stat1, stat2, stat4, stat8, stat16;
  415. /* HC registers */
  416. u32 intenb; /* "OHCI" interrupts */
  417. u16 irqenb; /* uP interrupts */
  418. /* Root hub registers */
  419. u32 rhdesca;
  420. u32 rhdescb;
  421. u32 rhstatus;
  422. u32 rhport[MAX_ROOT_PORTS];
  423. unsigned long next_statechange;
  424. /* HC control reg shadow copy */
  425. u32 hc_control;
  426. /* async schedule: control, bulk */
  427. struct list_head async;
  428. /* periodic schedule: int */
  429. u16 load[PERIODIC_SIZE];
  430. struct list_head periodic;
  431. u16 fmindex;
  432. /* periodic schedule: isochronous */
  433. struct list_head isoc;
  434. unsigned int istl_flip:1;
  435. unsigned int irq_active:1;
  436. /* Schedules for the current frame */
  437. struct isp1362_ep_queue atl_queue;
  438. struct isp1362_ep_queue intl_queue;
  439. struct isp1362_ep_queue istl_queue[2];
  440. /* list of PTDs retrieved from HC */
  441. struct list_head remove_list;
  442. enum {
  443. ISP1362_INT_SOF,
  444. ISP1362_INT_ISTL0,
  445. ISP1362_INT_ISTL1,
  446. ISP1362_INT_EOT,
  447. ISP1362_INT_OPR,
  448. ISP1362_INT_SUSP,
  449. ISP1362_INT_CLKRDY,
  450. ISP1362_INT_INTL,
  451. ISP1362_INT_ATL,
  452. ISP1362_INT_OTG,
  453. NUM_ISP1362_IRQS
  454. } IRQ_NAMES;
  455. unsigned int irq_stat[NUM_ISP1362_IRQS];
  456. int req_serial;
  457. };
  458. static inline const char *ISP1362_INT_NAME(int n)
  459. {
  460. switch (n) {
  461. case ISP1362_INT_SOF: return "SOF";
  462. case ISP1362_INT_ISTL0: return "ISTL0";
  463. case ISP1362_INT_ISTL1: return "ISTL1";
  464. case ISP1362_INT_EOT: return "EOT";
  465. case ISP1362_INT_OPR: return "OPR";
  466. case ISP1362_INT_SUSP: return "SUSP";
  467. case ISP1362_INT_CLKRDY: return "CLKRDY";
  468. case ISP1362_INT_INTL: return "INTL";
  469. case ISP1362_INT_ATL: return "ATL";
  470. case ISP1362_INT_OTG: return "OTG";
  471. default: return "unknown";
  472. }
  473. }
  474. static inline void ALIGNSTAT(struct isp1362_hcd *isp1362_hcd, void *ptr)
  475. {
  476. unsigned long p = (unsigned long)ptr;
  477. if (!(p & 0xf))
  478. isp1362_hcd->stat16++;
  479. else if (!(p & 0x7))
  480. isp1362_hcd->stat8++;
  481. else if (!(p & 0x3))
  482. isp1362_hcd->stat4++;
  483. else if (!(p & 0x1))
  484. isp1362_hcd->stat2++;
  485. else
  486. isp1362_hcd->stat1++;
  487. }
  488. static inline struct isp1362_hcd *hcd_to_isp1362_hcd(struct usb_hcd *hcd)
  489. {
  490. return (struct isp1362_hcd *) (hcd->hcd_priv);
  491. }
  492. static inline struct usb_hcd *isp1362_hcd_to_hcd(struct isp1362_hcd *isp1362_hcd)
  493. {
  494. return container_of((void *)isp1362_hcd, struct usb_hcd, hcd_priv);
  495. }
  496. #define frame_before(f1, f2) ((s16)((u16)f1 - (u16)f2) < 0)
  497. /*
  498. * ISP1362 HW Interface
  499. */
  500. #define DBG(level, fmt...) \
  501. do { \
  502. if (dbg_level > level) \
  503. pr_debug(fmt); \
  504. } while (0)
  505. #ifdef VERBOSE
  506. # define VDBG(fmt...) DBG(3, fmt)
  507. #else
  508. # define VDBG(fmt...) do {} while (0)
  509. #endif
  510. #ifdef REGISTERS
  511. # define RDBG(fmt...) DBG(1, fmt)
  512. #else
  513. # define RDBG(fmt...) do {} while (0)
  514. #endif
  515. #ifdef URB_TRACE
  516. #define URB_DBG(fmt...) DBG(0, fmt)
  517. #else
  518. #define URB_DBG(fmt...) do {} while (0)
  519. #endif
  520. #if USE_PLATFORM_DELAY
  521. #if USE_NDELAY
  522. #error USE_PLATFORM_DELAY and USE_NDELAY defined simultaneously.
  523. #endif
  524. #define isp1362_delay(h, d) (h)->board->delay(isp1362_hcd_to_hcd(h)->self.controller, d)
  525. #elif USE_NDELAY
  526. #define isp1362_delay(h, d) ndelay(d)
  527. #else
  528. #define isp1362_delay(h, d) do {} while (0)
  529. #endif
  530. #define get_urb(ep) ({ \
  531. BUG_ON(list_empty(&ep->hep->urb_list)); \
  532. container_of(ep->hep->urb_list.next, struct urb, urb_list); \
  533. })
  534. /* basic access functions for ISP1362 chip registers */
  535. /* NOTE: The contents of the address pointer register cannot be read back! The driver must ensure,
  536. * that all register accesses are performed with interrupts disabled, since the interrupt
  537. * handler has no way of restoring the previous state.
  538. */
  539. static void isp1362_write_addr(struct isp1362_hcd *isp1362_hcd, isp1362_reg_t reg)
  540. {
  541. REG_ACCESS_TEST(reg);
  542. DUMMY_DELAY_ACCESS;
  543. writew(ISP1362_REG_NO(reg), isp1362_hcd->addr_reg);
  544. DUMMY_DELAY_ACCESS;
  545. isp1362_delay(isp1362_hcd, 1);
  546. }
  547. static void isp1362_write_data16(struct isp1362_hcd *isp1362_hcd, u16 val)
  548. {
  549. DUMMY_DELAY_ACCESS;
  550. writew(val, isp1362_hcd->data_reg);
  551. }
  552. static u16 isp1362_read_data16(struct isp1362_hcd *isp1362_hcd)
  553. {
  554. u16 val;
  555. DUMMY_DELAY_ACCESS;
  556. val = readw(isp1362_hcd->data_reg);
  557. return val;
  558. }
  559. static void isp1362_write_data32(struct isp1362_hcd *isp1362_hcd, u32 val)
  560. {
  561. #if USE_32BIT
  562. DUMMY_DELAY_ACCESS;
  563. writel(val, isp1362_hcd->data_reg);
  564. #else
  565. DUMMY_DELAY_ACCESS;
  566. writew((u16)val, isp1362_hcd->data_reg);
  567. DUMMY_DELAY_ACCESS;
  568. writew(val >> 16, isp1362_hcd->data_reg);
  569. #endif
  570. }
  571. static u32 isp1362_read_data32(struct isp1362_hcd *isp1362_hcd)
  572. {
  573. u32 val;
  574. #if USE_32BIT
  575. DUMMY_DELAY_ACCESS;
  576. val = readl(isp1362_hcd->data_reg);
  577. #else
  578. DUMMY_DELAY_ACCESS;
  579. val = (u32)readw(isp1362_hcd->data_reg);
  580. DUMMY_DELAY_ACCESS;
  581. val |= (u32)readw(isp1362_hcd->data_reg) << 16;
  582. #endif
  583. return val;
  584. }
  585. /* use readsw/writesw to access the fifo whenever possible */
  586. /* assume HCDIRDATA or XFERCTR & addr_reg have been set up */
  587. static void isp1362_read_fifo(struct isp1362_hcd *isp1362_hcd, void *buf, u16 len)
  588. {
  589. u8 *dp = buf;
  590. u16 data;
  591. if (!len)
  592. return;
  593. RDBG("%s: Reading %d byte from fifo to mem @ %p\n", __func__, len, buf);
  594. #if USE_32BIT
  595. if (len >= 4) {
  596. RDBG("%s: Using readsl for %d dwords\n", __func__, len >> 2);
  597. readsl(isp1362_hcd->data_reg, dp, len >> 2);
  598. dp += len & ~3;
  599. len &= 3;
  600. }
  601. #endif
  602. if (len >= 2) {
  603. RDBG("%s: Using readsw for %d words\n", __func__, len >> 1);
  604. insw((unsigned long)isp1362_hcd->data_reg, dp, len >> 1);
  605. dp += len & ~1;
  606. len &= 1;
  607. }
  608. BUG_ON(len & ~1);
  609. if (len > 0) {
  610. data = isp1362_read_data16(isp1362_hcd);
  611. RDBG("%s: Reading trailing byte %02x to mem @ %08x\n", __func__,
  612. (u8)data, (u32)dp);
  613. *dp = (u8)data;
  614. }
  615. }
  616. static void isp1362_write_fifo(struct isp1362_hcd *isp1362_hcd, void *buf, u16 len)
  617. {
  618. u8 *dp = buf;
  619. u16 data;
  620. if (!len)
  621. return;
  622. if ((unsigned long)dp & 0x1) {
  623. /* not aligned */
  624. for (; len > 1; len -= 2) {
  625. data = *dp++;
  626. data |= *dp++ << 8;
  627. isp1362_write_data16(isp1362_hcd, data);
  628. }
  629. if (len)
  630. isp1362_write_data16(isp1362_hcd, *dp);
  631. return;
  632. }
  633. RDBG("%s: Writing %d byte to fifo from memory @%p\n", __func__, len, buf);
  634. #if USE_32BIT
  635. if (len >= 4) {
  636. RDBG("%s: Using writesl for %d dwords\n", __func__, len >> 2);
  637. writesl(isp1362_hcd->data_reg, dp, len >> 2);
  638. dp += len & ~3;
  639. len &= 3;
  640. }
  641. #endif
  642. if (len >= 2) {
  643. RDBG("%s: Using writesw for %d words\n", __func__, len >> 1);
  644. outsw((unsigned long)isp1362_hcd->data_reg, dp, len >> 1);
  645. dp += len & ~1;
  646. len &= 1;
  647. }
  648. BUG_ON(len & ~1);
  649. if (len > 0) {
  650. /* finally write any trailing byte; we don't need to care
  651. * about the high byte of the last word written
  652. */
  653. data = (u16)*dp;
  654. RDBG("%s: Sending trailing byte %02x from mem @ %08x\n", __func__,
  655. data, (u32)dp);
  656. isp1362_write_data16(isp1362_hcd, data);
  657. }
  658. }
  659. #define isp1362_read_reg16(d, r) ({ \
  660. u16 __v; \
  661. REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_16); \
  662. isp1362_write_addr(d, ISP1362_REG_##r); \
  663. __v = isp1362_read_data16(d); \
  664. RDBG("%s: Read %04x from %s[%02x]\n", __func__, __v, #r, \
  665. ISP1362_REG_NO(ISP1362_REG_##r)); \
  666. __v; \
  667. })
  668. #define isp1362_read_reg32(d, r) ({ \
  669. u32 __v; \
  670. REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_32); \
  671. isp1362_write_addr(d, ISP1362_REG_##r); \
  672. __v = isp1362_read_data32(d); \
  673. RDBG("%s: Read %08x from %s[%02x]\n", __func__, __v, #r, \
  674. ISP1362_REG_NO(ISP1362_REG_##r)); \
  675. __v; \
  676. })
  677. #define isp1362_write_reg16(d, r, v) { \
  678. REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_16); \
  679. isp1362_write_addr(d, (ISP1362_REG_##r) | ISP1362_REG_WRITE_OFFSET); \
  680. isp1362_write_data16(d, (u16)(v)); \
  681. RDBG("%s: Wrote %04x to %s[%02x]\n", __func__, (u16)(v), #r, \
  682. ISP1362_REG_NO(ISP1362_REG_##r)); \
  683. }
  684. #define isp1362_write_reg32(d, r, v) { \
  685. REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_32); \
  686. isp1362_write_addr(d, (ISP1362_REG_##r) | ISP1362_REG_WRITE_OFFSET); \
  687. isp1362_write_data32(d, (u32)(v)); \
  688. RDBG("%s: Wrote %08x to %s[%02x]\n", __func__, (u32)(v), #r, \
  689. ISP1362_REG_NO(ISP1362_REG_##r)); \
  690. }
  691. #define isp1362_set_mask16(d, r, m) { \
  692. u16 __v; \
  693. __v = isp1362_read_reg16(d, r); \
  694. if ((__v | m) != __v) \
  695. isp1362_write_reg16(d, r, __v | m); \
  696. }
  697. #define isp1362_clr_mask16(d, r, m) { \
  698. u16 __v; \
  699. __v = isp1362_read_reg16(d, r); \
  700. if ((__v & ~m) != __v) \
  701. isp1362_write_reg16(d, r, __v & ~m); \
  702. }
  703. #define isp1362_set_mask32(d, r, m) { \
  704. u32 __v; \
  705. __v = isp1362_read_reg32(d, r); \
  706. if ((__v | m) != __v) \
  707. isp1362_write_reg32(d, r, __v | m); \
  708. }
  709. #define isp1362_clr_mask32(d, r, m) { \
  710. u32 __v; \
  711. __v = isp1362_read_reg32(d, r); \
  712. if ((__v & ~m) != __v) \
  713. isp1362_write_reg32(d, r, __v & ~m); \
  714. }
  715. #define isp1362_show_reg(d, r) { \
  716. if ((ISP1362_REG_##r & REG_WIDTH_MASK) == REG_WIDTH_32) \
  717. DBG(0, "%-12s[%02x]: %08x\n", #r, \
  718. ISP1362_REG_NO(ISP1362_REG_##r), isp1362_read_reg32(d, r)); \
  719. else \
  720. DBG(0, "%-12s[%02x]: %04x\n", #r, \
  721. ISP1362_REG_NO(ISP1362_REG_##r), isp1362_read_reg16(d, r)); \
  722. }
  723. static void __attribute__((__unused__)) isp1362_show_regs(struct isp1362_hcd *isp1362_hcd)
  724. {
  725. isp1362_show_reg(isp1362_hcd, HCREVISION);
  726. isp1362_show_reg(isp1362_hcd, HCCONTROL);
  727. isp1362_show_reg(isp1362_hcd, HCCMDSTAT);
  728. isp1362_show_reg(isp1362_hcd, HCINTSTAT);
  729. isp1362_show_reg(isp1362_hcd, HCINTENB);
  730. isp1362_show_reg(isp1362_hcd, HCFMINTVL);
  731. isp1362_show_reg(isp1362_hcd, HCFMREM);
  732. isp1362_show_reg(isp1362_hcd, HCFMNUM);
  733. isp1362_show_reg(isp1362_hcd, HCLSTHRESH);
  734. isp1362_show_reg(isp1362_hcd, HCRHDESCA);
  735. isp1362_show_reg(isp1362_hcd, HCRHDESCB);
  736. isp1362_show_reg(isp1362_hcd, HCRHSTATUS);
  737. isp1362_show_reg(isp1362_hcd, HCRHPORT1);
  738. isp1362_show_reg(isp1362_hcd, HCRHPORT2);
  739. isp1362_show_reg(isp1362_hcd, HCHWCFG);
  740. isp1362_show_reg(isp1362_hcd, HCDMACFG);
  741. isp1362_show_reg(isp1362_hcd, HCXFERCTR);
  742. isp1362_show_reg(isp1362_hcd, HCuPINT);
  743. if (in_interrupt())
  744. DBG(0, "%-12s[%02x]: %04x\n", "HCuPINTENB",
  745. ISP1362_REG_NO(ISP1362_REG_HCuPINTENB), isp1362_hcd->irqenb);
  746. else
  747. isp1362_show_reg(isp1362_hcd, HCuPINTENB);
  748. isp1362_show_reg(isp1362_hcd, HCCHIPID);
  749. isp1362_show_reg(isp1362_hcd, HCSCRATCH);
  750. isp1362_show_reg(isp1362_hcd, HCBUFSTAT);
  751. isp1362_show_reg(isp1362_hcd, HCDIRADDR);
  752. /* Access would advance fifo
  753. * isp1362_show_reg(isp1362_hcd, HCDIRDATA);
  754. */
  755. isp1362_show_reg(isp1362_hcd, HCISTLBUFSZ);
  756. isp1362_show_reg(isp1362_hcd, HCISTLRATE);
  757. isp1362_show_reg(isp1362_hcd, HCINTLBUFSZ);
  758. isp1362_show_reg(isp1362_hcd, HCINTLBLKSZ);
  759. isp1362_show_reg(isp1362_hcd, HCINTLDONE);
  760. isp1362_show_reg(isp1362_hcd, HCINTLSKIP);
  761. isp1362_show_reg(isp1362_hcd, HCINTLLAST);
  762. isp1362_show_reg(isp1362_hcd, HCINTLCURR);
  763. isp1362_show_reg(isp1362_hcd, HCATLBUFSZ);
  764. isp1362_show_reg(isp1362_hcd, HCATLBLKSZ);
  765. /* only valid after ATL_DONE interrupt
  766. * isp1362_show_reg(isp1362_hcd, HCATLDONE);
  767. */
  768. isp1362_show_reg(isp1362_hcd, HCATLSKIP);
  769. isp1362_show_reg(isp1362_hcd, HCATLLAST);
  770. isp1362_show_reg(isp1362_hcd, HCATLCURR);
  771. isp1362_show_reg(isp1362_hcd, HCATLDTC);
  772. isp1362_show_reg(isp1362_hcd, HCATLDTCTO);
  773. }
  774. static void isp1362_write_diraddr(struct isp1362_hcd *isp1362_hcd, u16 offset, u16 len)
  775. {
  776. len = (len + 1) & ~1;
  777. isp1362_clr_mask16(isp1362_hcd, HCDMACFG, HCDMACFG_CTR_ENABLE);
  778. isp1362_write_reg32(isp1362_hcd, HCDIRADDR,
  779. HCDIRADDR_ADDR(offset) | HCDIRADDR_COUNT(len));
  780. }
  781. static void isp1362_read_buffer(struct isp1362_hcd *isp1362_hcd, void *buf, u16 offset, int len)
  782. {
  783. isp1362_write_diraddr(isp1362_hcd, offset, len);
  784. DBG(3, "%s: Reading %d byte from buffer @%04x to memory @ %p\n",
  785. __func__, len, offset, buf);
  786. isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
  787. isp1362_write_addr(isp1362_hcd, ISP1362_REG_HCDIRDATA);
  788. isp1362_read_fifo(isp1362_hcd, buf, len);
  789. isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
  790. }
  791. static void isp1362_write_buffer(struct isp1362_hcd *isp1362_hcd, void *buf, u16 offset, int len)
  792. {
  793. isp1362_write_diraddr(isp1362_hcd, offset, len);
  794. DBG(3, "%s: Writing %d byte to buffer @%04x from memory @ %p\n",
  795. __func__, len, offset, buf);
  796. isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
  797. isp1362_write_addr(isp1362_hcd, ISP1362_REG_HCDIRDATA | ISP1362_REG_WRITE_OFFSET);
  798. isp1362_write_fifo(isp1362_hcd, buf, len);
  799. isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
  800. }
  801. static void __attribute__((unused)) dump_data(char *buf, int len)
  802. {
  803. if (dbg_level > 0) {
  804. int k;
  805. int lf = 0;
  806. for (k = 0; k < len; ++k) {
  807. if (!lf)
  808. DBG(0, "%04x:", k);
  809. printk(" %02x", ((u8 *) buf)[k]);
  810. lf = 1;
  811. if (!k)
  812. continue;
  813. if (k % 16 == 15) {
  814. printk("\n");
  815. lf = 0;
  816. continue;
  817. }
  818. if (k % 8 == 7)
  819. printk(" ");
  820. if (k % 4 == 3)
  821. printk(" ");
  822. }
  823. if (lf)
  824. printk("\n");
  825. }
  826. }
  827. #if defined(PTD_TRACE)
  828. static void dump_ptd(struct ptd *ptd)
  829. {
  830. DBG(0, "EP %p: CC=%x EP=%d DIR=%x CNT=%d LEN=%d MPS=%d TGL=%x ACT=%x FA=%d SPD=%x SF=%x PR=%x LST=%x\n",
  831. container_of(ptd, struct isp1362_ep, ptd),
  832. PTD_GET_CC(ptd), PTD_GET_EP(ptd), PTD_GET_DIR(ptd),
  833. PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd),
  834. PTD_GET_TOGGLE(ptd), PTD_GET_ACTIVE(ptd), PTD_GET_FA(ptd),
  835. PTD_GET_SPD(ptd), PTD_GET_SF_INT(ptd), PTD_GET_PR(ptd), PTD_GET_LAST(ptd));
  836. DBG(0, " %04x %04x %04x %04x\n", ptd->count, ptd->mps, ptd->len, ptd->faddr);
  837. }
  838. static void dump_ptd_out_data(struct ptd *ptd, u8 *buf)
  839. {
  840. if (dbg_level > 0) {
  841. if (PTD_GET_DIR(ptd) != PTD_DIR_IN && PTD_GET_LEN(ptd)) {
  842. DBG(0, "--out->\n");
  843. dump_data(buf, PTD_GET_LEN(ptd));
  844. }
  845. }
  846. }
  847. static void dump_ptd_in_data(struct ptd *ptd, u8 *buf)
  848. {
  849. if (dbg_level > 0) {
  850. if (PTD_GET_DIR(ptd) == PTD_DIR_IN && PTD_GET_COUNT(ptd)) {
  851. DBG(0, "<--in--\n");
  852. dump_data(buf, PTD_GET_COUNT(ptd));
  853. }
  854. DBG(0, "-----\n");
  855. }
  856. }
  857. static void dump_ptd_queue(struct isp1362_ep_queue *epq)
  858. {
  859. struct isp1362_ep *ep;
  860. int dbg = dbg_level;
  861. dbg_level = 1;
  862. list_for_each_entry(ep, &epq->active, active) {
  863. dump_ptd(&ep->ptd);
  864. dump_data(ep->data, ep->length);
  865. }
  866. dbg_level = dbg;
  867. }
  868. #else
  869. #define dump_ptd(ptd) do {} while (0)
  870. #define dump_ptd_in_data(ptd, buf) do {} while (0)
  871. #define dump_ptd_out_data(ptd, buf) do {} while (0)
  872. #define dump_ptd_data(ptd, buf) do {} while (0)
  873. #define dump_ptd_queue(epq) do {} while (0)
  874. #endif