1 /* SPDX-License-Identifier: GPL-2.0+ */
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
10 #include <linux/errno.h>
15 * This uclass encapsulates hardware methods to gather information about a
16 * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders,
17 * read-only data in flash ICs, or similar.
19 * The interface offers functions to read the usual standard data types (bool,
20 * int, string) from the device, each of which is identified by a static
21 * numeric ID (which will usually be defined as a enum in a header file).
23 * If for example the sysinfo had a read-only serial number flash IC, we could
26 * ret = sysinfo_detect(dev);
28 * debug("sysinfo device not found.");
32 * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial);
34 * debug("Error when reading serial number from device.");
38 * to read the serial number.
41 /** enum sysinfo_id - Standard IDs defined by U-Boot */
45 /* For SMBIOS tables */
46 SYSINFO_ID_SMBIOS_SYSTEM_VERSION
,
47 SYSINFO_ID_SMBIOS_BASEBOARD_VERSION
,
49 /* For show_board_info() */
50 SYSINFO_ID_BOARD_MODEL
,
51 SYSINFO_ID_BOARD_MANUFACTURER
,
52 SYSINFO_ID_PRIOR_STAGE_VERSION
,
53 SYSINFO_ID_PRIOR_STAGE_DATE
,
55 /* First value available for downstream/board used */
56 SYSINFO_ID_USER
= 0x1000,
61 * detect() - Run the hardware info detection procedure for this
63 * @dev: The device containing the information
65 * This operation might take a long time (e.g. read from EEPROM,
66 * check the presence of a device on a bus etc.), hence this is not
67 * done in the probe() method, but later during operation in this
68 * dedicated method. This method will be called before any other
71 * Return: 0 if OK, -ve on error.
73 int (*detect
)(struct udevice
*dev
);
76 * get_bool() - Read a specific bool data value that describes the
78 * @dev: The sysinfo instance to gather the data.
79 * @id: A unique identifier for the bool value to be read.
80 * @val: Pointer to a buffer that receives the value read.
82 * Return: 0 if OK, -ve on error.
84 int (*get_bool
)(struct udevice
*dev
, int id
, bool *val
);
87 * get_int() - Read a specific int data value that describes the
89 * @dev: The sysinfo instance to gather the data.
90 * @id: A unique identifier for the int value to be read.
91 * @val: Pointer to a buffer that receives the value read.
93 * Return: 0 if OK, -ve on error.
95 int (*get_int
)(struct udevice
*dev
, int id
, int *val
);
98 * get_str() - Read a specific string data value that describes the
100 * @dev: The sysinfo instance to gather the data.
101 * @id: A unique identifier for the string value to be read.
102 * @size: The size of the buffer to receive the string data.
103 * @val: Pointer to a buffer that receives the value read.
105 * Return: 0 if OK, -ve on error.
107 int (*get_str
)(struct udevice
*dev
, int id
, size_t size
, char *val
);
110 * get_fit_loadable - Get the name of an image to load from FIT
111 * This function can be used to provide the image names based on runtime
112 * detection. A classic use-case would when DTBOs are used to describe
113 * additional daughter cards.
115 * @dev: The sysinfo instance to gather the data.
116 * @index: Index of the image. Starts at 0 and gets incremented
117 * after each call to this function.
118 * @type: The type of image. For example, "fdt" for DTBs
119 * @strp: A pointer to string. Untouched if the function fails
121 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
124 int (*get_fit_loadable
)(struct udevice
*dev
, int index
,
125 const char *type
, const char **strp
);
128 #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
130 #if CONFIG_IS_ENABLED(SYSINFO)
132 * sysinfo_detect() - Run the hardware info detection procedure for this device.
134 * @dev: The device containing the information
136 * This function must be called before any other accessor function for this
139 * Return: 0 if OK, -ve on error.
141 int sysinfo_detect(struct udevice
*dev
);
144 * sysinfo_get_bool() - Read a specific bool data value that describes the
146 * @dev: The sysinfo instance to gather the data.
147 * @id: A unique identifier for the bool value to be read.
148 * @val: Pointer to a buffer that receives the value read.
150 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
153 int sysinfo_get_bool(struct udevice
*dev
, int id
, bool *val
);
156 * sysinfo_get_int() - Read a specific int data value that describes the
158 * @dev: The sysinfo instance to gather the data.
159 * @id: A unique identifier for the int value to be read.
160 * @val: Pointer to a buffer that receives the value read.
162 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
165 int sysinfo_get_int(struct udevice
*dev
, int id
, int *val
);
168 * sysinfo_get_str() - Read a specific string data value that describes the
170 * @dev: The sysinfo instance to gather the data.
171 * @id: A unique identifier for the string value to be read.
172 * @size: The size of the buffer to receive the string data.
173 * @val: Pointer to a buffer that receives the value read.
175 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
178 int sysinfo_get_str(struct udevice
*dev
, int id
, size_t size
, char *val
);
181 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
182 * @devp: Pointer to structure to receive the sysinfo device.
184 * Since there can only be at most one sysinfo instance, the API can supply a
185 * function that returns the unique device. This is especially useful for use
188 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
191 int sysinfo_get(struct udevice
**devp
);
194 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
195 * This function can be used to provide the image names based on runtime
196 * detection. A classic use-case would when DTBOs are used to describe
197 * additional daughter cards.
199 * @dev: The sysinfo instance to gather the data.
200 * @index: Index of the image. Starts at 0 and gets incremented
201 * after each call to this function.
202 * @type: The type of image. For example, "fdt" for DTBs
203 * @strp: A pointer to string. Untouched if the function fails
206 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no
207 * loadable is available else -ve on error.
209 int sysinfo_get_fit_loadable(struct udevice
*dev
, int index
, const char *type
,
214 static inline int sysinfo_detect(struct udevice
*dev
)
219 static inline int sysinfo_get_bool(struct udevice
*dev
, int id
, bool *val
)
224 static inline int sysinfo_get_int(struct udevice
*dev
, int id
, int *val
)
229 static inline int sysinfo_get_str(struct udevice
*dev
, int id
, size_t size
,
235 static inline int sysinfo_get(struct udevice
**devp
)
240 static inline int sysinfo_get_fit_loadable(struct udevice
*dev
, int index
,
241 const char *type
, const char **strp
)