diff mbox series

[v2,2/2] test: dm: update test for open-drain/open-source emulation in gpio-uclass

Message ID 20200505084318.15307-3-narmstrong@baylibre.com
State Accepted
Commit 9bf87e256c26246fa6d8df491617e40cb7df89c2
Headers show
Series gpio: add gpio open-drain & open-source emulation | expand

Commit Message

Neil Armstrong May 5, 2020, 8:43 a.m. UTC
Add tests for testing open-drain/open-source emulation in gpio-uclass.
It also adds two test3-gpios configured as GPIO_ACTIVE_LOW.

Signed-off-by: Neil Armstrong <narmstrong at baylibre.com>
---
 arch/sandbox/dts/test.dts |  4 +-
 test/dm/gpio.c            | 89 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+), 1 deletion(-)

Comments

Simon Glass May 6, 2020, 2:47 p.m. UTC | #1
On Tue, 5 May 2020 at 02:43, Neil Armstrong <narmstrong at baylibre.com> wrote:
>
> Add tests for testing open-drain/open-source emulation in gpio-uclass.
> It also adds two test3-gpios configured as GPIO_ACTIVE_LOW.
>
> Signed-off-by: Neil Armstrong <narmstrong at baylibre.com>
> ---
>  arch/sandbox/dts/test.dts |  4 +-
>  test/dm/gpio.c            | 89 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 92 insertions(+), 1 deletion(-)
>

Reviewed-by: Simon Glass <sjg at chromium.org>
diff mbox series

Patch

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 4bccfbe6e1..e9b9404363 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -104,7 +104,9 @@ 
 			<&gpio_c 2 GPIO_OUT>,
 			<&gpio_c 3 (GPIO_IN|GPIO_PULL_UP)>,
 			<&gpio_c 4 (GPIO_IN|GPIO_PULL_DOWN)>,
-			<&gpio_c 5 GPIO_IN>;
+			<&gpio_c 5 GPIO_IN>,
+			<&gpio_c 6 (GPIO_ACTIVE_LOW|GPIO_OUT|GPIO_OPEN_DRAIN)>,
+			<&gpio_c 7 (GPIO_ACTIVE_LOW|GPIO_OUT|GPIO_OPEN_SOURCE)>;
 		int-value = <1234>;
 		uint-value = <(-1234)>;
 		int64-value = /bits/ 64 <0x1111222233334444>;
diff --git a/test/dm/gpio.c b/test/dm/gpio.c
index f5c7aaf3bc..7c18e5c411 100644
--- a/test/dm/gpio.c
+++ b/test/dm/gpio.c
@@ -112,6 +112,95 @@  static int dm_test_gpio(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_gpio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
+/* Test that GPIO open-drain/open-source emulation works correctly */
+static int dm_test_gpio_opendrain_opensource(struct unit_test_state *uts)
+{
+	struct gpio_desc desc_list[8];
+	struct udevice *dev, *gpio_c;
+	char buf[80];
+
+	ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
+	ut_asserteq_str("a-test", dev->name);
+
+	ut_assertok(uclass_get_device(UCLASS_GPIO, 3, &gpio_c));
+	ut_asserteq_str("pinmux-gpios", gpio_c->name);
+
+	ut_asserteq(8, gpio_request_list_by_name(dev, "test3-gpios", desc_list,
+						 ARRAY_SIZE(desc_list), 0))
+
+	ut_asserteq(true, !!device_active(gpio_c));
+	ut_asserteq_ptr(gpio_c, desc_list[0].dev);
+	ut_asserteq_ptr(gpio_c, desc_list[1].dev);
+	ut_asserteq_ptr(gpio_c, desc_list[2].dev);
+	ut_asserteq_ptr(gpio_c, desc_list[3].dev);
+	ut_asserteq_ptr(gpio_c, desc_list[4].dev);
+	ut_asserteq_ptr(gpio_c, desc_list[5].dev);
+	ut_asserteq_ptr(gpio_c, desc_list[6].dev);
+	ut_asserteq_ptr(gpio_c, desc_list[7].dev);
+
+	/* GPIO 0 is (GPIO_OUT|GPIO_OPEN_DRAIN) */
+	ut_asserteq(GPIOD_IS_OUT | GPIOD_OPEN_DRAIN,
+		    sandbox_gpio_get_dir_flags(gpio_c, 0));
+
+	/* Set it as output high, should become an input */
+	ut_assertok(dm_gpio_set_value(&desc_list[0], 1));
+	ut_assertok(gpio_get_status(gpio_c, 0, buf, sizeof(buf)));
+	ut_asserteq_str("c0: input: 0 [x] a-test.test3-gpios0", buf);
+
+	/* Set it as output low, should become output low */
+	ut_assertok(dm_gpio_set_value(&desc_list[0], 0));
+	ut_assertok(gpio_get_status(gpio_c, 0, buf, sizeof(buf)));
+	ut_asserteq_str("c0: output: 0 [x] a-test.test3-gpios0", buf);
+
+	/* GPIO 1 is (GPIO_OUT|GPIO_OPEN_SOURCE) */
+	ut_asserteq(GPIOD_IS_OUT | GPIOD_OPEN_SOURCE,
+		    sandbox_gpio_get_dir_flags(gpio_c, 1));
+
+	/* Set it as output high, should become output high */
+	ut_assertok(dm_gpio_set_value(&desc_list[1], 1));
+	ut_assertok(gpio_get_status(gpio_c, 1, buf, sizeof(buf)));
+	ut_asserteq_str("c1: output: 1 [x] a-test.test3-gpios1", buf);
+
+	/* Set it as output low, should become an input */
+	ut_assertok(dm_gpio_set_value(&desc_list[1], 0));
+	ut_assertok(gpio_get_status(gpio_c, 1, buf, sizeof(buf)));
+	ut_asserteq_str("c1: input: 1 [x] a-test.test3-gpios1", buf);
+
+	/* GPIO 6 is (GPIO_ACTIVE_LOW|GPIO_OUT|GPIO_OPEN_DRAIN) */
+	ut_asserteq(GPIOD_ACTIVE_LOW | GPIOD_IS_OUT | GPIOD_OPEN_DRAIN,
+		    sandbox_gpio_get_dir_flags(gpio_c, 6));
+
+	/* Set it as output high, should become output low */
+	ut_assertok(dm_gpio_set_value(&desc_list[6], 1));
+	ut_assertok(gpio_get_status(gpio_c, 6, buf, sizeof(buf)));
+	ut_asserteq_str("c6: output: 0 [x] a-test.test3-gpios6", buf);
+
+	/* Set it as output low, should become an input */
+	ut_assertok(dm_gpio_set_value(&desc_list[6], 0));
+	ut_assertok(gpio_get_status(gpio_c, 6, buf, sizeof(buf)));
+	ut_asserteq_str("c6: input: 0 [x] a-test.test3-gpios6", buf);
+
+	/* GPIO 7 is (GPIO_ACTIVE_LOW|GPIO_OUT|GPIO_OPEN_SOURCE) */
+	ut_asserteq(GPIOD_ACTIVE_LOW | GPIOD_IS_OUT | GPIOD_OPEN_SOURCE,
+		    sandbox_gpio_get_dir_flags(gpio_c, 7));
+
+	/* Set it as output high, should become an input */
+	ut_assertok(dm_gpio_set_value(&desc_list[7], 1));
+	ut_assertok(gpio_get_status(gpio_c, 7, buf, sizeof(buf)));
+	ut_asserteq_str("c7: input: 0 [x] a-test.test3-gpios7", buf);
+
+	/* Set it as output low, should become output high */
+	ut_assertok(dm_gpio_set_value(&desc_list[7], 0));
+	ut_assertok(gpio_get_status(gpio_c, 7, buf, sizeof(buf)));
+	ut_asserteq_str("c7: output: 1 [x] a-test.test3-gpios7", buf);
+
+	ut_assertok(gpio_free_list(dev, desc_list, 8));
+
+	return 0;
+}
+DM_TEST(dm_test_gpio_opendrain_opensource,
+	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
 /* Test that sandbox anonymous GPIOs work correctly */
 static int dm_test_gpio_anon(struct unit_test_state *uts)
 {