blob: 047184d4bcbc52c72424ea9d1c982e6637c5a0f3 [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
12static int dm_test_pinmux(struct unit_test_state *uts)
13{
14 char buf[64];
15 struct udevice *dev;
16
17#define test_muxing(selector, expected) do { \
18 ut_assertok(pinctrl_get_pin_muxing(dev, selector, buf, sizeof(buf))); \
19 ut_asserteq_str(expected, (char *)&buf); \
20} while (0)
21
22 ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL, "pinctrl", &dev));
23 test_muxing(0, "UART TX.");
24 test_muxing(1, "UART RX.");
25 test_muxing(2, "I2S SCK.");
26 test_muxing(3, "I2S SD.");
27 test_muxing(4, "I2S WS.");
28 test_muxing(5, "GPIO0 bias-pull-up input-disable.");
29 test_muxing(6, "GPIO1 drive-open-drain.");
30 test_muxing(7, "GPIO2 bias-pull-down input-enable.");
31 test_muxing(8, "GPIO3 bias-disable.");
32
33 ut_assertok(pinctrl_select_state(dev, "alternate"));
34 test_muxing(0, "I2C SCL drive-open-drain.");
35 test_muxing(1, "I2C SDA drive-open-drain.");
36 test_muxing(2, "SPI SCLK.");
37 test_muxing(3, "SPI MOSI.");
38 test_muxing(4, "SPI MISO.");
39 test_muxing(5, "SPI CS0.");
40 test_muxing(6, "SPI CS1.");
41 test_muxing(7, "GPIO2 bias-pull-down input-enable.");
42 test_muxing(8, "GPIO3 bias-disable.");
43
44 ut_assertok(pinctrl_select_state(dev, "0"));
45 test_muxing(0, "I2C SCL drive-open-drain.");
46 test_muxing(1, "I2C SDA drive-open-drain.");
47 test_muxing(2, "I2S SCK.");
48 test_muxing(3, "I2S SD.");
49 test_muxing(4, "I2S WS.");
50 test_muxing(5, "GPIO0 bias-pull-up input-disable.");
51 test_muxing(6, "GPIO1 drive-open-drain.");
52 test_muxing(7, "GPIO2 bias-pull-down input-enable.");
53 test_muxing(8, "GPIO3 bias-disable.");
54
55 return 0;
56}
57DM_TEST(dm_test_pinmux, UT_TESTF_SCAN_FDT);