Skip to content

Commit 5ac0002

Browse files
kylehendrydevkuba-moo
authored andcommitted
net: dsa: b53: mmap: Implement bcm63xx ephy power control
Implement the phy enable/disable calls for b53 mmap, and set the power down registers in the ephy control register appropriately. Signed-off-by: Kyle Hendry <kylehendrydev@gmail.com> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> Link: https://patch.msgid.link/20250724035300.20497-8-kylehendrydev@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent e8e1307 commit 5ac0002

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

drivers/net/dsa/b53/b53_mmap.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
#include <linux/mfd/syscon.h>
2525
#include <linux/platform_device.h>
2626
#include <linux/platform_data/b53.h>
27+
#include <linux/regmap.h>
2728

2829
#include "b53_priv.h"
2930

31+
#define BCM63XX_EPHY_REG 0x3C
32+
3033
struct b53_phy_info {
3134
u32 ephy_enable_mask;
3235
u32 ephy_port_mask;
@@ -38,6 +41,7 @@ struct b53_mmap_priv {
3841
void __iomem *regs;
3942
struct regmap *gpio_ctrl;
4043
const struct b53_phy_info *phy_info;
44+
u32 phys_enabled;
4145
};
4246

4347
static const u32 bcm6318_ephy_offsets[] = {4, 5, 6, 7};
@@ -266,6 +270,50 @@ static int b53_mmap_phy_write16(struct b53_device *dev, int addr, int reg,
266270
return -EIO;
267271
}
268272

273+
static int bcm63xx_ephy_set(struct b53_device *dev, int port, bool enable)
274+
{
275+
struct b53_mmap_priv *priv = dev->priv;
276+
const struct b53_phy_info *info = priv->phy_info;
277+
struct regmap *gpio_ctrl = priv->gpio_ctrl;
278+
u32 mask, val;
279+
280+
if (enable) {
281+
mask = (info->ephy_enable_mask << info->ephy_offset[port])
282+
| BIT(info->ephy_bias_bit);
283+
val = 0;
284+
} else {
285+
mask = (info->ephy_enable_mask << info->ephy_offset[port]);
286+
if (!((priv->phys_enabled & ~BIT(port)) & info->ephy_port_mask))
287+
mask |= BIT(info->ephy_bias_bit);
288+
val = mask;
289+
}
290+
return regmap_update_bits(gpio_ctrl, BCM63XX_EPHY_REG, mask, val);
291+
}
292+
293+
static void b53_mmap_phy_enable(struct b53_device *dev, int port)
294+
{
295+
struct b53_mmap_priv *priv = dev->priv;
296+
int ret = 0;
297+
298+
if (priv->phy_info && (BIT(port) & priv->phy_info->ephy_port_mask))
299+
ret = bcm63xx_ephy_set(dev, port, true);
300+
301+
if (!ret)
302+
priv->phys_enabled |= BIT(port);
303+
}
304+
305+
static void b53_mmap_phy_disable(struct b53_device *dev, int port)
306+
{
307+
struct b53_mmap_priv *priv = dev->priv;
308+
int ret = 0;
309+
310+
if (priv->phy_info && (BIT(port) & priv->phy_info->ephy_port_mask))
311+
ret = bcm63xx_ephy_set(dev, port, false);
312+
313+
if (!ret)
314+
priv->phys_enabled &= ~BIT(port);
315+
}
316+
269317
static const struct b53_io_ops b53_mmap_ops = {
270318
.read8 = b53_mmap_read8,
271319
.read16 = b53_mmap_read16,
@@ -279,6 +327,8 @@ static const struct b53_io_ops b53_mmap_ops = {
279327
.write64 = b53_mmap_write64,
280328
.phy_read16 = b53_mmap_phy_read16,
281329
.phy_write16 = b53_mmap_phy_write16,
330+
.phy_enable = b53_mmap_phy_enable,
331+
.phy_disable = b53_mmap_phy_disable,
282332
};
283333

284334
static int b53_mmap_probe_of(struct platform_device *pdev,

0 commit comments

Comments
 (0)