Lines Matching refs:map

30 static int regcache_hw_init(struct regmap *map)  in regcache_hw_init()  argument
38 if (!map->num_reg_defaults_raw) in regcache_hw_init()
42 for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) in regcache_hw_init()
43 if (regmap_readable(map, i * map->reg_stride) && in regcache_hw_init()
44 !regmap_volatile(map, i * map->reg_stride)) in regcache_hw_init()
49 map->cache_bypass = true; in regcache_hw_init()
53 map->num_reg_defaults = count; in regcache_hw_init()
54 map->reg_defaults = kmalloc_array(count, sizeof(struct reg_default), in regcache_hw_init()
56 if (!map->reg_defaults) in regcache_hw_init()
59 if (!map->reg_defaults_raw) { in regcache_hw_init()
60 bool cache_bypass = map->cache_bypass; in regcache_hw_init()
61 dev_warn(map->dev, "No cache defaults, reading back from HW\n"); in regcache_hw_init()
64 map->cache_bypass = true; in regcache_hw_init()
65 tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL); in regcache_hw_init()
70 ret = regmap_raw_read(map, 0, tmp_buf, in regcache_hw_init()
71 map->cache_size_raw); in regcache_hw_init()
72 map->cache_bypass = cache_bypass; in regcache_hw_init()
74 map->reg_defaults_raw = tmp_buf; in regcache_hw_init()
75 map->cache_free = 1; in regcache_hw_init()
82 for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) { in regcache_hw_init()
83 reg = i * map->reg_stride; in regcache_hw_init()
85 if (!regmap_readable(map, reg)) in regcache_hw_init()
88 if (regmap_volatile(map, reg)) in regcache_hw_init()
91 if (map->reg_defaults_raw) { in regcache_hw_init()
92 val = regcache_get_val(map, map->reg_defaults_raw, i); in regcache_hw_init()
94 bool cache_bypass = map->cache_bypass; in regcache_hw_init()
96 map->cache_bypass = true; in regcache_hw_init()
97 ret = regmap_read(map, reg, &val); in regcache_hw_init()
98 map->cache_bypass = cache_bypass; in regcache_hw_init()
100 dev_err(map->dev, "Failed to read %d: %d\n", in regcache_hw_init()
106 map->reg_defaults[j].reg = reg; in regcache_hw_init()
107 map->reg_defaults[j].def = val; in regcache_hw_init()
114 kfree(map->reg_defaults); in regcache_hw_init()
119 int regcache_init(struct regmap *map, const struct regmap_config *config) in regcache_init() argument
125 if (map->cache_type == REGCACHE_NONE) { in regcache_init()
127 dev_warn(map->dev, in regcache_init()
130 map->cache_bypass = true; 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 compress 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) in regcache_init()
191 map->max_register = map->num_reg_defaults_raw; 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()
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()
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 static bool regcache_reg_needs_sync(struct regmap *map, unsigned int reg, in regcache_reg_needs_sync() argument
288 if (!map->no_sync_defaults) in regcache_reg_needs_sync()
292 ret = regcache_lookup_reg(map, reg); in regcache_reg_needs_sync()
293 if (ret >= 0 && val == map->reg_defaults[ret].def) in regcache_reg_needs_sync()
298 static int regcache_default_sync(struct regmap *map, unsigned int min, in regcache_default_sync() argument
303 for (reg = min; reg <= max; reg += map->reg_stride) { in regcache_default_sync()
307 if (regmap_volatile(map, reg) || in regcache_default_sync()
308 !regmap_writeable(map, reg)) in regcache_default_sync()
311 ret = regcache_read(map, reg, &val); in regcache_default_sync()
315 if (!regcache_reg_needs_sync(map, reg, val)) in regcache_default_sync()
318 map->cache_bypass = true; in regcache_default_sync()
319 ret = _regmap_write(map, reg, val); in regcache_default_sync()
320 map->cache_bypass = false; in regcache_default_sync()
322 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_default_sync()
326 dev_dbg(map->dev, "Synced register %#x, value %#x\n", reg, val); in regcache_default_sync()
343 int regcache_sync(struct regmap *map) in regcache_sync() argument
350 BUG_ON(!map->cache_ops); in regcache_sync()
352 map->lock(map->lock_arg); in regcache_sync()
354 bypass = map->cache_bypass; in regcache_sync()
355 dev_dbg(map->dev, "Syncing %s cache\n", in regcache_sync()
356 map->cache_ops->name); in regcache_sync()
357 name = map->cache_ops->name; in regcache_sync()
358 trace_regcache_sync(map, name, "start"); in regcache_sync()
360 if (!map->cache_dirty) in regcache_sync()
363 map->async = true; in regcache_sync()
366 map->cache_bypass = true; in regcache_sync()
367 for (i = 0; i < map->patch_regs; i++) { in regcache_sync()
368 ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def); in regcache_sync()
370 dev_err(map->dev, "Failed to write %x = %x: %d\n", in regcache_sync()
371 map->patch[i].reg, map->patch[i].def, ret); in regcache_sync()
375 map->cache_bypass = false; in regcache_sync()
377 if (map->cache_ops->sync) in regcache_sync()
378 ret = map->cache_ops->sync(map, 0, map->max_register); in regcache_sync()
380 ret = regcache_default_sync(map, 0, map->max_register); in regcache_sync()
383 map->cache_dirty = false; in regcache_sync()
387 map->async = false; in regcache_sync()
388 map->cache_bypass = bypass; in regcache_sync()
389 map->no_sync_defaults = false; in regcache_sync()
390 map->unlock(map->lock_arg); in regcache_sync()
392 regmap_async_complete(map); in regcache_sync()
394 trace_regcache_sync(map, name, "stop"); in regcache_sync()
412 int regcache_sync_region(struct regmap *map, unsigned int min, in regcache_sync_region() argument
419 BUG_ON(!map->cache_ops); in regcache_sync_region()
421 map->lock(map->lock_arg); in regcache_sync_region()
424 bypass = map->cache_bypass; in regcache_sync_region()
426 name = map->cache_ops->name; in regcache_sync_region()
427 dev_dbg(map->dev, "Syncing %s cache from %d-%d\n", name, min, max); in regcache_sync_region()
429 trace_regcache_sync(map, name, "start region"); in regcache_sync_region()
431 if (!map->cache_dirty) in regcache_sync_region()
434 map->async = true; in regcache_sync_region()
436 if (map->cache_ops->sync) in regcache_sync_region()
437 ret = map->cache_ops->sync(map, min, max); in regcache_sync_region()
439 ret = regcache_default_sync(map, min, max); in regcache_sync_region()
443 map->cache_bypass = bypass; in regcache_sync_region()
444 map->async = false; in regcache_sync_region()
445 map->no_sync_defaults = false; in regcache_sync_region()
446 map->unlock(map->lock_arg); in regcache_sync_region()
448 regmap_async_complete(map); in regcache_sync_region()
450 trace_regcache_sync(map, name, "stop region"); in regcache_sync_region()
467 int regcache_drop_region(struct regmap *map, unsigned int min, in regcache_drop_region() argument
472 if (!map->cache_ops || !map->cache_ops->drop) in regcache_drop_region()
475 map->lock(map->lock_arg); in regcache_drop_region()
477 trace_regcache_drop_region(map, min, max); in regcache_drop_region()
479 ret = map->cache_ops->drop(map, min, max); in regcache_drop_region()
481 map->unlock(map->lock_arg); in regcache_drop_region()
499 void regcache_cache_only(struct regmap *map, bool enable) in regcache_cache_only() argument
501 map->lock(map->lock_arg); in regcache_cache_only()
502 WARN_ON(map->cache_bypass && enable); in regcache_cache_only()
503 map->cache_only = enable; in regcache_cache_only()
504 trace_regmap_cache_only(map, enable); in regcache_cache_only()
505 map->unlock(map->lock_arg); in regcache_cache_only()
522 void regcache_mark_dirty(struct regmap *map) in regcache_mark_dirty() argument
524 map->lock(map->lock_arg); in regcache_mark_dirty()
525 map->cache_dirty = true; in regcache_mark_dirty()
526 map->no_sync_defaults = true; in regcache_mark_dirty()
527 map->unlock(map->lock_arg); in regcache_mark_dirty()
542 void regcache_cache_bypass(struct regmap *map, bool enable) in regcache_cache_bypass() argument
544 map->lock(map->lock_arg); in regcache_cache_bypass()
545 WARN_ON(map->cache_only && enable); in regcache_cache_bypass()
546 map->cache_bypass = enable; in regcache_cache_bypass()
547 trace_regmap_cache_bypass(map, enable); in regcache_cache_bypass()
548 map->unlock(map->lock_arg); in regcache_cache_bypass()
552 bool regcache_set_val(struct regmap *map, void *base, unsigned int idx, in regcache_set_val() argument
555 if (regcache_get_val(map, base, idx) == val) in regcache_set_val()
559 if (map->format.format_val) { in regcache_set_val()
560 map->format.format_val(base + (map->cache_word_size * idx), in regcache_set_val()
565 switch (map->cache_word_size) { in regcache_set_val()
598 unsigned int regcache_get_val(struct regmap *map, const void *base, in regcache_get_val() argument
605 if (map->format.parse_val) in regcache_get_val()
606 return map->format.parse_val(regcache_get_val_addr(map, base, in regcache_get_val()
609 switch (map->cache_word_size) { in regcache_get_val()
647 int regcache_lookup_reg(struct regmap *map, unsigned int reg) in regcache_lookup_reg() argument
655 r = bsearch(&key, map->reg_defaults, map->num_reg_defaults, in regcache_lookup_reg()
659 return r - map->reg_defaults; in regcache_lookup_reg()
672 static int regcache_sync_block_single(struct regmap *map, void *block, in regcache_sync_block_single() argument
681 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_single()
684 !regmap_writeable(map, regtmp)) in regcache_sync_block_single()
687 val = regcache_get_val(map, block, i); in regcache_sync_block_single()
688 if (!regcache_reg_needs_sync(map, regtmp, val)) in regcache_sync_block_single()
691 map->cache_bypass = true; in regcache_sync_block_single()
693 ret = _regmap_write(map, regtmp, val); in regcache_sync_block_single()
695 map->cache_bypass = false; in regcache_sync_block_single()
697 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_sync_block_single()
701 dev_dbg(map->dev, "Synced register %#x, value %#x\n", in regcache_sync_block_single()
708 static int regcache_sync_block_raw_flush(struct regmap *map, const void **data, in regcache_sync_block_raw_flush() argument
711 size_t val_bytes = map->format.val_bytes; in regcache_sync_block_raw_flush()
717 count = (cur - base) / map->reg_stride; in regcache_sync_block_raw_flush()
719 dev_dbg(map->dev, "Writing %zu bytes for %d registers from 0x%x-0x%x\n", in regcache_sync_block_raw_flush()
720 count * val_bytes, count, base, cur - map->reg_stride); in regcache_sync_block_raw_flush()
722 map->cache_bypass = true; in regcache_sync_block_raw_flush()
724 ret = _regmap_raw_write(map, base, *data, count * val_bytes); in regcache_sync_block_raw_flush()
726 dev_err(map->dev, "Unable to sync registers %#x-%#x. %d\n", in regcache_sync_block_raw_flush()
727 base, cur - map->reg_stride, ret); in regcache_sync_block_raw_flush()
729 map->cache_bypass = false; in regcache_sync_block_raw_flush()
736 static int regcache_sync_block_raw(struct regmap *map, void *block, in regcache_sync_block_raw() argument
748 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_raw()
751 !regmap_writeable(map, regtmp)) { in regcache_sync_block_raw()
752 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
759 val = regcache_get_val(map, block, i); in regcache_sync_block_raw()
760 if (!regcache_reg_needs_sync(map, regtmp, val)) { in regcache_sync_block_raw()
761 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
769 data = regcache_get_val_addr(map, block, i); in regcache_sync_block_raw()
774 return regcache_sync_block_raw_flush(map, &data, base, regtmp + in regcache_sync_block_raw()
775 map->reg_stride); in regcache_sync_block_raw()
778 int regcache_sync_block(struct regmap *map, void *block, in regcache_sync_block() argument
783 if (regmap_can_raw_write(map) && !map->use_single_write) in regcache_sync_block()
784 return regcache_sync_block_raw(map, block, cache_present, in regcache_sync_block()
787 return regcache_sync_block_single(map, block, cache_present, in regcache_sync_block()