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
31
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
58struct nvmem_config {
59 struct device *dev;
60 const char *name;
61 int id;
62 struct module *owner;
63 struct gpio_desc *wp_gpio;
64 const struct nvmem_cell_info *cells;
65 int ncells;
66 enum nvmem_type type;
67 bool read_only;
68 bool root_only;
69 bool no_of_node;
70 nvmem_reg_read_t reg_read;
71 nvmem_reg_write_t reg_write;
72 int size;
73 int word_size;
74 int stride;
75 void *priv;
76
77 bool compat;
78 struct device *base_dev;
79};
80
81
82
83
84
85
86
87
88
89
90
91
92
93struct nvmem_cell_table {
94 const char *nvmem_name;
95 const struct nvmem_cell_info *cells;
96 size_t ncells;
97 struct list_head node;
98};
99
100#if IS_ENABLED(CONFIG_NVMEM)
101
102struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
103void nvmem_unregister(struct nvmem_device *nvmem);
104
105struct nvmem_device *devm_nvmem_register(struct device *dev,
106 const struct nvmem_config *cfg);
107
108int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
109
110void nvmem_add_cell_table(struct nvmem_cell_table *table);
111void nvmem_del_cell_table(struct nvmem_cell_table *table);
112
113#else
114
115static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
116{
117 return ERR_PTR(-EOPNOTSUPP);
118}
119
120static inline void nvmem_unregister(struct nvmem_device *nvmem) {}
121
122static inline struct nvmem_device *
123devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
124{
125 return nvmem_register(c);
126}
127
128static inline int
129devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
130{
131 return -EOPNOTSUPP;
132}
133
134static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
135static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
136
137#endif
138#endif
139