2 * nvmem framework consumer.
4 * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
5 * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com>
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.
12 #ifndef _LINUX_NVMEM_CONSUMER_H
13 #define _LINUX_NVMEM_CONSUMER_H
15 #include <linux/err.h>
16 #include <linux/errno.h>
24 struct nvmem_cell_info
{
28 unsigned int bit_offset
;
32 #if IS_ENABLED(CONFIG_NVMEM)
34 /* Cell based interface */
35 struct nvmem_cell
*nvmem_cell_get(struct device
*dev
, const char *name
);
36 struct nvmem_cell
*devm_nvmem_cell_get(struct device
*dev
, const char *name
);
37 void nvmem_cell_put(struct nvmem_cell
*cell
);
38 void devm_nvmem_cell_put(struct device
*dev
, struct nvmem_cell
*cell
);
39 void *nvmem_cell_read(struct nvmem_cell
*cell
, size_t *len
);
40 int nvmem_cell_write(struct nvmem_cell
*cell
, void *buf
, size_t len
);
41 int nvmem_cell_read_u32(struct device
*dev
, const char *cell_id
, u32
*val
);
43 /* direct nvmem device read/write interface */
44 struct nvmem_device
*nvmem_device_get(struct device
*dev
, const char *name
);
45 struct nvmem_device
*devm_nvmem_device_get(struct device
*dev
,
47 void nvmem_device_put(struct nvmem_device
*nvmem
);
48 void devm_nvmem_device_put(struct device
*dev
, struct nvmem_device
*nvmem
);
49 int nvmem_device_read(struct nvmem_device
*nvmem
, unsigned int offset
,
50 size_t bytes
, void *buf
);
51 int nvmem_device_write(struct nvmem_device
*nvmem
, unsigned int offset
,
52 size_t bytes
, void *buf
);
53 ssize_t
nvmem_device_cell_read(struct nvmem_device
*nvmem
,
54 struct nvmem_cell_info
*info
, void *buf
);
55 int nvmem_device_cell_write(struct nvmem_device
*nvmem
,
56 struct nvmem_cell_info
*info
, void *buf
);
60 static inline struct nvmem_cell
*nvmem_cell_get(struct device
*dev
,
63 return ERR_PTR(-ENOSYS
);
66 static inline struct nvmem_cell
*devm_nvmem_cell_get(struct device
*dev
,
69 return ERR_PTR(-ENOSYS
);
72 static inline void devm_nvmem_cell_put(struct device
*dev
,
73 struct nvmem_cell
*cell
)
77 static inline void nvmem_cell_put(struct nvmem_cell
*cell
)
81 static inline void *nvmem_cell_read(struct nvmem_cell
*cell
, size_t *len
)
83 return ERR_PTR(-ENOSYS
);
86 static inline int nvmem_cell_write(struct nvmem_cell
*cell
,
87 const char *buf
, size_t len
)
92 static inline int nvmem_cell_read_u32(struct device
*dev
,
93 const char *cell_id
, u32
*val
)
98 static inline struct nvmem_device
*nvmem_device_get(struct device
*dev
,
101 return ERR_PTR(-ENOSYS
);
104 static inline struct nvmem_device
*devm_nvmem_device_get(struct device
*dev
,
107 return ERR_PTR(-ENOSYS
);
110 static inline void nvmem_device_put(struct nvmem_device
*nvmem
)
114 static inline void devm_nvmem_device_put(struct device
*dev
,
115 struct nvmem_device
*nvmem
)
119 static inline ssize_t
nvmem_device_cell_read(struct nvmem_device
*nvmem
,
120 struct nvmem_cell_info
*info
,
126 static inline int nvmem_device_cell_write(struct nvmem_device
*nvmem
,
127 struct nvmem_cell_info
*info
,
133 static inline int nvmem_device_read(struct nvmem_device
*nvmem
,
134 unsigned int offset
, size_t bytes
,
140 static inline int nvmem_device_write(struct nvmem_device
*nvmem
,
141 unsigned int offset
, size_t bytes
,
146 #endif /* CONFIG_NVMEM */
148 #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
149 struct nvmem_cell
*of_nvmem_cell_get(struct device_node
*np
,
151 struct nvmem_device
*of_nvmem_device_get(struct device_node
*np
,
154 static inline struct nvmem_cell
*of_nvmem_cell_get(struct device_node
*np
,
157 return ERR_PTR(-ENOSYS
);
160 static inline struct nvmem_device
*of_nvmem_device_get(struct device_node
*np
,
163 return ERR_PTR(-ENOSYS
);
165 #endif /* CONFIG_NVMEM && CONFIG_OF */
167 #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */