Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 280559
b: refs/heads/master
c: 8569d02
h: refs/heads/master
i:
  280557: 3064006
  280555: d5bbf40
  280551: fc10a5b
  280543: 5dd07a2
v: v3
  • Loading branch information
Mark Brown committed Dec 5, 2011
1 parent 0cc0170 commit 5e1265c
Show file tree
Hide file tree
Showing 12 changed files with 565 additions and 154 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: bf315173359b2f3b8b8ccca4264815e91f30be12
refs/heads/master: 8569d023a0db699c462337d471f7e92163142e37
3 changes: 3 additions & 0 deletions trunk/drivers/base/regmap/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ config REGMAP_I2C

config REGMAP_SPI
tristate

config REGMAP_IRQ
bool
4 changes: 3 additions & 1 deletion trunk/drivers/base/regmap/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
obj-$(CONFIG_REGMAP) += regmap.o regcache.o regcache-indexed.o regcache-rbtree.o regcache-lzo.o
obj-$(CONFIG_REGMAP) += regmap.o regcache.o
obj-$(CONFIG_REGMAP) += regcache-rbtree.o regcache-lzo.o
obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o
obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o
obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o
obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o
5 changes: 1 addition & 4 deletions trunk/drivers/base/regmap/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static inline void regmap_debugfs_exit(struct regmap *map) { }
#endif

/* regcache core declarations */
int regcache_init(struct regmap *map);
int regcache_init(struct regmap *map, const struct regmap_config *config);
void regcache_exit(struct regmap *map);
int regcache_read(struct regmap *map,
unsigned int reg, unsigned int *value);
Expand All @@ -119,10 +119,7 @@ unsigned int regcache_get_val(const void *base, unsigned int idx,
bool regcache_set_val(void *base, unsigned int idx,
unsigned int val, unsigned int word_size);
int regcache_lookup_reg(struct regmap *map, unsigned int reg);
int regcache_insert_reg(struct regmap *map, unsigned int reg,
unsigned int val);

extern struct regcache_ops regcache_indexed_ops;
extern struct regcache_ops regcache_rbtree_ops;
extern struct regcache_ops regcache_lzo_ops;

Expand Down
64 changes: 0 additions & 64 deletions trunk/drivers/base/regmap/regcache-indexed.c

This file was deleted.

19 changes: 12 additions & 7 deletions trunk/drivers/base/regmap/regcache-lzo.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include "internal.h"

static int regcache_lzo_exit(struct regmap *map);

struct regcache_lzo_ctx {
void *wmem;
void *dst;
Expand All @@ -27,7 +29,7 @@ struct regcache_lzo_ctx {
};

#define LZO_BLOCK_NUM 8
static int regcache_lzo_block_count(void)
static int regcache_lzo_block_count(struct regmap *map)
{
return LZO_BLOCK_NUM;
}
Expand Down Expand Up @@ -106,19 +108,22 @@ static inline int regcache_lzo_get_blkindex(struct regmap *map,
unsigned int reg)
{
return (reg * map->cache_word_size) /
DIV_ROUND_UP(map->cache_size_raw, regcache_lzo_block_count());
DIV_ROUND_UP(map->cache_size_raw,
regcache_lzo_block_count(map));
}

static inline int regcache_lzo_get_blkpos(struct regmap *map,
unsigned int reg)
{
return reg % (DIV_ROUND_UP(map->cache_size_raw, regcache_lzo_block_count()) /
return reg % (DIV_ROUND_UP(map->cache_size_raw,
regcache_lzo_block_count(map)) /
map->cache_word_size);
}

static inline int regcache_lzo_get_blksize(struct regmap *map)
{
return DIV_ROUND_UP(map->cache_size_raw, regcache_lzo_block_count());
return DIV_ROUND_UP(map->cache_size_raw,
regcache_lzo_block_count(map));
}

static int regcache_lzo_init(struct regmap *map)
Expand All @@ -131,7 +136,7 @@ static int regcache_lzo_init(struct regmap *map)

ret = 0;

blkcount = regcache_lzo_block_count();
blkcount = regcache_lzo_block_count(map);
map->cache = kzalloc(blkcount * sizeof *lzo_blocks,
GFP_KERNEL);
if (!map->cache)
Expand Down Expand Up @@ -190,7 +195,7 @@ static int regcache_lzo_init(struct regmap *map)

return 0;
err:
regcache_exit(map);
regcache_lzo_exit(map);
return ret;
}

Expand All @@ -203,7 +208,7 @@ static int regcache_lzo_exit(struct regmap *map)
if (!lzo_blocks)
return 0;

blkcount = regcache_lzo_block_count();
blkcount = regcache_lzo_block_count(map);
/*
* the pointer to the bitmap used for syncing the cache
* is shared amongst all lzo_blocks. Ensure it is freed
Expand Down
61 changes: 60 additions & 1 deletion trunk/drivers/base/regmap/regcache-rbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
*/

#include <linux/slab.h>
#include <linux/debugfs.h>
#include <linux/rbtree.h>
#include <linux/seq_file.h>

#include "internal.h"

static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
unsigned int value);
static int regcache_rbtree_exit(struct regmap *map);

struct regcache_rbtree_node {
/* the actual rbtree node holding this block */
Expand Down Expand Up @@ -124,6 +127,60 @@ static int regcache_rbtree_insert(struct rb_root *root,
return 1;
}

#ifdef CONFIG_DEBUG_FS
static int rbtree_show(struct seq_file *s, void *ignored)
{
struct regmap *map = s->private;
struct regcache_rbtree_ctx *rbtree_ctx = map->cache;
struct regcache_rbtree_node *n;
struct rb_node *node;
unsigned int base, top;
int nodes = 0;
int registers = 0;

mutex_lock(&map->lock);

for (node = rb_first(&rbtree_ctx->root); node != NULL;
node = rb_next(node)) {
n = container_of(node, struct regcache_rbtree_node, node);

regcache_rbtree_get_base_top_reg(n, &base, &top);
seq_printf(s, "%x-%x (%d)\n", base, top, top - base + 1);

nodes++;
registers += top - base + 1;
}

seq_printf(s, "%d nodes, %d registers, average %d registers\n",
nodes, registers, registers / nodes);

mutex_unlock(&map->lock);

return 0;
}

static int rbtree_open(struct inode *inode, struct file *file)
{
return single_open(file, rbtree_show, inode->i_private);
}

static const struct file_operations rbtree_fops = {
.open = rbtree_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

static void rbtree_debugfs_init(struct regmap *map)
{
debugfs_create_file("rbtree", 0400, map->debugfs, map, &rbtree_fops);
}
#else
static void rbtree_debugfs_init(struct regmap *map)
{
}
#endif

static int regcache_rbtree_init(struct regmap *map)
{
struct regcache_rbtree_ctx *rbtree_ctx;
Expand All @@ -146,10 +203,12 @@ static int regcache_rbtree_init(struct regmap *map)
goto err;
}

rbtree_debugfs_init(map);

return 0;

err:
regcache_exit(map);
regcache_rbtree_exit(map);
return ret;
}

Expand Down
68 changes: 38 additions & 30 deletions trunk/drivers/base/regmap/regcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "internal.h"

static const struct regcache_ops *cache_types[] = {
&regcache_indexed_ops,
&regcache_rbtree_ops,
&regcache_lzo_ops,
};
Expand Down Expand Up @@ -61,8 +60,10 @@ static int regcache_hw_init(struct regmap *map)

map->reg_defaults = kmalloc(count * sizeof(struct reg_default),
GFP_KERNEL);
if (!map->reg_defaults)
return -ENOMEM;
if (!map->reg_defaults) {
ret = -ENOMEM;
goto err_free;
}

/* fill the reg_defaults */
map->num_reg_defaults = count;
Expand All @@ -77,9 +78,15 @@ static int regcache_hw_init(struct regmap *map)
}

return 0;

err_free:
if (map->cache_free)
kfree(map->reg_defaults_raw);

return ret;
}

int regcache_init(struct regmap *map)
int regcache_init(struct regmap *map, const struct regmap_config *config)
{
int ret;
int i;
Expand All @@ -100,6 +107,12 @@ int regcache_init(struct regmap *map)
return -EINVAL;
}

map->num_reg_defaults = config->num_reg_defaults;
map->num_reg_defaults_raw = config->num_reg_defaults_raw;
map->reg_defaults_raw = config->reg_defaults_raw;
map->cache_word_size = DIV_ROUND_UP(config->val_bits, 8);
map->cache_size_raw = map->cache_word_size * config->num_reg_defaults_raw;

map->cache = NULL;
map->cache_ops = cache_types[i];

Expand All @@ -112,10 +125,10 @@ int regcache_init(struct regmap *map)
* won't vanish from under us. We'll need to make
* a copy of it.
*/
if (map->reg_defaults) {
if (config->reg_defaults) {
if (!map->num_reg_defaults)
return -EINVAL;
tmp_buf = kmemdup(map->reg_defaults, map->num_reg_defaults *
tmp_buf = kmemdup(config->reg_defaults, map->num_reg_defaults *
sizeof(struct reg_default), GFP_KERNEL);
if (!tmp_buf)
return -ENOMEM;
Expand All @@ -136,9 +149,18 @@ int regcache_init(struct regmap *map)
if (map->cache_ops->init) {
dev_dbg(map->dev, "Initializing %s cache\n",
map->cache_ops->name);
return map->cache_ops->init(map);
ret = map->cache_ops->init(map);
if (ret)
goto err_free;
}
return 0;

err_free:
kfree(map->reg_defaults);
if (map->cache_free)
kfree(map->reg_defaults_raw);

return ret;
}

void regcache_exit(struct regmap *map)
Expand Down Expand Up @@ -171,16 +193,21 @@ void regcache_exit(struct regmap *map)
int regcache_read(struct regmap *map,
unsigned int reg, unsigned int *value)
{
int ret;

if (map->cache_type == REGCACHE_NONE)
return -ENOSYS;

BUG_ON(!map->cache_ops);

if (!regmap_readable(map, reg))
return -EIO;
if (!regmap_volatile(map, reg)) {
ret = map->cache_ops->read(map, reg, value);

if (!regmap_volatile(map, reg))
return map->cache_ops->read(map, reg, value);
if (ret == 0)
trace_regmap_reg_read_cache(map->dev, reg, *value);

return ret;
}

return -EINVAL;
}
Expand Down Expand Up @@ -400,22 +427,3 @@ int regcache_lookup_reg(struct regmap *map, unsigned int reg)
else
return -ENOENT;
}

int regcache_insert_reg(struct regmap *map, unsigned int reg,
unsigned int val)
{
void *tmp;

tmp = krealloc(map->reg_defaults,
(map->num_reg_defaults + 1) * sizeof(struct reg_default),
GFP_KERNEL);
if (!tmp)
return -ENOMEM;
map->reg_defaults = tmp;
map->num_reg_defaults++;
map->reg_defaults[map->num_reg_defaults - 1].reg = reg;
map->reg_defaults[map->num_reg_defaults - 1].def = val;
sort(map->reg_defaults, map->num_reg_defaults,
sizeof(struct reg_default), regcache_default_cmp, NULL);
return 0;
}
Loading

0 comments on commit 5e1265c

Please sign in to comment.