aboutsummaryrefslogtreecommitdiff
path: root/test/dm/pinmux.c
blob: 6880b2d2cd9c970f542effdd66fc69a75da9c9eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
 */

#include <common.h>
#include <dm.h>
#include <dm/pinctrl.h>
#include <dm/test.h>
#include <test/ut.h>

static char buf[64];
#define test_muxing(selector, expected) do { \
	ut_assertok(pinctrl_get_pin_muxing(dev, selector, buf, sizeof(buf))); \
	ut_asserteq_str(expected, (char *)&buf); \
} while (0)

#define test_muxing_regaddr(selector, regaddr, expected) do { \
	char estr[64] = { 0 }; \
	if (IS_ENABLED(CONFIG_PHYS_64BIT)) \
		snprintf(estr, sizeof(estr), "0x%016llx %s", (u64)regaddr, expected); \
	else \
		snprintf(estr, sizeof(estr), "0x%08x %s", (u32)regaddr, expected); \
	ut_assertok(pinctrl_get_pin_muxing(dev, selector, buf, sizeof(buf))); \
	ut_asserteq_str(estr, (char *)&buf); \
} while (0)

#define test_name(selector, expected) do { \
	ut_assertok(pinctrl_get_pin_name(dev, selector, buf, sizeof(buf))); \
	ut_asserteq_str(expected, (char *)&buf); \
} while (0)

static int dm_test_pinmux(struct unit_test_state *uts)
{
	struct udevice *dev;

	ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL, "pinctrl", &dev));
	test_muxing(0, "UART TX.");
	test_muxing(1, "UART RX.");
	test_muxing(2, "I2S SCK.");
	test_muxing(3, "I2S SD.");
	test_muxing(4, "I2S WS.");
	test_muxing(5, "GPIO0 bias-pull-up input-disable.");
	test_muxing(6, "GPIO1 drive-open-drain.");
	test_muxing(7, "GPIO2 bias-pull-down input-enable.");
	test_muxing(8, "GPIO3 bias-disable.");

	ut_assertok(pinctrl_select_state(dev, "alternate"));
	test_muxing(0, "I2C SCL drive-open-drain.");
	test_muxing(1, "I2C SDA drive-open-drain.");
	test_muxing(2, "SPI SCLK.");
	test_muxing(3, "SPI MOSI.");
	test_muxing(4, "SPI MISO.");
	test_muxing(5, "SPI CS0.");
	test_muxing(6, "SPI CS1.");
	test_muxing(7, "GPIO2 bias-pull-down input-enable.");
	test_muxing(8, "GPIO3 bias-disable.");

	ut_assertok(pinctrl_select_state(dev, "0"));
	test_muxing(0, "I2C SCL drive-open-drain.");
	test_muxing(1, "I2C SDA drive-open-drain.");
	test_muxing(2, "I2S SCK.");
	test_muxing(3, "I2S SD.");
	test_muxing(4, "I2S WS.");
	test_muxing(5, "GPIO0 bias-pull-up input-disable.");
	test_muxing(6, "GPIO1 drive-open-drain.");
	test_muxing(7, "GPIO2 bias-pull-down input-enable.");
	test_muxing(8, "GPIO3 bias-disable.");

	return 0;
}

DM_TEST(dm_test_pinmux, UT_TESTF_SCAN_FDT);

static int dm_test_pinctrl_single(struct unit_test_state *uts)
{
	struct udevice *dev;
	int ret;

	ret = uclass_get_device_by_name(UCLASS_PINCTRL,
					"pinctrl-single-no-width", &dev);
	ut_asserteq(-EINVAL, ret);
	ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &dev));
	ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial", &dev));
	ut_assertok(uclass_get_device_by_name(UCLASS_SPI, "spi@0", &dev));
	ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL,
					      "pinctrl-single-pins", &dev));
	ut_asserteq(142, pinctrl_get_pins_count(dev));
	test_name(0, "PIN0");
	test_name(141, "PIN141");
	test_name(142, "Error");
	test_muxing_regaddr(0, 0x0, "0x00000000 UNCLAIMED");
	test_muxing_regaddr(18, 0x48, "0x00000006 pinmux_pwm_pins");
	test_muxing_regaddr(28, 0x70, "0x00000030 pinmux_uart0_pins");
	test_muxing_regaddr(29, 0x74, "0x00000000 pinmux_uart0_pins");
	test_muxing_regaddr(100, 0x190, "0x0000000c pinmux_spi0_pins");
	test_muxing_regaddr(101, 0x194, "0x0000000c pinmux_spi0_pins");
	test_muxing_regaddr(102, 0x198, "0x00000023 pinmux_spi0_pins");
	test_muxing_regaddr(103, 0x19c, "0x0000000c pinmux_spi0_pins");
	ret = pinctrl_get_pin_muxing(dev, 142, buf, sizeof(buf));
	ut_asserteq(-EINVAL, ret);
	ut_assertok(uclass_get_device_by_name(UCLASS_I2C, "i2c@0", &dev));
	ut_assertok(uclass_get_device_by_name(UCLASS_VIDEO, "lcd", &dev));
	ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL,
					      "pinctrl-single-bits", &dev));
	ut_asserteq(160, pinctrl_get_pins_count(dev));
	test_name(0, "PIN0");
	test_name(159, "PIN159");
	test_name(160, "Error");
	test_muxing_regaddr(0, 0x0, "0x00000000 UNCLAIMED");
	test_muxing_regaddr(34, 0x10, "0x00000200 pinmux_i2c0_pins");
	test_muxing_regaddr(35, 0x10, "0x00002000 pinmux_i2c0_pins");
	test_muxing_regaddr(130, 0x40, "0x00000200 pinmux_lcd_pins");
	test_muxing_regaddr(131, 0x40, "0x00002000 pinmux_lcd_pins");
	test_muxing_regaddr(132, 0x40, "0x00020000 pinmux_lcd_pins");
	test_muxing_regaddr(133, 0x40, "0x00200000 pinmux_lcd_pins");
	test_muxing_regaddr(134, 0x40, "0x02000000 pinmux_lcd_pins");
	test_muxing_regaddr(135, 0x40, "0x20000000 pinmux_lcd_pins");
	test_muxing_regaddr(136, 0x44, "0x00000002 pinmux_lcd_pins");
	test_muxing_regaddr(137, 0x44, "0x00000020 pinmux_lcd_pins");
	test_muxing_regaddr(138, 0x44, "0x00000200 pinmux_lcd_pins");
	test_muxing_regaddr(139, 0x44, "0x00002000 pinmux_lcd_pins");
	test_muxing_regaddr(140, 0x44, "0x00020000 pinmux_lcd_pins");
	test_muxing_regaddr(141, 0x44, "0x00200000 pinmux_lcd_pins");
	test_muxing_regaddr(142, 0x44, "0x02000000 pinmux_lcd_pins");
	test_muxing_regaddr(143, 0x44, "0x20000000 pinmux_lcd_pins");
	test_muxing_regaddr(144, 0x48, "0x00000002 pinmux_lcd_pins");
	test_muxing_regaddr(145, 0x48, "0x00000020 pinmux_lcd_pins");
	test_muxing_regaddr(146, 0x48, "0x00000000 UNCLAIMED");
	test_muxing_regaddr(147, 0x48, "0x00000000 UNCLAIMED");
	test_muxing_regaddr(148, 0x48, "0x00000000 UNCLAIMED");
	test_muxing_regaddr(149, 0x48, "0x00000000 UNCLAIMED");
	test_muxing_regaddr(150, 0x48, "0x02000000 pinmux_lcd_pins");
	test_muxing_regaddr(151, 0x48, "0x00000000 UNCLAIMED");
	test_muxing_regaddr(152, 0x4c, "0x00000002 pinmux_lcd_pins");
	test_muxing_regaddr(153, 0x4c, "0x00000020 pinmux_lcd_pins");
	test_muxing_regaddr(154, 0x4c, "0x00000000 UNCLAIMED");
	test_muxing_regaddr(155, 0x4c, "0x00000000 UNCLAIMED");
	test_muxing_regaddr(156, 0x4c, "0x00000000 UNCLAIMED");
	test_muxing_regaddr(157, 0x4c, "0x00000000 UNCLAIMED");
	test_muxing_regaddr(158, 0x4c, "0x02000000 pinmux_lcd_pins");
	test_muxing_regaddr(159, 0x4c, "0x00000000 UNCLAIMED");
	ret = pinctrl_get_pin_muxing(dev, 160, buf, sizeof(buf));
	ut_asserteq(-EINVAL, ret);
	return 0;
}

DM_TEST(dm_test_pinctrl_single, UT_TESTF_SCAN_FDT);