]>
Commit | Line | Data |
---|---|---|
b1c1db98 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
eace75cf SK |
2 | /* |
3 | * nvmem framework consumer. | |
4 | * | |
5 | * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org> | |
6 | * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com> | |
eace75cf SK |
7 | */ |
8 | ||
9 | #ifndef _LINUX_NVMEM_CONSUMER_H | |
10 | #define _LINUX_NVMEM_CONSUMER_H | |
11 | ||
4da69f49 SK |
12 | #include <linux/err.h> |
13 | #include <linux/errno.h> | |
bee1138b | 14 | #include <linux/notifier.h> |
4da69f49 | 15 | |
69aba794 SK |
16 | struct device; |
17 | struct device_node; | |
18 | /* consumer cookie */ | |
19 | struct nvmem_cell; | |
e2a5402e | 20 | struct nvmem_device; |
69aba794 | 21 | |
eace75cf SK |
22 | struct nvmem_cell_info { |
23 | const char *name; | |
24 | unsigned int offset; | |
25 | unsigned int bytes; | |
26 | unsigned int bit_offset; | |
27 | unsigned int nbits; | |
28 | }; | |
29 | ||
506157be BG |
30 | /** |
31 | * struct nvmem_cell_lookup - cell lookup entry | |
32 | * | |
33 | * @nvmem_name: Name of the provider. | |
34 | * @cell_name: Name of the nvmem cell as defined in the name field of | |
35 | * struct nvmem_cell_info. | |
36 | * @dev_id: Name of the consumer device that will be associated with | |
37 | * this cell. | |
38 | * @con_id: Connector id for this cell lookup. | |
39 | */ | |
40 | struct nvmem_cell_lookup { | |
41 | const char *nvmem_name; | |
42 | const char *cell_name; | |
43 | const char *dev_id; | |
44 | const char *con_id; | |
45 | struct list_head node; | |
46 | }; | |
47 | ||
bee1138b BG |
48 | enum { |
49 | NVMEM_ADD = 1, | |
50 | NVMEM_REMOVE, | |
51 | NVMEM_CELL_ADD, | |
52 | NVMEM_CELL_REMOVE, | |
53 | }; | |
54 | ||
69aba794 SK |
55 | #if IS_ENABLED(CONFIG_NVMEM) |
56 | ||
57 | /* Cell based interface */ | |
165589f0 BG |
58 | struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id); |
59 | struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id); | |
69aba794 SK |
60 | void nvmem_cell_put(struct nvmem_cell *cell); |
61 | void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); | |
62 | void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); | |
63 | int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len); | |
5037d368 | 64 | int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val); |
0a9b2d1c | 65 | int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val); |
d026d70a | 66 | int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val); |
8b977c54 | 67 | int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val); |
a28e824f DA |
68 | int nvmem_cell_read_variable_le_u32(struct device *dev, const char *cell_id, |
69 | u32 *val); | |
70 | int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id, | |
71 | u64 *val); | |
69aba794 | 72 | |
e2a5402e SK |
73 | /* direct nvmem device read/write interface */ |
74 | struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); | |
75 | struct nvmem_device *devm_nvmem_device_get(struct device *dev, | |
76 | const char *name); | |
77 | void nvmem_device_put(struct nvmem_device *nvmem); | |
78 | void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem); | |
79 | int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset, | |
80 | size_t bytes, void *buf); | |
81 | int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset, | |
82 | size_t bytes, void *buf); | |
83 | ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, | |
84 | struct nvmem_cell_info *info, void *buf); | |
85 | int nvmem_device_cell_write(struct nvmem_device *nvmem, | |
86 | struct nvmem_cell_info *info, void *buf); | |
87 | ||
d7b9fd16 BG |
88 | const char *nvmem_dev_name(struct nvmem_device *nvmem); |
89 | ||
506157be BG |
90 | void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, |
91 | size_t nentries); | |
92 | void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, | |
93 | size_t nentries); | |
94 | ||
bee1138b BG |
95 | int nvmem_register_notifier(struct notifier_block *nb); |
96 | int nvmem_unregister_notifier(struct notifier_block *nb); | |
97 | ||
8c2a2b8c TB |
98 | struct nvmem_device *nvmem_device_find(void *data, |
99 | int (*match)(struct device *dev, const void *data)); | |
100 | ||
69aba794 SK |
101 | #else |
102 | ||
103 | static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, | |
165589f0 | 104 | const char *id) |
69aba794 | 105 | { |
20167b70 | 106 | return ERR_PTR(-EOPNOTSUPP); |
69aba794 SK |
107 | } |
108 | ||
109 | static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, | |
165589f0 | 110 | const char *id) |
69aba794 | 111 | { |
20167b70 | 112 | return ERR_PTR(-EOPNOTSUPP); |
69aba794 SK |
113 | } |
114 | ||
115 | static inline void devm_nvmem_cell_put(struct device *dev, | |
116 | struct nvmem_cell *cell) | |
117 | { | |
118 | ||
119 | } | |
120 | static inline void nvmem_cell_put(struct nvmem_cell *cell) | |
121 | { | |
122 | } | |
123 | ||
a6c50912 | 124 | static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) |
69aba794 | 125 | { |
20167b70 | 126 | return ERR_PTR(-EOPNOTSUPP); |
69aba794 SK |
127 | } |
128 | ||
129 | static inline int nvmem_cell_write(struct nvmem_cell *cell, | |
9b8303fc | 130 | void *buf, size_t len) |
69aba794 | 131 | { |
20167b70 | 132 | return -EOPNOTSUPP; |
69aba794 | 133 | } |
e2a5402e | 134 | |
0a9b2d1c FG |
135 | static inline int nvmem_cell_read_u16(struct device *dev, |
136 | const char *cell_id, u16 *val) | |
137 | { | |
138 | return -EOPNOTSUPP; | |
139 | } | |
140 | ||
d026d70a LC |
141 | static inline int nvmem_cell_read_u32(struct device *dev, |
142 | const char *cell_id, u32 *val) | |
143 | { | |
20167b70 | 144 | return -EOPNOTSUPP; |
d026d70a LC |
145 | } |
146 | ||
8b977c54 YL |
147 | static inline int nvmem_cell_read_u64(struct device *dev, |
148 | const char *cell_id, u64 *val) | |
149 | { | |
150 | return -EOPNOTSUPP; | |
151 | } | |
152 | ||
7a8aa39d DA |
153 | static inline int nvmem_cell_read_variable_le_u32(struct device *dev, |
154 | const char *cell_id, | |
155 | u32 *val) | |
156 | { | |
157 | return -EOPNOTSUPP; | |
158 | } | |
159 | ||
160 | static inline int nvmem_cell_read_variable_le_u64(struct device *dev, | |
161 | const char *cell_id, | |
162 | u64 *val) | |
163 | { | |
164 | return -EOPNOTSUPP; | |
165 | } | |
166 | ||
e2a5402e SK |
167 | static inline struct nvmem_device *nvmem_device_get(struct device *dev, |
168 | const char *name) | |
169 | { | |
20167b70 | 170 | return ERR_PTR(-EOPNOTSUPP); |
e2a5402e SK |
171 | } |
172 | ||
173 | static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev, | |
174 | const char *name) | |
175 | { | |
20167b70 | 176 | return ERR_PTR(-EOPNOTSUPP); |
e2a5402e SK |
177 | } |
178 | ||
179 | static inline void nvmem_device_put(struct nvmem_device *nvmem) | |
180 | { | |
181 | } | |
182 | ||
183 | static inline void devm_nvmem_device_put(struct device *dev, | |
184 | struct nvmem_device *nvmem) | |
185 | { | |
186 | } | |
187 | ||
188 | static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, | |
189 | struct nvmem_cell_info *info, | |
190 | void *buf) | |
191 | { | |
20167b70 | 192 | return -EOPNOTSUPP; |
e2a5402e SK |
193 | } |
194 | ||
195 | static inline int nvmem_device_cell_write(struct nvmem_device *nvmem, | |
196 | struct nvmem_cell_info *info, | |
197 | void *buf) | |
198 | { | |
20167b70 | 199 | return -EOPNOTSUPP; |
e2a5402e SK |
200 | } |
201 | ||
202 | static inline int nvmem_device_read(struct nvmem_device *nvmem, | |
203 | unsigned int offset, size_t bytes, | |
204 | void *buf) | |
205 | { | |
20167b70 | 206 | return -EOPNOTSUPP; |
e2a5402e SK |
207 | } |
208 | ||
209 | static inline int nvmem_device_write(struct nvmem_device *nvmem, | |
210 | unsigned int offset, size_t bytes, | |
211 | void *buf) | |
212 | { | |
20167b70 | 213 | return -EOPNOTSUPP; |
e2a5402e | 214 | } |
d7b9fd16 BG |
215 | |
216 | static inline const char *nvmem_dev_name(struct nvmem_device *nvmem) | |
217 | { | |
218 | return NULL; | |
219 | } | |
220 | ||
506157be BG |
221 | static inline void |
222 | nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} | |
223 | static inline void | |
224 | nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} | |
225 | ||
bee1138b BG |
226 | static inline int nvmem_register_notifier(struct notifier_block *nb) |
227 | { | |
20167b70 | 228 | return -EOPNOTSUPP; |
bee1138b BG |
229 | } |
230 | ||
231 | static inline int nvmem_unregister_notifier(struct notifier_block *nb) | |
232 | { | |
20167b70 | 233 | return -EOPNOTSUPP; |
bee1138b BG |
234 | } |
235 | ||
8c2a2b8c TB |
236 | static inline struct nvmem_device *nvmem_device_find(void *data, |
237 | int (*match)(struct device *dev, const void *data)) | |
238 | { | |
239 | return NULL; | |
240 | } | |
241 | ||
69aba794 SK |
242 | #endif /* CONFIG_NVMEM */ |
243 | ||
244 | #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) | |
245 | struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, | |
165589f0 | 246 | const char *id); |
e2a5402e SK |
247 | struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
248 | const char *name); | |
69aba794 SK |
249 | #else |
250 | static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, | |
165589f0 | 251 | const char *id) |
69aba794 | 252 | { |
20167b70 | 253 | return ERR_PTR(-EOPNOTSUPP); |
69aba794 | 254 | } |
e2a5402e SK |
255 | |
256 | static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, | |
257 | const char *name) | |
258 | { | |
20167b70 | 259 | return ERR_PTR(-EOPNOTSUPP); |
e2a5402e | 260 | } |
69aba794 SK |
261 | #endif /* CONFIG_NVMEM && CONFIG_OF */ |
262 | ||
eace75cf | 263 | #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */ |