1 /* SPDX-License-Identifier: GPL-2.0 */
3 * nvmem framework consumer.
5 * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
6 * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com>
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;
28 struct device_node *np;
32 * struct nvmem_cell_lookup - cell lookup entry
34 * @nvmem_name: Name of the provider.
35 * @cell_name: Name of the nvmem cell as defined in the name field of
36 * struct nvmem_cell_info.
37 * @dev_id: Name of the consumer device that will be associated with
39 * @con_id: Connector id for this cell lookup.
41 struct nvmem_cell_lookup {
42 const char *nvmem_name;
43 const char *cell_name;
46 struct list_head node;
56 #if IS_ENABLED(CONFIG_NVMEM)
58 /* Cell based interface */
59 struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id);
60 struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id);
61 void nvmem_cell_put(struct nvmem_cell *cell);
62 void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
63 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
64 int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
65 int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val);
66 int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val);
67 int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
68 int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val);
69 int nvmem_cell_read_variable_le_u32(struct device *dev, const char *cell_id,
71 int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id,
74 /* direct nvmem device read/write interface */
75 struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
76 struct nvmem_device *devm_nvmem_device_get(struct device *dev,
78 void nvmem_device_put(struct nvmem_device *nvmem);
79 void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
80 int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
81 size_t bytes, void *buf);
82 int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
83 size_t bytes, void *buf);
84 ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
85 struct nvmem_cell_info *info, void *buf);
86 int nvmem_device_cell_write(struct nvmem_device *nvmem,
87 struct nvmem_cell_info *info, void *buf);
89 const char *nvmem_dev_name(struct nvmem_device *nvmem);
91 void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries,
93 void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries,
96 int nvmem_register_notifier(struct notifier_block *nb);
97 int nvmem_unregister_notifier(struct notifier_block *nb);
99 struct nvmem_device *nvmem_device_find(void *data,
100 int (*match)(struct device *dev, const void *data));
104 static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
107 return ERR_PTR(-EOPNOTSUPP);
110 static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
113 return ERR_PTR(-EOPNOTSUPP);
116 static inline void devm_nvmem_cell_put(struct device *dev,
117 struct nvmem_cell *cell)
121 static inline void nvmem_cell_put(struct nvmem_cell *cell)
125 static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
127 return ERR_PTR(-EOPNOTSUPP);
130 static inline int nvmem_cell_write(struct nvmem_cell *cell,
131 void *buf, size_t len)
136 static inline int nvmem_cell_read_u16(struct device *dev,
137 const char *cell_id, u16 *val)
142 static inline int nvmem_cell_read_u32(struct device *dev,
143 const char *cell_id, u32 *val)
148 static inline int nvmem_cell_read_u64(struct device *dev,
149 const char *cell_id, u64 *val)
154 static inline int nvmem_cell_read_variable_le_u32(struct device *dev,
161 static inline int nvmem_cell_read_variable_le_u64(struct device *dev,
168 static inline struct nvmem_device *nvmem_device_get(struct device *dev,
171 return ERR_PTR(-EOPNOTSUPP);
174 static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
177 return ERR_PTR(-EOPNOTSUPP);
180 static inline void nvmem_device_put(struct nvmem_device *nvmem)
184 static inline void devm_nvmem_device_put(struct device *dev,
185 struct nvmem_device *nvmem)
189 static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
190 struct nvmem_cell_info *info,
196 static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
197 struct nvmem_cell_info *info,
203 static inline int nvmem_device_read(struct nvmem_device *nvmem,
204 unsigned int offset, size_t bytes,
210 static inline int nvmem_device_write(struct nvmem_device *nvmem,
211 unsigned int offset, size_t bytes,
217 static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
223 nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
225 nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
227 static inline int nvmem_register_notifier(struct notifier_block *nb)
232 static inline int nvmem_unregister_notifier(struct notifier_block *nb)
237 static inline struct nvmem_device *nvmem_device_find(void *data,
238 int (*match)(struct device *dev, const void *data))
243 #endif /* CONFIG_NVMEM */
245 #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
246 struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
248 struct nvmem_device *of_nvmem_device_get(struct device_node *np,
251 static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
254 return ERR_PTR(-EOPNOTSUPP);
257 static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
260 return ERR_PTR(-EOPNOTSUPP);
262 #endif /* CONFIG_NVMEM && CONFIG_OF */
264 #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */