Adam Ford | 9442e74 | 2019-07-10 13:59:09 -0500 | [diff] [blame] | 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 | |
Adam Ford | 9442e74 | 2019-07-10 13:59:09 -0500 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 11 | #include <time.h> |
Adam Ford | 9442e74 | 2019-07-10 13:59:09 -0500 | [diff] [blame] | 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 | }; |