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