Skip to contentSkip to conversation

net: dsa: b53: mmap: Add device tree support

PATCH Superseded Álvaro Fernández Rojas 2 participants 3 messages Mar 8, 2021

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dsa: b53: mmap: Add device tree support

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

---
 drivers/net/dsa/b53/b53_mmap.c | 36 ++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/net/dsa/b53/b53_mmap.c +36 -0
index c628d0980c0b..b897b4263930 100644
@@ -228,12 +228,48 @@ 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 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_property_read_u16(np, "brcm,ports", &pdata->enabled_ports);
+
+	*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;
 
+	if (np) {
+		int ret = b53_mmap_probe_of(pdev, &pdata);
+		if (ret) {
+			dev_err(&pdev->dev, "OF probe error\n");
+			return ret;
+		}
+	}
+
 	if (!pdata)
 		return -EINVAL;
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 46 lines · Álvaro Fernández Rojas

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

---
 drivers/net/dsa/b53/b53_mmap.c | 36 ++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/net/dsa/b53/b53_mmap.c +28 -0
index c628d0980c0b..b897b4263930 100644
@@ -228,12 +228,48 @@ 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 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_property_read_u16(np, "brcm,ports", &pdata->enabled_ports);
+
+	*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;

drivers/net/dsa/b53/b53_mmap.c static const struct b53_io_ops b53_mmap_ops = { · line 271

Quoted 10 lines
drivers/net/dsa/b53/b53_mmap.c +7 -0
 	struct b53_mmap_priv *priv;
 	struct b53_device *dev;
 
+	if (np) {
+		int ret = b53_mmap_probe_of(pdev, &pdata);
+		if (ret) {
+			dev_err(&pdev->dev, "OF probe error\n");
+			return ret;
+		}
+	}

I would be keen on making this less "OF-centric" and just have it happen whenever pdata is NULL such that we have an easier transition path if we wanted to migrate bcm63xx to passing down the switch base register address a platform_device source in the future (not that I expect it to happen though).

Other than that, the logic looks sound.

Signature · 1 line
Florian
#2 lore raw

Hi Florian,

Quoted 50 lines · Florian Fainelli
Quoted 49 lines · Álvaro Fernández Rojas

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

---
  drivers/net/dsa/b53/b53_mmap.c | 36 ++++++++++++++++++++++++++++++++++
  1 file changed, 36 insertions(+)
drivers/net/dsa/b53/b53_mmap.c +28 -0
index c628d0980c0b..b897b4263930 100644
@@ -228,12 +228,48 @@ 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 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_property_read_u16(np, "brcm,ports", &pdata->enabled_ports);
+
+	*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;
 
Quoted 13 lines

drivers/net/dsa/b53/b53_mmap.c static const struct b53_io_ops b53_mmap_ops = { · line 271

Quoted 7 lines
drivers/net/dsa/b53/b53_mmap.c +7 -0
+	if (np) {
+		int ret = b53_mmap_probe_of(pdev, &pdata);
+		if (ret) {
+			dev_err(&pdev->dev, "OF probe error\n");
+			return ret;
+		}
+	}

I would be keen on making this less "OF-centric" and just have it happen whenever pdata is NULL such that we have an easier transition path if we wanted to migrate bcm63xx to passing down the switch base register address a platform_device source in the future (not that I expect it to happen though).

Honestly, it's probably easier to switch to bmips instead of migrating bcm63xx...

Quoted 3 lines

Other than that, the logic looks sound.

Best regards,
Álvaro.