1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <ddk/platform-defs.h>
6 
7 #include "test.h"
8 #include "test-resources.h"
9 
10 namespace board_test {
11 namespace {
12 
13 constexpr pbus_gpio_t child_1_gpios[] = {
14     {
15         .gpio = TEST_GPIO_1,
16     },
17 };
18 
19 constexpr pbus_gpio_t child_2_gpios[] = {
20     {
21         .gpio = TEST_GPIO_2,
22     },
23     {
24         .gpio = TEST_GPIO_3,
25     },
26 };
27 
28 constexpr pbus_gpio_t child_3_gpios[] = {
29     {
30         .gpio = TEST_GPIO_4,
31     },
32 };
33 
34 } // namespace
35 
TestInit()36 zx_status_t TestBoard::TestInit() {
37     pbus_dev_t child_1_kids[2] = {};
38     // Resources for child-2
39     child_1_kids[0].gpio_list = child_2_gpios;
40     child_1_kids[0].gpio_count = countof(child_2_gpios);
41 
42     // Resources for child-3
43     child_1_kids[1].gpio_list = child_3_gpios;
44     child_1_kids[1].gpio_count = countof(child_3_gpios);
45 
46     pbus_dev_t parent_kids[1] = {};
47     // Resources for child-1
48     parent_kids[0].gpio_list = child_1_gpios;
49     parent_kids[0].gpio_count = countof(child_1_gpios);
50     parent_kids[0].child_list = child_1_kids;
51     parent_kids[0].child_count = countof(child_1_kids);
52 
53     pbus_dev_t test_dev = {};
54     test_dev.name = "test-parent";
55     test_dev.vid = PDEV_VID_TEST;
56     test_dev.pid = PDEV_PID_PBUS_TEST;
57     test_dev.did = PDEV_DID_TEST_PARENT;
58     test_dev.child_list = parent_kids;
59     test_dev.child_count = countof(parent_kids);
60 
61     return pbus_.DeviceAdd(&test_dev);
62 }
63 
64 } // namespace board_test
65