xref: /linux/drivers/nvmem/internals.h (revision 1b78070aaef63512688aebfbc82365ef9d6660f1)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef _LINUX_NVMEM_INTERNALS_H
4 #define _LINUX_NVMEM_INTERNALS_H
5 
6 #include <linux/device.h>
7 #include <linux/nvmem-consumer.h>
8 #include <linux/nvmem-provider.h>
9 
10 /* Hold pointers to callbacks owned by the nvmem provider module. */
11 struct nvmem_operations {
12 	nvmem_reg_read_t	reg_read;
13 	nvmem_reg_write_t	reg_write;
14 };
15 
16 struct nvmem_device {
17 	struct module		*owner;
18 	struct device		dev;
19 	int			stride;
20 	int			word_size;
21 	int			id;
22 	struct kref		refcnt;
23 	size_t			size;
24 	bool			read_only;
25 	bool			root_only;
26 	int			flags;
27 	enum nvmem_type		type;
28 	struct bin_attribute	eeprom;
29 	struct device		*base_dev;
30 	struct list_head	cells;
31 	void (*fixup_dt_cell_info)(struct nvmem_device *nvmem,
32 				   struct nvmem_cell_info *cell);
33 	const struct nvmem_keepout *keepout;
34 	unsigned int		nkeepout;
35 	struct gpio_desc	*wp_gpio;
36 	struct nvmem_layout	*layout;
37 	struct nvmem_operations	*ops;
38 	void *priv;
39 	bool			sysfs_cells_populated;
40 };
41 
42 int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np);
43 
44 #if IS_ENABLED(CONFIG_OF)
45 int nvmem_layout_bus_register(void);
46 void nvmem_layout_bus_unregister(void);
47 int nvmem_populate_layout(struct nvmem_device *nvmem);
48 void nvmem_destroy_layout(struct nvmem_device *nvmem);
49 #else /* CONFIG_OF */
50 static inline int nvmem_layout_bus_register(void)
51 {
52 	return 0;
53 }
54 
55 static inline void nvmem_layout_bus_unregister(void) {}
56 
57 static inline int nvmem_populate_layout(struct nvmem_device *nvmem)
58 {
59 	return 0;
60 }
61 
62 static inline void nvmem_destroy_layout(struct nvmem_device *nvmem) { }
63 #endif /* CONFIG_OF */
64 
65 #endif  /* ifndef _LINUX_NVMEM_INTERNALS_H */
66