Lines Matching full:map
24 static int regcache_hw_init(struct regmap *map) in regcache_hw_init() argument
32 if (!map->num_reg_defaults_raw) in regcache_hw_init()
36 for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) in regcache_hw_init()
37 if (regmap_readable(map, i * map->reg_stride) && in regcache_hw_init()
38 !regmap_volatile(map, i * map->reg_stride)) in regcache_hw_init()
43 map->cache_bypass = true; in regcache_hw_init()
47 map->num_reg_defaults = count; in regcache_hw_init()
48 map->reg_defaults = kmalloc_array(count, sizeof(struct reg_default), in regcache_hw_init()
50 if (!map->reg_defaults) in regcache_hw_init()
53 if (!map->reg_defaults_raw) { in regcache_hw_init()
54 bool cache_bypass = map->cache_bypass; in regcache_hw_init()
55 dev_warn(map->dev, "No cache defaults, reading back from HW\n"); in regcache_hw_init()
58 map->cache_bypass = true; in regcache_hw_init()
59 tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL); in regcache_hw_init()
64 ret = regmap_raw_read(map, 0, tmp_buf, in regcache_hw_init()
65 map->cache_size_raw); in regcache_hw_init()
66 map->cache_bypass = cache_bypass; in regcache_hw_init()
68 map->reg_defaults_raw = tmp_buf; in regcache_hw_init()
69 map->cache_free = true; in regcache_hw_init()
76 for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) { in regcache_hw_init()
77 reg = i * map->reg_stride; in regcache_hw_init()
79 if (!regmap_readable(map, reg)) in regcache_hw_init()
82 if (regmap_volatile(map, reg)) in regcache_hw_init()
85 if (map->reg_defaults_raw) { in regcache_hw_init()
86 val = regcache_get_val(map, map->reg_defaults_raw, i); in regcache_hw_init()
88 bool cache_bypass = map->cache_bypass; in regcache_hw_init()
90 map->cache_bypass = true; in regcache_hw_init()
91 ret = regmap_read(map, reg, &val); in regcache_hw_init()
92 map->cache_bypass = cache_bypass; in regcache_hw_init()
94 dev_err(map->dev, "Failed to read %d: %d\n", in regcache_hw_init()
100 map->reg_defaults[j].reg = reg; in regcache_hw_init()
101 map->reg_defaults[j].def = val; in regcache_hw_init()
108 kfree(map->reg_defaults); in regcache_hw_init()
113 int regcache_init(struct regmap *map, const struct regmap_config *config) in regcache_init() argument
119 if (map->cache_type == REGCACHE_NONE) { in regcache_init()
121 dev_warn(map->dev, in regcache_init()
124 map->cache_bypass = true; in regcache_init()
129 dev_err(map->dev, in regcache_init()
135 dev_err(map->dev, in regcache_init()
141 if (config->reg_defaults[i].reg % map->reg_stride) in regcache_init()
145 if (cache_types[i]->type == map->cache_type) in regcache_init()
149 dev_err(map->dev, "Could not match cache type: %d\n", in regcache_init()
150 map->cache_type); in regcache_init()
154 map->num_reg_defaults = config->num_reg_defaults; in regcache_init()
155 map->num_reg_defaults_raw = config->num_reg_defaults_raw; in regcache_init()
156 map->reg_defaults_raw = config->reg_defaults_raw; in regcache_init()
157 map->cache_word_size = DIV_ROUND_UP(config->val_bits, 8); in regcache_init()
158 map->cache_size_raw = map->cache_word_size * config->num_reg_defaults_raw; in regcache_init()
160 map->cache = NULL; in regcache_init()
161 map->cache_ops = cache_types[i]; in regcache_init()
163 if (!map->cache_ops->read || in regcache_init()
164 !map->cache_ops->write || in regcache_init()
165 !map->cache_ops->name) in regcache_init()
173 tmp_buf = kmemdup(config->reg_defaults, map->num_reg_defaults * in regcache_init()
177 map->reg_defaults = tmp_buf; in regcache_init()
178 } else if (map->num_reg_defaults_raw) { in regcache_init()
183 ret = regcache_hw_init(map); in regcache_init()
186 if (map->cache_bypass) in regcache_init()
190 if (!map->max_register && map->num_reg_defaults_raw) in regcache_init()
191 map->max_register = (map->num_reg_defaults_raw - 1) * map->reg_stride; in regcache_init()
193 if (map->cache_ops->init) { in regcache_init()
194 dev_dbg(map->dev, "Initializing %s cache\n", in regcache_init()
195 map->cache_ops->name); in regcache_init()
196 ret = map->cache_ops->init(map); in regcache_init()
203 kfree(map->reg_defaults); in regcache_init()
204 if (map->cache_free) in regcache_init()
205 kfree(map->reg_defaults_raw); in regcache_init()
210 void regcache_exit(struct regmap *map) in regcache_exit() argument
212 if (map->cache_type == REGCACHE_NONE) in regcache_exit()
215 BUG_ON(!map->cache_ops); in regcache_exit()
217 kfree(map->reg_defaults); in regcache_exit()
218 if (map->cache_free) in regcache_exit()
219 kfree(map->reg_defaults_raw); in regcache_exit()
221 if (map->cache_ops->exit) { in regcache_exit()
222 dev_dbg(map->dev, "Destroying %s cache\n", in regcache_exit()
223 map->cache_ops->name); in regcache_exit()
224 map->cache_ops->exit(map); in regcache_exit()
231 * @map: map to configure.
237 int regcache_read(struct regmap *map, in regcache_read() argument
242 if (map->cache_type == REGCACHE_NONE) in regcache_read()
245 BUG_ON(!map->cache_ops); in regcache_read()
247 if (!regmap_volatile(map, reg)) { in regcache_read()
248 ret = map->cache_ops->read(map, reg, value); in regcache_read()
251 trace_regmap_reg_read_cache(map, reg, *value); in regcache_read()
262 * @map: map to configure.
268 int regcache_write(struct regmap *map, in regcache_write() argument
271 if (map->cache_type == REGCACHE_NONE) in regcache_write()
274 BUG_ON(!map->cache_ops); in regcache_write()
276 if (!regmap_volatile(map, reg)) in regcache_write()
277 return map->cache_ops->write(map, reg, value); in regcache_write()
282 bool regcache_reg_needs_sync(struct regmap *map, unsigned int reg, in regcache_reg_needs_sync() argument
287 if (!regmap_writeable(map, reg)) in regcache_reg_needs_sync()
291 if (!map->no_sync_defaults) in regcache_reg_needs_sync()
295 ret = regcache_lookup_reg(map, reg); in regcache_reg_needs_sync()
296 if (ret >= 0 && val == map->reg_defaults[ret].def) in regcache_reg_needs_sync()
301 static int regcache_default_sync(struct regmap *map, unsigned int min, in regcache_default_sync() argument
306 for (reg = min; reg <= max; reg += map->reg_stride) { in regcache_default_sync()
310 if (regmap_volatile(map, reg) || in regcache_default_sync()
311 !regmap_writeable(map, reg)) in regcache_default_sync()
314 ret = regcache_read(map, reg, &val); in regcache_default_sync()
320 if (!regcache_reg_needs_sync(map, reg, val)) in regcache_default_sync()
323 map->cache_bypass = true; in regcache_default_sync()
324 ret = _regmap_write(map, reg, val); in regcache_default_sync()
325 map->cache_bypass = false; in regcache_default_sync()
327 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_default_sync()
331 dev_dbg(map->dev, "Synced register %#x, value %#x\n", reg, val); in regcache_default_sync()
340 * @map: map to configure.
348 int regcache_sync(struct regmap *map) in regcache_sync() argument
355 if (WARN_ON(map->cache_type == REGCACHE_NONE)) in regcache_sync()
358 BUG_ON(!map->cache_ops); in regcache_sync()
360 map->lock(map->lock_arg); in regcache_sync()
362 bypass = map->cache_bypass; in regcache_sync()
363 dev_dbg(map->dev, "Syncing %s cache\n", in regcache_sync()
364 map->cache_ops->name); in regcache_sync()
365 name = map->cache_ops->name; in regcache_sync()
366 trace_regcache_sync(map, name, "start"); in regcache_sync()
368 if (!map->cache_dirty) in regcache_sync()
372 map->cache_bypass = true; in regcache_sync()
373 for (i = 0; i < map->patch_regs; i++) { in regcache_sync()
374 ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def); in regcache_sync()
376 dev_err(map->dev, "Failed to write %x = %x: %d\n", in regcache_sync()
377 map->patch[i].reg, map->patch[i].def, ret); in regcache_sync()
381 map->cache_bypass = false; in regcache_sync()
383 if (map->cache_ops->sync) in regcache_sync()
384 ret = map->cache_ops->sync(map, 0, map->max_register); in regcache_sync()
386 ret = regcache_default_sync(map, 0, map->max_register); in regcache_sync()
389 map->cache_dirty = false; in regcache_sync()
393 map->cache_bypass = bypass; in regcache_sync()
394 map->no_sync_defaults = false; in regcache_sync()
395 map->unlock(map->lock_arg); in regcache_sync()
397 regmap_async_complete(map); in regcache_sync()
399 trace_regcache_sync(map, name, "stop"); in regcache_sync()
408 * @map: map to sync.
417 int regcache_sync_region(struct regmap *map, unsigned int min, in regcache_sync_region() argument
424 if (WARN_ON(map->cache_type == REGCACHE_NONE)) in regcache_sync_region()
427 BUG_ON(!map->cache_ops); in regcache_sync_region()
429 map->lock(map->lock_arg); in regcache_sync_region()
432 bypass = map->cache_bypass; in regcache_sync_region()
434 name = map->cache_ops->name; in regcache_sync_region()
435 dev_dbg(map->dev, "Syncing %s cache from %d-%d\n", name, min, max); in regcache_sync_region()
437 trace_regcache_sync(map, name, "start region"); in regcache_sync_region()
439 if (!map->cache_dirty) in regcache_sync_region()
442 map->async = true; in regcache_sync_region()
444 if (map->cache_ops->sync) in regcache_sync_region()
445 ret = map->cache_ops->sync(map, min, max); in regcache_sync_region()
447 ret = regcache_default_sync(map, min, max); in regcache_sync_region()
451 map->cache_bypass = bypass; in regcache_sync_region()
452 map->async = false; in regcache_sync_region()
453 map->no_sync_defaults = false; in regcache_sync_region()
454 map->unlock(map->lock_arg); in regcache_sync_region()
456 regmap_async_complete(map); in regcache_sync_region()
458 trace_regcache_sync(map, name, "stop region"); in regcache_sync_region()
467 * @map: map to operate on
475 int regcache_drop_region(struct regmap *map, unsigned int min, in regcache_drop_region() argument
480 if (!map->cache_ops || !map->cache_ops->drop) in regcache_drop_region()
483 map->lock(map->lock_arg); in regcache_drop_region()
485 trace_regcache_drop_region(map, min, max); in regcache_drop_region()
487 ret = map->cache_ops->drop(map, min, max); in regcache_drop_region()
489 map->unlock(map->lock_arg); in regcache_drop_region()
496 * regcache_cache_only - Put a register map into cache only mode
498 * @map: map to configure
501 * When a register map is marked as cache only writes to the register
502 * map API will only update the register cache, they will not cause
507 void regcache_cache_only(struct regmap *map, bool enable) in regcache_cache_only() argument
509 map->lock(map->lock_arg); in regcache_cache_only()
510 WARN_ON(map->cache_type != REGCACHE_NONE && in regcache_cache_only()
511 map->cache_bypass && enable); in regcache_cache_only()
512 map->cache_only = enable; in regcache_cache_only()
513 trace_regmap_cache_only(map, enable); in regcache_cache_only()
514 map->unlock(map->lock_arg); in regcache_cache_only()
521 * @map: map to mark
531 void regcache_mark_dirty(struct regmap *map) in regcache_mark_dirty() argument
533 map->lock(map->lock_arg); in regcache_mark_dirty()
534 map->cache_dirty = true; in regcache_mark_dirty()
535 map->no_sync_defaults = true; in regcache_mark_dirty()
536 map->unlock(map->lock_arg); in regcache_mark_dirty()
541 * regcache_cache_bypass - Put a register map into cache bypass mode
543 * @map: map to configure
546 * When a register map is marked with the cache bypass option, writes
547 * to the register map API will only update the hardware and not
551 void regcache_cache_bypass(struct regmap *map, bool enable) in regcache_cache_bypass() argument
553 map->lock(map->lock_arg); in regcache_cache_bypass()
554 WARN_ON(map->cache_only && enable); in regcache_cache_bypass()
555 map->cache_bypass = enable; in regcache_cache_bypass()
556 trace_regmap_cache_bypass(map, enable); in regcache_cache_bypass()
557 map->unlock(map->lock_arg); in regcache_cache_bypass()
564 * @map: map to check
569 bool regcache_reg_cached(struct regmap *map, unsigned int reg) in regcache_reg_cached() argument
574 map->lock(map->lock_arg); in regcache_reg_cached()
576 ret = regcache_read(map, reg, &val); in regcache_reg_cached()
578 map->unlock(map->lock_arg); in regcache_reg_cached()
584 void regcache_set_val(struct regmap *map, void *base, unsigned int idx, in regcache_set_val() argument
588 if (map->format.format_val) { in regcache_set_val()
589 map->format.format_val(base + (map->cache_word_size * idx), in regcache_set_val()
594 switch (map->cache_word_size) { in regcache_set_val()
618 unsigned int regcache_get_val(struct regmap *map, const void *base, in regcache_get_val() argument
625 if (map->format.parse_val) in regcache_get_val()
626 return map->format.parse_val(regcache_get_val_addr(map, base, in regcache_get_val()
629 switch (map->cache_word_size) { in regcache_get_val()
660 int regcache_lookup_reg(struct regmap *map, unsigned int reg) in regcache_lookup_reg() argument
668 r = bsearch(&key, map->reg_defaults, map->num_reg_defaults, in regcache_lookup_reg()
672 return r - map->reg_defaults; in regcache_lookup_reg()
685 int regcache_sync_val(struct regmap *map, unsigned int reg, unsigned int val) in regcache_sync_val() argument
689 if (!regcache_reg_needs_sync(map, reg, val)) in regcache_sync_val()
692 map->cache_bypass = true; in regcache_sync_val()
694 ret = _regmap_write(map, reg, val); in regcache_sync_val()
696 map->cache_bypass = false; in regcache_sync_val()
699 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_sync_val()
703 dev_dbg(map->dev, "Synced register %#x, value %#x\n", in regcache_sync_val()
709 static int regcache_sync_block_single(struct regmap *map, void *block, in regcache_sync_block_single() argument
718 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_single()
721 !regmap_writeable(map, regtmp)) in regcache_sync_block_single()
724 val = regcache_get_val(map, block, i); in regcache_sync_block_single()
725 ret = regcache_sync_val(map, regtmp, val); in regcache_sync_block_single()
733 static int regcache_sync_block_raw_flush(struct regmap *map, const void **data, in regcache_sync_block_raw_flush() argument
736 size_t val_bytes = map->format.val_bytes; in regcache_sync_block_raw_flush()
742 count = (cur - base) / map->reg_stride; in regcache_sync_block_raw_flush()
744 dev_dbg(map->dev, "Writing %zu bytes for %d registers from 0x%x-0x%x\n", in regcache_sync_block_raw_flush()
745 count * val_bytes, count, base, cur - map->reg_stride); in regcache_sync_block_raw_flush()
747 map->cache_bypass = true; in regcache_sync_block_raw_flush()
749 ret = _regmap_raw_write(map, base, *data, count * val_bytes, false); in regcache_sync_block_raw_flush()
751 dev_err(map->dev, "Unable to sync registers %#x-%#x. %d\n", in regcache_sync_block_raw_flush()
752 base, cur - map->reg_stride, ret); in regcache_sync_block_raw_flush()
754 map->cache_bypass = false; in regcache_sync_block_raw_flush()
761 static int regcache_sync_block_raw(struct regmap *map, void *block, in regcache_sync_block_raw() argument
773 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_raw()
776 !regmap_writeable(map, regtmp)) { in regcache_sync_block_raw()
777 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
784 val = regcache_get_val(map, block, i); in regcache_sync_block_raw()
785 if (!regcache_reg_needs_sync(map, regtmp, val)) { in regcache_sync_block_raw()
786 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
794 data = regcache_get_val_addr(map, block, i); in regcache_sync_block_raw()
799 return regcache_sync_block_raw_flush(map, &data, base, regtmp + in regcache_sync_block_raw()
800 map->reg_stride); in regcache_sync_block_raw()
803 int regcache_sync_block(struct regmap *map, void *block, in regcache_sync_block() argument
808 if (regmap_can_raw_write(map) && !map->use_single_write) in regcache_sync_block()
809 return regcache_sync_block_raw(map, block, cache_present, in regcache_sync_block()
812 return regcache_sync_block_single(map, block, cache_present, in regcache_sync_block()