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

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

Add source for uniaud32 based on code from linux kernel 5.4.86

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.14.202 */
13
14#include <linux/device.h>
15#include <linux/seq_file.h>
16#include <linux/slab.h>
17#include <linux/module.h>
18#include <linux/workqueue.h>
19#include <linux/byteorder/little_endian.h>
20#include <linux/printk.h>
21
22#include "internal.h"
23
24static inline unsigned int regcache_flat_get_index(const struct regmap *map,
25 unsigned int reg)
26{
27 return regcache_get_index_by_order(map, reg);
28}
29
30static int regcache_flat_init(struct regmap *map)
31{
32 int i;
33 unsigned int *cache;
34
35 if (!map || map->reg_stride_order < 0 || !map->max_register)
36 return -EINVAL;
37
38 map->cache = kcalloc(regcache_flat_get_index(map, map->max_register)
39 + 1, sizeof(unsigned int), GFP_KERNEL);
40 if (!map->cache)
41 return -ENOMEM;
42
43 cache = map->cache;
44
45 for (i = 0; i < map->num_reg_defaults; i++)
46 cache[regcache_flat_get_index(map, map->reg_defaults[i].reg)] =
47 map->reg_defaults[i].def;
48
49 return 0;
50}
51
52static int regcache_flat_exit(struct regmap *map)
53{
54 kfree(map->cache);
55 map->cache = NULL;
56
57 return 0;
58}
59
60static int regcache_flat_read(struct regmap *map,
61 unsigned int reg, unsigned int *value)
62{
63 unsigned int *cache = map->cache;
64
65 *value = cache[regcache_flat_get_index(map, reg)];
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
75 cache[regcache_flat_get_index(map, reg)] = value;
76
77 return 0;
78}
79
80struct regcache_ops regcache_flat_ops = {
81 .type = REGCACHE_FLAT,
82 .name = "flat",
83 .init = regcache_flat_init,
84 .exit = regcache_flat_exit,
85 .read = regcache_flat_read,
86 .write = regcache_flat_write,
87};
Note: See TracBrowser for help on using the repository browser.