2 * Register map access API
4 * Copyright 2011 Wolfson Microelectronics plc
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
13 #include <linux/device.h>
14 #include <linux/slab.h>
15 #include <linux/export.h>
16 #include <linux/mutex.h>
17 #include <linux/err.h>
19 #define CREATE_TRACE_POINTS
20 #include <trace/events/regmap.h>
24 bool regmap_writeable(struct regmap
*map
, unsigned int reg
)
26 if (map
->max_register
&& reg
> map
->max_register
)
29 if (map
->writeable_reg
)
30 return map
->writeable_reg(map
->dev
, reg
);
35 bool regmap_readable(struct regmap
*map
, unsigned int reg
)
37 if (map
->max_register
&& reg
> map
->max_register
)
40 if (map
->format
.format_write
)
43 if (map
->readable_reg
)
44 return map
->readable_reg(map
->dev
, reg
);
49 bool regmap_volatile(struct regmap
*map
, unsigned int reg
)
51 if (!regmap_readable(map
, reg
))
54 if (map
->volatile_reg
)
55 return map
->volatile_reg(map
->dev
, reg
);
60 bool regmap_precious(struct regmap
*map
, unsigned int reg
)
62 if (!regmap_readable(map
, reg
))
65 if (map
->precious_reg
)
66 return map
->precious_reg(map
->dev
, reg
);
71 static bool regmap_volatile_range(struct regmap
*map
, unsigned int reg
,
76 for (i
= 0; i
< num
; i
++)
77 if (!regmap_volatile(map
, reg
+ i
))
83 static void regmap_format_2_6_write(struct regmap
*map
,
84 unsigned int reg
, unsigned int val
)
86 u8
*out
= map
->work_buf
;
88 *out
= (reg
<< 6) | val
;
91 static void regmap_format_4_12_write(struct regmap
*map
,
92 unsigned int reg
, unsigned int val
)
94 __be16
*out
= map
->work_buf
;
95 *out
= cpu_to_be16((reg
<< 12) | val
);
98 static void regmap_format_7_9_write(struct regmap
*map
,
99 unsigned int reg
, unsigned int val
)
101 __be16
*out
= map
->work_buf
;
102 *out
= cpu_to_be16((reg
<< 9) | val
);
105 static void regmap_format_10_14_write(struct regmap
*map
,
106 unsigned int reg
, unsigned int val
)
108 u8
*out
= map
->work_buf
;
111 out
[1] = (val
>> 8) | (reg
<< 6);
115 static void regmap_format_8(void *buf
, unsigned int val
, unsigned int shift
)
122 static void regmap_format_16(void *buf
, unsigned int val
, unsigned int shift
)
126 b
[0] = cpu_to_be16(val
<< shift
);
129 static void regmap_format_24(void *buf
, unsigned int val
, unsigned int shift
)
140 static void regmap_format_32(void *buf
, unsigned int val
, unsigned int shift
)
144 b
[0] = cpu_to_be32(val
<< shift
);
147 static unsigned int regmap_parse_8(void *buf
)
154 static unsigned int regmap_parse_16(void *buf
)
158 b
[0] = be16_to_cpu(b
[0]);
163 static unsigned int regmap_parse_24(void *buf
)
166 unsigned int ret
= b
[2];
167 ret
|= ((unsigned int)b
[1]) << 8;
168 ret
|= ((unsigned int)b
[0]) << 16;
173 static unsigned int regmap_parse_32(void *buf
)
177 b
[0] = be32_to_cpu(b
[0]);
182 static void regmap_lock_mutex(struct regmap
*map
)
184 mutex_lock(&map
->mutex
);
187 static void regmap_unlock_mutex(struct regmap
*map
)
189 mutex_unlock(&map
->mutex
);
192 static void regmap_lock_spinlock(struct regmap
*map
)
194 spin_lock(&map
->spinlock
);
197 static void regmap_unlock_spinlock(struct regmap
*map
)
199 spin_unlock(&map
->spinlock
);
202 static void dev_get_regmap_release(struct device
*dev
, void *res
)
205 * We don't actually have anything to do here; the goal here
206 * is not to manage the regmap but to provide a simple way to
207 * get the regmap back given a struct device.
212 * regmap_init(): Initialise register map
214 * @dev: Device that will be interacted with
215 * @bus: Bus-specific callbacks to use with device
216 * @bus_context: Data passed to bus-specific callbacks
217 * @config: Configuration for register map
219 * The return value will be an ERR_PTR() on error or a valid pointer to
220 * a struct regmap. This function should generally not be called
221 * directly, it should be called by bus-specific init functions.
223 struct regmap
*regmap_init(struct device
*dev
,
224 const struct regmap_bus
*bus
,
226 const struct regmap_config
*config
)
228 struct regmap
*map
, **m
;
234 map
= kzalloc(sizeof(*map
), GFP_KERNEL
);
241 spin_lock_init(&map
->spinlock
);
242 map
->lock
= regmap_lock_spinlock
;
243 map
->unlock
= regmap_unlock_spinlock
;
245 mutex_init(&map
->mutex
);
246 map
->lock
= regmap_lock_mutex
;
247 map
->unlock
= regmap_unlock_mutex
;
249 map
->format
.reg_bytes
= DIV_ROUND_UP(config
->reg_bits
, 8);
250 map
->format
.pad_bytes
= config
->pad_bits
/ 8;
251 map
->format
.val_bytes
= DIV_ROUND_UP(config
->val_bits
, 8);
252 map
->format
.buf_size
= DIV_ROUND_UP(config
->reg_bits
+
253 config
->val_bits
+ config
->pad_bits
, 8);
254 map
->reg_shift
= config
->pad_bits
% 8;
255 if (config
->reg_stride
)
256 map
->reg_stride
= config
->reg_stride
;
259 map
->use_single_rw
= config
->use_single_rw
;
262 map
->bus_context
= bus_context
;
263 map
->max_register
= config
->max_register
;
264 map
->writeable_reg
= config
->writeable_reg
;
265 map
->readable_reg
= config
->readable_reg
;
266 map
->volatile_reg
= config
->volatile_reg
;
267 map
->precious_reg
= config
->precious_reg
;
268 map
->cache_type
= config
->cache_type
;
269 map
->name
= config
->name
;
271 if (config
->read_flag_mask
|| config
->write_flag_mask
) {
272 map
->read_flag_mask
= config
->read_flag_mask
;
273 map
->write_flag_mask
= config
->write_flag_mask
;
275 map
->read_flag_mask
= bus
->read_flag_mask
;
278 switch (config
->reg_bits
+ map
->reg_shift
) {
280 switch (config
->val_bits
) {
282 map
->format
.format_write
= regmap_format_2_6_write
;
290 switch (config
->val_bits
) {
292 map
->format
.format_write
= regmap_format_4_12_write
;
300 switch (config
->val_bits
) {
302 map
->format
.format_write
= regmap_format_7_9_write
;
310 switch (config
->val_bits
) {
312 map
->format
.format_write
= regmap_format_10_14_write
;
320 map
->format
.format_reg
= regmap_format_8
;
324 map
->format
.format_reg
= regmap_format_16
;
328 map
->format
.format_reg
= regmap_format_32
;
335 switch (config
->val_bits
) {
337 map
->format
.format_val
= regmap_format_8
;
338 map
->format
.parse_val
= regmap_parse_8
;
341 map
->format
.format_val
= regmap_format_16
;
342 map
->format
.parse_val
= regmap_parse_16
;
345 map
->format
.format_val
= regmap_format_24
;
346 map
->format
.parse_val
= regmap_parse_24
;
349 map
->format
.format_val
= regmap_format_32
;
350 map
->format
.parse_val
= regmap_parse_32
;
354 if (map
->format
.format_write
)
355 map
->use_single_rw
= true;
357 if (!map
->format
.format_write
&&
358 !(map
->format
.format_reg
&& map
->format
.format_val
))
361 map
->work_buf
= kzalloc(map
->format
.buf_size
, GFP_KERNEL
);
362 if (map
->work_buf
== NULL
) {
367 regmap_debugfs_init(map
, config
->name
);
369 ret
= regcache_init(map
, config
);
373 /* Add a devres resource for dev_get_regmap() */
374 m
= devres_alloc(dev_get_regmap_release
, sizeof(*m
), GFP_KERNEL
);
387 regmap_debugfs_exit(map
);
388 kfree(map
->work_buf
);
394 EXPORT_SYMBOL_GPL(regmap_init
);
396 static void devm_regmap_release(struct device
*dev
, void *res
)
398 regmap_exit(*(struct regmap
**)res
);
402 * devm_regmap_init(): Initialise managed register map
404 * @dev: Device that will be interacted with
405 * @bus: Bus-specific callbacks to use with device
406 * @bus_context: Data passed to bus-specific callbacks
407 * @config: Configuration for register map
409 * The return value will be an ERR_PTR() on error or a valid pointer
410 * to a struct regmap. This function should generally not be called
411 * directly, it should be called by bus-specific init functions. The
412 * map will be automatically freed by the device management code.
414 struct regmap
*devm_regmap_init(struct device
*dev
,
415 const struct regmap_bus
*bus
,
417 const struct regmap_config
*config
)
419 struct regmap
**ptr
, *regmap
;
421 ptr
= devres_alloc(devm_regmap_release
, sizeof(*ptr
), GFP_KERNEL
);
423 return ERR_PTR(-ENOMEM
);
425 regmap
= regmap_init(dev
, bus
, bus_context
, config
);
426 if (!IS_ERR(regmap
)) {
428 devres_add(dev
, ptr
);
435 EXPORT_SYMBOL_GPL(devm_regmap_init
);
438 * regmap_reinit_cache(): Reinitialise the current register cache
440 * @map: Register map to operate on.
441 * @config: New configuration. Only the cache data will be used.
443 * Discard any existing register cache for the map and initialize a
444 * new cache. This can be used to restore the cache to defaults or to
445 * update the cache configuration to reflect runtime discovery of the
448 int regmap_reinit_cache(struct regmap
*map
, const struct regmap_config
*config
)
455 regmap_debugfs_exit(map
);
457 map
->max_register
= config
->max_register
;
458 map
->writeable_reg
= config
->writeable_reg
;
459 map
->readable_reg
= config
->readable_reg
;
460 map
->volatile_reg
= config
->volatile_reg
;
461 map
->precious_reg
= config
->precious_reg
;
462 map
->cache_type
= config
->cache_type
;
464 regmap_debugfs_init(map
, config
->name
);
466 map
->cache_bypass
= false;
467 map
->cache_only
= false;
469 ret
= regcache_init(map
, config
);
475 EXPORT_SYMBOL_GPL(regmap_reinit_cache
);
478 * regmap_exit(): Free a previously allocated register map
480 void regmap_exit(struct regmap
*map
)
483 regmap_debugfs_exit(map
);
484 if (map
->bus
->free_context
)
485 map
->bus
->free_context(map
->bus_context
);
486 kfree(map
->work_buf
);
489 EXPORT_SYMBOL_GPL(regmap_exit
);
491 static int dev_get_regmap_match(struct device
*dev
, void *res
, void *data
)
493 struct regmap
**r
= res
;
499 /* If the user didn't specify a name match any */
501 return (*r
)->name
== data
;
507 * dev_get_regmap(): Obtain the regmap (if any) for a device
509 * @dev: Device to retrieve the map for
510 * @name: Optional name for the register map, usually NULL.
512 * Returns the regmap for the device if one is present, or NULL. If
513 * name is specified then it must match the name specified when
514 * registering the device, if it is NULL then the first regmap found
515 * will be used. Devices with multiple register maps are very rare,
516 * generic code should normally not need to specify a name.
518 struct regmap
*dev_get_regmap(struct device
*dev
, const char *name
)
520 struct regmap
**r
= devres_find(dev
, dev_get_regmap_release
,
521 dev_get_regmap_match
, (void *)name
);
527 EXPORT_SYMBOL_GPL(dev_get_regmap
);
529 static int _regmap_raw_write(struct regmap
*map
, unsigned int reg
,
530 const void *val
, size_t val_len
)
532 u8
*u8
= map
->work_buf
;
538 /* Check for unwritable registers before we start */
539 if (map
->writeable_reg
)
540 for (i
= 0; i
< val_len
/ map
->format
.val_bytes
; i
++)
541 if (!map
->writeable_reg(map
->dev
,
542 reg
+ (i
* map
->reg_stride
)))
545 if (!map
->cache_bypass
&& map
->format
.parse_val
) {
547 int val_bytes
= map
->format
.val_bytes
;
548 for (i
= 0; i
< val_len
/ val_bytes
; i
++) {
549 memcpy(map
->work_buf
, val
+ (i
* val_bytes
), val_bytes
);
550 ival
= map
->format
.parse_val(map
->work_buf
);
551 ret
= regcache_write(map
, reg
+ (i
* map
->reg_stride
),
555 "Error in caching of register: %u ret: %d\n",
560 if (map
->cache_only
) {
561 map
->cache_dirty
= true;
566 map
->format
.format_reg(map
->work_buf
, reg
, map
->reg_shift
);
568 u8
[0] |= map
->write_flag_mask
;
570 trace_regmap_hw_write_start(map
->dev
, reg
,
571 val_len
/ map
->format
.val_bytes
);
573 /* If we're doing a single register write we can probably just
574 * send the work_buf directly, otherwise try to do a gather
577 if (val
== (map
->work_buf
+ map
->format
.pad_bytes
+
578 map
->format
.reg_bytes
))
579 ret
= map
->bus
->write(map
->bus_context
, map
->work_buf
,
580 map
->format
.reg_bytes
+
581 map
->format
.pad_bytes
+
583 else if (map
->bus
->gather_write
)
584 ret
= map
->bus
->gather_write(map
->bus_context
, map
->work_buf
,
585 map
->format
.reg_bytes
+
586 map
->format
.pad_bytes
,
589 /* If that didn't work fall back on linearising by hand. */
590 if (ret
== -ENOTSUPP
) {
591 len
= map
->format
.reg_bytes
+ map
->format
.pad_bytes
+ val_len
;
592 buf
= kzalloc(len
, GFP_KERNEL
);
596 memcpy(buf
, map
->work_buf
, map
->format
.reg_bytes
);
597 memcpy(buf
+ map
->format
.reg_bytes
+ map
->format
.pad_bytes
,
599 ret
= map
->bus
->write(map
->bus_context
, buf
, len
);
604 trace_regmap_hw_write_done(map
->dev
, reg
,
605 val_len
/ map
->format
.val_bytes
);
610 int _regmap_write(struct regmap
*map
, unsigned int reg
,
614 BUG_ON(!map
->format
.format_write
&& !map
->format
.format_val
);
616 if (!map
->cache_bypass
&& map
->format
.format_write
) {
617 ret
= regcache_write(map
, reg
, val
);
620 if (map
->cache_only
) {
621 map
->cache_dirty
= true;
626 trace_regmap_reg_write(map
->dev
, reg
, val
);
628 if (map
->format
.format_write
) {
629 map
->format
.format_write(map
, reg
, val
);
631 trace_regmap_hw_write_start(map
->dev
, reg
, 1);
633 ret
= map
->bus
->write(map
->bus_context
, map
->work_buf
,
634 map
->format
.buf_size
);
636 trace_regmap_hw_write_done(map
->dev
, reg
, 1);
640 map
->format
.format_val(map
->work_buf
+ map
->format
.reg_bytes
641 + map
->format
.pad_bytes
, val
, 0);
642 return _regmap_raw_write(map
, reg
,
644 map
->format
.reg_bytes
+
645 map
->format
.pad_bytes
,
646 map
->format
.val_bytes
);
651 * regmap_write(): Write a value to a single register
653 * @map: Register map to write to
654 * @reg: Register to write to
655 * @val: Value to be written
657 * A value of zero will be returned on success, a negative errno will
658 * be returned in error cases.
660 int regmap_write(struct regmap
*map
, unsigned int reg
, unsigned int val
)
664 if (reg
% map
->reg_stride
)
669 ret
= _regmap_write(map
, reg
, val
);
675 EXPORT_SYMBOL_GPL(regmap_write
);
678 * regmap_raw_write(): Write raw values to one or more registers
680 * @map: Register map to write to
681 * @reg: Initial register to write to
682 * @val: Block of data to be written, laid out for direct transmission to the
684 * @val_len: Length of data pointed to by val.
686 * This function is intended to be used for things like firmware
687 * download where a large block of data needs to be transferred to the
688 * device. No formatting will be done on the data provided.
690 * A value of zero will be returned on success, a negative errno will
691 * be returned in error cases.
693 int regmap_raw_write(struct regmap
*map
, unsigned int reg
,
694 const void *val
, size_t val_len
)
698 if (val_len
% map
->format
.val_bytes
)
700 if (reg
% map
->reg_stride
)
705 ret
= _regmap_raw_write(map
, reg
, val
, val_len
);
711 EXPORT_SYMBOL_GPL(regmap_raw_write
);
714 * regmap_bulk_write(): Write multiple registers to the device
716 * @map: Register map to write to
717 * @reg: First register to be write from
718 * @val: Block of data to be written, in native register size for device
719 * @val_count: Number of registers to write
721 * This function is intended to be used for writing a large block of
722 * data to be device either in single transfer or multiple transfer.
724 * A value of zero will be returned on success, a negative errno will
725 * be returned in error cases.
727 int regmap_bulk_write(struct regmap
*map
, unsigned int reg
, const void *val
,
731 size_t val_bytes
= map
->format
.val_bytes
;
734 if (!map
->format
.parse_val
)
736 if (reg
% map
->reg_stride
)
741 /* No formatting is require if val_byte is 1 */
742 if (val_bytes
== 1) {
745 wval
= kmemdup(val
, val_count
* val_bytes
, GFP_KERNEL
);
748 dev_err(map
->dev
, "Error in memory allocation\n");
751 for (i
= 0; i
< val_count
* val_bytes
; i
+= val_bytes
)
752 map
->format
.parse_val(wval
+ i
);
755 * Some devices does not support bulk write, for
756 * them we have a series of single write operations.
758 if (map
->use_single_rw
) {
759 for (i
= 0; i
< val_count
; i
++) {
760 ret
= regmap_raw_write(map
,
761 reg
+ (i
* map
->reg_stride
),
762 val
+ (i
* val_bytes
),
768 ret
= _regmap_raw_write(map
, reg
, wval
, val_bytes
* val_count
);
778 EXPORT_SYMBOL_GPL(regmap_bulk_write
);
780 static int _regmap_raw_read(struct regmap
*map
, unsigned int reg
, void *val
,
781 unsigned int val_len
)
783 u8
*u8
= map
->work_buf
;
786 map
->format
.format_reg(map
->work_buf
, reg
, map
->reg_shift
);
789 * Some buses or devices flag reads by setting the high bits in the
790 * register addresss; since it's always the high bits for all
791 * current formats we can do this here rather than in
792 * formatting. This may break if we get interesting formats.
794 u8
[0] |= map
->read_flag_mask
;
796 trace_regmap_hw_read_start(map
->dev
, reg
,
797 val_len
/ map
->format
.val_bytes
);
799 ret
= map
->bus
->read(map
->bus_context
, map
->work_buf
,
800 map
->format
.reg_bytes
+ map
->format
.pad_bytes
,
803 trace_regmap_hw_read_done(map
->dev
, reg
,
804 val_len
/ map
->format
.val_bytes
);
809 static int _regmap_read(struct regmap
*map
, unsigned int reg
,
814 if (!map
->cache_bypass
) {
815 ret
= regcache_read(map
, reg
, val
);
820 if (!map
->format
.parse_val
)
826 ret
= _regmap_raw_read(map
, reg
, map
->work_buf
, map
->format
.val_bytes
);
828 *val
= map
->format
.parse_val(map
->work_buf
);
829 trace_regmap_reg_read(map
->dev
, reg
, *val
);
832 if (ret
== 0 && !map
->cache_bypass
)
833 regcache_write(map
, reg
, *val
);
839 * regmap_read(): Read a value from a single register
841 * @map: Register map to write to
842 * @reg: Register to be read from
843 * @val: Pointer to store read value
845 * A value of zero will be returned on success, a negative errno will
846 * be returned in error cases.
848 int regmap_read(struct regmap
*map
, unsigned int reg
, unsigned int *val
)
852 if (reg
% map
->reg_stride
)
857 ret
= _regmap_read(map
, reg
, val
);
863 EXPORT_SYMBOL_GPL(regmap_read
);
866 * regmap_raw_read(): Read raw data from the device
868 * @map: Register map to write to
869 * @reg: First register to be read from
870 * @val: Pointer to store read value
871 * @val_len: Size of data to read
873 * A value of zero will be returned on success, a negative errno will
874 * be returned in error cases.
876 int regmap_raw_read(struct regmap
*map
, unsigned int reg
, void *val
,
879 size_t val_bytes
= map
->format
.val_bytes
;
880 size_t val_count
= val_len
/ val_bytes
;
884 if (val_len
% map
->format
.val_bytes
)
886 if (reg
% map
->reg_stride
)
891 if (regmap_volatile_range(map
, reg
, val_count
) || map
->cache_bypass
||
892 map
->cache_type
== REGCACHE_NONE
) {
893 /* Physical block read if there's no cache involved */
894 ret
= _regmap_raw_read(map
, reg
, val
, val_len
);
897 /* Otherwise go word by word for the cache; should be low
898 * cost as we expect to hit the cache.
900 for (i
= 0; i
< val_count
; i
++) {
901 ret
= _regmap_read(map
, reg
+ (i
* map
->reg_stride
),
906 map
->format
.format_val(val
+ (i
* val_bytes
), v
, 0);
915 EXPORT_SYMBOL_GPL(regmap_raw_read
);
918 * regmap_bulk_read(): Read multiple registers from the device
920 * @map: Register map to write to
921 * @reg: First register to be read from
922 * @val: Pointer to store read value, in native register size for device
923 * @val_count: Number of registers to read
925 * A value of zero will be returned on success, a negative errno will
926 * be returned in error cases.
928 int regmap_bulk_read(struct regmap
*map
, unsigned int reg
, void *val
,
932 size_t val_bytes
= map
->format
.val_bytes
;
933 bool vol
= regmap_volatile_range(map
, reg
, val_count
);
935 if (!map
->format
.parse_val
)
937 if (reg
% map
->reg_stride
)
940 if (vol
|| map
->cache_type
== REGCACHE_NONE
) {
942 * Some devices does not support bulk read, for
943 * them we have a series of single read operations.
945 if (map
->use_single_rw
) {
946 for (i
= 0; i
< val_count
; i
++) {
947 ret
= regmap_raw_read(map
,
948 reg
+ (i
* map
->reg_stride
),
949 val
+ (i
* val_bytes
),
955 ret
= regmap_raw_read(map
, reg
, val
,
956 val_bytes
* val_count
);
961 for (i
= 0; i
< val_count
* val_bytes
; i
+= val_bytes
)
962 map
->format
.parse_val(val
+ i
);
964 for (i
= 0; i
< val_count
; i
++) {
966 ret
= regmap_read(map
, reg
+ (i
* map
->reg_stride
),
970 memcpy(val
+ (i
* val_bytes
), &ival
, val_bytes
);
976 EXPORT_SYMBOL_GPL(regmap_bulk_read
);
978 static int _regmap_update_bits(struct regmap
*map
, unsigned int reg
,
979 unsigned int mask
, unsigned int val
,
983 unsigned int tmp
, orig
;
987 ret
= _regmap_read(map
, reg
, &orig
);
995 ret
= _regmap_write(map
, reg
, tmp
);
1008 * regmap_update_bits: Perform a read/modify/write cycle on the register map
1010 * @map: Register map to update
1011 * @reg: Register to update
1012 * @mask: Bitmask to change
1013 * @val: New value for bitmask
1015 * Returns zero for success, a negative number on error.
1017 int regmap_update_bits(struct regmap
*map
, unsigned int reg
,
1018 unsigned int mask
, unsigned int val
)
1021 return _regmap_update_bits(map
, reg
, mask
, val
, &change
);
1023 EXPORT_SYMBOL_GPL(regmap_update_bits
);
1026 * regmap_update_bits_check: Perform a read/modify/write cycle on the
1027 * register map and report if updated
1029 * @map: Register map to update
1030 * @reg: Register to update
1031 * @mask: Bitmask to change
1032 * @val: New value for bitmask
1033 * @change: Boolean indicating if a write was done
1035 * Returns zero for success, a negative number on error.
1037 int regmap_update_bits_check(struct regmap
*map
, unsigned int reg
,
1038 unsigned int mask
, unsigned int val
,
1041 return _regmap_update_bits(map
, reg
, mask
, val
, change
);
1043 EXPORT_SYMBOL_GPL(regmap_update_bits_check
);
1046 * regmap_register_patch: Register and apply register updates to be applied
1047 * on device initialistion
1049 * @map: Register map to apply updates to.
1050 * @regs: Values to update.
1051 * @num_regs: Number of entries in regs.
1053 * Register a set of register updates to be applied to the device
1054 * whenever the device registers are synchronised with the cache and
1055 * apply them immediately. Typically this is used to apply
1056 * corrections to be applied to the device defaults on startup, such
1057 * as the updates some vendors provide to undocumented registers.
1059 int regmap_register_patch(struct regmap
*map
, const struct reg_default
*regs
,
1065 /* If needed the implementation can be extended to support this */
1071 bypass
= map
->cache_bypass
;
1073 map
->cache_bypass
= true;
1075 /* Write out first; it's useful to apply even if we fail later. */
1076 for (i
= 0; i
< num_regs
; i
++) {
1077 ret
= _regmap_write(map
, regs
[i
].reg
, regs
[i
].def
);
1079 dev_err(map
->dev
, "Failed to write %x = %x: %d\n",
1080 regs
[i
].reg
, regs
[i
].def
, ret
);
1085 map
->patch
= kcalloc(num_regs
, sizeof(struct reg_default
), GFP_KERNEL
);
1086 if (map
->patch
!= NULL
) {
1087 memcpy(map
->patch
, regs
,
1088 num_regs
* sizeof(struct reg_default
));
1089 map
->patch_regs
= num_regs
;
1095 map
->cache_bypass
= bypass
;
1101 EXPORT_SYMBOL_GPL(regmap_register_patch
);
1104 * regmap_get_val_bytes(): Report the size of a register value
1106 * Report the size of a register value, mainly intended to for use by
1107 * generic infrastructure built on top of regmap.
1109 int regmap_get_val_bytes(struct regmap
*map
)
1111 if (map
->format
.format_write
)
1114 return map
->format
.val_bytes
;
1116 EXPORT_SYMBOL_GPL(regmap_get_val_bytes
);
1118 static int __init
regmap_initcall(void)
1120 regmap_debugfs_initcall();
1124 postcore_initcall(regmap_initcall
);