Loading...
Note: File does not exist in v3.1.
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);
68
69/* direct nvmem device read/write interface */
70struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
71struct nvmem_device *devm_nvmem_device_get(struct device *dev,
72 const char *name);
73void nvmem_device_put(struct nvmem_device *nvmem);
74void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
75int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
76 size_t bytes, void *buf);
77int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
78 size_t bytes, void *buf);
79ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
80 struct nvmem_cell_info *info, void *buf);
81int nvmem_device_cell_write(struct nvmem_device *nvmem,
82 struct nvmem_cell_info *info, void *buf);
83
84const char *nvmem_dev_name(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_u16(struct device *dev,
132 const char *cell_id, u16 *val)
133{
134 return -EOPNOTSUPP;
135}
136
137static inline int nvmem_cell_read_u32(struct device *dev,
138 const char *cell_id, u32 *val)
139{
140 return -EOPNOTSUPP;
141}
142
143static inline int nvmem_cell_read_u64(struct device *dev,
144 const char *cell_id, u64 *val)
145{
146 return -EOPNOTSUPP;
147}
148
149static inline struct nvmem_device *nvmem_device_get(struct device *dev,
150 const char *name)
151{
152 return ERR_PTR(-EOPNOTSUPP);
153}
154
155static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
156 const char *name)
157{
158 return ERR_PTR(-EOPNOTSUPP);
159}
160
161static inline void nvmem_device_put(struct nvmem_device *nvmem)
162{
163}
164
165static inline void devm_nvmem_device_put(struct device *dev,
166 struct nvmem_device *nvmem)
167{
168}
169
170static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
171 struct nvmem_cell_info *info,
172 void *buf)
173{
174 return -EOPNOTSUPP;
175}
176
177static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
178 struct nvmem_cell_info *info,
179 void *buf)
180{
181 return -EOPNOTSUPP;
182}
183
184static inline int nvmem_device_read(struct nvmem_device *nvmem,
185 unsigned int offset, size_t bytes,
186 void *buf)
187{
188 return -EOPNOTSUPP;
189}
190
191static inline int nvmem_device_write(struct nvmem_device *nvmem,
192 unsigned int offset, size_t bytes,
193 void *buf)
194{
195 return -EOPNOTSUPP;
196}
197
198static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
199{
200 return NULL;
201}
202
203static inline void
204nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
205static inline void
206nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
207
208static inline int nvmem_register_notifier(struct notifier_block *nb)
209{
210 return -EOPNOTSUPP;
211}
212
213static inline int nvmem_unregister_notifier(struct notifier_block *nb)
214{
215 return -EOPNOTSUPP;
216}
217
218static inline struct nvmem_device *nvmem_device_find(void *data,
219 int (*match)(struct device *dev, const void *data))
220{
221 return NULL;
222}
223
224#endif /* CONFIG_NVMEM */
225
226#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
227struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
228 const char *id);
229struct nvmem_device *of_nvmem_device_get(struct device_node *np,
230 const char *name);
231#else
232static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
233 const char *id)
234{
235 return ERR_PTR(-EOPNOTSUPP);
236}
237
238static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
239 const char *name)
240{
241 return ERR_PTR(-EOPNOTSUPP);
242}
243#endif /* CONFIG_NVMEM && CONFIG_OF */
244
245#endif /* ifndef _LINUX_NVMEM_CONSUMER_H */