All of lore.kernel.org
 help / color / mirror / Atom feed
From: kishon@ti.com (Kishon Vijay Abraham I)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] phy-sun4i-usb: Add support for the host usb-phys found on the H3 SoC
Date: Mon, 23 Nov 2015 10:40:45 +0530	[thread overview]
Message-ID: <56529FD5.5020305@ti.com> (raw)
In-Reply-To: <1448191764-11454-1-git-send-email-hdegoede@redhat.com>

Hi,

On Sunday 22 November 2015 04:59 PM, Hans de Goede wrote:
> From: Reinder de Haan <patchesrdh@mveas.com>
> 
> Note this commit only adds support for phys 1-3, phy 0, the otg phy, is
> not yet (fully) supported after this commit.
> 
> Signed-off-by: Reinder de Haan <patchesrdh@mveas.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> Changes in v2:
> -Change break; after dev_err() to return, as intended, fixing a compiler
>  warning (the dev_err case should never be reached).
> ---
>  .../devicetree/bindings/phy/sun4i-usb-phy.txt      |  1 +
>  drivers/phy/phy-sun4i-usb.c                        | 67 +++++++++++++++++-----
>  2 files changed, 53 insertions(+), 15 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
> index 0cebf74..95736d7 100644
> --- a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
> +++ b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
> @@ -9,6 +9,7 @@ Required properties:
>    * allwinner,sun7i-a20-usb-phy
>    * allwinner,sun8i-a23-usb-phy
>    * allwinner,sun8i-a33-usb-phy
> +  * allwinner,sun8i-h3-usb-phy
>  - reg : a list of offset + length pairs
>  - reg-names :
>    * "phy_ctrl"
> diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
> index b12964b..11bc9cd 100644
> --- a/drivers/phy/phy-sun4i-usb.c
> +++ b/drivers/phy/phy-sun4i-usb.c
> @@ -46,6 +46,9 @@
>  #define REG_PHYBIST			0x08
>  #define REG_PHYTUNE			0x0c
>  #define REG_PHYCTL_A33			0x10
> +#define REG_PHY_UNK_H3			0x20
> +
> +#define REG_PMU_UNK_H3			0x10
>  
>  #define PHYCTL_DATA			BIT(7)
>  
> @@ -79,7 +82,7 @@
>  #define PHY_DISCON_TH_SEL		0x2a
>  #define PHY_SQUELCH_DETECT		0x3c
>  
> -#define MAX_PHYS			3
> +#define MAX_PHYS			4

Is it 4 only for h3-usb-phy or for others too? If so, can we add it in driver data?
>  
>  /*
>   * Note do not raise the debounce time, we must report Vusb high within 100ms
> @@ -88,12 +91,19 @@
>  #define DEBOUNCE_TIME			msecs_to_jiffies(50)
>  #define POLL_TIME			msecs_to_jiffies(250)
>  
> +enum sun4i_usb_phy_type {
> +	sun4i_a10_phy,
> +	sun8i_a33_phy,
> +	sun8i_h3_phy
> +};
> +
>  struct sun4i_usb_phy_data {
> +	struct device *dev;
>  	void __iomem *base;
>  	struct mutex mutex;
>  	int num_phys;
>  	u32 disc_thresh;
> -	bool has_a33_phyctl;
> +	enum sun4i_usb_phy_type type;
>  	struct sun4i_usb_phy {
>  		struct phy *phy;
>  		void __iomem *pmu;
> @@ -164,12 +174,18 @@ static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data,
>  
>  	mutex_lock(&phy_data->mutex);
>  
> -	if (phy_data->has_a33_phyctl) {
> +	switch (phy_data->type) {
> +	case sun4i_a10_phy:
> +		phyctl = phy_data->base + REG_PHYCTL_A10;
> +		break;
> +	case sun8i_a33_phy:
>  		phyctl = phy_data->base + REG_PHYCTL_A33;
>  		/* A33 needs us to set phyctl to 0 explicitly */
>  		writel(0, phyctl);
> -	} else {
> -		phyctl = phy_data->base + REG_PHYCTL_A10;
> +		break;
> +	case sun8i_h3_phy:
> +		dev_err(phy_data->dev, "H3 usb_phy_write is not supported\n");
> +		return;
>  	}
>  
>  	for (i = 0; i < len; i++) {
> @@ -230,6 +246,7 @@ static int sun4i_usb_phy_init(struct phy *_phy)
>  	struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
>  	struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
>  	int ret;
> +	u32 val;
>  
>  	ret = clk_prepare_enable(phy->clk);
>  	if (ret)
> @@ -241,15 +258,26 @@ static int sun4i_usb_phy_init(struct phy *_phy)
>  		return ret;
>  	}
>  
> -	/* Enable USB 45 Ohm resistor calibration */
> -	if (phy->index == 0)
> -		sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
> +	if (data->type == sun8i_h3_phy) {
> +		if (phy->index == 0) {
> +			val = readl(data->base + REG_PHY_UNK_H3);
> +			writel(val & ~1, data->base + REG_PHY_UNK_H3);
> +		}
> +
> +		val = readl(phy->pmu + REG_PMU_UNK_H3);
> +		writel(val & ~2, phy->pmu + REG_PMU_UNK_H3);
> +	} else {
> +		/* Enable USB 45 Ohm resistor calibration */
> +		if (phy->index == 0)
> +			sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
>  
> -	/* Adjust PHY's magnitude and rate */
> -	sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
> +		/* Adjust PHY's magnitude and rate */
> +		sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
>  
> -	/* Disconnect threshold adjustment */
> -	sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL, data->disc_thresh, 2);
> +		/* Disconnect threshold adjustment */
> +		sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> +				    data->disc_thresh, 2);
> +	}
>  
>  	sun4i_usb_phy_passby(phy, 1);
>  
> @@ -522,11 +550,14 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
>  	mutex_init(&data->mutex);
>  	INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan);
>  	dev_set_drvdata(dev, data);
> +	data->dev = dev;
>  
>  	if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy") ||
>  	    of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy") ||
>  	    of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy"))
>  		data->num_phys = 2;
> +	else if (of_device_is_compatible(np, "allwinner,sun8i-h3-usb-phy"))
> +		data->num_phys = 4;

this should come from driver data.
>  	else
>  		data->num_phys = 3;
>  
> @@ -538,13 +569,18 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
>  
>  	if (of_device_is_compatible(np, "allwinner,sun6i-a31-usb-phy") ||
>  	    of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy") ||
> -	    of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy"))
> +	    of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy") ||
> +	    of_device_is_compatible(np, "allwinner,sun8i-h3-usb-phy"))
>  		dedicated_clocks = true;

same here.
>  	else
>  		dedicated_clocks = false;
>  
>  	if (of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy"))
> -		data->has_a33_phyctl = true;
> +		data->type = sun8i_a33_phy;
> +	else if (of_device_is_compatible(np, "allwinner,sun8i-h3-usb-phy"))
> +		data->type = sun8i_h3_phy;
> +	else
> +		data->type = sun4i_a10_phy;

this too can come from driver data.

Thanks
Kishon

WARNING: multiple messages have this Message-ID (diff)
From: Kishon Vijay Abraham I <kishon-l0cyMroinI0@public.gmane.org>
To: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Greg Kroah-Hartman
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
Cc: Alan Stern
	<stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>,
	Tony Prisk <linux-ci5G2KO2hbZ+pU9mqzGVBQ@public.gmane.org>,
	Reinder de Haan
	<patchesrdh-I1/eAgTnXDYAvxtiuMwx3w@public.gmane.org>,
	linux-usb <linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Maxime Ripard
	<maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	devicetree <devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH v2] phy-sun4i-usb: Add support for the host usb-phys found on the H3 SoC
Date: Mon, 23 Nov 2015 10:40:45 +0530	[thread overview]
Message-ID: <56529FD5.5020305@ti.com> (raw)
In-Reply-To: <1448191764-11454-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

Hi,

On Sunday 22 November 2015 04:59 PM, Hans de Goede wrote:
> From: Reinder de Haan <patchesrdh-I1/eAgTnXDYAvxtiuMwx3w@public.gmane.org>
> 
> Note this commit only adds support for phys 1-3, phy 0, the otg phy, is
> not yet (fully) supported after this commit.
> 
> Signed-off-by: Reinder de Haan <patchesrdh-I1/eAgTnXDYAvxtiuMwx3w@public.gmane.org>
> Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> ---
> Changes in v2:
> -Change break; after dev_err() to return, as intended, fixing a compiler
>  warning (the dev_err case should never be reached).
> ---
>  .../devicetree/bindings/phy/sun4i-usb-phy.txt      |  1 +
>  drivers/phy/phy-sun4i-usb.c                        | 67 +++++++++++++++++-----
>  2 files changed, 53 insertions(+), 15 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
> index 0cebf74..95736d7 100644
> --- a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
> +++ b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
> @@ -9,6 +9,7 @@ Required properties:
>    * allwinner,sun7i-a20-usb-phy
>    * allwinner,sun8i-a23-usb-phy
>    * allwinner,sun8i-a33-usb-phy
> +  * allwinner,sun8i-h3-usb-phy
>  - reg : a list of offset + length pairs
>  - reg-names :
>    * "phy_ctrl"
> diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
> index b12964b..11bc9cd 100644
> --- a/drivers/phy/phy-sun4i-usb.c
> +++ b/drivers/phy/phy-sun4i-usb.c
> @@ -46,6 +46,9 @@
>  #define REG_PHYBIST			0x08
>  #define REG_PHYTUNE			0x0c
>  #define REG_PHYCTL_A33			0x10
> +#define REG_PHY_UNK_H3			0x20
> +
> +#define REG_PMU_UNK_H3			0x10
>  
>  #define PHYCTL_DATA			BIT(7)
>  
> @@ -79,7 +82,7 @@
>  #define PHY_DISCON_TH_SEL		0x2a
>  #define PHY_SQUELCH_DETECT		0x3c
>  
> -#define MAX_PHYS			3
> +#define MAX_PHYS			4

Is it 4 only for h3-usb-phy or for others too? If so, can we add it in driver data?
>  
>  /*
>   * Note do not raise the debounce time, we must report Vusb high within 100ms
> @@ -88,12 +91,19 @@
>  #define DEBOUNCE_TIME			msecs_to_jiffies(50)
>  #define POLL_TIME			msecs_to_jiffies(250)
>  
> +enum sun4i_usb_phy_type {
> +	sun4i_a10_phy,
> +	sun8i_a33_phy,
> +	sun8i_h3_phy
> +};
> +
>  struct sun4i_usb_phy_data {
> +	struct device *dev;
>  	void __iomem *base;
>  	struct mutex mutex;
>  	int num_phys;
>  	u32 disc_thresh;
> -	bool has_a33_phyctl;
> +	enum sun4i_usb_phy_type type;
>  	struct sun4i_usb_phy {
>  		struct phy *phy;
>  		void __iomem *pmu;
> @@ -164,12 +174,18 @@ static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data,
>  
>  	mutex_lock(&phy_data->mutex);
>  
> -	if (phy_data->has_a33_phyctl) {
> +	switch (phy_data->type) {
> +	case sun4i_a10_phy:
> +		phyctl = phy_data->base + REG_PHYCTL_A10;
> +		break;
> +	case sun8i_a33_phy:
>  		phyctl = phy_data->base + REG_PHYCTL_A33;
>  		/* A33 needs us to set phyctl to 0 explicitly */
>  		writel(0, phyctl);
> -	} else {
> -		phyctl = phy_data->base + REG_PHYCTL_A10;
> +		break;
> +	case sun8i_h3_phy:
> +		dev_err(phy_data->dev, "H3 usb_phy_write is not supported\n");
> +		return;
>  	}
>  
>  	for (i = 0; i < len; i++) {
> @@ -230,6 +246,7 @@ static int sun4i_usb_phy_init(struct phy *_phy)
>  	struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
>  	struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
>  	int ret;
> +	u32 val;
>  
>  	ret = clk_prepare_enable(phy->clk);
>  	if (ret)
> @@ -241,15 +258,26 @@ static int sun4i_usb_phy_init(struct phy *_phy)
>  		return ret;
>  	}
>  
> -	/* Enable USB 45 Ohm resistor calibration */
> -	if (phy->index == 0)
> -		sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
> +	if (data->type == sun8i_h3_phy) {
> +		if (phy->index == 0) {
> +			val = readl(data->base + REG_PHY_UNK_H3);
> +			writel(val & ~1, data->base + REG_PHY_UNK_H3);
> +		}
> +
> +		val = readl(phy->pmu + REG_PMU_UNK_H3);
> +		writel(val & ~2, phy->pmu + REG_PMU_UNK_H3);
> +	} else {
> +		/* Enable USB 45 Ohm resistor calibration */
> +		if (phy->index == 0)
> +			sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
>  
> -	/* Adjust PHY's magnitude and rate */
> -	sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
> +		/* Adjust PHY's magnitude and rate */
> +		sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
>  
> -	/* Disconnect threshold adjustment */
> -	sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL, data->disc_thresh, 2);
> +		/* Disconnect threshold adjustment */
> +		sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
> +				    data->disc_thresh, 2);
> +	}
>  
>  	sun4i_usb_phy_passby(phy, 1);
>  
> @@ -522,11 +550,14 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
>  	mutex_init(&data->mutex);
>  	INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan);
>  	dev_set_drvdata(dev, data);
> +	data->dev = dev;
>  
>  	if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy") ||
>  	    of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy") ||
>  	    of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy"))
>  		data->num_phys = 2;
> +	else if (of_device_is_compatible(np, "allwinner,sun8i-h3-usb-phy"))
> +		data->num_phys = 4;

this should come from driver data.
>  	else
>  		data->num_phys = 3;
>  
> @@ -538,13 +569,18 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
>  
>  	if (of_device_is_compatible(np, "allwinner,sun6i-a31-usb-phy") ||
>  	    of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy") ||
> -	    of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy"))
> +	    of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy") ||
> +	    of_device_is_compatible(np, "allwinner,sun8i-h3-usb-phy"))
>  		dedicated_clocks = true;

same here.
>  	else
>  		dedicated_clocks = false;
>  
>  	if (of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy"))
> -		data->has_a33_phyctl = true;
> +		data->type = sun8i_a33_phy;
> +	else if (of_device_is_compatible(np, "allwinner,sun8i-h3-usb-phy"))
> +		data->type = sun8i_h3_phy;
> +	else
> +		data->type = sun4i_a10_phy;

this too can come from driver data.

Thanks
Kishon

  parent reply	other threads:[~2015-11-23  5:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-22 11:29 [PATCH v2] phy-sun4i-usb: Add support for the host usb-phys found on the H3 SoC Hans de Goede
2015-11-22 11:29 ` Hans de Goede
2015-11-22 22:15 ` Rob Herring
2015-11-22 22:15   ` Rob Herring
2015-11-23  5:10 ` Kishon Vijay Abraham I [this message]
2015-11-23  5:10   ` Kishon Vijay Abraham I

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56529FD5.5020305@ti.com \
    --to=kishon@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.