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#include <asm/io.h>
26#include "davinci.h"
27#include <asm/arch/hardware.h>
28
29
30struct musb_config musb_cfg = {
31 .regs = (struct musb_regs *)MENTOR_USB0_BASE,
32 .timeout = DAVINCI_USB_TIMEOUT,
33 .musb_speed = 0,
34};
35
36
37struct davinci_usb_regs *dregs;
38
39
40
41
42static u8 phy_on(void)
43{
44 u32 timeout;
45#ifdef DAVINCI_DM365EVM
46 u32 val;
47#endif
48
49#ifdef DAVINCI_DM365EVM
50 writel(USBPHY_PHY24MHZ | USBPHY_SESNDEN |
51 USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
52#else
53 writel(USBPHY_SESNDEN | USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
54#endif
55 timeout = musb_cfg.timeout;
56
57#ifdef DAVINCI_DM365EVM
58
59 val = readl(PINMUX4);
60 val &= ~(PINMUX4_USBDRVBUS_BITCLEAR);
61 val |= PINMUX4_USBDRVBUS_BITSET;
62 writel(val, PINMUX4);
63#endif
64 while (timeout--)
65 if (readl(USBPHY_CTL_PADDR) & USBPHY_PHYCLKGD)
66 return 1;
67
68
69 return 0;
70}
71
72
73
74
75static void phy_off(void)
76{
77
78 writel(USBPHY_OSCPDWN | USBPHY_PHYPDWN, USBPHY_CTL_PADDR);
79}
80
81
82
83
84int musb_platform_init(void)
85{
86 u32 revision;
87
88
89#ifndef DAVINCI_DM365EVM
90 enable_vbus();
91#endif
92
93 if (!phy_on())
94 return -1;
95
96
97 dregs = (struct davinci_usb_regs *)DAVINCI_USB0_BASE;
98 writel(1, &dregs->ctrlr);
99 udelay(5000);
100
101
102 revision = readl(&dregs->version);
103 if (!revision)
104 return -1;
105
106
107 writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_RXINT_MASK |
108 DAVINCI_USB_TXINT_MASK , &dregs->intmsksetr);
109 return 0;
110}
111
112
113
114
115void musb_platform_deinit(void)
116{
117
118 phy_off();
119
120
121 writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_TXINT_MASK |
122 DAVINCI_USB_RXINT_MASK , &dregs->intclrr);
123}
124