All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 net-next] net: dsa: b53: mmap: Add device tree support
@ 2021-03-15 15:11 Álvaro Fernández Rojas
  2021-03-15 17:20 ` Florian Fainelli
  2021-03-15 19:23 ` Jakub Kicinski
  0 siblings, 2 replies; 3+ messages in thread
From: Álvaro Fernández Rojas @ 2021-03-15 15:11 UTC (permalink / raw)
  To: jonas.gorski, Florian Fainelli, Andrew Lunn, Vivien Didelot,
	Vladimir Oltean, David S. Miller, Jakub Kicinski, netdev,
	linux-kernel
  Cc: Álvaro Fernández Rojas

Add device tree support to b53_mmap.c while keeping platform devices support.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 v2: add change suggested by Florian Fainelli (less "OF-centric") and replace
  brcm,ports property with a ports child scan.

 drivers/net/dsa/b53/b53_mmap.c | 54 ++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/drivers/net/dsa/b53/b53_mmap.c b/drivers/net/dsa/b53/b53_mmap.c
index c628d0980c0b..94a4e3929ebf 100644
--- a/drivers/net/dsa/b53/b53_mmap.c
+++ b/drivers/net/dsa/b53/b53_mmap.c
@@ -16,6 +16,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include <linux/bits.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/io.h>
@@ -228,11 +229,64 @@ static const struct b53_io_ops b53_mmap_ops = {
 	.write64 = b53_mmap_write64,
 };
 
+static int b53_mmap_probe_of(struct platform_device *pdev,
+			     struct b53_platform_data **ppdata)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
+	struct device_node *of_ports, *of_port;
+	struct b53_platform_data *pdata;
+	void __iomem *mem;
+
+	mem = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(mem))
+		return PTR_ERR(mem);
+
+	pdata = devm_kzalloc(dev, sizeof(struct b53_platform_data),
+			     GFP_KERNEL);
+	if (!pdata)
+		return -ENOMEM;
+
+	pdata->regs = mem;
+	pdata->chip_id = BCM63XX_DEVICE_ID;
+	pdata->big_endian = of_property_read_bool(np, "big-endian");
+
+	of_ports = of_get_child_by_name(np, "ports");
+	if (!of_ports) {
+		dev_err(dev, "no ports child node found\n");
+		return -EINVAL;
+	}
+
+	for_each_available_child_of_node(of_ports, of_port) {
+		u32 reg;
+
+		if (of_property_read_u32(of_port, "reg", &reg))
+			continue;
+
+		if (reg < B53_CPU_PORT)
+			pdata->enabled_ports |= BIT(reg);
+	}
+
+	*ppdata = pdata;
+
+	return 0;
+}
+
 static int b53_mmap_probe(struct platform_device *pdev)
 {
+	struct device_node *np = pdev->dev.of_node;
 	struct b53_platform_data *pdata = pdev->dev.platform_data;
 	struct b53_mmap_priv *priv;
 	struct b53_device *dev;
+	int ret;
+
+	if (!pdata && np) {
+		ret = b53_mmap_probe_of(pdev, &pdata);
+		if (ret) {
+			dev_err(&pdev->dev, "OF probe error\n");
+			return ret;
+		}
+	}
 
 	if (!pdata)
 		return -EINVAL;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 net-next] net: dsa: b53: mmap: Add device tree support
  2021-03-15 15:11 [PATCH v2 net-next] net: dsa: b53: mmap: Add device tree support Álvaro Fernández Rojas
@ 2021-03-15 17:20 ` Florian Fainelli
  2021-03-15 19:23 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2021-03-15 17:20 UTC (permalink / raw)
  To: Álvaro Fernández Rojas, jonas.gorski, Andrew Lunn,
	Vivien Didelot, Vladimir Oltean, David S. Miller, Jakub Kicinski,
	netdev, linux-kernel



On 3/15/2021 8:11 AM, Álvaro Fernández Rojas wrote:
> Add device tree support to b53_mmap.c while keeping platform devices support.
> 
> Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>

Acked-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 net-next] net: dsa: b53: mmap: Add device tree support
  2021-03-15 15:11 [PATCH v2 net-next] net: dsa: b53: mmap: Add device tree support Álvaro Fernández Rojas
  2021-03-15 17:20 ` Florian Fainelli
@ 2021-03-15 19:23 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2021-03-15 19:23 UTC (permalink / raw)
  To: Álvaro Fernández Rojas
  Cc: jonas.gorski, Florian Fainelli, Andrew Lunn, Vivien Didelot,
	Vladimir Oltean, David S. Miller, netdev, linux-kernel

On Mon, 15 Mar 2021 16:11:40 +0100 Álvaro Fernández Rojas wrote:
> Add device tree support to b53_mmap.c while keeping platform devices support.
> 
> Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
> ---
>  v2: add change suggested by Florian Fainelli (less "OF-centric") and replace
>   brcm,ports property with a ports child scan.
> 
>  drivers/net/dsa/b53/b53_mmap.c | 54 ++++++++++++++++++++++++++++++++++
>  1 file changed, 54 insertions(+)
> 
> diff --git a/drivers/net/dsa/b53/b53_mmap.c b/drivers/net/dsa/b53/b53_mmap.c
> index c628d0980c0b..94a4e3929ebf 100644
> --- a/drivers/net/dsa/b53/b53_mmap.c
> +++ b/drivers/net/dsa/b53/b53_mmap.c
> @@ -16,6 +16,7 @@
>   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>   */
>  
> +#include <linux/bits.h>
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/io.h>
> @@ -228,11 +229,64 @@ static const struct b53_io_ops b53_mmap_ops = {
>  	.write64 = b53_mmap_write64,
>  };
>  
> +static int b53_mmap_probe_of(struct platform_device *pdev,
> +			     struct b53_platform_data **ppdata)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct device_node *np = dev->of_node;
> +	struct device_node *of_ports, *of_port;
> +	struct b53_platform_data *pdata;
> +	void __iomem *mem;

reverse xmas tree? Initialize out of line if needed.

> +	mem = devm_platform_ioremap_resource(pdev, 0);
> +	if (IS_ERR(mem))
> +		return PTR_ERR(mem);
> +
> +	pdata = devm_kzalloc(dev, sizeof(struct b53_platform_data),
> +			     GFP_KERNEL);
> +	if (!pdata)
> +		return -ENOMEM;
> +
> +	pdata->regs = mem;
> +	pdata->chip_id = BCM63XX_DEVICE_ID;
> +	pdata->big_endian = of_property_read_bool(np, "big-endian");
> +
> +	of_ports = of_get_child_by_name(np, "ports");

Isn't this leaking a ref on of_ports? I don't see any put.

> +	if (!of_ports) {
> +		dev_err(dev, "no ports child node found\n");
> +		return -EINVAL;
> +	}
> +
> +	for_each_available_child_of_node(of_ports, of_port) {
> +		u32 reg;
> +
> +		if (of_property_read_u32(of_port, "reg", &reg))
> +			continue;
> +
> +		if (reg < B53_CPU_PORT)
> +			pdata->enabled_ports |= BIT(reg);
> +	}
> +
> +	*ppdata = pdata;
> +
> +	return 0;
> +}
> +
>  static int b53_mmap_probe(struct platform_device *pdev)
>  {
> +	struct device_node *np = pdev->dev.of_node;
>  	struct b53_platform_data *pdata = pdev->dev.platform_data;
>  	struct b53_mmap_priv *priv;
>  	struct b53_device *dev;
> +	int ret;
> +
> +	if (!pdata && np) {
> +		ret = b53_mmap_probe_of(pdev, &pdata);
> +		if (ret) {
> +			dev_err(&pdev->dev, "OF probe error\n");
> +			return ret;
> +		}
> +	}
>  
>  	if (!pdata)
>  		return -EINVAL;


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-15 19:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-15 15:11 [PATCH v2 net-next] net: dsa: b53: mmap: Add device tree support Álvaro Fernández Rojas
2021-03-15 17:20 ` Florian Fainelli
2021-03-15 19:23 ` Jakub Kicinski

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.