public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [PATCH v5 2/3] sandbox, test: add test for GPIO_HOG function
Date: Fri, 15 May 2020 16:00:58 +0200	[thread overview]
Message-ID: <20200515140100.3306517-3-hs@denx.de> (raw)
In-Reply-To: <20200515140100.3306517-1-hs@denx.de>

currently gpio hog function is not tested with "ut dm gpio"
so add some basic tests for gpio hog functionality.

For this enable GPIO_HOG in sandbox_defconfig, add
in DTS some gpio hog entries, and add testcase in
"ut dm gpio" command.

Signed-off-by: Heiko Schocher <hs@denx.de>

---

Changes in v5: None
Changes in v4:
- rebased to current master ac14bc4169

Changes in v3: None
Changes in v2:
- add basic gpio hog test functions

 arch/sandbox/dts/test.dts          | 20 ++++++++++++++++++++
 configs/sandbox64_defconfig        |  1 +
 configs/sandbox_defconfig          |  1 +
 configs/sandbox_flattree_defconfig |  1 +
 configs/sandbox_spl_defconfig      |  1 +
 test/dm/gpio.c                     | 23 +++++++++++++++++++++++
 6 files changed, 47 insertions(+)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 5ce5e28476..24bb3ce36f 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -343,6 +343,26 @@
 			#gpio-cells = <1>;
 			gpio-bank-name = "a";
 			sandbox,gpio-count = <20>;
+			hog_input_active_low {
+				gpio-hog;
+				input;
+				gpios = <0 GPIO_ACTIVE_LOW>;
+			};
+			hog_input_active_high {
+				gpio-hog;
+				input;
+				gpios = <1 GPIO_ACTIVE_HIGH>;
+			};
+			hog_output_low {
+				gpio-hog;
+				output-low;
+				gpios = <2 GPIO_ACTIVE_HIGH>;
+			};
+			hog_output_high {
+				gpio-hog;
+				output-high;
+				gpios = <3 GPIO_ACTIVE_HIGH>;
+			};
 		};
 
 		gpio_b: extra-gpios {
diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index c1237ea296..39dc3dc687 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -98,6 +98,7 @@ CONFIG_DM_DEMO_SIMPLE=y
 CONFIG_DM_DEMO_SHAPE=y
 CONFIG_BOARD=y
 CONFIG_BOARD_SANDBOX=y
+CONFIG_GPIO_HOG=y
 CONFIG_PM8916_GPIO=y
 CONFIG_SANDBOX_GPIO=y
 CONFIG_I2C_CROS_EC_TUNNEL=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 9445d78118..9015458070 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -115,6 +115,7 @@ CONFIG_BOARD_SANDBOX=y
 CONFIG_DMA=y
 CONFIG_DMA_CHANNELS=y
 CONFIG_SANDBOX_DMA=y
+CONFIG_GPIO_HOG=y
 CONFIG_PM8916_GPIO=y
 CONFIG_SANDBOX_GPIO=y
 CONFIG_DM_HWSPINLOCK=y
diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig
index a4a7ae8379..b5a85e1278 100644
--- a/configs/sandbox_flattree_defconfig
+++ b/configs/sandbox_flattree_defconfig
@@ -83,6 +83,7 @@ CONFIG_DM_DEMO_SIMPLE=y
 CONFIG_DM_DEMO_SHAPE=y
 CONFIG_BOARD=y
 CONFIG_BOARD_SANDBOX=y
+CONFIG_GPIO_HOG=y
 CONFIG_PM8916_GPIO=y
 CONFIG_SANDBOX_GPIO=y
 CONFIG_I2C_CROS_EC_TUNNEL=y
diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig
index 945fe54d20..7341fa3221 100644
--- a/configs/sandbox_spl_defconfig
+++ b/configs/sandbox_spl_defconfig
@@ -102,6 +102,7 @@ CONFIG_DM_DEMO_SHAPE=y
 CONFIG_BOARD=y
 CONFIG_BOARD_SANDBOX=y
 CONFIG_SPL_FIRMWARE=y
+CONFIG_GPIO_HOG=y
 CONFIG_PM8916_GPIO=y
 CONFIG_SANDBOX_GPIO=y
 CONFIG_I2C_CROS_EC_TUNNEL=y
diff --git a/test/dm/gpio.c b/test/dm/gpio.c
index 7c18e5c411..1443a2db79 100644
--- a/test/dm/gpio.c
+++ b/test/dm/gpio.c
@@ -19,6 +19,7 @@ static int dm_test_gpio(struct unit_test_state *uts)
 	unsigned int offset, gpio;
 	struct dm_gpio_ops *ops;
 	struct udevice *dev;
+	struct gpio_desc *desc;
 	const char *name;
 	int offset_count;
 	char buf[80];
@@ -108,6 +109,28 @@ static int dm_test_gpio(struct unit_test_state *uts)
 	ut_asserteq_str("a", name);
 	ut_asserteq(20, offset_count);
 
+	/* add gpio hog tests */
+	ut_assertok(gpio_hog_lookup_name("hog_input_active_low", &desc));
+	ut_asserteq(GPIOD_IS_IN | GPIOD_ACTIVE_LOW, desc->flags);
+	ut_asserteq(0, desc->offset);
+	ut_asserteq(1, dm_gpio_get_value(desc));
+	ut_assertok(gpio_hog_lookup_name("hog_input_active_high", &desc));
+	ut_asserteq(GPIOD_IS_IN, desc->flags);
+	ut_asserteq(1, desc->offset);
+	ut_asserteq(0, dm_gpio_get_value(desc));
+	ut_assertok(gpio_hog_lookup_name("hog_output_low", &desc));
+	ut_asserteq(GPIOD_IS_OUT, desc->flags);
+	ut_asserteq(2, desc->offset);
+	ut_asserteq(0, dm_gpio_get_value(desc));
+	ut_assertok(dm_gpio_set_value(desc, 1));
+	ut_asserteq(1, dm_gpio_get_value(desc));
+	ut_assertok(gpio_hog_lookup_name("hog_output_high", &desc));
+	ut_asserteq(GPIOD_IS_OUT, desc->flags);
+	ut_asserteq(3, desc->offset);
+	ut_asserteq(1, dm_gpio_get_value(desc));
+	ut_assertok(dm_gpio_set_value(desc, 0));
+	ut_asserteq(0, dm_gpio_get_value(desc));
+
 	return 0;
 }
 DM_TEST(dm_test_gpio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.24.1

  parent reply	other threads:[~2020-05-15 14:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-15 14:00 [PATCH v5 0/3] gpio: add possibility to search for gpio label name Heiko Schocher
2020-05-15 14:00 ` [PATCH v5 1/3] gpio-uclass.c: save the GPIOD flags also in the gpio descriptor Heiko Schocher
2020-05-15 19:36   ` Patrick DELAUNAY
2020-05-20  3:06   ` Simon Glass
2020-07-02 19:05   ` Baruch Siach
2020-07-03  5:10     ` Heiko Schocher
2020-05-15 14:00 ` Heiko Schocher [this message]
2020-05-20  3:06   ` [PATCH v5 2/3] sandbox, test: add test for GPIO_HOG function Simon Glass
2020-05-15 14:00 ` [PATCH v5 3/3] gpio: search for gpio label if gpio is not found through bank name Heiko Schocher
2020-05-20  3:06   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200515140100.3306517-3-hs@denx.de \
    --to=hs@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox