lkml.org 
[lkml]   [2023]   [Apr]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 19/43] net: cirrus: add DT support for Cirrus EP93xx
Date
- find register range from the device tree
- get "copy_addr" from the device tree
- get phy_id from the device tree

Signed-off-by: Nikita Shubin <nikita.shubin@maquefel.me>
---

Notes:
rfc->v0
Fixed warnings on "(base_addr == NULL)", pace required before the open
parenthesis '('.

Arnd Bergmann:
- wildcards ep93xx to something meaningful, i.e. ep9301
- drop wrappers

drivers/net/ethernet/cirrus/ep93xx_eth.c | 49 +++++++++++++++++++++---
1 file changed, 43 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/cirrus/ep93xx_eth.c b/drivers/net/ethernet/cirrus/ep93xx_eth.c
index 8627ab19d470..b156cc75daad 100644
--- a/drivers/net/ethernet/cirrus/ep93xx_eth.c
+++ b/drivers/net/ethernet/cirrus/ep93xx_eth.c
@@ -17,6 +17,8 @@
#include <linux/interrupt.h>
#include <linux/moduleparam.h>
#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/slab.h>
@@ -792,6 +794,8 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
struct net_device *dev;
struct ep93xx_priv *ep;
struct resource *mem;
+ void __iomem *base_addr;
+ struct device_node *np;
int irq;
int err;

@@ -804,6 +808,38 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
if (!mem || irq < 0)
return -ENXIO;

+ base_addr = ioremap(mem->start, resource_size(mem));
+ if (!base_addr) {
+ dev_err(&pdev->dev, "Failed to ioremap ethernet registers\n");
+ return -EIO;
+ }
+
+ if (!data) {
+ np = pdev->dev.of_node;
+ if (IS_ENABLED(CONFIG_OF) && np) {
+ u32 phy_id;
+
+ data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ if (of_property_read_bool(np, "copy_addr")) {
+ memcpy_fromio(data->dev_addr, base_addr + 0x50, 6);
+ dev_info(&pdev->dev, "MAC=%pM\n", data->dev_addr);
+ }
+
+ if (of_property_read_u32(np, "phy_id", &phy_id)) {
+ dev_err(&pdev->dev, "Failed to parse \"phy_id\"\n");
+ return -ENOENT;
+ }
+
+ data->phy_id = phy_id;
+ }
+ }
+
+ if (!data)
+ return -ENOENT;
+
dev = ep93xx_dev_alloc(data);
if (dev == NULL) {
err = -ENOMEM;
@@ -824,12 +860,7 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
goto err_out;
}

- ep->base_addr = ioremap(mem->start, resource_size(mem));
- if (ep->base_addr == NULL) {
- dev_err(&pdev->dev, "Failed to ioremap ethernet registers\n");
- err = -EIO;
- goto err_out;
- }
+ ep->base_addr = base_addr;
ep->irq = irq;

ep->mii.phy_id = data->phy_id;
@@ -859,12 +890,18 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
return err;
}

+static const struct of_device_id ep93xx_eth_of_ids[] = {
+ { .compatible = "cirrus,ep9301-eth" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, ep93xx_eth_of_ids);

static struct platform_driver ep93xx_eth_driver = {
.probe = ep93xx_eth_probe,
.remove = ep93xx_eth_remove,
.driver = {
.name = "ep93xx-eth",
+ .of_match_table = ep93xx_eth_of_ids,
},
};

--
2.39.2
\
 
 \ /
  Last update: 2023-04-24 12:35    [W:1.175 / U:4.740 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site