Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FE310-based boards: transition from pinmux to pinctrl #44068

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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 <fkokosinski@antmicro.com>
  • Loading branch information
fkokosinski committed Mar 23, 2022
commit f132c59c1365c0f166766fa94f15137cef49e45f
4 changes: 0 additions & 4 deletions boards/riscv/hifive1/CMakeLists.txt

This file was deleted.

10 changes: 10 additions & 0 deletions boards/riscv/hifive1/hifive1.dts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/dts-v1/;

#include <riscv32-fe310.dtsi>
#include "hifive1-pinctrl.dtsi"

/ {
model = "SiFive HiFive 1";
Expand Down Expand Up @@ -46,6 +47,8 @@
status = "okay";
current-speed = <115200>;
clock-frequency = <16000000>;
pinctrl-0 = <&uart0_rx_default &uart0_tx_default>;
pinctrl-names = "default";
};

&uart1 {
Expand All @@ -70,6 +73,9 @@
&spi1 {
status = "okay";
clock-frequency = <16000000>;
pinctrl-0 = <&spi1_cs0_default &spi1_cs2_default &spi1_cs3_default
&spi1_mosi_default &spi1_miso_default &spi1_sck_default>;
pinctrl-names = "default";
};

&spi2 {
Expand All @@ -85,9 +91,13 @@
&pwm1 {
status = "okay";
clock-frequency = <16000000>;
pinctrl-0 = <&pwm1_1_default &pwm1_2_default &pwm1_3_default>;
pinctrl-names = "default";
};

&pwm2 {
status = "okay";
clock-frequency = <16000000>;
pinctrl-0 = <&pwm2_1_default &pwm2_2_default &pwm2_3_default>;
pinctrl-names = "default";
};
3 changes: 1 addition & 2 deletions boards/riscv/hifive1/hifive1_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ CONFIG_UART_SIFIVE=y
CONFIG_UART_SIFIVE_PORT_0=y
CONFIG_UART_CONSOLE=y
CONFIG_PLIC=y
CONFIG_PINMUX=y
CONFIG_PINMUX_SIFIVE=y
CONFIG_PINCTRL=y
CONFIG_RISCV_MACHINE_TIMER=y
CONFIG_GPIO=y
CONFIG_GPIO_SIFIVE=y
Expand Down
54 changes: 0 additions & 54 deletions boards/riscv/hifive1/pinmux.c

This file was deleted.

4 changes: 0 additions & 4 deletions boards/riscv/hifive1_revb/CMakeLists.txt

This file was deleted.

5 changes: 5 additions & 0 deletions boards/riscv/hifive1_revb/hifive1_revb.dts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <riscv32-fe310.dtsi>
#include <dt-bindings/i2c/i2c.h>
#include "hifive1_revb-pinctrl.dtsi"

/ {
model = "SiFive HiFive 1 Rev B";
Expand Down Expand Up @@ -78,6 +79,8 @@
status = "okay";
current-speed = <115200>;
clock-frequency = <16000000>;
pinctrl-0 = <&uart0_rx_default &uart0_tx_default>;
pinctrl-names = "default";
};

&uart1 {
Expand Down Expand Up @@ -131,4 +134,6 @@ arduino_i2c: &i2c0 {
label = "I2C_0";
input-frequency = <16000000>;
clock-frequency = <100000>;
pinctrl-0 = <&i2c0_0_default &i2c0_1_default>;
pinctrl-names = "default";
};
3 changes: 1 addition & 2 deletions boards/riscv/hifive1_revb/hifive1_revb_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ CONFIG_RISCV_MACHINE_TIMER=y
CONFIG_PLIC=y
CONFIG_GPIO=y
CONFIG_GPIO_SIFIVE=y
CONFIG_PINMUX=y
CONFIG_PINMUX_SIFIVE=y
CONFIG_PINCTRL=y
CONFIG_CONSOLE=y
CONFIG_SERIAL=y
CONFIG_UART_SIFIVE=y
Expand Down
47 changes: 0 additions & 47 deletions boards/riscv/hifive1_revb/pinmux.c

This file was deleted.

3 changes: 3 additions & 0 deletions boards/riscv/qemu_riscv32/qemu_riscv32_xip.dts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/dts-v1/;

#include <riscv32-fe310.dtsi>
#include "qemu_riscv32_xip-pinctrl.dtsi"

/ {
model = "SiFive HiFive 1";
Expand All @@ -29,6 +30,8 @@
status = "okay";
current-speed = <115200>;
clock-frequency = <16000000>;
pinctrl-0 = <&uart0_rx_default &uart0_tx_default>;
pinctrl-names = "default";
};

&uart1 {
Expand Down
3 changes: 1 addition & 2 deletions boards/riscv/qemu_riscv32/qemu_riscv32_xip_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ CONFIG_UART_SIFIVE=y
CONFIG_UART_SIFIVE_PORT_0=y
CONFIG_UART_CONSOLE=y
CONFIG_PLIC=y
CONFIG_PINMUX=y
CONFIG_PINMUX_SIFIVE=y
CONFIG_PINCTRL=y
CONFIG_RISCV_MACHINE_TIMER=y
CONFIG_GPIO=y
CONFIG_GPIO_SIFIVE=y
Expand Down
12 changes: 12 additions & 0 deletions drivers/pwm/pwm_sifive.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LOG_MODULE_REGISTER(pwm_sifive, CONFIG_PWM_LOG_LEVEL);

#include <sys/sys_io.h>
#include <device.h>
#include <drivers/pinctrl.h>
#include <drivers/pwm.h>

/* Macros */
Expand Down Expand Up @@ -52,6 +53,7 @@ struct pwm_sifive_cfg {
uint32_t base;
uint32_t f_sys;
uint32_t cmpwidth;
const struct pinctrl_dev_config *pcfg;
};

/* Helper Functions */
Expand All @@ -71,6 +73,14 @@ static inline void sys_set_mask(mem_addr_t addr, uint32_t mask, uint32_t value)
static int pwm_sifive_init(const struct device *dev)
{
const struct pwm_sifive_cfg *config = dev->config;
#ifdef CONFIG_PINCTRL
int ret;

ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
if (ret < 0) {
return ret;
}
#endif

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

#define PWM_SIFIVE_INIT(n) \
PINCTRL_DT_INST_DEFINE(n); \
static struct pwm_sifive_data pwm_sifive_data_##n; \
static const struct pwm_sifive_cfg pwm_sifive_cfg_##n = { \
.base = DT_INST_REG_ADDR(n), \
.f_sys = DT_INST_PROP(n, clock_frequency), \
.cmpwidth = DT_INST_PROP(n, sifive_compare_width), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
}; \
DEVICE_DT_INST_DEFINE(n, \
pwm_sifive_init, \
Expand Down
31 changes: 25 additions & 6 deletions drivers/serial/uart_sifive.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <kernel.h>
#include <arch/cpu.h>
#include <drivers/uart.h>
#include <drivers/pinctrl.h>

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

struct uart_sifive_device_config {
uintptr_t port;
uint32_t sys_clk_freq;
uint32_t baud_rate;
uint32_t rxcnt_irq;
uint32_t txcnt_irq;
uintptr_t port;
uint32_t sys_clk_freq;
uint32_t baud_rate;
uint32_t rxcnt_irq;
uint32_t txcnt_irq;
const struct pinctrl_dev_config *pcfg;
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
irq_cfg_func_t cfg_func;
irq_cfg_func_t cfg_func;
#endif
};

Expand Down Expand Up @@ -318,6 +320,9 @@ static int uart_sifive_init(const struct device *dev)
{
const struct uart_sifive_device_config * const cfg = dev->config;
volatile struct uart_sifive_regs_t *uart = DEV_UART(dev);
#ifdef CONFIG_PINCTRL
int ret;
#endif

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

#ifdef CONFIG_PINCTRL
ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
if (ret < 0) {
return ret;
}
#endif
gmarull marked this conversation as resolved.
Show resolved Hide resolved

return 0;
}

Expand Down Expand Up @@ -367,12 +379,15 @@ static struct uart_sifive_data uart_sifive_data_0;
static void uart_sifive_irq_cfg_func_0(void);
#endif

PINCTRL_DT_INST_DEFINE(0);

static const struct uart_sifive_device_config uart_sifive_dev_cfg_0 = {
.port = DT_INST_REG_ADDR(0),
.sys_clk_freq = DT_INST_PROP(0, clock_frequency),
.baud_rate = DT_INST_PROP(0, current_speed),
.rxcnt_irq = CONFIG_UART_SIFIVE_PORT_0_RXCNT_IRQ,
.txcnt_irq = CONFIG_UART_SIFIVE_PORT_0_TXCNT_IRQ,
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0),
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
.cfg_func = uart_sifive_irq_cfg_func_0,
#endif
Expand All @@ -385,6 +400,7 @@ DEVICE_DT_INST_DEFINE(0,
PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY,
(void *)&uart_sifive_driver_api);


#ifdef CONFIG_UART_INTERRUPT_DRIVEN
static void uart_sifive_irq_cfg_func_0(void)
{
Expand All @@ -406,12 +422,15 @@ static struct uart_sifive_data uart_sifive_data_1;
static void uart_sifive_irq_cfg_func_1(void);
#endif

PINCTRL_DT_INST_DEFINE(1);

static const struct uart_sifive_device_config uart_sifive_dev_cfg_1 = {
.port = DT_INST_REG_ADDR(1),
.sys_clk_freq = DT_INST_PROP(1, clock_frequency),
.baud_rate = DT_INST_PROP(1, current_speed),
.rxcnt_irq = CONFIG_UART_SIFIVE_PORT_1_RXCNT_IRQ,
.txcnt_irq = CONFIG_UART_SIFIVE_PORT_1_TXCNT_IRQ,
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(1),
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
.cfg_func = uart_sifive_irq_cfg_func_1,
#endif
Expand Down
Loading