0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LINUX_NVMEM_PROVIDER_H
0010 #define _LINUX_NVMEM_PROVIDER_H
0011
0012 #include <linux/err.h>
0013 #include <linux/errno.h>
0014 #include <linux/gpio/consumer.h>
0015
0016 struct nvmem_device;
0017 struct nvmem_cell_info;
0018 typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
0019 void *val, size_t bytes);
0020 typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
0021 void *val, size_t bytes);
0022
0023 typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, unsigned int offset,
0024 void *buf, size_t bytes);
0025
0026 enum nvmem_type {
0027 NVMEM_TYPE_UNKNOWN = 0,
0028 NVMEM_TYPE_EEPROM,
0029 NVMEM_TYPE_OTP,
0030 NVMEM_TYPE_BATTERY_BACKED,
0031 NVMEM_TYPE_FRAM,
0032 };
0033
0034 #define NVMEM_DEVID_NONE (-1)
0035 #define NVMEM_DEVID_AUTO (-2)
0036
0037
0038
0039
0040
0041
0042
0043
0044 struct nvmem_keepout {
0045 unsigned int start;
0046 unsigned int end;
0047 unsigned char value;
0048 };
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 struct nvmem_config {
0084 struct device *dev;
0085 const char *name;
0086 int id;
0087 struct module *owner;
0088 struct gpio_desc *wp_gpio;
0089 const struct nvmem_cell_info *cells;
0090 int ncells;
0091 const struct nvmem_keepout *keepout;
0092 unsigned int nkeepout;
0093 enum nvmem_type type;
0094 bool read_only;
0095 bool root_only;
0096 bool ignore_wp;
0097 struct device_node *of_node;
0098 bool no_of_node;
0099 nvmem_reg_read_t reg_read;
0100 nvmem_reg_write_t reg_write;
0101 nvmem_cell_post_process_t cell_post_process;
0102 int size;
0103 int word_size;
0104 int stride;
0105 void *priv;
0106
0107 bool compat;
0108 struct device *base_dev;
0109 };
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 struct nvmem_cell_table {
0124 const char *nvmem_name;
0125 const struct nvmem_cell_info *cells;
0126 size_t ncells;
0127 struct list_head node;
0128 };
0129
0130 #if IS_ENABLED(CONFIG_NVMEM)
0131
0132 struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
0133 void nvmem_unregister(struct nvmem_device *nvmem);
0134
0135 struct nvmem_device *devm_nvmem_register(struct device *dev,
0136 const struct nvmem_config *cfg);
0137
0138 void nvmem_add_cell_table(struct nvmem_cell_table *table);
0139 void nvmem_del_cell_table(struct nvmem_cell_table *table);
0140
0141 #else
0142
0143 static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
0144 {
0145 return ERR_PTR(-EOPNOTSUPP);
0146 }
0147
0148 static inline void nvmem_unregister(struct nvmem_device *nvmem) {}
0149
0150 static inline struct nvmem_device *
0151 devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
0152 {
0153 return nvmem_register(c);
0154 }
0155
0156 static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
0157 static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
0158
0159 #endif
0160 #endif