blob: 0389fe00b17748f2568c3dc059f4d412e3d3007d [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
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010032#if IS_ENABLED(CONFIG_NVMEM)
33
34/* Cell based interface */
35struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *name);
36struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *name);
37void nvmem_cell_put(struct nvmem_cell *cell);
38void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
39void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
40int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
Leonard Crestezd026d702017-07-26 11:34:46 +020041int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010042
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010043/* direct nvmem device read/write interface */
44struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
45struct nvmem_device *devm_nvmem_device_get(struct device *dev,
46 const char *name);
47void nvmem_device_put(struct nvmem_device *nvmem);
48void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
49int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
50 size_t bytes, void *buf);
51int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
52 size_t bytes, void *buf);
53ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
54 struct nvmem_cell_info *info, void *buf);
55int nvmem_device_cell_write(struct nvmem_device *nvmem,
56 struct nvmem_cell_info *info, void *buf);
57
Bartosz Golaszewskid7b9fd12018-09-21 06:40:03 -070058const char *nvmem_dev_name(struct nvmem_device *nvmem);
59
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010060#else
61
62static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
63 const char *name)
64{
65 return ERR_PTR(-ENOSYS);
66}
67
68static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
69 const char *name)
70{
71 return ERR_PTR(-ENOSYS);
72}
73
74static inline void devm_nvmem_cell_put(struct device *dev,
75 struct nvmem_cell *cell)
76{
77
78}
79static inline void nvmem_cell_put(struct nvmem_cell *cell)
80{
81}
82
Guenter Roecka6c50912016-06-02 12:05:12 +010083static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010084{
85 return ERR_PTR(-ENOSYS);
86}
87
88static inline int nvmem_cell_write(struct nvmem_cell *cell,
89 const char *buf, size_t len)
90{
91 return -ENOSYS;
92}
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010093
Leonard Crestezd026d702017-07-26 11:34:46 +020094static inline int nvmem_cell_read_u32(struct device *dev,
95 const char *cell_id, u32 *val)
96{
97 return -ENOSYS;
98}
99
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100100static inline struct nvmem_device *nvmem_device_get(struct device *dev,
101 const char *name)
102{
103 return ERR_PTR(-ENOSYS);
104}
105
106static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
107 const char *name)
108{
109 return ERR_PTR(-ENOSYS);
110}
111
112static inline void nvmem_device_put(struct nvmem_device *nvmem)
113{
114}
115
116static inline void devm_nvmem_device_put(struct device *dev,
117 struct nvmem_device *nvmem)
118{
119}
120
121static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
122 struct nvmem_cell_info *info,
123 void *buf)
124{
125 return -ENOSYS;
126}
127
128static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
129 struct nvmem_cell_info *info,
130 void *buf)
131{
132 return -ENOSYS;
133}
134
135static inline int nvmem_device_read(struct nvmem_device *nvmem,
136 unsigned int offset, size_t bytes,
137 void *buf)
138{
139 return -ENOSYS;
140}
141
142static inline int nvmem_device_write(struct nvmem_device *nvmem,
143 unsigned int offset, size_t bytes,
144 void *buf)
145{
146 return -ENOSYS;
147}
Bartosz Golaszewskid7b9fd12018-09-21 06:40:03 -0700148
149static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
150{
151 return NULL;
152}
153
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100154#endif /* CONFIG_NVMEM */
155
156#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
157struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
158 const char *name);
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100159struct nvmem_device *of_nvmem_device_get(struct device_node *np,
160 const char *name);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100161#else
162static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
163 const char *name)
164{
165 return ERR_PTR(-ENOSYS);
166}
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100167
168static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
169 const char *name)
170{
171 return ERR_PTR(-ENOSYS);
172}
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100173#endif /* CONFIG_NVMEM && CONFIG_OF */
174
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +0100175#endif /* ifndef _LINUX_NVMEM_CONSUMER_H */