at v5.6 6.2 kB view raw
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}; 29 30/** 31 * struct nvmem_cell_lookup - cell lookup entry 32 * 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 37 * this cell. 38 * @con_id: Connector id for this cell lookup. 39 */ 40struct nvmem_cell_lookup { 41 const char *nvmem_name; 42 const char *cell_name; 43 const char *dev_id; 44 const char *con_id; 45 struct list_head node; 46}; 47 48enum { 49 NVMEM_ADD = 1, 50 NVMEM_REMOVE, 51 NVMEM_CELL_ADD, 52 NVMEM_CELL_REMOVE, 53}; 54 55#if IS_ENABLED(CONFIG_NVMEM) 56 57/* Cell based interface */ 58struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id); 59struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id); 60void nvmem_cell_put(struct nvmem_cell *cell); 61void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); 62void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); 63int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len); 64int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val); 65int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val); 66 67/* direct nvmem device read/write interface */ 68struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); 69struct nvmem_device *devm_nvmem_device_get(struct device *dev, 70 const char *name); 71void nvmem_device_put(struct nvmem_device *nvmem); 72void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem); 73int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset, 74 size_t bytes, void *buf); 75int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset, 76 size_t bytes, void *buf); 77ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, 78 struct nvmem_cell_info *info, void *buf); 79int nvmem_device_cell_write(struct nvmem_device *nvmem, 80 struct nvmem_cell_info *info, void *buf); 81 82const char *nvmem_dev_name(struct nvmem_device *nvmem); 83 84void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, 85 size_t nentries); 86void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, 87 size_t nentries); 88 89int nvmem_register_notifier(struct notifier_block *nb); 90int nvmem_unregister_notifier(struct notifier_block *nb); 91 92struct nvmem_device *nvmem_device_find(void *data, 93 int (*match)(struct device *dev, const void *data)); 94 95#else 96 97static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, 98 const char *id) 99{ 100 return ERR_PTR(-EOPNOTSUPP); 101} 102 103static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, 104 const char *id) 105{ 106 return ERR_PTR(-EOPNOTSUPP); 107} 108 109static inline void devm_nvmem_cell_put(struct device *dev, 110 struct nvmem_cell *cell) 111{ 112 113} 114static inline void nvmem_cell_put(struct nvmem_cell *cell) 115{ 116} 117 118static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) 119{ 120 return ERR_PTR(-EOPNOTSUPP); 121} 122 123static inline int nvmem_cell_write(struct nvmem_cell *cell, 124 void *buf, size_t len) 125{ 126 return -EOPNOTSUPP; 127} 128 129static inline int nvmem_cell_read_u16(struct device *dev, 130 const char *cell_id, u16 *val) 131{ 132 return -EOPNOTSUPP; 133} 134 135static inline int nvmem_cell_read_u32(struct device *dev, 136 const char *cell_id, u32 *val) 137{ 138 return -EOPNOTSUPP; 139} 140 141static inline struct nvmem_device *nvmem_device_get(struct device *dev, 142 const char *name) 143{ 144 return ERR_PTR(-EOPNOTSUPP); 145} 146 147static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev, 148 const char *name) 149{ 150 return ERR_PTR(-EOPNOTSUPP); 151} 152 153static inline void nvmem_device_put(struct nvmem_device *nvmem) 154{ 155} 156 157static inline void devm_nvmem_device_put(struct device *dev, 158 struct nvmem_device *nvmem) 159{ 160} 161 162static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, 163 struct nvmem_cell_info *info, 164 void *buf) 165{ 166 return -EOPNOTSUPP; 167} 168 169static inline int nvmem_device_cell_write(struct nvmem_device *nvmem, 170 struct nvmem_cell_info *info, 171 void *buf) 172{ 173 return -EOPNOTSUPP; 174} 175 176static inline int nvmem_device_read(struct nvmem_device *nvmem, 177 unsigned int offset, size_t bytes, 178 void *buf) 179{ 180 return -EOPNOTSUPP; 181} 182 183static inline int nvmem_device_write(struct nvmem_device *nvmem, 184 unsigned int offset, size_t bytes, 185 void *buf) 186{ 187 return -EOPNOTSUPP; 188} 189 190static inline const char *nvmem_dev_name(struct nvmem_device *nvmem) 191{ 192 return NULL; 193} 194 195static inline void 196nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} 197static inline void 198nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} 199 200static inline int nvmem_register_notifier(struct notifier_block *nb) 201{ 202 return -EOPNOTSUPP; 203} 204 205static inline int nvmem_unregister_notifier(struct notifier_block *nb) 206{ 207 return -EOPNOTSUPP; 208} 209 210static inline struct nvmem_device *nvmem_device_find(void *data, 211 int (*match)(struct device *dev, const void *data)) 212{ 213 return NULL; 214} 215 216#endif /* CONFIG_NVMEM */ 217 218#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) 219struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, 220 const char *id); 221struct nvmem_device *of_nvmem_device_get(struct device_node *np, 222 const char *name); 223#else 224static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, 225 const char *id) 226{ 227 return ERR_PTR(-EOPNOTSUPP); 228} 229 230static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, 231 const char *name) 232{ 233 return ERR_PTR(-EOPNOTSUPP); 234} 235#endif /* CONFIG_NVMEM && CONFIG_OF */ 236 237#endif /* ifndef _LINUX_NVMEM_CONSUMER_H */