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 | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame^] | 15 | struct device; |
| 16 | struct device_node; |
| 17 | /* consumer cookie */ |
| 18 | struct nvmem_cell; |
| 19 | |
Srinivas Kandagatla | eace75c | 2015-07-27 12:13:19 +0100 | [diff] [blame] | 20 | struct nvmem_cell_info { |
| 21 | const char *name; |
| 22 | unsigned int offset; |
| 23 | unsigned int bytes; |
| 24 | unsigned int bit_offset; |
| 25 | unsigned int nbits; |
| 26 | }; |
| 27 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame^] | 28 | #if IS_ENABLED(CONFIG_NVMEM) |
| 29 | |
| 30 | /* Cell based interface */ |
| 31 | struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *name); |
| 32 | struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *name); |
| 33 | void nvmem_cell_put(struct nvmem_cell *cell); |
| 34 | void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); |
| 35 | void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); |
| 36 | int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len); |
| 37 | |
| 38 | #else |
| 39 | |
| 40 | static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, |
| 41 | const char *name) |
| 42 | { |
| 43 | return ERR_PTR(-ENOSYS); |
| 44 | } |
| 45 | |
| 46 | static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, |
| 47 | const char *name) |
| 48 | { |
| 49 | return ERR_PTR(-ENOSYS); |
| 50 | } |
| 51 | |
| 52 | static inline void devm_nvmem_cell_put(struct device *dev, |
| 53 | struct nvmem_cell *cell) |
| 54 | { |
| 55 | |
| 56 | } |
| 57 | static inline void nvmem_cell_put(struct nvmem_cell *cell) |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | static inline char *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) |
| 62 | { |
| 63 | return ERR_PTR(-ENOSYS); |
| 64 | } |
| 65 | |
| 66 | static inline int nvmem_cell_write(struct nvmem_cell *cell, |
| 67 | const char *buf, size_t len) |
| 68 | { |
| 69 | return -ENOSYS; |
| 70 | } |
| 71 | #endif /* CONFIG_NVMEM */ |
| 72 | |
| 73 | #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) |
| 74 | struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
| 75 | const char *name); |
| 76 | #else |
| 77 | static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
| 78 | const char *name) |
| 79 | { |
| 80 | return ERR_PTR(-ENOSYS); |
| 81 | } |
| 82 | #endif /* CONFIG_NVMEM && CONFIG_OF */ |
| 83 | |
Srinivas Kandagatla | eace75c | 2015-07-27 12:13:19 +0100 | [diff] [blame] | 84 | #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */ |