1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
4 * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
10 #include <generic-phy.h>
12 #include <asm/arch/psc_defs.h>
14 /* USB PHY control register offsets */
15 #define USB_PHY_CTL_UTMI 0x0000
16 #define USB_PHY_CTL_PIPE 0x0004
17 #define USB_PHY_CTL_PARAM_1 0x0008
18 #define USB_PHY_CTL_PARAM_2 0x000c
19 #define USB_PHY_CTL_CLOCK 0x0010
20 #define USB_PHY_CTL_PLL 0x0014
22 #define PHY_OTG_VBUSVLDECTSEL BIT(16)
23 #define PHY_REF_SSP_EN BIT(29)
25 struct keystone_usb_phy {
30 static int keystone_usb_init(struct phy *phy)
34 struct udevice *dev = phy->dev;
35 struct keystone_usb_phy *keystone = dev_get_priv(dev);
37 /* Release USB from reset */
38 rc = psc_enable_module(keystone->psc_domain);
40 debug("Cannot enable USB module");
46 * VBUSVLDEXTSEL has a default value of 1 in BootCfg but shouldn't.
47 * It should always be cleared because our USB PHY has an onchip VBUS
50 val = readl(keystone->reg + USB_PHY_CTL_CLOCK);
51 /* quit selecting the vbusvldextsel by default! */
52 val &= ~PHY_OTG_VBUSVLDECTSEL;
53 writel(val, keystone->reg + USB_PHY_CTL_CLOCK);
58 static int keystone_usb_power_on(struct phy *phy)
61 struct udevice *dev = phy->dev;
62 struct keystone_usb_phy *keystone = dev_get_priv(dev);
64 val = readl(keystone->reg + USB_PHY_CTL_CLOCK);
65 val |= PHY_REF_SSP_EN;
66 writel(val, keystone->reg + USB_PHY_CTL_CLOCK);
71 static int keystone_usb_power_off(struct phy *phy)
74 struct udevice *dev = phy->dev;
75 struct keystone_usb_phy *keystone = dev_get_priv(dev);
77 val = readl(keystone->reg + USB_PHY_CTL_CLOCK);
78 val &= ~PHY_REF_SSP_EN;
79 writel(val, keystone->reg + USB_PHY_CTL_CLOCK);
84 static int keystone_usb_exit(struct phy *phy)
86 struct udevice *dev = phy->dev;
87 struct keystone_usb_phy *keystone = dev_get_priv(dev);
89 if (psc_disable_module(keystone->psc_domain))
90 debug("failed to disable USB module!\n");
95 static int keystone_usb_phy_probe(struct udevice *dev)
98 struct keystone_usb_phy *keystone = dev_get_priv(dev);
100 rc = dev_read_u32(dev, "psc-domain", &keystone->psc_domain);
104 keystone->reg = dev_remap_addr_index(dev, 0);
105 if (!keystone->reg) {
106 pr_err("unable to remap usb phy\n");
112 static const struct udevice_id keystone_usb_phy_ids[] = {
113 { .compatible = "ti,keystone-usbphy" },
117 static struct phy_ops keystone_usb_phy_ops = {
118 .init = keystone_usb_init,
119 .power_on = keystone_usb_power_on,
120 .power_off = keystone_usb_power_off,
121 .exit = keystone_usb_exit,
124 U_BOOT_DRIVER(keystone_usb_phy) = {
125 .name = "keystone_usb_phy",
127 .of_match = keystone_usb_phy_ids,
128 .ops = &keystone_usb_phy_ops,
129 .probe = keystone_usb_phy_probe,
130 .priv_auto_alloc_size = sizeof(struct keystone_usb_phy),