summaryrefslogtreecommitdiff
path: root/drivers/soc/soc-uclass.c
blob: c32d647864f28c59b1384af6dd031ee7fa7bf45d (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
// SPDX-License-Identifier: GPL-2.0+
/*
 * (C) Copyright 2020 - Texas Instruments Incorporated - http://www.ti.com/
 *	Dave Gerlach <d-gerlach@ti.com>
 */

#include <common.h>
#include <soc.h>
#include <dm.h>
#include <errno.h>
#include <dm/lists.h>
#include <dm/root.h>

int soc_get(struct udevice **devp)
{
	return uclass_first_device_err(UCLASS_SOC, devp);
}

int soc_get_machine(struct udevice *dev, char *buf, int size)
{
	struct soc_ops *ops = soc_get_ops(dev);

	if (!ops->get_machine)
		return -ENOSYS;

	return ops->get_machine(dev, buf, size);
}

int soc_get_family(struct udevice *dev, char *buf, int size)
{
	struct soc_ops *ops = soc_get_ops(dev);

	if (!ops->get_family)
		return -ENOSYS;

	return ops->get_family(dev, buf, size);
}

int soc_get_revision(struct udevice *dev, char *buf, int size)
{
	struct soc_ops *ops = soc_get_ops(dev);

	if (!ops->get_revision)
		return -ENOSYS;

	return ops->get_revision(dev, buf, size);
}

const struct soc_attr *
soc_device_match(const struct soc_attr *matches)
{
	bool match;
	struct udevice *soc;
	char str[SOC_MAX_STR_SIZE];

	if (!matches)
		return NULL;

	if (soc_get(&soc))
		return NULL;

	while (1) {
		if (!(matches->machine || matches->family ||
		      matches->revision))
			break;

		match = true;

		if (matches->machine) {
			if (!soc_get_machine(soc, str, SOC_MAX_STR_SIZE)) {
				if (strcmp(matches->machine, str))
					match = false;
			}
		}

		if (matches->family) {
			if (!soc_get_family(soc, str, SOC_MAX_STR_SIZE)) {
				if (strcmp(matches->family, str))
					match = false;
			}
		}

		if (matches->revision) {
			if (!soc_get_revision(soc, str, SOC_MAX_STR_SIZE)) {
				if (strcmp(matches->revision, str))
					match = false;
			}
		}

		if (match)
			return matches;

		matches++;
	}

	return NULL;
}

UCLASS_DRIVER(soc) = {
	.id		= UCLASS_SOC,
	.name		= "soc",
};