From e3549cd01347ef211d01353bdf2572b086574007 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Tue, 2 Oct 2012 20:17:15 +0100 Subject: [PATCH 01/12] regmap: Rename n_ranges to num_ranges This makes things consistent with the rest of the API and is actually what the documentation says. We don't currently have any in tree users so low cost. Signed-off-by: Mark Brown --- drivers/base/regmap/regmap.c | 4 ++-- include/linux/regmap.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 52069d29ff12..ea9d6eb826bd 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -519,7 +519,7 @@ struct regmap *regmap_init(struct device *dev, } 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]; struct regmap_range_node *new; @@ -532,7 +532,7 @@ struct regmap *regmap_init(struct device *dev, /* Make sure, that this register range has no selector 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 win_min = config->ranges[j].window_start; unsigned win_max = win_min + diff --git a/include/linux/regmap.h b/include/linux/regmap.h index e3bcc3f4dcb8..afc8e1a2cd1b 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -133,7 +133,7 @@ struct regmap_config { enum regmap_endian val_format_endian; const struct regmap_range_cfg *ranges; - unsigned int n_ranges; + unsigned int num_ranges; }; /** From 061adc064adbbdd9eb127ab2e86b7a71f4ccaf2e Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 3 Oct 2012 12:17:51 +0100 Subject: [PATCH 02/12] regmap: When we sanity check during range adds say what errors we find Rather than just returning a single error code for every possible thing we can notice print an error message saying what the problem was. This makes it very much easier to figure out what's wrong and fix it. Signed-off-by: Mark Brown --- drivers/base/regmap/regmap.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index ea9d6eb826bd..0544f63ecd31 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -524,11 +524,29 @@ struct regmap *regmap_init(struct device *dev, struct regmap_range_node *new; /* Sanity check */ - if (range_cfg->range_max < range_cfg->range_min || - range_cfg->range_max > map->max_register || - range_cfg->selector_reg > map->max_register || - range_cfg->window_len == 0) + if (range_cfg->range_max < range_cfg->range_min) { + dev_err(map->dev, "Invalid range %d: %d < %d\n", i, + range_cfg->range_max, range_cfg->range_min); 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 or data window within its boundary */ @@ -540,11 +558,17 @@ struct regmap *regmap_init(struct device *dev, if (range_cfg->range_min <= sel_reg && sel_reg <= range_cfg->range_max) { + dev_err(map->dev, + "Range %d: selector for %d in window\n", + i, j); goto err_range; } if (!(win_max < range_cfg->range_min || win_min > range_cfg->range_max)) { + dev_err(map->dev, + "Range %d: window for %d in window\n", + i, j); goto err_range; } } @@ -564,6 +588,7 @@ struct regmap *regmap_init(struct device *dev, new->window_len = range_cfg->window_len; if (_regmap_range_add(map, new) == false) { + dev_err(map->dev, "Failed to add range %d\n", i); kfree(new); goto err_range; } From d058bb49618482f2eff0db57618c9a7352916dd5 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 3 Oct 2012 12:40:47 +0100 Subject: [PATCH 03/12] regmap: Allow ranges to be named For more useful diagnostics. Signed-off-by: Mark Brown --- drivers/base/regmap/internal.h | 1 + drivers/base/regmap/regmap.c | 1 + include/linux/regmap.h | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h index 80f9ab9c3aa4..27e66c3e7a59 100644 --- a/drivers/base/regmap/internal.h +++ b/drivers/base/regmap/internal.h @@ -120,6 +120,7 @@ int _regmap_write(struct regmap *map, unsigned int reg, struct regmap_range_node { struct rb_node node; + const char *name; unsigned int range_min; unsigned int range_max; diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 0544f63ecd31..ce5129df4406 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -579,6 +579,7 @@ struct regmap *regmap_init(struct device *dev, goto err_range; } + new->name = range_cfg->name; new->range_min = range_cfg->range_min; new->range_max = range_cfg->range_max; new->selector_reg = range_cfg->selector_reg; diff --git a/include/linux/regmap.h b/include/linux/regmap.h index afc8e1a2cd1b..9f228d7f7ac4 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -142,6 +142,8 @@ struct regmap_config { * 1. page selector register update; * 2. access through data window registers. * + * @name: Descriptive name for diagnostics + * * @range_min: Address of the lowest register address in virtual range. * @range_max: Address of the highest register in virtual range. * @@ -153,6 +155,8 @@ struct regmap_config { * @window_len: Number of registers in data window. */ struct regmap_range_cfg { + const char *name; + /* Registers of virtual address range */ unsigned int range_min; unsigned int range_max; From bd9cc12f4a7e7389432bba0cae6970dfc28f423c Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 3 Oct 2012 12:45:37 +0100 Subject: [PATCH 04/12] regmap: Factor out debugfs register read This will allow the use of the same code for reading register ranges. Signed-off-by: Mark Brown --- drivers/base/regmap/regmap-debugfs.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index bb1ff175b962..25b6843d6a41 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -56,15 +56,15 @@ static const struct file_operations regmap_name_fops = { .llseek = default_llseek, }; -static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf, - size_t count, loff_t *ppos) +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) { int reg_len, val_len, tot_len; size_t buf_pos = 0; loff_t p = 0; ssize_t ret; int i; - struct regmap *map = file->private_data; char *buf; unsigned int val; @@ -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; 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)) continue; @@ -95,7 +95,7 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf, /* Format the register */ snprintf(buf + buf_pos, count - buf_pos, "%.*x: ", - reg_len, i); + reg_len, i - from); buf_pos += reg_len + 2; /* 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, 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 #ifdef REGMAP_ALLOW_WRITE_DEBUGFS /* From 4b020b3f9ba2af8031c5c7d759fbafd234d1c390 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 3 Oct 2012 13:13:16 +0100 Subject: [PATCH 05/12] regmap: Provide debugfs read of register ranges If a register range is named then provide a debugfs file showing the contents of the range separately. Signed-off-by: Mark Brown --- drivers/base/regmap/internal.h | 1 + drivers/base/regmap/regmap-debugfs.c | 31 ++++++++++++++++++++++++++++ drivers/base/regmap/regmap.c | 1 + 3 files changed, 33 insertions(+) diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h index 27e66c3e7a59..ac869d28d5ba 100644 --- a/drivers/base/regmap/internal.h +++ b/drivers/base/regmap/internal.h @@ -121,6 +121,7 @@ int _regmap_write(struct regmap *map, unsigned int reg, struct regmap_range_node { struct rb_node node; const char *name; + struct regmap *map; unsigned int range_min; unsigned int range_max; diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index 25b6843d6a41..f4b9dd01c981 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -183,6 +183,22 @@ static const struct file_operations regmap_map_fops = { .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, char __user *user_buf, size_t count, loff_t *ppos) @@ -253,6 +269,9 @@ static const struct file_operations regmap_access_fops = { void regmap_debugfs_init(struct regmap *map, const char *name) { + struct rb_node *next; + struct regmap_range_node *range_node; + if (name) { map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s", dev_name(map->dev), name); @@ -285,6 +304,18 @@ void regmap_debugfs_init(struct regmap *map, const char *name) debugfs_create_bool("cache_bypass", 0400, map->debugfs, &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, + ®map_range_fops); + + next = rb_next(&range_node->node); + } } void regmap_debugfs_exit(struct regmap *map) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index ce5129df4406..366b629f4b10 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -579,6 +579,7 @@ struct regmap *regmap_init(struct device *dev, goto err_range; } + new->map = map; new->name = range_cfg->name; new->range_min = range_cfg->range_min; new->range_max = range_cfg->range_max; From 98bc7dfd76407eaa0964ecb4d5319c957a3b9df9 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 4 Oct 2012 17:31:11 +0100 Subject: [PATCH 06/12] regmap: Factor range lookup out of page selection This will support a subsequent update to allow bulk writes to cross window boundaries. Signed-off-by: Mark Brown --- drivers/base/regmap/regmap.c | 99 ++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 44 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 366b629f4b10..4bb926cd7bf2 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -765,59 +765,57 @@ struct regmap *dev_get_regmap(struct device *dev, const char *name) EXPORT_SYMBOL_GPL(dev_get_regmap); static int _regmap_select_page(struct regmap *map, unsigned int *reg, + struct regmap_range_node *range, unsigned int val_num) { - struct regmap_range_node *range; void *orig_work_buf; unsigned int win_offset; unsigned int win_page; bool page_chg; int ret; - range = _regmap_range_lookup(map, *reg); - if (range) { - win_offset = (*reg - range->range_min) % range->window_len; - win_page = (*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; - if (val_num > 1) { - /* Bulk write shouldn't cross range boundary */ - if (*reg + val_num - 1 > range->range_max) - return -EINVAL; + if (val_num > 1) { + /* Bulk write shouldn't cross range boundary */ + if (*reg + val_num - 1 > range->range_max) + return -EINVAL; - /* ... or single page boundary */ - if (val_num > range->window_len - win_offset) - return -EINVAL; - } - - /* It is possible to have selector register inside data window. - In that case, selector register is located on every page and - it needs no page switching, when accessed alone. */ - if (val_num > 1 || - range->window_start + win_offset != range->selector_reg) { - /* Use separate work_buf during page switching */ - orig_work_buf = map->work_buf; - map->work_buf = map->selector_work_buf; - - ret = _regmap_update_bits(map, range->selector_reg, - range->selector_mask, - win_page << range->selector_shift, - &page_chg); - - map->work_buf = orig_work_buf; - - if (ret < 0) - return ret; - } - - *reg = range->window_start + win_offset; + /* ... or single page boundary */ + if (val_num > range->window_len - win_offset) + return -EINVAL; } + /* It is possible to have selector register inside data window. + In that case, selector register is located on every page and + it needs no page switching, when accessed alone. */ + if (val_num > 1 || + range->window_start + win_offset != range->selector_reg) { + /* Use separate work_buf during page switching */ + orig_work_buf = map->work_buf; + map->work_buf = map->selector_work_buf; + + ret = _regmap_update_bits(map, range->selector_reg, + range->selector_mask, + win_page << range->selector_shift, + &page_chg); + + map->work_buf = orig_work_buf; + + if (ret < 0) + return ret; + } + + *reg = range->window_start + win_offset; + return 0; } static int _regmap_raw_write(struct regmap *map, unsigned int reg, const void *val, size_t val_len) { + struct regmap_range_node *range; u8 *u8 = map->work_buf; void *buf; int ret = -ENOTSUPP; @@ -852,9 +850,13 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg, } } - ret = _regmap_select_page(map, ®, val_len / map->format.val_bytes); - if (ret < 0) - return ret; + range = _regmap_range_lookup(map, reg); + if (range) { + ret = _regmap_select_page(map, ®, range, + val_len / map->format.val_bytes); + if (ret < 0) + return ret; + } map->format.format_reg(map->work_buf, reg, map->reg_shift); @@ -903,6 +905,7 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg, int _regmap_write(struct regmap *map, unsigned int reg, unsigned int val) { + struct regmap_range_node *range; int ret; BUG_ON(!map->format.format_write && !map->format.format_val); @@ -924,9 +927,12 @@ int _regmap_write(struct regmap *map, unsigned int reg, trace_regmap_reg_write(map->dev, reg, val); if (map->format.format_write) { - ret = _regmap_select_page(map, ®, 1); - if (ret < 0) - return ret; + range = _regmap_range_lookup(map, reg); + if (range) { + ret = _regmap_select_page(map, ®, range, 1); + if (ret < 0) + return ret; + } map->format.format_write(map, reg, val); @@ -1082,12 +1088,17 @@ EXPORT_SYMBOL_GPL(regmap_bulk_write); static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, unsigned int val_len) { + struct regmap_range_node *range; u8 *u8 = map->work_buf; int ret; - ret = _regmap_select_page(map, ®, val_len / map->format.val_bytes); - if (ret < 0) - return ret; + range = _regmap_range_lookup(map, reg); + if (range) { + ret = _regmap_select_page(map, ®, range, + val_len / map->format.val_bytes); + if (ret < 0) + return ret; + } map->format.format_reg(map->work_buf, reg, map->reg_shift); From 0ff3e62ff119f2b65b0a8ad48fcb669f609fd904 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 4 Oct 2012 17:39:13 +0100 Subject: [PATCH 07/12] regmap: Make return code checks consistent The range code was written to check for return codes less than zero as errors but throughout the rest of the API return codes not equal to zero are errors. Change all these checks to match the house style. Signed-off-by: Mark Brown --- drivers/base/regmap/regmap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 4bb926cd7bf2..baf9586b4fd8 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -606,7 +606,7 @@ struct regmap *regmap_init(struct device *dev, } ret = regcache_init(map, config); - if (ret < 0) + if (ret != 0) goto err_range; regmap_debugfs_init(map, config->name); @@ -803,7 +803,7 @@ static int _regmap_select_page(struct regmap *map, unsigned int *reg, map->work_buf = orig_work_buf; - if (ret < 0) + if (ret != 0) return ret; } @@ -854,7 +854,7 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg, if (range) { ret = _regmap_select_page(map, ®, range, val_len / map->format.val_bytes); - if (ret < 0) + if (ret != 0) return ret; } @@ -930,7 +930,7 @@ int _regmap_write(struct regmap *map, unsigned int reg, range = _regmap_range_lookup(map, reg); if (range) { ret = _regmap_select_page(map, ®, range, 1); - if (ret < 0) + if (ret != 0) return ret; } @@ -1096,7 +1096,7 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, if (range) { ret = _regmap_select_page(map, ®, range, val_len / map->format.val_bytes); - if (ret < 0) + if (ret != 0) return ret; } From 8a2ceac6617a67d8a1ee4bd255743d577bde311a Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 4 Oct 2012 18:20:18 +0100 Subject: [PATCH 08/12] regmap: Split raw writes that cross window boundaries If a block write covers a paged memory region and crosses a window boundary then rather than failing the write split the transfer up into multiple writes, making the whole process more transparent for drivers. Signed-off-by: Mark Brown --- drivers/base/regmap/regmap.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index baf9586b4fd8..96253cd949e9 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -852,8 +852,30 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg, range = _regmap_range_lookup(map, reg); if (range) { - ret = _regmap_select_page(map, ®, range, - val_len / map->format.val_bytes); + 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, ®, range, val_num); if (ret != 0) return ret; } From 9874482985fb26f90c3b2d8f1a82bd796d141304 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 3 Oct 2012 13:31:49 +0100 Subject: [PATCH 09/12] ASoC: wm2200: Add names for ranges Signed-off-by: Mark Brown --- sound/soc/codecs/wm2200.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/sound/soc/codecs/wm2200.c b/sound/soc/codecs/wm2200.c index 06d4e612a164..b63391a7dae9 100644 --- a/sound/soc/codecs/wm2200.c +++ b/sound/soc/codecs/wm2200.c @@ -109,48 +109,42 @@ struct wm2200_priv { #define WM2200_DSP2_ZM_BASE (WM2200_DSP_RANGE_BASE + (5 * WM2200_DSP_SPACING)) static const struct regmap_range_cfg wm2200_ranges[] = { - /* DSP1 DM */ - { .range_min = WM2200_DSP1_DM_BASE, + { .name = "DSP1DM", .range_min = WM2200_DSP1_DM_BASE, .range_max = WM2200_DSP1_DM_BASE + 12287, .selector_reg = WM2200_DSP1_CONTROL_3, .selector_mask = WM2200_DSP1_PAGE_BASE_DM_0_MASK, .selector_shift = WM2200_DSP1_PAGE_BASE_DM_0_SHIFT, .window_start = WM2200_DSP1_DM_0, .window_len = 2048, }, - /* DSP1 PM */ - { .range_min = WM2200_DSP1_PM_BASE, + { .name = "DSP1PM", .range_min = WM2200_DSP1_PM_BASE, .range_max = WM2200_DSP1_PM_BASE + 12287, .selector_reg = WM2200_DSP1_CONTROL_2, .selector_mask = WM2200_DSP1_PAGE_BASE_PM_0_MASK, .selector_shift = WM2200_DSP1_PAGE_BASE_PM_0_SHIFT, .window_start = WM2200_DSP1_PM_0, .window_len = 768, }, - /* DSP1 ZM */ - { .range_min = WM2200_DSP1_ZM_BASE, + { .name = "DSP1ZM", .range_min = WM2200_DSP1_ZM_BASE, .range_max = WM2200_DSP1_ZM_BASE + 2047, .selector_reg = WM2200_DSP1_CONTROL_4, .selector_mask = WM2200_DSP1_PAGE_BASE_ZM_0_MASK, .selector_shift = WM2200_DSP1_PAGE_BASE_ZM_0_SHIFT, .window_start = WM2200_DSP1_ZM_0, .window_len = 1024, }, - /* DSP2 DM */ - { .range_min = WM2200_DSP2_DM_BASE, + { .name = "DSP2DM", .range_min = WM2200_DSP2_DM_BASE, .range_max = WM2200_DSP2_DM_BASE + 4095, .selector_reg = WM2200_DSP2_CONTROL_3, .selector_mask = WM2200_DSP2_PAGE_BASE_DM_0_MASK, .selector_shift = WM2200_DSP2_PAGE_BASE_DM_0_SHIFT, .window_start = WM2200_DSP2_DM_0, .window_len = 2048, }, - /* DSP2 PM */ - { .range_min = WM2200_DSP2_PM_BASE, + { .name = "DSP2PM", .range_min = WM2200_DSP2_PM_BASE, .range_max = WM2200_DSP2_PM_BASE + 11287, .selector_reg = WM2200_DSP2_CONTROL_2, .selector_mask = WM2200_DSP2_PAGE_BASE_PM_0_MASK, .selector_shift = WM2200_DSP2_PAGE_BASE_PM_0_SHIFT, .window_start = WM2200_DSP2_PM_0, .window_len = 768, }, - /* DSP2 ZM */ - { .range_min = WM2200_DSP2_ZM_BASE, + { .name = "DSP2ZM", .range_min = WM2200_DSP2_ZM_BASE, .range_max = WM2200_DSP2_ZM_BASE + 2047, .selector_reg = WM2200_DSP2_CONTROL_4, .selector_mask = WM2200_DSP2_PAGE_BASE_ZM_0_MASK, From 8858086f35d13dcaceeebabcedade0ebbc9e01fa Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Fri, 19 Oct 2012 16:13:07 -0700 Subject: [PATCH 10/12] ASoC: fix wm2200.c printk format warnings Fix wm2200.c printk format warnings (seen on x86_64): sound/soc/codecs/wm2200.c:1027:4: warning: format '%d' expects type 'int', but argument 4 has type 'size_t' sound/soc/codecs/wm2200.c:1139:5: warning: format '%d' expects type 'int', but argument 5 has type 'long unsigned int' sound/soc/codecs/wm2200.c:1181:2: warning: format '%d' expects type 'int', but argument 7 has type 'size_t' sound/soc/codecs/wm2200.c:1201:5: warning: format '%x' expects type 'unsigned int', but argument 3 has type 'long unsigned int' sound/soc/codecs/wm2200.c:1264:4: warning: format '%d' expects type 'int', but argument 4 has type 'size_t' sound/soc/codecs/wm2200.c:1328:5: warning: format '%d' expects type 'int', but argument 5 has type 'long unsigned int' Signed-off-by: Randy Dunlap Signed-off-by: Mark Brown --- sound/soc/codecs/wm2200.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/wm2200.c b/sound/soc/codecs/wm2200.c index b63391a7dae9..2148ee31cd66 100644 --- a/sound/soc/codecs/wm2200.c +++ b/sound/soc/codecs/wm2200.c @@ -1023,7 +1023,7 @@ static int wm2200_dsp_load(struct snd_soc_codec *codec, int base) pos = sizeof(*header) + sizeof(*adsp1_sizes) + sizeof(*footer); if (pos >= firmware->size) { - dev_err(codec->dev, "%s: file too short, %d bytes\n", + dev_err(codec->dev, "%s: file too short, %zu bytes\n", file, firmware->size); return -EINVAL; } @@ -1135,7 +1135,7 @@ static int wm2200_dsp_load(struct snd_soc_codec *codec, int base) } if (pos > firmware->size) - dev_warn(codec->dev, "%s.%d: %d bytes at end of file\n", + dev_warn(codec->dev, "%s.%d: %zu bytes at end of file\n", file, regions, pos - firmware->size); out: @@ -1178,7 +1178,7 @@ static int wm2200_setup_algs(struct snd_soc_codec *codec, int base) } algs = be32_to_cpu(id.algs); - dev_info(codec->dev, "Firmware: %x v%d.%d.%d, %d algorithms\n", + dev_info(codec->dev, "Firmware: %x v%d.%d.%d, %zu algorithms\n", be32_to_cpu(id.fw.id), (be32_to_cpu(id.fw.ver) & 0xff000) >> 16, (be32_to_cpu(id.fw.ver) & 0xff00) >> 8, @@ -1196,7 +1196,7 @@ static int wm2200_setup_algs(struct snd_soc_codec *codec, int base) } if (be32_to_cpu(val) != 0xbedead) - dev_warn(codec->dev, "Algorithm list end %x 0x%x != 0xbeadead\n", + dev_warn(codec->dev, "Algorithm list end %zx 0x%x != 0xbeadead\n", (sizeof(id) + (algs * sizeof(*alg))) / 2, be32_to_cpu(val)); @@ -1260,7 +1260,7 @@ static int wm2200_load_coeff(struct snd_soc_codec *codec, int base) } if (sizeof(*hdr) >= firmware->size) { - dev_err(codec->dev, "%s: file too short, %d bytes\n", + dev_err(codec->dev, "%s: file too short, %zu bytes\n", file, firmware->size); return -EINVAL; } @@ -1324,7 +1324,7 @@ static int wm2200_load_coeff(struct snd_soc_codec *codec, int base) } if (pos > firmware->size) - dev_warn(codec->dev, "%s.%d: %d bytes at end of file\n", + dev_warn(codec->dev, "%s.%d: %zu bytes at end of file\n", file, blocks, pos - firmware->size); return 0; From f017eb299c3ac219215ce896718ea128ad9343eb Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 25 Oct 2012 21:48:11 +0100 Subject: [PATCH 11/12] ASoC: wm2200: Convert over to wm_adsp for ADSP1 support Signed-off-by: Mark Brown --- sound/soc/codecs/wm2200.c | 432 +++----------------------------------- 1 file changed, 32 insertions(+), 400 deletions(-) diff --git a/sound/soc/codecs/wm2200.c b/sound/soc/codecs/wm2200.c index 2148ee31cd66..1730df83839c 100644 --- a/sound/soc/codecs/wm2200.c +++ b/sound/soc/codecs/wm2200.c @@ -34,6 +34,7 @@ #include "wm2200.h" #include "wmfw.h" +#include "wm_adsp.h" #define WM2200_DSP_CONTROL_1 0x00 #define WM2200_DSP_CONTROL_2 0x02 @@ -83,6 +84,7 @@ struct wm2200_fll { /* codec private data */ struct wm2200_priv { + struct wm_adsp dsp[2]; struct regmap *regmap; struct device *dev; struct snd_soc_codec *codec; @@ -152,6 +154,18 @@ static const struct regmap_range_cfg wm2200_ranges[] = { .window_start = WM2200_DSP2_ZM_0, .window_len = 1024, }, }; +static const struct wm_adsp_region wm2200_dsp1_regions[] = { + { .type = WMFW_ADSP1_PM, .base = WM2200_DSP1_PM_BASE }, + { .type = WMFW_ADSP1_DM, .base = WM2200_DSP1_DM_BASE }, + { .type = WMFW_ADSP1_ZM, .base = WM2200_DSP1_ZM_BASE }, +}; + +static const struct wm_adsp_region wm2200_dsp2_regions[] = { + { .type = WMFW_ADSP1_PM, .base = WM2200_DSP2_PM_BASE }, + { .type = WMFW_ADSP1_DM, .base = WM2200_DSP2_DM_BASE }, + { .type = WMFW_ADSP1_ZM, .base = WM2200_DSP2_ZM_BASE }, +}; + static struct reg_default wm2200_reg_defaults[] = { { 0x000B, 0x0000 }, /* R11 - Tone Generator 1 */ { 0x0102, 0x0000 }, /* R258 - Clocking 3 */ @@ -981,400 +995,6 @@ static int wm2200_reset(struct wm2200_priv *wm2200) } } -static int wm2200_dsp_load(struct snd_soc_codec *codec, int base) -{ - const struct firmware *firmware; - struct regmap *regmap = codec->control_data; - unsigned int pos = 0; - const struct wmfw_header *header; - const struct wmfw_adsp1_sizes *adsp1_sizes; - const struct wmfw_footer *footer; - const struct wmfw_region *region; - const char *file, *region_name; - char *text; - unsigned int dm, pm, zm, reg; - int regions = 0; - int ret, offset, type; - - switch (base) { - case WM2200_DSP1_CONTROL_1: - file = "wm2200-dsp1.wmfw"; - dm = WM2200_DSP1_DM_BASE; - pm = WM2200_DSP1_PM_BASE; - zm = WM2200_DSP1_ZM_BASE; - break; - case WM2200_DSP2_CONTROL_1: - file = "wm2200-dsp2.wmfw"; - dm = WM2200_DSP2_DM_BASE; - pm = WM2200_DSP2_PM_BASE; - zm = WM2200_DSP2_ZM_BASE; - break; - default: - dev_err(codec->dev, "BASE %x\n", base); - BUG_ON(1); - return -EINVAL; - } - - ret = request_firmware(&firmware, file, codec->dev); - if (ret != 0) { - dev_err(codec->dev, "Failed to request '%s'\n", file); - return ret; - } - - pos = sizeof(*header) + sizeof(*adsp1_sizes) + sizeof(*footer); - if (pos >= firmware->size) { - dev_err(codec->dev, "%s: file too short, %zu bytes\n", - file, firmware->size); - return -EINVAL; - } - - header = (void*)&firmware->data[0]; - - if (memcmp(&header->magic[0], "WMFW", 4) != 0) { - dev_err(codec->dev, "%s: invalid magic\n", file); - return -EINVAL; - } - - if (header->ver != 0) { - dev_err(codec->dev, "%s: unknown file format %d\n", - file, header->ver); - return -EINVAL; - } - - if (le32_to_cpu(header->len) != sizeof(*header) + - sizeof(*adsp1_sizes) + sizeof(*footer)) { - dev_err(codec->dev, "%s: unexpected header length %d\n", - file, le32_to_cpu(header->len)); - return -EINVAL; - } - - if (header->core != WMFW_ADSP1) { - dev_err(codec->dev, "%s: invalid core %d\n", - file, header->core); - return -EINVAL; - } - - adsp1_sizes = (void *)&(header[1]); - footer = (void *)&(adsp1_sizes[1]); - - dev_dbg(codec->dev, "%s: %d DM, %d PM, %d ZM\n", - file, le32_to_cpu(adsp1_sizes->dm), - le32_to_cpu(adsp1_sizes->pm), le32_to_cpu(adsp1_sizes->zm)); - - dev_dbg(codec->dev, "%s: timestamp %llu\n", file, - le64_to_cpu(footer->timestamp)); - - while (pos < firmware->size && - pos - firmware->size > sizeof(*region)) { - region = (void *)&(firmware->data[pos]); - region_name = "Unknown"; - reg = 0; - text = NULL; - offset = le32_to_cpu(region->offset) & 0xffffff; - type = be32_to_cpu(region->type) & 0xff; - - switch (type) { - case WMFW_NAME_TEXT: - region_name = "Firmware name"; - text = kzalloc(le32_to_cpu(region->len) + 1, - GFP_KERNEL); - break; - case WMFW_INFO_TEXT: - region_name = "Information"; - text = kzalloc(le32_to_cpu(region->len) + 1, - GFP_KERNEL); - break; - case WMFW_ABSOLUTE: - region_name = "Absolute"; - reg = offset; - break; - case WMFW_ADSP1_PM: - region_name = "PM"; - reg = pm + (offset * 3); - break; - case WMFW_ADSP1_DM: - region_name = "DM"; - reg = dm + (offset * 2); - break; - case WMFW_ADSP1_ZM: - region_name = "ZM"; - reg = zm + (offset * 2); - break; - default: - dev_warn(codec->dev, - "%s.%d: Unknown region type %x at %d(%x)\n", - file, regions, type, pos, pos); - break; - } - - dev_dbg(codec->dev, "%s.%d: %d bytes at %d in %s\n", file, - regions, le32_to_cpu(region->len), offset, - region_name); - - if (text) { - memcpy(text, region->data, le32_to_cpu(region->len)); - dev_info(codec->dev, "%s: %s\n", file, text); - kfree(text); - } - - if (reg) { - ret = regmap_raw_write(regmap, reg, region->data, - le32_to_cpu(region->len)); - if (ret != 0) { - dev_err(codec->dev, - "%s.%d: Failed to write %d bytes at %d in %s: %d\n", - file, regions, - le32_to_cpu(region->len), offset, - region_name, ret); - goto out; - } - } - - pos += le32_to_cpu(region->len) + sizeof(*region); - regions++; - } - - if (pos > firmware->size) - dev_warn(codec->dev, "%s.%d: %zu bytes at end of file\n", - file, regions, pos - firmware->size); - -out: - release_firmware(firmware); - - return ret; -} - -static int wm2200_setup_algs(struct snd_soc_codec *codec, int base) -{ - struct regmap *regmap = codec->control_data; - struct wmfw_adsp1_id_hdr id; - struct wmfw_adsp1_alg_hdr *alg; - size_t algs; - int zm, dm, pm, ret, i; - __be32 val; - - switch (base) { - case WM2200_DSP1_CONTROL_1: - dm = WM2200_DSP1_DM_BASE; - pm = WM2200_DSP1_PM_BASE; - zm = WM2200_DSP1_ZM_BASE; - break; - case WM2200_DSP2_CONTROL_1: - dm = WM2200_DSP2_DM_BASE; - pm = WM2200_DSP2_PM_BASE; - zm = WM2200_DSP2_ZM_BASE; - break; - default: - dev_err(codec->dev, "BASE %x\n", base); - BUG_ON(1); - return -EINVAL; - } - - ret = regmap_raw_read(regmap, dm, &id, sizeof(id)); - if (ret != 0) { - dev_err(codec->dev, "Failed to read algorithm info: %d\n", - ret); - return ret; - } - - algs = be32_to_cpu(id.algs); - dev_info(codec->dev, "Firmware: %x v%d.%d.%d, %zu algorithms\n", - be32_to_cpu(id.fw.id), - (be32_to_cpu(id.fw.ver) & 0xff000) >> 16, - (be32_to_cpu(id.fw.ver) & 0xff00) >> 8, - be32_to_cpu(id.fw.ver) & 0xff, - algs); - - /* Read the terminator first to validate the length */ - ret = regmap_raw_read(regmap, dm + - (sizeof(id) + (algs * sizeof(*alg))) / 2, - &val, sizeof(val)); - if (ret != 0) { - dev_err(codec->dev, "Failed to read algorithm list end: %d\n", - ret); - return ret; - } - - if (be32_to_cpu(val) != 0xbedead) - dev_warn(codec->dev, "Algorithm list end %zx 0x%x != 0xbeadead\n", - (sizeof(id) + (algs * sizeof(*alg))) / 2, - be32_to_cpu(val)); - - alg = kzalloc(sizeof(*alg) * algs, GFP_KERNEL); - if (!alg) - return -ENOMEM; - - ret = regmap_raw_read(regmap, dm + (sizeof(id) / 2), - alg, algs * sizeof(*alg)); - if (ret != 0) { - dev_err(codec->dev, "Failed to read algorithm list: %d\n", - ret); - goto out; - } - - for (i = 0; i < algs; i++) { - dev_info(codec->dev, "%d: ID %x v%d.%d.%d\n", - i, be32_to_cpu(alg[i].alg.id), - (be32_to_cpu(alg[i].alg.ver) & 0xff000) >> 16, - (be32_to_cpu(alg[i].alg.ver) & 0xff00) >> 8, - be32_to_cpu(alg[i].alg.ver) & 0xff); - } - -out: - kfree(alg); - return ret; -} - -static int wm2200_load_coeff(struct snd_soc_codec *codec, int base) -{ - struct regmap *regmap = codec->control_data; - struct wmfw_coeff_hdr *hdr; - struct wmfw_coeff_item *blk; - const struct firmware *firmware; - const char *file, *region_name; - int ret, dm, pm, zm, pos, blocks, type, offset, reg; - - switch (base) { - case WM2200_DSP1_CONTROL_1: - file = "wm2200-dsp1.bin"; - dm = WM2200_DSP1_DM_BASE; - pm = WM2200_DSP1_PM_BASE; - zm = WM2200_DSP1_ZM_BASE; - break; - case WM2200_DSP2_CONTROL_1: - file = "wm2200-dsp2.bin"; - dm = WM2200_DSP2_DM_BASE; - pm = WM2200_DSP2_PM_BASE; - zm = WM2200_DSP2_ZM_BASE; - break; - default: - dev_err(codec->dev, "BASE %x\n", base); - BUG_ON(1); - return -EINVAL; - } - - ret = request_firmware(&firmware, file, codec->dev); - if (ret != 0) { - dev_err(codec->dev, "Failed to request '%s'\n", file); - return ret; - } - - if (sizeof(*hdr) >= firmware->size) { - dev_err(codec->dev, "%s: file too short, %zu bytes\n", - file, firmware->size); - return -EINVAL; - } - - hdr = (void*)&firmware->data[0]; - if (memcmp(hdr->magic, "WMDR", 4) != 0) { - dev_err(codec->dev, "%s: invalid magic\n", file); - return -EINVAL; - } - - dev_dbg(codec->dev, "%s: v%d.%d.%d\n", file, - (le32_to_cpu(hdr->ver) >> 16) & 0xff, - (le32_to_cpu(hdr->ver) >> 8) & 0xff, - le32_to_cpu(hdr->ver) & 0xff); - - pos = le32_to_cpu(hdr->len); - - blocks = 0; - while (pos < firmware->size && - pos - firmware->size > sizeof(*blk)) { - blk = (void*)(&firmware->data[pos]); - - type = be32_to_cpu(blk->type) & 0xff; - offset = le32_to_cpu(blk->offset) & 0xffffff; - - dev_dbg(codec->dev, "%s.%d: %x v%d.%d.%d\n", - file, blocks, le32_to_cpu(blk->id), - (le32_to_cpu(blk->ver) >> 16) & 0xff, - (le32_to_cpu(blk->ver) >> 8) & 0xff, - le32_to_cpu(blk->ver) & 0xff); - dev_dbg(codec->dev, "%s.%d: %d bytes at 0x%x in %x\n", - file, blocks, le32_to_cpu(blk->len), offset, type); - - reg = 0; - region_name = "Unknown"; - switch (type) { - case WMFW_NAME_TEXT: - case WMFW_INFO_TEXT: - break; - case WMFW_ABSOLUTE: - region_name = "register"; - reg = offset; - break; - default: - dev_err(codec->dev, "Unknown region type %x\n", type); - break; - } - - if (reg) { - ret = regmap_raw_write(regmap, reg, blk->data, - le32_to_cpu(blk->len)); - if (ret != 0) { - dev_err(codec->dev, - "%s.%d: Failed to write to %x in %s\n", - file, blocks, reg, region_name); - } - } - - pos += le32_to_cpu(blk->len) + sizeof(*blk); - blocks++; - } - - if (pos > firmware->size) - dev_warn(codec->dev, "%s.%d: %zu bytes at end of file\n", - file, blocks, pos - firmware->size); - - return 0; -} - -static int wm2200_dsp_ev(struct snd_soc_dapm_widget *w, - struct snd_kcontrol *kcontrol, - int event) -{ - struct snd_soc_codec *codec = w->codec; - int base = w->reg - WM2200_DSP_CONTROL_30; - int ret; - - switch (event) { - case SND_SOC_DAPM_POST_PMU: - ret = wm2200_dsp_load(codec, base); - if (ret != 0) - return ret; - - ret = wm2200_setup_algs(codec, base); - if (ret != 0) - return ret; - - ret = wm2200_load_coeff(codec, base); - if (ret != 0) - return ret; - - /* Start the core running */ - snd_soc_update_bits(codec, w->reg, - WM2200_DSP1_CORE_ENA | WM2200_DSP1_START, - WM2200_DSP1_CORE_ENA | WM2200_DSP1_START); - break; - - case SND_SOC_DAPM_PRE_PMD: - /* Halt the core */ - snd_soc_update_bits(codec, w->reg, - WM2200_DSP1_CORE_ENA | WM2200_DSP1_START, - 0); - - snd_soc_update_bits(codec, base + WM2200_DSP_CONTROL_19, - WM2200_DSP1_WDMA_BUFFER_LENGTH_MASK, 0); - break; - - default: - break; - } - - return 0; -} - static DECLARE_TLV_DB_SCALE(in_tlv, -6300, 100, 0); static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0); static DECLARE_TLV_DB_SCALE(out_tlv, -6400, 100, 0); @@ -1722,12 +1342,8 @@ SND_SOC_DAPM_PGA("LHPF1", WM2200_HPLPF1_1, WM2200_LHPF1_ENA_SHIFT, 0, SND_SOC_DAPM_PGA("LHPF2", WM2200_HPLPF2_1, WM2200_LHPF2_ENA_SHIFT, 0, NULL, 0), -SND_SOC_DAPM_PGA_E("DSP1", WM2200_DSP1_CONTROL_30, WM2200_DSP1_SYS_ENA_SHIFT, - 0, NULL, 0, wm2200_dsp_ev, - SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), -SND_SOC_DAPM_PGA_E("DSP2", WM2200_DSP2_CONTROL_30, WM2200_DSP2_SYS_ENA_SHIFT, - 0, NULL, 0, wm2200_dsp_ev, - SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), +WM_ADSP1("DSP1", 0), +WM_ADSP1("DSP2", 1), SND_SOC_DAPM_AIF_OUT("AIF1TX1", "Capture", 0, WM2200_AUDIO_IF_1_22, WM2200_AIF1TX1_ENA_SHIFT, 0), @@ -2592,6 +2208,22 @@ static __devinit int wm2200_i2c_probe(struct i2c_client *i2c, goto err; } + for (i = 0; i < 2; i++) { + wm2200->dsp[i].type = WMFW_ADSP1; + wm2200->dsp[i].part = "wm2200"; + wm2200->dsp[i].num = i + 1; + wm2200->dsp[i].dev = &i2c->dev; + wm2200->dsp[i].regmap = wm2200->regmap; + } + + wm2200->dsp[0].base = WM2200_DSP1_CONTROL_1; + wm2200->dsp[0].mem = wm2200_dsp1_regions; + wm2200->dsp[0].num_mems = ARRAY_SIZE(wm2200_dsp1_regions); + + wm2200->dsp[1].base = WM2200_DSP2_CONTROL_1; + wm2200->dsp[1].mem = wm2200_dsp2_regions; + wm2200->dsp[1].num_mems = ARRAY_SIZE(wm2200_dsp2_regions); + if (pdata) wm2200->pdata = *pdata; From f55ec27f48a833febe8c78453bac55bb14e2cc4a Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Wed, 28 Nov 2012 14:45:25 +0530 Subject: [PATCH 12/12] ASoC: wm2200: Remove empty labels Removed unnecessary labels probably left out of some previous cleanup. Signed-off-by: Sachin Kamat Signed-off-by: Mark Brown --- sound/soc/codecs/wm2200.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/wm2200.c b/sound/soc/codecs/wm2200.c index 1730df83839c..ff45b02a9dff 100644 --- a/sound/soc/codecs/wm2200.c +++ b/sound/soc/codecs/wm2200.c @@ -2205,7 +2205,7 @@ static __devinit int wm2200_i2c_probe(struct i2c_client *i2c, ret = PTR_ERR(wm2200->regmap); dev_err(&i2c->dev, "Failed to allocate register map: %d\n", ret); - goto err; + return ret; } for (i = 0; i < 2; i++) { @@ -2238,7 +2238,7 @@ static __devinit int wm2200_i2c_probe(struct i2c_client *i2c, if (ret != 0) { dev_err(&i2c->dev, "Failed to request core supplies: %d\n", ret); - goto err_regmap; + return ret; } ret = regulator_bulk_enable(ARRAY_SIZE(wm2200->core_supplies), @@ -2246,7 +2246,7 @@ static __devinit int wm2200_i2c_probe(struct i2c_client *i2c, if (ret != 0) { dev_err(&i2c->dev, "Failed to enable core supplies: %d\n", ret); - goto err_core; + return ret; } if (wm2200->pdata.ldo_ena) { @@ -2382,9 +2382,6 @@ static __devinit int wm2200_i2c_probe(struct i2c_client *i2c, err_enable: regulator_bulk_disable(ARRAY_SIZE(wm2200->core_supplies), wm2200->core_supplies); -err_core: -err_regmap: -err: return ret; }