xref: /linux/drivers/base/regmap/internal.h (revision ce7240e445303de3ca66e6d08f17a2ec278a5bf6)
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 
19 struct regmap;
20 struct regcache_ops;
21 
22 struct regmap_format {
23 	size_t buf_size;
24 	size_t reg_bytes;
25 	size_t pad_bytes;
26 	size_t val_bytes;
27 	void (*format_write)(struct regmap *map,
28 			     unsigned int reg, unsigned int val);
29 	void (*format_reg)(void *buf, unsigned int reg, unsigned int shift);
30 	void (*format_val)(void *buf, unsigned int val, unsigned int shift);
31 	unsigned int (*parse_val)(void *buf);
32 };
33 
34 typedef void (*regmap_lock)(struct regmap *map);
35 typedef void (*regmap_unlock)(struct regmap *map);
36 
37 struct regmap {
38 	struct mutex mutex;
39 	spinlock_t spinlock;
40 	regmap_lock lock;
41 	regmap_unlock unlock;
42 
43 	struct device *dev; /* Device we do I/O on */
44 	void *work_buf;     /* Scratch buffer used to format I/O */
45 	struct regmap_format format;  /* Buffer format */
46 	const struct regmap_bus *bus;
47 	void *bus_context;
48 	const char *name;
49 
50 #ifdef CONFIG_DEBUG_FS
51 	struct dentry *debugfs;
52 	const char *debugfs_name;
53 #endif
54 
55 	unsigned int max_register;
56 	bool (*writeable_reg)(struct device *dev, unsigned int reg);
57 	bool (*readable_reg)(struct device *dev, unsigned int reg);
58 	bool (*volatile_reg)(struct device *dev, unsigned int reg);
59 	bool (*precious_reg)(struct device *dev, unsigned int reg);
60 
61 	u8 read_flag_mask;
62 	u8 write_flag_mask;
63 
64 	/* number of bits to (left) shift the reg value when formatting*/
65 	int reg_shift;
66 	int reg_stride;
67 
68 	/* regcache specific members */
69 	const struct regcache_ops *cache_ops;
70 	enum regcache_type cache_type;
71 
72 	/* number of bytes in reg_defaults_raw */
73 	unsigned int cache_size_raw;
74 	/* number of bytes per word in reg_defaults_raw */
75 	unsigned int cache_word_size;
76 	/* number of entries in reg_defaults */
77 	unsigned int num_reg_defaults;
78 	/* number of entries in reg_defaults_raw */
79 	unsigned int num_reg_defaults_raw;
80 
81 	/* if set, only the cache is modified not the HW */
82 	u32 cache_only;
83 	/* if set, only the HW is modified not the cache */
84 	u32 cache_bypass;
85 	/* if set, remember to free reg_defaults_raw */
86 	bool cache_free;
87 
88 	struct reg_default *reg_defaults;
89 	const void *reg_defaults_raw;
90 	void *cache;
91 	u32 cache_dirty;
92 
93 	struct reg_default *patch;
94 	int patch_regs;
95 
96 	/* if set, converts bulk rw to single rw */
97 	bool use_single_rw;
98 };
99 
100 struct regcache_ops {
101 	const char *name;
102 	enum regcache_type type;
103 	int (*init)(struct regmap *map);
104 	int (*exit)(struct regmap *map);
105 	int (*read)(struct regmap *map, unsigned int reg, unsigned int *value);
106 	int (*write)(struct regmap *map, unsigned int reg, unsigned int value);
107 	int (*sync)(struct regmap *map, unsigned int min, unsigned int max);
108 };
109 
110 bool regmap_writeable(struct regmap *map, unsigned int reg);
111 bool regmap_readable(struct regmap *map, unsigned int reg);
112 bool regmap_volatile(struct regmap *map, unsigned int reg);
113 bool regmap_precious(struct regmap *map, unsigned int reg);
114 
115 int _regmap_write(struct regmap *map, unsigned int reg,
116 		  unsigned int val);
117 
118 #ifdef CONFIG_DEBUG_FS
119 extern void regmap_debugfs_initcall(void);
120 extern void regmap_debugfs_init(struct regmap *map, const char *name);
121 extern void regmap_debugfs_exit(struct regmap *map);
122 #else
123 static inline void regmap_debugfs_initcall(void) { }
124 static inline void regmap_debugfs_init(struct regmap *map, const char *name) { }
125 static inline void regmap_debugfs_exit(struct regmap *map) { }
126 #endif
127 
128 /* regcache core declarations */
129 int regcache_init(struct regmap *map, const struct regmap_config *config);
130 void regcache_exit(struct regmap *map);
131 int regcache_read(struct regmap *map,
132 		       unsigned int reg, unsigned int *value);
133 int regcache_write(struct regmap *map,
134 			unsigned int reg, unsigned int value);
135 int regcache_sync(struct regmap *map);
136 
137 unsigned int regcache_get_val(const void *base, unsigned int idx,
138 			      unsigned int word_size);
139 bool regcache_set_val(void *base, unsigned int idx,
140 		      unsigned int val, unsigned int word_size);
141 int regcache_lookup_reg(struct regmap *map, unsigned int reg);
142 
143 extern struct regcache_ops regcache_rbtree_ops;
144 extern struct regcache_ops regcache_lzo_ops;
145 
146 #endif
147