nvmem-consumer.h (6967B)
1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * nvmem framework consumer. 4 * 5 * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org> 6 * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com> 7 */ 8 9#ifndef _LINUX_NVMEM_CONSUMER_H 10#define _LINUX_NVMEM_CONSUMER_H 11 12#include <linux/err.h> 13#include <linux/errno.h> 14#include <linux/notifier.h> 15 16struct device; 17struct device_node; 18/* consumer cookie */ 19struct nvmem_cell; 20struct nvmem_device; 21 22struct nvmem_cell_info { 23 const char *name; 24 unsigned int offset; 25 unsigned int bytes; 26 unsigned int bit_offset; 27 unsigned int nbits; 28 struct device_node *np; 29}; 30 31/** 32 * struct nvmem_cell_lookup - cell lookup entry 33 * 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 38 * this cell. 39 * @con_id: Connector id for this cell lookup. 40 */ 41struct nvmem_cell_lookup { 42 const char *nvmem_name; 43 const char *cell_name; 44 const char *dev_id; 45 const char *con_id; 46 struct list_head node; 47}; 48 49enum { 50 NVMEM_ADD = 1, 51 NVMEM_REMOVE, 52 NVMEM_CELL_ADD, 53 NVMEM_CELL_REMOVE, 54}; 55 56#if IS_ENABLED(CONFIG_NVMEM) 57 58/* Cell based interface */ 59struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id); 60struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id); 61void nvmem_cell_put(struct nvmem_cell *cell); 62void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); 63void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); 64int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len); 65int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val); 66int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val); 67int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val); 68int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val); 69int nvmem_cell_read_variable_le_u32(struct device *dev, const char *cell_id, 70 u32 *val); 71int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id, 72 u64 *val); 73 74/* direct nvmem device read/write interface */ 75struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); 76struct nvmem_device *devm_nvmem_device_get(struct device *dev, 77 const char *name); 78void nvmem_device_put(struct nvmem_device *nvmem); 79void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem); 80int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset, 81 size_t bytes, void *buf); 82int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset, 83 size_t bytes, void *buf); 84ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, 85 struct nvmem_cell_info *info, void *buf); 86int nvmem_device_cell_write(struct nvmem_device *nvmem, 87 struct nvmem_cell_info *info, void *buf); 88 89const char *nvmem_dev_name(struct nvmem_device *nvmem); 90 91void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, 92 size_t nentries); 93void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, 94 size_t nentries); 95 96int nvmem_register_notifier(struct notifier_block *nb); 97int nvmem_unregister_notifier(struct notifier_block *nb); 98 99struct nvmem_device *nvmem_device_find(void *data, 100 int (*match)(struct device *dev, const void *data)); 101 102#else 103 104static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, 105 const char *id) 106{ 107 return ERR_PTR(-EOPNOTSUPP); 108} 109 110static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, 111 const char *id) 112{ 113 return ERR_PTR(-EOPNOTSUPP); 114} 115 116static inline void devm_nvmem_cell_put(struct device *dev, 117 struct nvmem_cell *cell) 118{ 119 120} 121static inline void nvmem_cell_put(struct nvmem_cell *cell) 122{ 123} 124 125static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) 126{ 127 return ERR_PTR(-EOPNOTSUPP); 128} 129 130static inline int nvmem_cell_write(struct nvmem_cell *cell, 131 void *buf, size_t len) 132{ 133 return -EOPNOTSUPP; 134} 135 136static inline int nvmem_cell_read_u16(struct device *dev, 137 const char *cell_id, u16 *val) 138{ 139 return -EOPNOTSUPP; 140} 141 142static inline int nvmem_cell_read_u32(struct device *dev, 143 const char *cell_id, u32 *val) 144{ 145 return -EOPNOTSUPP; 146} 147 148static inline int nvmem_cell_read_u64(struct device *dev, 149 const char *cell_id, u64 *val) 150{ 151 return -EOPNOTSUPP; 152} 153 154static inline int nvmem_cell_read_variable_le_u32(struct device *dev, 155 const char *cell_id, 156 u32 *val) 157{ 158 return -EOPNOTSUPP; 159} 160 161static inline int nvmem_cell_read_variable_le_u64(struct device *dev, 162 const char *cell_id, 163 u64 *val) 164{ 165 return -EOPNOTSUPP; 166} 167 168static inline struct nvmem_device *nvmem_device_get(struct device *dev, 169 const char *name) 170{ 171 return ERR_PTR(-EOPNOTSUPP); 172} 173 174static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev, 175 const char *name) 176{ 177 return ERR_PTR(-EOPNOTSUPP); 178} 179 180static inline void nvmem_device_put(struct nvmem_device *nvmem) 181{ 182} 183 184static inline void devm_nvmem_device_put(struct device *dev, 185 struct nvmem_device *nvmem) 186{ 187} 188 189static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, 190 struct nvmem_cell_info *info, 191 void *buf) 192{ 193 return -EOPNOTSUPP; 194} 195 196static inline int nvmem_device_cell_write(struct nvmem_device *nvmem, 197 struct nvmem_cell_info *info, 198 void *buf) 199{ 200 return -EOPNOTSUPP; 201} 202 203static inline int nvmem_device_read(struct nvmem_device *nvmem, 204 unsigned int offset, size_t bytes, 205 void *buf) 206{ 207 return -EOPNOTSUPP; 208} 209 210static inline int nvmem_device_write(struct nvmem_device *nvmem, 211 unsigned int offset, size_t bytes, 212 void *buf) 213{ 214 return -EOPNOTSUPP; 215} 216 217static inline const char *nvmem_dev_name(struct nvmem_device *nvmem) 218{ 219 return NULL; 220} 221 222static inline void 223nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} 224static inline void 225nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} 226 227static inline int nvmem_register_notifier(struct notifier_block *nb) 228{ 229 return -EOPNOTSUPP; 230} 231 232static inline int nvmem_unregister_notifier(struct notifier_block *nb) 233{ 234 return -EOPNOTSUPP; 235} 236 237static inline struct nvmem_device *nvmem_device_find(void *data, 238 int (*match)(struct device *dev, const void *data)) 239{ 240 return NULL; 241} 242 243#endif /* CONFIG_NVMEM */ 244 245#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) 246struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, 247 const char *id); 248struct nvmem_device *of_nvmem_device_get(struct device_node *np, 249 const char *name); 250#else 251static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, 252 const char *id) 253{ 254 return ERR_PTR(-EOPNOTSUPP); 255} 256 257static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, 258 const char *name) 259{ 260 return ERR_PTR(-EOPNOTSUPP); 261} 262#endif /* CONFIG_NVMEM && CONFIG_OF */ 263 264#endif /* ifndef _LINUX_NVMEM_CONSUMER_H */