Commit ec6ba50c authored by Oleksij Rempel's avatar Oleksij Rempel Committed by David S. Miller

net: dsa: microchip: add support for regmap_access_tables

This is complex driver with support for different chips with different
layouts. To detect at least some bugs earlier, we should validate register
accesses by using regmap_access_table support.
Signed-off-by: default avatarOleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: default avatarVladimir Oltean <olteanv@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b5708dc6
...@@ -62,6 +62,8 @@ struct ksz_chip_data { ...@@ -62,6 +62,8 @@ struct ksz_chip_data {
bool supports_rgmii[KSZ_MAX_NUM_PORTS]; bool supports_rgmii[KSZ_MAX_NUM_PORTS];
bool internal_phy[KSZ_MAX_NUM_PORTS]; bool internal_phy[KSZ_MAX_NUM_PORTS];
bool gbit_capable[KSZ_MAX_NUM_PORTS]; bool gbit_capable[KSZ_MAX_NUM_PORTS];
const struct regmap_access_table *wr_table;
const struct regmap_access_table *rd_table;
}; };
struct ksz_port { struct ksz_port {
...@@ -333,6 +335,10 @@ static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val) ...@@ -333,6 +335,10 @@ static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val)
unsigned int value; unsigned int value;
int ret = regmap_read(dev->regmap[0], reg, &value); int ret = regmap_read(dev->regmap[0], reg, &value);
if (ret)
dev_err(dev->dev, "can't read 8bit reg: 0x%x %pe\n", reg,
ERR_PTR(ret));
*val = value; *val = value;
return ret; return ret;
} }
...@@ -342,6 +348,10 @@ static inline int ksz_read16(struct ksz_device *dev, u32 reg, u16 *val) ...@@ -342,6 +348,10 @@ static inline int ksz_read16(struct ksz_device *dev, u32 reg, u16 *val)
unsigned int value; unsigned int value;
int ret = regmap_read(dev->regmap[1], reg, &value); int ret = regmap_read(dev->regmap[1], reg, &value);
if (ret)
dev_err(dev->dev, "can't read 16bit reg: 0x%x %pe\n", reg,
ERR_PTR(ret));
*val = value; *val = value;
return ret; return ret;
} }
...@@ -351,6 +361,10 @@ static inline int ksz_read32(struct ksz_device *dev, u32 reg, u32 *val) ...@@ -351,6 +361,10 @@ static inline int ksz_read32(struct ksz_device *dev, u32 reg, u32 *val)
unsigned int value; unsigned int value;
int ret = regmap_read(dev->regmap[2], reg, &value); int ret = regmap_read(dev->regmap[2], reg, &value);
if (ret)
dev_err(dev->dev, "can't read 32bit reg: 0x%x %pe\n", reg,
ERR_PTR(ret));
*val = value; *val = value;
return ret; return ret;
} }
...@@ -361,7 +375,10 @@ static inline int ksz_read64(struct ksz_device *dev, u32 reg, u64 *val) ...@@ -361,7 +375,10 @@ static inline int ksz_read64(struct ksz_device *dev, u32 reg, u64 *val)
int ret; int ret;
ret = regmap_bulk_read(dev->regmap[2], reg, value, 2); ret = regmap_bulk_read(dev->regmap[2], reg, value, 2);
if (!ret) if (ret)
dev_err(dev->dev, "can't read 64bit reg: 0x%x %pe\n", reg,
ERR_PTR(ret));
else
*val = (u64)value[0] << 32 | value[1]; *val = (u64)value[0] << 32 | value[1];
return ret; return ret;
...@@ -369,17 +386,38 @@ static inline int ksz_read64(struct ksz_device *dev, u32 reg, u64 *val) ...@@ -369,17 +386,38 @@ static inline int ksz_read64(struct ksz_device *dev, u32 reg, u64 *val)
static inline int ksz_write8(struct ksz_device *dev, u32 reg, u8 value) static inline int ksz_write8(struct ksz_device *dev, u32 reg, u8 value)
{ {
return regmap_write(dev->regmap[0], reg, value); int ret;
ret = regmap_write(dev->regmap[0], reg, value);
if (ret)
dev_err(dev->dev, "can't write 8bit reg: 0x%x %pe\n", reg,
ERR_PTR(ret));
return ret;
} }
static inline int ksz_write16(struct ksz_device *dev, u32 reg, u16 value) static inline int ksz_write16(struct ksz_device *dev, u32 reg, u16 value)
{ {
return regmap_write(dev->regmap[1], reg, value); int ret;
ret = regmap_write(dev->regmap[1], reg, value);
if (ret)
dev_err(dev->dev, "can't write 16bit reg: 0x%x %pe\n", reg,
ERR_PTR(ret));
return ret;
} }
static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value) static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value)
{ {
return regmap_write(dev->regmap[2], reg, value); int ret;
ret = regmap_write(dev->regmap[2], reg, value);
if (ret)
dev_err(dev->dev, "can't write 32bit reg: 0x%x %pe\n", reg,
ERR_PTR(ret));
return ret;
} }
static inline int ksz_write64(struct ksz_device *dev, u32 reg, u64 value) static inline int ksz_write64(struct ksz_device *dev, u32 reg, u64 value)
......
...@@ -66,7 +66,10 @@ static int ksz_spi_probe(struct spi_device *spi) ...@@ -66,7 +66,10 @@ static int ksz_spi_probe(struct spi_device *spi)
for (i = 0; i < ARRAY_SIZE(ksz8795_regmap_config); i++) { for (i = 0; i < ARRAY_SIZE(ksz8795_regmap_config); i++) {
rc = regmap_config[i]; rc = regmap_config[i];
rc.lock_arg = &dev->regmap_mutex; rc.lock_arg = &dev->regmap_mutex;
rc.wr_table = chip->wr_table;
rc.rd_table = chip->rd_table;
dev->regmap[i] = devm_regmap_init_spi(spi, &rc); dev->regmap[i] = devm_regmap_init_spi(spi, &rc);
if (IS_ERR(dev->regmap[i])) { if (IS_ERR(dev->regmap[i])) {
ret = PTR_ERR(dev->regmap[i]); ret = PTR_ERR(dev->regmap[i]);
dev_err(&spi->dev, dev_err(&spi->dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment