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; |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 19 | struct nvmem_device; |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 20 | |
Srinivas Kandagatla | eace75c | 2015-07-27 12:13:19 +0100 | [diff] [blame] | 21 | struct nvmem_cell_info { |
| 22 | const char *name; |
| 23 | unsigned int offset; |
| 24 | unsigned int bytes; |
| 25 | unsigned int bit_offset; |
| 26 | unsigned int nbits; |
| 27 | }; |
| 28 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 29 | #if IS_ENABLED(CONFIG_NVMEM) |
| 30 | |
| 31 | /* Cell based interface */ |
| 32 | struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *name); |
| 33 | struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *name); |
| 34 | void nvmem_cell_put(struct nvmem_cell *cell); |
| 35 | void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); |
| 36 | void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); |
| 37 | 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^] | 38 | 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] | 39 | |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 40 | /* direct nvmem device read/write interface */ |
| 41 | struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); |
| 42 | struct nvmem_device *devm_nvmem_device_get(struct device *dev, |
| 43 | const char *name); |
| 44 | void nvmem_device_put(struct nvmem_device *nvmem); |
| 45 | void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem); |
| 46 | int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset, |
| 47 | size_t bytes, void *buf); |
| 48 | int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset, |
| 49 | size_t bytes, void *buf); |
| 50 | ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, |
| 51 | struct nvmem_cell_info *info, void *buf); |
| 52 | int nvmem_device_cell_write(struct nvmem_device *nvmem, |
| 53 | struct nvmem_cell_info *info, void *buf); |
| 54 | |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 55 | #else |
| 56 | |
| 57 | static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, |
| 58 | const char *name) |
| 59 | { |
| 60 | return ERR_PTR(-ENOSYS); |
| 61 | } |
| 62 | |
| 63 | static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, |
| 64 | const char *name) |
| 65 | { |
| 66 | return ERR_PTR(-ENOSYS); |
| 67 | } |
| 68 | |
| 69 | static inline void devm_nvmem_cell_put(struct device *dev, |
| 70 | struct nvmem_cell *cell) |
| 71 | { |
| 72 | |
| 73 | } |
| 74 | static inline void nvmem_cell_put(struct nvmem_cell *cell) |
| 75 | { |
| 76 | } |
| 77 | |
Guenter Roeck | a6c5091 | 2016-06-02 12:05:12 +0100 | [diff] [blame] | 78 | 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] | 79 | { |
| 80 | return ERR_PTR(-ENOSYS); |
| 81 | } |
| 82 | |
| 83 | static inline int nvmem_cell_write(struct nvmem_cell *cell, |
| 84 | const char *buf, size_t len) |
| 85 | { |
| 86 | return -ENOSYS; |
| 87 | } |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 88 | |
Leonard Crestez | d026d70 | 2017-07-26 11:34:46 +0200 | [diff] [blame^] | 89 | static inline int nvmem_cell_read_u32(struct device *dev, |
| 90 | const char *cell_id, u32 *val) |
| 91 | { |
| 92 | return -ENOSYS; |
| 93 | } |
| 94 | |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 95 | static inline struct nvmem_device *nvmem_device_get(struct device *dev, |
| 96 | const char *name) |
| 97 | { |
| 98 | return ERR_PTR(-ENOSYS); |
| 99 | } |
| 100 | |
| 101 | static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev, |
| 102 | const char *name) |
| 103 | { |
| 104 | return ERR_PTR(-ENOSYS); |
| 105 | } |
| 106 | |
| 107 | static inline void nvmem_device_put(struct nvmem_device *nvmem) |
| 108 | { |
| 109 | } |
| 110 | |
| 111 | static inline void devm_nvmem_device_put(struct device *dev, |
| 112 | struct nvmem_device *nvmem) |
| 113 | { |
| 114 | } |
| 115 | |
| 116 | static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, |
| 117 | struct nvmem_cell_info *info, |
| 118 | void *buf) |
| 119 | { |
| 120 | return -ENOSYS; |
| 121 | } |
| 122 | |
| 123 | static inline int nvmem_device_cell_write(struct nvmem_device *nvmem, |
| 124 | struct nvmem_cell_info *info, |
| 125 | void *buf) |
| 126 | { |
| 127 | return -ENOSYS; |
| 128 | } |
| 129 | |
| 130 | static inline int nvmem_device_read(struct nvmem_device *nvmem, |
| 131 | unsigned int offset, size_t bytes, |
| 132 | void *buf) |
| 133 | { |
| 134 | return -ENOSYS; |
| 135 | } |
| 136 | |
| 137 | static inline int nvmem_device_write(struct nvmem_device *nvmem, |
| 138 | unsigned int offset, size_t bytes, |
| 139 | void *buf) |
| 140 | { |
| 141 | return -ENOSYS; |
| 142 | } |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 143 | #endif /* CONFIG_NVMEM */ |
| 144 | |
| 145 | #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) |
| 146 | struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
| 147 | const char *name); |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 148 | struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
| 149 | const char *name); |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 150 | #else |
| 151 | static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
| 152 | const char *name) |
| 153 | { |
| 154 | return ERR_PTR(-ENOSYS); |
| 155 | } |
Srinivas Kandagatla | e2a5402 | 2015-07-27 12:13:45 +0100 | [diff] [blame] | 156 | |
| 157 | static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
| 158 | const char *name) |
| 159 | { |
| 160 | return ERR_PTR(-ENOSYS); |
| 161 | } |
Srinivas Kandagatla | 69aba79 | 2015-07-27 12:13:34 +0100 | [diff] [blame] | 162 | #endif /* CONFIG_NVMEM && CONFIG_OF */ |
| 163 | |
Srinivas Kandagatla | eace75c | 2015-07-27 12:13:19 +0100 | [diff] [blame] | 164 | #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */ |