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