All of lore.kernel.org
 help / color / mirror / Atom feed
From: jason@lakedaemon.net (Jason Cooper)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH V3 7/8] mv643xx.c: Add basic device tree support.
Date: Fri, 25 Jan 2013 20:53:59 +0000	[thread overview]
Message-ID: <d2db6ddfddf90dd79c6c6c90a6006887076dea1a.1359146831.git.jason@lakedaemon.net> (raw)
In-Reply-To: <cover.1359146831.git.jason@lakedaemon.net>

From: Ian Molton <ian.molton@codethink.co.uk>

    This patch adds basic device tree support to the mv643xx ethernet driver.

    It should be enough for most current users of the device, and should allow
    a painless migration.

    Signed-off-by: Ian Molton <ian.molton@codethink.co.uk>

Signed-off-by: Jason Cooper <jason@lakedaemon.net>
---
 Documentation/devicetree/bindings/net/mv643xx.txt | 75 ++++++++++++++++++
 drivers/net/ethernet/marvell/mv643xx_eth.c        | 93 +++++++++++++++++++++--
 2 files changed, 161 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/mv643xx.txt

diff --git a/Documentation/devicetree/bindings/net/mv643xx.txt b/Documentation/devicetree/bindings/net/mv643xx.txt
new file mode 100644
index 0000000..2727f798
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/mv643xx.txt
@@ -0,0 +1,75 @@
+mv643xx related nodes.
+
+marvell,mdio-mv643xx:
+
+Required properties:
+
+ - interrupts : <a> where a is the SMI interrupt number.
+ - reg : the base address and size of the controllers register space.
+
+Optional properties:
+ - shared_smi : on some chips, the second PHY is "shared", meaning it is
+	really accessed via the first SMI controller. It is passed in this
+	way due to the present structure of the driver, which requires the
+	base address for the MAC to be passed in via the SMI controllers
+	platform data.
+ - tx_csum_limit : on some devices, this option is required for proper
+	operation wrt. jumbo frames.
+
+
+Example:
+
+smi0: mdio at 72000 {
+	compatible = "marvell,mdio-mv643xx";
+	reg = <0x72000 0x4000>;
+	interrupts = <46>;
+	tx_csum_limit = <1600>;
+	status = "disabled";
+};
+
+smi1: mdio at 76000 {
+	compatible = "marvell,mdio-mv643xx";
+	reg = <0x76000 0x4000>;
+	interrupts = <47>;
+	shared_smi = <&smi0>;
+	tx_csum_limit = <1600>;
+	status = "disabled";
+};
+
+
+
+marvell,mv643xx-eth:
+
+Required properties:
+ - interrupts : the port interrupt number.
+ - mdio : phandle of the smi device as drescribed above
+
+Optional properties:
+ - port_number : the port number on this bus.
+ - phy_addr : the PHY address.
+ - reg : should match the mdio reg this device is attached to.
+	this is a required hack for now due to the way the
+	driver is constructed. This allows the device clock to be
+	kept running so that the MAC is not lost after boot.
+
+
+Example:
+
+egiga0 {
+	compatible = "marvell,mv643xx-eth";
+	reg = <0x72000 0x4000>;
+	mdio = <&smi0>;
+	port_number = <0>;
+	phy_addr = <0x80>;
+	interrupts = <11>;
+};
+
+egiga1 {
+	compatible = "marvell,mv643xx-eth";
+	reg = <0x76000 0x4000>;
+	mdio = <&smi1>;
+	port_number = <0>;
+	phy_addr = <0x81>;
+	interrupts = <15>;
+};
+
diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index 84c1326..7048d7c 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -48,6 +48,9 @@
 #include <linux/ethtool.h>
 #include <linux/platform_device.h>
 #include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/of_irq.h>
 #include <linux/kernel.h>
 #include <linux/spinlock.h>
 #include <linux/workqueue.h>
@@ -2586,7 +2589,7 @@ static void infer_hw_params(struct mv643xx_eth_shared_private *msp)
 static int mv643xx_eth_shared_probe(struct platform_device *pdev)
 {
 	static int mv643xx_eth_version_printed;
-	struct mv643xx_eth_shared_platform_data *pd = pdev->dev.platform_data;
+	struct mv643xx_eth_shared_platform_data *pd;
 	struct mv643xx_eth_shared_private *msp;
 	const struct mbus_dram_target_info *dram;
 	struct resource *res;
@@ -2610,6 +2613,26 @@ static int mv643xx_eth_shared_probe(struct platform_device *pdev)
 	if (msp->base == NULL)
 		goto out_free;
 
+	if (pdev->dev.of_node) {
+		struct device_node *np = NULL;
+
+		/* when all users of this driver use FDT, we can remove this */
+		pd = kzalloc(sizeof(*pd), GFP_KERNEL);
+		if (!pd) {
+			dev_dbg(&pdev->dev, "Could not allocate platform data\n");
+			goto out_free;
+		}
+
+		of_property_read_u32(pdev->dev.of_node,
+			"tx_csum_limit", &pd->tx_csum_limit);
+
+		np = of_parse_phandle(pdev->dev.of_node, "shared_smi", 0);
+		if (np)
+			pd->shared_smi = of_find_device_by_node(np);
+
+	} else {
+		pd = pdev->dev.platform_data;
+	}
 	/*
 	 * Set up and register SMI bus.
 	 */
@@ -2642,7 +2665,6 @@ static int mv643xx_eth_shared_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (res != NULL) {
 		int err;
-
 		err = request_irq(res->start, mv643xx_eth_err_irq,
 				  IRQF_SHARED, "mv643xx_eth", msp);
 		if (!err) {
@@ -2660,6 +2682,10 @@ static int mv643xx_eth_shared_probe(struct platform_device *pdev)
 
 	msp->tx_csum_limit = (pd != NULL && pd->tx_csum_limit) ?
 					pd->tx_csum_limit : 9 * 1024;
+
+	if (pdev->dev.of_node)
+		kfree(pd);  /* If we created a fake pd, free it now */
+
 	infer_hw_params(msp);
 
 	platform_set_drvdata(pdev, msp);
@@ -2693,12 +2719,21 @@ static int mv643xx_eth_shared_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static struct of_device_id mv_mdio_dt_ids[] __devinitdata = {
+	{ .compatible = "marvell,mdio-mv643xx", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, mv_mdio_dt_ids);
+#endif
+
 static struct platform_driver mv643xx_eth_shared_driver = {
 	.probe		= mv643xx_eth_shared_probe,
 	.remove		= mv643xx_eth_shared_remove,
 	.driver = {
 		.name	= MV643XX_ETH_SHARED_NAME,
 		.owner	= THIS_MODULE,
+		.of_match_table = of_match_ptr(mv_mdio_dt_ids),
 	},
 };
 
@@ -2858,7 +2893,36 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
 	struct resource *res;
 	int err;
 
-	pd = pdev->dev.platform_data;
+	if (pdev->dev.of_node) {
+		struct device_node *np = NULL;
+
+		/* when all users of this driver use FDT, we can remove this */
+		pd = kzalloc(sizeof(*pd), GFP_KERNEL);
+		if (!pd) {
+			dev_dbg(&pdev->dev, "Could not allocate platform data\n");
+			return -ENOMEM;
+		}
+
+		of_property_read_u32(pdev->dev.of_node,
+			"port_number", &pd->port_number);
+
+		if (!of_property_read_u32(pdev->dev.of_node,
+				"phy_addr", &pd->phy_addr))
+			pd->phy_addr = MV643XX_ETH_PHY_ADDR(pd->phy_addr);
+		else
+			pd->phy_addr = MV643XX_ETH_PHY_ADDR_DEFAULT;
+
+		np = of_parse_phandle(pdev->dev.of_node, "mdio", 0);
+		if (np) {
+			pd->shared = of_find_device_by_node(np);
+		} else {
+			kfree(pd);
+			return -ENODEV;
+		}
+	} else {
+		pd = pdev->dev.platform_data;
+	}
+
 	if (pd == NULL) {
 		dev_err(&pdev->dev, "no mv643xx_eth_platform_data\n");
 		return -ENODEV;
@@ -2866,12 +2930,15 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
 
 	if (pd->shared == NULL) {
 		dev_err(&pdev->dev, "no mv643xx_eth_platform_data->shared\n");
-		return -ENODEV;
+		err = -ENODEV;
+		goto out_free_pd;
 	}
 
 	dev = alloc_etherdev_mq(sizeof(struct mv643xx_eth_private), 8);
-	if (!dev)
-		return -ENOMEM;
+	if (!dev) {
+		err = -ENOMEM;
+		goto out_free_pd;
+	}
 
 	mp = netdev_priv(dev);
 	platform_set_drvdata(pdev, mp);
@@ -2908,6 +2975,8 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
 
 	init_pscr(mp, pd->speed, pd->duplex);
 
+	if (pdev->dev.of_node)
+		kfree(pd); /* If we created a fake pd, free it now */
 
 	mib_counters_clear(mp);
 
@@ -2927,7 +2996,6 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
 	mp->rx_oom.data = (unsigned long)mp;
 	mp->rx_oom.function = oom_timer_wrapper;
 
-
 	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	BUG_ON(!res);
 	dev->irq = res->start;
@@ -2976,6 +3044,8 @@ out:
 	}
 #endif
 	free_netdev(dev);
+out_free_pd:
+	kfree(pd);
 
 	return err;
 }
@@ -3015,6 +3085,14 @@ static void mv643xx_eth_shutdown(struct platform_device *pdev)
 		port_reset(mp);
 }
 
+#ifdef CONFIG_OF
+static struct of_device_id mv_eth_dt_ids[] __devinitdata = {
+	{ .compatible = "marvell,mv643xx-eth", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, mv_eth_dt_ids);
+#endif
+
 static struct platform_driver mv643xx_eth_driver = {
 	.probe		= mv643xx_eth_probe,
 	.remove		= mv643xx_eth_remove,
@@ -3022,6 +3100,7 @@ static struct platform_driver mv643xx_eth_driver = {
 	.driver = {
 		.name	= MV643XX_ETH_NAME,
 		.owner	= THIS_MODULE,
+		.of_match_table = of_match_ptr(mv_eth_dt_ids),
 	},
 };
 
-- 
1.8.1.1

  parent reply	other threads:[~2013-01-25 20:53 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-23 23:34 [RFC PATCH 0/6] ARM: kirkwood: cleanup DT conversion Jason Cooper
2013-01-23 23:34 ` [RFC PATCH 1/6] ARM: kirkwood: topkick: init mvsdio via DT Jason Cooper
2013-01-23 23:34 ` [RFC PATCH 2/6] ARM: kirkwood: topkick: convert to pinctrl Jason Cooper
2013-01-23 23:34 ` [RFC PATCH 3/6] ARM: kirkwood: nsa310: cleanup includes and unneeded code Jason Cooper
2013-01-24  5:50   ` Andrew Lunn
2013-01-24 13:43     ` Florian Fainelli
2013-01-24 14:39       ` Jason Cooper
2013-01-24 15:41     ` Jason Cooper
2013-01-23 23:34 ` [RFC PATCH 4/6] ARM: kirkwood: nsa310: convert to pinctrl Jason Cooper
2013-01-23 23:34 ` [RFC PATCH 5/6] ARM: kirkwood: consolidate DT init of pcie Jason Cooper
2013-01-23 23:34 ` [RFC PATCH 6/6] ARM: kirkwood: consolidate mv643xx_eth init for DT Jason Cooper
2013-01-24  1:39   ` Jason Cooper
2013-01-24  6:23     ` Andrew Lunn
2013-01-24 12:07       ` Jason Cooper
2013-01-24 13:37   ` Florian Fainelli
2013-01-24 14:37     ` Jason Cooper
2013-01-24 15:54       ` Arnd Bergmann
2013-01-24 16:13         ` Jason Cooper
2013-01-24 17:51           ` Florian Fainelli
2013-01-24 18:16             ` Jason Cooper
2013-01-24 20:27               ` Florian Fainelli
2013-01-24 20:38                 ` Jason Cooper
2013-01-24 20:52                   ` Florian Fainelli
2013-01-24  1:33 ` [RFC PATCH 0/6] ARM: kirkwood: cleanup DT conversion Jason Cooper
2013-01-25  5:32 ` [RFC V2 PATCH 0/8] " Jason Cooper
2013-01-25  5:32   ` [RFC V2 PATCH 1/8] ARM: kirkwood: topkick: init mvsdio via DT Jason Cooper
2013-01-25  5:32   ` [RFC V2 PATCH 2/8] ARM: kirkwood: topkick: convert to pinctrl Jason Cooper
2013-01-25  5:32   ` [RFC V2 PATCH 3/8] ARM: kirkwood: nsa310: cleanup includes and unneeded code Jason Cooper
2013-01-26 20:08     ` Sergei Shtylyov
2013-01-26 20:22       ` Jason Cooper
2013-01-27 15:04         ` Sergei Shtylyov
2013-01-27 15:26           ` Jason Cooper
2013-01-25  5:32   ` [RFC V2 PATCH 4/8] ARM: kirkwood: nsa310: convert to pinctrl Jason Cooper
2013-01-25  5:32   ` [RFC V2 PATCH 5/8] ARM: kirkwood: consolidate DT init of pcie Jason Cooper
2013-01-25  5:32   ` [RFC V2 PATCH 6/8] ARM: mvebu: correct gated clock documentation Jason Cooper
2013-01-25  5:32   ` [RFC V2 PATCH 7/8] mv643xx.c: Add basic device tree support Jason Cooper
2013-01-25  5:32   ` [RFC V2 PATCH 8/8] ARM: kirkwood: mv643xx_eth dt conversion Jason Cooper
2013-01-25 11:15   ` [RFC V2 PATCH 0/8] ARM: kirkwood: cleanup DT conversion Arnd Bergmann
2013-01-25 12:52     ` Jason Cooper
2013-01-25 15:03       ` Sebastian Hesselbarth
2013-01-25 18:34         ` Jason Gunthorpe
2013-01-25 20:03           ` Arnd Bergmann
2013-01-28 10:40           ` Ezequiel Garcia
2013-01-28 18:07             ` Jason Gunthorpe
2013-01-28 18:24               ` Thomas Petazzoni
2013-01-28 18:41                 ` Ezequiel Garcia
2013-01-28 19:03                   ` Thomas Petazzoni
2013-01-28 19:19                     ` Jason Gunthorpe
2013-01-28 19:19                     ` Ezequiel Garcia
2013-01-28 18:43                 ` Jason Gunthorpe
2013-01-25 20:53 ` [PATCH V3 " Jason Cooper
2013-01-25 20:53   ` [PATCH V3 1/8] ARM: kirkwood: topkick: init mvsdio via DT Jason Cooper
2013-01-26 16:21     ` Andrew Lunn
2013-01-25 20:53   ` [PATCH V3 2/8] ARM: kirkwood: topkick: convert to pinctrl Jason Cooper
2013-01-26 16:55     ` [PATCH 1/2] ARM: Kirkwood: topkick: Fix SoC type and add missing pins Andrew Lunn
2013-01-26 16:55       ` [PATCH 2/2] ARM: Kirkwood: topkick: Enable i2c bus Andrew Lunn
2013-01-26 17:38         ` Sebastian Hesselbarth
2013-01-26 18:24           ` Andrew Lunn
2013-01-26 18:51             ` Sebastian Hesselbarth
2013-01-26 20:40         ` Jason Cooper
2013-01-26 20:39       ` [PATCH 1/2] ARM: Kirkwood: topkick: Fix SoC type and add missing pins Jason Cooper
2013-01-25 20:53   ` [PATCH V3 3/8] ARM: kirkwood: nsa310: cleanup includes and unneeded code Jason Cooper
2013-01-25 20:53   ` [PATCH V3 4/8] ARM: kirkwood: nsa310: convert to pinctrl Jason Cooper
2013-01-25 20:53   ` [PATCH V3 5/8] ARM: kirkwood: consolidate DT init of pcie Jason Cooper
2013-01-25 20:53   ` [PATCH V3 6/8] ARM: mvebu: correct gated clock documentation Jason Cooper
2013-01-25 20:53   ` Jason Cooper [this message]
2013-01-28 10:12     ` [PATCH V3 7/8] mv643xx.c: Add basic device tree support Mark Rutland
2013-01-28 19:38       ` Jason Cooper
2013-01-29 10:26         ` Ian Molton
2013-01-25 20:54   ` [PATCH V3 8/8] ARM: kirkwood: mv643xx_eth dt conversion Jason Cooper
2013-01-26 12:38     ` Andrew Lunn
2013-01-26 12:50       ` Sebastian Hesselbarth
2013-01-26 13:40         ` Andrew Lunn
2013-01-26 13:46           ` Sebastian Hesselbarth
2013-01-26 15:42           ` Jason Cooper
2013-01-27 12:21           ` Russell King - ARM Linux
2013-01-27 13:10             ` Sebastian Hesselbarth
2013-01-27 18:38               ` Russell King - ARM Linux
2013-01-26 15:06       ` Jason Cooper
2013-01-26 15:12         ` Andrew Lunn
2013-01-26 15:33     ` Andrew Lunn
2013-01-26 15:44       ` Jason Cooper
2013-01-26 20:50 ` [PATCH V4 0/8] ARM: kirkwood: cleanup DT conversion Jason Cooper
2013-01-26 20:50   ` [PATCH V4 01/11] ARM: kirkwood: topkick: init mvsdio via DT Jason Cooper
2013-02-16 16:25     ` Jason Cooper
2013-01-26 20:50   ` [PATCH V4 02/11] ARM: kirkwood: topkick: convert to pinctrl Jason Cooper
2013-02-16 16:11     ` Jason Cooper
2013-01-26 20:50   ` [PATCH V4 03/11] ARM: Kirkwood: topkick: Enable i2c bus Jason Cooper
2013-02-16 16:15     ` Jason Cooper
2013-01-26 20:50   ` [PATCH V4 04/11] ARM: kirkwood: nsa310: cleanup includes and unneeded code Jason Cooper
2013-01-26 20:50   ` [PATCH V4 05/11] ARM: kirkwood: nsa310: convert to pinctrl Jason Cooper
2013-02-16 16:17     ` Jason Cooper
2013-01-26 20:50   ` [PATCH V4 06/11] ARM: kirkwood: consolidate DT init of pcie Jason Cooper
2013-01-26 20:50   ` [PATCH V4 07/11] ARM: mvebu: correct gated clock documentation Jason Cooper
2013-02-15 20:37     ` Jason Cooper
2013-01-26 20:50   ` [PATCH V4 08/11] mv643xx.c: Add basic device tree support Jason Cooper
2013-01-26 20:50   ` [PATCH V4 09/11] NET: mv643xx: Get clk from device tree Jason Cooper
2013-01-27 14:27     ` [PATCH] NET: mv643xx: get smi clock " Sebastian Hesselbarth
2013-01-26 20:50   ` [PATCH V4 10/11] ARM: kirkwood: mv643xx_eth dt conversion Jason Cooper
2013-01-27 13:41     ` Sebastian Hesselbarth
2013-01-27 15:35       ` Jason Cooper
2013-01-26 20:50   ` [PATCH V4 11/11] ARM: Kirkwood: Convert QNAP TS219 Ethernet to DT Jason Cooper

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=d2db6ddfddf90dd79c6c6c90a6006887076dea1a.1359146831.git.jason@lakedaemon.net \
    --to=jason@lakedaemon.net \
    --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.