0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _REGMAP_INTERNAL_H
0011 #define _REGMAP_INTERNAL_H
0012
0013 #include <linux/device.h>
0014 #include <linux/regmap.h>
0015 #include <linux/fs.h>
0016 #include <linux/list.h>
0017 #include <linux/wait.h>
0018
0019 struct regmap;
0020 struct regcache_ops;
0021
0022 struct regmap_debugfs_off_cache {
0023 struct list_head list;
0024 off_t min;
0025 off_t max;
0026 unsigned int base_reg;
0027 unsigned int max_reg;
0028 };
0029
0030 struct regmap_format {
0031 size_t buf_size;
0032 size_t reg_bytes;
0033 size_t pad_bytes;
0034 size_t reg_downshift;
0035 size_t val_bytes;
0036 void (*format_write)(struct regmap *map,
0037 unsigned int reg, unsigned int val);
0038 void (*format_reg)(void *buf, unsigned int reg, unsigned int shift);
0039 void (*format_val)(void *buf, unsigned int val, unsigned int shift);
0040 unsigned int (*parse_val)(const void *buf);
0041 void (*parse_inplace)(void *buf);
0042 };
0043
0044 struct regmap_async {
0045 struct list_head list;
0046 struct regmap *map;
0047 void *work_buf;
0048 };
0049
0050 struct regmap {
0051 union {
0052 struct mutex mutex;
0053 struct {
0054 spinlock_t spinlock;
0055 unsigned long spinlock_flags;
0056 };
0057 struct {
0058 raw_spinlock_t raw_spinlock;
0059 unsigned long raw_spinlock_flags;
0060 };
0061 };
0062 regmap_lock lock;
0063 regmap_unlock unlock;
0064 void *lock_arg;
0065 gfp_t alloc_flags;
0066 unsigned int reg_base;
0067
0068 struct device *dev;
0069 void *work_buf;
0070 struct regmap_format format;
0071 const struct regmap_bus *bus;
0072 void *bus_context;
0073 const char *name;
0074
0075 bool async;
0076 spinlock_t async_lock;
0077 wait_queue_head_t async_waitq;
0078 struct list_head async_list;
0079 struct list_head async_free;
0080 int async_ret;
0081
0082 #ifdef CONFIG_DEBUG_FS
0083 bool debugfs_disable;
0084 struct dentry *debugfs;
0085 const char *debugfs_name;
0086
0087 unsigned int debugfs_reg_len;
0088 unsigned int debugfs_val_len;
0089 unsigned int debugfs_tot_len;
0090
0091 struct list_head debugfs_off_cache;
0092 struct mutex cache_lock;
0093 #endif
0094
0095 unsigned int max_register;
0096 bool (*writeable_reg)(struct device *dev, unsigned int reg);
0097 bool (*readable_reg)(struct device *dev, unsigned int reg);
0098 bool (*volatile_reg)(struct device *dev, unsigned int reg);
0099 bool (*precious_reg)(struct device *dev, unsigned int reg);
0100 bool (*writeable_noinc_reg)(struct device *dev, unsigned int reg);
0101 bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
0102 const struct regmap_access_table *wr_table;
0103 const struct regmap_access_table *rd_table;
0104 const struct regmap_access_table *volatile_table;
0105 const struct regmap_access_table *precious_table;
0106 const struct regmap_access_table *wr_noinc_table;
0107 const struct regmap_access_table *rd_noinc_table;
0108
0109 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
0110 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
0111 int (*reg_update_bits)(void *context, unsigned int reg,
0112 unsigned int mask, unsigned int val);
0113
0114 int (*read)(void *context, const void *reg_buf, size_t reg_size,
0115 void *val_buf, size_t val_size);
0116 int (*write)(void *context, const void *data, size_t count);
0117
0118 bool defer_caching;
0119
0120 unsigned long read_flag_mask;
0121 unsigned long write_flag_mask;
0122
0123
0124 int reg_shift;
0125 int reg_stride;
0126 int reg_stride_order;
0127
0128
0129 const struct regcache_ops *cache_ops;
0130 enum regcache_type cache_type;
0131
0132
0133 unsigned int cache_size_raw;
0134
0135 unsigned int cache_word_size;
0136
0137 unsigned int num_reg_defaults;
0138
0139 unsigned int num_reg_defaults_raw;
0140
0141
0142 bool cache_only;
0143
0144 bool cache_bypass;
0145
0146 bool cache_free;
0147
0148 struct reg_default *reg_defaults;
0149 const void *reg_defaults_raw;
0150 void *cache;
0151
0152 bool cache_dirty;
0153
0154 bool no_sync_defaults;
0155
0156 struct reg_sequence *patch;
0157 int patch_regs;
0158
0159
0160 bool use_single_read;
0161
0162 bool use_single_write;
0163
0164 bool can_multi_write;
0165
0166
0167 size_t max_raw_read;
0168 size_t max_raw_write;
0169
0170 struct rb_root range_tree;
0171 void *selector_work_buf;
0172
0173 struct hwspinlock *hwlock;
0174
0175
0176 bool can_sleep;
0177 };
0178
0179 struct regcache_ops {
0180 const char *name;
0181 enum regcache_type type;
0182 int (*init)(struct regmap *map);
0183 int (*exit)(struct regmap *map);
0184 #ifdef CONFIG_DEBUG_FS
0185 void (*debugfs_init)(struct regmap *map);
0186 #endif
0187 int (*read)(struct regmap *map, unsigned int reg, unsigned int *value);
0188 int (*write)(struct regmap *map, unsigned int reg, unsigned int value);
0189 int (*sync)(struct regmap *map, unsigned int min, unsigned int max);
0190 int (*drop)(struct regmap *map, unsigned int min, unsigned int max);
0191 };
0192
0193 bool regmap_cached(struct regmap *map, unsigned int reg);
0194 bool regmap_writeable(struct regmap *map, unsigned int reg);
0195 bool regmap_readable(struct regmap *map, unsigned int reg);
0196 bool regmap_volatile(struct regmap *map, unsigned int reg);
0197 bool regmap_precious(struct regmap *map, unsigned int reg);
0198 bool regmap_writeable_noinc(struct regmap *map, unsigned int reg);
0199 bool regmap_readable_noinc(struct regmap *map, unsigned int reg);
0200
0201 int _regmap_write(struct regmap *map, unsigned int reg,
0202 unsigned int val);
0203
0204 struct regmap_range_node {
0205 struct rb_node node;
0206 const char *name;
0207 struct regmap *map;
0208
0209 unsigned int range_min;
0210 unsigned int range_max;
0211
0212 unsigned int selector_reg;
0213 unsigned int selector_mask;
0214 int selector_shift;
0215
0216 unsigned int window_start;
0217 unsigned int window_len;
0218 };
0219
0220 struct regmap_field {
0221 struct regmap *regmap;
0222 unsigned int mask;
0223
0224 unsigned int shift;
0225 unsigned int reg;
0226
0227 unsigned int id_size;
0228 unsigned int id_offset;
0229 };
0230
0231 #ifdef CONFIG_DEBUG_FS
0232 extern void regmap_debugfs_initcall(void);
0233 extern void regmap_debugfs_init(struct regmap *map);
0234 extern void regmap_debugfs_exit(struct regmap *map);
0235
0236 static inline void regmap_debugfs_disable(struct regmap *map)
0237 {
0238 map->debugfs_disable = true;
0239 }
0240
0241 #else
0242 static inline void regmap_debugfs_initcall(void) { }
0243 static inline void regmap_debugfs_init(struct regmap *map) { }
0244 static inline void regmap_debugfs_exit(struct regmap *map) { }
0245 static inline void regmap_debugfs_disable(struct regmap *map) { }
0246 #endif
0247
0248
0249 int regcache_init(struct regmap *map, const struct regmap_config *config);
0250 void regcache_exit(struct regmap *map);
0251 int regcache_read(struct regmap *map,
0252 unsigned int reg, unsigned int *value);
0253 int regcache_write(struct regmap *map,
0254 unsigned int reg, unsigned int value);
0255 int regcache_sync(struct regmap *map);
0256 int regcache_sync_block(struct regmap *map, void *block,
0257 unsigned long *cache_present,
0258 unsigned int block_base, unsigned int start,
0259 unsigned int end);
0260
0261 static inline const void *regcache_get_val_addr(struct regmap *map,
0262 const void *base,
0263 unsigned int idx)
0264 {
0265 return base + (map->cache_word_size * idx);
0266 }
0267
0268 unsigned int regcache_get_val(struct regmap *map, const void *base,
0269 unsigned int idx);
0270 bool regcache_set_val(struct regmap *map, void *base, unsigned int idx,
0271 unsigned int val);
0272 int regcache_lookup_reg(struct regmap *map, unsigned int reg);
0273
0274 int _regmap_raw_write(struct regmap *map, unsigned int reg,
0275 const void *val, size_t val_len, bool noinc);
0276
0277 void regmap_async_complete_cb(struct regmap_async *async, int ret);
0278
0279 enum regmap_endian regmap_get_val_endian(struct device *dev,
0280 const struct regmap_bus *bus,
0281 const struct regmap_config *config);
0282
0283 extern struct regcache_ops regcache_rbtree_ops;
0284 extern struct regcache_ops regcache_lzo_ops;
0285 extern struct regcache_ops regcache_flat_ops;
0286
0287 static inline const char *regmap_name(const struct regmap *map)
0288 {
0289 if (map->dev)
0290 return dev_name(map->dev);
0291
0292 return map->name;
0293 }
0294
0295 static inline unsigned int regmap_get_offset(const struct regmap *map,
0296 unsigned int index)
0297 {
0298 if (map->reg_stride_order >= 0)
0299 return index << map->reg_stride_order;
0300 else
0301 return index * map->reg_stride;
0302 }
0303
0304 static inline unsigned int regcache_get_index_by_order(const struct regmap *map,
0305 unsigned int reg)
0306 {
0307 return reg >> map->reg_stride_order;
0308 }
0309
0310 #endif