From 8f0018663fdaf871d56e41647d869e5e5f13c3fd Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Fri, 3 Apr 2020 12:08:55 -0500 Subject: [PATCH] drivers: pinmux: rv32m1: Convert driver to new DT_INST macros Convert driver to use DT_INST macros and remove related board per instance Kconfig symbol usage. Updated the openisa,rv32m1_vega-pinmux binding to require the label property and updated the rv32m1.dtsi to add label properties for the pinmux nodes. Also update gpio_basic_api test to use DT_NODELABEL. Signed-off-by: Kumar Gala --- boards/riscv/rv32m1_vega/Kconfig.defconfig | 19 ----- boards/riscv/rv32m1_vega/pinmux.c | 10 +-- drivers/pinmux/Kconfig.rv32m1 | 57 +------------- drivers/pinmux/pinmux_rv32m1.c | 78 ++++--------------- .../pinctrl/openisa,rv32m1-pinmux.yaml | 3 + dts/riscv/rv32m1.dtsi | 5 ++ tests/drivers/gpio/gpio_basic_api/src/main.c | 2 +- 7 files changed, 30 insertions(+), 144 deletions(-) diff --git a/boards/riscv/rv32m1_vega/Kconfig.defconfig b/boards/riscv/rv32m1_vega/Kconfig.defconfig index a8f13522a37..7f291bd1b10 100644 --- a/boards/riscv/rv32m1_vega/Kconfig.defconfig +++ b/boards/riscv/rv32m1_vega/Kconfig.defconfig @@ -7,25 +7,6 @@ config BOARD default "rv32m1_vega_ri5cy" if SOC_OPENISA_RV32M1_RI5CY default "rv32m1_vega_zero_riscy" if SOC_OPENISA_RV32M1_ZERO_RISCY -if PINMUX_RV32M1 - -config PINMUX_RV32M1_PORTA - default y - -config PINMUX_RV32M1_PORTB - default y - -config PINMUX_RV32M1_PORTC - default y - -config PINMUX_RV32M1_PORTD - default y - -config PINMUX_RV32M1_PORTE - default y if RV32M1_INTMUX - -endif # PINMUX_RV32M1 - if GPIO_RV32M1 config GPIO_RV32M1_PORTA diff --git a/boards/riscv/rv32m1_vega/pinmux.c b/boards/riscv/rv32m1_vega/pinmux.c index aea1d07629c..47e135e7890 100644 --- a/boards/riscv/rv32m1_vega/pinmux.c +++ b/boards/riscv/rv32m1_vega/pinmux.c @@ -21,23 +21,23 @@ static int rv32m1_vega_pinmux_init(struct device *dev) #if DT_HAS_NODE(DT_NODELABEL(porta)) __unused struct device *porta = - device_get_binding(CONFIG_PINMUX_RV32M1_PORTA_NAME); + device_get_binding(DT_LABEL(DT_NODELABEL(porta))); #endif #if DT_HAS_NODE(DT_NODELABEL(portb)) __unused struct device *portb = - device_get_binding(CONFIG_PINMUX_RV32M1_PORTB_NAME); + device_get_binding(DT_LABEL(DT_NODELABEL(portb))); #endif #if DT_HAS_NODE(DT_NODELABEL(portc)) __unused struct device *portc = - device_get_binding(CONFIG_PINMUX_RV32M1_PORTC_NAME); + device_get_binding(DT_LABEL(DT_NODELABEL(portc))); #endif #if DT_HAS_NODE(DT_NODELABEL(portd)) __unused struct device *portd = - device_get_binding(CONFIG_PINMUX_RV32M1_PORTD_NAME); + device_get_binding(DT_LABEL(DT_NODELABEL(portd))); #endif #if DT_HAS_NODE(DT_NODELABEL(porte)) __unused struct device *porte = - device_get_binding(CONFIG_PINMUX_RV32M1_PORTE_NAME); + device_get_binding(DT_LABEL(DT_NODELABEL(porte))); #endif #if DT_HAS_NODE(DT_NODELABEL(lpuart0)) diff --git a/drivers/pinmux/Kconfig.rv32m1 b/drivers/pinmux/Kconfig.rv32m1 index 4d025d32c3f..b7cfb5f2d0b 100644 --- a/drivers/pinmux/Kconfig.rv32m1 +++ b/drivers/pinmux/Kconfig.rv32m1 @@ -3,63 +3,8 @@ # Copyright (c) 2018 Foundries.io # SPDX-License-Identifier: Apache-2.0 -menuconfig PINMUX_RV32M1 +config PINMUX_RV32M1 bool "RV32M1 pinmux driver" depends on SOC_OPENISA_RV32M1_RISCV32 help Enable the RV32M1 pinmux driver. - -if PINMUX_RV32M1 - -config PINMUX_RV32M1_PORTA - bool "Port A" - help - Enable Port A. - -config PINMUX_RV32M1_PORTA_NAME - string "Pinmux Port A driver name" - depends on PINMUX_RV32M1_PORTA - default "porta" - -config PINMUX_RV32M1_PORTB - bool "Port B" - help - Enable Port B. - -config PINMUX_RV32M1_PORTB_NAME - string "Pinmux Port B driver name" - depends on PINMUX_RV32M1_PORTB - default "portb" - -config PINMUX_RV32M1_PORTC - bool "Port C" - help - Enable Port C. - -config PINMUX_RV32M1_PORTC_NAME - string "Pinmux Port C driver name" - depends on PINMUX_RV32M1_PORTC - default "portc" - -config PINMUX_RV32M1_PORTD - bool "Port D" - help - Enable Port D. - -config PINMUX_RV32M1_PORTD_NAME - string "Pinmux Port D driver name" - depends on PINMUX_RV32M1_PORTD - default "portd" - -config PINMUX_RV32M1_PORTE - bool "Port E" - depends on RV32M1_INTMUX - help - Enable Port E. - -config PINMUX_RV32M1_PORTE_NAME - string "Pinmux Port E driver name" - depends on PINMUX_RV32M1_PORTE - default "porte" - -endif # PINMUX_RV32M1 diff --git a/drivers/pinmux/pinmux_rv32m1.c b/drivers/pinmux/pinmux_rv32m1.c index be37816f2ed..590c51d7a68 100644 --- a/drivers/pinmux/pinmux_rv32m1.c +++ b/drivers/pinmux/pinmux_rv32m1.c @@ -5,6 +5,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#define DT_DRV_COMPAT openisa_rv32m1_pinmux + #include #include #include @@ -63,67 +65,17 @@ static const struct pinmux_driver_api pinmux_rv32m1_driver_api = { .input = pinmux_rv32m1_input, }; -#ifdef CONFIG_PINMUX_RV32M1_PORTA -static const struct pinmux_rv32m1_config pinmux_rv32m1_porta_config = { - .base = (PORT_Type *)DT_OPENISA_RV32M1_PINMUX_PINMUX_A_BASE_ADDRESS, - .clock_ip_name = kCLOCK_PortA, -}; +#define PINMUX_RV32M1_INIT(n) \ + static const struct pinmux_rv32m1_config pinmux_rv32m1_##n##_config = {\ + .base = (PORT_Type *)DT_INST_REG_ADDR(n), \ + .clock_ip_name = INST_DT_CLOCK_IP_NAME(n), \ + }; \ + \ + DEVICE_AND_API_INIT(pinmux_rv32m1_##n, DT_INST_LABEL(n), \ + &pinmux_rv32m1_init, \ + NULL, &pinmux_rv32m1_##n##_config, \ + PRE_KERNEL_1, \ + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + &pinmux_rv32m1_driver_api) -DEVICE_AND_API_INIT(pinmux_porta, CONFIG_PINMUX_RV32M1_PORTA_NAME, - &pinmux_rv32m1_init, - NULL, &pinmux_rv32m1_porta_config, - PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, - &pinmux_rv32m1_driver_api); -#endif - -#ifdef CONFIG_PINMUX_RV32M1_PORTB -static const struct pinmux_rv32m1_config pinmux_rv32m1_portb_config = { - .base = (PORT_Type *)DT_OPENISA_RV32M1_PINMUX_PINMUX_B_BASE_ADDRESS, - .clock_ip_name = kCLOCK_PortB, -}; - -DEVICE_AND_API_INIT(pinmux_portb, CONFIG_PINMUX_RV32M1_PORTB_NAME, - &pinmux_rv32m1_init, - NULL, &pinmux_rv32m1_portb_config, - PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, - &pinmux_rv32m1_driver_api); -#endif - -#ifdef CONFIG_PINMUX_RV32M1_PORTC -static const struct pinmux_rv32m1_config pinmux_rv32m1_portc_config = { - .base = (PORT_Type *)DT_OPENISA_RV32M1_PINMUX_PINMUX_C_BASE_ADDRESS, - .clock_ip_name = kCLOCK_PortC, -}; - -DEVICE_AND_API_INIT(pinmux_portc, CONFIG_PINMUX_RV32M1_PORTC_NAME, - &pinmux_rv32m1_init, - NULL, &pinmux_rv32m1_portc_config, - PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, - &pinmux_rv32m1_driver_api); -#endif - -#ifdef CONFIG_PINMUX_RV32M1_PORTD -static const struct pinmux_rv32m1_config pinmux_rv32m1_portd_config = { - .base = (PORT_Type *)DT_OPENISA_RV32M1_PINMUX_PINMUX_D_BASE_ADDRESS, - .clock_ip_name = kCLOCK_PortD, -}; - -DEVICE_AND_API_INIT(pinmux_portd, CONFIG_PINMUX_RV32M1_PORTD_NAME, - &pinmux_rv32m1_init, - NULL, &pinmux_rv32m1_portd_config, - PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, - &pinmux_rv32m1_driver_api); -#endif - -#ifdef CONFIG_PINMUX_RV32M1_PORTE -static const struct pinmux_rv32m1_config pinmux_rv32m1_porte_config = { - .base = (PORT_Type *)DT_OPENISA_RV32M1_PINMUX_PINMUX_E_BASE_ADDRESS, - .clock_ip_name = kCLOCK_PortE, -}; - -DEVICE_AND_API_INIT(pinmux_porte, CONFIG_PINMUX_RV32M1_PORTE_NAME, - &pinmux_rv32m1_init, - NULL, &pinmux_rv32m1_porte_config, - PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, - &pinmux_rv32m1_driver_api); -#endif +DT_INST_FOREACH(PINMUX_RV32M1_INIT) diff --git a/dts/bindings/pinctrl/openisa,rv32m1-pinmux.yaml b/dts/bindings/pinctrl/openisa,rv32m1-pinmux.yaml index 87f49b6d5f3..cb1b64767c6 100644 --- a/dts/bindings/pinctrl/openisa,rv32m1-pinmux.yaml +++ b/dts/bindings/pinctrl/openisa,rv32m1-pinmux.yaml @@ -5,6 +5,9 @@ compatible: "openisa,rv32m1-pinmux" include: base.yaml properties: + label: + required: true + reg: required: true diff --git a/dts/riscv/rv32m1.dtsi b/dts/riscv/rv32m1.dtsi index bbdd29b542e..8f0fb631df9 100644 --- a/dts/riscv/rv32m1.dtsi +++ b/dts/riscv/rv32m1.dtsi @@ -308,30 +308,35 @@ compatible = "openisa,rv32m1-pinmux"; reg = <0x40046000 0xd0>; clocks = <&pcc0 0x118>; + label = "porta"; }; portb: pinmux@40047000 { compatible = "openisa,rv32m1-pinmux"; reg = <0x40047000 0xd0>; clocks = <&pcc0 0x11c>; + label = "portb"; }; portc: pinmux@40048000 { compatible = "openisa,rv32m1-pinmux"; reg = <0x40048000 0xd0>; clocks = <&pcc0 0x120>; + label = "portc"; }; portd: pinmux@40049000 { compatible = "openisa,rv32m1-pinmux"; reg = <0x40049000 0xd0>; clocks = <&pcc0 0x124>; + label = "portd"; }; porte: pinmux@41037000 { compatible = "openisa,rv32m1-pinmux"; reg = <0x41037000 0xd0>; clocks = <&pcc1 0xdc>; + label = "porte"; }; gpioa: gpio@48020000 { diff --git a/tests/drivers/gpio/gpio_basic_api/src/main.c b/tests/drivers/gpio/gpio_basic_api/src/main.c index 7e2948205bf..4b1cdfa257d 100644 --- a/tests/drivers/gpio/gpio_basic_api/src/main.c +++ b/tests/drivers/gpio/gpio_basic_api/src/main.c @@ -110,7 +110,7 @@ static void board_setup(void) pinmux_pin_set(port0, PIN_IN, pin_config); pinmux_pin_set(port0, PIN_OUT, pin_config); #elif defined(CONFIG_BOARD_RV32M1_VEGA) - const char *pmx_name = CONFIG_PINMUX_RV32M1_PORTA_NAME; + const char *pmx_name = DT_LABEL(DT_NODELABEL(porta)); struct device *pmx = device_get_binding(pmx_name); pinmux_pin_set(pmx, PIN_OUT, PORT_PCR_MUX(kPORT_MuxAsGpio));