Commit 9586c959bfc917695893bef0102433a7d0675691

Authored by Linus Torvalds

Merge tag 'regmap-3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap

Pull regmap updates from Mark Brown:
 "Things are really quieting down with the regmap API, while we're still
  seeing a trickle of new features coming in they're getting much
  smaller than they were.  It's also nice to have some features which
  support other subsystems building infrastructure on top of regmap.
  Highlights include:

  - Support for padding between the register and the value when
    interacting with the device, sometimes needed for fast interfaces.
  - Support for applying register updates to the device when restoring
    the register state.  This is intended to be used to apply updates
    supplied by manufacturers for tuning the performance of the device
    (many of which are to undocumented registers which aren't otherwise
    covered).
  - Support for multi-register operations on cached registers.
  - Support for syncing only part of the register cache.
  - Stubs and parameter query functions intended to make it easier for
    other subsystems to build infrastructure on top of the regmap API.

  plus a few driver updates making use of the new features which it was
  easier to merge via this tree."

* tag 'regmap-3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap: (41 commits)
  regmap: Fix future missing prototype of devres_alloc() and friends
  regmap: Rejig struct declarations for stubbed API
  regmap: Fix rbtree block base in sync
  regcache: Make sure we sync register 0 in an rbtree cache
  regmap: delete unused module.h from drivers/base/regmap files
  regmap: Add stub for regcache_sync_region()
  mfd: Improve performance of later WM1811 revisions
  regmap: Fix x86_64 breakage
  regmap: Allow drivers to sync only part of the register cache
  regmap: Supply ranges to the sync operations
  regmap: Add tracepoints for cache only and cache bypass
  regmap: Mark the cache as clean after a successful sync
  regmap: Remove default cache sync implementation
  regmap: Skip hardware defaults for LZO caches
  regmap: Expose the driver name in debugfs
  mfd: wm8400: Convert to devm_regmap_init_i2c()
  mfd: wm831x: Convert to devm_regmap_init()
  mfd: wm8994: Convert to devm_regmap_init()
  mfd/ASoC: Convert WM8994 driver to use regmap patches
  mfd: Add __devinit and __devexit annotations in wm8994
  ...

Showing 16 changed files Side-by-side Diff

drivers/base/regmap/internal.h
... ... @@ -22,6 +22,7 @@
22 22 struct regmap_format {
23 23 size_t buf_size;
24 24 size_t reg_bytes;
  25 + size_t pad_bytes;
25 26 size_t val_bytes;
26 27 void (*format_write)(struct regmap *map,
27 28 unsigned int reg, unsigned int val);
28 29  
29 30  
30 31  
... ... @@ -65,16 +66,16 @@
65 66 unsigned int num_reg_defaults_raw;
66 67  
67 68 /* if set, only the cache is modified not the HW */
68   - unsigned int cache_only:1;
  69 + u32 cache_only;
69 70 /* if set, only the HW is modified not the cache */
70   - unsigned int cache_bypass:1;
  71 + u32 cache_bypass;
71 72 /* if set, remember to free reg_defaults_raw */
72   - unsigned int cache_free:1;
  73 + bool cache_free;
73 74  
74 75 struct reg_default *reg_defaults;
75 76 const void *reg_defaults_raw;
76 77 void *cache;
77   - bool cache_dirty;
  78 + u32 cache_dirty;
78 79  
79 80 struct reg_default *patch;
80 81 int patch_regs;
... ... @@ -87,7 +88,7 @@
87 88 int (*exit)(struct regmap *map);
88 89 int (*read)(struct regmap *map, unsigned int reg, unsigned int *value);
89 90 int (*write)(struct regmap *map, unsigned int reg, unsigned int value);
90   - int (*sync)(struct regmap *map);
  91 + int (*sync)(struct regmap *map, unsigned int min, unsigned int max);
91 92 };
92 93  
93 94 bool regmap_writeable(struct regmap *map, unsigned int reg);
drivers/base/regmap/regcache-lzo.c
... ... @@ -331,7 +331,8 @@
331 331 return ret;
332 332 }
333 333  
334   -static int regcache_lzo_sync(struct regmap *map)
  334 +static int regcache_lzo_sync(struct regmap *map, unsigned int min,
  335 + unsigned int max)
335 336 {
336 337 struct regcache_lzo_ctx **lzo_blocks;
337 338 unsigned int val;
338 339  
... ... @@ -339,10 +340,21 @@
339 340 int ret;
340 341  
341 342 lzo_blocks = map->cache;
342   - for_each_set_bit(i, lzo_blocks[0]->sync_bmp, lzo_blocks[0]->sync_bmp_nbits) {
  343 + i = min;
  344 + for_each_set_bit_cont(i, lzo_blocks[0]->sync_bmp,
  345 + lzo_blocks[0]->sync_bmp_nbits) {
  346 + if (i > max)
  347 + continue;
  348 +
343 349 ret = regcache_read(map, i, &val);
344 350 if (ret)
345 351 return ret;
  352 +
  353 + /* Is this the hardware default? If so skip. */
  354 + ret = regcache_lookup_reg(map, i);
  355 + if (ret > 0 && val == map->reg_defaults[ret].def)
  356 + continue;
  357 +
346 358 map->cache_bypass = 1;
347 359 ret = _regmap_write(map, i, val);
348 360 map->cache_bypass = 0;
drivers/base/regmap/regcache-rbtree.c
... ... @@ -357,7 +357,8 @@
357 357 return 0;
358 358 }
359 359  
360   -static int regcache_rbtree_sync(struct regmap *map)
  360 +static int regcache_rbtree_sync(struct regmap *map, unsigned int min,
  361 + unsigned int max)
361 362 {
362 363 struct regcache_rbtree_ctx *rbtree_ctx;
363 364 struct rb_node *node;
364 365  
365 366  
... ... @@ -365,19 +366,37 @@
365 366 unsigned int regtmp;
366 367 unsigned int val;
367 368 int ret;
368   - int i;
  369 + int i, base, end;
369 370  
370 371 rbtree_ctx = map->cache;
371 372 for (node = rb_first(&rbtree_ctx->root); node; node = rb_next(node)) {
372 373 rbnode = rb_entry(node, struct regcache_rbtree_node, node);
373   - for (i = 0; i < rbnode->blklen; i++) {
  374 +
  375 + if (rbnode->base_reg < min)
  376 + continue;
  377 + if (rbnode->base_reg > max)
  378 + break;
  379 + if (rbnode->base_reg + rbnode->blklen < min)
  380 + continue;
  381 +
  382 + if (min > rbnode->base_reg)
  383 + base = min - rbnode->base_reg;
  384 + else
  385 + base = 0;
  386 +
  387 + if (max < rbnode->base_reg + rbnode->blklen)
  388 + end = rbnode->base_reg + rbnode->blklen - max;
  389 + else
  390 + end = rbnode->blklen;
  391 +
  392 + for (i = base; i < end; i++) {
374 393 regtmp = rbnode->base_reg + i;
375 394 val = regcache_rbtree_get_register(rbnode, i,
376 395 map->cache_word_size);
377 396  
378 397 /* Is this the hardware default? If so skip. */
379 398 ret = regcache_lookup_reg(map, i);
380   - if (ret > 0 && val == map->reg_defaults[ret].def)
  399 + if (ret >= 0 && val == map->reg_defaults[ret].def)
381 400 continue;
382 401  
383 402 map->cache_bypass = 1;
drivers/base/regmap/regcache.c
... ... @@ -35,12 +35,17 @@
35 35 return -EINVAL;
36 36  
37 37 if (!map->reg_defaults_raw) {
  38 + u32 cache_bypass = map->cache_bypass;
38 39 dev_warn(map->dev, "No cache defaults, reading back from HW\n");
  40 +
  41 + /* Bypass the cache access till data read from HW*/
  42 + map->cache_bypass = 1;
39 43 tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL);
40 44 if (!tmp_buf)
41 45 return -EINVAL;
42 46 ret = regmap_bulk_read(map, 0, tmp_buf,
43 47 map->num_reg_defaults_raw);
  48 + map->cache_bypass = cache_bypass;
44 49 if (ret < 0) {
45 50 kfree(tmp_buf);
46 51 return ret;
... ... @@ -211,7 +216,6 @@
211 216  
212 217 return -EINVAL;
213 218 }
214   -EXPORT_SYMBOL_GPL(regcache_read);
215 219  
216 220 /**
217 221 * regcache_write: Set the value of a given register in the cache.
... ... @@ -238,7 +242,6 @@
238 242  
239 243 return 0;
240 244 }
241   -EXPORT_SYMBOL_GPL(regcache_write);
242 245  
243 246 /**
244 247 * regcache_sync: Sync the register cache with the hardware.
245 248  
... ... @@ -254,12 +257,11 @@
254 257 int regcache_sync(struct regmap *map)
255 258 {
256 259 int ret = 0;
257   - unsigned int val;
258 260 unsigned int i;
259 261 const char *name;
260 262 unsigned int bypass;
261 263  
262   - BUG_ON(!map->cache_ops);
  264 + BUG_ON(!map->cache_ops || !map->cache_ops->sync);
263 265  
264 266 mutex_lock(&map->lock);
265 267 /* Remember the initial bypass state */
266 268  
... ... @@ -269,7 +271,11 @@
269 271 name = map->cache_ops->name;
270 272 trace_regcache_sync(map->dev, name, "start");
271 273  
  274 + if (!map->cache_dirty)
  275 + goto out;
  276 +
272 277 /* Apply any patch first */
  278 + map->cache_bypass = 1;
273 279 for (i = 0; i < map->patch_regs; i++) {
274 280 ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def);
275 281 if (ret != 0) {
276 282  
277 283  
... ... @@ -278,27 +284,13 @@
278 284 goto out;
279 285 }
280 286 }
  287 + map->cache_bypass = 0;
281 288  
282   - if (!map->cache_dirty)
283   - goto out;
284   - if (map->cache_ops->sync) {
285   - ret = map->cache_ops->sync(map);
286   - } else {
287   - for (i = 0; i < map->num_reg_defaults; i++) {
288   - ret = regcache_read(map, i, &val);
289   - if (ret < 0)
290   - goto out;
291   - map->cache_bypass = 1;
292   - ret = _regmap_write(map, i, val);
293   - map->cache_bypass = 0;
294   - if (ret < 0)
295   - goto out;
296   - dev_dbg(map->dev, "Synced register %#x, value %#x\n",
297   - map->reg_defaults[i].reg,
298   - map->reg_defaults[i].def);
299   - }
  289 + ret = map->cache_ops->sync(map, 0, map->max_register);
300 290  
301   - }
  291 + if (ret == 0)
  292 + map->cache_dirty = false;
  293 +
302 294 out:
303 295 trace_regcache_sync(map->dev, name, "stop");
304 296 /* Restore the bypass state */
... ... @@ -310,6 +302,51 @@
310 302 EXPORT_SYMBOL_GPL(regcache_sync);
311 303  
312 304 /**
  305 + * regcache_sync_region: Sync part of the register cache with the hardware.
  306 + *
  307 + * @map: map to sync.
  308 + * @min: first register to sync
  309 + * @max: last register to sync
  310 + *
  311 + * Write all non-default register values in the specified region to
  312 + * the hardware.
  313 + *
  314 + * Return a negative value on failure, 0 on success.
  315 + */
  316 +int regcache_sync_region(struct regmap *map, unsigned int min,
  317 + unsigned int max)
  318 +{
  319 + int ret = 0;
  320 + const char *name;
  321 + unsigned int bypass;
  322 +
  323 + BUG_ON(!map->cache_ops || !map->cache_ops->sync);
  324 +
  325 + mutex_lock(&map->lock);
  326 +
  327 + /* Remember the initial bypass state */
  328 + bypass = map->cache_bypass;
  329 +
  330 + name = map->cache_ops->name;
  331 + dev_dbg(map->dev, "Syncing %s cache from %d-%d\n", name, min, max);
  332 +
  333 + trace_regcache_sync(map->dev, name, "start region");
  334 +
  335 + if (!map->cache_dirty)
  336 + goto out;
  337 +
  338 + ret = map->cache_ops->sync(map, min, max);
  339 +
  340 +out:
  341 + trace_regcache_sync(map->dev, name, "stop region");
  342 + /* Restore the bypass state */
  343 + map->cache_bypass = bypass;
  344 + mutex_unlock(&map->lock);
  345 +
  346 + return ret;
  347 +}
  348 +
  349 +/**
313 350 * regcache_cache_only: Put a register map into cache only mode
314 351 *
315 352 * @map: map to configure
... ... @@ -326,6 +363,7 @@
326 363 mutex_lock(&map->lock);
327 364 WARN_ON(map->cache_bypass && enable);
328 365 map->cache_only = enable;
  366 + trace_regmap_cache_only(map->dev, enable);
329 367 mutex_unlock(&map->lock);
330 368 }
331 369 EXPORT_SYMBOL_GPL(regcache_cache_only);
... ... @@ -363,6 +401,7 @@
363 401 mutex_lock(&map->lock);
364 402 WARN_ON(map->cache_only && enable);
365 403 map->cache_bypass = enable;
  404 + trace_regmap_cache_bypass(map->dev, enable);
366 405 mutex_unlock(&map->lock);
367 406 }
368 407 EXPORT_SYMBOL_GPL(regcache_cache_bypass);
369 408  
... ... @@ -385,10 +424,16 @@
385 424 cache[idx] = val;
386 425 break;
387 426 }
  427 + case 4: {
  428 + u32 *cache = base;
  429 + if (cache[idx] == val)
  430 + return true;
  431 + cache[idx] = val;
  432 + break;
  433 + }
388 434 default:
389 435 BUG();
390 436 }
391   - /* unreachable */
392 437 return false;
393 438 }
394 439  
... ... @@ -405,6 +450,10 @@
405 450 }
406 451 case 2: {
407 452 const u16 *cache = base;
  453 + return cache[idx];
  454 + }
  455 + case 4: {
  456 + const u32 *cache = base;
408 457 return cache[idx];
409 458 }
410 459 default:
drivers/base/regmap/regmap-debugfs.c
... ... @@ -11,7 +11,6 @@
11 11 */
12 12  
13 13 #include <linux/slab.h>
14   -#include <linux/module.h>
15 14 #include <linux/mutex.h>
16 15 #include <linux/debugfs.h>
17 16 #include <linux/uaccess.h>
... ... @@ -33,6 +32,35 @@
33 32 return 0;
34 33 }
35 34  
  35 +static ssize_t regmap_name_read_file(struct file *file,
  36 + char __user *user_buf, size_t count,
  37 + loff_t *ppos)
  38 +{
  39 + struct regmap *map = file->private_data;
  40 + int ret;
  41 + char *buf;
  42 +
  43 + buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  44 + if (!buf)
  45 + return -ENOMEM;
  46 +
  47 + ret = snprintf(buf, PAGE_SIZE, "%s\n", map->dev->driver->name);
  48 + if (ret < 0) {
  49 + kfree(buf);
  50 + return ret;
  51 + }
  52 +
  53 + ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  54 + kfree(buf);
  55 + return ret;
  56 +}
  57 +
  58 +static const struct file_operations regmap_name_fops = {
  59 + .open = regmap_open_file,
  60 + .read = regmap_name_read_file,
  61 + .llseek = default_llseek,
  62 +};
  63 +
36 64 static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
37 65 size_t count, loff_t *ppos)
38 66 {
39 67  
... ... @@ -103,9 +131,51 @@
103 131 return ret;
104 132 }
105 133  
  134 +#undef REGMAP_ALLOW_WRITE_DEBUGFS
  135 +#ifdef REGMAP_ALLOW_WRITE_DEBUGFS
  136 +/*
  137 + * This can be dangerous especially when we have clients such as
  138 + * PMICs, therefore don't provide any real compile time configuration option
  139 + * for this feature, people who want to use this will need to modify
  140 + * the source code directly.
  141 + */
  142 +static ssize_t regmap_map_write_file(struct file *file,
  143 + const char __user *user_buf,
  144 + size_t count, loff_t *ppos)
  145 +{
  146 + char buf[32];
  147 + size_t buf_size;
  148 + char *start = buf;
  149 + unsigned long reg, value;
  150 + struct regmap *map = file->private_data;
  151 +
  152 + buf_size = min(count, (sizeof(buf)-1));
  153 + if (copy_from_user(buf, user_buf, buf_size))
  154 + return -EFAULT;
  155 + buf[buf_size] = 0;
  156 +
  157 + while (*start == ' ')
  158 + start++;
  159 + reg = simple_strtoul(start, &start, 16);
  160 + while (*start == ' ')
  161 + start++;
  162 + if (strict_strtoul(start, 16, &value))
  163 + return -EINVAL;
  164 +
  165 + /* Userspace has been fiddling around behind the kernel's back */
  166 + add_taint(TAINT_USER);
  167 +
  168 + regmap_write(map, reg, value);
  169 + return buf_size;
  170 +}
  171 +#else
  172 +#define regmap_map_write_file NULL
  173 +#endif
  174 +
106 175 static const struct file_operations regmap_map_fops = {
107 176 .open = regmap_open_file,
108 177 .read = regmap_map_read_file,
  178 + .write = regmap_map_write_file,
109 179 .llseek = default_llseek,
110 180 };
111 181  
112 182  
... ... @@ -186,11 +256,23 @@
186 256 return;
187 257 }
188 258  
  259 + debugfs_create_file("name", 0400, map->debugfs,
  260 + map, &regmap_name_fops);
  261 +
189 262 if (map->max_register) {
190 263 debugfs_create_file("registers", 0400, map->debugfs,
191 264 map, &regmap_map_fops);
192 265 debugfs_create_file("access", 0400, map->debugfs,
193 266 map, &regmap_access_fops);
  267 + }
  268 +
  269 + if (map->cache_type) {
  270 + debugfs_create_bool("cache_only", 0400, map->debugfs,
  271 + &map->cache_only);
  272 + debugfs_create_bool("cache_dirty", 0400, map->debugfs,
  273 + &map->cache_dirty);
  274 + debugfs_create_bool("cache_bypass", 0400, map->debugfs,
  275 + &map->cache_bypass);
194 276 }
195 277 }
196 278  
drivers/base/regmap/regmap-i2c.c
... ... @@ -111,5 +111,22 @@
111 111 }
112 112 EXPORT_SYMBOL_GPL(regmap_init_i2c);
113 113  
  114 +/**
  115 + * devm_regmap_init_i2c(): Initialise managed register map
  116 + *
  117 + * @i2c: Device that will be interacted with
  118 + * @config: Configuration for register map
  119 + *
  120 + * The return value will be an ERR_PTR() on error or a valid pointer
  121 + * to a struct regmap. The regmap will be automatically freed by the
  122 + * device management code.
  123 + */
  124 +struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c,
  125 + const struct regmap_config *config)
  126 +{
  127 + return devm_regmap_init(&i2c->dev, &regmap_i2c, config);
  128 +}
  129 +EXPORT_SYMBOL_GPL(devm_regmap_init_i2c);
  130 +
114 131 MODULE_LICENSE("GPL");
drivers/base/regmap/regmap-spi.c
... ... @@ -70,5 +70,22 @@
70 70 }
71 71 EXPORT_SYMBOL_GPL(regmap_init_spi);
72 72  
  73 +/**
  74 + * devm_regmap_init_spi(): Initialise register map
  75 + *
  76 + * @spi: Device that will be interacted with
  77 + * @config: Configuration for register map
  78 + *
  79 + * The return value will be an ERR_PTR() on error or a valid pointer
  80 + * to a struct regmap. The map will be automatically freed by the
  81 + * device management code.
  82 + */
  83 +struct regmap *devm_regmap_init_spi(struct spi_device *spi,
  84 + const struct regmap_config *config)
  85 +{
  86 + return devm_regmap_init(&spi->dev, &regmap_spi, config);
  87 +}
  88 +EXPORT_SYMBOL_GPL(devm_regmap_init_spi);
  89 +
73 90 MODULE_LICENSE("GPL");
drivers/base/regmap/regmap.c
... ... @@ -10,8 +10,9 @@
10 10 * published by the Free Software Foundation.
11 11 */
12 12  
  13 +#include <linux/device.h>
13 14 #include <linux/slab.h>
14   -#include <linux/module.h>
  15 +#include <linux/export.h>
15 16 #include <linux/mutex.h>
16 17 #include <linux/err.h>
17 18  
... ... @@ -36,6 +37,9 @@
36 37 if (map->max_register && reg > map->max_register)
37 38 return false;
38 39  
  40 + if (map->format.format_write)
  41 + return false;
  42 +
39 43 if (map->readable_reg)
40 44 return map->readable_reg(map->dev, reg);
41 45  
... ... @@ -44,7 +48,7 @@
44 48  
45 49 bool regmap_volatile(struct regmap *map, unsigned int reg)
46 50 {
47   - if (map->max_register && reg > map->max_register)
  51 + if (!regmap_readable(map, reg))
48 52 return false;
49 53  
50 54 if (map->volatile_reg)
... ... @@ -55,7 +59,7 @@
55 59  
56 60 bool regmap_precious(struct regmap *map, unsigned int reg)
57 61 {
58   - if (map->max_register && reg > map->max_register)
  62 + if (!regmap_readable(map, reg))
59 63 return false;
60 64  
61 65 if (map->precious_reg)
... ... @@ -76,6 +80,14 @@
76 80 return true;
77 81 }
78 82  
  83 +static void regmap_format_2_6_write(struct regmap *map,
  84 + unsigned int reg, unsigned int val)
  85 +{
  86 + u8 *out = map->work_buf;
  87 +
  88 + *out = (reg << 6) | val;
  89 +}
  90 +
79 91 static void regmap_format_4_12_write(struct regmap *map,
80 92 unsigned int reg, unsigned int val)
81 93 {
... ... @@ -114,6 +126,13 @@
114 126 b[0] = cpu_to_be16(val);
115 127 }
116 128  
  129 +static void regmap_format_32(void *buf, unsigned int val)
  130 +{
  131 + __be32 *b = buf;
  132 +
  133 + b[0] = cpu_to_be32(val);
  134 +}
  135 +
117 136 static unsigned int regmap_parse_8(void *buf)
118 137 {
119 138 u8 *b = buf;
... ... @@ -130,6 +149,15 @@
130 149 return b[0];
131 150 }
132 151  
  152 +static unsigned int regmap_parse_32(void *buf)
  153 +{
  154 + __be32 *b = buf;
  155 +
  156 + b[0] = be32_to_cpu(b[0]);
  157 +
  158 + return b[0];
  159 +}
  160 +
133 161 /**
134 162 * regmap_init(): Initialise register map
135 163 *
... ... @@ -159,8 +187,10 @@
159 187  
160 188 mutex_init(&map->lock);
161 189 map->format.buf_size = (config->reg_bits + config->val_bits) / 8;
162   - map->format.reg_bytes = config->reg_bits / 8;
163   - map->format.val_bytes = config->val_bits / 8;
  190 + map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
  191 + map->format.pad_bytes = config->pad_bits / 8;
  192 + map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
  193 + map->format.buf_size += map->format.pad_bytes;
164 194 map->dev = dev;
165 195 map->bus = bus;
166 196 map->max_register = config->max_register;
... ... @@ -178,6 +208,16 @@
178 208 }
179 209  
180 210 switch (config->reg_bits) {
  211 + case 2:
  212 + switch (config->val_bits) {
  213 + case 6:
  214 + map->format.format_write = regmap_format_2_6_write;
  215 + break;
  216 + default:
  217 + goto err_map;
  218 + }
  219 + break;
  220 +
181 221 case 4:
182 222 switch (config->val_bits) {
183 223 case 12:
... ... @@ -216,6 +256,10 @@
216 256 map->format.format_reg = regmap_format_16;
217 257 break;
218 258  
  259 + case 32:
  260 + map->format.format_reg = regmap_format_32;
  261 + break;
  262 +
219 263 default:
220 264 goto err_map;
221 265 }
222 266  
... ... @@ -229,13 +273,17 @@
229 273 map->format.format_val = regmap_format_16;
230 274 map->format.parse_val = regmap_parse_16;
231 275 break;
  276 + case 32:
  277 + map->format.format_val = regmap_format_32;
  278 + map->format.parse_val = regmap_parse_32;
  279 + break;
232 280 }
233 281  
234 282 if (!map->format.format_write &&
235 283 !(map->format.format_reg && map->format.format_val))
236 284 goto err_map;
237 285  
238   - map->work_buf = kmalloc(map->format.buf_size, GFP_KERNEL);
  286 + map->work_buf = kzalloc(map->format.buf_size, GFP_KERNEL);
239 287 if (map->work_buf == NULL) {
240 288 ret = -ENOMEM;
241 289 goto err_map;
242 290  
... ... @@ -258,7 +306,46 @@
258 306 }
259 307 EXPORT_SYMBOL_GPL(regmap_init);
260 308  
  309 +static void devm_regmap_release(struct device *dev, void *res)
  310 +{
  311 + regmap_exit(*(struct regmap **)res);
  312 +}
  313 +
261 314 /**
  315 + * devm_regmap_init(): Initialise managed register map
  316 + *
  317 + * @dev: Device that will be interacted with
  318 + * @bus: Bus-specific callbacks to use with device
  319 + * @config: Configuration for register map
  320 + *
  321 + * The return value will be an ERR_PTR() on error or a valid pointer
  322 + * to a struct regmap. This function should generally not be called
  323 + * directly, it should be called by bus-specific init functions. The
  324 + * map will be automatically freed by the device management code.
  325 + */
  326 +struct regmap *devm_regmap_init(struct device *dev,
  327 + const struct regmap_bus *bus,
  328 + const struct regmap_config *config)
  329 +{
  330 + struct regmap **ptr, *regmap;
  331 +
  332 + ptr = devres_alloc(devm_regmap_release, sizeof(*ptr), GFP_KERNEL);
  333 + if (!ptr)
  334 + return ERR_PTR(-ENOMEM);
  335 +
  336 + regmap = regmap_init(dev, bus, config);
  337 + if (!IS_ERR(regmap)) {
  338 + *ptr = regmap;
  339 + devres_add(dev, ptr);
  340 + } else {
  341 + devres_free(ptr);
  342 + }
  343 +
  344 + return regmap;
  345 +}
  346 +EXPORT_SYMBOL_GPL(devm_regmap_init);
  347 +
  348 +/**
262 349 * regmap_reinit_cache(): Reinitialise the current register cache
263 350 *
264 351 * @map: Register map to operate on.
... ... @@ -276,6 +363,7 @@
276 363 mutex_lock(&map->lock);
277 364  
278 365 regcache_exit(map);
  366 + regmap_debugfs_exit(map);
279 367  
280 368 map->max_register = config->max_register;
281 369 map->writeable_reg = config->writeable_reg;
... ... @@ -284,6 +372,8 @@
284 372 map->precious_reg = config->precious_reg;
285 373 map->cache_type = config->cache_type;
286 374  
  375 + regmap_debugfs_init(map);
  376 +
287 377 map->cache_bypass = false;
288 378 map->cache_only = false;
289 379  
... ... @@ -321,6 +411,26 @@
321 411 if (!map->writeable_reg(map->dev, reg + i))
322 412 return -EINVAL;
323 413  
  414 + if (!map->cache_bypass && map->format.parse_val) {
  415 + unsigned int ival;
  416 + int val_bytes = map->format.val_bytes;
  417 + for (i = 0; i < val_len / val_bytes; i++) {
  418 + memcpy(map->work_buf, val + (i * val_bytes), val_bytes);
  419 + ival = map->format.parse_val(map->work_buf);
  420 + ret = regcache_write(map, reg + i, ival);
  421 + if (ret) {
  422 + dev_err(map->dev,
  423 + "Error in caching of register: %u ret: %d\n",
  424 + reg + i, ret);
  425 + return ret;
  426 + }
  427 + }
  428 + if (map->cache_only) {
  429 + map->cache_dirty = true;
  430 + return 0;
  431 + }
  432 + }
  433 +
324 434 map->format.format_reg(map->work_buf, reg);
325 435  
326 436 u8[0] |= map->write_flag_mask;
327 437  
328 438  
329 439  
330 440  
... ... @@ -332,23 +442,28 @@
332 442 * send the work_buf directly, otherwise try to do a gather
333 443 * write.
334 444 */
335   - if (val == map->work_buf + map->format.reg_bytes)
  445 + if (val == (map->work_buf + map->format.pad_bytes +
  446 + map->format.reg_bytes))
336 447 ret = map->bus->write(map->dev, map->work_buf,
337   - map->format.reg_bytes + val_len);
  448 + map->format.reg_bytes +
  449 + map->format.pad_bytes +
  450 + val_len);
338 451 else if (map->bus->gather_write)
339 452 ret = map->bus->gather_write(map->dev, map->work_buf,
340   - map->format.reg_bytes,
  453 + map->format.reg_bytes +
  454 + map->format.pad_bytes,
341 455 val, val_len);
342 456  
343 457 /* If that didn't work fall back on linearising by hand. */
344 458 if (ret == -ENOTSUPP) {
345   - len = map->format.reg_bytes + val_len;
346   - buf = kmalloc(len, GFP_KERNEL);
  459 + len = map->format.reg_bytes + map->format.pad_bytes + val_len;
  460 + buf = kzalloc(len, GFP_KERNEL);
347 461 if (!buf)
348 462 return -ENOMEM;
349 463  
350 464 memcpy(buf, map->work_buf, map->format.reg_bytes);
351   - memcpy(buf + map->format.reg_bytes, val, val_len);
  465 + memcpy(buf + map->format.reg_bytes + map->format.pad_bytes,
  466 + val, val_len);
352 467 ret = map->bus->write(map->dev, buf, len);
353 468  
354 469 kfree(buf);
... ... @@ -366,7 +481,7 @@
366 481 int ret;
367 482 BUG_ON(!map->format.format_write && !map->format.format_val);
368 483  
369   - if (!map->cache_bypass) {
  484 + if (!map->cache_bypass && map->format.format_write) {
370 485 ret = regcache_write(map, reg, val);
371 486 if (ret != 0)
372 487 return ret;
373 488  
... ... @@ -390,10 +505,12 @@
390 505  
391 506 return ret;
392 507 } else {
393   - map->format.format_val(map->work_buf + map->format.reg_bytes,
394   - val);
  508 + map->format.format_val(map->work_buf + map->format.reg_bytes
  509 + + map->format.pad_bytes, val);
395 510 return _regmap_raw_write(map, reg,
396   - map->work_buf + map->format.reg_bytes,
  511 + map->work_buf +
  512 + map->format.reg_bytes +
  513 + map->format.pad_bytes,
397 514 map->format.val_bytes);
398 515 }
399 516 }
400 517  
... ... @@ -441,12 +558,8 @@
441 558 int regmap_raw_write(struct regmap *map, unsigned int reg,
442 559 const void *val, size_t val_len)
443 560 {
444   - size_t val_count = val_len / map->format.val_bytes;
445 561 int ret;
446 562  
447   - WARN_ON(!regmap_volatile_range(map, reg, val_count) &&
448   - map->cache_type != REGCACHE_NONE);
449   -
450 563 mutex_lock(&map->lock);
451 564  
452 565 ret = _regmap_raw_write(map, reg, val, val_len);
... ... @@ -457,6 +570,56 @@
457 570 }
458 571 EXPORT_SYMBOL_GPL(regmap_raw_write);
459 572  
  573 +/*
  574 + * regmap_bulk_write(): Write multiple registers to the device
  575 + *
  576 + * @map: Register map to write to
  577 + * @reg: First register to be write from
  578 + * @val: Block of data to be written, in native register size for device
  579 + * @val_count: Number of registers to write
  580 + *
  581 + * This function is intended to be used for writing a large block of
  582 + * data to be device either in single transfer or multiple transfer.
  583 + *
  584 + * A value of zero will be returned on success, a negative errno will
  585 + * be returned in error cases.
  586 + */
  587 +int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
  588 + size_t val_count)
  589 +{
  590 + int ret = 0, i;
  591 + size_t val_bytes = map->format.val_bytes;
  592 + void *wval;
  593 +
  594 + if (!map->format.parse_val)
  595 + return -EINVAL;
  596 +
  597 + mutex_lock(&map->lock);
  598 +
  599 + /* No formatting is require if val_byte is 1 */
  600 + if (val_bytes == 1) {
  601 + wval = (void *)val;
  602 + } else {
  603 + wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL);
  604 + if (!wval) {
  605 + ret = -ENOMEM;
  606 + dev_err(map->dev, "Error in memory allocation\n");
  607 + goto out;
  608 + }
  609 + for (i = 0; i < val_count * val_bytes; i += val_bytes)
  610 + map->format.parse_val(wval + i);
  611 + }
  612 + ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count);
  613 +
  614 + if (val_bytes != 1)
  615 + kfree(wval);
  616 +
  617 +out:
  618 + mutex_unlock(&map->lock);
  619 + return ret;
  620 +}
  621 +EXPORT_SYMBOL_GPL(regmap_bulk_write);
  622 +
460 623 static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
461 624 unsigned int val_len)
462 625 {
... ... @@ -476,7 +639,8 @@
476 639 trace_regmap_hw_read_start(map->dev, reg,
477 640 val_len / map->format.val_bytes);
478 641  
479   - ret = map->bus->read(map->dev, map->work_buf, map->format.reg_bytes,
  642 + ret = map->bus->read(map->dev, map->work_buf,
  643 + map->format.reg_bytes + map->format.pad_bytes,
480 644 val, val_len);
481 645  
482 646 trace_regmap_hw_read_done(map->dev, reg,
483 647  
484 648  
485 649  
... ... @@ -549,16 +713,32 @@
549 713 int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
550 714 size_t val_len)
551 715 {
552   - size_t val_count = val_len / map->format.val_bytes;
553   - int ret;
  716 + size_t val_bytes = map->format.val_bytes;
  717 + size_t val_count = val_len / val_bytes;
  718 + unsigned int v;
  719 + int ret, i;
554 720  
555   - WARN_ON(!regmap_volatile_range(map, reg, val_count) &&
556   - map->cache_type != REGCACHE_NONE);
557   -
558 721 mutex_lock(&map->lock);
559 722  
560   - ret = _regmap_raw_read(map, reg, val, val_len);
  723 + if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass ||
  724 + map->cache_type == REGCACHE_NONE) {
  725 + /* Physical block read if there's no cache involved */
  726 + ret = _regmap_raw_read(map, reg, val, val_len);
561 727  
  728 + } else {
  729 + /* Otherwise go word by word for the cache; should be low
  730 + * cost as we expect to hit the cache.
  731 + */
  732 + for (i = 0; i < val_count; i++) {
  733 + ret = _regmap_read(map, reg + i, &v);
  734 + if (ret != 0)
  735 + goto out;
  736 +
  737 + map->format.format_val(val + (i * val_bytes), v);
  738 + }
  739 + }
  740 +
  741 + out:
562 742 mutex_unlock(&map->lock);
563 743  
564 744 return ret;
... ... @@ -712,7 +892,7 @@
712 892 }
713 893 }
714 894  
715   - map->patch = kcalloc(sizeof(struct reg_default), num_regs, GFP_KERNEL);
  895 + map->patch = kcalloc(num_regs, sizeof(struct reg_default), GFP_KERNEL);
716 896 if (map->patch != NULL) {
717 897 memcpy(map->patch, regs,
718 898 num_regs * sizeof(struct reg_default));
drivers/mfd/wm831x-core.c
... ... @@ -1631,7 +1631,7 @@
1631 1631 ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID);
1632 1632 if (ret < 0) {
1633 1633 dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret);
1634   - goto err_regmap;
  1634 + goto err;
1635 1635 }
1636 1636 switch (ret) {
1637 1637 case 0x6204:
1638 1638  
1639 1639  
... ... @@ -1640,20 +1640,20 @@
1640 1640 default:
1641 1641 dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret);
1642 1642 ret = -EINVAL;
1643   - goto err_regmap;
  1643 + goto err;
1644 1644 }
1645 1645  
1646 1646 ret = wm831x_reg_read(wm831x, WM831X_REVISION);
1647 1647 if (ret < 0) {
1648 1648 dev_err(wm831x->dev, "Failed to read revision: %d\n", ret);
1649   - goto err_regmap;
  1649 + goto err;
1650 1650 }
1651 1651 rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT;
1652 1652  
1653 1653 ret = wm831x_reg_read(wm831x, WM831X_RESET_ID);
1654 1654 if (ret < 0) {
1655 1655 dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret);
1656   - goto err_regmap;
  1656 + goto err;
1657 1657 }
1658 1658  
1659 1659 /* Some engineering samples do not have the ID set, rely on
... ... @@ -1728,7 +1728,7 @@
1728 1728 default:
1729 1729 dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
1730 1730 ret = -EINVAL;
1731   - goto err_regmap;
  1731 + goto err;
1732 1732 }
1733 1733  
1734 1734 /* This will need revisiting in future but is OK for all
... ... @@ -1742,7 +1742,7 @@
1742 1742 ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
1743 1743 if (ret < 0) {
1744 1744 dev_err(wm831x->dev, "Failed to read security key: %d\n", ret);
1745   - goto err_regmap;
  1745 + goto err;
1746 1746 }
1747 1747 if (ret != 0) {
1748 1748 dev_warn(wm831x->dev, "Security key had non-zero value %x\n",
... ... @@ -1755,7 +1755,7 @@
1755 1755 ret = pdata->pre_init(wm831x);
1756 1756 if (ret != 0) {
1757 1757 dev_err(wm831x->dev, "pre_init() failed: %d\n", ret);
1758   - goto err_regmap;
  1758 + goto err;
1759 1759 }
1760 1760 }
1761 1761  
... ... @@ -1778,7 +1778,7 @@
1778 1778  
1779 1779 ret = wm831x_irq_init(wm831x, irq);
1780 1780 if (ret != 0)
1781   - goto err_regmap;
  1781 + goto err;
1782 1782  
1783 1783 wm831x_auxadc_init(wm831x);
1784 1784  
1785 1785  
... ... @@ -1874,9 +1874,8 @@
1874 1874  
1875 1875 err_irq:
1876 1876 wm831x_irq_exit(wm831x);
1877   -err_regmap:
  1877 +err:
1878 1878 mfd_remove_devices(wm831x->dev);
1879   - regmap_exit(wm831x->regmap);
1880 1879 return ret;
1881 1880 }
1882 1881  
... ... @@ -1887,7 +1886,6 @@
1887 1886 if (wm831x->irq_base)
1888 1887 free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x);
1889 1888 wm831x_irq_exit(wm831x);
1890   - regmap_exit(wm831x->regmap);
1891 1889 }
1892 1890  
1893 1891 int wm831x_device_suspend(struct wm831x *wm831x)
drivers/mfd/wm831x-i2c.c
... ... @@ -37,7 +37,7 @@
37 37 i2c_set_clientdata(i2c, wm831x);
38 38 wm831x->dev = &i2c->dev;
39 39  
40   - wm831x->regmap = regmap_init_i2c(i2c, &wm831x_regmap_config);
  40 + wm831x->regmap = devm_regmap_init_i2c(i2c, &wm831x_regmap_config);
41 41 if (IS_ERR(wm831x->regmap)) {
42 42 ret = PTR_ERR(wm831x->regmap);
43 43 dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
drivers/mfd/wm831x-spi.c
... ... @@ -40,7 +40,7 @@
40 40 dev_set_drvdata(&spi->dev, wm831x);
41 41 wm831x->dev = &spi->dev;
42 42  
43   - wm831x->regmap = regmap_init_spi(spi, &wm831x_regmap_config);
  43 + wm831x->regmap = devm_regmap_init_spi(spi, &wm831x_regmap_config);
44 44 if (IS_ERR(wm831x->regmap)) {
45 45 ret = PTR_ERR(wm831x->regmap);
46 46 dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
drivers/mfd/wm8400-core.c
... ... @@ -350,7 +350,7 @@
350 350 goto err;
351 351 }
352 352  
353   - wm8400->regmap = regmap_init_i2c(i2c, &wm8400_regmap_config);
  353 + wm8400->regmap = devm_regmap_init_i2c(i2c, &wm8400_regmap_config);
354 354 if (IS_ERR(wm8400->regmap)) {
355 355 ret = PTR_ERR(wm8400->regmap);
356 356 goto err;
357 357  
... ... @@ -361,12 +361,10 @@
361 361  
362 362 ret = wm8400_init(wm8400, i2c->dev.platform_data);
363 363 if (ret != 0)
364   - goto map_err;
  364 + goto err;
365 365  
366 366 return 0;
367 367  
368   -map_err:
369   - regmap_exit(wm8400->regmap);
370 368 err:
371 369 return ret;
372 370 }
... ... @@ -376,7 +374,6 @@
376 374 struct wm8400 *wm8400 = i2c_get_clientdata(i2c);
377 375  
378 376 wm8400_release(wm8400);
379   - regmap_exit(wm8400->regmap);
380 377  
381 378 return 0;
382 379 }
drivers/mfd/wm8994-core.c
... ... @@ -359,15 +359,38 @@
359 359 }
360 360 #endif
361 361  
  362 +static const __devinitdata struct reg_default wm8994_revc_patch[] = {
  363 + { 0x102, 0x3 },
  364 + { 0x56, 0x3 },
  365 + { 0x817, 0x0 },
  366 + { 0x102, 0x0 },
  367 +};
  368 +
  369 +static const __devinitdata struct reg_default wm8958_reva_patch[] = {
  370 + { 0x102, 0x3 },
  371 + { 0xcb, 0x81 },
  372 + { 0x817, 0x0 },
  373 + { 0x102, 0x0 },
  374 +};
  375 +
  376 +static const __devinitdata struct reg_default wm1811_reva_patch[] = {
  377 + { 0x102, 0x3 },
  378 + { 0x56, 0x7 },
  379 + { 0x5d, 0x7e },
  380 + { 0x5e, 0x0 },
  381 + { 0x102, 0x0 },
  382 +};
  383 +
362 384 /*
363 385 * Instantiate the generic non-control parts of the device.
364 386 */
365   -static int wm8994_device_init(struct wm8994 *wm8994, int irq)
  387 +static __devinit int wm8994_device_init(struct wm8994 *wm8994, int irq)
366 388 {
367 389 struct wm8994_pdata *pdata = wm8994->dev->platform_data;
368 390 struct regmap_config *regmap_config;
  391 + const struct reg_default *regmap_patch = NULL;
369 392 const char *devname;
370   - int ret, i;
  393 + int ret, i, patch_regs;
371 394 int pulls = 0;
372 395  
373 396 dev_set_drvdata(wm8994->dev, wm8994);
... ... @@ -379,7 +402,7 @@
379 402 NULL, 0);
380 403 if (ret != 0) {
381 404 dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
382   - goto err_regmap;
  405 + goto err;
383 406 }
384 407  
385 408 switch (wm8994->type) {
... ... @@ -394,7 +417,7 @@
394 417 break;
395 418 default:
396 419 BUG();
397   - goto err_regmap;
  420 + goto err;
398 421 }
399 422  
400 423 wm8994->supplies = devm_kzalloc(wm8994->dev,
... ... @@ -402,7 +425,7 @@
402 425 wm8994->num_supplies, GFP_KERNEL);
403 426 if (!wm8994->supplies) {
404 427 ret = -ENOMEM;
405   - goto err_regmap;
  428 + goto err;
406 429 }
407 430  
408 431 switch (wm8994->type) {
409 432  
... ... @@ -420,14 +443,14 @@
420 443 break;
421 444 default:
422 445 BUG();
423   - goto err_regmap;
  446 + goto err;
424 447 }
425 448  
426 449 ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies,
427 450 wm8994->supplies);
428 451 if (ret != 0) {
429 452 dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret);
430   - goto err_regmap;
  453 + goto err;
431 454 }
432 455  
433 456 ret = regulator_bulk_enable(wm8994->num_supplies,
434 457  
435 458  
436 459  
... ... @@ -488,15 +511,44 @@
488 511 "revision %c not fully supported\n",
489 512 'A' + wm8994->revision);
490 513 break;
  514 + case 2:
  515 + case 3:
  516 + regmap_patch = wm8994_revc_patch;
  517 + patch_regs = ARRAY_SIZE(wm8994_revc_patch);
  518 + break;
491 519 default:
492 520 break;
493 521 }
494 522 break;
  523 +
  524 + case WM8958:
  525 + switch (wm8994->revision) {
  526 + case 0:
  527 + regmap_patch = wm8958_reva_patch;
  528 + patch_regs = ARRAY_SIZE(wm8958_reva_patch);
  529 + break;
  530 + default:
  531 + break;
  532 + }
  533 + break;
  534 +
495 535 case WM1811:
496 536 /* Revision C did not change the relevant layer */
497 537 if (wm8994->revision > 1)
498 538 wm8994->revision++;
  539 + switch (wm8994->revision) {
  540 + case 0:
  541 + case 1:
  542 + case 2:
  543 + case 3:
  544 + regmap_patch = wm1811_reva_patch;
  545 + patch_regs = ARRAY_SIZE(wm1811_reva_patch);
  546 + break;
  547 + default:
  548 + break;
  549 + }
499 550 break;
  551 +
500 552 default:
501 553 break;
502 554 }
... ... @@ -526,6 +578,16 @@
526 578 return ret;
527 579 }
528 580  
  581 + if (regmap_patch) {
  582 + ret = regmap_register_patch(wm8994->regmap, regmap_patch,
  583 + patch_regs);
  584 + if (ret != 0) {
  585 + dev_err(wm8994->dev, "Failed to register patch: %d\n",
  586 + ret);
  587 + goto err;
  588 + }
  589 + }
  590 +
529 591 if (pdata) {
530 592 wm8994->irq_base = pdata->irq_base;
531 593 wm8994->gpio_base = pdata->gpio_base;
532 594  
... ... @@ -588,13 +650,12 @@
588 650 wm8994->supplies);
589 651 err_get:
590 652 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
591   -err_regmap:
592   - regmap_exit(wm8994->regmap);
  653 +err:
593 654 mfd_remove_devices(wm8994->dev);
594 655 return ret;
595 656 }
596 657  
597   -static void wm8994_device_exit(struct wm8994 *wm8994)
  658 +static __devexit void wm8994_device_exit(struct wm8994 *wm8994)
598 659 {
599 660 pm_runtime_disable(wm8994->dev);
600 661 mfd_remove_devices(wm8994->dev);
... ... @@ -602,7 +663,6 @@
602 663 regulator_bulk_disable(wm8994->num_supplies,
603 664 wm8994->supplies);
604 665 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
605   - regmap_exit(wm8994->regmap);
606 666 }
607 667  
608 668 static const struct of_device_id wm8994_of_match[] = {
... ... @@ -613,8 +673,8 @@
613 673 };
614 674 MODULE_DEVICE_TABLE(of, wm8994_of_match);
615 675  
616   -static int wm8994_i2c_probe(struct i2c_client *i2c,
617   - const struct i2c_device_id *id)
  676 +static __devinit int wm8994_i2c_probe(struct i2c_client *i2c,
  677 + const struct i2c_device_id *id)
618 678 {
619 679 struct wm8994 *wm8994;
620 680 int ret;
... ... @@ -628,7 +688,7 @@
628 688 wm8994->irq = i2c->irq;
629 689 wm8994->type = id->driver_data;
630 690  
631   - wm8994->regmap = regmap_init_i2c(i2c, &wm8994_base_regmap_config);
  691 + wm8994->regmap = devm_regmap_init_i2c(i2c, &wm8994_base_regmap_config);
632 692 if (IS_ERR(wm8994->regmap)) {
633 693 ret = PTR_ERR(wm8994->regmap);
634 694 dev_err(wm8994->dev, "Failed to allocate register map: %d\n",
... ... @@ -639,7 +699,7 @@
639 699 return wm8994_device_init(wm8994, i2c->irq);
640 700 }
641 701  
642   -static int wm8994_i2c_remove(struct i2c_client *i2c)
  702 +static __devexit int wm8994_i2c_remove(struct i2c_client *i2c)
643 703 {
644 704 struct wm8994 *wm8994 = i2c_get_clientdata(i2c);
645 705  
... ... @@ -668,7 +728,7 @@
668 728 .of_match_table = wm8994_of_match,
669 729 },
670 730 .probe = wm8994_i2c_probe,
671   - .remove = wm8994_i2c_remove,
  731 + .remove = __devexit_p(wm8994_i2c_remove),
672 732 .id_table = wm8994_i2c_id,
673 733 };
674 734  
include/linux/regmap.h
... ... @@ -19,6 +19,7 @@
19 19 struct module;
20 20 struct i2c_client;
21 21 struct spi_device;
  22 +struct regmap;
22 23  
23 24 /* An enum of all the supported cache types */
24 25 enum regcache_type {
25 26  
... ... @@ -40,10 +41,13 @@
40 41 unsigned int def;
41 42 };
42 43  
  44 +#ifdef CONFIG_REGMAP
  45 +
43 46 /**
44 47 * Configuration for the register map of a device.
45 48 *
46 49 * @reg_bits: Number of bits in a register address, mandatory.
  50 + * @pad_bits: Number of bits of padding between register and value.
47 51 * @val_bits: Number of bits in a register value, mandatory.
48 52 *
49 53 * @writeable_reg: Optional callback returning true if the register
... ... @@ -74,6 +78,7 @@
74 78 */
75 79 struct regmap_config {
76 80 int reg_bits;
  81 + int pad_bits;
77 82 int val_bits;
78 83  
79 84 bool (*writeable_reg)(struct device *dev, unsigned int reg);
80 85  
... ... @@ -127,12 +132,22 @@
127 132 struct regmap *regmap_init_spi(struct spi_device *dev,
128 133 const struct regmap_config *config);
129 134  
  135 +struct regmap *devm_regmap_init(struct device *dev,
  136 + const struct regmap_bus *bus,
  137 + const struct regmap_config *config);
  138 +struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c,
  139 + const struct regmap_config *config);
  140 +struct regmap *devm_regmap_init_spi(struct spi_device *dev,
  141 + const struct regmap_config *config);
  142 +
130 143 void regmap_exit(struct regmap *map);
131 144 int regmap_reinit_cache(struct regmap *map,
132 145 const struct regmap_config *config);
133 146 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
134 147 int regmap_raw_write(struct regmap *map, unsigned int reg,
135 148 const void *val, size_t val_len);
  149 +int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
  150 + size_t val_count);
136 151 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
137 152 int regmap_raw_read(struct regmap *map, unsigned int reg,
138 153 void *val, size_t val_len);
... ... @@ -146,6 +161,8 @@
146 161 int regmap_get_val_bytes(struct regmap *map);
147 162  
148 163 int regcache_sync(struct regmap *map);
  164 +int regcache_sync_region(struct regmap *map, unsigned int min,
  165 + unsigned int max);
149 166 void regcache_cache_only(struct regmap *map, bool enable);
150 167 void regcache_cache_bypass(struct regmap *map, bool enable);
151 168 void regcache_mark_dirty(struct regmap *map);
... ... @@ -200,6 +217,117 @@
200 217 struct regmap_irq_chip_data **data);
201 218 void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
202 219 int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
  220 +
  221 +#else
  222 +
  223 +/*
  224 + * These stubs should only ever be called by generic code which has
  225 + * regmap based facilities, if they ever get called at runtime
  226 + * something is going wrong and something probably needs to select
  227 + * REGMAP.
  228 + */
  229 +
  230 +static inline int regmap_write(struct regmap *map, unsigned int reg,
  231 + unsigned int val)
  232 +{
  233 + WARN_ONCE(1, "regmap API is disabled");
  234 + return -EINVAL;
  235 +}
  236 +
  237 +static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
  238 + const void *val, size_t val_len)
  239 +{
  240 + WARN_ONCE(1, "regmap API is disabled");
  241 + return -EINVAL;
  242 +}
  243 +
  244 +static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
  245 + const void *val, size_t val_count)
  246 +{
  247 + WARN_ONCE(1, "regmap API is disabled");
  248 + return -EINVAL;
  249 +}
  250 +
  251 +static inline int regmap_read(struct regmap *map, unsigned int reg,
  252 + unsigned int *val)
  253 +{
  254 + WARN_ONCE(1, "regmap API is disabled");
  255 + return -EINVAL;
  256 +}
  257 +
  258 +static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
  259 + void *val, size_t val_len)
  260 +{
  261 + WARN_ONCE(1, "regmap API is disabled");
  262 + return -EINVAL;
  263 +}
  264 +
  265 +static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
  266 + void *val, size_t val_count)
  267 +{
  268 + WARN_ONCE(1, "regmap API is disabled");
  269 + return -EINVAL;
  270 +}
  271 +
  272 +static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
  273 + unsigned int mask, unsigned int val)
  274 +{
  275 + WARN_ONCE(1, "regmap API is disabled");
  276 + return -EINVAL;
  277 +}
  278 +
  279 +static inline int regmap_update_bits_check(struct regmap *map,
  280 + unsigned int reg,
  281 + unsigned int mask, unsigned int val,
  282 + bool *change)
  283 +{
  284 + WARN_ONCE(1, "regmap API is disabled");
  285 + return -EINVAL;
  286 +}
  287 +
  288 +static inline int regmap_get_val_bytes(struct regmap *map)
  289 +{
  290 + WARN_ONCE(1, "regmap API is disabled");
  291 + return -EINVAL;
  292 +}
  293 +
  294 +static inline int regcache_sync(struct regmap *map)
  295 +{
  296 + WARN_ONCE(1, "regmap API is disabled");
  297 + return -EINVAL;
  298 +}
  299 +
  300 +static inline int regcache_sync_region(struct regmap *map, unsigned int min,
  301 + unsigned int max)
  302 +{
  303 + WARN_ONCE(1, "regmap API is disabled");
  304 + return -EINVAL;
  305 +}
  306 +
  307 +static inline void regcache_cache_only(struct regmap *map, bool enable)
  308 +{
  309 + WARN_ONCE(1, "regmap API is disabled");
  310 +}
  311 +
  312 +static inline void regcache_cache_bypass(struct regmap *map, bool enable)
  313 +{
  314 + WARN_ONCE(1, "regmap API is disabled");
  315 +}
  316 +
  317 +static inline void regcache_mark_dirty(struct regmap *map)
  318 +{
  319 + WARN_ONCE(1, "regmap API is disabled");
  320 +}
  321 +
  322 +static inline int regmap_register_patch(struct regmap *map,
  323 + const struct reg_default *regs,
  324 + int num_regs)
  325 +{
  326 + WARN_ONCE(1, "regmap API is disabled");
  327 + return -EINVAL;
  328 +}
  329 +
  330 +#endif
203 331  
204 332 #endif
include/trace/events/regmap.h
... ... @@ -139,6 +139,42 @@
139 139 __get_str(type), __get_str(status))
140 140 );
141 141  
  142 +DECLARE_EVENT_CLASS(regmap_bool,
  143 +
  144 + TP_PROTO(struct device *dev, bool flag),
  145 +
  146 + TP_ARGS(dev, flag),
  147 +
  148 + TP_STRUCT__entry(
  149 + __string( name, dev_name(dev) )
  150 + __field( int, flag )
  151 + ),
  152 +
  153 + TP_fast_assign(
  154 + __assign_str(name, dev_name(dev));
  155 + __entry->flag = flag;
  156 + ),
  157 +
  158 + TP_printk("%s flag=%d", __get_str(name),
  159 + (int)__entry->flag)
  160 +);
  161 +
  162 +DEFINE_EVENT(regmap_bool, regmap_cache_only,
  163 +
  164 + TP_PROTO(struct device *dev, bool flag),
  165 +
  166 + TP_ARGS(dev, flag)
  167 +
  168 +);
  169 +
  170 +DEFINE_EVENT(regmap_bool, regmap_cache_bypass,
  171 +
  172 + TP_PROTO(struct device *dev, bool flag),
  173 +
  174 + TP_ARGS(dev, flag)
  175 +
  176 +);
  177 +
142 178 #endif /* _TRACE_REGMAP_H */
143 179  
144 180 /* This part must be outside protection */
sound/soc/codecs/wm8994.c
... ... @@ -2181,26 +2181,9 @@
2181 2181 case SND_SOC_BIAS_STANDBY:
2182 2182 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
2183 2183 switch (control->type) {
2184   - case WM8994:
2185   - if (wm8994->revision < 4) {
2186   - /* Tweak DC servo and DSP
2187   - * configuration for improved
2188   - * performance. */
2189   - snd_soc_write(codec, 0x102, 0x3);
2190   - snd_soc_write(codec, 0x56, 0x3);
2191   - snd_soc_write(codec, 0x817, 0);
2192   - snd_soc_write(codec, 0x102, 0);
2193   - }
2194   - break;
2195   -
2196 2184 case WM8958:
2197 2185 if (wm8994->revision == 0) {
2198 2186 /* Optimise performance for rev A */
2199   - snd_soc_write(codec, 0x102, 0x3);
2200   - snd_soc_write(codec, 0xcb, 0x81);
2201   - snd_soc_write(codec, 0x817, 0);
2202   - snd_soc_write(codec, 0x102, 0);
2203   -
2204 2187 snd_soc_update_bits(codec,
2205 2188 WM8958_CHARGE_PUMP_2,
2206 2189 WM8958_CP_DISCH,
... ... @@ -2208,13 +2191,7 @@
2208 2191 }
2209 2192 break;
2210 2193  
2211   - case WM1811:
2212   - if (wm8994->revision < 2) {
2213   - snd_soc_write(codec, 0x102, 0x3);
2214   - snd_soc_write(codec, 0x5d, 0x7e);
2215   - snd_soc_write(codec, 0x5e, 0x0);
2216   - snd_soc_write(codec, 0x102, 0x0);
2217   - }
  2194 + default:
2218 2195 break;
2219 2196 }
2220 2197