Skip to content

Commit 5f0b7a7

Browse files
committed
drivers: pinctrl: Add pinctrl driver for SOPHGO CVI series
This commit introduces a pin-controller driver for the CVI series SoCs by SOPHGO. Predefined pinmux values are also added. Please refer to the official datasheet for the naming conventions of pins and signals. Signed-off-by: Chen Xingyu <[email protected]>
1 parent b9eda39 commit 5f0b7a7

File tree

11 files changed

+1397
-0
lines changed

11 files changed

+1397
-0
lines changed

drivers/pinctrl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ zephyr_library_sources_ifdef(CONFIG_PINCTRL_SY1XX pinctrl_sy1xx.c)
5454
zephyr_library_sources_ifdef(CONFIG_PINCTRL_REALTEK_RTS5912 pinctrl_realtek_rts5912.c)
5555
zephyr_library_sources_ifdef(CONFIG_PINCTRL_WCH_20X_30X_AFIO pinctrl_wch_20x_30x_afio.c)
5656
zephyr_library_sources_ifdef(CONFIG_PINCTRL_WCH_00X_AFIO pinctrl_wch_00x_afio.c)
57+
zephyr_library_sources_ifdef(CONFIG_PINCTRL_SOPHGO_CVI pinctrl_sophgo_cvi.c)
5758

5859
add_subdirectory(renesas)

drivers/pinctrl/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ source "drivers/pinctrl/Kconfig.sy1xx"
8181
source "drivers/pinctrl/Kconfig.realtek_rts5912"
8282
source "drivers/pinctrl/Kconfig.wch_20x_30x_afio"
8383
source "drivers/pinctrl/Kconfig.wch_00x_afio"
84+
source "drivers/pinctrl/Kconfig.sophgo"
8485

8586
rsource "renesas/Kconfig"
8687

drivers/pinctrl/Kconfig.sophgo

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2023-2024 Chen Xingyu <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config PINCTRL_SOPHGO_CVI
5+
bool "SOPHGO CVI series pin controller driver"
6+
default y
7+
depends on DT_HAS_SOPHGO_CVI_PINCTRL_ENABLED
8+
help
9+
Enables support for the SOPHGO CVI series pin controller.

drivers/pinctrl/pinctrl_sophgo_cvi.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2023-2024 Chen Xingyu <[email protected]>
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#define DT_DRV_COMPAT sophgo_cvi_pinctrl
7+
8+
#include <zephyr/arch/cpu.h>
9+
#include <zephyr/device.h>
10+
#include <zephyr/drivers/pinctrl.h>
11+
12+
#define PINCTRL_BASE DT_INST_REG_ADDR(0)
13+
14+
#define PINCTRL_FMUX(n) (0x00 + (n) * 4)
15+
16+
#define FMUX_MASK BIT_MASK(3)
17+
18+
static void pinctrl_configure_pin(const pinctrl_soc_pin_t *pin)
19+
{
20+
uint32_t regval;
21+
22+
regval = sys_read32(PINCTRL_BASE + PINCTRL_FMUX(pin->fmux_idx));
23+
regval &= ~FMUX_MASK;
24+
regval |= pin->fmux_sel;
25+
sys_write32(regval, PINCTRL_BASE + PINCTRL_FMUX(pin->fmux_idx));
26+
}
27+
28+
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg)
29+
{
30+
ARG_UNUSED(reg);
31+
32+
for (uint8_t i = 0; i < pin_cnt; i++) {
33+
pinctrl_configure_pin(&pins[i]);
34+
}
35+
36+
return 0;
37+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2023-2024 Chen Xingyu <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: SOPHGO CVI series pin controller driver
5+
6+
compatible: "sophgo,cvi-pinctrl"
7+
8+
include: base.yaml
9+
10+
child-binding:
11+
description: CVI pinmux group
12+
13+
child-binding:
14+
properties:
15+
pinmux:
16+
required: true
17+
type: array

dts/riscv/sophgo/cv180x.dtsi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
#include <freq.h>
88

99
#include <sophgo/cv18xx-c906-common.dtsi>
10+
#include <zephyr/dt-bindings/pinctrl/sophgo-cv180x-pinctrl.h>
1011

1112
/ {
1213
soc {
1314
compatible = "sophgo,cv180x", "simple-bus";
1415

16+
pinctrl: pin-controller@3001000 {
17+
compatible = "sophgo,cvi-pinctrl";
18+
reg = <0x3001000 DT_SIZE_K(4)>;
19+
};
20+
1521
gpioa: gpio@3020000 {
1622
compatible = "snps,designware-gpio";
1723
reg = <0x3020000 DT_SIZE_K(4)>;

dts/riscv/sophgo/cv181x.dtsi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
#include <freq.h>
88

99
#include <sophgo/cv18xx-c906-common.dtsi>
10+
#include <zephyr/dt-bindings/pinctrl/sophgo-cv181x-pinctrl.h>
1011

1112
/ {
1213
soc {
1314
compatible = "sophgo,cv181x", "simple-bus";
1415

16+
pinctrl: pin-controller@3001000 {
17+
compatible = "sophgo,cvi-pinctrl";
18+
reg = <0x3001000 DT_SIZE_K(4)>;
19+
};
20+
1521
gpioa: gpio@3020000 {
1622
compatible = "snps,designware-gpio";
1723
reg = <0x3020000 DT_SIZE_K(4)>;

0 commit comments

Comments
 (0)