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>
21 struct nvmem_cell_info;
24 * struct nvmem_cell_lookup - cell lookup entry
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
31 * @con_id: Connector id for this cell lookup.
33 struct nvmem_cell_lookup {
34 const char *nvmem_name;
35 const char *cell_name;
38 struct list_head node;
50 #if IS_ENABLED(CONFIG_NVMEM)
52 /* Cell based interface */
53 struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id);
54 struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id);
55 void nvmem_cell_put(struct nvmem_cell *cell);
56 void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
57 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
58 int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
59 int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val);
60 int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val);
61 int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
62 int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val);
63 int nvmem_cell_read_variable_le_u32(struct device *dev, const char *cell_id,
65 int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id,
68 /* direct nvmem device read/write interface */
69 struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
70 struct nvmem_device *devm_nvmem_device_get(struct device *dev,
72 void nvmem_device_put(struct nvmem_device *nvmem);
73 void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
74 int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
75 size_t bytes, void *buf);
76 int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
77 size_t bytes, void *buf);
78 ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
79 struct nvmem_cell_info *info, void *buf);
80 int nvmem_device_cell_write(struct nvmem_device *nvmem,
81 struct nvmem_cell_info *info, void *buf);
83 const char *nvmem_dev_name(struct nvmem_device *nvmem);
84 size_t nvmem_dev_size(struct nvmem_device *nvmem);
86 void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries,
88 void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries,
91 int nvmem_register_notifier(struct notifier_block *nb);
92 int nvmem_unregister_notifier(struct notifier_block *nb);
94 struct nvmem_device *nvmem_device_find(void *data,
95 int (*match)(struct device *dev, const void *data));
99 static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
102 return ERR_PTR(-EOPNOTSUPP);
105 static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
108 return ERR_PTR(-EOPNOTSUPP);
111 static inline void devm_nvmem_cell_put(struct device *dev,
112 struct nvmem_cell *cell)
116 static inline void nvmem_cell_put(struct nvmem_cell *cell)
120 static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
122 return ERR_PTR(-EOPNOTSUPP);
125 static inline int nvmem_cell_write(struct nvmem_cell *cell,
126 void *buf, size_t len)
131 static inline int nvmem_cell_read_u8(struct device *dev,
132 const char *cell_id, u8 *val)
137 static inline int nvmem_cell_read_u16(struct device *dev,
138 const char *cell_id, u16 *val)
143 static inline int nvmem_cell_read_u32(struct device *dev,
144 const char *cell_id, u32 *val)
149 static inline int nvmem_cell_read_u64(struct device *dev,
150 const char *cell_id, u64 *val)
155 static inline int nvmem_cell_read_variable_le_u32(struct device *dev,
162 static inline int nvmem_cell_read_variable_le_u64(struct device *dev,
169 static inline struct nvmem_device *nvmem_device_get(struct device *dev,
172 return ERR_PTR(-EOPNOTSUPP);
175 static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
178 return ERR_PTR(-EOPNOTSUPP);
181 static inline void nvmem_device_put(struct nvmem_device *nvmem)
185 static inline void devm_nvmem_device_put(struct device *dev,
186 struct nvmem_device *nvmem)
190 static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
191 struct nvmem_cell_info *info,
197 static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
198 struct nvmem_cell_info *info,
204 static inline int nvmem_device_read(struct nvmem_device *nvmem,
205 unsigned int offset, size_t bytes,
211 static inline int nvmem_device_write(struct nvmem_device *nvmem,
212 unsigned int offset, size_t bytes,
218 static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
224 nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
226 nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
228 static inline int nvmem_register_notifier(struct notifier_block *nb)
233 static inline int nvmem_unregister_notifier(struct notifier_block *nb)
238 static inline struct nvmem_device *nvmem_device_find(void *data,
239 int (*match)(struct device *dev, const void *data))
244 #endif /* CONFIG_NVMEM */
246 #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
247 struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
249 struct nvmem_device *of_nvmem_device_get(struct device_node *np,
252 static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
255 return ERR_PTR(-EOPNOTSUPP);
258 static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
261 return ERR_PTR(-EOPNOTSUPP);
263 #endif /* CONFIG_NVMEM && CONFIG_OF */
265 #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */