blob: 0326b52e906bb886a82dd9304a5f8f9d87c04be6 [file] [log] [blame]
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +01001/*
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 Kandagatla4da69f42017-07-26 11:34:48 +020015#include <linux/err.h>
16#include <linux/errno.h>
Bartosz Golaszewskibee11382018-09-21 06:40:19 -070017#include <linux/notifier.h>
Srinivas Kandagatla4da69f42017-07-26 11:34:48 +020018
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010019struct device;
20struct device_node;
21/* consumer cookie */
22struct nvmem_cell;
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010023struct nvmem_device;
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010024
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +010025struct nvmem_cell_info {
26 const char *name;
27 unsigned int offset;
28 unsigned int bytes;
29 unsigned int bit_offset;
30 unsigned int nbits;
31};
32
Bartosz Golaszewski506157b2018-09-21 06:40:17 -070033/**
34 * struct nvmem_cell_lookup - cell lookup entry
35 *
36 * @nvmem_name: Name of the provider.
37 * @cell_name: Name of the nvmem cell as defined in the name field of
38 * struct nvmem_cell_info.
39 * @dev_id: Name of the consumer device that will be associated with
40 * this cell.
41 * @con_id: Connector id for this cell lookup.
42 */
43struct nvmem_cell_lookup {
44 const char *nvmem_name;
45 const char *cell_name;
46 const char *dev_id;
47 const char *con_id;
48 struct list_head node;
49};
50
Bartosz Golaszewskibee11382018-09-21 06:40:19 -070051enum {
52 NVMEM_ADD = 1,
53 NVMEM_REMOVE,
54 NVMEM_CELL_ADD,
55 NVMEM_CELL_REMOVE,
56};
57
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010058#if IS_ENABLED(CONFIG_NVMEM)
59
60/* Cell based interface */
61struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *name);
62struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *name);
63void nvmem_cell_put(struct nvmem_cell *cell);
64void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
65void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
66int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
Leonard Crestezd026d702017-07-26 11:34:46 +020067int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010068
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010069/* direct nvmem device read/write interface */
70struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
71struct nvmem_device *devm_nvmem_device_get(struct device *dev,
72 const char *name);
73void nvmem_device_put(struct nvmem_device *nvmem);
74void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
75int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
76 size_t bytes, void *buf);
77int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
78 size_t bytes, void *buf);
79ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
80 struct nvmem_cell_info *info, void *buf);
81int nvmem_device_cell_write(struct nvmem_device *nvmem,
82 struct nvmem_cell_info *info, void *buf);
83
Bartosz Golaszewskid7b9fd12018-09-21 06:40:03 -070084const char *nvmem_dev_name(struct nvmem_device *nvmem);
85
Bartosz Golaszewski506157b2018-09-21 06:40:17 -070086void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries,
87 size_t nentries);
88void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries,
89 size_t nentries);
90
Bartosz Golaszewskibee11382018-09-21 06:40:19 -070091int nvmem_register_notifier(struct notifier_block *nb);
92int nvmem_unregister_notifier(struct notifier_block *nb);
93
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010094#else
95
96static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
97 const char *name)
98{
99 return ERR_PTR(-ENOSYS);
100}
101
102static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
103 const char *name)
104{
105 return ERR_PTR(-ENOSYS);
106}
107
108static inline void devm_nvmem_cell_put(struct device *dev,
109 struct nvmem_cell *cell)
110{
111
112}
113static inline void nvmem_cell_put(struct nvmem_cell *cell)
114{
115}
116
Guenter Roecka6c50912016-06-02 12:05:12 +0100117static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100118{
119 return ERR_PTR(-ENOSYS);
120}
121
122static inline int nvmem_cell_write(struct nvmem_cell *cell,
123 const char *buf, size_t len)
124{
125 return -ENOSYS;
126}
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100127
Leonard Crestezd026d702017-07-26 11:34:46 +0200128static inline int nvmem_cell_read_u32(struct device *dev,
129 const char *cell_id, u32 *val)
130{
131 return -ENOSYS;
132}
133
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100134static inline struct nvmem_device *nvmem_device_get(struct device *dev,
135 const char *name)
136{
137 return ERR_PTR(-ENOSYS);
138}
139
140static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
141 const char *name)
142{
143 return ERR_PTR(-ENOSYS);
144}
145
146static inline void nvmem_device_put(struct nvmem_device *nvmem)
147{
148}
149
150static inline void devm_nvmem_device_put(struct device *dev,
151 struct nvmem_device *nvmem)
152{
153}
154
155static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
156 struct nvmem_cell_info *info,
157 void *buf)
158{
159 return -ENOSYS;
160}
161
162static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
163 struct nvmem_cell_info *info,
164 void *buf)
165{
166 return -ENOSYS;
167}
168
169static inline int nvmem_device_read(struct nvmem_device *nvmem,
170 unsigned int offset, size_t bytes,
171 void *buf)
172{
173 return -ENOSYS;
174}
175
176static inline int nvmem_device_write(struct nvmem_device *nvmem,
177 unsigned int offset, size_t bytes,
178 void *buf)
179{
180 return -ENOSYS;
181}
Bartosz Golaszewskid7b9fd12018-09-21 06:40:03 -0700182
183static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
184{
185 return NULL;
186}
187
Bartosz Golaszewski506157b2018-09-21 06:40:17 -0700188static inline void
189nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
190static inline void
191nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
192
Bartosz Golaszewskibee11382018-09-21 06:40:19 -0700193static inline int nvmem_register_notifier(struct notifier_block *nb)
194{
195 return -ENOSYS;
196}
197
198static inline int nvmem_unregister_notifier(struct notifier_block *nb)
199{
200 return -ENOSYS;
201}
202
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100203#endif /* CONFIG_NVMEM */
204
205#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
206struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
207 const char *name);
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100208struct nvmem_device *of_nvmem_device_get(struct device_node *np,
209 const char *name);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100210#else
211static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
212 const char *name)
213{
214 return ERR_PTR(-ENOSYS);
215}
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100216
217static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
218 const char *name)
219{
220 return ERR_PTR(-ENOSYS);
221}
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100222#endif /* CONFIG_NVMEM && CONFIG_OF */
223
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +0100224#endif /* ifndef _LINUX_NVMEM_CONSUMER_H */