Skip to content

Commit 7b3c4c3

Browse files
lunnbroonie
authored andcommitted
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 <[email protected]> Signed-off-by: Michael Walle <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 1b929c0 commit 7b3c4c3

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

drivers/base/regmap/regmap-mdio.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,21 @@
1010
/* Clause-45 mask includes the device type (5 bit) and actual register number (16 bit) */
1111
#define REGNUM_C45_MASK GENMASK(20, 0)
1212

13-
static int regmap_mdio_read(struct mdio_device *mdio_dev, u32 reg, unsigned int *val)
13+
static int regmap_mdio_c22_read(void *context, unsigned int reg, unsigned int *val)
1414
{
15+
struct mdio_device *mdio_dev = context;
1516
int ret;
1617

18+
if (unlikely(reg & ~REGNUM_C22_MASK))
19+
return -ENXIO;
20+
1721
ret = mdiodev_read(mdio_dev, reg);
1822
if (ret < 0)
1923
return ret;
2024

2125
*val = ret & REGVAL_MASK;
22-
return 0;
23-
}
24-
25-
static int regmap_mdio_write(struct mdio_device *mdio_dev, u32 reg, unsigned int val)
26-
{
27-
return mdiodev_write(mdio_dev, reg, val);
28-
}
29-
30-
static int regmap_mdio_c22_read(void *context, unsigned int reg, unsigned int *val)
31-
{
32-
struct mdio_device *mdio_dev = context;
33-
34-
if (unlikely(reg & ~REGNUM_C22_MASK))
35-
return -ENXIO;
3626

37-
return regmap_mdio_read(mdio_dev, reg, val);
27+
return 0;
3828
}
3929

4030
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 = {
5545
static int regmap_mdio_c45_read(void *context, unsigned int reg, unsigned int *val)
5646
{
5747
struct mdio_device *mdio_dev = context;
48+
unsigned int devad;
49+
int ret;
5850

5951
if (unlikely(reg & ~REGNUM_C45_MASK))
6052
return -ENXIO;
6153

62-
return regmap_mdio_read(mdio_dev, MII_ADDR_C45 | reg, val);
54+
devad = reg >> REGMAP_MDIO_C45_DEVAD_SHIFT;
55+
reg = reg & REGMAP_MDIO_C45_REGNUM_MASK;
56+
57+
ret = mdiodev_c45_read(mdio_dev, devad, reg);
58+
if (ret < 0)
59+
return ret;
60+
61+
*val = ret & REGVAL_MASK;
62+
63+
return 0;
6364
}
6465

6566
static int regmap_mdio_c45_write(void *context, unsigned int reg, unsigned int val)
6667
{
6768
struct mdio_device *mdio_dev = context;
69+
unsigned int devad;
6870

6971
if (unlikely(reg & ~REGNUM_C45_MASK))
7072
return -ENXIO;
7173

72-
return regmap_mdio_write(mdio_dev, MII_ADDR_C45 | reg, val);
74+
devad = reg >> REGMAP_MDIO_C45_DEVAD_SHIFT;
75+
reg = reg & REGMAP_MDIO_C45_REGNUM_MASK;
76+
77+
return mdiodev_c45_write(mdio_dev, devad, reg, val);
7378
}
7479

7580
static const struct regmap_bus regmap_mdio_c45_bus = {

include/linux/regmap.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ struct regmap_field;
3838
struct snd_ac97;
3939
struct sdw_slave;
4040

41+
/*
42+
* regmap_mdio address encoding. IEEE 802.3ae clause 45 addresses consist of a
43+
* device address and a register address.
44+
*/
45+
#define REGMAP_MDIO_C45_DEVAD_SHIFT 16
46+
#define REGMAP_MDIO_C45_DEVAD_MASK GENMASK(20, 16)
47+
#define REGMAP_MDIO_C45_REGNUM_MASK GENMASK(15, 0)
48+
4149
/* An enum of all the supported cache types */
4250
enum regcache_type {
4351
REGCACHE_NONE,

0 commit comments

Comments
 (0)