]>
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); | |
0a9b2d1c | 64 | int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val); |
d026d70a | 65 | int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val); |
8b977c54 | 66 | int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val); |
69aba794 | 67 | |
e2a5402e SK |
68 | /* direct nvmem device read/write interface */ |
69 | struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); | |
70 | struct nvmem_device *devm_nvmem_device_get(struct device *dev, | |
71 | const char *name); | |
72 | void nvmem_device_put(struct nvmem_device *nvmem); | |
73 | void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem); | |
74 | int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset, | |
75 | size_t bytes, void *buf); | |
76 | int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset, | |
77 | size_t bytes, void *buf); | |
78 | ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, | |
79 | struct nvmem_cell_info *info, void *buf); | |
80 | int nvmem_device_cell_write(struct nvmem_device *nvmem, | |
81 | struct nvmem_cell_info *info, void *buf); | |
82 | ||
d7b9fd16 BG |
83 | const char *nvmem_dev_name(struct nvmem_device *nvmem); |
84 | ||
506157be BG |
85 | void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, |
86 | size_t nentries); | |
87 | void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, | |
88 | size_t nentries); | |
89 | ||
bee1138b BG |
90 | int nvmem_register_notifier(struct notifier_block *nb); |
91 | int nvmem_unregister_notifier(struct notifier_block *nb); | |
92 | ||
8c2a2b8c TB |
93 | struct nvmem_device *nvmem_device_find(void *data, |
94 | int (*match)(struct device *dev, const void *data)); | |
95 | ||
69aba794 SK |
96 | #else |
97 | ||
98 | static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, | |
165589f0 | 99 | const char *id) |
69aba794 | 100 | { |
20167b70 | 101 | return ERR_PTR(-EOPNOTSUPP); |
69aba794 SK |
102 | } |
103 | ||
104 | static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, | |
165589f0 | 105 | const char *id) |
69aba794 | 106 | { |
20167b70 | 107 | return ERR_PTR(-EOPNOTSUPP); |
69aba794 SK |
108 | } |
109 | ||
110 | static inline void devm_nvmem_cell_put(struct device *dev, | |
111 | struct nvmem_cell *cell) | |
112 | { | |
113 | ||
114 | } | |
115 | static inline void nvmem_cell_put(struct nvmem_cell *cell) | |
116 | { | |
117 | } | |
118 | ||
a6c50912 | 119 | static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) |
69aba794 | 120 | { |
20167b70 | 121 | return ERR_PTR(-EOPNOTSUPP); |
69aba794 SK |
122 | } |
123 | ||
124 | static inline int nvmem_cell_write(struct nvmem_cell *cell, | |
9b8303fc | 125 | void *buf, size_t len) |
69aba794 | 126 | { |
20167b70 | 127 | return -EOPNOTSUPP; |
69aba794 | 128 | } |
e2a5402e | 129 | |
0a9b2d1c FG |
130 | static inline int nvmem_cell_read_u16(struct device *dev, |
131 | const char *cell_id, u16 *val) | |
132 | { | |
133 | return -EOPNOTSUPP; | |
134 | } | |
135 | ||
d026d70a LC |
136 | static inline int nvmem_cell_read_u32(struct device *dev, |
137 | const char *cell_id, u32 *val) | |
138 | { | |
20167b70 | 139 | return -EOPNOTSUPP; |
d026d70a LC |
140 | } |
141 | ||
8b977c54 YL |
142 | static inline int nvmem_cell_read_u64(struct device *dev, |
143 | const char *cell_id, u64 *val) | |
144 | { | |
145 | return -EOPNOTSUPP; | |
146 | } | |
147 | ||
e2a5402e SK |
148 | static inline struct nvmem_device *nvmem_device_get(struct device *dev, |
149 | const char *name) | |
150 | { | |
20167b70 | 151 | return ERR_PTR(-EOPNOTSUPP); |
e2a5402e SK |
152 | } |
153 | ||
154 | static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev, | |
155 | const char *name) | |
156 | { | |
20167b70 | 157 | return ERR_PTR(-EOPNOTSUPP); |
e2a5402e SK |
158 | } |
159 | ||
160 | static inline void nvmem_device_put(struct nvmem_device *nvmem) | |
161 | { | |
162 | } | |
163 | ||
164 | static inline void devm_nvmem_device_put(struct device *dev, | |
165 | struct nvmem_device *nvmem) | |
166 | { | |
167 | } | |
168 | ||
169 | static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, | |
170 | struct nvmem_cell_info *info, | |
171 | void *buf) | |
172 | { | |
20167b70 | 173 | return -EOPNOTSUPP; |
e2a5402e SK |
174 | } |
175 | ||
176 | static inline int nvmem_device_cell_write(struct nvmem_device *nvmem, | |
177 | struct nvmem_cell_info *info, | |
178 | void *buf) | |
179 | { | |
20167b70 | 180 | return -EOPNOTSUPP; |
e2a5402e SK |
181 | } |
182 | ||
183 | static inline int nvmem_device_read(struct nvmem_device *nvmem, | |
184 | unsigned int offset, size_t bytes, | |
185 | void *buf) | |
186 | { | |
20167b70 | 187 | return -EOPNOTSUPP; |
e2a5402e SK |
188 | } |
189 | ||
190 | static inline int nvmem_device_write(struct nvmem_device *nvmem, | |
191 | unsigned int offset, size_t bytes, | |
192 | void *buf) | |
193 | { | |
20167b70 | 194 | return -EOPNOTSUPP; |
e2a5402e | 195 | } |
d7b9fd16 BG |
196 | |
197 | static inline const char *nvmem_dev_name(struct nvmem_device *nvmem) | |
198 | { | |
199 | return NULL; | |
200 | } | |
201 | ||
506157be BG |
202 | static inline void |
203 | nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} | |
204 | static inline void | |
205 | nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} | |
206 | ||
bee1138b BG |
207 | static inline int nvmem_register_notifier(struct notifier_block *nb) |
208 | { | |
20167b70 | 209 | return -EOPNOTSUPP; |
bee1138b BG |
210 | } |
211 | ||
212 | static inline int nvmem_unregister_notifier(struct notifier_block *nb) | |
213 | { | |
20167b70 | 214 | return -EOPNOTSUPP; |
bee1138b BG |
215 | } |
216 | ||
8c2a2b8c TB |
217 | static inline struct nvmem_device *nvmem_device_find(void *data, |
218 | int (*match)(struct device *dev, const void *data)) | |
219 | { | |
220 | return NULL; | |
221 | } | |
222 | ||
69aba794 SK |
223 | #endif /* CONFIG_NVMEM */ |
224 | ||
225 | #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) | |
226 | struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, | |
165589f0 | 227 | const char *id); |
e2a5402e SK |
228 | struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
229 | const char *name); | |
69aba794 SK |
230 | #else |
231 | static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, | |
165589f0 | 232 | const char *id) |
69aba794 | 233 | { |
20167b70 | 234 | return ERR_PTR(-EOPNOTSUPP); |
69aba794 | 235 | } |
e2a5402e SK |
236 | |
237 | static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, | |
238 | const char *name) | |
239 | { | |
20167b70 | 240 | return ERR_PTR(-EOPNOTSUPP); |
e2a5402e | 241 | } |
69aba794 SK |
242 | #endif /* CONFIG_NVMEM && CONFIG_OF */ |
243 | ||
eace75cf | 244 | #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */ |