* [PATCH 1/2] regmap: Add support for device with 24 data bits.
@ 2012-03-16 1:11 Marc Reilly
2012-03-16 1:11 ` [PATCH 2/2] regmap: Use pad_bits and reg_bits when determining register format Marc Reilly
2012-03-17 22:06 ` [PATCH 1/2] regmap: Add support for device with 24 data bits Mark Brown
0 siblings, 2 replies; 3+ messages in thread
From: Marc Reilly @ 2012-03-16 1:11 UTC (permalink / raw)
To: broonie; +Cc: linux-kernel, Marc Reilly
Add support for devices with 24 data bits.
Signed-off-by: Marc Reilly <marc@cpdesign.com.au>
---
drivers/base/regmap/regmap.c | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 253882d..9cfe203 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -126,6 +126,15 @@ static void regmap_format_16(void *buf, unsigned int val)
b[0] = cpu_to_be16(val);
}
+static void regmap_format_24(void *buf, unsigned int val)
+{
+ u8 *b = buf;
+
+ b[0] = val >> 16;
+ b[1] = val >> 8;
+ b[2] = val;
+}
+
static void regmap_format_32(void *buf, unsigned int val)
{
__be32 *b = buf;
@@ -149,6 +158,16 @@ static unsigned int regmap_parse_16(void *buf)
return b[0];
}
+static unsigned int regmap_parse_24(void *buf)
+{
+ u8 *b = buf;
+ unsigned int ret = b[2];
+ ret |= ((unsigned int)b[1]) << 8;
+ ret |= ((unsigned int)b[0]) << 16;
+
+ return ret;
+}
+
static unsigned int regmap_parse_32(void *buf)
{
__be32 *b = buf;
@@ -273,6 +292,10 @@ struct regmap *regmap_init(struct device *dev,
map->format.format_val = regmap_format_16;
map->format.parse_val = regmap_parse_16;
break;
+ case 24:
+ map->format.format_val = regmap_format_24;
+ map->format.parse_val = regmap_parse_24;
+ break;
case 32:
map->format.format_val = regmap_format_32;
map->format.parse_val = regmap_parse_32;
--
1.7.3.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] regmap: Use pad_bits and reg_bits when determining register format.
2012-03-16 1:11 [PATCH 1/2] regmap: Add support for device with 24 data bits Marc Reilly
@ 2012-03-16 1:11 ` Marc Reilly
2012-03-17 22:06 ` [PATCH 1/2] regmap: Add support for device with 24 data bits Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Marc Reilly @ 2012-03-16 1:11 UTC (permalink / raw)
To: broonie; +Cc: linux-kernel, Marc Reilly
This change combines any padding bits into the register address bits when
determining register format handlers to use the next byte-divisible
register size.
A reg_shift member is introduced to the regmap struct to enable fixup
of the reg format.
Format handlers now take an extra parameter specifying the number of
bits to shift the value by.
Signed-off-by: Marc Reilly <marc@cpdesign.com.au>
---
drivers/base/regmap/internal.h | 7 +++++--
drivers/base/regmap/regmap.c | 27 +++++++++++++++------------
2 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index e93d7b7..7b1411d 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -26,8 +26,8 @@ struct regmap_format {
size_t val_bytes;
void (*format_write)(struct regmap *map,
unsigned int reg, unsigned int val);
- void (*format_reg)(void *buf, unsigned int reg);
- void (*format_val)(void *buf, unsigned int val);
+ void (*format_reg)(void *buf, unsigned int reg, unsigned int shift);
+ void (*format_val)(void *buf, unsigned int val, unsigned int shift);
unsigned int (*parse_val)(void *buf);
};
@@ -52,6 +52,9 @@ struct regmap {
u8 read_flag_mask;
u8 write_flag_mask;
+ /* number of bits to (left) shift the reg value when formatting*/
+ int reg_shift;
+
/* regcache specific members */
const struct regcache_ops *cache_ops;
enum regcache_type cache_type;
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 9cfe203..ca08592 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -112,34 +112,36 @@ static void regmap_format_10_14_write(struct regmap *map,
out[0] = reg >> 2;
}
-static void regmap_format_8(void *buf, unsigned int val)
+static void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
{
u8 *b = buf;
- b[0] = val;
+ b[0] = val << shift;
}
-static void regmap_format_16(void *buf, unsigned int val)
+static void regmap_format_16(void *buf, unsigned int val, unsigned int shift)
{
__be16 *b = buf;
- b[0] = cpu_to_be16(val);
+ b[0] = cpu_to_be16(val << shift);
}
-static void regmap_format_24(void *buf, unsigned int val)
+static void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
{
u8 *b = buf;
+ val <<= shift;
+
b[0] = val >> 16;
b[1] = val >> 8;
b[2] = val;
}
-static void regmap_format_32(void *buf, unsigned int val)
+static void regmap_format_32(void *buf, unsigned int val, unsigned int shift)
{
__be32 *b = buf;
- b[0] = cpu_to_be32(val);
+ b[0] = cpu_to_be32(val << shift);
}
static unsigned int regmap_parse_8(void *buf)
@@ -210,6 +212,7 @@ struct regmap *regmap_init(struct device *dev,
map->format.pad_bytes = config->pad_bits / 8;
map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
map->format.buf_size += map->format.pad_bytes;
+ map->reg_shift = config->pad_bits % 8;
map->dev = dev;
map->bus = bus;
map->max_register = config->max_register;
@@ -226,7 +229,7 @@ struct regmap *regmap_init(struct device *dev,
map->read_flag_mask = bus->read_flag_mask;
}
- switch (config->reg_bits) {
+ switch (config->reg_bits + map->reg_shift) {
case 2:
switch (config->val_bits) {
case 6:
@@ -392,7 +395,7 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
if (!map->writeable_reg(map->dev, reg + i))
return -EINVAL;
- map->format.format_reg(map->work_buf, reg);
+ map->format.format_reg(map->work_buf, reg, map->reg_shift);
u8[0] |= map->write_flag_mask;
@@ -467,7 +470,7 @@ int _regmap_write(struct regmap *map, unsigned int reg,
return ret;
} else {
map->format.format_val(map->work_buf + map->format.reg_bytes
- + map->format.pad_bytes, val);
+ + map->format.pad_bytes, val, 0);
return _regmap_raw_write(map, reg,
map->work_buf +
map->format.reg_bytes +
@@ -541,7 +544,7 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
u8 *u8 = map->work_buf;
int ret;
- map->format.format_reg(map->work_buf, reg);
+ map->format.format_reg(map->work_buf, reg, map->reg_shift);
/*
* Some buses or devices flag reads by setting the high bits in the
@@ -649,7 +652,7 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
if (ret != 0)
goto out;
- map->format.format_val(val + (i * val_bytes), v);
+ map->format.format_val(val + (i * val_bytes), v, 0);
}
}
--
1.7.3.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] regmap: Add support for device with 24 data bits.
2012-03-16 1:11 [PATCH 1/2] regmap: Add support for device with 24 data bits Marc Reilly
2012-03-16 1:11 ` [PATCH 2/2] regmap: Use pad_bits and reg_bits when determining register format Marc Reilly
@ 2012-03-17 22:06 ` Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2012-03-17 22:06 UTC (permalink / raw)
To: Marc Reilly; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 374 bytes --]
On Fri, Mar 16, 2012 at 12:11:42PM +1100, Marc Reilly wrote:
> Add support for devices with 24 data bits.
Applied both, thanks. I'm not sure if I'll send them for 3.4 or not,
obviously we're very close to the merge window opening (I'm actually
surprised it isn't open already), but since there's no external
interface changes it shouldn't create merge issues for the MFD.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-03-17 22:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-16 1:11 [PATCH 1/2] regmap: Add support for device with 24 data bits Marc Reilly
2012-03-16 1:11 ` [PATCH 2/2] regmap: Use pad_bits and reg_bits when determining register format Marc Reilly
2012-03-17 22:06 ` [PATCH 1/2] regmap: Add support for device with 24 data bits Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox