From feaf0070fcc2fe0046086bf3f1b70dab40cb62cf Mon Sep 17 00:00:00 2001 From: Katsuhiro Suzuki Date: Wed, 19 Jan 2022 17:31:21 +0900 Subject: [PATCH] boards: riscv: hifive_unleashed: add GPIO support This patch adds GPIO and 96board LS (Low Speed)iexpansion connector support for SiFive HiFive Unleashed and also enables GPIO basic test. Signed-off-by: Katsuhiro Suzuki --- .../hifive_unleashed/hifive_unleashed.dts | 23 +++++++++++++++++++ .../hifive_unleashed/hifive_unleashed.yaml | 1 + .../hifive_unleashed_defconfig | 2 ++ drivers/gpio/Kconfig.sifive | 2 +- dts/riscv/riscv64-fu540.dtsi | 19 +++++++++++++++ .../riscv-privilege/sifive-freedom/soc.h | 3 +++ .../boards/hifive_unleashed.overlay | 13 +++++++++++ 7 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/drivers/gpio/gpio_basic_api/boards/hifive_unleashed.overlay diff --git a/boards/riscv/hifive_unleashed/hifive_unleashed.dts b/boards/riscv/hifive_unleashed/hifive_unleashed.dts index 1742d08a92..742c9ad3de 100644 --- a/boards/riscv/hifive_unleashed/hifive_unleashed.dts +++ b/boards/riscv/hifive_unleashed/hifive_unleashed.dts @@ -20,6 +20,25 @@ reg = <0x80000000 0xf0000000>; reg-names = "mem"; }; + + lscon_96b: connector { + compatible = "linaro,96b-lscon-1v8"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <22 0 &gpio0 0 0>, /* GPIO-A */ + <23 0 &gpio0 1 0>, /* GPIO-B */ + <24 0 &gpio0 2 0>, /* GPIO-C */ + <25 0 &gpio0 3 0>, /* GPIO-D */ + <26 0 &gpio0 4 0>, /* GPIO-E */ + <27 0 &gpio0 5 0>, /* GPIO-F */ + <38 0 &gpio0 6 0>, /* GPIO-G */ + <39 0 &gpio0 7 0>, /* GPIO-H */ + <30 0 &gpio0 8 0>, /* GPIO-I */ + <31 0 &gpio0 9 0>, /* GPIO-J */ + <32 0 &gpio0 15 0>; /* GPIO-K */ + /* GPIO-L not connected */ + }; }; &uart0 { @@ -52,3 +71,7 @@ status = "okay"; clock-frequency = <500000000>; }; + +&gpio0 { + status = "okay"; +}; diff --git a/boards/riscv/hifive_unleashed/hifive_unleashed.yaml b/boards/riscv/hifive_unleashed/hifive_unleashed.yaml index 4e7b31467e..6a31ee47f6 100644 --- a/boards/riscv/hifive_unleashed/hifive_unleashed.yaml +++ b/boards/riscv/hifive_unleashed/hifive_unleashed.yaml @@ -10,4 +10,5 @@ testing: - net - bluetooth supported: + - gpio - spi diff --git a/boards/riscv/hifive_unleashed/hifive_unleashed_defconfig b/boards/riscv/hifive_unleashed/hifive_unleashed_defconfig index f7cf44092c..e09e8599ac 100644 --- a/boards/riscv/hifive_unleashed/hifive_unleashed_defconfig +++ b/boards/riscv/hifive_unleashed/hifive_unleashed_defconfig @@ -4,6 +4,8 @@ CONFIG_BOARD_HIFIVE_UNLEASHED=y CONFIG_RISCV_MACHINE_TIMER=y CONFIG_PLIC=y CONFIG_CONSOLE=y +CONFIG_GPIO=y +CONFIG_GPIO_SIFIVE=y CONFIG_SPI=y CONFIG_SPI_SIFIVE=y CONFIG_SERIAL=y diff --git a/drivers/gpio/Kconfig.sifive b/drivers/gpio/Kconfig.sifive index 478fe14167..49f0528310 100644 --- a/drivers/gpio/Kconfig.sifive +++ b/drivers/gpio/Kconfig.sifive @@ -5,7 +5,7 @@ config GPIO_SIFIVE bool "SiFive Freedom Processor GPIO driver" - depends on SOC_RISCV_SIFIVE_FREEDOM + depends on SOC_SERIES_RISCV_SIFIVE_FREEDOM help Enable driver for the SiFive Freedom GPIO controller. diff --git a/dts/riscv/riscv64-fu540.dtsi b/dts/riscv/riscv64-fu540.dtsi index 9ecdb586e5..790afe0e72 100644 --- a/dts/riscv/riscv64-fu540.dtsi +++ b/dts/riscv/riscv64-fu540.dtsi @@ -168,5 +168,24 @@ #address-cells = <1>; #size-cells = <0>; }; + + gpio0: gpio@10060000 { + compatible = "sifive,gpio0"; + gpio-controller; + interrupt-parent = <&plic>; + interrupts = <7 1>, <8 1>, <9 1>, <10 1>, + <11 1>, <12 1>, <13 1>, <14 1>, + <15 1>, <16 1>, <17 1>, <18 1>, + <19 1>, <20 1>, <21 1>, <22 1>; + reg = <0x10060000 0x1000>; + reg-names = "control"; + label = "gpio_0"; + status = "disabled"; + #gpio-cells = <2>; + + #address-cells = <1>; + #size-cells = <1>; + ranges; + }; }; }; diff --git a/soc/riscv/riscv-privilege/sifive-freedom/soc.h b/soc/riscv/riscv-privilege/sifive-freedom/soc.h index f67b9e85b0..52078ef5c3 100644 --- a/soc/riscv/riscv-privilege/sifive-freedom/soc.h +++ b/soc/riscv/riscv-privilege/sifive-freedom/soc.h @@ -39,6 +39,9 @@ /* Clock controller. */ #define PRCI_BASE_ADDR 0x10000000 +/* PINMUX MAX PINS */ +#define SIFIVE_PINMUX_PINS 16 + #endif /* Timer configuration */ diff --git a/tests/drivers/gpio/gpio_basic_api/boards/hifive_unleashed.overlay b/tests/drivers/gpio/gpio_basic_api/boards/hifive_unleashed.overlay new file mode 100644 index 0000000000..390edf97fd --- /dev/null +++ b/tests/drivers/gpio/gpio_basic_api/boards/hifive_unleashed.overlay @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2021 Katsuhiro Suzuki + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + resources { + compatible = "test-gpio-basic-api"; + out-gpios = <&gpio0 0 0>; /* GPIO-A */ + in-gpios = <&gpio0 1 0>; /* GPIO-B */ + }; +};