1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Sughosh Ganu <urwithsughosh@gmail.com>
11 #include <dm/device_compat.h>
12 #include <dm/devres.h>
13 #include <dm/ofnode.h>
14 #include <generic-phy.h>
17 #include <asm/arch/da8xx-usb.h>
21 struct clk *clocks; /* clock list */
23 int clock_count; /* number of clock in clock list */
26 static int usb_phy_on(void)
28 unsigned long timeout;
30 clrsetbits_le32(&davinci_syscfg_regs->cfgchip2,
31 (CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN |
32 CFGCHIP2_OTGPWRDN | CFGCHIP2_OTGMODE |
33 CFGCHIP2_REFFREQ | CFGCHIP2_USB1PHYCLKMUX),
34 (CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN |
35 CFGCHIP2_PHY_PLLON | CFGCHIP2_REFFREQ_24MHZ |
36 CFGCHIP2_USB2PHYCLKMUX | CFGCHIP2_USB1SUSPENDM));
38 /* wait until the usb phy pll locks */
39 timeout = get_timer(0);
40 while (get_timer(timeout) < 10) {
41 if (readl(&davinci_syscfg_regs->cfgchip2) & CFGCHIP2_PHYCLKGD)
45 /* USB phy was not turned on */
49 static void usb_phy_off(void)
51 /* Power down the on-chip PHY. */
52 clrsetbits_le32(&davinci_syscfg_regs->cfgchip2,
53 CFGCHIP2_PHY_PLLON | CFGCHIP2_USB1SUSPENDM,
54 CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN |
58 int usb_cpu_init(void)
60 /* enable psc for usb2.0 */
61 lpsc_on(DAVINCI_LPSC_USB20);
63 /* enable psc for usb1.0 */
64 lpsc_on(DAVINCI_LPSC_USB11);
66 /* start the on-chip usb phy and its pll */
73 int usb_cpu_stop(void)
77 /* turn off the usb clock and assert the module reset */
78 lpsc_disable(DAVINCI_LPSC_USB11);
79 lpsc_disable(DAVINCI_LPSC_USB20);
84 int usb_cpu_init_fail(void)
86 return usb_cpu_stop();
89 #if CONFIG_IS_ENABLED(DM_USB)
90 static int ohci_da8xx_probe(struct udevice *dev)
92 struct ohci_regs *regs = dev_read_addr_ptr(dev);
93 struct da8xx_ohci *priv = dev_get_priv(dev);
94 int i, err, ret, clock_nb;
97 priv->clock_count = 0;
98 clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells",
105 priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk),
110 for (i = 0; i < clock_nb; i++) {
111 err = clk_get_by_index(dev, i, &priv->clocks[i]);
115 err = clk_enable(&priv->clocks[i]);
117 dev_err(dev, "failed to enable clock %d\n", i);
118 clk_free(&priv->clocks[i]);
125 err = usb_cpu_init();
130 err = ohci_register(dev, regs);
137 ret = usb_cpu_stop();
139 dev_err(dev, "failed to shutdown usb phy\n");
142 ret = clk_release_all(priv->clocks, priv->clock_count);
144 dev_err(dev, "failed to disable all clocks\n");
149 static int ohci_da8xx_remove(struct udevice *dev)
151 struct da8xx_ohci *priv = dev_get_priv(dev);
154 ret = ohci_deregister(dev);
158 ret = usb_cpu_stop();
162 return clk_release_all(priv->clocks, priv->clock_count);
165 static const struct udevice_id da8xx_ohci_ids[] = {
166 { .compatible = "ti,da830-ohci" },
170 U_BOOT_DRIVER(ohci_generic) = {
171 .name = "ohci-da8xx",
173 .of_match = da8xx_ohci_ids,
174 .probe = ohci_da8xx_probe,
175 .remove = ohci_da8xx_remove,
176 .ops = &ohci_usb_ops,
177 .priv_auto = sizeof(struct da8xx_ohci),
178 .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_OS_PREPARE,