Skip to content

Commit e9fa65f

Browse files
committed
dts: gd32e1: change gd32 pinctrl
change gd32 pinctrl Signed-off-by: YuLong Yao <[email protected]>
1 parent b1a41a6 commit e9fa65f

File tree

5 files changed

+202
-44
lines changed

5 files changed

+202
-44
lines changed

boards/arm/gd32e103v_eval/gd32e103v_eval.dts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/dts-v1/;
99

1010
#include <gigadevice/e1/gd32e103Xb.dtsi>
11-
#include <gd/e1/gd32e103c(b-c-e)tx-pinctrl.dtsi>
11+
#include <gd/e1/gd32e103v(8-b)tx-pinctrl.dtsi>
1212

1313
/ {
1414
model = "GigaDevice GD32E103VB-EVAL board";

dts/arm/gigadevice/e1/gd32e1.dtsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@
144144
reg = <0x40010400 0x400>;
145145
};
146146

147-
pinctrl: pin-controller@40010000 {
147+
pinctrl: pin-controller@40010800 {
148148
compatible = "gd,gd32-pinctrl";
149149
#address-cells = <1>;
150150
#size-cells = <1>;
151-
reg = <0x40010000 0x2000>;
151+
reg = <0x40010800 0x2000>;
152152

153153
gpioa: gpio@40010800 {
154154
compatible = "gd,gd32-gpio";
Lines changed: 68 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,104 @@
11
# Copyright (c) 2020 Linaro Limited
22
# SPDX-License-Identifier: Apache-2.0
33

4-
description: |
5-
GD32 Pin controller Node
6-
Based on pincfg-node.yaml binding.
7-
8-
Note: `bias-disable` and `drive-push-pull` are default pin configurations.
9-
They will be applied in case no `bias-foo` or `driver-bar` properties
10-
are set.
4+
description: GD32 Pin controller Node
115

126
compatible: "gd,gd32-pinctrl"
137

14-
include:
15-
- name: base.yaml
16-
- name: pincfg-node.yaml
17-
child-binding:
18-
property-allowlist:
19-
- bias-disable
20-
- bias-pull-down
21-
- bias-pull-up
22-
- drive-push-pull
23-
- drive-open-drain
8+
include: [base.yaml]
249

2510
properties:
2611
reg:
2712
required: true
2813

2914
child-binding:
3015
description: |
31-
This binding gives a base representation of the STM32 pins configration
16+
This binding gives a base representation of the GD32F1 pins
17+
configration
3218
3319
properties:
3420
pinmux:
3521
required: true
3622
type: int
3723
description: |
38-
Reused from https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/pinctrl/st,stm32-pinctrl.yaml
3924
Integer array, represents gpio pin number and mux setting.
40-
These defines are calculated as: ((port * 16 + line) << 8) | function
25+
These defines are calculated as: ((port * 16 + line) << 8) | (function << 6) | remap)
4126
With:
4227
- port: The gpio port index (PA = 0, PB = 1, ..., PK = 11)
4328
- line: The line offset within the port (PA0 = 0, PA1 = 1, ..., PA15 = 15)
44-
- function: The function number, can be:
45-
* 0 : Alternate Function 0
46-
* 1 : Alternate Function 1
47-
* 2 : Alternate Function 2
48-
* ...
49-
* 15 : Alternate Function 15
50-
* 16 : Analog
29+
- function: The configuration mode, can be:
30+
* 0 : Alternate function output
31+
* 1 : Input
32+
* 2 : Analog
33+
- remap: The pin remapping configuration. It allows to assign the pin
34+
function to a different peripheral. Remain configuration can be:
35+
* 0 : No remap
36+
* 1 : Partial remap 1
37+
* 2 : Partial remap 2
38+
* 3 : Partial remap 3
39+
* 4 : Full remap
5140
To simplify the usage, macro is available to generate "pinmux" field.
5241
This macro is available here:
53-
-include/dt-bindings/pinctrl/stm32-pinctrl-common.h
42+
-include/dt-bindings/pinctrl/gd32-pinctrl.h
5443
Some examples of macro usage:
55-
GPIO A9 set as alernate function 2
44+
GPIO A9 set as alernate with no remap
45+
... {
46+
pinmux = <GD32F1_PINMUX('A', 9, ALTERNATE, REMAP_NO)>;
47+
};
48+
GPIO A9 set as alernate with full remap
5649
... {
57-
pinmux = <STM32_PINMUX('A', 9, AF2)>;
50+
pinmux = <GD32F1_PINMUX('A', 9, ALTERNATE, REMAP_FULL)>;
5851
};
59-
GPIO A9 set as analog
52+
GPIO A9 set as input
6053
... {
61-
pinmux = <STM32_PINMUX('A', 9, ANALOG)>;
54+
pinmux = <GD32F1_PINMUX('A', 9, GPIO_IN, REMAP_NO)>;
6255
};
6356
57+
bias-disable:
58+
required: false
59+
type: boolean
60+
description: |
61+
Pin bias (push-pull) disabled. This is the default pin
62+
configuration and will be applied if no bias- property is
63+
specified. Only available in input mode ("floating" configuration).
64+
65+
bias-pull-down:
66+
required: false
67+
type: boolean
68+
description: |
69+
Weak pull down resistor enabled. Not compatible with
70+
output configuration modes (atlernate or general purpose output).
71+
72+
bias-pull-up:
73+
required: false
74+
type: boolean
75+
description: |
76+
Weak pull up resistor enabled. Not compatible with
77+
output configuration modes (atlernate or general purpose output).
78+
79+
drive-push-pull:
80+
required: false
81+
type: boolean
82+
description: |
83+
Pin driven actively high and low. This is the default pin
84+
configueration and will be applied if no drive- property is
85+
specified. Only valid for output configuration modes.
86+
87+
drive-open-drain:
88+
required: false
89+
type: boolean
90+
description: |
91+
Pin driven in open drain. Only valid for output
92+
configuration modes.
93+
6494
slew-rate:
6595
required: false
6696
type: string
67-
default: "low-speed"
97+
default: "max-speed-10mhz"
6898
enum:
69-
- "low-speed" # Default value.
70-
- "medium-speed"
71-
- "high-speed"
72-
- "very-high-speed"
99+
- "max-speed-10mhz" # Default
100+
- "max-speed-2mhz"
101+
- "max-speed-50mhz"
73102
description: |
74-
Pin speed. Default to low-speed. For few pins (PA11 and
75-
PB3 depending on SoCs)hardware reset value could differ
76-
(very-high-speed). Carefully check reference manual for these pins.
103+
Pin output mode, maximum achievable speed. Only applies to
104+
output mode (alternate).

include/dt-bindings/pinctrl/gd32-pinctrl.h

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,134 @@
223223
#define GD32_PIN_PK14 GD32PIN(GD32_PORTK, 14)
224224
#define GD32_PIN_PK15 GD32PIN(GD32_PORTK, 15)
225225

226+
/**
227+
* @brief Macro to generate pinmux int using port, pin number and mode arguments
228+
*/
229+
230+
#define PIN_NO(port, line) (((port) - 'A') * 0x10 + (line))
231+
#define GD32_PINMUX(port, line, mode, remap) \
232+
(((PIN_NO(port, line)) << 8) | (mode << 6) | (remap))
233+
234+
/**
235+
* @brief Pin modes
236+
*/
237+
238+
#define ALTERNATE 0x0 /* Alternate function output */
239+
#define GPIO_IN 0x1 /* Input */
240+
#define ANALOG 0x2 /* Analog */
241+
242+
/**
243+
* @brief Pin remapping configurations
244+
*/
245+
246+
#define NO_REMAP 0x0 /* No remapping */
247+
#define REMAP_1 0x1 /* Partial remapping 1 */
248+
#define REMAP_2 0x2 /* Partial remapping 2 */
249+
#define REMAP_3 0x3 /* Partial remapping 3 */
250+
#define REMAP_FULL 0x4 /* Full remapping */
251+
252+
/**
253+
* @brief PIN configuration bitfield
254+
*
255+
* Pin configuration is coded with the following
256+
* fields
257+
* GPIO I/O Mode [ 0 ]
258+
* GPIO Input config [ 1 : 2 ]
259+
* GPIO Output speed [ 3 : 4 ]
260+
* GPIO Output PP/OD [ 5 ]
261+
* GPIO Output AF/GP [ 6 ]
262+
* GPIO PUPD Config [ 7 : 8 ]
263+
*
264+
* Applicable to GD32F1 series
265+
*/
266+
267+
/* Alternate functions */
268+
/* GD32F1 Pinmux doesn't use explicit alternate functions */
269+
/* These are kept for compatibility with other GD32 pinmux */
270+
#define GD32_AFR_MASK 0
271+
#define GD32_AFR_SHIFT 0
272+
273+
/* Port Mode */
274+
#define GD32_MODE_INPUT (0x0<<GD32_MODE_INOUT_SHIFT)
275+
#define GD32_MODE_OUTPUT (0x1<<GD32_MODE_INOUT_SHIFT)
276+
#define GD32_MODE_INOUT_MASK 0x1
277+
#define GD32_MODE_INOUT_SHIFT 0
278+
279+
/* Input Port configuration */
280+
#define GD32_CNF_IN_ANALOG (0x0<<GD32_CNF_IN_SHIFT)
281+
#define GD32_CNF_IN_FLOAT (0x1<<GD32_CNF_IN_SHIFT)
282+
#define GD32_CNF_IN_PUPD (0x2<<GD32_CNF_IN_SHIFT)
283+
#define GD32_CNF_IN_MASK 0x3
284+
#define GD32_CNF_IN_SHIFT 1
285+
286+
/* Output Port configuration */
287+
#define GD32_MODE_OUTPUT_MAX_10 (0x0<<GD32_MODE_OSPEED_SHIFT)
288+
#define GD32_MODE_OUTPUT_MAX_2 (0x1<<GD32_MODE_OSPEED_SHIFT)
289+
#define GD32_MODE_OUTPUT_MAX_50 (0x2<<GD32_MODE_OSPEED_SHIFT)
290+
#define GD32_MODE_OSPEED_MASK 0x3
291+
#define GD32_MODE_OSPEED_SHIFT 3
292+
293+
#define GD32_CNF_PUSH_PULL (0x0<<GD32_CNF_OUT_0_SHIFT)
294+
#define GD32_CNF_OPEN_DRAIN (0x1<<GD32_CNF_OUT_0_SHIFT)
295+
#define GD32_CNF_OUT_0_MASK 0x1
296+
#define GD32_CNF_OUT_0_SHIFT 5
297+
298+
#define GD32_CNF_GP_OUTPUT (0x0<<GD32_CNF_OUT_1_SHIFT)
299+
#define GD32_CNF_ALT_FUNC (0x1<<GD32_CNF_OUT_1_SHIFT)
300+
#define GD32_CNF_OUT_1_MASK 0x1
301+
#define GD32_CNF_OUT_1_SHIFT 6
302+
303+
/* GPIO High impedance/Pull-up/Pull-down */
304+
#define GD32_PUPD_NO_PULL (0x0<<GD32_PUPD_SHIFT)
305+
#define GD32_PUPD_PULL_UP (0x1<<GD32_PUPD_SHIFT)
306+
#define GD32_PUPD_PULL_DOWN (0x2<<GD32_PUPD_SHIFT)
307+
#define GD32_PUPD_MASK 0x3
308+
#define GD32_PUPD_SHIFT 7
309+
310+
/* Alternate defines */
311+
/* IO pin functions are mostly common across GD32 devices. Notable
312+
* exception is GD32F1 as these MCUs do not have registers for
313+
* configuration of pin's alternate function. The configuration is
314+
* done implicitly by setting specific mode and config in MODE and CNF
315+
* registers for particular pin.
316+
*/
317+
#define GD32_ALTERNATE (GD32_MODE_OUTPUT | GD32_CNF_ALT_FUNC)
318+
319+
#define GD32_PIN_USART_TX (GD32_ALTERNATE | GD32_CNF_PUSH_PULL)
320+
#define GD32_PIN_USART_RX (GD32_MODE_INPUT | GD32_CNF_IN_FLOAT)
321+
#define GD32_PIN_I2C (GD32_ALTERNATE | GD32_CNF_OPEN_DRAIN)
322+
#define GD32_PIN_PWM (GD32_ALTERNATE | GD32_CNF_PUSH_PULL)
323+
#define GD32_PIN_SPI_MASTER_SCK (GD32_ALTERNATE | GD32_CNF_PUSH_PULL)
324+
#define GD32_PIN_SPI_SLAVE_SCK (GD32_MODE_INPUT | GD32_CNF_IN_FLOAT)
325+
#define GD32_PIN_SPI_MASTER_MOSI (GD32_ALTERNATE | GD32_CNF_PUSH_PULL)
326+
#define GD32_PIN_SPI_SLAVE_MOSI (GD32_MODE_INPUT | GD32_CNF_IN_FLOAT)
327+
#define GD32_PIN_SPI_MASTER_MISO (GD32_MODE_INPUT | GD32_CNF_IN_FLOAT)
328+
#define GD32_PIN_SPI_SLAVE_MISO (GD32_ALTERNATE | GD32_CNF_PUSH_PULL)
329+
#define GD32_PIN_CAN_TX (GD32_ALTERNATE | GD32_CNF_PUSH_PULL)
330+
#define GD32_PIN_CAN_RX (GD32_MODE_INPUT | GD32_PUPD_PULL_UP)
331+
332+
/*
333+
* Reference manual (RM0008)
334+
* Section 25.3.1: Slave select (NSS) pin management
335+
*
336+
* Hardware NSS management:
337+
* - NSS output disabled: allows multimaster capability for devices operating
338+
* in master mode.
339+
* - NSS output enabled: used only when the device operates in master mode.
340+
*
341+
* Software NSS management:
342+
* - External NSS pin remains free for other application uses.
343+
*
344+
*/
345+
346+
/* Hardware master NSS output disabled */
347+
#define GD32_PIN_SPI_MASTER_NSS (GD32_MODE_INPUT | GD32_CNF_IN_FLOAT)
348+
/* Hardware master NSS output enabled */
349+
#define GD32_PIN_SPI_MASTER_NSS_OE (GD32_MODE_OUTPUT | \
350+
GD32_CNF_ALT_FUNC | \
351+
GD32_CNF_PUSH_PULL)
352+
#define GD32_PIN_SPI_SLAVE_NSS (GD32_MODE_INPUT | GD32_CNF_IN_FLOAT)
353+
#define GD32_PIN_USB (GD32_MODE_INPUT | GD32_CNF_IN_PUPD)
354+
355+
226356
#endif /* ZEPHYR_GD32_PINCTRL_COMMON_H_ */

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ manifest:
137137
- hal
138138
- name: hal_gd32
139139
remote: feilongfl_temp
140-
revision: 3b4c2f7fdf8e67387e43f5939bb829a52ad2a575
140+
revision: c8c63a71d8eed34dd896580aab01617f43e45a6e
141141
path: modules/hal/gigadevice
142142
- name: libmetal
143143
revision: 39d049d4ae68e6f6d595fce7de1dcfc1024fb4eb

0 commit comments

Comments
 (0)