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;
48 #if IS_ENABLED(CONFIG_NVMEM)
50 /* Cell based interface */
51 struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id);
52 struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id);
53 void nvmem_cell_put(struct nvmem_cell *cell);
54 void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
55 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
56 int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
57 int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val);
58 int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val);
59 int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
60 int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val);
61 int nvmem_cell_read_variable_le_u32(struct device *dev, const char *cell_id,
63 int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id,
66 /* direct nvmem device read/write interface */
67 struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
68 struct nvmem_device *devm_nvmem_device_get(struct device *dev,
70 void nvmem_device_put(struct nvmem_device *nvmem);
71 void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
72 int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
73 size_t bytes, void *buf);
74 int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
75 size_t bytes, void *buf);
76 ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
77 struct nvmem_cell_info *info, void *buf);
78 int nvmem_device_cell_write(struct nvmem_device *nvmem,
79 struct nvmem_cell_info *info, void *buf);
81 const char *nvmem_dev_name(struct nvmem_device *nvmem);
83 void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries,
85 void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries,
88 int nvmem_register_notifier(struct notifier_block *nb);
89 int nvmem_unregister_notifier(struct notifier_block *nb);
91 struct nvmem_device *nvmem_device_find(void *data,
92 int (*match)(struct device *dev, const void *data));
96 static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
99 return ERR_PTR(-EOPNOTSUPP);
102 static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
105 return ERR_PTR(-EOPNOTSUPP);
108 static inline void devm_nvmem_cell_put(struct device *dev,
109 struct nvmem_cell *cell)
113 static inline void nvmem_cell_put(struct nvmem_cell *cell)
117 static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
119 return ERR_PTR(-EOPNOTSUPP);
122 static inline int nvmem_cell_write(struct nvmem_cell *cell,
123 void *buf, size_t len)
128 static inline int nvmem_cell_read_u16(struct device *dev,
129 const char *cell_id, u16 *val)
134 static inline int nvmem_cell_read_u32(struct device *dev,
135 const char *cell_id, u32 *val)
140 static inline int nvmem_cell_read_u64(struct device *dev,
141 const char *cell_id, u64 *val)
146 static inline int nvmem_cell_read_variable_le_u32(struct device *dev,
153 static inline int nvmem_cell_read_variable_le_u64(struct device *dev,
160 static inline struct nvmem_device *nvmem_device_get(struct device *dev,
163 return ERR_PTR(-EOPNOTSUPP);
166 static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
169 return ERR_PTR(-EOPNOTSUPP);
172 static inline void nvmem_device_put(struct nvmem_device *nvmem)
176 static inline void devm_nvmem_device_put(struct device *dev,
177 struct nvmem_device *nvmem)
181 static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
182 struct nvmem_cell_info *info,
188 static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
189 struct nvmem_cell_info *info,
195 static inline int nvmem_device_read(struct nvmem_device *nvmem,
196 unsigned int offset, size_t bytes,
202 static inline int nvmem_device_write(struct nvmem_device *nvmem,
203 unsigned int offset, size_t bytes,
209 static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
215 nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
217 nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
219 static inline int nvmem_register_notifier(struct notifier_block *nb)
224 static inline int nvmem_unregister_notifier(struct notifier_block *nb)
229 static inline struct nvmem_device *nvmem_device_find(void *data,
230 int (*match)(struct device *dev, const void *data))
235 #endif /* CONFIG_NVMEM */
237 #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
238 struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
240 struct nvmem_device *of_nvmem_device_get(struct device_node *np,
242 struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem);
244 static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
247 return ERR_PTR(-EOPNOTSUPP);
250 static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
253 return ERR_PTR(-EOPNOTSUPP);
256 static inline struct device_node *
257 of_nvmem_layout_get_container(struct nvmem_device *nvmem)
259 return ERR_PTR(-EOPNOTSUPP);
261 #endif /* CONFIG_NVMEM && CONFIG_OF */
263 #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */