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 4/5] phy: miphy365x: Represent each PHY channel as a subnode
Date: Wed, 2 Jul 2014 15:56:23 +0530	[thread overview]
Message-ID: <53B3DE4F.1040100@ti.com> (raw)
In-Reply-To: <20140630144114.GB25926@lee--X1>

Hi,

On Monday 30 June 2014 08:11 PM, Lee Jones wrote:
> phy: miphy365x: Represent each PHY channel as a DT subnode
> 
> This has the added advantages of being able to enable/disable each
> of the channels as simply as enabling/disabling the DT node.
> 
> Suggested-by: Kishon Vijay Abraham I <kishon@ti.com>
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> 
> diff --git a/drivers/phy/phy-miphy365x.c b/drivers/phy/phy-miphy365x.c
> index 1109f42..2c4ea6e 100644
> --- a/drivers/phy/phy-miphy365x.c
> +++ b/drivers/phy/phy-miphy365x.c
> @@ -17,6 +17,7 @@
>  #include <linux/module.h>
>  #include <linux/of.h>
>  #include <linux/of_platform.h>
> +#include <linux/of_address.h>
>  #include <linux/clk.h>
>  #include <linux/phy/phy.h>
>  #include <linux/delay.h>
> @@ -144,6 +145,7 @@ struct miphy365x {
>  	void __iomem *pcie;
>  	u8 type;
>  	u8 port;
> +	bool enabled;
>  };
>  
>  struct miphy365x_dev {
> @@ -468,7 +470,7 @@ static struct phy *miphy365x_xlate(struct device *dev,
>  	struct miphy365x_dev *state = dev_get_drvdata(dev);
>  	u8 port, type;
>  
> -	if (args->count != 2) {
> +	if (args->args_count != 2) {
>  		dev_err(dev, "Invalid number of cells in 'phy' property\n");
>  		return ERR_PTR(-EINVAL);
>  	}
> @@ -484,6 +486,11 @@ static struct phy *miphy365x_xlate(struct device *dev,
>  	if (WARN_ON(port >= ARRAY_SIZE(ports)))
>  		return ERR_PTR(-EINVAL);
>  
> +	if (!state->phys[port].enabled) {
> +		dev_warn(dev, "PHY port %d is disabled\n", port);
> +		return ERR_PTR(-EINVAL);
> +	}
> +
>  	if (type == MIPHY_TYPE_SATA)
>  		state->phys[port].base = state->phys[port].sata;
>  	else if (type == MIPHY_TYPE_PCIE)
> @@ -503,38 +510,75 @@ static struct phy_ops miphy365x_ops = {
>  	.owner		= THIS_MODULE,
>  };
>  
> -static int miphy365x_get_base_addr(struct platform_device *pdev,
> -				    struct miphy365x_phy *phy, u8 port)
> +static int miphy365x_get_base_addr_one(struct platform_device *pdev,
> +				       struct miphy365x *phy,
> +				       struct device_node *child,
> +				       int index)
>  {
> -	struct resource *res;
> -	char type[6];
> +	void __iomem *base;
> +	const char *name;
> +	int ret;
>  
> -	sprintf(type, "sata%d", port);
> +	base = of_iomap(child, index);
> +	if (!base) {
> +		dev_err(&pdev->dev, "Failed to map %s\n", child->full_name);
> +		return -EINVAL;
> +	}
>  
> -	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, type);
> -	if (!res)
> -		return -ENODEV;
> +	ret = of_property_read_string_index(child, "reg-names", index, &name);
> +	if (ret) {
> +		dev_err(&pdev->dev,
> +			"%s: no reg-names property not found\n", child->name);
> +		return ret;
> +	}
>  
> -	phy->sata = devm_ioremap(&pdev->dev, res->start, resource_size(res));
> -	if (!phy->sata)
> -		return -ENOMEM;
> +	if (!strncmp(name, "sata", 4))
> +		phy->sata = base;
> +	else if (!strncmp(name, "pcie", 4))
> +		phy->pcie = base;
> +	else {
> +		dev_err(&pdev->dev, "reg-names in %s not sata or pcie: %s",
> +			child->name, name);
> +		return -EINVAL;
> +	}
>  
> -	sprintf(type, "pcie%d", port);
> +	return 0;
> +}
>  
> -	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, type);
> -	if (!res)
> -		return -ENODEV;
> +static int miphy365x_get_base_addr(struct platform_device *pdev,
> +				   struct miphy365x *phy,
> +				   struct device_node *child)
> +{
> +	int index;
> +	int ret;
>  
> -	phy->pcie = devm_ioremap(&pdev->dev, res->start, resource_size(res));
> -	if (!phy->pcie)
> -		return -ENOMEM;
> +	/* Each port handles SATA or PCIE. */
> +	for (index = 0; index < 2; index++) {
> +		ret = miphy365x_get_base_addr_one(pdev, phy,
> +						  child, index);
> +		if (ret)
> +			return ret;
> +	}
>  
>  	return 0;
>  }
>  
> -static int miphy365x_of_probe(struct device_node *np,
> +static int miphy365x_of_probe(struct platform_device *pdev,
>  			      struct miphy365x_dev *phy_dev)
>  {
> +	struct device_node *np = pdev->dev.of_node;
> +	struct device_node *child;
> +	int child_count = 0;
> +
> +	for_each_child_of_node(np, child)
> +		child_count++;

use of_get_child_count() instead.
> +
> +	if (child_count != ARRAY_SIZE(ports)) {
> +		dev_err(&pdev->dev, "%d ports supported, %d supplied\n",
> +			ARRAY_SIZE(ports), child_count);
> +		return -EINVAL;
> +	}
> +
>  	phy_dev->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
>  	if (IS_ERR(phy_dev->regmap)) {
>  		dev_err(phy_dev->dev, "No syscfg phandle specified\n");
> @@ -556,11 +600,10 @@ static int miphy365x_of_probe(struct device_node *np,
>  
>  static int miphy365x_probe(struct platform_device *pdev)
>  {
> -	struct device_node *np = pdev->dev.of_node;
> +	struct device_node *child, *np = pdev->dev.of_node;
>  	struct miphy365x_dev *phy_dev;
>  	struct device *dev = &pdev->dev;
>  	struct phy_provider *provider;
> -	u8 port;
>  	int ret;
>  
>  	if (!np) {
> @@ -572,7 +615,7 @@ static int miphy365x_probe(struct platform_device *pdev)
>  	if (!phy_dev)
>  		return -ENOMEM;
>  
> -	ret = miphy365x_of_probe(np, phy_dev);
> +	ret = miphy365x_of_probe(pdev, phy_dev);
>  	if (ret)
>  		return ret;
>  
> @@ -582,8 +625,9 @@ static int miphy365x_probe(struct platform_device *pdev)
>  
>  	mutex_init(&phy_dev->miphy_mutex);
>  
> -	for (port = 0; port < ARRAY_SIZE(ports); port++) {
> +	for_each_child_of_node(np, child) {
>  		struct phy *phy;
> +		static int port = 0;
>  
>  		phy = devm_phy_create(dev, &miphy365x_ops, NULL);
>  		if (IS_ERR(phy)) {
> @@ -591,15 +635,17 @@ static int miphy365x_probe(struct platform_device *pdev)
>  			return PTR_ERR(phy);
>  		}
>  
> -		phy_dev->phys[port].phy  = phy;
> -		phy_dev->phys[port].port = port;
> -
> -		ret = miphy365x_get_base_addr(pdev,
> -					&phy_dev->phys[port], port);
> +		ret = miphy365x_get_base_addr(pdev, &phy_dev->phys[port],
> +					      child);
>  		if (ret)
>  			return ret;
>  
> +		phy_dev->phys[port].phy  = phy;
> +		phy_dev->phys[port].port = port;
> +		phy_dev->phys[port].enabled = !!of_device_is_available(child);
> +
>  		phy_set_drvdata(phy, &phy_dev->phys[port]);
> +		port++;
>  	}
>  
>  	provider = devm_of_phy_provider_register(dev, miphy365x_xlate);

I think you can merge this to your original patch.

Cheers
Kishon

WARNING: multiple messages have this Message-ID (diff)
From: Kishon Vijay Abraham I <kishon@ti.com>
To: Lee Jones <lee.jones@linaro.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Cc: <kernel@stlinux.com>
Subject: Re: [PATCH v2 4/5] phy: miphy365x: Represent each PHY channel as a subnode
Date: Wed, 2 Jul 2014 15:56:23 +0530	[thread overview]
Message-ID: <53B3DE4F.1040100@ti.com> (raw)
In-Reply-To: <20140630144114.GB25926@lee--X1>

Hi,

On Monday 30 June 2014 08:11 PM, Lee Jones wrote:
> phy: miphy365x: Represent each PHY channel as a DT subnode
> 
> This has the added advantages of being able to enable/disable each
> of the channels as simply as enabling/disabling the DT node.
> 
> Suggested-by: Kishon Vijay Abraham I <kishon@ti.com>
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> 
> diff --git a/drivers/phy/phy-miphy365x.c b/drivers/phy/phy-miphy365x.c
> index 1109f42..2c4ea6e 100644
> --- a/drivers/phy/phy-miphy365x.c
> +++ b/drivers/phy/phy-miphy365x.c
> @@ -17,6 +17,7 @@
>  #include <linux/module.h>
>  #include <linux/of.h>
>  #include <linux/of_platform.h>
> +#include <linux/of_address.h>
>  #include <linux/clk.h>
>  #include <linux/phy/phy.h>
>  #include <linux/delay.h>
> @@ -144,6 +145,7 @@ struct miphy365x {
>  	void __iomem *pcie;
>  	u8 type;
>  	u8 port;
> +	bool enabled;
>  };
>  
>  struct miphy365x_dev {
> @@ -468,7 +470,7 @@ static struct phy *miphy365x_xlate(struct device *dev,
>  	struct miphy365x_dev *state = dev_get_drvdata(dev);
>  	u8 port, type;
>  
> -	if (args->count != 2) {
> +	if (args->args_count != 2) {
>  		dev_err(dev, "Invalid number of cells in 'phy' property\n");
>  		return ERR_PTR(-EINVAL);
>  	}
> @@ -484,6 +486,11 @@ static struct phy *miphy365x_xlate(struct device *dev,
>  	if (WARN_ON(port >= ARRAY_SIZE(ports)))
>  		return ERR_PTR(-EINVAL);
>  
> +	if (!state->phys[port].enabled) {
> +		dev_warn(dev, "PHY port %d is disabled\n", port);
> +		return ERR_PTR(-EINVAL);
> +	}
> +
>  	if (type == MIPHY_TYPE_SATA)
>  		state->phys[port].base = state->phys[port].sata;
>  	else if (type == MIPHY_TYPE_PCIE)
> @@ -503,38 +510,75 @@ static struct phy_ops miphy365x_ops = {
>  	.owner		= THIS_MODULE,
>  };
>  
> -static int miphy365x_get_base_addr(struct platform_device *pdev,
> -				    struct miphy365x_phy *phy, u8 port)
> +static int miphy365x_get_base_addr_one(struct platform_device *pdev,
> +				       struct miphy365x *phy,
> +				       struct device_node *child,
> +				       int index)
>  {
> -	struct resource *res;
> -	char type[6];
> +	void __iomem *base;
> +	const char *name;
> +	int ret;
>  
> -	sprintf(type, "sata%d", port);
> +	base = of_iomap(child, index);
> +	if (!base) {
> +		dev_err(&pdev->dev, "Failed to map %s\n", child->full_name);
> +		return -EINVAL;
> +	}
>  
> -	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, type);
> -	if (!res)
> -		return -ENODEV;
> +	ret = of_property_read_string_index(child, "reg-names", index, &name);
> +	if (ret) {
> +		dev_err(&pdev->dev,
> +			"%s: no reg-names property not found\n", child->name);
> +		return ret;
> +	}
>  
> -	phy->sata = devm_ioremap(&pdev->dev, res->start, resource_size(res));
> -	if (!phy->sata)
> -		return -ENOMEM;
> +	if (!strncmp(name, "sata", 4))
> +		phy->sata = base;
> +	else if (!strncmp(name, "pcie", 4))
> +		phy->pcie = base;
> +	else {
> +		dev_err(&pdev->dev, "reg-names in %s not sata or pcie: %s",
> +			child->name, name);
> +		return -EINVAL;
> +	}
>  
> -	sprintf(type, "pcie%d", port);
> +	return 0;
> +}
>  
> -	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, type);
> -	if (!res)
> -		return -ENODEV;
> +static int miphy365x_get_base_addr(struct platform_device *pdev,
> +				   struct miphy365x *phy,
> +				   struct device_node *child)
> +{
> +	int index;
> +	int ret;
>  
> -	phy->pcie = devm_ioremap(&pdev->dev, res->start, resource_size(res));
> -	if (!phy->pcie)
> -		return -ENOMEM;
> +	/* Each port handles SATA or PCIE. */
> +	for (index = 0; index < 2; index++) {
> +		ret = miphy365x_get_base_addr_one(pdev, phy,
> +						  child, index);
> +		if (ret)
> +			return ret;
> +	}
>  
>  	return 0;
>  }
>  
> -static int miphy365x_of_probe(struct device_node *np,
> +static int miphy365x_of_probe(struct platform_device *pdev,
>  			      struct miphy365x_dev *phy_dev)
>  {
> +	struct device_node *np = pdev->dev.of_node;
> +	struct device_node *child;
> +	int child_count = 0;
> +
> +	for_each_child_of_node(np, child)
> +		child_count++;

use of_get_child_count() instead.
> +
> +	if (child_count != ARRAY_SIZE(ports)) {
> +		dev_err(&pdev->dev, "%d ports supported, %d supplied\n",
> +			ARRAY_SIZE(ports), child_count);
> +		return -EINVAL;
> +	}
> +
>  	phy_dev->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
>  	if (IS_ERR(phy_dev->regmap)) {
>  		dev_err(phy_dev->dev, "No syscfg phandle specified\n");
> @@ -556,11 +600,10 @@ static int miphy365x_of_probe(struct device_node *np,
>  
>  static int miphy365x_probe(struct platform_device *pdev)
>  {
> -	struct device_node *np = pdev->dev.of_node;
> +	struct device_node *child, *np = pdev->dev.of_node;
>  	struct miphy365x_dev *phy_dev;
>  	struct device *dev = &pdev->dev;
>  	struct phy_provider *provider;
> -	u8 port;
>  	int ret;
>  
>  	if (!np) {
> @@ -572,7 +615,7 @@ static int miphy365x_probe(struct platform_device *pdev)
>  	if (!phy_dev)
>  		return -ENOMEM;
>  
> -	ret = miphy365x_of_probe(np, phy_dev);
> +	ret = miphy365x_of_probe(pdev, phy_dev);
>  	if (ret)
>  		return ret;
>  
> @@ -582,8 +625,9 @@ static int miphy365x_probe(struct platform_device *pdev)
>  
>  	mutex_init(&phy_dev->miphy_mutex);
>  
> -	for (port = 0; port < ARRAY_SIZE(ports); port++) {
> +	for_each_child_of_node(np, child) {
>  		struct phy *phy;
> +		static int port = 0;
>  
>  		phy = devm_phy_create(dev, &miphy365x_ops, NULL);
>  		if (IS_ERR(phy)) {
> @@ -591,15 +635,17 @@ static int miphy365x_probe(struct platform_device *pdev)
>  			return PTR_ERR(phy);
>  		}
>  
> -		phy_dev->phys[port].phy  = phy;
> -		phy_dev->phys[port].port = port;
> -
> -		ret = miphy365x_get_base_addr(pdev,
> -					&phy_dev->phys[port], port);
> +		ret = miphy365x_get_base_addr(pdev, &phy_dev->phys[port],
> +					      child);
>  		if (ret)
>  			return ret;
>  
> +		phy_dev->phys[port].phy  = phy;
> +		phy_dev->phys[port].port = port;
> +		phy_dev->phys[port].enabled = !!of_device_is_available(child);
> +
>  		phy_set_drvdata(phy, &phy_dev->phys[port]);
> +		port++;
>  	}
>  
>  	provider = devm_of_phy_provider_register(dev, miphy365x_xlate);

I think you can merge this to your original patch.

Cheers
Kishon

  reply	other threads:[~2014-07-02 10:26 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-30 13:01 [PATCH 0/5] phy: miphy365x: Introduce support for MiPHY365x Lee Jones
2014-06-30 13:01 ` Lee Jones
2014-06-30 13:01 ` [PATCH 1/5] phy: miphy365x: Add Device Tree bindings for the MiPHY365x Lee Jones
2014-06-30 13:01   ` Lee Jones
2014-07-02  9:24   ` Kishon Vijay Abraham I
2014-07-02  9:24     ` Kishon Vijay Abraham I
2014-07-02 12:06     ` Lee Jones
2014-07-02 12:06       ` Lee Jones
2014-07-03  9:06       ` Kishon Vijay Abraham I
2014-07-03  9:06         ` Kishon Vijay Abraham I
2014-06-30 13:01 ` [PATCH 2/5] phy: miphy365x: Add MiPHY365x header file for DT x Driver defines Lee Jones
2014-06-30 13:01   ` Lee Jones
2014-07-02  9:28   ` Kishon Vijay Abraham I
2014-07-02  9:28     ` Kishon Vijay Abraham I
2014-07-02 12:02     ` Lee Jones
2014-07-02 12:02       ` Lee Jones
2014-06-30 13:01 ` [PATCH 3/5] phy: miphy365x: Provide support for the MiPHY356x Generic PHY Lee Jones
2014-06-30 13:01   ` Lee Jones
2014-07-02 10:19   ` Kishon Vijay Abraham I
2014-07-02 10:19     ` Kishon Vijay Abraham I
2014-07-02 12:00     ` Lee Jones
2014-07-02 12:00       ` Lee Jones
2014-07-03  8:07     ` Lee Jones
2014-07-03  8:07       ` Lee Jones
2014-07-03 10:06       ` Kishon Vijay Abraham I
2014-07-03 10:06         ` Kishon Vijay Abraham I
2014-07-04 13:55   ` Gabriel Fernandez
2014-07-04 13:55     ` Gabriel Fernandez
2014-07-08  7:15     ` Lee Jones
2014-07-08  7:15       ` Lee Jones
2014-06-30 13:01 ` [PATCH 4/5] phy: miphy365x: Represent each PHY channel as a subnode Lee Jones
2014-06-30 13:01   ` Lee Jones
2014-06-30 13:06   ` [STLinux Kernel] " Maxime Coquelin
2014-06-30 13:06     ` Maxime Coquelin
2014-06-30 13:52     ` Lee Jones
2014-06-30 13:52       ` Lee Jones
2014-06-30 14:41   ` [PATCH v2 " Lee Jones
2014-06-30 14:41     ` Lee Jones
2014-07-02 10:26     ` Kishon Vijay Abraham I [this message]
2014-07-02 10:26       ` Kishon Vijay Abraham I
2014-07-02 11:34       ` Lee Jones
2014-07-02 11:34         ` Lee Jones
2014-07-02 11:57         ` Kishon Vijay Abraham I
2014-07-02 11:57           ` Kishon Vijay Abraham I
2014-07-02 12:19           ` Lee Jones
2014-07-02 12:19             ` Lee Jones
2014-06-30 13:01 ` [PATCH 5/5] ARM: DT: STi: Add DT node for MiPHY365x Lee Jones
2014-06-30 13:01   ` Lee Jones
2014-07-03 14:08   ` Gabriel Fernandez
2014-07-03 14:08     ` Gabriel Fernandez
2014-07-02  9:19 ` [PATCH 0/5] phy: miphy365x: Introduce support " Kishon Vijay Abraham I
2014-07-02  9:19   ` 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=53B3DE4F.1040100@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.