netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] net: at91_ether add dt and pinctrl support
@ 2012-11-04 15:49 Jean-Christophe PLAGNIOL-VILLARD
  2012-11-04 18:10 ` [PATCH 1/2] net: at91_ether: add dt support Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 4+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-11-04 15:49 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: netdev, devicetree-discuss, Nicolas Ferre, Joachim Eastwood

Hi,

	This patch serie add dt and pinctrl support to the at91 ether

	this is need to use the network on at91rm9200 as we now have dt
	support on it

Jean-Christophe PLAGNIOL-VILLARD (2):
      net: at91_ether: add dt support
      net: at91_ether: add pinctrl support

 Documentation/devicetree/bindings/net/cdns-emac.txt |   23 +++++++++++++++++++++++
 drivers/net/ethernet/cadence/at91_ether.c           |   83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 99 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/cdns-emac.txt

Best Regards,
J.

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

* [PATCH 1/2] net: at91_ether: add dt support
  2012-11-04 15:49 [PATCH 0/2] net: at91_ether add dt and pinctrl support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-11-04 18:10 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-11-04 18:10   ` [PATCH 2/2] net: at91_ether: add pinctrl support Jean-Christophe PLAGNIOL-VILLARD
  2012-11-04 22:21   ` [PATCH 1/2] net: at91_ether: add dt support Joachim Eastwood
  0 siblings, 2 replies; 4+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-11-04 18:10 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Nicolas Ferre, devicetree-discuss,
	Jean-Christophe PLAGNIOL-VILLARD, Joachim Eastwood, netdev

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: Joachim Eastwood <manabian@gmail.com>
Cc: netdev@vger.kernel.org
---
 .../devicetree/bindings/net/cdns-emac.txt          |   23 +++++++
 drivers/net/ethernet/cadence/at91_ether.c          |   72 ++++++++++++++++++--
 2 files changed, 88 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/cdns-emac.txt

diff --git a/Documentation/devicetree/bindings/net/cdns-emac.txt b/Documentation/devicetree/bindings/net/cdns-emac.txt
new file mode 100644
index 0000000..45b8760
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/cdns-emac.txt
@@ -0,0 +1,23 @@
+* Cadence EMAC Ethernet controller
+
+Required properties:
+- compatible: Should be "cdns,[<chip>-]{emac}"
+  Use "cdns,at91rm9200-emac" Atmel at91rm9200 SoC.
+  or the generic form: "cdns,emac".
+- reg: Address and length of the register set for the device
+- interrupts: Should contain macb interrupt
+- phy-mode: String, operation mode of the PHY interface.
+  Supported values are: "mii", "rmii".
+
+Optional properties:
+- local-mac-address: 6 bytes, mac address
+
+Examples:
+
+	macb0: ethernet@fffc4000 {
+		compatible = "cdns,atrm9200-emac";
+		reg = <0xfffc4000 0x4000>;
+		interrupts = <21>;
+		phy-mode = "rmii";
+		local-mac-address = [3a 0e 03 04 05 06];
+	};
diff --git a/drivers/net/ethernet/cadence/at91_ether.c b/drivers/net/ethernet/cadence/at91_ether.c
index 0d6392d..3e843b4 100644
--- a/drivers/net/ethernet/cadence/at91_ether.c
+++ b/drivers/net/ethernet/cadence/at91_ether.c
@@ -31,6 +31,9 @@
 #include <linux/gfp.h>
 #include <linux/phy.h>
 #include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_net.h>
 
 #include "macb.h"
 
@@ -443,6 +446,49 @@ static const struct net_device_ops at91ether_netdev_ops = {
 #endif
 };
 
+#if defined(CONFIG_OF)
+static const struct of_device_id at91ether_dt_ids[] = {
+	{ .compatible = "cdns,at91rm9200-emac" },
+	{ .compatible = "cdns,emac" },
+	{ /* sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, at91ether_dt_ids);
+
+static int at91ether_get_phy_mode_dt(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+
+	if (np)
+		return of_get_phy_mode(np);
+
+	return -ENODEV;
+}
+
+static int at91ether_get_hwaddr_dt(struct macb *bp)
+{
+	struct device_node *np = bp->pdev->dev.of_node;
+	if (np) {
+		const char *mac = of_get_mac_address(np);
+		if (mac) {
+			memcpy(bp->dev->dev_addr, mac, ETH_ALEN);
+			return 0;
+		}
+	}
+
+	return -ENODEV;
+}
+#else
+static int at91ether_get_phy_mode_dt(struct platform_device *pdev)
+{
+	return -ENODEV;
+}
+static int at91ether_get_hwaddr_dt(struct macb *bp)
+{
+	return -ENODEV;
+}
+#endif
+
 /*
  * Detect MAC & PHY and perform ethernet interface initialization
  */
@@ -466,7 +512,8 @@ static int __init at91ether_probe(struct platform_device *pdev)
 	lp = netdev_priv(dev);
 	lp->pdev = pdev;
 	lp->dev = dev;
-	lp->board_data = *board_data;
+	if (board_data)
+		lp->board_data = *board_data;
 	spin_lock_init(&lp->lock);
 
 	dev->base_addr = regs->start;		/* physical base address */
@@ -496,18 +543,28 @@ static int __init at91ether_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, dev);
 	SET_NETDEV_DEV(dev, &pdev->dev);
 
-	get_mac_address(dev);		/* Get ethernet address and store it in dev->dev_addr */
+	res = at91ether_get_hwaddr_dt(lp);
+	if (res < 0)
+		get_mac_address(dev);		/* Get ethernet address and store it in dev->dev_addr */
+
 	update_mac_address(dev);	/* Program ethernet address into MAC */
 
+	res = at91ether_get_phy_mode_dt(pdev);
+	if (res < 0) {
+		if (board_data && board_data->is_rmii)
+			lp->phy_interface = PHY_INTERFACE_MODE_RMII;
+		else
+			lp->phy_interface = PHY_INTERFACE_MODE_MII;
+	} else {
+		lp->phy_interface = res;
+	}
+
 	macb_writel(lp, NCR, 0);
 
-	if (board_data->is_rmii) {
+	if (lp->phy_interface == PHY_INTERFACE_MODE_RMII)
 		macb_writel(lp, NCFGR, MACB_BF(CLK, MACB_CLK_DIV32) | MACB_BIT(BIG) | MACB_BIT(RM9200_RMII));
-		lp->phy_interface = PHY_INTERFACE_MODE_RMII;
-	} else {
+	else
 		macb_writel(lp, NCFGR, MACB_BF(CLK, MACB_CLK_DIV32) | MACB_BIT(BIG));
-		lp->phy_interface = PHY_INTERFACE_MODE_MII;
-	}
 
 	/* Register the network interface */
 	res = register_netdev(dev);
@@ -602,6 +659,7 @@ static struct platform_driver at91ether_driver = {
 	.driver		= {
 		.name	= DRV_NAME,
 		.owner	= THIS_MODULE,
+		.of_match_table	= of_match_ptr(at91ether_dt_ids),
 	},
 };
 
-- 
1.7.10.4

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

* [PATCH 2/2] net: at91_ether: add pinctrl support
  2012-11-04 18:10 ` [PATCH 1/2] net: at91_ether: add dt support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-11-04 18:10   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-11-04 22:21   ` [PATCH 1/2] net: at91_ether: add dt support Joachim Eastwood
  1 sibling, 0 replies; 4+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-11-04 18:10 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Nicolas Ferre, devicetree-discuss,
	Jean-Christophe PLAGNIOL-VILLARD, Joachim Eastwood, netdev

If no pinctrl available just report a warning as some architecture may not
need to do anything.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: Joachim Eastwood <manabian@gmail.com>
Cc: netdev@vger.kernel.org
---
 drivers/net/ethernet/cadence/at91_ether.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/net/ethernet/cadence/at91_ether.c b/drivers/net/ethernet/cadence/at91_ether.c
index 3e843b4..ffcdbc3 100644
--- a/drivers/net/ethernet/cadence/at91_ether.c
+++ b/drivers/net/ethernet/cadence/at91_ether.c
@@ -34,6 +34,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/of_net.h>
+#include <linux/pinctrl/consumer.h>
 
 #include "macb.h"
 
@@ -500,11 +501,21 @@ static int __init at91ether_probe(struct platform_device *pdev)
 	struct phy_device *phydev;
 	struct macb *lp;
 	int res;
+	struct pinctrl *pinctrl;
 
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!regs)
 		return -ENOENT;
 
+	pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
+	if (IS_ERR(pinctrl)) {
+		res = PTR_ERR(pinctrl);
+		if (res == -EPROBE_DEFER)
+			return res;
+
+		dev_warn(&pdev->dev, "No pinctrl provided\n");
+	}
+
 	dev = alloc_etherdev(sizeof(struct macb));
 	if (!dev)
 		return -ENOMEM;
-- 
1.7.10.4

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

* Re: [PATCH 1/2] net: at91_ether: add dt support
  2012-11-04 18:10 ` [PATCH 1/2] net: at91_ether: add dt support Jean-Christophe PLAGNIOL-VILLARD
  2012-11-04 18:10   ` [PATCH 2/2] net: at91_ether: add pinctrl support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-11-04 22:21   ` Joachim Eastwood
  1 sibling, 0 replies; 4+ messages in thread
From: Joachim Eastwood @ 2012-11-04 22:21 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: linux-arm-kernel, devicetree-discuss, Nicolas Ferre, netdev

Hi Jean-Christophe,

Some minor comments below.

On 4 November 2012 19:10, Jean-Christophe PLAGNIOL-VILLARD
<plagnioj@jcrosoft.com> wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: Joachim Eastwood <manabian@gmail.com>
> Cc: netdev@vger.kernel.org
> ---
>  .../devicetree/bindings/net/cdns-emac.txt          |   23 +++++++
>  drivers/net/ethernet/cadence/at91_ether.c          |   72 ++++++++++++++++++--
>  2 files changed, 88 insertions(+), 7 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/net/cdns-emac.txt
>
> diff --git a/Documentation/devicetree/bindings/net/cdns-emac.txt b/Documentation/devicetree/bindings/net/cdns-emac.txt
> new file mode 100644
> index 0000000..45b8760
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/cdns-emac.txt
> @@ -0,0 +1,23 @@
> +* Cadence EMAC Ethernet controller
> +
> +Required properties:
> +- compatible: Should be "cdns,[<chip>-]{emac}"
> +  Use "cdns,at91rm9200-emac" Atmel at91rm9200 SoC.
> +  or the generic form: "cdns,emac".
> +- reg: Address and length of the register set for the device
> +- interrupts: Should contain macb interrupt
> +- phy-mode: String, operation mode of the PHY interface.
> +  Supported values are: "mii", "rmii".
> +
> +Optional properties:
> +- local-mac-address: 6 bytes, mac address
> +
> +Examples:
> +
> +       macb0: ethernet@fffc4000 {
> +               compatible = "cdns,atrm9200-emac";

Typo in the compatible string. Should be "cdns,at91rm9200-emac"

> +               reg = <0xfffc4000 0x4000>;
> +               interrupts = <21>;
> +               phy-mode = "rmii";
> +               local-mac-address = [3a 0e 03 04 05 06];
> +       };
> diff --git a/drivers/net/ethernet/cadence/at91_ether.c b/drivers/net/ethernet/cadence/at91_ether.c
> index 0d6392d..3e843b4 100644
> --- a/drivers/net/ethernet/cadence/at91_ether.c
> +++ b/drivers/net/ethernet/cadence/at91_ether.c
> @@ -31,6 +31,9 @@
>  #include <linux/gfp.h>
>  #include <linux/phy.h>
>  #include <linux/io.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_net.h>
>
>  #include "macb.h"
>
> @@ -443,6 +446,49 @@ static const struct net_device_ops at91ether_netdev_ops = {
>  #endif
>  };
>
> +#if defined(CONFIG_OF)
> +static const struct of_device_id at91ether_dt_ids[] = {
> +       { .compatible = "cdns,at91rm9200-emac" },
> +       { .compatible = "cdns,emac" },
> +       { /* sentinel */ }
> +};
> +
> +MODULE_DEVICE_TABLE(of, at91ether_dt_ids);
> +
> +static int at91ether_get_phy_mode_dt(struct platform_device *pdev)
> +{
> +       struct device_node *np = pdev->dev.of_node;
> +
> +       if (np)
> +               return of_get_phy_mode(np);
> +
> +       return -ENODEV;
> +}
> +
> +static int at91ether_get_hwaddr_dt(struct macb *bp)
> +{
> +       struct device_node *np = bp->pdev->dev.of_node;

Space between variables and code, please.

> +       if (np) {
> +               const char *mac = of_get_mac_address(np);
> +               if (mac) {
> +                       memcpy(bp->dev->dev_addr, mac, ETH_ALEN);
> +                       return 0;
> +               }
> +       }
> +
> +       return -ENODEV;
> +}
> +#else
> +static int at91ether_get_phy_mode_dt(struct platform_device *pdev)
> +{
> +       return -ENODEV;
> +}
> +static int at91ether_get_hwaddr_dt(struct macb *bp)
> +{
> +       return -ENODEV;
> +}
> +#endif
> +
>  /*
>   * Detect MAC & PHY and perform ethernet interface initialization
>   */
> @@ -466,7 +512,8 @@ static int __init at91ether_probe(struct platform_device *pdev)
>         lp = netdev_priv(dev);
>         lp->pdev = pdev;
>         lp->dev = dev;
> -       lp->board_data = *board_data;
> +       if (board_data)
> +               lp->board_data = *board_data;
>         spin_lock_init(&lp->lock);
>
>         dev->base_addr = regs->start;           /* physical base address */
> @@ -496,18 +543,28 @@ static int __init at91ether_probe(struct platform_device *pdev)
>         platform_set_drvdata(pdev, dev);
>         SET_NETDEV_DEV(dev, &pdev->dev);
>
> -       get_mac_address(dev);           /* Get ethernet address and store it in dev->dev_addr */
> +       res = at91ether_get_hwaddr_dt(lp);
> +       if (res < 0)
> +               get_mac_address(dev);           /* Get ethernet address and store it in dev->dev_addr */
> +
>         update_mac_address(dev);        /* Program ethernet address into MAC */
>
> +       res = at91ether_get_phy_mode_dt(pdev);
> +       if (res < 0) {
> +               if (board_data && board_data->is_rmii)
> +                       lp->phy_interface = PHY_INTERFACE_MODE_RMII;
> +               else
> +                       lp->phy_interface = PHY_INTERFACE_MODE_MII;
> +       } else {
> +               lp->phy_interface = res;
> +       }
> +
>         macb_writel(lp, NCR, 0);
>
> -       if (board_data->is_rmii) {
> +       if (lp->phy_interface == PHY_INTERFACE_MODE_RMII)
>                 macb_writel(lp, NCFGR, MACB_BF(CLK, MACB_CLK_DIV32) | MACB_BIT(BIG) | MACB_BIT(RM9200_RMII));
> -               lp->phy_interface = PHY_INTERFACE_MODE_RMII;
> -       } else {
> +       else
>                 macb_writel(lp, NCFGR, MACB_BF(CLK, MACB_CLK_DIV32) | MACB_BIT(BIG));
> -               lp->phy_interface = PHY_INTERFACE_MODE_MII;
> -       }
>
>         /* Register the network interface */
>         res = register_netdev(dev);
> @@ -602,6 +659,7 @@ static struct platform_driver at91ether_driver = {
>         .driver         = {
>                 .name   = DRV_NAME,
>                 .owner  = THIS_MODULE,
> +               .of_match_table = of_match_ptr(at91ether_dt_ids),
>         },
>  };
>

Tested-by: Joachim Eastwood <manabian@gmail.com>

regards
Joachim Eastwood

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

end of thread, other threads:[~2012-11-04 22:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-04 15:49 [PATCH 0/2] net: at91_ether add dt and pinctrl support Jean-Christophe PLAGNIOL-VILLARD
2012-11-04 18:10 ` [PATCH 1/2] net: at91_ether: add dt support Jean-Christophe PLAGNIOL-VILLARD
2012-11-04 18:10   ` [PATCH 2/2] net: at91_ether: add pinctrl support Jean-Christophe PLAGNIOL-VILLARD
2012-11-04 22:21   ` [PATCH 1/2] net: at91_ether: add dt support Joachim Eastwood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).