diff options
author | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2019-12-14 23:10:08 +0100 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2019-12-18 10:37:49 +0100 |
commit | c509e4344bc0e2505a635ee8ac948298c7f21127 (patch) | |
tree | 4355c8b0ddcd2a1c56fd5e3df988ce601df70119 /drivers | |
parent | 9b45ef977440f30a0d990fc6bf60081c78c453bd (diff) | |
download | linux-stable-c509e4344bc0e2505a635ee8ac948298c7f21127.tar.gz linux-stable-c509e4344bc0e2505a635ee8ac948298c7f21127.tar.bz2 linux-stable-c509e4344bc0e2505a635ee8ac948298c7f21127.zip |
rtc: rv3029: let regmap validate the register ranges
Instead of trying to validate the accessed registers in custom functions,
let regmap handle that. This allows to defines all the holes in the
register range and gives access to the regmap debugfs register dump.
Link: https://lore.kernel.org/r/20191214221022.622482-3-alexandre.belloni@bootlin.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/rtc/rtc-rv3029c2.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c index b8294d9d94c5..09433d4a86e3 100644 --- a/drivers/rtc/rtc-rv3029c2.c +++ b/drivers/rtc/rtc-rv3029c2.c @@ -126,10 +126,6 @@ static int rv3029_read_regs(struct device *dev, u8 reg, u8 *buf, { struct rv3029_data *rv3029 = dev_get_drvdata(dev); - if ((reg > RV3029_USR1_RAM_PAGE + 7) || - (reg + len > RV3029_USR1_RAM_PAGE + 8)) - return -EINVAL; - return regmap_bulk_read(rv3029->regmap, reg, buf, len); } @@ -138,10 +134,6 @@ static int rv3029_write_regs(struct device *dev, u8 reg, u8 const buf[], { struct rv3029_data *rv3029 = dev_get_drvdata(dev); - if ((reg > RV3029_USR1_RAM_PAGE + 7) || - (reg + len > RV3029_USR1_RAM_PAGE + 8)) - return -EINVAL; - return regmap_bulk_write(rv3029->regmap, reg, buf, len); } @@ -837,17 +829,34 @@ static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq, return 0; } +static const struct regmap_range rv3029_holes_range[] = { + regmap_reg_range(0x05, 0x07), + regmap_reg_range(0x0f, 0x0f), + regmap_reg_range(0x17, 0x17), + regmap_reg_range(0x1a, 0x1f), + regmap_reg_range(0x21, 0x27), + regmap_reg_range(0x34, 0x37), +}; + +static const struct regmap_access_table rv3029_regs = { + .no_ranges = rv3029_holes_range, + .n_no_ranges = ARRAY_SIZE(rv3029_holes_range), +}; + +static const struct regmap_config config = { + .reg_bits = 8, + .val_bits = 8, + .rd_table = &rv3029_regs, + .wr_table = &rv3029_regs, + .max_register = 0x3f, +}; + #if IS_ENABLED(CONFIG_I2C) static int rv3029_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct regmap *regmap; - static const struct regmap_config config = { - .reg_bits = 8, - .val_bits = 8, - }; - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_BYTE)) { dev_err(&client->dev, "Adapter does not support SMBUS_I2C_BLOCK or SMBUS_I2C_BYTE\n"); @@ -917,10 +926,6 @@ static void rv3029_unregister_driver(void) static int rv3049_probe(struct spi_device *spi) { - static const struct regmap_config config = { - .reg_bits = 8, - .val_bits = 8, - }; struct regmap *regmap; regmap = devm_regmap_init_spi(spi, &config); |