blob: 265df4ccb9791831d2788dbecf69bc0d61237145 [file] [log] [blame]
Sean Anderson7f0f1802020-09-14 11:01:57 -04001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
4 */
5
6#include <common.h>
7#include <dm.h>
8#include <dm/pinctrl.h>
9#include <dm/test.h>
10#include <test/ut.h>
11
Dario Binacchi55322622021-04-11 09:39:50 +020012static char buf[64];
Sean Anderson7f0f1802020-09-14 11:01:57 -040013#define test_muxing(selector, expected) do { \
14 ut_assertok(pinctrl_get_pin_muxing(dev, selector, buf, sizeof(buf))); \
15 ut_asserteq_str(expected, (char *)&buf); \
16} while (0)
17
Dario Binacchi55322622021-04-11 09:39:50 +020018#define test_name(selector, expected) do { \
19 ut_assertok(pinctrl_get_pin_name(dev, selector, buf, sizeof(buf))); \
20 ut_asserteq_str(expected, (char *)&buf); \
21} while (0)
22
23static int dm_test_pinmux(struct unit_test_state *uts)
24{
25 struct udevice *dev;
26
Sean Anderson7f0f1802020-09-14 11:01:57 -040027 ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL, "pinctrl", &dev));
28 test_muxing(0, "UART TX.");
29 test_muxing(1, "UART RX.");
30 test_muxing(2, "I2S SCK.");
31 test_muxing(3, "I2S SD.");
32 test_muxing(4, "I2S WS.");
33 test_muxing(5, "GPIO0 bias-pull-up input-disable.");
34 test_muxing(6, "GPIO1 drive-open-drain.");
35 test_muxing(7, "GPIO2 bias-pull-down input-enable.");
36 test_muxing(8, "GPIO3 bias-disable.");
37
38 ut_assertok(pinctrl_select_state(dev, "alternate"));
39 test_muxing(0, "I2C SCL drive-open-drain.");
40 test_muxing(1, "I2C SDA drive-open-drain.");
41 test_muxing(2, "SPI SCLK.");
42 test_muxing(3, "SPI MOSI.");
43 test_muxing(4, "SPI MISO.");
44 test_muxing(5, "SPI CS0.");
45 test_muxing(6, "SPI CS1.");
46 test_muxing(7, "GPIO2 bias-pull-down input-enable.");
47 test_muxing(8, "GPIO3 bias-disable.");
48
49 ut_assertok(pinctrl_select_state(dev, "0"));
50 test_muxing(0, "I2C SCL drive-open-drain.");
51 test_muxing(1, "I2C SDA drive-open-drain.");
52 test_muxing(2, "I2S SCK.");
53 test_muxing(3, "I2S SD.");
54 test_muxing(4, "I2S WS.");
55 test_muxing(5, "GPIO0 bias-pull-up input-disable.");
56 test_muxing(6, "GPIO1 drive-open-drain.");
57 test_muxing(7, "GPIO2 bias-pull-down input-enable.");
58 test_muxing(8, "GPIO3 bias-disable.");
59
60 return 0;
61}
Dario Binacchi55322622021-04-11 09:39:50 +020062
Sean Anderson7f0f1802020-09-14 11:01:57 -040063DM_TEST(dm_test_pinmux, UT_TESTF_SCAN_FDT);
Dario Binacchi55322622021-04-11 09:39:50 +020064
65static int dm_test_pinctrl_single(struct unit_test_state *uts)
66{
67 struct udevice *dev;
68 int ret;
69
70 ret = uclass_get_device_by_name(UCLASS_PINCTRL,
71 "pinctrl-single-no-width", &dev);
72 ut_asserteq(-EINVAL, ret);
73 ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &dev));
74 ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial", &dev));
75 ut_assertok(uclass_get_device_by_name(UCLASS_SPI, "spi@0", &dev));
76 ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL,
77 "pinctrl-single-pins", &dev));
78 ut_asserteq(142, pinctrl_get_pins_count(dev));
79 test_name(0, "PIN0");
80 test_name(141, "PIN141");
81 test_name(142, "Error");
82 test_muxing(0, "0x00000000 0x00000000 UNCLAIMED");
83 test_muxing(18, "0x00000048 0x00000006 pinmux_pwm_pins");
84 test_muxing(28, "0x00000070 0x00000030 pinmux_uart0_pins");
85 test_muxing(29, "0x00000074 0x00000000 pinmux_uart0_pins");
86 test_muxing(100, "0x00000190 0x0000000c pinmux_spi0_pins");
87 test_muxing(101, "0x00000194 0x0000000c pinmux_spi0_pins");
88 test_muxing(102, "0x00000198 0x00000023 pinmux_spi0_pins");
89 test_muxing(103, "0x0000019c 0x0000000c pinmux_spi0_pins");
90 ret = pinctrl_get_pin_muxing(dev, 142, buf, sizeof(buf));
91 ut_asserteq(-EINVAL, ret);
92 ut_assertok(uclass_get_device_by_name(UCLASS_I2C, "i2c@0", &dev));
93 ut_assertok(uclass_get_device_by_name(UCLASS_VIDEO, "lcd", &dev));
94 ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL,
95 "pinctrl-single-bits", &dev));
96 ut_asserteq(160, pinctrl_get_pins_count(dev));
97 test_name(0, "PIN0");
98 test_name(159, "PIN159");
99 test_name(160, "Error");
100 test_muxing(0, "0x00000000 0x00000000 UNCLAIMED");
101 test_muxing(34, "0x00000010 0x00000200 pinmux_i2c0_pins");
102 test_muxing(35, "0x00000010 0x00002000 pinmux_i2c0_pins");
103 test_muxing(130, "0x00000040 0x00000200 pinmux_lcd_pins");
104 test_muxing(131, "0x00000040 0x00002000 pinmux_lcd_pins");
105 test_muxing(132, "0x00000040 0x00020000 pinmux_lcd_pins");
106 test_muxing(133, "0x00000040 0x00200000 pinmux_lcd_pins");
107 test_muxing(134, "0x00000040 0x02000000 pinmux_lcd_pins");
108 test_muxing(135, "0x00000040 0x20000000 pinmux_lcd_pins");
109 test_muxing(136, "0x00000044 0x00000002 pinmux_lcd_pins");
110 test_muxing(137, "0x00000044 0x00000020 pinmux_lcd_pins");
111 test_muxing(138, "0x00000044 0x00000200 pinmux_lcd_pins");
112 test_muxing(139, "0x00000044 0x00002000 pinmux_lcd_pins");
113 test_muxing(140, "0x00000044 0x00020000 pinmux_lcd_pins");
114 test_muxing(141, "0x00000044 0x00200000 pinmux_lcd_pins");
115 test_muxing(142, "0x00000044 0x02000000 pinmux_lcd_pins");
116 test_muxing(143, "0x00000044 0x20000000 pinmux_lcd_pins");
117 test_muxing(144, "0x00000048 0x00000002 pinmux_lcd_pins");
118 test_muxing(145, "0x00000048 0x00000020 pinmux_lcd_pins");
119 test_muxing(146, "0x00000048 0x00000000 UNCLAIMED");
120 test_muxing(147, "0x00000048 0x00000000 UNCLAIMED");
121 test_muxing(148, "0x00000048 0x00000000 UNCLAIMED");
122 test_muxing(149, "0x00000048 0x00000000 UNCLAIMED");
123 test_muxing(150, "0x00000048 0x02000000 pinmux_lcd_pins");
124 test_muxing(151, "0x00000048 0x00000000 UNCLAIMED");
125 test_muxing(152, "0x0000004c 0x00000002 pinmux_lcd_pins");
126 test_muxing(153, "0x0000004c 0x00000020 pinmux_lcd_pins");
127 test_muxing(154, "0x0000004c 0x00000000 UNCLAIMED");
128 test_muxing(155, "0x0000004c 0x00000000 UNCLAIMED");
129 test_muxing(156, "0x0000004c 0x00000000 UNCLAIMED");
130 test_muxing(157, "0x0000004c 0x00000000 UNCLAIMED");
131 test_muxing(158, "0x0000004c 0x02000000 pinmux_lcd_pins");
132 test_muxing(159, "0x0000004c 0x00000000 UNCLAIMED");
133 ret = pinctrl_get_pin_muxing(dev, 160, buf, sizeof(buf));
134 ut_asserteq(-EINVAL, ret);
135 return 0;
136}
137
138DM_TEST(dm_test_pinctrl_single, UT_TESTF_SCAN_FDT);