]>
Commit | Line | Data |
---|---|---|
6d3b82df DG |
1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | /* | |
a94a4071 | 3 | * (C) Copyright 2020 - Texas Instruments Incorporated - https://www.ti.com/ |
6d3b82df DG |
4 | * Dave Gerlach <[email protected]> |
5 | */ | |
6 | ||
b953ec2b PD |
7 | #define LOG_CATEGORY UCLASS_SOC |
8 | ||
6d3b82df DG |
9 | #include <soc.h> |
10 | #include <dm.h> | |
11 | #include <errno.h> | |
12 | #include <dm/lists.h> | |
13 | #include <dm/root.h> | |
14 | ||
15 | int soc_get(struct udevice **devp) | |
16 | { | |
17 | return uclass_first_device_err(UCLASS_SOC, devp); | |
18 | } | |
19 | ||
20 | int 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 | ||
30 | int 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 | ||
40 | int 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 | ||
50 | const struct soc_attr * | |
51 | soc_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 | ||
100 | UCLASS_DRIVER(soc) = { | |
101 | .id = UCLASS_SOC, | |
102 | .name = "soc", | |
103 | }; |