Commit | Line | Data |
---|---|---|
b1c1db98 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
eace75cf SK |
2 | /* |
3 | * nvmem framework consumer. | |
4 | * | |
5 | * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org> | |
6 | * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com> | |
eace75cf SK |
7 | */ |
8 | ||
9 | #ifndef _LINUX_NVMEM_CONSUMER_H | |
10 | #define _LINUX_NVMEM_CONSUMER_H | |
11 | ||
4da69f49 SK |
12 | #include <linux/err.h> |
13 | #include <linux/errno.h> | |
bee1138b | 14 | #include <linux/notifier.h> |
4da69f49 | 15 | |
69aba794 SK |
16 | struct device; |
17 | struct device_node; | |
18 | /* consumer cookie */ | |
19 | struct nvmem_cell; | |
e2a5402e | 20 | struct nvmem_device; |
69aba794 | 21 | |
eace75cf SK |
22 | struct nvmem_cell_info { |
23 | const char *name; | |
24 | unsigned int offset; | |
25 | unsigned int bytes; | |
26 | unsigned int bit_offset; | |
27 | unsigned int nbits; | |
28 | }; | |
29 | ||
506157be BG |
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 | ||
bee1138b BG |
48 | enum { |
49 | NVMEM_ADD = 1, | |
50 | NVMEM_REMOVE, | |
51 | NVMEM_CELL_ADD, | |
52 | NVMEM_CELL_REMOVE, | |
53 | }; | |
54 | ||
69aba794 SK |
55 | #if IS_ENABLED(CONFIG_NVMEM) |
56 | ||
57 | /* Cell based interface */ | |
165589f0 BG |
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); | |
69aba794 SK |
60 | void nvmem_cell_put(struct nvmem_cell *cell); |
61 | void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); | |
62 | void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); | |
63 | int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len); | |
d026d70a | 64 | int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val); |
69aba794 | 65 | |
e2a5402e SK |
66 | /* direct nvmem device read/write interface */ |
67 | struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); | |
68 | struct nvmem_device *devm_nvmem_device_get(struct device *dev, | |
69 | const char *name); | |
70 | void nvmem_device_put(struct nvmem_device *nvmem); | |
71 | void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem); | |
72 | int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset, | |
73 | size_t bytes, void *buf); | |
74 | int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset, | |
75 | size_t bytes, void *buf); | |
76 | ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, | |
77 | struct nvmem_cell_info *info, void *buf); | |
78 | int nvmem_device_cell_write(struct nvmem_device *nvmem, | |
79 | struct nvmem_cell_info *info, void *buf); | |
80 | ||
d7b9fd16 BG |
81 | const char *nvmem_dev_name(struct nvmem_device *nvmem); |
82 | ||
506157be BG |
83 | void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, |
84 | size_t nentries); | |
85 | void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, | |
86 | size_t nentries); | |
87 | ||
bee1138b BG |
88 | int nvmem_register_notifier(struct notifier_block *nb); |
89 | int nvmem_unregister_notifier(struct notifier_block *nb); | |
90 | ||
69aba794 SK |
91 | #else |
92 | ||
93 | static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, | |
165589f0 | 94 | const char *id) |
69aba794 | 95 | { |
20167b70 | 96 | return ERR_PTR(-EOPNOTSUPP); |
69aba794 SK |
97 | } |
98 | ||
99 | static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, | |
165589f0 | 100 | const char *id) |
69aba794 | 101 | { |
20167b70 | 102 | return ERR_PTR(-EOPNOTSUPP); |
69aba794 SK |
103 | } |
104 | ||
105 | static inline void devm_nvmem_cell_put(struct device *dev, | |
106 | struct nvmem_cell *cell) | |
107 | { | |
108 | ||
109 | } | |
110 | static inline void nvmem_cell_put(struct nvmem_cell *cell) | |
111 | { | |
112 | } | |
113 | ||
a6c50912 | 114 | static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) |
69aba794 | 115 | { |
20167b70 | 116 | return ERR_PTR(-EOPNOTSUPP); |
69aba794 SK |
117 | } |
118 | ||
119 | static inline int nvmem_cell_write(struct nvmem_cell *cell, | |
120 | const char *buf, size_t len) | |
121 | { | |
20167b70 | 122 | return -EOPNOTSUPP; |
69aba794 | 123 | } |
e2a5402e | 124 | |
d026d70a LC |
125 | static inline int nvmem_cell_read_u32(struct device *dev, |
126 | const char *cell_id, u32 *val) | |
127 | { | |
20167b70 | 128 | return -EOPNOTSUPP; |
d026d70a LC |
129 | } |
130 | ||
e2a5402e SK |
131 | static inline struct nvmem_device *nvmem_device_get(struct device *dev, |
132 | const char *name) | |
133 | { | |
20167b70 | 134 | return ERR_PTR(-EOPNOTSUPP); |
e2a5402e SK |
135 | } |
136 | ||
137 | static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev, | |
138 | const char *name) | |
139 | { | |
20167b70 | 140 | return ERR_PTR(-EOPNOTSUPP); |
e2a5402e SK |
141 | } |
142 | ||
143 | static inline void nvmem_device_put(struct nvmem_device *nvmem) | |
144 | { | |
145 | } | |
146 | ||
147 | static inline void devm_nvmem_device_put(struct device *dev, | |
148 | struct nvmem_device *nvmem) | |
149 | { | |
150 | } | |
151 | ||
152 | static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, | |
153 | struct nvmem_cell_info *info, | |
154 | void *buf) | |
155 | { | |
20167b70 | 156 | return -EOPNOTSUPP; |
e2a5402e SK |
157 | } |
158 | ||
159 | static inline int nvmem_device_cell_write(struct nvmem_device *nvmem, | |
160 | struct nvmem_cell_info *info, | |
161 | void *buf) | |
162 | { | |
20167b70 | 163 | return -EOPNOTSUPP; |
e2a5402e SK |
164 | } |
165 | ||
166 | static inline int nvmem_device_read(struct nvmem_device *nvmem, | |
167 | unsigned int offset, size_t bytes, | |
168 | void *buf) | |
169 | { | |
20167b70 | 170 | return -EOPNOTSUPP; |
e2a5402e SK |
171 | } |
172 | ||
173 | static inline int nvmem_device_write(struct nvmem_device *nvmem, | |
174 | unsigned int offset, size_t bytes, | |
175 | void *buf) | |
176 | { | |
20167b70 | 177 | return -EOPNOTSUPP; |
e2a5402e | 178 | } |
d7b9fd16 BG |
179 | |
180 | static inline const char *nvmem_dev_name(struct nvmem_device *nvmem) | |
181 | { | |
182 | return NULL; | |
183 | } | |
184 | ||
506157be BG |
185 | static inline void |
186 | nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} | |
187 | static inline void | |
188 | nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {} | |
189 | ||
bee1138b BG |
190 | static inline int nvmem_register_notifier(struct notifier_block *nb) |
191 | { | |
20167b70 | 192 | return -EOPNOTSUPP; |
bee1138b BG |
193 | } |
194 | ||
195 | static inline int nvmem_unregister_notifier(struct notifier_block *nb) | |
196 | { | |
20167b70 | 197 | return -EOPNOTSUPP; |
bee1138b BG |
198 | } |
199 | ||
69aba794 SK |
200 | #endif /* CONFIG_NVMEM */ |
201 | ||
202 | #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) | |
203 | struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, | |
165589f0 | 204 | const char *id); |
e2a5402e SK |
205 | struct nvmem_device *of_nvmem_device_get(struct device_node *np, |
206 | const char *name); | |
69aba794 SK |
207 | #else |
208 | static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, | |
165589f0 | 209 | const char *id) |
69aba794 | 210 | { |
20167b70 | 211 | return ERR_PTR(-EOPNOTSUPP); |
69aba794 | 212 | } |
e2a5402e SK |
213 | |
214 | static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, | |
215 | const char *name) | |
216 | { | |
20167b70 | 217 | return ERR_PTR(-EOPNOTSUPP); |
e2a5402e | 218 | } |
69aba794 SK |
219 | #endif /* CONFIG_NVMEM && CONFIG_OF */ |
220 | ||
eace75cf | 221 | #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */ |