Srinivas Kandagatla | eace75c | 2015-07-27 12:13:19 +0100 | [diff] [blame] | 1 | /* |
| 2 | * nvmem framework consumer. |
| 3 | * |
| 4 | * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org> |
| 5 | * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com> |
| 6 | * |
| 7 | * This file is licensed under the terms of the GNU General Public |
| 8 | * License version 2. This program is licensed "as is" without any |
| 9 | * warranty of any kind, whether express or implied. |
| 10 | */ |
| 11 | |
| 12 | #ifndef _LINUX_NVMEM_CONSUMER_H |
| 13 | #define _LINUX_NVMEM_CONSUMER_H |
| 14 | |
Srinivas Kandagatla | 4da69f4 | 2017-07-26 11:34:48 +0200 | [diff] [blame] | 15 | #include <linux/err.h> |
| 16 | #include <linux/errno.h> |
Bartosz Golaszewski | bee1138 | 2018-09-21 06:40:19 -0700 | [diff] [blame^] | 17 | #include <linux/notifier.h> |
Srinivas Kandagatla | 4da69f4 | 2017-07-26 11:34:48 +0200 | [diff] [blame] | 18 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 19 | struct device; |
| 20 | struct device_node; |
| 21 | /* consumer cookie */ |
| 22 | struct nvmem_cell; |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 23 | struct nvmem_device; |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 24 | |
Srinivas Kandagatla | eace75c | 2015-07-27 12:13:19 +0100 | [diff] [blame] | 25 | struct nvmem_cell_info { |
| 26 | const char *name; |
| 27 | unsigned int offset; |
| 28 | unsigned int bytes; |
| 29 | unsigned int bit_offset; |
| 30 | unsigned int nbits; |
| 31 | }; |
| 32 | |
Bartosz Golaszewski | 506157b | 2018-09-21 06:40:17 -0700 | [diff] [blame] | 33 | /** |
| 34 | * struct nvmem_cell_lookup - cell lookup entry |
| 35 | * |
| 36 | * @nvmem_name: Name of the provider. |
| 37 | * @cell_name: Name of the nvmem cell as defined in the name field of |
| 38 | * struct nvmem_cell_info. |
| 39 | * @dev_id: Name of the consumer device that will be associated with |
| 40 | * this cell. |
| 41 | * @con_id: Connector id for this cell lookup. |
| 42 | */ |
| 43 | struct nvmem_cell_lookup { |
| 44 | const char *nvmem_name; |
| 45 | const char *cell_name; |
| 46 | const char *dev_id; |
| 47 | const char *con_id; |
| 48 | struct list_head node; |
| 49 | }; |
| 50 | |
Bartosz Golaszewski | bee1138 | 2018-09-21 06:40:19 -0700 | [diff] [blame^] | 51 | enum { |
| 52 | NVMEM_ADD = 1, |
| 53 | NVMEM_REMOVE, |
| 54 | NVMEM_CELL_ADD, |
| 55 | NVMEM_CELL_REMOVE, |
| 56 | }; |
| 57 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 58 | #if IS_ENABLED(CONFIG_NVMEM) |
| 59 | |
| 60 | /* Cell based interface */ |
| 61 | struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *name); |
| 62 | struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *name); |
| 63 | void nvmem_cell_put(struct nvmem_cell *cell); |
| 64 | void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); |
| 65 | void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); |
| 66 | int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len); |
Leonard Crestez | d026d70 | 2017-07-26 11:34:46 +0200 | [diff] [blame] | 67 | 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] | 68 | |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 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 | |
Bartosz Golaszewski | d7b9fd1 | 2018-09-21 06:40:03 -0700 | [diff] [blame] | 84 | const char *nvmem_dev_name(struct nvmem_device *nvmem); |
| 85 | |
Bartosz Golaszewski | 506157b | 2018-09-21 06:40:17 -0700 | [diff] [blame] | 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 | |
Bartosz Golaszewski | bee1138 | 2018-09-21 06:40:19 -0700 | [diff] [blame^] | 91 | int nvmem_register_notifier(struct notifier_block *nb); |
| 92 | int nvmem_unregister_notifier(struct notifier_block *nb); |
| 93 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 94 | #else |
| 95 | |
| 96 | static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, |
| 97 | const char *name) |
| 98 | { |
| 99 | return ERR_PTR(-ENOSYS); |
| 100 | } |
| 101 | |
| 102 | static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, |
| 103 | const char *name) |
| 104 | { |
| 105 | return ERR_PTR(-ENOSYS); |
| 106 | } |
| 107 | |
| 108 | static inline void devm_nvmem_cell_put(struct device *dev, |
| 109 | struct nvmem_cell *cell) |
| 110 | { |
| 111 | |
| 112 | } |
| 113 | static inline void nvmem_cell_put(struct nvmem_cell *cell) |
| 114 | { |
| 115 | } |
| 116 | |
Guenter Roeck | a6c5091 | 2016-06-02 12:05:12 +0100 | [diff] [blame] | 117 | 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] | 118 | { |
| 119 | return ERR_PTR(-ENOSYS); |
| 120 | } |
| 121 | |
| 122 | static inline int nvmem_cell_write(struct nvmem_cell *cell, |
| 123 | const char *buf, size_t len) |
| 124 | { |
| 125 | return -ENOSYS; |
| 126 | } |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 127 | |
Leonard Crestez | d026d70 | 2017-07-26 11:34:46 +0200 | [diff] [blame] | 128 | static inline int nvmem_cell_read_u32(struct device *dev, |
| 129 | const char *cell_id, u32 *val) |
| 130 | { |
| 131 | return -ENOSYS; |
| 132 | } |
| 133 | |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 134 | static inline struct nvmem_device *nvmem_device_get(struct device *dev, |
| 135 | const char *name) |
| 136 | { |
| 137 | return ERR_PTR(-ENOSYS); |
| 138 | } |
| 139 | |
| 140 | static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev, |
| 141 | const char *name) |
| 142 | { |
| 143 | return ERR_PTR(-ENOSYS); |
| 144 | } |
| 145 | |
| 146 | static inline void nvmem_device_put(struct nvmem_device *nvmem) |
| 147 | { |
| 148 | } |
| 149 | |
| 150 | static inline void devm_nvmem_device_put(struct device *dev, |
| 151 | struct nvmem_device *nvmem) |
| 152 | { |
| 153 | } |
| 154 | |
| 155 | static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, |
| 156 | struct nvmem_cell_info *info, |
| 157 | void *buf) |
| 158 | { |
| 159 | return -ENOSYS; |
| 160 | } |
| 161 | |
| 162 | static inline int nvmem_device_cell_write(struct nvmem_device *nvmem, |
| 163 | struct nvmem_cell_info *info, |
| 164 | void *buf) |
| 165 | { |
| 166 | return -ENOSYS; |
| 167 | } |
| 168 | |
| 169 | static inline int nvmem_device_read(struct nvmem_device *nvmem, |
| 170 | unsigned int offset, size_t bytes, |
| 171 | void *buf) |
| 172 | { |
| 173 | return -ENOSYS; |
| 174 | } |
| 175 | |
| 176 | static inline int nvmem_device_write(struct nvmem_device *nvmem, |
| 177 | unsigned int offset, size_t bytes, |
| 178 | void *buf) |
| 179 | { |
| 180 | return -ENOSYS; |
| 181 | } |
Bartosz Golaszewski | d7b9fd1 | 2018-09-21 06:40:03 -0700 | [diff] [blame] | 182 | |
| 183 | static inline const char *nvmem_dev_name(struct nvmem_device *nvmem) |
| 184 | { |
| 185 | return NULL; |
| 186 | } |
| 187 | |
Bartosz Golaszewski | 506157b | 2018-09-21 06:40:17 -0700 | [diff] [blame] | 188 | static inline void |
| 189 | nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} |
| 190 | static inline void |
| 191 | nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} |
| 192 | |
Bartosz Golaszewski | bee1138 | 2018-09-21 06:40:19 -0700 | [diff] [blame^] | 193 | static inline int nvmem_register_notifier(struct notifier_block *nb) |
| 194 | { |
| 195 | return -ENOSYS; |
| 196 | } |
| 197 | |
| 198 | static inline int nvmem_unregister_notifier(struct notifier_block *nb) |
| 199 | { |
| 200 | return -ENOSYS; |
| 201 | } |
| 202 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 203 | #endif /* CONFIG_NVMEM */ |
| 204 | |
| 205 | #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) |
| 206 | struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
| 207 | const char *name); |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 208 | struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
| 209 | const char *name); |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 210 | #else |
| 211 | static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
| 212 | const char *name) |
| 213 | { |
| 214 | return ERR_PTR(-ENOSYS); |
| 215 | } |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 216 | |
| 217 | static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
| 218 | const char *name) |
| 219 | { |
| 220 | return ERR_PTR(-ENOSYS); |
| 221 | } |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 222 | #endif /* CONFIG_NVMEM && CONFIG_OF */ |
| 223 | |
Srinivas Kandagatla | eace75c | 2015-07-27 12:13:19 +0100 | [diff] [blame] | 224 | #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */ |