1 /* SPDX-License-Identifier: GPL-2.0+ */
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
13 * This uclass encapsulates hardware methods to gather information about a
14 * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders,
15 * read-only data in flash ICs, or similar.
17 * The interface offers functions to read the usual standard data types (bool,
18 * int, string) from the device, each of which is identified by a static
19 * numeric ID (which will usually be defined as a enum in a header file).
21 * If for example the sysinfo had a read-only serial number flash IC, we could
24 * ret = sysinfo_detect(dev);
26 * debug("sysinfo device not found.");
30 * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial);
32 * debug("Error when reading serial number from device.");
36 * to read the serial number.
39 /** enum sysinfo_id - Standard IDs defined by U-Boot */
43 /* For SMBIOS tables */
44 SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
45 SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
47 /* For show_board_info() */
48 SYSINFO_ID_BOARD_MODEL,
50 /* First value available for downstream/board used */
51 SYSINFO_ID_USER = 0x1000,
56 * detect() - Run the hardware info detection procedure for this
58 * @dev: The device containing the information
60 * This operation might take a long time (e.g. read from EEPROM,
61 * check the presence of a device on a bus etc.), hence this is not
62 * done in the probe() method, but later during operation in this
65 * Return: 0 if OK, -ve on error.
67 int (*detect)(struct udevice *dev);
70 * get_bool() - Read a specific bool data value that describes the
72 * @dev: The sysinfo instance to gather the data.
73 * @id: A unique identifier for the bool value to be read.
74 * @val: Pointer to a buffer that receives the value read.
76 * Return: 0 if OK, -ve on error.
78 int (*get_bool)(struct udevice *dev, int id, bool *val);
81 * get_int() - Read a specific int data value that describes the
83 * @dev: The sysinfo instance to gather the data.
84 * @id: A unique identifier for the int value to be read.
85 * @val: Pointer to a buffer that receives the value read.
87 * Return: 0 if OK, -ve on error.
89 int (*get_int)(struct udevice *dev, int id, int *val);
92 * get_str() - Read a specific string data value that describes the
94 * @dev: The sysinfo instance to gather the data.
95 * @id: A unique identifier for the string value to be read.
96 * @size: The size of the buffer to receive the string data.
97 * @val: Pointer to a buffer that receives the value read.
99 * Return: 0 if OK, -ve on error.
101 int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
104 * get_fit_loadable - Get the name of an image to load from FIT
105 * This function can be used to provide the image names based on runtime
106 * detection. A classic use-case would when DTBOs are used to describe
107 * additionnal daughter cards.
109 * @dev: The sysinfo instance to gather the data.
110 * @index: Index of the image. Starts at 0 and gets incremented
111 * after each call to this function.
112 * @type: The type of image. For example, "fdt" for DTBs
113 * @strp: A pointer to string. Untouched if the function fails
115 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
118 int (*get_fit_loadable)(struct udevice *dev, int index,
119 const char *type, const char **strp);
122 #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
124 #if CONFIG_IS_ENABLED(SYSINFO)
126 * sysinfo_detect() - Run the hardware info detection procedure for this device.
128 * @dev: The device containing the information
130 * Return: 0 if OK, -ve on error.
132 int sysinfo_detect(struct udevice *dev);
135 * sysinfo_get_bool() - Read a specific bool data value that describes the
137 * @dev: The sysinfo instance to gather the data.
138 * @id: A unique identifier for the bool value to be read.
139 * @val: Pointer to a buffer that receives the value read.
141 * Return: 0 if OK, -ve on error.
143 int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
146 * sysinfo_get_int() - Read a specific int data value that describes the
148 * @dev: The sysinfo instance to gather the data.
149 * @id: A unique identifier for the int value to be read.
150 * @val: Pointer to a buffer that receives the value read.
152 * Return: 0 if OK, -ve on error.
154 int sysinfo_get_int(struct udevice *dev, int id, int *val);
157 * sysinfo_get_str() - Read a specific string data value that describes the
159 * @dev: The sysinfo instance to gather the data.
160 * @id: A unique identifier for the string value to be read.
161 * @size: The size of the buffer to receive the string data.
162 * @val: Pointer to a buffer that receives the value read.
164 * Return: 0 if OK, -ve on error.
166 int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
169 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
170 * @devp: Pointer to structure to receive the sysinfo device.
172 * Since there can only be at most one sysinfo instance, the API can supply a
173 * function that returns the unique device. This is especially useful for use
176 * Return: 0 if OK, -ve on error.
178 int sysinfo_get(struct udevice **devp);
181 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
182 * This function can be used to provide the image names based on runtime
183 * detection. A classic use-case would when DTBOs are used to describe
184 * additionnal daughter cards.
186 * @dev: The sysinfo instance to gather the data.
187 * @index: Index of the image. Starts at 0 and gets incremented
188 * after each call to this function.
189 * @type: The type of image. For example, "fdt" for DTBs
190 * @strp: A pointer to string. Untouched if the function fails
193 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
196 int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
201 static inline int sysinfo_detect(struct udevice *dev)
206 static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
211 static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
216 static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
222 static inline int sysinfo_get(struct udevice **devp)
227 static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
228 const char *type, const char **strp)