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