Commit 54fc5a1a authored by Mark Brown's avatar Mark Brown

Merge remote-tracking branch 'asoc/topic/wm2200' into asoc-next

parents 9f07f658 f55ec27f
...@@ -120,6 +120,8 @@ int _regmap_write(struct regmap *map, unsigned int reg, ...@@ -120,6 +120,8 @@ int _regmap_write(struct regmap *map, unsigned int reg,
struct regmap_range_node { struct regmap_range_node {
struct rb_node node; struct rb_node node;
const char *name;
struct regmap *map;
unsigned int range_min; unsigned int range_min;
unsigned int range_max; unsigned int range_max;
......
...@@ -56,7 +56,8 @@ static const struct file_operations regmap_name_fops = { ...@@ -56,7 +56,8 @@ static const struct file_operations regmap_name_fops = {
.llseek = default_llseek, .llseek = default_llseek,
}; };
static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf, static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
unsigned int to, char __user *user_buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
int reg_len, val_len, tot_len; int reg_len, val_len, tot_len;
...@@ -64,7 +65,6 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf, ...@@ -64,7 +65,6 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
loff_t p = 0; loff_t p = 0;
ssize_t ret; ssize_t ret;
int i; int i;
struct regmap *map = file->private_data;
char *buf; char *buf;
unsigned int val; unsigned int val;
...@@ -80,7 +80,7 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf, ...@@ -80,7 +80,7 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
val_len = 2 * map->format.val_bytes; val_len = 2 * map->format.val_bytes;
tot_len = reg_len + val_len + 3; /* : \n */ tot_len = reg_len + val_len + 3; /* : \n */
for (i = 0; i <= map->max_register; i += map->reg_stride) { for (i = from; i <= to; i += map->reg_stride) {
if (!regmap_readable(map, i)) if (!regmap_readable(map, i))
continue; continue;
...@@ -95,7 +95,7 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf, ...@@ -95,7 +95,7 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
/* Format the register */ /* Format the register */
snprintf(buf + buf_pos, count - buf_pos, "%.*x: ", snprintf(buf + buf_pos, count - buf_pos, "%.*x: ",
reg_len, i); reg_len, i - from);
buf_pos += reg_len + 2; buf_pos += reg_len + 2;
/* Format the value, write all X if we can't read */ /* Format the value, write all X if we can't read */
...@@ -126,6 +126,15 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf, ...@@ -126,6 +126,15 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
return ret; return ret;
} }
static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos)
{
struct regmap *map = file->private_data;
return regmap_read_debugfs(map, 0, map->max_register, user_buf,
count, ppos);
}
#undef REGMAP_ALLOW_WRITE_DEBUGFS #undef REGMAP_ALLOW_WRITE_DEBUGFS
#ifdef REGMAP_ALLOW_WRITE_DEBUGFS #ifdef REGMAP_ALLOW_WRITE_DEBUGFS
/* /*
...@@ -174,6 +183,22 @@ static const struct file_operations regmap_map_fops = { ...@@ -174,6 +183,22 @@ static const struct file_operations regmap_map_fops = {
.llseek = default_llseek, .llseek = default_llseek,
}; };
static ssize_t regmap_range_read_file(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos)
{
struct regmap_range_node *range = file->private_data;
struct regmap *map = range->map;
return regmap_read_debugfs(map, range->range_min, range->range_max,
user_buf, count, ppos);
}
static const struct file_operations regmap_range_fops = {
.open = simple_open,
.read = regmap_range_read_file,
.llseek = default_llseek,
};
static ssize_t regmap_access_read_file(struct file *file, static ssize_t regmap_access_read_file(struct file *file,
char __user *user_buf, size_t count, char __user *user_buf, size_t count,
loff_t *ppos) loff_t *ppos)
...@@ -244,6 +269,9 @@ static const struct file_operations regmap_access_fops = { ...@@ -244,6 +269,9 @@ static const struct file_operations regmap_access_fops = {
void regmap_debugfs_init(struct regmap *map, const char *name) void regmap_debugfs_init(struct regmap *map, const char *name)
{ {
struct rb_node *next;
struct regmap_range_node *range_node;
if (name) { if (name) {
map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s", map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s",
dev_name(map->dev), name); dev_name(map->dev), name);
...@@ -276,6 +304,18 @@ void regmap_debugfs_init(struct regmap *map, const char *name) ...@@ -276,6 +304,18 @@ void regmap_debugfs_init(struct regmap *map, const char *name)
debugfs_create_bool("cache_bypass", 0400, map->debugfs, debugfs_create_bool("cache_bypass", 0400, map->debugfs,
&map->cache_bypass); &map->cache_bypass);
} }
next = rb_first(&map->range_tree);
while (next) {
range_node = rb_entry(next, struct regmap_range_node, node);
if (range_node->name)
debugfs_create_file(range_node->name, 0400,
map->debugfs, range_node,
&regmap_range_fops);
next = rb_next(&range_node->node);
}
} }
void regmap_debugfs_exit(struct regmap *map) void regmap_debugfs_exit(struct regmap *map)
......
...@@ -519,20 +519,38 @@ struct regmap *regmap_init(struct device *dev, ...@@ -519,20 +519,38 @@ struct regmap *regmap_init(struct device *dev,
} }
map->range_tree = RB_ROOT; map->range_tree = RB_ROOT;
for (i = 0; i < config->n_ranges; i++) { for (i = 0; i < config->num_ranges; i++) {
const struct regmap_range_cfg *range_cfg = &config->ranges[i]; const struct regmap_range_cfg *range_cfg = &config->ranges[i];
struct regmap_range_node *new; struct regmap_range_node *new;
/* Sanity check */ /* Sanity check */
if (range_cfg->range_max < range_cfg->range_min || if (range_cfg->range_max < range_cfg->range_min) {
range_cfg->range_max > map->max_register || dev_err(map->dev, "Invalid range %d: %d < %d\n", i,
range_cfg->selector_reg > map->max_register || range_cfg->range_max, range_cfg->range_min);
range_cfg->window_len == 0)
goto err_range; goto err_range;
}
if (range_cfg->range_max > map->max_register) {
dev_err(map->dev, "Invalid range %d: %d > %d\n", i,
range_cfg->range_max, map->max_register);
goto err_range;
}
if (range_cfg->selector_reg > map->max_register) {
dev_err(map->dev,
"Invalid range %d: selector out of map\n", i);
goto err_range;
}
if (range_cfg->window_len == 0) {
dev_err(map->dev, "Invalid range %d: window_len 0\n",
i);
goto err_range;
}
/* Make sure, that this register range has no selector /* Make sure, that this register range has no selector
or data window within its boundary */ or data window within its boundary */
for (j = 0; j < config->n_ranges; j++) { for (j = 0; j < config->num_ranges; j++) {
unsigned sel_reg = config->ranges[j].selector_reg; unsigned sel_reg = config->ranges[j].selector_reg;
unsigned win_min = config->ranges[j].window_start; unsigned win_min = config->ranges[j].window_start;
unsigned win_max = win_min + unsigned win_max = win_min +
...@@ -540,11 +558,17 @@ struct regmap *regmap_init(struct device *dev, ...@@ -540,11 +558,17 @@ struct regmap *regmap_init(struct device *dev,
if (range_cfg->range_min <= sel_reg && if (range_cfg->range_min <= sel_reg &&
sel_reg <= range_cfg->range_max) { sel_reg <= range_cfg->range_max) {
dev_err(map->dev,
"Range %d: selector for %d in window\n",
i, j);
goto err_range; goto err_range;
} }
if (!(win_max < range_cfg->range_min || if (!(win_max < range_cfg->range_min ||
win_min > range_cfg->range_max)) { win_min > range_cfg->range_max)) {
dev_err(map->dev,
"Range %d: window for %d in window\n",
i, j);
goto err_range; goto err_range;
} }
} }
...@@ -555,6 +579,8 @@ struct regmap *regmap_init(struct device *dev, ...@@ -555,6 +579,8 @@ struct regmap *regmap_init(struct device *dev,
goto err_range; goto err_range;
} }
new->map = map;
new->name = range_cfg->name;
new->range_min = range_cfg->range_min; new->range_min = range_cfg->range_min;
new->range_max = range_cfg->range_max; new->range_max = range_cfg->range_max;
new->selector_reg = range_cfg->selector_reg; new->selector_reg = range_cfg->selector_reg;
...@@ -564,6 +590,7 @@ struct regmap *regmap_init(struct device *dev, ...@@ -564,6 +590,7 @@ struct regmap *regmap_init(struct device *dev,
new->window_len = range_cfg->window_len; new->window_len = range_cfg->window_len;
if (_regmap_range_add(map, new) == false) { if (_regmap_range_add(map, new) == false) {
dev_err(map->dev, "Failed to add range %d\n", i);
kfree(new); kfree(new);
goto err_range; goto err_range;
} }
...@@ -579,7 +606,7 @@ struct regmap *regmap_init(struct device *dev, ...@@ -579,7 +606,7 @@ struct regmap *regmap_init(struct device *dev,
} }
ret = regcache_init(map, config); ret = regcache_init(map, config);
if (ret < 0) if (ret != 0)
goto err_range; goto err_range;
regmap_debugfs_init(map, config->name); regmap_debugfs_init(map, config->name);
...@@ -738,17 +765,15 @@ struct regmap *dev_get_regmap(struct device *dev, const char *name) ...@@ -738,17 +765,15 @@ struct regmap *dev_get_regmap(struct device *dev, const char *name)
EXPORT_SYMBOL_GPL(dev_get_regmap); EXPORT_SYMBOL_GPL(dev_get_regmap);
static int _regmap_select_page(struct regmap *map, unsigned int *reg, static int _regmap_select_page(struct regmap *map, unsigned int *reg,
struct regmap_range_node *range,
unsigned int val_num) unsigned int val_num)
{ {
struct regmap_range_node *range;
void *orig_work_buf; void *orig_work_buf;
unsigned int win_offset; unsigned int win_offset;
unsigned int win_page; unsigned int win_page;
bool page_chg; bool page_chg;
int ret; int ret;
range = _regmap_range_lookup(map, *reg);
if (range) {
win_offset = (*reg - range->range_min) % range->window_len; win_offset = (*reg - range->range_min) % range->window_len;
win_page = (*reg - range->range_min) / range->window_len; win_page = (*reg - range->range_min) / range->window_len;
...@@ -778,12 +803,11 @@ static int _regmap_select_page(struct regmap *map, unsigned int *reg, ...@@ -778,12 +803,11 @@ static int _regmap_select_page(struct regmap *map, unsigned int *reg,
map->work_buf = orig_work_buf; map->work_buf = orig_work_buf;
if (ret < 0) if (ret != 0)
return ret; return ret;
} }
*reg = range->window_start + win_offset; *reg = range->window_start + win_offset;
}
return 0; return 0;
} }
...@@ -791,6 +815,7 @@ static int _regmap_select_page(struct regmap *map, unsigned int *reg, ...@@ -791,6 +815,7 @@ static int _regmap_select_page(struct regmap *map, unsigned int *reg,
static int _regmap_raw_write(struct regmap *map, unsigned int reg, static int _regmap_raw_write(struct regmap *map, unsigned int reg,
const void *val, size_t val_len) const void *val, size_t val_len)
{ {
struct regmap_range_node *range;
u8 *u8 = map->work_buf; u8 *u8 = map->work_buf;
void *buf; void *buf;
int ret = -ENOTSUPP; int ret = -ENOTSUPP;
...@@ -825,9 +850,35 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg, ...@@ -825,9 +850,35 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
} }
} }
ret = _regmap_select_page(map, &reg, val_len / map->format.val_bytes); range = _regmap_range_lookup(map, reg);
if (ret < 0) if (range) {
int val_num = val_len / map->format.val_bytes;
int win_offset = (reg - range->range_min) % range->window_len;
int win_residue = range->window_len - win_offset;
/* If the write goes beyond the end of the window split it */
while (val_num > win_residue) {
dev_dbg(map->dev, "Writing window %d/%d\n",
win_residue, val_len / map->format.val_bytes);
ret = _regmap_raw_write(map, reg, val, win_residue *
map->format.val_bytes);
if (ret != 0)
return ret;
reg += win_residue;
val_num -= win_residue;
val += win_residue * map->format.val_bytes;
val_len -= win_residue * map->format.val_bytes;
win_offset = (reg - range->range_min) %
range->window_len;
win_residue = range->window_len - win_offset;
}
ret = _regmap_select_page(map, &reg, range, val_num);
if (ret != 0)
return ret; return ret;
}
map->format.format_reg(map->work_buf, reg, map->reg_shift); map->format.format_reg(map->work_buf, reg, map->reg_shift);
...@@ -876,6 +927,7 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg, ...@@ -876,6 +927,7 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
int _regmap_write(struct regmap *map, unsigned int reg, int _regmap_write(struct regmap *map, unsigned int reg,
unsigned int val) unsigned int val)
{ {
struct regmap_range_node *range;
int ret; int ret;
BUG_ON(!map->format.format_write && !map->format.format_val); BUG_ON(!map->format.format_write && !map->format.format_val);
...@@ -897,9 +949,12 @@ int _regmap_write(struct regmap *map, unsigned int reg, ...@@ -897,9 +949,12 @@ int _regmap_write(struct regmap *map, unsigned int reg,
trace_regmap_reg_write(map->dev, reg, val); trace_regmap_reg_write(map->dev, reg, val);
if (map->format.format_write) { if (map->format.format_write) {
ret = _regmap_select_page(map, &reg, 1); range = _regmap_range_lookup(map, reg);
if (ret < 0) if (range) {
ret = _regmap_select_page(map, &reg, range, 1);
if (ret != 0)
return ret; return ret;
}
map->format.format_write(map, reg, val); map->format.format_write(map, reg, val);
...@@ -1055,12 +1110,17 @@ EXPORT_SYMBOL_GPL(regmap_bulk_write); ...@@ -1055,12 +1110,17 @@ EXPORT_SYMBOL_GPL(regmap_bulk_write);
static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
unsigned int val_len) unsigned int val_len)
{ {
struct regmap_range_node *range;
u8 *u8 = map->work_buf; u8 *u8 = map->work_buf;
int ret; int ret;
ret = _regmap_select_page(map, &reg, val_len / map->format.val_bytes); range = _regmap_range_lookup(map, reg);
if (ret < 0) if (range) {
ret = _regmap_select_page(map, &reg, range,
val_len / map->format.val_bytes);
if (ret != 0)
return ret; return ret;
}
map->format.format_reg(map->work_buf, reg, map->reg_shift); map->format.format_reg(map->work_buf, reg, map->reg_shift);
......
...@@ -133,7 +133,7 @@ struct regmap_config { ...@@ -133,7 +133,7 @@ struct regmap_config {
enum regmap_endian val_format_endian; enum regmap_endian val_format_endian;
const struct regmap_range_cfg *ranges; const struct regmap_range_cfg *ranges;
unsigned int n_ranges; unsigned int num_ranges;
}; };
/** /**
...@@ -142,6 +142,8 @@ struct regmap_config { ...@@ -142,6 +142,8 @@ struct regmap_config {
* 1. page selector register update; * 1. page selector register update;
* 2. access through data window registers. * 2. access through data window registers.
* *
* @name: Descriptive name for diagnostics
*
* @range_min: Address of the lowest register address in virtual range. * @range_min: Address of the lowest register address in virtual range.
* @range_max: Address of the highest register in virtual range. * @range_max: Address of the highest register in virtual range.
* *
...@@ -153,6 +155,8 @@ struct regmap_config { ...@@ -153,6 +155,8 @@ struct regmap_config {
* @window_len: Number of registers in data window. * @window_len: Number of registers in data window.
*/ */
struct regmap_range_cfg { struct regmap_range_cfg {
const char *name;
/* Registers of virtual address range */ /* Registers of virtual address range */
unsigned int range_min; unsigned int range_min;
unsigned int range_max; unsigned int range_max;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment