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>
16 #include <linux/bitops.h>
17 #include <linux/err.h>
19 #define OMAP_USB2_CALIBRATE_FALSE_DISCONNECT BIT(0)
20 #define OMAP_USB2_DISABLE_CHG_DET BIT(1)
22 #define OMAP_DEV_PHY_PD BIT(0)
23 #define OMAP_USB2_PHY_PD BIT(28)
25 #define AM437X_USB2_PHY_PD BIT(0)
26 #define AM437X_USB2_OTG_PD BIT(1)
27 #define AM437X_USB2_OTGVDET_EN BIT(19)
28 #define AM437X_USB2_OTGSESSEND_EN BIT(20)
30 #define USB2PHY_DISCON_BYP_LATCH BIT(31)
31 #define USB2PHY_ANA_CONFIG1 (0x4c)
33 #define AM654_USB2_OTG_PD BIT(8)
34 #define AM654_USB2_VBUS_DET_EN BIT(5)
35 #define AM654_USB2_VBUSVALID_DET_EN BIT(4)
37 #define USB2PHY_CHRG_DET 0x14
38 #define USB2PHY_USE_CHG_DET_REG BIT(29)
39 #define USB2PHY_DIS_CHG_DET BIT(28)
41 DECLARE_GLOBAL_DATA_PTR;
43 struct omap_usb2_phy {
44 struct regmap *pwr_regmap;
58 static const struct usb_phy_data omap5_usb2_data = {
59 .label = "omap5_usb2",
61 .mask = OMAP_DEV_PHY_PD,
62 .power_off = OMAP_DEV_PHY_PD,
65 static const struct usb_phy_data dra7x_usb2_data = {
66 .label = "dra7x_usb2",
67 .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
68 .mask = OMAP_DEV_PHY_PD,
69 .power_off = OMAP_DEV_PHY_PD,
72 static const struct usb_phy_data dra7x_usb2_phy2_data = {
73 .label = "dra7x_usb2_phy2",
74 .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
75 .mask = OMAP_USB2_PHY_PD,
76 .power_off = OMAP_USB2_PHY_PD,
79 static const struct usb_phy_data am437x_usb2_data = {
80 .label = "am437x_usb2",
82 .mask = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD |
83 AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN,
84 .power_on = AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN,
85 .power_off = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD,
88 static const struct usb_phy_data am654_usb2_data = {
89 .label = "am654_usb2",
90 .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
91 .mask = AM654_USB2_OTG_PD | AM654_USB2_VBUS_DET_EN |
92 AM654_USB2_VBUSVALID_DET_EN,
93 .power_on = AM654_USB2_VBUS_DET_EN | AM654_USB2_VBUSVALID_DET_EN,
94 .power_off = AM654_USB2_OTG_PD,
97 static const struct udevice_id omap_usb2_id_table[] = {
99 .compatible = "ti,omap5-usb2",
100 .data = (ulong)&omap5_usb2_data,
103 .compatible = "ti,dra7x-usb2",
104 .data = (ulong)&dra7x_usb2_data,
107 .compatible = "ti,dra7x-usb2-phy2",
108 .data = (ulong)&dra7x_usb2_phy2_data,
111 .compatible = "ti,am437x-usb2",
112 .data = (ulong)&am437x_usb2_data,
115 .compatible = "ti,am654-usb2",
116 .data = (ulong)&am654_usb2_data,
121 static int omap_usb_phy_power(struct phy *usb_phy, bool on)
123 struct udevice *dev = usb_phy->dev;
124 const struct usb_phy_data *data;
125 const struct omap_usb2_phy *phy = dev_get_priv(dev);
129 data = (const struct usb_phy_data *)dev_get_driver_data(dev);
133 rc = regmap_read(phy->pwr_regmap, phy->pwr_reg_offset, &val);
138 val |= data->power_on;
140 val |= data->power_off;
141 rc = regmap_write(phy->pwr_regmap, phy->pwr_reg_offset, val);
148 static int omap_usb2_phy_init(struct phy *usb_phy)
150 struct udevice *dev = usb_phy->dev;
151 struct omap_usb2_phy *priv = dev_get_priv(dev);
154 if (priv->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
157 * Reduce the sensitivity of internal PHY by enabling the
158 * DISCON_BYP_LATCH of the USB2PHY_ANA_CONFIG1 register. This
159 * resolves issues with certain devices which can otherwise
160 * be prone to false disconnects.
163 val = readl(priv->phy_base + USB2PHY_ANA_CONFIG1);
164 val |= USB2PHY_DISCON_BYP_LATCH;
165 writel(val, priv->phy_base + USB2PHY_ANA_CONFIG1);
168 if (priv->flags & OMAP_USB2_DISABLE_CHG_DET) {
169 val = readl(priv->phy_base + USB2PHY_CHRG_DET);
170 val |= USB2PHY_USE_CHG_DET_REG | USB2PHY_DIS_CHG_DET;
171 writel(val, priv->phy_base + USB2PHY_CHRG_DET);
177 static int omap_usb2_phy_power_on(struct phy *usb_phy)
179 return omap_usb_phy_power(usb_phy, true);
182 static int omap_usb2_phy_power_off(struct phy *usb_phy)
184 return omap_usb_phy_power(usb_phy, false);
187 static int omap_usb2_phy_exit(struct phy *usb_phy)
189 return omap_usb_phy_power(usb_phy, false);
192 struct phy_ops omap_usb2_phy_ops = {
193 .init = omap_usb2_phy_init,
194 .power_on = omap_usb2_phy_power_on,
195 .power_off = omap_usb2_phy_power_off,
196 .exit = omap_usb2_phy_exit,
199 int omap_usb2_phy_probe(struct udevice *dev)
202 struct regmap *regmap;
203 struct omap_usb2_phy *priv = dev_get_priv(dev);
204 const struct usb_phy_data *data;
207 data = (const struct usb_phy_data *)dev_get_driver_data(dev);
211 priv->phy_base = dev_read_addr_ptr(dev);
216 if (data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT)
217 priv->flags |= OMAP_USB2_CALIBRATE_FALSE_DISCONNECT;
220 * AM654x PG1.0 has a silicon bug that D+ is pulled high after
221 * POR, which could cause enumeration failure with some USB hubs.
222 * Disabling the USB2_PHY Charger Detect function will put D+
223 * into the normal state.
225 * Using property "ti,dis-chg-det-quirk" in the DT usb2-phy node
226 * to enable this workaround for AM654x PG1.0.
228 if (dev_read_bool(dev, "ti,dis-chg-det-quirk"))
229 priv->flags |= OMAP_USB2_DISABLE_CHG_DET;
231 regmap = syscon_regmap_lookup_by_phandle(dev, "syscon-phy-power");
232 if (!IS_ERR(regmap)) {
233 priv->pwr_regmap = regmap;
234 rc = dev_read_u32_array(dev, "syscon-phy-power", tmp, 2);
236 printf("couldn't get power reg. offset (err %d)\n", rc);
239 priv->pwr_reg_offset = tmp[1];
242 regmap = syscon_regmap_lookup_by_phandle(dev, "ctrl-module");
243 if (!IS_ERR(regmap)) {
244 priv->pwr_regmap = regmap;
245 priv->pwr_reg_offset = 0;
249 printf("can't get regmap (err %ld)\n", PTR_ERR(regmap));
250 return PTR_ERR(regmap);
253 U_BOOT_DRIVER(omap_usb2_phy) = {
254 .name = "omap_usb2_phy",
256 .of_match = omap_usb2_id_table,
257 .probe = omap_usb2_phy_probe,
258 .ops = &omap_usb2_phy_ops,
259 .priv_auto_alloc_size = sizeof(struct omap_usb2_phy),