riscv: Add FPIOA and GPIO support for Kendryte K210
Subsystems (5)
cover riscv: Add FPIOA and GPIO support for Kendryte K210
This patch series adds support for pinmuxing, gpios, and leds on the Kendyte K210.
This patch series was previously part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576
This patch series depends on
https://patchwork.ozlabs.org/project/uboot/list/?series=162643
Sean Anderson (8):
pinctrl: Add support for Kendryte K210 FPIOA
gpio: sifive: Use generic reg read function
gpio: dw: Fix warnings about casting int to pointer
gpio: dw: Add a trailing underscore to generated name
gpio: dw: Return output value when direction is out
led: gpio: Default to using node name if label is absent
riscv: Add pinmux and gpio bindings for Kendryte K210
riscv: Add FPIOA and GPIO support for Kendryte K210
MAINTAINERS | 2 + arch/riscv/dts/k210-maix-bit.dts | 196 ++++++ arch/riscv/dts/k210.dtsi | 43 +- board/sipeed/maix/Kconfig | 12 + doc/board/sipeed/maix.rst | 64 +- .../pinctrl/kendryte,k210-fpioa.txt | 116 +++ drivers/gpio/dwapb_gpio.c | 33 +- drivers/gpio/sifive-gpio.c | 2 +- drivers/led/led_gpio.c | 7 +- drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/kendryte/Kconfig | 7 + drivers/pinctrl/kendryte/Makefile | 1 + drivers/pinctrl/kendryte/pinctrl.c | 666 ++++++++++++++++++ drivers/pinctrl/kendryte/pinctrl.h | 325 +++++++++ include/dt-bindings/pinctrl/k210-pinctrl.h | 12 + 16 files changed, 1465 insertions(+), 23 deletions(-) create mode 100644 doc/device-tree-bindings/pinctrl/kendryte,k210-fpioa.txt create mode 100644 drivers/pinctrl/kendryte/Kconfig create mode 100644 drivers/pinctrl/kendryte/Makefile create mode 100644 drivers/pinctrl/kendryte/pinctrl.c create mode 100644 drivers/pinctrl/kendryte/pinctrl.h create mode 100644 include/dt-bindings/pinctrl/k210-pinctrl.h
Signature · 1 line
2.25.0
PATCH 1/8 pinctrl: Add support for Kendryte K210 FPIOA
The Fully-Programmable Input/Output Array (FPIOA) device controls pin multiplexing on the K210. The FPIOA can remap any supported function to any multifunctional IO pin. It can also perform basic GPIO functions, such as reading the current value of a pin.
---
This patch was previously submitted as part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576
Changes from that version include:
- Reformat to reduce errors from checkpatch
MAINTAINERS | 2 + .../pinctrl/kendryte,k210-fpioa.txt | 116 +++ drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/kendryte/Kconfig | 7 + drivers/pinctrl/kendryte/Makefile | 1 + drivers/pinctrl/kendryte/pinctrl.c | 666 ++++++++++++++++++ drivers/pinctrl/kendryte/pinctrl.h | 325 +++++++++ include/dt-bindings/pinctrl/k210-pinctrl.h | 12 + 9 files changed, 1131 insertions(+) create mode 100644 doc/device-tree-bindings/pinctrl/kendryte,k210-fpioa.txt create mode 100644 drivers/pinctrl/kendryte/Kconfig create mode 100644 drivers/pinctrl/kendryte/Makefile create mode 100644 drivers/pinctrl/kendryte/pinctrl.c create mode 100644 drivers/pinctrl/kendryte/pinctrl.h create mode 100644 include/dt-bindings/pinctrl/k210-pinctrl.h
MAINTAINERS +2 -0
@@ -811,7 +811,9 @@ RISC-V KENDRYTE M: Sean Anderson <[email protected]> S: Maintained F: doc/device-tree-bindings/mfd/kendryte,k210-sysctl.txt +F: doc/device-tree-bindings/pinctrl/kendryte,k210-fpioa.txt F: drivers/clk/kendryte/ +F: drivers/pinctrl/kendryte/ F: include/kendryte/ RNG
doc/device-tree-bindings/pinctrl/kendryte,k210-fpioa.txt new file +116 -0
116 lines not on this page · raw message
drivers/pinctrl/Kconfig +1 -0
@@ -289,6 +289,7 @@ endif source "drivers/pinctrl/broadcom/Kconfig" source "drivers/pinctrl/exynos/Kconfig" source "drivers/pinctrl/intel/Kconfig" +source "drivers/pinctrl/kendryte/Kconfig" source "drivers/pinctrl/mediatek/Kconfig" source "drivers/pinctrl/meson/Kconfig" source "drivers/pinctrl/mscc/Kconfig"
drivers/pinctrl/Makefile +1 -0
@@ -17,6 +17,7 @@ obj-$(CONFIG_PINCTRL_SANDBOX) += pinctrl-sandbox.o obj-$(CONFIG_PINCTRL_UNIPHIER) += uniphier/ obj-$(CONFIG_PINCTRL_PIC32) += pinctrl_pic32.o obj-$(CONFIG_PINCTRL_EXYNOS) += exynos/ +obj-$(CONFIG_PINCTRL_K210) += kendryte/ obj-$(CONFIG_PINCTRL_MESON) += meson/ obj-$(CONFIG_PINCTRL_MTK) += mediatek/ obj-$(CONFIG_PINCTRL_MSCC) += mscc/
drivers/pinctrl/kendryte/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +config PINCTRL_K210 + bool "Kendryte K210 Fully-Programmable Input/Output Array driver" + depends on DM && PINCTRL_GENERIC + help + Support pin multiplexing on the K210. The "FPIOA" can remap any + supported function to any multifunctional IO pin. It can also perform + basic GPIO functions, such as reading the current value of a pin.
drivers/pinctrl/kendryte/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += pinctrl.o
drivers/pinctrl/kendryte/pinctrl.c new file +666 -0
666 lines not on this page · raw message
drivers/pinctrl/kendryte/pinctrl.h new file +325 -0
325 lines not on this page · raw message
include/dt-bindings/pinctrl/k210-pinctrl.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2020 Sean Anderson <[email protected]> +*/ + +#ifndef DT_K210_PINCTRL_H +#define DT_K210_PINCTRL_H + +#define K210_PC_POWER_3V3 0 +#define K210_PC_POWER_1V8 1 + +#endif /* DT_K210_PINCTRL_H */
Signature · 1 line
2.25.0
PATCH 2/8 gpio: sifive: Use generic reg read function
In reply to Sean AndersonUsing an fdt-specific function causes problems with a live tree.
---
This patch was previously submitted as part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576
drivers/gpio/sifive-gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/sifive-gpio.c +1 -1
@@ -158,7 +158,7 @@ static int sifive_gpio_ofdata_to_platdata(struct udevice *dev)struct sifive_gpio_platdata *plat =dev_get_platdata (dev);fdt_addr_t addr; - addr =devfdt_get_addr (dev); + addr =dev_read_addr (dev);if (addr ==FDT_ADDR_T_NONE )return -EINVAL ;
Signature · 1 line
2.25.0
PATCH 3/8 gpio: dw: Fix warnings about casting int to pointer
In reply to Sean AndersonChange the type of gpio_dwabp_platdata.base from fdt_addr_t to a void pointer, since we pass it to readl.
---
This patch was previously submitted as part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576
drivers/gpio/dwapb_gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/dwapb_gpio.c +2 -2
@@ -38,7 +38,7 @@ struct gpio_dwapb_platdata {const char *name;int bank;int pins; -fdt_addr_t base; +void __iomem *base; };static int dwapb_gpio_direction_input (struct udevice *dev,unsigned pin)
@@ -174,7 +174,7 @@ static int gpio_dwapb_bind(struct udevice *dev)if (!plat)return -ENOMEM ; - plat->base = base; + plat->base = (void *)base; plat->bank = bank; plat->pins =ofnode_read_u32_default (node,"snps,nr-gpios" ,0 );
Signature · 1 line
2.25.0
PATCH 4/8 gpio: dw: Add a trailing underscore to generated name
In reply to Sean AndersonPreviously, if there was no bank-name property, it was easy to have confusing gpio names like "gpio1 at 08", instead of "gpio1 at 0_8". This patch follows the example of the sifive gpio driver.
---
This patch was previously submitted as part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576
drivers/gpio/dwapb_gpio.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpio/dwapb_gpio.c +9 -1
@@ -184,7 +184,15 @@ static int gpio_dwapb_bind(struct udevice *dev)* Fall back to node name. This means accessing pins * via bank name won't work. */ - plat->name =ofnode_get_name (node); +char name[32 ]; + +snprintf (name,sizeof (name),"%s_" , +ofnode_get_name (node)); + plat->name =strdup (name); +if (!plat->name) { +kfree (plat); +return -ENOMEM ; + } } ret = device_bind_ofnode(dev, dev->driver, plat->name,
Signature · 1 line
2.25.0
PATCH 5/8 gpio: dw: Return output value when direction is out
In reply to Sean Andersondm_gpio_ops.get_value can be called when the gpio is either input or output. The current dw code always returns the input value, which is invalid if the direction is set to out.
---
This patch was previously submitted as part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576
drivers/gpio/dwapb_gpio.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/gpio/dwapb_gpio.c +12 -7
@@ -64,13 +64,6 @@ static int dwapb_gpio_direction_output(struct udevice *dev, unsigned pin,return 0 ; } -static int dwapb_gpio_get_value (struct udevice *dev,unsigned pin) -{ -struct gpio_dwapb_platdata *plat =dev_get_platdata (dev); -return !!(readl (plat->base +GPIO_EXT_PORT (plat->bank)) & (1 << pin)); -} - -static int dwapb_gpio_set_value (struct udevice *dev,unsigned pin,int val) {struct gpio_dwapb_platdata *plat =dev_get_platdata (dev);
@@ -96,6 +89,18 @@ static int dwapb_gpio_get_function(struct udevice *dev, unsigned offset)return GPIOF_INPUT ; } +static int dwapb_gpio_get_value (struct udevice *dev,unsigned pin) +{ +struct gpio_dwapb_platdata *plat =dev_get_platdata (dev); +u32 value; + +if (dwapb_gpio_get_function (dev, pin) ==GPIOF_OUTPUT ) + value =readl (plat->base +GPIO_SWPORT_DR (plat->bank)); +else + value =readl (plat->base +GPIO_EXT_PORT (plat->bank)); +return !!(value &BIT (pin)); +} +static const struct dm_gpio_ops gpio_dwapb_ops = { .direction_input = dwapb_gpio_direction_input, .direction_output = dwapb_gpio_direction_output,
Signature · 1 line
2.25.0
PATCH 6/8 led: gpio: Default to using node name if label is absent
In reply to Sean AndersonThis more closely mirrors Linux's behaviour, and will make it easier to transition to using function+color in the future.
---
This patch was previously submitted as part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576
drivers/led/led_gpio.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/led/led_gpio.c +2 -5
@@ -98,11 +98,8 @@ static int led_gpio_bind(struct udevice *parent)const char *label; label =ofnode_read_string (node,"label" ); -if (!label) { -debug ("%s: node %s has no label\n" , __func__, -ofnode_get_name (node)); -return -EINVAL ; - } +if (!label) + label =ofnode_get_name (node); ret =device_bind_driver_to_node (parent,"gpio_led" ,ofnode_get_name (node), node, &dev);
Signature · 1 line
2.25.0
PATCH 7/8 riscv: Add pinmux and gpio bindings for Kendryte K210
In reply to Sean AndersonThis patch adds the necessary device tree bindings.
---
arch/riscv/dts/k210-maix-bit.dts | 196 +++++++++++++++++++++++++++++++ arch/riscv/dts/k210.dtsi | 43 ++++++- 2 files changed, 234 insertions(+), 5 deletions(-)
arch/riscv/dts/k210-maix-bit.dts +196 -0
@@ -17,6 +17,22 @@ stdout-path = "serial0:115200"; }; + gpio-leds { + compatible = "gpio-leds"; + + green { + gpios = <&gpio1_0 4 GPIO_ACTIVE_LOW>; + }; + + red { + gpios = <&gpio1_0 5 GPIO_ACTIVE_LOW>; + }; + + blue { + gpios = <&gpio1_0 6 GPIO_ACTIVE_LOW>; + }; + }; + sound { compatible = "simple-audio-card"; simple-audio-card,format = "i2s";
@@ -39,9 +55,189 @@ }; &uarths0 { + pinctrl-0 = <&fpioa_uarths>; + pinctrl-names = "default"; + status = "okay"; +}; + +&gpio0 { + pinctrl-0 = <&fpioa_gpiohs>; + pinctrl-names = "default"; + status = "okay"; +}; + +&gpio1 { + pinctrl-0 = <&fpioa_gpio>; + pinctrl-names = "default"; status = "okay"; }; &i2s0 { #sound-dai-cells = <1>; + pinctrl-0 = <&fpioa_i2s0>; + pinctrl-names = "default"; +}; + +&fpioa { + status = "okay"; + + fpioa_uarths: uarths { + rx { + function = "UARTHS_RX"; + pins = "IO_4"; + }; + tx { + function = "UARTHS_TX"; + pins = "IO_5"; + }; + }; + + fpioa_gpiohs: gpiohs { + 1 { + function = "GPIOHS1"; + pins = "IO_6"; + }; + 2 { + function = "GPIOHS2"; + pins = "IO_7"; + }; + 3 { + function = "GPIOHS3"; + pins = "IO_17"; + }; + 4 { + function = "GPIOHS4"; + pins = "IO_21"; + }; + 5 { + function = "GPIOHS5"; + pins = "IO_22"; + }; + 6 { + function = "GPIOHS6"; + pins = "IO_23"; + }; + 7 { + function = "GPIOHS7"; + pins = "IO_24"; + }; + 8 { + function = "GPIOHS8"; + pins = "IO_25"; + }; + 9 { + function = "GPIOHS9"; + pins = "IO_30"; + }; + 10 { + function = "GPIOHS10"; + pins = "IO_31"; + }; + 11 { + function = "GPIOHS11"; + pins = "IO_32"; + }; + 12 { + function = "GPIOHS12"; + pins = "IO_33"; + }; + 13 { + function = "GPIOHS13"; + pins = "IO_34"; + }; + 14 { + function = "GPIOHS14"; + pins = "IO_35"; + }; + }; + + fpioa_gpio: gpio { + 0 { + function = "GPIO0"; + pins = "IO_8"; + }; + 1 { + function = "GPIO1"; + pins = "IO_9"; + }; + 2 { + function = "GPIO2"; + pins = "IO_10"; + }; + 3 { + function = "GPIO3"; + pins = "IO_11"; + }; + 4 { + function = "GPIO4"; + pins = "IO_12"; + }; + 5 { + function = "GPIO5"; + pins = "IO_13"; + }; + 6 { + function = "GPIO6"; + pins = "IO_14"; + }; + 7 { + function = "GPIO7"; + pins = "IO_15"; + }; + }; + + fpioa_i2s0: i2s0 { + bck { + function = "I2S0_SCLK"; + pins = "IO_18"; + }; + ws { + function = "I2S0_WS"; + pins = "IO_19"; + }; + dat { + function = "I2S0_IN_D0"; + pins = "IO_20"; + }; + }; + + fpioa_dvp: dvp { + sda { + function = "SCCP_SDA"; + pins = "IO_40"; + }; + sck { + function = "SCCP_SCLK"; + pins = "IO_41"; + }; + rst { + function = "DVP_RST"; + pins = "IO_42"; + }; + vsync { + function = "DVP_VSYNC"; + pins = "IO_43"; + }; + pwdn { + function = "DVP_PWDN"; + pins = "IO_44"; + }; + hsync { + function = "DVP_HSYNC"; + pins = "IO_45"; + }; + xclk { + function = "DVP_XCLK"; + pins = "IO_46"; + }; + pclk { + function = "DVP_PCLK"; + pins = "IO_47"; + }; + }; +}; + +&dvp0 { + pinctrl-0 = <&fpioa_dvp>; + pinctrl-names = "default"; };
arch/riscv/dts/k210.dtsi +38 -5
62 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH 8/8 riscv: Add FPIOA and GPIO support for Kendryte K210
In reply to Sean AndersonThis patch adds the necessary configs and docs for FPIOA and GPIO support on the K210.
---
board/sipeed/maix/Kconfig | 12 ++++++++ doc/board/sipeed/maix.rst | 64 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 2 deletions(-)
board/sipeed/maix/Kconfig +12 -0
@@ -27,6 +27,9 @@ config NR_CPUS config NR_DRAM_BANKS default 3 +config SF_DEFAULT_BUS + default 3 + config BOARD_SPECIFIC_OPTIONS def_bool y select GENERIC_RISCV
@@ -45,4 +48,13 @@ config BOARD_SPECIFIC_OPTIONS imply RESET_SYSCON imply SYSRESET imply SYSRESET_SYSCON + imply PINCTRL + imply PINCONF + imply PINCTRL_K210 + imply DM_GPIO + imply DWAPB_GPIO + imply SIFIVE_GPIO + imply CMD_GPIO + imply LED + imply LED_GPIO endif
doc/board/sipeed/maix.rst +62 -2
80 lines not on this page · raw message
Signature · 1 line
2.25.0