1 /* SPDX-License-Identifier: GPL-2.0+ */
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
10 * This uclass encapsulates hardware methods to gather information about a
11 * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders,
12 * read-only data in flash ICs, or similar.
14 * The interface offers functions to read the usual standard data types (bool,
15 * int, string) from the device, each of which is identified by a static
16 * numeric ID (which will usually be defined as a enum in a header file).
18 * If for example the sysinfo had a read-only serial number flash IC, we could
21 * ret = sysinfo_detect(dev);
23 * debug("sysinfo device not found.");
27 * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial);
29 * debug("Error when reading serial number from device.");
33 * to read the serial number.
36 #if CONFIG_IS_ENABLED(SYSINFO)
39 * detect() - Run the hardware info detection procedure for this
41 * @dev: The device containing the information
43 * This operation might take a long time (e.g. read from EEPROM,
44 * check the presence of a device on a bus etc.), hence this is not
45 * done in the probe() method, but later during operation in this
48 * Return: 0 if OK, -ve on error.
50 int (*detect)(struct udevice *dev);
53 * get_bool() - Read a specific bool data value that describes the
55 * @dev: The sysinfo instance to gather the data.
56 * @id: A unique identifier for the bool value to be read.
57 * @val: Pointer to a buffer that receives the value read.
59 * Return: 0 if OK, -ve on error.
61 int (*get_bool)(struct udevice *dev, int id, bool *val);
64 * get_int() - Read a specific int data value that describes the
66 * @dev: The sysinfo instance to gather the data.
67 * @id: A unique identifier for the int value to be read.
68 * @val: Pointer to a buffer that receives the value read.
70 * Return: 0 if OK, -ve on error.
72 int (*get_int)(struct udevice *dev, int id, int *val);
75 * get_str() - Read a specific string data value that describes the
77 * @dev: The sysinfo instance to gather the data.
78 * @id: A unique identifier for the string value to be read.
79 * @size: The size of the buffer to receive the string data.
80 * @val: Pointer to a buffer that receives the value read.
82 * Return: 0 if OK, -ve on error.
84 int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
87 * get_fit_loadable - Get the name of an image to load from FIT
88 * This function can be used to provide the image names based on runtime
89 * detection. A classic use-case would when DTBOs are used to describe
90 * additionnal daughter cards.
92 * @dev: The sysinfo instance to gather the data.
93 * @index: Index of the image. Starts at 0 and gets incremented
94 * after each call to this function.
95 * @type: The type of image. For example, "fdt" for DTBs
96 * @strp: A pointer to string. Untouched if the function fails
98 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
101 int (*get_fit_loadable)(struct udevice *dev, int index,
102 const char *type, const char **strp);
105 #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
108 * sysinfo_detect() - Run the hardware info detection procedure for this device.
110 * @dev: The device containing the information
112 * Return: 0 if OK, -ve on error.
114 int sysinfo_detect(struct udevice *dev);
117 * sysinfo_get_bool() - Read a specific bool data value that describes the
119 * @dev: The sysinfo instance to gather the data.
120 * @id: A unique identifier for the bool value to be read.
121 * @val: Pointer to a buffer that receives the value read.
123 * Return: 0 if OK, -ve on error.
125 int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
128 * sysinfo_get_int() - Read a specific int data value that describes the
130 * @dev: The sysinfo instance to gather the data.
131 * @id: A unique identifier for the int value to be read.
132 * @val: Pointer to a buffer that receives the value read.
134 * Return: 0 if OK, -ve on error.
136 int sysinfo_get_int(struct udevice *dev, int id, int *val);
139 * sysinfo_get_str() - Read a specific string data value that describes the
141 * @dev: The sysinfo instance to gather the data.
142 * @id: A unique identifier for the string value to be read.
143 * @size: The size of the buffer to receive the string data.
144 * @val: Pointer to a buffer that receives the value read.
146 * Return: 0 if OK, -ve on error.
148 int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
151 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
152 * @devp: Pointer to structure to receive the sysinfo device.
154 * Since there can only be at most one sysinfo instance, the API can supply a
155 * function that returns the unique device. This is especially useful for use
158 * Return: 0 if OK, -ve on error.
160 int sysinfo_get(struct udevice **devp);
163 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
164 * This function can be used to provide the image names based on runtime
165 * detection. A classic use-case would when DTBOs are used to describe
166 * additionnal daughter cards.
168 * @dev: The sysinfo instance to gather the data.
169 * @index: Index of the image. Starts at 0 and gets incremented
170 * after each call to this function.
171 * @type: The type of image. For example, "fdt" for DTBs
172 * @strp: A pointer to string. Untouched if the function fails
175 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
178 int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
183 static inline int sysinfo_detect(struct udevice *dev)
188 static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
193 static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
198 static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
204 static inline int sysinfo_get(struct udevice **devp)
209 static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
210 const char *type, const char **strp)