1
2
3
4
5
6
7
8
9
10
11
12#include <common.h>
13
14#include "musb_core.h"
15#include <asm/arch/da8xx-usb.h>
16
17
18struct musb_config musb_cfg = {
19 .regs = (struct musb_regs *)DA8XX_USB_OTG_CORE_BASE,
20 .timeout = DA8XX_USB_OTG_TIMEOUT,
21 .musb_speed = 0,
22};
23
24
25
26
27static void enable_vbus(void)
28{
29 u32 value;
30
31
32 value = readl(&davinci_gpio_bank45->dir);
33 writel((value & (~DA8XX_USB_VBUS_GPIO)), &davinci_gpio_bank45->dir);
34
35
36 value = readl(&davinci_gpio_bank45->set_data);
37 writel((value | DA8XX_USB_VBUS_GPIO), &davinci_gpio_bank45->set_data);
38}
39
40
41
42
43
44static u8 phy_on(void)
45{
46 u32 timeout;
47 u32 cfgchip2;
48
49 cfgchip2 = readl(&davinci_syscfg_regs->cfgchip2);
50
51 cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN |
52 CFGCHIP2_OTGMODE | CFGCHIP2_REFFREQ);
53 cfgchip2 |= CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN | CFGCHIP2_PHY_PLLON |
54 CFGCHIP2_REFFREQ_24MHZ;
55
56 writel(cfgchip2, &davinci_syscfg_regs->cfgchip2);
57
58
59 timeout = musb_cfg.timeout;
60 while (timeout--)
61 if (readl(&davinci_syscfg_regs->cfgchip2) & CFGCHIP2_PHYCLKGD)
62 return 1;
63
64
65 return 0;
66}
67
68
69
70
71static void phy_off(void)
72{
73 u32 cfgchip2;
74
75
76
77
78 cfgchip2 = readl(&davinci_syscfg_regs->cfgchip2);
79 cfgchip2 &= ~CFGCHIP2_PHY_PLLON;
80 cfgchip2 |= CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN;
81 writel(cfgchip2, &davinci_syscfg_regs->cfgchip2);
82}
83
84
85
86
87int musb_platform_init(void)
88{
89 u32 revision;
90
91
92 lpsc_on(33);
93
94
95 enable_vbus();
96
97
98 writel(0x1, &da8xx_usb_regs->control);
99 udelay(5000);
100
101
102 if (phy_on() == 0)
103 return -1;
104
105
106 revision = readl(&da8xx_usb_regs->revision);
107 if (revision == 0)
108 return -1;
109
110
111 writel((DA8XX_USB_USBINT_MASK | DA8XX_USB_TXINT_MASK |
112 DA8XX_USB_RXINT_MASK), &da8xx_usb_regs->intmsk_set);
113 return 0;
114}
115
116
117
118
119void musb_platform_deinit(void)
120{
121
122 phy_off();
123
124
125 writel((DA8XX_USB_USBINT_MASK | DA8XX_USB_TXINT_MASK |
126 DA8XX_USB_RXINT_MASK), &da8xx_usb_regs->intmsk_clr);
127 writel(0, &da8xx_usb_regs->eoi);
128}
129