]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - include/linux/nvmem-consumer.h
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
;
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_u8(struct device
*dev
, const char *cell_id
, u8
*val
);
65 int nvmem_cell_read_u16(struct device
*dev
, const char *cell_id
, u16
*val
);
66 int nvmem_cell_read_u32(struct device
*dev
, const char *cell_id
, u32
*val
);
67 int nvmem_cell_read_u64(struct device
*dev
, const char *cell_id
, u64
*val
);
68 int nvmem_cell_read_variable_le_u32(struct device
*dev
, const char *cell_id
,
70 int nvmem_cell_read_variable_le_u64(struct device
*dev
, const char *cell_id
,
73 /* direct nvmem device read/write interface */
74 struct nvmem_device
*nvmem_device_get(struct device
*dev
, const char *name
);
75 struct nvmem_device
*devm_nvmem_device_get(struct device
*dev
,
77 void nvmem_device_put(struct nvmem_device
*nvmem
);
78 void devm_nvmem_device_put(struct device
*dev
, struct nvmem_device
*nvmem
);
79 int nvmem_device_read(struct nvmem_device
*nvmem
, unsigned int offset
,
80 size_t bytes
, void *buf
);
81 int nvmem_device_write(struct nvmem_device
*nvmem
, unsigned int offset
,
82 size_t bytes
, void *buf
);
83 ssize_t
nvmem_device_cell_read(struct nvmem_device
*nvmem
,
84 struct nvmem_cell_info
*info
, void *buf
);
85 int nvmem_device_cell_write(struct nvmem_device
*nvmem
,
86 struct nvmem_cell_info
*info
, void *buf
);
88 const char *nvmem_dev_name(struct nvmem_device
*nvmem
);
90 void nvmem_add_cell_lookups(struct nvmem_cell_lookup
*entries
,
92 void nvmem_del_cell_lookups(struct nvmem_cell_lookup
*entries
,
95 int nvmem_register_notifier(struct notifier_block
*nb
);
96 int nvmem_unregister_notifier(struct notifier_block
*nb
);
98 struct nvmem_device
*nvmem_device_find(void *data
,
99 int (*match
)(struct device
*dev
, const void *data
));
103 static inline struct nvmem_cell
*nvmem_cell_get(struct device
*dev
,
106 return ERR_PTR(-EOPNOTSUPP
);
109 static inline struct nvmem_cell
*devm_nvmem_cell_get(struct device
*dev
,
112 return ERR_PTR(-EOPNOTSUPP
);
115 static inline void devm_nvmem_cell_put(struct device
*dev
,
116 struct nvmem_cell
*cell
)
120 static inline void nvmem_cell_put(struct nvmem_cell
*cell
)
124 static inline void *nvmem_cell_read(struct nvmem_cell
*cell
, size_t *len
)
126 return ERR_PTR(-EOPNOTSUPP
);
129 static inline int nvmem_cell_write(struct nvmem_cell
*cell
,
130 void *buf
, size_t len
)
135 static inline int nvmem_cell_read_u16(struct device
*dev
,
136 const char *cell_id
, u16
*val
)
141 static inline int nvmem_cell_read_u32(struct device
*dev
,
142 const char *cell_id
, u32
*val
)
147 static inline int nvmem_cell_read_u64(struct device
*dev
,
148 const char *cell_id
, u64
*val
)
153 static inline struct nvmem_device
*nvmem_device_get(struct device
*dev
,
156 return ERR_PTR(-EOPNOTSUPP
);
159 static inline struct nvmem_device
*devm_nvmem_device_get(struct device
*dev
,
162 return ERR_PTR(-EOPNOTSUPP
);
165 static inline void nvmem_device_put(struct nvmem_device
*nvmem
)
169 static inline void devm_nvmem_device_put(struct device
*dev
,
170 struct nvmem_device
*nvmem
)
174 static inline ssize_t
nvmem_device_cell_read(struct nvmem_device
*nvmem
,
175 struct nvmem_cell_info
*info
,
181 static inline int nvmem_device_cell_write(struct nvmem_device
*nvmem
,
182 struct nvmem_cell_info
*info
,
188 static inline int nvmem_device_read(struct nvmem_device
*nvmem
,
189 unsigned int offset
, size_t bytes
,
195 static inline int nvmem_device_write(struct nvmem_device
*nvmem
,
196 unsigned int offset
, size_t bytes
,
202 static inline const char *nvmem_dev_name(struct nvmem_device
*nvmem
)
208 nvmem_add_cell_lookups(struct nvmem_cell_lookup
*entries
, size_t nentries
) {}
210 nvmem_del_cell_lookups(struct nvmem_cell_lookup
*entries
, size_t nentries
) {}
212 static inline int nvmem_register_notifier(struct notifier_block
*nb
)
217 static inline int nvmem_unregister_notifier(struct notifier_block
*nb
)
222 static inline struct nvmem_device
*nvmem_device_find(void *data
,
223 int (*match
)(struct device
*dev
, const void *data
))
228 #endif /* CONFIG_NVMEM */
230 #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
231 struct nvmem_cell
*of_nvmem_cell_get(struct device_node
*np
,
233 struct nvmem_device
*of_nvmem_device_get(struct device_node
*np
,
236 static inline struct nvmem_cell
*of_nvmem_cell_get(struct device_node
*np
,
239 return ERR_PTR(-EOPNOTSUPP
);
242 static inline struct nvmem_device
*of_nvmem_device_get(struct device_node
*np
,
245 return ERR_PTR(-EOPNOTSUPP
);
247 #endif /* CONFIG_NVMEM && CONFIG_OF */
249 #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */