Lines Matching full:map

3 // Register map access API
36 static inline bool regmap_should_log(struct regmap *map) in regmap_should_log() argument
38 return (map->dev && strcmp(dev_name(map->dev), LOG_DEVICE) == 0); in regmap_should_log()
41 static inline bool regmap_should_log(struct regmap *map) { return false; } in regmap_should_log() argument
45 static int _regmap_update_bits(struct regmap *map, unsigned int reg,
74 bool regmap_check_range_table(struct regmap *map, unsigned int reg, in regmap_check_range_table() argument
90 bool regmap_writeable(struct regmap *map, unsigned int reg) in regmap_writeable() argument
92 if (map->max_register && reg > map->max_register) in regmap_writeable()
95 if (map->writeable_reg) in regmap_writeable()
96 return map->writeable_reg(map->dev, reg); in regmap_writeable()
98 if (map->wr_table) in regmap_writeable()
99 return regmap_check_range_table(map, reg, map->wr_table); in regmap_writeable()
104 bool regmap_cached(struct regmap *map, unsigned int reg) in regmap_cached() argument
109 if (map->cache_type == REGCACHE_NONE) in regmap_cached()
112 if (!map->cache_ops) in regmap_cached()
115 if (map->max_register && reg > map->max_register) in regmap_cached()
118 map->lock(map->lock_arg); in regmap_cached()
119 ret = regcache_read(map, reg, &val); in regmap_cached()
120 map->unlock(map->lock_arg); in regmap_cached()
127 bool regmap_readable(struct regmap *map, unsigned int reg) in regmap_readable() argument
129 if (!map->reg_read) in regmap_readable()
132 if (map->max_register && reg > map->max_register) in regmap_readable()
135 if (map->format.format_write) in regmap_readable()
138 if (map->readable_reg) in regmap_readable()
139 return map->readable_reg(map->dev, reg); in regmap_readable()
141 if (map->rd_table) in regmap_readable()
142 return regmap_check_range_table(map, reg, map->rd_table); in regmap_readable()
147 bool regmap_volatile(struct regmap *map, unsigned int reg) in regmap_volatile() argument
149 if (!map->format.format_write && !regmap_readable(map, reg)) in regmap_volatile()
152 if (map->volatile_reg) in regmap_volatile()
153 return map->volatile_reg(map->dev, reg); in regmap_volatile()
155 if (map->volatile_table) in regmap_volatile()
156 return regmap_check_range_table(map, reg, map->volatile_table); in regmap_volatile()
158 if (map->cache_ops) in regmap_volatile()
164 bool regmap_precious(struct regmap *map, unsigned int reg) in regmap_precious() argument
166 if (!regmap_readable(map, reg)) in regmap_precious()
169 if (map->precious_reg) in regmap_precious()
170 return map->precious_reg(map->dev, reg); in regmap_precious()
172 if (map->precious_table) in regmap_precious()
173 return regmap_check_range_table(map, reg, map->precious_table); in regmap_precious()
178 bool regmap_writeable_noinc(struct regmap *map, unsigned int reg) in regmap_writeable_noinc() argument
180 if (map->writeable_noinc_reg) in regmap_writeable_noinc()
181 return map->writeable_noinc_reg(map->dev, reg); in regmap_writeable_noinc()
183 if (map->wr_noinc_table) in regmap_writeable_noinc()
184 return regmap_check_range_table(map, reg, map->wr_noinc_table); in regmap_writeable_noinc()
189 bool regmap_readable_noinc(struct regmap *map, unsigned int reg) in regmap_readable_noinc() argument
191 if (map->readable_noinc_reg) in regmap_readable_noinc()
192 return map->readable_noinc_reg(map->dev, reg); in regmap_readable_noinc()
194 if (map->rd_noinc_table) in regmap_readable_noinc()
195 return regmap_check_range_table(map, reg, map->rd_noinc_table); in regmap_readable_noinc()
200 static bool regmap_volatile_range(struct regmap *map, unsigned int reg, in regmap_volatile_range() argument
206 if (!regmap_volatile(map, reg + regmap_get_offset(map, i))) in regmap_volatile_range()
212 static void regmap_format_12_20_write(struct regmap *map, in regmap_format_12_20_write() argument
215 u8 *out = map->work_buf; in regmap_format_12_20_write()
224 static void regmap_format_2_6_write(struct regmap *map, in regmap_format_2_6_write() argument
227 u8 *out = map->work_buf; in regmap_format_2_6_write()
232 static void regmap_format_4_12_write(struct regmap *map, in regmap_format_4_12_write() argument
235 __be16 *out = map->work_buf; in regmap_format_4_12_write()
239 static void regmap_format_7_9_write(struct regmap *map, in regmap_format_7_9_write() argument
242 __be16 *out = map->work_buf; in regmap_format_7_9_write()
246 static void regmap_format_7_17_write(struct regmap *map, in regmap_format_7_17_write() argument
249 u8 *out = map->work_buf; in regmap_format_7_17_write()
256 static void regmap_format_10_14_write(struct regmap *map, in regmap_format_10_14_write() argument
259 u8 *out = map->work_buf; in regmap_format_10_14_write()
450 struct regmap *map = __map; in regmap_lock_hwlock() local
452 hwspin_lock_timeout(map->hwlock, UINT_MAX); in regmap_lock_hwlock()
457 struct regmap *map = __map; in regmap_lock_hwlock_irq() local
459 hwspin_lock_timeout_irq(map->hwlock, UINT_MAX); in regmap_lock_hwlock_irq()
464 struct regmap *map = __map; in regmap_lock_hwlock_irqsave() local
466 hwspin_lock_timeout_irqsave(map->hwlock, UINT_MAX, in regmap_lock_hwlock_irqsave()
467 &map->spinlock_flags); in regmap_lock_hwlock_irqsave()
472 struct regmap *map = __map; in regmap_unlock_hwlock() local
474 hwspin_unlock(map->hwlock); in regmap_unlock_hwlock()
479 struct regmap *map = __map; in regmap_unlock_hwlock_irq() local
481 hwspin_unlock_irq(map->hwlock); in regmap_unlock_hwlock_irq()
486 struct regmap *map = __map; in regmap_unlock_hwlock_irqrestore() local
488 hwspin_unlock_irqrestore(map->hwlock, &map->spinlock_flags); in regmap_unlock_hwlock_irqrestore()
498 struct regmap *map = __map; in regmap_lock_mutex() local
499 mutex_lock(&map->mutex); in regmap_lock_mutex()
504 struct regmap *map = __map; in regmap_unlock_mutex() local
505 mutex_unlock(&map->mutex); in regmap_unlock_mutex()
509 __acquires(&map->spinlock) in regmap_lock_spinlock()
511 struct regmap *map = __map; in regmap_lock_spinlock() local
514 spin_lock_irqsave(&map->spinlock, flags); in regmap_lock_spinlock()
515 map->spinlock_flags = flags; in regmap_lock_spinlock()
519 __releases(&map->spinlock) in regmap_unlock_spinlock()
521 struct regmap *map = __map; in regmap_unlock_spinlock() local
522 spin_unlock_irqrestore(&map->spinlock, map->spinlock_flags); in regmap_unlock_spinlock()
526 __acquires(&map->raw_spinlock) in regmap_lock_raw_spinlock()
528 struct regmap *map = __map; in regmap_lock_raw_spinlock() local
531 raw_spin_lock_irqsave(&map->raw_spinlock, flags); in regmap_lock_raw_spinlock()
532 map->raw_spinlock_flags = flags; in regmap_lock_raw_spinlock()
536 __releases(&map->raw_spinlock) in regmap_unlock_raw_spinlock()
538 struct regmap *map = __map; in regmap_unlock_raw_spinlock() local
539 raw_spin_unlock_irqrestore(&map->raw_spinlock, map->raw_spinlock_flags); in regmap_unlock_raw_spinlock()
551 static bool _regmap_range_add(struct regmap *map, in _regmap_range_add() argument
554 struct rb_root *root = &map->range_tree; in _regmap_range_add()
576 static struct regmap_range_node *_regmap_range_lookup(struct regmap *map, in _regmap_range_lookup() argument
579 struct rb_node *node = map->range_tree.rb_node; in _regmap_range_lookup()
596 static void regmap_range_exit(struct regmap *map) in regmap_range_exit() argument
601 next = rb_first(&map->range_tree); in regmap_range_exit()
605 rb_erase(&range_node->node, &map->range_tree); in regmap_range_exit()
609 kfree(map->selector_work_buf); in regmap_range_exit()
612 static int regmap_set_name(struct regmap *map, const struct regmap_config *config) in regmap_set_name() argument
620 kfree_const(map->name); in regmap_set_name()
621 map->name = name; in regmap_set_name()
627 int regmap_attach_dev(struct device *dev, struct regmap *map, in regmap_attach_dev() argument
633 map->dev = dev; in regmap_attach_dev()
635 ret = regmap_set_name(map, config); in regmap_attach_dev()
639 regmap_debugfs_exit(map); in regmap_attach_dev()
640 regmap_debugfs_init(map); in regmap_attach_dev()
645 regmap_debugfs_exit(map); in regmap_attach_dev()
648 *m = map; in regmap_attach_dev()
725 struct regmap *map; in __regmap_init() local
733 map = kzalloc(sizeof(*map), GFP_KERNEL); in __regmap_init()
734 if (map == NULL) { in __regmap_init()
739 ret = regmap_set_name(map, config); in __regmap_init()
746 map->lock = map->unlock = regmap_lock_unlock_none; in __regmap_init()
747 map->can_sleep = config->can_sleep; in __regmap_init()
748 regmap_debugfs_disable(map); in __regmap_init()
750 map->lock = config->lock; in __regmap_init()
751 map->unlock = config->unlock; in __regmap_init()
752 map->lock_arg = config->lock_arg; in __regmap_init()
753 map->can_sleep = config->can_sleep; in __regmap_init()
755 map->hwlock = hwspin_lock_request_specific(config->hwlock_id); in __regmap_init()
756 if (!map->hwlock) { in __regmap_init()
763 map->lock = regmap_lock_hwlock_irqsave; in __regmap_init()
764 map->unlock = regmap_unlock_hwlock_irqrestore; in __regmap_init()
767 map->lock = regmap_lock_hwlock_irq; in __regmap_init()
768 map->unlock = regmap_unlock_hwlock_irq; in __regmap_init()
771 map->lock = regmap_lock_hwlock; in __regmap_init()
772 map->unlock = regmap_unlock_hwlock; in __regmap_init()
776 map->lock_arg = map; in __regmap_init()
781 raw_spin_lock_init(&map->raw_spinlock); in __regmap_init()
782 map->lock = regmap_lock_raw_spinlock; in __regmap_init()
783 map->unlock = regmap_unlock_raw_spinlock; in __regmap_init()
784 lockdep_set_class_and_name(&map->raw_spinlock, in __regmap_init()
787 spin_lock_init(&map->spinlock); in __regmap_init()
788 map->lock = regmap_lock_spinlock; in __regmap_init()
789 map->unlock = regmap_unlock_spinlock; in __regmap_init()
790 lockdep_set_class_and_name(&map->spinlock, in __regmap_init()
794 mutex_init(&map->mutex); in __regmap_init()
795 map->lock = regmap_lock_mutex; in __regmap_init()
796 map->unlock = regmap_unlock_mutex; in __regmap_init()
797 map->can_sleep = true; in __regmap_init()
798 lockdep_set_class_and_name(&map->mutex, in __regmap_init()
801 map->lock_arg = map; in __regmap_init()
809 map->alloc_flags = GFP_ATOMIC; in __regmap_init()
811 map->alloc_flags = GFP_KERNEL; in __regmap_init()
813 map->reg_base = config->reg_base; in __regmap_init()
815 map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8); in __regmap_init()
816 map->format.pad_bytes = config->pad_bits / 8; in __regmap_init()
817 map->format.reg_downshift = config->reg_downshift; in __regmap_init()
818 map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8); in __regmap_init()
819 map->format.buf_size = DIV_ROUND_UP(config->reg_bits + in __regmap_init()
821 map->reg_shift = config->pad_bits % 8; in __regmap_init()
823 map->reg_stride = config->reg_stride; in __regmap_init()
825 map->reg_stride = 1; in __regmap_init()
826 if (is_power_of_2(map->reg_stride)) in __regmap_init()
827 map->reg_stride_order = ilog2(map->reg_stride); in __regmap_init()
829 map->reg_stride_order = -1; in __regmap_init()
830 map->use_single_read = config->use_single_read || !(config->read || (bus && bus->read)); in __regmap_init()
831 map->use_single_write = config->use_single_write || !(config->write || (bus && bus->write)); in __regmap_init()
832 map->can_multi_write = config->can_multi_write && (config->write || (bus && bus->write)); in __regmap_init()
834 map->max_raw_read = bus->max_raw_read; in __regmap_init()
835 map->max_raw_write = bus->max_raw_write; in __regmap_init()
837 map->max_raw_read = config->max_raw_read; in __regmap_init()
838 map->max_raw_write = config->max_raw_write; in __regmap_init()
840 map->dev = dev; in __regmap_init()
841 map->bus = bus; in __regmap_init()
842 map->bus_context = bus_context; in __regmap_init()
843 map->max_register = config->max_register; in __regmap_init()
844 map->wr_table = config->wr_table; in __regmap_init()
845 map->rd_table = config->rd_table; in __regmap_init()
846 map->volatile_table = config->volatile_table; in __regmap_init()
847 map->precious_table = config->precious_table; in __regmap_init()
848 map->wr_noinc_table = config->wr_noinc_table; in __regmap_init()
849 map->rd_noinc_table = config->rd_noinc_table; in __regmap_init()
850 map->writeable_reg = config->writeable_reg; in __regmap_init()
851 map->readable_reg = config->readable_reg; in __regmap_init()
852 map->volatile_reg = config->volatile_reg; in __regmap_init()
853 map->precious_reg = config->precious_reg; in __regmap_init()
854 map->writeable_noinc_reg = config->writeable_noinc_reg; in __regmap_init()
855 map->readable_noinc_reg = config->readable_noinc_reg; in __regmap_init()
856 map->cache_type = config->cache_type; in __regmap_init()
858 spin_lock_init(&map->async_lock); in __regmap_init()
859 INIT_LIST_HEAD(&map->async_list); in __regmap_init()
860 INIT_LIST_HEAD(&map->async_free); in __regmap_init()
861 init_waitqueue_head(&map->async_waitq); in __regmap_init()
866 map->read_flag_mask = config->read_flag_mask; in __regmap_init()
867 map->write_flag_mask = config->write_flag_mask; in __regmap_init()
869 map->read_flag_mask = bus->read_flag_mask; in __regmap_init()
873 map->reg_read = _regmap_bus_read; in __regmap_init()
875 map->reg_update_bits = config->reg_update_bits; in __regmap_init()
878 map->read = config->read; in __regmap_init()
879 map->write = config->write; in __regmap_init()
884 map->reg_read = config->reg_read; in __regmap_init()
885 map->reg_write = config->reg_write; in __regmap_init()
886 map->reg_update_bits = config->reg_update_bits; in __regmap_init()
888 map->defer_caching = false; in __regmap_init()
891 map->reg_read = _regmap_bus_reg_read; in __regmap_init()
892 map->reg_write = _regmap_bus_reg_write; in __regmap_init()
893 map->reg_update_bits = bus->reg_update_bits; in __regmap_init()
895 map->defer_caching = false; in __regmap_init()
898 map->reg_read = _regmap_bus_read; in __regmap_init()
899 map->reg_update_bits = bus->reg_update_bits; in __regmap_init()
901 map->read = bus->read; in __regmap_init()
902 map->write = bus->write; in __regmap_init()
908 switch (config->reg_bits + map->reg_shift) { in __regmap_init()
912 map->format.format_write = regmap_format_2_6_write; in __regmap_init()
922 map->format.format_write = regmap_format_4_12_write; in __regmap_init()
932 map->format.format_write = regmap_format_7_9_write; in __regmap_init()
935 map->format.format_write = regmap_format_7_17_write; in __regmap_init()
945 map->format.format_write = regmap_format_10_14_write; in __regmap_init()
955 map->format.format_write = regmap_format_12_20_write; in __regmap_init()
963 map->format.format_reg = regmap_format_8; in __regmap_init()
969 map->format.format_reg = regmap_format_16_be; in __regmap_init()
972 map->format.format_reg = regmap_format_16_le; in __regmap_init()
975 map->format.format_reg = regmap_format_16_native; in __regmap_init()
985 map->format.format_reg = regmap_format_24_be; in __regmap_init()
995 map->format.format_reg = regmap_format_32_be; in __regmap_init()
998 map->format.format_reg = regmap_format_32_le; in __regmap_init()
1001 map->format.format_reg = regmap_format_32_native; in __regmap_init()
1012 map->format.format_reg = regmap_format_64_be; in __regmap_init()
1015 map->format.format_reg = regmap_format_64_le; in __regmap_init()
1018 map->format.format_reg = regmap_format_64_native; in __regmap_init()
1031 map->format.parse_inplace = regmap_parse_inplace_noop; in __regmap_init()
1035 map->format.format_val = regmap_format_8; in __regmap_init()
1036 map->format.parse_val = regmap_parse_8; in __regmap_init()
1037 map->format.parse_inplace = regmap_parse_inplace_noop; in __regmap_init()
1042 map->format.format_val = regmap_format_16_be; in __regmap_init()
1043 map->format.parse_val = regmap_parse_16_be; in __regmap_init()
1044 map->format.parse_inplace = regmap_parse_16_be_inplace; in __regmap_init()
1047 map->format.format_val = regmap_format_16_le; in __regmap_init()
1048 map->format.parse_val = regmap_parse_16_le; in __regmap_init()
1049 map->format.parse_inplace = regmap_parse_16_le_inplace; in __regmap_init()
1052 map->format.format_val = regmap_format_16_native; in __regmap_init()
1053 map->format.parse_val = regmap_parse_16_native; in __regmap_init()
1062 map->format.format_val = regmap_format_24_be; in __regmap_init()
1063 map->format.parse_val = regmap_parse_24_be; in __regmap_init()
1072 map->format.format_val = regmap_format_32_be; in __regmap_init()
1073 map->format.parse_val = regmap_parse_32_be; in __regmap_init()
1074 map->format.parse_inplace = regmap_parse_32_be_inplace; in __regmap_init()
1077 map->format.format_val = regmap_format_32_le; in __regmap_init()
1078 map->format.parse_val = regmap_parse_32_le; in __regmap_init()
1079 map->format.parse_inplace = regmap_parse_32_le_inplace; in __regmap_init()
1082 map->format.format_val = regmap_format_32_native; in __regmap_init()
1083 map->format.parse_val = regmap_parse_32_native; in __regmap_init()
1093 map->format.format_val = regmap_format_64_be; in __regmap_init()
1094 map->format.parse_val = regmap_parse_64_be; in __regmap_init()
1095 map->format.parse_inplace = regmap_parse_64_be_inplace; in __regmap_init()
1098 map->format.format_val = regmap_format_64_le; in __regmap_init()
1099 map->format.parse_val = regmap_parse_64_le; in __regmap_init()
1100 map->format.parse_inplace = regmap_parse_64_le_inplace; in __regmap_init()
1103 map->format.format_val = regmap_format_64_native; in __regmap_init()
1104 map->format.parse_val = regmap_parse_64_native; in __regmap_init()
1113 if (map->format.format_write) { in __regmap_init()
1117 map->use_single_write = true; in __regmap_init()
1120 if (!map->format.format_write && in __regmap_init()
1121 !(map->format.format_reg && map->format.format_val)) in __regmap_init()
1124 map->work_buf = kzalloc(map->format.buf_size, GFP_KERNEL); in __regmap_init()
1125 if (map->work_buf == NULL) { in __regmap_init()
1130 if (map->format.format_write) { in __regmap_init()
1131 map->defer_caching = false; in __regmap_init()
1132 map->reg_write = _regmap_bus_formatted_write; in __regmap_init()
1133 } else if (map->format.format_val) { in __regmap_init()
1134 map->defer_caching = true; in __regmap_init()
1135 map->reg_write = _regmap_bus_raw_write; in __regmap_init()
1140 map->range_tree = RB_ROOT; in __regmap_init()
1147 dev_err(map->dev, "Invalid range %d: %d < %d\n", i, in __regmap_init()
1152 if (range_cfg->range_max > map->max_register) { in __regmap_init()
1153 dev_err(map->dev, "Invalid range %d: %d > %d\n", i, in __regmap_init()
1154 range_cfg->range_max, map->max_register); in __regmap_init()
1158 if (range_cfg->selector_reg > map->max_register) { in __regmap_init()
1159 dev_err(map->dev, in __regmap_init()
1160 "Invalid range %d: selector out of map\n", i); in __regmap_init()
1165 dev_err(map->dev, "Invalid range %d: window_len 0\n", in __regmap_init()
1184 dev_err(map->dev, in __regmap_init()
1192 dev_err(map->dev, in __regmap_init()
1205 new->map = map; in __regmap_init()
1215 if (!_regmap_range_add(map, new)) { in __regmap_init()
1216 dev_err(map->dev, "Failed to add range %d\n", i); in __regmap_init()
1221 if (map->selector_work_buf == NULL) { in __regmap_init()
1222 map->selector_work_buf = in __regmap_init()
1223 kzalloc(map->format.buf_size, GFP_KERNEL); in __regmap_init()
1224 if (map->selector_work_buf == NULL) { in __regmap_init()
1231 ret = regcache_init(map, config); in __regmap_init()
1236 ret = regmap_attach_dev(dev, map, config); in __regmap_init()
1240 regmap_debugfs_init(map); in __regmap_init()
1243 return map; in __regmap_init()
1246 regcache_exit(map); in __regmap_init()
1248 regmap_range_exit(map); in __regmap_init()
1249 kfree(map->work_buf); in __regmap_init()
1251 if (map->hwlock) in __regmap_init()
1252 hwspin_lock_free(map->hwlock); in __regmap_init()
1254 kfree_const(map->name); in __regmap_init()
1256 kfree(map); in __regmap_init()
1490 * @map: Register map to operate on.
1493 * Discard any existing register cache for the map and initialize a
1501 int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) in regmap_reinit_cache() argument
1505 regcache_exit(map); in regmap_reinit_cache()
1506 regmap_debugfs_exit(map); in regmap_reinit_cache()
1508 map->max_register = config->max_register; in regmap_reinit_cache()
1509 map->writeable_reg = config->writeable_reg; in regmap_reinit_cache()
1510 map->readable_reg = config->readable_reg; in regmap_reinit_cache()
1511 map->volatile_reg = config->volatile_reg; in regmap_reinit_cache()
1512 map->precious_reg = config->precious_reg; in regmap_reinit_cache()
1513 map->writeable_noinc_reg = config->writeable_noinc_reg; in regmap_reinit_cache()
1514 map->readable_noinc_reg = config->readable_noinc_reg; in regmap_reinit_cache()
1515 map->cache_type = config->cache_type; in regmap_reinit_cache()
1517 ret = regmap_set_name(map, config); in regmap_reinit_cache()
1521 regmap_debugfs_init(map); in regmap_reinit_cache()
1523 map->cache_bypass = false; in regmap_reinit_cache()
1524 map->cache_only = false; in regmap_reinit_cache()
1526 return regcache_init(map, config); in regmap_reinit_cache()
1531 * regmap_exit() - Free a previously allocated register map
1533 * @map: Register map to operate on.
1535 void regmap_exit(struct regmap *map) in regmap_exit() argument
1539 regcache_exit(map); in regmap_exit()
1540 regmap_debugfs_exit(map); in regmap_exit()
1541 regmap_range_exit(map); in regmap_exit()
1542 if (map->bus && map->bus->free_context) in regmap_exit()
1543 map->bus->free_context(map->bus_context); in regmap_exit()
1544 kfree(map->work_buf); in regmap_exit()
1545 while (!list_empty(&map->async_free)) { in regmap_exit()
1546 async = list_first_entry_or_null(&map->async_free, in regmap_exit()
1553 if (map->hwlock) in regmap_exit()
1554 hwspin_lock_free(map->hwlock); in regmap_exit()
1555 if (map->lock == regmap_lock_mutex) in regmap_exit()
1556 mutex_destroy(&map->mutex); in regmap_exit()
1557 kfree_const(map->name); in regmap_exit()
1558 kfree(map->patch); in regmap_exit()
1559 if (map->bus && map->bus->free_on_exit) in regmap_exit()
1560 kfree(map->bus); in regmap_exit()
1561 kfree(map); in regmap_exit()
1583 * @dev: Device to retrieve the map for
1584 * @name: Optional name for the register map, usually NULL.
1606 * @map: Register map to operate on.
1610 struct device *regmap_get_device(struct regmap *map) in regmap_get_device() argument
1612 return map->dev; in regmap_get_device()
1616 static int _regmap_select_page(struct regmap *map, unsigned int *reg, in _regmap_select_page() argument
1645 orig_work_buf = map->work_buf; in _regmap_select_page()
1646 map->work_buf = map->selector_work_buf; in _regmap_select_page()
1648 ret = _regmap_update_bits(map, range->selector_reg, in _regmap_select_page()
1653 map->work_buf = orig_work_buf; in _regmap_select_page()
1664 static void regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes, in regmap_set_work_buf_flag_mask() argument
1670 if (!mask || !map->work_buf) in regmap_set_work_buf_flag_mask()
1673 buf = map->work_buf; in regmap_set_work_buf_flag_mask()
1679 static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg, in _regmap_raw_write_impl() argument
1684 void *work_val = map->work_buf + map->format.reg_bytes + in _regmap_raw_write_impl()
1685 map->format.pad_bytes; in _regmap_raw_write_impl()
1694 if (!regmap_writeable_noinc(map, reg)) { in _regmap_raw_write_impl()
1695 for (i = 0; i < val_len / map->format.val_bytes; i++) { in _regmap_raw_write_impl()
1697 reg + regmap_get_offset(map, i); in _regmap_raw_write_impl()
1698 if (!regmap_writeable(map, element) || in _regmap_raw_write_impl()
1699 regmap_writeable_noinc(map, element)) in _regmap_raw_write_impl()
1704 if (!map->cache_bypass && map->format.parse_val) { in _regmap_raw_write_impl()
1706 int val_bytes = map->format.val_bytes; in _regmap_raw_write_impl()
1708 ival = map->format.parse_val(val + (i * val_bytes)); in _regmap_raw_write_impl()
1709 ret = regcache_write(map, in _regmap_raw_write_impl()
1710 reg + regmap_get_offset(map, i), in _regmap_raw_write_impl()
1713 dev_err(map->dev, in _regmap_raw_write_impl()
1715 reg + regmap_get_offset(map, i), ret); in _regmap_raw_write_impl()
1719 if (map->cache_only) { in _regmap_raw_write_impl()
1720 map->cache_dirty = true; in _regmap_raw_write_impl()
1725 range = _regmap_range_lookup(map, reg); in _regmap_raw_write_impl()
1727 int val_num = val_len / map->format.val_bytes; in _regmap_raw_write_impl()
1733 dev_dbg(map->dev, "Writing window %d/%zu\n", in _regmap_raw_write_impl()
1734 win_residue, val_len / map->format.val_bytes); in _regmap_raw_write_impl()
1735 ret = _regmap_raw_write_impl(map, reg, val, in _regmap_raw_write_impl()
1737 map->format.val_bytes, noinc); in _regmap_raw_write_impl()
1743 val += win_residue * map->format.val_bytes; in _regmap_raw_write_impl()
1744 val_len -= win_residue * map->format.val_bytes; in _regmap_raw_write_impl()
1751 ret = _regmap_select_page(map, &reg, range, noinc ? 1 : val_num); in _regmap_raw_write_impl()
1756 reg += map->reg_base; in _regmap_raw_write_impl()
1757 reg >>= map->format.reg_downshift; in _regmap_raw_write_impl()
1758 map->format.format_reg(map->work_buf, reg, map->reg_shift); in _regmap_raw_write_impl()
1759 regmap_set_work_buf_flag_mask(map, map->format.reg_bytes, in _regmap_raw_write_impl()
1760 map->write_flag_mask); in _regmap_raw_write_impl()
1767 if (val != work_val && val_len == map->format.val_bytes) { in _regmap_raw_write_impl()
1768 memcpy(work_val, val, map->format.val_bytes); in _regmap_raw_write_impl()
1772 if (map->async && map->bus && map->bus->async_write) { in _regmap_raw_write_impl()
1775 trace_regmap_async_write_start(map, reg, val_len); in _regmap_raw_write_impl()
1777 spin_lock_irqsave(&map->async_lock, flags); in _regmap_raw_write_impl()
1778 async = list_first_entry_or_null(&map->async_free, in _regmap_raw_write_impl()
1783 spin_unlock_irqrestore(&map->async_lock, flags); in _regmap_raw_write_impl()
1786 async = map->bus->async_alloc(); in _regmap_raw_write_impl()
1790 async->work_buf = kzalloc(map->format.buf_size, in _regmap_raw_write_impl()
1798 async->map = map; in _regmap_raw_write_impl()
1801 memcpy(async->work_buf, map->work_buf, map->format.pad_bytes + in _regmap_raw_write_impl()
1802 map->format.reg_bytes + map->format.val_bytes); in _regmap_raw_write_impl()
1804 spin_lock_irqsave(&map->async_lock, flags); in _regmap_raw_write_impl()
1805 list_add_tail(&async->list, &map->async_list); in _regmap_raw_write_impl()
1806 spin_unlock_irqrestore(&map->async_lock, flags); in _regmap_raw_write_impl()
1809 ret = map->bus->async_write(map->bus_context, in _regmap_raw_write_impl()
1811 map->format.reg_bytes + in _regmap_raw_write_impl()
1812 map->format.pad_bytes, in _regmap_raw_write_impl()
1815 ret = map->bus->async_write(map->bus_context, in _regmap_raw_write_impl()
1817 map->format.reg_bytes + in _regmap_raw_write_impl()
1818 map->format.pad_bytes + in _regmap_raw_write_impl()
1822 dev_err(map->dev, "Failed to schedule write: %d\n", in _regmap_raw_write_impl()
1825 spin_lock_irqsave(&map->async_lock, flags); in _regmap_raw_write_impl()
1826 list_move(&async->list, &map->async_free); in _regmap_raw_write_impl()
1827 spin_unlock_irqrestore(&map->async_lock, flags); in _regmap_raw_write_impl()
1833 trace_regmap_hw_write_start(map, reg, val_len / map->format.val_bytes); in _regmap_raw_write_impl()
1840 ret = map->write(map->bus_context, map->work_buf, in _regmap_raw_write_impl()
1841 map->format.reg_bytes + in _regmap_raw_write_impl()
1842 map->format.pad_bytes + in _regmap_raw_write_impl()
1844 else if (map->bus && map->bus->gather_write) in _regmap_raw_write_impl()
1845 ret = map->bus->gather_write(map->bus_context, map->work_buf, in _regmap_raw_write_impl()
1846 map->format.reg_bytes + in _regmap_raw_write_impl()
1847 map->format.pad_bytes, in _regmap_raw_write_impl()
1854 len = map->format.reg_bytes + map->format.pad_bytes + val_len; in _regmap_raw_write_impl()
1859 memcpy(buf, map->work_buf, map->format.reg_bytes); in _regmap_raw_write_impl()
1860 memcpy(buf + map->format.reg_bytes + map->format.pad_bytes, in _regmap_raw_write_impl()
1862 ret = map->write(map->bus_context, buf, len); in _regmap_raw_write_impl()
1865 } else if (ret != 0 && !map->cache_bypass && map->format.parse_val) { in _regmap_raw_write_impl()
1867 * thus call map->cache_ops->drop() directly in _regmap_raw_write_impl()
1869 if (map->cache_ops && map->cache_ops->drop) in _regmap_raw_write_impl()
1870 map->cache_ops->drop(map, reg, reg + 1); in _regmap_raw_write_impl()
1873 trace_regmap_hw_write_done(map, reg, val_len / map->format.val_bytes); in _regmap_raw_write_impl()
1881 * @map: Map to check.
1883 bool regmap_can_raw_write(struct regmap *map) in regmap_can_raw_write() argument
1885 return map->write && map->format.format_val && map->format.format_reg; in regmap_can_raw_write()
1892 * @map: Map to check.
1894 size_t regmap_get_raw_read_max(struct regmap *map) in regmap_get_raw_read_max() argument
1896 return map->max_raw_read; in regmap_get_raw_read_max()
1903 * @map: Map to check.
1905 size_t regmap_get_raw_write_max(struct regmap *map) in regmap_get_raw_write_max() argument
1907 return map->max_raw_write; in regmap_get_raw_write_max()
1916 struct regmap *map = context; in _regmap_bus_formatted_write() local
1918 WARN_ON(!map->format.format_write); in _regmap_bus_formatted_write()
1920 range = _regmap_range_lookup(map, reg); in _regmap_bus_formatted_write()
1922 ret = _regmap_select_page(map, &reg, range, 1); in _regmap_bus_formatted_write()
1927 reg += map->reg_base; in _regmap_bus_formatted_write()
1928 reg >>= map->format.reg_downshift; in _regmap_bus_formatted_write()
1929 map->format.format_write(map, reg, val); in _regmap_bus_formatted_write()
1931 trace_regmap_hw_write_start(map, reg, 1); in _regmap_bus_formatted_write()
1933 ret = map->write(map->bus_context, map->work_buf, map->format.buf_size); in _regmap_bus_formatted_write()
1935 trace_regmap_hw_write_done(map, reg, 1); in _regmap_bus_formatted_write()
1943 struct regmap *map = context; in _regmap_bus_reg_write() local
1945 return map->bus->reg_write(map->bus_context, reg, val); in _regmap_bus_reg_write()
1951 struct regmap *map = context; in _regmap_bus_raw_write() local
1953 WARN_ON(!map->format.format_val); in _regmap_bus_raw_write()
1955 map->format.format_val(map->work_buf + map->format.reg_bytes in _regmap_bus_raw_write()
1956 + map->format.pad_bytes, val, 0); in _regmap_bus_raw_write()
1957 return _regmap_raw_write_impl(map, reg, in _regmap_bus_raw_write()
1958 map->work_buf + in _regmap_bus_raw_write()
1959 map->format.reg_bytes + in _regmap_bus_raw_write()
1960 map->format.pad_bytes, in _regmap_bus_raw_write()
1961 map->format.val_bytes, in _regmap_bus_raw_write()
1965 static inline void *_regmap_map_get_context(struct regmap *map) in _regmap_map_get_context() argument
1967 return (map->bus || (!map->bus && map->read)) ? map : map->bus_context; in _regmap_map_get_context()
1970 int _regmap_write(struct regmap *map, unsigned int reg, in _regmap_write() argument
1974 void *context = _regmap_map_get_context(map); in _regmap_write()
1976 if (!regmap_writeable(map, reg)) in _regmap_write()
1979 if (!map->cache_bypass && !map->defer_caching) { in _regmap_write()
1980 ret = regcache_write(map, reg, val); in _regmap_write()
1983 if (map->cache_only) { in _regmap_write()
1984 map->cache_dirty = true; in _regmap_write()
1989 ret = map->reg_write(context, reg, val); in _regmap_write()
1991 if (regmap_should_log(map)) in _regmap_write()
1992 dev_info(map->dev, "%x <= %x\n", reg, val); in _regmap_write()
1994 trace_regmap_reg_write(map, reg, val); in _regmap_write()
2003 * @map: Register map to write to
2010 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val) in regmap_write() argument
2014 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_write()
2017 map->lock(map->lock_arg); in regmap_write()
2019 ret = _regmap_write(map, reg, val); in regmap_write()
2021 map->unlock(map->lock_arg); in regmap_write()
2030 * @map: Register map to write to
2037 int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val) in regmap_write_async() argument
2041 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_write_async()
2044 map->lock(map->lock_arg); in regmap_write_async()
2046 map->async = true; in regmap_write_async()
2048 ret = _regmap_write(map, reg, val); in regmap_write_async()
2050 map->async = false; in regmap_write_async()
2052 map->unlock(map->lock_arg); in regmap_write_async()
2058 int _regmap_raw_write(struct regmap *map, unsigned int reg, in _regmap_raw_write() argument
2061 size_t val_bytes = map->format.val_bytes; in _regmap_raw_write()
2070 if (map->use_single_write) in _regmap_raw_write()
2072 else if (map->max_raw_write && val_len > map->max_raw_write) in _regmap_raw_write()
2073 chunk_regs = map->max_raw_write / val_bytes; in _regmap_raw_write()
2080 ret = _regmap_raw_write_impl(map, reg, val, chunk_bytes, noinc); in _regmap_raw_write()
2084 reg += regmap_get_offset(map, chunk_regs); in _regmap_raw_write()
2091 ret = _regmap_raw_write_impl(map, reg, val, val_len, noinc); in _regmap_raw_write()
2099 * @map: Register map to write to
2112 int regmap_raw_write(struct regmap *map, unsigned int reg, in regmap_raw_write() argument
2117 if (!regmap_can_raw_write(map)) in regmap_raw_write()
2119 if (val_len % map->format.val_bytes) in regmap_raw_write()
2122 map->lock(map->lock_arg); in regmap_raw_write()
2124 ret = _regmap_raw_write(map, reg, val, val_len, false); in regmap_raw_write()
2126 map->unlock(map->lock_arg); in regmap_raw_write()
2132 static int regmap_noinc_readwrite(struct regmap *map, unsigned int reg, in regmap_noinc_readwrite() argument
2135 size_t val_bytes = map->format.val_bytes; in regmap_noinc_readwrite()
2180 if (!map->cache_bypass && !map->defer_caching) { in regmap_noinc_readwrite()
2181 ret = regcache_write(map, reg, lastval); in regmap_noinc_readwrite()
2184 if (map->cache_only) { in regmap_noinc_readwrite()
2185 map->cache_dirty = true; in regmap_noinc_readwrite()
2189 ret = map->bus->reg_noinc_write(map->bus_context, reg, val, val_count); in regmap_noinc_readwrite()
2191 ret = map->bus->reg_noinc_read(map->bus_context, reg, val, val_count); in regmap_noinc_readwrite()
2194 if (!ret && regmap_should_log(map)) { in regmap_noinc_readwrite()
2195 dev_info(map->dev, "%x %s [", reg, write ? "<=" : "=>"); in regmap_noinc_readwrite()
2229 * @map: Register map to write to
2246 int regmap_noinc_write(struct regmap *map, unsigned int reg, in regmap_noinc_write() argument
2252 if (!map->write && !(map->bus && map->bus->reg_noinc_write)) in regmap_noinc_write()
2254 if (val_len % map->format.val_bytes) in regmap_noinc_write()
2256 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_noinc_write()
2261 map->lock(map->lock_arg); in regmap_noinc_write()
2263 if (!regmap_volatile(map, reg) || !regmap_writeable_noinc(map, reg)) { in regmap_noinc_write()
2272 if (map->bus->reg_noinc_write) { in regmap_noinc_write()
2273 ret = regmap_noinc_readwrite(map, reg, (void *)val, val_len, true); in regmap_noinc_write()
2278 if (map->max_raw_write && map->max_raw_write < val_len) in regmap_noinc_write()
2279 write_len = map->max_raw_write; in regmap_noinc_write()
2282 ret = _regmap_raw_write(map, reg, val, write_len, true); in regmap_noinc_write()
2290 map->unlock(map->lock_arg); in regmap_noinc_write()
2380 * @map: Register map to write to
2391 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, in regmap_bulk_write() argument
2395 size_t val_bytes = map->format.val_bytes; in regmap_bulk_write()
2397 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_bulk_write()
2404 if (!map->write || !map->format.parse_inplace) { in regmap_bulk_write()
2405 map->lock(map->lock_arg); in regmap_bulk_write()
2429 ret = _regmap_write(map, in regmap_bulk_write()
2430 reg + regmap_get_offset(map, i), in regmap_bulk_write()
2436 map->unlock(map->lock_arg); in regmap_bulk_write()
2440 wval = kmemdup(val, val_count * val_bytes, map->alloc_flags); in regmap_bulk_write()
2445 map->format.parse_inplace(wval + i); in regmap_bulk_write()
2447 ret = regmap_raw_write(map, reg, wval, val_bytes * val_count); in regmap_bulk_write()
2453 trace_regmap_bulk_write(map, reg, val, val_bytes * val_count); in regmap_bulk_write()
2466 static int _regmap_raw_multi_reg_write(struct regmap *map, in _regmap_raw_multi_reg_write() argument
2474 size_t val_bytes = map->format.val_bytes; in _regmap_raw_multi_reg_write()
2475 size_t reg_bytes = map->format.reg_bytes; in _regmap_raw_multi_reg_write()
2476 size_t pad_bytes = map->format.pad_bytes; in _regmap_raw_multi_reg_write()
2494 trace_regmap_hw_write_start(map, reg, 1); in _regmap_raw_multi_reg_write()
2495 reg += map->reg_base; in _regmap_raw_multi_reg_write()
2496 reg >>= map->format.reg_downshift; in _regmap_raw_multi_reg_write()
2497 map->format.format_reg(u8, reg, map->reg_shift); in _regmap_raw_multi_reg_write()
2499 map->format.format_val(u8, val, 0); in _regmap_raw_multi_reg_write()
2503 *u8 |= map->write_flag_mask; in _regmap_raw_multi_reg_write()
2505 ret = map->write(map->bus_context, buf, len); in _regmap_raw_multi_reg_write()
2511 trace_regmap_hw_write_done(map, reg, 1); in _regmap_raw_multi_reg_write()
2516 static unsigned int _regmap_register_page(struct regmap *map, in _regmap_register_page() argument
2525 static int _regmap_range_multi_paged_reg_write(struct regmap *map, in _regmap_range_multi_paged_reg_write() argument
2545 range = _regmap_range_lookup(map, reg); in _regmap_range_multi_paged_reg_write()
2547 unsigned int win_page = _regmap_register_page(map, reg, in _regmap_range_multi_paged_reg_write()
2574 ret = _regmap_raw_multi_reg_write(map, base, n); in _regmap_range_multi_paged_reg_write()
2579 if (map->can_sleep) in _regmap_range_multi_paged_reg_write()
2589 ret = _regmap_select_page(map, in _regmap_range_multi_paged_reg_write()
2602 return _regmap_raw_multi_reg_write(map, base, n); in _regmap_range_multi_paged_reg_write()
2606 static int _regmap_multi_reg_write(struct regmap *map, in _regmap_multi_reg_write() argument
2613 if (!map->can_multi_write) { in _regmap_multi_reg_write()
2615 ret = _regmap_write(map, regs[i].reg, regs[i].def); in _regmap_multi_reg_write()
2620 if (map->can_sleep) in _regmap_multi_reg_write()
2629 if (!map->format.parse_inplace) in _regmap_multi_reg_write()
2632 if (map->writeable_reg) in _regmap_multi_reg_write()
2635 if (!map->writeable_reg(map->dev, reg)) in _regmap_multi_reg_write()
2637 if (!IS_ALIGNED(reg, map->reg_stride)) in _regmap_multi_reg_write()
2641 if (!map->cache_bypass) { in _regmap_multi_reg_write()
2645 ret = regcache_write(map, reg, val); in _regmap_multi_reg_write()
2647 dev_err(map->dev, in _regmap_multi_reg_write()
2653 if (map->cache_only) { in _regmap_multi_reg_write()
2654 map->cache_dirty = true; in _regmap_multi_reg_write()
2659 WARN_ON(!map->bus); in _regmap_multi_reg_write()
2668 range = _regmap_range_lookup(map, reg); in _regmap_multi_reg_write()
2675 ret = _regmap_range_multi_paged_reg_write(map, base, in _regmap_multi_reg_write()
2682 return _regmap_raw_multi_reg_write(map, regs, num_regs); in _regmap_multi_reg_write()
2688 * @map: Register map to write to
2704 int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs, in regmap_multi_reg_write() argument
2709 map->lock(map->lock_arg); in regmap_multi_reg_write()
2711 ret = _regmap_multi_reg_write(map, regs, num_regs); in regmap_multi_reg_write()
2713 map->unlock(map->lock_arg); in regmap_multi_reg_write()
2723 * @map: Register map to write to
2737 int regmap_multi_reg_write_bypassed(struct regmap *map, in regmap_multi_reg_write_bypassed() argument
2744 map->lock(map->lock_arg); in regmap_multi_reg_write_bypassed()
2746 bypass = map->cache_bypass; in regmap_multi_reg_write_bypassed()
2747 map->cache_bypass = true; in regmap_multi_reg_write_bypassed()
2749 ret = _regmap_multi_reg_write(map, regs, num_regs); in regmap_multi_reg_write_bypassed()
2751 map->cache_bypass = bypass; in regmap_multi_reg_write_bypassed()
2753 map->unlock(map->lock_arg); in regmap_multi_reg_write_bypassed()
2763 * @map: Register map to write to
2781 int regmap_raw_write_async(struct regmap *map, unsigned int reg, in regmap_raw_write_async() argument
2786 if (val_len % map->format.val_bytes) in regmap_raw_write_async()
2788 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_raw_write_async()
2791 map->lock(map->lock_arg); in regmap_raw_write_async()
2793 map->async = true; in regmap_raw_write_async()
2795 ret = _regmap_raw_write(map, reg, val, val_len, false); in regmap_raw_write_async()
2797 map->async = false; in regmap_raw_write_async()
2799 map->unlock(map->lock_arg); in regmap_raw_write_async()
2805 static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, in _regmap_raw_read() argument
2811 if (!map->read) in _regmap_raw_read()
2814 range = _regmap_range_lookup(map, reg); in _regmap_raw_read()
2816 ret = _regmap_select_page(map, &reg, range, in _regmap_raw_read()
2817 noinc ? 1 : val_len / map->format.val_bytes); in _regmap_raw_read()
2822 reg += map->reg_base; in _regmap_raw_read()
2823 reg >>= map->format.reg_downshift; in _regmap_raw_read()
2824 map->format.format_reg(map->work_buf, reg, map->reg_shift); in _regmap_raw_read()
2825 regmap_set_work_buf_flag_mask(map, map->format.reg_bytes, in _regmap_raw_read()
2826 map->read_flag_mask); in _regmap_raw_read()
2827 trace_regmap_hw_read_start(map, reg, val_len / map->format.val_bytes); in _regmap_raw_read()
2829 ret = map->read(map->bus_context, map->work_buf, in _regmap_raw_read()
2830 map->format.reg_bytes + map->format.pad_bytes, in _regmap_raw_read()
2833 trace_regmap_hw_read_done(map, reg, val_len / map->format.val_bytes); in _regmap_raw_read()
2841 struct regmap *map = context; in _regmap_bus_reg_read() local
2843 return map->bus->reg_read(map->bus_context, reg, val); in _regmap_bus_reg_read()
2850 struct regmap *map = context; in _regmap_bus_read() local
2851 void *work_val = map->work_buf + map->format.reg_bytes + in _regmap_bus_read()
2852 map->format.pad_bytes; in _regmap_bus_read()
2854 if (!map->format.parse_val) in _regmap_bus_read()
2857 ret = _regmap_raw_read(map, reg, work_val, map->format.val_bytes, false); in _regmap_bus_read()
2859 *val = map->format.parse_val(work_val); in _regmap_bus_read()
2864 static int _regmap_read(struct regmap *map, unsigned int reg, in _regmap_read() argument
2868 void *context = _regmap_map_get_context(map); in _regmap_read()
2870 if (!map->cache_bypass) { in _regmap_read()
2871 ret = regcache_read(map, reg, val); in _regmap_read()
2876 if (map->cache_only) in _regmap_read()
2879 if (!regmap_readable(map, reg)) in _regmap_read()
2882 ret = map->reg_read(context, reg, val); in _regmap_read()
2884 if (regmap_should_log(map)) in _regmap_read()
2885 dev_info(map->dev, "%x => %x\n", reg, *val); in _regmap_read()
2887 trace_regmap_reg_read(map, reg, *val); in _regmap_read()
2889 if (!map->cache_bypass) in _regmap_read()
2890 regcache_write(map, reg, *val); in _regmap_read()
2899 * @map: Register map to read from
2906 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val) in regmap_read() argument
2910 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_read()
2913 map->lock(map->lock_arg); in regmap_read()
2915 ret = _regmap_read(map, reg, val); in regmap_read()
2917 map->unlock(map->lock_arg); in regmap_read()
2926 * @map: Register map to read from
2934 int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, in regmap_raw_read() argument
2937 size_t val_bytes = map->format.val_bytes; in regmap_raw_read()
2942 if (val_len % map->format.val_bytes) in regmap_raw_read()
2944 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_raw_read()
2949 map->lock(map->lock_arg); in regmap_raw_read()
2951 if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass || in regmap_raw_read()
2952 map->cache_type == REGCACHE_NONE) { in regmap_raw_read()
2956 if (!map->read) { in regmap_raw_read()
2961 if (map->use_single_read) in regmap_raw_read()
2963 else if (map->max_raw_read && val_len > map->max_raw_read) in regmap_raw_read()
2964 chunk_regs = map->max_raw_read / val_bytes; in regmap_raw_read()
2971 ret = _regmap_raw_read(map, reg, val, chunk_bytes, false); in regmap_raw_read()
2975 reg += regmap_get_offset(map, chunk_regs); in regmap_raw_read()
2982 ret = _regmap_raw_read(map, reg, val, val_len, false); in regmap_raw_read()
2991 ret = _regmap_read(map, reg + regmap_get_offset(map, i), in regmap_raw_read()
2996 map->format.format_val(val + (i * val_bytes), v, 0); in regmap_raw_read()
3001 map->unlock(map->lock_arg); in regmap_raw_read()
3011 * @map: Register map to read from
3028 int regmap_noinc_read(struct regmap *map, unsigned int reg, in regmap_noinc_read() argument
3034 if (!map->read) in regmap_noinc_read()
3037 if (val_len % map->format.val_bytes) in regmap_noinc_read()
3039 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_noinc_read()
3044 map->lock(map->lock_arg); in regmap_noinc_read()
3046 if (!regmap_volatile(map, reg) || !regmap_readable_noinc(map, reg)) { in regmap_noinc_read()
3052 if (map->bus->reg_noinc_read) { in regmap_noinc_read()
3059 if (map->cache_only) { in regmap_noinc_read()
3063 ret = regmap_noinc_readwrite(map, reg, val, val_len, false); in regmap_noinc_read()
3068 if (map->max_raw_read && map->max_raw_read < val_len) in regmap_noinc_read()
3069 read_len = map->max_raw_read; in regmap_noinc_read()
3072 ret = _regmap_raw_read(map, reg, val, read_len, true); in regmap_noinc_read()
3080 map->unlock(map->lock_arg); in regmap_noinc_read()
3146 * @map: Register map to read from
3154 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, in regmap_bulk_read() argument
3158 size_t val_bytes = map->format.val_bytes; in regmap_bulk_read()
3159 bool vol = regmap_volatile_range(map, reg, val_count); in regmap_bulk_read()
3161 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_bulk_read()
3166 if (map->read && map->format.parse_inplace && (vol || map->cache_type == REGCACHE_NONE)) { in regmap_bulk_read()
3167 ret = regmap_raw_read(map, reg, val, val_bytes * val_count); in regmap_bulk_read()
3172 map->format.parse_inplace(val + i); in regmap_bulk_read()
3181 map->lock(map->lock_arg); in regmap_bulk_read()
3186 ret = _regmap_read(map, reg + regmap_get_offset(map, i), in regmap_bulk_read()
3191 switch (map->format.val_bytes) { in regmap_bulk_read()
3213 map->unlock(map->lock_arg); in regmap_bulk_read()
3217 trace_regmap_bulk_read(map, reg, val, val_bytes * val_count); in regmap_bulk_read()
3223 static int _regmap_update_bits(struct regmap *map, unsigned int reg, in _regmap_update_bits() argument
3233 if (regmap_volatile(map, reg) && map->reg_update_bits) { in _regmap_update_bits()
3234 ret = map->reg_update_bits(map->bus_context, reg, mask, val); in _regmap_update_bits()
3238 ret = _regmap_read(map, reg, &orig); in _regmap_update_bits()
3246 ret = _regmap_write(map, reg, tmp); in _regmap_update_bits()
3258 * @map: Register map to update
3266 * Perform a read/modify/write cycle on a register map with change, async, force
3277 int regmap_update_bits_base(struct regmap *map, unsigned int reg, in regmap_update_bits_base() argument
3283 map->lock(map->lock_arg); in regmap_update_bits_base()
3285 map->async = async; in regmap_update_bits_base()
3287 ret = _regmap_update_bits(map, reg, mask, val, change, force); in regmap_update_bits_base()
3289 map->async = false; in regmap_update_bits_base()
3291 map->unlock(map->lock_arg); in regmap_update_bits_base()
3300 * @map: Register map to operate on
3308 int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits) in regmap_test_bits() argument
3312 ret = regmap_read(map, reg, &val); in regmap_test_bits()
3322 struct regmap *map = async->map; in regmap_async_complete_cb() local
3325 trace_regmap_async_io_complete(map); in regmap_async_complete_cb()
3327 spin_lock(&map->async_lock); in regmap_async_complete_cb()
3328 list_move(&async->list, &map->async_free); in regmap_async_complete_cb()
3329 wake = list_empty(&map->async_list); in regmap_async_complete_cb()
3332 map->async_ret = ret; in regmap_async_complete_cb()
3334 spin_unlock(&map->async_lock); in regmap_async_complete_cb()
3337 wake_up(&map->async_waitq); in regmap_async_complete_cb()
3341 static int regmap_async_is_done(struct regmap *map) in regmap_async_is_done() argument
3346 spin_lock_irqsave(&map->async_lock, flags); in regmap_async_is_done()
3347 ret = list_empty(&map->async_list); in regmap_async_is_done()
3348 spin_unlock_irqrestore(&map->async_lock, flags); in regmap_async_is_done()
3356 * @map: Map to operate on.
3361 int regmap_async_complete(struct regmap *map) in regmap_async_complete() argument
3367 if (!map->bus || !map->bus->async_write) in regmap_async_complete()
3370 trace_regmap_async_complete_start(map); in regmap_async_complete()
3372 wait_event(map->async_waitq, regmap_async_is_done(map)); in regmap_async_complete()
3374 spin_lock_irqsave(&map->async_lock, flags); in regmap_async_complete()
3375 ret = map->async_ret; in regmap_async_complete()
3376 map->async_ret = 0; in regmap_async_complete()
3377 spin_unlock_irqrestore(&map->async_lock, flags); in regmap_async_complete()
3379 trace_regmap_async_complete_done(map); in regmap_async_complete()
3389 * @map: Register map to apply updates to.
3402 int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs, in regmap_register_patch() argument
3413 p = krealloc(map->patch, in regmap_register_patch()
3414 sizeof(struct reg_sequence) * (map->patch_regs + num_regs), in regmap_register_patch()
3417 memcpy(p + map->patch_regs, regs, num_regs * sizeof(*regs)); in regmap_register_patch()
3418 map->patch = p; in regmap_register_patch()
3419 map->patch_regs += num_regs; in regmap_register_patch()
3424 map->lock(map->lock_arg); in regmap_register_patch()
3426 bypass = map->cache_bypass; in regmap_register_patch()
3428 map->cache_bypass = true; in regmap_register_patch()
3429 map->async = true; in regmap_register_patch()
3431 ret = _regmap_multi_reg_write(map, regs, num_regs); in regmap_register_patch()
3433 map->async = false; in regmap_register_patch()
3434 map->cache_bypass = bypass; in regmap_register_patch()
3436 map->unlock(map->lock_arg); in regmap_register_patch()
3438 regmap_async_complete(map); in regmap_register_patch()
3447 * @map: Register map to operate on.
3452 int regmap_get_val_bytes(struct regmap *map) in regmap_get_val_bytes() argument
3454 if (map->format.format_write) in regmap_get_val_bytes()
3457 return map->format.val_bytes; in regmap_get_val_bytes()
3464 * @map: Register map to operate on.
3469 int regmap_get_max_register(struct regmap *map) in regmap_get_max_register() argument
3471 return map->max_register ? map->max_register : -EINVAL; in regmap_get_max_register()
3478 * @map: Register map to operate on.
3483 int regmap_get_reg_stride(struct regmap *map) in regmap_get_reg_stride() argument
3485 return map->reg_stride; in regmap_get_reg_stride()
3489 int regmap_parse_val(struct regmap *map, const void *buf, in regmap_parse_val() argument
3492 if (!map->format.parse_val) in regmap_parse_val()
3495 *val = map->format.parse_val(buf); in regmap_parse_val()