30 #include <linux/module.h>
46 #define USB_REVISION_REG 0x00
47 #define USB_CTRL_REG 0x04
48 #define USB_STAT_REG 0x08
49 #define USB_EMULATION_REG 0x0c
51 #define USB_AUTOREQ_REG 0x14
52 #define USB_SRP_FIX_TIME_REG 0x18
53 #define USB_TEARDOWN_REG 0x1c
54 #define EP_INTR_SRC_REG 0x20
55 #define EP_INTR_SRC_SET_REG 0x24
56 #define EP_INTR_SRC_CLEAR_REG 0x28
57 #define EP_INTR_MASK_REG 0x2c
58 #define EP_INTR_MASK_SET_REG 0x30
59 #define EP_INTR_MASK_CLEAR_REG 0x34
60 #define EP_INTR_SRC_MASKED_REG 0x38
61 #define CORE_INTR_SRC_REG 0x40
62 #define CORE_INTR_SRC_SET_REG 0x44
63 #define CORE_INTR_SRC_CLEAR_REG 0x48
64 #define CORE_INTR_MASK_REG 0x4c
65 #define CORE_INTR_MASK_SET_REG 0x50
66 #define CORE_INTR_MASK_CLEAR_REG 0x54
67 #define CORE_INTR_SRC_MASKED_REG 0x58
69 #define USB_END_OF_INTR_REG 0x60
72 #define AM35X_SOFT_RESET_MASK 1
75 #define AM35X_INTR_USB_SHIFT 16
76 #define AM35X_INTR_USB_MASK (0x1ff << AM35X_INTR_USB_SHIFT)
77 #define AM35X_INTR_DRVVBUS 0x100
78 #define AM35X_INTR_RX_SHIFT 16
79 #define AM35X_INTR_TX_SHIFT 0
80 #define AM35X_TX_EP_MASK 0xffff
81 #define AM35X_RX_EP_MASK 0xfffe
82 #define AM35X_TX_INTR_MASK (AM35X_TX_EP_MASK << AM35X_INTR_TX_SHIFT)
83 #define AM35X_RX_INTR_MASK (AM35X_RX_EP_MASK << AM35X_INTR_RX_SHIFT)
85 #define USB_MENTOR_CORE_OFFSET 0x400
93 #define glue_to_musb(g) platform_get_drvdata(g->musb)
98 static void am35x_musb_enable(
struct musb *
musb)
118 static void am35x_musb_disable(
struct musb *
musb)
129 #define portstate(stmt) stmt
131 static void am35x_musb_set_vbus(
struct musb *
musb,
int is_on)
136 #define POLL_SECONDS 2
140 static void otg_timer(
unsigned long _musb)
156 switch (musb->
xceiv->state) {
177 if (devctl & MUSB_DEVCTL_BDEVICE)
185 spin_unlock_irqrestore(&musb->
lock, flags);
188 static void am35x_musb_try_idle(
struct musb *musb,
unsigned long timeout)
190 static unsigned long last_timer;
205 if (
time_after(last_timer, timeout) && timer_pending(&otg_workaround)) {
209 last_timer = timeout;
217 static irqreturn_t am35x_musb_interrupt(
int irq,
void *hci)
219 struct musb *musb = hci;
245 if (!usbintr && !epintr)
284 WARNING(
"VBUS error workaround (delay coming)\n");
285 }
else if (drvvbus) {
301 drvvbus ?
"on" :
"off",
331 spin_unlock_irqrestore(&musb->
lock, flags);
336 static int am35x_musb_set_mode(
struct musb *musb,
u8 musb_mode)
340 struct omap_musb_board_data *data = plat->
board_data;
344 data->set_mode(musb_mode);
351 static int am35x_musb_init(
struct musb *musb)
355 struct omap_musb_board_data *data = plat->
board_data;
368 if (IS_ERR_OR_NULL(musb->
xceiv))
371 setup_timer(&otg_workaround, otg_timer, (
unsigned long) musb);
381 if (data->set_phy_power)
382 data->set_phy_power(1);
386 musb->
isr = am35x_musb_interrupt;
395 static int am35x_musb_exit(
struct musb *musb)
399 struct omap_musb_board_data *data = plat->
board_data;
404 if (data->set_phy_power)
405 data->set_phy_power(0);
421 if (
likely((0x03 & (
unsigned long) dst) == 0) && len >= 4) {
422 readsl(fifo, dst, len >> 2);
431 for (i = 0; i < (len >> 2); i++) {
432 *(
u32 *) dst = musb_readl(fifo, 0);
438 val = musb_readl(fifo, 0);
444 .init = am35x_musb_init,
445 .exit = am35x_musb_exit,
447 .enable = am35x_musb_enable,
448 .disable = am35x_musb_disable,
450 .set_mode = am35x_musb_set_mode,
451 .try_idle = am35x_musb_try_idle,
453 .set_vbus = am35x_musb_set_vbus,
472 dev_err(&pdev->
dev,
"failed to allocate glue context\n");
479 dev_err(&pdev->
dev,
"failed to allocate musb id\n");
486 dev_err(&pdev->
dev,
"failed to allocate musb device\n");
491 if (IS_ERR(phy_clk)) {
492 dev_err(&pdev->
dev,
"failed to get PHY clock\n");
493 ret = PTR_ERR(phy_clk);
506 dev_err(&pdev->
dev,
"failed to enable PHY clock\n");
512 dev_err(&pdev->
dev,
"failed to enable clock\n");
517 musb->
dev.parent = &pdev->
dev;
518 musb->
dev.dma_mask = &am35x_dmamask;
519 musb->
dev.coherent_dma_mask = am35x_dmamask;
528 platform_set_drvdata(pdev, glue);
533 dev_err(&pdev->
dev,
"failed to add resources\n");
539 dev_err(&pdev->
dev,
"failed to add platform_data\n");
545 dev_err(&pdev->
dev,
"failed to register musb device\n");
578 struct am35x_glue *glue = platform_get_drvdata(pdev);
593 static int am35x_suspend(
struct device *dev)
597 struct omap_musb_board_data *data = plat->
board_data;
600 if (data->set_phy_power)
601 data->set_phy_power(0);
609 static int am35x_resume(
struct device *dev)
613 struct omap_musb_board_data *data = plat->
board_data;
617 if (data->set_phy_power)
618 data->set_phy_power(1);
622 dev_err(dev,
"failed to enable PHY clock\n");
628 dev_err(dev,
"failed to enable clock\n");
637 .resume = am35x_resume,
640 #define DEV_PM_OPS &am35x_pm_ops
642 #define DEV_PM_OPS NULL
646 .probe = am35x_probe,
649 .name =
"musb-am35x",
658 static int __init am35x_init(
void)
664 static void __exit am35x_exit(
void)