blob: 0bcda488f11cd45e6252e113ffd025b058309e99 [file] [log] [blame]
Mark Brownb83a3132011-05-11 19:59:58 +02001/*
2 * Register map access API
3 *
4 * Copyright 2011 Wolfson Microelectronics plc
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
Stephen Warrenf5d6eba2012-03-09 13:17:28 -070013#include <linux/device.h>
Mark Brownb83a3132011-05-11 19:59:58 +020014#include <linux/slab.h>
Paul Gortmaker19694b52012-02-28 19:28:02 -050015#include <linux/export.h>
Mark Brownb83a3132011-05-11 19:59:58 +020016#include <linux/mutex.h>
17#include <linux/err.h>
18
Mark Brownfb2736b2011-07-24 21:30:55 +010019#define CREATE_TRACE_POINTS
20#include <trace/events/regmap.h>
21
Mark Brown93de9122011-07-20 22:35:37 +010022#include "internal.h"
Mark Brownb83a3132011-05-11 19:59:58 +020023
Mark Brown8de2f082011-08-10 17:14:41 +090024bool regmap_writeable(struct regmap *map, unsigned int reg)
25{
26 if (map->max_register && reg > map->max_register)
27 return false;
28
29 if (map->writeable_reg)
30 return map->writeable_reg(map->dev, reg);
31
32 return true;
33}
34
35bool regmap_readable(struct regmap *map, unsigned int reg)
36{
37 if (map->max_register && reg > map->max_register)
38 return false;
39
Wolfram Sang4191f192012-01-30 15:08:16 +010040 if (map->format.format_write)
41 return false;
42
Mark Brown8de2f082011-08-10 17:14:41 +090043 if (map->readable_reg)
44 return map->readable_reg(map->dev, reg);
45
46 return true;
47}
48
49bool regmap_volatile(struct regmap *map, unsigned int reg)
50{
Wolfram Sang4191f192012-01-30 15:08:16 +010051 if (!regmap_readable(map, reg))
Mark Brown8de2f082011-08-10 17:14:41 +090052 return false;
53
54 if (map->volatile_reg)
55 return map->volatile_reg(map->dev, reg);
56
57 return true;
58}
59
60bool regmap_precious(struct regmap *map, unsigned int reg)
61{
Wolfram Sang4191f192012-01-30 15:08:16 +010062 if (!regmap_readable(map, reg))
Mark Brown8de2f082011-08-10 17:14:41 +090063 return false;
64
65 if (map->precious_reg)
66 return map->precious_reg(map->dev, reg);
67
68 return false;
69}
70
Lars-Peter Clausen82cd9962011-11-08 18:37:25 +010071static bool regmap_volatile_range(struct regmap *map, unsigned int reg,
72 unsigned int num)
73{
74 unsigned int i;
75
76 for (i = 0; i < num; i++)
77 if (!regmap_volatile(map, reg + i))
78 return false;
79
80 return true;
81}
82
Wolfram Sang9aa50752012-01-27 16:10:22 +010083static 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
Mark Brownb83a3132011-05-11 19:59:58 +020091static void regmap_format_4_12_write(struct regmap *map,
92 unsigned int reg, unsigned int val)
93{
94 __be16 *out = map->work_buf;
95 *out = cpu_to_be16((reg << 12) | val);
96}
97
98static void regmap_format_7_9_write(struct regmap *map,
99 unsigned int reg, unsigned int val)
100{
101 __be16 *out = map->work_buf;
102 *out = cpu_to_be16((reg << 9) | val);
103}
104
Lars-Peter Clausen7e5ec632011-11-16 16:28:21 +0100105static void regmap_format_10_14_write(struct regmap *map,
106 unsigned int reg, unsigned int val)
107{
108 u8 *out = map->work_buf;
109
110 out[2] = val;
111 out[1] = (val >> 8) | (reg << 6);
112 out[0] = reg >> 2;
113}
114
Marc Reillyd939fb92012-03-16 12:11:43 +1100115static void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
Mark Brownb83a3132011-05-11 19:59:58 +0200116{
117 u8 *b = buf;
118
Marc Reillyd939fb92012-03-16 12:11:43 +1100119 b[0] = val << shift;
Mark Brownb83a3132011-05-11 19:59:58 +0200120}
121
Marc Reillyd939fb92012-03-16 12:11:43 +1100122static void regmap_format_16(void *buf, unsigned int val, unsigned int shift)
Mark Brownb83a3132011-05-11 19:59:58 +0200123{
124 __be16 *b = buf;
125
Marc Reillyd939fb92012-03-16 12:11:43 +1100126 b[0] = cpu_to_be16(val << shift);
Mark Brownb83a3132011-05-11 19:59:58 +0200127}
128
Marc Reillyd939fb92012-03-16 12:11:43 +1100129static void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
Marc Reillyea279fc2012-03-16 12:11:42 +1100130{
131 u8 *b = buf;
132
Marc Reillyd939fb92012-03-16 12:11:43 +1100133 val <<= shift;
134
Marc Reillyea279fc2012-03-16 12:11:42 +1100135 b[0] = val >> 16;
136 b[1] = val >> 8;
137 b[2] = val;
138}
139
Marc Reillyd939fb92012-03-16 12:11:43 +1100140static void regmap_format_32(void *buf, unsigned int val, unsigned int shift)
Mark Brown7d5e5252012-02-17 15:58:25 -0800141{
142 __be32 *b = buf;
143
Marc Reillyd939fb92012-03-16 12:11:43 +1100144 b[0] = cpu_to_be32(val << shift);
Mark Brown7d5e5252012-02-17 15:58:25 -0800145}
146
Mark Brownb83a3132011-05-11 19:59:58 +0200147static unsigned int regmap_parse_8(void *buf)
148{
149 u8 *b = buf;
150
151 return b[0];
152}
153
154static unsigned int regmap_parse_16(void *buf)
155{
156 __be16 *b = buf;
157
158 b[0] = be16_to_cpu(b[0]);
159
160 return b[0];
161}
162
Marc Reillyea279fc2012-03-16 12:11:42 +1100163static unsigned int regmap_parse_24(void *buf)
164{
165 u8 *b = buf;
166 unsigned int ret = b[2];
167 ret |= ((unsigned int)b[1]) << 8;
168 ret |= ((unsigned int)b[0]) << 16;
169
170 return ret;
171}
172
Mark Brown7d5e5252012-02-17 15:58:25 -0800173static unsigned int regmap_parse_32(void *buf)
174{
175 __be32 *b = buf;
176
177 b[0] = be32_to_cpu(b[0]);
178
179 return b[0];
180}
181
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600182static void regmap_lock_mutex(struct regmap *map)
183{
184 mutex_lock(&map->mutex);
185}
186
187static void regmap_unlock_mutex(struct regmap *map)
188{
189 mutex_unlock(&map->mutex);
190}
191
192static void regmap_lock_spinlock(struct regmap *map)
193{
194 spin_lock(&map->spinlock);
195}
196
197static void regmap_unlock_spinlock(struct regmap *map)
198{
199 spin_unlock(&map->spinlock);
200}
201
Mark Brown72b39f62012-05-08 17:44:40 +0100202static void dev_get_regmap_release(struct device *dev, void *res)
203{
204 /*
205 * We don't actually have anything to do here; the goal here
206 * is not to manage the regmap but to provide a simple way to
207 * get the regmap back given a struct device.
208 */
209}
210
Mark Brownb83a3132011-05-11 19:59:58 +0200211/**
212 * regmap_init(): Initialise register map
213 *
214 * @dev: Device that will be interacted with
215 * @bus: Bus-specific callbacks to use with device
Stephen Warren0135bbc2012-04-04 15:48:30 -0600216 * @bus_context: Data passed to bus-specific callbacks
Mark Brownb83a3132011-05-11 19:59:58 +0200217 * @config: Configuration for register map
218 *
219 * The return value will be an ERR_PTR() on error or a valid pointer to
220 * a struct regmap. This function should generally not be called
221 * directly, it should be called by bus-specific init functions.
222 */
223struct regmap *regmap_init(struct device *dev,
224 const struct regmap_bus *bus,
Stephen Warren0135bbc2012-04-04 15:48:30 -0600225 void *bus_context,
Mark Brownb83a3132011-05-11 19:59:58 +0200226 const struct regmap_config *config)
227{
Mark Brown72b39f62012-05-08 17:44:40 +0100228 struct regmap *map, **m;
Mark Brownb83a3132011-05-11 19:59:58 +0200229 int ret = -EINVAL;
230
231 if (!bus || !config)
Lars-Peter Clausenabbb18f2011-11-14 10:40:15 +0100232 goto err;
Mark Brownb83a3132011-05-11 19:59:58 +0200233
234 map = kzalloc(sizeof(*map), GFP_KERNEL);
235 if (map == NULL) {
236 ret = -ENOMEM;
237 goto err;
238 }
239
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600240 if (bus->fast_io) {
241 spin_lock_init(&map->spinlock);
242 map->lock = regmap_lock_spinlock;
243 map->unlock = regmap_unlock_spinlock;
244 } else {
245 mutex_init(&map->mutex);
246 map->lock = regmap_lock_mutex;
247 map->unlock = regmap_unlock_mutex;
248 }
Mark Brownb83a3132011-05-11 19:59:58 +0200249 map->format.buf_size = (config->reg_bits + config->val_bits) / 8;
Wolfram Sangc212acc2012-01-28 02:16:41 +0100250 map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
Mark Brown82159ba2012-01-18 10:52:25 +0000251 map->format.pad_bytes = config->pad_bits / 8;
Wolfram Sangc212acc2012-01-28 02:16:41 +0100252 map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
Mark Brown82159ba2012-01-18 10:52:25 +0000253 map->format.buf_size += map->format.pad_bytes;
Marc Reillyd939fb92012-03-16 12:11:43 +1100254 map->reg_shift = config->pad_bits % 8;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600255 if (config->reg_stride)
256 map->reg_stride = config->reg_stride;
257 else
258 map->reg_stride = 1;
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100259 map->use_single_rw = config->use_single_rw;
Mark Brownb83a3132011-05-11 19:59:58 +0200260 map->dev = dev;
261 map->bus = bus;
Stephen Warren0135bbc2012-04-04 15:48:30 -0600262 map->bus_context = bus_context;
Mark Brown2e2ae662011-07-20 22:33:39 +0100263 map->max_register = config->max_register;
264 map->writeable_reg = config->writeable_reg;
265 map->readable_reg = config->readable_reg;
266 map->volatile_reg = config->volatile_reg;
Mark Brown2efe1642011-08-08 15:41:46 +0900267 map->precious_reg = config->precious_reg;
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100268 map->cache_type = config->cache_type;
Mark Brown72b39f62012-05-08 17:44:40 +0100269 map->name = config->name;
Mark Brownb83a3132011-05-11 19:59:58 +0200270
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200271 if (config->read_flag_mask || config->write_flag_mask) {
272 map->read_flag_mask = config->read_flag_mask;
273 map->write_flag_mask = config->write_flag_mask;
274 } else {
275 map->read_flag_mask = bus->read_flag_mask;
276 }
277
Marc Reillyd939fb92012-03-16 12:11:43 +1100278 switch (config->reg_bits + map->reg_shift) {
Wolfram Sang9aa50752012-01-27 16:10:22 +0100279 case 2:
280 switch (config->val_bits) {
281 case 6:
282 map->format.format_write = regmap_format_2_6_write;
283 break;
284 default:
285 goto err_map;
286 }
287 break;
288
Mark Brownb83a3132011-05-11 19:59:58 +0200289 case 4:
290 switch (config->val_bits) {
291 case 12:
292 map->format.format_write = regmap_format_4_12_write;
293 break;
294 default:
295 goto err_map;
296 }
297 break;
298
299 case 7:
300 switch (config->val_bits) {
301 case 9:
302 map->format.format_write = regmap_format_7_9_write;
303 break;
304 default:
305 goto err_map;
306 }
307 break;
308
Lars-Peter Clausen7e5ec632011-11-16 16:28:21 +0100309 case 10:
310 switch (config->val_bits) {
311 case 14:
312 map->format.format_write = regmap_format_10_14_write;
313 break;
314 default:
315 goto err_map;
316 }
317 break;
318
Mark Brownb83a3132011-05-11 19:59:58 +0200319 case 8:
320 map->format.format_reg = regmap_format_8;
321 break;
322
323 case 16:
324 map->format.format_reg = regmap_format_16;
325 break;
326
Mark Brown7d5e5252012-02-17 15:58:25 -0800327 case 32:
328 map->format.format_reg = regmap_format_32;
329 break;
330
Mark Brownb83a3132011-05-11 19:59:58 +0200331 default:
332 goto err_map;
333 }
334
335 switch (config->val_bits) {
336 case 8:
337 map->format.format_val = regmap_format_8;
338 map->format.parse_val = regmap_parse_8;
339 break;
340 case 16:
341 map->format.format_val = regmap_format_16;
342 map->format.parse_val = regmap_parse_16;
343 break;
Marc Reillyea279fc2012-03-16 12:11:42 +1100344 case 24:
345 map->format.format_val = regmap_format_24;
346 map->format.parse_val = regmap_parse_24;
347 break;
Mark Brown7d5e5252012-02-17 15:58:25 -0800348 case 32:
349 map->format.format_val = regmap_format_32;
350 map->format.parse_val = regmap_parse_32;
351 break;
Mark Brownb83a3132011-05-11 19:59:58 +0200352 }
353
Mark Brown7a647612012-04-30 23:26:32 +0100354 if (map->format.format_write)
355 map->use_single_rw = true;
356
Mark Brownb83a3132011-05-11 19:59:58 +0200357 if (!map->format.format_write &&
358 !(map->format.format_reg && map->format.format_val))
359 goto err_map;
360
Mark Brown82159ba2012-01-18 10:52:25 +0000361 map->work_buf = kzalloc(map->format.buf_size, GFP_KERNEL);
Mark Brownb83a3132011-05-11 19:59:58 +0200362 if (map->work_buf == NULL) {
363 ret = -ENOMEM;
Mark Brown5204f5e2011-09-05 08:07:47 -0700364 goto err_map;
Mark Brownb83a3132011-05-11 19:59:58 +0200365 }
366
Stephen Warrend3c242e2012-04-04 15:48:29 -0600367 regmap_debugfs_init(map, config->name);
Mark Brown052d2cd2011-11-21 19:05:13 +0000368
Lars-Peter Clausene5e3b8a2011-11-16 16:28:16 +0100369 ret = regcache_init(map, config);
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100370 if (ret < 0)
Lars-Peter Clausen58072cb2011-11-10 18:15:15 +0100371 goto err_free_workbuf;
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100372
Mark Brown72b39f62012-05-08 17:44:40 +0100373 /* Add a devres resource for dev_get_regmap() */
374 m = devres_alloc(dev_get_regmap_release, sizeof(*m), GFP_KERNEL);
375 if (!m) {
376 ret = -ENOMEM;
377 goto err_cache;
378 }
379 *m = map;
380 devres_add(dev, m);
381
Mark Brownb83a3132011-05-11 19:59:58 +0200382 return map;
383
Mark Brown72b39f62012-05-08 17:44:40 +0100384err_cache:
385 regcache_exit(map);
Lars-Peter Clausen58072cb2011-11-10 18:15:15 +0100386err_free_workbuf:
387 kfree(map->work_buf);
Mark Brownb83a3132011-05-11 19:59:58 +0200388err_map:
389 kfree(map);
390err:
391 return ERR_PTR(ret);
392}
393EXPORT_SYMBOL_GPL(regmap_init);
394
Mark Brownc0eb4672012-01-30 19:56:52 +0000395static void devm_regmap_release(struct device *dev, void *res)
396{
397 regmap_exit(*(struct regmap **)res);
398}
399
400/**
401 * devm_regmap_init(): Initialise managed register map
402 *
403 * @dev: Device that will be interacted with
404 * @bus: Bus-specific callbacks to use with device
Stephen Warren0135bbc2012-04-04 15:48:30 -0600405 * @bus_context: Data passed to bus-specific callbacks
Mark Brownc0eb4672012-01-30 19:56:52 +0000406 * @config: Configuration for register map
407 *
408 * The return value will be an ERR_PTR() on error or a valid pointer
409 * to a struct regmap. This function should generally not be called
410 * directly, it should be called by bus-specific init functions. The
411 * map will be automatically freed by the device management code.
412 */
413struct regmap *devm_regmap_init(struct device *dev,
414 const struct regmap_bus *bus,
Stephen Warren0135bbc2012-04-04 15:48:30 -0600415 void *bus_context,
Mark Brownc0eb4672012-01-30 19:56:52 +0000416 const struct regmap_config *config)
417{
418 struct regmap **ptr, *regmap;
419
420 ptr = devres_alloc(devm_regmap_release, sizeof(*ptr), GFP_KERNEL);
421 if (!ptr)
422 return ERR_PTR(-ENOMEM);
423
Stephen Warren0135bbc2012-04-04 15:48:30 -0600424 regmap = regmap_init(dev, bus, bus_context, config);
Mark Brownc0eb4672012-01-30 19:56:52 +0000425 if (!IS_ERR(regmap)) {
426 *ptr = regmap;
427 devres_add(dev, ptr);
428 } else {
429 devres_free(ptr);
430 }
431
432 return regmap;
433}
434EXPORT_SYMBOL_GPL(devm_regmap_init);
435
Mark Brownb83a3132011-05-11 19:59:58 +0200436/**
Mark Brownbf315172011-12-03 17:06:20 +0000437 * regmap_reinit_cache(): Reinitialise the current register cache
438 *
439 * @map: Register map to operate on.
440 * @config: New configuration. Only the cache data will be used.
441 *
442 * Discard any existing register cache for the map and initialize a
443 * new cache. This can be used to restore the cache to defaults or to
444 * update the cache configuration to reflect runtime discovery of the
445 * hardware.
446 */
447int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
448{
449 int ret;
450
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600451 map->lock(map);
Mark Brownbf315172011-12-03 17:06:20 +0000452
453 regcache_exit(map);
Mark Browna24f64a2012-01-26 18:30:16 +0000454 regmap_debugfs_exit(map);
Mark Brownbf315172011-12-03 17:06:20 +0000455
456 map->max_register = config->max_register;
457 map->writeable_reg = config->writeable_reg;
458 map->readable_reg = config->readable_reg;
459 map->volatile_reg = config->volatile_reg;
460 map->precious_reg = config->precious_reg;
461 map->cache_type = config->cache_type;
462
Stephen Warrend3c242e2012-04-04 15:48:29 -0600463 regmap_debugfs_init(map, config->name);
Mark Browna24f64a2012-01-26 18:30:16 +0000464
Mark Brown421e8d22012-01-20 13:39:37 +0000465 map->cache_bypass = false;
466 map->cache_only = false;
467
Mark Brownbf315172011-12-03 17:06:20 +0000468 ret = regcache_init(map, config);
469
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600470 map->unlock(map);
Mark Brownbf315172011-12-03 17:06:20 +0000471
472 return ret;
473}
474
475/**
Mark Brownb83a3132011-05-11 19:59:58 +0200476 * regmap_exit(): Free a previously allocated register map
477 */
478void regmap_exit(struct regmap *map)
479{
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100480 regcache_exit(map);
Mark Brown31244e32011-07-20 22:56:53 +0100481 regmap_debugfs_exit(map);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600482 if (map->bus->free_context)
483 map->bus->free_context(map->bus_context);
Mark Brownb83a3132011-05-11 19:59:58 +0200484 kfree(map->work_buf);
Mark Brownb83a3132011-05-11 19:59:58 +0200485 kfree(map);
486}
487EXPORT_SYMBOL_GPL(regmap_exit);
488
Mark Brown72b39f62012-05-08 17:44:40 +0100489static int dev_get_regmap_match(struct device *dev, void *res, void *data)
490{
491 struct regmap **r = res;
492 if (!r || !*r) {
493 WARN_ON(!r || !*r);
494 return 0;
495 }
496
497 /* If the user didn't specify a name match any */
498 if (data)
499 return (*r)->name == data;
500 else
501 return 1;
502}
503
504/**
505 * dev_get_regmap(): Obtain the regmap (if any) for a device
506 *
507 * @dev: Device to retrieve the map for
508 * @name: Optional name for the register map, usually NULL.
509 *
510 * Returns the regmap for the device if one is present, or NULL. If
511 * name is specified then it must match the name specified when
512 * registering the device, if it is NULL then the first regmap found
513 * will be used. Devices with multiple register maps are very rare,
514 * generic code should normally not need to specify a name.
515 */
516struct regmap *dev_get_regmap(struct device *dev, const char *name)
517{
518 struct regmap **r = devres_find(dev, dev_get_regmap_release,
519 dev_get_regmap_match, (void *)name);
520
521 if (!r)
522 return NULL;
523 return *r;
524}
525EXPORT_SYMBOL_GPL(dev_get_regmap);
526
Mark Brownb83a3132011-05-11 19:59:58 +0200527static int _regmap_raw_write(struct regmap *map, unsigned int reg,
528 const void *val, size_t val_len)
529{
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200530 u8 *u8 = map->work_buf;
Mark Brownb83a3132011-05-11 19:59:58 +0200531 void *buf;
532 int ret = -ENOTSUPP;
533 size_t len;
Mark Brown73304782011-07-24 11:46:20 +0100534 int i;
535
536 /* Check for unwritable registers before we start */
537 if (map->writeable_reg)
538 for (i = 0; i < val_len / map->format.val_bytes; i++)
Stephen Warrenf01ee602012-04-09 13:40:24 -0600539 if (!map->writeable_reg(map->dev,
540 reg + (i * map->reg_stride)))
Mark Brown73304782011-07-24 11:46:20 +0100541 return -EINVAL;
Mark Brownb83a3132011-05-11 19:59:58 +0200542
Laxman Dewanganc9157192012-02-10 21:30:27 +0530543 if (!map->cache_bypass && map->format.parse_val) {
544 unsigned int ival;
545 int val_bytes = map->format.val_bytes;
546 for (i = 0; i < val_len / val_bytes; i++) {
547 memcpy(map->work_buf, val + (i * val_bytes), val_bytes);
548 ival = map->format.parse_val(map->work_buf);
Stephen Warrenf01ee602012-04-09 13:40:24 -0600549 ret = regcache_write(map, reg + (i * map->reg_stride),
550 ival);
Laxman Dewanganc9157192012-02-10 21:30:27 +0530551 if (ret) {
552 dev_err(map->dev,
553 "Error in caching of register: %u ret: %d\n",
554 reg + i, ret);
555 return ret;
556 }
557 }
558 if (map->cache_only) {
559 map->cache_dirty = true;
560 return 0;
561 }
562 }
563
Marc Reillyd939fb92012-03-16 12:11:43 +1100564 map->format.format_reg(map->work_buf, reg, map->reg_shift);
Mark Brownb83a3132011-05-11 19:59:58 +0200565
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200566 u8[0] |= map->write_flag_mask;
567
Mark Brownfb2736b2011-07-24 21:30:55 +0100568 trace_regmap_hw_write_start(map->dev, reg,
569 val_len / map->format.val_bytes);
570
Mark Brown2547e202011-07-20 21:47:22 +0100571 /* If we're doing a single register write we can probably just
572 * send the work_buf directly, otherwise try to do a gather
573 * write.
574 */
Mark Brown82159ba2012-01-18 10:52:25 +0000575 if (val == (map->work_buf + map->format.pad_bytes +
576 map->format.reg_bytes))
Stephen Warren0135bbc2012-04-04 15:48:30 -0600577 ret = map->bus->write(map->bus_context, map->work_buf,
Mark Brown82159ba2012-01-18 10:52:25 +0000578 map->format.reg_bytes +
579 map->format.pad_bytes +
580 val_len);
Mark Brown2547e202011-07-20 21:47:22 +0100581 else if (map->bus->gather_write)
Stephen Warren0135bbc2012-04-04 15:48:30 -0600582 ret = map->bus->gather_write(map->bus_context, map->work_buf,
Mark Brown82159ba2012-01-18 10:52:25 +0000583 map->format.reg_bytes +
584 map->format.pad_bytes,
Mark Brownb83a3132011-05-11 19:59:58 +0200585 val, val_len);
586
Mark Brown2547e202011-07-20 21:47:22 +0100587 /* If that didn't work fall back on linearising by hand. */
Mark Brownb83a3132011-05-11 19:59:58 +0200588 if (ret == -ENOTSUPP) {
Mark Brown82159ba2012-01-18 10:52:25 +0000589 len = map->format.reg_bytes + map->format.pad_bytes + val_len;
590 buf = kzalloc(len, GFP_KERNEL);
Mark Brownb83a3132011-05-11 19:59:58 +0200591 if (!buf)
592 return -ENOMEM;
593
594 memcpy(buf, map->work_buf, map->format.reg_bytes);
Mark Brown82159ba2012-01-18 10:52:25 +0000595 memcpy(buf + map->format.reg_bytes + map->format.pad_bytes,
596 val, val_len);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600597 ret = map->bus->write(map->bus_context, buf, len);
Mark Brownb83a3132011-05-11 19:59:58 +0200598
599 kfree(buf);
600 }
601
Mark Brownfb2736b2011-07-24 21:30:55 +0100602 trace_regmap_hw_write_done(map->dev, reg,
603 val_len / map->format.val_bytes);
604
Mark Brownb83a3132011-05-11 19:59:58 +0200605 return ret;
606}
607
Dimitris Papastamos4d2dc092011-09-29 10:39:07 +0100608int _regmap_write(struct regmap *map, unsigned int reg,
609 unsigned int val)
Mark Brownb83a3132011-05-11 19:59:58 +0200610{
Mark Brownfb2736b2011-07-24 21:30:55 +0100611 int ret;
Mark Brownb83a3132011-05-11 19:59:58 +0200612 BUG_ON(!map->format.format_write && !map->format.format_val);
613
Laxman Dewanganc9157192012-02-10 21:30:27 +0530614 if (!map->cache_bypass && map->format.format_write) {
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100615 ret = regcache_write(map, reg, val);
616 if (ret != 0)
617 return ret;
Mark Brown8ae0d7e2011-10-26 10:34:22 +0200618 if (map->cache_only) {
619 map->cache_dirty = true;
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100620 return 0;
Mark Brown8ae0d7e2011-10-26 10:34:22 +0200621 }
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100622 }
623
Mark Brownfb2736b2011-07-24 21:30:55 +0100624 trace_regmap_reg_write(map->dev, reg, val);
625
Mark Brownb83a3132011-05-11 19:59:58 +0200626 if (map->format.format_write) {
627 map->format.format_write(map, reg, val);
628
Mark Brownfb2736b2011-07-24 21:30:55 +0100629 trace_regmap_hw_write_start(map->dev, reg, 1);
630
Stephen Warren0135bbc2012-04-04 15:48:30 -0600631 ret = map->bus->write(map->bus_context, map->work_buf,
Mark Brownfb2736b2011-07-24 21:30:55 +0100632 map->format.buf_size);
633
634 trace_regmap_hw_write_done(map->dev, reg, 1);
635
636 return ret;
Mark Brownb83a3132011-05-11 19:59:58 +0200637 } else {
Mark Brown82159ba2012-01-18 10:52:25 +0000638 map->format.format_val(map->work_buf + map->format.reg_bytes
Marc Reillyd939fb92012-03-16 12:11:43 +1100639 + map->format.pad_bytes, val, 0);
Mark Brownb83a3132011-05-11 19:59:58 +0200640 return _regmap_raw_write(map, reg,
Mark Brown82159ba2012-01-18 10:52:25 +0000641 map->work_buf +
642 map->format.reg_bytes +
643 map->format.pad_bytes,
Mark Brownb83a3132011-05-11 19:59:58 +0200644 map->format.val_bytes);
645 }
646}
647
648/**
649 * regmap_write(): Write a value to a single register
650 *
651 * @map: Register map to write to
652 * @reg: Register to write to
653 * @val: Value to be written
654 *
655 * A value of zero will be returned on success, a negative errno will
656 * be returned in error cases.
657 */
658int regmap_write(struct regmap *map, unsigned int reg, unsigned int val)
659{
660 int ret;
661
Stephen Warrenf01ee602012-04-09 13:40:24 -0600662 if (reg % map->reg_stride)
663 return -EINVAL;
664
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600665 map->lock(map);
Mark Brownb83a3132011-05-11 19:59:58 +0200666
667 ret = _regmap_write(map, reg, val);
668
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600669 map->unlock(map);
Mark Brownb83a3132011-05-11 19:59:58 +0200670
671 return ret;
672}
673EXPORT_SYMBOL_GPL(regmap_write);
674
675/**
676 * regmap_raw_write(): Write raw values to one or more registers
677 *
678 * @map: Register map to write to
679 * @reg: Initial register to write to
680 * @val: Block of data to be written, laid out for direct transmission to the
681 * device
682 * @val_len: Length of data pointed to by val.
683 *
684 * This function is intended to be used for things like firmware
685 * download where a large block of data needs to be transferred to the
686 * device. No formatting will be done on the data provided.
687 *
688 * A value of zero will be returned on success, a negative errno will
689 * be returned in error cases.
690 */
691int regmap_raw_write(struct regmap *map, unsigned int reg,
692 const void *val, size_t val_len)
693{
694 int ret;
695
Stephen Warren851960b2012-04-06 15:16:03 -0600696 if (val_len % map->format.val_bytes)
697 return -EINVAL;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600698 if (reg % map->reg_stride)
699 return -EINVAL;
Stephen Warren851960b2012-04-06 15:16:03 -0600700
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600701 map->lock(map);
Mark Brownb83a3132011-05-11 19:59:58 +0200702
703 ret = _regmap_raw_write(map, reg, val, val_len);
704
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600705 map->unlock(map);
Mark Brownb83a3132011-05-11 19:59:58 +0200706
707 return ret;
708}
709EXPORT_SYMBOL_GPL(regmap_raw_write);
710
Laxman Dewangan8eaeb212012-02-12 19:49:43 +0530711/*
712 * regmap_bulk_write(): Write multiple registers to the device
713 *
714 * @map: Register map to write to
715 * @reg: First register to be write from
716 * @val: Block of data to be written, in native register size for device
717 * @val_count: Number of registers to write
718 *
719 * This function is intended to be used for writing a large block of
720 * data to be device either in single transfer or multiple transfer.
721 *
722 * A value of zero will be returned on success, a negative errno will
723 * be returned in error cases.
724 */
725int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
726 size_t val_count)
727{
728 int ret = 0, i;
729 size_t val_bytes = map->format.val_bytes;
730 void *wval;
731
732 if (!map->format.parse_val)
733 return -EINVAL;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600734 if (reg % map->reg_stride)
735 return -EINVAL;
Laxman Dewangan8eaeb212012-02-12 19:49:43 +0530736
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600737 map->lock(map);
Laxman Dewangan8eaeb212012-02-12 19:49:43 +0530738
739 /* No formatting is require if val_byte is 1 */
740 if (val_bytes == 1) {
741 wval = (void *)val;
742 } else {
743 wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL);
744 if (!wval) {
745 ret = -ENOMEM;
746 dev_err(map->dev, "Error in memory allocation\n");
747 goto out;
748 }
749 for (i = 0; i < val_count * val_bytes; i += val_bytes)
750 map->format.parse_val(wval + i);
751 }
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100752 /*
753 * Some devices does not support bulk write, for
754 * them we have a series of single write operations.
755 */
756 if (map->use_single_rw) {
757 for (i = 0; i < val_count; i++) {
758 ret = regmap_raw_write(map,
759 reg + (i * map->reg_stride),
760 val + (i * val_bytes),
761 val_bytes);
762 if (ret != 0)
763 return ret;
764 }
765 } else {
766 ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count);
767 }
Laxman Dewangan8eaeb212012-02-12 19:49:43 +0530768
769 if (val_bytes != 1)
770 kfree(wval);
771
772out:
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600773 map->unlock(map);
Laxman Dewangan8eaeb212012-02-12 19:49:43 +0530774 return ret;
775}
776EXPORT_SYMBOL_GPL(regmap_bulk_write);
777
Mark Brownb83a3132011-05-11 19:59:58 +0200778static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
779 unsigned int val_len)
780{
781 u8 *u8 = map->work_buf;
782 int ret;
783
Marc Reillyd939fb92012-03-16 12:11:43 +1100784 map->format.format_reg(map->work_buf, reg, map->reg_shift);
Mark Brownb83a3132011-05-11 19:59:58 +0200785
786 /*
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200787 * Some buses or devices flag reads by setting the high bits in the
Mark Brownb83a3132011-05-11 19:59:58 +0200788 * register addresss; since it's always the high bits for all
789 * current formats we can do this here rather than in
790 * formatting. This may break if we get interesting formats.
791 */
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200792 u8[0] |= map->read_flag_mask;
Mark Brownb83a3132011-05-11 19:59:58 +0200793
Mark Brownfb2736b2011-07-24 21:30:55 +0100794 trace_regmap_hw_read_start(map->dev, reg,
795 val_len / map->format.val_bytes);
796
Stephen Warren0135bbc2012-04-04 15:48:30 -0600797 ret = map->bus->read(map->bus_context, map->work_buf,
Mark Brown82159ba2012-01-18 10:52:25 +0000798 map->format.reg_bytes + map->format.pad_bytes,
Mark Brown40c5cc22011-07-24 22:39:12 +0100799 val, val_len);
Mark Brownb83a3132011-05-11 19:59:58 +0200800
Mark Brownfb2736b2011-07-24 21:30:55 +0100801 trace_regmap_hw_read_done(map->dev, reg,
802 val_len / map->format.val_bytes);
803
804 return ret;
Mark Brownb83a3132011-05-11 19:59:58 +0200805}
806
807static int _regmap_read(struct regmap *map, unsigned int reg,
808 unsigned int *val)
809{
810 int ret;
811
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100812 if (!map->cache_bypass) {
813 ret = regcache_read(map, reg, val);
814 if (ret == 0)
815 return 0;
816 }
817
Lars-Peter Clausen19254412011-11-16 16:28:19 +0100818 if (!map->format.parse_val)
819 return -EINVAL;
820
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100821 if (map->cache_only)
822 return -EBUSY;
823
Mark Brownb83a3132011-05-11 19:59:58 +0200824 ret = _regmap_raw_read(map, reg, map->work_buf, map->format.val_bytes);
Mark Brownfb2736b2011-07-24 21:30:55 +0100825 if (ret == 0) {
Mark Brownb83a3132011-05-11 19:59:58 +0200826 *val = map->format.parse_val(map->work_buf);
Mark Brownfb2736b2011-07-24 21:30:55 +0100827 trace_regmap_reg_read(map->dev, reg, *val);
828 }
Mark Brownb83a3132011-05-11 19:59:58 +0200829
Mark Brownf2985362012-04-30 21:25:05 +0100830 if (ret == 0 && !map->cache_bypass)
831 regcache_write(map, reg, *val);
832
Mark Brownb83a3132011-05-11 19:59:58 +0200833 return ret;
834}
835
836/**
837 * regmap_read(): Read a value from a single register
838 *
839 * @map: Register map to write to
840 * @reg: Register to be read from
841 * @val: Pointer to store read value
842 *
843 * A value of zero will be returned on success, a negative errno will
844 * be returned in error cases.
845 */
846int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val)
847{
848 int ret;
849
Stephen Warrenf01ee602012-04-09 13:40:24 -0600850 if (reg % map->reg_stride)
851 return -EINVAL;
852
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600853 map->lock(map);
Mark Brownb83a3132011-05-11 19:59:58 +0200854
855 ret = _regmap_read(map, reg, val);
856
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600857 map->unlock(map);
Mark Brownb83a3132011-05-11 19:59:58 +0200858
859 return ret;
860}
861EXPORT_SYMBOL_GPL(regmap_read);
862
863/**
864 * regmap_raw_read(): Read raw data from the device
865 *
866 * @map: Register map to write to
867 * @reg: First register to be read from
868 * @val: Pointer to store read value
869 * @val_len: Size of data to read
870 *
871 * A value of zero will be returned on success, a negative errno will
872 * be returned in error cases.
873 */
874int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
875 size_t val_len)
876{
Mark Brownb8fb5ab2012-02-21 19:12:47 +0000877 size_t val_bytes = map->format.val_bytes;
878 size_t val_count = val_len / val_bytes;
879 unsigned int v;
880 int ret, i;
Mark Brown04e016a2011-10-09 13:35:43 +0100881
Stephen Warren851960b2012-04-06 15:16:03 -0600882 if (val_len % map->format.val_bytes)
883 return -EINVAL;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600884 if (reg % map->reg_stride)
885 return -EINVAL;
Stephen Warren851960b2012-04-06 15:16:03 -0600886
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600887 map->lock(map);
Mark Brownb83a3132011-05-11 19:59:58 +0200888
Mark Brownb8fb5ab2012-02-21 19:12:47 +0000889 if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass ||
890 map->cache_type == REGCACHE_NONE) {
891 /* Physical block read if there's no cache involved */
892 ret = _regmap_raw_read(map, reg, val, val_len);
Mark Brownb83a3132011-05-11 19:59:58 +0200893
Mark Brownb8fb5ab2012-02-21 19:12:47 +0000894 } else {
895 /* Otherwise go word by word for the cache; should be low
896 * cost as we expect to hit the cache.
897 */
898 for (i = 0; i < val_count; i++) {
Stephen Warrenf01ee602012-04-09 13:40:24 -0600899 ret = _regmap_read(map, reg + (i * map->reg_stride),
900 &v);
Mark Brownb8fb5ab2012-02-21 19:12:47 +0000901 if (ret != 0)
902 goto out;
903
Marc Reillyd939fb92012-03-16 12:11:43 +1100904 map->format.format_val(val + (i * val_bytes), v, 0);
Mark Brownb8fb5ab2012-02-21 19:12:47 +0000905 }
906 }
907
908 out:
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600909 map->unlock(map);
Mark Brownb83a3132011-05-11 19:59:58 +0200910
911 return ret;
912}
913EXPORT_SYMBOL_GPL(regmap_raw_read);
914
915/**
916 * regmap_bulk_read(): Read multiple registers from the device
917 *
918 * @map: Register map to write to
919 * @reg: First register to be read from
920 * @val: Pointer to store read value, in native register size for device
921 * @val_count: Number of registers to read
922 *
923 * A value of zero will be returned on success, a negative errno will
924 * be returned in error cases.
925 */
926int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
927 size_t val_count)
928{
929 int ret, i;
930 size_t val_bytes = map->format.val_bytes;
Lars-Peter Clausen82cd9962011-11-08 18:37:25 +0100931 bool vol = regmap_volatile_range(map, reg, val_count);
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100932
Mark Brownb83a3132011-05-11 19:59:58 +0200933 if (!map->format.parse_val)
934 return -EINVAL;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600935 if (reg % map->reg_stride)
936 return -EINVAL;
Mark Brownb83a3132011-05-11 19:59:58 +0200937
Mark Brownde2d8082011-10-10 13:24:52 +0100938 if (vol || map->cache_type == REGCACHE_NONE) {
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100939 /*
940 * Some devices does not support bulk read, for
941 * them we have a series of single read operations.
942 */
943 if (map->use_single_rw) {
944 for (i = 0; i < val_count; i++) {
945 ret = regmap_raw_read(map,
946 reg + (i * map->reg_stride),
947 val + (i * val_bytes),
948 val_bytes);
949 if (ret != 0)
950 return ret;
951 }
952 } else {
953 ret = regmap_raw_read(map, reg, val,
954 val_bytes * val_count);
955 if (ret != 0)
956 return ret;
957 }
Mark Brownde2d8082011-10-10 13:24:52 +0100958
959 for (i = 0; i < val_count * val_bytes; i += val_bytes)
960 map->format.parse_val(val + i);
961 } else {
962 for (i = 0; i < val_count; i++) {
Laxman Dewangan6560ffd2012-05-09 17:43:12 +0530963 unsigned int ival;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600964 ret = regmap_read(map, reg + (i * map->reg_stride),
Mark Brown25061d22012-05-12 13:06:08 +0100965 &ival);
Mark Brownde2d8082011-10-10 13:24:52 +0100966 if (ret != 0)
967 return ret;
Laxman Dewangan6560ffd2012-05-09 17:43:12 +0530968 memcpy(val + (i * val_bytes), &ival, val_bytes);
Mark Brownde2d8082011-10-10 13:24:52 +0100969 }
970 }
Mark Brownb83a3132011-05-11 19:59:58 +0200971
972 return 0;
973}
974EXPORT_SYMBOL_GPL(regmap_bulk_read);
975
Mark Brown018690d2011-11-29 20:10:36 +0000976static int _regmap_update_bits(struct regmap *map, unsigned int reg,
977 unsigned int mask, unsigned int val,
978 bool *change)
Mark Brownb83a3132011-05-11 19:59:58 +0200979{
980 int ret;
Mark Brownd91e8db22011-11-18 16:03:50 +0000981 unsigned int tmp, orig;
Mark Brownb83a3132011-05-11 19:59:58 +0200982
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600983 map->lock(map);
Mark Brownb83a3132011-05-11 19:59:58 +0200984
Mark Brownd91e8db22011-11-18 16:03:50 +0000985 ret = _regmap_read(map, reg, &orig);
Mark Brownb83a3132011-05-11 19:59:58 +0200986 if (ret != 0)
987 goto out;
988
Mark Brownd91e8db22011-11-18 16:03:50 +0000989 tmp = orig & ~mask;
Mark Brownb83a3132011-05-11 19:59:58 +0200990 tmp |= val & mask;
991
Mark Brown018690d2011-11-29 20:10:36 +0000992 if (tmp != orig) {
Mark Brownd91e8db22011-11-18 16:03:50 +0000993 ret = _regmap_write(map, reg, tmp);
Mark Brown018690d2011-11-29 20:10:36 +0000994 *change = true;
995 } else {
996 *change = false;
997 }
Mark Brownb83a3132011-05-11 19:59:58 +0200998
999out:
Stephen Warrenbacdbe02012-04-04 15:48:28 -06001000 map->unlock(map);
Mark Brownb83a3132011-05-11 19:59:58 +02001001
1002 return ret;
1003}
Mark Brown018690d2011-11-29 20:10:36 +00001004
1005/**
1006 * regmap_update_bits: Perform a read/modify/write cycle on the register map
1007 *
1008 * @map: Register map to update
1009 * @reg: Register to update
1010 * @mask: Bitmask to change
1011 * @val: New value for bitmask
1012 *
1013 * Returns zero for success, a negative number on error.
1014 */
1015int regmap_update_bits(struct regmap *map, unsigned int reg,
1016 unsigned int mask, unsigned int val)
1017{
1018 bool change;
1019 return _regmap_update_bits(map, reg, mask, val, &change);
1020}
Mark Brownb83a3132011-05-11 19:59:58 +02001021EXPORT_SYMBOL_GPL(regmap_update_bits);
Mark Brown31244e32011-07-20 22:56:53 +01001022
Mark Brown018690d2011-11-29 20:10:36 +00001023/**
1024 * regmap_update_bits_check: Perform a read/modify/write cycle on the
1025 * register map and report if updated
1026 *
1027 * @map: Register map to update
1028 * @reg: Register to update
1029 * @mask: Bitmask to change
1030 * @val: New value for bitmask
1031 * @change: Boolean indicating if a write was done
1032 *
1033 * Returns zero for success, a negative number on error.
1034 */
1035int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1036 unsigned int mask, unsigned int val,
1037 bool *change)
1038{
1039 return _regmap_update_bits(map, reg, mask, val, change);
1040}
1041EXPORT_SYMBOL_GPL(regmap_update_bits_check);
1042
Mark Brown22f0d902012-01-21 12:01:14 +00001043/**
1044 * regmap_register_patch: Register and apply register updates to be applied
1045 * on device initialistion
1046 *
1047 * @map: Register map to apply updates to.
1048 * @regs: Values to update.
1049 * @num_regs: Number of entries in regs.
1050 *
1051 * Register a set of register updates to be applied to the device
1052 * whenever the device registers are synchronised with the cache and
1053 * apply them immediately. Typically this is used to apply
1054 * corrections to be applied to the device defaults on startup, such
1055 * as the updates some vendors provide to undocumented registers.
1056 */
1057int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
1058 int num_regs)
1059{
1060 int i, ret;
1061 bool bypass;
1062
1063 /* If needed the implementation can be extended to support this */
1064 if (map->patch)
1065 return -EBUSY;
1066
Stephen Warrenbacdbe02012-04-04 15:48:28 -06001067 map->lock(map);
Mark Brown22f0d902012-01-21 12:01:14 +00001068
1069 bypass = map->cache_bypass;
1070
1071 map->cache_bypass = true;
1072
1073 /* Write out first; it's useful to apply even if we fail later. */
1074 for (i = 0; i < num_regs; i++) {
1075 ret = _regmap_write(map, regs[i].reg, regs[i].def);
1076 if (ret != 0) {
1077 dev_err(map->dev, "Failed to write %x = %x: %d\n",
1078 regs[i].reg, regs[i].def, ret);
1079 goto out;
1080 }
1081 }
1082
Axel Lin2a14d7d92012-02-10 19:29:55 +08001083 map->patch = kcalloc(num_regs, sizeof(struct reg_default), GFP_KERNEL);
Mark Brown22f0d902012-01-21 12:01:14 +00001084 if (map->patch != NULL) {
1085 memcpy(map->patch, regs,
1086 num_regs * sizeof(struct reg_default));
1087 map->patch_regs = num_regs;
1088 } else {
1089 ret = -ENOMEM;
1090 }
1091
1092out:
1093 map->cache_bypass = bypass;
1094
Stephen Warrenbacdbe02012-04-04 15:48:28 -06001095 map->unlock(map);
Mark Brown22f0d902012-01-21 12:01:14 +00001096
1097 return ret;
1098}
1099EXPORT_SYMBOL_GPL(regmap_register_patch);
1100
Mark Browneae4b512012-03-14 13:15:03 +00001101/*
Mark Browna6539c32012-02-17 14:20:14 -08001102 * regmap_get_val_bytes(): Report the size of a register value
1103 *
1104 * Report the size of a register value, mainly intended to for use by
1105 * generic infrastructure built on top of regmap.
1106 */
1107int regmap_get_val_bytes(struct regmap *map)
1108{
1109 if (map->format.format_write)
1110 return -EINVAL;
1111
1112 return map->format.val_bytes;
1113}
1114EXPORT_SYMBOL_GPL(regmap_get_val_bytes);
1115
Mark Brown31244e32011-07-20 22:56:53 +01001116static int __init regmap_initcall(void)
1117{
1118 regmap_debugfs_initcall();
1119
1120 return 0;
1121}
1122postcore_initcall(regmap_initcall);