musb_core.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /******************************************************************
  2. * Copyright 2008 Mentor Graphics Corporation
  3. * Copyright (C) 2008 by Texas Instruments
  4. *
  5. * This file is part of the Inventra Controller Driver for Linux.
  6. *
  7. * The Inventra Controller Driver for Linux is free software; you
  8. * can redistribute it and/or modify it under the terms of the GNU
  9. * General Public License version 2 as published by the Free Software
  10. * Foundation.
  11. *
  12. * The Inventra Controller Driver for Linux is distributed in
  13. * the hope that it will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  16. * License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with The Inventra Controller Driver for Linux ; if not,
  20. * write to the Free Software Foundation, Inc., 59 Temple Place,
  21. * Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. * ANY DOWNLOAD, USE, REPRODUCTION, MODIFICATION OR DISTRIBUTION
  24. * OF THIS DRIVER INDICATES YOUR COMPLETE AND UNCONDITIONAL ACCEPTANCE
  25. * OF THOSE TERMS.THIS DRIVER IS PROVIDED "AS IS" AND MENTOR GRAPHICS
  26. * MAKES NO WARRANTIES, EXPRESS OR IMPLIED, RELATED TO THIS DRIVER.
  27. * MENTOR GRAPHICS SPECIFICALLY DISCLAIMS ALL IMPLIED WARRANTIES
  28. * OF MERCHANTABILITY; FITNESS FOR A PARTICULAR PURPOSE AND
  29. * NON-INFRINGEMENT. MENTOR GRAPHICS DOES NOT PROVIDE SUPPORT
  30. * SERVICES OR UPDATES FOR THIS DRIVER, EVEN IF YOU ARE A MENTOR
  31. * GRAPHICS SUPPORT CUSTOMER.
  32. ******************************************************************/
  33. #ifndef __MUSB_HDRC_DEFS_H__
  34. #define __MUSB_HDRC_DEFS_H__
  35. #include <usb.h>
  36. #include <usb_defs.h>
  37. #include <asm/io.h>
  38. #ifdef CONFIG_USB_BLACKFIN
  39. # include "blackfin_usb.h"
  40. #endif
  41. #define MUSB_EP0_FIFOSIZE 64 /* This is non-configurable */
  42. /* EP0 */
  43. struct musb_ep0_regs {
  44. u16 reserved4;
  45. u16 csr0;
  46. u16 reserved5;
  47. u16 reserved6;
  48. u16 count0;
  49. u8 host_type0;
  50. u8 host_naklimit0;
  51. u8 reserved7;
  52. u8 reserved8;
  53. u8 reserved9;
  54. u8 configdata;
  55. };
  56. /* EP 1-15 */
  57. struct musb_epN_regs {
  58. u16 txmaxp;
  59. u16 txcsr;
  60. u16 rxmaxp;
  61. u16 rxcsr;
  62. u16 rxcount;
  63. u8 txtype;
  64. u8 txinterval;
  65. u8 rxtype;
  66. u8 rxinterval;
  67. u8 reserved0;
  68. u8 fifosize;
  69. };
  70. /* Mentor USB core register overlay structure */
  71. #ifndef musb_regs
  72. struct musb_regs {
  73. /* common registers */
  74. u8 faddr;
  75. u8 power;
  76. u16 intrtx;
  77. u16 intrrx;
  78. u16 intrtxe;
  79. u16 intrrxe;
  80. u8 intrusb;
  81. u8 intrusbe;
  82. u16 frame;
  83. u8 index;
  84. u8 testmode;
  85. /* indexed registers */
  86. u16 txmaxp;
  87. u16 txcsr;
  88. u16 rxmaxp;
  89. u16 rxcsr;
  90. u16 rxcount;
  91. u8 txtype;
  92. u8 txinterval;
  93. u8 rxtype;
  94. u8 rxinterval;
  95. u8 reserved0;
  96. u8 fifosize;
  97. /* fifo */
  98. u32 fifox[16];
  99. /* OTG, dynamic FIFO, version & vendor registers */
  100. u8 devctl;
  101. u8 reserved1;
  102. u8 txfifosz;
  103. u8 rxfifosz;
  104. u16 txfifoadd;
  105. u16 rxfifoadd;
  106. u32 vcontrol;
  107. u16 hwvers;
  108. u16 reserved2a[1];
  109. u8 ulpi_busctl;
  110. u8 reserved2b[1];
  111. u16 reserved2[3];
  112. u8 epinfo;
  113. u8 raminfo;
  114. u8 linkinfo;
  115. u8 vplen;
  116. u8 hseof1;
  117. u8 fseof1;
  118. u8 lseof1;
  119. u8 reserved3;
  120. /* target address registers */
  121. struct musb_tar_regs {
  122. u8 txfuncaddr;
  123. u8 reserved0;
  124. u8 txhubaddr;
  125. u8 txhubport;
  126. u8 rxfuncaddr;
  127. u8 reserved1;
  128. u8 rxhubaddr;
  129. u8 rxhubport;
  130. } tar[16];
  131. /*
  132. * endpoint registers
  133. * ep0 elements are valid when array index is 0
  134. * otherwise epN is valid
  135. */
  136. union musb_ep_regs {
  137. struct musb_ep0_regs ep0;
  138. struct musb_epN_regs epN;
  139. } ep[16];
  140. } __attribute__((packed, aligned(32)));
  141. #endif
  142. /*
  143. * MUSB Register bits
  144. */
  145. /* POWER */
  146. #define MUSB_POWER_ISOUPDATE 0x80
  147. #define MUSB_POWER_SOFTCONN 0x40
  148. #define MUSB_POWER_HSENAB 0x20
  149. #define MUSB_POWER_HSMODE 0x10
  150. #define MUSB_POWER_RESET 0x08
  151. #define MUSB_POWER_RESUME 0x04
  152. #define MUSB_POWER_SUSPENDM 0x02
  153. #define MUSB_POWER_ENSUSPEND 0x01
  154. #define MUSB_POWER_HSMODE_SHIFT 4
  155. /* INTRUSB */
  156. #define MUSB_INTR_SUSPEND 0x01
  157. #define MUSB_INTR_RESUME 0x02
  158. #define MUSB_INTR_RESET 0x04
  159. #define MUSB_INTR_BABBLE 0x04
  160. #define MUSB_INTR_SOF 0x08
  161. #define MUSB_INTR_CONNECT 0x10
  162. #define MUSB_INTR_DISCONNECT 0x20
  163. #define MUSB_INTR_SESSREQ 0x40
  164. #define MUSB_INTR_VBUSERROR 0x80 /* For SESSION end */
  165. /* DEVCTL */
  166. #define MUSB_DEVCTL_BDEVICE 0x80
  167. #define MUSB_DEVCTL_FSDEV 0x40
  168. #define MUSB_DEVCTL_LSDEV 0x20
  169. #define MUSB_DEVCTL_VBUS 0x18
  170. #define MUSB_DEVCTL_VBUS_SHIFT 3
  171. #define MUSB_DEVCTL_HM 0x04
  172. #define MUSB_DEVCTL_HR 0x02
  173. #define MUSB_DEVCTL_SESSION 0x01
  174. /* ULPI VBUSCONTROL */
  175. #define ULPI_USE_EXTVBUS 0x01
  176. #define ULPI_USE_EXTVBUSIND 0x02
  177. /* TESTMODE */
  178. #define MUSB_TEST_FORCE_HOST 0x80
  179. #define MUSB_TEST_FIFO_ACCESS 0x40
  180. #define MUSB_TEST_FORCE_FS 0x20
  181. #define MUSB_TEST_FORCE_HS 0x10
  182. #define MUSB_TEST_PACKET 0x08
  183. #define MUSB_TEST_K 0x04
  184. #define MUSB_TEST_J 0x02
  185. #define MUSB_TEST_SE0_NAK 0x01
  186. /* Allocate for double-packet buffering (effectively doubles assigned _SIZE) */
  187. #define MUSB_FIFOSZ_DPB 0x10
  188. /* Allocation size (8, 16, 32, ... 4096) */
  189. #define MUSB_FIFOSZ_SIZE 0x0f
  190. /* CSR0 */
  191. #define MUSB_CSR0_FLUSHFIFO 0x0100
  192. #define MUSB_CSR0_TXPKTRDY 0x0002
  193. #define MUSB_CSR0_RXPKTRDY 0x0001
  194. /* CSR0 in Peripheral mode */
  195. #define MUSB_CSR0_P_SVDSETUPEND 0x0080
  196. #define MUSB_CSR0_P_SVDRXPKTRDY 0x0040
  197. #define MUSB_CSR0_P_SENDSTALL 0x0020
  198. #define MUSB_CSR0_P_SETUPEND 0x0010
  199. #define MUSB_CSR0_P_DATAEND 0x0008
  200. #define MUSB_CSR0_P_SENTSTALL 0x0004
  201. /* CSR0 in Host mode */
  202. #define MUSB_CSR0_H_DIS_PING 0x0800
  203. #define MUSB_CSR0_H_WR_DATATOGGLE 0x0400 /* Set to allow setting: */
  204. #define MUSB_CSR0_H_DATATOGGLE 0x0200 /* Data toggle control */
  205. #define MUSB_CSR0_H_NAKTIMEOUT 0x0080
  206. #define MUSB_CSR0_H_STATUSPKT 0x0040
  207. #define MUSB_CSR0_H_REQPKT 0x0020
  208. #define MUSB_CSR0_H_ERROR 0x0010
  209. #define MUSB_CSR0_H_SETUPPKT 0x0008
  210. #define MUSB_CSR0_H_RXSTALL 0x0004
  211. /* CSR0 bits to avoid zeroing (write zero clears, write 1 ignored) */
  212. #define MUSB_CSR0_P_WZC_BITS \
  213. (MUSB_CSR0_P_SENTSTALL)
  214. #define MUSB_CSR0_H_WZC_BITS \
  215. (MUSB_CSR0_H_NAKTIMEOUT | MUSB_CSR0_H_RXSTALL \
  216. | MUSB_CSR0_RXPKTRDY)
  217. /* TxType/RxType */
  218. #define MUSB_TYPE_SPEED 0xc0
  219. #define MUSB_TYPE_SPEED_SHIFT 6
  220. #define MUSB_TYPE_SPEED_HIGH 1
  221. #define MUSB_TYPE_SPEED_FULL 2
  222. #define MUSB_TYPE_SPEED_LOW 3
  223. #define MUSB_TYPE_PROTO 0x30 /* Implicitly zero for ep0 */
  224. #define MUSB_TYPE_PROTO_SHIFT 4
  225. #define MUSB_TYPE_REMOTE_END 0xf /* Implicitly zero for ep0 */
  226. #define MUSB_TYPE_PROTO_BULK 2
  227. #define MUSB_TYPE_PROTO_INTR 3
  228. /* CONFIGDATA */
  229. #define MUSB_CONFIGDATA_MPRXE 0x80 /* Auto bulk pkt combining */
  230. #define MUSB_CONFIGDATA_MPTXE 0x40 /* Auto bulk pkt splitting */
  231. #define MUSB_CONFIGDATA_BIGENDIAN 0x20
  232. #define MUSB_CONFIGDATA_HBRXE 0x10 /* HB-ISO for RX */
  233. #define MUSB_CONFIGDATA_HBTXE 0x08 /* HB-ISO for TX */
  234. #define MUSB_CONFIGDATA_DYNFIFO 0x04 /* Dynamic FIFO sizing */
  235. #define MUSB_CONFIGDATA_SOFTCONE 0x02 /* SoftConnect */
  236. #define MUSB_CONFIGDATA_UTMIDW 0x01 /* Data width 0/1 => 8/16bits */
  237. /* TXCSR in Peripheral and Host mode */
  238. #define MUSB_TXCSR_AUTOSET 0x8000
  239. #define MUSB_TXCSR_MODE 0x2000
  240. #define MUSB_TXCSR_DMAENAB 0x1000
  241. #define MUSB_TXCSR_FRCDATATOG 0x0800
  242. #define MUSB_TXCSR_DMAMODE 0x0400
  243. #define MUSB_TXCSR_CLRDATATOG 0x0040
  244. #define MUSB_TXCSR_FLUSHFIFO 0x0008
  245. #define MUSB_TXCSR_FIFONOTEMPTY 0x0002
  246. #define MUSB_TXCSR_TXPKTRDY 0x0001
  247. /* TXCSR in Peripheral mode */
  248. #define MUSB_TXCSR_P_ISO 0x4000
  249. #define MUSB_TXCSR_P_INCOMPTX 0x0080
  250. #define MUSB_TXCSR_P_SENTSTALL 0x0020
  251. #define MUSB_TXCSR_P_SENDSTALL 0x0010
  252. #define MUSB_TXCSR_P_UNDERRUN 0x0004
  253. /* TXCSR in Host mode */
  254. #define MUSB_TXCSR_H_WR_DATATOGGLE 0x0200
  255. #define MUSB_TXCSR_H_DATATOGGLE 0x0100
  256. #define MUSB_TXCSR_H_NAKTIMEOUT 0x0080
  257. #define MUSB_TXCSR_H_RXSTALL 0x0020
  258. #define MUSB_TXCSR_H_ERROR 0x0004
  259. #define MUSB_TXCSR_H_DATATOGGLE_SHIFT 8
  260. /* TXCSR bits to avoid zeroing (write zero clears, write 1 ignored) */
  261. #define MUSB_TXCSR_P_WZC_BITS \
  262. (MUSB_TXCSR_P_INCOMPTX | MUSB_TXCSR_P_SENTSTALL \
  263. | MUSB_TXCSR_P_UNDERRUN | MUSB_TXCSR_FIFONOTEMPTY)
  264. #define MUSB_TXCSR_H_WZC_BITS \
  265. (MUSB_TXCSR_H_NAKTIMEOUT | MUSB_TXCSR_H_RXSTALL \
  266. | MUSB_TXCSR_H_ERROR | MUSB_TXCSR_FIFONOTEMPTY)
  267. /* RXCSR in Peripheral and Host mode */
  268. #define MUSB_RXCSR_AUTOCLEAR 0x8000
  269. #define MUSB_RXCSR_DMAENAB 0x2000
  270. #define MUSB_RXCSR_DISNYET 0x1000
  271. #define MUSB_RXCSR_PID_ERR 0x1000
  272. #define MUSB_RXCSR_DMAMODE 0x0800
  273. #define MUSB_RXCSR_INCOMPRX 0x0100
  274. #define MUSB_RXCSR_CLRDATATOG 0x0080
  275. #define MUSB_RXCSR_FLUSHFIFO 0x0010
  276. #define MUSB_RXCSR_DATAERROR 0x0008
  277. #define MUSB_RXCSR_FIFOFULL 0x0002
  278. #define MUSB_RXCSR_RXPKTRDY 0x0001
  279. /* RXCSR in Peripheral mode */
  280. #define MUSB_RXCSR_P_ISO 0x4000
  281. #define MUSB_RXCSR_P_SENTSTALL 0x0040
  282. #define MUSB_RXCSR_P_SENDSTALL 0x0020
  283. #define MUSB_RXCSR_P_OVERRUN 0x0004
  284. /* RXCSR in Host mode */
  285. #define MUSB_RXCSR_H_AUTOREQ 0x4000
  286. #define MUSB_RXCSR_H_WR_DATATOGGLE 0x0400
  287. #define MUSB_RXCSR_H_DATATOGGLE 0x0200
  288. #define MUSB_RXCSR_H_RXSTALL 0x0040
  289. #define MUSB_RXCSR_H_REQPKT 0x0020
  290. #define MUSB_RXCSR_H_ERROR 0x0004
  291. #define MUSB_S_RXCSR_H_DATATOGGLE 9
  292. /* RXCSR bits to avoid zeroing (write zero clears, write 1 ignored) */
  293. #define MUSB_RXCSR_P_WZC_BITS \
  294. (MUSB_RXCSR_P_SENTSTALL | MUSB_RXCSR_P_OVERRUN \
  295. | MUSB_RXCSR_RXPKTRDY)
  296. #define MUSB_RXCSR_H_WZC_BITS \
  297. (MUSB_RXCSR_H_RXSTALL | MUSB_RXCSR_H_ERROR \
  298. | MUSB_RXCSR_DATAERROR | MUSB_RXCSR_RXPKTRDY)
  299. /* HUBADDR */
  300. #define MUSB_HUBADDR_MULTI_TT 0x80
  301. /* Endpoint configuration information. Note: The value of endpoint fifo size
  302. * element should be either 8,16,32,64,128,256,512,1024,2048 or 4096. Other
  303. * values are not supported
  304. */
  305. struct musb_epinfo {
  306. u8 epnum; /* endpoint number */
  307. u8 epdir; /* endpoint direction */
  308. u16 epsize; /* endpoint FIFO size */
  309. };
  310. /*
  311. * Platform specific MUSB configuration. Any platform using the musb
  312. * functionality should create one instance of this structure in the
  313. * platform specific file.
  314. */
  315. struct musb_config {
  316. struct musb_regs *regs;
  317. u32 timeout;
  318. u8 musb_speed;
  319. u8 extvbus;
  320. };
  321. /* externally defined data */
  322. extern struct musb_config musb_cfg;
  323. extern struct musb_regs *musbr;
  324. /* exported functions */
  325. extern void musb_start(void);
  326. extern void musb_configure_ep(const struct musb_epinfo *epinfo, u8 cnt);
  327. extern void write_fifo(u8 ep, u32 length, void *fifo_data);
  328. extern void read_fifo(u8 ep, u32 length, void *fifo_data);
  329. #if defined(CONFIG_USB_BLACKFIN)
  330. /* Every USB register is accessed as a 16-bit even if the value itself
  331. * is only 8-bits in size. Fun stuff.
  332. */
  333. # undef readb
  334. # define readb(addr) (u8)bfin_read16(addr)
  335. # undef writeb
  336. # define writeb(b, addr) bfin_write16(addr, b)
  337. # undef MUSB_TXCSR_MODE /* not supported */
  338. # define MUSB_TXCSR_MODE 0
  339. /*
  340. * The USB PHY on current Blackfin processors is a UTMI+ level 2 PHY.
  341. * However, it has no ULPI support - so there are no registers at all.
  342. * That means accesses to ULPI_BUSCONTROL have to be abstracted away.
  343. */
  344. static inline u8 musb_read_ulpi_buscontrol(struct musb_regs *musbr)
  345. {
  346. return 0;
  347. }
  348. static inline void musb_write_ulpi_buscontrol(struct musb_regs *musbr, u8 val)
  349. {}
  350. #else
  351. static inline u8 musb_read_ulpi_buscontrol(struct musb_regs *musbr)
  352. {
  353. return readb(&musbr->ulpi_busctl);
  354. }
  355. static inline void musb_write_ulpi_buscontrol(struct musb_regs *musbr, u8 val)
  356. {
  357. writeb(val, &musbr->ulpi_busctl);
  358. }
  359. #endif
  360. #endif /* __MUSB_HDRC_DEFS_H__ */