Lines Matching full:map
44 static int regcache_hw_init(struct regmap *map) in regcache_hw_init() argument
52 if (!map->num_reg_defaults_raw) in regcache_hw_init()
56 for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) in regcache_hw_init()
57 if (regmap_readable(map, i * map->reg_stride) && in regcache_hw_init()
58 !regmap_volatile(map, i * map->reg_stride)) in regcache_hw_init()
63 map->cache_bypass = true; in regcache_hw_init()
67 map->num_reg_defaults = count; in regcache_hw_init()
68 map->reg_defaults = kmalloc_array(count, sizeof(struct reg_default), in regcache_hw_init()
70 if (!map->reg_defaults) in regcache_hw_init()
73 if (!map->reg_defaults_raw) { in regcache_hw_init()
74 bool cache_bypass = map->cache_bypass; in regcache_hw_init()
75 dev_warn(map->dev, "No cache defaults, reading back from HW\n"); in regcache_hw_init()
78 map->cache_bypass = true; in regcache_hw_init()
79 tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL); in regcache_hw_init()
84 ret = regmap_raw_read(map, 0, tmp_buf, in regcache_hw_init()
85 map->cache_size_raw); in regcache_hw_init()
86 map->cache_bypass = cache_bypass; in regcache_hw_init()
88 map->reg_defaults_raw = tmp_buf; in regcache_hw_init()
89 map->cache_free = true; in regcache_hw_init()
96 for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) { in regcache_hw_init()
97 reg = i * map->reg_stride; in regcache_hw_init()
99 if (!regmap_readable(map, reg)) in regcache_hw_init()
102 if (regmap_volatile(map, reg)) in regcache_hw_init()
105 if (map->reg_defaults_raw) { in regcache_hw_init()
106 val = regcache_get_val(map, map->reg_defaults_raw, i); in regcache_hw_init()
108 bool cache_bypass = map->cache_bypass; in regcache_hw_init()
110 map->cache_bypass = true; in regcache_hw_init()
111 ret = regmap_read(map, reg, &val); in regcache_hw_init()
112 map->cache_bypass = cache_bypass; in regcache_hw_init()
114 dev_err(map->dev, "Failed to read %d: %d\n", in regcache_hw_init()
120 map->reg_defaults[j].reg = reg; in regcache_hw_init()
121 map->reg_defaults[j].def = val; in regcache_hw_init()
128 kfree(map->reg_defaults); in regcache_hw_init()
133 int regcache_init(struct regmap *map, const struct regmap_config *config) in regcache_init() argument
139 if (map->cache_type == REGCACHE_NONE) { in regcache_init()
141 dev_warn(map->dev, in regcache_init()
144 map->cache_bypass = true; in regcache_init()
149 dev_err(map->dev, in regcache_init()
155 dev_err(map->dev, in regcache_init()
161 if (config->reg_defaults[i].reg % map->reg_stride) in regcache_init()
165 if (cache_types[i]->type == map->cache_type) in regcache_init()
169 dev_err(map->dev, "Could not match cache type: %d\n", in regcache_init()
170 map->cache_type); in regcache_init()
174 map->num_reg_defaults = config->num_reg_defaults; in regcache_init()
175 map->num_reg_defaults_raw = config->num_reg_defaults_raw; in regcache_init()
176 map->reg_defaults_raw = config->reg_defaults_raw; in regcache_init()
177 map->cache_word_size = BITS_TO_BYTES(config->val_bits); in regcache_init()
178 map->cache_size_raw = map->cache_word_size * config->num_reg_defaults_raw; in regcache_init()
180 map->cache = NULL; in regcache_init()
181 map->cache_ops = cache_types[i]; in regcache_init()
183 if (!map->cache_ops->read || in regcache_init()
184 !map->cache_ops->write || in regcache_init()
185 !map->cache_ops->name) in regcache_init()
193 tmp_buf = kmemdup_array(config->reg_defaults, map->num_reg_defaults, in regcache_init()
194 sizeof(*map->reg_defaults), GFP_KERNEL); in regcache_init()
197 map->reg_defaults = tmp_buf; in regcache_init()
198 } else if (map->num_reg_defaults_raw) { in regcache_init()
203 ret = regcache_hw_init(map); in regcache_init()
206 if (map->cache_bypass) in regcache_init()
210 if (!map->max_register_is_set && map->num_reg_defaults_raw) { in regcache_init()
211 map->max_register = (map->num_reg_defaults_raw - 1) * map->reg_stride; in regcache_init()
212 map->max_register_is_set = true; in regcache_init()
215 if (map->cache_ops->init) { in regcache_init()
216 dev_dbg(map->dev, "Initializing %s cache\n", in regcache_init()
217 map->cache_ops->name); in regcache_init()
218 map->lock(map->lock_arg); in regcache_init()
219 ret = map->cache_ops->init(map); in regcache_init()
220 map->unlock(map->lock_arg); in regcache_init()
227 kfree(map->reg_defaults); in regcache_init()
228 if (map->cache_free) in regcache_init()
229 kfree(map->reg_defaults_raw); in regcache_init()
234 void regcache_exit(struct regmap *map) in regcache_exit() argument
236 if (map->cache_type == REGCACHE_NONE) in regcache_exit()
239 BUG_ON(!map->cache_ops); in regcache_exit()
241 kfree(map->reg_defaults); in regcache_exit()
242 if (map->cache_free) in regcache_exit()
243 kfree(map->reg_defaults_raw); in regcache_exit()
245 if (map->cache_ops->exit) { in regcache_exit()
246 dev_dbg(map->dev, "Destroying %s cache\n", in regcache_exit()
247 map->cache_ops->name); in regcache_exit()
248 map->lock(map->lock_arg); in regcache_exit()
249 map->cache_ops->exit(map); in regcache_exit()
250 map->unlock(map->lock_arg); in regcache_exit()
257 * @map: map to configure.
263 int regcache_read(struct regmap *map, in regcache_read() argument
268 if (map->cache_type == REGCACHE_NONE) in regcache_read()
271 BUG_ON(!map->cache_ops); in regcache_read()
273 if (!regmap_volatile(map, reg)) { in regcache_read()
274 ret = map->cache_ops->read(map, reg, value); in regcache_read()
277 trace_regmap_reg_read_cache(map, reg, *value); in regcache_read()
288 * @map: map to configure.
294 int regcache_write(struct regmap *map, in regcache_write() argument
297 if (map->cache_type == REGCACHE_NONE) in regcache_write()
300 BUG_ON(!map->cache_ops); in regcache_write()
302 if (!regmap_volatile(map, reg)) in regcache_write()
303 return map->cache_ops->write(map, reg, value); in regcache_write()
308 bool regcache_reg_needs_sync(struct regmap *map, unsigned int reg, in regcache_reg_needs_sync() argument
313 if (!regmap_writeable(map, reg)) in regcache_reg_needs_sync()
317 if (!map->no_sync_defaults) in regcache_reg_needs_sync()
321 ret = regcache_lookup_reg(map, reg); in regcache_reg_needs_sync()
322 if (ret >= 0 && val == map->reg_defaults[ret].def) in regcache_reg_needs_sync()
327 static int regcache_default_sync(struct regmap *map, unsigned int min, in regcache_default_sync() argument
332 for (reg = min; reg <= max; reg += map->reg_stride) { in regcache_default_sync()
336 if (regmap_volatile(map, reg) || in regcache_default_sync()
337 !regmap_writeable(map, reg)) in regcache_default_sync()
340 ret = regcache_read(map, reg, &val); in regcache_default_sync()
346 if (!regcache_reg_needs_sync(map, reg, val)) in regcache_default_sync()
349 map->cache_bypass = true; in regcache_default_sync()
350 ret = _regmap_write(map, reg, val); in regcache_default_sync()
351 map->cache_bypass = false; in regcache_default_sync()
353 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_default_sync()
357 dev_dbg(map->dev, "Synced register %#x, value %#x\n", reg, val); in regcache_default_sync()
371 * @map: map to configure.
379 int regcache_sync(struct regmap *map) in regcache_sync() argument
387 if (WARN_ON(map->cache_type == REGCACHE_NONE)) in regcache_sync()
390 BUG_ON(!map->cache_ops); in regcache_sync()
392 map->lock(map->lock_arg); in regcache_sync()
394 bypass = map->cache_bypass; in regcache_sync()
395 dev_dbg(map->dev, "Syncing %s cache\n", in regcache_sync()
396 map->cache_ops->name); in regcache_sync()
397 name = map->cache_ops->name; in regcache_sync()
398 trace_regcache_sync(map, name, "start"); in regcache_sync()
400 if (!map->cache_dirty) in regcache_sync()
404 map->cache_bypass = true; in regcache_sync()
405 for (i = 0; i < map->patch_regs; i++) { in regcache_sync()
406 ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def); in regcache_sync()
408 dev_err(map->dev, "Failed to write %x = %x: %d\n", in regcache_sync()
409 map->patch[i].reg, map->patch[i].def, ret); in regcache_sync()
413 map->cache_bypass = false; in regcache_sync()
415 if (map->cache_ops->sync) in regcache_sync()
416 ret = map->cache_ops->sync(map, 0, map->max_register); in regcache_sync()
418 ret = regcache_default_sync(map, 0, map->max_register); in regcache_sync()
421 map->cache_dirty = false; in regcache_sync()
425 map->cache_bypass = bypass; in regcache_sync()
426 map->no_sync_defaults = false; in regcache_sync()
434 rb_for_each(node, NULL, &map->range_tree, rbtree_all) { in regcache_sync()
439 if (regcache_read(map, this->selector_reg, &i) != 0) in regcache_sync()
442 ret = _regmap_write(map, this->selector_reg, i); in regcache_sync()
444 dev_err(map->dev, "Failed to write %x = %x: %d\n", in regcache_sync()
450 map->unlock(map->lock_arg); in regcache_sync()
452 regmap_async_complete(map); in regcache_sync()
454 trace_regcache_sync(map, name, "stop"); in regcache_sync()
463 * @map: map to sync.
472 int regcache_sync_region(struct regmap *map, unsigned int min, in regcache_sync_region() argument
479 if (WARN_ON(map->cache_type == REGCACHE_NONE)) in regcache_sync_region()
482 BUG_ON(!map->cache_ops); in regcache_sync_region()
484 map->lock(map->lock_arg); in regcache_sync_region()
487 bypass = map->cache_bypass; in regcache_sync_region()
489 name = map->cache_ops->name; in regcache_sync_region()
490 dev_dbg(map->dev, "Syncing %s cache from %d-%d\n", name, min, max); in regcache_sync_region()
492 trace_regcache_sync(map, name, "start region"); in regcache_sync_region()
494 if (!map->cache_dirty) in regcache_sync_region()
497 map->async = true; in regcache_sync_region()
499 if (map->cache_ops->sync) in regcache_sync_region()
500 ret = map->cache_ops->sync(map, min, max); in regcache_sync_region()
502 ret = regcache_default_sync(map, min, max); in regcache_sync_region()
506 map->cache_bypass = bypass; in regcache_sync_region()
507 map->async = false; in regcache_sync_region()
508 map->no_sync_defaults = false; in regcache_sync_region()
509 map->unlock(map->lock_arg); in regcache_sync_region()
511 regmap_async_complete(map); in regcache_sync_region()
513 trace_regcache_sync(map, name, "stop region"); in regcache_sync_region()
522 * @map: map to operate on
530 int regcache_drop_region(struct regmap *map, unsigned int min, in regcache_drop_region() argument
535 if (!map->cache_ops || !map->cache_ops->drop) in regcache_drop_region()
538 map->lock(map->lock_arg); in regcache_drop_region()
540 trace_regcache_drop_region(map, min, max); in regcache_drop_region()
542 ret = map->cache_ops->drop(map, min, max); in regcache_drop_region()
544 map->unlock(map->lock_arg); in regcache_drop_region()
551 * regcache_cache_only - Put a register map into cache only mode
553 * @map: map to configure
556 * When a register map is marked as cache only writes to the register
557 * map API will only update the register cache, they will not cause
562 void regcache_cache_only(struct regmap *map, bool enable) in regcache_cache_only() argument
564 map->lock(map->lock_arg); in regcache_cache_only()
565 WARN_ON(map->cache_type != REGCACHE_NONE && in regcache_cache_only()
566 map->cache_bypass && enable); in regcache_cache_only()
567 map->cache_only = enable; in regcache_cache_only()
568 trace_regmap_cache_only(map, enable); in regcache_cache_only()
569 map->unlock(map->lock_arg); in regcache_cache_only()
576 * @map: map to mark
586 void regcache_mark_dirty(struct regmap *map) in regcache_mark_dirty() argument
588 map->lock(map->lock_arg); in regcache_mark_dirty()
589 map->cache_dirty = true; in regcache_mark_dirty()
590 map->no_sync_defaults = true; in regcache_mark_dirty()
591 map->unlock(map->lock_arg); in regcache_mark_dirty()
596 * regcache_cache_bypass - Put a register map into cache bypass mode
598 * @map: map to configure
601 * When a register map is marked with the cache bypass option, writes
602 * to the register map API will only update the hardware and not
606 void regcache_cache_bypass(struct regmap *map, bool enable) in regcache_cache_bypass() argument
608 map->lock(map->lock_arg); in regcache_cache_bypass()
609 WARN_ON(map->cache_only && enable); in regcache_cache_bypass()
610 map->cache_bypass = enable; in regcache_cache_bypass()
611 trace_regmap_cache_bypass(map, enable); in regcache_cache_bypass()
612 map->unlock(map->lock_arg); in regcache_cache_bypass()
619 * @map: map to check
624 bool regcache_reg_cached(struct regmap *map, unsigned int reg) in regcache_reg_cached() argument
629 map->lock(map->lock_arg); in regcache_reg_cached()
631 ret = regcache_read(map, reg, &val); in regcache_reg_cached()
633 map->unlock(map->lock_arg); in regcache_reg_cached()
639 void regcache_set_val(struct regmap *map, void *base, unsigned int idx, in regcache_set_val() argument
643 if (map->format.format_val) { in regcache_set_val()
644 map->format.format_val(base + (map->cache_word_size * idx), in regcache_set_val()
649 switch (map->cache_word_size) { in regcache_set_val()
673 unsigned int regcache_get_val(struct regmap *map, const void *base, in regcache_get_val() argument
680 if (map->format.parse_val) in regcache_get_val()
681 return map->format.parse_val(regcache_get_val_addr(map, base, in regcache_get_val()
684 switch (map->cache_word_size) { in regcache_get_val()
715 int regcache_lookup_reg(struct regmap *map, unsigned int reg) in regcache_lookup_reg() argument
723 r = bsearch(&key, map->reg_defaults, map->num_reg_defaults, in regcache_lookup_reg()
727 return r - map->reg_defaults; in regcache_lookup_reg()
740 int regcache_sync_val(struct regmap *map, unsigned int reg, unsigned int val) in regcache_sync_val() argument
744 if (!regcache_reg_needs_sync(map, reg, val)) in regcache_sync_val()
747 map->cache_bypass = true; in regcache_sync_val()
749 ret = _regmap_write(map, reg, val); in regcache_sync_val()
751 map->cache_bypass = false; in regcache_sync_val()
754 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_sync_val()
758 dev_dbg(map->dev, "Synced register %#x, value %#x\n", in regcache_sync_val()
764 static int regcache_sync_block_single(struct regmap *map, void *block, in regcache_sync_block_single() argument
773 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_single()
776 !regmap_writeable(map, regtmp)) in regcache_sync_block_single()
779 val = regcache_get_val(map, block, i); in regcache_sync_block_single()
780 ret = regcache_sync_val(map, regtmp, val); in regcache_sync_block_single()
788 static int regcache_sync_block_raw_flush(struct regmap *map, const void **data, in regcache_sync_block_raw_flush() argument
791 size_t val_bytes = map->format.val_bytes; in regcache_sync_block_raw_flush()
797 count = (cur - base) / map->reg_stride; in regcache_sync_block_raw_flush()
799 dev_dbg(map->dev, "Writing %zu bytes for %d registers from 0x%x-0x%x\n", in regcache_sync_block_raw_flush()
800 count * val_bytes, count, base, cur - map->reg_stride); in regcache_sync_block_raw_flush()
802 map->cache_bypass = true; in regcache_sync_block_raw_flush()
804 ret = _regmap_raw_write(map, base, *data, count * val_bytes, false); in regcache_sync_block_raw_flush()
806 dev_err(map->dev, "Unable to sync registers %#x-%#x. %d\n", in regcache_sync_block_raw_flush()
807 base, cur - map->reg_stride, ret); in regcache_sync_block_raw_flush()
809 map->cache_bypass = false; in regcache_sync_block_raw_flush()
816 static int regcache_sync_block_raw(struct regmap *map, void *block, in regcache_sync_block_raw() argument
828 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_raw()
831 !regmap_writeable(map, regtmp)) { in regcache_sync_block_raw()
832 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
839 val = regcache_get_val(map, block, i); in regcache_sync_block_raw()
840 if (!regcache_reg_needs_sync(map, regtmp, val)) { in regcache_sync_block_raw()
841 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
849 data = regcache_get_val_addr(map, block, i); in regcache_sync_block_raw()
854 return regcache_sync_block_raw_flush(map, &data, base, regtmp + in regcache_sync_block_raw()
855 map->reg_stride); in regcache_sync_block_raw()
858 int regcache_sync_block(struct regmap *map, void *block, in regcache_sync_block() argument
863 if (regmap_can_raw_write(map) && !map->use_single_write) in regcache_sync_block()
864 return regcache_sync_block_raw(map, block, cache_present, in regcache_sync_block()
867 return regcache_sync_block_single(map, block, cache_present, in regcache_sync_block()