blob: 10194d0e14c358b3a1457a29f69452faf5654092 [file] [log] [blame]
Simon Glass3a8ee3d2020-11-05 06:32:05 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2017
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5 */
6
Patrick Delaunayb953ec22021-04-27 11:02:19 +02007#define LOG_CATEGORY UCLASS_SYSINFO
8
Simon Glass3a8ee3d2020-11-05 06:32:05 -07009#include <common.h>
10#include <dm.h>
11#include <sysinfo.h>
12
Sean Anderson4d65c6b2021-04-20 10:50:56 -040013struct sysinfo_priv {
14 bool detected;
15};
16
Simon Glass3a8ee3d2020-11-05 06:32:05 -070017int sysinfo_get(struct udevice **devp)
18{
Michal Suchanek58ddb932022-09-25 13:08:16 +020019 int ret = uclass_first_device_err(UCLASS_SYSINFO, devp);
20
21 /*
22 * There is some very dodgy error handling in gazerbeam,
23 * do not return a device on error.
24 */
25 if (ret)
26 *devp = NULL;
27 return ret;
Simon Glass3a8ee3d2020-11-05 06:32:05 -070028}
29
30int sysinfo_detect(struct udevice *dev)
31{
Sean Anderson4d65c6b2021-04-20 10:50:56 -040032 int ret;
33 struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
Simon Glass3a8ee3d2020-11-05 06:32:05 -070034 struct sysinfo_ops *ops = sysinfo_get_ops(dev);
35
36 if (!ops->detect)
37 return -ENOSYS;
38
Sean Anderson4d65c6b2021-04-20 10:50:56 -040039 ret = ops->detect(dev);
40 if (!ret)
41 priv->detected = true;
42
43 return ret;
Simon Glass3a8ee3d2020-11-05 06:32:05 -070044}
45
46int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
47 const char **strp)
48{
Sean Anderson4d65c6b2021-04-20 10:50:56 -040049 struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
Simon Glass3a8ee3d2020-11-05 06:32:05 -070050 struct sysinfo_ops *ops = sysinfo_get_ops(dev);
51
Sean Anderson4d65c6b2021-04-20 10:50:56 -040052 if (!priv->detected)
53 return -EPERM;
54
Simon Glass3a8ee3d2020-11-05 06:32:05 -070055 if (!ops->get_fit_loadable)
56 return -ENOSYS;
57
58 return ops->get_fit_loadable(dev, index, type, strp);
59}
60
61int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
62{
Sean Anderson4d65c6b2021-04-20 10:50:56 -040063 struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
Simon Glass3a8ee3d2020-11-05 06:32:05 -070064 struct sysinfo_ops *ops = sysinfo_get_ops(dev);
65
Sean Anderson4d65c6b2021-04-20 10:50:56 -040066 if (!priv->detected)
67 return -EPERM;
68
Simon Glass3a8ee3d2020-11-05 06:32:05 -070069 if (!ops->get_bool)
70 return -ENOSYS;
71
72 return ops->get_bool(dev, id, val);
73}
74
75int sysinfo_get_int(struct udevice *dev, int id, int *val)
76{
Sean Anderson4d65c6b2021-04-20 10:50:56 -040077 struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
Simon Glass3a8ee3d2020-11-05 06:32:05 -070078 struct sysinfo_ops *ops = sysinfo_get_ops(dev);
79
Sean Anderson4d65c6b2021-04-20 10:50:56 -040080 if (!priv->detected)
81 return -EPERM;
82
Simon Glass3a8ee3d2020-11-05 06:32:05 -070083 if (!ops->get_int)
84 return -ENOSYS;
85
86 return ops->get_int(dev, id, val);
87}
88
89int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val)
90{
Sean Anderson4d65c6b2021-04-20 10:50:56 -040091 struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
Simon Glass3a8ee3d2020-11-05 06:32:05 -070092 struct sysinfo_ops *ops = sysinfo_get_ops(dev);
93
Sean Anderson4d65c6b2021-04-20 10:50:56 -040094 if (!priv->detected)
95 return -EPERM;
96
Simon Glass3a8ee3d2020-11-05 06:32:05 -070097 if (!ops->get_str)
98 return -ENOSYS;
99
100 return ops->get_str(dev, id, size, val);
101}
102
103UCLASS_DRIVER(sysinfo) = {
104 .id = UCLASS_SYSINFO,
105 .name = "sysinfo",
106 .post_bind = dm_scan_fdt_dev,
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400107 .per_device_auto = sizeof(bool),
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700108};