isp1362.h 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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. #ifdef ISP1362_DEBUG
  61. typedef const unsigned int isp1362_reg_t;
  62. #define REG_WIDTH_16 0x000
  63. #define REG_WIDTH_32 0x100
  64. #define REG_WIDTH_MASK 0x100
  65. #define REG_NO_MASK 0x0ff
  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 proc_dir_entry *pde;
  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. #ifdef ISP1362_DEBUG
  501. #define DBG(level, fmt...) \
  502. do { \
  503. if (dbg_level > level) \
  504. pr_debug(fmt); \
  505. } while (0)
  506. #define _DBG(level, fmt...) \
  507. do { \
  508. if (dbg_level > level) \
  509. printk(fmt); \
  510. } while (0)
  511. #else
  512. #define DBG(fmt...) do {} while (0)
  513. #define _DBG DBG
  514. #endif
  515. #ifdef VERBOSE
  516. # define VDBG(fmt...) DBG(3, fmt)
  517. #else
  518. # define VDBG(fmt...) do {} while (0)
  519. #endif
  520. #ifdef REGISTERS
  521. # define RDBG(fmt...) DBG(1, fmt)
  522. #else
  523. # define RDBG(fmt...) do {} while (0)
  524. #endif
  525. #ifdef URB_TRACE
  526. #define URB_DBG(fmt...) DBG(0, fmt)
  527. #else
  528. #define URB_DBG(fmt...) do {} while (0)
  529. #endif
  530. #if USE_PLATFORM_DELAY
  531. #if USE_NDELAY
  532. #error USE_PLATFORM_DELAY and USE_NDELAY defined simultaneously.
  533. #endif
  534. #define isp1362_delay(h, d) (h)->board->delay(isp1362_hcd_to_hcd(h)->self.controller, d)
  535. #elif USE_NDELAY
  536. #define isp1362_delay(h, d) ndelay(d)
  537. #else
  538. #define isp1362_delay(h, d) do {} while (0)
  539. #endif
  540. #define get_urb(ep) ({ \
  541. BUG_ON(list_empty(&ep->hep->urb_list)); \
  542. container_of(ep->hep->urb_list.next, struct urb, urb_list); \
  543. })
  544. /* basic access functions for ISP1362 chip registers */
  545. /* NOTE: The contents of the address pointer register cannot be read back! The driver must ensure,
  546. * that all register accesses are performed with interrupts disabled, since the interrupt
  547. * handler has no way of restoring the previous state.
  548. */
  549. static void isp1362_write_addr(struct isp1362_hcd *isp1362_hcd, isp1362_reg_t reg)
  550. {
  551. REG_ACCESS_TEST(reg);
  552. DUMMY_DELAY_ACCESS;
  553. writew(ISP1362_REG_NO(reg), isp1362_hcd->addr_reg);
  554. DUMMY_DELAY_ACCESS;
  555. isp1362_delay(isp1362_hcd, 1);
  556. }
  557. static void isp1362_write_data16(struct isp1362_hcd *isp1362_hcd, u16 val)
  558. {
  559. DUMMY_DELAY_ACCESS;
  560. writew(val, isp1362_hcd->data_reg);
  561. }
  562. static u16 isp1362_read_data16(struct isp1362_hcd *isp1362_hcd)
  563. {
  564. u16 val;
  565. DUMMY_DELAY_ACCESS;
  566. val = readw(isp1362_hcd->data_reg);
  567. return val;
  568. }
  569. static void isp1362_write_data32(struct isp1362_hcd *isp1362_hcd, u32 val)
  570. {
  571. #if USE_32BIT
  572. DUMMY_DELAY_ACCESS;
  573. writel(val, isp1362_hcd->data_reg);
  574. #else
  575. DUMMY_DELAY_ACCESS;
  576. writew((u16)val, isp1362_hcd->data_reg);
  577. DUMMY_DELAY_ACCESS;
  578. writew(val >> 16, isp1362_hcd->data_reg);
  579. #endif
  580. }
  581. static u32 isp1362_read_data32(struct isp1362_hcd *isp1362_hcd)
  582. {
  583. u32 val;
  584. #if USE_32BIT
  585. DUMMY_DELAY_ACCESS;
  586. val = readl(isp1362_hcd->data_reg);
  587. #else
  588. DUMMY_DELAY_ACCESS;
  589. val = (u32)readw(isp1362_hcd->data_reg);
  590. DUMMY_DELAY_ACCESS;
  591. val |= (u32)readw(isp1362_hcd->data_reg) << 16;
  592. #endif
  593. return val;
  594. }
  595. /* use readsw/writesw to access the fifo whenever possible */
  596. /* assume HCDIRDATA or XFERCTR & addr_reg have been set up */
  597. static void isp1362_read_fifo(struct isp1362_hcd *isp1362_hcd, void *buf, u16 len)
  598. {
  599. u8 *dp = buf;
  600. u16 data;
  601. if (!len)
  602. return;
  603. RDBG("%s: Reading %d byte from fifo to mem @ %p\n", __func__, len, buf);
  604. #if USE_32BIT
  605. if (len >= 4) {
  606. RDBG("%s: Using readsl for %d dwords\n", __func__, len >> 2);
  607. readsl(isp1362_hcd->data_reg, dp, len >> 2);
  608. dp += len & ~3;
  609. len &= 3;
  610. }
  611. #endif
  612. if (len >= 2) {
  613. RDBG("%s: Using readsw for %d words\n", __func__, len >> 1);
  614. insw((unsigned long)isp1362_hcd->data_reg, dp, len >> 1);
  615. dp += len & ~1;
  616. len &= 1;
  617. }
  618. BUG_ON(len & ~1);
  619. if (len > 0) {
  620. data = isp1362_read_data16(isp1362_hcd);
  621. RDBG("%s: Reading trailing byte %02x to mem @ %08x\n", __func__,
  622. (u8)data, (u32)dp);
  623. *dp = (u8)data;
  624. }
  625. }
  626. static void isp1362_write_fifo(struct isp1362_hcd *isp1362_hcd, void *buf, u16 len)
  627. {
  628. u8 *dp = buf;
  629. u16 data;
  630. if (!len)
  631. return;
  632. if ((unsigned long)dp & 0x1) {
  633. /* not aligned */
  634. for (; len > 1; len -= 2) {
  635. data = *dp++;
  636. data |= *dp++ << 8;
  637. isp1362_write_data16(isp1362_hcd, data);
  638. }
  639. if (len)
  640. isp1362_write_data16(isp1362_hcd, *dp);
  641. return;
  642. }
  643. RDBG("%s: Writing %d byte to fifo from memory @%p\n", __func__, len, buf);
  644. #if USE_32BIT
  645. if (len >= 4) {
  646. RDBG("%s: Using writesl for %d dwords\n", __func__, len >> 2);
  647. writesl(isp1362_hcd->data_reg, dp, len >> 2);
  648. dp += len & ~3;
  649. len &= 3;
  650. }
  651. #endif
  652. if (len >= 2) {
  653. RDBG("%s: Using writesw for %d words\n", __func__, len >> 1);
  654. outsw((unsigned long)isp1362_hcd->data_reg, dp, len >> 1);
  655. dp += len & ~1;
  656. len &= 1;
  657. }
  658. BUG_ON(len & ~1);
  659. if (len > 0) {
  660. /* finally write any trailing byte; we don't need to care
  661. * about the high byte of the last word written
  662. */
  663. data = (u16)*dp;
  664. RDBG("%s: Sending trailing byte %02x from mem @ %08x\n", __func__,
  665. data, (u32)dp);
  666. isp1362_write_data16(isp1362_hcd, data);
  667. }
  668. }
  669. #define isp1362_read_reg16(d, r) ({ \
  670. u16 __v; \
  671. REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_16); \
  672. isp1362_write_addr(d, ISP1362_REG_##r); \
  673. __v = isp1362_read_data16(d); \
  674. RDBG("%s: Read %04x from %s[%02x]\n", __func__, __v, #r, \
  675. ISP1362_REG_NO(ISP1362_REG_##r)); \
  676. __v; \
  677. })
  678. #define isp1362_read_reg32(d, r) ({ \
  679. u32 __v; \
  680. REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_32); \
  681. isp1362_write_addr(d, ISP1362_REG_##r); \
  682. __v = isp1362_read_data32(d); \
  683. RDBG("%s: Read %08x from %s[%02x]\n", __func__, __v, #r, \
  684. ISP1362_REG_NO(ISP1362_REG_##r)); \
  685. __v; \
  686. })
  687. #define isp1362_write_reg16(d, r, v) { \
  688. REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_16); \
  689. isp1362_write_addr(d, (ISP1362_REG_##r) | ISP1362_REG_WRITE_OFFSET); \
  690. isp1362_write_data16(d, (u16)(v)); \
  691. RDBG("%s: Wrote %04x to %s[%02x]\n", __func__, (u16)(v), #r, \
  692. ISP1362_REG_NO(ISP1362_REG_##r)); \
  693. }
  694. #define isp1362_write_reg32(d, r, v) { \
  695. REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_32); \
  696. isp1362_write_addr(d, (ISP1362_REG_##r) | ISP1362_REG_WRITE_OFFSET); \
  697. isp1362_write_data32(d, (u32)(v)); \
  698. RDBG("%s: Wrote %08x to %s[%02x]\n", __func__, (u32)(v), #r, \
  699. ISP1362_REG_NO(ISP1362_REG_##r)); \
  700. }
  701. #define isp1362_set_mask16(d, r, m) { \
  702. u16 __v; \
  703. __v = isp1362_read_reg16(d, r); \
  704. if ((__v | m) != __v) \
  705. isp1362_write_reg16(d, r, __v | m); \
  706. }
  707. #define isp1362_clr_mask16(d, r, m) { \
  708. u16 __v; \
  709. __v = isp1362_read_reg16(d, r); \
  710. if ((__v & ~m) != __v) \
  711. isp1362_write_reg16(d, r, __v & ~m); \
  712. }
  713. #define isp1362_set_mask32(d, r, m) { \
  714. u32 __v; \
  715. __v = isp1362_read_reg32(d, r); \
  716. if ((__v | m) != __v) \
  717. isp1362_write_reg32(d, r, __v | m); \
  718. }
  719. #define isp1362_clr_mask32(d, r, m) { \
  720. u32 __v; \
  721. __v = isp1362_read_reg32(d, r); \
  722. if ((__v & ~m) != __v) \
  723. isp1362_write_reg32(d, r, __v & ~m); \
  724. }
  725. #ifdef ISP1362_DEBUG
  726. #define isp1362_show_reg(d, r) { \
  727. if ((ISP1362_REG_##r & REG_WIDTH_MASK) == REG_WIDTH_32) \
  728. DBG(0, "%-12s[%02x]: %08x\n", #r, \
  729. ISP1362_REG_NO(ISP1362_REG_##r), isp1362_read_reg32(d, r)); \
  730. else \
  731. DBG(0, "%-12s[%02x]: %04x\n", #r, \
  732. ISP1362_REG_NO(ISP1362_REG_##r), isp1362_read_reg16(d, r)); \
  733. }
  734. #else
  735. #define isp1362_show_reg(d, r) do {} while (0)
  736. #endif
  737. static void __attribute__((__unused__)) isp1362_show_regs(struct isp1362_hcd *isp1362_hcd)
  738. {
  739. isp1362_show_reg(isp1362_hcd, HCREVISION);
  740. isp1362_show_reg(isp1362_hcd, HCCONTROL);
  741. isp1362_show_reg(isp1362_hcd, HCCMDSTAT);
  742. isp1362_show_reg(isp1362_hcd, HCINTSTAT);
  743. isp1362_show_reg(isp1362_hcd, HCINTENB);
  744. isp1362_show_reg(isp1362_hcd, HCFMINTVL);
  745. isp1362_show_reg(isp1362_hcd, HCFMREM);
  746. isp1362_show_reg(isp1362_hcd, HCFMNUM);
  747. isp1362_show_reg(isp1362_hcd, HCLSTHRESH);
  748. isp1362_show_reg(isp1362_hcd, HCRHDESCA);
  749. isp1362_show_reg(isp1362_hcd, HCRHDESCB);
  750. isp1362_show_reg(isp1362_hcd, HCRHSTATUS);
  751. isp1362_show_reg(isp1362_hcd, HCRHPORT1);
  752. isp1362_show_reg(isp1362_hcd, HCRHPORT2);
  753. isp1362_show_reg(isp1362_hcd, HCHWCFG);
  754. isp1362_show_reg(isp1362_hcd, HCDMACFG);
  755. isp1362_show_reg(isp1362_hcd, HCXFERCTR);
  756. isp1362_show_reg(isp1362_hcd, HCuPINT);
  757. if (in_interrupt())
  758. DBG(0, "%-12s[%02x]: %04x\n", "HCuPINTENB",
  759. ISP1362_REG_NO(ISP1362_REG_HCuPINTENB), isp1362_hcd->irqenb);
  760. else
  761. isp1362_show_reg(isp1362_hcd, HCuPINTENB);
  762. isp1362_show_reg(isp1362_hcd, HCCHIPID);
  763. isp1362_show_reg(isp1362_hcd, HCSCRATCH);
  764. isp1362_show_reg(isp1362_hcd, HCBUFSTAT);
  765. isp1362_show_reg(isp1362_hcd, HCDIRADDR);
  766. /* Access would advance fifo
  767. * isp1362_show_reg(isp1362_hcd, HCDIRDATA);
  768. */
  769. isp1362_show_reg(isp1362_hcd, HCISTLBUFSZ);
  770. isp1362_show_reg(isp1362_hcd, HCISTLRATE);
  771. isp1362_show_reg(isp1362_hcd, HCINTLBUFSZ);
  772. isp1362_show_reg(isp1362_hcd, HCINTLBLKSZ);
  773. isp1362_show_reg(isp1362_hcd, HCINTLDONE);
  774. isp1362_show_reg(isp1362_hcd, HCINTLSKIP);
  775. isp1362_show_reg(isp1362_hcd, HCINTLLAST);
  776. isp1362_show_reg(isp1362_hcd, HCINTLCURR);
  777. isp1362_show_reg(isp1362_hcd, HCATLBUFSZ);
  778. isp1362_show_reg(isp1362_hcd, HCATLBLKSZ);
  779. /* only valid after ATL_DONE interrupt
  780. * isp1362_show_reg(isp1362_hcd, HCATLDONE);
  781. */
  782. isp1362_show_reg(isp1362_hcd, HCATLSKIP);
  783. isp1362_show_reg(isp1362_hcd, HCATLLAST);
  784. isp1362_show_reg(isp1362_hcd, HCATLCURR);
  785. isp1362_show_reg(isp1362_hcd, HCATLDTC);
  786. isp1362_show_reg(isp1362_hcd, HCATLDTCTO);
  787. }
  788. static void isp1362_write_diraddr(struct isp1362_hcd *isp1362_hcd, u16 offset, u16 len)
  789. {
  790. len = (len + 1) & ~1;
  791. isp1362_clr_mask16(isp1362_hcd, HCDMACFG, HCDMACFG_CTR_ENABLE);
  792. isp1362_write_reg32(isp1362_hcd, HCDIRADDR,
  793. HCDIRADDR_ADDR(offset) | HCDIRADDR_COUNT(len));
  794. }
  795. static void isp1362_read_buffer(struct isp1362_hcd *isp1362_hcd, void *buf, u16 offset, int len)
  796. {
  797. isp1362_write_diraddr(isp1362_hcd, offset, len);
  798. DBG(3, "%s: Reading %d byte from buffer @%04x to memory @ %p\n",
  799. __func__, len, offset, buf);
  800. isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
  801. isp1362_write_addr(isp1362_hcd, ISP1362_REG_HCDIRDATA);
  802. isp1362_read_fifo(isp1362_hcd, buf, len);
  803. isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
  804. }
  805. static void isp1362_write_buffer(struct isp1362_hcd *isp1362_hcd, void *buf, u16 offset, int len)
  806. {
  807. isp1362_write_diraddr(isp1362_hcd, offset, len);
  808. DBG(3, "%s: Writing %d byte to buffer @%04x from memory @ %p\n",
  809. __func__, len, offset, buf);
  810. isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
  811. isp1362_write_addr(isp1362_hcd, ISP1362_REG_HCDIRDATA | ISP1362_REG_WRITE_OFFSET);
  812. isp1362_write_fifo(isp1362_hcd, buf, len);
  813. isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
  814. }
  815. static void __attribute__((unused)) dump_data(char *buf, int len)
  816. {
  817. if (dbg_level > 0) {
  818. int k;
  819. int lf = 0;
  820. for (k = 0; k < len; ++k) {
  821. if (!lf)
  822. DBG(0, "%04x:", k);
  823. printk(" %02x", ((u8 *) buf)[k]);
  824. lf = 1;
  825. if (!k)
  826. continue;
  827. if (k % 16 == 15) {
  828. printk("\n");
  829. lf = 0;
  830. continue;
  831. }
  832. if (k % 8 == 7)
  833. printk(" ");
  834. if (k % 4 == 3)
  835. printk(" ");
  836. }
  837. if (lf)
  838. printk("\n");
  839. }
  840. }
  841. #if defined(ISP1362_DEBUG) && defined(PTD_TRACE)
  842. static void dump_ptd(struct ptd *ptd)
  843. {
  844. 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",
  845. container_of(ptd, struct isp1362_ep, ptd),
  846. PTD_GET_CC(ptd), PTD_GET_EP(ptd), PTD_GET_DIR(ptd),
  847. PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd),
  848. PTD_GET_TOGGLE(ptd), PTD_GET_ACTIVE(ptd), PTD_GET_FA(ptd),
  849. PTD_GET_SPD(ptd), PTD_GET_SF_INT(ptd), PTD_GET_PR(ptd), PTD_GET_LAST(ptd));
  850. DBG(0, " %04x %04x %04x %04x\n", ptd->count, ptd->mps, ptd->len, ptd->faddr);
  851. }
  852. static void dump_ptd_out_data(struct ptd *ptd, u8 *buf)
  853. {
  854. if (dbg_level > 0) {
  855. if (PTD_GET_DIR(ptd) != PTD_DIR_IN && PTD_GET_LEN(ptd)) {
  856. DBG(0, "--out->\n");
  857. dump_data(buf, PTD_GET_LEN(ptd));
  858. }
  859. }
  860. }
  861. static void dump_ptd_in_data(struct ptd *ptd, u8 *buf)
  862. {
  863. if (dbg_level > 0) {
  864. if (PTD_GET_DIR(ptd) == PTD_DIR_IN && PTD_GET_COUNT(ptd)) {
  865. DBG(0, "<--in--\n");
  866. dump_data(buf, PTD_GET_COUNT(ptd));
  867. }
  868. DBG(0, "-----\n");
  869. }
  870. }
  871. static void dump_ptd_queue(struct isp1362_ep_queue *epq)
  872. {
  873. struct isp1362_ep *ep;
  874. int dbg = dbg_level;
  875. dbg_level = 1;
  876. list_for_each_entry(ep, &epq->active, active) {
  877. dump_ptd(&ep->ptd);
  878. dump_data(ep->data, ep->length);
  879. }
  880. dbg_level = dbg;
  881. }
  882. #else
  883. #define dump_ptd(ptd) do {} while (0)
  884. #define dump_ptd_in_data(ptd, buf) do {} while (0)
  885. #define dump_ptd_out_data(ptd, buf) do {} while (0)
  886. #define dump_ptd_data(ptd, buf) do {} while (0)
  887. #define dump_ptd_queue(epq) do {} while (0)
  888. #endif