Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * (C) Copyright 2017 |
| 4 | * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc |
| 5 | */ |
| 6 | |
Tom Rini | 56a3433 | 2021-04-19 16:18:49 -0400 | [diff] [blame] | 7 | #ifndef __SYSINFO_H__ |
| 8 | #define __SYSINFO_H__ |
| 9 | |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | struct udevice; |
| 11 | |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 12 | /* |
| 13 | * This uclass encapsulates hardware methods to gather information about a |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 14 | * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders, |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 15 | * read-only data in flash ICs, or similar. |
| 16 | * |
| 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). |
| 20 | * |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 21 | * If for example the sysinfo had a read-only serial number flash IC, we could |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 22 | * call |
| 23 | * |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 24 | * ret = sysinfo_detect(dev); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 25 | * if (ret) { |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 26 | * debug("sysinfo device not found."); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 27 | * return ret; |
| 28 | * } |
| 29 | * |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 30 | * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 31 | * if (ret) { |
| 32 | * debug("Error when reading serial number from device."); |
| 33 | * return ret; |
| 34 | * } |
| 35 | * |
| 36 | * to read the serial number. |
| 37 | */ |
| 38 | |
Simon Glass | 07c9e68 | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 39 | /** enum sysinfo_id - Standard IDs defined by U-Boot */ |
| 40 | enum sysinfo_id { |
| 41 | SYSINFO_ID_NONE, |
| 42 | |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 43 | /* For SMBIOS tables */ |
Simon Glass | 07c9e68 | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 44 | SYSINFO_ID_SMBIOS_SYSTEM_VERSION, |
| 45 | SYSINFO_ID_SMBIOS_BASEBOARD_VERSION, |
| 46 | |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 47 | /* For show_board_info() */ |
| 48 | SYSINFO_ID_BOARD_MODEL, |
| 49 | |
Simon Glass | 07c9e68 | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 50 | /* First value available for downstream/board used */ |
| 51 | SYSINFO_ID_USER = 0x1000, |
| 52 | }; |
| 53 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 54 | struct sysinfo_ops { |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 55 | /** |
| 56 | * detect() - Run the hardware info detection procedure for this |
| 57 | * device. |
| 58 | * @dev: The device containing the information |
| 59 | * |
| 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. |
| 64 | * |
| 65 | * Return: 0 if OK, -ve on error. |
| 66 | */ |
| 67 | int (*detect)(struct udevice *dev); |
| 68 | |
| 69 | /** |
| 70 | * get_bool() - Read a specific bool data value that describes the |
| 71 | * hardware setup. |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 72 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 73 | * @id: A unique identifier for the bool value to be read. |
| 74 | * @val: Pointer to a buffer that receives the value read. |
| 75 | * |
| 76 | * Return: 0 if OK, -ve on error. |
| 77 | */ |
| 78 | int (*get_bool)(struct udevice *dev, int id, bool *val); |
| 79 | |
| 80 | /** |
| 81 | * get_int() - Read a specific int data value that describes the |
| 82 | * hardware setup. |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 83 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 84 | * @id: A unique identifier for the int value to be read. |
| 85 | * @val: Pointer to a buffer that receives the value read. |
| 86 | * |
| 87 | * Return: 0 if OK, -ve on error. |
| 88 | */ |
| 89 | int (*get_int)(struct udevice *dev, int id, int *val); |
| 90 | |
| 91 | /** |
| 92 | * get_str() - Read a specific string data value that describes the |
| 93 | * hardware setup. |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 94 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 95 | * @id: A unique identifier for the string value to be read. |
| 96 | * @size: The size of the buffer to receive the string data. |
| 97 | * @val: Pointer to a buffer that receives the value read. |
| 98 | * |
| 99 | * Return: 0 if OK, -ve on error. |
| 100 | */ |
| 101 | int (*get_str)(struct udevice *dev, int id, size_t size, char *val); |
Jean-Jacques Hiblot | d42730e | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * get_fit_loadable - Get the name of an image to load from FIT |
| 105 | * This function can be used to provide the image names based on runtime |
| 106 | * detection. A classic use-case would when DTBOs are used to describe |
| 107 | * additionnal daughter cards. |
| 108 | * |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 109 | * @dev: The sysinfo instance to gather the data. |
Jean-Jacques Hiblot | d42730e | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 110 | * @index: Index of the image. Starts at 0 and gets incremented |
| 111 | * after each call to this function. |
| 112 | * @type: The type of image. For example, "fdt" for DTBs |
| 113 | * @strp: A pointer to string. Untouched if the function fails |
| 114 | * |
| 115 | * Return: 0 if OK, -ENOENT if no loadable is available else -ve on |
| 116 | * error. |
| 117 | */ |
| 118 | int (*get_fit_loadable)(struct udevice *dev, int index, |
| 119 | const char *type, const char **strp); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 120 | }; |
| 121 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 122 | #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops) |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 123 | |
Simon Glass | 2b8e5c8 | 2021-02-04 21:17:21 -0700 | [diff] [blame] | 124 | #if CONFIG_IS_ENABLED(SYSINFO) |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 125 | /** |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 126 | * sysinfo_detect() - Run the hardware info detection procedure for this device. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 127 | * |
| 128 | * @dev: The device containing the information |
| 129 | * |
| 130 | * Return: 0 if OK, -ve on error. |
| 131 | */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 132 | int sysinfo_detect(struct udevice *dev); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 133 | |
| 134 | /** |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 135 | * sysinfo_get_bool() - Read a specific bool data value that describes the |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 136 | * hardware setup. |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 137 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 138 | * @id: A unique identifier for the bool value to be read. |
| 139 | * @val: Pointer to a buffer that receives the value read. |
| 140 | * |
| 141 | * Return: 0 if OK, -ve on error. |
| 142 | */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 143 | int sysinfo_get_bool(struct udevice *dev, int id, bool *val); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 144 | |
| 145 | /** |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 146 | * sysinfo_get_int() - Read a specific int data value that describes the |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 147 | * hardware setup. |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 148 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 149 | * @id: A unique identifier for the int value to be read. |
| 150 | * @val: Pointer to a buffer that receives the value read. |
| 151 | * |
| 152 | * Return: 0 if OK, -ve on error. |
| 153 | */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 154 | int sysinfo_get_int(struct udevice *dev, int id, int *val); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 155 | |
| 156 | /** |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 157 | * sysinfo_get_str() - Read a specific string data value that describes the |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 158 | * hardware setup. |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 159 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 160 | * @id: A unique identifier for the string value to be read. |
| 161 | * @size: The size of the buffer to receive the string data. |
| 162 | * @val: Pointer to a buffer that receives the value read. |
| 163 | * |
| 164 | * Return: 0 if OK, -ve on error. |
| 165 | */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 166 | int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 167 | |
| 168 | /** |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 169 | * sysinfo_get() - Return the sysinfo device for the sysinfo in question. |
| 170 | * @devp: Pointer to structure to receive the sysinfo device. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 171 | * |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 172 | * Since there can only be at most one sysinfo instance, the API can supply a |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 173 | * function that returns the unique device. This is especially useful for use |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 174 | * in sysinfo files. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 175 | * |
| 176 | * Return: 0 if OK, -ve on error. |
| 177 | */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 178 | int sysinfo_get(struct udevice **devp); |
Jean-Jacques Hiblot | d42730e | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 179 | |
| 180 | /** |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 181 | * sysinfo_get_fit_loadable - Get the name of an image to load from FIT |
Jean-Jacques Hiblot | d42730e | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 182 | * This function can be used to provide the image names based on runtime |
| 183 | * detection. A classic use-case would when DTBOs are used to describe |
| 184 | * additionnal daughter cards. |
| 185 | * |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 186 | * @dev: The sysinfo instance to gather the data. |
Jean-Jacques Hiblot | d42730e | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 187 | * @index: Index of the image. Starts at 0 and gets incremented |
| 188 | * after each call to this function. |
| 189 | * @type: The type of image. For example, "fdt" for DTBs |
| 190 | * @strp: A pointer to string. Untouched if the function fails |
| 191 | * |
| 192 | * |
| 193 | * Return: 0 if OK, -ENOENT if no loadable is available else -ve on |
| 194 | * error. |
| 195 | */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 196 | int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type, |
| 197 | const char **strp); |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 198 | |
| 199 | #else |
| 200 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 201 | static inline int sysinfo_detect(struct udevice *dev) |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 202 | { |
| 203 | return -ENOSYS; |
| 204 | } |
| 205 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 206 | static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val) |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 207 | { |
| 208 | return -ENOSYS; |
| 209 | } |
| 210 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 211 | static inline int sysinfo_get_int(struct udevice *dev, int id, int *val) |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 212 | { |
| 213 | return -ENOSYS; |
| 214 | } |
| 215 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 216 | static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size, |
| 217 | char *val) |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 218 | { |
| 219 | return -ENOSYS; |
| 220 | } |
| 221 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 222 | static inline int sysinfo_get(struct udevice **devp) |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 223 | { |
| 224 | return -ENOSYS; |
| 225 | } |
| 226 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 227 | static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index, |
| 228 | const char *type, const char **strp) |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 229 | { |
| 230 | return -ENOSYS; |
| 231 | } |
| 232 | |
| 233 | #endif |
Tom Rini | 56a3433 | 2021-04-19 16:18:49 -0400 | [diff] [blame] | 234 | #endif |