aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/base/regmap/internal.h11
-rw-r--r--drivers/base/regmap/regcache-lzo.c16
-rw-r--r--drivers/base/regmap/regcache-rbtree.c27
-rw-r--r--drivers/base/regmap/regcache.c97
-rw-r--r--drivers/base/regmap/regmap-debugfs.c84
-rw-r--r--drivers/base/regmap/regmap-i2c.c17
-rw-r--r--drivers/base/regmap/regmap-spi.c17
-rw-r--r--drivers/base/regmap/regmap.c236
-rw-r--r--drivers/mfd/wm831x-core.c20
-rw-r--r--drivers/mfd/wm831x-i2c.c2
-rw-r--r--drivers/mfd/wm831x-spi.c2
-rw-r--r--drivers/mfd/wm8400-core.c7
-rw-r--r--drivers/mfd/wm8994-core.c92
13 files changed, 530 insertions, 98 deletions
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index d141b80479b5..fcafc5b2e651 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -22,6 +22,7 @@ struct regcache_ops;
22struct regmap_format { 22struct regmap_format {
23 size_t buf_size; 23 size_t buf_size;
24 size_t reg_bytes; 24 size_t reg_bytes;
25 size_t pad_bytes;
25 size_t val_bytes; 26 size_t val_bytes;
26 void (*format_write)(struct regmap *map, 27 void (*format_write)(struct regmap *map,
27 unsigned int reg, unsigned int val); 28 unsigned int reg, unsigned int val);
@@ -65,16 +66,16 @@ struct regmap {
65 unsigned int num_reg_defaults_raw; 66 unsigned int num_reg_defaults_raw;
66 67
67 /* if set, only the cache is modified not the HW */ 68 /* if set, only the cache is modified not the HW */
68 unsigned int cache_only:1; 69 u32 cache_only;
69 /* if set, only the HW is modified not the cache */ 70 /* if set, only the HW is modified not the cache */
70 unsigned int cache_bypass:1; 71 u32 cache_bypass;
71 /* if set, remember to free reg_defaults_raw */ 72 /* if set, remember to free reg_defaults_raw */
72 unsigned int cache_free:1; 73 bool cache_free;
73 74
74 struct reg_default *reg_defaults; 75 struct reg_default *reg_defaults;
75 const void *reg_defaults_raw; 76 const void *reg_defaults_raw;
76 void *cache; 77 void *cache;
77 bool cache_dirty; 78 u32 cache_dirty;
78 79
79 struct reg_default *patch; 80 struct reg_default *patch;
80 int patch_regs; 81 int patch_regs;
@@ -87,7 +88,7 @@ struct regcache_ops {
87 int (*exit)(struct regmap *map); 88 int (*exit)(struct regmap *map);
88 int (*read)(struct regmap *map, unsigned int reg, unsigned int *value); 89 int (*read)(struct regmap *map, unsigned int reg, unsigned int *value);
89 int (*write)(struct regmap *map, unsigned int reg, unsigned int value); 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
93bool regmap_writeable(struct regmap *map, unsigned int reg); 94bool regmap_writeable(struct regmap *map, unsigned int reg);
diff --git a/drivers/base/regmap/regcache-lzo.c b/drivers/base/regmap/regcache-lzo.c
index b7d16143edeb..8d0061569326 100644
--- a/drivers/base/regmap/regcache-lzo.c
+++ b/drivers/base/regmap/regcache-lzo.c
@@ -331,7 +331,8 @@ out:
331 return ret; 331 return ret;
332} 332}
333 333
334static int regcache_lzo_sync(struct regmap *map) 334static int regcache_lzo_sync(struct regmap *map, unsigned int min,
335 unsigned int max)
335{ 336{
336 struct regcache_lzo_ctx **lzo_blocks; 337 struct regcache_lzo_ctx **lzo_blocks;
337 unsigned int val; 338 unsigned int val;
@@ -339,10 +340,21 @@ static int regcache_lzo_sync(struct regmap *map)
339 int ret; 340 int ret;
340 341
341 lzo_blocks = map->cache; 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 ret = regcache_read(map, i, &val); 349 ret = regcache_read(map, i, &val);
344 if (ret) 350 if (ret)
345 return ret; 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 map->cache_bypass = 1; 358 map->cache_bypass = 1;
347 ret = _regmap_write(map, i, val); 359 ret = _regmap_write(map, i, val);
348 map->cache_bypass = 0; 360 map->cache_bypass = 0;
diff --git a/drivers/base/regmap/regcache-rbtree.c b/drivers/base/regmap/regcache-rbtree.c
index 32620c4f1683..8d51916a283d 100644
--- a/drivers/base/regmap/regcache-rbtree.c
+++ b/drivers/base/regmap/regcache-rbtree.c
@@ -357,7 +357,8 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
357 return 0; 357 return 0;
358} 358}
359 359
360static int regcache_rbtree_sync(struct regmap *map) 360static int regcache_rbtree_sync(struct regmap *map, unsigned int min,
361 unsigned int max)
361{ 362{
362 struct regcache_rbtree_ctx *rbtree_ctx; 363 struct regcache_rbtree_ctx *rbtree_ctx;
363 struct rb_node *node; 364 struct rb_node *node;
@@ -365,19 +366,37 @@ static int regcache_rbtree_sync(struct regmap *map)
365 unsigned int regtmp; 366 unsigned int regtmp;
366 unsigned int val; 367 unsigned int val;
367 int ret; 368 int ret;
368 int i; 369 int i, base, end;
369 370
370 rbtree_ctx = map->cache; 371 rbtree_ctx = map->cache;
371 for (node = rb_first(&rbtree_ctx->root); node; node = rb_next(node)) { 372 for (node = rb_first(&rbtree_ctx->root); node; node = rb_next(node)) {
372 rbnode = rb_entry(node, struct regcache_rbtree_node, node); 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 regtmp = rbnode->base_reg + i; 393 regtmp = rbnode->base_reg + i;
375 val = regcache_rbtree_get_register(rbnode, i, 394 val = regcache_rbtree_get_register(rbnode, i,
376 map->cache_word_size); 395 map->cache_word_size);
377 396
378 /* Is this the hardware default? If so skip. */ 397 /* Is this the hardware default? If so skip. */
379 ret = regcache_lookup_reg(map, i); 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 continue; 400 continue;
382 401
383 map->cache_bypass = 1; 402 map->cache_bypass = 1;
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index 5cd2a37e7688..938cb1d2ea26 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -35,12 +35,17 @@ static int regcache_hw_init(struct regmap *map)
35 return -EINVAL; 35 return -EINVAL;
36 36
37 if (!map->reg_defaults_raw) { 37 if (!map->reg_defaults_raw) {
38 u32 cache_bypass = map->cache_bypass;
38 dev_warn(map->dev, "No cache defaults, reading back from HW\n"); 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 tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL); 43 tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL);
40 if (!tmp_buf) 44 if (!tmp_buf)
41 return -EINVAL; 45 return -EINVAL;
42 ret = regmap_bulk_read(map, 0, tmp_buf, 46 ret = regmap_bulk_read(map, 0, tmp_buf,
43 map->num_reg_defaults_raw); 47 map->num_reg_defaults_raw);
48 map->cache_bypass = cache_bypass;
44 if (ret < 0) { 49 if (ret < 0) {
45 kfree(tmp_buf); 50 kfree(tmp_buf);
46 return ret; 51 return ret;
@@ -211,7 +216,6 @@ int regcache_read(struct regmap *map,
211 216
212 return -EINVAL; 217 return -EINVAL;
213} 218}
214EXPORT_SYMBOL_GPL(regcache_read);
215 219
216/** 220/**
217 * regcache_write: Set the value of a given register in the cache. 221 * regcache_write: Set the value of a given register in the cache.
@@ -238,7 +242,6 @@ int regcache_write(struct regmap *map,
238 242
239 return 0; 243 return 0;
240} 244}
241EXPORT_SYMBOL_GPL(regcache_write);
242 245
243/** 246/**
244 * regcache_sync: Sync the register cache with the hardware. 247 * regcache_sync: Sync the register cache with the hardware.
@@ -254,12 +257,11 @@ EXPORT_SYMBOL_GPL(regcache_write);
254int regcache_sync(struct regmap *map) 257int regcache_sync(struct regmap *map)
255{ 258{
256 int ret = 0; 259 int ret = 0;
257 unsigned int val;
258 unsigned int i; 260 unsigned int i;
259 const char *name; 261 const char *name;
260 unsigned int bypass; 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 mutex_lock(&map->lock); 266 mutex_lock(&map->lock);
265 /* Remember the initial bypass state */ 267 /* Remember the initial bypass state */
@@ -269,7 +271,11 @@ int regcache_sync(struct regmap *map)
269 name = map->cache_ops->name; 271 name = map->cache_ops->name;
270 trace_regcache_sync(map->dev, name, "start"); 272 trace_regcache_sync(map->dev, name, "start");
271 273
274 if (!map->cache_dirty)
275 goto out;
276
272 /* Apply any patch first */ 277 /* Apply any patch first */
278 map->cache_bypass = 1;
273 for (i = 0; i < map->patch_regs; i++) { 279 for (i = 0; i < map->patch_regs; i++) {
274 ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def); 280 ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def);
275 if (ret != 0) { 281 if (ret != 0) {
@@ -278,27 +284,13 @@ int regcache_sync(struct regmap *map)
278 goto out; 284 goto out;
279 } 285 }
280 } 286 }
287 map->cache_bypass = 0;
281 288
282 if (!map->cache_dirty) 289 ret = map->cache_ops->sync(map, 0, map->max_register);
283 goto out; 290
284 if (map->cache_ops->sync) { 291 if (ret == 0)
285 ret = map->cache_ops->sync(map); 292 map->cache_dirty = false;
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 }
300 293
301 }
302out: 294out:
303 trace_regcache_sync(map->dev, name, "stop"); 295 trace_regcache_sync(map->dev, name, "stop");
304 /* Restore the bypass state */ 296 /* Restore the bypass state */
@@ -310,6 +302,51 @@ out:
310EXPORT_SYMBOL_GPL(regcache_sync); 302EXPORT_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 */
316int 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
340out:
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 * regcache_cache_only: Put a register map into cache only mode 350 * regcache_cache_only: Put a register map into cache only mode
314 * 351 *
315 * @map: map to configure 352 * @map: map to configure
@@ -326,6 +363,7 @@ void regcache_cache_only(struct regmap *map, bool enable)
326 mutex_lock(&map->lock); 363 mutex_lock(&map->lock);
327 WARN_ON(map->cache_bypass && enable); 364 WARN_ON(map->cache_bypass && enable);
328 map->cache_only = enable; 365 map->cache_only = enable;
366 trace_regmap_cache_only(map->dev, enable);
329 mutex_unlock(&map->lock); 367 mutex_unlock(&map->lock);
330} 368}
331EXPORT_SYMBOL_GPL(regcache_cache_only); 369EXPORT_SYMBOL_GPL(regcache_cache_only);
@@ -363,6 +401,7 @@ void regcache_cache_bypass(struct regmap *map, bool enable)
363 mutex_lock(&map->lock); 401 mutex_lock(&map->lock);
364 WARN_ON(map->cache_only && enable); 402 WARN_ON(map->cache_only && enable);
365 map->cache_bypass = enable; 403 map->cache_bypass = enable;
404 trace_regmap_cache_bypass(map->dev, enable);
366 mutex_unlock(&map->lock); 405 mutex_unlock(&map->lock);
367} 406}
368EXPORT_SYMBOL_GPL(regcache_cache_bypass); 407EXPORT_SYMBOL_GPL(regcache_cache_bypass);
@@ -385,10 +424,16 @@ bool regcache_set_val(void *base, unsigned int idx,
385 cache[idx] = val; 424 cache[idx] = val;
386 break; 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 default: 434 default:
389 BUG(); 435 BUG();
390 } 436 }
391 /* unreachable */
392 return false; 437 return false;
393} 438}
394 439
@@ -407,6 +452,10 @@ unsigned int regcache_get_val(const void *base, unsigned int idx,
407 const u16 *cache = base; 452 const u16 *cache = base;
408 return cache[idx]; 453 return cache[idx];
409 } 454 }
455 case 4: {
456 const u32 *cache = base;
457 return cache[idx];
458 }
410 default: 459 default:
411 BUG(); 460 BUG();
412 } 461 }
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index 6f397476e27c..372f81a21201 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -11,7 +11,6 @@
11 */ 11 */
12 12
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/module.h>
15#include <linux/mutex.h> 14#include <linux/mutex.h>
16#include <linux/debugfs.h> 15#include <linux/debugfs.h>
17#include <linux/uaccess.h> 16#include <linux/uaccess.h>
@@ -33,6 +32,35 @@ static int regmap_open_file(struct inode *inode, struct file *file)
33 return 0; 32 return 0;
34} 33}
35 34
35static 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
58static const struct file_operations regmap_name_fops = {
59 .open = regmap_open_file,
60 .read = regmap_name_read_file,
61 .llseek = default_llseek,
62};
63
36static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf, 64static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
37 size_t count, loff_t *ppos) 65 size_t count, loff_t *ppos)
38{ 66{
@@ -103,9 +131,51 @@ out:
103 return ret; 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 */
142static 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
106static const struct file_operations regmap_map_fops = { 175static const struct file_operations regmap_map_fops = {
107 .open = regmap_open_file, 176 .open = regmap_open_file,
108 .read = regmap_map_read_file, 177 .read = regmap_map_read_file,
178 .write = regmap_map_write_file,
109 .llseek = default_llseek, 179 .llseek = default_llseek,
110}; 180};
111 181
@@ -186,12 +256,24 @@ void regmap_debugfs_init(struct regmap *map)
186 return; 256 return;
187 } 257 }
188 258
259 debugfs_create_file("name", 0400, map->debugfs,
260 map, &regmap_name_fops);
261
189 if (map->max_register) { 262 if (map->max_register) {
190 debugfs_create_file("registers", 0400, map->debugfs, 263 debugfs_create_file("registers", 0400, map->debugfs,
191 map, &regmap_map_fops); 264 map, &regmap_map_fops);
192 debugfs_create_file("access", 0400, map->debugfs, 265 debugfs_create_file("access", 0400, map->debugfs,
193 map, &regmap_access_fops); 266 map, &regmap_access_fops);
194 } 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);
276 }
195} 277}
196 278
197void regmap_debugfs_exit(struct regmap *map) 279void regmap_debugfs_exit(struct regmap *map)
diff --git a/drivers/base/regmap/regmap-i2c.c b/drivers/base/regmap/regmap-i2c.c
index 38621ec87c05..9a3a8c564389 100644
--- a/drivers/base/regmap/regmap-i2c.c
+++ b/drivers/base/regmap/regmap-i2c.c
@@ -111,4 +111,21 @@ struct regmap *regmap_init_i2c(struct i2c_client *i2c,
111} 111}
112EXPORT_SYMBOL_GPL(regmap_init_i2c); 112EXPORT_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 */
124struct 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}
129EXPORT_SYMBOL_GPL(devm_regmap_init_i2c);
130
114MODULE_LICENSE("GPL"); 131MODULE_LICENSE("GPL");
diff --git a/drivers/base/regmap/regmap-spi.c b/drivers/base/regmap/regmap-spi.c
index 2560658de344..7c0c35a39c33 100644
--- a/drivers/base/regmap/regmap-spi.c
+++ b/drivers/base/regmap/regmap-spi.c
@@ -70,4 +70,21 @@ struct regmap *regmap_init_spi(struct spi_device *spi,
70} 70}
71EXPORT_SYMBOL_GPL(regmap_init_spi); 71EXPORT_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 */
83struct 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}
88EXPORT_SYMBOL_GPL(devm_regmap_init_spi);
89
73MODULE_LICENSE("GPL"); 90MODULE_LICENSE("GPL");
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 7ac234f0b1c5..7a3f535e481c 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -10,8 +10,9 @@
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13#include <linux/device.h>
13#include <linux/slab.h> 14#include <linux/slab.h>
14#include <linux/module.h> 15#include <linux/export.h>
15#include <linux/mutex.h> 16#include <linux/mutex.h>
16#include <linux/err.h> 17#include <linux/err.h>
17 18
@@ -36,6 +37,9 @@ bool regmap_readable(struct regmap *map, unsigned int reg)
36 if (map->max_register && reg > map->max_register) 37 if (map->max_register && reg > map->max_register)
37 return false; 38 return false;
38 39
40 if (map->format.format_write)
41 return false;
42
39 if (map->readable_reg) 43 if (map->readable_reg)
40 return map->readable_reg(map->dev, reg); 44 return map->readable_reg(map->dev, reg);
41 45
@@ -44,7 +48,7 @@ bool regmap_readable(struct regmap *map, unsigned int reg)
44 48
45bool regmap_volatile(struct regmap *map, unsigned int reg) 49bool 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 return false; 52 return false;
49 53
50 if (map->volatile_reg) 54 if (map->volatile_reg)
@@ -55,7 +59,7 @@ bool regmap_volatile(struct regmap *map, unsigned int reg)
55 59
56bool regmap_precious(struct regmap *map, unsigned int reg) 60bool 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 return false; 63 return false;
60 64
61 if (map->precious_reg) 65 if (map->precious_reg)
@@ -76,6 +80,14 @@ static bool regmap_volatile_range(struct regmap *map, unsigned int reg,
76 return true; 80 return true;
77} 81}
78 82
83static 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
79static void regmap_format_4_12_write(struct regmap *map, 91static void regmap_format_4_12_write(struct regmap *map,
80 unsigned int reg, unsigned int val) 92 unsigned int reg, unsigned int val)
81{ 93{
@@ -114,6 +126,13 @@ static void regmap_format_16(void *buf, unsigned int val)
114 b[0] = cpu_to_be16(val); 126 b[0] = cpu_to_be16(val);
115} 127}
116 128
129static void regmap_format_32(void *buf, unsigned int val)
130{
131 __be32 *b = buf;
132
133 b[0] = cpu_to_be32(val);
134}
135
117static unsigned int regmap_parse_8(void *buf) 136static unsigned int regmap_parse_8(void *buf)
118{ 137{
119 u8 *b = buf; 138 u8 *b = buf;
@@ -130,6 +149,15 @@ static unsigned int regmap_parse_16(void *buf)
130 return b[0]; 149 return b[0];
131} 150}
132 151
152static 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 * regmap_init(): Initialise register map 162 * regmap_init(): Initialise register map
135 * 163 *
@@ -159,8 +187,10 @@ struct regmap *regmap_init(struct device *dev,
159 187
160 mutex_init(&map->lock); 188 mutex_init(&map->lock);
161 map->format.buf_size = (config->reg_bits + config->val_bits) / 8; 189 map->format.buf_size = (config->reg_bits + config->val_bits) / 8;
162 map->format.reg_bytes = config->reg_bits / 8; 190 map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
163 map->format.val_bytes = config->val_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 map->dev = dev; 194 map->dev = dev;
165 map->bus = bus; 195 map->bus = bus;
166 map->max_register = config->max_register; 196 map->max_register = config->max_register;
@@ -178,6 +208,16 @@ struct regmap *regmap_init(struct device *dev,
178 } 208 }
179 209
180 switch (config->reg_bits) { 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 case 4: 221 case 4:
182 switch (config->val_bits) { 222 switch (config->val_bits) {
183 case 12: 223 case 12:
@@ -216,6 +256,10 @@ struct regmap *regmap_init(struct device *dev,
216 map->format.format_reg = regmap_format_16; 256 map->format.format_reg = regmap_format_16;
217 break; 257 break;
218 258
259 case 32:
260 map->format.format_reg = regmap_format_32;
261 break;
262
219 default: 263 default:
220 goto err_map; 264 goto err_map;
221 } 265 }
@@ -229,13 +273,17 @@ struct regmap *regmap_init(struct device *dev,
229 map->format.format_val = regmap_format_16; 273 map->format.format_val = regmap_format_16;
230 map->format.parse_val = regmap_parse_16; 274 map->format.parse_val = regmap_parse_16;
231 break; 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 if (!map->format.format_write && 282 if (!map->format.format_write &&
235 !(map->format.format_reg && map->format.format_val)) 283 !(map->format.format_reg && map->format.format_val))
236 goto err_map; 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 if (map->work_buf == NULL) { 287 if (map->work_buf == NULL) {
240 ret = -ENOMEM; 288 ret = -ENOMEM;
241 goto err_map; 289 goto err_map;
@@ -258,6 +306,45 @@ err:
258} 306}
259EXPORT_SYMBOL_GPL(regmap_init); 307EXPORT_SYMBOL_GPL(regmap_init);
260 308
309static void devm_regmap_release(struct device *dev, void *res)
310{
311 regmap_exit(*(struct regmap **)res);
312}
313
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 */
326struct 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}
346EXPORT_SYMBOL_GPL(devm_regmap_init);
347
261/** 348/**
262 * regmap_reinit_cache(): Reinitialise the current register cache 349 * regmap_reinit_cache(): Reinitialise the current register cache
263 * 350 *
@@ -276,6 +363,7 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
276 mutex_lock(&map->lock); 363 mutex_lock(&map->lock);
277 364
278 regcache_exit(map); 365 regcache_exit(map);
366 regmap_debugfs_exit(map);
279 367
280 map->max_register = config->max_register; 368 map->max_register = config->max_register;
281 map->writeable_reg = config->writeable_reg; 369 map->writeable_reg = config->writeable_reg;
@@ -284,6 +372,8 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
284 map->precious_reg = config->precious_reg; 372 map->precious_reg = config->precious_reg;
285 map->cache_type = config->cache_type; 373 map->cache_type = config->cache_type;
286 374
375 regmap_debugfs_init(map);
376
287 map->cache_bypass = false; 377 map->cache_bypass = false;
288 map->cache_only = false; 378 map->cache_only = false;
289 379
@@ -321,6 +411,26 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
321 if (!map->writeable_reg(map->dev, reg + i)) 411 if (!map->writeable_reg(map->dev, reg + i))
322 return -EINVAL; 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 map->format.format_reg(map->work_buf, reg); 434 map->format.format_reg(map->work_buf, reg);
325 435
326 u8[0] |= map->write_flag_mask; 436 u8[0] |= map->write_flag_mask;
@@ -332,23 +442,28 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
332 * send the work_buf directly, otherwise try to do a gather 442 * send the work_buf directly, otherwise try to do a gather
333 * write. 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 ret = map->bus->write(map->dev, map->work_buf, 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 else if (map->bus->gather_write) 451 else if (map->bus->gather_write)
339 ret = map->bus->gather_write(map->dev, map->work_buf, 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 val, val_len); 455 val, val_len);
342 456
343 /* If that didn't work fall back on linearising by hand. */ 457 /* If that didn't work fall back on linearising by hand. */
344 if (ret == -ENOTSUPP) { 458 if (ret == -ENOTSUPP) {
345 len = map->format.reg_bytes + val_len; 459 len = map->format.reg_bytes + map->format.pad_bytes + val_len;
346 buf = kmalloc(len, GFP_KERNEL); 460 buf = kzalloc(len, GFP_KERNEL);
347 if (!buf) 461 if (!buf)
348 return -ENOMEM; 462 return -ENOMEM;
349 463
350 memcpy(buf, map->work_buf, map->format.reg_bytes); 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 ret = map->bus->write(map->dev, buf, len); 467 ret = map->bus->write(map->dev, buf, len);
353 468
354 kfree(buf); 469 kfree(buf);
@@ -366,7 +481,7 @@ int _regmap_write(struct regmap *map, unsigned int reg,
366 int ret; 481 int ret;
367 BUG_ON(!map->format.format_write && !map->format.format_val); 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 ret = regcache_write(map, reg, val); 485 ret = regcache_write(map, reg, val);
371 if (ret != 0) 486 if (ret != 0)
372 return ret; 487 return ret;
@@ -390,10 +505,12 @@ int _regmap_write(struct regmap *map, unsigned int reg,
390 505
391 return ret; 506 return ret;
392 } else { 507 } else {
393 map->format.format_val(map->work_buf + map->format.reg_bytes, 508 map->format.format_val(map->work_buf + map->format.reg_bytes
394 val); 509 + map->format.pad_bytes, val);
395 return _regmap_raw_write(map, reg, 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 map->format.val_bytes); 514 map->format.val_bytes);
398 } 515 }
399} 516}
@@ -441,12 +558,8 @@ EXPORT_SYMBOL_GPL(regmap_write);
441int regmap_raw_write(struct regmap *map, unsigned int reg, 558int regmap_raw_write(struct regmap *map, unsigned int reg,
442 const void *val, size_t val_len) 559 const void *val, size_t val_len)
443{ 560{
444 size_t val_count = val_len / map->format.val_bytes;
445 int ret; 561 int ret;
446 562
447 WARN_ON(!regmap_volatile_range(map, reg, val_count) &&
448 map->cache_type != REGCACHE_NONE);
449
450 mutex_lock(&map->lock); 563 mutex_lock(&map->lock);
451 564
452 ret = _regmap_raw_write(map, reg, val, val_len); 565 ret = _regmap_raw_write(map, reg, val, val_len);
@@ -457,6 +570,56 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
457} 570}
458EXPORT_SYMBOL_GPL(regmap_raw_write); 571EXPORT_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 */
587int 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
617out:
618 mutex_unlock(&map->lock);
619 return ret;
620}
621EXPORT_SYMBOL_GPL(regmap_bulk_write);
622
460static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, 623static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
461 unsigned int val_len) 624 unsigned int val_len)
462{ 625{
@@ -476,7 +639,8 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
476 trace_regmap_hw_read_start(map->dev, reg, 639 trace_regmap_hw_read_start(map->dev, reg,
477 val_len / map->format.val_bytes); 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 val, val_len); 644 val, val_len);
481 645
482 trace_regmap_hw_read_done(map->dev, reg, 646 trace_regmap_hw_read_done(map->dev, reg,
@@ -549,16 +713,32 @@ EXPORT_SYMBOL_GPL(regmap_read);
549int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, 713int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
550 size_t val_len) 714 size_t val_len)
551{ 715{
552 size_t val_count = val_len / map->format.val_bytes; 716 size_t val_bytes = map->format.val_bytes;
553 int ret; 717 size_t val_count = val_len / val_bytes;
554 718 unsigned int v;
555 WARN_ON(!regmap_volatile_range(map, reg, val_count) && 719 int ret, i;
556 map->cache_type != REGCACHE_NONE);
557 720
558 mutex_lock(&map->lock); 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);
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 }
561 740
741 out:
562 mutex_unlock(&map->lock); 742 mutex_unlock(&map->lock);
563 743
564 return ret; 744 return ret;
@@ -712,7 +892,7 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
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 if (map->patch != NULL) { 896 if (map->patch != NULL) {
717 memcpy(map->patch, regs, 897 memcpy(map->patch, regs,
718 num_regs * sizeof(struct reg_default)); 898 num_regs * sizeof(struct reg_default));
diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c
index f5e54fae8ada..838056c3493a 100644
--- a/drivers/mfd/wm831x-core.c
+++ b/drivers/mfd/wm831x-core.c
@@ -1631,7 +1631,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1631 ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID); 1631 ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID);
1632 if (ret < 0) { 1632 if (ret < 0) {
1633 dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret); 1633 dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret);
1634 goto err_regmap; 1634 goto err;
1635 } 1635 }
1636 switch (ret) { 1636 switch (ret) {
1637 case 0x6204: 1637 case 0x6204:
@@ -1640,20 +1640,20 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1640 default: 1640 default:
1641 dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret); 1641 dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret);
1642 ret = -EINVAL; 1642 ret = -EINVAL;
1643 goto err_regmap; 1643 goto err;
1644 } 1644 }
1645 1645
1646 ret = wm831x_reg_read(wm831x, WM831X_REVISION); 1646 ret = wm831x_reg_read(wm831x, WM831X_REVISION);
1647 if (ret < 0) { 1647 if (ret < 0) {
1648 dev_err(wm831x->dev, "Failed to read revision: %d\n", ret); 1648 dev_err(wm831x->dev, "Failed to read revision: %d\n", ret);
1649 goto err_regmap; 1649 goto err;
1650 } 1650 }
1651 rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT; 1651 rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT;
1652 1652
1653 ret = wm831x_reg_read(wm831x, WM831X_RESET_ID); 1653 ret = wm831x_reg_read(wm831x, WM831X_RESET_ID);
1654 if (ret < 0) { 1654 if (ret < 0) {
1655 dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret); 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 /* Some engineering samples do not have the ID set, rely on 1659 /* Some engineering samples do not have the ID set, rely on
@@ -1728,7 +1728,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1728 default: 1728 default:
1729 dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret); 1729 dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
1730 ret = -EINVAL; 1730 ret = -EINVAL;
1731 goto err_regmap; 1731 goto err;
1732 } 1732 }
1733 1733
1734 /* This will need revisiting in future but is OK for all 1734 /* This will need revisiting in future but is OK for all
@@ -1742,7 +1742,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1742 ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY); 1742 ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
1743 if (ret < 0) { 1743 if (ret < 0) {
1744 dev_err(wm831x->dev, "Failed to read security key: %d\n", ret); 1744 dev_err(wm831x->dev, "Failed to read security key: %d\n", ret);
1745 goto err_regmap; 1745 goto err;
1746 } 1746 }
1747 if (ret != 0) { 1747 if (ret != 0) {
1748 dev_warn(wm831x->dev, "Security key had non-zero value %x\n", 1748 dev_warn(wm831x->dev, "Security key had non-zero value %x\n",
@@ -1755,7 +1755,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1755 ret = pdata->pre_init(wm831x); 1755 ret = pdata->pre_init(wm831x);
1756 if (ret != 0) { 1756 if (ret != 0) {
1757 dev_err(wm831x->dev, "pre_init() failed: %d\n", ret); 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 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1778 1778
1779 ret = wm831x_irq_init(wm831x, irq); 1779 ret = wm831x_irq_init(wm831x, irq);
1780 if (ret != 0) 1780 if (ret != 0)
1781 goto err_regmap; 1781 goto err;
1782 1782
1783 wm831x_auxadc_init(wm831x); 1783 wm831x_auxadc_init(wm831x);
1784 1784
@@ -1874,9 +1874,8 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1874 1874
1875err_irq: 1875err_irq:
1876 wm831x_irq_exit(wm831x); 1876 wm831x_irq_exit(wm831x);
1877err_regmap: 1877err:
1878 mfd_remove_devices(wm831x->dev); 1878 mfd_remove_devices(wm831x->dev);
1879 regmap_exit(wm831x->regmap);
1880 return ret; 1879 return ret;
1881} 1880}
1882 1881
@@ -1887,7 +1886,6 @@ void wm831x_device_exit(struct wm831x *wm831x)
1887 if (wm831x->irq_base) 1886 if (wm831x->irq_base)
1888 free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x); 1887 free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x);
1889 wm831x_irq_exit(wm831x); 1888 wm831x_irq_exit(wm831x);
1890 regmap_exit(wm831x->regmap);
1891} 1889}
1892 1890
1893int wm831x_device_suspend(struct wm831x *wm831x) 1891int wm831x_device_suspend(struct wm831x *wm831x)
diff --git a/drivers/mfd/wm831x-i2c.c b/drivers/mfd/wm831x-i2c.c
index cb15609b0a48..2b29caebc9cf 100644
--- a/drivers/mfd/wm831x-i2c.c
+++ b/drivers/mfd/wm831x-i2c.c
@@ -37,7 +37,7 @@ static int wm831x_i2c_probe(struct i2c_client *i2c,
37 i2c_set_clientdata(i2c, wm831x); 37 i2c_set_clientdata(i2c, wm831x);
38 wm831x->dev = &i2c->dev; 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 if (IS_ERR(wm831x->regmap)) { 41 if (IS_ERR(wm831x->regmap)) {
42 ret = PTR_ERR(wm831x->regmap); 42 ret = PTR_ERR(wm831x->regmap);
43 dev_err(wm831x->dev, "Failed to allocate register map: %d\n", 43 dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
diff --git a/drivers/mfd/wm831x-spi.c b/drivers/mfd/wm831x-spi.c
index 62ef3254105f..745c87945664 100644
--- a/drivers/mfd/wm831x-spi.c
+++ b/drivers/mfd/wm831x-spi.c
@@ -40,7 +40,7 @@ static int __devinit wm831x_spi_probe(struct spi_device *spi)
40 dev_set_drvdata(&spi->dev, wm831x); 40 dev_set_drvdata(&spi->dev, wm831x);
41 wm831x->dev = &spi->dev; 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 if (IS_ERR(wm831x->regmap)) { 44 if (IS_ERR(wm831x->regmap)) {
45 ret = PTR_ERR(wm831x->regmap); 45 ret = PTR_ERR(wm831x->regmap);
46 dev_err(wm831x->dev, "Failed to allocate register map: %d\n", 46 dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
diff --git a/drivers/mfd/wm8400-core.c b/drivers/mfd/wm8400-core.c
index 2204893444a6..237764ae5f9b 100644
--- a/drivers/mfd/wm8400-core.c
+++ b/drivers/mfd/wm8400-core.c
@@ -350,7 +350,7 @@ static int wm8400_i2c_probe(struct i2c_client *i2c,
350 goto err; 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 if (IS_ERR(wm8400->regmap)) { 354 if (IS_ERR(wm8400->regmap)) {
355 ret = PTR_ERR(wm8400->regmap); 355 ret = PTR_ERR(wm8400->regmap);
356 goto err; 356 goto err;
@@ -361,12 +361,10 @@ static int wm8400_i2c_probe(struct i2c_client *i2c,
361 361
362 ret = wm8400_init(wm8400, i2c->dev.platform_data); 362 ret = wm8400_init(wm8400, i2c->dev.platform_data);
363 if (ret != 0) 363 if (ret != 0)
364 goto map_err; 364 goto err;
365 365
366 return 0; 366 return 0;
367 367
368map_err:
369 regmap_exit(wm8400->regmap);
370err: 368err:
371 return ret; 369 return ret;
372} 370}
@@ -376,7 +374,6 @@ static int wm8400_i2c_remove(struct i2c_client *i2c)
376 struct wm8400 *wm8400 = i2c_get_clientdata(i2c); 374 struct wm8400 *wm8400 = i2c_get_clientdata(i2c);
377 375
378 wm8400_release(wm8400); 376 wm8400_release(wm8400);
379 regmap_exit(wm8400->regmap);
380 377
381 return 0; 378 return 0;
382} 379}
diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c
index a04b3c108c8c..98733d408fee 100644
--- a/drivers/mfd/wm8994-core.c
+++ b/drivers/mfd/wm8994-core.c
@@ -359,15 +359,38 @@ static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo)
359} 359}
360#endif 360#endif
361 361
362static const __devinitdata struct reg_default wm8994_revc_patch[] = {
363 { 0x102, 0x3 },
364 { 0x56, 0x3 },
365 { 0x817, 0x0 },
366 { 0x102, 0x0 },
367};
368
369static const __devinitdata struct reg_default wm8958_reva_patch[] = {
370 { 0x102, 0x3 },
371 { 0xcb, 0x81 },
372 { 0x817, 0x0 },
373 { 0x102, 0x0 },
374};
375
376static 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 * Instantiate the generic non-control parts of the device. 385 * Instantiate the generic non-control parts of the device.
364 */ 386 */
365static int wm8994_device_init(struct wm8994 *wm8994, int irq) 387static __devinit int wm8994_device_init(struct wm8994 *wm8994, int irq)
366{ 388{
367 struct wm8994_pdata *pdata = wm8994->dev->platform_data; 389 struct wm8994_pdata *pdata = wm8994->dev->platform_data;
368 struct regmap_config *regmap_config; 390 struct regmap_config *regmap_config;
391 const struct reg_default *regmap_patch = NULL;
369 const char *devname; 392 const char *devname;
370 int ret, i; 393 int ret, i, patch_regs;
371 int pulls = 0; 394 int pulls = 0;
372 395
373 dev_set_drvdata(wm8994->dev, wm8994); 396 dev_set_drvdata(wm8994->dev, wm8994);
@@ -379,7 +402,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
379 NULL, 0); 402 NULL, 0);
380 if (ret != 0) { 403 if (ret != 0) {
381 dev_err(wm8994->dev, "Failed to add children: %d\n", ret); 404 dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
382 goto err_regmap; 405 goto err;
383 } 406 }
384 407
385 switch (wm8994->type) { 408 switch (wm8994->type) {
@@ -394,7 +417,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
394 break; 417 break;
395 default: 418 default:
396 BUG(); 419 BUG();
397 goto err_regmap; 420 goto err;
398 } 421 }
399 422
400 wm8994->supplies = devm_kzalloc(wm8994->dev, 423 wm8994->supplies = devm_kzalloc(wm8994->dev,
@@ -402,7 +425,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
402 wm8994->num_supplies, GFP_KERNEL); 425 wm8994->num_supplies, GFP_KERNEL);
403 if (!wm8994->supplies) { 426 if (!wm8994->supplies) {
404 ret = -ENOMEM; 427 ret = -ENOMEM;
405 goto err_regmap; 428 goto err;
406 } 429 }
407 430
408 switch (wm8994->type) { 431 switch (wm8994->type) {
@@ -420,14 +443,14 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
420 break; 443 break;
421 default: 444 default:
422 BUG(); 445 BUG();
423 goto err_regmap; 446 goto err;
424 } 447 }
425 448
426 ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies, 449 ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies,
427 wm8994->supplies); 450 wm8994->supplies);
428 if (ret != 0) { 451 if (ret != 0) {
429 dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret); 452 dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret);
430 goto err_regmap; 453 goto err;
431 } 454 }
432 455
433 ret = regulator_bulk_enable(wm8994->num_supplies, 456 ret = regulator_bulk_enable(wm8994->num_supplies,
@@ -488,15 +511,44 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
488 "revision %c not fully supported\n", 511 "revision %c not fully supported\n",
489 'A' + wm8994->revision); 512 'A' + wm8994->revision);
490 break; 513 break;
514 case 2:
515 case 3:
516 regmap_patch = wm8994_revc_patch;
517 patch_regs = ARRAY_SIZE(wm8994_revc_patch);
518 break;
519 default:
520 break;
521 }
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;
491 default: 530 default:
492 break; 531 break;
493 } 532 }
494 break; 533 break;
534
495 case WM1811: 535 case WM1811:
496 /* Revision C did not change the relevant layer */ 536 /* Revision C did not change the relevant layer */
497 if (wm8994->revision > 1) 537 if (wm8994->revision > 1)
498 wm8994->revision++; 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 break; 550 break;
551
500 default: 552 default:
501 break; 553 break;
502 } 554 }
@@ -526,6 +578,16 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
526 return ret; 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 if (pdata) { 591 if (pdata) {
530 wm8994->irq_base = pdata->irq_base; 592 wm8994->irq_base = pdata->irq_base;
531 wm8994->gpio_base = pdata->gpio_base; 593 wm8994->gpio_base = pdata->gpio_base;
@@ -588,13 +650,12 @@ err_enable:
588 wm8994->supplies); 650 wm8994->supplies);
589err_get: 651err_get:
590 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); 652 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
591err_regmap: 653err:
592 regmap_exit(wm8994->regmap);
593 mfd_remove_devices(wm8994->dev); 654 mfd_remove_devices(wm8994->dev);
594 return ret; 655 return ret;
595} 656}
596 657
597static void wm8994_device_exit(struct wm8994 *wm8994) 658static __devexit void wm8994_device_exit(struct wm8994 *wm8994)
598{ 659{
599 pm_runtime_disable(wm8994->dev); 660 pm_runtime_disable(wm8994->dev);
600 mfd_remove_devices(wm8994->dev); 661 mfd_remove_devices(wm8994->dev);
@@ -602,7 +663,6 @@ static void wm8994_device_exit(struct wm8994 *wm8994)
602 regulator_bulk_disable(wm8994->num_supplies, 663 regulator_bulk_disable(wm8994->num_supplies,
603 wm8994->supplies); 664 wm8994->supplies);
604 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); 665 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
605 regmap_exit(wm8994->regmap);
606} 666}
607 667
608static const struct of_device_id wm8994_of_match[] = { 668static const struct of_device_id wm8994_of_match[] = {
@@ -613,8 +673,8 @@ static const struct of_device_id wm8994_of_match[] = {
613}; 673};
614MODULE_DEVICE_TABLE(of, wm8994_of_match); 674MODULE_DEVICE_TABLE(of, wm8994_of_match);
615 675
616static int wm8994_i2c_probe(struct i2c_client *i2c, 676static __devinit int wm8994_i2c_probe(struct i2c_client *i2c,
617 const struct i2c_device_id *id) 677 const struct i2c_device_id *id)
618{ 678{
619 struct wm8994 *wm8994; 679 struct wm8994 *wm8994;
620 int ret; 680 int ret;
@@ -628,7 +688,7 @@ static int wm8994_i2c_probe(struct i2c_client *i2c,
628 wm8994->irq = i2c->irq; 688 wm8994->irq = i2c->irq;
629 wm8994->type = id->driver_data; 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 if (IS_ERR(wm8994->regmap)) { 692 if (IS_ERR(wm8994->regmap)) {
633 ret = PTR_ERR(wm8994->regmap); 693 ret = PTR_ERR(wm8994->regmap);
634 dev_err(wm8994->dev, "Failed to allocate register map: %d\n", 694 dev_err(wm8994->dev, "Failed to allocate register map: %d\n",
@@ -639,7 +699,7 @@ static int wm8994_i2c_probe(struct i2c_client *i2c,
639 return wm8994_device_init(wm8994, i2c->irq); 699 return wm8994_device_init(wm8994, i2c->irq);
640} 700}
641 701
642static int wm8994_i2c_remove(struct i2c_client *i2c) 702static __devexit int wm8994_i2c_remove(struct i2c_client *i2c)
643{ 703{
644 struct wm8994 *wm8994 = i2c_get_clientdata(i2c); 704 struct wm8994 *wm8994 = i2c_get_clientdata(i2c);
645 705
@@ -668,7 +728,7 @@ static struct i2c_driver wm8994_i2c_driver = {
668 .of_match_table = wm8994_of_match, 728 .of_match_table = wm8994_of_match,
669 }, 729 },
670 .probe = wm8994_i2c_probe, 730 .probe = wm8994_i2c_probe,
671 .remove = wm8994_i2c_remove, 731 .remove = __devexit_p(wm8994_i2c_remove),
672 .id_table = wm8994_i2c_id, 732 .id_table = wm8994_i2c_id,
673}; 733};
674 734