Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 280554
b: refs/heads/master
c: d23511f
h: refs/heads/master
v: v3
  • Loading branch information
Mark Brown committed Nov 28, 2011
1 parent 9b79bb9 commit 614e011
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 188 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: cce585ce1ebd5307c9709e24758d5eb8a1e087a7
refs/heads/master: d23511f9590870effa5ace575b59aac18c47175f
3 changes: 1 addition & 2 deletions trunk/drivers/base/regmap/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
obj-$(CONFIG_REGMAP) += regmap.o regcache.o
obj-$(CONFIG_REGMAP) += regcache-rbtree.o regcache-lzo.o
obj-$(CONFIG_REGMAP) += regmap.o regcache.o regcache-indexed.o 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
Expand Down
6 changes: 4 additions & 2 deletions trunk/drivers/base/regmap/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ struct regmap {
struct reg_default *reg_defaults;
const void *reg_defaults_raw;
void *cache;
bool cache_dirty;
};

struct regcache_ops {
Expand Down Expand Up @@ -106,7 +105,7 @@ static inline void regmap_debugfs_exit(struct regmap *map) { }
#endif

/* regcache core declarations */
int regcache_init(struct regmap *map, const struct regmap_config *config);
int regcache_init(struct regmap *map);
void regcache_exit(struct regmap *map);
int regcache_read(struct regmap *map,
unsigned int reg, unsigned int *value);
Expand All @@ -119,7 +118,10 @@ 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: 64 additions & 0 deletions trunk/drivers/base/regmap/regcache-indexed.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Register cache access API - indexed caching support
*
* Copyright 2011 Wolfson Microelectronics plc
*
* Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

#include <linux/slab.h>

#include "internal.h"

static int regcache_indexed_read(struct regmap *map, unsigned int reg,
unsigned int *value)
{
int ret;

ret = regcache_lookup_reg(map, reg);
if (ret >= 0)
*value = map->reg_defaults[ret].def;

return ret;
}

static int regcache_indexed_write(struct regmap *map, unsigned int reg,
unsigned int value)
{
int ret;

ret = regcache_lookup_reg(map, reg);
if (ret < 0)
return regcache_insert_reg(map, reg, value);
map->reg_defaults[ret].def = value;
return 0;
}

static int regcache_indexed_sync(struct regmap *map)
{
unsigned int i;
int ret;

for (i = 0; i < map->num_reg_defaults; i++) {
ret = _regmap_write(map, map->reg_defaults[i].reg,
map->reg_defaults[i].def);
if (ret < 0)
return ret;
dev_dbg(map->dev, "Synced register %#x, value %#x\n",
map->reg_defaults[i].reg,
map->reg_defaults[i].def);
}
return 0;
}

struct regcache_ops regcache_indexed_ops = {
.type = REGCACHE_INDEXED,
.name = "indexed",
.read = regcache_indexed_read,
.write = regcache_indexed_write,
.sync = regcache_indexed_sync
};
21 changes: 8 additions & 13 deletions trunk/drivers/base/regmap/regcache-lzo.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

#include "internal.h"

static int regcache_lzo_exit(struct regmap *map);

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

#define LZO_BLOCK_NUM 8
static int regcache_lzo_block_count(struct regmap *map)
static int regcache_lzo_block_count(void)
{
return LZO_BLOCK_NUM;
}
Expand Down Expand Up @@ -108,22 +106,19 @@ 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(map));
DIV_ROUND_UP(map->cache_size_raw, regcache_lzo_block_count());
}

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(map)) /
return reg % (DIV_ROUND_UP(map->cache_size_raw, regcache_lzo_block_count()) /
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(map));
return DIV_ROUND_UP(map->cache_size_raw, regcache_lzo_block_count());
}

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

ret = 0;

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

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

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

blkcount = regcache_lzo_block_count(map);
blkcount = regcache_lzo_block_count();
/*
* the pointer to the bitmap used for syncing the cache
* is shared amongst all lzo_blocks. Ensure it is freed
Expand Down Expand Up @@ -356,7 +351,7 @@ static int regcache_lzo_sync(struct regmap *map)
}

struct regcache_ops regcache_lzo_ops = {
.type = REGCACHE_COMPRESSED,
.type = REGCACHE_LZO,
.name = "lzo",
.init = regcache_lzo_init,
.exit = regcache_lzo_exit,
Expand Down
61 changes: 1 addition & 60 deletions trunk/drivers/base/regmap/regcache-rbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
*/

#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 @@ -127,60 +124,6 @@ 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 @@ -203,12 +146,10 @@ static int regcache_rbtree_init(struct regmap *map)
goto err;
}

rbtree_debugfs_init(map);

return 0;

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

Expand Down
Loading

0 comments on commit 614e011

Please sign in to comment.