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 "am35x.h"
27
28
29struct musb_config musb_cfg = {
30 .regs = (struct musb_regs *)AM35X_USB_OTG_CORE_BASE,
31 .timeout = AM35X_USB_OTG_TIMEOUT,
32 .musb_speed = 0,
33};
34
35
36
37
38static u8 phy_on(void)
39{
40 u32 devconf2;
41 u32 timeout;
42
43 devconf2 = readl(&am35x_scm_general_regs->devconf2);
44
45 devconf2 &= ~(DEVCONF2_RESET | DEVCONF2_PHYPWRDN | DEVCONF2_OTGPWRDN |
46 DEVCONF2_OTGMODE | DEVCONF2_REFFREQ |
47 DEVCONF2_PHY_GPIOMODE);
48 devconf2 |= DEVCONF2_SESENDEN | DEVCONF2_VBDTCTEN | DEVCONF2_PHY_PLLON |
49 DEVCONF2_REFFREQ_13MHZ | DEVCONF2_DATPOL;
50
51 writel(devconf2, &am35x_scm_general_regs->devconf2);
52
53
54 timeout = musb_cfg.timeout;
55 while (timeout--)
56 if (readl(&am35x_scm_general_regs->devconf2) & DEVCONF2_PHYCKGD)
57 return 1;
58
59
60 return 0;
61}
62
63
64
65
66static void phy_off(void)
67{
68 u32 devconf2;
69
70
71
72
73 devconf2 = readl(&am35x_scm_general_regs->devconf2);
74
75 devconf2 &= ~DEVCONF2_PHY_PLLON;
76 devconf2 |= DEVCONF2_PHYPWRDN | DEVCONF2_OTGPWRDN;
77 writel(devconf2, &am35x_scm_general_regs->devconf2);
78}
79
80
81
82
83int musb_platform_init(void)
84{
85 u32 revision;
86 u32 sw_reset;
87
88
89 sw_reset = readl(&am35x_scm_general_regs->ip_sw_reset);
90 sw_reset |= (1 << 0);
91 writel(sw_reset, &am35x_scm_general_regs->ip_sw_reset);
92 sw_reset &= ~(1 << 0);
93 writel(sw_reset, &am35x_scm_general_regs->ip_sw_reset);
94
95
96 writel(0x1, &am35x_usb_regs->control);
97 udelay(5000);
98
99
100 if (phy_on() == 0)
101 return -1;
102
103
104 revision = readl(&am35x_usb_regs->revision);
105 if (revision == 0)
106 return -1;
107
108 return 0;
109}
110
111
112
113
114void musb_platform_deinit(void)
115{
116
117 phy_off();
118}
119
120
121
122
123
124
125
126
127
128__attribute__((weak))
129void read_fifo(u8 ep, u32 length, void *fifo_data)
130{
131 u8 *data = (u8 *)fifo_data;
132 u32 val;
133 int i;
134
135
136 writeb(ep, &musbr->index);
137
138 if (length > 4) {
139 for (i = 0; i < (length >> 2); i++) {
140 val = readl(&musbr->fifox[ep]);
141 memcpy(data, &val, 4);
142 data += 4;
143 }
144 length %= 4;
145 }
146 if (length > 0) {
147 val = readl(&musbr->fifox[ep]);
148 memcpy(data, &val, length);
149 }
150}
151