2018-07-31 09:44:11 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
|
|
/*
|
|
|
|
* (C) Copyright 2017
|
|
|
|
* Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This uclass encapsulates hardware methods to gather information about a
|
2020-11-05 13:32:05 +00:00
|
|
|
* sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders,
|
2018-07-31 09:44:11 +00:00
|
|
|
* read-only data in flash ICs, or similar.
|
|
|
|
*
|
|
|
|
* The interface offers functions to read the usual standard data types (bool,
|
|
|
|
* int, string) from the device, each of which is identified by a static
|
|
|
|
* numeric ID (which will usually be defined as a enum in a header file).
|
|
|
|
*
|
2020-11-05 13:32:05 +00:00
|
|
|
* If for example the sysinfo had a read-only serial number flash IC, we could
|
2018-07-31 09:44:11 +00:00
|
|
|
* call
|
|
|
|
*
|
2020-11-05 13:32:05 +00:00
|
|
|
* ret = sysinfo_detect(dev);
|
2018-07-31 09:44:11 +00:00
|
|
|
* if (ret) {
|
2020-11-05 13:32:05 +00:00
|
|
|
* debug("sysinfo device not found.");
|
2018-07-31 09:44:11 +00:00
|
|
|
* return ret;
|
|
|
|
* }
|
|
|
|
*
|
2020-11-05 13:32:05 +00:00
|
|
|
* ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial);
|
2018-07-31 09:44:11 +00:00
|
|
|
* if (ret) {
|
|
|
|
* debug("Error when reading serial number from device.");
|
|
|
|
* return ret;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* to read the serial number.
|
|
|
|
*/
|
|
|
|
|
2021-02-05 04:17:23 +00:00
|
|
|
/** enum sysinfo_id - Standard IDs defined by U-Boot */
|
|
|
|
enum sysinfo_id {
|
|
|
|
SYSINFO_ID_NONE,
|
|
|
|
|
|
|
|
SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
|
|
|
|
SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
|
|
|
|
|
|
|
|
/* First value available for downstream/board used */
|
|
|
|
SYSINFO_ID_USER = 0x1000,
|
|
|
|
};
|
|
|
|
|
2020-11-05 13:32:05 +00:00
|
|
|
struct sysinfo_ops {
|
2018-07-31 09:44:11 +00:00
|
|
|
/**
|
|
|
|
* detect() - Run the hardware info detection procedure for this
|
|
|
|
* device.
|
|
|
|
* @dev: The device containing the information
|
|
|
|
*
|
|
|
|
* This operation might take a long time (e.g. read from EEPROM,
|
|
|
|
* check the presence of a device on a bus etc.), hence this is not
|
|
|
|
* done in the probe() method, but later during operation in this
|
|
|
|
* dedicated method.
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error.
|
|
|
|
*/
|
|
|
|
int (*detect)(struct udevice *dev);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get_bool() - Read a specific bool data value that describes the
|
|
|
|
* hardware setup.
|
2020-11-05 13:32:05 +00:00
|
|
|
* @dev: The sysinfo instance to gather the data.
|
2018-07-31 09:44:11 +00:00
|
|
|
* @id: A unique identifier for the bool value to be read.
|
|
|
|
* @val: Pointer to a buffer that receives the value read.
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error.
|
|
|
|
*/
|
|
|
|
int (*get_bool)(struct udevice *dev, int id, bool *val);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get_int() - Read a specific int data value that describes the
|
|
|
|
* hardware setup.
|
2020-11-05 13:32:05 +00:00
|
|
|
* @dev: The sysinfo instance to gather the data.
|
2018-07-31 09:44:11 +00:00
|
|
|
* @id: A unique identifier for the int value to be read.
|
|
|
|
* @val: Pointer to a buffer that receives the value read.
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error.
|
|
|
|
*/
|
|
|
|
int (*get_int)(struct udevice *dev, int id, int *val);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get_str() - Read a specific string data value that describes the
|
|
|
|
* hardware setup.
|
2020-11-05 13:32:05 +00:00
|
|
|
* @dev: The sysinfo instance to gather the data.
|
2018-07-31 09:44:11 +00:00
|
|
|
* @id: A unique identifier for the string value to be read.
|
|
|
|
* @size: The size of the buffer to receive the string data.
|
|
|
|
* @val: Pointer to a buffer that receives the value read.
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error.
|
|
|
|
*/
|
|
|
|
int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
|
2019-10-22 14:39:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get_fit_loadable - Get the name of an image to load from FIT
|
|
|
|
* This function can be used to provide the image names based on runtime
|
|
|
|
* detection. A classic use-case would when DTBOs are used to describe
|
|
|
|
* additionnal daughter cards.
|
|
|
|
*
|
2020-11-05 13:32:05 +00:00
|
|
|
* @dev: The sysinfo instance to gather the data.
|
2019-10-22 14:39:19 +00:00
|
|
|
* @index: Index of the image. Starts at 0 and gets incremented
|
|
|
|
* after each call to this function.
|
|
|
|
* @type: The type of image. For example, "fdt" for DTBs
|
|
|
|
* @strp: A pointer to string. Untouched if the function fails
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ENOENT if no loadable is available else -ve on
|
|
|
|
* error.
|
|
|
|
*/
|
|
|
|
int (*get_fit_loadable)(struct udevice *dev, int index,
|
|
|
|
const char *type, const char **strp);
|
2018-07-31 09:44:11 +00:00
|
|
|
};
|
|
|
|
|
2020-11-05 13:32:05 +00:00
|
|
|
#define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
|
2018-07-31 09:44:11 +00:00
|
|
|
|
2021-02-05 04:17:21 +00:00
|
|
|
#if CONFIG_IS_ENABLED(SYSINFO)
|
2018-07-31 09:44:11 +00:00
|
|
|
/**
|
2020-11-05 13:32:05 +00:00
|
|
|
* sysinfo_detect() - Run the hardware info detection procedure for this device.
|
2018-07-31 09:44:11 +00:00
|
|
|
*
|
|
|
|
* @dev: The device containing the information
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error.
|
|
|
|
*/
|
2020-11-05 13:32:05 +00:00
|
|
|
int sysinfo_detect(struct udevice *dev);
|
2018-07-31 09:44:11 +00:00
|
|
|
|
|
|
|
/**
|
2020-11-05 13:32:05 +00:00
|
|
|
* sysinfo_get_bool() - Read a specific bool data value that describes the
|
2018-07-31 09:44:11 +00:00
|
|
|
* hardware setup.
|
2020-11-05 13:32:05 +00:00
|
|
|
* @dev: The sysinfo instance to gather the data.
|
2018-07-31 09:44:11 +00:00
|
|
|
* @id: A unique identifier for the bool value to be read.
|
|
|
|
* @val: Pointer to a buffer that receives the value read.
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error.
|
|
|
|
*/
|
2020-11-05 13:32:05 +00:00
|
|
|
int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
|
2018-07-31 09:44:11 +00:00
|
|
|
|
|
|
|
/**
|
2020-11-05 13:32:05 +00:00
|
|
|
* sysinfo_get_int() - Read a specific int data value that describes the
|
2018-07-31 09:44:11 +00:00
|
|
|
* hardware setup.
|
2020-11-05 13:32:05 +00:00
|
|
|
* @dev: The sysinfo instance to gather the data.
|
2018-07-31 09:44:11 +00:00
|
|
|
* @id: A unique identifier for the int value to be read.
|
|
|
|
* @val: Pointer to a buffer that receives the value read.
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error.
|
|
|
|
*/
|
2020-11-05 13:32:05 +00:00
|
|
|
int sysinfo_get_int(struct udevice *dev, int id, int *val);
|
2018-07-31 09:44:11 +00:00
|
|
|
|
|
|
|
/**
|
2020-11-05 13:32:05 +00:00
|
|
|
* sysinfo_get_str() - Read a specific string data value that describes the
|
2018-07-31 09:44:11 +00:00
|
|
|
* hardware setup.
|
2020-11-05 13:32:05 +00:00
|
|
|
* @dev: The sysinfo instance to gather the data.
|
2018-07-31 09:44:11 +00:00
|
|
|
* @id: A unique identifier for the string value to be read.
|
|
|
|
* @size: The size of the buffer to receive the string data.
|
|
|
|
* @val: Pointer to a buffer that receives the value read.
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error.
|
|
|
|
*/
|
2020-11-05 13:32:05 +00:00
|
|
|
int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
|
2018-07-31 09:44:11 +00:00
|
|
|
|
|
|
|
/**
|
2020-11-05 13:32:05 +00:00
|
|
|
* sysinfo_get() - Return the sysinfo device for the sysinfo in question.
|
|
|
|
* @devp: Pointer to structure to receive the sysinfo device.
|
2018-07-31 09:44:11 +00:00
|
|
|
*
|
2020-11-05 13:32:05 +00:00
|
|
|
* Since there can only be at most one sysinfo instance, the API can supply a
|
2018-07-31 09:44:11 +00:00
|
|
|
* function that returns the unique device. This is especially useful for use
|
2020-11-05 13:32:05 +00:00
|
|
|
* in sysinfo files.
|
2018-07-31 09:44:11 +00:00
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error.
|
|
|
|
*/
|
2020-11-05 13:32:05 +00:00
|
|
|
int sysinfo_get(struct udevice **devp);
|
2019-10-22 14:39:19 +00:00
|
|
|
|
|
|
|
/**
|
2020-11-05 13:32:05 +00:00
|
|
|
* sysinfo_get_fit_loadable - Get the name of an image to load from FIT
|
2019-10-22 14:39:19 +00:00
|
|
|
* This function can be used to provide the image names based on runtime
|
|
|
|
* detection. A classic use-case would when DTBOs are used to describe
|
|
|
|
* additionnal daughter cards.
|
|
|
|
*
|
2020-11-05 13:32:05 +00:00
|
|
|
* @dev: The sysinfo instance to gather the data.
|
2019-10-22 14:39:19 +00:00
|
|
|
* @index: Index of the image. Starts at 0 and gets incremented
|
|
|
|
* after each call to this function.
|
|
|
|
* @type: The type of image. For example, "fdt" for DTBs
|
|
|
|
* @strp: A pointer to string. Untouched if the function fails
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ENOENT if no loadable is available else -ve on
|
|
|
|
* error.
|
|
|
|
*/
|
2020-11-05 13:32:05 +00:00
|
|
|
int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
|
|
|
|
const char **strp);
|
2019-10-22 14:39:20 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2020-11-05 13:32:05 +00:00
|
|
|
static inline int sysinfo_detect(struct udevice *dev)
|
2019-10-22 14:39:20 +00:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2020-11-05 13:32:05 +00:00
|
|
|
static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
|
2019-10-22 14:39:20 +00:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2020-11-05 13:32:05 +00:00
|
|
|
static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
|
2019-10-22 14:39:20 +00:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2020-11-05 13:32:05 +00:00
|
|
|
static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
|
|
|
|
char *val)
|
2019-10-22 14:39:20 +00:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2020-11-05 13:32:05 +00:00
|
|
|
static inline int sysinfo_get(struct udevice **devp)
|
2019-10-22 14:39:20 +00:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2020-11-05 13:32:05 +00:00
|
|
|
static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
|
|
|
|
const char *type, const char **strp)
|
2019-10-22 14:39:20 +00:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|