musb_core.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. /*
  2. * MUSB OTG driver defines
  3. *
  4. * Copyright 2005 Mentor Graphics Corporation
  5. * Copyright (C) 2005-2006 by Texas Instruments
  6. * Copyright (C) 2006-2007 Nokia Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  19. * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  22. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  23. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. #ifndef __MUSB_CORE_H__
  29. #define __MUSB_CORE_H__
  30. #include <linux/slab.h>
  31. #include <linux/list.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/errno.h>
  34. #include <linux/timer.h>
  35. #include <linux/clk.h>
  36. #include <linux/device.h>
  37. #include <linux/usb/ch9.h>
  38. #include <linux/usb/gadget.h>
  39. #include <linux/usb.h>
  40. #include <linux/usb/otg.h>
  41. #include <linux/wakelock.h>
  42. #include <linux/workqueue.h>
  43. #include <linux/switch.h>
  44. #include <linux/regulator/consumer.h>
  45. #include <linux/input.h>
  46. struct musb;
  47. struct musb_hw_ep;
  48. struct musb_ep;
  49. #include "ssusb_sysfs.h"
  50. /* #include "musb_io.h" */
  51. #include "musb_gadget.h"
  52. #include "ssusb.h"
  53. /* #define CONFIG_MUSB_PIO_ONLY */
  54. #ifdef SUPPORT_U3
  55. #define USB_GADGET_SUPERSPEED
  56. #else
  57. #define USB_GADGET_DUALSPEED
  58. #endif
  59. #define MUSB_DRIVER_NAME "musb-hdrc"
  60. #define is_peripheral_enabled(musb) ((musb)->board_mode != MUSB_HOST)
  61. #define is_host_enabled(musb) ((musb)->board_mode != MUSB_PERIPHERAL)
  62. #define is_otg_enabled(musb) ((musb)->board_mode == MUSB_OTG)
  63. #define DMA_ADDR_INVALID (~(dma_addr_t)0)
  64. #ifdef USE_SSUSB_QMU
  65. #define is_dma_capable() (1)
  66. #else
  67. #define is_dma_capable() (0)
  68. #endif
  69. #define SSUSB_XHCI_RSCS_NUM 2
  70. #define SSUSB_MU3D_RSCS_NUM 4
  71. #define K_QMU (1<<7)
  72. #define K_ALET (1<<6)
  73. #define K_CRIT (1<<5)
  74. #define K_ERR (1<<4)
  75. #define K_WARNIN (1<<3)
  76. #define K_NOTICE (1<<2)
  77. #define K_INFO (1<<1)
  78. #define K_DEBUG (1<<0)
  79. /*Set the debug level at musb_core.c*/
  80. extern u32 debug_level;
  81. extern struct musb *_mu3d_musb;
  82. extern struct musb_fifo_cfg ep0_cfg_u3;
  83. extern struct musb_fifo_cfg ep0_cfg_u2;
  84. #ifdef USE_SSUSB_QMU
  85. #define qmu_dbg(level, fmt, args...) do { \
  86. if (debug_level & (level|K_QMU)) { \
  87. pr_err("[MU3D][Q]" fmt, ## args); \
  88. } \
  89. } while (0)
  90. #endif
  91. #define mu3d_dbg(level, fmt, args...) do { \
  92. if (debug_level & level) { \
  93. pr_err("[MU3D]" fmt, ## args); \
  94. } \
  95. } while (0)
  96. /* NOTE: otg and peripheral-only state machines start at B_IDLE.
  97. * OTG or host-only go to A_IDLE when ID is sensed.
  98. */
  99. /* #define is_peripheral_active(m) (!(m)->is_host) */
  100. /* #define is_host_active(m) ((m)->is_host) */
  101. #if 0 /* ndef CONFIG_HAVE_CLK */
  102. /* Dummy stub for clk framework */
  103. #define clk_get(dev, id) NULL
  104. #define clk_put(clock) do {} while (0)
  105. #define clk_enable(clock) do {} while (0)
  106. #define clk_disable(clock) do {} while (0)
  107. #endif
  108. #ifdef CONFIG_PROC_FS
  109. #include <linux/fs.h>
  110. #define MUSB_CONFIG_PROC_FS
  111. #endif
  112. /* xtal clock related */
  113. /* #define UAP_PLL_CONX_BASE 0x10209000 */
  114. /* #define UAP_PLL_CONX_LEN 0x1000 */
  115. #define UAP_PLL_CON0 0x00
  116. #define CON0_RG_LTECLKSQ_EN (0x1 << 0)
  117. #define CON0_RG_LTECLKSQ_LPF_EN (0x1 << 1)
  118. #define UAP_PLL_CON1 0x04
  119. #define UAP_PLL_CON2 0x08
  120. #define CON2_DA_REF2USB_TX_EN (0x1 << 0)
  121. #define CON2_DA_REF2USB_TX_LPF_EN (0x1 << 1)
  122. #define CON2_DA_REF2USB_TX_OUT_EN (0x1 << 2)
  123. #define CON2_DA_REF2USB_TX_MASK \
  124. (CON2_DA_REF2USB_TX_EN | CON2_DA_REF2USB_TX_LPF_EN | CON2_DA_REF2USB_TX_OUT_EN)
  125. /* usb wakeup control related (pericfg doc) */
  126. /* #define PERIFSYS_BASE 0x10003000 */
  127. /* #define PERIFSYS_LEN 0x1000 */
  128. #define PERI_WK_CTRL0 0x400
  129. #define UWK_CTL1_1P_LS_E (0x1 << 0)
  130. #define UWK_CTL1_1P_LS_C(x) (((x) & 0xf) << 1)
  131. #define UWK_CTR0_0P_LS_NE (0x1 << 7) /* negedge for 0p linestate */
  132. #define UWK_CTR0_0P_LS_PE (0x1 << 8) /* posedge */
  133. #define PERI_WK_CTRL1 0x404
  134. #define UWK_CTL1_IS_P (0x1 << 6) /* polarity for ip sleep */
  135. #define UWK_CTL1_0P_LS_P (0x1 << 7)
  136. #define UWK_CTL1_IDDIG_P (0x1 << 9) /* polarity */
  137. #define UWK_CTL1_IDDIG_E (0x1 << 10) /* enable debounce */
  138. #define UWK_CTL1_IDDIG_C(x) (((x) & 0xf) << 11) /* cycle of debounce */
  139. #define UWK_CTL1_0P_LS_E (0x1 << 20)
  140. #define UWK_CTL1_0P_LS_C(x) (((x) & 0xf) << 21)
  141. #define UWK_CTL1_IS_E (0x1 << 25)
  142. #define UWK_CTL1_IS_C(x) (((x) & 0xf) << 26)
  143. /****************************** PERIPHERAL ROLE *****************************/
  144. /* #define is_peripheral_capable() (1) */
  145. extern irqreturn_t musb_g_ep0_irq(struct musb *);
  146. extern void musb_g_tx(struct musb *, u8);
  147. extern void musb_g_rx(struct musb *, u8);
  148. extern void musb_g_reset(struct musb *);
  149. extern void musb_g_suspend(struct musb *);
  150. extern void musb_g_resume(struct musb *);
  151. extern void musb_g_wakeup(struct musb *);
  152. extern void musb_g_disconnect(struct musb *);
  153. /****************************** HOST ROLE ***********************************/
  154. /* #define is_host_capable() (1) */
  155. /* extern irqreturn_t musb_h_ep0_irq(struct musb *); */
  156. /* extern void musb_host_tx(struct musb *, u8); */
  157. /* extern void musb_host_rx(struct musb *, u8); */
  158. /****************************** CONSTANTS ********************************/
  159. #define MUSB_EP0_FIFOSIZE 64 /* This is non-configurable */
  160. #ifndef MUSB_C_NUM_EPS
  161. #define MUSB_C_NUM_EPS ((u8)9)
  162. #endif
  163. #ifndef MUSB_MAX_END0_PACKET
  164. #define MUSB_MAX_END0_PACKET ((u16)MUSB_EP0_FIFOSIZE)
  165. #endif
  166. /* host side ep0 states */
  167. enum musb_h_ep0_state {
  168. MUSB_EP0_IDLE,
  169. MUSB_EP0_START, /* expect ack of setup */
  170. MUSB_EP0_IN, /* expect IN DATA */
  171. MUSB_EP0_OUT, /* expect ack of OUT DATA */
  172. MUSB_EP0_STATUS, /* expect ack of STATUS */
  173. };
  174. /* peripheral side ep0 states */
  175. enum musb_g_ep0_state {
  176. MUSB_EP0_STAGE_IDLE, /* idle, waiting for SETUP */
  177. MUSB_EP0_STAGE_SETUP, /* received SETUP */
  178. MUSB_EP0_STAGE_TX, /* IN data */
  179. MUSB_EP0_STAGE_RX, /* OUT data */
  180. MUSB_EP0_STAGE_STATUSIN, /* (after OUT data) */
  181. MUSB_EP0_STAGE_STATUSOUT, /* (after IN data) */
  182. MUSB_EP0_STAGE_ACKWAIT, /* after zlp, before statusin */
  183. };
  184. enum ssusb_vbus_mode {
  185. SSUSB_VBUS_DEF_ON, /* turn on already by default */
  186. SSUSB_VBUS_CHARGER, /* turn on/off by charger driver api */
  187. SSUSB_VBUS_GPIO, /* turn on/off by GPIO */
  188. };
  189. /*
  190. * @ SSUSB_OTG_STANDARD: by SRP and HNP, don't realize it temp.;
  191. * @ SSUSB_OTG_CHEINT: device mode is turned on/off by charge driver & idpin eint
  192. * is used to switch between device/host mode. (on tablet)
  193. * @ SSUSB_OTG_MANUAL: device and host is switch by sysfs interface (on box with type A)
  194. * @ SSUSB_OTG_IDPIN: device and host mode is switched by idpin eint, but device should turn
  195. * on by default which is almost the same as SSUSB_OTG_MANUAL; (on box with micro
  196. * port and inpin, but not charger ic and a gpio to detect vbus)
  197. */
  198. enum ssusb_otg_mode {
  199. SSUSB_OTG_STANDARD, /* by SRP or HNP */
  200. SSUSB_OTG_CHEINT, /* by charger & EINT */
  201. SSUSB_OTG_MANUAL, /* by sysfs interface */
  202. SSUSB_OTG_IDPIN, /* by iddig instead of sysfs interface */
  203. };
  204. /* same as musb_mode temp */
  205. enum ssusb_mode {
  206. SSUSB_MODE_UNDEFINED = 0,
  207. SSUSB_MODE_HOST,
  208. SSUSB_MODE_DEVICE,
  209. SSUSB_MODE_DRD,
  210. };
  211. /*
  212. * @SSUSB_STR_NONE: especially used by tablet: clocks, ports, mu3d and xhci
  213. * are all power down and phy also enter low-power mode when no cable is plugged in.
  214. * but keep LDOs on to let charger detect cable type. when plug in cable or OTG
  215. * device or host is enabled again, at the same time system never enter suspend
  216. * mode, so it doesn't need to support suspend/resume at the case.
  217. * @SSUSB_STR_ALIVE: mainly used by box: when system suspend, usb should keep
  218. * on link with devices such as wifi, bt and ethernet which layed out on board;
  219. * that means only close clocks and force phy enter low-power mode
  220. * when resume, usb should not enum device again but make use of resume-signal
  221. * to wakeup device.
  222. * @SSUSB_STR_DEEP: maily used by box: when systen suspend, close all LDO, clocks,
  223. * mu3d, xhci, and force phy enter low-power mode; when resume, mu3d or xhci
  224. * is reset and enabled again.
  225. */
  226. enum ssusb_str_mode {
  227. SSUSB_STR_NONE = 0,
  228. SSUSB_STR_ALIVE,
  229. SSUSB_STR_DEEP,
  230. };
  231. /*
  232. * bit definition for usb wakeup source:
  233. * @SSUSB_WK_IDDIG: wakeup system when plug-in OTG cable; it's only for OTG port
  234. * with id-pin; it is not affected by host/device mode which port is working on.
  235. * @SSUSB_WK_LINESTATE_0P: wakeup system when plug-in/out device for port0,
  236. * it's not necessary to enable it for port0 which supports OTG, but instead of
  237. * SSUSB_WK_IDDIG; and it works only when port0 is host mode.
  238. * @SSUSB_WK_LINESTATE_1P: wakeup system when plug-in/out device for port1 which
  239. * works only on host mode.
  240. * @SSUSB_WK_IP_SLEEP: wakeup system when device sends remote wakeup request.
  241. */
  242. enum ssusb_wakeup_src {
  243. SSUSB_WK_IDDIG = 1,
  244. SSUSB_WK_LINESTATE_0P = 2,
  245. SSUSB_WK_LINESTATE_1P = 4,
  246. SSUSB_WK_IP_SLEEP = 8,
  247. };
  248. /* only for annonce usb status to battery */
  249. enum usb_state_enum {
  250. USB_SUSPEND = 0,
  251. USB_UNCONFIGURED,
  252. USB_CONFIGURED
  253. };
  254. enum cable_mode {
  255. CABLE_MODE_CHRG_ONLY = 0,
  256. CABLE_MODE_NORMAL,
  257. CABLE_MODE_HOST_ONLY,
  258. CABLE_MODE_MAX
  259. };
  260. /*
  261. * OTG protocol constants. See USB OTG 1.3 spec,
  262. * sections 5.5 "Device Timings" and 6.6.5 "Timers".
  263. */
  264. #define OTG_TIME_A_WAIT_VRISE 100 /* msec (max) */
  265. #define OTG_TIME_A_WAIT_BCON 1100 /* min 1 second */
  266. #define OTG_TIME_A_AIDL_BDIS 200 /* min 200 msec */
  267. #define OTG_TIME_B_ASE0_BRST 100 /* min 3.125 ms */
  268. /*************************** REGISTER ACCESS ********************************/
  269. /* Endpoint registers (other than dynfifo setup) can be accessed either
  270. * directly with the "flat" model, or after setting up an index register.
  271. */
  272. #define MU3D_FIFO_OFFSET(epnum) (U3D_FIFO0 + ((epnum) * 0x10))
  273. #define MU3D_EP_TXCR0_OFFSET(_epnum, _offset) \
  274. (U3D_TX1CSR0 + ((_epnum - 1)*0x10) + (_offset))
  275. #define MU3D_EP_TXCR1_OFFSET(_epnum, _offset) \
  276. (U3D_TX1CSR1 + ((_epnum - 1)*0x10) + (_offset))
  277. #define MU3D_EP_TXCR2_OFFSET(_epnum, _offset) \
  278. (U3D_TX1CSR2 + ((_epnum - 1)*0x10) + (_offset))
  279. /* #define SSUSB_EP_TXMAXP_OFFSET(_epnum, _offset) */
  280. /* (U3D_TX1CSR0 + ((_epnum - 1)*0x10) + (_offset)) */
  281. #define MU3D_EP_RXCR0_OFFSET(_epnum, _offset) \
  282. (U3D_RX1CSR0 + ((_epnum - 1)*0x10) + (_offset))
  283. #define MU3D_EP_RXCR1_OFFSET(_epnum, _offset) \
  284. (U3D_RX1CSR1 + ((_epnum - 1)*0x10) + (_offset))
  285. #define MU3D_EP_RXCR2_OFFSET(_epnum, _offset) \
  286. (U3D_RX1CSR2 + ((_epnum - 1)*0x10) + (_offset))
  287. #define MU3D_EP_RXCR3_OFFSET(_epnum, _offset) \
  288. (U3D_RX1CSR3 + ((_epnum - 1)*0x10) + (_offset))
  289. /****************************** FUNCTIONS ********************************/
  290. /* #define MUSB_HST_MODE(_musb) { (_musb)->is_host = true; } */
  291. /* #define MUSB_DEV_MODE(_musb) { (_musb)->is_host = false; } */
  292. /* #define test_devctl_hst_mode(_x) */
  293. /* (musb_readb((_x)->mregs, MUSB_DEVCTL)&MUSB_DEVCTL_HM) */
  294. /* #define MUSB_MODE(musb) ((musb)->is_host ? "Host" : "Peripheral") */
  295. /******************************** TYPES *************************************/
  296. /* #define SSUSB_MODE_DEVICE 0 */
  297. /* #define SSUSB_MODE_HOST 1 */
  298. /* #define SSUSB_MODE_DRD 2 */
  299. struct vbus_ctrl_info {
  300. enum ssusb_vbus_mode vbus_mode;
  301. int vbus_gpio_num;
  302. int gpio_active_low;
  303. };
  304. /**
  305. * @is_iddig_registered: whether iddig eint ISR is registered or not.
  306. * @iddig_reg_dwork: delay work for iddig eint register, waiting for charger initialized to
  307. * provide vbus for p0(it's necessary for bootup system when plug in OTG cable ).
  308. * @switch_dwork: iddig eint delay work, process OTG switch.
  309. * @is_init_as_host: it is only used by SSUSB_OTG_MANUAL; for other otg mode,
  310. * its default value shold be zero.
  311. * @port0_u2 : only port0 supports OTG, @port0_u2 indicats whether it support OTG or not.
  312. * 0: no, 1: do switch if exist.
  313. * @port0_u3 : is the same as port0_u2.
  314. */
  315. struct otg_switch_mtk {
  316. struct switch_dev otg_state;
  317. struct vbus_ctrl_info p0_vbus;
  318. int is_iddig_registered;
  319. struct delayed_work iddig_reg_dwork;
  320. struct delayed_work switch_dwork;
  321. struct wake_lock xhci_wakelock;
  322. enum ssusb_otg_mode otg_mode;
  323. int is_init_as_host;
  324. int iddig_eint_num;
  325. int next_idpin_state;
  326. int vbus_gpio_num;
  327. enum ssusb_vbus_mode vbus_mode;
  328. int port0_u2;
  329. int port0_u3;
  330. };
  331. /**
  332. * @ pdata: for mu3d platform
  333. * @ mac_base: only mu3d device-mac regs, exclude xhci's
  334. * @ sif_base: include sif & sif2
  335. * @ scp_sys: it is usb-mtcmos power in fact
  336. * @ str_mode: if it is SSUSB_STR_NONE, then its otg mode should be SSUSB_OTG_CHENT.
  337. * @ usbnet33: only some box use it, maybe it is better to put in usbnet
  338. * @ start_mu3d: 0: use iddig to start/stop mu3d,
  339. * 1: need call musb_start/stop() in gadget_start/stop()
  340. * @ is_power_saving_mode: if there is only one port which supports OTG, usb power
  341. * and clocks can be closed when plug out cable, so the mode is what
  342. * tablet/phone wanted. (on mt8173, should close all LDO, clocks and
  343. * powerdown & disconnect all ports.)
  344. * @ u2_ports: number of usb2.0 host ports
  345. * @ u3_ports: number of usb3.0 host ports
  346. * @vi_dev: virtual power-key input device, only for usb host wakeup
  347. */
  348. struct ssusb_mtk {
  349. struct device *dev;
  350. struct musb *mu3di;
  351. /* struct platform_device *mu3d; */
  352. struct platform_device *xhci;
  353. struct resource xhci_rscs[SSUSB_XHCI_RSCS_NUM];
  354. struct resource mu3d_rscs[SSUSB_MU3D_RSCS_NUM];
  355. struct musb_hdrc_platform_data *pdata;
  356. void __iomem *mac_base;
  357. void __iomem *sif_base;
  358. /* power & clock */
  359. struct regulator *vusb33;
  360. struct regulator *usbnet33;
  361. void __iomem *uap_pll_con;
  362. struct clk *scp_sys;
  363. struct clk *peri_usb0;
  364. struct clk *peri_usb1;
  365. struct mutex power_mutex;
  366. int is_power_on;
  367. /* otg */
  368. int mu3d_irq;
  369. int p1_exist;
  370. int p1_vbus_gpio_num;
  371. enum ssusb_vbus_mode p1_vbus_mode;
  372. struct vbus_ctrl_info p1_vbus;
  373. struct otg_switch_mtk otg_switch;
  374. enum ssusb_mode drv_mode;
  375. enum ssusb_str_mode str_mode;
  376. int start_mu3d;
  377. int is_power_saving_mode;
  378. int u2_ports;
  379. int u3_ports;
  380. int ic_version;
  381. /* usb wakeup */
  382. void __iomem *perisys;
  383. struct input_dev *vi_dev;
  384. int wakeup_src;
  385. };
  386. #define glue_to_musb(g) platform_get_drvdata(g->mu3d)
  387. /**
  388. * struct musb_platform_ops - Operations passed to musb_core by HW glue layer
  389. * @init: turns on clocks, sets up platform-specific registers, etc
  390. * @exit: undoes @init
  391. * @set_mode: forcefully changes operating mode
  392. * @try_ilde: tries to idle the IP
  393. * @vbus_status: returns vbus status if possible
  394. * @set_vbus: forces vbus status
  395. * @adjust_channel_params: pre check for standard dma channel_program func
  396. */
  397. struct musb_platform_ops {
  398. int (*init)(struct musb *musb);
  399. int (*exit)(struct musb *musb);
  400. void (*enable)(struct musb *musb);
  401. void (*disable)(struct musb *musb);
  402. int (*set_mode)(struct musb *musb, u8 mode);
  403. void (*try_idle)(struct musb *musb, unsigned long timeout);
  404. int (*vbus_status)(struct musb *musb);
  405. void (*set_vbus)(struct musb *musb, int on);
  406. /* int (*adjust_channel_params) (struct dma_channel *channel, */
  407. /* u16 packet_sz, u8 *mode, dma_addr_t *dma_addr, u32 *len); */
  408. };
  409. /*
  410. * struct musb_hw_ep - endpoint hardware (bidirectional)
  411. *
  412. * Ordered slightly for better cacheline locality.
  413. */
  414. struct musb_hw_ep {
  415. struct musb *musb;
  416. void __iomem *fifo;
  417. void __iomem *regs;
  418. /* For ssusb+ , only for non-ep0 */
  419. void __iomem *addr_txcsr0;
  420. void __iomem *addr_txcsr1;
  421. void __iomem *addr_txcsr2;
  422. /* void __iomem *addr_txmaxpktsz; */
  423. void __iomem *addr_rxcsr0;
  424. void __iomem *addr_rxcsr1;
  425. void __iomem *addr_rxcsr2;
  426. void __iomem *addr_rxcsr3;
  427. void __iomem *addr_rxmaxpktsz;
  428. /* For ssusb- */
  429. /* index in musb->endpoints[] */
  430. u8 epnum;
  431. /* hardware configuration, possibly dynamic */
  432. bool is_shared_fifo;
  433. /* bool tx_double_buffered; */
  434. /* bool rx_double_buffered; */
  435. u16 max_packet_sz_tx;
  436. u16 max_packet_sz_rx;
  437. /* For ssusb+ */
  438. u32 fifoaddr_tx;
  439. u32 fifoaddr_rx;
  440. u8 mult_tx;
  441. u8 mult_rx;
  442. u8 interval_tx;
  443. u8 interval_rx;
  444. /* For ssusb- */
  445. /* struct dma_channel *tx_channel; */
  446. /* struct dma_channel *rx_channel; */
  447. /* void __iomem *target_regs; */
  448. /* currently scheduled peripheral endpoint */
  449. struct musb_qh *in_qh;
  450. struct musb_qh *out_qh;
  451. /* u8 rx_reinit; */
  452. /* u8 tx_reinit; */
  453. /* peripheral side */
  454. struct musb_ep ep_in; /* TX */
  455. struct musb_ep ep_out; /* RX */
  456. };
  457. static inline struct musb_request *next_in_request(struct musb_hw_ep *hw_ep)
  458. {
  459. return next_request(&hw_ep->ep_in);
  460. }
  461. static inline struct musb_request *next_out_request(struct musb_hw_ep *hw_ep)
  462. {
  463. return next_request(&hw_ep->ep_out);
  464. }
  465. static inline struct ssusb_mtk *dev_to_ssusb(struct device *dev)
  466. {
  467. return dev_get_drvdata(dev);
  468. }
  469. #ifdef NEVER
  470. struct musb_csr_regs {
  471. /* FIFO registers */
  472. u16 txmaxp, txcsr, rxmaxp, rxcsr;
  473. u16 rxfifoadd, txfifoadd;
  474. u8 txtype, txinterval, rxtype, rxinterval;
  475. u8 rxfifosz, txfifosz;
  476. u8 txfunaddr, txhubaddr, txhubport;
  477. u8 rxfunaddr, rxhubaddr, rxhubport;
  478. };
  479. struct musb_context_registers {
  480. u8 power;
  481. u16 intrtxe, intrrxe;
  482. u8 intrusbe;
  483. u16 frame;
  484. u8 index, testmode;
  485. u8 devctl, busctl, misc;
  486. struct musb_csr_regs index_regs[MUSB_C_NUM_EPS];
  487. };
  488. #endif /* NEVER */
  489. #ifdef CONFIG_SSUSB_DRV
  490. struct musb_csr_regs {
  491. /* FIFO registers */
  492. /* u32 txcsr0, txcsr1, txcsr2; */
  493. /* u32 rxcsr0, rxcsr1, rxcsr2; */
  494. #ifdef USE_SSUSB_QMU
  495. u32 txqmuaddr, rxqmuaddr;
  496. #endif
  497. /* u16 txmaxp, txcsr, rxmaxp, rxcsr; */
  498. /* u16 rxfifoadd, txfifoadd; */
  499. /* u8 txtype, txinterval, rxtype, rxinterval; */
  500. /* u8 rxfifosz, txfifosz; */
  501. /* u8 txfunaddr, txhubaddr, txhubport; */
  502. /* u8 rxfunaddr, rxhubaddr, rxhubport; */
  503. };
  504. struct musb_context_registers {
  505. /* u8 power; */
  506. /* u16 intrtxe, intrrxe; */
  507. /* u8 intrusbe; */
  508. /* u16 frame; */
  509. /* u8 index, testmode; */
  510. /* u8 devctl, busctl, misc; */
  511. /* u32 intr_ep; */
  512. /* u32 ep0_csr; */
  513. /* u32 qmu_crs, intr_qmu_done; */
  514. struct musb_csr_regs index_regs[MUSB_C_NUM_EPS];
  515. };
  516. #endif
  517. /*
  518. * struct musb - Driver instance data.
  519. */
  520. struct musb {
  521. /* device lock */
  522. spinlock_t lock;
  523. const struct musb_platform_ops *ops;
  524. struct musb_context_registers context;
  525. irqreturn_t (*isr)(int, void *);
  526. u32 hwvers;
  527. /* this hub status bit is reserved by USB 2.0 and not seen by usbcore */
  528. /* #define MUSB_PORT_STAT_RESUME (1 << 31) */
  529. /* u32 port1_status; */
  530. /* unsigned long rh_timer; */
  531. enum musb_h_ep0_state ep0_stage;
  532. /* bulk traffic normally dedicates endpoint hardware, and each
  533. * direction has its own ring of host side endpoints.
  534. * we try to progress the transfer at the head of each endpoint's
  535. * queue until it completes or NAKs too much; then we try the next
  536. * endpoint.
  537. */
  538. int start_mu3d;
  539. struct ssusb_mtk *ssusb;
  540. struct device *controller;
  541. void __iomem *mac_base;
  542. void __iomem *sif_base;
  543. /* passed down from chip/board specific irq handlers */
  544. u32 int_usb;
  545. u16 int_rx;
  546. u16 int_tx;
  547. struct usb_phy *xceiv;
  548. int irq;
  549. unsigned irq_wake:1;
  550. struct musb_hw_ep endpoints[MUSB_C_NUM_EPS];
  551. /* #define control_ep endpoints */
  552. u16 epmask;
  553. u8 nr_endpoints;
  554. u8 board_mode; /* enum musb_mode */
  555. /* active means connected and not suspended */
  556. unsigned is_active:1; /* maybe some wrong to set to 1, TODO modify it later. yun */
  557. /* is_suspended means USB B_PERIPHERAL suspend */
  558. unsigned is_suspended:1;
  559. /* may_wakeup means remote wakeup is enabled */
  560. unsigned may_wakeup:1;
  561. /* is_self_powered is reported in device status and the
  562. * config descriptor. is_bus_powered means B_PERIPHERAL
  563. * draws some VBUS current; both can be true.
  564. */
  565. unsigned is_self_powered:1;
  566. unsigned is_bus_powered:1;
  567. unsigned set_address:1;
  568. unsigned test_mode:1;
  569. unsigned softconnect:1;
  570. unsigned bU1Enabled:1;
  571. unsigned bU2Enabled:1;
  572. u8 address;
  573. u8 test_mode_nr;
  574. u32 ackpend; /* ep0 We don't maintain Max Packet size in it. */
  575. enum musb_g_ep0_state ep0_state;
  576. struct usb_gadget g; /* the gadget */
  577. struct usb_gadget_driver *gadget_driver; /* its driver */
  578. struct musb_hdrc_config *config;
  579. #ifdef MUSB_CONFIG_PROC_FS
  580. struct proc_dir_entry *proc_entry;
  581. #endif
  582. u32 txfifoadd_offset;
  583. u32 rxfifoadd_offset;
  584. #ifdef CONFIG_DEBUG_FS
  585. struct dentry *debugfs_root;
  586. #endif
  587. unsigned is_clk_on; /* deprecated */
  588. unsigned usb_mode;
  589. unsigned active_ep;
  590. struct work_struct suspend_work;
  591. struct work_struct otg_event_work;
  592. struct delayed_work connection_work;
  593. struct workqueue_struct *wq;
  594. struct wake_lock usb_wakelock;
  595. #ifdef USE_SSUSB_QMU
  596. struct tasklet_struct qmu_done;
  597. u32 qmu_done_intr;
  598. #endif
  599. };
  600. static inline struct musb *gadget_to_musb(struct usb_gadget *g)
  601. {
  602. return container_of(g, struct musb, g);
  603. }
  604. static inline void musb_configure_ep0(struct musb *musb)
  605. {
  606. musb->endpoints[0].max_packet_sz_tx = MUSB_EP0_FIFOSIZE;
  607. musb->endpoints[0].max_packet_sz_rx = MUSB_EP0_FIFOSIZE;
  608. musb->endpoints[0].is_shared_fifo = true;
  609. }
  610. static inline int is_first_entry(const struct list_head *list, const struct list_head *head)
  611. {
  612. return list_is_last(head, list);
  613. }
  614. void musb_dev_on_off(struct musb *musb, int is_on);
  615. int ssusb_gadget_init(struct ssusb_mtk *ssusb);
  616. void ssusb_gadget_exit(struct ssusb_mtk *ssusb);
  617. /***************************** Glue it together *****************************/
  618. extern const char musb_driver_name[];
  619. extern void musb_start(struct musb *musb);
  620. extern void musb_stop(struct musb *musb);
  621. extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src);
  622. extern void musb_read_fifo(struct musb_hw_ep *ep, u16 len, u8 *dst);
  623. extern void musb_load_testpacket(struct musb *);
  624. extern irqreturn_t musb_interrupt(struct musb *);
  625. /* extern void musb_hnp_stop(struct musb *musb); */
  626. static inline void musb_platform_set_vbus(struct musb *musb, int is_on)
  627. {
  628. if (musb->ops->set_vbus)
  629. musb->ops->set_vbus(musb, is_on);
  630. }
  631. static inline void musb_platform_enable(struct musb *musb)
  632. {
  633. if (musb->ops->enable)
  634. musb->ops->enable(musb);
  635. }
  636. static inline void musb_platform_disable(struct musb *musb)
  637. {
  638. if (musb->ops->disable)
  639. musb->ops->disable(musb);
  640. }
  641. static inline int musb_platform_set_mode(struct musb *musb, u8 mode)
  642. {
  643. if (!musb->ops->set_mode)
  644. return 0;
  645. return musb->ops->set_mode(musb, mode);
  646. }
  647. static inline void musb_platform_try_idle(struct musb *musb, unsigned long timeout)
  648. {
  649. if (musb->ops->try_idle)
  650. musb->ops->try_idle(musb, timeout);
  651. }
  652. static inline int musb_platform_get_vbus_status(struct musb *musb)
  653. {
  654. if (!musb->ops->vbus_status)
  655. return 0;
  656. return musb->ops->vbus_status(musb);
  657. }
  658. static inline int musb_platform_init(struct musb *musb)
  659. {
  660. if (!musb->ops->init)
  661. return -EINVAL;
  662. return musb->ops->init(musb);
  663. }
  664. static inline int musb_platform_exit(struct musb *musb)
  665. {
  666. if (!musb->ops->exit)
  667. return -EINVAL;
  668. return musb->ops->exit(musb);
  669. }
  670. /*
  671. * treat SSUSB_OTG_IDPIN as SSUSB_OTG_MANUAL;
  672. */
  673. static inline int is_maual_otg(struct ssusb_mtk *ssusb)
  674. {
  675. struct otg_switch_mtk *otg_switch = &ssusb->otg_switch;
  676. return ((SSUSB_MODE_DRD == ssusb->drv_mode) &&
  677. (SSUSB_OTG_MANUAL == otg_switch->otg_mode)) ||
  678. (SSUSB_OTG_IDPIN == otg_switch->otg_mode);
  679. }
  680. static inline int is_eint_used(enum ssusb_otg_mode otg_mode)
  681. {
  682. return (SSUSB_OTG_CHEINT == otg_mode) || (SSUSB_OTG_IDPIN == otg_mode);
  683. }
  684. static inline int need_vbus_chg_int(struct musb *musb)
  685. {
  686. struct ssusb_mtk *ssusb = musb->ssusb;
  687. struct otg_switch_mtk *otg_switch = &ssusb->otg_switch;
  688. return SSUSB_OTG_IDPIN == otg_switch->otg_mode;
  689. }
  690. bool usb_cable_connected(void);
  691. void mt_usb_disconnect(void);
  692. void mt_usb_connect(void);
  693. void musb_sync_with_bat(struct musb *musb, int usb_state);
  694. /* extern void usb_phy_savecurrent(unsigned int clk_on); */
  695. /* extern void usb_phy_recover(unsigned int clk_on); */
  696. void connection_work(struct work_struct *data);
  697. bool mtk_is_host_mode(void); /* remove later */
  698. u32 get_devinfo_with_index(u32 index);
  699. int ssusb_power_save(struct ssusb_mtk *ssusb);
  700. int ssusb_power_restore(struct ssusb_mtk *ssusb);
  701. void ssusb_otg_iddig_en(struct ssusb_mtk *ssusb);
  702. void ssusb_otg_plug_in(struct ssusb_mtk *ssusb);
  703. void ssusb_otg_plug_out(struct ssusb_mtk *ssusb);
  704. int is_init_host_for_manual_otg(struct ssusb_mtk *ssusb);
  705. int is_ssusb_connected_to_pc(struct ssusb_mtk *ssusb);
  706. void __iomem *get_xhci_base(void);
  707. void ep0_setup(struct musb *musb, struct musb_hw_ep *hw_ep0, const struct musb_fifo_cfg *cfg);
  708. extern void bat_charger_update_usb_state(int usb_state);
  709. extern int bat_charger_type_detection(void);
  710. extern bool upmu_is_chr_det(void);
  711. extern void BATTERY_SetUSBState(int usb_state);
  712. extern void upmu_interrupt_chrdet_int_en(u32 val);
  713. extern u32 upmu_get_rgs_chrdet(void);
  714. #endif