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 /** enum sysinfo_id - Standard IDs defined by U-Boot */
40 SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
41 SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
43 /* First value available for downstream/board used */
44 SYSINFO_ID_USER = 0x1000,
49 * detect() - Run the hardware info detection procedure for this
51 * @dev: The device containing the information
53 * This operation might take a long time (e.g. read from EEPROM,
54 * check the presence of a device on a bus etc.), hence this is not
55 * done in the probe() method, but later during operation in this
58 * Return: 0 if OK, -ve on error.
60 int (*detect)(struct udevice *dev);
63 * get_bool() - Read a specific bool data value that describes the
65 * @dev: The sysinfo instance to gather the data.
66 * @id: A unique identifier for the bool value to be read.
67 * @val: Pointer to a buffer that receives the value read.
69 * Return: 0 if OK, -ve on error.
71 int (*get_bool)(struct udevice *dev, int id, bool *val);
74 * get_int() - Read a specific int data value that describes the
76 * @dev: The sysinfo instance to gather the data.
77 * @id: A unique identifier for the int value to be read.
78 * @val: Pointer to a buffer that receives the value read.
80 * Return: 0 if OK, -ve on error.
82 int (*get_int)(struct udevice *dev, int id, int *val);
85 * get_str() - Read a specific string data value that describes the
87 * @dev: The sysinfo instance to gather the data.
88 * @id: A unique identifier for the string value to be read.
89 * @size: The size of the buffer to receive the string data.
90 * @val: Pointer to a buffer that receives the value read.
92 * Return: 0 if OK, -ve on error.
94 int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
97 * get_fit_loadable - Get the name of an image to load from FIT
98 * This function can be used to provide the image names based on runtime
99 * detection. A classic use-case would when DTBOs are used to describe
100 * additionnal daughter cards.
102 * @dev: The sysinfo instance to gather the data.
103 * @index: Index of the image. Starts at 0 and gets incremented
104 * after each call to this function.
105 * @type: The type of image. For example, "fdt" for DTBs
106 * @strp: A pointer to string. Untouched if the function fails
108 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
111 int (*get_fit_loadable)(struct udevice *dev, int index,
112 const char *type, const char **strp);
115 #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
117 #if CONFIG_IS_ENABLED(SYSINFO)
119 * sysinfo_detect() - Run the hardware info detection procedure for this device.
121 * @dev: The device containing the information
123 * Return: 0 if OK, -ve on error.
125 int sysinfo_detect(struct udevice *dev);
128 * sysinfo_get_bool() - Read a specific bool data value that describes the
130 * @dev: The sysinfo instance to gather the data.
131 * @id: A unique identifier for the bool 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_bool(struct udevice *dev, int id, bool *val);
139 * sysinfo_get_int() - Read a specific int data value that describes the
141 * @dev: The sysinfo instance to gather the data.
142 * @id: A unique identifier for the int value to be read.
143 * @val: Pointer to a buffer that receives the value read.
145 * Return: 0 if OK, -ve on error.
147 int sysinfo_get_int(struct udevice *dev, int id, int *val);
150 * sysinfo_get_str() - Read a specific string data value that describes the
152 * @dev: The sysinfo instance to gather the data.
153 * @id: A unique identifier for the string value to be read.
154 * @size: The size of the buffer to receive the string data.
155 * @val: Pointer to a buffer that receives the value read.
157 * Return: 0 if OK, -ve on error.
159 int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
162 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
163 * @devp: Pointer to structure to receive the sysinfo device.
165 * Since there can only be at most one sysinfo instance, the API can supply a
166 * function that returns the unique device. This is especially useful for use
169 * Return: 0 if OK, -ve on error.
171 int sysinfo_get(struct udevice **devp);
174 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
175 * This function can be used to provide the image names based on runtime
176 * detection. A classic use-case would when DTBOs are used to describe
177 * additionnal daughter cards.
179 * @dev: The sysinfo instance to gather the data.
180 * @index: Index of the image. Starts at 0 and gets incremented
181 * after each call to this function.
182 * @type: The type of image. For example, "fdt" for DTBs
183 * @strp: A pointer to string. Untouched if the function fails
186 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
189 int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
194 static inline int sysinfo_detect(struct udevice *dev)
199 static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
204 static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
209 static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
215 static inline int sysinfo_get(struct udevice **devp)
220 static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
221 const char *type, const char **strp)