blob: 4e85447f78602754f56b988f576beb8ab8ab71bf [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
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010058#else
59
60static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
61 const char *name)
62{
63 return ERR_PTR(-ENOSYS);
64}
65
66static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
67 const char *name)
68{
69 return ERR_PTR(-ENOSYS);
70}
71
72static inline void devm_nvmem_cell_put(struct device *dev,
73 struct nvmem_cell *cell)
74{
75
76}
77static inline void nvmem_cell_put(struct nvmem_cell *cell)
78{
79}
80
Guenter Roecka6c50912016-06-02 12:05:12 +010081static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010082{
83 return ERR_PTR(-ENOSYS);
84}
85
86static inline int nvmem_cell_write(struct nvmem_cell *cell,
87 const char *buf, size_t len)
88{
89 return -ENOSYS;
90}
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010091
Leonard Crestezd026d702017-07-26 11:34:46 +020092static inline int nvmem_cell_read_u32(struct device *dev,
93 const char *cell_id, u32 *val)
94{
95 return -ENOSYS;
96}
97
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010098static inline struct nvmem_device *nvmem_device_get(struct device *dev,
99 const char *name)
100{
101 return ERR_PTR(-ENOSYS);
102}
103
104static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
105 const char *name)
106{
107 return ERR_PTR(-ENOSYS);
108}
109
110static inline void nvmem_device_put(struct nvmem_device *nvmem)
111{
112}
113
114static inline void devm_nvmem_device_put(struct device *dev,
115 struct nvmem_device *nvmem)
116{
117}
118
119static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
120 struct nvmem_cell_info *info,
121 void *buf)
122{
123 return -ENOSYS;
124}
125
126static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
127 struct nvmem_cell_info *info,
128 void *buf)
129{
130 return -ENOSYS;
131}
132
133static inline int nvmem_device_read(struct nvmem_device *nvmem,
134 unsigned int offset, size_t bytes,
135 void *buf)
136{
137 return -ENOSYS;
138}
139
140static inline int nvmem_device_write(struct nvmem_device *nvmem,
141 unsigned int offset, size_t bytes,
142 void *buf)
143{
144 return -ENOSYS;
145}
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100146#endif /* CONFIG_NVMEM */
147
148#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
149struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
150 const char *name);
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100151struct nvmem_device *of_nvmem_device_get(struct device_node *np,
152 const char *name);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100153#else
154static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
155 const char *name)
156{
157 return ERR_PTR(-ENOSYS);
158}
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100159
160static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
161 const char *name)
162{
163 return ERR_PTR(-ENOSYS);
164}
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100165#endif /* CONFIG_NVMEM && CONFIG_OF */
166
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +0100167#endif /* ifndef _LINUX_NVMEM_CONSUMER_H */