summaryrefslogtreecommitdiff
path: root/drivers/sysinfo
diff options
context:
space:
mode:
authorSean Anderson <sean.anderson@seco.com>2021-04-20 17:50:56 +0300
committerTom Rini <trini@konsulko.com>2021-05-04 14:57:18 +0300
commit4d65c6bcd71ab2a03a5b7fff0ecf22d068597b25 (patch)
treec316ea01cce93a65522e5a08bef090cb01a16e74 /drivers/sysinfo
parenteed0a7a3e6087d038fccea18676e285d9807b644 (diff)
downloadu-boot-4d65c6bcd71ab2a03a5b7fff0ecf22d068597b25.tar.xz
sysinfo: Require that sysinfo_detect be called before other methods
This has the uclass enforce calling detect() before other methods. This allows drivers to cache information in detect() and perform (cheaper) retrieval in the other accessors. This also modifies the only instance where this sequencing was not followed. Signed-off-by: Sean Anderson <sean.anderson@seco.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/sysinfo')
-rw-r--r--drivers/sysinfo/sysinfo-uclass.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/drivers/sysinfo/sysinfo-uclass.c b/drivers/sysinfo/sysinfo-uclass.c
index 6df58fe160..4a660dfd15 100644
--- a/drivers/sysinfo/sysinfo-uclass.c
+++ b/drivers/sysinfo/sysinfo-uclass.c
@@ -8,6 +8,10 @@
#include <dm.h>
#include <sysinfo.h>
+struct sysinfo_priv {
+ bool detected;
+};
+
int sysinfo_get(struct udevice **devp)
{
return uclass_first_device_err(UCLASS_SYSINFO, devp);
@@ -15,19 +19,29 @@ int sysinfo_get(struct udevice **devp)
int sysinfo_detect(struct udevice *dev)
{
+ int ret;
+ struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
struct sysinfo_ops *ops = sysinfo_get_ops(dev);
if (!ops->detect)
return -ENOSYS;
- return ops->detect(dev);
+ ret = ops->detect(dev);
+ if (!ret)
+ priv->detected = true;
+
+ return ret;
}
int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
const char **strp)
{
+ struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
struct sysinfo_ops *ops = sysinfo_get_ops(dev);
+ if (!priv->detected)
+ return -EPERM;
+
if (!ops->get_fit_loadable)
return -ENOSYS;
@@ -36,8 +50,12 @@ int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
{
+ struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
struct sysinfo_ops *ops = sysinfo_get_ops(dev);
+ if (!priv->detected)
+ return -EPERM;
+
if (!ops->get_bool)
return -ENOSYS;
@@ -46,8 +64,12 @@ int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
int sysinfo_get_int(struct udevice *dev, int id, int *val)
{
+ struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
struct sysinfo_ops *ops = sysinfo_get_ops(dev);
+ if (!priv->detected)
+ return -EPERM;
+
if (!ops->get_int)
return -ENOSYS;
@@ -56,8 +78,12 @@ int sysinfo_get_int(struct udevice *dev, int id, int *val)
int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val)
{
+ struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
struct sysinfo_ops *ops = sysinfo_get_ops(dev);
+ if (!priv->detected)
+ return -EPERM;
+
if (!ops->get_str)
return -ENOSYS;
@@ -68,4 +94,5 @@ UCLASS_DRIVER(sysinfo) = {
.id = UCLASS_SYSINFO,
.name = "sysinfo",
.post_bind = dm_scan_fdt_dev,
+ .per_device_auto = sizeof(bool),
};