From 1ea975cf1ef57b1e44c0aec4820f60bb3b60904b Mon Sep 17 00:00:00 2001 From: Cristian Birsan Date: Mon, 8 Aug 2016 18:44:21 +0300 Subject: regmap: Add a function to check if a regmap register is cached Add a function to check if a regmap register is cached. This will be used in debugfs to dump the cached values of write only registers. Signed-off-by: Cristian Birsan Signed-off-by: Mark Brown --- drivers/base/regmap/internal.h | 1 + drivers/base/regmap/regmap.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h index a0380338946a..f4be4c19bb17 100644 --- a/drivers/base/regmap/internal.h +++ b/drivers/base/regmap/internal.h @@ -173,6 +173,7 @@ struct regcache_ops { int (*drop)(struct regmap *map, unsigned int min, unsigned int max); }; +bool regmap_cached(struct regmap *map, unsigned int reg); bool regmap_writeable(struct regmap *map, unsigned int reg); bool regmap_readable(struct regmap *map, unsigned int reg); bool regmap_volatile(struct regmap *map, unsigned int reg); diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 51fa7d66a393..1f011f9d6dcb 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -93,6 +93,29 @@ bool regmap_writeable(struct regmap *map, unsigned int reg) return true; } +bool regmap_cached(struct regmap *map, unsigned int reg) +{ + int ret; + unsigned int val; + + if (map->cache == REGCACHE_NONE) + return false; + + if (!map->cache_ops) + return false; + + if (map->max_register && reg > map->max_register) + return false; + + map->lock(map->lock_arg); + ret = regcache_read(map, reg, &val); + map->unlock(map->lock_arg); + if (ret) + return false; + + return true; +} + bool regmap_readable(struct regmap *map, unsigned int reg) { if (!map->reg_read) -- cgit v1.2.3 From 359a2f17604e2c1c8938be2bba32a8cef9cf6303 Mon Sep 17 00:00:00 2001 From: Cristian Birsan Date: Mon, 8 Aug 2016 18:44:22 +0300 Subject: regmap: debugfs: Add support for dumping write only device registers Add support for dumping write only device registers in debugfs. This is useful for audio codecs that have write only registers (like WM8731). The logic that decides if a value can be printed is moved to regmap_printable() function to allow for easier future updates. Signed-off-by: Cristian Birsan Signed-off-by: Mark Brown --- drivers/base/regmap/regmap-debugfs.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index 1ee3d40861c7..36ce3511c733 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -77,6 +77,17 @@ static void regmap_debugfs_free_dump_cache(struct regmap *map) } } +static bool regmap_printable(struct regmap *map, unsigned int reg) +{ + if (regmap_precious(map, reg)) + return false; + + if (!regmap_readable(map, reg) && !regmap_cached(map, reg)) + return false; + + return true; +} + /* * Work out where the start offset maps into register numbers, bearing * in mind that we suppress hidden registers. @@ -105,8 +116,7 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map, if (list_empty(&map->debugfs_off_cache)) { for (; i <= map->max_register; i += map->reg_stride) { /* Skip unprinted registers, closing off cache entry */ - if (!regmap_readable(map, i) || - regmap_precious(map, i)) { + if (!regmap_printable(map, i)) { if (c) { c->max = p - 1; c->max_reg = i - map->reg_stride; @@ -204,7 +214,7 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from, start_reg = regmap_debugfs_get_dump_start(map, from, *ppos, &p); for (i = start_reg; i <= to; i += map->reg_stride) { - if (!regmap_readable(map, i)) + if (!regmap_readable(map, i) && !regmap_cached(map, i)) continue; if (regmap_precious(map, i)) -- cgit v1.2.3 From f50e38c9966076465bc8d9dd0bc582c268a0031e Mon Sep 17 00:00:00 2001 From: Tony Lindgren Date: Thu, 15 Sep 2016 13:56:10 -0700 Subject: regmap: Allow longer flag masks for read and write We currently only support masking the top bit for read and write flags. Let's make the mask unsigned long and mask the bytes based on the configured register length to make things more generic. This allows using regmap for more exotic combinations like SPI devices that need little endian addressing. Signed-off-by: Tony Lindgren Signed-off-by: Mark Brown --- drivers/base/regmap/internal.h | 4 ++-- drivers/base/regmap/regmap.c | 32 +++++++++++++++++++------------- 2 files changed, 21 insertions(+), 15 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h index a0380338946a..6636f03ac2da 100644 --- a/drivers/base/regmap/internal.h +++ b/drivers/base/regmap/internal.h @@ -105,8 +105,8 @@ struct regmap { bool defer_caching; - u8 read_flag_mask; - u8 write_flag_mask; + unsigned long read_flag_mask; + unsigned long write_flag_mask; /* number of bits to (left) shift the reg value when formatting*/ int reg_shift; diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 51fa7d66a393..a6a5236b6c8d 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -1296,12 +1296,26 @@ static int _regmap_select_page(struct regmap *map, unsigned int *reg, return 0; } +static void regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes, + unsigned long mask) +{ + u8 *buf; + int i; + + if (!mask || !map->work_buf) + return; + + buf = map->work_buf; + + for (i = 0; i < max_bytes; i++) + buf[i] |= (mask >> (8 * i)) & 0xff; +} + int _regmap_raw_write(struct regmap *map, unsigned int reg, const void *val, size_t val_len) { struct regmap_range_node *range; unsigned long flags; - u8 *u8 = map->work_buf; void *work_val = map->work_buf + map->format.reg_bytes + map->format.pad_bytes; void *buf; @@ -1370,8 +1384,8 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg, } map->format.format_reg(map->work_buf, reg, map->reg_shift); - - u8[0] |= map->write_flag_mask; + regmap_set_work_buf_flag_mask(map, map->format.reg_bytes, + map->write_flag_mask); /* * Essentially all I/O mechanisms will be faster with a single @@ -2245,7 +2259,6 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, unsigned int val_len) { struct regmap_range_node *range; - u8 *u8 = map->work_buf; int ret; WARN_ON(!map->bus); @@ -2262,15 +2275,8 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, } map->format.format_reg(map->work_buf, reg, map->reg_shift); - - /* - * Some buses or devices flag reads by setting the high bits in the - * register address; since it's always the high bits for all - * current formats we can do this here rather than in - * formatting. This may break if we get interesting formats. - */ - u8[0] |= map->read_flag_mask; - + regmap_set_work_buf_flag_mask(map, map->format.reg_bytes, + map->read_flag_mask); trace_regmap_hw_read_start(map, reg, val_len / map->format.val_bytes); ret = map->bus->read(map->bus_context, map->work_buf, -- cgit v1.2.3 From 55562449032c43b84f839e2fbb84bf1d351d6603 Mon Sep 17 00:00:00 2001 From: Tony Lindgren Date: Thu, 15 Sep 2016 13:56:11 -0700 Subject: regmap: Add missing little endian functions This with the longer read and write masks allow supporting more exotic devices. For example a little endian SPI device: static const struct regmap_config foo_regmap_config = { .reg_bits = 16, .reg_stride = 4, .val_bits = 16, .write_flag_mask = 0x8000, .reg_format_endian = REGMAP_ENDIAN_LITTLE, .val_format_endian = REGMAP_ENDIAN_LITTLE, ... }; Signed-off-by: Tony Lindgren Signed-off-by: Mark Brown --- drivers/base/regmap/regmap.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index a6a5236b6c8d..31cfe70e6d53 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -749,6 +749,9 @@ struct regmap *__regmap_init(struct device *dev, case REGMAP_ENDIAN_BIG: map->format.format_reg = regmap_format_16_be; break; + case REGMAP_ENDIAN_LITTLE: + map->format.format_reg = regmap_format_16_le; + break; case REGMAP_ENDIAN_NATIVE: map->format.format_reg = regmap_format_16_native; break; @@ -768,6 +771,9 @@ struct regmap *__regmap_init(struct device *dev, case REGMAP_ENDIAN_BIG: map->format.format_reg = regmap_format_32_be; break; + case REGMAP_ENDIAN_LITTLE: + map->format.format_reg = regmap_format_32_le; + break; case REGMAP_ENDIAN_NATIVE: map->format.format_reg = regmap_format_32_native; break; @@ -782,6 +788,9 @@ struct regmap *__regmap_init(struct device *dev, case REGMAP_ENDIAN_BIG: map->format.format_reg = regmap_format_64_be; break; + case REGMAP_ENDIAN_LITTLE: + map->format.format_reg = regmap_format_64_le; + break; case REGMAP_ENDIAN_NATIVE: map->format.format_reg = regmap_format_64_native; break; -- cgit v1.2.3