1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com
6 * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
13 #include <generic-phy.h>
17 #define OMAP_USB2_CALIBRATE_FALSE_DISCONNECT BIT(0)
19 #define OMAP_DEV_PHY_PD BIT(0)
20 #define OMAP_USB2_PHY_PD BIT(28)
22 #define AM437X_USB2_PHY_PD BIT(0)
23 #define AM437X_USB2_OTG_PD BIT(1)
24 #define AM437X_USB2_OTGVDET_EN BIT(19)
25 #define AM437X_USB2_OTGSESSEND_EN BIT(20)
27 #define USB2PHY_DISCON_BYP_LATCH BIT(31)
28 #define USB2PHY_ANA_CONFIG1 (0x4c)
30 DECLARE_GLOBAL_DATA_PTR;
32 struct omap_usb2_phy {
33 struct regmap *pwr_regmap;
47 static const struct usb_phy_data omap5_usb2_data = {
48 .label = "omap5_usb2",
50 .mask = OMAP_DEV_PHY_PD,
51 .power_off = OMAP_DEV_PHY_PD,
54 static const struct usb_phy_data dra7x_usb2_data = {
55 .label = "dra7x_usb2",
56 .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
57 .mask = OMAP_DEV_PHY_PD,
58 .power_off = OMAP_DEV_PHY_PD,
61 static const struct usb_phy_data dra7x_usb2_phy2_data = {
62 .label = "dra7x_usb2_phy2",
63 .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
64 .mask = OMAP_USB2_PHY_PD,
65 .power_off = OMAP_USB2_PHY_PD,
68 static const struct usb_phy_data am437x_usb2_data = {
69 .label = "am437x_usb2",
71 .mask = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD |
72 AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN,
73 .power_on = AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN,
74 .power_off = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD,
77 static const struct udevice_id omap_usb2_id_table[] = {
79 .compatible = "ti,omap5-usb2",
80 .data = (ulong)&omap5_usb2_data,
83 .compatible = "ti,dra7x-usb2",
84 .data = (ulong)&dra7x_usb2_data,
87 .compatible = "ti,dra7x-usb2-phy2",
88 .data = (ulong)&dra7x_usb2_phy2_data,
91 .compatible = "ti,am437x-usb2",
92 .data = (ulong)&am437x_usb2_data,
97 static int omap_usb_phy_power(struct phy *usb_phy, bool on)
99 struct udevice *dev = usb_phy->dev;
100 const struct usb_phy_data *data;
101 const struct omap_usb2_phy *phy = dev_get_priv(dev);
105 data = (const struct usb_phy_data *)dev_get_driver_data(dev);
109 rc = regmap_read(phy->pwr_regmap, phy->pwr_reg_offset, &val);
114 val |= data->power_on;
116 val |= data->power_off;
117 rc = regmap_write(phy->pwr_regmap, phy->pwr_reg_offset, val);
124 static int omap_usb2_phy_init(struct phy *usb_phy)
126 struct udevice *dev = usb_phy->dev;
127 struct omap_usb2_phy *priv = dev_get_priv(dev);
130 if (priv->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
133 * Reduce the sensitivity of internal PHY by enabling the
134 * DISCON_BYP_LATCH of the USB2PHY_ANA_CONFIG1 register. This
135 * resolves issues with certain devices which can otherwise
136 * be prone to false disconnects.
139 val = readl(priv->phy_base + USB2PHY_ANA_CONFIG1);
140 val |= USB2PHY_DISCON_BYP_LATCH;
141 writel(val, priv->phy_base + USB2PHY_ANA_CONFIG1);
147 static int omap_usb2_phy_power_on(struct phy *usb_phy)
149 return omap_usb_phy_power(usb_phy, true);
152 static int omap_usb2_phy_power_off(struct phy *usb_phy)
154 return omap_usb_phy_power(usb_phy, false);
157 static int omap_usb2_phy_exit(struct phy *usb_phy)
159 return omap_usb_phy_power(usb_phy, false);
162 struct phy_ops omap_usb2_phy_ops = {
163 .init = omap_usb2_phy_init,
164 .power_on = omap_usb2_phy_power_on,
165 .power_off = omap_usb2_phy_power_off,
166 .exit = omap_usb2_phy_exit,
169 int omap_usb2_phy_probe(struct udevice *dev)
172 struct regmap *regmap;
173 struct omap_usb2_phy *priv = dev_get_priv(dev);
174 const struct usb_phy_data *data;
177 data = (const struct usb_phy_data *)dev_get_driver_data(dev);
181 if (data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
182 priv->phy_base = dev_read_addr_ptr(dev);
186 priv->flags |= OMAP_USB2_CALIBRATE_FALSE_DISCONNECT;
189 regmap = syscon_regmap_lookup_by_phandle(dev, "syscon-phy-power");
190 if (!IS_ERR(regmap)) {
191 priv->pwr_regmap = regmap;
192 rc = dev_read_u32_array(dev, "syscon-phy-power", tmp, 2);
194 printf("couldn't get power reg. offset (err %d)\n", rc);
197 priv->pwr_reg_offset = tmp[1];
200 regmap = syscon_regmap_lookup_by_phandle(dev, "ctrl-module");
201 if (!IS_ERR(regmap)) {
202 priv->pwr_regmap = regmap;
203 priv->pwr_reg_offset = 0;
207 printf("can't get regmap (err %ld)\n", PTR_ERR(regmap));
208 return PTR_ERR(regmap);
211 U_BOOT_DRIVER(omap_usb2_phy) = {
212 .name = "omap_usb2_phy",
214 .of_match = omap_usb2_id_table,
215 .probe = omap_usb2_phy_probe,
216 .ops = &omap_usb2_phy_ops,
217 .priv_auto_alloc_size = sizeof(struct omap_usb2_phy),