mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-08 06:04:34 +00:00
4d65c6bcd7
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>
98 lines
1.9 KiB
C
98 lines
1.9 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* (C) Copyright 2017
|
|
* Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
|
|
*/
|
|
|
|
#include <common.h>
|
|
#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);
|
|
}
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
return ops->get_fit_loadable(dev, index, type, strp);
|
|
}
|
|
|
|
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;
|
|
|
|
return ops->get_bool(dev, id, 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;
|
|
|
|
return ops->get_int(dev, id, 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;
|
|
|
|
return ops->get_str(dev, id, size, val);
|
|
}
|
|
|
|
UCLASS_DRIVER(sysinfo) = {
|
|
.id = UCLASS_SYSINFO,
|
|
.name = "sysinfo",
|
|
.post_bind = dm_scan_fdt_dev,
|
|
.per_device_auto = sizeof(bool),
|
|
};
|