diff options
author | Andrew Lunn <andrew@lunn.ch> | 2023-01-16 12:15:09 +0100 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2023-01-16 13:16:09 +0000 |
commit | 7b3c4c370c09313e22b555e79167e73d233611d1 (patch) | |
tree | 15b28c5ece5bc789521bf5d5f768f94c80ecadbd /drivers/base | |
parent | 1b929c02afd37871d5afb9d498426f83432e71c2 (diff) |
regmap: Rework regmap_mdio_c45_{read|write} for new C45 API.
The MDIO subsystem is getting rid of MII_ADDR_C45 and thus also
encoding associated encoding of the C45 device address and register
address into one value. regmap-mdio also uses this encoding for the
C45 bus.
Move to the new C45 helpers for MDIO access and provide regmap-mdio
helper macros.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Michael Walle <michael@walle.cc>
Link: https://lore.kernel.org/r/20230116111509.4086236-1-michael@walle.cc
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/regmap/regmap-mdio.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/drivers/base/regmap/regmap-mdio.c b/drivers/base/regmap/regmap-mdio.c index f7293040a2b1..6aa6a2409478 100644 --- a/drivers/base/regmap/regmap-mdio.c +++ b/drivers/base/regmap/regmap-mdio.c @@ -10,31 +10,21 @@ /* Clause-45 mask includes the device type (5 bit) and actual register number (16 bit) */ #define REGNUM_C45_MASK GENMASK(20, 0) -static int regmap_mdio_read(struct mdio_device *mdio_dev, u32 reg, unsigned int *val) +static int regmap_mdio_c22_read(void *context, unsigned int reg, unsigned int *val) { + struct mdio_device *mdio_dev = context; int ret; + if (unlikely(reg & ~REGNUM_C22_MASK)) + return -ENXIO; + ret = mdiodev_read(mdio_dev, reg); if (ret < 0) return ret; *val = ret & REGVAL_MASK; - return 0; -} - -static int regmap_mdio_write(struct mdio_device *mdio_dev, u32 reg, unsigned int val) -{ - return mdiodev_write(mdio_dev, reg, val); -} - -static int regmap_mdio_c22_read(void *context, unsigned int reg, unsigned int *val) -{ - struct mdio_device *mdio_dev = context; - - if (unlikely(reg & ~REGNUM_C22_MASK)) - return -ENXIO; - return regmap_mdio_read(mdio_dev, reg, val); + return 0; } static int regmap_mdio_c22_write(void *context, unsigned int reg, unsigned int val) @@ -55,21 +45,36 @@ static const struct regmap_bus regmap_mdio_c22_bus = { static int regmap_mdio_c45_read(void *context, unsigned int reg, unsigned int *val) { struct mdio_device *mdio_dev = context; + unsigned int devad; + int ret; if (unlikely(reg & ~REGNUM_C45_MASK)) return -ENXIO; - return regmap_mdio_read(mdio_dev, MII_ADDR_C45 | reg, val); + devad = reg >> REGMAP_MDIO_C45_DEVAD_SHIFT; + reg = reg & REGMAP_MDIO_C45_REGNUM_MASK; + + ret = mdiodev_c45_read(mdio_dev, devad, reg); + if (ret < 0) + return ret; + + *val = ret & REGVAL_MASK; + + return 0; } static int regmap_mdio_c45_write(void *context, unsigned int reg, unsigned int val) { struct mdio_device *mdio_dev = context; + unsigned int devad; if (unlikely(reg & ~REGNUM_C45_MASK)) return -ENXIO; - return regmap_mdio_write(mdio_dev, MII_ADDR_C45 | reg, val); + devad = reg >> REGMAP_MDIO_C45_DEVAD_SHIFT; + reg = reg & REGMAP_MDIO_C45_REGNUM_MASK; + + return mdiodev_c45_write(mdio_dev, devad, reg, val); } static const struct regmap_bus regmap_mdio_c45_bus = { |