blob: 68fad25a0659b20772a2f98e6b2d7f4b690761f1 [file] [log] [blame]
Mario Six2161e552018-07-31 11:44:11 +02001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * (C) Copyright 2017
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5 */
6
Simon Glass3ba929a2020-10-30 21:38:53 -06007struct udevice;
8
Mario Six2161e552018-07-31 11:44:11 +02009/*
10 * This uclass encapsulates hardware methods to gather information about a
Simon Glass458b66a2020-11-05 06:32:05 -070011 * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders,
Mario Six2161e552018-07-31 11:44:11 +020012 * read-only data in flash ICs, or similar.
13 *
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).
17 *
Simon Glass458b66a2020-11-05 06:32:05 -070018 * If for example the sysinfo had a read-only serial number flash IC, we could
Mario Six2161e552018-07-31 11:44:11 +020019 * call
20 *
Simon Glass458b66a2020-11-05 06:32:05 -070021 * ret = sysinfo_detect(dev);
Mario Six2161e552018-07-31 11:44:11 +020022 * if (ret) {
Simon Glass458b66a2020-11-05 06:32:05 -070023 * debug("sysinfo device not found.");
Mario Six2161e552018-07-31 11:44:11 +020024 * return ret;
25 * }
26 *
Simon Glass458b66a2020-11-05 06:32:05 -070027 * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial);
Mario Six2161e552018-07-31 11:44:11 +020028 * if (ret) {
29 * debug("Error when reading serial number from device.");
30 * return ret;
31 * }
32 *
33 * to read the serial number.
34 */
35
Simon Glasscf67d6d2021-02-04 21:17:23 -070036/** enum sysinfo_id - Standard IDs defined by U-Boot */
37enum sysinfo_id {
38 SYSINFO_ID_NONE,
39
Simon Glass43bc5432021-03-21 16:50:06 +130040 /* For SMBIOS tables */
Simon Glasscf67d6d2021-02-04 21:17:23 -070041 SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
42 SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
43
Simon Glass43bc5432021-03-21 16:50:06 +130044 /* For show_board_info() */
45 SYSINFO_ID_BOARD_MODEL,
46
Simon Glasscf67d6d2021-02-04 21:17:23 -070047 /* First value available for downstream/board used */
48 SYSINFO_ID_USER = 0x1000,
49};
50
Simon Glass458b66a2020-11-05 06:32:05 -070051struct sysinfo_ops {
Mario Six2161e552018-07-31 11:44:11 +020052 /**
53 * detect() - Run the hardware info detection procedure for this
54 * device.
55 * @dev: The device containing the information
56 *
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
60 * dedicated method.
61 *
62 * Return: 0 if OK, -ve on error.
63 */
64 int (*detect)(struct udevice *dev);
65
66 /**
67 * get_bool() - Read a specific bool data value that describes the
68 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -070069 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +020070 * @id: A unique identifier for the bool value to be read.
71 * @val: Pointer to a buffer that receives the value read.
72 *
73 * Return: 0 if OK, -ve on error.
74 */
75 int (*get_bool)(struct udevice *dev, int id, bool *val);
76
77 /**
78 * get_int() - Read a specific int data value that describes the
79 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -070080 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +020081 * @id: A unique identifier for the int value to be read.
82 * @val: Pointer to a buffer that receives the value read.
83 *
84 * Return: 0 if OK, -ve on error.
85 */
86 int (*get_int)(struct udevice *dev, int id, int *val);
87
88 /**
89 * get_str() - Read a specific string data value that describes the
90 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -070091 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +020092 * @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.
95 *
96 * Return: 0 if OK, -ve on error.
97 */
98 int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +020099
100 /**
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.
105 *
Simon Glass458b66a2020-11-05 06:32:05 -0700106 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200107 * @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
111 *
112 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
113 * error.
114 */
115 int (*get_fit_loadable)(struct udevice *dev, int index,
116 const char *type, const char **strp);
Mario Six2161e552018-07-31 11:44:11 +0200117};
118
Simon Glass458b66a2020-11-05 06:32:05 -0700119#define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
Mario Six2161e552018-07-31 11:44:11 +0200120
Simon Glass10e6f792021-02-04 21:17:21 -0700121#if CONFIG_IS_ENABLED(SYSINFO)
Mario Six2161e552018-07-31 11:44:11 +0200122/**
Simon Glass458b66a2020-11-05 06:32:05 -0700123 * sysinfo_detect() - Run the hardware info detection procedure for this device.
Mario Six2161e552018-07-31 11:44:11 +0200124 *
125 * @dev: The device containing the information
126 *
127 * Return: 0 if OK, -ve on error.
128 */
Simon Glass458b66a2020-11-05 06:32:05 -0700129int sysinfo_detect(struct udevice *dev);
Mario Six2161e552018-07-31 11:44:11 +0200130
131/**
Simon Glass458b66a2020-11-05 06:32:05 -0700132 * sysinfo_get_bool() - Read a specific bool data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200133 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700134 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200135 * @id: A unique identifier for the bool value to be read.
136 * @val: Pointer to a buffer that receives the value read.
137 *
138 * Return: 0 if OK, -ve on error.
139 */
Simon Glass458b66a2020-11-05 06:32:05 -0700140int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
Mario Six2161e552018-07-31 11:44:11 +0200141
142/**
Simon Glass458b66a2020-11-05 06:32:05 -0700143 * sysinfo_get_int() - Read a specific int data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200144 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700145 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200146 * @id: A unique identifier for the int value to be read.
147 * @val: Pointer to a buffer that receives the value read.
148 *
149 * Return: 0 if OK, -ve on error.
150 */
Simon Glass458b66a2020-11-05 06:32:05 -0700151int sysinfo_get_int(struct udevice *dev, int id, int *val);
Mario Six2161e552018-07-31 11:44:11 +0200152
153/**
Simon Glass458b66a2020-11-05 06:32:05 -0700154 * sysinfo_get_str() - Read a specific string data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200155 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700156 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200157 * @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.
160 *
161 * Return: 0 if OK, -ve on error.
162 */
Simon Glass458b66a2020-11-05 06:32:05 -0700163int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
Mario Six2161e552018-07-31 11:44:11 +0200164
165/**
Simon Glass458b66a2020-11-05 06:32:05 -0700166 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
167 * @devp: Pointer to structure to receive the sysinfo device.
Mario Six2161e552018-07-31 11:44:11 +0200168 *
Simon Glass458b66a2020-11-05 06:32:05 -0700169 * Since there can only be at most one sysinfo instance, the API can supply a
Mario Six2161e552018-07-31 11:44:11 +0200170 * function that returns the unique device. This is especially useful for use
Simon Glass458b66a2020-11-05 06:32:05 -0700171 * in sysinfo files.
Mario Six2161e552018-07-31 11:44:11 +0200172 *
173 * Return: 0 if OK, -ve on error.
174 */
Simon Glass458b66a2020-11-05 06:32:05 -0700175int sysinfo_get(struct udevice **devp);
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200176
177/**
Simon Glass458b66a2020-11-05 06:32:05 -0700178 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200179 * 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.
182 *
Simon Glass458b66a2020-11-05 06:32:05 -0700183 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200184 * @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
188 *
189 *
190 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
191 * error.
192 */
Simon Glass458b66a2020-11-05 06:32:05 -0700193int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
194 const char **strp);
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200195
196#else
197
Simon Glass458b66a2020-11-05 06:32:05 -0700198static inline int sysinfo_detect(struct udevice *dev)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200199{
200 return -ENOSYS;
201}
202
Simon Glass458b66a2020-11-05 06:32:05 -0700203static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200204{
205 return -ENOSYS;
206}
207
Simon Glass458b66a2020-11-05 06:32:05 -0700208static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200209{
210 return -ENOSYS;
211}
212
Simon Glass458b66a2020-11-05 06:32:05 -0700213static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
214 char *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200215{
216 return -ENOSYS;
217}
218
Simon Glass458b66a2020-11-05 06:32:05 -0700219static inline int sysinfo_get(struct udevice **devp)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200220{
221 return -ENOSYS;
222}
223
Simon Glass458b66a2020-11-05 06:32:05 -0700224static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
225 const char *type, const char **strp)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200226{
227 return -ENOSYS;
228}
229
230#endif