blob: efafccffaee8233c936f28727ca4261de1b6b7a7 [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 Kandagatla69aba792015-07-27 12:13:34 +010015struct device;
16struct device_node;
17/* consumer cookie */
18struct nvmem_cell;
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010019struct nvmem_device;
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010020
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +010021struct nvmem_cell_info {
22 const char *name;
23 unsigned int offset;
24 unsigned int bytes;
25 unsigned int bit_offset;
26 unsigned int nbits;
27};
28
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010029#if IS_ENABLED(CONFIG_NVMEM)
30
31/* Cell based interface */
32struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *name);
33struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *name);
34void nvmem_cell_put(struct nvmem_cell *cell);
35void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
36void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
37int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
Leonard Crestezd026d702017-07-26 11:34:46 +020038int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010039
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010040/* direct nvmem device read/write interface */
41struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
42struct nvmem_device *devm_nvmem_device_get(struct device *dev,
43 const char *name);
44void nvmem_device_put(struct nvmem_device *nvmem);
45void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
46int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
47 size_t bytes, void *buf);
48int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
49 size_t bytes, void *buf);
50ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
51 struct nvmem_cell_info *info, void *buf);
52int nvmem_device_cell_write(struct nvmem_device *nvmem,
53 struct nvmem_cell_info *info, void *buf);
54
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010055#else
56
57static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
58 const char *name)
59{
60 return ERR_PTR(-ENOSYS);
61}
62
63static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
64 const char *name)
65{
66 return ERR_PTR(-ENOSYS);
67}
68
69static inline void devm_nvmem_cell_put(struct device *dev,
70 struct nvmem_cell *cell)
71{
72
73}
74static inline void nvmem_cell_put(struct nvmem_cell *cell)
75{
76}
77
Guenter Roecka6c50912016-06-02 12:05:12 +010078static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010079{
80 return ERR_PTR(-ENOSYS);
81}
82
83static inline int nvmem_cell_write(struct nvmem_cell *cell,
84 const char *buf, size_t len)
85{
86 return -ENOSYS;
87}
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010088
Leonard Crestezd026d702017-07-26 11:34:46 +020089static inline int nvmem_cell_read_u32(struct device *dev,
90 const char *cell_id, u32 *val)
91{
92 return -ENOSYS;
93}
94
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010095static inline struct nvmem_device *nvmem_device_get(struct device *dev,
96 const char *name)
97{
98 return ERR_PTR(-ENOSYS);
99}
100
101static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
102 const char *name)
103{
104 return ERR_PTR(-ENOSYS);
105}
106
107static inline void nvmem_device_put(struct nvmem_device *nvmem)
108{
109}
110
111static inline void devm_nvmem_device_put(struct device *dev,
112 struct nvmem_device *nvmem)
113{
114}
115
116static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
117 struct nvmem_cell_info *info,
118 void *buf)
119{
120 return -ENOSYS;
121}
122
123static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
124 struct nvmem_cell_info *info,
125 void *buf)
126{
127 return -ENOSYS;
128}
129
130static inline int nvmem_device_read(struct nvmem_device *nvmem,
131 unsigned int offset, size_t bytes,
132 void *buf)
133{
134 return -ENOSYS;
135}
136
137static inline int nvmem_device_write(struct nvmem_device *nvmem,
138 unsigned int offset, size_t bytes,
139 void *buf)
140{
141 return -ENOSYS;
142}
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100143#endif /* CONFIG_NVMEM */
144
145#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
146struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
147 const char *name);
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100148struct nvmem_device *of_nvmem_device_get(struct device_node *np,
149 const char *name);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100150#else
151static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
152 const char *name)
153{
154 return ERR_PTR(-ENOSYS);
155}
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100156
157static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
158 const char *name)
159{
160 return ERR_PTR(-ENOSYS);
161}
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100162#endif /* CONFIG_NVMEM && CONFIG_OF */
163
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +0100164#endif /* ifndef _LINUX_NVMEM_CONSUMER_H */