2013-07-01 11:49:35

by Srinivas KANDAGATLA

[permalink] [raw]
Subject: [PATCH RFC 0/3] extend stmmac DT support.

From: Srinivas Kandagatla <[email protected]>

Hi Peppe,

This patch series adds support to new gmac versions 3.6.10 and 3.710, these
versions of IP are integrated into ST STiH415/STiH416 SOCs.
This patchset also adds phy reset capablity to stmmac-mdio driver via DT.


Thanks,
srini

Srinivas Kandagatla (3):
dt:net:stmmac: Allocate platform data only if its NULL.
dt:net:stmmac: Add support to dwmac version 3.610 and 3.710
dt:net:stmmac: Add dt specific phy reset callback support.

Documentation/devicetree/bindings/net/stmmac.txt | 10 ++++++
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 31 ++++++++++++++++++++
.../net/ethernet/stmicro/stmmac/stmmac_platform.c | 31 ++++++++++++++++++--
3 files changed, 69 insertions(+), 3 deletions(-)

--
1.7.6.5


2013-07-01 11:49:39

by Srinivas KANDAGATLA

[permalink] [raw]
Subject: [PATCH RFC 1/3] dt:net:stmmac: Allocate platform data only if its NULL.

From: Srinivas Kandagatla <[email protected]>

In some DT use-cases platform data might be already allocated and passed
via AUXDATA. These are the cases where machine level code populates few
callbacks in the platform data.

This patch adds check and reuses platform_data if its valid, before
allocating a new one.

Signed-off-by: Srinivas Kandagatla <[email protected]>
---
.../net/ethernet/stmicro/stmmac/stmmac_platform.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 1d3780f..5907920 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -92,8 +92,10 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
if (IS_ERR(addr))
return PTR_ERR(addr);

+ plat_dat = pdev->dev.platform_data;
if (pdev->dev.of_node) {
- plat_dat = devm_kzalloc(&pdev->dev,
+ if (!plat_dat)
+ plat_dat = devm_kzalloc(&pdev->dev,
sizeof(struct plat_stmmacenet_data),
GFP_KERNEL);
if (!plat_dat) {
@@ -106,8 +108,6 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
pr_err("%s: main dt probe failed", __func__);
return ret;
}
- } else {
- plat_dat = pdev->dev.platform_data;
}

/* Custom initialisation (if needed)*/
--
1.7.6.5

2013-07-01 11:49:49

by Srinivas KANDAGATLA

[permalink] [raw]
Subject: [PATCH RFC 2/3] dt:net:stmmac: Add support to dwmac version 3.610 and 3.710

From: Srinivas Kandagatla <[email protected]>

This patch adds dt support to dwmac version 3.610 and 3.710 these
versions are integrated in STiH415 and STiH416 ARM A9 SOCs.
To support these IP version, some of the device tree properties are
extended.

Signed-off-by: Srinivas Kandagatla <[email protected]>
---
Documentation/devicetree/bindings/net/stmmac.txt | 4 +++
.../net/ethernet/stmicro/stmmac/stmmac_platform.c | 25 ++++++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/stmmac.txt b/Documentation/devicetree/bindings/net/stmmac.txt
index 060bbf0..e1ddfcc 100644
--- a/Documentation/devicetree/bindings/net/stmmac.txt
+++ b/Documentation/devicetree/bindings/net/stmmac.txt
@@ -12,6 +12,10 @@ Required properties:
property
- phy-mode: String, operation mode of the PHY interface.
Supported values are: "mii", "rmii", "gmii", "rgmii".
+- snps,phy-addr phy address to connect to.
+- snps,pbl Programmable Burst Length
+- snps,fixed-burst Program the DMA to use the fixed burst mode
+- snps,mixed-burst Program the DMA to use the mixed burst mode

Optional properties:
- mac-address: 6 bytes, mac address
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 5907920..060758d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -29,17 +29,26 @@
#include "stmmac.h"

#ifdef CONFIG_OF
+
static int stmmac_probe_config_dt(struct platform_device *pdev,
struct plat_stmmacenet_data *plat,
const char **mac)
{
struct device_node *np = pdev->dev.of_node;
+ struct stmmac_dma_cfg *dma_cfg;

if (!np)
return -ENODEV;

*mac = of_get_mac_address(np);
plat->interface = of_get_phy_mode(np);
+
+ plat->bus_id = of_alias_get_id(np, "ethernet");
+ if (plat->bus_id < 0)
+ plat->bus_id = 0;
+
+ of_property_read_u32(np, "snps,phy-addr", &plat->phy_addr);
+
plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
sizeof(struct stmmac_mdio_bus_data),
GFP_KERNEL);
@@ -51,11 +60,25 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
*/
if (of_device_is_compatible(np, "st,spear600-gmac") ||
of_device_is_compatible(np, "snps,dwmac-3.70a") ||
+ of_device_is_compatible(np, "snps,dwmac-3.610") ||
of_device_is_compatible(np, "snps,dwmac")) {
plat->has_gmac = 1;
plat->pmt = 1;
}

+ if (of_device_is_compatible(np, "snps,dwmac-3.610") ||
+ of_device_is_compatible(np, "snps,dwmac-3.710")) {
+ plat->enh_desc = 1;
+ plat->bugged_jumbo = 1;
+ plat->force_sf_dma_mode = 1;
+ }
+
+ dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*dma_cfg), GFP_KERNEL);
+ plat->dma_cfg = dma_cfg;
+ of_property_read_u32(np, "snps,pbl", &dma_cfg->pbl);
+ dma_cfg->fixed_burst = of_property_read_bool(np, "snps,fixed-burst");
+ dma_cfg->mixed_burst = of_property_read_bool(np, "snps,mixed-burst");
+
return 0;
}
#else
@@ -230,7 +253,9 @@ static const struct dev_pm_ops stmmac_pltfr_pm_ops;

static const struct of_device_id stmmac_dt_ids[] = {
{ .compatible = "st,spear600-gmac"},
+ { .compatible = "snps,dwmac-3.610"},
{ .compatible = "snps,dwmac-3.70a"},
+ { .compatible = "snps,dwmac-3.710"},
{ .compatible = "snps,dwmac"},
{ /* sentinel */ }
};
--
1.7.6.5

2013-07-01 11:49:59

by Srinivas KANDAGATLA

[permalink] [raw]
Subject: [PATCH RFC 3/3] dt:net:stmmac: Add dt specific phy reset callback support.

From: Srinivas Kandagatla <[email protected]>

This patch adds phy reset callback support for stmmac driver via device
trees. It adds three new properties to gmac device tree bindings to
define the reset signal via gpio.

With this patch users can conveniently pass reset gpio number with pre,
pulse and post delay in micro secs via DTs.

active low:
_________ ____________
<pre-delay> |<pulse-delay> |<post-delay>
| |
|_______________|

active high:
________________
<pre-delay> |<pulse-delay> |<post-delay>
| |
________| |___________

Signed-off-by: Srinivas Kandagatla <[email protected]>
---
Documentation/devicetree/bindings/net/stmmac.txt | 6 ++++
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 31 +++++++++++++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/stmmac.txt b/Documentation/devicetree/bindings/net/stmmac.txt
index e1ddfcc..261c563 100644
--- a/Documentation/devicetree/bindings/net/stmmac.txt
+++ b/Documentation/devicetree/bindings/net/stmmac.txt
@@ -13,6 +13,12 @@ Required properties:
- phy-mode: String, operation mode of the PHY interface.
Supported values are: "mii", "rmii", "gmii", "rgmii".
- snps,phy-addr phy address to connect to.
+- snps,reset-gpio gpio number for phy reset.
+- snps,reset-active-low boolean flag to indicate if phy reset is active low.
+- snps,reset-delays-us is triplet of delays
+ The 1st cell is reset pre-delay in micro seconds.
+ The 2nd cell is reset pulse in micro seconds.
+ The 3rd cell is reset post-delay in micro seconds.
- snps,pbl Programmable Burst Length
- snps,fixed-burst Program the DMA to use the fixed burst mode
- snps,mixed-burst Program the DMA to use the mixed burst mode
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index cc15039..677ed16 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -27,6 +27,9 @@
#include <linux/mii.h>
#include <linux/phy.h>
#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+
#include <asm/io.h>

#include "stmmac.h"
@@ -131,6 +134,34 @@ static int stmmac_mdio_reset(struct mii_bus *bus)
struct net_device *ndev = bus->priv;
struct stmmac_priv *priv = netdev_priv(ndev);
unsigned int mii_address = priv->hw->mii.addr;
+ struct device *dev = priv->device;
+
+ if (dev->of_node) {
+ int reset_gpio, active_low;
+ struct device_node *np = dev->of_node;
+ u32 delays[3] = {0,};
+
+ if (!np)
+ return 0;
+
+ reset_gpio = of_get_named_gpio(np, "snps,reset-gpio", 0);
+ if (reset_gpio < 0)
+ return 0;
+
+ active_low = of_property_read_bool(np,
+ "snps,reset-active-low");
+ of_property_read_u32_array(np,
+ "snps,reset-delays-us", delays, 3);
+
+ gpio_request(reset_gpio, "mdio-reset");
+ gpio_direction_output(reset_gpio, active_low ? 1 : 0);
+ udelay(delays[0]);
+ gpio_set_value(reset_gpio, active_low ? 0 : 1);
+ udelay(delays[1]);
+ gpio_set_value(reset_gpio, active_low ? 1 : 0);
+ udelay(delays[2]);
+ gpio_free(reset_gpio);
+ }

if (priv->plat->mdio_bus_data->phy_reset) {
pr_debug("stmmac_mdio_reset: calling phy_reset\n");
--
1.7.6.5

2013-07-01 17:20:41

by Peppe CAVALLARO

[permalink] [raw]
Subject: Re: [PATCH RFC 2/3] dt:net:stmmac: Add support to dwmac version 3.610 and 3.710

On 7/1/2013 1:43 PM, Srinivas KANDAGATLA wrote:
> From: Srinivas Kandagatla <[email protected]>
>
> This patch adds dt support to dwmac version 3.610 and 3.710 these
> versions are integrated in STiH415 and STiH416 ARM A9 SOCs.
> To support these IP version, some of the device tree properties are
> extended.
>
> Signed-off-by: Srinivas Kandagatla <[email protected]>
> ---
> Documentation/devicetree/bindings/net/stmmac.txt | 4 +++
> .../net/ethernet/stmicro/stmmac/stmmac_platform.c | 25 ++++++++++++++++++++
> 2 files changed, 29 insertions(+), 0 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/net/stmmac.txt b/Documentation/devicetree/bindings/net/stmmac.txt
> index 060bbf0..e1ddfcc 100644
> --- a/Documentation/devicetree/bindings/net/stmmac.txt
> +++ b/Documentation/devicetree/bindings/net/stmmac.txt
> @@ -12,6 +12,10 @@ Required properties:
> property
> - phy-mode: String, operation mode of the PHY interface.
> Supported values are: "mii", "rmii", "gmii", "rgmii".
> +- snps,phy-addr phy address to connect to.
> +- snps,pbl Programmable Burst Length
> +- snps,fixed-burst Program the DMA to use the fixed burst mode
> +- snps,mixed-burst Program the DMA to use the mixed burst mode
>
> Optional properties:
> - mac-address: 6 bytes, mac address
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> index 5907920..060758d 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> @@ -29,17 +29,26 @@
> #include "stmmac.h"
>
> #ifdef CONFIG_OF
> +
> static int stmmac_probe_config_dt(struct platform_device *pdev,
> struct plat_stmmacenet_data *plat,
> const char **mac)
> {
> struct device_node *np = pdev->dev.of_node;
> + struct stmmac_dma_cfg *dma_cfg;
>
> if (!np)
> return -ENODEV;
>
> *mac = of_get_mac_address(np);
> plat->interface = of_get_phy_mode(np);
> +
> + plat->bus_id = of_alias_get_id(np, "ethernet");
> + if (plat->bus_id < 0)
> + plat->bus_id = 0;
> +
> + of_property_read_u32(np, "snps,phy-addr", &plat->phy_addr);
> +
> plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
> sizeof(struct stmmac_mdio_bus_data),
> GFP_KERNEL);
> @@ -51,11 +60,25 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
> */
> if (of_device_is_compatible(np, "st,spear600-gmac") ||
> of_device_is_compatible(np, "snps,dwmac-3.70a") ||
> + of_device_is_compatible(np, "snps,dwmac-3.610") ||
> of_device_is_compatible(np, "snps,dwmac")) {
> plat->has_gmac = 1;
> plat->pmt = 1;
> }
>
> + if (of_device_is_compatible(np, "snps,dwmac-3.610") ||
> + of_device_is_compatible(np, "snps,dwmac-3.710")) {
> + plat->enh_desc = 1;
> + plat->bugged_jumbo = 1;
> + plat->force_sf_dma_mode = 1;
> + }

I think some these shouldn't be forced here. Maybe plat->enh_desc could
be set because for new syn mac cores.

Also pmt could not be forced because it is an extra module so it could
happen that a new chip has no PMT block.

> +
> + dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*dma_cfg), GFP_KERNEL);
> + plat->dma_cfg = dma_cfg;
> + of_property_read_u32(np, "snps,pbl", &dma_cfg->pbl);
> + dma_cfg->fixed_burst = of_property_read_bool(np, "snps,fixed-burst");
> + dma_cfg->mixed_burst = of_property_read_bool(np, "snps,mixed-burst");
> +
> return 0;
> }
> #else
> @@ -230,7 +253,9 @@ static const struct dev_pm_ops stmmac_pltfr_pm_ops;
>
> static const struct of_device_id stmmac_dt_ids[] = {
> { .compatible = "st,spear600-gmac"},
> + { .compatible = "snps,dwmac-3.610"},
> { .compatible = "snps,dwmac-3.70a"},
> + { .compatible = "snps,dwmac-3.710"},
> { .compatible = "snps,dwmac"},
> { /* sentinel */ }
> };
>

2013-07-01 17:20:52

by Peppe CAVALLARO

[permalink] [raw]
Subject: Re: [PATCH RFC 1/3] dt:net:stmmac: Allocate platform data only if its NULL.

On 7/1/2013 1:43 PM, Srinivas KANDAGATLA wrote:
> From: Srinivas Kandagatla <[email protected]>
>
> In some DT use-cases platform data might be already allocated and passed
> via AUXDATA. These are the cases where machine level code populates few
> callbacks in the platform data.
>
> This patch adds check and reuses platform_data if its valid, before
> allocating a new one.

Yes, we had seen this long time ago and IIRC i prepared the patch
so

Acked-by: Giuseppe Cavallaro <[email protected]>

>
> Signed-off-by: Srinivas Kandagatla <[email protected]>
> ---
> .../net/ethernet/stmicro/stmmac/stmmac_platform.c | 6 +++---
> 1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> index 1d3780f..5907920 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> @@ -92,8 +92,10 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
> if (IS_ERR(addr))
> return PTR_ERR(addr);
>
> + plat_dat = pdev->dev.platform_data;
> if (pdev->dev.of_node) {
> - plat_dat = devm_kzalloc(&pdev->dev,
> + if (!plat_dat)
> + plat_dat = devm_kzalloc(&pdev->dev,
> sizeof(struct plat_stmmacenet_data),
> GFP_KERNEL);
> if (!plat_dat) {
> @@ -106,8 +108,6 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
> pr_err("%s: main dt probe failed", __func__);
> return ret;
> }
> - } else {
> - plat_dat = pdev->dev.platform_data;
> }
>
> /* Custom initialisation (if needed)*/
>

2013-07-01 17:52:32

by Peppe CAVALLARO

[permalink] [raw]
Subject: Re: [PATCH RFC 1/3] dt:net:stmmac: Allocate platform data only if its NULL.

On 7/1/2013 1:43 PM, Srinivas KANDAGATLA wrote:
> From: Srinivas Kandagatla <[email protected]>
>
> In some DT use-cases platform data might be already allocated and passed
> via AUXDATA. These are the cases where machine level code populates few
> callbacks in the platform data.
>
> This patch adds check and reuses platform_data if its valid, before
> allocating a new one.

Ye, we had seen this long time ago and IIRC i prepared the patch
so

Acked-by: Giuseppe Cavallaro <[email protected]>

>
> Signed-off-by: Srinivas Kandagatla <[email protected]>
> ---
> .../net/ethernet/stmicro/stmmac/stmmac_platform.c | 6 +++---
> 1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> index 1d3780f..5907920 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> @@ -92,8 +92,10 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
> if (IS_ERR(addr))
> return PTR_ERR(addr);
>
> + plat_dat = pdev->dev.platform_data;
> if (pdev->dev.of_node) {
> - plat_dat = devm_kzalloc(&pdev->dev,
> + if (!plat_dat)
> + plat_dat = devm_kzalloc(&pdev->dev,
> sizeof(struct plat_stmmacenet_data),
> GFP_KERNEL);
> if (!plat_dat) {
> @@ -106,8 +108,6 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
> pr_err("%s: main dt probe failed", __func__);
> return ret;
> }
> - } else {
> - plat_dat = pdev->dev.platform_data;
> }
>
> /* Custom initialisation (if needed)*/
>

2013-07-02 06:48:37

by Srinivas KANDAGATLA

[permalink] [raw]
Subject: Re: [PATCH RFC 2/3] dt:net:stmmac: Add support to dwmac version 3.610 and 3.710

Thanks Peppe for the comments,
On 01/07/13 18:20, Giuseppe CAVALLARO wrote:
> On 7/1/2013 1:43 PM, Srinivas KANDAGATLA wrote:
>> From: Srinivas Kandagatla <[email protected]>
>>
>> +
>> + plat->bus_id = of_alias_get_id(np, "ethernet");
>> + if (plat->bus_id < 0)
>> + plat->bus_id = 0;
>> +
>> + of_property_read_u32(np, "snps,phy-addr", &plat->phy_addr);
>> +
>> plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
>> sizeof(struct stmmac_mdio_bus_data),
>> GFP_KERNEL);
>> @@ -51,11 +60,25 @@ static int stmmac_probe_config_dt(struct
>> platform_device *pdev,
>> */
>> if (of_device_is_compatible(np, "st,spear600-gmac") ||
>> of_device_is_compatible(np, "snps,dwmac-3.70a") ||
>> + of_device_is_compatible(np, "snps,dwmac-3.610") ||
I forgot to add "snps,dwmac-3.710" to this list, I will do it in V2 patch.

>> of_device_is_compatible(np, "snps,dwmac")) {
>> plat->has_gmac = 1;
>> plat->pmt = 1;
>> }
>>
>> + if (of_device_is_compatible(np, "snps,dwmac-3.610") ||
>> + of_device_is_compatible(np, "snps,dwmac-3.710")) {
>> + plat->enh_desc = 1;
>> + plat->bugged_jumbo = 1;
>> + plat->force_sf_dma_mode = 1;
>> + }
>
> I think some these shouldn't be forced here. Maybe plat->enh_desc could
> be set because for new syn mac cores.
>
> Also pmt could not be forced because it is an extra module so it could
> happen that a new chip has no PMT block.
I agree with you, But the new chips should/will have different version
numbers, so having the version number in the compatible string should
make it possible for cores without PMT module to not set pmt or any
other properties.

Are you happy with the setting pmt based on compatible string or do you
think passing pmt as another property to device tree makes more sense?

Thanks,
srini

2013-07-02 08:04:53

by Peppe CAVALLARO

[permalink] [raw]
Subject: Re: [PATCH RFC 2/3] dt:net:stmmac: Add support to dwmac version 3.610 and 3.710

On 7/2/2013 8:42 AM, Srinivas KANDAGATLA wrote:
> Are you happy with the setting pmt based on compatible string or do you
> think passing pmt as another property to device tree makes more sense?

I prefer to pass pmt as another property but indeed this is not a big
problem because all the new chips have the HW cap. register to fix
at run-time the driver capability.

This field, as others, was really useful on old mac generations where
sometime the PMT was synthesized, sometime not.

The code should be safe enough because if, for example,
we have a new GMAC but w/o the extended module for PMT, so at probing
time the driver will fix all by looking at the HW cap register and
it will be never able to do WoL.

ciao
peppe