.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ |
---|
1 | 2 | /* |
---|
2 | 3 | * nvmem framework consumer. |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org> |
---|
5 | 6 | * 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 | 7 | */ |
---|
11 | 8 | |
---|
12 | 9 | #ifndef _LINUX_NVMEM_CONSUMER_H |
---|
.. | .. |
---|
14 | 11 | |
---|
15 | 12 | #include <linux/err.h> |
---|
16 | 13 | #include <linux/errno.h> |
---|
| 14 | +#include <linux/notifier.h> |
---|
17 | 15 | |
---|
18 | 16 | struct device; |
---|
19 | 17 | struct device_node; |
---|
.. | .. |
---|
29 | 27 | unsigned int nbits; |
---|
30 | 28 | }; |
---|
31 | 29 | |
---|
| 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 | + |
---|
| 48 | +enum { |
---|
| 49 | + NVMEM_ADD = 1, |
---|
| 50 | + NVMEM_REMOVE, |
---|
| 51 | + NVMEM_CELL_ADD, |
---|
| 52 | + NVMEM_CELL_REMOVE, |
---|
| 53 | +}; |
---|
| 54 | + |
---|
32 | 55 | #if IS_ENABLED(CONFIG_NVMEM) |
---|
33 | 56 | |
---|
34 | 57 | /* Cell based interface */ |
---|
35 | | -struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *name); |
---|
36 | | -struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *name); |
---|
| 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); |
---|
37 | 60 | void nvmem_cell_put(struct nvmem_cell *cell); |
---|
38 | 61 | void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); |
---|
39 | 62 | void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); |
---|
40 | 63 | int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len); |
---|
| 64 | +int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val); |
---|
| 65 | +int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val); |
---|
41 | 66 | int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val); |
---|
| 67 | +int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val); |
---|
42 | 68 | |
---|
43 | 69 | /* direct nvmem device read/write interface */ |
---|
44 | 70 | struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); |
---|
.. | .. |
---|
57 | 83 | |
---|
58 | 84 | const char *nvmem_dev_name(struct nvmem_device *nvmem); |
---|
59 | 85 | |
---|
| 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 | + |
---|
| 91 | +int nvmem_register_notifier(struct notifier_block *nb); |
---|
| 92 | +int nvmem_unregister_notifier(struct notifier_block *nb); |
---|
| 93 | + |
---|
| 94 | +struct nvmem_device *nvmem_device_find(void *data, |
---|
| 95 | + int (*match)(struct device *dev, const void *data)); |
---|
| 96 | + |
---|
60 | 97 | #else |
---|
61 | 98 | |
---|
62 | 99 | static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, |
---|
63 | | - const char *name) |
---|
| 100 | + const char *id) |
---|
64 | 101 | { |
---|
65 | | - return ERR_PTR(-ENOSYS); |
---|
| 102 | + return ERR_PTR(-EOPNOTSUPP); |
---|
66 | 103 | } |
---|
67 | 104 | |
---|
68 | 105 | static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, |
---|
69 | | - const char *name) |
---|
| 106 | + const char *id) |
---|
70 | 107 | { |
---|
71 | | - return ERR_PTR(-ENOSYS); |
---|
| 108 | + return ERR_PTR(-EOPNOTSUPP); |
---|
72 | 109 | } |
---|
73 | 110 | |
---|
74 | 111 | static inline void devm_nvmem_cell_put(struct device *dev, |
---|
.. | .. |
---|
82 | 119 | |
---|
83 | 120 | static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) |
---|
84 | 121 | { |
---|
85 | | - return ERR_PTR(-ENOSYS); |
---|
| 122 | + return ERR_PTR(-EOPNOTSUPP); |
---|
86 | 123 | } |
---|
87 | 124 | |
---|
88 | 125 | static inline int nvmem_cell_write(struct nvmem_cell *cell, |
---|
89 | | - const char *buf, size_t len) |
---|
| 126 | + void *buf, size_t len) |
---|
90 | 127 | { |
---|
91 | | - return -ENOSYS; |
---|
| 128 | + return -EOPNOTSUPP; |
---|
| 129 | +} |
---|
| 130 | + |
---|
| 131 | +static inline int nvmem_cell_read_u16(struct device *dev, |
---|
| 132 | + const char *cell_id, u16 *val) |
---|
| 133 | +{ |
---|
| 134 | + return -EOPNOTSUPP; |
---|
92 | 135 | } |
---|
93 | 136 | |
---|
94 | 137 | static inline int nvmem_cell_read_u32(struct device *dev, |
---|
95 | 138 | const char *cell_id, u32 *val) |
---|
96 | 139 | { |
---|
97 | | - return -ENOSYS; |
---|
| 140 | + return -EOPNOTSUPP; |
---|
| 141 | +} |
---|
| 142 | + |
---|
| 143 | +static inline int nvmem_cell_read_u64(struct device *dev, |
---|
| 144 | + const char *cell_id, u64 *val) |
---|
| 145 | +{ |
---|
| 146 | + return -EOPNOTSUPP; |
---|
98 | 147 | } |
---|
99 | 148 | |
---|
100 | 149 | static inline struct nvmem_device *nvmem_device_get(struct device *dev, |
---|
101 | 150 | const char *name) |
---|
102 | 151 | { |
---|
103 | | - return ERR_PTR(-ENOSYS); |
---|
| 152 | + return ERR_PTR(-EOPNOTSUPP); |
---|
104 | 153 | } |
---|
105 | 154 | |
---|
106 | 155 | static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev, |
---|
107 | 156 | const char *name) |
---|
108 | 157 | { |
---|
109 | | - return ERR_PTR(-ENOSYS); |
---|
| 158 | + return ERR_PTR(-EOPNOTSUPP); |
---|
110 | 159 | } |
---|
111 | 160 | |
---|
112 | 161 | static inline void nvmem_device_put(struct nvmem_device *nvmem) |
---|
.. | .. |
---|
122 | 171 | struct nvmem_cell_info *info, |
---|
123 | 172 | void *buf) |
---|
124 | 173 | { |
---|
125 | | - return -ENOSYS; |
---|
| 174 | + return -EOPNOTSUPP; |
---|
126 | 175 | } |
---|
127 | 176 | |
---|
128 | 177 | static inline int nvmem_device_cell_write(struct nvmem_device *nvmem, |
---|
129 | 178 | struct nvmem_cell_info *info, |
---|
130 | 179 | void *buf) |
---|
131 | 180 | { |
---|
132 | | - return -ENOSYS; |
---|
| 181 | + return -EOPNOTSUPP; |
---|
133 | 182 | } |
---|
134 | 183 | |
---|
135 | 184 | static inline int nvmem_device_read(struct nvmem_device *nvmem, |
---|
136 | 185 | unsigned int offset, size_t bytes, |
---|
137 | 186 | void *buf) |
---|
138 | 187 | { |
---|
139 | | - return -ENOSYS; |
---|
| 188 | + return -EOPNOTSUPP; |
---|
140 | 189 | } |
---|
141 | 190 | |
---|
142 | 191 | static inline int nvmem_device_write(struct nvmem_device *nvmem, |
---|
143 | 192 | unsigned int offset, size_t bytes, |
---|
144 | 193 | void *buf) |
---|
145 | 194 | { |
---|
146 | | - return -ENOSYS; |
---|
| 195 | + return -EOPNOTSUPP; |
---|
147 | 196 | } |
---|
148 | 197 | |
---|
149 | 198 | static inline const char *nvmem_dev_name(struct nvmem_device *nvmem) |
---|
| 199 | +{ |
---|
| 200 | + return NULL; |
---|
| 201 | +} |
---|
| 202 | + |
---|
| 203 | +static inline void |
---|
| 204 | +nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} |
---|
| 205 | +static inline void |
---|
| 206 | +nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} |
---|
| 207 | + |
---|
| 208 | +static inline int nvmem_register_notifier(struct notifier_block *nb) |
---|
| 209 | +{ |
---|
| 210 | + return -EOPNOTSUPP; |
---|
| 211 | +} |
---|
| 212 | + |
---|
| 213 | +static inline int nvmem_unregister_notifier(struct notifier_block *nb) |
---|
| 214 | +{ |
---|
| 215 | + return -EOPNOTSUPP; |
---|
| 216 | +} |
---|
| 217 | + |
---|
| 218 | +static inline struct nvmem_device *nvmem_device_find(void *data, |
---|
| 219 | + int (*match)(struct device *dev, const void *data)) |
---|
150 | 220 | { |
---|
151 | 221 | return NULL; |
---|
152 | 222 | } |
---|
.. | .. |
---|
155 | 225 | |
---|
156 | 226 | #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) |
---|
157 | 227 | struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
---|
158 | | - const char *name); |
---|
| 228 | + const char *id); |
---|
159 | 229 | struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
---|
160 | 230 | const char *name); |
---|
161 | 231 | #else |
---|
162 | 232 | static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, |
---|
163 | | - const char *name) |
---|
| 233 | + const char *id) |
---|
164 | 234 | { |
---|
165 | | - return ERR_PTR(-ENOSYS); |
---|
| 235 | + return ERR_PTR(-EOPNOTSUPP); |
---|
166 | 236 | } |
---|
167 | 237 | |
---|
168 | 238 | static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
---|
169 | 239 | const char *name) |
---|
170 | 240 | { |
---|
171 | | - return ERR_PTR(-ENOSYS); |
---|
| 241 | + return ERR_PTR(-EOPNOTSUPP); |
---|
172 | 242 | } |
---|
173 | 243 | #endif /* CONFIG_NVMEM && CONFIG_OF */ |
---|
174 | 244 | |
---|