Lines Matching refs:map
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()
396 struct regmap *map = __map; in regmap_lock_hwlock() local
398 hwspin_lock_timeout(map->hwlock, UINT_MAX); in regmap_lock_hwlock()
403 struct regmap *map = __map; in regmap_lock_hwlock_irq() local
405 hwspin_lock_timeout_irq(map->hwlock, UINT_MAX); in regmap_lock_hwlock_irq()
410 struct regmap *map = __map; in regmap_lock_hwlock_irqsave() local
412 hwspin_lock_timeout_irqsave(map->hwlock, UINT_MAX, in regmap_lock_hwlock_irqsave()
413 &map->spinlock_flags); in regmap_lock_hwlock_irqsave()
418 struct regmap *map = __map; in regmap_unlock_hwlock() local
420 hwspin_unlock(map->hwlock); in regmap_unlock_hwlock()
425 struct regmap *map = __map; in regmap_unlock_hwlock_irq() local
427 hwspin_unlock_irq(map->hwlock); in regmap_unlock_hwlock_irq()
432 struct regmap *map = __map; in regmap_unlock_hwlock_irqrestore() local
434 hwspin_unlock_irqrestore(map->hwlock, &map->spinlock_flags); in regmap_unlock_hwlock_irqrestore()
444 struct regmap *map = __map; in regmap_lock_mutex() local
445 mutex_lock(&map->mutex); in regmap_lock_mutex()
450 struct regmap *map = __map; in regmap_unlock_mutex() local
451 mutex_unlock(&map->mutex); in regmap_unlock_mutex()
455 __acquires(&map->spinlock) in regmap_lock_spinlock()
457 struct regmap *map = __map; in regmap_lock_spinlock() local
460 spin_lock_irqsave(&map->spinlock, flags); in regmap_lock_spinlock()
461 map->spinlock_flags = flags; in regmap_lock_spinlock()
465 __releases(&map->spinlock) in regmap_unlock_spinlock()
467 struct regmap *map = __map; in regmap_unlock_spinlock() local
468 spin_unlock_irqrestore(&map->spinlock, map->spinlock_flags); in regmap_unlock_spinlock()
472 __acquires(&map->raw_spinlock) in regmap_lock_raw_spinlock()
474 struct regmap *map = __map; in regmap_lock_raw_spinlock() local
477 raw_spin_lock_irqsave(&map->raw_spinlock, flags); in regmap_lock_raw_spinlock()
478 map->raw_spinlock_flags = flags; in regmap_lock_raw_spinlock()
482 __releases(&map->raw_spinlock) in regmap_unlock_raw_spinlock()
484 struct regmap *map = __map; in regmap_unlock_raw_spinlock() local
485 raw_spin_unlock_irqrestore(&map->raw_spinlock, map->raw_spinlock_flags); in regmap_unlock_raw_spinlock()
497 static bool _regmap_range_add(struct regmap *map, in _regmap_range_add() argument
500 struct rb_root *root = &map->range_tree; in _regmap_range_add()
522 static struct regmap_range_node *_regmap_range_lookup(struct regmap *map, in _regmap_range_lookup() argument
525 struct rb_node *node = map->range_tree.rb_node; in _regmap_range_lookup()
542 static void regmap_range_exit(struct regmap *map) in regmap_range_exit() argument
547 next = rb_first(&map->range_tree); in regmap_range_exit()
551 rb_erase(&range_node->node, &map->range_tree); in regmap_range_exit()
555 kfree(map->selector_work_buf); in regmap_range_exit()
558 static int regmap_set_name(struct regmap *map, const struct regmap_config *config) in regmap_set_name() argument
566 kfree_const(map->name); in regmap_set_name()
567 map->name = name; in regmap_set_name()
573 int regmap_attach_dev(struct device *dev, struct regmap *map, in regmap_attach_dev() argument
579 map->dev = dev; in regmap_attach_dev()
581 ret = regmap_set_name(map, config); in regmap_attach_dev()
585 regmap_debugfs_exit(map); in regmap_attach_dev()
586 regmap_debugfs_init(map); in regmap_attach_dev()
591 regmap_debugfs_exit(map); in regmap_attach_dev()
594 *m = map; in regmap_attach_dev()
671 struct regmap *map; in __regmap_init() local
679 map = kzalloc(sizeof(*map), GFP_KERNEL); in __regmap_init()
680 if (map == NULL) { in __regmap_init()
685 ret = regmap_set_name(map, config); in __regmap_init()
692 map->lock = map->unlock = regmap_lock_unlock_none; in __regmap_init()
693 map->can_sleep = config->can_sleep; in __regmap_init()
694 regmap_debugfs_disable(map); in __regmap_init()
696 map->lock = config->lock; in __regmap_init()
697 map->unlock = config->unlock; in __regmap_init()
698 map->lock_arg = config->lock_arg; in __regmap_init()
699 map->can_sleep = config->can_sleep; in __regmap_init()
701 map->hwlock = hwspin_lock_request_specific(config->hwlock_id); in __regmap_init()
702 if (!map->hwlock) { in __regmap_init()
709 map->lock = regmap_lock_hwlock_irqsave; in __regmap_init()
710 map->unlock = regmap_unlock_hwlock_irqrestore; in __regmap_init()
713 map->lock = regmap_lock_hwlock_irq; in __regmap_init()
714 map->unlock = regmap_unlock_hwlock_irq; in __regmap_init()
717 map->lock = regmap_lock_hwlock; in __regmap_init()
718 map->unlock = regmap_unlock_hwlock; in __regmap_init()
722 map->lock_arg = map; in __regmap_init()
727 raw_spin_lock_init(&map->raw_spinlock); in __regmap_init()
728 map->lock = regmap_lock_raw_spinlock; in __regmap_init()
729 map->unlock = regmap_unlock_raw_spinlock; in __regmap_init()
730 lockdep_set_class_and_name(&map->raw_spinlock, in __regmap_init()
733 spin_lock_init(&map->spinlock); in __regmap_init()
734 map->lock = regmap_lock_spinlock; in __regmap_init()
735 map->unlock = regmap_unlock_spinlock; in __regmap_init()
736 lockdep_set_class_and_name(&map->spinlock, in __regmap_init()
740 mutex_init(&map->mutex); in __regmap_init()
741 map->lock = regmap_lock_mutex; in __regmap_init()
742 map->unlock = regmap_unlock_mutex; in __regmap_init()
743 map->can_sleep = true; in __regmap_init()
744 lockdep_set_class_and_name(&map->mutex, in __regmap_init()
747 map->lock_arg = map; in __regmap_init()
755 map->alloc_flags = GFP_ATOMIC; in __regmap_init()
757 map->alloc_flags = GFP_KERNEL; in __regmap_init()
759 map->reg_base = config->reg_base; in __regmap_init()
761 map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8); in __regmap_init()
762 map->format.pad_bytes = config->pad_bits / 8; in __regmap_init()
763 map->format.reg_shift = config->reg_shift; in __regmap_init()
764 map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8); in __regmap_init()
765 map->format.buf_size = DIV_ROUND_UP(config->reg_bits + in __regmap_init()
767 map->reg_shift = config->pad_bits % 8; in __regmap_init()
769 map->reg_stride = config->reg_stride; in __regmap_init()
771 map->reg_stride = 1; in __regmap_init()
772 if (is_power_of_2(map->reg_stride)) in __regmap_init()
773 map->reg_stride_order = ilog2(map->reg_stride); in __regmap_init()
775 map->reg_stride_order = -1; in __regmap_init()
776 map->use_single_read = config->use_single_read || !(config->read || (bus && bus->read)); in __regmap_init()
777 map->use_single_write = config->use_single_write || !(config->write || (bus && bus->write)); in __regmap_init()
778 map->can_multi_write = config->can_multi_write && (config->write || (bus && bus->write)); in __regmap_init()
780 map->max_raw_read = bus->max_raw_read; in __regmap_init()
781 map->max_raw_write = bus->max_raw_write; in __regmap_init()
783 map->max_raw_read = config->max_raw_read; in __regmap_init()
784 map->max_raw_write = config->max_raw_write; in __regmap_init()
786 map->dev = dev; in __regmap_init()
787 map->bus = bus; in __regmap_init()
788 map->bus_context = bus_context; in __regmap_init()
789 map->max_register = config->max_register; in __regmap_init()
790 map->wr_table = config->wr_table; in __regmap_init()
791 map->rd_table = config->rd_table; in __regmap_init()
792 map->volatile_table = config->volatile_table; in __regmap_init()
793 map->precious_table = config->precious_table; in __regmap_init()
794 map->wr_noinc_table = config->wr_noinc_table; in __regmap_init()
795 map->rd_noinc_table = config->rd_noinc_table; in __regmap_init()
796 map->writeable_reg = config->writeable_reg; in __regmap_init()
797 map->readable_reg = config->readable_reg; in __regmap_init()
798 map->volatile_reg = config->volatile_reg; in __regmap_init()
799 map->precious_reg = config->precious_reg; in __regmap_init()
800 map->writeable_noinc_reg = config->writeable_noinc_reg; in __regmap_init()
801 map->readable_noinc_reg = config->readable_noinc_reg; in __regmap_init()
802 map->cache_type = config->cache_type; in __regmap_init()
804 spin_lock_init(&map->async_lock); in __regmap_init()
805 INIT_LIST_HEAD(&map->async_list); in __regmap_init()
806 INIT_LIST_HEAD(&map->async_free); in __regmap_init()
807 init_waitqueue_head(&map->async_waitq); in __regmap_init()
812 map->read_flag_mask = config->read_flag_mask; in __regmap_init()
813 map->write_flag_mask = config->write_flag_mask; in __regmap_init()
815 map->read_flag_mask = bus->read_flag_mask; in __regmap_init()
819 map->reg_read = _regmap_bus_read; in __regmap_init()
821 map->reg_update_bits = config->reg_update_bits; in __regmap_init()
824 map->read = config->read; in __regmap_init()
825 map->write = config->write; in __regmap_init()
830 map->reg_read = config->reg_read; in __regmap_init()
831 map->reg_write = config->reg_write; in __regmap_init()
832 map->reg_update_bits = config->reg_update_bits; in __regmap_init()
834 map->defer_caching = false; in __regmap_init()
837 map->reg_read = _regmap_bus_reg_read; in __regmap_init()
838 map->reg_write = _regmap_bus_reg_write; in __regmap_init()
839 map->reg_update_bits = bus->reg_update_bits; in __regmap_init()
841 map->defer_caching = false; in __regmap_init()
844 map->reg_read = _regmap_bus_read; in __regmap_init()
845 map->reg_update_bits = bus->reg_update_bits; in __regmap_init()
847 map->read = bus->read; in __regmap_init()
848 map->write = bus->write; in __regmap_init()
854 switch (config->reg_bits + map->reg_shift) { in __regmap_init()
858 map->format.format_write = regmap_format_2_6_write; in __regmap_init()
868 map->format.format_write = regmap_format_4_12_write; in __regmap_init()
878 map->format.format_write = regmap_format_7_9_write; in __regmap_init()
881 map->format.format_write = regmap_format_7_17_write; in __regmap_init()
891 map->format.format_write = regmap_format_10_14_write; in __regmap_init()
901 map->format.format_write = regmap_format_12_20_write; in __regmap_init()
909 map->format.format_reg = regmap_format_8; in __regmap_init()
915 map->format.format_reg = regmap_format_16_be; in __regmap_init()
918 map->format.format_reg = regmap_format_16_le; in __regmap_init()
921 map->format.format_reg = regmap_format_16_native; in __regmap_init()
931 map->format.format_reg = regmap_format_24_be; in __regmap_init()
941 map->format.format_reg = regmap_format_32_be; in __regmap_init()
944 map->format.format_reg = regmap_format_32_le; in __regmap_init()
947 map->format.format_reg = regmap_format_32_native; in __regmap_init()
959 map->format.parse_inplace = regmap_parse_inplace_noop; in __regmap_init()
963 map->format.format_val = regmap_format_8; in __regmap_init()
964 map->format.parse_val = regmap_parse_8; in __regmap_init()
965 map->format.parse_inplace = regmap_parse_inplace_noop; in __regmap_init()
970 map->format.format_val = regmap_format_16_be; in __regmap_init()
971 map->format.parse_val = regmap_parse_16_be; in __regmap_init()
972 map->format.parse_inplace = regmap_parse_16_be_inplace; in __regmap_init()
975 map->format.format_val = regmap_format_16_le; in __regmap_init()
976 map->format.parse_val = regmap_parse_16_le; in __regmap_init()
977 map->format.parse_inplace = regmap_parse_16_le_inplace; in __regmap_init()
980 map->format.format_val = regmap_format_16_native; in __regmap_init()
981 map->format.parse_val = regmap_parse_16_native; in __regmap_init()
990 map->format.format_val = regmap_format_24_be; in __regmap_init()
991 map->format.parse_val = regmap_parse_24_be; in __regmap_init()
1000 map->format.format_val = regmap_format_32_be; in __regmap_init()
1001 map->format.parse_val = regmap_parse_32_be; in __regmap_init()
1002 map->format.parse_inplace = regmap_parse_32_be_inplace; in __regmap_init()
1005 map->format.format_val = regmap_format_32_le; in __regmap_init()
1006 map->format.parse_val = regmap_parse_32_le; in __regmap_init()
1007 map->format.parse_inplace = regmap_parse_32_le_inplace; in __regmap_init()
1010 map->format.format_val = regmap_format_32_native; in __regmap_init()
1011 map->format.parse_val = regmap_parse_32_native; in __regmap_init()
1019 if (map->format.format_write) { in __regmap_init()
1023 map->use_single_write = true; in __regmap_init()
1026 if (!map->format.format_write && in __regmap_init()
1027 !(map->format.format_reg && map->format.format_val)) in __regmap_init()
1030 map->work_buf = kzalloc(map->format.buf_size, GFP_KERNEL); in __regmap_init()
1031 if (map->work_buf == NULL) { in __regmap_init()
1036 if (map->format.format_write) { in __regmap_init()
1037 map->defer_caching = false; in __regmap_init()
1038 map->reg_write = _regmap_bus_formatted_write; in __regmap_init()
1039 } else if (map->format.format_val) { in __regmap_init()
1040 map->defer_caching = true; in __regmap_init()
1041 map->reg_write = _regmap_bus_raw_write; in __regmap_init()
1046 map->range_tree = RB_ROOT; in __regmap_init()
1053 dev_err(map->dev, "Invalid range %d: %d < %d\n", i, in __regmap_init()
1058 if (range_cfg->range_max > map->max_register) { in __regmap_init()
1059 dev_err(map->dev, "Invalid range %d: %d > %d\n", i, in __regmap_init()
1060 range_cfg->range_max, map->max_register); in __regmap_init()
1064 if (range_cfg->selector_reg > map->max_register) { in __regmap_init()
1065 dev_err(map->dev, in __regmap_init()
1071 dev_err(map->dev, "Invalid range %d: window_len 0\n", in __regmap_init()
1090 dev_err(map->dev, in __regmap_init()
1098 dev_err(map->dev, in __regmap_init()
1111 new->map = map; in __regmap_init()
1121 if (!_regmap_range_add(map, new)) { in __regmap_init()
1122 dev_err(map->dev, "Failed to add range %d\n", i); in __regmap_init()
1127 if (map->selector_work_buf == NULL) { in __regmap_init()
1128 map->selector_work_buf = in __regmap_init()
1129 kzalloc(map->format.buf_size, GFP_KERNEL); in __regmap_init()
1130 if (map->selector_work_buf == NULL) { in __regmap_init()
1137 ret = regcache_init(map, config); in __regmap_init()
1142 ret = regmap_attach_dev(dev, map, config); in __regmap_init()
1146 regmap_debugfs_init(map); in __regmap_init()
1149 return map; in __regmap_init()
1152 regcache_exit(map); in __regmap_init()
1154 regmap_range_exit(map); in __regmap_init()
1155 kfree(map->work_buf); in __regmap_init()
1157 if (map->hwlock) in __regmap_init()
1158 hwspin_lock_free(map->hwlock); in __regmap_init()
1160 kfree_const(map->name); in __regmap_init()
1162 kfree(map); in __regmap_init()
1407 int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) in regmap_reinit_cache() argument
1411 regcache_exit(map); in regmap_reinit_cache()
1412 regmap_debugfs_exit(map); in regmap_reinit_cache()
1414 map->max_register = config->max_register; in regmap_reinit_cache()
1415 map->writeable_reg = config->writeable_reg; in regmap_reinit_cache()
1416 map->readable_reg = config->readable_reg; in regmap_reinit_cache()
1417 map->volatile_reg = config->volatile_reg; in regmap_reinit_cache()
1418 map->precious_reg = config->precious_reg; in regmap_reinit_cache()
1419 map->writeable_noinc_reg = config->writeable_noinc_reg; in regmap_reinit_cache()
1420 map->readable_noinc_reg = config->readable_noinc_reg; in regmap_reinit_cache()
1421 map->cache_type = config->cache_type; in regmap_reinit_cache()
1423 ret = regmap_set_name(map, config); in regmap_reinit_cache()
1427 regmap_debugfs_init(map); in regmap_reinit_cache()
1429 map->cache_bypass = false; in regmap_reinit_cache()
1430 map->cache_only = false; in regmap_reinit_cache()
1432 return regcache_init(map, config); in regmap_reinit_cache()
1441 void regmap_exit(struct regmap *map) in regmap_exit() argument
1445 regcache_exit(map); in regmap_exit()
1446 regmap_debugfs_exit(map); in regmap_exit()
1447 regmap_range_exit(map); in regmap_exit()
1448 if (map->bus && map->bus->free_context) in regmap_exit()
1449 map->bus->free_context(map->bus_context); in regmap_exit()
1450 kfree(map->work_buf); in regmap_exit()
1451 while (!list_empty(&map->async_free)) { in regmap_exit()
1452 async = list_first_entry_or_null(&map->async_free, in regmap_exit()
1459 if (map->hwlock) in regmap_exit()
1460 hwspin_lock_free(map->hwlock); in regmap_exit()
1461 if (map->lock == regmap_lock_mutex) in regmap_exit()
1462 mutex_destroy(&map->mutex); in regmap_exit()
1463 kfree_const(map->name); in regmap_exit()
1464 kfree(map->patch); in regmap_exit()
1465 if (map->bus && map->bus->free_on_exit) in regmap_exit()
1466 kfree(map->bus); in regmap_exit()
1467 kfree(map); in regmap_exit()
1516 struct device *regmap_get_device(struct regmap *map) in regmap_get_device() argument
1518 return map->dev; in regmap_get_device()
1522 static int _regmap_select_page(struct regmap *map, unsigned int *reg, in _regmap_select_page() argument
1551 orig_work_buf = map->work_buf; in _regmap_select_page()
1552 map->work_buf = map->selector_work_buf; in _regmap_select_page()
1554 ret = _regmap_update_bits(map, range->selector_reg, in _regmap_select_page()
1559 map->work_buf = orig_work_buf; in _regmap_select_page()
1570 static void regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes, in regmap_set_work_buf_flag_mask() argument
1576 if (!mask || !map->work_buf) in regmap_set_work_buf_flag_mask()
1579 buf = map->work_buf; in regmap_set_work_buf_flag_mask()
1585 static unsigned int regmap_reg_addr(struct regmap *map, unsigned int reg) in regmap_reg_addr() argument
1587 reg += map->reg_base; in regmap_reg_addr()
1589 if (map->format.reg_shift > 0) in regmap_reg_addr()
1590 reg >>= map->format.reg_shift; in regmap_reg_addr()
1591 else if (map->format.reg_shift < 0) in regmap_reg_addr()
1592 reg <<= -(map->format.reg_shift); in regmap_reg_addr()
1597 static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg, in _regmap_raw_write_impl() argument
1602 void *work_val = map->work_buf + map->format.reg_bytes + in _regmap_raw_write_impl()
1603 map->format.pad_bytes; in _regmap_raw_write_impl()
1612 if (!regmap_writeable_noinc(map, reg)) { in _regmap_raw_write_impl()
1613 for (i = 0; i < val_len / map->format.val_bytes; i++) { in _regmap_raw_write_impl()
1615 reg + regmap_get_offset(map, i); in _regmap_raw_write_impl()
1616 if (!regmap_writeable(map, element) || in _regmap_raw_write_impl()
1617 regmap_writeable_noinc(map, element)) in _regmap_raw_write_impl()
1622 if (!map->cache_bypass && map->format.parse_val) { in _regmap_raw_write_impl()
1624 int val_bytes = map->format.val_bytes; in _regmap_raw_write_impl()
1629 ival = map->format.parse_val(val + i); in _regmap_raw_write_impl()
1630 offset = noinc ? 0 : regmap_get_offset(map, i / val_bytes); in _regmap_raw_write_impl()
1631 ret = regcache_write(map, reg + offset, ival); in _regmap_raw_write_impl()
1633 dev_err(map->dev, in _regmap_raw_write_impl()
1639 if (map->cache_only) { in _regmap_raw_write_impl()
1640 map->cache_dirty = true; in _regmap_raw_write_impl()
1645 range = _regmap_range_lookup(map, reg); in _regmap_raw_write_impl()
1647 int val_num = val_len / map->format.val_bytes; in _regmap_raw_write_impl()
1653 dev_dbg(map->dev, "Writing window %d/%zu\n", in _regmap_raw_write_impl()
1654 win_residue, val_len / map->format.val_bytes); in _regmap_raw_write_impl()
1655 ret = _regmap_raw_write_impl(map, reg, val, in _regmap_raw_write_impl()
1657 map->format.val_bytes, noinc); in _regmap_raw_write_impl()
1663 val += win_residue * map->format.val_bytes; in _regmap_raw_write_impl()
1664 val_len -= win_residue * map->format.val_bytes; in _regmap_raw_write_impl()
1671 ret = _regmap_select_page(map, ®, range, noinc ? 1 : val_num); in _regmap_raw_write_impl()
1676 reg = regmap_reg_addr(map, reg); in _regmap_raw_write_impl()
1677 map->format.format_reg(map->work_buf, reg, map->reg_shift); in _regmap_raw_write_impl()
1678 regmap_set_work_buf_flag_mask(map, map->format.reg_bytes, in _regmap_raw_write_impl()
1679 map->write_flag_mask); in _regmap_raw_write_impl()
1686 if (val != work_val && val_len == map->format.val_bytes) { in _regmap_raw_write_impl()
1687 memcpy(work_val, val, map->format.val_bytes); in _regmap_raw_write_impl()
1691 if (map->async && map->bus && map->bus->async_write) { in _regmap_raw_write_impl()
1694 trace_regmap_async_write_start(map, reg, val_len); in _regmap_raw_write_impl()
1696 spin_lock_irqsave(&map->async_lock, flags); in _regmap_raw_write_impl()
1697 async = list_first_entry_or_null(&map->async_free, in _regmap_raw_write_impl()
1702 spin_unlock_irqrestore(&map->async_lock, flags); in _regmap_raw_write_impl()
1705 async = map->bus->async_alloc(); in _regmap_raw_write_impl()
1709 async->work_buf = kzalloc(map->format.buf_size, in _regmap_raw_write_impl()
1717 async->map = map; in _regmap_raw_write_impl()
1720 memcpy(async->work_buf, map->work_buf, map->format.pad_bytes + in _regmap_raw_write_impl()
1721 map->format.reg_bytes + map->format.val_bytes); in _regmap_raw_write_impl()
1723 spin_lock_irqsave(&map->async_lock, flags); in _regmap_raw_write_impl()
1724 list_add_tail(&async->list, &map->async_list); in _regmap_raw_write_impl()
1725 spin_unlock_irqrestore(&map->async_lock, flags); in _regmap_raw_write_impl()
1728 ret = map->bus->async_write(map->bus_context, in _regmap_raw_write_impl()
1730 map->format.reg_bytes + in _regmap_raw_write_impl()
1731 map->format.pad_bytes, in _regmap_raw_write_impl()
1734 ret = map->bus->async_write(map->bus_context, in _regmap_raw_write_impl()
1736 map->format.reg_bytes + in _regmap_raw_write_impl()
1737 map->format.pad_bytes + in _regmap_raw_write_impl()
1741 dev_err(map->dev, "Failed to schedule write: %d\n", in _regmap_raw_write_impl()
1744 spin_lock_irqsave(&map->async_lock, flags); in _regmap_raw_write_impl()
1745 list_move(&async->list, &map->async_free); in _regmap_raw_write_impl()
1746 spin_unlock_irqrestore(&map->async_lock, flags); in _regmap_raw_write_impl()
1752 trace_regmap_hw_write_start(map, reg, val_len / map->format.val_bytes); in _regmap_raw_write_impl()
1759 ret = map->write(map->bus_context, map->work_buf, in _regmap_raw_write_impl()
1760 map->format.reg_bytes + in _regmap_raw_write_impl()
1761 map->format.pad_bytes + in _regmap_raw_write_impl()
1763 else if (map->bus && map->bus->gather_write) in _regmap_raw_write_impl()
1764 ret = map->bus->gather_write(map->bus_context, map->work_buf, in _regmap_raw_write_impl()
1765 map->format.reg_bytes + in _regmap_raw_write_impl()
1766 map->format.pad_bytes, in _regmap_raw_write_impl()
1773 len = map->format.reg_bytes + map->format.pad_bytes + val_len; in _regmap_raw_write_impl()
1778 memcpy(buf, map->work_buf, map->format.reg_bytes); in _regmap_raw_write_impl()
1779 memcpy(buf + map->format.reg_bytes + map->format.pad_bytes, in _regmap_raw_write_impl()
1781 ret = map->write(map->bus_context, buf, len); in _regmap_raw_write_impl()
1784 } else if (ret != 0 && !map->cache_bypass && map->format.parse_val) { in _regmap_raw_write_impl()
1788 if (map->cache_ops && map->cache_ops->drop) in _regmap_raw_write_impl()
1789 map->cache_ops->drop(map, reg, reg + 1); in _regmap_raw_write_impl()
1792 trace_regmap_hw_write_done(map, reg, val_len / map->format.val_bytes); in _regmap_raw_write_impl()
1802 bool regmap_can_raw_write(struct regmap *map) in regmap_can_raw_write() argument
1804 return map->write && map->format.format_val && map->format.format_reg; in regmap_can_raw_write()
1813 size_t regmap_get_raw_read_max(struct regmap *map) in regmap_get_raw_read_max() argument
1815 return map->max_raw_read; in regmap_get_raw_read_max()
1824 size_t regmap_get_raw_write_max(struct regmap *map) in regmap_get_raw_write_max() argument
1826 return map->max_raw_write; in regmap_get_raw_write_max()
1835 struct regmap *map = context; in _regmap_bus_formatted_write() local
1837 WARN_ON(!map->format.format_write); in _regmap_bus_formatted_write()
1839 range = _regmap_range_lookup(map, reg); in _regmap_bus_formatted_write()
1841 ret = _regmap_select_page(map, ®, range, 1); in _regmap_bus_formatted_write()
1846 reg = regmap_reg_addr(map, reg); in _regmap_bus_formatted_write()
1847 map->format.format_write(map, reg, val); in _regmap_bus_formatted_write()
1849 trace_regmap_hw_write_start(map, reg, 1); in _regmap_bus_formatted_write()
1851 ret = map->write(map->bus_context, map->work_buf, map->format.buf_size); in _regmap_bus_formatted_write()
1853 trace_regmap_hw_write_done(map, reg, 1); in _regmap_bus_formatted_write()
1861 struct regmap *map = context; in _regmap_bus_reg_write() local
1865 range = _regmap_range_lookup(map, reg); in _regmap_bus_reg_write()
1867 ret = _regmap_select_page(map, ®, range, 1); in _regmap_bus_reg_write()
1872 reg = regmap_reg_addr(map, reg); in _regmap_bus_reg_write()
1873 return map->bus->reg_write(map->bus_context, reg, val); in _regmap_bus_reg_write()
1879 struct regmap *map = context; in _regmap_bus_raw_write() local
1881 WARN_ON(!map->format.format_val); in _regmap_bus_raw_write()
1883 map->format.format_val(map->work_buf + map->format.reg_bytes in _regmap_bus_raw_write()
1884 + map->format.pad_bytes, val, 0); in _regmap_bus_raw_write()
1885 return _regmap_raw_write_impl(map, reg, in _regmap_bus_raw_write()
1886 map->work_buf + in _regmap_bus_raw_write()
1887 map->format.reg_bytes + in _regmap_bus_raw_write()
1888 map->format.pad_bytes, in _regmap_bus_raw_write()
1889 map->format.val_bytes, in _regmap_bus_raw_write()
1893 static inline void *_regmap_map_get_context(struct regmap *map) in _regmap_map_get_context() argument
1895 return (map->bus || (!map->bus && map->read)) ? map : map->bus_context; in _regmap_map_get_context()
1898 int _regmap_write(struct regmap *map, unsigned int reg, in _regmap_write() argument
1902 void *context = _regmap_map_get_context(map); in _regmap_write()
1904 if (!regmap_writeable(map, reg)) in _regmap_write()
1907 if (!map->cache_bypass && !map->defer_caching) { in _regmap_write()
1908 ret = regcache_write(map, reg, val); in _regmap_write()
1911 if (map->cache_only) { in _regmap_write()
1912 map->cache_dirty = true; in _regmap_write()
1917 ret = map->reg_write(context, reg, val); in _regmap_write()
1919 if (regmap_should_log(map)) in _regmap_write()
1920 dev_info(map->dev, "%x <= %x\n", reg, val); in _regmap_write()
1922 trace_regmap_reg_write(map, reg, val); in _regmap_write()
1938 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val) in regmap_write() argument
1942 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_write()
1945 map->lock(map->lock_arg); in regmap_write()
1947 ret = _regmap_write(map, reg, val); in regmap_write()
1949 map->unlock(map->lock_arg); in regmap_write()
1965 int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val) in regmap_write_async() argument
1969 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_write_async()
1972 map->lock(map->lock_arg); in regmap_write_async()
1974 map->async = true; in regmap_write_async()
1976 ret = _regmap_write(map, reg, val); in regmap_write_async()
1978 map->async = false; in regmap_write_async()
1980 map->unlock(map->lock_arg); in regmap_write_async()
1986 int _regmap_raw_write(struct regmap *map, unsigned int reg, in _regmap_raw_write() argument
1989 size_t val_bytes = map->format.val_bytes; in _regmap_raw_write()
1998 if (map->use_single_write) in _regmap_raw_write()
2000 else if (map->max_raw_write && val_len > map->max_raw_write) in _regmap_raw_write()
2001 chunk_regs = map->max_raw_write / val_bytes; in _regmap_raw_write()
2008 ret = _regmap_raw_write_impl(map, reg, val, chunk_bytes, noinc); in _regmap_raw_write()
2012 reg += regmap_get_offset(map, chunk_regs); in _regmap_raw_write()
2019 ret = _regmap_raw_write_impl(map, reg, val, val_len, noinc); in _regmap_raw_write()
2040 int regmap_raw_write(struct regmap *map, unsigned int reg, in regmap_raw_write() argument
2045 if (!regmap_can_raw_write(map)) in regmap_raw_write()
2047 if (val_len % map->format.val_bytes) in regmap_raw_write()
2050 map->lock(map->lock_arg); in regmap_raw_write()
2052 ret = _regmap_raw_write(map, reg, val, val_len, false); in regmap_raw_write()
2054 map->unlock(map->lock_arg); in regmap_raw_write()
2060 static int regmap_noinc_readwrite(struct regmap *map, unsigned int reg, in regmap_noinc_readwrite() argument
2063 size_t val_bytes = map->format.val_bytes; in regmap_noinc_readwrite()
2098 if (!map->cache_bypass && !map->defer_caching) { in regmap_noinc_readwrite()
2099 ret = regcache_write(map, reg, lastval); in regmap_noinc_readwrite()
2102 if (map->cache_only) { in regmap_noinc_readwrite()
2103 map->cache_dirty = true; in regmap_noinc_readwrite()
2107 ret = map->bus->reg_noinc_write(map->bus_context, reg, val, val_count); in regmap_noinc_readwrite()
2109 ret = map->bus->reg_noinc_read(map->bus_context, reg, val, val_count); in regmap_noinc_readwrite()
2112 if (!ret && regmap_should_log(map)) { in regmap_noinc_readwrite()
2113 dev_info(map->dev, "%x %s [", reg, write ? "<=" : "=>"); in regmap_noinc_readwrite()
2159 int regmap_noinc_write(struct regmap *map, unsigned int reg, in regmap_noinc_write() argument
2165 if (!map->write && !(map->bus && map->bus->reg_noinc_write)) in regmap_noinc_write()
2167 if (val_len % map->format.val_bytes) in regmap_noinc_write()
2169 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_noinc_write()
2174 map->lock(map->lock_arg); in regmap_noinc_write()
2176 if (!regmap_volatile(map, reg) || !regmap_writeable_noinc(map, reg)) { in regmap_noinc_write()
2185 if (map->bus->reg_noinc_write) { in regmap_noinc_write()
2186 ret = regmap_noinc_readwrite(map, reg, (void *)val, val_len, true); in regmap_noinc_write()
2191 if (map->max_raw_write && map->max_raw_write < val_len) in regmap_noinc_write()
2192 write_len = map->max_raw_write; in regmap_noinc_write()
2195 ret = _regmap_raw_write(map, reg, val, write_len, true); in regmap_noinc_write()
2203 map->unlock(map->lock_arg); in regmap_noinc_write()
2304 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, in regmap_bulk_write() argument
2308 size_t val_bytes = map->format.val_bytes; in regmap_bulk_write()
2310 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_bulk_write()
2317 if (!map->write || !map->format.parse_inplace) { in regmap_bulk_write()
2318 map->lock(map->lock_arg); in regmap_bulk_write()
2337 ret = _regmap_write(map, in regmap_bulk_write()
2338 reg + regmap_get_offset(map, i), in regmap_bulk_write()
2344 map->unlock(map->lock_arg); in regmap_bulk_write()
2348 wval = kmemdup(val, val_count * val_bytes, map->alloc_flags); in regmap_bulk_write()
2353 map->format.parse_inplace(wval + i); in regmap_bulk_write()
2355 ret = regmap_raw_write(map, reg, wval, val_bytes * val_count); in regmap_bulk_write()
2361 trace_regmap_bulk_write(map, reg, val, val_bytes * val_count); in regmap_bulk_write()
2374 static int _regmap_raw_multi_reg_write(struct regmap *map, in _regmap_raw_multi_reg_write() argument
2382 size_t val_bytes = map->format.val_bytes; in _regmap_raw_multi_reg_write()
2383 size_t reg_bytes = map->format.reg_bytes; in _regmap_raw_multi_reg_write()
2384 size_t pad_bytes = map->format.pad_bytes; in _regmap_raw_multi_reg_write()
2402 trace_regmap_hw_write_start(map, reg, 1); in _regmap_raw_multi_reg_write()
2403 reg = regmap_reg_addr(map, reg); in _regmap_raw_multi_reg_write()
2404 map->format.format_reg(u8, reg, map->reg_shift); in _regmap_raw_multi_reg_write()
2406 map->format.format_val(u8, val, 0); in _regmap_raw_multi_reg_write()
2410 *u8 |= map->write_flag_mask; in _regmap_raw_multi_reg_write()
2412 ret = map->write(map->bus_context, buf, len); in _regmap_raw_multi_reg_write()
2418 trace_regmap_hw_write_done(map, reg, 1); in _regmap_raw_multi_reg_write()
2423 static unsigned int _regmap_register_page(struct regmap *map, in _regmap_register_page() argument
2432 static int _regmap_range_multi_paged_reg_write(struct regmap *map, in _regmap_range_multi_paged_reg_write() argument
2452 range = _regmap_range_lookup(map, reg); in _regmap_range_multi_paged_reg_write()
2454 unsigned int win_page = _regmap_register_page(map, reg, in _regmap_range_multi_paged_reg_write()
2481 ret = _regmap_raw_multi_reg_write(map, base, n); in _regmap_range_multi_paged_reg_write()
2486 if (map->can_sleep) in _regmap_range_multi_paged_reg_write()
2496 ret = _regmap_select_page(map, in _regmap_range_multi_paged_reg_write()
2509 return _regmap_raw_multi_reg_write(map, base, n); in _regmap_range_multi_paged_reg_write()
2513 static int _regmap_multi_reg_write(struct regmap *map, in _regmap_multi_reg_write() argument
2520 if (!map->can_multi_write) { in _regmap_multi_reg_write()
2522 ret = _regmap_write(map, regs[i].reg, regs[i].def); in _regmap_multi_reg_write()
2527 if (map->can_sleep) in _regmap_multi_reg_write()
2536 if (!map->format.parse_inplace) in _regmap_multi_reg_write()
2539 if (map->writeable_reg) in _regmap_multi_reg_write()
2542 if (!map->writeable_reg(map->dev, reg)) in _regmap_multi_reg_write()
2544 if (!IS_ALIGNED(reg, map->reg_stride)) in _regmap_multi_reg_write()
2548 if (!map->cache_bypass) { in _regmap_multi_reg_write()
2552 ret = regcache_write(map, reg, val); in _regmap_multi_reg_write()
2554 dev_err(map->dev, in _regmap_multi_reg_write()
2560 if (map->cache_only) { in _regmap_multi_reg_write()
2561 map->cache_dirty = true; in _regmap_multi_reg_write()
2566 WARN_ON(!map->bus); in _regmap_multi_reg_write()
2575 range = _regmap_range_lookup(map, reg); in _regmap_multi_reg_write()
2582 ret = _regmap_range_multi_paged_reg_write(map, base, in _regmap_multi_reg_write()
2589 return _regmap_raw_multi_reg_write(map, regs, num_regs); in _regmap_multi_reg_write()
2611 int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs, in regmap_multi_reg_write() argument
2616 map->lock(map->lock_arg); in regmap_multi_reg_write()
2618 ret = _regmap_multi_reg_write(map, regs, num_regs); in regmap_multi_reg_write()
2620 map->unlock(map->lock_arg); in regmap_multi_reg_write()
2644 int regmap_multi_reg_write_bypassed(struct regmap *map, in regmap_multi_reg_write_bypassed() argument
2651 map->lock(map->lock_arg); in regmap_multi_reg_write_bypassed()
2653 bypass = map->cache_bypass; in regmap_multi_reg_write_bypassed()
2654 map->cache_bypass = true; in regmap_multi_reg_write_bypassed()
2656 ret = _regmap_multi_reg_write(map, regs, num_regs); in regmap_multi_reg_write_bypassed()
2658 map->cache_bypass = bypass; in regmap_multi_reg_write_bypassed()
2660 map->unlock(map->lock_arg); in regmap_multi_reg_write_bypassed()
2688 int regmap_raw_write_async(struct regmap *map, unsigned int reg, in regmap_raw_write_async() argument
2693 if (val_len % map->format.val_bytes) in regmap_raw_write_async()
2695 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_raw_write_async()
2698 map->lock(map->lock_arg); in regmap_raw_write_async()
2700 map->async = true; in regmap_raw_write_async()
2702 ret = _regmap_raw_write(map, reg, val, val_len, false); in regmap_raw_write_async()
2704 map->async = false; in regmap_raw_write_async()
2706 map->unlock(map->lock_arg); in regmap_raw_write_async()
2712 static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, in _regmap_raw_read() argument
2718 if (!map->read) in _regmap_raw_read()
2721 range = _regmap_range_lookup(map, reg); in _regmap_raw_read()
2723 ret = _regmap_select_page(map, ®, range, in _regmap_raw_read()
2724 noinc ? 1 : val_len / map->format.val_bytes); in _regmap_raw_read()
2729 reg = regmap_reg_addr(map, reg); in _regmap_raw_read()
2730 map->format.format_reg(map->work_buf, reg, map->reg_shift); in _regmap_raw_read()
2731 regmap_set_work_buf_flag_mask(map, map->format.reg_bytes, in _regmap_raw_read()
2732 map->read_flag_mask); in _regmap_raw_read()
2733 trace_regmap_hw_read_start(map, reg, val_len / map->format.val_bytes); in _regmap_raw_read()
2735 ret = map->read(map->bus_context, map->work_buf, in _regmap_raw_read()
2736 map->format.reg_bytes + map->format.pad_bytes, in _regmap_raw_read()
2739 trace_regmap_hw_read_done(map, reg, val_len / map->format.val_bytes); in _regmap_raw_read()
2747 struct regmap *map = context; in _regmap_bus_reg_read() local
2751 range = _regmap_range_lookup(map, reg); in _regmap_bus_reg_read()
2753 ret = _regmap_select_page(map, ®, range, 1); in _regmap_bus_reg_read()
2758 reg = regmap_reg_addr(map, reg); in _regmap_bus_reg_read()
2759 return map->bus->reg_read(map->bus_context, reg, val); in _regmap_bus_reg_read()
2766 struct regmap *map = context; in _regmap_bus_read() local
2767 void *work_val = map->work_buf + map->format.reg_bytes + in _regmap_bus_read()
2768 map->format.pad_bytes; in _regmap_bus_read()
2770 if (!map->format.parse_val) in _regmap_bus_read()
2773 ret = _regmap_raw_read(map, reg, work_val, map->format.val_bytes, false); in _regmap_bus_read()
2775 *val = map->format.parse_val(work_val); in _regmap_bus_read()
2780 static int _regmap_read(struct regmap *map, unsigned int reg, in _regmap_read() argument
2784 void *context = _regmap_map_get_context(map); in _regmap_read()
2786 if (!map->cache_bypass) { in _regmap_read()
2787 ret = regcache_read(map, reg, val); in _regmap_read()
2792 if (map->cache_only) in _regmap_read()
2795 if (!regmap_readable(map, reg)) in _regmap_read()
2798 ret = map->reg_read(context, reg, val); in _regmap_read()
2800 if (regmap_should_log(map)) in _regmap_read()
2801 dev_info(map->dev, "%x => %x\n", reg, *val); in _regmap_read()
2803 trace_regmap_reg_read(map, reg, *val); in _regmap_read()
2805 if (!map->cache_bypass) in _regmap_read()
2806 regcache_write(map, reg, *val); in _regmap_read()
2822 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val) in regmap_read() argument
2826 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_read()
2829 map->lock(map->lock_arg); in regmap_read()
2831 ret = _regmap_read(map, reg, val); in regmap_read()
2833 map->unlock(map->lock_arg); in regmap_read()
2850 int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, in regmap_raw_read() argument
2853 size_t val_bytes = map->format.val_bytes; in regmap_raw_read()
2858 if (val_len % map->format.val_bytes) in regmap_raw_read()
2860 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_raw_read()
2865 map->lock(map->lock_arg); in regmap_raw_read()
2867 if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass || in regmap_raw_read()
2868 map->cache_type == REGCACHE_NONE) { in regmap_raw_read()
2872 if (!map->cache_bypass && map->cache_only) { in regmap_raw_read()
2877 if (!map->read) { in regmap_raw_read()
2882 if (map->use_single_read) in regmap_raw_read()
2884 else if (map->max_raw_read && val_len > map->max_raw_read) in regmap_raw_read()
2885 chunk_regs = map->max_raw_read / val_bytes; in regmap_raw_read()
2892 ret = _regmap_raw_read(map, reg, val, chunk_bytes, false); in regmap_raw_read()
2896 reg += regmap_get_offset(map, chunk_regs); in regmap_raw_read()
2903 ret = _regmap_raw_read(map, reg, val, val_len, false); in regmap_raw_read()
2912 ret = _regmap_read(map, reg + regmap_get_offset(map, i), in regmap_raw_read()
2917 map->format.format_val(val + (i * val_bytes), v, 0); in regmap_raw_read()
2922 map->unlock(map->lock_arg); in regmap_raw_read()
2949 int regmap_noinc_read(struct regmap *map, unsigned int reg, in regmap_noinc_read() argument
2955 if (!map->read) in regmap_noinc_read()
2958 if (val_len % map->format.val_bytes) in regmap_noinc_read()
2960 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_noinc_read()
2965 map->lock(map->lock_arg); in regmap_noinc_read()
2967 if (!regmap_volatile(map, reg) || !regmap_readable_noinc(map, reg)) { in regmap_noinc_read()
2978 if (!map->cache_bypass && map->cache_only) { in regmap_noinc_read()
2984 if (map->bus->reg_noinc_read) { in regmap_noinc_read()
2985 ret = regmap_noinc_readwrite(map, reg, val, val_len, false); in regmap_noinc_read()
2990 if (map->max_raw_read && map->max_raw_read < val_len) in regmap_noinc_read()
2991 read_len = map->max_raw_read; in regmap_noinc_read()
2994 ret = _regmap_raw_read(map, reg, val, read_len, true); in regmap_noinc_read()
3002 map->unlock(map->lock_arg); in regmap_noinc_read()
3076 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, in regmap_bulk_read() argument
3080 size_t val_bytes = map->format.val_bytes; in regmap_bulk_read()
3081 bool vol = regmap_volatile_range(map, reg, val_count); in regmap_bulk_read()
3083 if (!IS_ALIGNED(reg, map->reg_stride)) in regmap_bulk_read()
3088 if (map->read && map->format.parse_inplace && (vol || map->cache_type == REGCACHE_NONE)) { in regmap_bulk_read()
3089 ret = regmap_raw_read(map, reg, val, val_bytes * val_count); in regmap_bulk_read()
3094 map->format.parse_inplace(val + i); in regmap_bulk_read()
3100 map->lock(map->lock_arg); in regmap_bulk_read()
3105 ret = _regmap_read(map, reg + regmap_get_offset(map, i), in regmap_bulk_read()
3110 switch (map->format.val_bytes) { in regmap_bulk_read()
3127 map->unlock(map->lock_arg); in regmap_bulk_read()
3131 trace_regmap_bulk_read(map, reg, val, val_bytes * val_count); in regmap_bulk_read()
3137 static int _regmap_update_bits(struct regmap *map, unsigned int reg, in _regmap_update_bits() argument
3147 if (regmap_volatile(map, reg) && map->reg_update_bits) { in _regmap_update_bits()
3148 reg = regmap_reg_addr(map, reg); in _regmap_update_bits()
3149 ret = map->reg_update_bits(map->bus_context, reg, mask, val); in _regmap_update_bits()
3153 ret = _regmap_read(map, reg, &orig); in _regmap_update_bits()
3160 if (force_write || (tmp != orig) || map->force_write_field) { in _regmap_update_bits()
3161 ret = _regmap_write(map, reg, tmp); in _regmap_update_bits()
3192 int regmap_update_bits_base(struct regmap *map, unsigned int reg, in regmap_update_bits_base() argument
3198 map->lock(map->lock_arg); in regmap_update_bits_base()
3200 map->async = async; in regmap_update_bits_base()
3202 ret = _regmap_update_bits(map, reg, mask, val, change, force); in regmap_update_bits_base()
3204 map->async = false; in regmap_update_bits_base()
3206 map->unlock(map->lock_arg); in regmap_update_bits_base()
3223 int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits) in regmap_test_bits() argument
3227 ret = regmap_read(map, reg, &val); in regmap_test_bits()
3237 struct regmap *map = async->map; in regmap_async_complete_cb() local
3240 trace_regmap_async_io_complete(map); in regmap_async_complete_cb()
3242 spin_lock(&map->async_lock); in regmap_async_complete_cb()
3243 list_move(&async->list, &map->async_free); in regmap_async_complete_cb()
3244 wake = list_empty(&map->async_list); in regmap_async_complete_cb()
3247 map->async_ret = ret; in regmap_async_complete_cb()
3249 spin_unlock(&map->async_lock); in regmap_async_complete_cb()
3252 wake_up(&map->async_waitq); in regmap_async_complete_cb()
3256 static int regmap_async_is_done(struct regmap *map) in regmap_async_is_done() argument
3261 spin_lock_irqsave(&map->async_lock, flags); in regmap_async_is_done()
3262 ret = list_empty(&map->async_list); in regmap_async_is_done()
3263 spin_unlock_irqrestore(&map->async_lock, flags); in regmap_async_is_done()
3276 int regmap_async_complete(struct regmap *map) in regmap_async_complete() argument
3282 if (!map->bus || !map->bus->async_write) in regmap_async_complete()
3285 trace_regmap_async_complete_start(map); in regmap_async_complete()
3287 wait_event(map->async_waitq, regmap_async_is_done(map)); in regmap_async_complete()
3289 spin_lock_irqsave(&map->async_lock, flags); in regmap_async_complete()
3290 ret = map->async_ret; in regmap_async_complete()
3291 map->async_ret = 0; in regmap_async_complete()
3292 spin_unlock_irqrestore(&map->async_lock, flags); in regmap_async_complete()
3294 trace_regmap_async_complete_done(map); in regmap_async_complete()
3317 int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs, in regmap_register_patch() argument
3328 p = krealloc(map->patch, in regmap_register_patch()
3329 sizeof(struct reg_sequence) * (map->patch_regs + num_regs), in regmap_register_patch()
3332 memcpy(p + map->patch_regs, regs, num_regs * sizeof(*regs)); in regmap_register_patch()
3333 map->patch = p; in regmap_register_patch()
3334 map->patch_regs += num_regs; in regmap_register_patch()
3339 map->lock(map->lock_arg); in regmap_register_patch()
3341 bypass = map->cache_bypass; in regmap_register_patch()
3343 map->cache_bypass = true; in regmap_register_patch()
3344 map->async = true; in regmap_register_patch()
3346 ret = _regmap_multi_reg_write(map, regs, num_regs); in regmap_register_patch()
3348 map->async = false; in regmap_register_patch()
3349 map->cache_bypass = bypass; in regmap_register_patch()
3351 map->unlock(map->lock_arg); in regmap_register_patch()
3353 regmap_async_complete(map); in regmap_register_patch()
3367 int regmap_get_val_bytes(struct regmap *map) in regmap_get_val_bytes() argument
3369 if (map->format.format_write) in regmap_get_val_bytes()
3372 return map->format.val_bytes; in regmap_get_val_bytes()
3384 int regmap_get_max_register(struct regmap *map) in regmap_get_max_register() argument
3386 return map->max_register ? map->max_register : -EINVAL; in regmap_get_max_register()
3398 int regmap_get_reg_stride(struct regmap *map) in regmap_get_reg_stride() argument
3400 return map->reg_stride; in regmap_get_reg_stride()
3411 bool regmap_might_sleep(struct regmap *map) in regmap_might_sleep() argument
3413 return map->can_sleep; in regmap_might_sleep()
3417 int regmap_parse_val(struct regmap *map, const void *buf, in regmap_parse_val() argument
3420 if (!map->format.parse_val) in regmap_parse_val()
3423 *val = map->format.parse_val(buf); in regmap_parse_val()