colibri_imx6: fix video stdout in default environment
[oweals/u-boot.git] / drivers / phy / phy-da8xx-usb.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Based on the DA8xx "glue layer" code.
4  * Copyright (c) 2008-2019, MontaVista Software, Inc. <source@mvista.com>
5  *
6  * DT support added by: Adam Ford <aford173@gmail.com>
7  */
8
9 #include <common.h>
10 #include <dm.h>
11 #include <log.h>
12 #include <dm/device-internal.h>
13 #include <dm/lists.h>
14 #include <asm/arch/hardware.h>
15 #include <asm/arch/da8xx-usb.h>
16 #include <asm/io.h>
17 #include <generic-phy.h>
18
19 static int da8xx_usb_phy_power_on(struct phy *phy)
20 {
21         unsigned long timeout;
22
23         clrsetbits_le32(&davinci_syscfg_regs->cfgchip2,
24                         CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN |
25                         CFGCHIP2_OTGMODE | CFGCHIP2_REFFREQ,
26                         CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN |
27                         CFGCHIP2_PHY_PLLON | CFGCHIP2_REFFREQ_24MHZ);
28
29         /* wait until the usb phy pll locks */
30         timeout = get_timer(0);
31         while (get_timer(timeout) < 10) {
32                 if (readl(&davinci_syscfg_regs->cfgchip2) & CFGCHIP2_PHYCLKGD)
33                         return 0;
34         }
35
36         debug("Phy was not turned on\n");
37
38         return -ENODEV;
39 }
40
41 static int da8xx_usb_phy_power_off(struct phy *phy)
42 {
43         clrsetbits_le32(&davinci_syscfg_regs->cfgchip2,
44                         CFGCHIP2_PHY_PLLON,
45                         CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN);
46
47         return 0;
48 }
49
50 static const struct udevice_id da8xx_phy_ids[] = {
51         { .compatible = "ti,da830-usb-phy" },
52         { }
53 };
54
55 static struct phy_ops da8xx_phy_ops = {
56         .power_on = da8xx_usb_phy_power_on,
57         .power_off = da8xx_usb_phy_power_off,
58 };
59
60 U_BOOT_DRIVER(da8xx_phy) = {
61         .name   = "da8xx-usb-phy",
62         .id     = UCLASS_PHY,
63         .of_match = da8xx_phy_ids,
64         .ops = &da8xx_phy_ops,
65 };