Sean Anderson | 7f0f180 | 2020-09-14 11:01:57 -0400 | [diff] [blame] | 1 | // 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 Binacchi | 5532262 | 2021-04-11 09:39:50 +0200 | [diff] [blame] | 12 | static char buf[64]; |
Sean Anderson | 7f0f180 | 2020-09-14 11:01:57 -0400 | [diff] [blame] | 13 | #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 | |
Marek Vasut | 2fff288 | 2023-08-13 05:32:08 +0200 | [diff] [blame] | 18 | #define test_muxing_regaddr(selector, regaddr, expected) do { \ |
| 19 | char estr[64] = { 0 }; \ |
| 20 | if (IS_ENABLED(CONFIG_PHYS_64BIT)) \ |
| 21 | snprintf(estr, sizeof(estr), "0x%016llx %s", (u64)regaddr, expected); \ |
| 22 | else \ |
| 23 | snprintf(estr, sizeof(estr), "0x%08x %s", (u32)regaddr, expected); \ |
| 24 | ut_assertok(pinctrl_get_pin_muxing(dev, selector, buf, sizeof(buf))); \ |
| 25 | ut_asserteq_str(estr, (char *)&buf); \ |
| 26 | } while (0) |
| 27 | |
Dario Binacchi | 5532262 | 2021-04-11 09:39:50 +0200 | [diff] [blame] | 28 | #define test_name(selector, expected) do { \ |
| 29 | ut_assertok(pinctrl_get_pin_name(dev, selector, buf, sizeof(buf))); \ |
| 30 | ut_asserteq_str(expected, (char *)&buf); \ |
| 31 | } while (0) |
| 32 | |
| 33 | static int dm_test_pinmux(struct unit_test_state *uts) |
| 34 | { |
| 35 | struct udevice *dev; |
| 36 | |
Sean Anderson | 7f0f180 | 2020-09-14 11:01:57 -0400 | [diff] [blame] | 37 | ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL, "pinctrl", &dev)); |
| 38 | test_muxing(0, "UART TX."); |
| 39 | test_muxing(1, "UART RX."); |
| 40 | test_muxing(2, "I2S SCK."); |
| 41 | test_muxing(3, "I2S SD."); |
| 42 | test_muxing(4, "I2S WS."); |
| 43 | test_muxing(5, "GPIO0 bias-pull-up input-disable."); |
| 44 | test_muxing(6, "GPIO1 drive-open-drain."); |
| 45 | test_muxing(7, "GPIO2 bias-pull-down input-enable."); |
| 46 | test_muxing(8, "GPIO3 bias-disable."); |
| 47 | |
| 48 | ut_assertok(pinctrl_select_state(dev, "alternate")); |
| 49 | test_muxing(0, "I2C SCL drive-open-drain."); |
| 50 | test_muxing(1, "I2C SDA drive-open-drain."); |
| 51 | test_muxing(2, "SPI SCLK."); |
| 52 | test_muxing(3, "SPI MOSI."); |
| 53 | test_muxing(4, "SPI MISO."); |
| 54 | test_muxing(5, "SPI CS0."); |
| 55 | test_muxing(6, "SPI CS1."); |
| 56 | test_muxing(7, "GPIO2 bias-pull-down input-enable."); |
| 57 | test_muxing(8, "GPIO3 bias-disable."); |
| 58 | |
| 59 | ut_assertok(pinctrl_select_state(dev, "0")); |
| 60 | test_muxing(0, "I2C SCL drive-open-drain."); |
| 61 | test_muxing(1, "I2C SDA drive-open-drain."); |
| 62 | test_muxing(2, "I2S SCK."); |
| 63 | test_muxing(3, "I2S SD."); |
| 64 | test_muxing(4, "I2S WS."); |
| 65 | test_muxing(5, "GPIO0 bias-pull-up input-disable."); |
| 66 | test_muxing(6, "GPIO1 drive-open-drain."); |
| 67 | test_muxing(7, "GPIO2 bias-pull-down input-enable."); |
| 68 | test_muxing(8, "GPIO3 bias-disable."); |
| 69 | |
| 70 | return 0; |
| 71 | } |
Dario Binacchi | 5532262 | 2021-04-11 09:39:50 +0200 | [diff] [blame] | 72 | |
Sean Anderson | 7f0f180 | 2020-09-14 11:01:57 -0400 | [diff] [blame] | 73 | DM_TEST(dm_test_pinmux, UT_TESTF_SCAN_FDT); |
Dario Binacchi | 5532262 | 2021-04-11 09:39:50 +0200 | [diff] [blame] | 74 | |
| 75 | static int dm_test_pinctrl_single(struct unit_test_state *uts) |
| 76 | { |
| 77 | struct udevice *dev; |
| 78 | int ret; |
| 79 | |
| 80 | ret = uclass_get_device_by_name(UCLASS_PINCTRL, |
| 81 | "pinctrl-single-no-width", &dev); |
| 82 | ut_asserteq(-EINVAL, ret); |
| 83 | ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &dev)); |
| 84 | ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial", &dev)); |
| 85 | ut_assertok(uclass_get_device_by_name(UCLASS_SPI, "spi@0", &dev)); |
| 86 | ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL, |
| 87 | "pinctrl-single-pins", &dev)); |
| 88 | ut_asserteq(142, pinctrl_get_pins_count(dev)); |
| 89 | test_name(0, "PIN0"); |
| 90 | test_name(141, "PIN141"); |
| 91 | test_name(142, "Error"); |
Marek Vasut | 2fff288 | 2023-08-13 05:32:08 +0200 | [diff] [blame] | 92 | test_muxing_regaddr(0, 0x0, "0x00000000 UNCLAIMED"); |
| 93 | test_muxing_regaddr(18, 0x48, "0x00000006 pinmux_pwm_pins"); |
| 94 | test_muxing_regaddr(28, 0x70, "0x00000030 pinmux_uart0_pins"); |
| 95 | test_muxing_regaddr(29, 0x74, "0x00000000 pinmux_uart0_pins"); |
| 96 | test_muxing_regaddr(100, 0x190, "0x0000000c pinmux_spi0_pins"); |
| 97 | test_muxing_regaddr(101, 0x194, "0x0000000c pinmux_spi0_pins"); |
| 98 | test_muxing_regaddr(102, 0x198, "0x00000023 pinmux_spi0_pins"); |
| 99 | test_muxing_regaddr(103, 0x19c, "0x0000000c pinmux_spi0_pins"); |
Dario Binacchi | 5532262 | 2021-04-11 09:39:50 +0200 | [diff] [blame] | 100 | ret = pinctrl_get_pin_muxing(dev, 142, buf, sizeof(buf)); |
| 101 | ut_asserteq(-EINVAL, ret); |
| 102 | ut_assertok(uclass_get_device_by_name(UCLASS_I2C, "i2c@0", &dev)); |
| 103 | ut_assertok(uclass_get_device_by_name(UCLASS_VIDEO, "lcd", &dev)); |
| 104 | ut_assertok(uclass_get_device_by_name(UCLASS_PINCTRL, |
| 105 | "pinctrl-single-bits", &dev)); |
| 106 | ut_asserteq(160, pinctrl_get_pins_count(dev)); |
| 107 | test_name(0, "PIN0"); |
| 108 | test_name(159, "PIN159"); |
| 109 | test_name(160, "Error"); |
Marek Vasut | 2fff288 | 2023-08-13 05:32:08 +0200 | [diff] [blame] | 110 | test_muxing_regaddr(0, 0x0, "0x00000000 UNCLAIMED"); |
| 111 | test_muxing_regaddr(34, 0x10, "0x00000200 pinmux_i2c0_pins"); |
| 112 | test_muxing_regaddr(35, 0x10, "0x00002000 pinmux_i2c0_pins"); |
| 113 | test_muxing_regaddr(130, 0x40, "0x00000200 pinmux_lcd_pins"); |
| 114 | test_muxing_regaddr(131, 0x40, "0x00002000 pinmux_lcd_pins"); |
| 115 | test_muxing_regaddr(132, 0x40, "0x00020000 pinmux_lcd_pins"); |
| 116 | test_muxing_regaddr(133, 0x40, "0x00200000 pinmux_lcd_pins"); |
| 117 | test_muxing_regaddr(134, 0x40, "0x02000000 pinmux_lcd_pins"); |
| 118 | test_muxing_regaddr(135, 0x40, "0x20000000 pinmux_lcd_pins"); |
| 119 | test_muxing_regaddr(136, 0x44, "0x00000002 pinmux_lcd_pins"); |
| 120 | test_muxing_regaddr(137, 0x44, "0x00000020 pinmux_lcd_pins"); |
| 121 | test_muxing_regaddr(138, 0x44, "0x00000200 pinmux_lcd_pins"); |
| 122 | test_muxing_regaddr(139, 0x44, "0x00002000 pinmux_lcd_pins"); |
| 123 | test_muxing_regaddr(140, 0x44, "0x00020000 pinmux_lcd_pins"); |
| 124 | test_muxing_regaddr(141, 0x44, "0x00200000 pinmux_lcd_pins"); |
| 125 | test_muxing_regaddr(142, 0x44, "0x02000000 pinmux_lcd_pins"); |
| 126 | test_muxing_regaddr(143, 0x44, "0x20000000 pinmux_lcd_pins"); |
| 127 | test_muxing_regaddr(144, 0x48, "0x00000002 pinmux_lcd_pins"); |
| 128 | test_muxing_regaddr(145, 0x48, "0x00000020 pinmux_lcd_pins"); |
| 129 | test_muxing_regaddr(146, 0x48, "0x00000000 UNCLAIMED"); |
| 130 | test_muxing_regaddr(147, 0x48, "0x00000000 UNCLAIMED"); |
| 131 | test_muxing_regaddr(148, 0x48, "0x00000000 UNCLAIMED"); |
| 132 | test_muxing_regaddr(149, 0x48, "0x00000000 UNCLAIMED"); |
| 133 | test_muxing_regaddr(150, 0x48, "0x02000000 pinmux_lcd_pins"); |
| 134 | test_muxing_regaddr(151, 0x48, "0x00000000 UNCLAIMED"); |
| 135 | test_muxing_regaddr(152, 0x4c, "0x00000002 pinmux_lcd_pins"); |
| 136 | test_muxing_regaddr(153, 0x4c, "0x00000020 pinmux_lcd_pins"); |
| 137 | test_muxing_regaddr(154, 0x4c, "0x00000000 UNCLAIMED"); |
| 138 | test_muxing_regaddr(155, 0x4c, "0x00000000 UNCLAIMED"); |
| 139 | test_muxing_regaddr(156, 0x4c, "0x00000000 UNCLAIMED"); |
| 140 | test_muxing_regaddr(157, 0x4c, "0x00000000 UNCLAIMED"); |
| 141 | test_muxing_regaddr(158, 0x4c, "0x02000000 pinmux_lcd_pins"); |
| 142 | test_muxing_regaddr(159, 0x4c, "0x00000000 UNCLAIMED"); |
Dario Binacchi | 5532262 | 2021-04-11 09:39:50 +0200 | [diff] [blame] | 143 | ret = pinctrl_get_pin_muxing(dev, 160, buf, sizeof(buf)); |
| 144 | ut_asserteq(-EINVAL, ret); |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | DM_TEST(dm_test_pinctrl_single, UT_TESTF_SCAN_FDT); |