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> |
| 17 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 18 | struct device; |
| 19 | struct device_node; |
| 20 | /* consumer cookie */ |
| 21 | struct nvmem_cell; |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 22 | struct nvmem_device; |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 23 | |
Srinivas Kandagatla | eace75c | 2015-07-27 12:13:19 +0100 | [diff] [blame] | 24 | struct nvmem_cell_info { |
| 25 | const char *name; |
| 26 | unsigned int offset; |
| 27 | unsigned int bytes; |
| 28 | unsigned int bit_offset; |
| 29 | unsigned int nbits; |
| 30 | }; |
| 31 | |
Bartosz Golaszewski | 506157b | 2018-09-21 06:40:17 -0700 | [diff] [blame^] | 32 | /** |
| 33 | * struct nvmem_cell_lookup - cell lookup entry |
| 34 | * |
| 35 | * @nvmem_name: Name of the provider. |
| 36 | * @cell_name: Name of the nvmem cell as defined in the name field of |
| 37 | * struct nvmem_cell_info. |
| 38 | * @dev_id: Name of the consumer device that will be associated with |
| 39 | * this cell. |
| 40 | * @con_id: Connector id for this cell lookup. |
| 41 | */ |
| 42 | struct nvmem_cell_lookup { |
| 43 | const char *nvmem_name; |
| 44 | const char *cell_name; |
| 45 | const char *dev_id; |
| 46 | const char *con_id; |
| 47 | struct list_head node; |
| 48 | }; |
| 49 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 50 | #if IS_ENABLED(CONFIG_NVMEM) |
| 51 | |
| 52 | /* Cell based interface */ |
| 53 | struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *name); |
| 54 | struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *name); |
| 55 | void nvmem_cell_put(struct nvmem_cell *cell); |
| 56 | void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); |
| 57 | void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); |
| 58 | 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] | 59 | 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] | 60 | |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 61 | /* direct nvmem device read/write interface */ |
| 62 | struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); |
| 63 | struct nvmem_device *devm_nvmem_device_get(struct device *dev, |
| 64 | const char *name); |
| 65 | void nvmem_device_put(struct nvmem_device *nvmem); |
| 66 | void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem); |
| 67 | int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset, |
| 68 | size_t bytes, void *buf); |
| 69 | int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset, |
| 70 | size_t bytes, void *buf); |
| 71 | ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, |
| 72 | struct nvmem_cell_info *info, void *buf); |
| 73 | int nvmem_device_cell_write(struct nvmem_device *nvmem, |
| 74 | struct nvmem_cell_info *info, void *buf); |
| 75 | |
Bartosz Golaszewski | d7b9fd1 | 2018-09-21 06:40:03 -0700 | [diff] [blame] | 76 | const char *nvmem_dev_name(struct nvmem_device *nvmem); |
| 77 | |
Bartosz Golaszewski | 506157b | 2018-09-21 06:40:17 -0700 | [diff] [blame^] | 78 | void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, |
| 79 | size_t nentries); |
| 80 | void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, |
| 81 | size_t nentries); |
| 82 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 83 | #else |
| 84 | |
| 85 | static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, |
| 86 | const char *name) |
| 87 | { |
| 88 | return ERR_PTR(-ENOSYS); |
| 89 | } |
| 90 | |
| 91 | static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, |
| 92 | const char *name) |
| 93 | { |
| 94 | return ERR_PTR(-ENOSYS); |
| 95 | } |
| 96 | |
| 97 | static inline void devm_nvmem_cell_put(struct device *dev, |
| 98 | struct nvmem_cell *cell) |
| 99 | { |
| 100 | |
| 101 | } |
| 102 | static inline void nvmem_cell_put(struct nvmem_cell *cell) |
| 103 | { |
| 104 | } |
| 105 | |
Guenter Roeck | a6c5091 | 2016-06-02 12:05:12 +0100 | [diff] [blame] | 106 | 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] | 107 | { |
| 108 | return ERR_PTR(-ENOSYS); |
| 109 | } |
| 110 | |
| 111 | static inline int nvmem_cell_write(struct nvmem_cell *cell, |
| 112 | const char *buf, size_t len) |
| 113 | { |
| 114 | return -ENOSYS; |
| 115 | } |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 116 | |
Leonard Crestez | d026d70 | 2017-07-26 11:34:46 +0200 | [diff] [blame] | 117 | static inline int nvmem_cell_read_u32(struct device *dev, |
| 118 | const char *cell_id, u32 *val) |
| 119 | { |
| 120 | return -ENOSYS; |
| 121 | } |
| 122 | |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 123 | static inline struct nvmem_device *nvmem_device_get(struct device *dev, |
| 124 | const char *name) |
| 125 | { |
| 126 | return ERR_PTR(-ENOSYS); |
| 127 | } |
| 128 | |
| 129 | static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev, |
| 130 | const char *name) |
| 131 | { |
| 132 | return ERR_PTR(-ENOSYS); |
| 133 | } |
| 134 | |
| 135 | static inline void nvmem_device_put(struct nvmem_device *nvmem) |
| 136 | { |
| 137 | } |
| 138 | |
| 139 | static inline void devm_nvmem_device_put(struct device *dev, |
| 140 | struct nvmem_device *nvmem) |
| 141 | { |
| 142 | } |
| 143 | |
| 144 | static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, |
| 145 | struct nvmem_cell_info *info, |
| 146 | void *buf) |
| 147 | { |
| 148 | return -ENOSYS; |
| 149 | } |
| 150 | |
| 151 | static inline int nvmem_device_cell_write(struct nvmem_device *nvmem, |
| 152 | struct nvmem_cell_info *info, |
| 153 | void *buf) |
| 154 | { |
| 155 | return -ENOSYS; |
| 156 | } |
| 157 | |
| 158 | static inline int nvmem_device_read(struct nvmem_device *nvmem, |
| 159 | unsigned int offset, size_t bytes, |
| 160 | void *buf) |
| 161 | { |
| 162 | return -ENOSYS; |
| 163 | } |
| 164 | |
| 165 | static inline int nvmem_device_write(struct nvmem_device *nvmem, |
| 166 | unsigned int offset, size_t bytes, |
| 167 | void *buf) |
| 168 | { |
| 169 | return -ENOSYS; |
| 170 | } |
Bartosz Golaszewski | d7b9fd1 | 2018-09-21 06:40:03 -0700 | [diff] [blame] | 171 | |
| 172 | static inline const char *nvmem_dev_name(struct nvmem_device *nvmem) |
| 173 | { |
| 174 | return NULL; |
| 175 | } |
| 176 | |
Bartosz Golaszewski | 506157b | 2018-09-21 06:40:17 -0700 | [diff] [blame^] | 177 | static inline void |
| 178 | nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} |
| 179 | static inline void |
| 180 | nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} |
| 181 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 182 | #endif /* CONFIG_NVMEM */ |
| 183 | |
| 184 | #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) |
| 185 | struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
| 186 | const char *name); |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 187 | struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
| 188 | const char *name); |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 189 | #else |
| 190 | static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
| 191 | const char *name) |
| 192 | { |
| 193 | return ERR_PTR(-ENOSYS); |
| 194 | } |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 195 | |
| 196 | static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
| 197 | const char *name) |
| 198 | { |
| 199 | return ERR_PTR(-ENOSYS); |
| 200 | } |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 201 | #endif /* CONFIG_NVMEM && CONFIG_OF */ |
| 202 | |
Srinivas Kandagatla | eace75c | 2015-07-27 12:13:19 +0100 | [diff] [blame] | 203 | #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */ |