]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/base/regmap/internal.h
Merge remote-tracking branch 'regmap/topic/lock' into regmap-next
[karo-tx-linux.git] / drivers / base / regmap / internal.h
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>
17 #include <linux/fs.h>
18 #include <linux/list.h>
19
20 struct regmap;
21 struct regcache_ops;
22
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
30 struct regmap_format {
31         size_t buf_size;
32         size_t reg_bytes;
33         size_t pad_bytes;
34         size_t val_bytes;
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);
40 };
41
42 struct regmap {
43         struct mutex mutex;
44         spinlock_t spinlock;
45         regmap_lock lock;
46         regmap_unlock unlock;
47         void *lock_arg; /* This is passed to lock/unlock functions */
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;
53         void *bus_context;
54         const char *name;
55
56 #ifdef CONFIG_DEBUG_FS
57         struct dentry *debugfs;
58         const char *debugfs_name;
59
60         unsigned int debugfs_reg_len;
61         unsigned int debugfs_val_len;
62         unsigned int debugfs_tot_len;
63
64         struct list_head debugfs_off_cache;
65 #endif
66
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
73         u8 read_flag_mask;
74         u8 write_flag_mask;
75
76         /* number of bits to (left) shift the reg value when formatting*/
77         int reg_shift;
78         int reg_stride;
79
80         /* regcache specific members */
81         const struct regcache_ops *cache_ops;
82         enum regcache_type cache_type;
83
84         /* number of bytes in reg_defaults_raw */
85         unsigned int cache_size_raw;
86         /* number of bytes per word in reg_defaults_raw */
87         unsigned int cache_word_size;
88         /* number of entries in reg_defaults */
89         unsigned int num_reg_defaults;
90         /* number of entries in reg_defaults_raw */
91         unsigned int num_reg_defaults_raw;
92
93         /* if set, only the cache is modified not the HW */
94         u32 cache_only;
95         /* if set, only the HW is modified not the cache */
96         u32 cache_bypass;
97         /* if set, remember to free reg_defaults_raw */
98         bool cache_free;
99
100         struct reg_default *reg_defaults;
101         const void *reg_defaults_raw;
102         void *cache;
103         u32 cache_dirty;
104
105         struct reg_default *patch;
106         int patch_regs;
107
108         /* if set, converts bulk rw to single rw */
109         bool use_single_rw;
110
111         struct rb_root range_tree;
112         void *selector_work_buf;        /* Scratch buffer used for selector */
113 };
114
115 struct regcache_ops {
116         const char *name;
117         enum regcache_type type;
118         int (*init)(struct regmap *map);
119         int (*exit)(struct regmap *map);
120         int (*read)(struct regmap *map, unsigned int reg, unsigned int *value);
121         int (*write)(struct regmap *map, unsigned int reg, unsigned int value);
122         int (*sync)(struct regmap *map, unsigned int min, unsigned int max);
123 };
124
125 bool regmap_writeable(struct regmap *map, unsigned int reg);
126 bool regmap_readable(struct regmap *map, unsigned int reg);
127 bool regmap_volatile(struct regmap *map, unsigned int reg);
128 bool regmap_precious(struct regmap *map, unsigned int reg);
129
130 int _regmap_write(struct regmap *map, unsigned int reg,
131                   unsigned int val);
132
133 struct regmap_range_node {
134         struct rb_node node;
135         const char *name;
136         struct regmap *map;
137
138         unsigned int range_min;
139         unsigned int range_max;
140
141         unsigned int selector_reg;
142         unsigned int selector_mask;
143         int selector_shift;
144
145         unsigned int window_start;
146         unsigned int window_len;
147 };
148
149 #ifdef CONFIG_DEBUG_FS
150 extern void regmap_debugfs_initcall(void);
151 extern void regmap_debugfs_init(struct regmap *map, const char *name);
152 extern void regmap_debugfs_exit(struct regmap *map);
153 #else
154 static inline void regmap_debugfs_initcall(void) { }
155 static inline void regmap_debugfs_init(struct regmap *map, const char *name) { }
156 static inline void regmap_debugfs_exit(struct regmap *map) { }
157 #endif
158
159 /* regcache core declarations */
160 int regcache_init(struct regmap *map, const struct regmap_config *config);
161 void regcache_exit(struct regmap *map);
162 int regcache_read(struct regmap *map,
163                        unsigned int reg, unsigned int *value);
164 int regcache_write(struct regmap *map,
165                         unsigned int reg, unsigned int value);
166 int regcache_sync(struct regmap *map);
167
168 unsigned int regcache_get_val(const void *base, unsigned int idx,
169                               unsigned int word_size);
170 bool regcache_set_val(void *base, unsigned int idx,
171                       unsigned int val, unsigned int word_size);
172 int regcache_lookup_reg(struct regmap *map, unsigned int reg);
173
174 extern struct regcache_ops regcache_rbtree_ops;
175 extern struct regcache_ops regcache_lzo_ops;
176
177 #endif