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