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