summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2020-07-05 08:06:52 -0400
committerTom Rini <trini@konsulko.com>2020-07-05 08:06:52 -0400
commit04da1cd8076b44ff49a79b7fe048a9e8e56b5f60 (patch)
tree7a276566b545e1a8df7f2113d67baaace3c5b2e8
parent06e1321553ffa442248e35d9100fd70153690348 (diff)
parent9ba84329dc45f28f8581e95de155b5bf0373bb3d (diff)
downloadu-boot-04da1cd8076b44ff49a79b7fe048a9e8e56b5f60.tar.gz
u-boot-04da1cd8076b44ff49a79b7fe048a9e8e56b5f60.tar.bz2
u-boot-04da1cd8076b44ff49a79b7fe048a9e8e56b5f60.zip
Merge branch '2020-07-05-gpio-regression-fix'
- Merge a fix to the gpio uclass and a test for it.
-rw-r--r--arch/sandbox/dts/test.dts20
-rw-r--r--configs/sandbox64_defconfig1
-rw-r--r--configs/sandbox_defconfig1
-rw-r--r--configs/sandbox_flattree_defconfig1
-rw-r--r--configs/sandbox_spl_defconfig1
-rw-r--r--drivers/gpio/gpio-uclass.c8
-rw-r--r--test/dm/gpio.c23
7 files changed, 51 insertions, 4 deletions
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 a3f049e124..0f9a27c39c 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -97,6 +97,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 5b7569319b..6f450aa637 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -114,6 +114,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 21f9047046..05ce9bda37 100644
--- a/configs/sandbox_flattree_defconfig
+++ b/configs/sandbox_flattree_defconfig
@@ -82,6 +82,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 fc8b26e88c..f5e90f7488 100644
--- a/configs/sandbox_spl_defconfig
+++ b/configs/sandbox_spl_defconfig
@@ -101,6 +101,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/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 9eeab22eef..f016532354 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -600,6 +600,10 @@ static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
}
}
+ /* save the flags also in descriptor */
+ if (!ret)
+ desc->flags = flags;
+
return ret;
}
@@ -615,10 +619,6 @@ int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
flags |= desc->flags;
ret = _dm_gpio_set_dir_flags(desc, flags);
- /* update the descriptor flags */
- if (ret)
- desc->flags = flags;
-
return ret;
}
diff --git a/test/dm/gpio.c b/test/dm/gpio.c
index b5ee4e4f87..ecba566983 100644
--- a/test/dm/gpio.c
+++ b/test/dm/gpio.c
@@ -20,6 +20,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];
@@ -109,6 +110,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);