regmap: implement register striding
regmap_config.reg_stride is introduced. All extant register addresses
are a multiple of this value. Users of serial-oriented regmap busses will
typically set this to 1. Users of the MMIO regmap bus will typically set
this based on the value size of their registers, in bytes, so 4 for a
32-bit register.
Throughout the regmap code, actual register addresses are used. Wherever
the register address is used to index some array of values, the address
is divided by the stride to determine the index, or vice-versa. Error-
checking is added to all entry-points for register address data to ensure
that register addresses actually satisfy the specified stride. The MMIO
bus ensures that the specified stride is large enough for the register
size.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c
index bdf4dc8..febd6de 100644
--- a/drivers/base/regmap/regmap-mmio.c
+++ b/drivers/base/regmap/regmap-mmio.c
@@ -130,6 +130,7 @@
const struct regmap_config *config)
{
struct regmap_mmio_context *ctx;
+ int min_stride;
if (config->reg_bits != 32)
return ERR_PTR(-EINVAL);
@@ -139,16 +140,28 @@
switch (config->val_bits) {
case 8:
+ /* The core treats 0 as 1 */
+ min_stride = 0;
+ break;
case 16:
+ min_stride = 2;
+ break;
case 32:
+ min_stride = 4;
+ break;
#ifdef CONFIG_64BIT
case 64:
+ min_stride = 8;
+ break;
#endif
break;
default:
return ERR_PTR(-EINVAL);
}
+ if (config->reg_stride < min_stride)
+ return ERR_PTR(-EINVAL);
+
ctx = kzalloc(GFP_KERNEL, sizeof(*ctx));
if (!ctx)
return ERR_PTR(-ENOMEM);