source: GPL/branches/uniaud32-next/lib32/internal.h@ 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: 7.9 KB
Line 
1/*
2 * Register map access API internal header
3 *
4 * Copyright 2011 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#ifndef _REGMAP_INTERNAL_H
15#define _REGMAP_INTERNAL_H
16
17#include <linux/device.h>
18#include <linux/regmap.h>
19#include <linux/fs.h>
20#include <linux/list.h>
21#include <linux/wait.h>
22#include <linux/timer.h>
23#include <linux/bitops.h>
24#include <linux/bitmap.h>
25
26struct regmap;
27struct regcache_ops;
28
29struct regmap_debugfs_off_cache {
30 struct list_head list;
31 off_t min;
32 off_t max;
33 unsigned int base_reg;
34 unsigned int max_reg;
35};
36
37struct regmap_format {
38 size_t buf_size;
39 size_t reg_bytes;
40 size_t pad_bytes;
41 size_t val_bytes;
42 void (*format_write)(struct regmap *map,
43 unsigned int reg, unsigned int val);
44 void (*format_reg)(void *buf, unsigned int reg, unsigned int shift);
45 void (*format_val)(void *buf, unsigned int val, unsigned int shift);
46 unsigned int (*parse_val)(const void *buf);
47 void (*parse_inplace)(void *buf);
48};
49
50struct regmap_async {
51 struct list_head list;
52 struct regmap *map;
53 void *work_buf;
54};
55
56struct regmap {
57 union {
58 struct mutex mutex;
59 struct {
60 spinlock_t spinlock;
61 unsigned long spinlock_flags;
62 };
63 };
64 regmap_lock lock;
65 regmap_unlock unlock;
66 void *lock_arg; /* This is passed to lock/unlock functions */
67 gfp_t alloc_flags;
68
69 struct device *dev; /* Device we do I/O on */
70 void *work_buf; /* Scratch buffer used to format I/O */
71 struct regmap_format format; /* Buffer format */
72 const struct regmap_bus *bus;
73 void *bus_context;
74 const char *name;
75
76 bool async;
77 spinlock_t async_lock;
78 wait_queue_head_t async_waitq;
79 struct list_head async_list;
80 struct list_head async_free;
81 int async_ret;
82
83#ifdef CONFIG_DEBUG_FS
84 struct dentry *debugfs;
85 const char *debugfs_name;
86
87 unsigned int debugfs_reg_len;
88 unsigned int debugfs_val_len;
89 unsigned int debugfs_tot_len;
90
91 struct list_head debugfs_off_cache;
92 struct mutex cache_lock;
93#endif
94
95 unsigned int max_register;
96 bool (*writeable_reg)(struct device *dev, unsigned int reg);
97 bool (*readable_reg)(struct device *dev, unsigned int reg);
98 bool (*volatile_reg)(struct device *dev, unsigned int reg);
99 bool (*precious_reg)(struct device *dev, unsigned int reg);
100 const struct regmap_access_table *wr_table;
101 const struct regmap_access_table *rd_table;
102 const struct regmap_access_table *volatile_table;
103 const struct regmap_access_table *precious_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 read to single read */
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
166struct regcache_ops {
167 const char *name;
168 enum regcache_type type;
169 int (*init)(struct regmap *map);
170 int (*exit)(struct regmap *map);
171#ifdef CONFIG_DEBUG_FS
172 void (*debugfs_init)(struct regmap *map);
173#endif
174 int (*read)(struct regmap *map, unsigned int reg, unsigned int *value);
175 int (*write)(struct regmap *map, unsigned int reg, unsigned int value);
176 int (*sync)(struct regmap *map, unsigned int min, unsigned int max);
177 int (*drop)(struct regmap *map, unsigned int min, unsigned int max);
178};
179
180bool regmap_cached(struct regmap *map, unsigned int reg);
181bool regmap_writeable(struct regmap *map, unsigned int reg);
182bool regmap_readable(struct regmap *map, unsigned int reg);
183bool regmap_volatile(struct regmap *map, unsigned int reg);
184bool regmap_precious(struct regmap *map, unsigned int reg);
185
186int _regmap_write(struct regmap *map, unsigned int reg,
187 unsigned int val);
188
189struct regmap_range_node {
190 struct rb_node node;
191 const char *name;
192 struct regmap *map;
193
194 unsigned int range_min;
195 unsigned int range_max;
196
197 unsigned int selector_reg;
198 unsigned int selector_mask;
199 int selector_shift;
200
201 unsigned int window_start;
202 unsigned int window_len;
203};
204
205struct regmap_field {
206 struct regmap *regmap;
207 unsigned int mask;
208 /* lsb */
209 unsigned int shift;
210 unsigned int reg;
211
212 unsigned int id_size;
213 unsigned int id_offset;
214};
215
216#ifdef CONFIG_DEBUG_FS
217extern void regmap_debugfs_initcall(void);
218extern void regmap_debugfs_init(struct regmap *map, const char *name);
219extern void regmap_debugfs_exit(struct regmap *map);
220#else
221static inline void regmap_debugfs_initcall(void) { }
222static inline void regmap_debugfs_init(struct regmap *map, const char *name) { }
223static inline void regmap_debugfs_exit(struct regmap *map) { }
224#endif
225
226/* regcache core declarations */
227int regcache_init(struct regmap *map, const struct regmap_config *config);
228void regcache_exit(struct regmap *map);
229int regcache_read(struct regmap *map,
230 unsigned int reg, unsigned int *value);
231int regcache_write(struct regmap *map,
232 unsigned int reg, unsigned int value);
233int regcache_sync(struct regmap *map);
234int regcache_sync_block(struct regmap *map, void *block,
235 unsigned long *cache_present,
236 unsigned int block_base, unsigned int start,
237 unsigned int end);
238
239static inline const void *regcache_get_val_addr(struct regmap *map,
240 const void *base,
241 unsigned int idx)
242{
243 return base + (map->cache_word_size * idx);
244}
245
246unsigned int regcache_get_val(struct regmap *map, const void *base,
247 unsigned int idx);
248bool regcache_set_val(struct regmap *map, void *base, unsigned int idx,
249 unsigned int val);
250int regcache_lookup_reg(struct regmap *map, unsigned int reg);
251
252int _regmap_raw_write(struct regmap *map, unsigned int reg,
253 const void *val, size_t val_len);
254
255void regmap_async_complete_cb(struct regmap_async *async, int ret);
256
257enum regmap_endian regmap_get_val_endian(struct device *dev,
258 const struct regmap_bus *bus,
259 const struct regmap_config *config);
260
261extern struct regcache_ops regcache_rbtree_ops;
262extern struct regcache_ops regcache_lzo_ops;
263extern struct regcache_ops regcache_flat_ops;
264
265static inline const char *regmap_name(const struct regmap *map)
266{
267 if (map->dev)
268 return dev_name(map->dev);
269
270 return map->name;
271}
272
273static inline unsigned int regmap_get_offset(const struct regmap *map,
274 unsigned int index)
275{
276 if (map->reg_stride_order >= 0)
277 return index << map->reg_stride_order;
278 else
279 return index * map->reg_stride;
280}
281
282static inline unsigned int regcache_get_index_by_order(const struct regmap *map,
283 unsigned int reg)
284{
285 return reg >> map->reg_stride_order;
286}
287
288#endif
Note: See TracBrowser for help on using the repository browser.