blob: 6845a077bd845536677d41bc10b9cb0540180148 [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);
Andrey Smirnov07c320d2013-01-12 12:54:13 -080039static int _regmap_bus_formatted_write(void *context, unsigned int reg,
40 unsigned int val);
41static int _regmap_bus_raw_write(void *context, unsigned int reg,
42 unsigned int val);
Andrey Smirnovad278402013-01-12 12:54:12 -080043
Davide Ciminaghi76aad392012-11-20 15:20:30 +010044bool regmap_reg_in_ranges(unsigned int reg,
45 const struct regmap_range *ranges,
46 unsigned int nranges)
47{
48 const struct regmap_range *r;
49 int i;
50
51 for (i = 0, r = ranges; i < nranges; i++, r++)
52 if (regmap_reg_in_range(reg, r))
53 return true;
54 return false;
55}
56EXPORT_SYMBOL_GPL(regmap_reg_in_ranges);
57
58static bool _regmap_check_range_table(struct regmap *map,
59 unsigned int reg,
60 const struct regmap_access_table *table)
61{
62 /* Check "no ranges" first */
63 if (regmap_reg_in_ranges(reg, table->no_ranges, table->n_no_ranges))
64 return false;
65
66 /* In case zero "yes ranges" are supplied, any reg is OK */
67 if (!table->n_yes_ranges)
68 return true;
69
70 return regmap_reg_in_ranges(reg, table->yes_ranges,
71 table->n_yes_ranges);
72}
73
Mark Brown8de2f082011-08-10 17:14:41 +090074bool regmap_writeable(struct regmap *map, unsigned int reg)
75{
76 if (map->max_register && reg > map->max_register)
77 return false;
78
79 if (map->writeable_reg)
80 return map->writeable_reg(map->dev, reg);
81
Davide Ciminaghi76aad392012-11-20 15:20:30 +010082 if (map->wr_table)
83 return _regmap_check_range_table(map, reg, map->wr_table);
84
Mark Brown8de2f082011-08-10 17:14:41 +090085 return true;
86}
87
88bool regmap_readable(struct regmap *map, unsigned int reg)
89{
90 if (map->max_register && reg > map->max_register)
91 return false;
92
Wolfram Sang4191f192012-01-30 15:08:16 +010093 if (map->format.format_write)
94 return false;
95
Mark Brown8de2f082011-08-10 17:14:41 +090096 if (map->readable_reg)
97 return map->readable_reg(map->dev, reg);
98
Davide Ciminaghi76aad392012-11-20 15:20:30 +010099 if (map->rd_table)
100 return _regmap_check_range_table(map, reg, map->rd_table);
101
Mark Brown8de2f082011-08-10 17:14:41 +0900102 return true;
103}
104
105bool regmap_volatile(struct regmap *map, unsigned int reg)
106{
Wolfram Sang4191f192012-01-30 15:08:16 +0100107 if (!regmap_readable(map, reg))
Mark Brown8de2f082011-08-10 17:14:41 +0900108 return false;
109
110 if (map->volatile_reg)
111 return map->volatile_reg(map->dev, reg);
112
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100113 if (map->volatile_table)
114 return _regmap_check_range_table(map, reg, map->volatile_table);
115
Mark Brown8de2f082011-08-10 17:14:41 +0900116 return true;
117}
118
119bool regmap_precious(struct regmap *map, unsigned int reg)
120{
Wolfram Sang4191f192012-01-30 15:08:16 +0100121 if (!regmap_readable(map, reg))
Mark Brown8de2f082011-08-10 17:14:41 +0900122 return false;
123
124 if (map->precious_reg)
125 return map->precious_reg(map->dev, reg);
126
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100127 if (map->precious_table)
128 return _regmap_check_range_table(map, reg, map->precious_table);
129
Mark Brown8de2f082011-08-10 17:14:41 +0900130 return false;
131}
132
Lars-Peter Clausen82cd9962011-11-08 18:37:25 +0100133static bool regmap_volatile_range(struct regmap *map, unsigned int reg,
Paul Bollea8f28cf2012-10-08 22:06:30 +0200134 size_t num)
Lars-Peter Clausen82cd9962011-11-08 18:37:25 +0100135{
136 unsigned int i;
137
138 for (i = 0; i < num; i++)
139 if (!regmap_volatile(map, reg + i))
140 return false;
141
142 return true;
143}
144
Wolfram Sang9aa50752012-01-27 16:10:22 +0100145static void regmap_format_2_6_write(struct regmap *map,
146 unsigned int reg, unsigned int val)
147{
148 u8 *out = map->work_buf;
149
150 *out = (reg << 6) | val;
151}
152
Mark Brownb83a3132011-05-11 19:59:58 +0200153static void regmap_format_4_12_write(struct regmap *map,
154 unsigned int reg, unsigned int val)
155{
156 __be16 *out = map->work_buf;
157 *out = cpu_to_be16((reg << 12) | val);
158}
159
160static void regmap_format_7_9_write(struct regmap *map,
161 unsigned int reg, unsigned int val)
162{
163 __be16 *out = map->work_buf;
164 *out = cpu_to_be16((reg << 9) | val);
165}
166
Lars-Peter Clausen7e5ec632011-11-16 16:28:21 +0100167static void regmap_format_10_14_write(struct regmap *map,
168 unsigned int reg, unsigned int val)
169{
170 u8 *out = map->work_buf;
171
172 out[2] = val;
173 out[1] = (val >> 8) | (reg << 6);
174 out[0] = reg >> 2;
175}
176
Marc Reillyd939fb92012-03-16 12:11:43 +1100177static void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
Mark Brownb83a3132011-05-11 19:59:58 +0200178{
179 u8 *b = buf;
180
Marc Reillyd939fb92012-03-16 12:11:43 +1100181 b[0] = val << shift;
Mark Brownb83a3132011-05-11 19:59:58 +0200182}
183
Stephen Warren141eba22012-05-24 10:47:26 -0600184static void regmap_format_16_be(void *buf, unsigned int val, unsigned int shift)
Mark Brownb83a3132011-05-11 19:59:58 +0200185{
186 __be16 *b = buf;
187
Marc Reillyd939fb92012-03-16 12:11:43 +1100188 b[0] = cpu_to_be16(val << shift);
Mark Brownb83a3132011-05-11 19:59:58 +0200189}
190
Stephen Warren141eba22012-05-24 10:47:26 -0600191static void regmap_format_16_native(void *buf, unsigned int val,
192 unsigned int shift)
193{
194 *(u16 *)buf = val << shift;
195}
196
Marc Reillyd939fb92012-03-16 12:11:43 +1100197static void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
Marc Reillyea279fc2012-03-16 12:11:42 +1100198{
199 u8 *b = buf;
200
Marc Reillyd939fb92012-03-16 12:11:43 +1100201 val <<= shift;
202
Marc Reillyea279fc2012-03-16 12:11:42 +1100203 b[0] = val >> 16;
204 b[1] = val >> 8;
205 b[2] = val;
206}
207
Stephen Warren141eba22012-05-24 10:47:26 -0600208static void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift)
Mark Brown7d5e5252012-02-17 15:58:25 -0800209{
210 __be32 *b = buf;
211
Marc Reillyd939fb92012-03-16 12:11:43 +1100212 b[0] = cpu_to_be32(val << shift);
Mark Brown7d5e5252012-02-17 15:58:25 -0800213}
214
Stephen Warren141eba22012-05-24 10:47:26 -0600215static void regmap_format_32_native(void *buf, unsigned int val,
216 unsigned int shift)
217{
218 *(u32 *)buf = val << shift;
219}
220
Mark Brownb83a3132011-05-11 19:59:58 +0200221static unsigned int regmap_parse_8(void *buf)
222{
223 u8 *b = buf;
224
225 return b[0];
226}
227
Stephen Warren141eba22012-05-24 10:47:26 -0600228static unsigned int regmap_parse_16_be(void *buf)
Mark Brownb83a3132011-05-11 19:59:58 +0200229{
230 __be16 *b = buf;
231
232 b[0] = be16_to_cpu(b[0]);
233
234 return b[0];
235}
236
Stephen Warren141eba22012-05-24 10:47:26 -0600237static unsigned int regmap_parse_16_native(void *buf)
238{
239 return *(u16 *)buf;
240}
241
Marc Reillyea279fc2012-03-16 12:11:42 +1100242static unsigned int regmap_parse_24(void *buf)
243{
244 u8 *b = buf;
245 unsigned int ret = b[2];
246 ret |= ((unsigned int)b[1]) << 8;
247 ret |= ((unsigned int)b[0]) << 16;
248
249 return ret;
250}
251
Stephen Warren141eba22012-05-24 10:47:26 -0600252static unsigned int regmap_parse_32_be(void *buf)
Mark Brown7d5e5252012-02-17 15:58:25 -0800253{
254 __be32 *b = buf;
255
256 b[0] = be32_to_cpu(b[0]);
257
258 return b[0];
259}
260
Stephen Warren141eba22012-05-24 10:47:26 -0600261static unsigned int regmap_parse_32_native(void *buf)
262{
263 return *(u32 *)buf;
264}
265
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200266static void regmap_lock_mutex(void *__map)
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600267{
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200268 struct regmap *map = __map;
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600269 mutex_lock(&map->mutex);
270}
271
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200272static void regmap_unlock_mutex(void *__map)
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600273{
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200274 struct regmap *map = __map;
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600275 mutex_unlock(&map->mutex);
276}
277
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200278static void regmap_lock_spinlock(void *__map)
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600279{
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200280 struct regmap *map = __map;
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600281 spin_lock(&map->spinlock);
282}
283
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200284static void regmap_unlock_spinlock(void *__map)
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600285{
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200286 struct regmap *map = __map;
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600287 spin_unlock(&map->spinlock);
288}
289
Mark Brown72b39f62012-05-08 17:44:40 +0100290static void dev_get_regmap_release(struct device *dev, void *res)
291{
292 /*
293 * We don't actually have anything to do here; the goal here
294 * is not to manage the regmap but to provide a simple way to
295 * get the regmap back given a struct device.
296 */
297}
298
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100299static bool _regmap_range_add(struct regmap *map,
300 struct regmap_range_node *data)
301{
302 struct rb_root *root = &map->range_tree;
303 struct rb_node **new = &(root->rb_node), *parent = NULL;
304
305 while (*new) {
306 struct regmap_range_node *this =
307 container_of(*new, struct regmap_range_node, node);
308
309 parent = *new;
310 if (data->range_max < this->range_min)
311 new = &((*new)->rb_left);
312 else if (data->range_min > this->range_max)
313 new = &((*new)->rb_right);
314 else
315 return false;
316 }
317
318 rb_link_node(&data->node, parent, new);
319 rb_insert_color(&data->node, root);
320
321 return true;
322}
323
324static struct regmap_range_node *_regmap_range_lookup(struct regmap *map,
325 unsigned int reg)
326{
327 struct rb_node *node = map->range_tree.rb_node;
328
329 while (node) {
330 struct regmap_range_node *this =
331 container_of(node, struct regmap_range_node, node);
332
333 if (reg < this->range_min)
334 node = node->rb_left;
335 else if (reg > this->range_max)
336 node = node->rb_right;
337 else
338 return this;
339 }
340
341 return NULL;
342}
343
344static void regmap_range_exit(struct regmap *map)
345{
346 struct rb_node *next;
347 struct regmap_range_node *range_node;
348
349 next = rb_first(&map->range_tree);
350 while (next) {
351 range_node = rb_entry(next, struct regmap_range_node, node);
352 next = rb_next(&range_node->node);
353 rb_erase(&range_node->node, &map->range_tree);
354 kfree(range_node);
355 }
356
357 kfree(map->selector_work_buf);
358}
359
Mark Brownb83a3132011-05-11 19:59:58 +0200360/**
361 * regmap_init(): Initialise register map
362 *
363 * @dev: Device that will be interacted with
364 * @bus: Bus-specific callbacks to use with device
Stephen Warren0135bbc2012-04-04 15:48:30 -0600365 * @bus_context: Data passed to bus-specific callbacks
Mark Brownb83a3132011-05-11 19:59:58 +0200366 * @config: Configuration for register map
367 *
368 * The return value will be an ERR_PTR() on error or a valid pointer to
369 * a struct regmap. This function should generally not be called
370 * directly, it should be called by bus-specific init functions.
371 */
372struct regmap *regmap_init(struct device *dev,
373 const struct regmap_bus *bus,
Stephen Warren0135bbc2012-04-04 15:48:30 -0600374 void *bus_context,
Mark Brownb83a3132011-05-11 19:59:58 +0200375 const struct regmap_config *config)
376{
Mark Brown72b39f62012-05-08 17:44:40 +0100377 struct regmap *map, **m;
Mark Brownb83a3132011-05-11 19:59:58 +0200378 int ret = -EINVAL;
Stephen Warren141eba22012-05-24 10:47:26 -0600379 enum regmap_endian reg_endian, val_endian;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100380 int i, j;
Mark Brownb83a3132011-05-11 19:59:58 +0200381
382 if (!bus || !config)
Lars-Peter Clausenabbb18f2011-11-14 10:40:15 +0100383 goto err;
Mark Brownb83a3132011-05-11 19:59:58 +0200384
385 map = kzalloc(sizeof(*map), GFP_KERNEL);
386 if (map == NULL) {
387 ret = -ENOMEM;
388 goto err;
389 }
390
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200391 if (config->lock && config->unlock) {
392 map->lock = config->lock;
393 map->unlock = config->unlock;
394 map->lock_arg = config->lock_arg;
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600395 } else {
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200396 if (bus->fast_io) {
397 spin_lock_init(&map->spinlock);
398 map->lock = regmap_lock_spinlock;
399 map->unlock = regmap_unlock_spinlock;
400 } else {
401 mutex_init(&map->mutex);
402 map->lock = regmap_lock_mutex;
403 map->unlock = regmap_unlock_mutex;
404 }
405 map->lock_arg = map;
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600406 }
Wolfram Sangc212acc2012-01-28 02:16:41 +0100407 map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
Mark Brown82159ba2012-01-18 10:52:25 +0000408 map->format.pad_bytes = config->pad_bits / 8;
Wolfram Sangc212acc2012-01-28 02:16:41 +0100409 map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
Fabio Estevam5494a982012-05-31 21:10:30 -0300410 map->format.buf_size = DIV_ROUND_UP(config->reg_bits +
411 config->val_bits + config->pad_bits, 8);
Marc Reillyd939fb92012-03-16 12:11:43 +1100412 map->reg_shift = config->pad_bits % 8;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600413 if (config->reg_stride)
414 map->reg_stride = config->reg_stride;
415 else
416 map->reg_stride = 1;
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100417 map->use_single_rw = config->use_single_rw;
Mark Brownb83a3132011-05-11 19:59:58 +0200418 map->dev = dev;
419 map->bus = bus;
Stephen Warren0135bbc2012-04-04 15:48:30 -0600420 map->bus_context = bus_context;
Mark Brown2e2ae662011-07-20 22:33:39 +0100421 map->max_register = config->max_register;
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100422 map->wr_table = config->wr_table;
423 map->rd_table = config->rd_table;
424 map->volatile_table = config->volatile_table;
425 map->precious_table = config->precious_table;
Mark Brown2e2ae662011-07-20 22:33:39 +0100426 map->writeable_reg = config->writeable_reg;
427 map->readable_reg = config->readable_reg;
428 map->volatile_reg = config->volatile_reg;
Mark Brown2efe1642011-08-08 15:41:46 +0900429 map->precious_reg = config->precious_reg;
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100430 map->cache_type = config->cache_type;
Mark Brown72b39f62012-05-08 17:44:40 +0100431 map->name = config->name;
Mark Brownb83a3132011-05-11 19:59:58 +0200432
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200433 if (config->read_flag_mask || config->write_flag_mask) {
434 map->read_flag_mask = config->read_flag_mask;
435 map->write_flag_mask = config->write_flag_mask;
436 } else {
437 map->read_flag_mask = bus->read_flag_mask;
438 }
439
Andrey Smirnovad278402013-01-12 12:54:12 -0800440 map->reg_read = _regmap_bus_read;
441
Stephen Warren141eba22012-05-24 10:47:26 -0600442 reg_endian = config->reg_format_endian;
443 if (reg_endian == REGMAP_ENDIAN_DEFAULT)
444 reg_endian = bus->reg_format_endian_default;
445 if (reg_endian == REGMAP_ENDIAN_DEFAULT)
446 reg_endian = REGMAP_ENDIAN_BIG;
447
448 val_endian = config->val_format_endian;
449 if (val_endian == REGMAP_ENDIAN_DEFAULT)
450 val_endian = bus->val_format_endian_default;
451 if (val_endian == REGMAP_ENDIAN_DEFAULT)
452 val_endian = REGMAP_ENDIAN_BIG;
453
Marc Reillyd939fb92012-03-16 12:11:43 +1100454 switch (config->reg_bits + map->reg_shift) {
Wolfram Sang9aa50752012-01-27 16:10:22 +0100455 case 2:
456 switch (config->val_bits) {
457 case 6:
458 map->format.format_write = regmap_format_2_6_write;
459 break;
460 default:
461 goto err_map;
462 }
463 break;
464
Mark Brownb83a3132011-05-11 19:59:58 +0200465 case 4:
466 switch (config->val_bits) {
467 case 12:
468 map->format.format_write = regmap_format_4_12_write;
469 break;
470 default:
471 goto err_map;
472 }
473 break;
474
475 case 7:
476 switch (config->val_bits) {
477 case 9:
478 map->format.format_write = regmap_format_7_9_write;
479 break;
480 default:
481 goto err_map;
482 }
483 break;
484
Lars-Peter Clausen7e5ec632011-11-16 16:28:21 +0100485 case 10:
486 switch (config->val_bits) {
487 case 14:
488 map->format.format_write = regmap_format_10_14_write;
489 break;
490 default:
491 goto err_map;
492 }
493 break;
494
Mark Brownb83a3132011-05-11 19:59:58 +0200495 case 8:
496 map->format.format_reg = regmap_format_8;
497 break;
498
499 case 16:
Stephen Warren141eba22012-05-24 10:47:26 -0600500 switch (reg_endian) {
501 case REGMAP_ENDIAN_BIG:
502 map->format.format_reg = regmap_format_16_be;
503 break;
504 case REGMAP_ENDIAN_NATIVE:
505 map->format.format_reg = regmap_format_16_native;
506 break;
507 default:
508 goto err_map;
509 }
Mark Brownb83a3132011-05-11 19:59:58 +0200510 break;
511
Mark Brown7d5e5252012-02-17 15:58:25 -0800512 case 32:
Stephen Warren141eba22012-05-24 10:47:26 -0600513 switch (reg_endian) {
514 case REGMAP_ENDIAN_BIG:
515 map->format.format_reg = regmap_format_32_be;
516 break;
517 case REGMAP_ENDIAN_NATIVE:
518 map->format.format_reg = regmap_format_32_native;
519 break;
520 default:
521 goto err_map;
522 }
Mark Brown7d5e5252012-02-17 15:58:25 -0800523 break;
524
Mark Brownb83a3132011-05-11 19:59:58 +0200525 default:
526 goto err_map;
527 }
528
529 switch (config->val_bits) {
530 case 8:
531 map->format.format_val = regmap_format_8;
532 map->format.parse_val = regmap_parse_8;
533 break;
534 case 16:
Stephen Warren141eba22012-05-24 10:47:26 -0600535 switch (val_endian) {
536 case REGMAP_ENDIAN_BIG:
537 map->format.format_val = regmap_format_16_be;
538 map->format.parse_val = regmap_parse_16_be;
539 break;
540 case REGMAP_ENDIAN_NATIVE:
541 map->format.format_val = regmap_format_16_native;
542 map->format.parse_val = regmap_parse_16_native;
543 break;
544 default:
545 goto err_map;
546 }
Mark Brownb83a3132011-05-11 19:59:58 +0200547 break;
Marc Reillyea279fc2012-03-16 12:11:42 +1100548 case 24:
Stephen Warren141eba22012-05-24 10:47:26 -0600549 if (val_endian != REGMAP_ENDIAN_BIG)
550 goto err_map;
Marc Reillyea279fc2012-03-16 12:11:42 +1100551 map->format.format_val = regmap_format_24;
552 map->format.parse_val = regmap_parse_24;
553 break;
Mark Brown7d5e5252012-02-17 15:58:25 -0800554 case 32:
Stephen Warren141eba22012-05-24 10:47:26 -0600555 switch (val_endian) {
556 case REGMAP_ENDIAN_BIG:
557 map->format.format_val = regmap_format_32_be;
558 map->format.parse_val = regmap_parse_32_be;
559 break;
560 case REGMAP_ENDIAN_NATIVE:
561 map->format.format_val = regmap_format_32_native;
562 map->format.parse_val = regmap_parse_32_native;
563 break;
564 default:
565 goto err_map;
566 }
Mark Brown7d5e5252012-02-17 15:58:25 -0800567 break;
Mark Brownb83a3132011-05-11 19:59:58 +0200568 }
569
Stephen Warren141eba22012-05-24 10:47:26 -0600570 if (map->format.format_write) {
571 if ((reg_endian != REGMAP_ENDIAN_BIG) ||
572 (val_endian != REGMAP_ENDIAN_BIG))
573 goto err_map;
Mark Brown7a647612012-04-30 23:26:32 +0100574 map->use_single_rw = true;
Stephen Warren141eba22012-05-24 10:47:26 -0600575 }
Mark Brown7a647612012-04-30 23:26:32 +0100576
Mark Brownb83a3132011-05-11 19:59:58 +0200577 if (!map->format.format_write &&
578 !(map->format.format_reg && map->format.format_val))
579 goto err_map;
580
Mark Brown82159ba2012-01-18 10:52:25 +0000581 map->work_buf = kzalloc(map->format.buf_size, GFP_KERNEL);
Mark Brownb83a3132011-05-11 19:59:58 +0200582 if (map->work_buf == NULL) {
583 ret = -ENOMEM;
Mark Brown5204f5e2011-09-05 08:07:47 -0700584 goto err_map;
Mark Brownb83a3132011-05-11 19:59:58 +0200585 }
586
Andrey Smirnov07c320d2013-01-12 12:54:13 -0800587 if (map->format.format_write)
588 map->reg_write = _regmap_bus_formatted_write;
589 else if (map->format.format_val)
590 map->reg_write = _regmap_bus_raw_write;
591
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100592 map->range_tree = RB_ROOT;
Mark Browne3549cd2012-10-02 20:17:15 +0100593 for (i = 0; i < config->num_ranges; i++) {
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100594 const struct regmap_range_cfg *range_cfg = &config->ranges[i];
595 struct regmap_range_node *new;
596
597 /* Sanity check */
Mark Brown061adc02012-10-03 12:17:51 +0100598 if (range_cfg->range_max < range_cfg->range_min) {
599 dev_err(map->dev, "Invalid range %d: %d < %d\n", i,
600 range_cfg->range_max, range_cfg->range_min);
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100601 goto err_range;
Mark Brown061adc02012-10-03 12:17:51 +0100602 }
603
604 if (range_cfg->range_max > map->max_register) {
605 dev_err(map->dev, "Invalid range %d: %d > %d\n", i,
606 range_cfg->range_max, map->max_register);
607 goto err_range;
608 }
609
610 if (range_cfg->selector_reg > map->max_register) {
611 dev_err(map->dev,
612 "Invalid range %d: selector out of map\n", i);
613 goto err_range;
614 }
615
616 if (range_cfg->window_len == 0) {
617 dev_err(map->dev, "Invalid range %d: window_len 0\n",
618 i);
619 goto err_range;
620 }
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100621
622 /* Make sure, that this register range has no selector
623 or data window within its boundary */
Mark Browne3549cd2012-10-02 20:17:15 +0100624 for (j = 0; j < config->num_ranges; j++) {
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100625 unsigned sel_reg = config->ranges[j].selector_reg;
626 unsigned win_min = config->ranges[j].window_start;
627 unsigned win_max = win_min +
628 config->ranges[j].window_len - 1;
629
630 if (range_cfg->range_min <= sel_reg &&
631 sel_reg <= range_cfg->range_max) {
Mark Brown061adc02012-10-03 12:17:51 +0100632 dev_err(map->dev,
633 "Range %d: selector for %d in window\n",
634 i, j);
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100635 goto err_range;
636 }
637
638 if (!(win_max < range_cfg->range_min ||
639 win_min > range_cfg->range_max)) {
Mark Brown061adc02012-10-03 12:17:51 +0100640 dev_err(map->dev,
641 "Range %d: window for %d in window\n",
642 i, j);
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100643 goto err_range;
644 }
645 }
646
647 new = kzalloc(sizeof(*new), GFP_KERNEL);
648 if (new == NULL) {
649 ret = -ENOMEM;
650 goto err_range;
651 }
652
Mark Brown4b020b32012-10-03 13:13:16 +0100653 new->map = map;
Mark Brownd058bb42012-10-03 12:40:47 +0100654 new->name = range_cfg->name;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100655 new->range_min = range_cfg->range_min;
656 new->range_max = range_cfg->range_max;
657 new->selector_reg = range_cfg->selector_reg;
658 new->selector_mask = range_cfg->selector_mask;
659 new->selector_shift = range_cfg->selector_shift;
660 new->window_start = range_cfg->window_start;
661 new->window_len = range_cfg->window_len;
662
663 if (_regmap_range_add(map, new) == false) {
Mark Brown061adc02012-10-03 12:17:51 +0100664 dev_err(map->dev, "Failed to add range %d\n", i);
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100665 kfree(new);
666 goto err_range;
667 }
668
669 if (map->selector_work_buf == NULL) {
670 map->selector_work_buf =
671 kzalloc(map->format.buf_size, GFP_KERNEL);
672 if (map->selector_work_buf == NULL) {
673 ret = -ENOMEM;
674 goto err_range;
675 }
676 }
677 }
Mark Brown052d2cd2011-11-21 19:05:13 +0000678
Lars-Peter Clausene5e3b8a2011-11-16 16:28:16 +0100679 ret = regcache_init(map, config);
Mark Brown0ff3e622012-10-04 17:39:13 +0100680 if (ret != 0)
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100681 goto err_range;
682
683 regmap_debugfs_init(map, config->name);
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100684
Mark Brown72b39f62012-05-08 17:44:40 +0100685 /* Add a devres resource for dev_get_regmap() */
686 m = devres_alloc(dev_get_regmap_release, sizeof(*m), GFP_KERNEL);
687 if (!m) {
688 ret = -ENOMEM;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100689 goto err_debugfs;
Mark Brown72b39f62012-05-08 17:44:40 +0100690 }
691 *m = map;
692 devres_add(dev, m);
693
Mark Brownb83a3132011-05-11 19:59:58 +0200694 return map;
695
Stephen Warrenbfaa25f2012-05-23 16:30:53 -0600696err_debugfs:
697 regmap_debugfs_exit(map);
Mark Brown72b39f62012-05-08 17:44:40 +0100698 regcache_exit(map);
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100699err_range:
700 regmap_range_exit(map);
Lars-Peter Clausen58072cb2011-11-10 18:15:15 +0100701 kfree(map->work_buf);
Mark Brownb83a3132011-05-11 19:59:58 +0200702err_map:
703 kfree(map);
704err:
705 return ERR_PTR(ret);
706}
707EXPORT_SYMBOL_GPL(regmap_init);
708
Mark Brownc0eb4672012-01-30 19:56:52 +0000709static void devm_regmap_release(struct device *dev, void *res)
710{
711 regmap_exit(*(struct regmap **)res);
712}
713
714/**
715 * devm_regmap_init(): Initialise managed register map
716 *
717 * @dev: Device that will be interacted with
718 * @bus: Bus-specific callbacks to use with device
Stephen Warren0135bbc2012-04-04 15:48:30 -0600719 * @bus_context: Data passed to bus-specific callbacks
Mark Brownc0eb4672012-01-30 19:56:52 +0000720 * @config: Configuration for register map
721 *
722 * The return value will be an ERR_PTR() on error or a valid pointer
723 * to a struct regmap. This function should generally not be called
724 * directly, it should be called by bus-specific init functions. The
725 * map will be automatically freed by the device management code.
726 */
727struct regmap *devm_regmap_init(struct device *dev,
728 const struct regmap_bus *bus,
Stephen Warren0135bbc2012-04-04 15:48:30 -0600729 void *bus_context,
Mark Brownc0eb4672012-01-30 19:56:52 +0000730 const struct regmap_config *config)
731{
732 struct regmap **ptr, *regmap;
733
734 ptr = devres_alloc(devm_regmap_release, sizeof(*ptr), GFP_KERNEL);
735 if (!ptr)
736 return ERR_PTR(-ENOMEM);
737
Stephen Warren0135bbc2012-04-04 15:48:30 -0600738 regmap = regmap_init(dev, bus, bus_context, config);
Mark Brownc0eb4672012-01-30 19:56:52 +0000739 if (!IS_ERR(regmap)) {
740 *ptr = regmap;
741 devres_add(dev, ptr);
742 } else {
743 devres_free(ptr);
744 }
745
746 return regmap;
747}
748EXPORT_SYMBOL_GPL(devm_regmap_init);
749
Mark Brownb83a3132011-05-11 19:59:58 +0200750/**
Mark Brownbf315172011-12-03 17:06:20 +0000751 * regmap_reinit_cache(): Reinitialise the current register cache
752 *
753 * @map: Register map to operate on.
754 * @config: New configuration. Only the cache data will be used.
755 *
756 * Discard any existing register cache for the map and initialize a
757 * new cache. This can be used to restore the cache to defaults or to
758 * update the cache configuration to reflect runtime discovery of the
759 * hardware.
Dimitris Papastamos4d879512012-07-27 14:54:15 +0100760 *
761 * No explicit locking is done here, the user needs to ensure that
762 * this function will not race with other calls to regmap.
Mark Brownbf315172011-12-03 17:06:20 +0000763 */
764int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
765{
Mark Brownbf315172011-12-03 17:06:20 +0000766 regcache_exit(map);
Mark Browna24f64a2012-01-26 18:30:16 +0000767 regmap_debugfs_exit(map);
Mark Brownbf315172011-12-03 17:06:20 +0000768
769 map->max_register = config->max_register;
770 map->writeable_reg = config->writeable_reg;
771 map->readable_reg = config->readable_reg;
772 map->volatile_reg = config->volatile_reg;
773 map->precious_reg = config->precious_reg;
774 map->cache_type = config->cache_type;
775
Stephen Warrend3c242e2012-04-04 15:48:29 -0600776 regmap_debugfs_init(map, config->name);
Mark Browna24f64a2012-01-26 18:30:16 +0000777
Mark Brown421e8d22012-01-20 13:39:37 +0000778 map->cache_bypass = false;
779 map->cache_only = false;
780
Dimitris Papastamos4d879512012-07-27 14:54:15 +0100781 return regcache_init(map, config);
Mark Brownbf315172011-12-03 17:06:20 +0000782}
Mark Brown752a6a52012-05-14 10:00:12 +0100783EXPORT_SYMBOL_GPL(regmap_reinit_cache);
Mark Brownbf315172011-12-03 17:06:20 +0000784
785/**
Mark Brownb83a3132011-05-11 19:59:58 +0200786 * regmap_exit(): Free a previously allocated register map
787 */
788void regmap_exit(struct regmap *map)
789{
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100790 regcache_exit(map);
Mark Brown31244e32011-07-20 22:56:53 +0100791 regmap_debugfs_exit(map);
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100792 regmap_range_exit(map);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600793 if (map->bus->free_context)
794 map->bus->free_context(map->bus_context);
Mark Brownb83a3132011-05-11 19:59:58 +0200795 kfree(map->work_buf);
Mark Brownb83a3132011-05-11 19:59:58 +0200796 kfree(map);
797}
798EXPORT_SYMBOL_GPL(regmap_exit);
799
Mark Brown72b39f62012-05-08 17:44:40 +0100800static int dev_get_regmap_match(struct device *dev, void *res, void *data)
801{
802 struct regmap **r = res;
803 if (!r || !*r) {
804 WARN_ON(!r || !*r);
805 return 0;
806 }
807
808 /* If the user didn't specify a name match any */
809 if (data)
810 return (*r)->name == data;
811 else
812 return 1;
813}
814
815/**
816 * dev_get_regmap(): Obtain the regmap (if any) for a device
817 *
818 * @dev: Device to retrieve the map for
819 * @name: Optional name for the register map, usually NULL.
820 *
821 * Returns the regmap for the device if one is present, or NULL. If
822 * name is specified then it must match the name specified when
823 * registering the device, if it is NULL then the first regmap found
824 * will be used. Devices with multiple register maps are very rare,
825 * generic code should normally not need to specify a name.
826 */
827struct regmap *dev_get_regmap(struct device *dev, const char *name)
828{
829 struct regmap **r = devres_find(dev, dev_get_regmap_release,
830 dev_get_regmap_match, (void *)name);
831
832 if (!r)
833 return NULL;
834 return *r;
835}
836EXPORT_SYMBOL_GPL(dev_get_regmap);
837
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100838static int _regmap_select_page(struct regmap *map, unsigned int *reg,
Mark Brown98bc7df2012-10-04 17:31:11 +0100839 struct regmap_range_node *range,
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100840 unsigned int val_num)
841{
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100842 void *orig_work_buf;
843 unsigned int win_offset;
844 unsigned int win_page;
845 bool page_chg;
846 int ret;
847
Mark Brown98bc7df2012-10-04 17:31:11 +0100848 win_offset = (*reg - range->range_min) % range->window_len;
849 win_page = (*reg - range->range_min) / range->window_len;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100850
Mark Brown98bc7df2012-10-04 17:31:11 +0100851 if (val_num > 1) {
852 /* Bulk write shouldn't cross range boundary */
853 if (*reg + val_num - 1 > range->range_max)
854 return -EINVAL;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100855
Mark Brown98bc7df2012-10-04 17:31:11 +0100856 /* ... or single page boundary */
857 if (val_num > range->window_len - win_offset)
858 return -EINVAL;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100859 }
860
Mark Brown98bc7df2012-10-04 17:31:11 +0100861 /* It is possible to have selector register inside data window.
862 In that case, selector register is located on every page and
863 it needs no page switching, when accessed alone. */
864 if (val_num > 1 ||
865 range->window_start + win_offset != range->selector_reg) {
866 /* Use separate work_buf during page switching */
867 orig_work_buf = map->work_buf;
868 map->work_buf = map->selector_work_buf;
869
870 ret = _regmap_update_bits(map, range->selector_reg,
871 range->selector_mask,
872 win_page << range->selector_shift,
873 &page_chg);
874
875 map->work_buf = orig_work_buf;
876
Mark Brown0ff3e622012-10-04 17:39:13 +0100877 if (ret != 0)
Mark Brown98bc7df2012-10-04 17:31:11 +0100878 return ret;
879 }
880
881 *reg = range->window_start + win_offset;
882
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100883 return 0;
884}
885
Mark Brownb83a3132011-05-11 19:59:58 +0200886static int _regmap_raw_write(struct regmap *map, unsigned int reg,
887 const void *val, size_t val_len)
888{
Mark Brown98bc7df2012-10-04 17:31:11 +0100889 struct regmap_range_node *range;
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200890 u8 *u8 = map->work_buf;
Mark Brownb83a3132011-05-11 19:59:58 +0200891 void *buf;
892 int ret = -ENOTSUPP;
893 size_t len;
Mark Brown73304782011-07-24 11:46:20 +0100894 int i;
895
896 /* Check for unwritable registers before we start */
897 if (map->writeable_reg)
898 for (i = 0; i < val_len / map->format.val_bytes; i++)
Stephen Warrenf01ee602012-04-09 13:40:24 -0600899 if (!map->writeable_reg(map->dev,
900 reg + (i * map->reg_stride)))
Mark Brown73304782011-07-24 11:46:20 +0100901 return -EINVAL;
Mark Brownb83a3132011-05-11 19:59:58 +0200902
Laxman Dewanganc9157192012-02-10 21:30:27 +0530903 if (!map->cache_bypass && map->format.parse_val) {
904 unsigned int ival;
905 int val_bytes = map->format.val_bytes;
906 for (i = 0; i < val_len / val_bytes; i++) {
907 memcpy(map->work_buf, val + (i * val_bytes), val_bytes);
908 ival = map->format.parse_val(map->work_buf);
Stephen Warrenf01ee602012-04-09 13:40:24 -0600909 ret = regcache_write(map, reg + (i * map->reg_stride),
910 ival);
Laxman Dewanganc9157192012-02-10 21:30:27 +0530911 if (ret) {
912 dev_err(map->dev,
Mark Brown6d04b8a2012-10-26 19:05:32 +0100913 "Error in caching of register: %x ret: %d\n",
Laxman Dewanganc9157192012-02-10 21:30:27 +0530914 reg + i, ret);
915 return ret;
916 }
917 }
918 if (map->cache_only) {
919 map->cache_dirty = true;
920 return 0;
921 }
922 }
923
Mark Brown98bc7df2012-10-04 17:31:11 +0100924 range = _regmap_range_lookup(map, reg);
925 if (range) {
Mark Brown8a2ceac2012-10-04 18:20:18 +0100926 int val_num = val_len / map->format.val_bytes;
927 int win_offset = (reg - range->range_min) % range->window_len;
928 int win_residue = range->window_len - win_offset;
929
930 /* If the write goes beyond the end of the window split it */
931 while (val_num > win_residue) {
Fabio Estevam1a61cfe2012-10-25 14:07:18 -0200932 dev_dbg(map->dev, "Writing window %d/%zu\n",
Mark Brown8a2ceac2012-10-04 18:20:18 +0100933 win_residue, val_len / map->format.val_bytes);
934 ret = _regmap_raw_write(map, reg, val, win_residue *
935 map->format.val_bytes);
936 if (ret != 0)
937 return ret;
938
939 reg += win_residue;
940 val_num -= win_residue;
941 val += win_residue * map->format.val_bytes;
942 val_len -= win_residue * map->format.val_bytes;
943
944 win_offset = (reg - range->range_min) %
945 range->window_len;
946 win_residue = range->window_len - win_offset;
947 }
948
949 ret = _regmap_select_page(map, &reg, range, val_num);
Mark Brown0ff3e622012-10-04 17:39:13 +0100950 if (ret != 0)
Mark Brown98bc7df2012-10-04 17:31:11 +0100951 return ret;
952 }
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100953
Marc Reillyd939fb92012-03-16 12:11:43 +1100954 map->format.format_reg(map->work_buf, reg, map->reg_shift);
Mark Brownb83a3132011-05-11 19:59:58 +0200955
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200956 u8[0] |= map->write_flag_mask;
957
Mark Brownfb2736b2011-07-24 21:30:55 +0100958 trace_regmap_hw_write_start(map->dev, reg,
959 val_len / map->format.val_bytes);
960
Mark Brown2547e202011-07-20 21:47:22 +0100961 /* If we're doing a single register write we can probably just
962 * send the work_buf directly, otherwise try to do a gather
963 * write.
964 */
Mark Brown82159ba2012-01-18 10:52:25 +0000965 if (val == (map->work_buf + map->format.pad_bytes +
966 map->format.reg_bytes))
Stephen Warren0135bbc2012-04-04 15:48:30 -0600967 ret = map->bus->write(map->bus_context, map->work_buf,
Mark Brown82159ba2012-01-18 10:52:25 +0000968 map->format.reg_bytes +
969 map->format.pad_bytes +
970 val_len);
Mark Brown2547e202011-07-20 21:47:22 +0100971 else if (map->bus->gather_write)
Stephen Warren0135bbc2012-04-04 15:48:30 -0600972 ret = map->bus->gather_write(map->bus_context, map->work_buf,
Mark Brown82159ba2012-01-18 10:52:25 +0000973 map->format.reg_bytes +
974 map->format.pad_bytes,
Mark Brownb83a3132011-05-11 19:59:58 +0200975 val, val_len);
976
Mark Brown2547e202011-07-20 21:47:22 +0100977 /* If that didn't work fall back on linearising by hand. */
Mark Brownb83a3132011-05-11 19:59:58 +0200978 if (ret == -ENOTSUPP) {
Mark Brown82159ba2012-01-18 10:52:25 +0000979 len = map->format.reg_bytes + map->format.pad_bytes + val_len;
980 buf = kzalloc(len, GFP_KERNEL);
Mark Brownb83a3132011-05-11 19:59:58 +0200981 if (!buf)
982 return -ENOMEM;
983
984 memcpy(buf, map->work_buf, map->format.reg_bytes);
Mark Brown82159ba2012-01-18 10:52:25 +0000985 memcpy(buf + map->format.reg_bytes + map->format.pad_bytes,
986 val, val_len);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600987 ret = map->bus->write(map->bus_context, buf, len);
Mark Brownb83a3132011-05-11 19:59:58 +0200988
989 kfree(buf);
990 }
991
Mark Brownfb2736b2011-07-24 21:30:55 +0100992 trace_regmap_hw_write_done(map->dev, reg,
993 val_len / map->format.val_bytes);
994
Mark Brownb83a3132011-05-11 19:59:58 +0200995 return ret;
996}
997
Andrey Smirnov07c320d2013-01-12 12:54:13 -0800998static int _regmap_bus_formatted_write(void *context, unsigned int reg,
999 unsigned int val)
1000{
1001 int ret;
1002 struct regmap_range_node *range;
1003 struct regmap *map = context;
1004
1005 BUG_ON(!map->format.format_write);
1006
1007 range = _regmap_range_lookup(map, reg);
1008 if (range) {
1009 ret = _regmap_select_page(map, &reg, range, 1);
1010 if (ret != 0)
1011 return ret;
1012 }
1013
1014 map->format.format_write(map, reg, val);
1015
1016 trace_regmap_hw_write_start(map->dev, reg, 1);
1017
1018 ret = map->bus->write(map->bus_context, map->work_buf,
1019 map->format.buf_size);
1020
1021 trace_regmap_hw_write_done(map->dev, reg, 1);
1022
1023 return ret;
1024}
1025
1026static int _regmap_bus_raw_write(void *context, unsigned int reg,
1027 unsigned int val)
1028{
1029 struct regmap *map = context;
1030
1031 BUG_ON(!map->format.format_val);
1032
1033 map->format.format_val(map->work_buf + map->format.reg_bytes
1034 + map->format.pad_bytes, val, 0);
1035 return _regmap_raw_write(map, reg,
1036 map->work_buf +
1037 map->format.reg_bytes +
1038 map->format.pad_bytes,
1039 map->format.val_bytes);
1040}
1041
Dimitris Papastamos4d2dc092011-09-29 10:39:07 +01001042int _regmap_write(struct regmap *map, unsigned int reg,
1043 unsigned int val)
Mark Brownb83a3132011-05-11 19:59:58 +02001044{
Mark Brownfb2736b2011-07-24 21:30:55 +01001045 int ret;
Mark Brownb83a3132011-05-11 19:59:58 +02001046
Laxman Dewanganc9157192012-02-10 21:30:27 +05301047 if (!map->cache_bypass && map->format.format_write) {
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +01001048 ret = regcache_write(map, reg, val);
1049 if (ret != 0)
1050 return ret;
Mark Brown8ae0d7e2011-10-26 10:34:22 +02001051 if (map->cache_only) {
1052 map->cache_dirty = true;
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +01001053 return 0;
Mark Brown8ae0d7e2011-10-26 10:34:22 +02001054 }
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +01001055 }
1056
Mark Brown1044c182012-07-06 14:10:23 +01001057#ifdef LOG_DEVICE
1058 if (strcmp(dev_name(map->dev), LOG_DEVICE) == 0)
1059 dev_info(map->dev, "%x <= %x\n", reg, val);
1060#endif
1061
Mark Brownfb2736b2011-07-24 21:30:55 +01001062 trace_regmap_reg_write(map->dev, reg, val);
1063
Andrey Smirnov07c320d2013-01-12 12:54:13 -08001064 return map->reg_write(map, reg, val);
Mark Brownb83a3132011-05-11 19:59:58 +02001065}
1066
1067/**
1068 * regmap_write(): Write a value to a single register
1069 *
1070 * @map: Register map to write to
1071 * @reg: Register to write to
1072 * @val: Value to be written
1073 *
1074 * A value of zero will be returned on success, a negative errno will
1075 * be returned in error cases.
1076 */
1077int regmap_write(struct regmap *map, unsigned int reg, unsigned int val)
1078{
1079 int ret;
1080
Stephen Warrenf01ee602012-04-09 13:40:24 -06001081 if (reg % map->reg_stride)
1082 return -EINVAL;
1083
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001084 map->lock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001085
1086 ret = _regmap_write(map, reg, val);
1087
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001088 map->unlock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001089
1090 return ret;
1091}
1092EXPORT_SYMBOL_GPL(regmap_write);
1093
1094/**
1095 * regmap_raw_write(): Write raw values to one or more registers
1096 *
1097 * @map: Register map to write to
1098 * @reg: Initial register to write to
1099 * @val: Block of data to be written, laid out for direct transmission to the
1100 * device
1101 * @val_len: Length of data pointed to by val.
1102 *
1103 * This function is intended to be used for things like firmware
1104 * download where a large block of data needs to be transferred to the
1105 * device. No formatting will be done on the data provided.
1106 *
1107 * A value of zero will be returned on success, a negative errno will
1108 * be returned in error cases.
1109 */
1110int regmap_raw_write(struct regmap *map, unsigned int reg,
1111 const void *val, size_t val_len)
1112{
1113 int ret;
1114
Stephen Warren851960b2012-04-06 15:16:03 -06001115 if (val_len % map->format.val_bytes)
1116 return -EINVAL;
Stephen Warrenf01ee602012-04-09 13:40:24 -06001117 if (reg % map->reg_stride)
1118 return -EINVAL;
Stephen Warren851960b2012-04-06 15:16:03 -06001119
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001120 map->lock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001121
1122 ret = _regmap_raw_write(map, reg, val, val_len);
1123
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001124 map->unlock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001125
1126 return ret;
1127}
1128EXPORT_SYMBOL_GPL(regmap_raw_write);
1129
Laxman Dewangan8eaeb212012-02-12 19:49:43 +05301130/*
1131 * regmap_bulk_write(): Write multiple registers to the device
1132 *
1133 * @map: Register map to write to
1134 * @reg: First register to be write from
1135 * @val: Block of data to be written, in native register size for device
1136 * @val_count: Number of registers to write
1137 *
1138 * This function is intended to be used for writing a large block of
1139 * data to be device either in single transfer or multiple transfer.
1140 *
1141 * A value of zero will be returned on success, a negative errno will
1142 * be returned in error cases.
1143 */
1144int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
1145 size_t val_count)
1146{
1147 int ret = 0, i;
1148 size_t val_bytes = map->format.val_bytes;
1149 void *wval;
1150
1151 if (!map->format.parse_val)
1152 return -EINVAL;
Stephen Warrenf01ee602012-04-09 13:40:24 -06001153 if (reg % map->reg_stride)
1154 return -EINVAL;
Laxman Dewangan8eaeb212012-02-12 19:49:43 +05301155
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001156 map->lock(map->lock_arg);
Laxman Dewangan8eaeb212012-02-12 19:49:43 +05301157
1158 /* No formatting is require if val_byte is 1 */
1159 if (val_bytes == 1) {
1160 wval = (void *)val;
1161 } else {
1162 wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL);
1163 if (!wval) {
1164 ret = -ENOMEM;
1165 dev_err(map->dev, "Error in memory allocation\n");
1166 goto out;
1167 }
1168 for (i = 0; i < val_count * val_bytes; i += val_bytes)
1169 map->format.parse_val(wval + i);
1170 }
Ashish Jangam2e33caf2012-04-30 23:23:40 +01001171 /*
1172 * Some devices does not support bulk write, for
1173 * them we have a series of single write operations.
1174 */
1175 if (map->use_single_rw) {
1176 for (i = 0; i < val_count; i++) {
1177 ret = regmap_raw_write(map,
1178 reg + (i * map->reg_stride),
1179 val + (i * val_bytes),
1180 val_bytes);
1181 if (ret != 0)
1182 return ret;
1183 }
1184 } else {
1185 ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count);
1186 }
Laxman Dewangan8eaeb212012-02-12 19:49:43 +05301187
1188 if (val_bytes != 1)
1189 kfree(wval);
1190
1191out:
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001192 map->unlock(map->lock_arg);
Laxman Dewangan8eaeb212012-02-12 19:49:43 +05301193 return ret;
1194}
1195EXPORT_SYMBOL_GPL(regmap_bulk_write);
1196
Mark Brownb83a3132011-05-11 19:59:58 +02001197static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
1198 unsigned int val_len)
1199{
Mark Brown98bc7df2012-10-04 17:31:11 +01001200 struct regmap_range_node *range;
Mark Brownb83a3132011-05-11 19:59:58 +02001201 u8 *u8 = map->work_buf;
1202 int ret;
1203
Mark Brown98bc7df2012-10-04 17:31:11 +01001204 range = _regmap_range_lookup(map, reg);
1205 if (range) {
1206 ret = _regmap_select_page(map, &reg, range,
1207 val_len / map->format.val_bytes);
Mark Brown0ff3e622012-10-04 17:39:13 +01001208 if (ret != 0)
Mark Brown98bc7df2012-10-04 17:31:11 +01001209 return ret;
1210 }
Krystian Garbaciak6863ca62012-06-15 11:23:56 +01001211
Marc Reillyd939fb92012-03-16 12:11:43 +11001212 map->format.format_reg(map->work_buf, reg, map->reg_shift);
Mark Brownb83a3132011-05-11 19:59:58 +02001213
1214 /*
Lars-Peter Clausen6f306442011-09-05 20:46:32 +02001215 * Some buses or devices flag reads by setting the high bits in the
Mark Brownb83a3132011-05-11 19:59:58 +02001216 * register addresss; since it's always the high bits for all
1217 * current formats we can do this here rather than in
1218 * formatting. This may break if we get interesting formats.
1219 */
Lars-Peter Clausen6f306442011-09-05 20:46:32 +02001220 u8[0] |= map->read_flag_mask;
Mark Brownb83a3132011-05-11 19:59:58 +02001221
Mark Brownfb2736b2011-07-24 21:30:55 +01001222 trace_regmap_hw_read_start(map->dev, reg,
1223 val_len / map->format.val_bytes);
1224
Stephen Warren0135bbc2012-04-04 15:48:30 -06001225 ret = map->bus->read(map->bus_context, map->work_buf,
Mark Brown82159ba2012-01-18 10:52:25 +00001226 map->format.reg_bytes + map->format.pad_bytes,
Mark Brown40c5cc22011-07-24 22:39:12 +01001227 val, val_len);
Mark Brownb83a3132011-05-11 19:59:58 +02001228
Mark Brownfb2736b2011-07-24 21:30:55 +01001229 trace_regmap_hw_read_done(map->dev, reg,
1230 val_len / map->format.val_bytes);
1231
1232 return ret;
Mark Brownb83a3132011-05-11 19:59:58 +02001233}
1234
Andrey Smirnovad278402013-01-12 12:54:12 -08001235static int _regmap_bus_read(void *context, unsigned int reg,
1236 unsigned int *val)
1237{
1238 int ret;
1239 struct regmap *map = context;
1240
1241 if (!map->format.parse_val)
1242 return -EINVAL;
1243
1244 ret = _regmap_raw_read(map, reg, map->work_buf, map->format.val_bytes);
1245 if (ret == 0)
1246 *val = map->format.parse_val(map->work_buf);
1247
1248 return ret;
1249}
1250
Mark Brownb83a3132011-05-11 19:59:58 +02001251static int _regmap_read(struct regmap *map, unsigned int reg,
1252 unsigned int *val)
1253{
1254 int ret;
Andrey Smirnovad278402013-01-12 12:54:12 -08001255 BUG_ON(!map->reg_read);
Mark Brownb83a3132011-05-11 19:59:58 +02001256
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +01001257 if (!map->cache_bypass) {
1258 ret = regcache_read(map, reg, val);
1259 if (ret == 0)
1260 return 0;
1261 }
1262
1263 if (map->cache_only)
1264 return -EBUSY;
1265
Andrey Smirnovad278402013-01-12 12:54:12 -08001266 ret = map->reg_read(map, reg, val);
Mark Brownfb2736b2011-07-24 21:30:55 +01001267 if (ret == 0) {
Mark Brown1044c182012-07-06 14:10:23 +01001268#ifdef LOG_DEVICE
1269 if (strcmp(dev_name(map->dev), LOG_DEVICE) == 0)
1270 dev_info(map->dev, "%x => %x\n", reg, *val);
1271#endif
1272
Mark Brownfb2736b2011-07-24 21:30:55 +01001273 trace_regmap_reg_read(map->dev, reg, *val);
Mark Brownb83a3132011-05-11 19:59:58 +02001274
Andrey Smirnovad278402013-01-12 12:54:12 -08001275 if (!map->cache_bypass)
1276 regcache_write(map, reg, *val);
1277 }
Mark Brownf2985362012-04-30 21:25:05 +01001278
Mark Brownb83a3132011-05-11 19:59:58 +02001279 return ret;
1280}
1281
1282/**
1283 * regmap_read(): Read a value from a single register
1284 *
1285 * @map: Register map to write to
1286 * @reg: Register to be read from
1287 * @val: Pointer to store read value
1288 *
1289 * A value of zero will be returned on success, a negative errno will
1290 * be returned in error cases.
1291 */
1292int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val)
1293{
1294 int ret;
1295
Stephen Warrenf01ee602012-04-09 13:40:24 -06001296 if (reg % map->reg_stride)
1297 return -EINVAL;
1298
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001299 map->lock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001300
1301 ret = _regmap_read(map, reg, val);
1302
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001303 map->unlock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001304
1305 return ret;
1306}
1307EXPORT_SYMBOL_GPL(regmap_read);
1308
1309/**
1310 * regmap_raw_read(): Read raw data from the device
1311 *
1312 * @map: Register map to write to
1313 * @reg: First register to be read from
1314 * @val: Pointer to store read value
1315 * @val_len: Size of data to read
1316 *
1317 * A value of zero will be returned on success, a negative errno will
1318 * be returned in error cases.
1319 */
1320int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
1321 size_t val_len)
1322{
Mark Brownb8fb5ab2012-02-21 19:12:47 +00001323 size_t val_bytes = map->format.val_bytes;
1324 size_t val_count = val_len / val_bytes;
1325 unsigned int v;
1326 int ret, i;
Mark Brown04e016a2011-10-09 13:35:43 +01001327
Stephen Warren851960b2012-04-06 15:16:03 -06001328 if (val_len % map->format.val_bytes)
1329 return -EINVAL;
Stephen Warrenf01ee602012-04-09 13:40:24 -06001330 if (reg % map->reg_stride)
1331 return -EINVAL;
Stephen Warren851960b2012-04-06 15:16:03 -06001332
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001333 map->lock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001334
Mark Brownb8fb5ab2012-02-21 19:12:47 +00001335 if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass ||
1336 map->cache_type == REGCACHE_NONE) {
1337 /* Physical block read if there's no cache involved */
1338 ret = _regmap_raw_read(map, reg, val, val_len);
Mark Brownb83a3132011-05-11 19:59:58 +02001339
Mark Brownb8fb5ab2012-02-21 19:12:47 +00001340 } else {
1341 /* Otherwise go word by word for the cache; should be low
1342 * cost as we expect to hit the cache.
1343 */
1344 for (i = 0; i < val_count; i++) {
Stephen Warrenf01ee602012-04-09 13:40:24 -06001345 ret = _regmap_read(map, reg + (i * map->reg_stride),
1346 &v);
Mark Brownb8fb5ab2012-02-21 19:12:47 +00001347 if (ret != 0)
1348 goto out;
1349
Marc Reillyd939fb92012-03-16 12:11:43 +11001350 map->format.format_val(val + (i * val_bytes), v, 0);
Mark Brownb8fb5ab2012-02-21 19:12:47 +00001351 }
1352 }
1353
1354 out:
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001355 map->unlock(map->lock_arg);
Mark Brownb83a3132011-05-11 19:59:58 +02001356
1357 return ret;
1358}
1359EXPORT_SYMBOL_GPL(regmap_raw_read);
1360
1361/**
1362 * regmap_bulk_read(): Read multiple registers from the device
1363 *
1364 * @map: Register map to write to
1365 * @reg: First register to be read from
1366 * @val: Pointer to store read value, in native register size for device
1367 * @val_count: Number of registers to read
1368 *
1369 * A value of zero will be returned on success, a negative errno will
1370 * be returned in error cases.
1371 */
1372int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
1373 size_t val_count)
1374{
1375 int ret, i;
1376 size_t val_bytes = map->format.val_bytes;
Lars-Peter Clausen82cd9962011-11-08 18:37:25 +01001377 bool vol = regmap_volatile_range(map, reg, val_count);
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +01001378
Mark Brownb83a3132011-05-11 19:59:58 +02001379 if (!map->format.parse_val)
1380 return -EINVAL;
Stephen Warrenf01ee602012-04-09 13:40:24 -06001381 if (reg % map->reg_stride)
1382 return -EINVAL;
Mark Brownb83a3132011-05-11 19:59:58 +02001383
Mark Brownde2d8082011-10-10 13:24:52 +01001384 if (vol || map->cache_type == REGCACHE_NONE) {
Ashish Jangam2e33caf2012-04-30 23:23:40 +01001385 /*
1386 * Some devices does not support bulk read, for
1387 * them we have a series of single read operations.
1388 */
1389 if (map->use_single_rw) {
1390 for (i = 0; i < val_count; i++) {
1391 ret = regmap_raw_read(map,
1392 reg + (i * map->reg_stride),
1393 val + (i * val_bytes),
1394 val_bytes);
1395 if (ret != 0)
1396 return ret;
1397 }
1398 } else {
1399 ret = regmap_raw_read(map, reg, val,
1400 val_bytes * val_count);
1401 if (ret != 0)
1402 return ret;
1403 }
Mark Brownde2d8082011-10-10 13:24:52 +01001404
1405 for (i = 0; i < val_count * val_bytes; i += val_bytes)
1406 map->format.parse_val(val + i);
1407 } else {
1408 for (i = 0; i < val_count; i++) {
Laxman Dewangan6560ffd2012-05-09 17:43:12 +05301409 unsigned int ival;
Stephen Warrenf01ee602012-04-09 13:40:24 -06001410 ret = regmap_read(map, reg + (i * map->reg_stride),
Mark Brown25061d22012-05-12 13:06:08 +01001411 &ival);
Mark Brownde2d8082011-10-10 13:24:52 +01001412 if (ret != 0)
1413 return ret;
Laxman Dewangan6560ffd2012-05-09 17:43:12 +05301414 memcpy(val + (i * val_bytes), &ival, val_bytes);
Mark Brownde2d8082011-10-10 13:24:52 +01001415 }
1416 }
Mark Brownb83a3132011-05-11 19:59:58 +02001417
1418 return 0;
1419}
1420EXPORT_SYMBOL_GPL(regmap_bulk_read);
1421
Mark Brown018690d2011-11-29 20:10:36 +00001422static int _regmap_update_bits(struct regmap *map, unsigned int reg,
1423 unsigned int mask, unsigned int val,
1424 bool *change)
Mark Brownb83a3132011-05-11 19:59:58 +02001425{
1426 int ret;
Mark Brownd91e8db22011-11-18 16:03:50 +00001427 unsigned int tmp, orig;
Mark Brownb83a3132011-05-11 19:59:58 +02001428
Mark Brownd91e8db22011-11-18 16:03:50 +00001429 ret = _regmap_read(map, reg, &orig);
Mark Brownb83a3132011-05-11 19:59:58 +02001430 if (ret != 0)
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001431 return ret;
Mark Brownb83a3132011-05-11 19:59:58 +02001432
Mark Brownd91e8db22011-11-18 16:03:50 +00001433 tmp = orig & ~mask;
Mark Brownb83a3132011-05-11 19:59:58 +02001434 tmp |= val & mask;
1435
Mark Brown018690d2011-11-29 20:10:36 +00001436 if (tmp != orig) {
Mark Brownd91e8db22011-11-18 16:03:50 +00001437 ret = _regmap_write(map, reg, tmp);
Mark Brown018690d2011-11-29 20:10:36 +00001438 *change = true;
1439 } else {
1440 *change = false;
1441 }
Mark Brownb83a3132011-05-11 19:59:58 +02001442
Mark Brownb83a3132011-05-11 19:59:58 +02001443 return ret;
1444}
Mark Brown018690d2011-11-29 20:10:36 +00001445
1446/**
1447 * regmap_update_bits: Perform a read/modify/write cycle on the register map
1448 *
1449 * @map: Register map to update
1450 * @reg: Register to update
1451 * @mask: Bitmask to change
1452 * @val: New value for bitmask
1453 *
1454 * Returns zero for success, a negative number on error.
1455 */
1456int regmap_update_bits(struct regmap *map, unsigned int reg,
1457 unsigned int mask, unsigned int val)
1458{
1459 bool change;
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001460 int ret;
1461
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001462 map->lock(map->lock_arg);
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001463 ret = _regmap_update_bits(map, reg, mask, val, &change);
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001464 map->unlock(map->lock_arg);
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001465
1466 return ret;
Mark Brown018690d2011-11-29 20:10:36 +00001467}
Mark Brownb83a3132011-05-11 19:59:58 +02001468EXPORT_SYMBOL_GPL(regmap_update_bits);
Mark Brown31244e32011-07-20 22:56:53 +01001469
Mark Brown018690d2011-11-29 20:10:36 +00001470/**
1471 * regmap_update_bits_check: Perform a read/modify/write cycle on the
1472 * register map and report if updated
1473 *
1474 * @map: Register map to update
1475 * @reg: Register to update
1476 * @mask: Bitmask to change
1477 * @val: New value for bitmask
1478 * @change: Boolean indicating if a write was done
1479 *
1480 * Returns zero for success, a negative number on error.
1481 */
1482int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1483 unsigned int mask, unsigned int val,
1484 bool *change)
1485{
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001486 int ret;
1487
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001488 map->lock(map->lock_arg);
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001489 ret = _regmap_update_bits(map, reg, mask, val, change);
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001490 map->unlock(map->lock_arg);
Krystian Garbaciakfc3ebd72012-06-15 11:23:56 +01001491 return ret;
Mark Brown018690d2011-11-29 20:10:36 +00001492}
1493EXPORT_SYMBOL_GPL(regmap_update_bits_check);
1494
Mark Brown22f0d902012-01-21 12:01:14 +00001495/**
1496 * regmap_register_patch: Register and apply register updates to be applied
1497 * on device initialistion
1498 *
1499 * @map: Register map to apply updates to.
1500 * @regs: Values to update.
1501 * @num_regs: Number of entries in regs.
1502 *
1503 * Register a set of register updates to be applied to the device
1504 * whenever the device registers are synchronised with the cache and
1505 * apply them immediately. Typically this is used to apply
1506 * corrections to be applied to the device defaults on startup, such
1507 * as the updates some vendors provide to undocumented registers.
1508 */
1509int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
1510 int num_regs)
1511{
1512 int i, ret;
1513 bool bypass;
1514
1515 /* If needed the implementation can be extended to support this */
1516 if (map->patch)
1517 return -EBUSY;
1518
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001519 map->lock(map->lock_arg);
Mark Brown22f0d902012-01-21 12:01:14 +00001520
1521 bypass = map->cache_bypass;
1522
1523 map->cache_bypass = true;
1524
1525 /* Write out first; it's useful to apply even if we fail later. */
1526 for (i = 0; i < num_regs; i++) {
1527 ret = _regmap_write(map, regs[i].reg, regs[i].def);
1528 if (ret != 0) {
1529 dev_err(map->dev, "Failed to write %x = %x: %d\n",
1530 regs[i].reg, regs[i].def, ret);
1531 goto out;
1532 }
1533 }
1534
Axel Lin2a14d7d92012-02-10 19:29:55 +08001535 map->patch = kcalloc(num_regs, sizeof(struct reg_default), GFP_KERNEL);
Mark Brown22f0d902012-01-21 12:01:14 +00001536 if (map->patch != NULL) {
1537 memcpy(map->patch, regs,
1538 num_regs * sizeof(struct reg_default));
1539 map->patch_regs = num_regs;
1540 } else {
1541 ret = -ENOMEM;
1542 }
1543
1544out:
1545 map->cache_bypass = bypass;
1546
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +02001547 map->unlock(map->lock_arg);
Mark Brown22f0d902012-01-21 12:01:14 +00001548
1549 return ret;
1550}
1551EXPORT_SYMBOL_GPL(regmap_register_patch);
1552
Mark Browneae4b512012-03-14 13:15:03 +00001553/*
Mark Browna6539c32012-02-17 14:20:14 -08001554 * regmap_get_val_bytes(): Report the size of a register value
1555 *
1556 * Report the size of a register value, mainly intended to for use by
1557 * generic infrastructure built on top of regmap.
1558 */
1559int regmap_get_val_bytes(struct regmap *map)
1560{
1561 if (map->format.format_write)
1562 return -EINVAL;
1563
1564 return map->format.val_bytes;
1565}
1566EXPORT_SYMBOL_GPL(regmap_get_val_bytes);
1567
Mark Brown31244e32011-07-20 22:56:53 +01001568static int __init regmap_initcall(void)
1569{
1570 regmap_debugfs_initcall();
1571
1572 return 0;
1573}
1574postcore_initcall(regmap_initcall);