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
63 * dedicated method. This method will be called before any other
66 * Return: 0 if OK, -ve on error.
68 int (*detect)(struct udevice *dev);
71 * get_bool() - Read a specific bool data value that describes the
73 * @dev: The sysinfo instance to gather the data.
74 * @id: A unique identifier for the bool value to be read.
75 * @val: Pointer to a buffer that receives the value read.
77 * Return: 0 if OK, -ve on error.
79 int (*get_bool)(struct udevice *dev, int id, bool *val);
82 * get_int() - Read a specific int data value that describes the
84 * @dev: The sysinfo instance to gather the data.
85 * @id: A unique identifier for the int value to be read.
86 * @val: Pointer to a buffer that receives the value read.
88 * Return: 0 if OK, -ve on error.
90 int (*get_int)(struct udevice *dev, int id, int *val);
93 * get_str() - Read a specific string data value that describes the
95 * @dev: The sysinfo instance to gather the data.
96 * @id: A unique identifier for the string value to be read.
97 * @size: The size of the buffer to receive the string data.
98 * @val: Pointer to a buffer that receives the value read.
100 * Return: 0 if OK, -ve on error.
102 int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
105 * get_fit_loadable - Get the name of an image to load from FIT
106 * This function can be used to provide the image names based on runtime
107 * detection. A classic use-case would when DTBOs are used to describe
108 * additional daughter cards.
110 * @dev: The sysinfo instance to gather the data.
111 * @index: Index of the image. Starts at 0 and gets incremented
112 * after each call to this function.
113 * @type: The type of image. For example, "fdt" for DTBs
114 * @strp: A pointer to string. Untouched if the function fails
116 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
119 int (*get_fit_loadable)(struct udevice *dev, int index,
120 const char *type, const char **strp);
123 #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
125 #if CONFIG_IS_ENABLED(SYSINFO)
127 * sysinfo_detect() - Run the hardware info detection procedure for this device.
129 * @dev: The device containing the information
131 * This function must be called before any other accessor function for this
134 * Return: 0 if OK, -ve on error.
136 int sysinfo_detect(struct udevice *dev);
139 * sysinfo_get_bool() - Read a specific bool data value that describes the
141 * @dev: The sysinfo instance to gather the data.
142 * @id: A unique identifier for the bool value to be read.
143 * @val: Pointer to a buffer that receives the value read.
145 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
148 int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
151 * sysinfo_get_int() - Read a specific int data value that describes the
153 * @dev: The sysinfo instance to gather the data.
154 * @id: A unique identifier for the int value to be read.
155 * @val: Pointer to a buffer that receives the value read.
157 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
160 int sysinfo_get_int(struct udevice *dev, int id, int *val);
163 * sysinfo_get_str() - Read a specific string data value that describes the
165 * @dev: The sysinfo instance to gather the data.
166 * @id: A unique identifier for the string value to be read.
167 * @size: The size of the buffer to receive the string data.
168 * @val: Pointer to a buffer that receives the value read.
170 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
173 int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
176 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
177 * @devp: Pointer to structure to receive the sysinfo device.
179 * Since there can only be at most one sysinfo instance, the API can supply a
180 * function that returns the unique device. This is especially useful for use
183 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
186 int sysinfo_get(struct udevice **devp);
189 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
190 * This function can be used to provide the image names based on runtime
191 * detection. A classic use-case would when DTBOs are used to describe
192 * additional daughter cards.
194 * @dev: The sysinfo instance to gather the data.
195 * @index: Index of the image. Starts at 0 and gets incremented
196 * after each call to this function.
197 * @type: The type of image. For example, "fdt" for DTBs
198 * @strp: A pointer to string. Untouched if the function fails
201 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no
202 * loadable is available else -ve on error.
204 int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
209 static inline int sysinfo_detect(struct udevice *dev)
214 static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
219 static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
224 static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
230 static inline int sysinfo_get(struct udevice **devp)
235 static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
236 const char *type, const char **strp)