Skip to content

Commit

Permalink
Merge tag 'regmap-mdio-c45-rework' of https://git.kernel.org/pub/scm/…
Browse files Browse the repository at this point in the history
…linux/kernel/git/broonie/regmap

Mark Brown says:

====================
regmap: Rework regmap_mdio_c45_{read|write} for new C45 API.

This reworks the regmap MDIO handling of C45 addresses in
preparation for some forthcoming updates to the networking code.

* tag 'regmap-mdio-c45-rework' of https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap:
  regmap: Rework regmap_mdio_c45_{read|write} for new C45 API.
====================

Link: https://lore.kernel.org/r/Y8VjkgcWHjR9TzNw@sirena.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Jan 18, 2023
2 parents 0c68c8e + 7b3c4c3 commit 87a26f2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
41 changes: 23 additions & 18 deletions drivers/base/regmap/regmap-mdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = {
Expand Down
8 changes: 8 additions & 0 deletions include/linux/regmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ struct regmap_field;
struct snd_ac97;
struct sdw_slave;

/*
* regmap_mdio address encoding. IEEE 802.3ae clause 45 addresses consist of a
* device address and a register address.
*/
#define REGMAP_MDIO_C45_DEVAD_SHIFT 16
#define REGMAP_MDIO_C45_DEVAD_MASK GENMASK(20, 16)
#define REGMAP_MDIO_C45_REGNUM_MASK GENMASK(15, 0)

/* An enum of all the supported cache types */
enum regcache_type {
REGCACHE_NONE,
Expand Down

0 comments on commit 87a26f2

Please sign in to comment.