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
40struct nvmem_keepout {
41 unsigned int start;
42 unsigned int end;
43 unsigned char value;
44};
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76struct nvmem_config {
77 struct device *dev;
78 const char *name;
79 int id;
80 struct module *owner;
81 struct gpio_desc *wp_gpio;
82 const struct nvmem_cell_info *cells;
83 int ncells;
84 const struct nvmem_keepout *keepout;
85 unsigned int nkeepout;
86 enum nvmem_type type;
87 bool read_only;
88 bool root_only;
89 bool no_of_node;
90 nvmem_reg_read_t reg_read;
91 nvmem_reg_write_t reg_write;
92 int size;
93 int word_size;
94 int stride;
95 void *priv;
96
97 bool compat;
98 struct device *base_dev;
99};
100
101
102
103
104
105
106
107
108
109
110
111
112
113struct nvmem_cell_table {
114 const char *nvmem_name;
115 const struct nvmem_cell_info *cells;
116 size_t ncells;
117 struct list_head node;
118};
119
120#if IS_ENABLED(CONFIG_NVMEM)
121
122struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
123void nvmem_unregister(struct nvmem_device *nvmem);
124
125struct nvmem_device *devm_nvmem_register(struct device *dev,
126 const struct nvmem_config *cfg);
127
128int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
129
130void nvmem_add_cell_table(struct nvmem_cell_table *table);
131void nvmem_del_cell_table(struct nvmem_cell_table *table);
132
133#else
134
135static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
136{
137 return ERR_PTR(-EOPNOTSUPP);
138}
139
140static inline void nvmem_unregister(struct nvmem_device *nvmem) {}
141
142static inline struct nvmem_device *
143devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
144{
145 return nvmem_register(c);
146}
147
148static inline int
149devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
150{
151 return -EOPNOTSUPP;
152}
153
154static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
155static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
156
157#endif
158#endif
159