hc
2024-05-10 61598093bbdd283a7edc367d900f223070ead8d2
kernel/include/linux/nvmem-consumer.h
....@@ -1,12 +1,9 @@
1
+/* SPDX-License-Identifier: GPL-2.0 */
12 /*
23 * nvmem framework consumer.
34 *
45 * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
56 * 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.
107 */
118
129 #ifndef _LINUX_NVMEM_CONSUMER_H
....@@ -14,6 +11,7 @@
1411
1512 #include <linux/err.h>
1613 #include <linux/errno.h>
14
+#include <linux/notifier.h>
1715
1816 struct device;
1917 struct device_node;
....@@ -29,16 +27,44 @@
2927 unsigned int nbits;
3028 };
3129
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
+
3255 #if IS_ENABLED(CONFIG_NVMEM)
3356
3457 /* 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);
3760 void nvmem_cell_put(struct nvmem_cell *cell);
3861 void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
3962 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
4063 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);
4166 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);
4268
4369 /* direct nvmem device read/write interface */
4470 struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
....@@ -57,18 +83,29 @@
5783
5884 const char *nvmem_dev_name(struct nvmem_device *nvmem);
5985
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
+
6097 #else
6198
6299 static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
63
- const char *name)
100
+ const char *id)
64101 {
65
- return ERR_PTR(-ENOSYS);
102
+ return ERR_PTR(-EOPNOTSUPP);
66103 }
67104
68105 static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
69
- const char *name)
106
+ const char *id)
70107 {
71
- return ERR_PTR(-ENOSYS);
108
+ return ERR_PTR(-EOPNOTSUPP);
72109 }
73110
74111 static inline void devm_nvmem_cell_put(struct device *dev,
....@@ -82,31 +119,43 @@
82119
83120 static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
84121 {
85
- return ERR_PTR(-ENOSYS);
122
+ return ERR_PTR(-EOPNOTSUPP);
86123 }
87124
88125 static inline int nvmem_cell_write(struct nvmem_cell *cell,
89
- const char *buf, size_t len)
126
+ void *buf, size_t len)
90127 {
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;
92135 }
93136
94137 static inline int nvmem_cell_read_u32(struct device *dev,
95138 const char *cell_id, u32 *val)
96139 {
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;
98147 }
99148
100149 static inline struct nvmem_device *nvmem_device_get(struct device *dev,
101150 const char *name)
102151 {
103
- return ERR_PTR(-ENOSYS);
152
+ return ERR_PTR(-EOPNOTSUPP);
104153 }
105154
106155 static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
107156 const char *name)
108157 {
109
- return ERR_PTR(-ENOSYS);
158
+ return ERR_PTR(-EOPNOTSUPP);
110159 }
111160
112161 static inline void nvmem_device_put(struct nvmem_device *nvmem)
....@@ -122,31 +171,52 @@
122171 struct nvmem_cell_info *info,
123172 void *buf)
124173 {
125
- return -ENOSYS;
174
+ return -EOPNOTSUPP;
126175 }
127176
128177 static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
129178 struct nvmem_cell_info *info,
130179 void *buf)
131180 {
132
- return -ENOSYS;
181
+ return -EOPNOTSUPP;
133182 }
134183
135184 static inline int nvmem_device_read(struct nvmem_device *nvmem,
136185 unsigned int offset, size_t bytes,
137186 void *buf)
138187 {
139
- return -ENOSYS;
188
+ return -EOPNOTSUPP;
140189 }
141190
142191 static inline int nvmem_device_write(struct nvmem_device *nvmem,
143192 unsigned int offset, size_t bytes,
144193 void *buf)
145194 {
146
- return -ENOSYS;
195
+ return -EOPNOTSUPP;
147196 }
148197
149198 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))
150220 {
151221 return NULL;
152222 }
....@@ -155,20 +225,20 @@
155225
156226 #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
157227 struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
158
- const char *name);
228
+ const char *id);
159229 struct nvmem_device *of_nvmem_device_get(struct device_node *np,
160230 const char *name);
161231 #else
162232 static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
163
- const char *name)
233
+ const char *id)
164234 {
165
- return ERR_PTR(-ENOSYS);
235
+ return ERR_PTR(-EOPNOTSUPP);
166236 }
167237
168238 static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
169239 const char *name)
170240 {
171
- return ERR_PTR(-ENOSYS);
241
+ return ERR_PTR(-EOPNOTSUPP);
172242 }
173243 #endif /* CONFIG_NVMEM && CONFIG_OF */
174244