Skip to content

Commit 27dbe61

Browse files
committed
drivers: pinctrl: bouffalolab: Add bflb pinctrl driver
Add Bouffalo Lab pinctrl driver. Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent 63f3a54 commit 27dbe61

File tree

11 files changed

+334
-0
lines changed

11 files changed

+334
-0
lines changed

drivers/pinctrl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ zephyr_library()
55
zephyr_library_sources(common.c)
66
zephyr_library_sources_ifdef(CONFIG_PINCTRL_TELINK_B91 pinctrl_b91.c)
77
zephyr_library_sources_ifdef(CONFIG_PINCTRL_AMBIQ pinctrl_ambiq.c)
8+
zephyr_library_sources_ifdef(CONFIG_PINCTRL_BFLB pinctrl_bflb.c)
89
zephyr_library_sources_ifdef(CONFIG_PINCTRL_GD32_AF pinctrl_gd32_af.c)
910
zephyr_library_sources_ifdef(CONFIG_PINCTRL_GD32_AFIO pinctrl_gd32_afio.c)
1011
zephyr_library_sources_ifdef(CONFIG_PINCTRL_ITE_IT8XXX2 pinctrl_ite_it8xxx2.c)

drivers/pinctrl/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ config PINCTRL_DYNAMIC
3434
peripheral at early boot stages depending on a certain input.
3535

3636
source "drivers/pinctrl/Kconfig.b91"
37+
source "drivers/pinctrl/Kconfig.bflb"
3738
source "drivers/pinctrl/Kconfig.ambiq"
3839
source "drivers/pinctrl/Kconfig.gd32"
3940
source "drivers/pinctrl/Kconfig.it8xxx2"

drivers/pinctrl/Kconfig.bflb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2021-2025 Gerson Fernando Budke <[email protected]>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
config PINCTRL_BFLB
6+
bool "Bouffalo Lab pin control driver"
7+
depends on DT_HAS_BFLB_PINCTRL_ENABLED
8+
default y
9+
help
10+
Bouffalo Lab pin control driver

drivers/pinctrl/pinctrl_bflb.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2021-2025 Gerson Fernando Budke <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/drivers/pinctrl.h>
9+
#include <bflb_pinctrl.h>
10+
#include <bflb_glb.h>
11+
#include <bflb_gpio.h>
12+
13+
/* clang-format off */
14+
15+
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt,
16+
uintptr_t reg)
17+
{
18+
GLB_GPIO_Cfg_Type pincfg;
19+
uint8_t i;
20+
21+
ARG_UNUSED(reg);
22+
23+
for (i = 0U; i < pin_cnt; i++) {
24+
pincfg.gpioFun = BFLB_PINMUX_GET_FUN(pins[i]);
25+
pincfg.gpioMode = BFLB_PINMUX_GET_MODE(pins[i]);
26+
pincfg.gpioPin = BFLB_PINMUX_GET_PIN(pins[i]);
27+
pincfg.pullType = BFLB_PINMUX_GET_PULL_MODES(pins[i]);
28+
pincfg.smtCtrl = BFLB_PINMUX_GET_SMT(pins[i]);
29+
pincfg.drive = BFLB_PINMUX_GET_DRIVER_STRENGTH(pins[i]);
30+
31+
if (pincfg.gpioFun == BFLB_PINMUX_FUN_INST_uart0) {
32+
GLB_UART_Fun_Sel(pincfg.gpioPin % 8,
33+
(BFLB_PINMUX_GET_INST(pins[i]))
34+
* 0x4U /* rts, cts, rx, tx */
35+
+ BFLB_PINMUX_GET_SIGNAL(pins[i])
36+
);
37+
}
38+
39+
GLB_GPIO_Init(&pincfg);
40+
}
41+
42+
return 0;
43+
}
44+
45+
/* clang-format on */

dts/bindings/gpio/bflb,gpio.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) 2021-2025 Gerson Fernando Budke <[email protected]>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
description: Bouffalo Lab GPIO node
6+
7+
compatible: "bflb,gpio"
8+
9+
include:
10+
- name: base.yaml
11+
- name: gpio-controller.yaml
12+
13+
properties:
14+
reg:
15+
required: true
16+
17+
interrupts:
18+
required: true
19+
20+
"#gpio-cells":
21+
const: 2
22+
23+
"#bflb,pin-cells":
24+
type: int
25+
required: true
26+
const: 2
27+
description: Number of items to expect in a bflb,pins specifier
28+
29+
gpio-cells:
30+
- pin
31+
- flags
32+
33+
bflb,pin-cells:
34+
- pin
35+
- peripheral
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright (c) 2021-2025 Gerson Fernando Budke <[email protected]>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
description: Bouffalo Lab Pinctrl node
6+
7+
compatible: "bflb,pinctrl"
8+
9+
include: base.yaml
10+
11+
properties:
12+
"#address-cells":
13+
required: true
14+
const: 1
15+
"#size-cells":
16+
required: true
17+
const: 1
18+
19+
child-binding:
20+
description: |
21+
Bouffalo Lab pin controller pin configuration nodes. Each node is composed
22+
by one or more groups, each defining the configuration for a set of pins.
23+
24+
child-binding:
25+
description: |
26+
Bouffalo Lab pin controller pin configuration group. Each group contains
27+
a list of pins sharing the same set of properties. Example:
28+
29+
uart0_default: uart0_default {
30+
/* group 1 (name is arbitrary) */
31+
group1 {
32+
/* configure to uart0 function plus modem interrupt, pin 7 as UART_RX
33+
pin 16 as UART_TX and finally pin 18 as gpio */
34+
pinmux = <GPIO7_UART0_RX>,
35+
<GPIO16_UART0_TX>;
36+
bias-pull-up;
37+
input-schmitt-enable;
38+
};
39+
};
40+
41+
uart0_sleep: uart0_sleep {
42+
group1 {
43+
pinmux = <GPIO7_UART0_RX>,
44+
<GPIO16_UART0_TX>;
45+
bias-high-impedance;
46+
};
47+
};
48+
49+
The list of supported standard properties:
50+
- bias-high-impedance: Disable pull-up/down (default behavior, not
51+
required).
52+
- bias-pull-up: Enable pull-up resistor.
53+
- bias-pull-down: Enable pull-down resistor.
54+
- input-enable: Enable GPIO as input (default behavior, not required).
55+
- input-schmitt-enable: Enable Schimitt Trigger when GPIO is Input.
56+
- output-enable: Enable GPIO as output.
57+
58+
Note that bias options are mutually exclusive. It is the same with GPIO
59+
input/output enable options.
60+
61+
include:
62+
- name: pincfg-node.yaml
63+
property-allowlist:
64+
- bias-high-impedance
65+
- bias-pull-down
66+
- bias-pull-up
67+
- input-enable
68+
- input-schmitt-enable
69+
- output-enable
70+
71+
properties:
72+
pinmux:
73+
required: true
74+
type: array
75+
description: |
76+
An array of pins sharing the same group properties. The pins should be
77+
defined using the BFLB_PINMUX utility macro that encode all the pin
78+
route matrix.
79+
drive-strength:
80+
type: int
81+
default: 0
82+
enum:
83+
- 0 # Default value, lower strength, 8mA
84+
- 1 # 9.6mA
85+
- 2 # 11.2mA
86+
- 3 # highest strength, 12.8mA
87+
description: |
88+
Pin drive strength. It tunes pin max current where 0 means lower
89+
value, which is the default, and 3 represents max drive strength.
90+
The driver will automatically apply the default value (8mA) to all
91+
pins to save power.

dts/riscv/bouffalolab/bl60x.dtsi

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include <freq.h>
88
#include <mem.h>
9+
#include <dt-bindings/pinctrl/bl60x-pinctrl.h>
10+
#include <dt-bindings/pinctrl/bflb-common-pinctrl.h>
911

1012
/ {
1113
#address-cells = <1>;
@@ -60,6 +62,27 @@
6062
interrupts-extended = <&ictrl 7>;
6163
};
6264

65+
pinctrl: pin-controller@40000000 {
66+
compatible = "bflb,pinctrl";
67+
reg = <0x40000000 0x1000>;
68+
ranges = <0x40000000 0x40000000 0x1000>;
69+
#address-cells = <1>;
70+
#size-cells = <1>;
71+
status = "okay";
72+
73+
glb: gpio@40000000 {
74+
compatible = "bflb,gpio";
75+
reg = <0x40000000 0x1000>;
76+
#gpio-cells = <2>;
77+
#bflb,pin-cells = <2>;
78+
status = "disabled";
79+
80+
gpio-controller;
81+
interrupts = <1 0>;
82+
interrupt-parent = <&ictrl>;
83+
};
84+
};
85+
6386
spi0: spi@4000a200 {
6487
compatible = "bflb,spi";
6588
reg = <0x4000a200 0x100>;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) 2021-2025 Gerson Fernando Budke <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file
9+
* Bouffalo Lab SoC specific helpers for pinctrl driver
10+
*/
11+
12+
#ifndef ZEPHYR_INCLUDE_DRIVERS_PINCTRL_PINCTRL_SOC_BFLB_COMMON_H_
13+
#define ZEPHYR_INCLUDE_DRIVERS_PINCTRL_PINCTRL_SOC_BFLB_COMMON_H_
14+
15+
#include <zephyr/devicetree.h>
16+
#include <zephyr/types.h>
17+
18+
/* clang-format off */
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
/** @cond INTERNAL_HIDDEN */
25+
26+
/**
27+
* @brief BFLB pincfg bit field.
28+
* @anchor BFLB_PINMUX
29+
*
30+
* Fields:
31+
*
32+
* - 24..31: pin
33+
* - 20..23: signal
34+
* - 18..19: mode
35+
* - 16..17: instance
36+
* - 8..15: function
37+
* - 7: reserved
38+
* - 6: GPIO Output Enable
39+
* - 5: Pull Down
40+
* - 4: Pull Up
41+
* - 2..3: Driver Strength
42+
* - 1: Schmitt trigger (SMT)
43+
* - 0: reserved
44+
*/
45+
typedef uint32_t pinctrl_soc_pin_t;
46+
47+
/**
48+
* @brief Utility macro to initialize each pin.
49+
*
50+
* @param node_id Node identifier.
51+
* @param prop Property name.
52+
* @param idx Property entry index.
53+
*/
54+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
55+
((DT_PROP_BY_IDX(node_id, prop, idx)) \
56+
| (DT_PROP(node_id, bias_pull_up) << BFLB_PINMUX_PULL_UP_POS) \
57+
| (DT_PROP(node_id, bias_pull_down) << BFLB_PINMUX_PULL_DOWN_POS) \
58+
| (DT_PROP(node_id, output_enable) << BFLB_PINMUX_OE_POS) \
59+
| (DT_PROP(node_id, input_schmitt_enable) << BFLB_PINMUX_SMT_POS) \
60+
| (DT_ENUM_IDX(node_id, drive_strength) << BFLB_PINMUX_DRIVER_STRENGTH_POS) \
61+
),
62+
63+
/**
64+
* @brief Utility macro to initialize state pins contained in a given property.
65+
*
66+
* @param node_id Node identifier.
67+
* @param prop Property name describing state pins.
68+
*/
69+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
70+
{DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), \
71+
DT_FOREACH_PROP_ELEM, pinmux, \
72+
Z_PINCTRL_STATE_PIN_INIT)}
73+
74+
/** @endcond */
75+
76+
#ifdef __cplusplus
77+
}
78+
#endif
79+
80+
/* clang-format on */
81+
82+
#endif /* ZEPHYR_INCLUDE_DRIVERS_PINCTRL_PINCTRL_SOC_BFLB_COMMON_H_ */
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2021-2025 Gerson Fernando Budke <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_HAL_BFLB_GPIO_H_
8+
#define ZEPHYR_HAL_BFLB_GPIO_H_
9+
10+
#ifdef CONFIG_SOC_SERIES_BL60X
11+
#include <bl602_gpio.h>
12+
#endif
13+
14+
#endif /* ZEPHYR_HAL_BFLB_GPIO_H_ */
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2021-2025 Gerson Fernando Budke <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_HAL_BFLB_PINCTRL_H_
8+
#define ZEPHYR_HAL_BFLB_PINCTRL_H_
9+
10+
#ifdef CONFIG_SOC_SERIES_BL60X
11+
#include <zephyr/dt-bindings/pinctrl/bl60x-pinctrl.h>
12+
#endif
13+
#include <zephyr/dt-bindings/pinctrl/bflb-common-pinctrl.h>
14+
15+
#endif /* ZEPHYR_HAL_BFLB_PINCTRL_H_ */

0 commit comments

Comments
 (0)