2 * Register map access API internal header
4 * Copyright 2011 Wolfson Microelectronics plc
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
13 #ifndef _REGMAP_INTERNAL_H
14 #define _REGMAP_INTERNAL_H
16 #include <linux/regmap.h>
18 #include <linux/list.h>
23 struct regmap_debugfs_off_cache {
24 struct list_head list;
27 unsigned int base_reg;
30 struct regmap_format {
35 void (*format_write)(struct regmap *map,
36 unsigned int reg, unsigned int val);
37 void (*format_reg)(void *buf, unsigned int reg, unsigned int shift);
38 void (*format_val)(void *buf, unsigned int val, unsigned int shift);
39 unsigned int (*parse_val)(void *buf);
47 void *lock_arg; /* This is passed to lock/unlock functions */
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;
56 #ifdef CONFIG_DEBUG_FS
57 struct dentry *debugfs;
58 const char *debugfs_name;
60 unsigned int debugfs_reg_len;
61 unsigned int debugfs_val_len;
62 unsigned int debugfs_tot_len;
64 struct list_head debugfs_off_cache;
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);
71 bool (*precious_reg)(struct device *dev, unsigned int reg);
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;
80 /* number of bits to (left) shift the reg value when formatting*/
84 /* regcache specific members */
85 const struct regcache_ops *cache_ops;
86 enum regcache_type cache_type;
88 /* number of bytes in reg_defaults_raw */
89 unsigned int cache_size_raw;
90 /* number of bytes per word in reg_defaults_raw */
91 unsigned int cache_word_size;
92 /* number of entries in reg_defaults */
93 unsigned int num_reg_defaults;
94 /* number of entries in reg_defaults_raw */
95 unsigned int num_reg_defaults_raw;
97 /* if set, only the cache is modified not the HW */
99 /* if set, only the HW is modified not the cache */
101 /* if set, remember to free reg_defaults_raw */
104 struct reg_default *reg_defaults;
105 const void *reg_defaults_raw;
109 struct reg_default *patch;
112 /* if set, converts bulk rw to single rw */
115 struct rb_root range_tree;
116 void *selector_work_buf; /* Scratch buffer used for selector */
119 struct regcache_ops {
121 enum regcache_type type;
122 int (*init)(struct regmap *map);
123 int (*exit)(struct regmap *map);
124 int (*read)(struct regmap *map, unsigned int reg, unsigned int *value);
125 int (*write)(struct regmap *map, unsigned int reg, unsigned int value);
126 int (*sync)(struct regmap *map, unsigned int min, unsigned int max);
129 bool regmap_writeable(struct regmap *map, unsigned int reg);
130 bool regmap_readable(struct regmap *map, unsigned int reg);
131 bool regmap_volatile(struct regmap *map, unsigned int reg);
132 bool regmap_precious(struct regmap *map, unsigned int reg);
134 int _regmap_write(struct regmap *map, unsigned int reg,
137 struct regmap_range_node {
142 unsigned int range_min;
143 unsigned int range_max;
145 unsigned int selector_reg;
146 unsigned int selector_mask;
149 unsigned int window_start;
150 unsigned int window_len;
153 #ifdef CONFIG_DEBUG_FS
154 extern void regmap_debugfs_initcall(void);
155 extern void regmap_debugfs_init(struct regmap *map, const char *name);
156 extern void regmap_debugfs_exit(struct regmap *map);
158 static inline void regmap_debugfs_initcall(void) { }
159 static inline void regmap_debugfs_init(struct regmap *map, const char *name) { }
160 static inline void regmap_debugfs_exit(struct regmap *map) { }
163 /* regcache core declarations */
164 int regcache_init(struct regmap *map, const struct regmap_config *config);
165 void regcache_exit(struct regmap *map);
166 int regcache_read(struct regmap *map,
167 unsigned int reg, unsigned int *value);
168 int regcache_write(struct regmap *map,
169 unsigned int reg, unsigned int value);
170 int regcache_sync(struct regmap *map);
172 unsigned int regcache_get_val(const void *base, unsigned int idx,
173 unsigned int word_size);
174 bool regcache_set_val(void *base, unsigned int idx,
175 unsigned int val, unsigned int word_size);
176 int regcache_lookup_reg(struct regmap *map, unsigned int reg);
178 extern struct regcache_ops regcache_rbtree_ops;
179 extern struct regcache_ops regcache_lzo_ops;