• Home
  • Raw
  • Download

Lines Matching refs: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 = 1; 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 if (config->reg_defaults[i].reg % map->reg_stride) in regcache_init()
141 if (cache_types[i]->type == map->cache_type) in regcache_init()
145 dev_err(map->dev, "Could not match compress type: %d\n", in regcache_init()
146 map->cache_type); in regcache_init()
150 map->num_reg_defaults = config->num_reg_defaults; in regcache_init()
151 map->num_reg_defaults_raw = config->num_reg_defaults_raw; in regcache_init()
152 map->reg_defaults_raw = config->reg_defaults_raw; in regcache_init()
153 map->cache_word_size = DIV_ROUND_UP(config->val_bits, 8); in regcache_init()
154 map->cache_size_raw = map->cache_word_size * config->num_reg_defaults_raw; in regcache_init()
156 map->cache = NULL; in regcache_init()
157 map->cache_ops = cache_types[i]; in regcache_init()
159 if (!map->cache_ops->read || in regcache_init()
160 !map->cache_ops->write || in regcache_init()
161 !map->cache_ops->name) in regcache_init()
169 tmp_buf = kmemdup(config->reg_defaults, map->num_reg_defaults * in regcache_init()
173 map->reg_defaults = tmp_buf; in regcache_init()
174 } else if (map->num_reg_defaults_raw) { in regcache_init()
179 ret = regcache_hw_init(map); in regcache_init()
182 if (map->cache_bypass) in regcache_init()
186 if (!map->max_register) in regcache_init()
187 map->max_register = map->num_reg_defaults_raw; in regcache_init()
189 if (map->cache_ops->init) { in regcache_init()
190 dev_dbg(map->dev, "Initializing %s cache\n", in regcache_init()
191 map->cache_ops->name); in regcache_init()
192 ret = map->cache_ops->init(map); in regcache_init()
199 kfree(map->reg_defaults); in regcache_init()
200 if (map->cache_free) in regcache_init()
201 kfree(map->reg_defaults_raw); in regcache_init()
206 void regcache_exit(struct regmap *map) in regcache_exit() argument
208 if (map->cache_type == REGCACHE_NONE) in regcache_exit()
211 BUG_ON(!map->cache_ops); in regcache_exit()
213 kfree(map->reg_defaults); in regcache_exit()
214 if (map->cache_free) in regcache_exit()
215 kfree(map->reg_defaults_raw); in regcache_exit()
217 if (map->cache_ops->exit) { in regcache_exit()
218 dev_dbg(map->dev, "Destroying %s cache\n", in regcache_exit()
219 map->cache_ops->name); in regcache_exit()
220 map->cache_ops->exit(map); in regcache_exit()
233 int regcache_read(struct regmap *map, in regcache_read() argument
238 if (map->cache_type == REGCACHE_NONE) in regcache_read()
241 BUG_ON(!map->cache_ops); in regcache_read()
243 if (!regmap_volatile(map, reg)) { in regcache_read()
244 ret = map->cache_ops->read(map, reg, value); in regcache_read()
247 trace_regmap_reg_read_cache(map, reg, *value); in regcache_read()
264 int regcache_write(struct regmap *map, in regcache_write() argument
267 if (map->cache_type == REGCACHE_NONE) in regcache_write()
270 BUG_ON(!map->cache_ops); in regcache_write()
272 if (!regmap_volatile(map, reg)) in regcache_write()
273 return map->cache_ops->write(map, reg, value); in regcache_write()
278 static bool regcache_reg_needs_sync(struct regmap *map, unsigned int reg, in regcache_reg_needs_sync() argument
284 if (!map->no_sync_defaults) in regcache_reg_needs_sync()
288 ret = regcache_lookup_reg(map, reg); in regcache_reg_needs_sync()
289 if (ret >= 0 && val == map->reg_defaults[ret].def) in regcache_reg_needs_sync()
294 static int regcache_default_sync(struct regmap *map, unsigned int min, in regcache_default_sync() argument
299 for (reg = min; reg <= max; reg += map->reg_stride) { in regcache_default_sync()
303 if (regmap_volatile(map, reg) || in regcache_default_sync()
304 !regmap_writeable(map, reg)) in regcache_default_sync()
307 ret = regcache_read(map, reg, &val); in regcache_default_sync()
311 if (!regcache_reg_needs_sync(map, reg, val)) in regcache_default_sync()
314 map->cache_bypass = true; in regcache_default_sync()
315 ret = _regmap_write(map, reg, val); in regcache_default_sync()
316 map->cache_bypass = false; in regcache_default_sync()
318 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_default_sync()
322 dev_dbg(map->dev, "Synced register %#x, value %#x\n", reg, val); in regcache_default_sync()
339 int regcache_sync(struct regmap *map) in regcache_sync() argument
346 BUG_ON(!map->cache_ops); in regcache_sync()
348 map->lock(map->lock_arg); in regcache_sync()
350 bypass = map->cache_bypass; in regcache_sync()
351 dev_dbg(map->dev, "Syncing %s cache\n", in regcache_sync()
352 map->cache_ops->name); in regcache_sync()
353 name = map->cache_ops->name; in regcache_sync()
354 trace_regcache_sync(map, name, "start"); in regcache_sync()
356 if (!map->cache_dirty) in regcache_sync()
359 map->async = true; in regcache_sync()
362 map->cache_bypass = true; in regcache_sync()
363 for (i = 0; i < map->patch_regs; i++) { in regcache_sync()
364 ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def); in regcache_sync()
366 dev_err(map->dev, "Failed to write %x = %x: %d\n", in regcache_sync()
367 map->patch[i].reg, map->patch[i].def, ret); in regcache_sync()
371 map->cache_bypass = false; in regcache_sync()
373 if (map->cache_ops->sync) in regcache_sync()
374 ret = map->cache_ops->sync(map, 0, map->max_register); in regcache_sync()
376 ret = regcache_default_sync(map, 0, map->max_register); in regcache_sync()
379 map->cache_dirty = false; in regcache_sync()
383 map->async = false; in regcache_sync()
384 map->cache_bypass = bypass; in regcache_sync()
385 map->no_sync_defaults = false; in regcache_sync()
386 map->unlock(map->lock_arg); in regcache_sync()
388 regmap_async_complete(map); in regcache_sync()
390 trace_regcache_sync(map, name, "stop"); in regcache_sync()
408 int regcache_sync_region(struct regmap *map, unsigned int min, in regcache_sync_region() argument
415 BUG_ON(!map->cache_ops); in regcache_sync_region()
417 map->lock(map->lock_arg); in regcache_sync_region()
420 bypass = map->cache_bypass; in regcache_sync_region()
422 name = map->cache_ops->name; in regcache_sync_region()
423 dev_dbg(map->dev, "Syncing %s cache from %d-%d\n", name, min, max); in regcache_sync_region()
425 trace_regcache_sync(map, name, "start region"); in regcache_sync_region()
427 if (!map->cache_dirty) in regcache_sync_region()
430 map->async = true; in regcache_sync_region()
432 if (map->cache_ops->sync) in regcache_sync_region()
433 ret = map->cache_ops->sync(map, min, max); in regcache_sync_region()
435 ret = regcache_default_sync(map, min, max); in regcache_sync_region()
439 map->cache_bypass = bypass; in regcache_sync_region()
440 map->async = false; in regcache_sync_region()
441 map->no_sync_defaults = false; in regcache_sync_region()
442 map->unlock(map->lock_arg); in regcache_sync_region()
444 regmap_async_complete(map); in regcache_sync_region()
446 trace_regcache_sync(map, name, "stop region"); in regcache_sync_region()
463 int regcache_drop_region(struct regmap *map, unsigned int min, in regcache_drop_region() argument
468 if (!map->cache_ops || !map->cache_ops->drop) in regcache_drop_region()
471 map->lock(map->lock_arg); in regcache_drop_region()
473 trace_regcache_drop_region(map, min, max); in regcache_drop_region()
475 ret = map->cache_ops->drop(map, min, max); in regcache_drop_region()
477 map->unlock(map->lock_arg); in regcache_drop_region()
495 void regcache_cache_only(struct regmap *map, bool enable) in regcache_cache_only() argument
497 map->lock(map->lock_arg); in regcache_cache_only()
498 WARN_ON(map->cache_bypass && enable); in regcache_cache_only()
499 map->cache_only = enable; in regcache_cache_only()
500 trace_regmap_cache_only(map, enable); in regcache_cache_only()
501 map->unlock(map->lock_arg); in regcache_cache_only()
518 void regcache_mark_dirty(struct regmap *map) in regcache_mark_dirty() argument
520 map->lock(map->lock_arg); in regcache_mark_dirty()
521 map->cache_dirty = true; in regcache_mark_dirty()
522 map->no_sync_defaults = true; in regcache_mark_dirty()
523 map->unlock(map->lock_arg); in regcache_mark_dirty()
538 void regcache_cache_bypass(struct regmap *map, bool enable) in regcache_cache_bypass() argument
540 map->lock(map->lock_arg); in regcache_cache_bypass()
541 WARN_ON(map->cache_only && enable); in regcache_cache_bypass()
542 map->cache_bypass = enable; in regcache_cache_bypass()
543 trace_regmap_cache_bypass(map, enable); in regcache_cache_bypass()
544 map->unlock(map->lock_arg); in regcache_cache_bypass()
548 bool regcache_set_val(struct regmap *map, void *base, unsigned int idx, in regcache_set_val() argument
551 if (regcache_get_val(map, base, idx) == val) in regcache_set_val()
555 if (map->format.format_val) { in regcache_set_val()
556 map->format.format_val(base + (map->cache_word_size * idx), in regcache_set_val()
561 switch (map->cache_word_size) { in regcache_set_val()
594 unsigned int regcache_get_val(struct regmap *map, const void *base, in regcache_get_val() argument
601 if (map->format.parse_val) in regcache_get_val()
602 return map->format.parse_val(regcache_get_val_addr(map, base, in regcache_get_val()
605 switch (map->cache_word_size) { in regcache_get_val()
643 int regcache_lookup_reg(struct regmap *map, unsigned int reg) in regcache_lookup_reg() argument
651 r = bsearch(&key, map->reg_defaults, map->num_reg_defaults, in regcache_lookup_reg()
655 return r - map->reg_defaults; in regcache_lookup_reg()
668 static int regcache_sync_block_single(struct regmap *map, void *block, in regcache_sync_block_single() argument
677 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_single()
680 !regmap_writeable(map, regtmp)) in regcache_sync_block_single()
683 val = regcache_get_val(map, block, i); in regcache_sync_block_single()
684 if (!regcache_reg_needs_sync(map, regtmp, val)) in regcache_sync_block_single()
687 map->cache_bypass = true; in regcache_sync_block_single()
689 ret = _regmap_write(map, regtmp, val); in regcache_sync_block_single()
691 map->cache_bypass = false; in regcache_sync_block_single()
693 dev_err(map->dev, "Unable to sync register %#x. %d\n", in regcache_sync_block_single()
697 dev_dbg(map->dev, "Synced register %#x, value %#x\n", in regcache_sync_block_single()
704 static int regcache_sync_block_raw_flush(struct regmap *map, const void **data, in regcache_sync_block_raw_flush() argument
707 size_t val_bytes = map->format.val_bytes; in regcache_sync_block_raw_flush()
713 count = (cur - base) / map->reg_stride; in regcache_sync_block_raw_flush()
715 dev_dbg(map->dev, "Writing %zu bytes for %d registers from 0x%x-0x%x\n", in regcache_sync_block_raw_flush()
716 count * val_bytes, count, base, cur - map->reg_stride); in regcache_sync_block_raw_flush()
718 map->cache_bypass = true; in regcache_sync_block_raw_flush()
720 ret = _regmap_raw_write(map, base, *data, count * val_bytes, false); in regcache_sync_block_raw_flush()
722 dev_err(map->dev, "Unable to sync registers %#x-%#x. %d\n", in regcache_sync_block_raw_flush()
723 base, cur - map->reg_stride, ret); in regcache_sync_block_raw_flush()
725 map->cache_bypass = false; in regcache_sync_block_raw_flush()
732 static int regcache_sync_block_raw(struct regmap *map, void *block, in regcache_sync_block_raw() argument
744 regtmp = block_base + (i * map->reg_stride); in regcache_sync_block_raw()
747 !regmap_writeable(map, regtmp)) { in regcache_sync_block_raw()
748 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
755 val = regcache_get_val(map, block, i); in regcache_sync_block_raw()
756 if (!regcache_reg_needs_sync(map, regtmp, val)) { in regcache_sync_block_raw()
757 ret = regcache_sync_block_raw_flush(map, &data, in regcache_sync_block_raw()
765 data = regcache_get_val_addr(map, block, i); in regcache_sync_block_raw()
770 return regcache_sync_block_raw_flush(map, &data, base, regtmp + in regcache_sync_block_raw()
771 map->reg_stride); in regcache_sync_block_raw()
774 int regcache_sync_block(struct regmap *map, void *block, in regcache_sync_block() argument
779 if (regmap_can_raw_write(map) && !map->use_single_write) in regcache_sync_block()
780 return regcache_sync_block_raw(map, block, cache_present, in regcache_sync_block()
783 return regcache_sync_block_single(map, block, cache_present, in regcache_sync_block()