1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2017
4  * Mario Six,  Guntermann & Drunck GmbH, mario.six@gdsys.cc
5  */
6 
7 #include <common.h>
8 #include <dm.h>
9 #include <sysinfo.h>
10 
sysinfo_get(struct udevice ** devp)11 int sysinfo_get(struct udevice **devp)
12 {
13 	return uclass_first_device_err(UCLASS_SYSINFO, devp);
14 }
15 
sysinfo_detect(struct udevice * dev)16 int sysinfo_detect(struct udevice *dev)
17 {
18 	struct sysinfo_ops *ops = sysinfo_get_ops(dev);
19 
20 	if (!ops->detect)
21 		return -ENOSYS;
22 
23 	return ops->detect(dev);
24 }
25 
sysinfo_get_fit_loadable(struct udevice * dev,int index,const char * type,const char ** strp)26 int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
27 			     const char **strp)
28 {
29 	struct sysinfo_ops *ops = sysinfo_get_ops(dev);
30 
31 	if (!ops->get_fit_loadable)
32 		return -ENOSYS;
33 
34 	return ops->get_fit_loadable(dev, index, type, strp);
35 }
36 
sysinfo_get_bool(struct udevice * dev,int id,bool * val)37 int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
38 {
39 	struct sysinfo_ops *ops = sysinfo_get_ops(dev);
40 
41 	if (!ops->get_bool)
42 		return -ENOSYS;
43 
44 	return ops->get_bool(dev, id, val);
45 }
46 
sysinfo_get_int(struct udevice * dev,int id,int * val)47 int sysinfo_get_int(struct udevice *dev, int id, int *val)
48 {
49 	struct sysinfo_ops *ops = sysinfo_get_ops(dev);
50 
51 	if (!ops->get_int)
52 		return -ENOSYS;
53 
54 	return ops->get_int(dev, id, val);
55 }
56 
sysinfo_get_str(struct udevice * dev,int id,size_t size,char * val)57 int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val)
58 {
59 	struct sysinfo_ops *ops = sysinfo_get_ops(dev);
60 
61 	if (!ops->get_str)
62 		return -ENOSYS;
63 
64 	return ops->get_str(dev, id, size, val);
65 }
66 
67 UCLASS_DRIVER(sysinfo) = {
68 	.id		= UCLASS_SYSINFO,
69 	.name		= "sysinfo",
70 	.post_bind	= dm_scan_fdt_dev,
71 };
72