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