blob: 27eee394540548bfeeb77176fad442d7ee7582ac [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>
17
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010018struct device;
19struct device_node;
20/* consumer cookie */
21struct nvmem_cell;
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010022struct nvmem_device;
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010023
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +010024struct nvmem_cell_info {
25 const char *name;
26 unsigned int offset;
27 unsigned int bytes;
28 unsigned int bit_offset;
29 unsigned int nbits;
30};
31
Bartosz Golaszewski506157b2018-09-21 06:40:17 -070032/**
33 * struct nvmem_cell_lookup - cell lookup entry
34 *
35 * @nvmem_name: Name of the provider.
36 * @cell_name: Name of the nvmem cell as defined in the name field of
37 * struct nvmem_cell_info.
38 * @dev_id: Name of the consumer device that will be associated with
39 * this cell.
40 * @con_id: Connector id for this cell lookup.
41 */
42struct nvmem_cell_lookup {
43 const char *nvmem_name;
44 const char *cell_name;
45 const char *dev_id;
46 const char *con_id;
47 struct list_head node;
48};
49
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010050#if IS_ENABLED(CONFIG_NVMEM)
51
52/* Cell based interface */
53struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *name);
54struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *name);
55void nvmem_cell_put(struct nvmem_cell *cell);
56void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
57void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
58int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
Leonard Crestezd026d702017-07-26 11:34:46 +020059int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010060
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010061/* direct nvmem device read/write interface */
62struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
63struct nvmem_device *devm_nvmem_device_get(struct device *dev,
64 const char *name);
65void nvmem_device_put(struct nvmem_device *nvmem);
66void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
67int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
68 size_t bytes, void *buf);
69int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
70 size_t bytes, void *buf);
71ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
72 struct nvmem_cell_info *info, void *buf);
73int nvmem_device_cell_write(struct nvmem_device *nvmem,
74 struct nvmem_cell_info *info, void *buf);
75
Bartosz Golaszewskid7b9fd12018-09-21 06:40:03 -070076const char *nvmem_dev_name(struct nvmem_device *nvmem);
77
Bartosz Golaszewski506157b2018-09-21 06:40:17 -070078void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries,
79 size_t nentries);
80void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries,
81 size_t nentries);
82
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010083#else
84
85static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
86 const char *name)
87{
88 return ERR_PTR(-ENOSYS);
89}
90
91static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
92 const char *name)
93{
94 return ERR_PTR(-ENOSYS);
95}
96
97static inline void devm_nvmem_cell_put(struct device *dev,
98 struct nvmem_cell *cell)
99{
100
101}
102static inline void nvmem_cell_put(struct nvmem_cell *cell)
103{
104}
105
Guenter Roecka6c50912016-06-02 12:05:12 +0100106static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100107{
108 return ERR_PTR(-ENOSYS);
109}
110
111static inline int nvmem_cell_write(struct nvmem_cell *cell,
112 const char *buf, size_t len)
113{
114 return -ENOSYS;
115}
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100116
Leonard Crestezd026d702017-07-26 11:34:46 +0200117static inline int nvmem_cell_read_u32(struct device *dev,
118 const char *cell_id, u32 *val)
119{
120 return -ENOSYS;
121}
122
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100123static inline struct nvmem_device *nvmem_device_get(struct device *dev,
124 const char *name)
125{
126 return ERR_PTR(-ENOSYS);
127}
128
129static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
130 const char *name)
131{
132 return ERR_PTR(-ENOSYS);
133}
134
135static inline void nvmem_device_put(struct nvmem_device *nvmem)
136{
137}
138
139static inline void devm_nvmem_device_put(struct device *dev,
140 struct nvmem_device *nvmem)
141{
142}
143
144static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
145 struct nvmem_cell_info *info,
146 void *buf)
147{
148 return -ENOSYS;
149}
150
151static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
152 struct nvmem_cell_info *info,
153 void *buf)
154{
155 return -ENOSYS;
156}
157
158static inline int nvmem_device_read(struct nvmem_device *nvmem,
159 unsigned int offset, size_t bytes,
160 void *buf)
161{
162 return -ENOSYS;
163}
164
165static inline int nvmem_device_write(struct nvmem_device *nvmem,
166 unsigned int offset, size_t bytes,
167 void *buf)
168{
169 return -ENOSYS;
170}
Bartosz Golaszewskid7b9fd12018-09-21 06:40:03 -0700171
172static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
173{
174 return NULL;
175}
176
Bartosz Golaszewski506157b2018-09-21 06:40:17 -0700177static inline void
178nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
179static inline void
180nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
181
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100182#endif /* CONFIG_NVMEM */
183
184#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
185struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
186 const char *name);
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100187struct nvmem_device *of_nvmem_device_get(struct device_node *np,
188 const char *name);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100189#else
190static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
191 const char *name)
192{
193 return ERR_PTR(-ENOSYS);
194}
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100195
196static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
197 const char *name)
198{
199 return ERR_PTR(-ENOSYS);
200}
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100201#endif /* CONFIG_NVMEM && CONFIG_OF */
202
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +0100203#endif /* ifndef _LINUX_NVMEM_CONSUMER_H */