musb_core.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  23. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  24. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  25. * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  28. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  29. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */
  34. #ifndef __MUSB_CORE_H__
  35. #define __MUSB_CORE_H__
  36. #include <linux/slab.h>
  37. #include <linux/list.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/errno.h>
  40. #include <linux/timer.h>
  41. #include <linux/clk.h>
  42. #include <linux/device.h>
  43. #include <linux/usb/ch9.h>
  44. #include <linux/usb/gadget.h>
  45. #include <linux/usb.h>
  46. #include <linux/usb/otg.h>
  47. #include <linux/usb/musb.h>
  48. #include <linux/wakelock.h>
  49. #include <linux/workqueue.h>
  50. /*#include <mt-plat/battery_common.h>*/
  51. #ifndef CONFIG_MTK_FPGA
  52. #include <mt-plat/charging.h>
  53. #endif
  54. struct musb;
  55. struct musb_hw_ep;
  56. struct musb_ep;
  57. #ifdef CONFIG_MTK_KERNEL_POWER_OFF_CHARGING
  58. #include <mt-plat/mt_boot_common.h>
  59. #endif
  60. extern u32 fake_CDP;
  61. extern struct musb *_mu3d_musb;
  62. #if defined(CONFIG_MTK_SMART_BATTERY)
  63. extern void BATTERY_SetUSBState(int usb_state_value);
  64. extern CHARGER_TYPE mt_get_charger_type(void);
  65. #endif
  66. /* Helper defines for struct musb->hwvers */
  67. #define MUSB_HWVERS_MAJOR(x) ((x >> 10) & 0x1f)
  68. #define MUSB_HWVERS_MINOR(x) (x & 0x3ff)
  69. #define MUSB_HWVERS_RC 0x8000
  70. #define MUSB_HWVERS_1300 0x52C
  71. #define MUSB_HWVERS_1400 0x590
  72. #define MUSB_HWVERS_1800 0x720
  73. #define MUSB_HWVERS_1900 0x784
  74. #define MUSB_HWVERS_2000 0x800
  75. #include "musb_debug.h"
  76. #include "musb_dma.h"
  77. #include "musb_io.h"
  78. #include "musb_regs.h" /* We don't want to use original musb registers any more. */
  79. #include "musb_gadget.h"
  80. #include <linux/usb/hcd.h>
  81. #define USB_GADGET_SUPERSPEED
  82. #define EP_PROFILING
  83. #define MUSB_DRIVER_NAME "musb-hdrc"
  84. #define is_peripheral_enabled(musb) ((musb)->board_mode != MUSB_HOST)
  85. #define is_host_enabled(musb) ((musb)->board_mode != MUSB_PERIPHERAL)
  86. #define is_otg_enabled(musb) ((musb)->board_mode == MUSB_OTG)
  87. /* NOTE: otg and peripheral-only state machines start at B_IDLE.
  88. * OTG or host-only go to A_IDLE when ID is sensed.
  89. */
  90. #define is_peripheral_active(m) (!(m)->is_host)
  91. #define is_host_active(m) ((m)->is_host)
  92. #ifndef CONFIG_HAVE_CLK
  93. /* Dummy stub for clk framework */
  94. #define clk_get(dev, id) NULL
  95. #define clk_put(clock) do {} while (0)
  96. #define clk_enable(clock) do {} while (0)
  97. #define clk_disable(clock) do {} while (0)
  98. #endif
  99. #ifdef CONFIG_PROC_FS
  100. #include <linux/fs.h>
  101. #define MUSB_CONFIG_PROC_FS
  102. #endif
  103. static inline struct usb_hcd *musb_to_hcd(struct musb *musb)
  104. {
  105. return container_of((void *)musb, struct usb_hcd, hcd_priv);
  106. }
  107. static inline struct musb *hcd_to_musb(struct usb_hcd *hcd)
  108. {
  109. return (struct musb *)(hcd->hcd_priv);
  110. }
  111. /****************************** PERIPHERAL ROLE *****************************/
  112. #define is_peripheral_capable() (1)
  113. extern irqreturn_t musb_g_ep0_irq(struct musb *);
  114. extern void musb_g_tx(struct musb *, u8);
  115. extern void musb_g_rx(struct musb *, u8);
  116. extern void musb_g_reset(struct musb *);
  117. extern void musb_g_suspend(struct musb *);
  118. extern void musb_g_resume(struct musb *);
  119. extern void musb_g_wakeup(struct musb *);
  120. extern void musb_g_disconnect(struct musb *);
  121. #ifdef CONFIG_DEBUG_FS
  122. extern unsigned musb_uart_debug;
  123. extern int usb20_phy_init_debugfs(void);
  124. #endif
  125. /****************************** HOST ROLE ***********************************/
  126. #define is_host_capable() (1)
  127. extern irqreturn_t musb_h_ep0_irq(struct musb *);
  128. extern void musb_host_tx(struct musb *, u8);
  129. extern void musb_host_rx(struct musb *, u8);
  130. /****************************** CONSTANTS ********************************/
  131. #ifndef MUSB_C_NUM_EPS
  132. #define MUSB_C_NUM_EPS ((u8)9)
  133. #endif
  134. #ifndef MUSB_MAX_END0_PACKET
  135. #define MUSB_MAX_END0_PACKET ((u16)MUSB_EP0_FIFOSIZE)
  136. #endif
  137. /* USB working mode */
  138. typedef enum {
  139. CABLE_MODE_CHRG_ONLY = 0,
  140. CABLE_MODE_NORMAL,
  141. CABLE_MODE_HOST_ONLY,
  142. CABLE_MODE_MAX
  143. } CABLE_MODE;
  144. typedef enum {
  145. USB_SUSPEND = 0,
  146. USB_UNCONFIGURED,
  147. USB_CONFIGURED
  148. } usb_state_enum;
  149. /* host side ep0 states */
  150. enum musb_h_ep0_state {
  151. MUSB_EP0_IDLE,
  152. MUSB_EP0_START, /* expect ack of setup */
  153. MUSB_EP0_IN, /* expect IN DATA */
  154. MUSB_EP0_OUT, /* expect ack of OUT DATA */
  155. MUSB_EP0_STATUS, /* expect ack of STATUS */
  156. } __packed;
  157. /* peripheral side ep0 states */
  158. enum musb_g_ep0_state {
  159. MUSB_EP0_STAGE_IDLE, /* idle, waiting for SETUP */
  160. MUSB_EP0_STAGE_SETUP, /* received SETUP */
  161. MUSB_EP0_STAGE_TX, /* IN data */
  162. MUSB_EP0_STAGE_RX, /* OUT data */
  163. MUSB_EP0_STAGE_STATUSIN, /* (after OUT data) */
  164. MUSB_EP0_STAGE_STATUSOUT, /* (after IN data) */
  165. MUSB_EP0_STAGE_ACKWAIT, /* after zlp, before statusin */
  166. } __packed;
  167. /*
  168. * OTG protocol constants. See USB OTG 1.3 spec,
  169. * sections 5.5 "Device Timings" and 6.6.5 "Timers".
  170. */
  171. #define OTG_TIME_A_WAIT_VRISE 100 /* msec (max) */
  172. #define OTG_TIME_A_WAIT_BCON 1100 /* min 1 second */
  173. #define OTG_TIME_A_AIDL_BDIS 200 /* min 200 msec */
  174. #define OTG_TIME_B_ASE0_BRST 100 /* min 3.125 ms */
  175. /*************************** REGISTER ACCESS ********************************/
  176. /* Endpoint registers (other than dynfifo setup) can be accessed either
  177. * directly with the "flat" model, or after setting up an index register.
  178. */
  179. #if defined(CONFIG_ARCH_DAVINCI) || defined(CONFIG_SOC_OMAP2430) \
  180. || defined(CONFIG_SOC_OMAP3430) || defined(CONFIG_BLACKFIN) \
  181. || defined(CONFIG_ARCH_OMAP4)
  182. /* REVISIT indexed access seemed to
  183. * misbehave (on DaVinci) for at least peripheral IN ...
  184. */
  185. #define MUSB_FLAT_REG
  186. #endif
  187. /* TUSB mapping: "flat" plus ep0 special cases */
  188. #if defined(CONFIG_USB_TUSB6010)
  189. #define musb_ep_select(_mbase, _epnum) \
  190. musb_writeb((_mbase), MUSB_INDEX, (_epnum))
  191. #define MUSB_EP_OFFSET MUSB_TUSB_OFFSET
  192. /* "flat" mapping: each endpoint has its own i/o address */
  193. #elif defined(MUSB_FLAT_REG)
  194. #define musb_ep_select(_mbase, _epnum) (((void)(_mbase)), ((void)(_epnum)))
  195. #define MUSB_EP_OFFSET MUSB_FLAT_OFFSET
  196. /* "indexed" mapping: INDEX register controls register bank select */
  197. #else
  198. #define musb_ep_select(_mbase, _epnum) \
  199. musb_writeb((_mbase), MUSB_INDEX, (_epnum))
  200. #define MUSB_EP_OFFSET MUSB_INDEXED_OFFSET
  201. #endif
  202. #define SSUSB_EP_TXCR0_OFFSET(_epnum, _offset) \
  203. (U3D_TX1CSR0 + ((_epnum - 1)*0x10) + (_offset))
  204. #define SSUSB_EP_TXCR1_OFFSET(_epnum, _offset) \
  205. (U3D_TX1CSR1 + ((_epnum - 1)*0x10) + (_offset))
  206. #define SSUSB_EP_TXCR2_OFFSET(_epnum, _offset) \
  207. (U3D_TX1CSR2 + ((_epnum - 1)*0x10) + (_offset))
  208. #define SSUSB_EP_TXMAXP_OFFSET(_epnum, _offset) \
  209. (U3D_TX1CSR0 + ((_epnum - 1)*0x10) + (_offset))
  210. #define SSUSB_EP_RXCR0_OFFSET(_epnum, _offset) \
  211. (U3D_RX1CSR0 + ((_epnum - 1)*0x10) + (_offset))
  212. #define SSUSB_EP_RXCR1_OFFSET(_epnum, _offset) \
  213. (U3D_RX1CSR1 + ((_epnum - 1)*0x10) + (_offset))
  214. #define SSUSB_EP_RXCR2_OFFSET(_epnum, _offset) \
  215. (U3D_RX1CSR2 + ((_epnum - 1)*0x10) + (_offset))
  216. #define SSUSB_EP_RXCR3_OFFSET(_epnum, _offset) \
  217. (U3D_RX1CSR3 + ((_epnum - 1)*0x10) + (_offset))
  218. /****************************** FUNCTIONS ********************************/
  219. #define MUSB_HST_MODE(_musb)\
  220. { (_musb)->is_host = true; }
  221. #define MUSB_DEV_MODE(_musb) \
  222. { (_musb)->is_host = false; }
  223. #define test_devctl_hst_mode(_x) \
  224. (musb_readb((_x)->mregs, MUSB_DEVCTL)&MUSB_DEVCTL_HM)
  225. #define MUSB_MODE(musb) ((musb)->is_host ? "Host" : "Peripheral")
  226. /******************************** TYPES *************************************/
  227. /**
  228. * struct musb_platform_ops - Operations passed to musb_core by HW glue layer
  229. * @init: turns on clocks, sets up platform-specific registers, etc
  230. * @exit: undoes @init
  231. * @set_mode: forcefully changes operating mode
  232. * @try_ilde: tries to idle the IP
  233. * @vbus_status: returns vbus status if possible
  234. * @set_vbus: forces vbus status
  235. * @adjust_channel_params: pre check for standard dma channel_program func
  236. */
  237. struct musb_platform_ops {
  238. int (*init)(struct musb *musb);
  239. int (*exit)(struct musb *musb);
  240. void (*enable)(struct musb *musb);
  241. void (*disable)(struct musb *musb);
  242. int (*set_mode)(struct musb *musb, u8 mode);
  243. void (*try_idle)(struct musb *musb, unsigned long timeout);
  244. int (*vbus_status)(struct musb *musb);
  245. void (*set_vbus)(struct musb *musb, int on);
  246. int (*adjust_channel_params)(struct dma_channel *channel,
  247. u16 packet_sz, u8 *mode, dma_addr_t *dma_addr, u32 *len);
  248. };
  249. /*
  250. * struct musb_hw_ep - endpoint hardware (bidirectional)
  251. *
  252. * Ordered slightly for better cacheline locality.
  253. */
  254. struct musb_hw_ep {
  255. struct musb *musb;
  256. void __iomem *fifo;
  257. void __iomem *regs;
  258. /* For ssusb+ */
  259. void __iomem *addr_txcsr0;
  260. void __iomem *addr_txcsr1;
  261. void __iomem *addr_txcsr2;
  262. /* void __iomem *addr_txmaxpktsz; */
  263. void __iomem *addr_rxcsr0;
  264. void __iomem *addr_rxcsr1;
  265. void __iomem *addr_rxcsr2;
  266. void __iomem *addr_rxcsr3;
  267. void __iomem *addr_rxmaxpktsz;
  268. /* For ssusb- */
  269. #if defined(CONFIG_USB_MUSB_TUSB6010) || \
  270. defined(CONFIG_USB_MUSB_TUSB6010_MODULE)
  271. void __iomem *conf;
  272. #endif
  273. /* index in musb->endpoints[] */
  274. u8 epnum;
  275. /* hardware configuration, possibly dynamic */
  276. bool is_shared_fifo;
  277. /* bool tx_double_buffered; */
  278. /* bool rx_double_buffered; */
  279. u16 max_packet_sz_tx;
  280. u16 max_packet_sz_rx;
  281. /* For ssusb+ */
  282. u32 fifoaddr_tx;
  283. u32 fifoaddr_rx;
  284. u8 mult_tx;
  285. u8 mult_rx;
  286. u8 interval_tx;
  287. u8 interval_rx;
  288. /* For ssusb- */
  289. struct dma_channel *tx_channel;
  290. struct dma_channel *rx_channel;
  291. #if defined(CONFIG_USB_MUSB_TUSB6010) || \
  292. defined(CONFIG_USB_MUSB_TUSB6010_MODULE)
  293. /* TUSB has "asynchronous" and "synchronous" dma modes */
  294. dma_addr_t fifo_async;
  295. dma_addr_t fifo_sync;
  296. void __iomem *fifo_sync_va;
  297. #endif
  298. void __iomem *target_regs;
  299. /* currently scheduled peripheral endpoint */
  300. struct musb_qh *in_qh;
  301. struct musb_qh *out_qh;
  302. u8 rx_reinit;
  303. u8 tx_reinit;
  304. /* peripheral side */
  305. struct musb_ep ep_in; /* TX */
  306. struct musb_ep ep_out; /* RX */
  307. };
  308. static inline struct musb_request *next_in_request(struct musb_hw_ep *hw_ep)
  309. {
  310. return next_request(&hw_ep->ep_in);
  311. }
  312. static inline struct musb_request *next_out_request(struct musb_hw_ep *hw_ep)
  313. {
  314. return next_request(&hw_ep->ep_out);
  315. }
  316. #ifdef NEVER
  317. struct musb_csr_regs {
  318. /* FIFO registers */
  319. u16 txmaxp, txcsr, rxmaxp, rxcsr;
  320. u16 rxfifoadd, txfifoadd;
  321. u8 txtype, txinterval, rxtype, rxinterval;
  322. u8 rxfifosz, txfifosz;
  323. u8 txfunaddr, txhubaddr, txhubport;
  324. u8 rxfunaddr, rxhubaddr, rxhubport;
  325. };
  326. struct musb_context_registers {
  327. u8 power;
  328. u16 intrtxe, intrrxe;
  329. u8 intrusbe;
  330. u16 frame;
  331. u8 index, testmode;
  332. u8 devctl, busctl, misc;
  333. struct musb_csr_regs index_regs[MUSB_C_NUM_EPS];
  334. };
  335. #endif /* NEVER */
  336. #ifdef CONFIG_USB_MU3D_DRV
  337. struct musb_csr_regs {
  338. /* FIFO registers */
  339. /* u32 txcsr0, txcsr1, txcsr2; */
  340. /* u32 rxcsr0, rxcsr1, rxcsr2; */
  341. #ifdef USE_SSUSB_QMU
  342. u32 txqmuaddr, rxqmuaddr;
  343. #endif
  344. /* u16 txmaxp, txcsr, rxmaxp, rxcsr; */
  345. /* u16 rxfifoadd, txfifoadd; */
  346. /* u8 txtype, txinterval, rxtype, rxinterval; */
  347. /* u8 rxfifosz, txfifosz; */
  348. /* u8 txfunaddr, txhubaddr, txhubport; */
  349. /* u8 rxfunaddr, rxhubaddr, rxhubport; */
  350. };
  351. struct musb_context_registers {
  352. /* u8 power; */
  353. /* u16 intrtxe, intrrxe; */
  354. /* u8 intrusbe; */
  355. /* u16 frame; */
  356. /* u8 index, testmode; */
  357. /* u8 devctl, busctl, misc; */
  358. /* u32 intr_ep; */
  359. /* u32 ep0_csr; */
  360. /* u32 qmu_crs, intr_qmu_done; */
  361. struct musb_csr_regs index_regs[MUSB_C_NUM_EPS];
  362. };
  363. #endif
  364. /*
  365. * struct musb - Driver instance data.
  366. */
  367. struct musb {
  368. /* device lock */
  369. spinlock_t lock;
  370. struct semaphore musb_lock;
  371. const struct musb_platform_ops *ops;
  372. struct musb_context_registers context;
  373. irqreturn_t (*isr)(int, void *);
  374. struct work_struct irq_work;
  375. u32 hwvers;
  376. /* this hub status bit is reserved by USB 2.0 and not seen by usbcore */
  377. #define MUSB_PORT_STAT_RESUME (1 << 31)
  378. u32 port1_status;
  379. unsigned long rh_timer;
  380. enum musb_h_ep0_state ep0_stage;
  381. /* bulk traffic normally dedicates endpoint hardware, and each
  382. * direction has its own ring of host side endpoints.
  383. * we try to progress the transfer at the head of each endpoint's
  384. * queue until it completes or NAKs too much; then we try the next
  385. * endpoint.
  386. */
  387. struct musb_hw_ep *bulk_ep;
  388. struct list_head control; /* of musb_qh */
  389. struct list_head in_bulk; /* of musb_qh */
  390. struct list_head out_bulk; /* of musb_qh */
  391. struct timer_list otg_timer;
  392. struct notifier_block nb;
  393. struct dma_controller *dma_controller;
  394. struct device *controller;
  395. void __iomem *ctrl_base;
  396. void __iomem *mregs;
  397. #if defined(CONFIG_USB_MUSB_TUSB6010) || \
  398. defined(CONFIG_USB_MUSB_TUSB6010_MODULE)
  399. dma_addr_t async;
  400. dma_addr_t sync;
  401. void __iomem *sync_va;
  402. #endif
  403. /* passed down from chip/board specific irq handlers */
  404. u32 int_usb;
  405. u16 int_rx;
  406. u16 int_tx;
  407. struct usb_phy *xceiv;
  408. int nIrq;
  409. unsigned irq_wake:1;
  410. struct musb_hw_ep endpoints[MUSB_C_NUM_EPS];
  411. #define control_ep endpoints
  412. #define VBUSERR_RETRY_COUNT 3
  413. u16 vbuserr_retry;
  414. u16 epmask;
  415. u8 nr_endpoints;
  416. u8 board_mode; /* enum musb_mode */
  417. int (*board_set_power)(int state);
  418. u8 min_power; /* vbus for periph, in mA/2 */
  419. bool is_host;
  420. int a_wait_bcon; /* VBUS timeout in msecs */
  421. unsigned long idle_timeout; /* Next timeout in jiffies */
  422. /* active means connected and not suspended */
  423. unsigned is_active:1;
  424. unsigned is_multipoint:1;
  425. unsigned ignore_disconnect:1; /* during bus resets */
  426. unsigned hb_iso_rx:1; /* high bandwidth iso rx? */
  427. unsigned hb_iso_tx:1; /* high bandwidth iso tx? */
  428. unsigned dyn_fifo:1; /* dynamic FIFO supported? */
  429. unsigned bulk_split:1;
  430. #define can_bulk_split(musb, type) \
  431. (((type) == USB_ENDPOINT_XFER_BULK) && (musb)->bulk_split)
  432. unsigned bulk_combine:1;
  433. #define can_bulk_combine(musb, type) \
  434. (((type) == USB_ENDPOINT_XFER_BULK) && (musb)->bulk_combine)
  435. /* is_suspended means USB B_PERIPHERAL suspend */
  436. unsigned is_suspended:1;
  437. /* may_wakeup means remote wakeup is enabled */
  438. unsigned may_wakeup:1;
  439. /* is_self_powered is reported in device status and the
  440. * config descriptor. is_bus_powered means B_PERIPHERAL
  441. * draws some VBUS current; both can be true.
  442. */
  443. unsigned is_self_powered:1;
  444. unsigned is_bus_powered:1;
  445. unsigned set_address:1;
  446. unsigned test_mode:1;
  447. unsigned softconnect:1;
  448. u8 address;
  449. u8 test_mode_nr;
  450. bool in_ipo_off;
  451. u32 ackpend; /* ep0 *//*We don't maintain Max Packet size in it. */
  452. enum musb_g_ep0_state ep0_state;
  453. struct usb_gadget g; /* the gadget */
  454. struct usb_gadget_driver *gadget_driver; /* its driver */
  455. /*
  456. * FIXME: Remove this flag.
  457. *
  458. * This is only added to allow Blackfin to work
  459. * with current driver. For some unknown reason
  460. * Blackfin doesn't work with double buffering
  461. * and that's enabled by default.
  462. *
  463. * We added this flag to forcefully disable double
  464. * buffering until we get it working.
  465. */
  466. unsigned double_buffer_not_ok:1;
  467. struct musb_hdrc_config *config;
  468. #ifdef MUSB_CONFIG_PROC_FS
  469. struct proc_dir_entry *proc_entry;
  470. #endif
  471. u32 txfifoadd_offset;
  472. u32 rxfifoadd_offset;
  473. #ifdef CONFIG_DEBUG_FS
  474. struct dentry *debugfs_root;
  475. #endif
  476. unsigned is_clk_on;
  477. unsigned usb_mode;
  478. unsigned active_ep;
  479. struct work_struct suspend_work;
  480. struct wake_lock usb_wakelock;
  481. struct delayed_work connection_work;
  482. struct delayed_work check_ltssm_work;
  483. #ifndef CONFIG_USBIF_COMPLIANCE
  484. struct delayed_work reconnect_work;
  485. #endif
  486. #ifdef EP_PROFILING
  487. struct delayed_work ep_prof_work;
  488. #endif
  489. #ifdef USE_SSUSB_QMU
  490. struct tasklet_struct qmu_done;
  491. u32 qmu_done_intr;
  492. struct tasklet_struct error_recovery;
  493. u32 error_wQmuVal;
  494. u32 error_wErrVal;
  495. #endif
  496. };
  497. static inline struct musb *gadget_to_musb(struct usb_gadget *g)
  498. {
  499. return container_of(g, struct musb, g);
  500. }
  501. #ifdef CONFIG_BLACKFIN
  502. static inline int musb_read_fifosize(struct musb *musb, struct musb_hw_ep *hw_ep, u8 epnum)
  503. {
  504. musb->nr_endpoints++;
  505. musb->epmask |= (1 << epnum);
  506. if (epnum < 5) {
  507. hw_ep->max_packet_sz_tx = 128;
  508. hw_ep->max_packet_sz_rx = 128;
  509. } else {
  510. hw_ep->max_packet_sz_tx = 1024;
  511. hw_ep->max_packet_sz_rx = 1024;
  512. }
  513. hw_ep->is_shared_fifo = false;
  514. return 0;
  515. }
  516. static inline void musb_configure_ep0(struct musb *musb)
  517. {
  518. musb->endpoints[0].max_packet_sz_tx = MUSB_EP0_FIFOSIZE;
  519. musb->endpoints[0].max_packet_sz_rx = MUSB_EP0_FIFOSIZE;
  520. musb->endpoints[0].is_shared_fifo = true;
  521. }
  522. #else
  523. static inline int musb_read_fifosize(struct musb *musb, struct musb_hw_ep *hw_ep, u8 epnum)
  524. {
  525. void __iomem *mbase = musb->mregs;
  526. u8 reg = 0;
  527. /* read from core using indexed model */
  528. reg = musb_readb(mbase, MUSB_EP_OFFSET(epnum, MUSB_FIFOSIZE));
  529. /* 0's returned when no more endpoints */
  530. if (!reg)
  531. return -ENODEV;
  532. musb->nr_endpoints++;
  533. musb->epmask |= (1 << epnum);
  534. hw_ep->max_packet_sz_tx = 1 << (reg & 0x0f);
  535. /* shared TX/RX FIFO? */
  536. if ((reg & 0xf0) == 0xf0) {
  537. hw_ep->max_packet_sz_rx = hw_ep->max_packet_sz_tx;
  538. hw_ep->is_shared_fifo = true;
  539. } else {
  540. hw_ep->max_packet_sz_rx = 1 << ((reg & 0xf0) >> 4);
  541. hw_ep->is_shared_fifo = false;
  542. }
  543. return 0;
  544. }
  545. static inline void musb_configure_ep0(struct musb *musb)
  546. {
  547. musb->endpoints[0].max_packet_sz_tx = MUSB_EP0_FIFOSIZE;
  548. musb->endpoints[0].max_packet_sz_rx = MUSB_EP0_FIFOSIZE;
  549. musb->endpoints[0].is_shared_fifo = true;
  550. }
  551. #endif /* CONFIG_BLACKFIN */
  552. /***************************** Glue it together *****************************/
  553. extern const char musb_driver_name[];
  554. extern void musb_start(struct musb *musb);
  555. extern void musb_stop(struct musb *musb);
  556. extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src);
  557. extern void musb_read_fifo(struct musb_hw_ep *ep, u16 len, u8 *dst);
  558. extern void musb_load_testpacket(struct musb *);
  559. extern irqreturn_t musb_interrupt(struct musb *);
  560. extern void musb_hnp_stop(struct musb *musb);
  561. static inline void musb_platform_set_vbus(struct musb *musb, int is_on)
  562. {
  563. if (musb->ops->set_vbus)
  564. musb->ops->set_vbus(musb, is_on);
  565. }
  566. static inline void musb_platform_enable(struct musb *musb)
  567. {
  568. if (musb->ops->enable)
  569. musb->ops->enable(musb);
  570. }
  571. static inline void musb_platform_disable(struct musb *musb)
  572. {
  573. if (musb->ops->disable)
  574. musb->ops->disable(musb);
  575. }
  576. static inline int musb_platform_set_mode(struct musb *musb, u8 mode)
  577. {
  578. if (!musb->ops->set_mode)
  579. return 0;
  580. return musb->ops->set_mode(musb, mode);
  581. }
  582. static inline void musb_platform_try_idle(struct musb *musb, unsigned long timeout)
  583. {
  584. if (musb->ops->try_idle)
  585. musb->ops->try_idle(musb, timeout);
  586. }
  587. static inline int musb_platform_get_vbus_status(struct musb *musb)
  588. {
  589. if (!musb->ops->vbus_status)
  590. return 0;
  591. return musb->ops->vbus_status(musb);
  592. }
  593. static inline int musb_platform_init(struct musb *musb)
  594. {
  595. if (!musb->ops->init)
  596. return -EINVAL;
  597. return musb->ops->init(musb);
  598. }
  599. static inline int musb_platform_exit(struct musb *musb)
  600. {
  601. if (!musb->ops->exit)
  602. return -EINVAL;
  603. return musb->ops->exit(musb);
  604. }
  605. extern bool usb_cable_connected(void);
  606. extern void usb_phy_savecurrent(unsigned int clk_on);
  607. extern void usb_phy_recover(unsigned int clk_on);
  608. extern void usb_fake_powerdown(unsigned int clk_on);
  609. extern void connection_work(struct work_struct *data);
  610. extern void check_ltssm_work(struct work_struct *data);
  611. #ifndef CONFIG_USBIF_COMPLIANCE
  612. extern void reconnect_work(struct work_struct *data);
  613. extern struct timespec get_connect_timestamp(void);
  614. #else /*CONFIG_USBIF_COMPLIANCE */
  615. extern void init_connection_work(void);
  616. extern void init_check_ltssm_work(void);
  617. extern void Charger_Detect_En(bool enable);
  618. #endif /*CONFIG_USBIF_COMPLIANCE */
  619. extern void musb_sync_with_bat(struct musb *musb, int usb_state);
  620. #ifdef CONFIG_MTK_UART_USB_SWITCH
  621. extern bool in_uart_mode;
  622. extern ssize_t musb_portmode_show(struct device *dev, struct device_attribute *attr, char *buf);
  623. extern ssize_t musb_portmode_store(struct device *dev, struct device_attribute *attr,
  624. const char *buf, size_t count);
  625. extern ssize_t musb_tx_show(struct device *dev, struct device_attribute *attr, char *buf);
  626. extern ssize_t musb_tx_store(struct device *dev, struct device_attribute *attr, const char *buf,
  627. size_t count);
  628. extern ssize_t musb_rx_show(struct device *dev, struct device_attribute *attr, char *buf);
  629. extern ssize_t musb_uart_path_show(struct device *dev, struct device_attribute *attr, char *buf);
  630. extern bool usb_phy_check_in_uart_mode(void);
  631. extern void usb_phy_switch_to_uart(void);
  632. #endif /*CONFIG_MTK_UART_USB_SWITCH */
  633. extern ssize_t musb_cmode_show(struct device *dev, struct device_attribute *attr, char *buf);
  634. extern ssize_t musb_cmode_store(struct device *dev, struct device_attribute *attr, const char *buf,
  635. size_t count);
  636. extern void usb20_pll_settings(bool host, bool forceOn);
  637. #if defined(FOR_BRING_UP) || !defined(CONFIG_MTK_SMART_BATTERY)
  638. /* implement static function in mt_usb.c */
  639. #else
  640. extern bool upmu_is_chr_det(void);
  641. extern u32 upmu_get_rgs_chrdet(void);
  642. #endif
  643. #ifdef CONFIG_USB_MTK_DUALMODE
  644. extern bool mtk_is_host_mode(void);
  645. extern void mtk_unload_xhci_on_ipo(void);
  646. extern void switch_int_to_host_and_mask(void);
  647. extern void switch_int_to_host(void);
  648. #else
  649. static inline int mtk_is_host_mode(void)
  650. {
  651. return 0;
  652. }
  653. #endif
  654. #ifdef CONFIG_USB_C_SWITCH
  655. extern int typec_switch_usb_disconnect(void *data);
  656. extern int typec_switch_usb_connect(void *data);
  657. #endif
  658. #endif /* __MUSB_CORE_H__ */