David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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> |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14 | #include <linux/notifier.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15 | |
| 16 | struct device; |
| 17 | struct device_node; |
| 18 | /* consumer cookie */ |
| 19 | struct nvmem_cell; |
| 20 | struct nvmem_device; |
| 21 | |
| 22 | struct 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 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 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 | */ |
| 40 | struct 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 | |
| 48 | enum { |
| 49 | NVMEM_ADD = 1, |
| 50 | NVMEM_REMOVE, |
| 51 | NVMEM_CELL_ADD, |
| 52 | NVMEM_CELL_REMOVE, |
| 53 | }; |
| 54 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 55 | #if IS_ENABLED(CONFIG_NVMEM) |
| 56 | |
| 57 | /* Cell based interface */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 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); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 64 | int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 65 | int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 66 | int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 67 | int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 68 | |
| 69 | /* direct nvmem device read/write interface */ |
| 70 | struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); |
| 71 | struct nvmem_device *devm_nvmem_device_get(struct device *dev, |
| 72 | const char *name); |
| 73 | void nvmem_device_put(struct nvmem_device *nvmem); |
| 74 | void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem); |
| 75 | int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset, |
| 76 | size_t bytes, void *buf); |
| 77 | int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset, |
| 78 | size_t bytes, void *buf); |
| 79 | ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, |
| 80 | struct nvmem_cell_info *info, void *buf); |
| 81 | int nvmem_device_cell_write(struct nvmem_device *nvmem, |
| 82 | struct nvmem_cell_info *info, void *buf); |
| 83 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 84 | const char *nvmem_dev_name(struct nvmem_device *nvmem); |
| 85 | |
| 86 | void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, |
| 87 | size_t nentries); |
| 88 | void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, |
| 89 | size_t nentries); |
| 90 | |
| 91 | int nvmem_register_notifier(struct notifier_block *nb); |
| 92 | int nvmem_unregister_notifier(struct notifier_block *nb); |
| 93 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 94 | struct nvmem_device *nvmem_device_find(void *data, |
| 95 | int (*match)(struct device *dev, const void *data)); |
| 96 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 97 | #else |
| 98 | |
| 99 | static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 100 | const char *id) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 101 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 102 | return ERR_PTR(-EOPNOTSUPP); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 106 | const char *id) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 107 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 108 | return ERR_PTR(-EOPNOTSUPP); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | static inline void devm_nvmem_cell_put(struct device *dev, |
| 112 | struct nvmem_cell *cell) |
| 113 | { |
| 114 | |
| 115 | } |
| 116 | static inline void nvmem_cell_put(struct nvmem_cell *cell) |
| 117 | { |
| 118 | } |
| 119 | |
| 120 | static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) |
| 121 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 122 | return ERR_PTR(-EOPNOTSUPP); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static inline int nvmem_cell_write(struct nvmem_cell *cell, |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 126 | void *buf, size_t len) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 127 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 128 | return -EOPNOTSUPP; |
| 129 | } |
| 130 | |
| 131 | static inline int nvmem_cell_read_u16(struct device *dev, |
| 132 | const char *cell_id, u16 *val) |
| 133 | { |
| 134 | return -EOPNOTSUPP; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static inline int nvmem_cell_read_u32(struct device *dev, |
| 138 | const char *cell_id, u32 *val) |
| 139 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 140 | return -EOPNOTSUPP; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 143 | static inline int nvmem_cell_read_u64(struct device *dev, |
| 144 | const char *cell_id, u64 *val) |
| 145 | { |
| 146 | return -EOPNOTSUPP; |
| 147 | } |
| 148 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 149 | static inline struct nvmem_device *nvmem_device_get(struct device *dev, |
| 150 | const char *name) |
| 151 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 152 | return ERR_PTR(-EOPNOTSUPP); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev, |
| 156 | const char *name) |
| 157 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 158 | return ERR_PTR(-EOPNOTSUPP); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static inline void nvmem_device_put(struct nvmem_device *nvmem) |
| 162 | { |
| 163 | } |
| 164 | |
| 165 | static inline void devm_nvmem_device_put(struct device *dev, |
| 166 | struct nvmem_device *nvmem) |
| 167 | { |
| 168 | } |
| 169 | |
| 170 | static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, |
| 171 | struct nvmem_cell_info *info, |
| 172 | void *buf) |
| 173 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 174 | return -EOPNOTSUPP; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static inline int nvmem_device_cell_write(struct nvmem_device *nvmem, |
| 178 | struct nvmem_cell_info *info, |
| 179 | void *buf) |
| 180 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 181 | return -EOPNOTSUPP; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static inline int nvmem_device_read(struct nvmem_device *nvmem, |
| 185 | unsigned int offset, size_t bytes, |
| 186 | void *buf) |
| 187 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 188 | return -EOPNOTSUPP; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | static inline int nvmem_device_write(struct nvmem_device *nvmem, |
| 192 | unsigned int offset, size_t bytes, |
| 193 | void *buf) |
| 194 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 195 | return -EOPNOTSUPP; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 196 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 197 | |
| 198 | static inline const char *nvmem_dev_name(struct nvmem_device *nvmem) |
| 199 | { |
| 200 | return NULL; |
| 201 | } |
| 202 | |
| 203 | static inline void |
| 204 | nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} |
| 205 | static inline void |
| 206 | nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} |
| 207 | |
| 208 | static inline int nvmem_register_notifier(struct notifier_block *nb) |
| 209 | { |
| 210 | return -EOPNOTSUPP; |
| 211 | } |
| 212 | |
| 213 | static inline int nvmem_unregister_notifier(struct notifier_block *nb) |
| 214 | { |
| 215 | return -EOPNOTSUPP; |
| 216 | } |
| 217 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 218 | static inline struct nvmem_device *nvmem_device_find(void *data, |
| 219 | int (*match)(struct device *dev, const void *data)) |
| 220 | { |
| 221 | return NULL; |
| 222 | } |
| 223 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 224 | #endif /* CONFIG_NVMEM */ |
| 225 | |
| 226 | #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) |
| 227 | struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 228 | const char *id); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 229 | struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
| 230 | const char *name); |
| 231 | #else |
| 232 | static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 233 | const char *id) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 234 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 235 | return ERR_PTR(-EOPNOTSUPP); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
| 239 | const char *name) |
| 240 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 241 | return ERR_PTR(-EOPNOTSUPP); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 242 | } |
| 243 | #endif /* CONFIG_NVMEM && CONFIG_OF */ |
| 244 | |
| 245 | #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */ |