Lines Matching full:map
26 static int regcache_hw_init(struct regmap *map) in regcache_hw_init() argument
34 if (!map->num_reg_defaults_raw) in regcache_hw_init()
38 for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) in regcache_hw_init()
39 if (regmap_readable(map, i * map->reg_stride) && in regcache_hw_init()
40 !regmap_volatile(map, i * map->reg_stride)) in regcache_hw_init()
45 map->cache_bypass = true; in regcache_hw_init()
49 map->num_reg_defaults = count; in regcache_hw_init()
50 map->reg_defaults = kmalloc_array(count, sizeof(struct reg_default), in regcache_hw_init()
52 if (!map->reg_defaults) in regcache_hw_init()
55 if (!map->reg_defaults_raw) { in regcache_hw_init()
56 bool cache_bypass = map->cache_bypass; in regcache_hw_init()
57 dev_warn(map->dev, "No cache defaults, reading back from HW\n"); in regcache_hw_init()
60 map->cache_bypass = true; in regcache_hw_init()
61 tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL); in regcache_hw_init()
66 ret = regmap_raw_read(map, 0, tmp_buf, in regcache_hw_init()
67 map->cache_size_raw); in regcache_hw_init()
68 map->cache_bypass = cache_bypass; in regcache_hw_init()
70 map->reg_defaults_raw = tmp_buf; in regcache_hw_init()
71 map->cache_free = true; in regcache_hw_init()
78 for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) { in regcache_hw_init()
79 reg = i * map->reg_stride; in regcache_hw_init()
81 if (!regmap_readable(map, reg)) in regcache_hw_init()
84 if (regmap_volatile(map, reg)) in regcache_hw_init()
87 if (map->reg_defaults_raw) { in regcache_hw_init()
88 val = regcache_get_val(map, map->reg_defaults_raw, i); in regcache_hw_init()
90 bool cache_bypass = map->cache_bypass; in regcache_hw_init()
92 map->cache_bypass = true; in regcache_hw_init()
93 ret = regmap_read(map, reg, &val); in regcache_hw_init()
94 map->cache_bypass = cache_bypass; in regcache_hw_init()
96 dev_err(map->dev, "Failed to read %d: %d\n", in regcache_hw_init()
102 map->reg_defaults[j].reg = reg; in regcache_hw_init()
103 map->reg_defaults[j].def = val; in regcache_hw_init()
110 kfree(map->reg_defaults); in regcache_hw_init()
115 int regcache_init(struct regmap *map, const struct regmap_config *config) in regcache_init() argument
121 if (map->cache_type == REGCACHE_NONE) { in regcache_init()
123 dev_warn(map->dev, in regcache_init()
126 map->cache_bypass = true; in regcache_init()
131 dev_err(map->dev, in regcache_init()
137 dev_err(map->dev, in regcache_init()
143 if (config->reg_defaults[i].reg % map->reg_stride) in regcache_init()
147 if (cache_types[i]->type == map->cache_type) in regcache_init()
151 dev_err(map->dev, "Could not match compress type: %d\n", in regcache_init()
152 map->cache_type); in regcache_init()
156 map->num_reg_defaults = config->num_reg_defaults; in regcache_init()
157 map->num_reg_defaults_raw = config->num_reg_defaults_raw; in regcache_init()
158 map->reg_defaults_raw = config->reg_defaults_raw; in regcache_init()
159 map->cache_word_size = DIV_ROUND_UP(config->val_bits, 8); in regcache_init()
160 map->cache_size_raw = map->cache_word_size * config->num_reg_defaults_raw; in regcache_init()
162 map->cache = NULL; in regcache_init()
163 map->cache_ops = cache_types[i]; in regcache_init()
165 if (!map->cache_ops->read || in regcache_init()
166 !map->cache_ops->write || in regcache_init()
167 !map->cache_ops->name) in regcache_init()
175 tmp_buf = kmemdup(config->reg_defaults, map->num_reg_defaults * in regcache_init()
179 map->reg_defaults = tmp_buf; in regcache_init()
180 } else if (map->num_reg_defaults_raw) { in regcache_init()
185 ret = regcache_hw_init(map); in regcache_init()
188 if (map->cache_bypass) in regcache_init()
192 if (!map->max_register && map->num_reg_defaults_raw) in regcache_init()
193 map->max_register = (map->num_reg_defaults_raw - 1) * map->reg_stride; in regcache_init()
195 if (map->cache_ops->init) { in regcache_init()
196 dev_dbg(map->dev, "Initializing %s cache\n", in regcache_init()
197 map->cache_ops->name); in regcache_init()
198 ret = map->cache_ops->init(map); in regcache_init()
205 kfree(map->reg_defaults); in regcache_init()
206 if (map->cache_free) in regcache_init()
207 kfree(map->reg_defaults_raw); in regcache_init()
212 void regcache_exit(struct regmap *map) in regcache_exit() argument
214 if (map->cache_type == REGCACHE_NONE) in regcache_exit()
217 BUG_ON(!map->cache_ops); in regcache_exit()
219 kfree(map->reg_defaults); in regcache_exit()
220 if (map->cache_free) in regcache_exit()
221 kfree(map->reg_defaults_raw); in regcache_exit()
223 if (map->cache_ops->exit) { in regcache_exit()
224 dev_dbg(map->dev, "Destroying %s cache\n", in regcache_exit()
225 map->cache_ops->name); in regcache_exit()
226 map->cache_ops->exit(map); in regcache_exit()
233 * @map: map to configure.
239 int regcache_read(struct regmap *map, in regcache_read() argument
244 if (map->cache_type == REGCACHE_NONE) in regcache_read()
247 BUG_ON(!map->cache_ops); in regcache_read()
249 if (!regmap_volatile(map, reg)) { in regcache_read()
250 ret = map->cache_ops->read(map, reg, value); in regcache_read()
253 trace_regmap_reg_read_cache(map, reg, *value); in regcache_read()
264 * @map: map to configure.
270 int regcache_write(struct regmap *map, in regcache_write() argument
273 if (map->cache_type == REGCACHE_NONE) in regcache_write()
276 BUG_ON(!map->cache_ops); in regcache_write()
278 if (!regmap_volatile(map, reg)) in regcache_write()
279 return map->cache_ops->write(map, reg, value); in regcache_write()
284 static bool regcache_reg_needs_sync(struct regmap *map, unsigned int reg, in regcache_reg_needs_sync() argument
290 if (!map->no_sync_defaults) in regcache_reg_needs_sync()
294 ret = regcache_lookup_reg(map, reg); in regcache_reg_needs_sync()
295 if (ret >= 0 && val == map->reg_defaults[ret].def) in regcache_reg_needs_sync()
300 static int regcache_default_sync(struct regmap *map, unsigned int min, in regcache_default_sync() argument
305 for (reg = min; reg <= max; reg += map->reg_stride) { in regcache_default_sync()
309 if (regmap_volatile(map, reg) || in regcache_default_sync()
310 !regmap_writeable(map, reg)) in regcache_default_sync()
313 ret = regcache_read(map, reg, &val); in regcache_default_sync()
317 if (!regcache_reg_needs_sync(map, reg, val)) in regcache_default_sync()
320 map->cache_bypass = true; in regcache_default_sync()
321 ret = _regmap_write(map, reg, val); in regcache_default_sync()
322 map->cache_bypass = false; in regcache_default_sync()
324 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_default_sync()
328 dev_dbg(map->dev, "Synced register %#x, value %#x\n", reg, val); in regcache_default_sync()
337 * @map: map to configure.
345 int regcache_sync(struct regmap *map) in regcache_sync() argument
352 BUG_ON(!map->cache_ops); in regcache_sync()
354 map->lock(map->lock_arg); in regcache_sync()
356 bypass = map->cache_bypass; in regcache_sync()
357 dev_dbg(map->dev, "Syncing %s cache\n", in regcache_sync()
358 map->cache_ops->name); in regcache_sync()
359 name = map->cache_ops->name; in regcache_sync()
360 trace_regcache_sync(map, name, "start"); in regcache_sync()
362 if (!map->cache_dirty) in regcache_sync()
365 map->async = true; in regcache_sync()
368 map->cache_bypass = true; in regcache_sync()
369 for (i = 0; i < map->patch_regs; i++) { in regcache_sync()
370 ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def); in regcache_sync()
372 dev_err(map->dev, "Failed to write %x = %x: %d\n", in regcache_sync()
373 map->patch[i].reg, map->patch[i].def, ret); in regcache_sync()
377 map->cache_bypass = false; in regcache_sync()
379 if (map->cache_ops->sync) in regcache_sync()
380 ret = map->cache_ops->sync(map, 0, map->max_register); in regcache_sync()
382 ret = regcache_default_sync(map, 0, map->max_register); in regcache_sync()
385 map->cache_dirty = false; in regcache_sync()
389 map->async = false; in regcache_sync()
390 map->cache_bypass = bypass; in regcache_sync()
391 map->no_sync_defaults = false; in regcache_sync()
392 map->unlock(map->lock_arg); in regcache_sync()
394 regmap_async_complete(map); in regcache_sync()
396 trace_regcache_sync(map, name, "stop"); in regcache_sync()
405 * @map: map to sync.
414 int regcache_sync_region(struct regmap *map, unsigned int min, in regcache_sync_region() argument
421 BUG_ON(!map->cache_ops); in regcache_sync_region()
423 map->lock(map->lock_arg); in regcache_sync_region()
426 bypass = map->cache_bypass; in regcache_sync_region()
428 name = map->cache_ops->name; in regcache_sync_region()
429 dev_dbg(map->dev, "Syncing %s cache from %d-%d\n", name, min, max); in regcache_sync_region()
431 trace_regcache_sync(map, name, "start region"); in regcache_sync_region()
433 if (!map->cache_dirty) in regcache_sync_region()
436 map->async = true; in regcache_sync_region()
438 if (map->cache_ops->sync) in regcache_sync_region()
439 ret = map->cache_ops->sync(map, min, max); in regcache_sync_region()
441 ret = regcache_default_sync(map, min, max); in regcache_sync_region()
445 map->cache_bypass = bypass; in regcache_sync_region()
446 map->async = false; in regcache_sync_region()
447 map->no_sync_defaults = false; in regcache_sync_region()
448 map->unlock(map->lock_arg); in regcache_sync_region()
450 regmap_async_complete(map); in regcache_sync_region()
452 trace_regcache_sync(map, name, "stop region"); in regcache_sync_region()
461 * @map: map to operate on
469 int regcache_drop_region(struct regmap *map, unsigned int min, in regcache_drop_region() argument
474 if (!map->cache_ops || !map->cache_ops->drop) in regcache_drop_region()
477 map->lock(map->lock_arg); in regcache_drop_region()
479 trace_regcache_drop_region(map, min, max); in regcache_drop_region()
481 ret = map->cache_ops->drop(map, min, max); in regcache_drop_region()
483 map->unlock(map->lock_arg); in regcache_drop_region()
490 * regcache_cache_only - Put a register map into cache only mode
492 * @map: map to configure
495 * When a register map is marked as cache only writes to the register
496 * map API will only update the register cache, they will not cause
501 void regcache_cache_only(struct regmap *map, bool enable) in regcache_cache_only() argument
503 map->lock(map->lock_arg); in regcache_cache_only()
504 WARN_ON(map->cache_type != REGCACHE_NONE && in regcache_cache_only()
505 map->cache_bypass && enable); in regcache_cache_only()
506 map->cache_only = enable; in regcache_cache_only()
507 trace_regmap_cache_only(map, enable); in regcache_cache_only()
508 map->unlock(map->lock_arg); in regcache_cache_only()
515 * @map: map to mark
525 void regcache_mark_dirty(struct regmap *map) in regcache_mark_dirty() argument
527 map->lock(map->lock_arg); in regcache_mark_dirty()
528 map->cache_dirty = true; in regcache_mark_dirty()
529 map->no_sync_defaults = true; in regcache_mark_dirty()
530 map->unlock(map->lock_arg); in regcache_mark_dirty()
535 * regcache_cache_bypass - Put a register map into cache bypass mode
537 * @map: map to configure
540 * When a register map is marked with the cache bypass option, writes
541 * to the register map API will only update the hardware and not
545 void regcache_cache_bypass(struct regmap *map, bool enable) in regcache_cache_bypass() argument
547 map->lock(map->lock_arg); in regcache_cache_bypass()
548 WARN_ON(map->cache_only && enable); in regcache_cache_bypass()
549 map->cache_bypass = enable; in regcache_cache_bypass()
550 trace_regmap_cache_bypass(map, enable); in regcache_cache_bypass()
551 map->unlock(map->lock_arg); in regcache_cache_bypass()
555 bool regcache_set_val(struct regmap *map, void *base, unsigned int idx, in regcache_set_val() argument
558 if (regcache_get_val(map, base, idx) == val) in regcache_set_val()
562 if (map->format.format_val) { in regcache_set_val()
563 map->format.format_val(base + (map->cache_word_size * idx), in regcache_set_val()
568 switch (map->cache_word_size) { in regcache_set_val()
601 unsigned int regcache_get_val(struct regmap *map, const void *base, in regcache_get_val() argument
608 if (map->format.parse_val) in regcache_get_val()
609 return map->format.parse_val(regcache_get_val_addr(map, base, in regcache_get_val()
612 switch (map->cache_word_size) { in regcache_get_val()
650 int regcache_lookup_reg(struct regmap *map, unsigned int reg) in regcache_lookup_reg() argument
658 r = bsearch(&key, map->reg_defaults, map->num_reg_defaults, in regcache_lookup_reg()
662 return r - map->reg_defaults; in regcache_lookup_reg()
675 static int regcache_sync_block_single(struct regmap *map, void *block, in regcache_sync_block_single() argument
684 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_single()
687 !regmap_writeable(map, regtmp)) in regcache_sync_block_single()
690 val = regcache_get_val(map, block, i); in regcache_sync_block_single()
691 if (!regcache_reg_needs_sync(map, regtmp, val)) in regcache_sync_block_single()
694 map->cache_bypass = true; in regcache_sync_block_single()
696 ret = _regmap_write(map, regtmp, val); in regcache_sync_block_single()
698 map->cache_bypass = false; in regcache_sync_block_single()
700 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_sync_block_single()
704 dev_dbg(map->dev, "Synced register %#x, value %#x\n", in regcache_sync_block_single()
711 static int regcache_sync_block_raw_flush(struct regmap *map, const void **data, in regcache_sync_block_raw_flush() argument
714 size_t val_bytes = map->format.val_bytes; in regcache_sync_block_raw_flush()
720 count = (cur - base) / map->reg_stride; in regcache_sync_block_raw_flush()
722 dev_dbg(map->dev, "Writing %zu bytes for %d registers from 0x%x-0x%x\n", in regcache_sync_block_raw_flush()
723 count * val_bytes, count, base, cur - map->reg_stride); in regcache_sync_block_raw_flush()
725 map->cache_bypass = true; in regcache_sync_block_raw_flush()
727 ret = _regmap_raw_write(map, base, *data, count * val_bytes, false); in regcache_sync_block_raw_flush()
729 dev_err(map->dev, "Unable to sync registers %#x-%#x. %d\n", in regcache_sync_block_raw_flush()
730 base, cur - map->reg_stride, ret); in regcache_sync_block_raw_flush()
732 map->cache_bypass = false; in regcache_sync_block_raw_flush()
739 static int regcache_sync_block_raw(struct regmap *map, void *block, in regcache_sync_block_raw() argument
751 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_raw()
754 !regmap_writeable(map, regtmp)) { in regcache_sync_block_raw()
755 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
762 val = regcache_get_val(map, block, i); in regcache_sync_block_raw()
763 if (!regcache_reg_needs_sync(map, regtmp, val)) { in regcache_sync_block_raw()
764 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
772 data = regcache_get_val_addr(map, block, i); in regcache_sync_block_raw()
777 return regcache_sync_block_raw_flush(map, &data, base, regtmp + in regcache_sync_block_raw()
778 map->reg_stride); in regcache_sync_block_raw()
781 int regcache_sync_block(struct regmap *map, void *block, in regcache_sync_block() argument
786 if (regmap_can_raw_write(map) && !map->use_single_write) in regcache_sync_block()
787 return regcache_sync_block_raw(map, block, cache_present, in regcache_sync_block()
790 return regcache_sync_block_single(map, block, cache_present, in regcache_sync_block()