1
2
3
4
5
6
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
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
32
33
34
35
36
37
38
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
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_u16(struct device *dev, const char *cell_id, u16 *val);
65int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
66
67
68struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
69struct nvmem_device *devm_nvmem_device_get(struct device *dev,
70 const char *name);
71void nvmem_device_put(struct nvmem_device *nvmem);
72void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
73int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
74 size_t bytes, void *buf);
75int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
76 size_t bytes, void *buf);
77ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
78 struct nvmem_cell_info *info, void *buf);
79int nvmem_device_cell_write(struct nvmem_device *nvmem,
80 struct nvmem_cell_info *info, void *buf);
81
82const char *nvmem_dev_name(struct nvmem_device *nvmem);
83
84void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries,
85 size_t nentries);
86void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries,
87 size_t nentries);
88
89int nvmem_register_notifier(struct notifier_block *nb);
90int nvmem_unregister_notifier(struct notifier_block *nb);
91
92#else
93
94static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
95 const char *id)
96{
97 return ERR_PTR(-EOPNOTSUPP);
98}
99
100static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
101 const char *id)
102{
103 return ERR_PTR(-EOPNOTSUPP);
104}
105
106static inline void devm_nvmem_cell_put(struct device *dev,
107 struct nvmem_cell *cell)
108{
109
110}
111static inline void nvmem_cell_put(struct nvmem_cell *cell)
112{
113}
114
115static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
116{
117 return ERR_PTR(-EOPNOTSUPP);
118}
119
120static inline int nvmem_cell_write(struct nvmem_cell *cell,
121 const char *buf, size_t len)
122{
123 return -EOPNOTSUPP;
124}
125
126static inline int nvmem_cell_read_u16(struct device *dev,
127 const char *cell_id, u16 *val)
128{
129 return -EOPNOTSUPP;
130}
131
132static inline int nvmem_cell_read_u32(struct device *dev,
133 const char *cell_id, u32 *val)
134{
135 return -EOPNOTSUPP;
136}
137
138static inline struct nvmem_device *nvmem_device_get(struct device *dev,
139 const char *name)
140{
141 return ERR_PTR(-EOPNOTSUPP);
142}
143
144static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
145 const char *name)
146{
147 return ERR_PTR(-EOPNOTSUPP);
148}
149
150static inline void nvmem_device_put(struct nvmem_device *nvmem)
151{
152}
153
154static inline void devm_nvmem_device_put(struct device *dev,
155 struct nvmem_device *nvmem)
156{
157}
158
159static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
160 struct nvmem_cell_info *info,
161 void *buf)
162{
163 return -EOPNOTSUPP;
164}
165
166static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
167 struct nvmem_cell_info *info,
168 void *buf)
169{
170 return -EOPNOTSUPP;
171}
172
173static inline int nvmem_device_read(struct nvmem_device *nvmem,
174 unsigned int offset, size_t bytes,
175 void *buf)
176{
177 return -EOPNOTSUPP;
178}
179
180static inline int nvmem_device_write(struct nvmem_device *nvmem,
181 unsigned int offset, size_t bytes,
182 void *buf)
183{
184 return -EOPNOTSUPP;
185}
186
187static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
188{
189 return NULL;
190}
191
192static inline void
193nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
194static inline void
195nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
196
197static inline int nvmem_register_notifier(struct notifier_block *nb)
198{
199 return -EOPNOTSUPP;
200}
201
202static inline int nvmem_unregister_notifier(struct notifier_block *nb)
203{
204 return -EOPNOTSUPP;
205}
206
207#endif
208
209#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
210struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
211 const char *id);
212struct nvmem_device *of_nvmem_device_get(struct device_node *np,
213 const char *name);
214#else
215static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
216 const char *id)
217{
218 return ERR_PTR(-EOPNOTSUPP);
219}
220
221static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
222 const char *name)
223{
224 return ERR_PTR(-EOPNOTSUPP);
225}
226#endif
227
228#endif
229