blob: 034b47932da354b461a2d884fd89aafd524a6faf [file] [log] [blame]
Adam Ford9442e742019-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>
11#include <dm/device-internal.h>
12#include <dm/lists.h>
13#include <asm/arch/hardware.h>
14#include <asm/arch/da8xx-usb.h>
15#include <asm/io.h>
16#include <generic-phy.h>
17
18static int da8xx_usb_phy_power_on(struct phy *phy)
19{
20 unsigned long timeout;
21
22 clrsetbits_le32(&davinci_syscfg_regs->cfgchip2,
23 CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN |
24 CFGCHIP2_OTGMODE | CFGCHIP2_REFFREQ,
25 CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN |
26 CFGCHIP2_PHY_PLLON | CFGCHIP2_REFFREQ_24MHZ);
27
28 /* wait until the usb phy pll locks */
29 timeout = get_timer(0);
30 while (get_timer(timeout) < 10) {
31 if (readl(&davinci_syscfg_regs->cfgchip2) & CFGCHIP2_PHYCLKGD)
32 return 0;
33 }
34
35 debug("Phy was not turned on\n");
36
37 return -ENODEV;
38}
39
40static int da8xx_usb_phy_power_off(struct phy *phy)
41{
42 clrsetbits_le32(&davinci_syscfg_regs->cfgchip2,
43 CFGCHIP2_PHY_PLLON,
44 CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN);
45
46 return 0;
47}
48
49static const struct udevice_id da8xx_phy_ids[] = {
50 { .compatible = "ti,da830-usb-phy" },
51 { }
52};
53
54static struct phy_ops da8xx_phy_ops = {
55 .power_on = da8xx_usb_phy_power_on,
56 .power_off = da8xx_usb_phy_power_off,
57};
58
59U_BOOT_DRIVER(da8xx_phy) = {
60 .name = "da8xx-usb-phy",
61 .id = UCLASS_PHY,
62 .of_match = da8xx_phy_ids,
63 .ops = &da8xx_phy_ops,
64};