1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com
9 #include <asm/global_data.h>
13 #include <generic-phy.h>
17 #include <linux/bitops.h>
18 #include <linux/err.h>
20 #define OMAP_USB2_CALIBRATE_FALSE_DISCONNECT BIT(0)
21 #define OMAP_USB2_DISABLE_CHG_DET BIT(1)
23 #define OMAP_DEV_PHY_PD BIT(0)
24 #define OMAP_USB2_PHY_PD BIT(28)
26 #define AM437X_USB2_PHY_PD BIT(0)
27 #define AM437X_USB2_OTG_PD BIT(1)
28 #define AM437X_USB2_OTGVDET_EN BIT(19)
29 #define AM437X_USB2_OTGSESSEND_EN BIT(20)
31 #define USB2PHY_DISCON_BYP_LATCH BIT(31)
32 #define USB2PHY_ANA_CONFIG1 (0x4c)
34 #define AM654_USB2_OTG_PD BIT(8)
35 #define AM654_USB2_VBUS_DET_EN BIT(5)
36 #define AM654_USB2_VBUSVALID_DET_EN BIT(4)
38 #define USB2PHY_CHRG_DET 0x14
39 #define USB2PHY_USE_CHG_DET_REG BIT(29)
40 #define USB2PHY_DIS_CHG_DET BIT(28)
42 DECLARE_GLOBAL_DATA_PTR;
44 struct omap_usb2_phy {
45 struct regmap *pwr_regmap;
59 static const struct usb_phy_data omap5_usb2_data = {
60 .label = "omap5_usb2",
62 .mask = OMAP_DEV_PHY_PD,
63 .power_off = OMAP_DEV_PHY_PD,
66 static const struct usb_phy_data dra7x_usb2_data = {
67 .label = "dra7x_usb2",
68 .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
69 .mask = OMAP_DEV_PHY_PD,
70 .power_off = OMAP_DEV_PHY_PD,
73 static const struct usb_phy_data dra7x_usb2_phy2_data = {
74 .label = "dra7x_usb2_phy2",
75 .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
76 .mask = OMAP_USB2_PHY_PD,
77 .power_off = OMAP_USB2_PHY_PD,
80 static const struct usb_phy_data am437x_usb2_data = {
81 .label = "am437x_usb2",
83 .mask = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD |
84 AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN,
85 .power_on = AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN,
86 .power_off = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD,
89 static const struct usb_phy_data am654_usb2_data = {
90 .label = "am654_usb2",
91 .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
92 .mask = AM654_USB2_OTG_PD | AM654_USB2_VBUS_DET_EN |
93 AM654_USB2_VBUSVALID_DET_EN,
94 .power_on = AM654_USB2_VBUS_DET_EN | AM654_USB2_VBUSVALID_DET_EN,
95 .power_off = AM654_USB2_OTG_PD,
98 static const struct udevice_id omap_usb2_id_table[] = {
100 .compatible = "ti,omap5-usb2",
101 .data = (ulong)&omap5_usb2_data,
104 .compatible = "ti,dra7x-usb2",
105 .data = (ulong)&dra7x_usb2_data,
108 .compatible = "ti,dra7x-usb2-phy2",
109 .data = (ulong)&dra7x_usb2_phy2_data,
112 .compatible = "ti,am437x-usb2",
113 .data = (ulong)&am437x_usb2_data,
116 .compatible = "ti,am654-usb2",
117 .data = (ulong)&am654_usb2_data,
122 static int omap_usb_phy_power(struct phy *usb_phy, bool on)
124 struct udevice *dev = usb_phy->dev;
125 const struct usb_phy_data *data;
126 const struct omap_usb2_phy *phy = dev_get_priv(dev);
130 data = (const struct usb_phy_data *)dev_get_driver_data(dev);
134 rc = regmap_read(phy->pwr_regmap, phy->pwr_reg_offset, &val);
139 val |= data->power_on;
141 val |= data->power_off;
142 rc = regmap_write(phy->pwr_regmap, phy->pwr_reg_offset, val);
149 static int omap_usb2_phy_init(struct phy *usb_phy)
151 struct udevice *dev = usb_phy->dev;
152 struct omap_usb2_phy *priv = dev_get_priv(dev);
155 if (priv->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
158 * Reduce the sensitivity of internal PHY by enabling the
159 * DISCON_BYP_LATCH of the USB2PHY_ANA_CONFIG1 register. This
160 * resolves issues with certain devices which can otherwise
161 * be prone to false disconnects.
164 val = readl(priv->phy_base + USB2PHY_ANA_CONFIG1);
165 val |= USB2PHY_DISCON_BYP_LATCH;
166 writel(val, priv->phy_base + USB2PHY_ANA_CONFIG1);
169 if (priv->flags & OMAP_USB2_DISABLE_CHG_DET) {
170 val = readl(priv->phy_base + USB2PHY_CHRG_DET);
171 val |= USB2PHY_USE_CHG_DET_REG | USB2PHY_DIS_CHG_DET;
172 writel(val, priv->phy_base + USB2PHY_CHRG_DET);
178 static int omap_usb2_phy_power_on(struct phy *usb_phy)
180 return omap_usb_phy_power(usb_phy, true);
183 static int omap_usb2_phy_power_off(struct phy *usb_phy)
185 return omap_usb_phy_power(usb_phy, false);
188 static int omap_usb2_phy_exit(struct phy *usb_phy)
190 return omap_usb_phy_power(usb_phy, false);
193 struct phy_ops omap_usb2_phy_ops = {
194 .init = omap_usb2_phy_init,
195 .power_on = omap_usb2_phy_power_on,
196 .power_off = omap_usb2_phy_power_off,
197 .exit = omap_usb2_phy_exit,
200 static const struct soc_attr am65x_sr10_soc_devices[] = {
201 { .family = "AM65X", .revision = "SR1.0" },
205 int omap_usb2_phy_probe(struct udevice *dev)
208 struct regmap *regmap;
209 struct omap_usb2_phy *priv = dev_get_priv(dev);
210 const struct usb_phy_data *data;
213 data = (const struct usb_phy_data *)dev_get_driver_data(dev);
217 priv->phy_base = dev_read_addr_ptr(dev);
222 if (data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT)
223 priv->flags |= OMAP_USB2_CALIBRATE_FALSE_DISCONNECT;
226 * AM654x PG1.0 has a silicon bug that D+ is pulled high after
227 * POR, which could cause enumeration failure with some USB hubs.
228 * Disabling the USB2_PHY Charger Detect function will put D+
229 * into the normal state.
231 * Enable this workaround for AM654x PG1.0.
233 if (soc_device_match(am65x_sr10_soc_devices))
234 priv->flags |= OMAP_USB2_DISABLE_CHG_DET;
236 regmap = syscon_regmap_lookup_by_phandle(dev, "syscon-phy-power");
237 if (!IS_ERR(regmap)) {
238 priv->pwr_regmap = regmap;
239 rc = dev_read_u32_array(dev, "syscon-phy-power", tmp, 2);
241 printf("couldn't get power reg. offset (err %d)\n", rc);
244 priv->pwr_reg_offset = tmp[1];
247 regmap = syscon_regmap_lookup_by_phandle(dev, "ctrl-module");
248 if (!IS_ERR(regmap)) {
249 priv->pwr_regmap = regmap;
250 priv->pwr_reg_offset = 0;
254 printf("can't get regmap (err %ld)\n", PTR_ERR(regmap));
255 return PTR_ERR(regmap);
258 U_BOOT_DRIVER(omap_usb2_phy) = {
259 .name = "omap_usb2_phy",
261 .of_match = omap_usb2_id_table,
262 .probe = omap_usb2_phy_probe,
263 .ops = &omap_usb2_phy_ops,
264 .priv_auto = sizeof(struct omap_usb2_phy),