source: GPL/branches/uniaud32-next/lib32/regcache-flat.c@ 625

Last change on this file since 625 was 625, checked in by Paul Smedley, 5 years ago

Code cleanups to simplify future maintenance, update regmap/regcache/rbtree to linux 4.19.163 level

File size: 1.9 KB
Line 
1/*
2 * Register cache access API - flat caching support
3 *
4 * Copyright 2012 Wolfson Microelectronics plc
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12/* from 4.19.163 */
13
14#include <linux/device.h>
15#include <linux/seq_file.h>
16#include <linux/slab.h>
17
18#include "internal.h"
19
20static inline unsigned int regcache_flat_get_index(const struct regmap *map,
21 unsigned int reg)
22{
23 return regcache_get_index_by_order(map, reg);
24}
25
26static int regcache_flat_init(struct regmap *map)
27{
28 int i;
29 unsigned int *cache;
30
31 if (!map || map->reg_stride_order < 0 || !map->max_register)
32 return -EINVAL;
33
34 map->cache = kcalloc(regcache_flat_get_index(map, map->max_register)
35 + 1, sizeof(unsigned int), GFP_KERNEL);
36 if (!map->cache)
37 return -ENOMEM;
38
39 cache = map->cache;
40
41 for (i = 0; i < map->num_reg_defaults; i++) {
42 unsigned int reg = map->reg_defaults[i].reg;
43 unsigned int index = regcache_flat_get_index(map, reg);
44
45 cache[index] = map->reg_defaults[i].def;
46 }
47
48 return 0;
49}
50
51static int regcache_flat_exit(struct regmap *map)
52{
53 kfree(map->cache);
54 map->cache = NULL;
55
56 return 0;
57}
58
59static int regcache_flat_read(struct regmap *map,
60 unsigned int reg, unsigned int *value)
61{
62 unsigned int *cache = map->cache;
63 unsigned int index = regcache_flat_get_index(map, reg);
64
65 *value = cache[index];
66
67 return 0;
68}
69
70static int regcache_flat_write(struct regmap *map, unsigned int reg,
71 unsigned int value)
72{
73 unsigned int *cache = map->cache;
74 unsigned int index = regcache_flat_get_index(map, reg);
75
76 cache[index] = value;
77
78 return 0;
79}
80
81struct regcache_ops regcache_flat_ops = {
82 .type = REGCACHE_FLAT,
83 .name = "flat",
84 .init = regcache_flat_init,
85 .exit = regcache_flat_exit,
86 .read = regcache_flat_read,
87 .write = regcache_flat_write,
88};
Note: See TracBrowser for help on using the repository browser.