Commit | Line | Data |
---|---|---|
93de9124 MB |
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 | ||
13 | #ifndef _REGMAP_INTERNAL_H | |
14 | #define _REGMAP_INTERNAL_H | |
15 | ||
16 | #include <linux/regmap.h> | |
31244e39 | 17 | #include <linux/fs.h> |
5166b7c0 | 18 | #include <linux/list.h> |
93de9124 MB |
19 | |
20 | struct regmap; | |
9fabe24e | 21 | struct regcache_ops; |
93de9124 | 22 | |
5166b7c0 MB |
23 | struct regmap_debugfs_off_cache { |
24 | struct list_head list; | |
25 | off_t min; | |
26 | off_t max; | |
27 | unsigned int base_reg; | |
28 | }; | |
29 | ||
93de9124 MB |
30 | struct regmap_format { |
31 | size_t buf_size; | |
32 | size_t reg_bytes; | |
82159ba8 | 33 | size_t pad_bytes; |
93de9124 MB |
34 | size_t val_bytes; |
35 | void (*format_write)(struct regmap *map, | |
36 | unsigned int reg, unsigned int val); | |
d939fb9a MR |
37 | void (*format_reg)(void *buf, unsigned int reg, unsigned int shift); |
38 | void (*format_val)(void *buf, unsigned int val, unsigned int shift); | |
93de9124 MB |
39 | unsigned int (*parse_val)(void *buf); |
40 | }; | |
41 | ||
42 | struct regmap { | |
bacdbe07 SW |
43 | struct mutex mutex; |
44 | spinlock_t spinlock; | |
45 | regmap_lock lock; | |
46 | regmap_unlock unlock; | |
0d4529c5 | 47 | void *lock_arg; /* This is passed to lock/unlock functions */ |
93de9124 MB |
48 | |
49 | struct device *dev; /* Device we do I/O on */ | |
50 | void *work_buf; /* Scratch buffer used to format I/O */ | |
51 | struct regmap_format format; /* Buffer format */ | |
52 | const struct regmap_bus *bus; | |
0135bbcc | 53 | void *bus_context; |
72b39f6f | 54 | const char *name; |
93de9124 | 55 | |
31244e39 MB |
56 | #ifdef CONFIG_DEBUG_FS |
57 | struct dentry *debugfs; | |
d3c242e1 | 58 | const char *debugfs_name; |
cbc1938b MB |
59 | |
60 | unsigned int debugfs_reg_len; | |
61 | unsigned int debugfs_val_len; | |
62 | unsigned int debugfs_tot_len; | |
5166b7c0 MB |
63 | |
64 | struct list_head debugfs_off_cache; | |
31244e39 MB |
65 | #endif |
66 | ||
93de9124 MB |
67 | unsigned int max_register; |
68 | bool (*writeable_reg)(struct device *dev, unsigned int reg); | |
69 | bool (*readable_reg)(struct device *dev, unsigned int reg); | |
70 | bool (*volatile_reg)(struct device *dev, unsigned int reg); | |
2efe1642 | 71 | bool (*precious_reg)(struct device *dev, unsigned int reg); |
76aad392 DC |
72 | const struct regmap_access_table *wr_table; |
73 | const struct regmap_access_table *rd_table; | |
74 | const struct regmap_access_table *volatile_table; | |
75 | const struct regmap_access_table *precious_table; | |
6f306441 | 76 | |
ad278406 AS |
77 | int (*reg_read)(void *context, unsigned int reg, unsigned int *val); |
78 | ||
6f306441 LPC |
79 | u8 read_flag_mask; |
80 | u8 write_flag_mask; | |
9fabe24e | 81 | |
d939fb9a MR |
82 | /* number of bits to (left) shift the reg value when formatting*/ |
83 | int reg_shift; | |
f01ee60f | 84 | int reg_stride; |
d939fb9a | 85 | |
9fabe24e DP |
86 | /* regcache specific members */ |
87 | const struct regcache_ops *cache_ops; | |
88 | enum regcache_type cache_type; | |
89 | ||
90 | /* number of bytes in reg_defaults_raw */ | |
91 | unsigned int cache_size_raw; | |
92 | /* number of bytes per word in reg_defaults_raw */ | |
93 | unsigned int cache_word_size; | |
94 | /* number of entries in reg_defaults */ | |
95 | unsigned int num_reg_defaults; | |
96 | /* number of entries in reg_defaults_raw */ | |
97 | unsigned int num_reg_defaults_raw; | |
98 | ||
99 | /* if set, only the cache is modified not the HW */ | |
847fb6fd | 100 | u32 cache_only; |
9fabe24e | 101 | /* if set, only the HW is modified not the cache */ |
847fb6fd | 102 | u32 cache_bypass; |
9fabe24e | 103 | /* if set, remember to free reg_defaults_raw */ |
847fb6fd | 104 | bool cache_free; |
9fabe24e DP |
105 | |
106 | struct reg_default *reg_defaults; | |
107 | const void *reg_defaults_raw; | |
108 | void *cache; | |
847fb6fd | 109 | u32 cache_dirty; |
22f0d90a MB |
110 | |
111 | struct reg_default *patch; | |
112 | int patch_regs; | |
2e33caf1 AJ |
113 | |
114 | /* if set, converts bulk rw to single rw */ | |
115 | bool use_single_rw; | |
6863ca62 KG |
116 | |
117 | struct rb_root range_tree; | |
118 | void *selector_work_buf; /* Scratch buffer used for selector */ | |
9fabe24e DP |
119 | }; |
120 | ||
121 | struct regcache_ops { | |
122 | const char *name; | |
123 | enum regcache_type type; | |
124 | int (*init)(struct regmap *map); | |
125 | int (*exit)(struct regmap *map); | |
126 | int (*read)(struct regmap *map, unsigned int reg, unsigned int *value); | |
127 | int (*write)(struct regmap *map, unsigned int reg, unsigned int value); | |
ac8d91c8 | 128 | int (*sync)(struct regmap *map, unsigned int min, unsigned int max); |
93de9124 MB |
129 | }; |
130 | ||
8de2f081 MB |
131 | bool regmap_writeable(struct regmap *map, unsigned int reg); |
132 | bool regmap_readable(struct regmap *map, unsigned int reg); | |
133 | bool regmap_volatile(struct regmap *map, unsigned int reg); | |
134 | bool regmap_precious(struct regmap *map, unsigned int reg); | |
135 | ||
4d2dc095 DP |
136 | int _regmap_write(struct regmap *map, unsigned int reg, |
137 | unsigned int val); | |
138 | ||
6863ca62 KG |
139 | struct regmap_range_node { |
140 | struct rb_node node; | |
d058bb49 | 141 | const char *name; |
4b020b3f | 142 | struct regmap *map; |
6863ca62 KG |
143 | |
144 | unsigned int range_min; | |
145 | unsigned int range_max; | |
146 | ||
147 | unsigned int selector_reg; | |
148 | unsigned int selector_mask; | |
149 | int selector_shift; | |
150 | ||
151 | unsigned int window_start; | |
152 | unsigned int window_len; | |
153 | }; | |
154 | ||
31244e39 MB |
155 | #ifdef CONFIG_DEBUG_FS |
156 | extern void regmap_debugfs_initcall(void); | |
d3c242e1 | 157 | extern void regmap_debugfs_init(struct regmap *map, const char *name); |
31244e39 MB |
158 | extern void regmap_debugfs_exit(struct regmap *map); |
159 | #else | |
bbcf61ca | 160 | static inline void regmap_debugfs_initcall(void) { } |
abec95ad | 161 | static inline void regmap_debugfs_init(struct regmap *map, const char *name) { } |
bbcf61ca | 162 | static inline void regmap_debugfs_exit(struct regmap *map) { } |
31244e39 MB |
163 | #endif |
164 | ||
9fabe24e | 165 | /* regcache core declarations */ |
e5e3b8ab | 166 | int regcache_init(struct regmap *map, const struct regmap_config *config); |
9fabe24e DP |
167 | void regcache_exit(struct regmap *map); |
168 | int regcache_read(struct regmap *map, | |
169 | unsigned int reg, unsigned int *value); | |
170 | int regcache_write(struct regmap *map, | |
171 | unsigned int reg, unsigned int value); | |
172 | int regcache_sync(struct regmap *map); | |
173 | ||
174 | unsigned int regcache_get_val(const void *base, unsigned int idx, | |
175 | unsigned int word_size); | |
176 | bool regcache_set_val(void *base, unsigned int idx, | |
177 | unsigned int val, unsigned int word_size); | |
178 | int regcache_lookup_reg(struct regmap *map, unsigned int reg); | |
9fabe24e | 179 | |
28644c80 | 180 | extern struct regcache_ops regcache_rbtree_ops; |
2cbbb579 DP |
181 | extern struct regcache_ops regcache_lzo_ops; |
182 | ||
93de9124 | 183 | #endif |