]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/nvmem-provider.h
mm: memcontrol: convert NR_ANON_THPS account to pages
[mirror_ubuntu-jammy-kernel.git] / include / linux / nvmem-provider.h
CommitLineData
b1c1db98 1/* SPDX-License-Identifier: GPL-2.0 */
eace75cf
SK
2/*
3 * nvmem framework provider.
4 *
5 * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
6 * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com>
eace75cf
SK
7 */
8
9#ifndef _LINUX_NVMEM_PROVIDER_H
10#define _LINUX_NVMEM_PROVIDER_H
11
42a6e099
AB
12#include <linux/err.h>
13#include <linux/errno.h>
2a127da4 14#include <linux/gpio/consumer.h>
42a6e099 15
eace75cf
SK
16struct nvmem_device;
17struct nvmem_cell_info;
795ddd18
SK
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);
eace75cf 22
16688453
AB
23enum nvmem_type {
24 NVMEM_TYPE_UNKNOWN = 0,
25 NVMEM_TYPE_EEPROM,
26 NVMEM_TYPE_OTP,
27 NVMEM_TYPE_BATTERY_BACKED,
28};
29
731aa3fa
SK
30#define NVMEM_DEVID_NONE (-1)
31#define NVMEM_DEVID_AUTO (-2)
32
fd3bb8f5
EG
33/**
34 * struct nvmem_keepout - NVMEM register keepout range.
35 *
36 * @start: The first byte offset to avoid.
37 * @end: One beyond the last byte offset to avoid.
38 * @value: The byte to fill reads with for this region.
39 */
40struct nvmem_keepout {
41 unsigned int start;
42 unsigned int end;
43 unsigned char value;
44};
45
0b2ed745
AS
46/**
47 * struct nvmem_config - NVMEM device configuration
48 *
49 * @dev: Parent device.
50 * @name: Optional name.
51 * @id: Optional device ID used in full name. Ignored if name is NULL.
52 * @owner: Pointer to exporter module. Used for refcounting.
53 * @cells: Optional array of pre-defined NVMEM cells.
54 * @ncells: Number of elements in cells.
fd3bb8f5
EG
55 * @keepout: Optional array of keepout ranges (sorted ascending by start).
56 * @nkeepout: Number of elements in the keepout array.
16688453 57 * @type: Type of the nvmem storage
0b2ed745
AS
58 * @read_only: Device is read-only.
59 * @root_only: Device is accessibly to root only.
517f14d9 60 * @no_of_node: Device should not use the parent's of_node even if it's !NULL.
0b2ed745
AS
61 * @reg_read: Callback to read data.
62 * @reg_write: Callback to write data.
63 * @size: Device size.
64 * @word_size: Minimum read/write access granularity.
65 * @stride: Minimum read/write access stride.
66 * @priv: User context passed to read/write callbacks.
2a127da4 67 * @wp-gpio: Write protect pin
0b2ed745
AS
68 *
69 * Note: A default "nvmem<id>" name will be assigned to the device if
70 * no name is specified in its configuration. In such case "<id>" is
71 * generated with ida_simple_get() and provided id field is ignored.
fd0f4906
AS
72 *
73 * Note: Specifying name and setting id to -1 implies a unique device
74 * whose name is provided as-is (kept unaltered).
0b2ed745 75 */
eace75cf
SK
76struct nvmem_config {
77 struct device *dev;
78 const char *name;
79 int id;
80 struct module *owner;
2a127da4 81 struct gpio_desc *wp_gpio;
eace75cf
SK
82 const struct nvmem_cell_info *cells;
83 int ncells;
fd3bb8f5
EG
84 const struct nvmem_keepout *keepout;
85 unsigned int nkeepout;
16688453 86 enum nvmem_type type;
eace75cf 87 bool read_only;
811b0d65 88 bool root_only;
517f14d9 89 bool no_of_node;
795ddd18
SK
90 nvmem_reg_read_t reg_read;
91 nvmem_reg_write_t reg_write;
92 int size;
93 int word_size;
94 int stride;
95 void *priv;
b6c217ab
AL
96 /* To be only used by old driver/misc/eeprom drivers */
97 bool compat;
98 struct device *base_dev;
eace75cf
SK
99};
100
b985f4cb
BG
101/**
102 * struct nvmem_cell_table - NVMEM cell definitions for given provider
103 *
104 * @nvmem_name: Provider name.
105 * @cells: Array of cell definitions.
106 * @ncells: Number of cell definitions in the array.
107 * @node: List node.
108 *
109 * This structure together with related helper functions is provided for users
110 * that don't can't access the nvmem provided structure but wish to register
111 * cell definitions for it e.g. board files registering an EEPROM device.
112 */
113struct nvmem_cell_table {
114 const char *nvmem_name;
115 const struct nvmem_cell_info *cells;
116 size_t ncells;
117 struct list_head node;
118};
119
eace75cf
SK
120#if IS_ENABLED(CONFIG_NVMEM)
121
122struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
bf58e882 123void nvmem_unregister(struct nvmem_device *nvmem);
eace75cf 124
f1f50eca
AS
125struct nvmem_device *devm_nvmem_register(struct device *dev,
126 const struct nvmem_config *cfg);
127
128int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
129
b985f4cb
BG
130void nvmem_add_cell_table(struct nvmem_cell_table *table);
131void nvmem_del_cell_table(struct nvmem_cell_table *table);
132
eace75cf
SK
133#else
134
135static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
136{
20167b70 137 return ERR_PTR(-EOPNOTSUPP);
eace75cf
SK
138}
139
bf58e882 140static inline void nvmem_unregister(struct nvmem_device *nvmem) {}
eace75cf 141
f1f50eca
AS
142static inline struct nvmem_device *
143devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
144{
145 return nvmem_register(c);
146}
147
148static inline int
149devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
150{
20167b70 151 return -EOPNOTSUPP;
b3db17e4
AL
152}
153
b985f4cb
BG
154static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
155static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
f1f50eca 156
eace75cf 157#endif /* CONFIG_NVMEM */
eace75cf 158#endif /* ifndef _LINUX_NVMEM_PROVIDER_H */