summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2020-05-12 16:23:15 +0300
committerTom Rini <trini@konsulko.com>2020-05-12 16:23:15 +0300
commit1e6d9f515dfa6dbaf33095bf1e04d733da9fc41b (patch)
tree533fb609ba98d94946300e9170b92b6f4dae0a47
parent2a38d2239d0bb4d128b00886bf097ab247a0b1a7 (diff)
parent9bf87e256c26246fa6d8df491617e40cb7df89c2 (diff)
downloadu-boot-1e6d9f515dfa6dbaf33095bf1e04d733da9fc41b.tar.xz
Merge tag 'u-boot-amlogic-20200511' of https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic
- Enable USB Host for Odroid-C2 board - Add Open-Drain/Open-Source emulation in GPIO uclass
-rw-r--r--arch/arm/dts/meson-gxbb-odroidc2-u-boot.dtsi8
-rw-r--r--arch/sandbox/dts/test.dts4
-rw-r--r--configs/odroid-c2_defconfig7
-rw-r--r--drivers/gpio/gpio-uclass.c15
-rw-r--r--test/dm/gpio.c89
5 files changed, 122 insertions, 1 deletions
diff --git a/arch/arm/dts/meson-gxbb-odroidc2-u-boot.dtsi b/arch/arm/dts/meson-gxbb-odroidc2-u-boot.dtsi
index c35158d7e9..484b40504d 100644
--- a/arch/arm/dts/meson-gxbb-odroidc2-u-boot.dtsi
+++ b/arch/arm/dts/meson-gxbb-odroidc2-u-boot.dtsi
@@ -5,3 +5,11 @@
*/
#include "meson-gx-u-boot.dtsi"
+
+&usb0 {
+ status = "disabled";
+};
+
+&usb1 {
+ hnp-srp-disable;
+};
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 15cd2330a3..5ce5e28476 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/configs/odroid-c2_defconfig b/configs/odroid-c2_defconfig
index 39279b40db..3fb6f2d089 100644
--- a/configs/odroid-c2_defconfig
+++ b/configs/odroid-c2_defconfig
@@ -19,6 +19,7 @@ CONFIG_CMD_GPIO=y
CONFIG_CMD_I2C=y
# CONFIG_CMD_LOADS is not set
CONFIG_CMD_MMC=y
+CONFIG_CMD_USB=y
# CONFIG_CMD_SETEXPR is not set
CONFIG_CMD_REGULATOR=y
CONFIG_OF_CONTROL=y
@@ -32,14 +33,20 @@ CONFIG_MMC_MESON_GX=y
CONFIG_PHY_REALTEK=y
CONFIG_DM_ETH=y
CONFIG_ETH_DESIGNWARE=y
+CONFIG_PHY=y
+CONFIG_MESON_GXBB_USB_PHY=y
CONFIG_PINCTRL=y
CONFIG_PINCTRL_MESON_GXBB=y
CONFIG_DM_REGULATOR=y
CONFIG_DM_REGULATOR_FIXED=y
+CONFIG_DM_REGULATOR_GPIO=y
CONFIG_DM_RESET=y
CONFIG_DEBUG_UART_MESON=y
CONFIG_DEBUG_UART_ANNOUNCE=y
CONFIG_DEBUG_UART_SKIP_INIT=y
CONFIG_MESON_SERIAL=y
+CONFIG_USB=y
+CONFIG_DM_USB=y
+CONFIG_USB_DWC2=y
CONFIG_OF_LIBFDT_OVERLAY=y
CONFIG_SMBIOS_MANUFACTURER="Hardkernel Co., Ltd."
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 757ab7106e..d3cea11f76 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -526,6 +526,21 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value)
if (desc->flags & GPIOD_ACTIVE_LOW)
value = !value;
+
+ /*
+ * Emulate open drain by not actively driving the line high or
+ * Emulate open source by not actively driving the line low
+ */
+ if ((desc->flags & GPIOD_OPEN_DRAIN && value) ||
+ (desc->flags & GPIOD_OPEN_SOURCE && !value))
+ return gpio_get_ops(desc->dev)->direction_input(desc->dev,
+ desc->offset);
+ else if (desc->flags & GPIOD_OPEN_DRAIN ||
+ desc->flags & GPIOD_OPEN_SOURCE)
+ return gpio_get_ops(desc->dev)->direction_output(desc->dev,
+ desc->offset,
+ value);
+
gpio_get_ops(desc->dev)->set_value(desc->dev, desc->offset, value);
return 0;
}
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)
{