net: bcmgenet: enable driver to work without a device tree
Subsystems (3)
PATCH v2 1/1 net: bcmgenet: enable driver to work without a device tree
Broadcom 7xxx MIPS-based STB platforms do not use device trees. Modify bcmgenet driver so that it can be used on those platforms.
--- drivers/net/ethernet/broadcom/Kconfig | 1 - drivers/net/ethernet/broadcom/genet/bcmgenet.c | 31 ++++-- drivers/net/ethernet/broadcom/genet/bcmmii.c | 134 +++++++++++++++++++++---- include/linux/platform_data/bcmgenet.h | 18 ++++ 4 files changed, 152 insertions(+), 32 deletions(-) create mode 100644 include/linux/platform_data/bcmgenet.h
drivers/net/ethernet/broadcom/Kconfig +0 -1
@@ -62,7 +62,6 @@ config BCM63XX_ENET config BCMGENET tristate "Broadcom GENET internal MAC support" - depends on OF select MII select PHYLIB select FIXED_PHY if BCMGENET=y
drivers/net/ethernet/broadcom/genet/bcmgenet.c +22 -9
@@ -42,6 +42,7 @@#include <linux/ip.h> #include <linux/ipv6.h> #include <linux/phy.h> +#include <linux/platform_data/bcmgenet.h> #include <asm/unaligned.h>
@@ -2586,6 +2587,7 @@ static const struct of_device_id bcmgenet_match[] = {static int bcmgenet_probe (struct platform_device *pdev) { +struct bcmgenet_platform_data *pd = pdev->dev.platform_data;struct device_node *dn = pdev->dev.of_node;const struct of_device_id *of_id;struct bcmgenet_priv *priv;
@@ -2601,9 +2603,13 @@ static int bcmgenet_probe(struct platform_device *pdev)return -ENOMEM ; } - of_id =of_match_node (bcmgenet_match, dn); -if (!of_id) -return -EINVAL ; +if (dn) { + of_id =of_match_node (bcmgenet_match, dn); +if (!of_id) +return -EINVAL ; + }else { + of_id =NULL ; + } priv =netdev_priv (dev); priv->irq0 =platform_get_irq (pdev,0 );
@@ -2615,11 +2621,15 @@ static int bcmgenet_probe(struct platform_device *pdev) goto err; } - macaddr =of_get_mac_address (dn); -if (!macaddr) { -dev_err (&pdev->dev,"can't find MAC address\n" ); - err = -EINVAL ; - goto err; +if (dn) { + macaddr =of_get_mac_address (dn); +if (!macaddr) { +dev_err (&pdev->dev,"can't find MAC address\n" ); + err = -EINVAL ; + goto err; + } + }else { + macaddr = pd->macaddr; } r =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
@@ -2659,7 +2669,10 @@ static int bcmgenet_probe(struct platform_device *pdev) priv->dev = dev; priv->pdev = pdev; - priv->version = (enum bcmgenet_version )of_id->data; +if (of_id) + priv->version = (enum bcmgenet_version )of_id->data; +else + priv->version = pd->genet_version; priv->clk =devm_clk_get (&priv->pdev->dev,"enet" );if (IS_ERR (priv->clk))
drivers/net/ethernet/broadcom/genet/bcmmii.c +112 -22
164 lines not on this page · raw message
include/linux/platform_data/bcmgenet.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef __LINUX_PLATFORM_DATA_BCMGENET_H__ +#define __LINUX_PLATFORM_DATA_BCMGENET_H__ + +#include <linux/compiler.h> +#include <linux/if_ether.h> + +struct bcmgenet_platform_data { +void __iomem *base_reg; +int irq0; +int irq1; +bool mdio_enabled; +int phy_type; +int phy_addr; +u8 macaddr[ETH_ALEN ]; +int genet_version; +}; + +#endif
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Quoted 2 lines · Petri Gynther
Broadcom 7xxx MIPS-based STB platforms do not use device trees. Modify bcmgenet driver so that it can be used on those platforms.
Well, that statement is technically not true anymore thanks to Kevin's recent efforts, but this is not exactly what we have been advertising/supporting so far.
Looks mostly good to me, some minor nits below:
Quoted 3 lines
Signed-off-by Petri Gynther <[email protected]>---
[snip]
drivers/net/ethernet/broadcom/genet/bcmgenet.c static int bcmgenet_probe(struct platform_device *pdev) · line 2612
Quoted 7 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +7
-0+if (dn) { + of_id =of_match_node (bcmgenet_match, dn); +if (!of_id) +return -EINVAL ; + }else { + of_id =NULL ; + }
You could probably get way with this else condition by assigning of_id to NULL by default.
[snip]
drivers/net/ethernet/broadcom/genet/bcmmii.c static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv) · line 487
Quoted 10 lines
drivers/net/ethernet/broadcom/genet/bcmmii.c +10
-0+if (pd->phy_addr >=0 && pd->phy_addr <PHY_MAX_ADDR ) { + phydev = mdio->phy_map[pd->phy_addr]; + }else { + phydev =NULL ; +for (i =0 ; i <PHY_MAX_ADDR ; i++) { +if (mdio->phy_map[i]) { + phydev = mdio->phy_map[i]; +break ; + } + }
phy_find_first() might provide a shorter version of this.
Quoted 15 lines
drivers/net/ethernet/broadcom/genet/bcmmii.c +15
-0+ } + +if (!phydev) { +dev_err (kdev,"failed to register PHY device\n" ); +mdiobus_unregister (mdio); +return -ENODEV ; + } + }else { +/* +* MoCA port or no MDIO access. +* Use 1000/FD fixed PHY to represent the link layer. +*/ +struct fixed_phy_status fphy_status = { + .link =1 , + .duplex = DUPLEX_FULL,
drivers/net/ethernet/broadcom/genet/bcmmii.c static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv) · line 512
Quoted 10 lines
drivers/net/ethernet/broadcom/genet/bcmmii.c +10
-0+ .speed = SPEED_1000, + .pause = 0, + .asym_pause = 0, + }; + + phydev =fixed_phy_register (PHY_POLL , &fphy_status,NULL ); +if (!phydev ||IS_ERR (phydev)) { +dev_err (kdev,"failed to register fixed PHY device\n" ); +return -ENODEV ; + }
This is typically done by platform code (not necessarily for good reasons though) but I cannot seen any problems with doing this here as well.
[snip]
include/linux/platform_data/bcmgenet.h line 4
Quoted 10 lines
include/linux/platform_data/bcmgenet.h new file +4
-0@@ -0,0 +1,18 @@ +#ifndef __LINUX_PLATFORM_DATA_BCMGENET_H__ +#define __LINUX_PLATFORM_DATA_BCMGENET_H__ + +#include <linux/compiler.h>
That include does not look necessary, you might want linux/types.h for "u8" though.
include/linux/platform_data/bcmgenet.h line 10
Quoted 6 lines
include/linux/platform_data/bcmgenet.h new file +6
-0+#include <linux/if_ether.h> + +struct bcmgenet_platform_data { +void __iomem *base_reg; +int irq0; +int irq1;
These 3 members are unused and should be communicated to the driver as resources, not side parameters, can you get rid of them?
include/linux/platform_data/bcmgenet.h line 12
Quoted 2 lines
include/linux/platform_data/bcmgenet.h new file +2
-0+bool mdio_enabled; +int phy_type;
This is essentially phy_interface_t, so let's use that type directly here.
include/linux/platform_data/bcmgenet.h line 15
Quoted 3 lines
include/linux/platform_data/bcmgenet.h new file +3
-0+int phy_addr; +u8 macaddr[ETH_ALEN ]; +int genet_version;
That is also an enum, if that helps, you could move it from drivers/net/ethernet/broadcom/bcmgenet.h there as well. --
Florian
Quoted 60 lines · Florian Fainelli
Quoted 2 lines · Petri Gynther
Broadcom 7xxx MIPS-based STB platforms do not use device trees. Modify bcmgenet driver so that it can be used on those platforms.
Well, that statement is technically not true anymore thanks to Kevin's recent efforts, but this is not exactly what we have been advertising/supporting so far.
Looks mostly good to me, some minor nits below:
Quoted 3 lines
Signed-off-by Petri Gynther <[email protected]>---
[snip]
drivers/net/ethernet/broadcom/genet/bcmgenet.c static int bcmgenet_probe(struct platform_device *pdev) · line 2612
Quoted 7 lines
drivers/net/ethernet/broadcom/genet/bcmgenet.c +7
-0+if (dn) { + of_id =of_match_node (bcmgenet_match, dn); +if (!of_id) +return -EINVAL ; + }else { + of_id =NULL ; + }You could probably get way with this else condition by assigning
of_idto NULL by default.[snip]
drivers/net/ethernet/broadcom/genet/bcmmii.c static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv) · line 487
Quoted 10 lines
drivers/net/ethernet/broadcom/genet/bcmmii.c +10
-0+if (pd->phy_addr >=0 && pd->phy_addr <PHY_MAX_ADDR ) { + phydev = mdio->phy_map[pd->phy_addr]; + }else { + phydev =NULL ; +for (i =0 ; i <PHY_MAX_ADDR ; i++) { +if (mdio->phy_map[i]) { + phydev = mdio->phy_map[i]; +break ; + } + }
phy_find_first()might provide a shorter version of this.Quoted 20 lines
drivers/net/ethernet/broadcom/genet/bcmmii.c +20
-0+ } + +if (!phydev) { +dev_err (kdev,"failed to register PHY device\n" ); +mdiobus_unregister (mdio); +return -ENODEV ; + } + }else { +/* +* MoCA port or no MDIO access. +* Use 1000/FD fixed PHY to represent the link layer. +*/ +struct fixed_phy_status fphy_status = { + .link =1 , + .duplex =DUPLEX_FULL , + .speed =SPEED_1000 , + .pause =0 , + .asym_pause =0 , + }; +
Quoted 8 lines
drivers/net/ethernet/broadcom/genet/bcmmii.c static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv) · line 512
Quoted 5 lines
drivers/net/ethernet/broadcom/genet/bcmmii.c +5
-0+ phydev =fixed_phy_register (PHY_POLL , &fphy_status,NULL ); +if (!phydev ||IS_ERR (phydev)) { +dev_err (kdev,"failed to register fixed PHY device\n" ); +return -ENODEV ; + }This is typically done by platform code (not necessarily for good reasons though) but I cannot seen any problems with doing this here as well.
Well actually there could be one issue, we don't want to assume 1Gbits/sec here, we would want to be communicated a speed information (typically ETH0_SPEED) in CFE so we can program the link parameters accordingly, just in case someone interfaces this GENET instance with e.g: a non-MDIO managed external 10/100 switch.
Quoted 41 lines
[snip]
include/linux/platform_data/bcmgenet.h line 4
Quoted 10 lines
include/linux/platform_data/bcmgenet.h new file +4
-0@@ -0,0 +1,18 @@ +#ifndef __LINUX_PLATFORM_DATA_BCMGENET_H__ +#define __LINUX_PLATFORM_DATA_BCMGENET_H__ + +#include <linux/compiler.h> That include does not look necessary, you might want
linux/types.hfor "u8" though.include/linux/platform_data/bcmgenet.h line 10
Quoted 6 lines
include/linux/platform_data/bcmgenet.h new file +6
-0+#include <linux/if_ether.h> + +struct bcmgenet_platform_data { +void __iomem *base_reg; +int irq0; +int irq1;These 3 members are unused and should be communicated to the driver as resources, not side parameters, can you get rid of them?
include/linux/platform_data/bcmgenet.h line 12
Quoted 2 lines
include/linux/platform_data/bcmgenet.h new file +2
-0+bool mdio_enabled; +int phy_type;This is essentially
phy_interface_t, so let's use that type directly here.include/linux/platform_data/bcmgenet.h line 15
Quoted 3 lines
include/linux/platform_data/bcmgenet.h new file +3
-0+int phy_addr; +u8 macaddr[ETH_ALEN ]; +int genet_version;That is also an enum, if that helps, you could move it from
drivers/net/ethernet/broadcom/bcmgenet.hthere as well. --
Florian