Skip to content

Commit aa469e0

Browse files
nzmichaelhkartben
authored andcommitted
drivers: pinctrl: enable the AFIO clock on the CH32V003/20x/30x
The Alternate Function IO (AFIO) block must have the clock enabled before configuring. Some remappings seem to work without, but some like EXTI do not. Fix. Signed-off-by: Michael Hope <michaelh@juju.nz>
1 parent b64cd0d commit aa469e0

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

drivers/pinctrl/pinctrl_wch_20x_30x_afio.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#define DT_DRV_COMPAT wch_20x_30x_afio
8+
9+
#include <zephyr/drivers/clock_control.h>
710
#include <zephyr/drivers/pinctrl.h>
811
#include <zephyr/dt-bindings/pinctrl/ch32v20x_30x-pinctrl.h>
912

@@ -87,3 +90,13 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp
8790

8891
return 0;
8992
}
93+
94+
static int pinctrl_clock_init(void)
95+
{
96+
const struct device *clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(0));
97+
uint8_t clock_id = DT_INST_CLOCKS_CELL(0, id);
98+
99+
return clock_control_on(clock_dev, (clock_control_subsys_t *)(uintptr_t)clock_id);
100+
}
101+
102+
SYS_INIT(pinctrl_clock_init, PRE_KERNEL_1, 0);

drivers/pinctrl/pinctrl_wch_afio.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#define DT_DRV_COMPAT wch_afio
8+
9+
#include <zephyr/drivers/clock_control.h>
710
#include <zephyr/drivers/pinctrl.h>
811
#include <zephyr/dt-bindings/pinctrl/ch32v003-pinctrl.h>
912

@@ -28,10 +31,6 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp
2831
uint32_t pcfr1 = AFIO->PCFR1;
2932
uint8_t cfg = 0;
3033

31-
if (remap != 0) {
32-
RCC->APB2PCENR |= RCC_AFIOEN;
33-
}
34-
3534
if (pins->output_high || pins->output_low) {
3635
cfg |= (pins->slew_rate + 1);
3736
if (pins->drive_open_drain) {
@@ -77,3 +76,13 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp
7776

7877
return 0;
7978
}
79+
80+
static int pinctrl_clock_init(void)
81+
{
82+
const struct device *clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(0));
83+
uint8_t clock_id = DT_INST_CLOCKS_CELL(0, id);
84+
85+
return clock_control_on(clock_dev, (clock_control_subsys_t *)(uintptr_t)clock_id);
86+
}
87+
88+
SYS_INIT(pinctrl_clock_init, PRE_KERNEL_1, 0);

dts/riscv/wch/ch32v0/ch32v003.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
reg = <0x40010000 0x10>;
7878
#address-cells = <1>;
7979
#size-cells = <1>;
80+
clocks = <&rcc CH32V00X_CLOCK_AFIO>;
8081
status = "okay";
8182

8283
gpioa: gpio@40010800 {

dts/riscv/wch/ch32v208/ch32v208.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
reg = <0x40010000 16>;
7777
#address-cells = <1>;
7878
#size-cells = <1>;
79+
clocks = <&rcc CH32V20X_V30X_CLOCK_AFIO>;
7980

8081
gpioa: gpio@40010800 {
8182
compatible = "wch,gpio";

0 commit comments

Comments
 (0)