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>
25 * Sometimes for failures during very early init the trace
26 * infrastructure isn't available early enough to be used. For this
27 * sort of problem defining LOG_DEVICE will add printks for basic
28 * register I/O on a specific device.
32 static int _regmap_update_bits(struct regmap *map, unsigned int reg,
33 unsigned int mask, unsigned int val,
36 bool regmap_writeable(struct regmap *map, unsigned int reg)
38 if (map->max_register && reg > map->max_register)
41 if (map->writeable_reg)
42 return map->writeable_reg(map->dev, reg);
47 bool regmap_readable(struct regmap *map, unsigned int reg)
49 if (map->max_register && reg > map->max_register)
52 if (map->format.format_write)
55 if (map->readable_reg)
56 return map->readable_reg(map->dev, reg);
61 bool regmap_volatile(struct regmap *map, unsigned int reg)
63 if (!regmap_readable(map, reg))
66 if (map->volatile_reg)
67 return map->volatile_reg(map->dev, reg);
72 bool regmap_precious(struct regmap *map, unsigned int reg)
74 if (!regmap_readable(map, reg))
77 if (map->precious_reg)
78 return map->precious_reg(map->dev, reg);
83 static bool regmap_volatile_range(struct regmap *map, unsigned int reg,
88 for (i = 0; i < num; i++)
89 if (!regmap_volatile(map, reg + i))
95 static void regmap_format_2_6_write(struct regmap *map,
96 unsigned int reg, unsigned int val)
98 u8 *out = map->work_buf;
100 *out = (reg << 6) | val;
103 static void regmap_format_4_12_write(struct regmap *map,
104 unsigned int reg, unsigned int val)
106 __be16 *out = map->work_buf;
107 *out = cpu_to_be16((reg << 12) | val);
110 static void regmap_format_7_9_write(struct regmap *map,
111 unsigned int reg, unsigned int val)
113 __be16 *out = map->work_buf;
114 *out = cpu_to_be16((reg << 9) | val);
117 static void regmap_format_10_14_write(struct regmap *map,
118 unsigned int reg, unsigned int val)
120 u8 *out = map->work_buf;
123 out[1] = (val >> 8) | (reg << 6);
127 static void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
134 static void regmap_format_16_be(void *buf, unsigned int val, unsigned int shift)
138 b[0] = cpu_to_be16(val << shift);
141 static void regmap_format_16_native(void *buf, unsigned int val,
144 *(u16 *)buf = val << shift;
147 static void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
158 static void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift)
162 b[0] = cpu_to_be32(val << shift);
165 static void regmap_format_32_native(void *buf, unsigned int val,
168 *(u32 *)buf = val << shift;
171 static unsigned int regmap_parse_8(void *buf)
178 static unsigned int regmap_parse_16_be(void *buf)
182 b[0] = be16_to_cpu(b[0]);
187 static unsigned int regmap_parse_16_native(void *buf)
192 static unsigned int regmap_parse_24(void *buf)
195 unsigned int ret = b[2];
196 ret |= ((unsigned int)b[1]) << 8;
197 ret |= ((unsigned int)b[0]) << 16;
202 static unsigned int regmap_parse_32_be(void *buf)
206 b[0] = be32_to_cpu(b[0]);
211 static unsigned int regmap_parse_32_native(void *buf)
216 static void regmap_lock_mutex(struct regmap *map)
218 mutex_lock(&map->mutex);
221 static void regmap_unlock_mutex(struct regmap *map)
223 mutex_unlock(&map->mutex);
226 static void regmap_lock_spinlock(struct regmap *map)
228 spin_lock(&map->spinlock);
231 static void regmap_unlock_spinlock(struct regmap *map)
233 spin_unlock(&map->spinlock);
236 static void dev_get_regmap_release(struct device *dev, void *res)
239 * We don't actually have anything to do here; the goal here
240 * is not to manage the regmap but to provide a simple way to
241 * get the regmap back given a struct device.
246 * regmap_init(): Initialise register map
248 * @dev: Device that will be interacted with
249 * @bus: Bus-specific callbacks to use with device
250 * @bus_context: Data passed to bus-specific callbacks
251 * @config: Configuration for register map
253 * The return value will be an ERR_PTR() on error or a valid pointer to
254 * a struct regmap. This function should generally not be called
255 * directly, it should be called by bus-specific init functions.
257 struct regmap *regmap_init(struct device *dev,
258 const struct regmap_bus *bus,
260 const struct regmap_config *config)
262 struct regmap *map, **m;
264 enum regmap_endian reg_endian, val_endian;
269 map = kzalloc(sizeof(*map), GFP_KERNEL);
276 spin_lock_init(&map->spinlock);
277 map->lock = regmap_lock_spinlock;
278 map->unlock = regmap_unlock_spinlock;
280 mutex_init(&map->mutex);
281 map->lock = regmap_lock_mutex;
282 map->unlock = regmap_unlock_mutex;
284 map->format.buf_size = (config->reg_bits + config->val_bits) / 8;
285 map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
286 map->format.pad_bytes = config->pad_bits / 8;
287 map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
288 map->format.buf_size += map->format.pad_bytes;
289 map->reg_shift = config->pad_bits % 8;
290 if (config->reg_stride)
291 map->reg_stride = config->reg_stride;
294 map->use_single_rw = config->use_single_rw;
297 map->bus_context = bus_context;
298 map->max_register = config->max_register;
299 map->writeable_reg = config->writeable_reg;
300 map->readable_reg = config->readable_reg;
301 map->volatile_reg = config->volatile_reg;
302 map->precious_reg = config->precious_reg;
303 map->cache_type = config->cache_type;
304 map->name = config->name;
306 if (config->read_flag_mask || config->write_flag_mask) {
307 map->read_flag_mask = config->read_flag_mask;
308 map->write_flag_mask = config->write_flag_mask;
310 map->read_flag_mask = bus->read_flag_mask;
313 reg_endian = config->reg_format_endian;
314 if (reg_endian == REGMAP_ENDIAN_DEFAULT)
315 reg_endian = bus->reg_format_endian_default;
316 if (reg_endian == REGMAP_ENDIAN_DEFAULT)
317 reg_endian = REGMAP_ENDIAN_BIG;
319 val_endian = config->val_format_endian;
320 if (val_endian == REGMAP_ENDIAN_DEFAULT)
321 val_endian = bus->val_format_endian_default;
322 if (val_endian == REGMAP_ENDIAN_DEFAULT)
323 val_endian = REGMAP_ENDIAN_BIG;
325 switch (config->reg_bits + map->reg_shift) {
327 switch (config->val_bits) {
329 map->format.format_write = regmap_format_2_6_write;
337 switch (config->val_bits) {
339 map->format.format_write = regmap_format_4_12_write;
347 switch (config->val_bits) {
349 map->format.format_write = regmap_format_7_9_write;
357 switch (config->val_bits) {
359 map->format.format_write = regmap_format_10_14_write;
367 map->format.format_reg = regmap_format_8;
371 switch (reg_endian) {
372 case REGMAP_ENDIAN_BIG:
373 map->format.format_reg = regmap_format_16_be;
375 case REGMAP_ENDIAN_NATIVE:
376 map->format.format_reg = regmap_format_16_native;
384 switch (reg_endian) {
385 case REGMAP_ENDIAN_BIG:
386 map->format.format_reg = regmap_format_32_be;
388 case REGMAP_ENDIAN_NATIVE:
389 map->format.format_reg = regmap_format_32_native;
400 switch (config->val_bits) {
402 map->format.format_val = regmap_format_8;
403 map->format.parse_val = regmap_parse_8;
406 switch (val_endian) {
407 case REGMAP_ENDIAN_BIG:
408 map->format.format_val = regmap_format_16_be;
409 map->format.parse_val = regmap_parse_16_be;
411 case REGMAP_ENDIAN_NATIVE:
412 map->format.format_val = regmap_format_16_native;
413 map->format.parse_val = regmap_parse_16_native;
420 if (val_endian != REGMAP_ENDIAN_BIG)
422 map->format.format_val = regmap_format_24;
423 map->format.parse_val = regmap_parse_24;
426 switch (val_endian) {
427 case REGMAP_ENDIAN_BIG:
428 map->format.format_val = regmap_format_32_be;
429 map->format.parse_val = regmap_parse_32_be;
431 case REGMAP_ENDIAN_NATIVE:
432 map->format.format_val = regmap_format_32_native;
433 map->format.parse_val = regmap_parse_32_native;
441 if (map->format.format_write) {
442 if ((reg_endian != REGMAP_ENDIAN_BIG) ||
443 (val_endian != REGMAP_ENDIAN_BIG))
445 map->use_single_rw = true;
448 if (!map->format.format_write &&
449 !(map->format.format_reg && map->format.format_val))
452 map->work_buf = kzalloc(map->format.buf_size, GFP_KERNEL);
453 if (map->work_buf == NULL) {
458 regmap_debugfs_init(map, config->name);
460 ret = regcache_init(map, config);
462 goto err_free_workbuf;
464 /* Add a devres resource for dev_get_regmap() */
465 m = devres_alloc(dev_get_regmap_release, sizeof(*m), GFP_KERNEL);
478 kfree(map->work_buf);
484 EXPORT_SYMBOL_GPL(regmap_init);
486 static void devm_regmap_release(struct device *dev, void *res)
488 regmap_exit(*(struct regmap **)res);
492 * devm_regmap_init(): Initialise managed register map
494 * @dev: Device that will be interacted with
495 * @bus: Bus-specific callbacks to use with device
496 * @bus_context: Data passed to bus-specific callbacks
497 * @config: Configuration for register map
499 * The return value will be an ERR_PTR() on error or a valid pointer
500 * to a struct regmap. This function should generally not be called
501 * directly, it should be called by bus-specific init functions. The
502 * map will be automatically freed by the device management code.
504 struct regmap *devm_regmap_init(struct device *dev,
505 const struct regmap_bus *bus,
507 const struct regmap_config *config)
509 struct regmap **ptr, *regmap;
511 ptr = devres_alloc(devm_regmap_release, sizeof(*ptr), GFP_KERNEL);
513 return ERR_PTR(-ENOMEM);
515 regmap = regmap_init(dev, bus, bus_context, config);
516 if (!IS_ERR(regmap)) {
518 devres_add(dev, ptr);
525 EXPORT_SYMBOL_GPL(devm_regmap_init);
528 * regmap_reinit_cache(): Reinitialise the current register cache
530 * @map: Register map to operate on.
531 * @config: New configuration. Only the cache data will be used.
533 * Discard any existing register cache for the map and initialize a
534 * new cache. This can be used to restore the cache to defaults or to
535 * update the cache configuration to reflect runtime discovery of the
538 int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
545 regmap_debugfs_exit(map);
547 map->max_register = config->max_register;
548 map->writeable_reg = config->writeable_reg;
549 map->readable_reg = config->readable_reg;
550 map->volatile_reg = config->volatile_reg;
551 map->precious_reg = config->precious_reg;
552 map->cache_type = config->cache_type;
554 regmap_debugfs_init(map, config->name);
556 map->cache_bypass = false;
557 map->cache_only = false;
559 ret = regcache_init(map, config);
567 * regmap_exit(): Free a previously allocated register map
569 void regmap_exit(struct regmap *map)
572 regmap_debugfs_exit(map);
573 if (map->bus->free_context)
574 map->bus->free_context(map->bus_context);
575 kfree(map->work_buf);
578 EXPORT_SYMBOL_GPL(regmap_exit);
580 static int dev_get_regmap_match(struct device *dev, void *res, void *data)
582 struct regmap **r = res;
588 /* If the user didn't specify a name match any */
590 return (*r)->name == data;
596 * dev_get_regmap(): Obtain the regmap (if any) for a device
598 * @dev: Device to retrieve the map for
599 * @name: Optional name for the register map, usually NULL.
601 * Returns the regmap for the device if one is present, or NULL. If
602 * name is specified then it must match the name specified when
603 * registering the device, if it is NULL then the first regmap found
604 * will be used. Devices with multiple register maps are very rare,
605 * generic code should normally not need to specify a name.
607 struct regmap *dev_get_regmap(struct device *dev, const char *name)
609 struct regmap **r = devres_find(dev, dev_get_regmap_release,
610 dev_get_regmap_match, (void *)name);
616 EXPORT_SYMBOL_GPL(dev_get_regmap);
618 static int _regmap_raw_write(struct regmap *map, unsigned int reg,
619 const void *val, size_t val_len)
621 u8 *u8 = map->work_buf;
627 /* Check for unwritable registers before we start */
628 if (map->writeable_reg)
629 for (i = 0; i < val_len / map->format.val_bytes; i++)
630 if (!map->writeable_reg(map->dev,
631 reg + (i * map->reg_stride)))
634 if (!map->cache_bypass && map->format.parse_val) {
636 int val_bytes = map->format.val_bytes;
637 for (i = 0; i < val_len / val_bytes; i++) {
638 memcpy(map->work_buf, val + (i * val_bytes), val_bytes);
639 ival = map->format.parse_val(map->work_buf);
640 ret = regcache_write(map, reg + (i * map->reg_stride),
644 "Error in caching of register: %u ret: %d\n",
649 if (map->cache_only) {
650 map->cache_dirty = true;
655 map->format.format_reg(map->work_buf, reg, map->reg_shift);
657 u8[0] |= map->write_flag_mask;
659 trace_regmap_hw_write_start(map->dev, reg,
660 val_len / map->format.val_bytes);
662 /* If we're doing a single register write we can probably just
663 * send the work_buf directly, otherwise try to do a gather
666 if (val == (map->work_buf + map->format.pad_bytes +
667 map->format.reg_bytes))
668 ret = map->bus->write(map->bus_context, map->work_buf,
669 map->format.reg_bytes +
670 map->format.pad_bytes +
672 else if (map->bus->gather_write)
673 ret = map->bus->gather_write(map->bus_context, map->work_buf,
674 map->format.reg_bytes +
675 map->format.pad_bytes,
678 /* If that didn't work fall back on linearising by hand. */
679 if (ret == -ENOTSUPP) {
680 len = map->format.reg_bytes + map->format.pad_bytes + val_len;
681 buf = kzalloc(len, GFP_KERNEL);
685 memcpy(buf, map->work_buf, map->format.reg_bytes);
686 memcpy(buf + map->format.reg_bytes + map->format.pad_bytes,
688 ret = map->bus->write(map->bus_context, buf, len);
693 trace_regmap_hw_write_done(map->dev, reg,
694 val_len / map->format.val_bytes);
699 int _regmap_write(struct regmap *map, unsigned int reg,
703 BUG_ON(!map->format.format_write && !map->format.format_val);
705 if (!map->cache_bypass && map->format.format_write) {
706 ret = regcache_write(map, reg, val);
709 if (map->cache_only) {
710 map->cache_dirty = true;
716 if (strcmp(dev_name(map->dev), LOG_DEVICE) == 0)
717 dev_info(map->dev, "%x <= %x\n", reg, val);
720 trace_regmap_reg_write(map->dev, reg, val);
722 if (map->format.format_write) {
723 map->format.format_write(map, reg, val);
725 trace_regmap_hw_write_start(map->dev, reg, 1);
727 ret = map->bus->write(map->bus_context, map->work_buf,
728 map->format.buf_size);
730 trace_regmap_hw_write_done(map->dev, reg, 1);
734 map->format.format_val(map->work_buf + map->format.reg_bytes
735 + map->format.pad_bytes, val, 0);
736 return _regmap_raw_write(map, reg,
738 map->format.reg_bytes +
739 map->format.pad_bytes,
740 map->format.val_bytes);
745 * regmap_write(): Write a value to a single register
747 * @map: Register map to write to
748 * @reg: Register to write to
749 * @val: Value to be written
751 * A value of zero will be returned on success, a negative errno will
752 * be returned in error cases.
754 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val)
758 if (reg % map->reg_stride)
763 ret = _regmap_write(map, reg, val);
769 EXPORT_SYMBOL_GPL(regmap_write);
772 * regmap_raw_write(): Write raw values to one or more registers
774 * @map: Register map to write to
775 * @reg: Initial register to write to
776 * @val: Block of data to be written, laid out for direct transmission to the
778 * @val_len: Length of data pointed to by val.
780 * This function is intended to be used for things like firmware
781 * download where a large block of data needs to be transferred to the
782 * device. No formatting will be done on the data provided.
784 * A value of zero will be returned on success, a negative errno will
785 * be returned in error cases.
787 int regmap_raw_write(struct regmap *map, unsigned int reg,
788 const void *val, size_t val_len)
792 if (val_len % map->format.val_bytes)
794 if (reg % map->reg_stride)
799 ret = _regmap_raw_write(map, reg, val, val_len);
805 EXPORT_SYMBOL_GPL(regmap_raw_write);
808 * regmap_bulk_write(): Write multiple registers to the device
810 * @map: Register map to write to
811 * @reg: First register to be write from
812 * @val: Block of data to be written, in native register size for device
813 * @val_count: Number of registers to write
815 * This function is intended to be used for writing a large block of
816 * data to be device either in single transfer or multiple transfer.
818 * A value of zero will be returned on success, a negative errno will
819 * be returned in error cases.
821 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
825 size_t val_bytes = map->format.val_bytes;
828 if (!map->format.parse_val)
830 if (reg % map->reg_stride)
835 /* No formatting is require if val_byte is 1 */
836 if (val_bytes == 1) {
839 wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL);
842 dev_err(map->dev, "Error in memory allocation\n");
845 for (i = 0; i < val_count * val_bytes; i += val_bytes)
846 map->format.parse_val(wval + i);
849 * Some devices does not support bulk write, for
850 * them we have a series of single write operations.
852 if (map->use_single_rw) {
853 for (i = 0; i < val_count; i++) {
854 ret = regmap_raw_write(map,
855 reg + (i * map->reg_stride),
856 val + (i * val_bytes),
862 ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count);
872 EXPORT_SYMBOL_GPL(regmap_bulk_write);
874 static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
875 unsigned int val_len)
877 u8 *u8 = map->work_buf;
880 map->format.format_reg(map->work_buf, reg, map->reg_shift);
883 * Some buses or devices flag reads by setting the high bits in the
884 * register addresss; since it's always the high bits for all
885 * current formats we can do this here rather than in
886 * formatting. This may break if we get interesting formats.
888 u8[0] |= map->read_flag_mask;
890 trace_regmap_hw_read_start(map->dev, reg,
891 val_len / map->format.val_bytes);
893 ret = map->bus->read(map->bus_context, map->work_buf,
894 map->format.reg_bytes + map->format.pad_bytes,
897 trace_regmap_hw_read_done(map->dev, reg,
898 val_len / map->format.val_bytes);
903 static int _regmap_read(struct regmap *map, unsigned int reg,
908 if (!map->cache_bypass) {
909 ret = regcache_read(map, reg, val);
914 if (!map->format.parse_val)
920 ret = _regmap_raw_read(map, reg, map->work_buf, map->format.val_bytes);
922 *val = map->format.parse_val(map->work_buf);
925 if (strcmp(dev_name(map->dev), LOG_DEVICE) == 0)
926 dev_info(map->dev, "%x => %x\n", reg, *val);
929 trace_regmap_reg_read(map->dev, reg, *val);
932 if (ret == 0 && !map->cache_bypass)
933 regcache_write(map, reg, *val);
939 * regmap_read(): Read a value from a single register
941 * @map: Register map to write to
942 * @reg: Register to be read from
943 * @val: Pointer to store read value
945 * A value of zero will be returned on success, a negative errno will
946 * be returned in error cases.
948 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val)
952 if (reg % map->reg_stride)
957 ret = _regmap_read(map, reg, val);
963 EXPORT_SYMBOL_GPL(regmap_read);
966 * regmap_raw_read(): Read raw data from the device
968 * @map: Register map to write to
969 * @reg: First register to be read from
970 * @val: Pointer to store read value
971 * @val_len: Size of data to read
973 * A value of zero will be returned on success, a negative errno will
974 * be returned in error cases.
976 int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
979 size_t val_bytes = map->format.val_bytes;
980 size_t val_count = val_len / val_bytes;
984 if (val_len % map->format.val_bytes)
986 if (reg % map->reg_stride)
991 if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass ||
992 map->cache_type == REGCACHE_NONE) {
993 /* Physical block read if there's no cache involved */
994 ret = _regmap_raw_read(map, reg, val, val_len);
997 /* Otherwise go word by word for the cache; should be low
998 * cost as we expect to hit the cache.
1000 for (i = 0; i < val_count; i++) {
1001 ret = _regmap_read(map, reg + (i * map->reg_stride),
1006 map->format.format_val(val + (i * val_bytes), v, 0);
1015 EXPORT_SYMBOL_GPL(regmap_raw_read);
1018 * regmap_bulk_read(): Read multiple registers from the device
1020 * @map: Register map to write to
1021 * @reg: First register to be read from
1022 * @val: Pointer to store read value, in native register size for device
1023 * @val_count: Number of registers to read
1025 * A value of zero will be returned on success, a negative errno will
1026 * be returned in error cases.
1028 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
1032 size_t val_bytes = map->format.val_bytes;
1033 bool vol = regmap_volatile_range(map, reg, val_count);
1035 if (!map->format.parse_val)
1037 if (reg % map->reg_stride)
1040 if (vol || map->cache_type == REGCACHE_NONE) {
1042 * Some devices does not support bulk read, for
1043 * them we have a series of single read operations.
1045 if (map->use_single_rw) {
1046 for (i = 0; i < val_count; i++) {
1047 ret = regmap_raw_read(map,
1048 reg + (i * map->reg_stride),
1049 val + (i * val_bytes),
1055 ret = regmap_raw_read(map, reg, val,
1056 val_bytes * val_count);
1061 for (i = 0; i < val_count * val_bytes; i += val_bytes)
1062 map->format.parse_val(val + i);
1064 for (i = 0; i < val_count; i++) {
1066 ret = regmap_read(map, reg + (i * map->reg_stride),
1070 memcpy(val + (i * val_bytes), &ival, val_bytes);
1076 EXPORT_SYMBOL_GPL(regmap_bulk_read);
1078 static int _regmap_update_bits(struct regmap *map, unsigned int reg,
1079 unsigned int mask, unsigned int val,
1083 unsigned int tmp, orig;
1087 ret = _regmap_read(map, reg, &orig);
1095 ret = _regmap_write(map, reg, tmp);
1108 * regmap_update_bits: Perform a read/modify/write cycle on the register map
1110 * @map: Register map to update
1111 * @reg: Register to update
1112 * @mask: Bitmask to change
1113 * @val: New value for bitmask
1115 * Returns zero for success, a negative number on error.
1117 int regmap_update_bits(struct regmap *map, unsigned int reg,
1118 unsigned int mask, unsigned int val)
1121 return _regmap_update_bits(map, reg, mask, val, &change);
1123 EXPORT_SYMBOL_GPL(regmap_update_bits);
1126 * regmap_update_bits_check: Perform a read/modify/write cycle on the
1127 * register map and report if updated
1129 * @map: Register map to update
1130 * @reg: Register to update
1131 * @mask: Bitmask to change
1132 * @val: New value for bitmask
1133 * @change: Boolean indicating if a write was done
1135 * Returns zero for success, a negative number on error.
1137 int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1138 unsigned int mask, unsigned int val,
1141 return _regmap_update_bits(map, reg, mask, val, change);
1143 EXPORT_SYMBOL_GPL(regmap_update_bits_check);
1146 * regmap_register_patch: Register and apply register updates to be applied
1147 * on device initialistion
1149 * @map: Register map to apply updates to.
1150 * @regs: Values to update.
1151 * @num_regs: Number of entries in regs.
1153 * Register a set of register updates to be applied to the device
1154 * whenever the device registers are synchronised with the cache and
1155 * apply them immediately. Typically this is used to apply
1156 * corrections to be applied to the device defaults on startup, such
1157 * as the updates some vendors provide to undocumented registers.
1159 int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
1165 /* If needed the implementation can be extended to support this */
1171 bypass = map->cache_bypass;
1173 map->cache_bypass = true;
1175 /* Write out first; it's useful to apply even if we fail later. */
1176 for (i = 0; i < num_regs; i++) {
1177 ret = _regmap_write(map, regs[i].reg, regs[i].def);
1179 dev_err(map->dev, "Failed to write %x = %x: %d\n",
1180 regs[i].reg, regs[i].def, ret);
1185 map->patch = kcalloc(num_regs, sizeof(struct reg_default), GFP_KERNEL);
1186 if (map->patch != NULL) {
1187 memcpy(map->patch, regs,
1188 num_regs * sizeof(struct reg_default));
1189 map->patch_regs = num_regs;
1195 map->cache_bypass = bypass;
1201 EXPORT_SYMBOL_GPL(regmap_register_patch);
1204 * regmap_get_val_bytes(): Report the size of a register value
1206 * Report the size of a register value, mainly intended to for use by
1207 * generic infrastructure built on top of regmap.
1209 int regmap_get_val_bytes(struct regmap *map)
1211 if (map->format.format_write)
1214 return map->format.val_bytes;
1216 EXPORT_SYMBOL_GPL(regmap_get_val_bytes);
1218 static int __init regmap_initcall(void)
1220 regmap_debugfs_initcall();
1224 postcore_initcall(regmap_initcall);