Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 305611
b: refs/heads/master
c: 55c1371
h: refs/heads/master
i:
  305609: e14bda3
  305607: 243475c
v: v3
  • Loading branch information
Marc Reilly authored and Mark Brown committed Apr 13, 2012
1 parent d55b0f0 commit 1b2c748
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 89a89b5e4fb23aa133e4aa9e0be97b43996d4ad2
refs/heads/master: 55c1371c79713fb3795a04d369e46680be5ae2bf
7 changes: 5 additions & 2 deletions trunk/drivers/base/regmap/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand All @@ -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;
Expand Down
27 changes: 15 additions & 12 deletions trunk/drivers/base/regmap/regmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand Down Expand Up @@ -454,7 +457,7 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
}
}

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;

Expand Down Expand Up @@ -529,7 +532,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 +
Expand Down Expand Up @@ -649,7 +652,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
Expand Down Expand Up @@ -757,7 +760,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);
}
}

Expand Down

0 comments on commit 1b2c748

Please sign in to comment.