Lines Matching refs:map
28 static int regcache_hw_init(struct regmap *map) in regcache_hw_init() argument
36 if (!map->num_reg_defaults_raw) in regcache_hw_init()
40 for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) in regcache_hw_init()
41 if (!regmap_volatile(map, i * map->reg_stride)) in regcache_hw_init()
46 map->cache_bypass = true; in regcache_hw_init()
50 map->num_reg_defaults = count; in regcache_hw_init()
51 map->reg_defaults = kmalloc_array(count, sizeof(struct reg_default), in regcache_hw_init()
53 if (!map->reg_defaults) in regcache_hw_init()
56 if (!map->reg_defaults_raw) { in regcache_hw_init()
57 bool cache_bypass = map->cache_bypass; in regcache_hw_init()
58 dev_warn(map->dev, "No cache defaults, reading back from HW\n"); in regcache_hw_init()
61 map->cache_bypass = true; in regcache_hw_init()
62 tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL); in regcache_hw_init()
67 ret = regmap_raw_read(map, 0, tmp_buf, in regcache_hw_init()
68 map->num_reg_defaults_raw); in regcache_hw_init()
69 map->cache_bypass = cache_bypass; in regcache_hw_init()
73 map->reg_defaults_raw = tmp_buf; in regcache_hw_init()
74 map->cache_free = 1; in regcache_hw_init()
78 for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) { in regcache_hw_init()
79 if (regmap_volatile(map, i * map->reg_stride)) in regcache_hw_init()
81 val = regcache_get_val(map, map->reg_defaults_raw, i); in regcache_hw_init()
82 map->reg_defaults[j].reg = i * map->reg_stride; in regcache_hw_init()
83 map->reg_defaults[j].def = val; in regcache_hw_init()
92 kfree(map->reg_defaults); in regcache_hw_init()
97 int regcache_init(struct regmap *map, const struct regmap_config *config) in regcache_init() argument
104 if (config->reg_defaults[i].reg % map->reg_stride) in regcache_init()
107 if (map->cache_type == REGCACHE_NONE) { in regcache_init()
108 map->cache_bypass = true; in regcache_init()
113 if (cache_types[i]->type == map->cache_type) in regcache_init()
117 dev_err(map->dev, "Could not match compress type: %d\n", in regcache_init()
118 map->cache_type); in regcache_init()
122 map->num_reg_defaults = config->num_reg_defaults; in regcache_init()
123 map->num_reg_defaults_raw = config->num_reg_defaults_raw; in regcache_init()
124 map->reg_defaults_raw = config->reg_defaults_raw; in regcache_init()
125 map->cache_word_size = DIV_ROUND_UP(config->val_bits, 8); in regcache_init()
126 map->cache_size_raw = map->cache_word_size * config->num_reg_defaults_raw; in regcache_init()
128 map->cache = NULL; in regcache_init()
129 map->cache_ops = cache_types[i]; in regcache_init()
131 if (!map->cache_ops->read || in regcache_init()
132 !map->cache_ops->write || in regcache_init()
133 !map->cache_ops->name) in regcache_init()
141 if (!map->num_reg_defaults) in regcache_init()
143 tmp_buf = kmemdup(config->reg_defaults, map->num_reg_defaults * in regcache_init()
147 map->reg_defaults = tmp_buf; in regcache_init()
148 } else if (map->num_reg_defaults_raw) { in regcache_init()
153 ret = regcache_hw_init(map); in regcache_init()
156 if (map->cache_bypass) in regcache_init()
160 if (!map->max_register) in regcache_init()
161 map->max_register = map->num_reg_defaults_raw; in regcache_init()
163 if (map->cache_ops->init) { in regcache_init()
164 dev_dbg(map->dev, "Initializing %s cache\n", in regcache_init()
165 map->cache_ops->name); in regcache_init()
166 ret = map->cache_ops->init(map); in regcache_init()
173 kfree(map->reg_defaults); in regcache_init()
174 if (map->cache_free) in regcache_init()
175 kfree(map->reg_defaults_raw); in regcache_init()
180 void regcache_exit(struct regmap *map) in regcache_exit() argument
182 if (map->cache_type == REGCACHE_NONE) in regcache_exit()
185 BUG_ON(!map->cache_ops); in regcache_exit()
187 kfree(map->reg_defaults); in regcache_exit()
188 if (map->cache_free) in regcache_exit()
189 kfree(map->reg_defaults_raw); in regcache_exit()
191 if (map->cache_ops->exit) { in regcache_exit()
192 dev_dbg(map->dev, "Destroying %s cache\n", in regcache_exit()
193 map->cache_ops->name); in regcache_exit()
194 map->cache_ops->exit(map); in regcache_exit()
207 int regcache_read(struct regmap *map, in regcache_read() argument
212 if (map->cache_type == REGCACHE_NONE) in regcache_read()
215 BUG_ON(!map->cache_ops); in regcache_read()
217 if (!regmap_volatile(map, reg)) { in regcache_read()
218 ret = map->cache_ops->read(map, reg, value); in regcache_read()
221 trace_regmap_reg_read_cache(map, reg, *value); in regcache_read()
238 int regcache_write(struct regmap *map, in regcache_write() argument
241 if (map->cache_type == REGCACHE_NONE) in regcache_write()
244 BUG_ON(!map->cache_ops); in regcache_write()
246 if (!regmap_volatile(map, reg)) in regcache_write()
247 return map->cache_ops->write(map, reg, value); in regcache_write()
252 static bool regcache_reg_needs_sync(struct regmap *map, unsigned int reg, in regcache_reg_needs_sync() argument
258 if (!map->no_sync_defaults) in regcache_reg_needs_sync()
262 ret = regcache_lookup_reg(map, reg); in regcache_reg_needs_sync()
263 if (ret >= 0 && val == map->reg_defaults[ret].def) in regcache_reg_needs_sync()
268 static int regcache_default_sync(struct regmap *map, unsigned int min, in regcache_default_sync() argument
273 for (reg = min; reg <= max; reg += map->reg_stride) { in regcache_default_sync()
277 if (regmap_volatile(map, reg) || in regcache_default_sync()
278 !regmap_writeable(map, reg)) in regcache_default_sync()
281 ret = regcache_read(map, reg, &val); in regcache_default_sync()
285 if (!regcache_reg_needs_sync(map, reg, val)) in regcache_default_sync()
288 map->cache_bypass = true; in regcache_default_sync()
289 ret = _regmap_write(map, reg, val); in regcache_default_sync()
290 map->cache_bypass = false; in regcache_default_sync()
292 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_default_sync()
296 dev_dbg(map->dev, "Synced register %#x, value %#x\n", reg, val); in regcache_default_sync()
313 int regcache_sync(struct regmap *map) in regcache_sync() argument
320 BUG_ON(!map->cache_ops); in regcache_sync()
322 map->lock(map->lock_arg); in regcache_sync()
324 bypass = map->cache_bypass; in regcache_sync()
325 dev_dbg(map->dev, "Syncing %s cache\n", in regcache_sync()
326 map->cache_ops->name); in regcache_sync()
327 name = map->cache_ops->name; in regcache_sync()
328 trace_regcache_sync(map, name, "start"); in regcache_sync()
330 if (!map->cache_dirty) in regcache_sync()
333 map->async = true; in regcache_sync()
336 map->cache_bypass = true; in regcache_sync()
337 for (i = 0; i < map->patch_regs; i++) { in regcache_sync()
338 ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def); in regcache_sync()
340 dev_err(map->dev, "Failed to write %x = %x: %d\n", in regcache_sync()
341 map->patch[i].reg, map->patch[i].def, ret); in regcache_sync()
345 map->cache_bypass = false; in regcache_sync()
347 if (map->cache_ops->sync) in regcache_sync()
348 ret = map->cache_ops->sync(map, 0, map->max_register); in regcache_sync()
350 ret = regcache_default_sync(map, 0, map->max_register); in regcache_sync()
353 map->cache_dirty = false; in regcache_sync()
357 map->async = false; in regcache_sync()
358 map->cache_bypass = bypass; in regcache_sync()
359 map->no_sync_defaults = false; in regcache_sync()
360 map->unlock(map->lock_arg); in regcache_sync()
362 regmap_async_complete(map); in regcache_sync()
364 trace_regcache_sync(map, name, "stop"); in regcache_sync()
382 int regcache_sync_region(struct regmap *map, unsigned int min, in regcache_sync_region() argument
389 BUG_ON(!map->cache_ops); in regcache_sync_region()
391 map->lock(map->lock_arg); in regcache_sync_region()
394 bypass = map->cache_bypass; in regcache_sync_region()
396 name = map->cache_ops->name; in regcache_sync_region()
397 dev_dbg(map->dev, "Syncing %s cache from %d-%d\n", name, min, max); in regcache_sync_region()
399 trace_regcache_sync(map, name, "start region"); in regcache_sync_region()
401 if (!map->cache_dirty) in regcache_sync_region()
404 map->async = true; in regcache_sync_region()
406 if (map->cache_ops->sync) in regcache_sync_region()
407 ret = map->cache_ops->sync(map, min, max); in regcache_sync_region()
409 ret = regcache_default_sync(map, min, max); in regcache_sync_region()
413 map->cache_bypass = bypass; in regcache_sync_region()
414 map->async = false; in regcache_sync_region()
415 map->no_sync_defaults = false; in regcache_sync_region()
416 map->unlock(map->lock_arg); in regcache_sync_region()
418 regmap_async_complete(map); in regcache_sync_region()
420 trace_regcache_sync(map, name, "stop region"); in regcache_sync_region()
437 int regcache_drop_region(struct regmap *map, unsigned int min, in regcache_drop_region() argument
442 if (!map->cache_ops || !map->cache_ops->drop) in regcache_drop_region()
445 map->lock(map->lock_arg); in regcache_drop_region()
447 trace_regcache_drop_region(map, min, max); in regcache_drop_region()
449 ret = map->cache_ops->drop(map, min, max); in regcache_drop_region()
451 map->unlock(map->lock_arg); in regcache_drop_region()
469 void regcache_cache_only(struct regmap *map, bool enable) in regcache_cache_only() argument
471 map->lock(map->lock_arg); in regcache_cache_only()
472 WARN_ON(map->cache_bypass && enable); in regcache_cache_only()
473 map->cache_only = enable; in regcache_cache_only()
474 trace_regmap_cache_only(map, enable); in regcache_cache_only()
475 map->unlock(map->lock_arg); in regcache_cache_only()
492 void regcache_mark_dirty(struct regmap *map) in regcache_mark_dirty() argument
494 map->lock(map->lock_arg); in regcache_mark_dirty()
495 map->cache_dirty = true; in regcache_mark_dirty()
496 map->no_sync_defaults = true; in regcache_mark_dirty()
497 map->unlock(map->lock_arg); in regcache_mark_dirty()
512 void regcache_cache_bypass(struct regmap *map, bool enable) in regcache_cache_bypass() argument
514 map->lock(map->lock_arg); in regcache_cache_bypass()
515 WARN_ON(map->cache_only && enable); in regcache_cache_bypass()
516 map->cache_bypass = enable; in regcache_cache_bypass()
517 trace_regmap_cache_bypass(map, enable); in regcache_cache_bypass()
518 map->unlock(map->lock_arg); in regcache_cache_bypass()
522 bool regcache_set_val(struct regmap *map, void *base, unsigned int idx, in regcache_set_val() argument
525 if (regcache_get_val(map, base, idx) == val) in regcache_set_val()
529 if (map->format.format_val) { in regcache_set_val()
530 map->format.format_val(base + (map->cache_word_size * idx), in regcache_set_val()
535 switch (map->cache_word_size) { in regcache_set_val()
557 unsigned int regcache_get_val(struct regmap *map, const void *base, in regcache_get_val() argument
564 if (map->format.parse_val) in regcache_get_val()
565 return map->format.parse_val(regcache_get_val_addr(map, base, in regcache_get_val()
568 switch (map->cache_word_size) { in regcache_get_val()
596 int regcache_lookup_reg(struct regmap *map, unsigned int reg) in regcache_lookup_reg() argument
604 r = bsearch(&key, map->reg_defaults, map->num_reg_defaults, in regcache_lookup_reg()
608 return r - map->reg_defaults; in regcache_lookup_reg()
621 static int regcache_sync_block_single(struct regmap *map, void *block, in regcache_sync_block_single() argument
630 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_single()
633 !regmap_writeable(map, regtmp)) in regcache_sync_block_single()
636 val = regcache_get_val(map, block, i); in regcache_sync_block_single()
637 if (!regcache_reg_needs_sync(map, regtmp, val)) in regcache_sync_block_single()
640 map->cache_bypass = true; in regcache_sync_block_single()
642 ret = _regmap_write(map, regtmp, val); in regcache_sync_block_single()
644 map->cache_bypass = false; in regcache_sync_block_single()
646 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_sync_block_single()
650 dev_dbg(map->dev, "Synced register %#x, value %#x\n", in regcache_sync_block_single()
657 static int regcache_sync_block_raw_flush(struct regmap *map, const void **data, in regcache_sync_block_raw_flush() argument
660 size_t val_bytes = map->format.val_bytes; in regcache_sync_block_raw_flush()
666 count = (cur - base) / map->reg_stride; in regcache_sync_block_raw_flush()
668 dev_dbg(map->dev, "Writing %zu bytes for %d registers from 0x%x-0x%x\n", in regcache_sync_block_raw_flush()
669 count * val_bytes, count, base, cur - map->reg_stride); in regcache_sync_block_raw_flush()
671 map->cache_bypass = true; in regcache_sync_block_raw_flush()
673 ret = _regmap_raw_write(map, base, *data, count * val_bytes); in regcache_sync_block_raw_flush()
675 dev_err(map->dev, "Unable to sync registers %#x-%#x. %d\n", in regcache_sync_block_raw_flush()
676 base, cur - map->reg_stride, ret); in regcache_sync_block_raw_flush()
678 map->cache_bypass = false; in regcache_sync_block_raw_flush()
685 static int regcache_sync_block_raw(struct regmap *map, void *block, in regcache_sync_block_raw() argument
697 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_raw()
700 !regmap_writeable(map, regtmp)) { in regcache_sync_block_raw()
701 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
708 val = regcache_get_val(map, block, i); in regcache_sync_block_raw()
709 if (!regcache_reg_needs_sync(map, regtmp, val)) { in regcache_sync_block_raw()
710 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
718 data = regcache_get_val_addr(map, block, i); in regcache_sync_block_raw()
723 return regcache_sync_block_raw_flush(map, &data, base, regtmp + in regcache_sync_block_raw()
724 map->reg_stride); in regcache_sync_block_raw()
727 int regcache_sync_block(struct regmap *map, void *block, in regcache_sync_block() argument
732 if (regmap_can_raw_write(map) && !map->use_single_write) in regcache_sync_block()
733 return regcache_sync_block_raw(map, block, cache_present, in regcache_sync_block()
736 return regcache_sync_block_single(map, block, cache_present, in regcache_sync_block()