net: dsa: b53: Enable internal GPHY on BCM63268
cover net: dsa: b53: Enable internal GPHY on BCM63268
Some BCM63268 bootloaders do not enable the internal PHYs by default. This patch series adds functionality for the switch driver to configure the gigabit ethernet PHY.
Kyle Hendry (4):
net: dsa: b53: Indicate which BCM63268 port is GPHY
net: dsa: b53: mmap: Add gphy control register as a resource
net: dsa: b53: Add phy_enable(), phy_disable() methods
net: dsa: b53: mmap: Implement phy_enable for BCM63268 gphy
drivers/net/dsa/b53/b53_common.c | 9 +++++++ drivers/net/dsa/b53/b53_mmap.c | 42 ++++++++++++++++++++++++++++++- drivers/net/dsa/b53/b53_priv.h | 3 +++ drivers/net/dsa/b53/b53_regs.h | 7 ++++++ include/linux/platform_data/b53.h | 1 + 5 files changed, 61 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
PATCH 1/4 net: dsa: b53: Indicate which BCM63268 port is GPHY
Add a gphy mask member and initialize for BCM63268.
--- drivers/net/dsa/b53/b53_common.c | 3 +++ drivers/net/dsa/b53/b53_priv.h | 1 + 2 files changed, 4 insertions(+)
drivers/net/dsa/b53/b53_common.c +3 -0
@@ -2319,6 +2319,7 @@ struct b53_chip_data {const char *dev_name;u16 vlans;u16 enabled_ports; +u16 internal_gphy_mask;u8 imp_port;u8 cpu_port;u8 vta_regs[3 ];
@@ -2466,6 +2467,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM63268", .vlans = 4096, .enabled_ports = 0, /* pdata must provide them */ + .internal_gphy_mask = BIT(3), .arl_bins = 4, .arl_buckets = 1024, .imp_port = 8,
@@ -2642,6 +2644,7 @@ static int b53_switch_init(struct b53_device *dev) dev->num_vlans = chip->vlans; dev->num_arl_bins = chip->arl_bins; dev->num_arl_buckets = chip->arl_buckets; + dev->internal_gphy_mask = chip->internal_gphy_mask;break ; } }
drivers/net/dsa/b53/b53_priv.h +1 -0
@@ -128,6 +128,7 @@ struct b53_device {/* used ports mask */ u16 enabled_ports; +u16 internal_gphy_mask;unsigned int imp_port;/* connect specific data */
Signature · 1 line
2.43.0
PATCH 2/4 net: dsa: b53: mmap: Add gphy control register as a resource
In reply to Kyle HendryGive b53 driver access to the gphy control register by passing it in as an optional second reg in the device tree.
--- drivers/net/dsa/b53/b53_mmap.c | 8 +++++++- include/linux/platform_data/b53.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/net/dsa/b53/b53_mmap.c +7 -1
@@ -28,6 +28,7 @@struct b53_mmap_priv {void __iomem *regs; +void __iomem *gphy_ctrl; };static int b53_mmap_read8 (struct b53_device *dev,u8 page,u8 reg,u8 *val)
@@ -251,7 +252,7 @@ static int b53_mmap_probe_of(struct platform_device *pdev,struct device_node *of_ports, *of_port;struct device *dev = &pdev->dev;struct b53_platform_data *pdata; -void __iomem *mem; +void __iomem *mem, *gphy_ctrl; mem =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (mem))
@@ -266,6 +267,10 @@ static int b53_mmap_probe_of(struct platform_device *pdev, pdata->chip_id = (u32 )(unsigned long )device_get_match_data (dev); pdata->big_endian =of_property_read_bool (np,"big-endian" ); + gphy_ctrl =devm_platform_ioremap_resource (pdev,1 ); +if (!IS_ERR (gphy_ctrl)) + pdata->gphy_ctrl = gphy_ctrl; + of_ports =of_get_child_by_name (np,"ports" );if (!of_ports) {dev_err (dev,"no ports child node found\n" );
@@ -312,6 +317,7 @@ static int b53_mmap_probe(struct platform_device *pdev)return -ENOMEM ; priv->regs = pdata->regs; + priv->gphy_ctrl = pdata->gphy_ctrl; dev =b53_switch_alloc (&pdev->dev, &b53_mmap_ops, priv);if (!dev)
include/linux/platform_data/b53.h +1 -0
@@ -32,6 +32,7 @@ struct b53_platform_data {/* only used by MMAP'd driver */ unsigned big_endian:1;void __iomem *regs; + void __iomem *gphy_ctrl; };#endif
Signature · 1 line
2.43.0
PATCH 3/4 net: dsa: b53: Add phy_enable(), phy_disable() methods
In reply to Kyle HendryAdd phy enable/disable to b53 ops to be called when enabling/disabling ports.
--- drivers/net/dsa/b53/b53_common.c | 6 ++++++ drivers/net/dsa/b53/b53_priv.h | 2 ++ 2 files changed, 8 insertions(+)
drivers/net/dsa/b53/b53_common.c +6 -0
@@ -592,6 +592,9 @@ int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)b53_port_set_mcast_flood (dev, port, true);b53_port_set_learning (dev, port, false); +if (dev->ops->phy_enable) + dev->ops->phy_enable (dev, port); +if (dev->ops->irq_enable) ret = dev->ops->irq_enable (dev, port);if (ret)
@@ -630,6 +633,9 @@ void b53_disable_port(struct dsa_switch *ds, int port) reg |=PORT_CTRL_RX_DISABLE |PORT_CTRL_TX_DISABLE ;b53_write8 (dev,B53_CTRL_PAGE ,B53_PORT_CTRL (port), reg); +if (dev->ops->phy_disable) + dev->ops->phy_disable (dev, port); +if (dev->ops->irq_disable) dev->ops->irq_disable (dev, port); }
drivers/net/dsa/b53/b53_priv.h +2 -0
@@ -45,6 +45,8 @@ struct b53_io_ops {int (*phy_write16)(struct b53_device *dev,int addr,int reg,u16 value);int (*irq_enable)(struct b53_device *dev,int port);void (*irq_disable)(struct b53_device *dev,int port); +void (*phy_enable)(struct b53_device *dev,int port); +void (*phy_disable)(struct b53_device *dev,int port);void (*phylink_get_caps)(struct b53_device *dev,int port,struct phylink_config *config); struct phylink_pcs *(*phylink_mac_select_pcs)(struct b53_device *dev,
Signature · 1 line
2.43.0
PATCH 4/4 net: dsa: b53: mmap: Implement phy_enable for BCM63268 gphy
In reply to Kyle HendryAdd register defines for gphy control register. When gphy is enabled, disable low power mode.
--- drivers/net/dsa/b53/b53_mmap.c | 34 ++++++++++++++++++++++++++++++++++ drivers/net/dsa/b53/b53_regs.h | 7 +++++++ 2 files changed, 41 insertions(+)
drivers/net/dsa/b53/b53_mmap.c +34 -0
@@ -230,6 +230,38 @@ static int b53_mmap_phy_write16(struct b53_device *dev, int addr, int reg,return -EIO ; } +static void bcm63268_gphy_set (struct b53_device *dev,bool enable) +{ +struct b53_mmap_priv *priv = dev->priv; +void __iomem *gphy_ctrl = priv->gphy_ctrl; +u32 val; + + val =ioread32be (gphy_ctrl); + +if (enable) + val &= ~(GPHY_CTRL_IDDQ_BIAS |GPHY_CTRL_LOW_PWR ); +else + val |=GPHY_CTRL_IDDQ_BIAS |GPHY_CTRL_LOW_PWR ; + +iowrite32be (val, gphy_ctrl); +} + +static void b53_mmap_phy_enable (struct b53_device *dev,int port) +{ +struct b53_mmap_priv *priv = dev->priv; + +if ((dev->internal_gphy_mask &BIT (port)) && priv->gphy_ctrl) +bcm63268_gphy_set (dev, true); +} + +static void b53_mmap_phy_disable (struct b53_device *dev,int port) +{ +struct b53_mmap_priv *priv = dev->priv; + +if ((dev->internal_gphy_mask &BIT (port)) && priv->gphy_ctrl) +bcm63268_gphy_set (dev, false); +} +static const struct b53_io_ops b53_mmap_ops = { .read8 = b53_mmap_read8, .read16 = b53_mmap_read16,
@@ -243,6 +275,8 @@ static const struct b53_io_ops b53_mmap_ops = { .write64 = b53_mmap_write64, .phy_read16 = b53_mmap_phy_read16, .phy_write16 = b53_mmap_phy_write16, + .phy_enable = b53_mmap_phy_enable, + .phy_disable = b53_mmap_phy_disable, }; static int b53_mmap_probe_of(struct platform_device *pdev,
drivers/net/dsa/b53/b53_regs.h +7 -0
@@ -525,4 +525,11 @@/* CFP Control Register with ports map (8 bit) */ #define B53_CFP_CTRL 0x00 +/************************************************************************* +* Gigabit PHY Control Register +*************************************************************************/ + +#define GPHY_CTRL_IDDQ_BIAS BIT(0) +#define GPHY_CTRL_LOW_PWR BIT(3) +#endif /* !__B53_REGS_H */
Signature · 1 line
2.43.0
Florian Fainelli
maintainerHi Kyle,
Quoted 5 lines · Kyle Hendry
Some BCM63268 bootloaders do not enable the internal PHYs by default. This patch series adds functionality for the switch driver to configure the gigabit ethernet PHY.
Signed-off-by Kyle Hendry <[email protected]>
So the register address you are manipulating logically belongs in the GPIO block (GPIO_GPHY_CTRL) which has become quite a bit of a sundry here. I don't have a strong objection about the approach picked up here but we will need a Device Tree binding update describing the second (and optional) register range.
Thanks
Signature · 1 line
Florian
Andrew Lunn
maintainerQuoted 7 lines · Florian Fainelli
Hi Kyle,
Quoted 4 lines · Kyle Hendry
Some BCM63268 bootloaders do not enable the internal PHYs by default. This patch series adds functionality for the switch driver to configure the gigabit ethernet PHY.
Quoted 7 lines
Quoted 1 line
Signed-off-by Kyle Hendry <[email protected]>So the register address you are manipulating logically belongs in the GPIO block (
GPIO_GPHY_CTRL) which has become quite a bit of a sundry here. I don't have a strong objection about the approach picked up here but we will need a Device Tree binding update describing the second (and optional) register range.
Despite this being internal, is this actually a GPIO? Should it be modelled as a GPIO line connected to a reset input on the PHY? It would then nicely fit in the existing phylib handling of a PHY with a GPIO reset line?
Andrew
Quoted 14 lines · Andrew Lunn
Quoted 7 lines · Florian Fainelli
Hi Kyle,
Quoted 4 lines · Kyle Hendry
Some BCM63268 bootloaders do not enable the internal PHYs by default. This patch series adds functionality for the switch driver to configure the gigabit ethernet PHY.
Quoted 6 lines
Quoted 1 line
Signed-off-by Kyle Hendry <[email protected]>So the register address you are manipulating logically belongs in the GPIO block (
GPIO_GPHY_CTRL) which has become quite a bit of a sundry here. I don't have a strong objection about the approach picked up here but we will need a Device Tree binding update describing the second (and optional) register range.
Quoted 6 lines
Despite this being internal, is this actually a GPIO? Should it be modelled as a GPIO line connected to a reset input on the PHY? It would then nicely fit in the existing phylib handling of a PHY with a GPIO reset line?
Andrew
The main reason I took this approach is because a SF2 register has similar bits and I wanted to be consistent with that driver. If it makes more sense to treat these bits as GPIOs/clocks/resets then it would make the implementation simpler.
Best Regards,
Kyle
Vladimir Oltean
maintainerQuoted 20 lines · Kyle Hendry
Quoted 19 lines · Andrew Lunn
Quoted 7 lines · Florian Fainelli
Hi Kyle,
Quoted 4 lines · Kyle Hendry
Some BCM63268 bootloaders do not enable the internal PHYs by default. This patch series adds functionality for the switch driver to configure the gigabit ethernet PHY.
Quoted 6 lines
Quoted 1 line
Signed-off-by Kyle Hendry <[email protected]>So the register address you are manipulating logically belongs in the GPIO block (
GPIO_GPHY_CTRL) which has become quite a bit of a sundry here. I don't have a strong objection about the approach picked up here but we will need a Device Tree binding update describing the second (and optional) register range.Despite this being internal, is this actually a GPIO? Should it be modelled as a GPIO line connected to a reset input on the PHY? It would then nicely fit in the existing phylib handling of a PHY with a GPIO reset line?
Quoted 5 lines
Quoted 1 line
Andrew
The main reason I took this approach is because a SF2 register has similar bits and I wanted to be consistent with that driver. If it makes more sense to treat these bits as GPIOs/clocks/resets then it would make the implementation simpler.
This has not always been clear, but we prefer handling components unrelated to Ethernet switching outside of DSA, if at all possible.
Quoted 21 lines · Kyle Hendry
Quoted 19 lines · Andrew Lunn
Quoted 7 lines · Florian Fainelli
Hi Kyle,
Quoted 4 lines · Kyle Hendry
Some BCM63268 bootloaders do not enable the internal PHYs by default. This patch series adds functionality for the switch driver to configure the gigabit ethernet PHY.
Quoted 6 lines
Quoted 1 line
Signed-off-by Kyle Hendry <[email protected]>So the register address you are manipulating logically belongs in the GPIO block (
GPIO_GPHY_CTRL) which has become quite a bit of a sundry here. I don't have a strong objection about the approach picked up here but we will need a Device Tree binding update describing the second (and optional) register range.Despite this being internal, is this actually a GPIO? Should it be modelled as a GPIO line connected to a reset input on the PHY? It would then nicely fit in the existing phylib handling of a PHY with a GPIO reset line?
Quoted 5 lines
Quoted 1 line
Andrew
The main reason I took this approach is because a SF2 register has similar bits and I wanted to be consistent with that driver. If it makes more sense to treat these bits as GPIOs/clocks/resets then it would make the implementation simpler.
I don't think there is a need to go that far, and I don't think any of those abstractions work really well in the sense that they are neither clocks, nor resets, nor GPIOs, they are just enable bits for the power gating logic of the PHY, power domains would be the closest to what this is, but this is a very heavy handed approach with little benefit IMHO.
What we do need is document this register in the binding however.
Signature · 1 line
Florian
Andrew Lunn
maintainerQuoted 30 lines · Florian Fainelli
Quoted 23 lines · Kyle Hendry
Quoted 21 lines · Andrew Lunn
Quoted 7 lines · Florian Fainelli
Hi Kyle,
Quoted 4 lines · Kyle Hendry
Some BCM63268 bootloaders do not enable the internal PHYs by default. This patch series adds functionality for the switch driver to configure the gigabit ethernet PHY.
Quoted 8 lines
Quoted 1 line
Signed-off-by Kyle Hendry <[email protected]>So the register address you are manipulating logically belongs in the GPIO
block (GPIO_GPHY_CTRL) which has become quite a bit of a sundry here. I don't have a strong objection about the approach picked up here but we will
need a Device Tree binding update describing the second (and optional) register range.Despite this being internal, is this actually a GPIO? Should it be modelled as a GPIO line connected to a reset input on the PHY? It would then nicely fit in the existing phylib handling of a PHY with a GPIO reset line?
Quoted 5 lines
Quoted 1 line
Andrew
The main reason I took this approach is because a SF2 register has similar bits and I wanted to be consistent with that driver. If it makes more sense to treat these bits as GPIOs/clocks/resets then it would make the implementation simpler.
Quoted 5 lines
I don't think there is a need to go that far, and I don't think any of those abstractions work really well in the sense that they are neither clocks, nor resets, nor GPIOs, they are just enable bits for the power gating logic of the PHY, power domains would be the closest to what this is, but this is a very heavy handed approach with little benefit IMHO.
O.K. The naming is not particularly helpful. It is in the GPIO block, and named GPIO_GPHY_CTRL so it kind of sounds like a GPIO. If the existing GPIO driver could expose it as a GPIO it would of been a lot simpler.
If the SF2 has similar bits, could the SF2 code be shared?
Andrew
Florian Fainelli
maintainerQuoted 37 lines · Andrew Lunn
Quoted 30 lines · Florian Fainelli
Quoted 23 lines · Kyle Hendry
Quoted 21 lines · Andrew Lunn
Quoted 7 lines · Florian Fainelli
Hi Kyle,
Quoted 4 lines · Kyle Hendry
Some BCM63268 bootloaders do not enable the internal PHYs by default. This patch series adds functionality for the switch driver to configure the gigabit ethernet PHY.
Quoted 8 lines
Quoted 1 line
Signed-off-by Kyle Hendry <[email protected]>So the register address you are manipulating logically belongs in the GPIO
block (GPIO_GPHY_CTRL) which has become quite a bit of a sundry here. I don't have a strong objection about the approach picked up here but we will
need a Device Tree binding update describing the second (and optional) register range.Despite this being internal, is this actually a GPIO? Should it be modelled as a GPIO line connected to a reset input on the PHY? It would then nicely fit in the existing phylib handling of a PHY with a GPIO reset line?
Quoted 5 lines
Quoted 1 line
Andrew
The main reason I took this approach is because a SF2 register has similar bits and I wanted to be consistent with that driver. If it makes more sense to treat these bits as GPIOs/clocks/resets then it would make the implementation simpler.
Quoted 5 lines
I don't think there is a need to go that far, and I don't think any of those abstractions work really well in the sense that they are neither clocks, nor resets, nor GPIOs, they are just enable bits for the power gating logic of the PHY, power domains would be the closest to what this is, but this is a very heavy handed approach with little benefit IMHO.
Quoted 4 lines
O.K. The naming is not particularly helpful. It is in the GPIO block, and named
GPIO_GPHY_CTRLso it kind of sounds like a GPIO. If the existing GPIO driver could expose it as a GPIO it would of been a lot simpler.
You are no stranger to what HW designers like to do: use whatever existing hardware block already exists to add random enable and status bits to control whatever they fancy that was not exposed before. This happens whenever SW/FW people don't push back and ask for proper compartmentalization and abstractions to be used. Sometimes layout and schedule also play a role, but more often than not, it's "just software" so you can update to to account for the fact that bit is there, and not here, right?
This one is exactly what happened: there was spare room in the decoding address space of the register block, so it was natural from there to add a 32-bit word that would hold the enable bits for the internal Gigabit PHY... Those bits are not GPIOs, they are just simple enable/control bits feeding an internal signal.
Quoted 2 lines
If the SF2 has similar bits, could the SF2 code be shared?
The SF2 single GPHY control register is different and more standardized in many ways, so I don't see much value in sharing that code. The SWITCH_REG register block in that case does follow a consistent layout across different product lines.
Signature · 1 line
Florian