isp1362.h 32 KB

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