Skip to content

Commit 38f38e0

Browse files
fkokosinskicarlescufi
authored andcommitted
boards: FE310-based boards: transition to pinctrl driver
This commit makes the transition from the pinmux driver to the pinctrl driver. It also modifies UART, SPI and I2C drivers used in FE310-based boards to use the new pinctrl API. Signed-off-by: Filip Kokosinski <[email protected]>
1 parent a9543e0 commit 38f38e0

20 files changed

+77
-145
lines changed

boards/riscv/hifive1/CMakeLists.txt

-4
This file was deleted.

boards/riscv/hifive1/hifive1.dts

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/dts-v1/;
55

66
#include <riscv32-fe310.dtsi>
7+
#include "hifive1-pinctrl.dtsi"
78

89
/ {
910
model = "SiFive HiFive 1";
@@ -46,6 +47,8 @@
4647
status = "okay";
4748
current-speed = <115200>;
4849
clock-frequency = <16000000>;
50+
pinctrl-0 = <&uart0_rx_default &uart0_tx_default>;
51+
pinctrl-names = "default";
4952
};
5053

5154
&uart1 {
@@ -70,6 +73,9 @@
7073
&spi1 {
7174
status = "okay";
7275
clock-frequency = <16000000>;
76+
pinctrl-0 = <&spi1_cs0_default &spi1_cs2_default &spi1_cs3_default
77+
&spi1_mosi_default &spi1_miso_default &spi1_sck_default>;
78+
pinctrl-names = "default";
7379
};
7480

7581
&spi2 {
@@ -85,9 +91,13 @@
8591
&pwm1 {
8692
status = "okay";
8793
clock-frequency = <16000000>;
94+
pinctrl-0 = <&pwm1_1_default &pwm1_2_default &pwm1_3_default>;
95+
pinctrl-names = "default";
8896
};
8997

9098
&pwm2 {
9199
status = "okay";
92100
clock-frequency = <16000000>;
101+
pinctrl-0 = <&pwm2_1_default &pwm2_2_default &pwm2_3_default>;
102+
pinctrl-names = "default";
93103
};

boards/riscv/hifive1/hifive1_defconfig

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ CONFIG_UART_SIFIVE=y
99
CONFIG_UART_SIFIVE_PORT_0=y
1010
CONFIG_UART_CONSOLE=y
1111
CONFIG_PLIC=y
12-
CONFIG_PINMUX=y
13-
CONFIG_PINMUX_SIFIVE=y
12+
CONFIG_PINCTRL=y
1413
CONFIG_RISCV_MACHINE_TIMER=y
1514
CONFIG_GPIO=y
1615
CONFIG_GPIO_SIFIVE=y

boards/riscv/hifive1/pinmux.c

-54
This file was deleted.

boards/riscv/hifive1_revb/CMakeLists.txt

-4
This file was deleted.

boards/riscv/hifive1_revb/hifive1_revb.dts

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <riscv32-fe310.dtsi>
77
#include <dt-bindings/i2c/i2c.h>
8+
#include "hifive1_revb-pinctrl.dtsi"
89

910
/ {
1011
model = "SiFive HiFive 1 Rev B";
@@ -78,6 +79,8 @@
7879
status = "okay";
7980
current-speed = <115200>;
8081
clock-frequency = <16000000>;
82+
pinctrl-0 = <&uart0_rx_default &uart0_tx_default>;
83+
pinctrl-names = "default";
8184
};
8285

8386
&uart1 {
@@ -131,4 +134,6 @@ arduino_i2c: &i2c0 {
131134
label = "I2C_0";
132135
input-frequency = <16000000>;
133136
clock-frequency = <100000>;
137+
pinctrl-0 = <&i2c0_0_default &i2c0_1_default>;
138+
pinctrl-names = "default";
134139
};

boards/riscv/hifive1_revb/hifive1_revb_defconfig

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ CONFIG_RISCV_MACHINE_TIMER=y
55
CONFIG_PLIC=y
66
CONFIG_GPIO=y
77
CONFIG_GPIO_SIFIVE=y
8-
CONFIG_PINMUX=y
9-
CONFIG_PINMUX_SIFIVE=y
8+
CONFIG_PINCTRL=y
109
CONFIG_CONSOLE=y
1110
CONFIG_SERIAL=y
1211
CONFIG_UART_SIFIVE=y

boards/riscv/hifive1_revb/pinmux.c

-47
This file was deleted.

boards/riscv/qemu_riscv32/qemu_riscv32_xip.dts

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/dts-v1/;
88

99
#include <riscv32-fe310.dtsi>
10+
#include "qemu_riscv32_xip-pinctrl.dtsi"
1011

1112
/ {
1213
model = "SiFive HiFive 1";
@@ -29,6 +30,8 @@
2930
status = "okay";
3031
current-speed = <115200>;
3132
clock-frequency = <16000000>;
33+
pinctrl-0 = <&uart0_rx_default &uart0_tx_default>;
34+
pinctrl-names = "default";
3235
};
3336

3437
&uart1 {

boards/riscv/qemu_riscv32/qemu_riscv32_xip_defconfig

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ CONFIG_UART_SIFIVE=y
99
CONFIG_UART_SIFIVE_PORT_0=y
1010
CONFIG_UART_CONSOLE=y
1111
CONFIG_PLIC=y
12-
CONFIG_PINMUX=y
13-
CONFIG_PINMUX_SIFIVE=y
12+
CONFIG_PINCTRL=y
1413
CONFIG_RISCV_MACHINE_TIMER=y
1514
CONFIG_GPIO=y
1615
CONFIG_GPIO_SIFIVE=y

drivers/pwm/pwm_sifive.c

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LOG_MODULE_REGISTER(pwm_sifive, CONFIG_PWM_LOG_LEVEL);
1212

1313
#include <sys/sys_io.h>
1414
#include <device.h>
15+
#include <drivers/pinctrl.h>
1516
#include <drivers/pwm.h>
1617

1718
/* Macros */
@@ -52,6 +53,7 @@ struct pwm_sifive_cfg {
5253
uint32_t base;
5354
uint32_t f_sys;
5455
uint32_t cmpwidth;
56+
const struct pinctrl_dev_config *pcfg;
5557
};
5658

5759
/* Helper Functions */
@@ -71,6 +73,14 @@ static inline void sys_set_mask(mem_addr_t addr, uint32_t mask, uint32_t value)
7173
static int pwm_sifive_init(const struct device *dev)
7274
{
7375
const struct pwm_sifive_cfg *config = dev->config;
76+
#ifdef CONFIG_PINCTRL
77+
int ret;
78+
79+
ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
80+
if (ret < 0) {
81+
return ret;
82+
}
83+
#endif
7484

7585
/* When pwms == pwmcmp0, reset the counter */
7686
sys_set_bit(PWM_REG(config, REG_PWMCFG), SF_PWMZEROCMP);
@@ -223,11 +233,13 @@ static const struct pwm_driver_api pwm_sifive_api = {
223233
};
224234

225235
#define PWM_SIFIVE_INIT(n) \
236+
PINCTRL_DT_INST_DEFINE(n); \
226237
static struct pwm_sifive_data pwm_sifive_data_##n; \
227238
static const struct pwm_sifive_cfg pwm_sifive_cfg_##n = { \
228239
.base = DT_INST_REG_ADDR(n), \
229240
.f_sys = DT_INST_PROP(n, clock_frequency), \
230241
.cmpwidth = DT_INST_PROP(n, sifive_compare_width), \
242+
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
231243
}; \
232244
DEVICE_DT_INST_DEFINE(n, \
233245
pwm_sifive_init, \

drivers/serial/uart_sifive.c

+25-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <kernel.h>
1414
#include <arch/cpu.h>
1515
#include <drivers/uart.h>
16+
#include <drivers/pinctrl.h>
1617

1718
#define RXDATA_EMPTY (1 << 31) /* Receive FIFO Empty */
1819
#define RXDATA_MASK 0xFF /* Receive Data Mask */
@@ -47,13 +48,14 @@ typedef void (*irq_cfg_func_t)(void);
4748
#endif
4849

4950
struct uart_sifive_device_config {
50-
uintptr_t port;
51-
uint32_t sys_clk_freq;
52-
uint32_t baud_rate;
53-
uint32_t rxcnt_irq;
54-
uint32_t txcnt_irq;
51+
uintptr_t port;
52+
uint32_t sys_clk_freq;
53+
uint32_t baud_rate;
54+
uint32_t rxcnt_irq;
55+
uint32_t txcnt_irq;
56+
const struct pinctrl_dev_config *pcfg;
5557
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
56-
irq_cfg_func_t cfg_func;
58+
irq_cfg_func_t cfg_func;
5759
#endif
5860
};
5961

@@ -318,6 +320,9 @@ static int uart_sifive_init(const struct device *dev)
318320
{
319321
const struct uart_sifive_device_config * const cfg = dev->config;
320322
volatile struct uart_sifive_regs_t *uart = DEV_UART(dev);
323+
#ifdef CONFIG_PINCTRL
324+
int ret;
325+
#endif
321326

322327
/* Enable TX and RX channels */
323328
uart->txctrl = TXCTRL_TXEN | CTRL_CNT(cfg->txcnt_irq);
@@ -334,6 +339,13 @@ static int uart_sifive_init(const struct device *dev)
334339
cfg->cfg_func();
335340
#endif
336341

342+
#ifdef CONFIG_PINCTRL
343+
ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
344+
if (ret < 0) {
345+
return ret;
346+
}
347+
#endif
348+
337349
return 0;
338350
}
339351

@@ -367,12 +379,15 @@ static struct uart_sifive_data uart_sifive_data_0;
367379
static void uart_sifive_irq_cfg_func_0(void);
368380
#endif
369381

382+
PINCTRL_DT_INST_DEFINE(0);
383+
370384
static const struct uart_sifive_device_config uart_sifive_dev_cfg_0 = {
371385
.port = DT_INST_REG_ADDR(0),
372386
.sys_clk_freq = DT_INST_PROP(0, clock_frequency),
373387
.baud_rate = DT_INST_PROP(0, current_speed),
374388
.rxcnt_irq = CONFIG_UART_SIFIVE_PORT_0_RXCNT_IRQ,
375389
.txcnt_irq = CONFIG_UART_SIFIVE_PORT_0_TXCNT_IRQ,
390+
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0),
376391
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
377392
.cfg_func = uart_sifive_irq_cfg_func_0,
378393
#endif
@@ -385,6 +400,7 @@ DEVICE_DT_INST_DEFINE(0,
385400
PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY,
386401
(void *)&uart_sifive_driver_api);
387402

403+
388404
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
389405
static void uart_sifive_irq_cfg_func_0(void)
390406
{
@@ -406,12 +422,15 @@ static struct uart_sifive_data uart_sifive_data_1;
406422
static void uart_sifive_irq_cfg_func_1(void);
407423
#endif
408424

425+
PINCTRL_DT_INST_DEFINE(1);
426+
409427
static const struct uart_sifive_device_config uart_sifive_dev_cfg_1 = {
410428
.port = DT_INST_REG_ADDR(1),
411429
.sys_clk_freq = DT_INST_PROP(1, clock_frequency),
412430
.baud_rate = DT_INST_PROP(1, current_speed),
413431
.rxcnt_irq = CONFIG_UART_SIFIVE_PORT_1_RXCNT_IRQ,
414432
.txcnt_irq = CONFIG_UART_SIFIVE_PORT_1_TXCNT_IRQ,
433+
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(1),
415434
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
416435
.cfg_func = uart_sifive_irq_cfg_func_1,
417436
#endif

0 commit comments

Comments
 (0)