mt_musb.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*
  2. * Copyright (c) 2013 MediaTek Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #ifndef _MT6739_USB_H_
  24. #define _MT6739_USB_H_
  25. #include <dev/udc.h>
  26. #include <platform/mt_typedefs.h>
  27. #include <platform/mt_gpt.h>
  28. #include <platform/mt_irq.h>
  29. /*
  30. * MTK_MUSB now set QMU as default enabled.
  31. * Old platforms please set MTK_MUSB_NOT_SUPPORT_QMU in rules.mk.
  32. */
  33. #if !defined(MTK_MUSB_NOT_SUPPORT_QMU)
  34. #define SUPPORT_QMU
  35. #endif
  36. /* USB PHY registers */
  37. #define USB20_PHY_BASE (USBSIF_BASE + 0x0800)
  38. #define USB11_PHY_BASE (USBSIF_BASE + 0x0900)
  39. /* hardware spec */
  40. #define MT_EP_NUM 4
  41. #define MT_CHAN_NUM 4
  42. #define MT_EP0_FIFOSIZE 64
  43. #define FIFO_ADDR_START 512
  44. #define MT_BULK_MAXP 512
  45. #define MT_INT_MAXP 1024
  46. /* USB common registers */
  47. #define FADDR (USB_BASE + 0x0000) /* Function Address Register */
  48. #define POWER (USB_BASE + 0x0001) /* Power Management Register */
  49. #define INTRTX (USB_BASE + 0x0002) /* TX Interrupt Status Register */
  50. #define INTRRX (USB_BASE + 0x0004) /* RX Interrupt Status Register */
  51. #define INTRTXE (USB_BASE + 0x0006) /* TX Interrupt Status Enable Register */
  52. #define INTRRXE (USB_BASE + 0x0008) /* RX Interrupt Status Enable Register */
  53. #define INTRUSB (USB_BASE + 0x000a) /* Common USB Interrupt Register */
  54. #define INTRUSBE (USB_BASE + 0x000b) /* Common USB Interrupt Enable Register */
  55. #define FRAME (USB_BASE + 0x000c) /* Frame Number Register */
  56. #define INDEX (USB_BASE + 0x000e) /* Endpoint Selecting Index Register */
  57. #define TESTMODE (USB_BASE + 0x000f) /* Test Mode Enable Register */
  58. /* Toggle registers */
  59. #define RXTOG (USB_BASE + 0x0080)
  60. #define RXTOGEN (USB_BASE + 0x0082)
  61. #define TXTOG (USB_BASE + 0x0084)
  62. #define TXTOGEN (USB_BASE + 0x0086)
  63. /* POWER fields */
  64. #define PWR_ISO_UPDATE (1<<7)
  65. #define PWR_SOFT_CONN (1<<6)
  66. #define PWR_HS_ENAB (1<<5)
  67. #define PWR_HS_MODE (1<<4)
  68. #define PWR_RESET (1<<3)
  69. #define PWR_RESUME (1<<2)
  70. #define PWR_SUSPEND_MODE (1<<1)
  71. #define PWR_ENABLE_SUSPENDM (1<<0)
  72. /* INTRUSB fields */
  73. #define INTRUSB_VBUS_ERROR (1<<7)
  74. #define INTRUSB_SESS_REQ (1<<6)
  75. #define INTRUSB_DISCON (1<<5)
  76. #define INTRUSB_CONN (1<<4)
  77. #define INTRUSB_SOF (1<<3)
  78. #define INTRUSB_RESET (1<<2)
  79. #define INTRUSB_RESUME (1<<1)
  80. #define INTRUSB_SUSPEND (1<<0)
  81. /* DMA control registers */
  82. #define USB_DMA_INTR (USB_BASE + 0x0200)
  83. #define USB_DMA_INTR_UNMASK_SET_OFFSET (24)
  84. #define USB_DMA_CNTL(chan) (USB_BASE + 0x0204 + 0x10*(chan-1))
  85. #define USB_DMA_ADDR(chan) (USB_BASE + 0x0208 + 0x10*(chan-1))
  86. #define USB_DMA_COUNT(chan) (USB_BASE + 0x020c + 0x10*(chan-1))
  87. /* Endpoint Control/Status Registers */
  88. #define IECSR (USB_BASE + 0x0010)
  89. /* for EP0 */
  90. #define CSR0 0x2 /* EP0 Control Status Register */
  91. /* For Host Mode, it would be 0x2 */
  92. #define COUNT0 0x8 /* EP0 Received Bytes Register */
  93. #define NAKLIMIT0 0xB /* NAK Limit Register */
  94. #define CONFIGDATA 0xF /* Core Configuration Register */
  95. /* for other endpoints */
  96. #define TXMAP 0x0 /* TXMAP Register: Max Packet Size for TX */
  97. #define TXCSR 0x2 /* TXCSR Register: TX Control Status Register */
  98. #define RXMAP 0x4 /* RXMAP Register: Max Packet Size for RX */
  99. #define RXCSR 0x6 /* RXCSR Register: RX Control Status Register */
  100. #define RXCOUNT 0x8 /* RXCOUNT Register */
  101. #define TXTYPE 0xa /* TX Type Register */
  102. #define TXINTERVAL 0xb /* TX Interval Register */
  103. #define RXTYPE 0xc /* RX Type Register */
  104. #define RXINTERVAL 0xd /* RX Interval Register */
  105. #define FIFOSIZE 0xf /* configured FIFO size register */
  106. /* control status register fields */
  107. /* CSR0_DEV */
  108. #define EP0_FLUSH_FIFO (1<<8)
  109. #define EP0_SERVICE_SETUP_END (1<<7)
  110. #define EP0_SERVICED_RXPKTRDY (1<<6)
  111. #define EP0_SENDSTALL (1<<5)
  112. #define EP0_SETUPEND (1<<4)
  113. #define EP0_DATAEND (1<<3)
  114. #define EP0_SENTSTALL (1<<2)
  115. #define EP0_TXPKTRDY (1<<1)
  116. #define EP0_RXPKTRDY (1<<0)
  117. /* TXCSR_DEV */
  118. #define EPX_TX_AUTOSET (1<<15)
  119. #define EPX_TX_ISO (1<<14)
  120. #define EPX_TX_MODE (1<<13)
  121. #define EPX_TX_DMAREQEN (1<<12)
  122. #define EPX_TX_FRCDATATOG (1<<11)
  123. #define EPX_TX_DMAREQMODE (1<<10)
  124. #define EPX_TX_AUTOSETEN_SPKT (1<<9)
  125. #define EPX_TX_INCOMPTX (1<<7)
  126. #define EPX_TX_CLRDATATOG (1<<6)
  127. #define EPX_TX_SENTSTALL (1<<5)
  128. #define EPX_TX_SENDSTALL (1<<4)
  129. #define EPX_TX_FLUSHFIFO (1<<3)
  130. #define EPX_TX_UNDERRUN (1<<2)
  131. #define EPX_TX_FIFONOTEMPTY (1<<1)
  132. #define EPX_TX_TXPKTRDY (1<<0)
  133. /* RXCSR_DEV */
  134. #define EPX_RX_AUTOCLEAR (1<<15)
  135. #define EPX_RX_ISO (1<<14)
  136. #define EPX_RX_DMAREQEN (1<<13)
  137. #define EPX_RX_DISNYET (1<<12)
  138. #define EPX_RX_PIDERR (1<<12)
  139. #define EPX_RX_DMAREQMODE (1<<11)
  140. #define EPX_RX_AUTOCLRENSPKT (1<<10)
  141. #define EPX_RX_INCOMPRXINTREN (1<<9)
  142. #define EPX_RX_INCOMPRX (1<<8)
  143. #define EPX_RX_CLRDATATOG (1<<7)
  144. #define EPX_RX_SENTSTALL (1<<6)
  145. #define EPX_RX_SENDSTALL (1<<5)
  146. #define EPX_RX_FLUSHFIFO (1<<4)
  147. #define EPX_RX_DATAERR (1<<3)
  148. #define EPX_RX_OVERRUN (1<<2)
  149. #define EPX_RX_FIFOFULL (1<<1)
  150. #define EPX_RX_RXPKTRDY (1<<0)
  151. /* CONFIGDATA fields */
  152. #define MP_RXE (1<<7)
  153. #define MP_TXE (1<<6)
  154. #define BIGENDIAN (1<<5)
  155. #define HBRXE (1<<4)
  156. #define HBTXE (1<<3)
  157. #define DYNFIFOSIZING (1<<2)
  158. #define SOFTCONE (1<<1)
  159. #define UTMIDATAWIDTH (1<<0)
  160. /* FIFO register */
  161. /*
  162. * for endpint 1 ~ 4, writing to these addresses = writing to the
  163. * corresponding TX FIFO, reading from these addresses = reading from
  164. * corresponding RX FIFO
  165. */
  166. #define FIFO(ep_num) (USB_BASE + 0x0020 + ep_num*0x0004)
  167. /* ============================ */
  168. /* additional control registers */
  169. /* ============================ */
  170. #define DEVCTL (USB_BASE + 0x0060) /* OTG Device Control Register */
  171. #define PWRUPCNT (USB_BASE + 0x0061) /* Power Up Counter Register */
  172. #define TXFIFOSZ (USB_BASE + 0x0062) /* TX FIFO Size Register */
  173. #define RXFIFOSZ (USB_BASE + 0x0063) /* RX FIFO Size Register */
  174. #define TXFIFOADD (USB_BASE + 0x0064) /* TX FIFO Address Register */
  175. #define RXFIFOADD (USB_BASE + 0x0066) /* RX FIFO Address Register */
  176. #define HWVERS (USB_BASE + 0x006c) /* H/W Version Register */
  177. #define SWRST (USB_BASE + 0x0074) /* Software Reset Register */
  178. #define EPINFO (USB_BASE + 0x0078) /* TX and RX Information Register */
  179. #define RAM_DMAINFO (USB_BASE + 0x0079) /* RAM and DMA Information Register */
  180. #define LINKINFO (USB_BASE + 0x007a) /* Delay Time Information Register */
  181. #define VPLEN (USB_BASE + 0x007b) /* VBUS Pulse Charge Time Register */
  182. #define HSEOF1 (USB_BASE + 0x007c) /* High Speed EOF1 Register */
  183. #define FSEOF1 (USB_BASE + 0x007d) /* Full Speed EOF1 Register */
  184. #define LSEOF1 (USB_BASE + 0x007e) /* Low Speed EOF1 Register */
  185. #define RSTINFO (USB_BASE + 0x007f) /* Reset Information Register */
  186. /* FIFO size register fields and available packet size values */
  187. #define DOUBLE_BUF 1
  188. #define FIFOSZ_DPB (1 << 4)
  189. #define PKTSZ 0x0f
  190. #define PKTSZ_8 (1<<3)
  191. #define PKTSZ_16 (1<<4)
  192. #define PKTSZ_32 (1<<5)
  193. #define PKTSZ_64 (1<<6)
  194. #define PKTSZ_128 (1<<7)
  195. #define PKTSZ_256 (1<<8)
  196. #define PKTSZ_512 (1<<9)
  197. #define PKTSZ_1024 (1<<10)
  198. #define FIFOSZ_8 (0x0)
  199. #define FIFOSZ_16 (0x1)
  200. #define FIFOSZ_32 (0x2)
  201. #define FIFOSZ_64 (0x3)
  202. #define FIFOSZ_128 (0x4)
  203. #define FIFOSZ_256 (0x5)
  204. #define FIFOSZ_512 (0x6)
  205. #define FIFOSZ_1024 (0x7)
  206. #define FIFOSZ_2048 (0x8)
  207. #define FIFOSZ_4096 (0x9)
  208. #define FIFOSZ_3072 (0xF)
  209. /* SWRST fields */
  210. #define SWRST_PHY_RST (1<<7)
  211. #define SWRST_PHYSIG_GATE_HS (1<<6)
  212. #define SWRST_PHYSIG_GATE_EN (1<<5)
  213. #define SWRST_REDUCE_DLY (1<<4)
  214. #define SWRST_UNDO_SRPFIX (1<<3)
  215. #define SWRST_FRC_VBUSVALID (1<<2)
  216. #define SWRST_SWRST (1<<1)
  217. #define SWRST_DISUSBRESET (1<<0)
  218. /* DMA_CNTL */
  219. #define USB_DMA_CNTL_ENDMAMODE2 (1 << 13)
  220. #define USB_DMA_CNTL_PP_RST (1 << 12)
  221. #define USB_DMA_CNTL_PP_EN (1 << 11)
  222. #define USB_DMA_BURST_MODE_MASK (3 << 9)
  223. #define USB_DMA_BURST_MODE_0 (0 << 9)
  224. #define USB_DMA_BURST_MODE_1 (0x1 << 9)
  225. #define USB_DMA_BURST_MODE_2 (0x2 << 9)
  226. #define USB_DMA_BURST_MODE_3 (0x3 << 9)
  227. #define USB_DMA_BUS_ERROR (0x1 << 8)
  228. #define USB_DMA_ENDPNT_MASK (0xf << 4)
  229. #define USB_DMA_ENDPNT_OFFSET (4)
  230. #define USB_DMA_INTEN (1 << 3)
  231. #define USB_DMA_DMAMODE (1 << 2)
  232. #define USB_DMA_DIR (1 << 1)
  233. #define USB_DMA_EN (1 << 0)
  234. /* USB level 1 interrupt registers */
  235. #define USB_L1INTS (USB_BASE + 0xa0) /* USB level 1 interrupt status register */
  236. #define USB_L1INTM (USB_BASE + 0xa4) /* USB level 1 interrupt mask register */
  237. #define USB_L1INTP (USB_BASE + 0xa8) /* USB level 1 interrupt polarity register */
  238. #define TX_INT_STATUS (1 << 0)
  239. #define RX_INT_STATUS (1 << 1)
  240. #define USBCOM_INT_STATUS (1 << 2)
  241. #define DMA_INT_STATUS (1 << 3)
  242. #define PSR_INT_STATUS (1 << 4)
  243. #define QINT_STATUS (1 << 5)
  244. #define QHIF_INT_STATUS (1 << 6)
  245. #define DPDM_INT_STATUS (1 << 7)
  246. #define VBUSVALID_INT_STATUS (1 << 8)
  247. #define IDDIG_INT_STATUS (1 << 9)
  248. #define DRVVBUS_INT_STATUS (1 << 10)
  249. #define POWERDWN_INT_STATUS (1 << 11)
  250. #define VBUSVALID_INT_POL (1 << 8)
  251. #define IDDIG_INT_POL (1 << 9)
  252. #define DRVVBUS_INT_POL (1 << 10)
  253. /* mt_usb defines */
  254. typedef enum
  255. {
  256. EP0_IDLE = 0,
  257. EP0_RX,
  258. EP0_TX,
  259. } EP0_STATE;
  260. #if 0
  261. typedef enum
  262. {
  263. CHARGER_UNKNOWN,
  264. STANDARD_HOST,
  265. STANDARD_CHARGER,
  266. NONSTANDARD_CHARGER,
  267. } USB_CHARGER_TYPE;
  268. #endif
  269. /* some macros */
  270. #define EPMASK(X) (1 << X)
  271. #define CHANMASK(X) (1 << X)
  272. void mt_usb_phy_recover(void);
  273. void mt_usb_phy_poweron(void);
  274. void mt_usb_phy_savecurrent(void);
  275. /* mt_usb.c */
  276. struct udc_endpoint *mt_find_ep(int ep_num, u8 dir);
  277. void mt_setup_ep(unsigned int ep_num, struct udc_endpoint *endpoint);
  278. void mt_usb_connect_internal(void);
  279. void mt_usb_disconnect_internal(void);
  280. void usb_qmu_init_and_start(void);
  281. #define CHECKSUM_LENGTH 16
  282. /* from preloader */
  283. #define USB_EP_XFER_CTRL 0
  284. #define USB_EP_XFER_ISO 1
  285. #define USB_EP_XFER_BULK 2
  286. #define USB_EP_XFER_INT 3
  287. /* USB transfer directions */
  288. #define USB_DIR_IN DEVICE_WRITE /* val: 0x80 */
  289. #define USB_DIR_OUT DEVICE_READ /* val: 0x00 */
  290. struct urb {
  291. struct udc_endpoint *endpoint;
  292. struct udc_device *device;
  293. struct setup_packet device_request;
  294. u8 *buffer;
  295. unsigned int actual_length;
  296. u32 qmu_complete;
  297. };
  298. /* endpoint data - mt_ep */
  299. struct udc_endpoint {
  300. /* rx side */
  301. struct urb *rcv_urb; /* active urb */
  302. /* tx side */
  303. struct urb *tx_urb; /* active urb */
  304. /* info from hsusb */
  305. struct udc_request *req;
  306. unsigned int bit; /* EPT_TX/EPT_RX */
  307. unsigned char num;
  308. unsigned char in;
  309. unsigned short maxpkt;
  310. int status; /* status for error handling */
  311. unsigned int sent; /* data already sent */
  312. unsigned int last; /* data sent in last packet XXX do we need this */
  313. unsigned char mode; /* double buffer */
  314. unsigned char type; /* Transfer type */
  315. };
  316. /* from mt_usbtty.h */
  317. #define NUM_ENDPOINTS 3
  318. /* origin endpoint_array */
  319. struct udc_endpoint ep_list[NUM_ENDPOINTS + 1]; /* one extra for control endpoint */
  320. #endif