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 u32 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 = 1; 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 int regcache_default_sync(struct regmap *map, unsigned int min, in regcache_default_sync() argument
257 for (reg = min; reg <= max; reg += map->reg_stride) { in regcache_default_sync()
261 if (regmap_volatile(map, reg) || in regcache_default_sync()
262 !regmap_writeable(map, reg)) in regcache_default_sync()
265 ret = regcache_read(map, reg, &val); in regcache_default_sync()
270 ret = regcache_lookup_reg(map, reg); in regcache_default_sync()
271 if (ret >= 0 && val == map->reg_defaults[ret].def) in regcache_default_sync()
274 map->cache_bypass = 1; in regcache_default_sync()
275 ret = _regmap_write(map, reg, val); in regcache_default_sync()
276 map->cache_bypass = 0; in regcache_default_sync()
278 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_default_sync()
282 dev_dbg(map->dev, "Synced register %#x, value %#x\n", reg, val); in regcache_default_sync()
299 int regcache_sync(struct regmap *map) in regcache_sync() argument
306 BUG_ON(!map->cache_ops); in regcache_sync()
308 map->lock(map->lock_arg); in regcache_sync()
310 bypass = map->cache_bypass; in regcache_sync()
311 dev_dbg(map->dev, "Syncing %s cache\n", in regcache_sync()
312 map->cache_ops->name); in regcache_sync()
313 name = map->cache_ops->name; in regcache_sync()
314 trace_regcache_sync(map, name, "start"); in regcache_sync()
316 if (!map->cache_dirty) in regcache_sync()
319 map->async = true; in regcache_sync()
322 map->cache_bypass = 1; in regcache_sync()
323 for (i = 0; i < map->patch_regs; i++) { in regcache_sync()
324 ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def); in regcache_sync()
326 dev_err(map->dev, "Failed to write %x = %x: %d\n", in regcache_sync()
327 map->patch[i].reg, map->patch[i].def, ret); in regcache_sync()
331 map->cache_bypass = 0; in regcache_sync()
333 if (map->cache_ops->sync) in regcache_sync()
334 ret = map->cache_ops->sync(map, 0, map->max_register); in regcache_sync()
336 ret = regcache_default_sync(map, 0, map->max_register); in regcache_sync()
339 map->cache_dirty = false; in regcache_sync()
343 map->async = false; in regcache_sync()
344 map->cache_bypass = bypass; in regcache_sync()
345 map->unlock(map->lock_arg); in regcache_sync()
347 regmap_async_complete(map); in regcache_sync()
349 trace_regcache_sync(map, name, "stop"); in regcache_sync()
367 int regcache_sync_region(struct regmap *map, unsigned int min, in regcache_sync_region() argument
374 BUG_ON(!map->cache_ops); in regcache_sync_region()
376 map->lock(map->lock_arg); in regcache_sync_region()
379 bypass = map->cache_bypass; in regcache_sync_region()
381 name = map->cache_ops->name; in regcache_sync_region()
382 dev_dbg(map->dev, "Syncing %s cache from %d-%d\n", name, min, max); in regcache_sync_region()
384 trace_regcache_sync(map, name, "start region"); in regcache_sync_region()
386 if (!map->cache_dirty) in regcache_sync_region()
389 map->async = true; in regcache_sync_region()
391 if (map->cache_ops->sync) in regcache_sync_region()
392 ret = map->cache_ops->sync(map, min, max); in regcache_sync_region()
394 ret = regcache_default_sync(map, min, max); in regcache_sync_region()
398 map->cache_bypass = bypass; in regcache_sync_region()
399 map->async = false; in regcache_sync_region()
400 map->unlock(map->lock_arg); in regcache_sync_region()
402 regmap_async_complete(map); in regcache_sync_region()
404 trace_regcache_sync(map, name, "stop region"); in regcache_sync_region()
421 int regcache_drop_region(struct regmap *map, unsigned int min, in regcache_drop_region() argument
426 if (!map->cache_ops || !map->cache_ops->drop) in regcache_drop_region()
429 map->lock(map->lock_arg); in regcache_drop_region()
431 trace_regcache_drop_region(map, min, max); in regcache_drop_region()
433 ret = map->cache_ops->drop(map, min, max); in regcache_drop_region()
435 map->unlock(map->lock_arg); in regcache_drop_region()
453 void regcache_cache_only(struct regmap *map, bool enable) in regcache_cache_only() argument
455 map->lock(map->lock_arg); in regcache_cache_only()
456 WARN_ON(map->cache_bypass && enable); in regcache_cache_only()
457 map->cache_only = enable; in regcache_cache_only()
458 trace_regmap_cache_only(map, enable); in regcache_cache_only()
459 map->unlock(map->lock_arg); in regcache_cache_only()
472 void regcache_mark_dirty(struct regmap *map) in regcache_mark_dirty() argument
474 map->lock(map->lock_arg); in regcache_mark_dirty()
475 map->cache_dirty = true; in regcache_mark_dirty()
476 map->unlock(map->lock_arg); in regcache_mark_dirty()
491 void regcache_cache_bypass(struct regmap *map, bool enable) in regcache_cache_bypass() argument
493 map->lock(map->lock_arg); in regcache_cache_bypass()
494 WARN_ON(map->cache_only && enable); in regcache_cache_bypass()
495 map->cache_bypass = enable; in regcache_cache_bypass()
496 trace_regmap_cache_bypass(map, enable); in regcache_cache_bypass()
497 map->unlock(map->lock_arg); in regcache_cache_bypass()
501 bool regcache_set_val(struct regmap *map, void *base, unsigned int idx, in regcache_set_val() argument
504 if (regcache_get_val(map, base, idx) == val) in regcache_set_val()
508 if (map->format.format_val) { in regcache_set_val()
509 map->format.format_val(base + (map->cache_word_size * idx), in regcache_set_val()
514 switch (map->cache_word_size) { in regcache_set_val()
536 unsigned int regcache_get_val(struct regmap *map, const void *base, in regcache_get_val() argument
543 if (map->format.parse_val) in regcache_get_val()
544 return map->format.parse_val(regcache_get_val_addr(map, base, in regcache_get_val()
547 switch (map->cache_word_size) { in regcache_get_val()
575 int regcache_lookup_reg(struct regmap *map, unsigned int reg) in regcache_lookup_reg() argument
583 r = bsearch(&key, map->reg_defaults, map->num_reg_defaults, in regcache_lookup_reg()
587 return r - map->reg_defaults; in regcache_lookup_reg()
600 static int regcache_sync_block_single(struct regmap *map, void *block, in regcache_sync_block_single() argument
609 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_single()
612 !regmap_writeable(map, regtmp)) in regcache_sync_block_single()
615 val = regcache_get_val(map, block, i); in regcache_sync_block_single()
618 ret = regcache_lookup_reg(map, regtmp); in regcache_sync_block_single()
619 if (ret >= 0 && val == map->reg_defaults[ret].def) in regcache_sync_block_single()
622 map->cache_bypass = 1; in regcache_sync_block_single()
624 ret = _regmap_write(map, regtmp, val); in regcache_sync_block_single()
626 map->cache_bypass = 0; in regcache_sync_block_single()
628 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_sync_block_single()
632 dev_dbg(map->dev, "Synced register %#x, value %#x\n", in regcache_sync_block_single()
639 static int regcache_sync_block_raw_flush(struct regmap *map, const void **data, in regcache_sync_block_raw_flush() argument
642 size_t val_bytes = map->format.val_bytes; in regcache_sync_block_raw_flush()
648 count = (cur - base) / map->reg_stride; in regcache_sync_block_raw_flush()
650 dev_dbg(map->dev, "Writing %zu bytes for %d registers from 0x%x-0x%x\n", in regcache_sync_block_raw_flush()
651 count * val_bytes, count, base, cur - map->reg_stride); in regcache_sync_block_raw_flush()
653 map->cache_bypass = 1; in regcache_sync_block_raw_flush()
655 ret = _regmap_raw_write(map, base, *data, count * val_bytes); in regcache_sync_block_raw_flush()
657 dev_err(map->dev, "Unable to sync registers %#x-%#x. %d\n", in regcache_sync_block_raw_flush()
658 base, cur - map->reg_stride, ret); in regcache_sync_block_raw_flush()
660 map->cache_bypass = 0; in regcache_sync_block_raw_flush()
667 static int regcache_sync_block_raw(struct regmap *map, void *block, in regcache_sync_block_raw() argument
679 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_raw()
682 !regmap_writeable(map, regtmp)) { in regcache_sync_block_raw()
683 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
690 val = regcache_get_val(map, block, i); in regcache_sync_block_raw()
693 ret = regcache_lookup_reg(map, regtmp); in regcache_sync_block_raw()
694 if (ret >= 0 && val == map->reg_defaults[ret].def) { in regcache_sync_block_raw()
695 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
703 data = regcache_get_val_addr(map, block, i); in regcache_sync_block_raw()
708 return regcache_sync_block_raw_flush(map, &data, base, regtmp + in regcache_sync_block_raw()
709 map->reg_stride); in regcache_sync_block_raw()
712 int regcache_sync_block(struct regmap *map, void *block, in regcache_sync_block() argument
717 if (regmap_can_raw_write(map) && !map->use_single_rw) in regcache_sync_block()
718 return regcache_sync_block_raw(map, block, cache_present, in regcache_sync_block()
721 return regcache_sync_block_single(map, block, cache_present, in regcache_sync_block()