blob: cb0ac1545f7fb43f32dbd7fb3eed6935dc9f14d4 [file] [log] [blame]
Dave Gerlach21e3c212020-07-15 23:39:58 -05001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Test for the SOC uclass
4 *
Nishanth Menona94a4072023-11-01 15:56:03 -05005 * (C) Copyright 2020 - Texas Instruments Incorporated - https://www.ti.com/
Dave Gerlach21e3c212020-07-15 23:39:58 -05006 * Dave Gerlach <d-gerlach@ti.com>
7 */
8
Dave Gerlach21e3c212020-07-15 23:39:58 -05009#include <dm.h>
10#include <dm/test.h>
11#include <dm/uclass-internal.h>
12#include <soc.h>
13#include <test/ut.h>
14
15struct sb_soc_data {
16 unsigned long param;
17};
18
19static int dm_test_soc(struct unit_test_state *uts)
20{
21 struct udevice *dev;
22 char text[128];
23 const struct soc_attr *soc_data;
24 const struct sb_soc_data *match_data;
25
26 static const struct sb_soc_data soc_sandbox1_sr10_data = { 0x91919191 };
27 static const struct sb_soc_data soc_sandbox123_data = { 0x84848484 };
28
29 static const struct soc_attr sb_soc_devices_full[] = {
30 {
31 .family = "SANDBOX0xx",
32 .machine = "SANDBOX012",
33 .revision = "1.0",
34 .data = NULL,
35 },
36 {
37 .family = "SANDBOX1xx",
38 .machine = "SANDBOX107",
39 .revision = "1.0",
40 .data = NULL,
41 },
42 {
43 .family = "SANDBOX1xx",
44 .machine = "SANDBOX123",
45 .revision = "1.0",
46 .data = &soc_sandbox123_data,
47 },
48 {
49 .family = "SANDBOX1xx",
50 .machine = "SANDBOX131",
51 .revision = "2.0",
52 .data = NULL,
53 },
54 { /* sentinel */ }
55 };
56
57 static const struct soc_attr sb_soc_devices_partial[] = {
58 {
59 .family = "SANDBOX0xx",
60 .revision = "1.0",
61 .data = NULL,
62 },
63 {
64 .family = "SANDBOX1xx",
65 .revision = "1.0",
66 .data = &soc_sandbox1_sr10_data,
67 },
68 {
69 .family = "SANDBOX1xx",
70 .revision = "2.0",
71 .data = NULL,
72 },
73 { /* sentinel */ }
74 };
75
76 static const struct soc_attr sb_soc_devices_nomatch[] = {
77 {
78 .family = "SANDBOX0xx",
79 .revision = "1.0",
80 .data = NULL,
81 },
82 {
83 .family = "SANDBOX1xx",
84 .revision = "2.0",
85 .data = NULL,
86 },
87 { /* sentinel */ }
88 };
89
90 ut_assertok(soc_get(&dev));
91
92 ut_assertok(soc_get_machine(dev, text, sizeof(text)));
93 ut_assertok(strcmp(text, "SANDBOX123"));
94
95 ut_assertok(soc_get_family(dev, text, sizeof(text)));
96 ut_assertok(strcmp(text, "SANDBOX1xx"));
97
98 ut_assertok(soc_get_revision(dev, text, sizeof(text)));
99 ut_asserteq_str(text, "1.0");
100
101 soc_data = soc_device_match(sb_soc_devices_full);
102 ut_assert(soc_data);
103
104 match_data = soc_data->data;
105 ut_asserteq(match_data->param, 0x84848484);
106
107 soc_data = soc_device_match(sb_soc_devices_partial);
108 ut_assert(soc_data);
109
110 match_data = soc_data->data;
111 ut_asserteq(match_data->param, 0x91919191);
112
113 soc_data = soc_device_match(sb_soc_devices_nomatch);
114 ut_asserteq_ptr(soc_data, NULL);
115
116 return 0;
117}
118
Simon Glasse180c2b2020-07-28 19:41:12 -0600119DM_TEST(dm_test_soc, UT_TESTF_SCAN_FDT);