30 #include <linux/module.h>
48 #define DA8XX_USB_REVISION_REG 0x00
49 #define DA8XX_USB_CTRL_REG 0x04
50 #define DA8XX_USB_STAT_REG 0x08
51 #define DA8XX_USB_EMULATION_REG 0x0c
52 #define DA8XX_USB_MODE_REG 0x10
53 #define DA8XX_USB_AUTOREQ_REG 0x14
54 #define DA8XX_USB_SRP_FIX_TIME_REG 0x18
55 #define DA8XX_USB_TEARDOWN_REG 0x1c
56 #define DA8XX_USB_INTR_SRC_REG 0x20
57 #define DA8XX_USB_INTR_SRC_SET_REG 0x24
58 #define DA8XX_USB_INTR_SRC_CLEAR_REG 0x28
59 #define DA8XX_USB_INTR_MASK_REG 0x2c
60 #define DA8XX_USB_INTR_MASK_SET_REG 0x30
61 #define DA8XX_USB_INTR_MASK_CLEAR_REG 0x34
62 #define DA8XX_USB_INTR_SRC_MASKED_REG 0x38
63 #define DA8XX_USB_END_OF_INTR_REG 0x3c
64 #define DA8XX_USB_GENERIC_RNDIS_EP_SIZE_REG(n) (0x50 + (((n) - 1) << 2))
67 #define DA8XX_SOFT_RESET_MASK 1
69 #define DA8XX_USB_TX_EP_MASK 0x1f
70 #define DA8XX_USB_RX_EP_MASK 0x1e
73 #define DA8XX_INTR_USB_SHIFT 16
74 #define DA8XX_INTR_USB_MASK (0x1ff << DA8XX_INTR_USB_SHIFT)
76 #define DA8XX_INTR_DRVVBUS 0x100
77 #define DA8XX_INTR_RX_SHIFT 8
78 #define DA8XX_INTR_RX_MASK (DA8XX_USB_RX_EP_MASK << DA8XX_INTR_RX_SHIFT)
79 #define DA8XX_INTR_TX_SHIFT 0
80 #define DA8XX_INTR_TX_MASK (DA8XX_USB_TX_EP_MASK << DA8XX_INTR_TX_SHIFT)
82 #define DA8XX_MENTOR_CORE_OFFSET 0x400
84 #define CFGCHIP2 IO_ADDRESS(DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP2_REG)
99 static inline void phy_on(
void)
110 pr_info(
"Waiting for USB PHY clock good...\n");
115 static inline void phy_off(
void)
125 pr_warning(
"USB 1.1 clocked from USB 2.0 PHY -- "
126 "can't power it down\n");
147 static void da8xx_musb_enable(
struct musb *
musb)
166 static void da8xx_musb_disable(
struct musb *
musb)
177 #define portstate(stmt) stmt
179 static void da8xx_musb_set_vbus(
struct musb *
musb,
int is_on)
184 #define POLL_SECONDS 2
188 static void otg_timer(
unsigned long _musb)
204 switch (musb->
xceiv->state) {
248 if (devctl & MUSB_DEVCTL_BDEVICE)
256 spin_unlock_irqrestore(&musb->
lock, flags);
259 static void da8xx_musb_try_idle(
struct musb *musb,
unsigned long timeout)
261 static unsigned long last_timer;
276 if (
time_after(last_timer, timeout) && timer_pending(&otg_workaround)) {
280 last_timer = timeout;
288 static irqreturn_t da8xx_musb_interrupt(
int irq,
void *hci)
290 struct musb *musb = hci;
330 err = musb->
int_usb & USB_INTR_VBUSERROR;
346 WARNING(
"VBUS error workaround (delay coming)\n");
347 }
else if (drvvbus) {
362 drvvbus ?
"on" :
"off",
381 spin_unlock_irqrestore(&musb->
lock, flags);
386 static int da8xx_musb_set_mode(
struct musb *musb,
u8 musb_mode)
409 static int da8xx_musb_init(
struct musb *musb)
423 if (IS_ERR_OR_NULL(musb->
xceiv))
426 setup_timer(&otg_workaround, otg_timer, (
unsigned long)musb);
437 pr_debug(
"DA8xx OTG revision %08x, PHY %03x, control %02x\n",
441 musb->
isr = da8xx_musb_interrupt;
447 static int da8xx_musb_exit(
struct musb *musb)
460 .init = da8xx_musb_init,
461 .exit = da8xx_musb_exit,
463 .enable = da8xx_musb_enable,
464 .disable = da8xx_musb_disable,
466 .set_mode = da8xx_musb_set_mode,
467 .try_idle = da8xx_musb_try_idle,
469 .set_vbus = da8xx_musb_set_vbus,
487 dev_err(&pdev->
dev,
"failed to allocate glue context\n");
494 dev_err(&pdev->
dev,
"failed to allocate musb id\n");
501 dev_err(&pdev->
dev,
"failed to allocate musb device\n");
514 dev_err(&pdev->
dev,
"failed to enable clock\n");
519 musb->
dev.parent = &pdev->
dev;
520 musb->
dev.dma_mask = &da8xx_dmamask;
521 musb->
dev.coherent_dma_mask = da8xx_dmamask;
529 platform_set_drvdata(pdev, glue);
534 dev_err(&pdev->
dev,
"failed to add resources\n");
540 dev_err(&pdev->
dev,
"failed to add platform_data\n");
546 dev_err(&pdev->
dev,
"failed to register musb device\n");
573 struct da8xx_glue *glue = platform_get_drvdata(pdev);
586 .probe = da8xx_probe,
589 .name =
"musb-da8xx",
597 static int __init da8xx_init(
void)
603 static void __exit da8xx_exit(
void)