1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Sughosh Ganu <urwithsughosh@gmail.com>
10 #include <dm/ofnode.h>
11 #include <generic-phy.h>
14 #include <asm/arch/da8xx-usb.h>
18 struct clk *clocks; /* clock list */
20 int clock_count; /* number of clock in clock list */
23 static int usb_phy_on(void)
25 unsigned long timeout;
27 clrsetbits_le32(&davinci_syscfg_regs->cfgchip2,
28 (CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN |
29 CFGCHIP2_OTGPWRDN | CFGCHIP2_OTGMODE |
30 CFGCHIP2_REFFREQ | CFGCHIP2_USB1PHYCLKMUX),
31 (CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN |
32 CFGCHIP2_PHY_PLLON | CFGCHIP2_REFFREQ_24MHZ |
33 CFGCHIP2_USB2PHYCLKMUX | CFGCHIP2_USB1SUSPENDM));
35 /* wait until the usb phy pll locks */
36 timeout = get_timer(0);
37 while (get_timer(timeout) < 10) {
38 if (readl(&davinci_syscfg_regs->cfgchip2) & CFGCHIP2_PHYCLKGD)
42 /* USB phy was not turned on */
46 static void usb_phy_off(void)
48 /* Power down the on-chip PHY. */
49 clrsetbits_le32(&davinci_syscfg_regs->cfgchip2,
50 CFGCHIP2_PHY_PLLON | CFGCHIP2_USB1SUSPENDM,
51 CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN |
55 int usb_cpu_init(void)
57 /* enable psc for usb2.0 */
58 lpsc_on(DAVINCI_LPSC_USB20);
60 /* enable psc for usb1.0 */
61 lpsc_on(DAVINCI_LPSC_USB11);
63 /* start the on-chip usb phy and its pll */
70 int usb_cpu_stop(void)
74 /* turn off the usb clock and assert the module reset */
75 lpsc_disable(DAVINCI_LPSC_USB11);
76 lpsc_disable(DAVINCI_LPSC_USB20);
81 int usb_cpu_init_fail(void)
83 return usb_cpu_stop();
86 #if CONFIG_IS_ENABLED(DM_USB)
87 static int ohci_da8xx_probe(struct udevice *dev)
89 struct ohci_regs *regs = (struct ohci_regs *)devfdt_get_addr(dev);
90 struct da8xx_ohci *priv = dev_get_priv(dev);
91 int i, err, ret, clock_nb;
94 priv->clock_count = 0;
95 clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells");
97 priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk),
102 for (i = 0; i < clock_nb; i++) {
103 err = clk_get_by_index(dev, i, &priv->clocks[i]);
107 err = clk_enable(&priv->clocks[i]);
109 dev_err(dev, "failed to enable clock %d\n", i);
110 clk_free(&priv->clocks[i]);
115 } else if (clock_nb != -ENOENT) {
116 dev_err(dev, "failed to get clock phandle(%d)\n", clock_nb);
120 err = usb_cpu_init();
125 err = ohci_register(dev, regs);
132 ret = usb_cpu_stop();
134 dev_err(dev, "failed to shutdown usb phy\n");
137 ret = clk_release_all(priv->clocks, priv->clock_count);
139 dev_err(dev, "failed to disable all clocks\n");
144 static int ohci_da8xx_remove(struct udevice *dev)
146 struct da8xx_ohci *priv = dev_get_priv(dev);
149 ret = ohci_deregister(dev);
153 ret = usb_cpu_stop();
157 return clk_release_all(priv->clocks, priv->clock_count);
160 static const struct udevice_id da8xx_ohci_ids[] = {
161 { .compatible = "ti,da830-ohci" },
165 U_BOOT_DRIVER(ohci_generic) = {
166 .name = "ohci-da8xx",
168 .of_match = da8xx_ohci_ids,
169 .probe = ohci_da8xx_probe,
170 .remove = ohci_da8xx_remove,
171 .ops = &ohci_usb_ops,
172 .priv_auto_alloc_size = sizeof(struct da8xx_ohci),
173 .flags = DM_FLAG_ALLOC_PRIV_DMA,