phy-fsl-usb.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /* Copyright (C) 2007,2008 Freescale Semiconductor, Inc.
  2. *
  3. * This program is free software; you can redistribute it and/or modify it
  4. * under the terms of the GNU General Public License as published by the
  5. * Free Software Foundation; either version 2 of the License, or (at your
  6. * option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #include <linux/usb/otg-fsm.h>
  18. #include <linux/usb/otg.h>
  19. #include <linux/ioctl.h>
  20. /* USB Command Register Bit Masks */
  21. #define USB_CMD_RUN_STOP (0x1<<0)
  22. #define USB_CMD_CTRL_RESET (0x1<<1)
  23. #define USB_CMD_PERIODIC_SCHEDULE_EN (0x1<<4)
  24. #define USB_CMD_ASYNC_SCHEDULE_EN (0x1<<5)
  25. #define USB_CMD_INT_AA_DOORBELL (0x1<<6)
  26. #define USB_CMD_ASP (0x3<<8)
  27. #define USB_CMD_ASYNC_SCH_PARK_EN (0x1<<11)
  28. #define USB_CMD_SUTW (0x1<<13)
  29. #define USB_CMD_ATDTW (0x1<<14)
  30. #define USB_CMD_ITC (0xFF<<16)
  31. /* bit 15,3,2 are frame list size */
  32. #define USB_CMD_FRAME_SIZE_1024 (0x0<<15 | 0x0<<2)
  33. #define USB_CMD_FRAME_SIZE_512 (0x0<<15 | 0x1<<2)
  34. #define USB_CMD_FRAME_SIZE_256 (0x0<<15 | 0x2<<2)
  35. #define USB_CMD_FRAME_SIZE_128 (0x0<<15 | 0x3<<2)
  36. #define USB_CMD_FRAME_SIZE_64 (0x1<<15 | 0x0<<2)
  37. #define USB_CMD_FRAME_SIZE_32 (0x1<<15 | 0x1<<2)
  38. #define USB_CMD_FRAME_SIZE_16 (0x1<<15 | 0x2<<2)
  39. #define USB_CMD_FRAME_SIZE_8 (0x1<<15 | 0x3<<2)
  40. /* bit 9-8 are async schedule park mode count */
  41. #define USB_CMD_ASP_00 (0x0<<8)
  42. #define USB_CMD_ASP_01 (0x1<<8)
  43. #define USB_CMD_ASP_10 (0x2<<8)
  44. #define USB_CMD_ASP_11 (0x3<<8)
  45. #define USB_CMD_ASP_BIT_POS (8)
  46. /* bit 23-16 are interrupt threshold control */
  47. #define USB_CMD_ITC_NO_THRESHOLD (0x00<<16)
  48. #define USB_CMD_ITC_1_MICRO_FRM (0x01<<16)
  49. #define USB_CMD_ITC_2_MICRO_FRM (0x02<<16)
  50. #define USB_CMD_ITC_4_MICRO_FRM (0x04<<16)
  51. #define USB_CMD_ITC_8_MICRO_FRM (0x08<<16)
  52. #define USB_CMD_ITC_16_MICRO_FRM (0x10<<16)
  53. #define USB_CMD_ITC_32_MICRO_FRM (0x20<<16)
  54. #define USB_CMD_ITC_64_MICRO_FRM (0x40<<16)
  55. #define USB_CMD_ITC_BIT_POS (16)
  56. /* USB Status Register Bit Masks */
  57. #define USB_STS_INT (0x1<<0)
  58. #define USB_STS_ERR (0x1<<1)
  59. #define USB_STS_PORT_CHANGE (0x1<<2)
  60. #define USB_STS_FRM_LST_ROLL (0x1<<3)
  61. #define USB_STS_SYS_ERR (0x1<<4)
  62. #define USB_STS_IAA (0x1<<5)
  63. #define USB_STS_RESET_RECEIVED (0x1<<6)
  64. #define USB_STS_SOF (0x1<<7)
  65. #define USB_STS_DCSUSPEND (0x1<<8)
  66. #define USB_STS_HC_HALTED (0x1<<12)
  67. #define USB_STS_RCL (0x1<<13)
  68. #define USB_STS_PERIODIC_SCHEDULE (0x1<<14)
  69. #define USB_STS_ASYNC_SCHEDULE (0x1<<15)
  70. /* USB Interrupt Enable Register Bit Masks */
  71. #define USB_INTR_INT_EN (0x1<<0)
  72. #define USB_INTR_ERR_INT_EN (0x1<<1)
  73. #define USB_INTR_PC_DETECT_EN (0x1<<2)
  74. #define USB_INTR_FRM_LST_ROLL_EN (0x1<<3)
  75. #define USB_INTR_SYS_ERR_EN (0x1<<4)
  76. #define USB_INTR_ASYN_ADV_EN (0x1<<5)
  77. #define USB_INTR_RESET_EN (0x1<<6)
  78. #define USB_INTR_SOF_EN (0x1<<7)
  79. #define USB_INTR_DEVICE_SUSPEND (0x1<<8)
  80. /* Device Address bit masks */
  81. #define USB_DEVICE_ADDRESS_MASK (0x7F<<25)
  82. #define USB_DEVICE_ADDRESS_BIT_POS (25)
  83. /* PORTSC Register Bit Masks,Only one PORT in OTG mode*/
  84. #define PORTSC_CURRENT_CONNECT_STATUS (0x1<<0)
  85. #define PORTSC_CONNECT_STATUS_CHANGE (0x1<<1)
  86. #define PORTSC_PORT_ENABLE (0x1<<2)
  87. #define PORTSC_PORT_EN_DIS_CHANGE (0x1<<3)
  88. #define PORTSC_OVER_CURRENT_ACT (0x1<<4)
  89. #define PORTSC_OVER_CUURENT_CHG (0x1<<5)
  90. #define PORTSC_PORT_FORCE_RESUME (0x1<<6)
  91. #define PORTSC_PORT_SUSPEND (0x1<<7)
  92. #define PORTSC_PORT_RESET (0x1<<8)
  93. #define PORTSC_LINE_STATUS_BITS (0x3<<10)
  94. #define PORTSC_PORT_POWER (0x1<<12)
  95. #define PORTSC_PORT_INDICTOR_CTRL (0x3<<14)
  96. #define PORTSC_PORT_TEST_CTRL (0xF<<16)
  97. #define PORTSC_WAKE_ON_CONNECT_EN (0x1<<20)
  98. #define PORTSC_WAKE_ON_CONNECT_DIS (0x1<<21)
  99. #define PORTSC_WAKE_ON_OVER_CURRENT (0x1<<22)
  100. #define PORTSC_PHY_LOW_POWER_SPD (0x1<<23)
  101. #define PORTSC_PORT_FORCE_FULL_SPEED (0x1<<24)
  102. #define PORTSC_PORT_SPEED_MASK (0x3<<26)
  103. #define PORTSC_TRANSCEIVER_WIDTH (0x1<<28)
  104. #define PORTSC_PHY_TYPE_SEL (0x3<<30)
  105. /* bit 11-10 are line status */
  106. #define PORTSC_LINE_STATUS_SE0 (0x0<<10)
  107. #define PORTSC_LINE_STATUS_JSTATE (0x1<<10)
  108. #define PORTSC_LINE_STATUS_KSTATE (0x2<<10)
  109. #define PORTSC_LINE_STATUS_UNDEF (0x3<<10)
  110. #define PORTSC_LINE_STATUS_BIT_POS (10)
  111. /* bit 15-14 are port indicator control */
  112. #define PORTSC_PIC_OFF (0x0<<14)
  113. #define PORTSC_PIC_AMBER (0x1<<14)
  114. #define PORTSC_PIC_GREEN (0x2<<14)
  115. #define PORTSC_PIC_UNDEF (0x3<<14)
  116. #define PORTSC_PIC_BIT_POS (14)
  117. /* bit 19-16 are port test control */
  118. #define PORTSC_PTC_DISABLE (0x0<<16)
  119. #define PORTSC_PTC_JSTATE (0x1<<16)
  120. #define PORTSC_PTC_KSTATE (0x2<<16)
  121. #define PORTSC_PTC_SEQNAK (0x3<<16)
  122. #define PORTSC_PTC_PACKET (0x4<<16)
  123. #define PORTSC_PTC_FORCE_EN (0x5<<16)
  124. #define PORTSC_PTC_BIT_POS (16)
  125. /* bit 27-26 are port speed */
  126. #define PORTSC_PORT_SPEED_FULL (0x0<<26)
  127. #define PORTSC_PORT_SPEED_LOW (0x1<<26)
  128. #define PORTSC_PORT_SPEED_HIGH (0x2<<26)
  129. #define PORTSC_PORT_SPEED_UNDEF (0x3<<26)
  130. #define PORTSC_SPEED_BIT_POS (26)
  131. /* bit 28 is parallel transceiver width for UTMI interface */
  132. #define PORTSC_PTW (0x1<<28)
  133. #define PORTSC_PTW_8BIT (0x0<<28)
  134. #define PORTSC_PTW_16BIT (0x1<<28)
  135. /* bit 31-30 are port transceiver select */
  136. #define PORTSC_PTS_UTMI (0x0<<30)
  137. #define PORTSC_PTS_ULPI (0x2<<30)
  138. #define PORTSC_PTS_FSLS_SERIAL (0x3<<30)
  139. #define PORTSC_PTS_BIT_POS (30)
  140. #define PORTSC_W1C_BITS \
  141. (PORTSC_CONNECT_STATUS_CHANGE | \
  142. PORTSC_PORT_EN_DIS_CHANGE | \
  143. PORTSC_OVER_CUURENT_CHG)
  144. /* OTG Status Control Register Bit Masks */
  145. #define OTGSC_CTRL_VBUS_DISCHARGE (0x1<<0)
  146. #define OTGSC_CTRL_VBUS_CHARGE (0x1<<1)
  147. #define OTGSC_CTRL_OTG_TERMINATION (0x1<<3)
  148. #define OTGSC_CTRL_DATA_PULSING (0x1<<4)
  149. #define OTGSC_CTRL_ID_PULL_EN (0x1<<5)
  150. #define OTGSC_HA_DATA_PULSE (0x1<<6)
  151. #define OTGSC_HA_BA (0x1<<7)
  152. #define OTGSC_STS_USB_ID (0x1<<8)
  153. #define OTGSC_STS_A_VBUS_VALID (0x1<<9)
  154. #define OTGSC_STS_A_SESSION_VALID (0x1<<10)
  155. #define OTGSC_STS_B_SESSION_VALID (0x1<<11)
  156. #define OTGSC_STS_B_SESSION_END (0x1<<12)
  157. #define OTGSC_STS_1MS_TOGGLE (0x1<<13)
  158. #define OTGSC_STS_DATA_PULSING (0x1<<14)
  159. #define OTGSC_INTSTS_USB_ID (0x1<<16)
  160. #define OTGSC_INTSTS_A_VBUS_VALID (0x1<<17)
  161. #define OTGSC_INTSTS_A_SESSION_VALID (0x1<<18)
  162. #define OTGSC_INTSTS_B_SESSION_VALID (0x1<<19)
  163. #define OTGSC_INTSTS_B_SESSION_END (0x1<<20)
  164. #define OTGSC_INTSTS_1MS (0x1<<21)
  165. #define OTGSC_INTSTS_DATA_PULSING (0x1<<22)
  166. #define OTGSC_INTR_USB_ID_EN (0x1<<24)
  167. #define OTGSC_INTR_A_VBUS_VALID_EN (0x1<<25)
  168. #define OTGSC_INTR_A_SESSION_VALID_EN (0x1<<26)
  169. #define OTGSC_INTR_B_SESSION_VALID_EN (0x1<<27)
  170. #define OTGSC_INTR_B_SESSION_END_EN (0x1<<28)
  171. #define OTGSC_INTR_1MS_TIMER_EN (0x1<<29)
  172. #define OTGSC_INTR_DATA_PULSING_EN (0x1<<30)
  173. #define OTGSC_INTSTS_MASK (0x00ff0000)
  174. /* USB MODE Register Bit Masks */
  175. #define USB_MODE_CTRL_MODE_IDLE (0x0<<0)
  176. #define USB_MODE_CTRL_MODE_DEVICE (0x2<<0)
  177. #define USB_MODE_CTRL_MODE_HOST (0x3<<0)
  178. #define USB_MODE_CTRL_MODE_RSV (0x1<<0)
  179. #define USB_MODE_SETUP_LOCK_OFF (0x1<<3)
  180. #define USB_MODE_STREAM_DISABLE (0x1<<4)
  181. #define USB_MODE_ES (0x1<<2) /* Endian Select */
  182. /* control Register Bit Masks */
  183. #define USB_CTRL_IOENB (0x1<<2)
  184. #define USB_CTRL_ULPI_INT0EN (0x1<<0)
  185. /* BCSR5 */
  186. #define BCSR5_INT_USB (0x02)
  187. /* USB module clk cfg */
  188. #define SCCR_OFFS (0xA08)
  189. #define SCCR_USB_CLK_DISABLE (0x00000000) /* USB clk disable */
  190. #define SCCR_USB_MPHCM_11 (0x00c00000)
  191. #define SCCR_USB_MPHCM_01 (0x00400000)
  192. #define SCCR_USB_MPHCM_10 (0x00800000)
  193. #define SCCR_USB_DRCM_11 (0x00300000)
  194. #define SCCR_USB_DRCM_01 (0x00100000)
  195. #define SCCR_USB_DRCM_10 (0x00200000)
  196. #define SICRL_OFFS (0x114)
  197. #define SICRL_USB0 (0x40000000)
  198. #define SICRL_USB1 (0x20000000)
  199. #define SICRH_OFFS (0x118)
  200. #define SICRH_USB_UTMI (0x00020000)
  201. /* OTG interrupt enable bit masks */
  202. #define OTGSC_INTERRUPT_ENABLE_BITS_MASK \
  203. (OTGSC_INTR_USB_ID_EN | \
  204. OTGSC_INTR_1MS_TIMER_EN | \
  205. OTGSC_INTR_A_VBUS_VALID_EN | \
  206. OTGSC_INTR_A_SESSION_VALID_EN | \
  207. OTGSC_INTR_B_SESSION_VALID_EN | \
  208. OTGSC_INTR_B_SESSION_END_EN | \
  209. OTGSC_INTR_DATA_PULSING_EN)
  210. /* OTG interrupt status bit masks */
  211. #define OTGSC_INTERRUPT_STATUS_BITS_MASK \
  212. (OTGSC_INTSTS_USB_ID | \
  213. OTGSC_INTR_1MS_TIMER_EN | \
  214. OTGSC_INTSTS_A_VBUS_VALID | \
  215. OTGSC_INTSTS_A_SESSION_VALID | \
  216. OTGSC_INTSTS_B_SESSION_VALID | \
  217. OTGSC_INTSTS_B_SESSION_END | \
  218. OTGSC_INTSTS_DATA_PULSING)
  219. /*
  220. * A-DEVICE timing constants
  221. */
  222. /* Wait for VBUS Rise */
  223. #define TA_WAIT_VRISE (100) /* a_wait_vrise 100 ms, section: 6.6.5.1 */
  224. /* Wait for B-Connect */
  225. #define TA_WAIT_BCON (10000) /* a_wait_bcon > 1 sec, section: 6.6.5.2
  226. * This is only used to get out of
  227. * OTG_STATE_A_WAIT_BCON state if there was
  228. * no connection for these many milliseconds
  229. */
  230. /* A-Idle to B-Disconnect */
  231. /* It is necessary for this timer to be more than 750 ms because of a bug in OPT
  232. * test 5.4 in which B OPT disconnects after 750 ms instead of 75ms as stated
  233. * in the test description
  234. */
  235. #define TA_AIDL_BDIS (5000) /* a_suspend minimum 200 ms, section: 6.6.5.3 */
  236. /* B-Idle to A-Disconnect */
  237. #define TA_BIDL_ADIS (12) /* 3 to 200 ms */
  238. /* B-device timing constants */
  239. /* Data-Line Pulse Time*/
  240. #define TB_DATA_PLS (10) /* b_srp_init,continue 5~10ms, section:5.3.3 */
  241. #define TB_DATA_PLS_MIN (5) /* minimum 5 ms */
  242. #define TB_DATA_PLS_MAX (10) /* maximum 10 ms */
  243. /* SRP Initiate Time */
  244. #define TB_SRP_INIT (100) /* b_srp_init,maximum 100 ms, section:5.3.8 */
  245. /* SRP Fail Time */
  246. #define TB_SRP_FAIL (7000) /* b_srp_init,Fail time 5~30s, section:6.8.2.2*/
  247. /* SRP result wait time */
  248. #define TB_SRP_WAIT (60)
  249. /* VBus time */
  250. #define TB_VBUS_PLS (30) /* time to keep vbus pulsing asserted */
  251. /* Discharge time */
  252. /* This time should be less than 10ms. It varies from system to system. */
  253. #define TB_VBUS_DSCHRG (8)
  254. /* A-SE0 to B-Reset */
  255. #define TB_ASE0_BRST (20) /* b_wait_acon, mini 3.125 ms,section:6.8.2.4 */
  256. /* A bus suspend timer before we can switch to b_wait_aconn */
  257. #define TB_A_SUSPEND (7)
  258. #define TB_BUS_RESUME (12)
  259. /* SE0 Time Before SRP */
  260. #define TB_SE0_SRP (2) /* b_idle,minimum 2 ms, section:5.3.2 */
  261. #define SET_OTG_STATE(phy, newstate) ((phy)->otg->state = newstate)
  262. struct usb_dr_mmap {
  263. /* Capability register */
  264. u8 res1[256];
  265. u16 caplength; /* Capability Register Length */
  266. u16 hciversion; /* Host Controller Interface Version */
  267. u32 hcsparams; /* Host Controller Structual Parameters */
  268. u32 hccparams; /* Host Controller Capability Parameters */
  269. u8 res2[20];
  270. u32 dciversion; /* Device Controller Interface Version */
  271. u32 dccparams; /* Device Controller Capability Parameters */
  272. u8 res3[24];
  273. /* Operation register */
  274. u32 usbcmd; /* USB Command Register */
  275. u32 usbsts; /* USB Status Register */
  276. u32 usbintr; /* USB Interrupt Enable Register */
  277. u32 frindex; /* Frame Index Register */
  278. u8 res4[4];
  279. u32 deviceaddr; /* Device Address */
  280. u32 endpointlistaddr; /* Endpoint List Address Register */
  281. u8 res5[4];
  282. u32 burstsize; /* Master Interface Data Burst Size Register */
  283. u32 txttfilltuning; /* Transmit FIFO Tuning Controls Register */
  284. u8 res6[8];
  285. u32 ulpiview; /* ULPI register access */
  286. u8 res7[12];
  287. u32 configflag; /* Configure Flag Register */
  288. u32 portsc; /* Port 1 Status and Control Register */
  289. u8 res8[28];
  290. u32 otgsc; /* On-The-Go Status and Control */
  291. u32 usbmode; /* USB Mode Register */
  292. u32 endptsetupstat; /* Endpoint Setup Status Register */
  293. u32 endpointprime; /* Endpoint Initialization Register */
  294. u32 endptflush; /* Endpoint Flush Register */
  295. u32 endptstatus; /* Endpoint Status Register */
  296. u32 endptcomplete; /* Endpoint Complete Register */
  297. u32 endptctrl[6]; /* Endpoint Control Registers */
  298. u8 res9[552];
  299. u32 snoop1;
  300. u32 snoop2;
  301. u32 age_cnt_thresh; /* Age Count Threshold Register */
  302. u32 pri_ctrl; /* Priority Control Register */
  303. u32 si_ctrl; /* System Interface Control Register */
  304. u8 res10[236];
  305. u32 control; /* General Purpose Control Register */
  306. };
  307. struct fsl_otg_timer {
  308. unsigned long expires; /* Number of count increase to timeout */
  309. unsigned long count; /* Tick counter */
  310. void (*function)(unsigned long); /* Timeout function */
  311. unsigned long data; /* Data passed to function */
  312. struct list_head list;
  313. };
  314. inline struct fsl_otg_timer *otg_timer_initializer
  315. (void (*function)(unsigned long), unsigned long expires, unsigned long data)
  316. {
  317. struct fsl_otg_timer *timer;
  318. timer = kmalloc(sizeof(struct fsl_otg_timer), GFP_KERNEL);
  319. if (!timer)
  320. return NULL;
  321. timer->function = function;
  322. timer->expires = expires;
  323. timer->data = data;
  324. return timer;
  325. }
  326. struct fsl_otg {
  327. struct usb_phy phy;
  328. struct otg_fsm fsm;
  329. struct usb_dr_mmap *dr_mem_map;
  330. struct delayed_work otg_event;
  331. /* used for usb host */
  332. struct work_struct work_wq;
  333. u8 host_working;
  334. int irq;
  335. };
  336. struct fsl_otg_config {
  337. u8 otg_port;
  338. };
  339. /* For SRP and HNP handle */
  340. #define FSL_OTG_MAJOR 240
  341. #define FSL_OTG_NAME "fsl-usb2-otg"
  342. /* Command to OTG driver ioctl */
  343. #define OTG_IOCTL_MAGIC FSL_OTG_MAJOR
  344. /* if otg work as host, it should return 1, otherwise return 0 */
  345. #define GET_OTG_STATUS _IOR(OTG_IOCTL_MAGIC, 1, int)
  346. #define SET_A_SUSPEND_REQ _IOW(OTG_IOCTL_MAGIC, 2, int)
  347. #define SET_A_BUS_DROP _IOW(OTG_IOCTL_MAGIC, 3, int)
  348. #define SET_A_BUS_REQ _IOW(OTG_IOCTL_MAGIC, 4, int)
  349. #define SET_B_BUS_REQ _IOW(OTG_IOCTL_MAGIC, 5, int)
  350. #define GET_A_SUSPEND_REQ _IOR(OTG_IOCTL_MAGIC, 6, int)
  351. #define GET_A_BUS_DROP _IOR(OTG_IOCTL_MAGIC, 7, int)
  352. #define GET_A_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 8, int)
  353. #define GET_B_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 9, int)
  354. void fsl_otg_add_timer(struct otg_fsm *fsm, void *timer);
  355. void fsl_otg_del_timer(struct otg_fsm *fsm, void *timer);
  356. void fsl_otg_pulse_vbus(void);