blob: ceaefcfda8de83ce943ef8b1ee8b2abf72ef255e [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>
Krystian Garbaciak6863ca62012-06-15 11:23:56 +010018#include <linux/rbtree.h>
Mark Brownb83a3132011-05-11 19:59:58 +020019
Mark Brownfb2736b2011-07-24 21:30:55 +010020#define CREATE_TRACE_POINTS
21#include <trace/events/regmap.h>
22
Mark Brown93de9122011-07-20 22:35:37 +010023#include "internal.h"
Mark Brownb83a3132011-05-11 19:59:58 +020024
Mark Brown1044c182012-07-06 14:10:23 +010025/*
26 * Sometimes for failures during very early init the trace
27 * infrastructure isn't available early enough to be used. For this
28 * sort of problem defining LOG_DEVICE will add printks for basic
29 * register I/O on a specific device.
30 */
31#undef LOG_DEVICE
32
33static int _regmap_update_bits(struct regmap *map, unsigned int reg,
34 unsigned int mask, unsigned int val,
35 bool *change);
36
Andrey Smirnovad278402013-01-12 12:54:12 -080037static int _regmap_bus_read(void *context, unsigned int reg,
38 unsigned int *val);
39
Davide Ciminaghi76aad392012-11-20 15:20:30 +010040bool regmap_reg_in_ranges(unsigned int reg,
41 const struct regmap_range *ranges,
42 unsigned int nranges)
43{
44 const struct regmap_range *r;
45 int i;
46
47 for (i = 0, r = ranges; i < nranges; i++, r++)
48 if (regmap_reg_in_range(reg, r))
49 return true;
50 return false;
51}
52EXPORT_SYMBOL_GPL(regmap_reg_in_ranges);
53
54static bool _regmap_check_range_table(struct regmap *map,
55 unsigned int reg,
56 const struct regmap_access_table *table)
57{
58 /* Check "no ranges" first */
59 if (regmap_reg_in_ranges(reg, table->no_ranges, table->n_no_ranges))
60 return false;
61
62 /* In case zero "yes ranges" are supplied, any reg is OK */
63 if (!table->n_yes_ranges)
64 return true;
65
66 return regmap_reg_in_ranges(reg, table->yes_ranges,
67 table->n_yes_ranges);
68}
69
Mark Brown8de2f082011-08-10 17:14:41 +090070bool regmap_writeable(struct regmap *map, unsigned int reg)
71{
72 if (map->max_register && reg > map->max_register)
73 return false;
74
75 if (map->writeable_reg)
76 return map->writeable_reg(map->dev, reg);
77
Davide Ciminaghi76aad392012-11-20 15:20:30 +010078 if (map->wr_table)
79 return _regmap_check_range_table(map, reg, map->wr_table);
80
Mark Brown8de2f082011-08-10 17:14:41 +090081 return true;
82}
83
84bool regmap_readable(struct regmap *map, unsigned int reg)
85{
86 if (map->max_register && reg > map->max_register)
87 return false;
88
Wolfram Sang4191f192012-01-30 15:08:16 +010089 if (map->format.format_write)
90 return false;
91
Mark Brown8de2f082011-08-10 17:14:41 +090092 if (map->readable_reg)
93 return map->readable_reg(map->dev, reg);
94
Davide Ciminaghi76aad392012-11-20 15:20:30 +010095 if (map->rd_table)
96 return _regmap_check_range_table(map, reg, map->rd_table);
97
Mark Brown8de2f082011-08-10 17:14:41 +090098 return true;
99}
100
101bool regmap_volatile(struct regmap *map, unsigned int reg)
102{
Wolfram Sang4191f192012-01-30 15:08:16 +0100103 if (!regmap_readable(map, reg))
Mark Brown8de2f082011-08-10 17:14:41 +0900104 return false;
105
106 if (map->volatile_reg)
107 return map->volatile_reg(map->dev, reg);
108
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100109 if (map->volatile_table)
110 return _regmap_check_range_table(map, reg, map->volatile_table);
111
Mark Brown8de2f082011-08-10 17:14:41 +0900112 return true;
113}
114
115bool regmap_precious(struct regmap *map, unsigned int reg)
116{
Wolfram Sang4191f192012-01-30 15:08:16 +0100117 if (!regmap_readable(map, reg))
Mark Brown8de2f082011-08-10 17:14:41 +0900118 return false;
119
120 if (map->precious_reg)
121 return map->precious_reg(map->dev, reg);
122
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100123 if (map->precious_table)
124 return _regmap_check_range_table(map, reg, map->precious_table);
125
Mark Brown8de2f082011-08-10 17:14:41 +0900126 return false;
127}
128
Lars-Peter Clausen82cd9962011-11-08 18:37:25 +0100129static bool regmap_volatile_range(struct regmap *map, unsigned int reg,
Paul Bollea8f28cf2012-10-08 22:06:30 +0200130 size_t num)
Lars-Peter Clausen82cd9962011-11-08 18:37:25 +0100131{
132 unsigned int i;
133
134 for (i = 0; i < num; i++)
135 if (!regmap_volatile(map, reg + i))
136 return false;
137
138 return true;
139}
140
Wolfram Sang9aa50752012-01-27 16:10:22 +0100141static void regmap_format_2_6_write(struct regmap *map,
142 unsigned int reg, unsigned int val)
143{
144 u8 *out = map->work_buf;
145
146 *out = (reg << 6) | val;
147}
148
Mark Brownb83a3132011-05-11 19:59:58 +0200149static void regmap_format_4_12_write(struct regmap *map,
150 unsigned int reg, unsigned int val)
151{
152 __be16 *out = map->work_buf;
153 *out = cpu_to_be16((reg << 12) | val);
154}
155
156static void regmap_format_7_9_write(struct regmap *map,
157 unsigned int reg, unsigned int val)
158{
159 __be16 *out = map->work_buf;
160 *out = cpu_to_be16((reg << 9) | val);
161}
162
Lars-Peter Clausen7e5ec632011-11-16 16:28:21 +0100163static void regmap_format_10_14_write(struct regmap *map,
164 unsigned int reg, unsigned int val)
165{
166 u8 *out = map->work_buf;
167
168 out[2] = val;
169 out[1] = (val >> 8) | (reg << 6);
170 out[0] = reg >> 2;
171}
172
Marc Reillyd939fb92012-03-16 12:11:43 +1100173static void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
Mark Brownb83a3132011-05-11 19:59:58 +0200174{
175 u8 *b = buf;
176
Marc Reillyd939fb92012-03-16 12:11:43 +1100177 b[0] = val << shift;
Mark Brownb83a3132011-05-11 19:59:58 +0200178}
179
Stephen Warren141eba22012-05-24 10:47:26 -0600180static void regmap_format_16_be(void *buf, unsigned int val, unsigned int shift)
Mark Brownb83a3132011-05-11 19:59:58 +0200181{
182 __be16 *b = buf;
183
Marc Reillyd939fb92012-03-16 12:11:43 +1100184 b[0] = cpu_to_be16(val << shift);
Mark Brownb83a3132011-05-11 19:59:58 +0200185}
186
Stephen Warren141eba22012-05-24 10:47:26 -0600187static void regmap_format_16_native(void *buf, unsigned int val,
188 unsigned int shift)
189{
190 *(u16 *)buf = val << shift;
191}
192
Marc Reillyd939fb92012-03-16 12:11:43 +1100193static void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
Marc Reillyea279fc2012-03-16 12:11:42 +1100194{
195 u8 *b = buf;
196
Marc Reillyd939fb92012-03-16 12:11:43 +1100197 val <<= shift;
198
Marc Reillyea279fc2012-03-16 12:11:42 +1100199 b[0] = val >> 16;
200 b[1] = val >> 8;
201 b[2] = val;
202}
203
Stephen Warren141eba22012-05-24 10:47:26 -0600204static void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift)
Mark Brown7d5e5252012-02-17 15:58:25 -0800205{
206 __be32 *b = buf;
207
Marc Reillyd939fb92012-03-16 12:11:43 +1100208 b[0] = cpu_to_be32(val << shift);
Mark Brown7d5e5252012-02-17 15:58:25 -0800209}
210
Stephen Warren141eba22012-05-24 10:47:26 -0600211static void regmap_format_32_native(void *buf, unsigned int val,
212 unsigned int shift)
213{
214 *(u32 *)buf = val << shift;
215}
216
Mark Brownb83a3132011-05-11 19:59:58 +0200217static unsigned int regmap_parse_8(void *buf)
218{
219 u8 *b = buf;
220
221 return b[0];
222}
223
Stephen Warren141eba22012-05-24 10:47:26 -0600224static unsigned int regmap_parse_16_be(void *buf)
Mark Brownb83a3132011-05-11 19:59:58 +0200225{
226 __be16 *b = buf;
227
228 b[0] = be16_to_cpu(b[0]);
229
230 return b[0];
231}
232
Stephen Warren141eba22012-05-24 10:47:26 -0600233static unsigned int regmap_parse_16_native(void *buf)
234{
235 return *(u16 *)buf;
236}
237
Marc Reillyea279fc2012-03-16 12:11:42 +1100238static unsigned int regmap_parse_24(void *buf)
239{
240 u8 *b = buf;
241 unsigned int ret = b[2];
242 ret |= ((unsigned int)b[1]) << 8;
243 ret |= ((unsigned int)b[0]) << 16;
244
245 return ret;
246}
247
Stephen Warren141eba22012-05-24 10:47:26 -0600248static unsigned int regmap_parse_32_be(void *buf)
Mark Brown7d5e5252012-02-17 15:58:25 -0800249{
250 __be32 *b = buf;
251
252 b[0] = be32_to_cpu(b[0]);
253
254 return b[0];
255}
256
Stephen Warren141eba22012-05-24 10:47:26 -0600257static unsigned int regmap_parse_32_native(void *buf)
258{
259 return *(u32 *)buf;
260}
261
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200262static void regmap_lock_mutex(void *__map)
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600263{
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200264 struct regmap *map = __map;
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600265 mutex_lock(&map->mutex);
266}
267
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200268static void regmap_unlock_mutex(void *__map)
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600269{
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200270 struct regmap *map = __map;
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600271 mutex_unlock(&map->mutex);
272}
273
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200274static void regmap_lock_spinlock(void *__map)
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600275{
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200276 struct regmap *map = __map;
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600277 spin_lock(&map->spinlock);
278}
279
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200280static void regmap_unlock_spinlock(void *__map)
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600281{
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200282 struct regmap *map = __map;
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600283 spin_unlock(&map->spinlock);
284}
285
Mark Brown72b39f62012-05-08 17:44:40 +0100286static void dev_get_regmap_release(struct device *dev, void *res)
287{
288 /*
289 * We don't actually have anything to do here; the goal here
290 * is not to manage the regmap but to provide a simple way to
291 * get the regmap back given a struct device.
292 */
293}
294
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100295static bool _regmap_range_add(struct regmap *map,
296 struct regmap_range_node *data)
297{
298 struct rb_root *root = &map->range_tree;
299 struct rb_node **new = &(root->rb_node), *parent = NULL;
300
301 while (*new) {
302 struct regmap_range_node *this =
303 container_of(*new, struct regmap_range_node, node);
304
305 parent = *new;
306 if (data->range_max < this->range_min)
307 new = &((*new)->rb_left);
308 else if (data->range_min > this->range_max)
309 new = &((*new)->rb_right);
310 else
311 return false;
312 }
313
314 rb_link_node(&data->node, parent, new);
315 rb_insert_color(&data->node, root);
316
317 return true;
318}
319
320static struct regmap_range_node *_regmap_range_lookup(struct regmap *map,
321 unsigned int reg)
322{
323 struct rb_node *node = map->range_tree.rb_node;
324
325 while (node) {
326 struct regmap_range_node *this =
327 container_of(node, struct regmap_range_node, node);
328
329 if (reg < this->range_min)
330 node = node->rb_left;
331 else if (reg > this->range_max)
332 node = node->rb_right;
333 else
334 return this;
335 }
336
337 return NULL;
338}
339
340static void regmap_range_exit(struct regmap *map)
341{
342 struct rb_node *next;
343 struct regmap_range_node *range_node;
344
345 next = rb_first(&map->range_tree);
346 while (next) {
347 range_node = rb_entry(next, struct regmap_range_node, node);
348 next = rb_next(&range_node->node);
349 rb_erase(&range_node->node, &map->range_tree);
350 kfree(range_node);
351 }
352
353 kfree(map->selector_work_buf);
354}
355
Mark Brownb83a3132011-05-11 19:59:58 +0200356/**
357 * regmap_init(): Initialise register map
358 *
359 * @dev: Device that will be interacted with
360 * @bus: Bus-specific callbacks to use with device
Stephen Warren0135bbc2012-04-04 15:48:30 -0600361 * @bus_context: Data passed to bus-specific callbacks
Mark Brownb83a3132011-05-11 19:59:58 +0200362 * @config: Configuration for register map
363 *
364 * The return value will be an ERR_PTR() on error or a valid pointer to
365 * a struct regmap. This function should generally not be called
366 * directly, it should be called by bus-specific init functions.
367 */
368struct regmap *regmap_init(struct device *dev,
369 const struct regmap_bus *bus,
Stephen Warren0135bbc2012-04-04 15:48:30 -0600370 void *bus_context,
Mark Brownb83a3132011-05-11 19:59:58 +0200371 const struct regmap_config *config)
372{
Mark Brown72b39f62012-05-08 17:44:40 +0100373 struct regmap *map, **m;
Mark Brownb83a3132011-05-11 19:59:58 +0200374 int ret = -EINVAL;
Stephen Warren141eba22012-05-24 10:47:26 -0600375 enum regmap_endian reg_endian, val_endian;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100376 int i, j;
Mark Brownb83a3132011-05-11 19:59:58 +0200377
378 if (!bus || !config)
Lars-Peter Clausenabbb18f2011-11-14 10:40:15 +0100379 goto err;
Mark Brownb83a3132011-05-11 19:59:58 +0200380
381 map = kzalloc(sizeof(*map), GFP_KERNEL);
382 if (map == NULL) {
383 ret = -ENOMEM;
384 goto err;
385 }
386
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200387 if (config->lock && config->unlock) {
388 map->lock = config->lock;
389 map->unlock = config->unlock;
390 map->lock_arg = config->lock_arg;
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600391 } else {
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200392 if (bus->fast_io) {
393 spin_lock_init(&map->spinlock);
394 map->lock = regmap_lock_spinlock;
395 map->unlock = regmap_unlock_spinlock;
396 } else {
397 mutex_init(&map->mutex);
398 map->lock = regmap_lock_mutex;
399 map->unlock = regmap_unlock_mutex;
400 }
401 map->lock_arg = map;
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600402 }
Wolfram Sangc212acc2012-01-28 02:16:41 +0100403 map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
Mark Brown82159ba2012-01-18 10:52:25 +0000404 map->format.pad_bytes = config->pad_bits / 8;
Wolfram Sangc212acc2012-01-28 02:16:41 +0100405 map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
Fabio Estevam5494a982012-05-31 21:10:30 -0300406 map->format.buf_size = DIV_ROUND_UP(config->reg_bits +
407 config->val_bits + config->pad_bits, 8);
Marc Reillyd939fb92012-03-16 12:11:43 +1100408 map->reg_shift = config->pad_bits % 8;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600409 if (config->reg_stride)
410 map->reg_stride = config->reg_stride;
411 else
412 map->reg_stride = 1;
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100413 map->use_single_rw = config->use_single_rw;
Mark Brownb83a3132011-05-11 19:59:58 +0200414 map->dev = dev;
415 map->bus = bus;
Stephen Warren0135bbc2012-04-04 15:48:30 -0600416 map->bus_context = bus_context;
Mark Brown2e2ae662011-07-20 22:33:39 +0100417 map->max_register = config->max_register;
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100418 map->wr_table = config->wr_table;
419 map->rd_table = config->rd_table;
420 map->volatile_table = config->volatile_table;
421 map->precious_table = config->precious_table;
Mark Brown2e2ae662011-07-20 22:33:39 +0100422 map->writeable_reg = config->writeable_reg;
423 map->readable_reg = config->readable_reg;
424 map->volatile_reg = config->volatile_reg;
Mark Brown2efe1642011-08-08 15:41:46 +0900425 map->precious_reg = config->precious_reg;
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100426 map->cache_type = config->cache_type;
Mark Brown72b39f62012-05-08 17:44:40 +0100427 map->name = config->name;
Mark Brownb83a3132011-05-11 19:59:58 +0200428
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200429 if (config->read_flag_mask || config->write_flag_mask) {
430 map->read_flag_mask = config->read_flag_mask;
431 map->write_flag_mask = config->write_flag_mask;
432 } else {
433 map->read_flag_mask = bus->read_flag_mask;
434 }
435
Andrey Smirnovad278402013-01-12 12:54:12 -0800436 map->reg_read = _regmap_bus_read;
437
Stephen Warren141eba22012-05-24 10:47:26 -0600438 reg_endian = config->reg_format_endian;
439 if (reg_endian == REGMAP_ENDIAN_DEFAULT)
440 reg_endian = bus->reg_format_endian_default;
441 if (reg_endian == REGMAP_ENDIAN_DEFAULT)
442 reg_endian = REGMAP_ENDIAN_BIG;
443
444 val_endian = config->val_format_endian;
445 if (val_endian == REGMAP_ENDIAN_DEFAULT)
446 val_endian = bus->val_format_endian_default;
447 if (val_endian == REGMAP_ENDIAN_DEFAULT)
448 val_endian = REGMAP_ENDIAN_BIG;
449
Marc Reillyd939fb92012-03-16 12:11:43 +1100450 switch (config->reg_bits + map->reg_shift) {
Wolfram Sang9aa50752012-01-27 16:10:22 +0100451 case 2:
452 switch (config->val_bits) {
453 case 6:
454 map->format.format_write = regmap_format_2_6_write;
455 break;
456 default:
457 goto err_map;
458 }
459 break;
460
Mark Brownb83a3132011-05-11 19:59:58 +0200461 case 4:
462 switch (config->val_bits) {
463 case 12:
464 map->format.format_write = regmap_format_4_12_write;
465 break;
466 default:
467 goto err_map;
468 }
469 break;
470
471 case 7:
472 switch (config->val_bits) {
473 case 9:
474 map->format.format_write = regmap_format_7_9_write;
475 break;
476 default:
477 goto err_map;
478 }
479 break;
480
Lars-Peter Clausen7e5ec632011-11-16 16:28:21 +0100481 case 10:
482 switch (config->val_bits) {
483 case 14:
484 map->format.format_write = regmap_format_10_14_write;
485 break;
486 default:
487 goto err_map;
488 }
489 break;
490
Mark Brownb83a3132011-05-11 19:59:58 +0200491 case 8:
492 map->format.format_reg = regmap_format_8;
493 break;
494
495 case 16:
Stephen Warren141eba22012-05-24 10:47:26 -0600496 switch (reg_endian) {
497 case REGMAP_ENDIAN_BIG:
498 map->format.format_reg = regmap_format_16_be;
499 break;
500 case REGMAP_ENDIAN_NATIVE:
501 map->format.format_reg = regmap_format_16_native;
502 break;
503 default:
504 goto err_map;
505 }
Mark Brownb83a3132011-05-11 19:59:58 +0200506 break;
507
Mark Brown7d5e5252012-02-17 15:58:25 -0800508 case 32:
Stephen Warren141eba22012-05-24 10:47:26 -0600509 switch (reg_endian) {
510 case REGMAP_ENDIAN_BIG:
511 map->format.format_reg = regmap_format_32_be;
512 break;
513 case REGMAP_ENDIAN_NATIVE:
514 map->format.format_reg = regmap_format_32_native;
515 break;
516 default:
517 goto err_map;
518 }
Mark Brown7d5e5252012-02-17 15:58:25 -0800519 break;
520
Mark Brownb83a3132011-05-11 19:59:58 +0200521 default:
522 goto err_map;
523 }
524
525 switch (config->val_bits) {
526 case 8:
527 map->format.format_val = regmap_format_8;
528 map->format.parse_val = regmap_parse_8;
529 break;
530 case 16:
Stephen Warren141eba22012-05-24 10:47:26 -0600531 switch (val_endian) {
532 case REGMAP_ENDIAN_BIG:
533 map->format.format_val = regmap_format_16_be;
534 map->format.parse_val = regmap_parse_16_be;
535 break;
536 case REGMAP_ENDIAN_NATIVE:
537 map->format.format_val = regmap_format_16_native;
538 map->format.parse_val = regmap_parse_16_native;
539 break;
540 default:
541 goto err_map;
542 }
Mark Brownb83a3132011-05-11 19:59:58 +0200543 break;
Marc Reillyea279fc2012-03-16 12:11:42 +1100544 case 24:
Stephen Warren141eba22012-05-24 10:47:26 -0600545 if (val_endian != REGMAP_ENDIAN_BIG)
546 goto err_map;
Marc Reillyea279fc2012-03-16 12:11:42 +1100547 map->format.format_val = regmap_format_24;
548 map->format.parse_val = regmap_parse_24;
549 break;
Mark Brown7d5e5252012-02-17 15:58:25 -0800550 case 32:
Stephen Warren141eba22012-05-24 10:47:26 -0600551 switch (val_endian) {
552 case REGMAP_ENDIAN_BIG:
553 map->format.format_val = regmap_format_32_be;
554 map->format.parse_val = regmap_parse_32_be;
555 break;
556 case REGMAP_ENDIAN_NATIVE:
557 map->format.format_val = regmap_format_32_native;
558 map->format.parse_val = regmap_parse_32_native;
559 break;
560 default:
561 goto err_map;
562 }
Mark Brown7d5e5252012-02-17 15:58:25 -0800563 break;
Mark Brownb83a3132011-05-11 19:59:58 +0200564 }
565
Stephen Warren141eba22012-05-24 10:47:26 -0600566 if (map->format.format_write) {
567 if ((reg_endian != REGMAP_ENDIAN_BIG) ||
568 (val_endian != REGMAP_ENDIAN_BIG))
569 goto err_map;
Mark Brown7a647612012-04-30 23:26:32 +0100570 map->use_single_rw = true;
Stephen Warren141eba22012-05-24 10:47:26 -0600571 }
Mark Brown7a647612012-04-30 23:26:32 +0100572
Mark Brownb83a3132011-05-11 19:59:58 +0200573 if (!map->format.format_write &&
574 !(map->format.format_reg && map->format.format_val))
575 goto err_map;
576
Mark Brown82159ba2012-01-18 10:52:25 +0000577 map->work_buf = kzalloc(map->format.buf_size, GFP_KERNEL);
Mark Brownb83a3132011-05-11 19:59:58 +0200578 if (map->work_buf == NULL) {
579 ret = -ENOMEM;
Mark Brown5204f5e2011-09-05 08:07:47 -0700580 goto err_map;
Mark Brownb83a3132011-05-11 19:59:58 +0200581 }
582
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100583 map->range_tree = RB_ROOT;
Mark Browne3549cd2012-10-02 20:17:15 +0100584 for (i = 0; i < config->num_ranges; i++) {
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100585 const struct regmap_range_cfg *range_cfg = &config->ranges[i];
586 struct regmap_range_node *new;
587
588 /* Sanity check */
Mark Brown061adc02012-10-03 12:17:51 +0100589 if (range_cfg->range_max < range_cfg->range_min) {
590 dev_err(map->dev, "Invalid range %d: %d < %d\n", i,
591 range_cfg->range_max, range_cfg->range_min);
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100592 goto err_range;
Mark Brown061adc02012-10-03 12:17:51 +0100593 }
594
595 if (range_cfg->range_max > map->max_register) {
596 dev_err(map->dev, "Invalid range %d: %d > %d\n", i,
597 range_cfg->range_max, map->max_register);
598 goto err_range;
599 }
600
601 if (range_cfg->selector_reg > map->max_register) {
602 dev_err(map->dev,
603 "Invalid range %d: selector out of map\n", i);
604 goto err_range;
605 }
606
607 if (range_cfg->window_len == 0) {
608 dev_err(map->dev, "Invalid range %d: window_len 0\n",
609 i);
610 goto err_range;
611 }
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100612
613 /* Make sure, that this register range has no selector
614 or data window within its boundary */
Mark Browne3549cd2012-10-02 20:17:15 +0100615 for (j = 0; j < config->num_ranges; j++) {
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100616 unsigned sel_reg = config->ranges[j].selector_reg;
617 unsigned win_min = config->ranges[j].window_start;
618 unsigned win_max = win_min +
619 config->ranges[j].window_len - 1;
620
621 if (range_cfg->range_min <= sel_reg &&
622 sel_reg <= range_cfg->range_max) {
Mark Brown061adc02012-10-03 12:17:51 +0100623 dev_err(map->dev,
624 "Range %d: selector for %d in window\n",
625 i, j);
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100626 goto err_range;
627 }
628
629 if (!(win_max < range_cfg->range_min ||
630 win_min > range_cfg->range_max)) {
Mark Brown061adc02012-10-03 12:17:51 +0100631 dev_err(map->dev,
632 "Range %d: window for %d in window\n",
633 i, j);
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100634 goto err_range;
635 }
636 }
637
638 new = kzalloc(sizeof(*new), GFP_KERNEL);
639 if (new == NULL) {
640 ret = -ENOMEM;
641 goto err_range;
642 }
643
Mark Brown4b020b32012-10-03 13:13:16 +0100644 new->map = map;
Mark Brownd058bb42012-10-03 12:40:47 +0100645 new->name = range_cfg->name;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100646 new->range_min = range_cfg->range_min;
647 new->range_max = range_cfg->range_max;
648 new->selector_reg = range_cfg->selector_reg;
649 new->selector_mask = range_cfg->selector_mask;
650 new->selector_shift = range_cfg->selector_shift;
651 new->window_start = range_cfg->window_start;
652 new->window_len = range_cfg->window_len;
653
654 if (_regmap_range_add(map, new) == false) {
Mark Brown061adc02012-10-03 12:17:51 +0100655 dev_err(map->dev, "Failed to add range %d\n", i);
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100656 kfree(new);
657 goto err_range;
658 }
659
660 if (map->selector_work_buf == NULL) {
661 map->selector_work_buf =
662 kzalloc(map->format.buf_size, GFP_KERNEL);
663 if (map->selector_work_buf == NULL) {
664 ret = -ENOMEM;
665 goto err_range;
666 }
667 }
668 }
Mark Brown052d2cd2011-11-21 19:05:13 +0000669
Lars-Peter Clausene5e3b8a2011-11-16 16:28:16 +0100670 ret = regcache_init(map, config);
Mark Brown0ff3e622012-10-04 17:39:13 +0100671 if (ret != 0)
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100672 goto err_range;
673
674 regmap_debugfs_init(map, config->name);
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100675
Mark Brown72b39f62012-05-08 17:44:40 +0100676 /* Add a devres resource for dev_get_regmap() */
677 m = devres_alloc(dev_get_regmap_release, sizeof(*m), GFP_KERNEL);
678 if (!m) {
679 ret = -ENOMEM;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100680 goto err_debugfs;
Mark Brown72b39f62012-05-08 17:44:40 +0100681 }
682 *m = map;
683 devres_add(dev, m);
684
Mark Brownb83a3132011-05-11 19:59:58 +0200685 return map;
686
Stephen Warrenbfaa25f2012-05-23 16:30:53 -0600687err_debugfs:
688 regmap_debugfs_exit(map);
Mark Brown72b39f62012-05-08 17:44:40 +0100689 regcache_exit(map);
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100690err_range:
691 regmap_range_exit(map);
Lars-Peter Clausen58072cb2011-11-10 18:15:15 +0100692 kfree(map->work_buf);
Mark Brownb83a3132011-05-11 19:59:58 +0200693err_map:
694 kfree(map);
695err:
696 return ERR_PTR(ret);
697}
698EXPORT_SYMBOL_GPL(regmap_init);
699
Mark Brownc0eb4672012-01-30 19:56:52 +0000700static void devm_regmap_release(struct device *dev, void *res)
701{
702 regmap_exit(*(struct regmap **)res);
703}
704
705/**
706 * devm_regmap_init(): Initialise managed register map
707 *
708 * @dev: Device that will be interacted with
709 * @bus: Bus-specific callbacks to use with device
Stephen Warren0135bbc2012-04-04 15:48:30 -0600710 * @bus_context: Data passed to bus-specific callbacks
Mark Brownc0eb4672012-01-30 19:56:52 +0000711 * @config: Configuration for register map
712 *
713 * The return value will be an ERR_PTR() on error or a valid pointer
714 * to a struct regmap. This function should generally not be called
715 * directly, it should be called by bus-specific init functions. The
716 * map will be automatically freed by the device management code.
717 */
718struct regmap *devm_regmap_init(struct device *dev,
719 const struct regmap_bus *bus,
Stephen Warren0135bbc2012-04-04 15:48:30 -0600720 void *bus_context,
Mark Brownc0eb4672012-01-30 19:56:52 +0000721 const struct regmap_config *config)
722{
723 struct regmap **ptr, *regmap;
724
725 ptr = devres_alloc(devm_regmap_release, sizeof(*ptr), GFP_KERNEL);
726 if (!ptr)
727 return ERR_PTR(-ENOMEM);
728
Stephen Warren0135bbc2012-04-04 15:48:30 -0600729 regmap = regmap_init(dev, bus, bus_context, config);
Mark Brownc0eb4672012-01-30 19:56:52 +0000730 if (!IS_ERR(regmap)) {
731 *ptr = regmap;
732 devres_add(dev, ptr);
733 } else {
734 devres_free(ptr);
735 }
736
737 return regmap;
738}
739EXPORT_SYMBOL_GPL(devm_regmap_init);
740
Mark Brownb83a3132011-05-11 19:59:58 +0200741/**
Mark Brownbf315172011-12-03 17:06:20 +0000742 * regmap_reinit_cache(): Reinitialise the current register cache
743 *
744 * @map: Register map to operate on.
745 * @config: New configuration. Only the cache data will be used.
746 *
747 * Discard any existing register cache for the map and initialize a
748 * new cache. This can be used to restore the cache to defaults or to
749 * update the cache configuration to reflect runtime discovery of the
750 * hardware.
Dimitris Papastamos4d879512012-07-27 14:54:15 +0100751 *
752 * No explicit locking is done here, the user needs to ensure that
753 * this function will not race with other calls to regmap.
Mark Brownbf315172011-12-03 17:06:20 +0000754 */
755int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
756{
Mark Brownbf315172011-12-03 17:06:20 +0000757 regcache_exit(map);
Mark Browna24f64a2012-01-26 18:30:16 +0000758 regmap_debugfs_exit(map);
Mark Brownbf315172011-12-03 17:06:20 +0000759
760 map->max_register = config->max_register;
761 map->writeable_reg = config->writeable_reg;
762 map->readable_reg = config->readable_reg;
763 map->volatile_reg = config->volatile_reg;
764 map->precious_reg = config->precious_reg;
765 map->cache_type = config->cache_type;
766
Stephen Warrend3c242e2012-04-04 15:48:29 -0600767 regmap_debugfs_init(map, config->name);
Mark Browna24f64a2012-01-26 18:30:16 +0000768
Mark Brown421e8d22012-01-20 13:39:37 +0000769 map->cache_bypass = false;
770 map->cache_only = false;
771
Dimitris Papastamos4d879512012-07-27 14:54:15 +0100772 return regcache_init(map, config);
Mark Brownbf315172011-12-03 17:06:20 +0000773}
Mark Brown752a6a52012-05-14 10:00:12 +0100774EXPORT_SYMBOL_GPL(regmap_reinit_cache);
Mark Brownbf315172011-12-03 17:06:20 +0000775
776/**
Mark Brownb83a3132011-05-11 19:59:58 +0200777 * regmap_exit(): Free a previously allocated register map
778 */
779void regmap_exit(struct regmap *map)
780{
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100781 regcache_exit(map);
Mark Brown31244e32011-07-20 22:56:53 +0100782 regmap_debugfs_exit(map);
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100783 regmap_range_exit(map);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600784 if (map->bus->free_context)
785 map->bus->free_context(map->bus_context);
Mark Brownb83a3132011-05-11 19:59:58 +0200786 kfree(map->work_buf);
Mark Brownb83a3132011-05-11 19:59:58 +0200787 kfree(map);
788}
789EXPORT_SYMBOL_GPL(regmap_exit);
790
Mark Brown72b39f62012-05-08 17:44:40 +0100791static int dev_get_regmap_match(struct device *dev, void *res, void *data)
792{
793 struct regmap **r = res;
794 if (!r || !*r) {
795 WARN_ON(!r || !*r);
796 return 0;
797 }
798
799 /* If the user didn't specify a name match any */
800 if (data)
801 return (*r)->name == data;
802 else
803 return 1;
804}
805
806/**
807 * dev_get_regmap(): Obtain the regmap (if any) for a device
808 *
809 * @dev: Device to retrieve the map for
810 * @name: Optional name for the register map, usually NULL.
811 *
812 * Returns the regmap for the device if one is present, or NULL. If
813 * name is specified then it must match the name specified when
814 * registering the device, if it is NULL then the first regmap found
815 * will be used. Devices with multiple register maps are very rare,
816 * generic code should normally not need to specify a name.
817 */
818struct regmap *dev_get_regmap(struct device *dev, const char *name)
819{
820 struct regmap **r = devres_find(dev, dev_get_regmap_release,
821 dev_get_regmap_match, (void *)name);
822
823 if (!r)
824 return NULL;
825 return *r;
826}
827EXPORT_SYMBOL_GPL(dev_get_regmap);
828
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100829static int _regmap_select_page(struct regmap *map, unsigned int *reg,
Mark Brown98bc7df2012-10-04 17:31:11 +0100830 struct regmap_range_node *range,
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100831 unsigned int val_num)
832{
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100833 void *orig_work_buf;
834 unsigned int win_offset;
835 unsigned int win_page;
836 bool page_chg;
837 int ret;
838
Mark Brown98bc7df2012-10-04 17:31:11 +0100839 win_offset = (*reg - range->range_min) % range->window_len;
840 win_page = (*reg - range->range_min) / range->window_len;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100841
Mark Brown98bc7df2012-10-04 17:31:11 +0100842 if (val_num > 1) {
843 /* Bulk write shouldn't cross range boundary */
844 if (*reg + val_num - 1 > range->range_max)
845 return -EINVAL;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100846
Mark Brown98bc7df2012-10-04 17:31:11 +0100847 /* ... or single page boundary */
848 if (val_num > range->window_len - win_offset)
849 return -EINVAL;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100850 }
851
Mark Brown98bc7df2012-10-04 17:31:11 +0100852 /* It is possible to have selector register inside data window.
853 In that case, selector register is located on every page and
854 it needs no page switching, when accessed alone. */
855 if (val_num > 1 ||
856 range->window_start + win_offset != range->selector_reg) {
857 /* Use separate work_buf during page switching */
858 orig_work_buf = map->work_buf;
859 map->work_buf = map->selector_work_buf;
860
861 ret = _regmap_update_bits(map, range->selector_reg,
862 range->selector_mask,
863 win_page << range->selector_shift,
864 &page_chg);
865
866 map->work_buf = orig_work_buf;
867
Mark Brown0ff3e622012-10-04 17:39:13 +0100868 if (ret != 0)
Mark Brown98bc7df2012-10-04 17:31:11 +0100869 return ret;
870 }
871
872 *reg = range->window_start + win_offset;
873
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100874 return 0;
875}
876
Mark Brownb83a3132011-05-11 19:59:58 +0200877static int _regmap_raw_write(struct regmap *map, unsigned int reg,
878 const void *val, size_t val_len)
879{
Mark Brown98bc7df2012-10-04 17:31:11 +0100880 struct regmap_range_node *range;
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200881 u8 *u8 = map->work_buf;
Mark Brownb83a3132011-05-11 19:59:58 +0200882 void *buf;
883 int ret = -ENOTSUPP;
884 size_t len;
Mark Brown73304782011-07-24 11:46:20 +0100885 int i;
886
887 /* Check for unwritable registers before we start */
888 if (map->writeable_reg)
889 for (i = 0; i < val_len / map->format.val_bytes; i++)
Stephen Warrenf01ee602012-04-09 13:40:24 -0600890 if (!map->writeable_reg(map->dev,
891 reg + (i * map->reg_stride)))
Mark Brown73304782011-07-24 11:46:20 +0100892 return -EINVAL;
Mark Brownb83a3132011-05-11 19:59:58 +0200893
Laxman Dewanganc9157192012-02-10 21:30:27 +0530894 if (!map->cache_bypass && map->format.parse_val) {
895 unsigned int ival;
896 int val_bytes = map->format.val_bytes;
897 for (i = 0; i < val_len / val_bytes; i++) {
898 memcpy(map->work_buf, val + (i * val_bytes), val_bytes);
899 ival = map->format.parse_val(map->work_buf);
Stephen Warrenf01ee602012-04-09 13:40:24 -0600900 ret = regcache_write(map, reg + (i * map->reg_stride),
901 ival);
Laxman Dewanganc9157192012-02-10 21:30:27 +0530902 if (ret) {
903 dev_err(map->dev,
Mark Brown6d04b8a2012-10-26 19:05:32 +0100904 "Error in caching of register: %x ret: %d\n",
Laxman Dewanganc9157192012-02-10 21:30:27 +0530905 reg + i, ret);
906 return ret;
907 }
908 }
909 if (map->cache_only) {
910 map->cache_dirty = true;
911 return 0;
912 }
913 }
914
Mark Brown98bc7df2012-10-04 17:31:11 +0100915 range = _regmap_range_lookup(map, reg);
916 if (range) {
Mark Brown8a2ceac2012-10-04 18:20:18 +0100917 int val_num = val_len / map->format.val_bytes;
918 int win_offset = (reg - range->range_min) % range->window_len;
919 int win_residue = range->window_len - win_offset;
920
921 /* If the write goes beyond the end of the window split it */
922 while (val_num > win_residue) {
Fabio Estevam1a61cfe2012-10-25 14:07:18 -0200923 dev_dbg(map->dev, "Writing window %d/%zu\n",
Mark Brown8a2ceac2012-10-04 18:20:18 +0100924 win_residue, val_len / map->format.val_bytes);
925 ret = _regmap_raw_write(map, reg, val, win_residue *
926 map->format.val_bytes);
927 if (ret != 0)
928 return ret;
929
930 reg += win_residue;
931 val_num -= win_residue;
932 val += win_residue * map->format.val_bytes;
933 val_len -= win_residue * map->format.val_bytes;
934
935 win_offset = (reg - range->range_min) %
936 range->window_len;
937 win_residue = range->window_len - win_offset;
938 }
939
940 ret = _regmap_select_page(map, &reg, range, val_num);
Mark Brown0ff3e622012-10-04 17:39:13 +0100941 if (ret != 0)
Mark Brown98bc7df2012-10-04 17:31:11 +0100942 return ret;
943 }
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100944
Marc Reillyd939fb92012-03-16 12:11:43 +1100945 map->format.format_reg(map->work_buf, reg, map->reg_shift);
Mark Brownb83a3132011-05-11 19:59:58 +0200946
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200947 u8[0] |= map->write_flag_mask;
948
Mark Brownfb2736b2011-07-24 21:30:55 +0100949 trace_regmap_hw_write_start(map->dev, reg,
950 val_len / map->format.val_bytes);
951
Mark Brown2547e202011-07-20 21:47:22 +0100952 /* If we're doing a single register write we can probably just
953 * send the work_buf directly, otherwise try to do a gather
954 * write.
955 */
Mark Brown82159ba2012-01-18 10:52:25 +0000956 if (val == (map->work_buf + map->format.pad_bytes +
957 map->format.reg_bytes))
Stephen Warren0135bbc2012-04-04 15:48:30 -0600958 ret = map->bus->write(map->bus_context, map->work_buf,
Mark Brown82159ba2012-01-18 10:52:25 +0000959 map->format.reg_bytes +
960 map->format.pad_bytes +
961 val_len);
Mark Brown2547e202011-07-20 21:47:22 +0100962 else if (map->bus->gather_write)
Stephen Warren0135bbc2012-04-04 15:48:30 -0600963 ret = map->bus->gather_write(map->bus_context, map->work_buf,
Mark Brown82159ba2012-01-18 10:52:25 +0000964 map->format.reg_bytes +
965 map->format.pad_bytes,
Mark Brownb83a3132011-05-11 19:59:58 +0200966 val, val_len);
967
Mark Brown2547e202011-07-20 21:47:22 +0100968 /* If that didn't work fall back on linearising by hand. */
Mark Brownb83a3132011-05-11 19:59:58 +0200969 if (ret == -ENOTSUPP) {
Mark Brown82159ba2012-01-18 10:52:25 +0000970 len = map->format.reg_bytes + map->format.pad_bytes + val_len;
971 buf = kzalloc(len, GFP_KERNEL);
Mark Brownb83a3132011-05-11 19:59:58 +0200972 if (!buf)
973 return -ENOMEM;
974
975 memcpy(buf, map->work_buf, map->format.reg_bytes);
Mark Brown82159ba2012-01-18 10:52:25 +0000976 memcpy(buf + map->format.reg_bytes + map->format.pad_bytes,
977 val, val_len);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600978 ret = map->bus->write(map->bus_context, buf, len);
Mark Brownb83a3132011-05-11 19:59:58 +0200979
980 kfree(buf);
981 }
982
Mark Brownfb2736b2011-07-24 21:30:55 +0100983 trace_regmap_hw_write_done(map->dev, reg,
984 val_len / map->format.val_bytes);
985
Mark Brownb83a3132011-05-11 19:59:58 +0200986 return ret;
987}
988
Dimitris Papastamos4d2dc092011-09-29 10:39:07 +0100989int _regmap_write(struct regmap *map, unsigned int reg,
990 unsigned int val)
Mark Brownb83a3132011-05-11 19:59:58 +0200991{
Mark Brown98bc7df2012-10-04 17:31:11 +0100992 struct regmap_range_node *range;
Mark Brownfb2736b2011-07-24 21:30:55 +0100993 int ret;
Mark Brownb83a3132011-05-11 19:59:58 +0200994 BUG_ON(!map->format.format_write && !map->format.format_val);
995
Laxman Dewanganc9157192012-02-10 21:30:27 +0530996 if (!map->cache_bypass && map->format.format_write) {
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100997 ret = regcache_write(map, reg, val);
998 if (ret != 0)
999 return ret;
Mark Brown8ae0d7e2011-10-26 10:34:22 +02001000 if (map->cache_only) {
1001 map->cache_dirty = true;
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +01001002 return 0;
Mark Brown8ae0d7e2011-10-26 10:34:22 +02001003 }
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +01001004 }
1005
Mark Brown1044c182012-07-06 14:10:23 +01001006#ifdef LOG_DEVICE
1007 if (strcmp(dev_name(map->dev), LOG_DEVICE) == 0)
1008 dev_info(map->dev, "%x <= %x\n", reg, val);
1009#endif
1010
Mark Brownfb2736b2011-07-24 21:30:55 +01001011 trace_regmap_reg_write(map->dev, reg, val);
1012
Mark Brownb83a3132011-05-11 19:59:58 +02001013 if (map->format.format_write) {
Mark Brown98bc7df2012-10-04 17:31:11 +01001014 range = _regmap_range_lookup(map, reg);
1015 if (range) {
1016 ret = _regmap_select_page(map, &reg, range, 1);
Mark Brown0ff3e622012-10-04 17:39:13 +01001017 if (ret != 0)
Mark Brown98bc7df2012-10-04 17:31:11 +01001018 return ret;
1019 }
Krystian Garbaciak6863ca62012-06-15 11:23:56 +01001020
Mark Brownb83a3132011-05-11 19:59:58 +02001021 map->format.format_write(map, reg, val);
1022
Mark Brownfb2736b2011-07-24 21:30:55 +01001023 trace_regmap_hw_write_start(map->dev, reg, 1);
1024
Stephen Warren0135bbc2012-04-04 15:48:30 -06001025 ret = map->bus->write(map->bus_context, map->work_buf,
Mark Brownfb2736b2011-07-24 21:30:55 +01001026 map->format.buf_size);
1027
1028 trace_regmap_hw_write_done(map->dev, reg, 1);
1029
1030 return ret;
Mark Brownb83a3132011-05-11 19:59:58 +02001031 } else {
Mark Brown82159ba2012-01-18 10:52:25 +00001032 map->format.format_val(map->work_buf + map->format.reg_bytes
Marc Reillyd939fb92012-03-16 12:11:43 +11001033 + map->format.pad_bytes, val, 0);
Mark Brownb83a3132011-05-11 19:59:58 +02001034 return _regmap_raw_write(map, reg,
Mark Brown82159ba2012-01-18 10:52:25 +00001035 map->work_buf +
1036 map->format.reg_bytes +
1037 map->format.pad_bytes,
Mark Brownb83a3132011-05-11 19:59:58 +02001038 map->format.val_bytes);
1039 }
1040}
1041
1042/**
1043 * regmap_write(): Write a value to a single register
1044 *
1045 * @map: Register map to write to
1046 * @reg: Register to write to
1047 * @val: Value to be written
1048 *
1049 * A value of zero will be returned on success, a negative errno will
1050 * be returned in error cases.
1051 */
1052int regmap_write(struct regmap *map, unsigned int reg, unsigned int val)
1053{
1054 int ret;
1055
Stephen Warrenf01ee602012-04-09 13:40:24 -06001056 if (reg % map->reg_stride)
1057 return -EINVAL;
1058
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001059 map->lock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001060
1061 ret = _regmap_write(map, reg, val);
1062
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001063 map->unlock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001064
1065 return ret;
1066}
1067EXPORT_SYMBOL_GPL(regmap_write);
1068
1069/**
1070 * regmap_raw_write(): Write raw values to one or more registers
1071 *
1072 * @map: Register map to write to
1073 * @reg: Initial register to write to
1074 * @val: Block of data to be written, laid out for direct transmission to the
1075 * device
1076 * @val_len: Length of data pointed to by val.
1077 *
1078 * This function is intended to be used for things like firmware
1079 * download where a large block of data needs to be transferred to the
1080 * device. No formatting will be done on the data provided.
1081 *
1082 * A value of zero will be returned on success, a negative errno will
1083 * be returned in error cases.
1084 */
1085int regmap_raw_write(struct regmap *map, unsigned int reg,
1086 const void *val, size_t val_len)
1087{
1088 int ret;
1089
Stephen Warren851960b2012-04-06 15:16:03 -06001090 if (val_len % map->format.val_bytes)
1091 return -EINVAL;
Stephen Warrenf01ee602012-04-09 13:40:24 -06001092 if (reg % map->reg_stride)
1093 return -EINVAL;
Stephen Warren851960b2012-04-06 15:16:03 -06001094
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001095 map->lock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001096
1097 ret = _regmap_raw_write(map, reg, val, val_len);
1098
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001099 map->unlock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001100
1101 return ret;
1102}
1103EXPORT_SYMBOL_GPL(regmap_raw_write);
1104
Laxman Dewangan8eaeb212012-02-12 19:49:43 +05301105/*
1106 * regmap_bulk_write(): Write multiple registers to the device
1107 *
1108 * @map: Register map to write to
1109 * @reg: First register to be write from
1110 * @val: Block of data to be written, in native register size for device
1111 * @val_count: Number of registers to write
1112 *
1113 * This function is intended to be used for writing a large block of
1114 * data to be device either in single transfer or multiple transfer.
1115 *
1116 * A value of zero will be returned on success, a negative errno will
1117 * be returned in error cases.
1118 */
1119int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
1120 size_t val_count)
1121{
1122 int ret = 0, i;
1123 size_t val_bytes = map->format.val_bytes;
1124 void *wval;
1125
1126 if (!map->format.parse_val)
1127 return -EINVAL;
Stephen Warrenf01ee602012-04-09 13:40:24 -06001128 if (reg % map->reg_stride)
1129 return -EINVAL;
Laxman Dewangan8eaeb212012-02-12 19:49:43 +05301130
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001131 map->lock(map->lock_arg);
Laxman Dewangan8eaeb212012-02-12 19:49:43 +05301132
1133 /* No formatting is require if val_byte is 1 */
1134 if (val_bytes == 1) {
1135 wval = (void *)val;
1136 } else {
1137 wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL);
1138 if (!wval) {
1139 ret = -ENOMEM;
1140 dev_err(map->dev, "Error in memory allocation\n");
1141 goto out;
1142 }
1143 for (i = 0; i < val_count * val_bytes; i += val_bytes)
1144 map->format.parse_val(wval + i);
1145 }
Ashish Jangam2e33caf2012-04-30 23:23:40 +01001146 /*
1147 * Some devices does not support bulk write, for
1148 * them we have a series of single write operations.
1149 */
1150 if (map->use_single_rw) {
1151 for (i = 0; i < val_count; i++) {
1152 ret = regmap_raw_write(map,
1153 reg + (i * map->reg_stride),
1154 val + (i * val_bytes),
1155 val_bytes);
1156 if (ret != 0)
1157 return ret;
1158 }
1159 } else {
1160 ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count);
1161 }
Laxman Dewangan8eaeb212012-02-12 19:49:43 +05301162
1163 if (val_bytes != 1)
1164 kfree(wval);
1165
1166out:
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001167 map->unlock(map->lock_arg);
Laxman Dewangan8eaeb212012-02-12 19:49:43 +05301168 return ret;
1169}
1170EXPORT_SYMBOL_GPL(regmap_bulk_write);
1171
Mark Brownb83a3132011-05-11 19:59:58 +02001172static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
1173 unsigned int val_len)
1174{
Mark Brown98bc7df2012-10-04 17:31:11 +01001175 struct regmap_range_node *range;
Mark Brownb83a3132011-05-11 19:59:58 +02001176 u8 *u8 = map->work_buf;
1177 int ret;
1178
Mark Brown98bc7df2012-10-04 17:31:11 +01001179 range = _regmap_range_lookup(map, reg);
1180 if (range) {
1181 ret = _regmap_select_page(map, &reg, range,
1182 val_len / map->format.val_bytes);
Mark Brown0ff3e622012-10-04 17:39:13 +01001183 if (ret != 0)
Mark Brown98bc7df2012-10-04 17:31:11 +01001184 return ret;
1185 }
Krystian Garbaciak6863ca62012-06-15 11:23:56 +01001186
Marc Reillyd939fb92012-03-16 12:11:43 +11001187 map->format.format_reg(map->work_buf, reg, map->reg_shift);
Mark Brownb83a3132011-05-11 19:59:58 +02001188
1189 /*
Lars-Peter Clausen6f306442011-09-05 20:46:32 +02001190 * Some buses or devices flag reads by setting the high bits in the
Mark Brownb83a3132011-05-11 19:59:58 +02001191 * register addresss; since it's always the high bits for all
1192 * current formats we can do this here rather than in
1193 * formatting. This may break if we get interesting formats.
1194 */
Lars-Peter Clausen6f306442011-09-05 20:46:32 +02001195 u8[0] |= map->read_flag_mask;
Mark Brownb83a3132011-05-11 19:59:58 +02001196
Mark Brownfb2736b2011-07-24 21:30:55 +01001197 trace_regmap_hw_read_start(map->dev, reg,
1198 val_len / map->format.val_bytes);
1199
Stephen Warren0135bbc2012-04-04 15:48:30 -06001200 ret = map->bus->read(map->bus_context, map->work_buf,
Mark Brown82159ba2012-01-18 10:52:25 +00001201 map->format.reg_bytes + map->format.pad_bytes,
Mark Brown40c5cc22011-07-24 22:39:12 +01001202 val, val_len);
Mark Brownb83a3132011-05-11 19:59:58 +02001203
Mark Brownfb2736b2011-07-24 21:30:55 +01001204 trace_regmap_hw_read_done(map->dev, reg,
1205 val_len / map->format.val_bytes);
1206
1207 return ret;
Mark Brownb83a3132011-05-11 19:59:58 +02001208}
1209
Andrey Smirnovad278402013-01-12 12:54:12 -08001210static int _regmap_bus_read(void *context, unsigned int reg,
1211 unsigned int *val)
1212{
1213 int ret;
1214 struct regmap *map = context;
1215
1216 if (!map->format.parse_val)
1217 return -EINVAL;
1218
1219 ret = _regmap_raw_read(map, reg, map->work_buf, map->format.val_bytes);
1220 if (ret == 0)
1221 *val = map->format.parse_val(map->work_buf);
1222
1223 return ret;
1224}
1225
Mark Brownb83a3132011-05-11 19:59:58 +02001226static int _regmap_read(struct regmap *map, unsigned int reg,
1227 unsigned int *val)
1228{
1229 int ret;
Andrey Smirnovad278402013-01-12 12:54:12 -08001230 BUG_ON(!map->reg_read);
Mark Brownb83a3132011-05-11 19:59:58 +02001231
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +01001232 if (!map->cache_bypass) {
1233 ret = regcache_read(map, reg, val);
1234 if (ret == 0)
1235 return 0;
1236 }
1237
1238 if (map->cache_only)
1239 return -EBUSY;
1240
Andrey Smirnovad278402013-01-12 12:54:12 -08001241 ret = map->reg_read(map, reg, val);
Mark Brownfb2736b2011-07-24 21:30:55 +01001242 if (ret == 0) {
Mark Brown1044c182012-07-06 14:10:23 +01001243#ifdef LOG_DEVICE
1244 if (strcmp(dev_name(map->dev), LOG_DEVICE) == 0)
1245 dev_info(map->dev, "%x => %x\n", reg, *val);
1246#endif
1247
Mark Brownfb2736b2011-07-24 21:30:55 +01001248 trace_regmap_reg_read(map->dev, reg, *val);
Mark Brownb83a3132011-05-11 19:59:58 +02001249
Andrey Smirnovad278402013-01-12 12:54:12 -08001250 if (!map->cache_bypass)
1251 regcache_write(map, reg, *val);
1252 }
Mark Brownf2985362012-04-30 21:25:05 +01001253
Mark Brownb83a3132011-05-11 19:59:58 +02001254 return ret;
1255}
1256
1257/**
1258 * regmap_read(): Read a value from a single register
1259 *
1260 * @map: Register map to write to
1261 * @reg: Register to be read from
1262 * @val: Pointer to store read value
1263 *
1264 * A value of zero will be returned on success, a negative errno will
1265 * be returned in error cases.
1266 */
1267int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val)
1268{
1269 int ret;
1270
Stephen Warrenf01ee602012-04-09 13:40:24 -06001271 if (reg % map->reg_stride)
1272 return -EINVAL;
1273
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001274 map->lock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001275
1276 ret = _regmap_read(map, reg, val);
1277
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001278 map->unlock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001279
1280 return ret;
1281}
1282EXPORT_SYMBOL_GPL(regmap_read);
1283
1284/**
1285 * regmap_raw_read(): Read raw data from the device
1286 *
1287 * @map: Register map to write to
1288 * @reg: First register to be read from
1289 * @val: Pointer to store read value
1290 * @val_len: Size of data to read
1291 *
1292 * A value of zero will be returned on success, a negative errno will
1293 * be returned in error cases.
1294 */
1295int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
1296 size_t val_len)
1297{
Mark Brownb8fb5ab2012-02-21 19:12:47 +00001298 size_t val_bytes = map->format.val_bytes;
1299 size_t val_count = val_len / val_bytes;
1300 unsigned int v;
1301 int ret, i;
Mark Brown04e016a2011-10-09 13:35:43 +01001302
Stephen Warren851960b2012-04-06 15:16:03 -06001303 if (val_len % map->format.val_bytes)
1304 return -EINVAL;
Stephen Warrenf01ee602012-04-09 13:40:24 -06001305 if (reg % map->reg_stride)
1306 return -EINVAL;
Stephen Warren851960b2012-04-06 15:16:03 -06001307
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001308 map->lock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001309
Mark Brownb8fb5ab2012-02-21 19:12:47 +00001310 if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass ||
1311 map->cache_type == REGCACHE_NONE) {
1312 /* Physical block read if there's no cache involved */
1313 ret = _regmap_raw_read(map, reg, val, val_len);
Mark Brownb83a3132011-05-11 19:59:58 +02001314
Mark Brownb8fb5ab2012-02-21 19:12:47 +00001315 } else {
1316 /* Otherwise go word by word for the cache; should be low
1317 * cost as we expect to hit the cache.
1318 */
1319 for (i = 0; i < val_count; i++) {
Stephen Warrenf01ee602012-04-09 13:40:24 -06001320 ret = _regmap_read(map, reg + (i * map->reg_stride),
1321 &v);
Mark Brownb8fb5ab2012-02-21 19:12:47 +00001322 if (ret != 0)
1323 goto out;
1324
Marc Reillyd939fb92012-03-16 12:11:43 +11001325 map->format.format_val(val + (i * val_bytes), v, 0);
Mark Brownb8fb5ab2012-02-21 19:12:47 +00001326 }
1327 }
1328
1329 out:
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001330 map->unlock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001331
1332 return ret;
1333}
1334EXPORT_SYMBOL_GPL(regmap_raw_read);
1335
1336/**
1337 * regmap_bulk_read(): Read multiple registers from the device
1338 *
1339 * @map: Register map to write to
1340 * @reg: First register to be read from
1341 * @val: Pointer to store read value, in native register size for device
1342 * @val_count: Number of registers to read
1343 *
1344 * A value of zero will be returned on success, a negative errno will
1345 * be returned in error cases.
1346 */
1347int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
1348 size_t val_count)
1349{
1350 int ret, i;
1351 size_t val_bytes = map->format.val_bytes;
Lars-Peter Clausen82cd9962011-11-08 18:37:25 +01001352 bool vol = regmap_volatile_range(map, reg, val_count);
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +01001353
Mark Brownb83a3132011-05-11 19:59:58 +02001354 if (!map->format.parse_val)
1355 return -EINVAL;
Stephen Warrenf01ee602012-04-09 13:40:24 -06001356 if (reg % map->reg_stride)
1357 return -EINVAL;
Mark Brownb83a3132011-05-11 19:59:58 +02001358
Mark Brownde2d8082011-10-10 13:24:52 +01001359 if (vol || map->cache_type == REGCACHE_NONE) {
Ashish Jangam2e33caf2012-04-30 23:23:40 +01001360 /*
1361 * Some devices does not support bulk read, for
1362 * them we have a series of single read operations.
1363 */
1364 if (map->use_single_rw) {
1365 for (i = 0; i < val_count; i++) {
1366 ret = regmap_raw_read(map,
1367 reg + (i * map->reg_stride),
1368 val + (i * val_bytes),
1369 val_bytes);
1370 if (ret != 0)
1371 return ret;
1372 }
1373 } else {
1374 ret = regmap_raw_read(map, reg, val,
1375 val_bytes * val_count);
1376 if (ret != 0)
1377 return ret;
1378 }
Mark Brownde2d8082011-10-10 13:24:52 +01001379
1380 for (i = 0; i < val_count * val_bytes; i += val_bytes)
1381 map->format.parse_val(val + i);
1382 } else {
1383 for (i = 0; i < val_count; i++) {
Laxman Dewangan6560ffd2012-05-09 17:43:12 +05301384 unsigned int ival;
Stephen Warrenf01ee602012-04-09 13:40:24 -06001385 ret = regmap_read(map, reg + (i * map->reg_stride),
Mark Brown25061d22012-05-12 13:06:08 +01001386 &ival);
Mark Brownde2d8082011-10-10 13:24:52 +01001387 if (ret != 0)
1388 return ret;
Laxman Dewangan6560ffd2012-05-09 17:43:12 +05301389 memcpy(val + (i * val_bytes), &ival, val_bytes);
Mark Brownde2d8082011-10-10 13:24:52 +01001390 }
1391 }
Mark Brownb83a3132011-05-11 19:59:58 +02001392
1393 return 0;
1394}
1395EXPORT_SYMBOL_GPL(regmap_bulk_read);
1396
Mark Brown018690d2011-11-29 20:10:36 +00001397static int _regmap_update_bits(struct regmap *map, unsigned int reg,
1398 unsigned int mask, unsigned int val,
1399 bool *change)
Mark Brownb83a3132011-05-11 19:59:58 +02001400{
1401 int ret;
Mark Brownd91e8db2011-11-18 16:03:50 +00001402 unsigned int tmp, orig;
Mark Brownb83a3132011-05-11 19:59:58 +02001403
Mark Brownd91e8db2011-11-18 16:03:50 +00001404 ret = _regmap_read(map, reg, &orig);
Mark Brownb83a3132011-05-11 19:59:58 +02001405 if (ret != 0)
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001406 return ret;
Mark Brownb83a3132011-05-11 19:59:58 +02001407
Mark Brownd91e8db2011-11-18 16:03:50 +00001408 tmp = orig & ~mask;
Mark Brownb83a3132011-05-11 19:59:58 +02001409 tmp |= val & mask;
1410
Mark Brown018690d2011-11-29 20:10:36 +00001411 if (tmp != orig) {
Mark Brownd91e8db2011-11-18 16:03:50 +00001412 ret = _regmap_write(map, reg, tmp);
Mark Brown018690d2011-11-29 20:10:36 +00001413 *change = true;
1414 } else {
1415 *change = false;
1416 }
Mark Brownb83a3132011-05-11 19:59:58 +02001417
Mark Brownb83a3132011-05-11 19:59:58 +02001418 return ret;
1419}
Mark Brown018690d2011-11-29 20:10:36 +00001420
1421/**
1422 * regmap_update_bits: Perform a read/modify/write cycle on the register map
1423 *
1424 * @map: Register map to update
1425 * @reg: Register to update
1426 * @mask: Bitmask to change
1427 * @val: New value for bitmask
1428 *
1429 * Returns zero for success, a negative number on error.
1430 */
1431int regmap_update_bits(struct regmap *map, unsigned int reg,
1432 unsigned int mask, unsigned int val)
1433{
1434 bool change;
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001435 int ret;
1436
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001437 map->lock(map->lock_arg);
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001438 ret = _regmap_update_bits(map, reg, mask, val, &change);
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001439 map->unlock(map->lock_arg);
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001440
1441 return ret;
Mark Brown018690d2011-11-29 20:10:36 +00001442}
Mark Brownb83a3132011-05-11 19:59:58 +02001443EXPORT_SYMBOL_GPL(regmap_update_bits);
Mark Brown31244e32011-07-20 22:56:53 +01001444
Mark Brown018690d2011-11-29 20:10:36 +00001445/**
1446 * regmap_update_bits_check: Perform a read/modify/write cycle on the
1447 * register map and report if updated
1448 *
1449 * @map: Register map to update
1450 * @reg: Register to update
1451 * @mask: Bitmask to change
1452 * @val: New value for bitmask
1453 * @change: Boolean indicating if a write was done
1454 *
1455 * Returns zero for success, a negative number on error.
1456 */
1457int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1458 unsigned int mask, unsigned int val,
1459 bool *change)
1460{
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001461 int ret;
1462
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001463 map->lock(map->lock_arg);
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001464 ret = _regmap_update_bits(map, reg, mask, val, change);
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001465 map->unlock(map->lock_arg);
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001466 return ret;
Mark Brown018690d2011-11-29 20:10:36 +00001467}
1468EXPORT_SYMBOL_GPL(regmap_update_bits_check);
1469
Mark Brown22f0d902012-01-21 12:01:14 +00001470/**
1471 * regmap_register_patch: Register and apply register updates to be applied
1472 * on device initialistion
1473 *
1474 * @map: Register map to apply updates to.
1475 * @regs: Values to update.
1476 * @num_regs: Number of entries in regs.
1477 *
1478 * Register a set of register updates to be applied to the device
1479 * whenever the device registers are synchronised with the cache and
1480 * apply them immediately. Typically this is used to apply
1481 * corrections to be applied to the device defaults on startup, such
1482 * as the updates some vendors provide to undocumented registers.
1483 */
1484int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
1485 int num_regs)
1486{
1487 int i, ret;
1488 bool bypass;
1489
1490 /* If needed the implementation can be extended to support this */
1491 if (map->patch)
1492 return -EBUSY;
1493
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001494 map->lock(map->lock_arg);
Mark Brown22f0d902012-01-21 12:01:14 +00001495
1496 bypass = map->cache_bypass;
1497
1498 map->cache_bypass = true;
1499
1500 /* Write out first; it's useful to apply even if we fail later. */
1501 for (i = 0; i < num_regs; i++) {
1502 ret = _regmap_write(map, regs[i].reg, regs[i].def);
1503 if (ret != 0) {
1504 dev_err(map->dev, "Failed to write %x = %x: %d\n",
1505 regs[i].reg, regs[i].def, ret);
1506 goto out;
1507 }
1508 }
1509
Axel Lin2a14d7d92012-02-10 19:29:55 +08001510 map->patch = kcalloc(num_regs, sizeof(struct reg_default), GFP_KERNEL);
Mark Brown22f0d902012-01-21 12:01:14 +00001511 if (map->patch != NULL) {
1512 memcpy(map->patch, regs,
1513 num_regs * sizeof(struct reg_default));
1514 map->patch_regs = num_regs;
1515 } else {
1516 ret = -ENOMEM;
1517 }
1518
1519out:
1520 map->cache_bypass = bypass;
1521
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001522 map->unlock(map->lock_arg);
Mark Brown22f0d902012-01-21 12:01:14 +00001523
1524 return ret;
1525}
1526EXPORT_SYMBOL_GPL(regmap_register_patch);
1527
Mark Browneae4b512012-03-14 13:15:03 +00001528/*
Mark Browna6539c32012-02-17 14:20:14 -08001529 * regmap_get_val_bytes(): Report the size of a register value
1530 *
1531 * Report the size of a register value, mainly intended to for use by
1532 * generic infrastructure built on top of regmap.
1533 */
1534int regmap_get_val_bytes(struct regmap *map)
1535{
1536 if (map->format.format_write)
1537 return -EINVAL;
1538
1539 return map->format.val_bytes;
1540}
1541EXPORT_SYMBOL_GPL(regmap_get_val_bytes);
1542
Mark Brown31244e32011-07-20 22:56:53 +01001543static int __init regmap_initcall(void)
1544{
1545 regmap_debugfs_initcall();
1546
1547 return 0;
1548}
1549postcore_initcall(regmap_initcall);