Bartosz Golaszewski | b1c1db9 | 2018-09-21 06:40:20 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Srinivas Kandagatla | eace75c | 2015-07-27 12:13:19 +0100 | [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> |
Srinivas Kandagatla | eace75c | 2015-07-27 12:13:19 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _LINUX_NVMEM_CONSUMER_H |
| 10 | #define _LINUX_NVMEM_CONSUMER_H |
| 11 | |
Srinivas Kandagatla | 4da69f4 | 2017-07-26 11:34:48 +0200 | [diff] [blame] | 12 | #include <linux/err.h> |
| 13 | #include <linux/errno.h> |
Bartosz Golaszewski | bee1138 | 2018-09-21 06:40:19 -0700 | [diff] [blame] | 14 | #include <linux/notifier.h> |
Srinivas Kandagatla | 4da69f4 | 2017-07-26 11:34:48 +0200 | [diff] [blame] | 15 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 16 | struct device; |
| 17 | struct device_node; |
| 18 | /* consumer cookie */ |
| 19 | struct nvmem_cell; |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 20 | struct nvmem_device; |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 21 | |
Srinivas Kandagatla | eace75c | 2015-07-27 12:13:19 +0100 | [diff] [blame] | 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 | |
Bartosz Golaszewski | 506157b | 2018-09-21 06:40:17 -0700 | [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 | |
Bartosz Golaszewski | bee1138 | 2018-09-21 06:40:19 -0700 | [diff] [blame] | 48 | enum { |
| 49 | NVMEM_ADD = 1, |
| 50 | NVMEM_REMOVE, |
| 51 | NVMEM_CELL_ADD, |
| 52 | NVMEM_CELL_REMOVE, |
| 53 | }; |
| 54 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 55 | #if IS_ENABLED(CONFIG_NVMEM) |
| 56 | |
| 57 | /* Cell based interface */ |
Bartosz Golaszewski | 165589f | 2018-09-21 06:40:21 -0700 | [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); |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [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); |
Fabrice Gasnier | 0a9b2d1 | 2019-04-13 11:32:57 +0100 | [diff] [blame] | 64 | int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val); |
Leonard Crestez | d026d70 | 2017-07-26 11:34:46 +0200 | [diff] [blame] | 65 | int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val); |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 66 | |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 67 | /* direct nvmem device read/write interface */ |
| 68 | struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); |
| 69 | struct nvmem_device *devm_nvmem_device_get(struct device *dev, |
| 70 | const char *name); |
| 71 | void nvmem_device_put(struct nvmem_device *nvmem); |
| 72 | void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem); |
| 73 | int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset, |
| 74 | size_t bytes, void *buf); |
| 75 | int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset, |
| 76 | size_t bytes, void *buf); |
| 77 | ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, |
| 78 | struct nvmem_cell_info *info, void *buf); |
| 79 | int nvmem_device_cell_write(struct nvmem_device *nvmem, |
| 80 | struct nvmem_cell_info *info, void *buf); |
| 81 | |
Bartosz Golaszewski | d7b9fd1 | 2018-09-21 06:40:03 -0700 | [diff] [blame] | 82 | const char *nvmem_dev_name(struct nvmem_device *nvmem); |
| 83 | |
Bartosz Golaszewski | 506157b | 2018-09-21 06:40:17 -0700 | [diff] [blame] | 84 | void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, |
| 85 | size_t nentries); |
| 86 | void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, |
| 87 | size_t nentries); |
| 88 | |
Bartosz Golaszewski | bee1138 | 2018-09-21 06:40:19 -0700 | [diff] [blame] | 89 | int nvmem_register_notifier(struct notifier_block *nb); |
| 90 | int nvmem_unregister_notifier(struct notifier_block *nb); |
| 91 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 92 | #else |
| 93 | |
| 94 | static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, |
Bartosz Golaszewski | 165589f | 2018-09-21 06:40:21 -0700 | [diff] [blame] | 95 | const char *id) |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 96 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 97 | return ERR_PTR(-EOPNOTSUPP); |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, |
Bartosz Golaszewski | 165589f | 2018-09-21 06:40:21 -0700 | [diff] [blame] | 101 | const char *id) |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 102 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 103 | return ERR_PTR(-EOPNOTSUPP); |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static inline void devm_nvmem_cell_put(struct device *dev, |
| 107 | struct nvmem_cell *cell) |
| 108 | { |
| 109 | |
| 110 | } |
| 111 | static inline void nvmem_cell_put(struct nvmem_cell *cell) |
| 112 | { |
| 113 | } |
| 114 | |
Guenter Roeck | a6c5091 | 2016-06-02 12:05:12 +0100 | [diff] [blame] | 115 | static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 116 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 117 | return ERR_PTR(-EOPNOTSUPP); |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static inline int nvmem_cell_write(struct nvmem_cell *cell, |
| 121 | const char *buf, size_t len) |
| 122 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 123 | return -EOPNOTSUPP; |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 124 | } |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 125 | |
Fabrice Gasnier | 0a9b2d1 | 2019-04-13 11:32:57 +0100 | [diff] [blame] | 126 | static inline int nvmem_cell_read_u16(struct device *dev, |
| 127 | const char *cell_id, u16 *val) |
| 128 | { |
| 129 | return -EOPNOTSUPP; |
| 130 | } |
| 131 | |
Leonard Crestez | d026d70 | 2017-07-26 11:34:46 +0200 | [diff] [blame] | 132 | static inline int nvmem_cell_read_u32(struct device *dev, |
| 133 | const char *cell_id, u32 *val) |
| 134 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 135 | return -EOPNOTSUPP; |
Leonard Crestez | d026d70 | 2017-07-26 11:34:46 +0200 | [diff] [blame] | 136 | } |
| 137 | |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 138 | static inline struct nvmem_device *nvmem_device_get(struct device *dev, |
| 139 | const char *name) |
| 140 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 141 | return ERR_PTR(-EOPNOTSUPP); |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev, |
| 145 | const char *name) |
| 146 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 147 | return ERR_PTR(-EOPNOTSUPP); |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static inline void nvmem_device_put(struct nvmem_device *nvmem) |
| 151 | { |
| 152 | } |
| 153 | |
| 154 | static inline void devm_nvmem_device_put(struct device *dev, |
| 155 | struct nvmem_device *nvmem) |
| 156 | { |
| 157 | } |
| 158 | |
| 159 | static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, |
| 160 | struct nvmem_cell_info *info, |
| 161 | void *buf) |
| 162 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 163 | return -EOPNOTSUPP; |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static inline int nvmem_device_cell_write(struct nvmem_device *nvmem, |
| 167 | struct nvmem_cell_info *info, |
| 168 | void *buf) |
| 169 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 170 | return -EOPNOTSUPP; |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | static inline int nvmem_device_read(struct nvmem_device *nvmem, |
| 174 | unsigned int offset, size_t bytes, |
| 175 | void *buf) |
| 176 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 177 | return -EOPNOTSUPP; |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static inline int nvmem_device_write(struct nvmem_device *nvmem, |
| 181 | unsigned int offset, size_t bytes, |
| 182 | void *buf) |
| 183 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 184 | return -EOPNOTSUPP; |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 185 | } |
Bartosz Golaszewski | d7b9fd1 | 2018-09-21 06:40:03 -0700 | [diff] [blame] | 186 | |
| 187 | static inline const char *nvmem_dev_name(struct nvmem_device *nvmem) |
| 188 | { |
| 189 | return NULL; |
| 190 | } |
| 191 | |
Bartosz Golaszewski | 506157b | 2018-09-21 06:40:17 -0700 | [diff] [blame] | 192 | static inline void |
| 193 | nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} |
| 194 | static inline void |
| 195 | nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} |
| 196 | |
Bartosz Golaszewski | bee1138 | 2018-09-21 06:40:19 -0700 | [diff] [blame] | 197 | static inline int nvmem_register_notifier(struct notifier_block *nb) |
| 198 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 199 | return -EOPNOTSUPP; |
Bartosz Golaszewski | bee1138 | 2018-09-21 06:40:19 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | static inline int nvmem_unregister_notifier(struct notifier_block *nb) |
| 203 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 204 | return -EOPNOTSUPP; |
Bartosz Golaszewski | bee1138 | 2018-09-21 06:40:19 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 207 | #endif /* CONFIG_NVMEM */ |
| 208 | |
| 209 | #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) |
| 210 | struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
Bartosz Golaszewski | 165589f | 2018-09-21 06:40:21 -0700 | [diff] [blame] | 211 | const char *id); |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 212 | struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
| 213 | const char *name); |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 214 | #else |
| 215 | static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
Bartosz Golaszewski | 165589f | 2018-09-21 06:40:21 -0700 | [diff] [blame] | 216 | const char *id) |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 217 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 218 | return ERR_PTR(-EOPNOTSUPP); |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 219 | } |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 220 | |
| 221 | static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
| 222 | const char *name) |
| 223 | { |
Bartosz Golaszewski | 20167b7 | 2018-09-21 06:40:22 -0700 | [diff] [blame] | 224 | return ERR_PTR(-EOPNOTSUPP); |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 225 | } |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 226 | #endif /* CONFIG_NVMEM && CONFIG_OF */ |
| 227 | |
Srinivas Kandagatla | eace75c | 2015-07-27 12:13:19 +0100 | [diff] [blame] | 228 | #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */ |