blob: 744cdda2e187501847eae0b3180e1ba359e81152 [file] [log] [blame]
Dave Gerlach50a6c082020-07-15 23:39:57 -05001// SPDX-License-Identifier: GPL-2.0+
2/*
Nishanth Menoneaa39c62023-11-01 15:56:03 -05003 * (C) Copyright 2020 - Texas Instruments Incorporated - https://www.ti.com/
Dave Gerlach50a6c082020-07-15 23:39:57 -05004 * Dave Gerlach <d-gerlach@ti.com>
5 */
6
Patrick Delaunay81313352021-04-27 11:02:19 +02007#define LOG_CATEGORY UCLASS_SOC
8
Dave Gerlach50a6c082020-07-15 23:39:57 -05009#include <soc.h>
10#include <dm.h>
11#include <errno.h>
12#include <dm/lists.h>
13#include <dm/root.h>
14
15int soc_get(struct udevice **devp)
16{
17 return uclass_first_device_err(UCLASS_SOC, devp);
18}
19
20int soc_get_machine(struct udevice *dev, char *buf, int size)
21{
22 struct soc_ops *ops = soc_get_ops(dev);
23
24 if (!ops->get_machine)
25 return -ENOSYS;
26
27 return ops->get_machine(dev, buf, size);
28}
29
30int soc_get_family(struct udevice *dev, char *buf, int size)
31{
32 struct soc_ops *ops = soc_get_ops(dev);
33
34 if (!ops->get_family)
35 return -ENOSYS;
36
37 return ops->get_family(dev, buf, size);
38}
39
40int soc_get_revision(struct udevice *dev, char *buf, int size)
41{
42 struct soc_ops *ops = soc_get_ops(dev);
43
44 if (!ops->get_revision)
45 return -ENOSYS;
46
47 return ops->get_revision(dev, buf, size);
48}
49
50const struct soc_attr *
51soc_device_match(const struct soc_attr *matches)
52{
53 bool match;
54 struct udevice *soc;
55 char str[SOC_MAX_STR_SIZE];
56
57 if (!matches)
58 return NULL;
59
60 if (soc_get(&soc))
61 return NULL;
62
63 while (1) {
64 if (!(matches->machine || matches->family ||
65 matches->revision))
66 break;
67
68 match = true;
69
70 if (matches->machine) {
71 if (!soc_get_machine(soc, str, SOC_MAX_STR_SIZE)) {
72 if (strcmp(matches->machine, str))
73 match = false;
74 }
75 }
76
77 if (matches->family) {
78 if (!soc_get_family(soc, str, SOC_MAX_STR_SIZE)) {
79 if (strcmp(matches->family, str))
80 match = false;
81 }
82 }
83
84 if (matches->revision) {
85 if (!soc_get_revision(soc, str, SOC_MAX_STR_SIZE)) {
86 if (strcmp(matches->revision, str))
87 match = false;
88 }
89 }
90
91 if (match)
92 return matches;
93
94 matches++;
95 }
96
97 return NULL;
98}
99
100UCLASS_DRIVER(soc) = {
101 .id = UCLASS_SOC,
102 .name = "soc",
103};