blob: be10a4ff660915625454375ce9fb30a97d5b7ef9 [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
13#include <linux/slab.h>
14#include <linux/module.h>
15#include <linux/mutex.h>
16#include <linux/err.h>
17
Mark Brownfb2736b2011-07-24 21:30:55 +010018#define CREATE_TRACE_POINTS
19#include <trace/events/regmap.h>
20
Mark Brown93de9122011-07-20 22:35:37 +010021#include "internal.h"
Mark Brownb83a3132011-05-11 19:59:58 +020022
Mark Brown8de2f082011-08-10 17:14:41 +090023bool regmap_writeable(struct regmap *map, unsigned int reg)
24{
25 if (map->max_register && reg > map->max_register)
26 return false;
27
28 if (map->writeable_reg)
29 return map->writeable_reg(map->dev, reg);
30
31 return true;
32}
33
34bool regmap_readable(struct regmap *map, unsigned int reg)
35{
36 if (map->max_register && reg > map->max_register)
37 return false;
38
39 if (map->readable_reg)
40 return map->readable_reg(map->dev, reg);
41
42 return true;
43}
44
45bool regmap_volatile(struct regmap *map, unsigned int reg)
46{
47 if (map->max_register && reg > map->max_register)
48 return false;
49
50 if (map->volatile_reg)
51 return map->volatile_reg(map->dev, reg);
52
53 return true;
54}
55
56bool regmap_precious(struct regmap *map, unsigned int reg)
57{
58 if (map->max_register && reg > map->max_register)
59 return false;
60
61 if (map->precious_reg)
62 return map->precious_reg(map->dev, reg);
63
64 return false;
65}
66
Lars-Peter Clausen82cd9962011-11-08 18:37:25 +010067static bool regmap_volatile_range(struct regmap *map, unsigned int reg,
68 unsigned int num)
69{
70 unsigned int i;
71
72 for (i = 0; i < num; i++)
73 if (!regmap_volatile(map, reg + i))
74 return false;
75
76 return true;
77}
78
Mark Brownb83a3132011-05-11 19:59:58 +020079static void regmap_format_4_12_write(struct regmap *map,
80 unsigned int reg, unsigned int val)
81{
82 __be16 *out = map->work_buf;
83 *out = cpu_to_be16((reg << 12) | val);
84}
85
86static void regmap_format_7_9_write(struct regmap *map,
87 unsigned int reg, unsigned int val)
88{
89 __be16 *out = map->work_buf;
90 *out = cpu_to_be16((reg << 9) | val);
91}
92
Lars-Peter Clausen7e5ec632011-11-16 16:28:21 +010093static void regmap_format_10_14_write(struct regmap *map,
94 unsigned int reg, unsigned int val)
95{
96 u8 *out = map->work_buf;
97
98 out[2] = val;
99 out[1] = (val >> 8) | (reg << 6);
100 out[0] = reg >> 2;
101}
102
Mark Brownb83a3132011-05-11 19:59:58 +0200103static void regmap_format_8(void *buf, unsigned int val)
104{
105 u8 *b = buf;
106
107 b[0] = val;
108}
109
110static void regmap_format_16(void *buf, unsigned int val)
111{
112 __be16 *b = buf;
113
114 b[0] = cpu_to_be16(val);
115}
116
117static unsigned int regmap_parse_8(void *buf)
118{
119 u8 *b = buf;
120
121 return b[0];
122}
123
124static unsigned int regmap_parse_16(void *buf)
125{
126 __be16 *b = buf;
127
128 b[0] = be16_to_cpu(b[0]);
129
130 return b[0];
131}
132
133/**
134 * regmap_init(): Initialise register map
135 *
136 * @dev: Device that will be interacted with
137 * @bus: Bus-specific callbacks to use with device
138 * @config: Configuration for register map
139 *
140 * The return value will be an ERR_PTR() on error or a valid pointer to
141 * a struct regmap. This function should generally not be called
142 * directly, it should be called by bus-specific init functions.
143 */
144struct regmap *regmap_init(struct device *dev,
145 const struct regmap_bus *bus,
146 const struct regmap_config *config)
147{
148 struct regmap *map;
149 int ret = -EINVAL;
150
151 if (!bus || !config)
Lars-Peter Clausenabbb18f2011-11-14 10:40:15 +0100152 goto err;
Mark Brownb83a3132011-05-11 19:59:58 +0200153
154 map = kzalloc(sizeof(*map), GFP_KERNEL);
155 if (map == NULL) {
156 ret = -ENOMEM;
157 goto err;
158 }
159
160 mutex_init(&map->lock);
161 map->format.buf_size = (config->reg_bits + config->val_bits) / 8;
162 map->format.reg_bytes = config->reg_bits / 8;
163 map->format.val_bytes = config->val_bits / 8;
164 map->dev = dev;
165 map->bus = bus;
Mark Brown2e2ae662011-07-20 22:33:39 +0100166 map->max_register = config->max_register;
167 map->writeable_reg = config->writeable_reg;
168 map->readable_reg = config->readable_reg;
169 map->volatile_reg = config->volatile_reg;
Mark Brown2efe1642011-08-08 15:41:46 +0900170 map->precious_reg = config->precious_reg;
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100171 map->cache_type = config->cache_type;
Mark Brownb83a3132011-05-11 19:59:58 +0200172
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200173 if (config->read_flag_mask || config->write_flag_mask) {
174 map->read_flag_mask = config->read_flag_mask;
175 map->write_flag_mask = config->write_flag_mask;
176 } else {
177 map->read_flag_mask = bus->read_flag_mask;
178 }
179
Mark Brownb83a3132011-05-11 19:59:58 +0200180 switch (config->reg_bits) {
181 case 4:
182 switch (config->val_bits) {
183 case 12:
184 map->format.format_write = regmap_format_4_12_write;
185 break;
186 default:
187 goto err_map;
188 }
189 break;
190
191 case 7:
192 switch (config->val_bits) {
193 case 9:
194 map->format.format_write = regmap_format_7_9_write;
195 break;
196 default:
197 goto err_map;
198 }
199 break;
200
Lars-Peter Clausen7e5ec632011-11-16 16:28:21 +0100201 case 10:
202 switch (config->val_bits) {
203 case 14:
204 map->format.format_write = regmap_format_10_14_write;
205 break;
206 default:
207 goto err_map;
208 }
209 break;
210
Mark Brownb83a3132011-05-11 19:59:58 +0200211 case 8:
212 map->format.format_reg = regmap_format_8;
213 break;
214
215 case 16:
216 map->format.format_reg = regmap_format_16;
217 break;
218
219 default:
220 goto err_map;
221 }
222
223 switch (config->val_bits) {
224 case 8:
225 map->format.format_val = regmap_format_8;
226 map->format.parse_val = regmap_parse_8;
227 break;
228 case 16:
229 map->format.format_val = regmap_format_16;
230 map->format.parse_val = regmap_parse_16;
231 break;
232 }
233
234 if (!map->format.format_write &&
235 !(map->format.format_reg && map->format.format_val))
236 goto err_map;
237
238 map->work_buf = kmalloc(map->format.buf_size, GFP_KERNEL);
239 if (map->work_buf == NULL) {
240 ret = -ENOMEM;
Mark Brown5204f5e2011-09-05 08:07:47 -0700241 goto err_map;
Mark Brownb83a3132011-05-11 19:59:58 +0200242 }
243
Mark Brown052d2cd2011-11-21 19:05:13 +0000244 regmap_debugfs_init(map);
245
Lars-Peter Clausene5e3b8a2011-11-16 16:28:16 +0100246 ret = regcache_init(map, config);
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100247 if (ret < 0)
Lars-Peter Clausen58072cb2011-11-10 18:15:15 +0100248 goto err_free_workbuf;
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100249
Mark Brownb83a3132011-05-11 19:59:58 +0200250 return map;
251
Lars-Peter Clausen58072cb2011-11-10 18:15:15 +0100252err_free_workbuf:
253 kfree(map->work_buf);
Mark Brownb83a3132011-05-11 19:59:58 +0200254err_map:
255 kfree(map);
256err:
257 return ERR_PTR(ret);
258}
259EXPORT_SYMBOL_GPL(regmap_init);
260
261/**
Mark Brownbf315172011-12-03 17:06:20 +0000262 * regmap_reinit_cache(): Reinitialise the current register cache
263 *
264 * @map: Register map to operate on.
265 * @config: New configuration. Only the cache data will be used.
266 *
267 * Discard any existing register cache for the map and initialize a
268 * new cache. This can be used to restore the cache to defaults or to
269 * update the cache configuration to reflect runtime discovery of the
270 * hardware.
271 */
272int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
273{
274 int ret;
275
276 mutex_lock(&map->lock);
277
278 regcache_exit(map);
279
280 map->max_register = config->max_register;
281 map->writeable_reg = config->writeable_reg;
282 map->readable_reg = config->readable_reg;
283 map->volatile_reg = config->volatile_reg;
284 map->precious_reg = config->precious_reg;
285 map->cache_type = config->cache_type;
286
287 ret = regcache_init(map, config);
288
289 mutex_unlock(&map->lock);
290
291 return ret;
292}
293
294/**
Mark Brownb83a3132011-05-11 19:59:58 +0200295 * regmap_exit(): Free a previously allocated register map
296 */
297void regmap_exit(struct regmap *map)
298{
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100299 regcache_exit(map);
Mark Brown31244e32011-07-20 22:56:53 +0100300 regmap_debugfs_exit(map);
Mark Brownb83a3132011-05-11 19:59:58 +0200301 kfree(map->work_buf);
Mark Brownb83a3132011-05-11 19:59:58 +0200302 kfree(map);
303}
304EXPORT_SYMBOL_GPL(regmap_exit);
305
306static int _regmap_raw_write(struct regmap *map, unsigned int reg,
307 const void *val, size_t val_len)
308{
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200309 u8 *u8 = map->work_buf;
Mark Brownb83a3132011-05-11 19:59:58 +0200310 void *buf;
311 int ret = -ENOTSUPP;
312 size_t len;
Mark Brown73304782011-07-24 11:46:20 +0100313 int i;
314
315 /* Check for unwritable registers before we start */
316 if (map->writeable_reg)
317 for (i = 0; i < val_len / map->format.val_bytes; i++)
318 if (!map->writeable_reg(map->dev, reg + i))
319 return -EINVAL;
Mark Brownb83a3132011-05-11 19:59:58 +0200320
321 map->format.format_reg(map->work_buf, reg);
322
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200323 u8[0] |= map->write_flag_mask;
324
Mark Brownfb2736b2011-07-24 21:30:55 +0100325 trace_regmap_hw_write_start(map->dev, reg,
326 val_len / map->format.val_bytes);
327
Mark Brown2547e202011-07-20 21:47:22 +0100328 /* If we're doing a single register write we can probably just
329 * send the work_buf directly, otherwise try to do a gather
330 * write.
331 */
332 if (val == map->work_buf + map->format.reg_bytes)
333 ret = map->bus->write(map->dev, map->work_buf,
334 map->format.reg_bytes + val_len);
335 else if (map->bus->gather_write)
Mark Brownb83a3132011-05-11 19:59:58 +0200336 ret = map->bus->gather_write(map->dev, map->work_buf,
337 map->format.reg_bytes,
338 val, val_len);
339
Mark Brown2547e202011-07-20 21:47:22 +0100340 /* If that didn't work fall back on linearising by hand. */
Mark Brownb83a3132011-05-11 19:59:58 +0200341 if (ret == -ENOTSUPP) {
342 len = map->format.reg_bytes + val_len;
343 buf = kmalloc(len, GFP_KERNEL);
344 if (!buf)
345 return -ENOMEM;
346
347 memcpy(buf, map->work_buf, map->format.reg_bytes);
348 memcpy(buf + map->format.reg_bytes, val, val_len);
349 ret = map->bus->write(map->dev, buf, len);
350
351 kfree(buf);
352 }
353
Mark Brownfb2736b2011-07-24 21:30:55 +0100354 trace_regmap_hw_write_done(map->dev, reg,
355 val_len / map->format.val_bytes);
356
Mark Brownb83a3132011-05-11 19:59:58 +0200357 return ret;
358}
359
Dimitris Papastamos4d2dc092011-09-29 10:39:07 +0100360int _regmap_write(struct regmap *map, unsigned int reg,
361 unsigned int val)
Mark Brownb83a3132011-05-11 19:59:58 +0200362{
Mark Brownfb2736b2011-07-24 21:30:55 +0100363 int ret;
Mark Brownb83a3132011-05-11 19:59:58 +0200364 BUG_ON(!map->format.format_write && !map->format.format_val);
365
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100366 if (!map->cache_bypass) {
367 ret = regcache_write(map, reg, val);
368 if (ret != 0)
369 return ret;
Mark Brown8ae0d7e2011-10-26 10:34:22 +0200370 if (map->cache_only) {
371 map->cache_dirty = true;
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100372 return 0;
Mark Brown8ae0d7e2011-10-26 10:34:22 +0200373 }
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100374 }
375
Mark Brownfb2736b2011-07-24 21:30:55 +0100376 trace_regmap_reg_write(map->dev, reg, val);
377
Mark Brownb83a3132011-05-11 19:59:58 +0200378 if (map->format.format_write) {
379 map->format.format_write(map, reg, val);
380
Mark Brownfb2736b2011-07-24 21:30:55 +0100381 trace_regmap_hw_write_start(map->dev, reg, 1);
382
383 ret = map->bus->write(map->dev, map->work_buf,
384 map->format.buf_size);
385
386 trace_regmap_hw_write_done(map->dev, reg, 1);
387
388 return ret;
Mark Brownb83a3132011-05-11 19:59:58 +0200389 } else {
390 map->format.format_val(map->work_buf + map->format.reg_bytes,
391 val);
392 return _regmap_raw_write(map, reg,
393 map->work_buf + map->format.reg_bytes,
394 map->format.val_bytes);
395 }
396}
397
398/**
399 * regmap_write(): Write a value to a single register
400 *
401 * @map: Register map to write to
402 * @reg: Register to write to
403 * @val: Value to be written
404 *
405 * A value of zero will be returned on success, a negative errno will
406 * be returned in error cases.
407 */
408int regmap_write(struct regmap *map, unsigned int reg, unsigned int val)
409{
410 int ret;
411
412 mutex_lock(&map->lock);
413
414 ret = _regmap_write(map, reg, val);
415
416 mutex_unlock(&map->lock);
417
418 return ret;
419}
420EXPORT_SYMBOL_GPL(regmap_write);
421
422/**
423 * regmap_raw_write(): Write raw values to one or more registers
424 *
425 * @map: Register map to write to
426 * @reg: Initial register to write to
427 * @val: Block of data to be written, laid out for direct transmission to the
428 * device
429 * @val_len: Length of data pointed to by val.
430 *
431 * This function is intended to be used for things like firmware
432 * download where a large block of data needs to be transferred to the
433 * device. No formatting will be done on the data provided.
434 *
435 * A value of zero will be returned on success, a negative errno will
436 * be returned in error cases.
437 */
438int regmap_raw_write(struct regmap *map, unsigned int reg,
439 const void *val, size_t val_len)
440{
Lars-Peter Clausenc48a9d72011-11-08 18:37:26 +0100441 size_t val_count = val_len / map->format.val_bytes;
Mark Brownb83a3132011-05-11 19:59:58 +0200442 int ret;
443
Lars-Peter Clausenc48a9d72011-11-08 18:37:26 +0100444 WARN_ON(!regmap_volatile_range(map, reg, val_count) &&
445 map->cache_type != REGCACHE_NONE);
Mark Brown04e016a2011-10-09 13:35:43 +0100446
Mark Brownb83a3132011-05-11 19:59:58 +0200447 mutex_lock(&map->lock);
448
449 ret = _regmap_raw_write(map, reg, val, val_len);
450
451 mutex_unlock(&map->lock);
452
453 return ret;
454}
455EXPORT_SYMBOL_GPL(regmap_raw_write);
456
457static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
458 unsigned int val_len)
459{
460 u8 *u8 = map->work_buf;
461 int ret;
462
463 map->format.format_reg(map->work_buf, reg);
464
465 /*
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200466 * Some buses or devices flag reads by setting the high bits in the
Mark Brownb83a3132011-05-11 19:59:58 +0200467 * register addresss; since it's always the high bits for all
468 * current formats we can do this here rather than in
469 * formatting. This may break if we get interesting formats.
470 */
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200471 u8[0] |= map->read_flag_mask;
Mark Brownb83a3132011-05-11 19:59:58 +0200472
Mark Brownfb2736b2011-07-24 21:30:55 +0100473 trace_regmap_hw_read_start(map->dev, reg,
474 val_len / map->format.val_bytes);
475
Mark Brownb83a3132011-05-11 19:59:58 +0200476 ret = map->bus->read(map->dev, map->work_buf, map->format.reg_bytes,
Mark Brown40c5cc22011-07-24 22:39:12 +0100477 val, val_len);
Mark Brownb83a3132011-05-11 19:59:58 +0200478
Mark Brownfb2736b2011-07-24 21:30:55 +0100479 trace_regmap_hw_read_done(map->dev, reg,
480 val_len / map->format.val_bytes);
481
482 return ret;
Mark Brownb83a3132011-05-11 19:59:58 +0200483}
484
485static int _regmap_read(struct regmap *map, unsigned int reg,
486 unsigned int *val)
487{
488 int ret;
489
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100490 if (!map->cache_bypass) {
491 ret = regcache_read(map, reg, val);
492 if (ret == 0)
493 return 0;
494 }
495
Lars-Peter Clausen19254412011-11-16 16:28:19 +0100496 if (!map->format.parse_val)
497 return -EINVAL;
498
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100499 if (map->cache_only)
500 return -EBUSY;
501
Mark Brownb83a3132011-05-11 19:59:58 +0200502 ret = _regmap_raw_read(map, reg, map->work_buf, map->format.val_bytes);
Mark Brownfb2736b2011-07-24 21:30:55 +0100503 if (ret == 0) {
Mark Brownb83a3132011-05-11 19:59:58 +0200504 *val = map->format.parse_val(map->work_buf);
Mark Brownfb2736b2011-07-24 21:30:55 +0100505 trace_regmap_reg_read(map->dev, reg, *val);
506 }
Mark Brownb83a3132011-05-11 19:59:58 +0200507
508 return ret;
509}
510
511/**
512 * regmap_read(): Read a value from a single register
513 *
514 * @map: Register map to write to
515 * @reg: Register to be read from
516 * @val: Pointer to store read value
517 *
518 * A value of zero will be returned on success, a negative errno will
519 * be returned in error cases.
520 */
521int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val)
522{
523 int ret;
524
525 mutex_lock(&map->lock);
526
527 ret = _regmap_read(map, reg, val);
528
529 mutex_unlock(&map->lock);
530
531 return ret;
532}
533EXPORT_SYMBOL_GPL(regmap_read);
534
535/**
536 * regmap_raw_read(): Read raw data from the device
537 *
538 * @map: Register map to write to
539 * @reg: First register to be read from
540 * @val: Pointer to store read value
541 * @val_len: Size of data to read
542 *
543 * A value of zero will be returned on success, a negative errno will
544 * be returned in error cases.
545 */
546int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
547 size_t val_len)
548{
Lars-Peter Clausen82cd9962011-11-08 18:37:25 +0100549 size_t val_count = val_len / map->format.val_bytes;
Mark Brownb83a3132011-05-11 19:59:58 +0200550 int ret;
551
Lars-Peter Clausen82cd9962011-11-08 18:37:25 +0100552 WARN_ON(!regmap_volatile_range(map, reg, val_count) &&
553 map->cache_type != REGCACHE_NONE);
Mark Brown04e016a2011-10-09 13:35:43 +0100554
Mark Brownb83a3132011-05-11 19:59:58 +0200555 mutex_lock(&map->lock);
556
557 ret = _regmap_raw_read(map, reg, val, val_len);
558
559 mutex_unlock(&map->lock);
560
561 return ret;
562}
563EXPORT_SYMBOL_GPL(regmap_raw_read);
564
565/**
566 * regmap_bulk_read(): Read multiple registers from the device
567 *
568 * @map: Register map to write to
569 * @reg: First register to be read from
570 * @val: Pointer to store read value, in native register size for device
571 * @val_count: Number of registers to read
572 *
573 * A value of zero will be returned on success, a negative errno will
574 * be returned in error cases.
575 */
576int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
577 size_t val_count)
578{
579 int ret, i;
580 size_t val_bytes = map->format.val_bytes;
Lars-Peter Clausen82cd9962011-11-08 18:37:25 +0100581 bool vol = regmap_volatile_range(map, reg, val_count);
Dimitris Papastamos5d1729e2011-09-19 14:34:05 +0100582
Mark Brownb83a3132011-05-11 19:59:58 +0200583 if (!map->format.parse_val)
584 return -EINVAL;
585
Mark Brownde2d8082011-10-10 13:24:52 +0100586 if (vol || map->cache_type == REGCACHE_NONE) {
587 ret = regmap_raw_read(map, reg, val, val_bytes * val_count);
588 if (ret != 0)
589 return ret;
590
591 for (i = 0; i < val_count * val_bytes; i += val_bytes)
592 map->format.parse_val(val + i);
593 } else {
594 for (i = 0; i < val_count; i++) {
595 ret = regmap_read(map, reg + i, val + (i * val_bytes));
596 if (ret != 0)
597 return ret;
598 }
599 }
Mark Brownb83a3132011-05-11 19:59:58 +0200600
601 return 0;
602}
603EXPORT_SYMBOL_GPL(regmap_bulk_read);
604
Mark Brown018690d2011-11-29 20:10:36 +0000605static int _regmap_update_bits(struct regmap *map, unsigned int reg,
606 unsigned int mask, unsigned int val,
607 bool *change)
Mark Brownb83a3132011-05-11 19:59:58 +0200608{
609 int ret;
Mark Brownd91e8db22011-11-18 16:03:50 +0000610 unsigned int tmp, orig;
Mark Brownb83a3132011-05-11 19:59:58 +0200611
612 mutex_lock(&map->lock);
613
Mark Brownd91e8db22011-11-18 16:03:50 +0000614 ret = _regmap_read(map, reg, &orig);
Mark Brownb83a3132011-05-11 19:59:58 +0200615 if (ret != 0)
616 goto out;
617
Mark Brownd91e8db22011-11-18 16:03:50 +0000618 tmp = orig & ~mask;
Mark Brownb83a3132011-05-11 19:59:58 +0200619 tmp |= val & mask;
620
Mark Brown018690d2011-11-29 20:10:36 +0000621 if (tmp != orig) {
Mark Brownd91e8db22011-11-18 16:03:50 +0000622 ret = _regmap_write(map, reg, tmp);
Mark Brown018690d2011-11-29 20:10:36 +0000623 *change = true;
624 } else {
625 *change = false;
626 }
Mark Brownb83a3132011-05-11 19:59:58 +0200627
628out:
629 mutex_unlock(&map->lock);
630
631 return ret;
632}
Mark Brown018690d2011-11-29 20:10:36 +0000633
634/**
635 * regmap_update_bits: Perform a read/modify/write cycle on the register map
636 *
637 * @map: Register map to update
638 * @reg: Register to update
639 * @mask: Bitmask to change
640 * @val: New value for bitmask
641 *
642 * Returns zero for success, a negative number on error.
643 */
644int regmap_update_bits(struct regmap *map, unsigned int reg,
645 unsigned int mask, unsigned int val)
646{
647 bool change;
648 return _regmap_update_bits(map, reg, mask, val, &change);
649}
Mark Brownb83a3132011-05-11 19:59:58 +0200650EXPORT_SYMBOL_GPL(regmap_update_bits);
Mark Brown31244e32011-07-20 22:56:53 +0100651
Mark Brown018690d2011-11-29 20:10:36 +0000652/**
653 * regmap_update_bits_check: Perform a read/modify/write cycle on the
654 * register map and report if updated
655 *
656 * @map: Register map to update
657 * @reg: Register to update
658 * @mask: Bitmask to change
659 * @val: New value for bitmask
660 * @change: Boolean indicating if a write was done
661 *
662 * Returns zero for success, a negative number on error.
663 */
664int regmap_update_bits_check(struct regmap *map, unsigned int reg,
665 unsigned int mask, unsigned int val,
666 bool *change)
667{
668 return _regmap_update_bits(map, reg, mask, val, change);
669}
670EXPORT_SYMBOL_GPL(regmap_update_bits_check);
671
Mark Brown31244e32011-07-20 22:56:53 +0100672static int __init regmap_initcall(void)
673{
674 regmap_debugfs_initcall();
675
676 return 0;
677}
678postcore_initcall(regmap_initcall);