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 /* For SMBIOS tables */
41 SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
42 SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
44 /* For show_board_info() */
45 SYSINFO_ID_BOARD_MODEL,
47 /* First value available for downstream/board used */
48 SYSINFO_ID_USER = 0x1000,
53 * detect() - Run the hardware info detection procedure for this
55 * @dev: The device containing the information
57 * This operation might take a long time (e.g. read from EEPROM,
58 * check the presence of a device on a bus etc.), hence this is not
59 * done in the probe() method, but later during operation in this
62 * Return: 0 if OK, -ve on error.
64 int (*detect)(struct udevice *dev);
67 * get_bool() - Read a specific bool data value that describes the
69 * @dev: The sysinfo instance to gather the data.
70 * @id: A unique identifier for the bool value to be read.
71 * @val: Pointer to a buffer that receives the value read.
73 * Return: 0 if OK, -ve on error.
75 int (*get_bool)(struct udevice *dev, int id, bool *val);
78 * get_int() - Read a specific int data value that describes the
80 * @dev: The sysinfo instance to gather the data.
81 * @id: A unique identifier for the int value to be read.
82 * @val: Pointer to a buffer that receives the value read.
84 * Return: 0 if OK, -ve on error.
86 int (*get_int)(struct udevice *dev, int id, int *val);
89 * get_str() - Read a specific string data value that describes the
91 * @dev: The sysinfo instance to gather the data.
92 * @id: A unique identifier for the string value to be read.
93 * @size: The size of the buffer to receive the string data.
94 * @val: Pointer to a buffer that receives the value read.
96 * Return: 0 if OK, -ve on error.
98 int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
101 * get_fit_loadable - Get the name of an image to load from FIT
102 * This function can be used to provide the image names based on runtime
103 * detection. A classic use-case would when DTBOs are used to describe
104 * additionnal daughter cards.
106 * @dev: The sysinfo instance to gather the data.
107 * @index: Index of the image. Starts at 0 and gets incremented
108 * after each call to this function.
109 * @type: The type of image. For example, "fdt" for DTBs
110 * @strp: A pointer to string. Untouched if the function fails
112 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
115 int (*get_fit_loadable)(struct udevice *dev, int index,
116 const char *type, const char **strp);
119 #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
121 #if CONFIG_IS_ENABLED(SYSINFO)
123 * sysinfo_detect() - Run the hardware info detection procedure for this device.
125 * @dev: The device containing the information
127 * Return: 0 if OK, -ve on error.
129 int sysinfo_detect(struct udevice *dev);
132 * sysinfo_get_bool() - Read a specific bool data value that describes the
134 * @dev: The sysinfo instance to gather the data.
135 * @id: A unique identifier for the bool value to be read.
136 * @val: Pointer to a buffer that receives the value read.
138 * Return: 0 if OK, -ve on error.
140 int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
143 * sysinfo_get_int() - Read a specific int data value that describes the
145 * @dev: The sysinfo instance to gather the data.
146 * @id: A unique identifier for the int value to be read.
147 * @val: Pointer to a buffer that receives the value read.
149 * Return: 0 if OK, -ve on error.
151 int sysinfo_get_int(struct udevice *dev, int id, int *val);
154 * sysinfo_get_str() - Read a specific string data value that describes the
156 * @dev: The sysinfo instance to gather the data.
157 * @id: A unique identifier for the string value to be read.
158 * @size: The size of the buffer to receive the string data.
159 * @val: Pointer to a buffer that receives the value read.
161 * Return: 0 if OK, -ve on error.
163 int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
166 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
167 * @devp: Pointer to structure to receive the sysinfo device.
169 * Since there can only be at most one sysinfo instance, the API can supply a
170 * function that returns the unique device. This is especially useful for use
173 * Return: 0 if OK, -ve on error.
175 int sysinfo_get(struct udevice **devp);
178 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
179 * This function can be used to provide the image names based on runtime
180 * detection. A classic use-case would when DTBOs are used to describe
181 * additionnal daughter cards.
183 * @dev: The sysinfo instance to gather the data.
184 * @index: Index of the image. Starts at 0 and gets incremented
185 * after each call to this function.
186 * @type: The type of image. For example, "fdt" for DTBs
187 * @strp: A pointer to string. Untouched if the function fails
190 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
193 int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
198 static inline int sysinfo_detect(struct udevice *dev)
203 static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
208 static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
213 static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
219 static inline int sysinfo_get(struct udevice **devp)
224 static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
225 const char *type, const char **strp)