1 /* SPDX-License-Identifier: GPL-2.0 */
3 * nvmem framework provider.
9 #ifndef _LINUX_NVMEM_PROVIDER_H
10 #define _LINUX_NVMEM_PROVIDER_H
12 #include <linux/err.h>
13 #include <linux/errno.h>
14 #include <linux/gpio/consumer.h>
17 struct nvmem_cell_info;
18 typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
19 void *val, size_t bytes);
20 typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
21 void *val, size_t bytes);
24 NVMEM_TYPE_UNKNOWN = 0,
27 NVMEM_TYPE_BATTERY_BACKED,
30 #define NVMEM_DEVID_NONE (-1)
31 #define NVMEM_DEVID_AUTO (-2)
34 * struct nvmem_config - NVMEM device configuration
36 * @dev: Parent device.
37 * @name: Optional name.
38 * @id: Optional device ID used in full name. Ignored if name is NULL.
39 * @owner: Pointer to exporter module. Used for refcounting.
40 * @cells: Optional array of pre-defined NVMEM cells.
41 * @ncells: Number of elements in cells.
42 * @type: Type of the nvmem storage
43 * @read_only: Device is read-only.
44 * @root_only: Device is accessibly to root only.
45 * @no_of_node: Device should not use the parent's of_node even if it's !NULL.
46 * @reg_read: Callback to read data.
47 * @reg_write: Callback to write data.
49 * @word_size: Minimum read/write access granularity.
50 * @stride: Minimum read/write access stride.
51 * @priv: User context passed to read/write callbacks.
52 * @wp-gpio: Write protect pin
54 * Note: A default "nvmem<id>" name will be assigned to the device if
55 * no name is specified in its configuration. In such case "<id>" is
56 * generated with ida_simple_get() and provided id field is ignored.
58 * Note: Specifying name and setting id to -1 implies a unique device
59 * whose name is provided as-is (kept unaltered).
66 struct gpio_desc *wp_gpio;
67 const struct nvmem_cell_info *cells;
73 nvmem_reg_read_t reg_read;
74 nvmem_reg_write_t reg_write;
79 /* To be only used by old driver/misc/eeprom drivers */
81 struct device *base_dev;
85 * struct nvmem_cell_table - NVMEM cell definitions for given provider
87 * @nvmem_name: Provider name.
88 * @cells: Array of cell definitions.
89 * @ncells: Number of cell definitions in the array.
92 * This structure together with related helper functions is provided for users
93 * that don't can't access the nvmem provided structure but wish to register
94 * cell definitions for it e.g. board files registering an EEPROM device.
96 struct nvmem_cell_table {
97 const char *nvmem_name;
98 const struct nvmem_cell_info *cells;
100 struct list_head node;
103 #if IS_ENABLED(CONFIG_NVMEM)
105 struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
106 void nvmem_unregister(struct nvmem_device *nvmem);
108 struct nvmem_device *devm_nvmem_register(struct device *dev,
109 const struct nvmem_config *cfg);
111 int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
113 void nvmem_add_cell_table(struct nvmem_cell_table *table);
114 void nvmem_del_cell_table(struct nvmem_cell_table *table);
118 static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
120 return ERR_PTR(-EOPNOTSUPP);
123 static inline void nvmem_unregister(struct nvmem_device *nvmem) {}
125 static inline struct nvmem_device *
126 devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
128 return nvmem_register(c);
132 devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
137 static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
138 static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
140 #endif /* CONFIG_NVMEM */
141 #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */