source: GPL/branches/uniaud32-next/lib32/internal.h

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

Update regmap & regcache to 5.10.10 kernel code

File size: 8.3 KB
Line 
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Register map access API internal header
4 *
5 * Copyright 2011 Wolfson Microelectronics plc
6 *
7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 */
9
10/* from 5.10.10 */
11
12#ifndef _REGMAP_INTERNAL_H
13#define _REGMAP_INTERNAL_H
14
15#include <linux/device.h>
16#include <linux/regmap.h>
17#include <linux/fs.h>
18#include <linux/list.h>
19#include <linux/wait.h>
20
21struct regmap;
22struct regcache_ops;
23
24struct regmap_debugfs_off_cache {
25 struct list_head list;
26 off_t min;
27 off_t max;
28 unsigned int base_reg;
29 unsigned int max_reg;
30};
31
32struct regmap_format {
33 size_t buf_size;
34 size_t reg_bytes;
35 size_t pad_bytes;
36 size_t val_bytes;
37 void (*format_write)(struct regmap *map,
38 unsigned int reg, unsigned int val);
39 void (*format_reg)(void *buf, unsigned int reg, unsigned int shift);
40 void (*format_val)(void *buf, unsigned int val, unsigned int shift);
41 unsigned int (*parse_val)(const void *buf);
42 void (*parse_inplace)(void *buf);
43};
44
45struct regmap_async {
46 struct list_head list;
47 struct regmap *map;
48 void *work_buf;
49};
50
51struct regmap {
52 union {
53 struct mutex mutex;
54 struct {
55 spinlock_t spinlock;
56 unsigned long spinlock_flags;
57 };
58 };
59 regmap_lock lock;
60 regmap_unlock unlock;
61 void *lock_arg; /* This is passed to lock/unlock functions */
62 gfp_t alloc_flags;
63
64 struct device *dev; /* Device we do I/O on */
65 void *work_buf; /* Scratch buffer used to format I/O */
66 struct regmap_format format; /* Buffer format */
67 const struct regmap_bus *bus;
68 void *bus_context;
69 const char *name;
70
71 bool async;
72 spinlock_t async_lock;
73 wait_queue_head_t async_waitq;
74 struct list_head async_list;
75 struct list_head async_free;
76 int async_ret;
77
78#ifdef CONFIG_DEBUG_FS
79 bool debugfs_disable;
80 struct dentry *debugfs;
81 const char *debugfs_name;
82
83 unsigned int debugfs_reg_len;
84 unsigned int debugfs_val_len;
85 unsigned int debugfs_tot_len;
86
87 struct list_head debugfs_off_cache;
88 struct mutex cache_lock;
89#endif
90
91 unsigned int max_register;
92 bool (*writeable_reg)(struct device *dev, unsigned int reg);
93 bool (*readable_reg)(struct device *dev, unsigned int reg);
94 bool (*volatile_reg)(struct device *dev, unsigned int reg);
95 bool (*precious_reg)(struct device *dev, unsigned int reg);
96 bool (*writeable_noinc_reg)(struct device *dev, unsigned int reg);
97 bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
98 const struct regmap_access_table *wr_table;
99 const struct regmap_access_table *rd_table;
100 const struct regmap_access_table *volatile_table;
101 const struct regmap_access_table *precious_table;
102 const struct regmap_access_table *wr_noinc_table;
103 const struct regmap_access_table *rd_noinc_table;
104
105 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
106 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
107 int (*reg_update_bits)(void *context, unsigned int reg,
108 unsigned int mask, unsigned int val);
109
110 bool defer_caching;
111
112 unsigned long read_flag_mask;
113 unsigned long write_flag_mask;
114
115 /* number of bits to (left) shift the reg value when formatting*/
116 int reg_shift;
117 int reg_stride;
118 int reg_stride_order;
119
120 /* regcache specific members */
121 const struct regcache_ops *cache_ops;
122 enum regcache_type cache_type;
123
124 /* number of bytes in reg_defaults_raw */
125 unsigned int cache_size_raw;
126 /* number of bytes per word in reg_defaults_raw */
127 unsigned int cache_word_size;
128 /* number of entries in reg_defaults */
129 unsigned int num_reg_defaults;
130 /* number of entries in reg_defaults_raw */
131 unsigned int num_reg_defaults_raw;
132
133 /* if set, only the cache is modified not the HW */
134 bool cache_only;
135 /* if set, only the HW is modified not the cache */
136 bool cache_bypass;
137 /* if set, remember to free reg_defaults_raw */
138 bool cache_free;
139
140 struct reg_default *reg_defaults;
141 const void *reg_defaults_raw;
142 void *cache;
143 /* if set, the cache contains newer data than the HW */
144 bool cache_dirty;
145 /* if set, the HW registers are known to match map->reg_defaults */
146 bool no_sync_defaults;
147
148 struct reg_sequence *patch;
149 int patch_regs;
150
151 /* if set, converts bulk read to single read */
152 bool use_single_read;
153 /* if set, converts bulk write to single write */
154 bool use_single_write;
155 /* if set, the device supports multi write mode */
156 bool can_multi_write;
157
158 /* if set, raw reads/writes are limited to this size */
159 size_t max_raw_read;
160 size_t max_raw_write;
161
162 struct rb_root range_tree;
163 void *selector_work_buf; /* Scratch buffer used for selector */
164
165 struct hwspinlock *hwlock;
166
167 /* if set, the regmap core can sleep */
168 bool can_sleep;
169};
170
171struct regcache_ops {
172 const char *name;
173 enum regcache_type type;
174 int (*init)(struct regmap *map);
175 int (*exit)(struct regmap *map);
176#ifdef CONFIG_DEBUG_FS
177 void (*debugfs_init)(struct regmap *map);
178#endif
179 int (*read)(struct regmap *map, unsigned int reg, unsigned int *value);
180 int (*write)(struct regmap *map, unsigned int reg, unsigned int value);
181 int (*sync)(struct regmap *map, unsigned int min, unsigned int max);
182 int (*drop)(struct regmap *map, unsigned int min, unsigned int max);
183};
184
185bool regmap_cached(struct regmap *map, unsigned int reg);
186bool regmap_writeable(struct regmap *map, unsigned int reg);
187bool regmap_readable(struct regmap *map, unsigned int reg);
188bool regmap_volatile(struct regmap *map, unsigned int reg);
189bool regmap_precious(struct regmap *map, unsigned int reg);
190bool regmap_writeable_noinc(struct regmap *map, unsigned int reg);
191bool regmap_readable_noinc(struct regmap *map, unsigned int reg);
192
193int _regmap_write(struct regmap *map, unsigned int reg,
194 unsigned int val);
195
196struct regmap_range_node {
197 struct rb_node node;
198 const char *name;
199 struct regmap *map;
200
201 unsigned int range_min;
202 unsigned int range_max;
203
204 unsigned int selector_reg;
205 unsigned int selector_mask;
206 int selector_shift;
207
208 unsigned int window_start;
209 unsigned int window_len;
210};
211
212struct regmap_field {
213 struct regmap *regmap;
214 unsigned int mask;
215 /* lsb */
216 unsigned int shift;
217 unsigned int reg;
218
219 unsigned int id_size;
220 unsigned int id_offset;
221};
222
223#ifdef CONFIG_DEBUG_FS
224extern void regmap_debugfs_initcall(void);
225extern void regmap_debugfs_init(struct regmap *map);
226extern void regmap_debugfs_exit(struct regmap *map);
227
228static inline void regmap_debugfs_disable(struct regmap *map)
229{
230 map->debugfs_disable = true;
231}
232
233#else
234static inline void regmap_debugfs_initcall(void) { }
235static inline void regmap_debugfs_init(struct regmap *map) { }
236static inline void regmap_debugfs_exit(struct regmap *map) { }
237static inline void regmap_debugfs_disable(struct regmap *map) { }
238#endif
239
240/* regcache core declarations */
241int regcache_init(struct regmap *map, const struct regmap_config *config);
242void regcache_exit(struct regmap *map);
243int regcache_read(struct regmap *map,
244 unsigned int reg, unsigned int *value);
245int regcache_write(struct regmap *map,
246 unsigned int reg, unsigned int value);
247int regcache_sync(struct regmap *map);
248int regcache_sync_block(struct regmap *map, void *block,
249 unsigned long *cache_present,
250 unsigned int block_base, unsigned int start,
251 unsigned int end);
252
253static inline const void *regcache_get_val_addr(struct regmap *map,
254 const void *base,
255 unsigned int idx)
256{
257 return base + (map->cache_word_size * idx);
258}
259
260unsigned int regcache_get_val(struct regmap *map, const void *base,
261 unsigned int idx);
262bool regcache_set_val(struct regmap *map, void *base, unsigned int idx,
263 unsigned int val);
264int regcache_lookup_reg(struct regmap *map, unsigned int reg);
265
266int _regmap_raw_write(struct regmap *map, unsigned int reg,
267 const void *val, size_t val_len, bool noinc);
268
269void regmap_async_complete_cb(struct regmap_async *async, int ret);
270
271enum regmap_endian regmap_get_val_endian(struct device *dev,
272 const struct regmap_bus *bus,
273 const struct regmap_config *config);
274
275extern struct regcache_ops regcache_rbtree_ops;
276extern struct regcache_ops regcache_lzo_ops;
277extern struct regcache_ops regcache_flat_ops;
278
279static inline const char *regmap_name(const struct regmap *map)
280{
281 if (map->dev)
282 return dev_name(map->dev);
283
284 return map->name;
285}
286
287static inline unsigned int regmap_get_offset(const struct regmap *map,
288 unsigned int index)
289{
290 if (map->reg_stride_order >= 0)
291 return index << map->reg_stride_order;
292 else
293 return index * map->reg_stride;
294}
295
296static inline unsigned int regcache_get_index_by_order(const struct regmap *map,
297 unsigned int reg)
298{
299 return reg >> map->reg_stride_order;
300}
301
302#endif
Note: See TracBrowser for help on using the repository browser.