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>
16 struct nvmem_cell_info;
17 typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
18 void *val, size_t bytes);
19 typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
20 void *val, size_t bytes);
23 NVMEM_TYPE_UNKNOWN = 0,
26 NVMEM_TYPE_BATTERY_BACKED,
30 * struct nvmem_config - NVMEM device configuration
32 * @dev: Parent device.
33 * @name: Optional name.
34 * @id: Optional device ID used in full name. Ignored if name is NULL.
35 * @owner: Pointer to exporter module. Used for refcounting.
36 * @cells: Optional array of pre-defined NVMEM cells.
37 * @ncells: Number of elements in cells.
38 * @type: Type of the nvmem storage
39 * @read_only: Device is read-only.
40 * @root_only: Device is accessibly to root only.
41 * @no_of_node: Device should not use the parent's of_node even if it's !NULL.
42 * @reg_read: Callback to read data.
43 * @reg_write: Callback to write data.
45 * @word_size: Minimum read/write access granularity.
46 * @stride: Minimum read/write access stride.
47 * @priv: User context passed to read/write callbacks.
49 * Note: A default "nvmem<id>" name will be assigned to the device if
50 * no name is specified in its configuration. In such case "<id>" is
51 * generated with ida_simple_get() and provided id field is ignored.
53 * Note: Specifying name and setting id to -1 implies a unique device
54 * whose name is provided as-is (kept unaltered).
61 const struct nvmem_cell_info *cells;
67 nvmem_reg_read_t reg_read;
68 nvmem_reg_write_t reg_write;
73 /* To be only used by old driver/misc/eeprom drivers */
75 struct device *base_dev;
79 * struct nvmem_cell_table - NVMEM cell definitions for given provider
81 * @nvmem_name: Provider name.
82 * @cells: Array of cell definitions.
83 * @ncells: Number of cell definitions in the array.
86 * This structure together with related helper functions is provided for users
87 * that don't can't access the nvmem provided structure but wish to register
88 * cell definitions for it e.g. board files registering an EEPROM device.
90 struct nvmem_cell_table {
91 const char *nvmem_name;
92 const struct nvmem_cell_info *cells;
94 struct list_head node;
97 #if IS_ENABLED(CONFIG_NVMEM)
99 struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
100 void nvmem_unregister(struct nvmem_device *nvmem);
102 struct nvmem_device *devm_nvmem_register(struct device *dev,
103 const struct nvmem_config *cfg);
105 int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
107 void nvmem_add_cell_table(struct nvmem_cell_table *table);
108 void nvmem_del_cell_table(struct nvmem_cell_table *table);
112 static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
114 return ERR_PTR(-EOPNOTSUPP);
117 static inline void nvmem_unregister(struct nvmem_device *nvmem) {}
119 static inline struct nvmem_device *
120 devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
122 return nvmem_register(c);
126 devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
131 static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
132 static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
134 #endif /* CONFIG_NVMEM */
135 #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */