1 /* SPDX-License-Identifier: GPL-2.0+ */
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
8 * This uclass encapsulates hardware methods to gather information about a
9 * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders,
10 * read-only data in flash ICs, or similar.
12 * The interface offers functions to read the usual standard data types (bool,
13 * int, string) from the device, each of which is identified by a static
14 * numeric ID (which will usually be defined as a enum in a header file).
16 * If for example the sysinfo had a read-only serial number flash IC, we could
19 * ret = sysinfo_detect(dev);
21 * debug("sysinfo device not found.");
25 * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial);
27 * debug("Error when reading serial number from device.");
31 * to read the serial number.
34 /** enum sysinfo_id - Standard IDs defined by U-Boot */
38 SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
39 SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
41 /* First value available for downstream/board used */
42 SYSINFO_ID_USER = 0x1000,
47 * detect() - Run the hardware info detection procedure for this
49 * @dev: The device containing the information
51 * This operation might take a long time (e.g. read from EEPROM,
52 * check the presence of a device on a bus etc.), hence this is not
53 * done in the probe() method, but later during operation in this
56 * Return: 0 if OK, -ve on error.
58 int (*detect)(struct udevice *dev);
61 * get_bool() - Read a specific bool data value that describes the
63 * @dev: The sysinfo instance to gather the data.
64 * @id: A unique identifier for the bool value to be read.
65 * @val: Pointer to a buffer that receives the value read.
67 * Return: 0 if OK, -ve on error.
69 int (*get_bool)(struct udevice *dev, int id, bool *val);
72 * get_int() - Read a specific int data value that describes the
74 * @dev: The sysinfo instance to gather the data.
75 * @id: A unique identifier for the int value to be read.
76 * @val: Pointer to a buffer that receives the value read.
78 * Return: 0 if OK, -ve on error.
80 int (*get_int)(struct udevice *dev, int id, int *val);
83 * get_str() - Read a specific string data value that describes the
85 * @dev: The sysinfo instance to gather the data.
86 * @id: A unique identifier for the string value to be read.
87 * @size: The size of the buffer to receive the string data.
88 * @val: Pointer to a buffer that receives the value read.
90 * Return: 0 if OK, -ve on error.
92 int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
95 * get_fit_loadable - Get the name of an image to load from FIT
96 * This function can be used to provide the image names based on runtime
97 * detection. A classic use-case would when DTBOs are used to describe
98 * additionnal daughter cards.
100 * @dev: The sysinfo instance to gather the data.
101 * @index: Index of the image. Starts at 0 and gets incremented
102 * after each call to this function.
103 * @type: The type of image. For example, "fdt" for DTBs
104 * @strp: A pointer to string. Untouched if the function fails
106 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
109 int (*get_fit_loadable)(struct udevice *dev, int index,
110 const char *type, const char **strp);
113 #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
115 #if CONFIG_IS_ENABLED(SYSINFO)
117 * sysinfo_detect() - Run the hardware info detection procedure for this device.
119 * @dev: The device containing the information
121 * Return: 0 if OK, -ve on error.
123 int sysinfo_detect(struct udevice *dev);
126 * sysinfo_get_bool() - Read a specific bool data value that describes the
128 * @dev: The sysinfo instance to gather the data.
129 * @id: A unique identifier for the bool value to be read.
130 * @val: Pointer to a buffer that receives the value read.
132 * Return: 0 if OK, -ve on error.
134 int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
137 * sysinfo_get_int() - Read a specific int data value that describes the
139 * @dev: The sysinfo instance to gather the data.
140 * @id: A unique identifier for the int value to be read.
141 * @val: Pointer to a buffer that receives the value read.
143 * Return: 0 if OK, -ve on error.
145 int sysinfo_get_int(struct udevice *dev, int id, int *val);
148 * sysinfo_get_str() - Read a specific string data value that describes the
150 * @dev: The sysinfo instance to gather the data.
151 * @id: A unique identifier for the string value to be read.
152 * @size: The size of the buffer to receive the string data.
153 * @val: Pointer to a buffer that receives the value read.
155 * Return: 0 if OK, -ve on error.
157 int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
160 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
161 * @devp: Pointer to structure to receive the sysinfo device.
163 * Since there can only be at most one sysinfo instance, the API can supply a
164 * function that returns the unique device. This is especially useful for use
167 * Return: 0 if OK, -ve on error.
169 int sysinfo_get(struct udevice **devp);
172 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
173 * This function can be used to provide the image names based on runtime
174 * detection. A classic use-case would when DTBOs are used to describe
175 * additionnal daughter cards.
177 * @dev: The sysinfo instance to gather the data.
178 * @index: Index of the image. Starts at 0 and gets incremented
179 * after each call to this function.
180 * @type: The type of image. For example, "fdt" for DTBs
181 * @strp: A pointer to string. Untouched if the function fails
184 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
187 int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
192 static inline int sysinfo_detect(struct udevice *dev)
197 static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
202 static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
207 static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
213 static inline int sysinfo_get(struct udevice **devp)
218 static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
219 const char *type, const char **strp)