Lines Matching full:map

55 static int regcache_hw_init(struct regmap *map)  in regcache_hw_init()  argument
63 if (!map->num_reg_defaults_raw) in regcache_hw_init()
67 for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) in regcache_hw_init()
68 if (regmap_readable(map, i * map->reg_stride) && in regcache_hw_init()
69 !regmap_volatile(map, i * map->reg_stride)) in regcache_hw_init()
74 map->cache_bypass = true; in regcache_hw_init()
78 map->num_reg_defaults = count; in regcache_hw_init()
79 map->reg_defaults = kmalloc_array(count, sizeof(struct reg_default), in regcache_hw_init()
81 if (!map->reg_defaults) in regcache_hw_init()
84 if (!map->reg_defaults_raw) { in regcache_hw_init()
85 bool cache_bypass = map->cache_bypass; in regcache_hw_init()
86 dev_warn(map->dev, "No cache defaults, reading back from HW\n"); in regcache_hw_init()
89 map->cache_bypass = true; in regcache_hw_init()
90 tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL); in regcache_hw_init()
95 ret = regmap_raw_read(map, 0, tmp_buf, in regcache_hw_init()
96 map->cache_size_raw); in regcache_hw_init()
97 map->cache_bypass = cache_bypass; in regcache_hw_init()
99 map->reg_defaults_raw = tmp_buf; in regcache_hw_init()
100 map->cache_free = true; in regcache_hw_init()
107 for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) { in regcache_hw_init()
108 reg = i * map->reg_stride; in regcache_hw_init()
110 if (!regmap_readable(map, reg)) in regcache_hw_init()
113 if (regmap_volatile(map, reg)) in regcache_hw_init()
116 if (map->reg_defaults_raw) { in regcache_hw_init()
117 val = regcache_get_val(map, map->reg_defaults_raw, i); in regcache_hw_init()
119 bool cache_bypass = map->cache_bypass; in regcache_hw_init()
121 map->cache_bypass = true; in regcache_hw_init()
122 ret = regmap_read(map, reg, &val); in regcache_hw_init()
123 map->cache_bypass = cache_bypass; in regcache_hw_init()
125 dev_err(map->dev, "Failed to read %d: %d\n", in regcache_hw_init()
131 map->reg_defaults[j].reg = reg; in regcache_hw_init()
132 map->reg_defaults[j].def = val; in regcache_hw_init()
139 kfree(map->reg_defaults); in regcache_hw_init()
144 int regcache_init(struct regmap *map, const struct regmap_config *config) in regcache_init() argument
150 if (map->cache_type == REGCACHE_NONE) { in regcache_init()
152 dev_warn(map->dev, in regcache_init()
155 map->cache_bypass = true; in regcache_init()
160 dev_err(map->dev, in regcache_init()
166 dev_err(map->dev, in regcache_init()
172 if (config->reg_defaults[i].reg % map->reg_stride) in regcache_init()
176 if (cache_types[i]->type == map->cache_type) in regcache_init()
180 dev_err(map->dev, "Could not match cache type: %d\n", in regcache_init()
181 map->cache_type); in regcache_init()
185 map->num_reg_defaults = config->num_reg_defaults; in regcache_init()
186 map->num_reg_defaults_raw = config->num_reg_defaults_raw; in regcache_init()
187 map->reg_defaults_raw = config->reg_defaults_raw; in regcache_init()
188 map->cache_word_size = BITS_TO_BYTES(config->val_bits); in regcache_init()
189 map->cache_size_raw = map->cache_word_size * config->num_reg_defaults_raw; in regcache_init()
191 map->cache = NULL; in regcache_init()
192 map->cache_ops = cache_types[i]; in regcache_init()
194 if (!map->cache_ops->read || in regcache_init()
195 !map->cache_ops->write || in regcache_init()
196 !map->cache_ops->name) in regcache_init()
204 tmp_buf = kmemdup_array(config->reg_defaults, map->num_reg_defaults, in regcache_init()
205 sizeof(*map->reg_defaults), GFP_KERNEL); in regcache_init()
208 map->reg_defaults = tmp_buf; in regcache_init()
209 } else if (map->num_reg_defaults_raw) { in regcache_init()
214 ret = regcache_hw_init(map); in regcache_init()
217 if (map->cache_bypass) in regcache_init()
221 if (!map->max_register_is_set && map->num_reg_defaults_raw) { in regcache_init()
222 map->max_register = (map->num_reg_defaults_raw - 1) * map->reg_stride; in regcache_init()
223 map->max_register_is_set = true; in regcache_init()
226 if (map->cache_ops->init) { in regcache_init()
227 dev_dbg(map->dev, "Initializing %s cache\n", in regcache_init()
228 map->cache_ops->name); in regcache_init()
229 map->lock(map->lock_arg); in regcache_init()
230 ret = map->cache_ops->init(map); in regcache_init()
231 map->unlock(map->lock_arg); in regcache_init()
238 kfree(map->reg_defaults); in regcache_init()
239 if (map->cache_free) in regcache_init()
240 kfree(map->reg_defaults_raw); in regcache_init()
245 void regcache_exit(struct regmap *map) in regcache_exit() argument
247 if (map->cache_type == REGCACHE_NONE) in regcache_exit()
250 BUG_ON(!map->cache_ops); in regcache_exit()
252 kfree(map->reg_defaults); in regcache_exit()
253 if (map->cache_free) in regcache_exit()
254 kfree(map->reg_defaults_raw); in regcache_exit()
256 if (map->cache_ops->exit) { in regcache_exit()
257 dev_dbg(map->dev, "Destroying %s cache\n", in regcache_exit()
258 map->cache_ops->name); in regcache_exit()
259 map->lock(map->lock_arg); in regcache_exit()
260 map->cache_ops->exit(map); in regcache_exit()
261 map->unlock(map->lock_arg); in regcache_exit()
268 * @map: map to configure.
274 int regcache_read(struct regmap *map, in regcache_read() argument
279 if (map->cache_type == REGCACHE_NONE) in regcache_read()
282 BUG_ON(!map->cache_ops); in regcache_read()
284 if (!regmap_volatile(map, reg)) { in regcache_read()
285 ret = map->cache_ops->read(map, reg, value); in regcache_read()
288 trace_regmap_reg_read_cache(map, reg, *value); in regcache_read()
299 * @map: map to configure.
305 int regcache_write(struct regmap *map, in regcache_write() argument
308 if (map->cache_type == REGCACHE_NONE) in regcache_write()
311 BUG_ON(!map->cache_ops); in regcache_write()
313 if (!regmap_volatile(map, reg)) in regcache_write()
314 return map->cache_ops->write(map, reg, value); in regcache_write()
319 bool regcache_reg_needs_sync(struct regmap *map, unsigned int reg, in regcache_reg_needs_sync() argument
324 if (!regmap_writeable(map, reg)) in regcache_reg_needs_sync()
328 if (!map->no_sync_defaults) in regcache_reg_needs_sync()
332 ret = regcache_lookup_reg(map, reg); in regcache_reg_needs_sync()
333 if (ret >= 0 && val == map->reg_defaults[ret].def) in regcache_reg_needs_sync()
338 static int regcache_default_sync(struct regmap *map, unsigned int min, in regcache_default_sync() argument
343 for (reg = min; reg <= max; reg += map->reg_stride) { in regcache_default_sync()
347 if (regmap_volatile(map, reg) || in regcache_default_sync()
348 !regmap_writeable(map, reg)) in regcache_default_sync()
351 ret = regcache_read(map, reg, &val); in regcache_default_sync()
357 if (!regcache_reg_needs_sync(map, reg, val)) in regcache_default_sync()
360 map->cache_bypass = true; in regcache_default_sync()
361 ret = _regmap_write(map, reg, val); in regcache_default_sync()
362 map->cache_bypass = false; in regcache_default_sync()
364 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_default_sync()
368 dev_dbg(map->dev, "Synced register %#x, value %#x\n", reg, val); in regcache_default_sync()
382 * @map: map to configure.
390 int regcache_sync(struct regmap *map) in regcache_sync() argument
398 if (WARN_ON(map->cache_type == REGCACHE_NONE)) in regcache_sync()
401 BUG_ON(!map->cache_ops); in regcache_sync()
403 map->lock(map->lock_arg); in regcache_sync()
405 bypass = map->cache_bypass; in regcache_sync()
406 dev_dbg(map->dev, "Syncing %s cache\n", in regcache_sync()
407 map->cache_ops->name); in regcache_sync()
408 name = map->cache_ops->name; in regcache_sync()
409 trace_regcache_sync(map, name, "start"); in regcache_sync()
411 if (!map->cache_dirty) in regcache_sync()
415 map->cache_bypass = true; in regcache_sync()
416 for (i = 0; i < map->patch_regs; i++) { in regcache_sync()
417 ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def); in regcache_sync()
419 dev_err(map->dev, "Failed to write %x = %x: %d\n", in regcache_sync()
420 map->patch[i].reg, map->patch[i].def, ret); in regcache_sync()
424 map->cache_bypass = false; in regcache_sync()
426 if (map->cache_ops->sync) in regcache_sync()
427 ret = map->cache_ops->sync(map, 0, map->max_register); in regcache_sync()
429 ret = regcache_default_sync(map, 0, map->max_register); in regcache_sync()
432 map->cache_dirty = false; in regcache_sync()
436 map->cache_bypass = bypass; in regcache_sync()
437 map->no_sync_defaults = false; in regcache_sync()
445 rb_for_each(node, NULL, &map->range_tree, rbtree_all) { in regcache_sync()
450 if (regcache_read(map, this->selector_reg, &i) != 0) in regcache_sync()
453 ret = _regmap_write(map, this->selector_reg, i); in regcache_sync()
455 dev_err(map->dev, "Failed to write %x = %x: %d\n", in regcache_sync()
461 map->unlock(map->lock_arg); in regcache_sync()
463 regmap_async_complete(map); in regcache_sync()
465 trace_regcache_sync(map, name, "stop"); in regcache_sync()
474 * @map: map to sync.
483 int regcache_sync_region(struct regmap *map, unsigned int min, in regcache_sync_region() argument
490 if (WARN_ON(map->cache_type == REGCACHE_NONE)) in regcache_sync_region()
493 BUG_ON(!map->cache_ops); in regcache_sync_region()
495 map->lock(map->lock_arg); in regcache_sync_region()
498 bypass = map->cache_bypass; in regcache_sync_region()
500 name = map->cache_ops->name; in regcache_sync_region()
501 dev_dbg(map->dev, "Syncing %s cache from %d-%d\n", name, min, max); in regcache_sync_region()
503 trace_regcache_sync(map, name, "start region"); in regcache_sync_region()
505 if (!map->cache_dirty) in regcache_sync_region()
508 map->async = true; in regcache_sync_region()
510 if (map->cache_ops->sync) in regcache_sync_region()
511 ret = map->cache_ops->sync(map, min, max); in regcache_sync_region()
513 ret = regcache_default_sync(map, min, max); in regcache_sync_region()
517 map->cache_bypass = bypass; in regcache_sync_region()
518 map->async = false; in regcache_sync_region()
519 map->no_sync_defaults = false; in regcache_sync_region()
520 map->unlock(map->lock_arg); in regcache_sync_region()
522 regmap_async_complete(map); in regcache_sync_region()
524 trace_regcache_sync(map, name, "stop region"); in regcache_sync_region()
533 * @map: map to operate on
541 int regcache_drop_region(struct regmap *map, unsigned int min, in regcache_drop_region() argument
546 if (!map->cache_ops || !map->cache_ops->drop) in regcache_drop_region()
549 map->lock(map->lock_arg); in regcache_drop_region()
551 trace_regcache_drop_region(map, min, max); in regcache_drop_region()
553 ret = map->cache_ops->drop(map, min, max); in regcache_drop_region()
555 map->unlock(map->lock_arg); in regcache_drop_region()
562 * regcache_cache_only - Put a register map into cache only mode
564 * @map: map to configure
567 * When a register map is marked as cache only writes to the register
568 * map API will only update the register cache, they will not cause
573 void regcache_cache_only(struct regmap *map, bool enable) in regcache_cache_only() argument
575 map->lock(map->lock_arg); in regcache_cache_only()
576 WARN_ON(map->cache_type != REGCACHE_NONE && in regcache_cache_only()
577 map->cache_bypass && enable); in regcache_cache_only()
578 map->cache_only = enable; in regcache_cache_only()
579 trace_regmap_cache_only(map, enable); in regcache_cache_only()
580 map->unlock(map->lock_arg); in regcache_cache_only()
587 * @map: map to mark
597 void regcache_mark_dirty(struct regmap *map) in regcache_mark_dirty() argument
599 map->lock(map->lock_arg); in regcache_mark_dirty()
600 map->cache_dirty = true; in regcache_mark_dirty()
601 map->no_sync_defaults = true; in regcache_mark_dirty()
602 map->unlock(map->lock_arg); in regcache_mark_dirty()
607 * regcache_cache_bypass - Put a register map into cache bypass mode
609 * @map: map to configure
612 * When a register map is marked with the cache bypass option, writes
613 * to the register map API will only update the hardware and not
617 void regcache_cache_bypass(struct regmap *map, bool enable) in regcache_cache_bypass() argument
619 map->lock(map->lock_arg); in regcache_cache_bypass()
620 WARN_ON(map->cache_only && enable); in regcache_cache_bypass()
621 map->cache_bypass = enable; in regcache_cache_bypass()
622 trace_regmap_cache_bypass(map, enable); in regcache_cache_bypass()
623 map->unlock(map->lock_arg); in regcache_cache_bypass()
630 * @map: map to check
635 bool regcache_reg_cached(struct regmap *map, unsigned int reg) in regcache_reg_cached() argument
640 map->lock(map->lock_arg); in regcache_reg_cached()
642 ret = regcache_read(map, reg, &val); in regcache_reg_cached()
644 map->unlock(map->lock_arg); in regcache_reg_cached()
650 void regcache_set_val(struct regmap *map, void *base, unsigned int idx, in regcache_set_val() argument
654 if (map->format.format_val) { in regcache_set_val()
655 map->format.format_val(base + (map->cache_word_size * idx), in regcache_set_val()
660 switch (map->cache_word_size) { in regcache_set_val()
684 unsigned int regcache_get_val(struct regmap *map, const void *base, in regcache_get_val() argument
691 if (map->format.parse_val) in regcache_get_val()
692 return map->format.parse_val(regcache_get_val_addr(map, base, in regcache_get_val()
695 switch (map->cache_word_size) { in regcache_get_val()
726 int regcache_lookup_reg(struct regmap *map, unsigned int reg) in regcache_lookup_reg() argument
734 r = bsearch(&key, map->reg_defaults, map->num_reg_defaults, in regcache_lookup_reg()
738 return r - map->reg_defaults; in regcache_lookup_reg()
751 int regcache_sync_val(struct regmap *map, unsigned int reg, unsigned int val) in regcache_sync_val() argument
755 if (!regcache_reg_needs_sync(map, reg, val)) in regcache_sync_val()
758 map->cache_bypass = true; in regcache_sync_val()
760 ret = _regmap_write(map, reg, val); in regcache_sync_val()
762 map->cache_bypass = false; in regcache_sync_val()
765 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_sync_val()
769 dev_dbg(map->dev, "Synced register %#x, value %#x\n", in regcache_sync_val()
775 static int regcache_sync_block_single(struct regmap *map, void *block, in regcache_sync_block_single() argument
784 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_single()
787 !regmap_writeable(map, regtmp)) in regcache_sync_block_single()
790 val = regcache_get_val(map, block, i); in regcache_sync_block_single()
791 ret = regcache_sync_val(map, regtmp, val); in regcache_sync_block_single()
799 static int regcache_sync_block_raw_flush(struct regmap *map, const void **data, in regcache_sync_block_raw_flush() argument
802 size_t val_bytes = map->format.val_bytes; in regcache_sync_block_raw_flush()
808 count = (cur - base) / map->reg_stride; in regcache_sync_block_raw_flush()
810 dev_dbg(map->dev, "Writing %zu bytes for %d registers from 0x%x-0x%x\n", in regcache_sync_block_raw_flush()
811 count * val_bytes, count, base, cur - map->reg_stride); in regcache_sync_block_raw_flush()
813 map->cache_bypass = true; in regcache_sync_block_raw_flush()
815 ret = _regmap_raw_write(map, base, *data, count * val_bytes, false); in regcache_sync_block_raw_flush()
817 dev_err(map->dev, "Unable to sync registers %#x-%#x. %d\n", in regcache_sync_block_raw_flush()
818 base, cur - map->reg_stride, ret); in regcache_sync_block_raw_flush()
820 map->cache_bypass = false; in regcache_sync_block_raw_flush()
827 static int regcache_sync_block_raw(struct regmap *map, void *block, in regcache_sync_block_raw() argument
839 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_raw()
842 !regmap_writeable(map, regtmp)) { in regcache_sync_block_raw()
843 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
850 val = regcache_get_val(map, block, i); in regcache_sync_block_raw()
851 if (!regcache_reg_needs_sync(map, regtmp, val)) { in regcache_sync_block_raw()
852 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
860 data = regcache_get_val_addr(map, block, i); in regcache_sync_block_raw()
865 return regcache_sync_block_raw_flush(map, &data, base, regtmp + in regcache_sync_block_raw()
866 map->reg_stride); in regcache_sync_block_raw()
869 int regcache_sync_block(struct regmap *map, void *block, in regcache_sync_block() argument
874 if (regmap_can_raw_write(map) && !map->use_single_write) in regcache_sync_block()
875 return regcache_sync_block_raw(map, block, cache_present, in regcache_sync_block()
878 return regcache_sync_block_single(map, block, cache_present, in regcache_sync_block()