1 /* SPDX-License-Identifier: GPL-2.0 */
3 * nvmem framework consumer.
9 #ifndef _LINUX_NVMEM_CONSUMER_H
10 #define _LINUX_NVMEM_CONSUMER_H
12 #include <linux/err.h>
13 #include <linux/errno.h>
14 #include <linux/notifier.h>
22 struct nvmem_cell_info {
26 unsigned int bit_offset;
31 * struct nvmem_cell_lookup - cell lookup entry
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
38 * @con_id: Connector id for this cell lookup.
40 struct nvmem_cell_lookup {
41 const char *nvmem_name;
42 const char *cell_name;
45 struct list_head node;
55 #if IS_ENABLED(CONFIG_NVMEM)
57 /* Cell based interface */
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);
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);
64 int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val);
65 int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
67 /* direct nvmem device read/write interface */
68 struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
69 struct nvmem_device *devm_nvmem_device_get(struct device *dev,
71 void nvmem_device_put(struct nvmem_device *nvmem);
72 void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
73 int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
74 size_t bytes, void *buf);
75 int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
76 size_t bytes, void *buf);
77 ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
78 struct nvmem_cell_info *info, void *buf);
79 int nvmem_device_cell_write(struct nvmem_device *nvmem,
80 struct nvmem_cell_info *info, void *buf);
82 const char *nvmem_dev_name(struct nvmem_device *nvmem);
84 void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries,
86 void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries,
89 int nvmem_register_notifier(struct notifier_block *nb);
90 int nvmem_unregister_notifier(struct notifier_block *nb);
92 struct nvmem_device *nvmem_device_find(void *data,
93 int (*match)(struct device *dev, const void *data));
97 static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
100 return ERR_PTR(-EOPNOTSUPP);
103 static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
106 return ERR_PTR(-EOPNOTSUPP);
109 static inline void devm_nvmem_cell_put(struct device *dev,
110 struct nvmem_cell *cell)
114 static inline void nvmem_cell_put(struct nvmem_cell *cell)
118 static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
120 return ERR_PTR(-EOPNOTSUPP);
123 static inline int nvmem_cell_write(struct nvmem_cell *cell,
124 void *buf, size_t len)
129 static inline int nvmem_cell_read_u16(struct device *dev,
130 const char *cell_id, u16 *val)
135 static inline int nvmem_cell_read_u32(struct device *dev,
136 const char *cell_id, u32 *val)
141 static inline struct nvmem_device *nvmem_device_get(struct device *dev,
144 return ERR_PTR(-EOPNOTSUPP);
147 static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
150 return ERR_PTR(-EOPNOTSUPP);
153 static inline void nvmem_device_put(struct nvmem_device *nvmem)
157 static inline void devm_nvmem_device_put(struct device *dev,
158 struct nvmem_device *nvmem)
162 static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
163 struct nvmem_cell_info *info,
169 static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
170 struct nvmem_cell_info *info,
176 static inline int nvmem_device_read(struct nvmem_device *nvmem,
177 unsigned int offset, size_t bytes,
183 static inline int nvmem_device_write(struct nvmem_device *nvmem,
184 unsigned int offset, size_t bytes,
190 static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
196 nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
198 nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
200 static inline int nvmem_register_notifier(struct notifier_block *nb)
205 static inline int nvmem_unregister_notifier(struct notifier_block *nb)
210 static inline struct nvmem_device *nvmem_device_find(void *data,
211 int (*match)(struct device *dev, const void *data))
216 #endif /* CONFIG_NVMEM */
218 #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
219 struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
221 struct nvmem_device *of_nvmem_device_get(struct device_node *np,
224 static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
227 return ERR_PTR(-EOPNOTSUPP);
230 static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
233 return ERR_PTR(-EOPNOTSUPP);
235 #endif /* CONFIG_NVMEM && CONFIG_OF */
237 #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */