1 /*
2 * Copyright (c) 2021 Teslabs Engineering S.L.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6 #include <zephyr/drivers/pinctrl.h>
7 #include <zephyr/ztest.h>
8
9 /* pin configuration for test device */
10 #define TEST_DEVICE DT_NODELABEL(test_device)
11 PINCTRL_DT_DEV_CONFIG_DECLARE(TEST_DEVICE);
12 static const struct pinctrl_dev_config *pcfg = PINCTRL_DT_DEV_CONFIG_GET(TEST_DEVICE);
13
ZTEST(pinctrl_gd32,test_dt_extract)14 ZTEST(pinctrl_gd32, test_dt_extract)
15 {
16 const struct pinctrl_state *scfg;
17 pinctrl_soc_pin_t pin;
18
19 zassert_equal(pcfg->state_cnt, 1U);
20
21 scfg = &pcfg->states[0];
22
23 zassert_equal(scfg->id, PINCTRL_STATE_DEFAULT);
24 zassert_equal(scfg->pin_cnt, 14U);
25
26 pin = scfg->pins[0];
27 zassert_equal(GD32_PORT_GET(pin), 0);
28 zassert_equal(GD32_PIN_GET(pin), 0);
29 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_ANALOG);
30 zassert_equal(GD32_REMAP_GET(pin), GD32_NORMP);
31
32 pin = scfg->pins[1];
33 zassert_equal(GD32_PORT_GET(pin), 1);
34 zassert_equal(GD32_PIN_GET(pin), 1);
35 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_ALTERNATE);
36 zassert_equal(GD32_REMAP_GET(pin), GD32_NORMP);
37 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_2MHZ);
38
39 pin = scfg->pins[2];
40 zassert_equal(GD32_PORT_GET(pin), 2);
41 zassert_equal(GD32_PIN_GET(pin), 2);
42 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_GPIO_IN);
43 zassert_equal(GD32_REMAP_GET(pin), GD32_NORMP);
44 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
45 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
46
47 pin = scfg->pins[3];
48 zassert_equal(GD32_PORT_GET(pin), 0);
49 zassert_equal(GD32_PIN_GET(pin), 3);
50 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_GPIO_IN);
51 zassert_equal(GD32_REMAP_REG_GET(GD32_REMAP_GET(pin)), 0);
52 zassert_equal(GD32_REMAP_POS_GET(GD32_REMAP_GET(pin)), 0);
53 zassert_equal(GD32_REMAP_MSK_GET(GD32_REMAP_GET(pin)), 0x1);
54 zassert_equal(GD32_REMAP_VAL_GET(GD32_REMAP_GET(pin)), 1);
55 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
56 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
57
58 pin = scfg->pins[4];
59 zassert_equal(GD32_PORT_GET(pin), 1);
60 zassert_equal(GD32_PIN_GET(pin), 4);
61 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_ALTERNATE);
62 zassert_equal(GD32_REMAP_REG_GET(GD32_REMAP_GET(pin)), 0);
63 zassert_equal(GD32_REMAP_POS_GET(GD32_REMAP_GET(pin)), 0);
64 zassert_equal(GD32_REMAP_MSK_GET(GD32_REMAP_GET(pin)), 0x1);
65 zassert_equal(GD32_REMAP_VAL_GET(GD32_REMAP_GET(pin)), 1);
66 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_2MHZ);
67
68 pin = scfg->pins[5];
69 zassert_equal(GD32_PORT_GET(pin), 2);
70 zassert_equal(GD32_PIN_GET(pin), 5);
71 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_GPIO_IN);
72 zassert_equal(GD32_REMAP_GET(pin), GD32_NORMP);
73 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
74 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
75
76 pin = scfg->pins[6];
77 zassert_equal(GD32_PORT_GET(pin), 0);
78 zassert_equal(GD32_PIN_GET(pin), 6);
79 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_GPIO_IN);
80 zassert_equal(GD32_REMAP_GET(pin), GD32_NORMP);
81 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
82 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_OD);
83
84 pin = scfg->pins[7];
85 zassert_equal(GD32_PORT_GET(pin), 1);
86 zassert_equal(GD32_PIN_GET(pin), 7);
87 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_GPIO_IN);
88 zassert_equal(GD32_REMAP_GET(pin), GD32_NORMP);
89 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
90 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
91
92 pin = scfg->pins[8];
93 zassert_equal(GD32_PORT_GET(pin), 2);
94 zassert_equal(GD32_PIN_GET(pin), 8);
95 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_GPIO_IN);
96 zassert_equal(GD32_REMAP_GET(pin), GD32_NORMP);
97 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_PULLUP);
98 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
99
100 pin = scfg->pins[9];
101 zassert_equal(GD32_PORT_GET(pin), 0);
102 zassert_equal(GD32_PIN_GET(pin), 9);
103 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_GPIO_IN);
104 zassert_equal(GD32_REMAP_GET(pin), GD32_NORMP);
105 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_PULLDOWN);
106 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
107
108 pin = scfg->pins[10];
109 zassert_equal(GD32_PORT_GET(pin), 1);
110 zassert_equal(GD32_PIN_GET(pin), 10);
111 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_ALTERNATE);
112 zassert_equal(GD32_REMAP_GET(pin), GD32_NORMP);
113 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_2MHZ);
114
115 pin = scfg->pins[11];
116 zassert_equal(GD32_PORT_GET(pin), 2);
117 zassert_equal(GD32_PIN_GET(pin), 11);
118 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_ALTERNATE);
119 zassert_equal(GD32_REMAP_GET(pin), GD32_NORMP);
120 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_10MHZ);
121
122 pin = scfg->pins[12];
123 zassert_equal(GD32_PORT_GET(pin), 0);
124 zassert_equal(GD32_PIN_GET(pin), 12);
125 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_ALTERNATE);
126 zassert_equal(GD32_REMAP_GET(pin), GD32_NORMP);
127 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_50MHZ);
128
129 pin = scfg->pins[13];
130 zassert_equal(GD32_PORT_GET(pin), 1);
131 zassert_equal(GD32_PIN_GET(pin), 13);
132 zassert_equal(GD32_MODE_GET(pin), GD32_MODE_ALTERNATE);
133 zassert_equal(GD32_REMAP_GET(pin), GD32_NORMP);
134 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_MAX);
135 }
136
137 ZTEST_SUITE(pinctrl_gd32, NULL, NULL, NULL, NULL, NULL);
138