blob: 8f8be5b00060285b61f57abe008026ede9303ff3 [file] [log] [blame]
Bartosz Golaszewskib1c1db92018-09-21 06:40:20 -07001/* SPDX-License-Identifier: GPL-2.0 */
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +01002/*
3 * nvmem framework consumer.
4 *
5 * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
6 * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com>
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +01007 */
8
9#ifndef _LINUX_NVMEM_CONSUMER_H
10#define _LINUX_NVMEM_CONSUMER_H
11
Srinivas Kandagatla4da69f42017-07-26 11:34:48 +020012#include <linux/err.h>
13#include <linux/errno.h>
Bartosz Golaszewskibee11382018-09-21 06:40:19 -070014#include <linux/notifier.h>
Srinivas Kandagatla4da69f42017-07-26 11:34:48 +020015
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010016struct device;
17struct device_node;
18/* consumer cookie */
19struct nvmem_cell;
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010020struct nvmem_device;
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010021
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +010022struct nvmem_cell_info {
23 const char *name;
24 unsigned int offset;
25 unsigned int bytes;
26 unsigned int bit_offset;
27 unsigned int nbits;
28};
29
Bartosz Golaszewski506157b2018-09-21 06:40:17 -070030/**
31 * struct nvmem_cell_lookup - cell lookup entry
32 *
33 * @nvmem_name: Name of the provider.
34 * @cell_name: Name of the nvmem cell as defined in the name field of
35 * struct nvmem_cell_info.
36 * @dev_id: Name of the consumer device that will be associated with
37 * this cell.
38 * @con_id: Connector id for this cell lookup.
39 */
40struct nvmem_cell_lookup {
41 const char *nvmem_name;
42 const char *cell_name;
43 const char *dev_id;
44 const char *con_id;
45 struct list_head node;
46};
47
Bartosz Golaszewskibee11382018-09-21 06:40:19 -070048enum {
49 NVMEM_ADD = 1,
50 NVMEM_REMOVE,
51 NVMEM_CELL_ADD,
52 NVMEM_CELL_REMOVE,
53};
54
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010055#if IS_ENABLED(CONFIG_NVMEM)
56
57/* Cell based interface */
Bartosz Golaszewski165589f2018-09-21 06:40:21 -070058struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id);
59struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010060void nvmem_cell_put(struct nvmem_cell *cell);
61void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
62void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
63int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
Fabrice Gasnier0a9b2d12019-04-13 11:32:57 +010064int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val);
Leonard Crestezd026d702017-07-26 11:34:46 +020065int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010066
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +010067/* direct nvmem device read/write interface */
68struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
69struct nvmem_device *devm_nvmem_device_get(struct device *dev,
70 const char *name);
71void nvmem_device_put(struct nvmem_device *nvmem);
72void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
73int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
74 size_t bytes, void *buf);
75int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
76 size_t bytes, void *buf);
77ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
78 struct nvmem_cell_info *info, void *buf);
79int nvmem_device_cell_write(struct nvmem_device *nvmem,
80 struct nvmem_cell_info *info, void *buf);
81
Bartosz Golaszewskid7b9fd12018-09-21 06:40:03 -070082const char *nvmem_dev_name(struct nvmem_device *nvmem);
83
Bartosz Golaszewski506157b2018-09-21 06:40:17 -070084void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries,
85 size_t nentries);
86void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries,
87 size_t nentries);
88
Bartosz Golaszewskibee11382018-09-21 06:40:19 -070089int nvmem_register_notifier(struct notifier_block *nb);
90int nvmem_unregister_notifier(struct notifier_block *nb);
91
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010092#else
93
94static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
Bartosz Golaszewski165589f2018-09-21 06:40:21 -070095 const char *id)
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010096{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -070097 return ERR_PTR(-EOPNOTSUPP);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +010098}
99
100static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
Bartosz Golaszewski165589f2018-09-21 06:40:21 -0700101 const char *id)
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100102{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700103 return ERR_PTR(-EOPNOTSUPP);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100104}
105
106static inline void devm_nvmem_cell_put(struct device *dev,
107 struct nvmem_cell *cell)
108{
109
110}
111static inline void nvmem_cell_put(struct nvmem_cell *cell)
112{
113}
114
Guenter Roecka6c50912016-06-02 12:05:12 +0100115static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100116{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700117 return ERR_PTR(-EOPNOTSUPP);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100118}
119
120static inline int nvmem_cell_write(struct nvmem_cell *cell,
121 const char *buf, size_t len)
122{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700123 return -EOPNOTSUPP;
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100124}
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100125
Fabrice Gasnier0a9b2d12019-04-13 11:32:57 +0100126static inline int nvmem_cell_read_u16(struct device *dev,
127 const char *cell_id, u16 *val)
128{
129 return -EOPNOTSUPP;
130}
131
Leonard Crestezd026d702017-07-26 11:34:46 +0200132static inline int nvmem_cell_read_u32(struct device *dev,
133 const char *cell_id, u32 *val)
134{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700135 return -EOPNOTSUPP;
Leonard Crestezd026d702017-07-26 11:34:46 +0200136}
137
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100138static inline struct nvmem_device *nvmem_device_get(struct device *dev,
139 const char *name)
140{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700141 return ERR_PTR(-EOPNOTSUPP);
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100142}
143
144static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
145 const char *name)
146{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700147 return ERR_PTR(-EOPNOTSUPP);
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100148}
149
150static inline void nvmem_device_put(struct nvmem_device *nvmem)
151{
152}
153
154static inline void devm_nvmem_device_put(struct device *dev,
155 struct nvmem_device *nvmem)
156{
157}
158
159static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
160 struct nvmem_cell_info *info,
161 void *buf)
162{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700163 return -EOPNOTSUPP;
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100164}
165
166static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
167 struct nvmem_cell_info *info,
168 void *buf)
169{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700170 return -EOPNOTSUPP;
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100171}
172
173static inline int nvmem_device_read(struct nvmem_device *nvmem,
174 unsigned int offset, size_t bytes,
175 void *buf)
176{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700177 return -EOPNOTSUPP;
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100178}
179
180static inline int nvmem_device_write(struct nvmem_device *nvmem,
181 unsigned int offset, size_t bytes,
182 void *buf)
183{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700184 return -EOPNOTSUPP;
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100185}
Bartosz Golaszewskid7b9fd12018-09-21 06:40:03 -0700186
187static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
188{
189 return NULL;
190}
191
Bartosz Golaszewski506157b2018-09-21 06:40:17 -0700192static inline void
193nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
194static inline void
195nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
196
Bartosz Golaszewskibee11382018-09-21 06:40:19 -0700197static inline int nvmem_register_notifier(struct notifier_block *nb)
198{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700199 return -EOPNOTSUPP;
Bartosz Golaszewskibee11382018-09-21 06:40:19 -0700200}
201
202static inline int nvmem_unregister_notifier(struct notifier_block *nb)
203{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700204 return -EOPNOTSUPP;
Bartosz Golaszewskibee11382018-09-21 06:40:19 -0700205}
206
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100207#endif /* CONFIG_NVMEM */
208
209#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
210struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
Bartosz Golaszewski165589f2018-09-21 06:40:21 -0700211 const char *id);
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100212struct nvmem_device *of_nvmem_device_get(struct device_node *np,
213 const char *name);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100214#else
215static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
Bartosz Golaszewski165589f2018-09-21 06:40:21 -0700216 const char *id)
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100217{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700218 return ERR_PTR(-EOPNOTSUPP);
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100219}
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100220
221static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
222 const char *name)
223{
Bartosz Golaszewski20167b72018-09-21 06:40:22 -0700224 return ERR_PTR(-EOPNOTSUPP);
Srinivas Kandagatlae2a54022015-07-27 12:13:45 +0100225}
Srinivas Kandagatla69aba792015-07-27 12:13:34 +0100226#endif /* CONFIG_NVMEM && CONFIG_OF */
227
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +0100228#endif /* ifndef _LINUX_NVMEM_CONSUMER_H */