Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
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>
7 */
8
9#ifndef _LINUX_NVMEM_CONSUMER_H
10#define _LINUX_NVMEM_CONSUMER_H
11
12#include <linux/err.h>
13#include <linux/errno.h>
14#include <linux/notifier.h>
15
16struct device;
17struct device_node;
18/* consumer cookie */
19struct nvmem_cell;
20struct nvmem_device;
21
22struct 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
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 */
40struct 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
48enum {
49 NVMEM_ADD = 1,
50 NVMEM_REMOVE,
51 NVMEM_CELL_ADD,
52 NVMEM_CELL_REMOVE,
53};
54
55#if IS_ENABLED(CONFIG_NVMEM)
56
57/* Cell based interface */
58struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id);
59struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id);
60void nvmem_cell_put(struct nvmem_cell *cell);
61void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
62void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
63int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
64int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val);
65int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val);
66int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
67int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val);
68int nvmem_cell_read_variable_le_u32(struct device *dev, const char *cell_id,
69 u32 *val);
70int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id,
71 u64 *val);
72
73/* direct nvmem device read/write interface */
74struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
75struct nvmem_device *devm_nvmem_device_get(struct device *dev,
76 const char *name);
77void nvmem_device_put(struct nvmem_device *nvmem);
78void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
79int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
80 size_t bytes, void *buf);
81int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
82 size_t bytes, void *buf);
83ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
84 struct nvmem_cell_info *info, void *buf);
85int nvmem_device_cell_write(struct nvmem_device *nvmem,
86 struct nvmem_cell_info *info, void *buf);
87
88const char *nvmem_dev_name(struct nvmem_device *nvmem);
89
90void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries,
91 size_t nentries);
92void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries,
93 size_t nentries);
94
95int nvmem_register_notifier(struct notifier_block *nb);
96int nvmem_unregister_notifier(struct notifier_block *nb);
97
98struct nvmem_device *nvmem_device_find(void *data,
99 int (*match)(struct device *dev, const void *data));
100
101#else
102
103static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
104 const char *id)
105{
106 return ERR_PTR(-EOPNOTSUPP);
107}
108
109static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
110 const char *id)
111{
112 return ERR_PTR(-EOPNOTSUPP);
113}
114
115static inline void devm_nvmem_cell_put(struct device *dev,
116 struct nvmem_cell *cell)
117{
118
119}
120static inline void nvmem_cell_put(struct nvmem_cell *cell)
121{
122}
123
124static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
125{
126 return ERR_PTR(-EOPNOTSUPP);
127}
128
129static inline int nvmem_cell_write(struct nvmem_cell *cell,
130 void *buf, size_t len)
131{
132 return -EOPNOTSUPP;
133}
134
135static inline int nvmem_cell_read_u16(struct device *dev,
136 const char *cell_id, u16 *val)
137{
138 return -EOPNOTSUPP;
139}
140
141static inline int nvmem_cell_read_u32(struct device *dev,
142 const char *cell_id, u32 *val)
143{
144 return -EOPNOTSUPP;
145}
146
147static inline int nvmem_cell_read_u64(struct device *dev,
148 const char *cell_id, u64 *val)
149{
150 return -EOPNOTSUPP;
151}
152
153static inline struct nvmem_device *nvmem_device_get(struct device *dev,
154 const char *name)
155{
156 return ERR_PTR(-EOPNOTSUPP);
157}
158
159static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
160 const char *name)
161{
162 return ERR_PTR(-EOPNOTSUPP);
163}
164
165static inline void nvmem_device_put(struct nvmem_device *nvmem)
166{
167}
168
169static inline void devm_nvmem_device_put(struct device *dev,
170 struct nvmem_device *nvmem)
171{
172}
173
174static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
175 struct nvmem_cell_info *info,
176 void *buf)
177{
178 return -EOPNOTSUPP;
179}
180
181static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
182 struct nvmem_cell_info *info,
183 void *buf)
184{
185 return -EOPNOTSUPP;
186}
187
188static inline int nvmem_device_read(struct nvmem_device *nvmem,
189 unsigned int offset, size_t bytes,
190 void *buf)
191{
192 return -EOPNOTSUPP;
193}
194
195static inline int nvmem_device_write(struct nvmem_device *nvmem,
196 unsigned int offset, size_t bytes,
197 void *buf)
198{
199 return -EOPNOTSUPP;
200}
201
202static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
203{
204 return NULL;
205}
206
207static inline void
208nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
209static inline void
210nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
211
212static inline int nvmem_register_notifier(struct notifier_block *nb)
213{
214 return -EOPNOTSUPP;
215}
216
217static inline int nvmem_unregister_notifier(struct notifier_block *nb)
218{
219 return -EOPNOTSUPP;
220}
221
222static inline struct nvmem_device *nvmem_device_find(void *data,
223 int (*match)(struct device *dev, const void *data))
224{
225 return NULL;
226}
227
228#endif /* CONFIG_NVMEM */
229
230#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
231struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
232 const char *id);
233struct nvmem_device *of_nvmem_device_get(struct device_node *np,
234 const char *name);
235#else
236static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
237 const char *id)
238{
239 return ERR_PTR(-EOPNOTSUPP);
240}
241
242static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
243 const char *name)
244{
245 return ERR_PTR(-EOPNOTSUPP);
246}
247#endif /* CONFIG_NVMEM && CONFIG_OF */
248
249#endif /* ifndef _LINUX_NVMEM_CONSUMER_H */
1/* SPDX-License-Identifier: GPL-2.0 */
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>
7 */
8
9#ifndef _LINUX_NVMEM_CONSUMER_H
10#define _LINUX_NVMEM_CONSUMER_H
11
12#include <linux/err.h>
13#include <linux/errno.h>
14#include <linux/notifier.h>
15
16struct device;
17struct device_node;
18/* consumer cookie */
19struct nvmem_cell;
20struct nvmem_device;
21struct nvmem_cell_info;
22
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 */
33struct 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
41enum {
42 NVMEM_ADD = 1,
43 NVMEM_REMOVE,
44 NVMEM_CELL_ADD,
45 NVMEM_CELL_REMOVE,
46 NVMEM_LAYOUT_ADD,
47 NVMEM_LAYOUT_REMOVE,
48};
49
50#if IS_ENABLED(CONFIG_NVMEM)
51
52/* Cell based interface */
53struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id);
54struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id);
55void nvmem_cell_put(struct nvmem_cell *cell);
56void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
57void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
58int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
59int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val);
60int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val);
61int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
62int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val);
63int nvmem_cell_read_variable_le_u32(struct device *dev, const char *cell_id,
64 u32 *val);
65int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id,
66 u64 *val);
67
68/* direct nvmem device read/write interface */
69struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
70struct nvmem_device *devm_nvmem_device_get(struct device *dev,
71 const char *name);
72void nvmem_device_put(struct nvmem_device *nvmem);
73void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
74int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
75 size_t bytes, void *buf);
76int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
77 size_t bytes, void *buf);
78ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
79 struct nvmem_cell_info *info, void *buf);
80int nvmem_device_cell_write(struct nvmem_device *nvmem,
81 struct nvmem_cell_info *info, void *buf);
82
83const char *nvmem_dev_name(struct nvmem_device *nvmem);
84size_t nvmem_dev_size(struct nvmem_device *nvmem);
85
86void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries,
87 size_t nentries);
88void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries,
89 size_t nentries);
90
91int nvmem_register_notifier(struct notifier_block *nb);
92int nvmem_unregister_notifier(struct notifier_block *nb);
93
94struct nvmem_device *nvmem_device_find(void *data,
95 int (*match)(struct device *dev, const void *data));
96
97#else
98
99static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
100 const char *id)
101{
102 return ERR_PTR(-EOPNOTSUPP);
103}
104
105static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
106 const char *id)
107{
108 return ERR_PTR(-EOPNOTSUPP);
109}
110
111static inline void devm_nvmem_cell_put(struct device *dev,
112 struct nvmem_cell *cell)
113{
114
115}
116static inline void nvmem_cell_put(struct nvmem_cell *cell)
117{
118}
119
120static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
121{
122 return ERR_PTR(-EOPNOTSUPP);
123}
124
125static inline int nvmem_cell_write(struct nvmem_cell *cell,
126 void *buf, size_t len)
127{
128 return -EOPNOTSUPP;
129}
130
131static inline int nvmem_cell_read_u8(struct device *dev,
132 const char *cell_id, u8 *val)
133{
134 return -EOPNOTSUPP;
135}
136
137static inline int nvmem_cell_read_u16(struct device *dev,
138 const char *cell_id, u16 *val)
139{
140 return -EOPNOTSUPP;
141}
142
143static inline int nvmem_cell_read_u32(struct device *dev,
144 const char *cell_id, u32 *val)
145{
146 return -EOPNOTSUPP;
147}
148
149static inline int nvmem_cell_read_u64(struct device *dev,
150 const char *cell_id, u64 *val)
151{
152 return -EOPNOTSUPP;
153}
154
155static inline int nvmem_cell_read_variable_le_u32(struct device *dev,
156 const char *cell_id,
157 u32 *val)
158{
159 return -EOPNOTSUPP;
160}
161
162static inline int nvmem_cell_read_variable_le_u64(struct device *dev,
163 const char *cell_id,
164 u64 *val)
165{
166 return -EOPNOTSUPP;
167}
168
169static inline struct nvmem_device *nvmem_device_get(struct device *dev,
170 const char *name)
171{
172 return ERR_PTR(-EOPNOTSUPP);
173}
174
175static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
176 const char *name)
177{
178 return ERR_PTR(-EOPNOTSUPP);
179}
180
181static inline void nvmem_device_put(struct nvmem_device *nvmem)
182{
183}
184
185static inline void devm_nvmem_device_put(struct device *dev,
186 struct nvmem_device *nvmem)
187{
188}
189
190static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
191 struct nvmem_cell_info *info,
192 void *buf)
193{
194 return -EOPNOTSUPP;
195}
196
197static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
198 struct nvmem_cell_info *info,
199 void *buf)
200{
201 return -EOPNOTSUPP;
202}
203
204static inline int nvmem_device_read(struct nvmem_device *nvmem,
205 unsigned int offset, size_t bytes,
206 void *buf)
207{
208 return -EOPNOTSUPP;
209}
210
211static inline int nvmem_device_write(struct nvmem_device *nvmem,
212 unsigned int offset, size_t bytes,
213 void *buf)
214{
215 return -EOPNOTSUPP;
216}
217
218static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
219{
220 return NULL;
221}
222
223static inline void
224nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
225static inline void
226nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
227
228static inline int nvmem_register_notifier(struct notifier_block *nb)
229{
230 return -EOPNOTSUPP;
231}
232
233static inline int nvmem_unregister_notifier(struct notifier_block *nb)
234{
235 return -EOPNOTSUPP;
236}
237
238static inline struct nvmem_device *nvmem_device_find(void *data,
239 int (*match)(struct device *dev, const void *data))
240{
241 return NULL;
242}
243
244#endif /* CONFIG_NVMEM */
245
246#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
247struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
248 const char *id);
249struct nvmem_device *of_nvmem_device_get(struct device_node *np,
250 const char *name);
251#else
252static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
253 const char *id)
254{
255 return ERR_PTR(-EOPNOTSUPP);
256}
257
258static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
259 const char *name)
260{
261 return ERR_PTR(-EOPNOTSUPP);
262}
263#endif /* CONFIG_NVMEM && CONFIG_OF */
264
265#endif /* ifndef _LINUX_NVMEM_CONSUMER_H */