Re: [RFC PATCH] net: stmmac: Add OXNAS Glue Driver

2016-10-21 Thread Neil Armstrong
On 10/20/2016 06:26 PM, Joachim Eastwood wrote:
> Hi Neil,
> 
> On 20 October 2016 at 17:54, Neil Armstrong  wrote:
>> Add Synopsys Designware MAC Glue layer for the Oxford Semiconductor OX820.
>>
>> Signed-off-by: Neil Armstrong 
>> ---
>>  .../devicetree/bindings/net/oxnas-dwmac.txt|  44 ++
>>  drivers/net/ethernet/stmicro/stmmac/Kconfig|  11 ++
>>  drivers/net/ethernet/stmicro/stmmac/Makefile   |   1 +
>>  drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c  | 173 
>> +
>>  4 files changed, 229 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/net/oxnas-dwmac.txt
>>  create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
> 
>> +
>> +static int oxnas_dwmac_probe(struct platform_device *pdev)
>> +{
>> +   struct plat_stmmacenet_data *plat_dat;
>> +   struct stmmac_resources stmmac_res;
>> +   struct device_node *sysctrl;
>> +   struct oxnas_dwmac *dwmac;
>> +   int ret;
>> +
>> +   sysctrl = of_parse_phandle(pdev->dev.of_node, "oxsemi,sys-ctrl", 0);
>> +   if (!sysctrl) {
>> +   dev_err(>dev, "failed to get sys-ctrl node\n");
>> +   return -EINVAL;
>> +   }
>> +
>> +   ret = stmmac_get_platform_resources(pdev, _res);
>> +   if (ret)
>> +   return ret;
>> +
>> +   plat_dat = stmmac_probe_config_dt(pdev, _res.mac);
>> +   if (IS_ERR(plat_dat))
>> +   return PTR_ERR(plat_dat);
>> +
>> +   dwmac = devm_kzalloc(>dev, sizeof(*dwmac), GFP_KERNEL);
>> +   if (!dwmac)
>> +   return -ENOMEM;
>> +
>> +   dwmac->regmap = syscon_node_to_regmap(sysctrl);
>> +   if (IS_ERR(dwmac->regmap)) {
>> +   dev_err(>dev, "failed to have sysctrl regmap\n");
>> +   return PTR_ERR(dwmac->regmap);
>> +   }
>> +
>> +   dwmac->clk = devm_clk_get(>dev, "gmac");
>> +   if (IS_ERR(dwmac->clk))
>> +   return PTR_ERR(dwmac->clk);
>> +
>> +   plat_dat->bsp_priv = dwmac;
>> +   plat_dat->init = oxnas_dwmac_init;
>> +   plat_dat->exit = oxnas_dwmac_exit;
> 
> Please do not use the init/exit callbacks. Implement proper driver
> callbacks instead. I.e: PM resume/suspend and driver remove.
> 
> Shouldn't you call oxnas_dwmac_init() from probe as well?
> As it is now it will only be called during PM resume and that can't be right.
> 
> 
>> +
>> +   return stmmac_dvr_probe(>dev, plat_dat, _res);
> 
> If stmmac_dvr_probe() fails you should disable your clocks.
> 
> 
> regards,
> Joachim Eastwood
> 

Hi Joachim,

Thanks for the hints, stm32 glue does that and I will sync on it.

Neil


Re: [RFC PATCH] net: stmmac: Add OXNAS Glue Driver

2016-10-20 Thread Joachim Eastwood
Hi Neil,

On 20 October 2016 at 17:54, Neil Armstrong  wrote:
> Add Synopsys Designware MAC Glue layer for the Oxford Semiconductor OX820.
>
> Signed-off-by: Neil Armstrong 
> ---
>  .../devicetree/bindings/net/oxnas-dwmac.txt|  44 ++
>  drivers/net/ethernet/stmicro/stmmac/Kconfig|  11 ++
>  drivers/net/ethernet/stmicro/stmmac/Makefile   |   1 +
>  drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c  | 173 
> +
>  4 files changed, 229 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/net/oxnas-dwmac.txt
>  create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c

> +
> +static int oxnas_dwmac_probe(struct platform_device *pdev)
> +{
> +   struct plat_stmmacenet_data *plat_dat;
> +   struct stmmac_resources stmmac_res;
> +   struct device_node *sysctrl;
> +   struct oxnas_dwmac *dwmac;
> +   int ret;
> +
> +   sysctrl = of_parse_phandle(pdev->dev.of_node, "oxsemi,sys-ctrl", 0);
> +   if (!sysctrl) {
> +   dev_err(>dev, "failed to get sys-ctrl node\n");
> +   return -EINVAL;
> +   }
> +
> +   ret = stmmac_get_platform_resources(pdev, _res);
> +   if (ret)
> +   return ret;
> +
> +   plat_dat = stmmac_probe_config_dt(pdev, _res.mac);
> +   if (IS_ERR(plat_dat))
> +   return PTR_ERR(plat_dat);
> +
> +   dwmac = devm_kzalloc(>dev, sizeof(*dwmac), GFP_KERNEL);
> +   if (!dwmac)
> +   return -ENOMEM;
> +
> +   dwmac->regmap = syscon_node_to_regmap(sysctrl);
> +   if (IS_ERR(dwmac->regmap)) {
> +   dev_err(>dev, "failed to have sysctrl regmap\n");
> +   return PTR_ERR(dwmac->regmap);
> +   }
> +
> +   dwmac->clk = devm_clk_get(>dev, "gmac");
> +   if (IS_ERR(dwmac->clk))
> +   return PTR_ERR(dwmac->clk);
> +
> +   plat_dat->bsp_priv = dwmac;
> +   plat_dat->init = oxnas_dwmac_init;
> +   plat_dat->exit = oxnas_dwmac_exit;

Please do not use the init/exit callbacks. Implement proper driver
callbacks instead. I.e: PM resume/suspend and driver remove.

Shouldn't you call oxnas_dwmac_init() from probe as well?
As it is now it will only be called during PM resume and that can't be right.


> +
> +   return stmmac_dvr_probe(>dev, plat_dat, _res);

If stmmac_dvr_probe() fails you should disable your clocks.


regards,
Joachim Eastwood


[RFC PATCH] net: stmmac: Add OXNAS Glue Driver

2016-10-20 Thread Neil Armstrong
Add Synopsys Designware MAC Glue layer for the Oxford Semiconductor OX820.

Signed-off-by: Neil Armstrong 
---
 .../devicetree/bindings/net/oxnas-dwmac.txt|  44 ++
 drivers/net/ethernet/stmicro/stmmac/Kconfig|  11 ++
 drivers/net/ethernet/stmicro/stmmac/Makefile   |   1 +
 drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c  | 173 +
 4 files changed, 229 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/oxnas-dwmac.txt
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c

diff --git a/Documentation/devicetree/bindings/net/oxnas-dwmac.txt 
b/Documentation/devicetree/bindings/net/oxnas-dwmac.txt
new file mode 100644
index 000..5d2696c
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/oxnas-dwmac.txt
@@ -0,0 +1,44 @@
+* Oxford Semiconductor OXNAS DWMAC Ethernet controller
+
+The device inherits all the properties of the dwmac/stmmac devices
+described in the file stmmac.txt in the current directory with the
+following changes.
+
+Required properties on all platforms:
+
+- compatible:  Depending on the platform this should be one of:
+   - "oxsemi,ox820-dwmac"
+   Additionally "snps,dwmac" and any applicable more
+   detailed version number described in net/stmmac.txt
+   should be used.
+
+- reg: The first register range should be the one of the DWMAC
+   controller.
+
+- clocks: Should contain phandles to the following clocks
+- clock-names: Should contain the following:
+   - "stmmaceth" - see stmmac.txt
+   - "gmac" - peripheral gate clock
+
+- oxsemi,sys-ctrl: a phandle to the system controller syscon node
+
+Example :
+
+etha: ethernet@4040 {
+   compatible = "oxsemi,ox820-dwmac", "snps,dwmac";
+   reg = <0x4040 0x2000>;
+   interrupts = ,
+;
+   interrupt-names = "macirq", "eth_wake_irq";
+   mac-address = []; /* Filled in by U-Boot */
+   phy-mode = "rgmii";
+
+   clocks = < CLK_820_ETHA>, <>;
+   clock-names = "gmac", "stmmaceth";
+   resets = < RESET_MAC>;
+
+   /* Regmap for sys registers */
+   oxsemi,sys-ctrl = <>;
+
+   status = "disabled";
+};
diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig 
b/drivers/net/ethernet/stmicro/stmmac/Kconfig
index 3818c5e..27ed913 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
+++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
@@ -62,6 +62,7 @@ config DWMAC_MESON
tristate "Amlogic Meson dwmac support"
default ARCH_MESON
depends on OF && COMMON_CLK && (ARCH_MESON || COMPILE_TEST)
+   select MFD_SYSCON
help
  Support for Ethernet controller on Amlogic Meson SoCs.
 
@@ -69,6 +70,16 @@ config DWMAC_MESON
  the stmmac device driver. This driver is used for Meson6,
  Meson8, Meson8b and GXBB SoCs.
 
+config DWMAC_OXNAS
+   tristate "Oxford Semiconductor OXNAS dwmac support"
+   default ARCH_OXNAS
+   depends on OF && COMMON_CLK && (ARCH_OXNAS || COMPILE_TEST)
+   help
+ Support for Ethernet controller on Oxford Semiconductor OXNAS SoCs.
+
+ This selects the Oxford Semiconductor OXNASSoC glue layer support for
+ the stmmac device driver. This driver is used for OX820.
+
 config DWMAC_ROCKCHIP
tristate "Rockchip dwmac support"
default ARCH_ROCKCHIP
diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile 
b/drivers/net/ethernet/stmicro/stmmac/Makefile
index 5d6ece5..8f83a86 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Makefile
+++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_STMMAC_PLATFORM) += stmmac-platform.o
 obj-$(CONFIG_DWMAC_IPQ806X)+= dwmac-ipq806x.o
 obj-$(CONFIG_DWMAC_LPC18XX)+= dwmac-lpc18xx.o
 obj-$(CONFIG_DWMAC_MESON)  += dwmac-meson.o dwmac-meson8b.o
+obj-$(CONFIG_DWMAC_OXNAS)  += dwmac-oxnas.o
 obj-$(CONFIG_DWMAC_ROCKCHIP)   += dwmac-rk.o
 obj-$(CONFIG_DWMAC_SOCFPGA)+= dwmac-altr-socfpga.o
 obj-$(CONFIG_DWMAC_STI)+= dwmac-sti.o
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
new file mode 100644
index 000..c65f3a6
--- /dev/null
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
@@ -0,0 +1,173 @@
+/*
+ * Oxford Semiconductor OXNAS DWMAC glue layer
+ *
+ * Copyright (C) 2016 Neil Armstrong 
+ * Copyright (C) 2014 Daniel Golle 
+ * Copyright (C) 2013 Ma Haijun 
+ * Copyright (C) 2012 John Crispin 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see