blob: d025188eae983d42d8f91cc2a44df4e653d649ee [file] [log] [blame]
Adam Fordfc582632019-07-10 13:59:09 -05001// 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>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Adam Fordfc582632019-07-10 13:59:09 -050012#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
19static 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
41static 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
50static const struct udevice_id da8xx_phy_ids[] = {
51 { .compatible = "ti,da830-usb-phy" },
52 { }
53};
54
55static struct phy_ops da8xx_phy_ops = {
56 .power_on = da8xx_usb_phy_power_on,
57 .power_off = da8xx_usb_phy_power_off,
58};
59
60U_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};