diff mbox series

[U-Boot,v1,3/6] phy: Add a new driver for OMAP's USB2 PHYs

Message ID 1515160243-19815-4-git-send-email-jjhiblot@ti.com
State Superseded
Delegated to: Marek Vasut
Headers show
Series Add support for DM_USB for TI's DRA7 platforms | expand

Commit Message

Jean-Jacques Hiblot Jan. 5, 2018, 1:50 p.m. UTC
This drivers supports the USB2 PHY found on omap5 and dra7 SOCs.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---

 drivers/phy/Kconfig         |   8 ++
 drivers/phy/Makefile        |   2 +
 drivers/phy/omap-usb2-phy.c | 186 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 196 insertions(+)
 create mode 100644 drivers/phy/omap-usb2-phy.c

Comments

Raghavendra, Vignesh March 5, 2018, 11:56 a.m. UTC | #1
Hi,

On Friday 05 January 2018 07:20 PM, Jean-Jacques Hiblot wrote:
> This drivers supports the USB2 PHY found on omap5 and dra7 SOCs.
> 
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
> ---
> 
>  drivers/phy/Kconfig         |   8 ++
>  drivers/phy/Makefile        |   2 +
>  drivers/phy/omap-usb2-phy.c | 186 ++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 196 insertions(+)
>  create mode 100644 drivers/phy/omap-usb2-phy.c
> 

> diff --git a/drivers/phy/omap-usb2-phy.c b/drivers/phy/omap-usb2-phy.c
> new file mode 100644
> index 0000000..c8a87a5
> --- /dev/null
> +++ b/drivers/phy/omap-usb2-phy.c
> @@ -0,0 +1,186 @@

[...]

> +static int omap_usb2_phy_init(struct phy *usb_phy)
> +{
> +	struct udevice *dev = usb_phy->dev;
> +	struct omap_usb2_phy *priv = dev_get_priv(dev);
> +	u32 val;
> +
> +	if (priv->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
> +		/*
> +		 *
> +		 * Reduce the sensitivity of internal PHY by enabling the
> +		 * DISCON_BYP_LATCH of the USB2PHY_ANA_CONFIG1 register. This
> +		 * resolves issues with certain devices which can otherwise
> +		 * be prone to false disconnects.
> +		 *
> +		 */
> +		val = readl(priv->phy_base + USB2PHY_ANA_CONFIG1);
> +		val |= USB2PHY_DISCON_BYP_LATCH;
> +		writel(val, priv->phy_base + USB2PHY_ANA_CONFIG1);
> +	}
> +
> +	return omap_usb_phy_power(usb_phy, true);

phy_init() should not power on the phy, that should be done in .power_off().

I see xhci-dwc3.c calls only generic_phy_power_init() but not
generic_phy_power_on().  I have posted a fix for that.

> +}
> +
> +static int omap_usb2_phy_exit(struct phy *usb_phy)
> +{
> +	return omap_usb_phy_power(usb_phy, false);
> +}
> +
> +struct phy_ops omap_usb2_phy_ops = {
> +	.init = omap_usb2_phy_init,
> +	.exit = omap_usb2_phy_exit,
> +};
> +
> +int omap_usb2_phy_probe(struct udevice *dev)
> +{
> +	int rc;
> +	struct regmap *regmap;
> +	struct omap_usb2_phy *priv = dev_get_priv(dev);
> +	const struct usb_phy_data *data;
> +	u32 tmp[2];
> +
> +	data = (const struct usb_phy_data *)dev_get_driver_data(dev);
> +	if (!data)
> +		return -EINVAL;
> +
> +	if (data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
> +		u32 base = dev_read_addr(dev);
> +
> +		if (base == FDT_ADDR_T_NONE)
> +			return -EINVAL;
> +		priv->phy_base = (void *)base;
> +		priv->flags |= OMAP_USB2_CALIBRATE_FALSE_DISCONNECT;
> +	}
> +
> +	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);
> +	}
> +	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;
> +}
> +
> +U_BOOT_DRIVER(omap_usb2_phy) = {
> +	.name = "omap_usb2_phy",
> +	.id = UCLASS_PHY,
> +	.of_match = omap_usb2_id_table,
> +	.probe = omap_usb2_phy_probe,
> +	.ops = &omap_usb2_phy_ops,
> +	.priv_auto_alloc_size = sizeof(struct omap_usb2_phy),
> +};
>
Jean-Jacques Hiblot March 5, 2018, 1:20 p.m. UTC | #2
On 05/03/2018 12:56, Vignesh R wrote:
> Hi,
>
> On Friday 05 January 2018 07:20 PM, Jean-Jacques Hiblot wrote:
>> This drivers supports the USB2 PHY found on omap5 and dra7 SOCs.
>>
>> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
>> ---
>>
>>   drivers/phy/Kconfig         |   8 ++
>>   drivers/phy/Makefile        |   2 +
>>   drivers/phy/omap-usb2-phy.c | 186 ++++++++++++++++++++++++++++++++++++++++++++
>>   3 files changed, 196 insertions(+)
>>   create mode 100644 drivers/phy/omap-usb2-phy.c
>>
>> diff --git a/drivers/phy/omap-usb2-phy.c b/drivers/phy/omap-usb2-phy.c
>> new file mode 100644
>> index 0000000..c8a87a5
>> --- /dev/null
>> +++ b/drivers/phy/omap-usb2-phy.c
>> @@ -0,0 +1,186 @@
> [...]
>
>> +static int omap_usb2_phy_init(struct phy *usb_phy)
>> +{
>> +	struct udevice *dev = usb_phy->dev;
>> +	struct omap_usb2_phy *priv = dev_get_priv(dev);
>> +	u32 val;
>> +
>> +	if (priv->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
>> +		/*
>> +		 *
>> +		 * Reduce the sensitivity of internal PHY by enabling the
>> +		 * DISCON_BYP_LATCH of the USB2PHY_ANA_CONFIG1 register. This
>> +		 * resolves issues with certain devices which can otherwise
>> +		 * be prone to false disconnects.
>> +		 *
>> +		 */
>> +		val = readl(priv->phy_base + USB2PHY_ANA_CONFIG1);
>> +		val |= USB2PHY_DISCON_BYP_LATCH;
>> +		writel(val, priv->phy_base + USB2PHY_ANA_CONFIG1);
>> +	}
>> +
>> +	return omap_usb_phy_power(usb_phy, true);
> phy_init() should not power on the phy, that should be done in .power_off().
>
> I see xhci-dwc3.c calls only generic_phy_power_init() but not
> generic_phy_power_on().  I have posted a fix for that.
Yes. it makes more sense.
>
>> +}
>> +
>> +static int omap_usb2_phy_exit(struct phy *usb_phy)
>> +{
>> +	return omap_usb_phy_power(usb_phy, false);
>> +}
>> +
>> +struct phy_ops omap_usb2_phy_ops = {
>> +	.init = omap_usb2_phy_init,
>> +	.exit = omap_usb2_phy_exit,
>> +};
>> +
>> +int omap_usb2_phy_probe(struct udevice *dev)
>> +{
>> +	int rc;
>> +	struct regmap *regmap;
>> +	struct omap_usb2_phy *priv = dev_get_priv(dev);
>> +	const struct usb_phy_data *data;
>> +	u32 tmp[2];
>> +
>> +	data = (const struct usb_phy_data *)dev_get_driver_data(dev);
>> +	if (!data)
>> +		return -EINVAL;
>> +
>> +	if (data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
>> +		u32 base = dev_read_addr(dev);
>> +
>> +		if (base == FDT_ADDR_T_NONE)
>> +			return -EINVAL;
>> +		priv->phy_base = (void *)base;
>> +		priv->flags |= OMAP_USB2_CALIBRATE_FALSE_DISCONNECT;
>> +	}
>> +
>> +	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);
>> +	}
>> +	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;
>> +}
>> +
>> +U_BOOT_DRIVER(omap_usb2_phy) = {
>> +	.name = "omap_usb2_phy",
>> +	.id = UCLASS_PHY,
>> +	.of_match = omap_usb2_id_table,
>> +	.probe = omap_usb2_phy_probe,
>> +	.ops = &omap_usb2_phy_ops,
>> +	.priv_auto_alloc_size = sizeof(struct omap_usb2_phy),
>> +};
>>
diff mbox series

Patch

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 3b9a09c..dbf4e4d 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -85,4 +85,12 @@  config STI_USB_PHY
 	  used by USB2 and USB3 Host controllers available on
 	  STiH407 SoC families.
 
+config OMAP_USB2_PHY
+	bool "Support OMAP's USB2 PHY"
+	depends on PHY
+	depends on SYSCON
+	help
+	  Support for the OMAP's USB2 PHY.
+	  This PHY is found on OMAP devices supporting USB2.
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 668040b..ab7f205 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -10,3 +10,5 @@  obj-$(CONFIG_$(SPL_)NOP_PHY) += nop-phy.o
 obj-$(CONFIG_PHY_SANDBOX) += sandbox-phy.o
 obj-$(CONFIG_$(SPL_)PIPE3_PHY) += ti-pipe3-phy.o
 obj-$(CONFIG_STI_USB_PHY) += sti_usb_phy.o
+obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
+
diff --git a/drivers/phy/omap-usb2-phy.c b/drivers/phy/omap-usb2-phy.c
new file mode 100644
index 0000000..c8a87a5
--- /dev/null
+++ b/drivers/phy/omap-usb2-phy.c
@@ -0,0 +1,186 @@ 
+/*
+ * OMAP USB2 PHY driver
+ *
+ * Copyright (c) 2017
+ * Jean-Jacques Hiblot <jjhiblot@ti.com>
+ * based on dwc3-sti-glue
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <dm.h>
+#include <errno.h>
+#include <generic-phy.h>
+#include <regmap.h>
+#include <syscon.h>
+
+#define OMAP_USB2_CALIBRATE_FALSE_DISCONNECT	BIT(0)
+
+#define OMAP_DEV_PHY_PD		BIT(0)
+#define OMAP_USB2_PHY_PD	BIT(28)
+
+#define USB2PHY_DISCON_BYP_LATCH	BIT(31)
+#define USB2PHY_ANA_CONFIG1		(0x4c)
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct omap_usb2_phy {
+	struct regmap *pwr_regmap;
+	ulong flags;
+	void *phy_base;
+	u32 pwr_reg_offset;
+};
+
+struct usb_phy_data {
+	const char *label;
+	u8 flags;
+	u32 mask;
+	u32 power_on;
+	u32 power_off;
+};
+
+static const struct usb_phy_data omap5_usb2_data = {
+	.label = "omap5_usb2",
+	.flags = 0,
+	.mask = OMAP_DEV_PHY_PD,
+	.power_off = OMAP_DEV_PHY_PD,
+};
+
+static const struct usb_phy_data dra7x_usb2_data = {
+	.label = "dra7x_usb2",
+	.flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
+	.mask = OMAP_DEV_PHY_PD,
+	.power_off = OMAP_DEV_PHY_PD,
+};
+
+static const struct usb_phy_data dra7x_usb2_phy2_data = {
+	.label = "dra7x_usb2_phy2",
+	.flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
+	.mask = OMAP_USB2_PHY_PD,
+	.power_off = OMAP_USB2_PHY_PD,
+};
+
+static const struct udevice_id omap_usb2_id_table[] = {
+	{
+		.compatible = "ti,omap5-usb2",
+		.data = (ulong)&omap5_usb2_data,
+	},
+	{
+		.compatible = "ti,dra7x-usb2",
+		.data = (ulong)&dra7x_usb2_data,
+	},
+	{
+		.compatible = "ti,dra7x-usb2-phy2",
+		.data = (ulong)&dra7x_usb2_phy2_data,
+	},
+	{},
+};
+
+static int omap_usb_phy_power(struct phy *usb_phy, bool on)
+{
+	struct udevice *dev = usb_phy->dev;
+	const struct usb_phy_data *data;
+	const struct omap_usb2_phy *phy = dev_get_priv(dev);
+	u32 val;
+	int rc;
+
+	data = (const struct usb_phy_data *)dev_get_driver_data(dev);
+	if (!data)
+		return -EINVAL;
+
+	rc = regmap_read(phy->pwr_regmap, phy->pwr_reg_offset, &val);
+	if (rc)
+		return rc;
+	val &= ~data->mask;
+	if (on)
+		val |= data->power_on;
+	else
+		val |= data->power_off;
+	rc = regmap_write(phy->pwr_regmap, phy->pwr_reg_offset, val);
+	if (rc)
+		return rc;
+
+	return 0;
+}
+
+static int omap_usb2_phy_init(struct phy *usb_phy)
+{
+	struct udevice *dev = usb_phy->dev;
+	struct omap_usb2_phy *priv = dev_get_priv(dev);
+	u32 val;
+
+	if (priv->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
+		/*
+		 *
+		 * Reduce the sensitivity of internal PHY by enabling the
+		 * DISCON_BYP_LATCH of the USB2PHY_ANA_CONFIG1 register. This
+		 * resolves issues with certain devices which can otherwise
+		 * be prone to false disconnects.
+		 *
+		 */
+		val = readl(priv->phy_base + USB2PHY_ANA_CONFIG1);
+		val |= USB2PHY_DISCON_BYP_LATCH;
+		writel(val, priv->phy_base + USB2PHY_ANA_CONFIG1);
+	}
+
+	return omap_usb_phy_power(usb_phy, true);
+}
+
+static int omap_usb2_phy_exit(struct phy *usb_phy)
+{
+	return omap_usb_phy_power(usb_phy, false);
+}
+
+struct phy_ops omap_usb2_phy_ops = {
+	.init = omap_usb2_phy_init,
+	.exit = omap_usb2_phy_exit,
+};
+
+int omap_usb2_phy_probe(struct udevice *dev)
+{
+	int rc;
+	struct regmap *regmap;
+	struct omap_usb2_phy *priv = dev_get_priv(dev);
+	const struct usb_phy_data *data;
+	u32 tmp[2];
+
+	data = (const struct usb_phy_data *)dev_get_driver_data(dev);
+	if (!data)
+		return -EINVAL;
+
+	if (data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
+		u32 base = dev_read_addr(dev);
+
+		if (base == FDT_ADDR_T_NONE)
+			return -EINVAL;
+		priv->phy_base = (void *)base;
+		priv->flags |= OMAP_USB2_CALIBRATE_FALSE_DISCONNECT;
+	}
+
+	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);
+	}
+	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;
+}
+
+U_BOOT_DRIVER(omap_usb2_phy) = {
+	.name = "omap_usb2_phy",
+	.id = UCLASS_PHY,
+	.of_match = omap_usb2_id_table,
+	.probe = omap_usb2_phy_probe,
+	.ops = &omap_usb2_phy_ops,
+	.priv_auto_alloc_size = sizeof(struct omap_usb2_phy),
+};