1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * nvmem framework consumer.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
6*4882a593Smuzhiyun * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com>
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #ifndef _LINUX_NVMEM_CONSUMER_H
10*4882a593Smuzhiyun #define _LINUX_NVMEM_CONSUMER_H
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun #include <linux/err.h>
13*4882a593Smuzhiyun #include <linux/errno.h>
14*4882a593Smuzhiyun #include <linux/notifier.h>
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun struct device;
17*4882a593Smuzhiyun struct device_node;
18*4882a593Smuzhiyun /* consumer cookie */
19*4882a593Smuzhiyun struct nvmem_cell;
20*4882a593Smuzhiyun struct nvmem_device;
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun struct nvmem_cell_info {
23*4882a593Smuzhiyun const char *name;
24*4882a593Smuzhiyun unsigned int offset;
25*4882a593Smuzhiyun unsigned int bytes;
26*4882a593Smuzhiyun unsigned int bit_offset;
27*4882a593Smuzhiyun unsigned int nbits;
28*4882a593Smuzhiyun };
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun /**
31*4882a593Smuzhiyun * struct nvmem_cell_lookup - cell lookup entry
32*4882a593Smuzhiyun *
33*4882a593Smuzhiyun * @nvmem_name: Name of the provider.
34*4882a593Smuzhiyun * @cell_name: Name of the nvmem cell as defined in the name field of
35*4882a593Smuzhiyun * struct nvmem_cell_info.
36*4882a593Smuzhiyun * @dev_id: Name of the consumer device that will be associated with
37*4882a593Smuzhiyun * this cell.
38*4882a593Smuzhiyun * @con_id: Connector id for this cell lookup.
39*4882a593Smuzhiyun */
40*4882a593Smuzhiyun struct nvmem_cell_lookup {
41*4882a593Smuzhiyun const char *nvmem_name;
42*4882a593Smuzhiyun const char *cell_name;
43*4882a593Smuzhiyun const char *dev_id;
44*4882a593Smuzhiyun const char *con_id;
45*4882a593Smuzhiyun struct list_head node;
46*4882a593Smuzhiyun };
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun enum {
49*4882a593Smuzhiyun NVMEM_ADD = 1,
50*4882a593Smuzhiyun NVMEM_REMOVE,
51*4882a593Smuzhiyun NVMEM_CELL_ADD,
52*4882a593Smuzhiyun NVMEM_CELL_REMOVE,
53*4882a593Smuzhiyun };
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_NVMEM)
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun /* Cell based interface */
58*4882a593Smuzhiyun struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id);
59*4882a593Smuzhiyun struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id);
60*4882a593Smuzhiyun void nvmem_cell_put(struct nvmem_cell *cell);
61*4882a593Smuzhiyun void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
62*4882a593Smuzhiyun void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
63*4882a593Smuzhiyun int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
64*4882a593Smuzhiyun int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val);
65*4882a593Smuzhiyun int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val);
66*4882a593Smuzhiyun int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
67*4882a593Smuzhiyun int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val);
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun /* direct nvmem device read/write interface */
70*4882a593Smuzhiyun struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
71*4882a593Smuzhiyun struct nvmem_device *devm_nvmem_device_get(struct device *dev,
72*4882a593Smuzhiyun const char *name);
73*4882a593Smuzhiyun void nvmem_device_put(struct nvmem_device *nvmem);
74*4882a593Smuzhiyun void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
75*4882a593Smuzhiyun int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
76*4882a593Smuzhiyun size_t bytes, void *buf);
77*4882a593Smuzhiyun int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
78*4882a593Smuzhiyun size_t bytes, void *buf);
79*4882a593Smuzhiyun ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
80*4882a593Smuzhiyun struct nvmem_cell_info *info, void *buf);
81*4882a593Smuzhiyun int nvmem_device_cell_write(struct nvmem_device *nvmem,
82*4882a593Smuzhiyun struct nvmem_cell_info *info, void *buf);
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun const char *nvmem_dev_name(struct nvmem_device *nvmem);
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries,
87*4882a593Smuzhiyun size_t nentries);
88*4882a593Smuzhiyun void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries,
89*4882a593Smuzhiyun size_t nentries);
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun int nvmem_register_notifier(struct notifier_block *nb);
92*4882a593Smuzhiyun int nvmem_unregister_notifier(struct notifier_block *nb);
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun struct nvmem_device *nvmem_device_find(void *data,
95*4882a593Smuzhiyun int (*match)(struct device *dev, const void *data));
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun #else
98*4882a593Smuzhiyun
nvmem_cell_get(struct device * dev,const char * id)99*4882a593Smuzhiyun static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
100*4882a593Smuzhiyun const char *id)
101*4882a593Smuzhiyun {
102*4882a593Smuzhiyun return ERR_PTR(-EOPNOTSUPP);
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun
devm_nvmem_cell_get(struct device * dev,const char * id)105*4882a593Smuzhiyun static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
106*4882a593Smuzhiyun const char *id)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun return ERR_PTR(-EOPNOTSUPP);
109*4882a593Smuzhiyun }
110*4882a593Smuzhiyun
devm_nvmem_cell_put(struct device * dev,struct nvmem_cell * cell)111*4882a593Smuzhiyun static inline void devm_nvmem_cell_put(struct device *dev,
112*4882a593Smuzhiyun struct nvmem_cell *cell)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun }
nvmem_cell_put(struct nvmem_cell * cell)116*4882a593Smuzhiyun static inline void nvmem_cell_put(struct nvmem_cell *cell)
117*4882a593Smuzhiyun {
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun
nvmem_cell_read(struct nvmem_cell * cell,size_t * len)120*4882a593Smuzhiyun static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
121*4882a593Smuzhiyun {
122*4882a593Smuzhiyun return ERR_PTR(-EOPNOTSUPP);
123*4882a593Smuzhiyun }
124*4882a593Smuzhiyun
nvmem_cell_write(struct nvmem_cell * cell,void * buf,size_t len)125*4882a593Smuzhiyun static inline int nvmem_cell_write(struct nvmem_cell *cell,
126*4882a593Smuzhiyun void *buf, size_t len)
127*4882a593Smuzhiyun {
128*4882a593Smuzhiyun return -EOPNOTSUPP;
129*4882a593Smuzhiyun }
130*4882a593Smuzhiyun
nvmem_cell_read_u16(struct device * dev,const char * cell_id,u16 * val)131*4882a593Smuzhiyun static inline int nvmem_cell_read_u16(struct device *dev,
132*4882a593Smuzhiyun const char *cell_id, u16 *val)
133*4882a593Smuzhiyun {
134*4882a593Smuzhiyun return -EOPNOTSUPP;
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun
nvmem_cell_read_u32(struct device * dev,const char * cell_id,u32 * val)137*4882a593Smuzhiyun static inline int nvmem_cell_read_u32(struct device *dev,
138*4882a593Smuzhiyun const char *cell_id, u32 *val)
139*4882a593Smuzhiyun {
140*4882a593Smuzhiyun return -EOPNOTSUPP;
141*4882a593Smuzhiyun }
142*4882a593Smuzhiyun
nvmem_cell_read_u64(struct device * dev,const char * cell_id,u64 * val)143*4882a593Smuzhiyun static inline int nvmem_cell_read_u64(struct device *dev,
144*4882a593Smuzhiyun const char *cell_id, u64 *val)
145*4882a593Smuzhiyun {
146*4882a593Smuzhiyun return -EOPNOTSUPP;
147*4882a593Smuzhiyun }
148*4882a593Smuzhiyun
nvmem_device_get(struct device * dev,const char * name)149*4882a593Smuzhiyun static inline struct nvmem_device *nvmem_device_get(struct device *dev,
150*4882a593Smuzhiyun const char *name)
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun return ERR_PTR(-EOPNOTSUPP);
153*4882a593Smuzhiyun }
154*4882a593Smuzhiyun
devm_nvmem_device_get(struct device * dev,const char * name)155*4882a593Smuzhiyun static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
156*4882a593Smuzhiyun const char *name)
157*4882a593Smuzhiyun {
158*4882a593Smuzhiyun return ERR_PTR(-EOPNOTSUPP);
159*4882a593Smuzhiyun }
160*4882a593Smuzhiyun
nvmem_device_put(struct nvmem_device * nvmem)161*4882a593Smuzhiyun static inline void nvmem_device_put(struct nvmem_device *nvmem)
162*4882a593Smuzhiyun {
163*4882a593Smuzhiyun }
164*4882a593Smuzhiyun
devm_nvmem_device_put(struct device * dev,struct nvmem_device * nvmem)165*4882a593Smuzhiyun static inline void devm_nvmem_device_put(struct device *dev,
166*4882a593Smuzhiyun struct nvmem_device *nvmem)
167*4882a593Smuzhiyun {
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun
nvmem_device_cell_read(struct nvmem_device * nvmem,struct nvmem_cell_info * info,void * buf)170*4882a593Smuzhiyun static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
171*4882a593Smuzhiyun struct nvmem_cell_info *info,
172*4882a593Smuzhiyun void *buf)
173*4882a593Smuzhiyun {
174*4882a593Smuzhiyun return -EOPNOTSUPP;
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun
nvmem_device_cell_write(struct nvmem_device * nvmem,struct nvmem_cell_info * info,void * buf)177*4882a593Smuzhiyun static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
178*4882a593Smuzhiyun struct nvmem_cell_info *info,
179*4882a593Smuzhiyun void *buf)
180*4882a593Smuzhiyun {
181*4882a593Smuzhiyun return -EOPNOTSUPP;
182*4882a593Smuzhiyun }
183*4882a593Smuzhiyun
nvmem_device_read(struct nvmem_device * nvmem,unsigned int offset,size_t bytes,void * buf)184*4882a593Smuzhiyun static inline int nvmem_device_read(struct nvmem_device *nvmem,
185*4882a593Smuzhiyun unsigned int offset, size_t bytes,
186*4882a593Smuzhiyun void *buf)
187*4882a593Smuzhiyun {
188*4882a593Smuzhiyun return -EOPNOTSUPP;
189*4882a593Smuzhiyun }
190*4882a593Smuzhiyun
nvmem_device_write(struct nvmem_device * nvmem,unsigned int offset,size_t bytes,void * buf)191*4882a593Smuzhiyun static inline int nvmem_device_write(struct nvmem_device *nvmem,
192*4882a593Smuzhiyun unsigned int offset, size_t bytes,
193*4882a593Smuzhiyun void *buf)
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun return -EOPNOTSUPP;
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun
nvmem_dev_name(struct nvmem_device * nvmem)198*4882a593Smuzhiyun static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
199*4882a593Smuzhiyun {
200*4882a593Smuzhiyun return NULL;
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun static inline void
nvmem_add_cell_lookups(struct nvmem_cell_lookup * entries,size_t nentries)204*4882a593Smuzhiyun nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
205*4882a593Smuzhiyun static inline void
nvmem_del_cell_lookups(struct nvmem_cell_lookup * entries,size_t nentries)206*4882a593Smuzhiyun nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
207*4882a593Smuzhiyun
nvmem_register_notifier(struct notifier_block * nb)208*4882a593Smuzhiyun static inline int nvmem_register_notifier(struct notifier_block *nb)
209*4882a593Smuzhiyun {
210*4882a593Smuzhiyun return -EOPNOTSUPP;
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun
nvmem_unregister_notifier(struct notifier_block * nb)213*4882a593Smuzhiyun static inline int nvmem_unregister_notifier(struct notifier_block *nb)
214*4882a593Smuzhiyun {
215*4882a593Smuzhiyun return -EOPNOTSUPP;
216*4882a593Smuzhiyun }
217*4882a593Smuzhiyun
nvmem_device_find(void * data,int (* match)(struct device * dev,const void * data))218*4882a593Smuzhiyun static inline struct nvmem_device *nvmem_device_find(void *data,
219*4882a593Smuzhiyun int (*match)(struct device *dev, const void *data))
220*4882a593Smuzhiyun {
221*4882a593Smuzhiyun return NULL;
222*4882a593Smuzhiyun }
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun #endif /* CONFIG_NVMEM */
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
227*4882a593Smuzhiyun struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
228*4882a593Smuzhiyun const char *id);
229*4882a593Smuzhiyun struct nvmem_device *of_nvmem_device_get(struct device_node *np,
230*4882a593Smuzhiyun const char *name);
231*4882a593Smuzhiyun #else
of_nvmem_cell_get(struct device_node * np,const char * id)232*4882a593Smuzhiyun static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
233*4882a593Smuzhiyun const char *id)
234*4882a593Smuzhiyun {
235*4882a593Smuzhiyun return ERR_PTR(-EOPNOTSUPP);
236*4882a593Smuzhiyun }
237*4882a593Smuzhiyun
of_nvmem_device_get(struct device_node * np,const char * name)238*4882a593Smuzhiyun static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
239*4882a593Smuzhiyun const char *name)
240*4882a593Smuzhiyun {
241*4882a593Smuzhiyun return ERR_PTR(-EOPNOTSUPP);
242*4882a593Smuzhiyun }
243*4882a593Smuzhiyun #endif /* CONFIG_NVMEM && CONFIG_OF */
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */
246