blob: c5cc3cb9596bce525293fb8272c9733d674f1258 [file] [log] [blame]
Simon Glass458b66a2020-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 Delaunay81313352021-04-27 11:02:19 +02007#define LOG_CATEGORY UCLASS_SYSINFO
8
Simon Glass458b66a2020-11-05 06:32:05 -07009#include <common.h>
10#include <dm.h>
11#include <sysinfo.h>
12
Sean Anderson6ccf10a2021-04-20 10:50:56 -040013struct sysinfo_priv {
14 bool detected;
15};
16
Simon Glass458b66a2020-11-05 06:32:05 -070017int sysinfo_get(struct udevice **devp)
18{
19 return uclass_first_device_err(UCLASS_SYSINFO, devp);
20}
21
22int sysinfo_detect(struct udevice *dev)
23{
Sean Anderson6ccf10a2021-04-20 10:50:56 -040024 int ret;
25 struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
Simon Glass458b66a2020-11-05 06:32:05 -070026 struct sysinfo_ops *ops = sysinfo_get_ops(dev);
27
28 if (!ops->detect)
29 return -ENOSYS;
30
Sean Anderson6ccf10a2021-04-20 10:50:56 -040031 ret = ops->detect(dev);
32 if (!ret)
33 priv->detected = true;
34
35 return ret;
Simon Glass458b66a2020-11-05 06:32:05 -070036}
37
38int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
39 const char **strp)
40{
Sean Anderson6ccf10a2021-04-20 10:50:56 -040041 struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
Simon Glass458b66a2020-11-05 06:32:05 -070042 struct sysinfo_ops *ops = sysinfo_get_ops(dev);
43
Sean Anderson6ccf10a2021-04-20 10:50:56 -040044 if (!priv->detected)
45 return -EPERM;
46
Simon Glass458b66a2020-11-05 06:32:05 -070047 if (!ops->get_fit_loadable)
48 return -ENOSYS;
49
50 return ops->get_fit_loadable(dev, index, type, strp);
51}
52
53int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
54{
Sean Anderson6ccf10a2021-04-20 10:50:56 -040055 struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
Simon Glass458b66a2020-11-05 06:32:05 -070056 struct sysinfo_ops *ops = sysinfo_get_ops(dev);
57
Sean Anderson6ccf10a2021-04-20 10:50:56 -040058 if (!priv->detected)
59 return -EPERM;
60
Simon Glass458b66a2020-11-05 06:32:05 -070061 if (!ops->get_bool)
62 return -ENOSYS;
63
64 return ops->get_bool(dev, id, val);
65}
66
67int sysinfo_get_int(struct udevice *dev, int id, int *val)
68{
Sean Anderson6ccf10a2021-04-20 10:50:56 -040069 struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
Simon Glass458b66a2020-11-05 06:32:05 -070070 struct sysinfo_ops *ops = sysinfo_get_ops(dev);
71
Sean Anderson6ccf10a2021-04-20 10:50:56 -040072 if (!priv->detected)
73 return -EPERM;
74
Simon Glass458b66a2020-11-05 06:32:05 -070075 if (!ops->get_int)
76 return -ENOSYS;
77
78 return ops->get_int(dev, id, val);
79}
80
81int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val)
82{
Sean Anderson6ccf10a2021-04-20 10:50:56 -040083 struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
Simon Glass458b66a2020-11-05 06:32:05 -070084 struct sysinfo_ops *ops = sysinfo_get_ops(dev);
85
Sean Anderson6ccf10a2021-04-20 10:50:56 -040086 if (!priv->detected)
87 return -EPERM;
88
Simon Glass458b66a2020-11-05 06:32:05 -070089 if (!ops->get_str)
90 return -ENOSYS;
91
92 return ops->get_str(dev, id, size, val);
93}
94
95UCLASS_DRIVER(sysinfo) = {
96 .id = UCLASS_SYSINFO,
97 .name = "sysinfo",
98 .post_bind = dm_scan_fdt_dev,
Sean Anderson6ccf10a2021-04-20 10:50:56 -040099 .per_device_auto = sizeof(bool),
Simon Glass458b66a2020-11-05 06:32:05 -0700100};