Merge https://gitlab.denx.de/u-boot/custodians/u-boot-spi into next
[platform/kernel/u-boot.git] / drivers / phy / omap-usb2-phy.c
index fd20e8c..adc454d 100644 (file)
 #include <generic-phy.h>
 #include <regmap.h>
 #include <syscon.h>
+#include <linux/bitops.h>
+#include <linux/err.h>
 
 #define OMAP_USB2_CALIBRATE_FALSE_DISCONNECT   BIT(0)
+#define OMAP_USB2_DISABLE_CHG_DET              BIT(1)
 
 #define OMAP_DEV_PHY_PD                BIT(0)
 #define OMAP_USB2_PHY_PD       BIT(28)
 
+#define AM437X_USB2_PHY_PD             BIT(0)
+#define AM437X_USB2_OTG_PD             BIT(1)
+#define AM437X_USB2_OTGVDET_EN         BIT(19)
+#define AM437X_USB2_OTGSESSEND_EN      BIT(20)
+
 #define USB2PHY_DISCON_BYP_LATCH       BIT(31)
 #define USB2PHY_ANA_CONFIG1            (0x4c)
 
+#define AM654_USB2_OTG_PD              BIT(8)
+#define AM654_USB2_VBUS_DET_EN         BIT(5)
+#define AM654_USB2_VBUSVALID_DET_EN    BIT(4)
+
+#define USB2PHY_CHRG_DET                0x14
+#define USB2PHY_USE_CHG_DET_REG                BIT(29)
+#define USB2PHY_DIS_CHG_DET            BIT(28)
+
 DECLARE_GLOBAL_DATA_PTR;
 
 struct omap_usb2_phy {
@@ -60,6 +76,24 @@ static const struct usb_phy_data dra7x_usb2_phy2_data = {
        .power_off = OMAP_USB2_PHY_PD,
 };
 
+static const struct usb_phy_data am437x_usb2_data = {
+       .label = "am437x_usb2",
+       .flags =  0,
+       .mask = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD |
+               AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN,
+       .power_on = AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN,
+       .power_off = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD,
+};
+
+static const struct usb_phy_data am654_usb2_data = {
+       .label = "am654_usb2",
+       .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
+       .mask = AM654_USB2_OTG_PD | AM654_USB2_VBUS_DET_EN |
+               AM654_USB2_VBUSVALID_DET_EN,
+       .power_on = AM654_USB2_VBUS_DET_EN | AM654_USB2_VBUSVALID_DET_EN,
+       .power_off = AM654_USB2_OTG_PD,
+};
+
 static const struct udevice_id omap_usb2_id_table[] = {
        {
                .compatible = "ti,omap5-usb2",
@@ -73,6 +107,14 @@ static const struct udevice_id omap_usb2_id_table[] = {
                .compatible = "ti,dra7x-usb2-phy2",
                .data = (ulong)&dra7x_usb2_phy2_data,
        },
+       {
+               .compatible = "ti,am437x-usb2",
+               .data = (ulong)&am437x_usb2_data,
+       },
+       {
+               .compatible = "ti,am654-usb2",
+               .data = (ulong)&am654_usb2_data,
+       },
        {},
 };
 
@@ -123,6 +165,12 @@ static int omap_usb2_phy_init(struct phy *usb_phy)
                writel(val, priv->phy_base + USB2PHY_ANA_CONFIG1);
        }
 
+       if (priv->flags & OMAP_USB2_DISABLE_CHG_DET) {
+               val = readl(priv->phy_base + USB2PHY_CHRG_DET);
+               val |= USB2PHY_USE_CHG_DET_REG | USB2PHY_DIS_CHG_DET;
+               writel(val, priv->phy_base + USB2PHY_CHRG_DET);
+       }
+
        return 0;
 }
 
@@ -160,30 +208,46 @@ int omap_usb2_phy_probe(struct udevice *dev)
        if (!data)
                return -EINVAL;
 
-       if (data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
-               u32 base = dev_read_addr(dev);
+       priv->phy_base = dev_read_addr_ptr(dev);
+
+       if (!priv->phy_base)
+               return -EINVAL;
 
-               if (base == FDT_ADDR_T_NONE)
-                       return -EINVAL;
-               priv->phy_base = (void *)base;
+       if (data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT)
                priv->flags |= OMAP_USB2_CALIBRATE_FALSE_DISCONNECT;
-       }
+
+       /*
+        * AM654x PG1.0 has a silicon bug that D+ is pulled high after
+        * POR, which could cause enumeration failure with some USB hubs.
+        * Disabling the USB2_PHY Charger Detect function will put D+
+        * into the normal state.
+        *
+        * Using property "ti,dis-chg-det-quirk" in the DT usb2-phy node
+        * to enable this workaround for AM654x PG1.0.
+        */
+       if (dev_read_bool(dev, "ti,dis-chg-det-quirk"))
+               priv->flags |= OMAP_USB2_DISABLE_CHG_DET;
 
        regmap = syscon_regmap_lookup_by_phandle(dev, "syscon-phy-power");
-       if (IS_ERR(regmap)) {
-               printf("can't get regmap (err %ld)\n", PTR_ERR(regmap));
-               return PTR_ERR(regmap);
+       if (!IS_ERR(regmap)) {
+               priv->pwr_regmap = regmap;
+               rc =  dev_read_u32_array(dev, "syscon-phy-power", tmp, 2);
+               if (rc) {
+                       printf("couldn't get power reg. offset (err %d)\n", rc);
+                       return rc;
+               }
+               priv->pwr_reg_offset = tmp[1];
+               return 0;
        }
-       priv->pwr_regmap = regmap;
-
-       rc =  dev_read_u32_array(dev, "syscon-phy-power", tmp, 2);
-       if (rc) {
-               printf("couldn't get power reg. offset (err %d)\n", rc);
-               return rc;
+       regmap = syscon_regmap_lookup_by_phandle(dev, "ctrl-module");
+       if (!IS_ERR(regmap)) {
+               priv->pwr_regmap = regmap;
+               priv->pwr_reg_offset = 0;
+               return 0;
        }
-       priv->pwr_reg_offset = tmp[1];
 
-       return 0;
+       printf("can't get regmap (err %ld)\n", PTR_ERR(regmap));
+       return PTR_ERR(regmap);
 }
 
 U_BOOT_DRIVER(omap_usb2_phy) = {