1
2
3
4
5
6
7
8
9#ifndef _LINUX_NVMEM_PROVIDER_H
10#define _LINUX_NVMEM_PROVIDER_H
11
12#include <linux/err.h>
13#include <linux/errno.h>
14#include <linux/gpio/consumer.h>
15
16struct nvmem_device;
17struct nvmem_cell_info;
18typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
19 void *val, size_t bytes);
20typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
21 void *val, size_t bytes);
22
23enum nvmem_type {
24 NVMEM_TYPE_UNKNOWN = 0,
25 NVMEM_TYPE_EEPROM,
26 NVMEM_TYPE_OTP,
27 NVMEM_TYPE_BATTERY_BACKED,
28};
29
30#define NVMEM_DEVID_NONE (-1)
31#define NVMEM_DEVID_AUTO (-2)
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61struct nvmem_config {
62 struct device *dev;
63 const char *name;
64 int id;
65 struct module *owner;
66 struct gpio_desc *wp_gpio;
67 const struct nvmem_cell_info *cells;
68 int ncells;
69 enum nvmem_type type;
70 bool read_only;
71 bool root_only;
72 bool no_of_node;
73 nvmem_reg_read_t reg_read;
74 nvmem_reg_write_t reg_write;
75 int size;
76 int word_size;
77 int stride;
78 void *priv;
79
80 bool compat;
81 struct device *base_dev;
82};
83
84
85
86
87
88
89
90
91
92
93
94
95
96struct nvmem_cell_table {
97 const char *nvmem_name;
98 const struct nvmem_cell_info *cells;
99 size_t ncells;
100 struct list_head node;
101};
102
103#if IS_ENABLED(CONFIG_NVMEM)
104
105struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
106void nvmem_unregister(struct nvmem_device *nvmem);
107
108struct nvmem_device *devm_nvmem_register(struct device *dev,
109 const struct nvmem_config *cfg);
110
111int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
112
113void nvmem_add_cell_table(struct nvmem_cell_table *table);
114void nvmem_del_cell_table(struct nvmem_cell_table *table);
115
116#else
117
118static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
119{
120 return ERR_PTR(-EOPNOTSUPP);
121}
122
123static inline void nvmem_unregister(struct nvmem_device *nvmem) {}
124
125static inline struct nvmem_device *
126devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
127{
128 return nvmem_register(c);
129}
130
131static inline int
132devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
133{
134 return -EOPNOTSUPP;
135}
136
137static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
138static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
139
140#endif
141#endif
142