~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: 10194d0e14c358b3a1457a29f69452faf5654092 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// SPDX-License-Identifier: GPL-2.0+
/*
 * (C) Copyright 2017
 * Mario Six,  Guntermann & Drunck GmbH, mario.six@gdsys.cc
 */

#define LOG_CATEGORY UCLASS_SYSINFO

#include <common.h>
#include <dm.h>
#include <sysinfo.h>

struct sysinfo_priv {
	bool detected;
};

int sysinfo_get(struct udevice **devp)
{
	int ret = uclass_first_device_err(UCLASS_SYSINFO, devp);

	/*
	 * There is some very dodgy error handling in gazerbeam,
	 * do not return a device on error.
	 */
	if (ret)
		*devp = NULL;
	return ret;
}

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),
};