1# Copyright (c) 2021 Teslabs Engineering S.L. 2# SPDX-License-Identifier: Apache-2.0 3 4description: | 5 The GD32 pin controller (AFIO model) is a singleton node responsible for 6 controlling pin function selection and pin properties. For example, you can 7 use this node to route USART0 RX to pin PA10 and enable the pull-up resistor 8 on the pin. Remapping is also supported. 9 10 The node has the 'pinctrl' node label set in your SoC's devicetree, 11 so you can modify it like this: 12 13 &pinctrl { 14 /* your modifications go here */ 15 }; 16 17 All device pin configurations should be placed in child nodes of the 18 'pinctrl' node, as shown in this example: 19 20 /* You can put this in places like a board-pinctrl.dtsi file in 21 * your board directory, or a devicetree overlay in your application. 22 */ 23 24 /* include pre-defined combinations for the SoC variant used by the board */ 25 #include <dt-bindings/pinctrl/gd32f403z(k-i-g-e-c-b)xx-pinctrl.h> 26 27 &pinctrl { 28 /* configuration for the usart0 "default" state */ 29 usart0_default: usart0_default { 30 /* group 1 */ 31 group1 { 32 /* configure PA9 as USART0 TX and PA11 as USART0 CTS (no remap) */ 33 pinmux = <USART0_TX_PA9_NORMP>, <USART0_CTS_PA11_NORMP>; 34 }; 35 /* group 2 */ 36 group2 { 37 /* configure PA10 as USART0 RX and PA12 as USART0 RTS (no remap) */ 38 pinmux = <USART0_RX_PA10_NORMP>, <USART0_RTS_PA12_NORMP>; 39 /* both PA10 and PA12 have pull-up enabled */ 40 bias-pull-up; 41 }; 42 43 /* configuration for the usart0 "sleep" state */ 44 usart0_sleep: usart0_sleep { 45 /* group 1 */ 46 group1 { 47 /* configure PA9, PA10, PA11 and PA12 in analog mode */ 48 pinmux = <ANALOG_PA9>, <ANALOG_PA10>, <ANALOG_PA12>, <ANALOG_PA11>; 49 }; 50 }; 51 52 The 'usart0_default' child node encodes the pin configurations for a 53 particular state of a device; in this case, the default (that is, active) 54 state. Similarly, 'usart0_sleep' child node encodes the pin configurations 55 for the sleep state (used in device low power mode). Note that analog mode 56 is used for low power states because it disconnects the pin pull-up/down 57 resistor, schmitt trigger, and output buffer. 58 59 As shown, pin configurations are organized in groups within each child node. 60 Each group can specify a list of pin function selections in the 'pinmux' 61 property. 62 63 A group can also specify shared pin properties common to all the specified 64 pins, such as the 'bias-pull-up' property in group 2. Here is a list of 65 supported standard pin properties: 66 67 - drive-push-pull: Push-pull drive mode (default, not required). Only 68 applies for GPIO_IN mode. 69 - drive-open-drain: Open-drain drive mode. Only applies for GPIO_IN mode. 70 - bias-disable: Disable pull-up/down (default, not required). Only applies 71 for GPIO_IN mode. 72 - bias-pull-up: Enable pull-up resistor. Only applies for GPIO_IN mode. 73 - bias-pull-down: Enable pull-down resistor. Only applies for GPIO_IN mode. 74 - slew-rate: Set the maximum speed (and so the slew-rate) of the output 75 signal (default: 2MHz). Only applies for ALTERNATE mode. 76 77 Note that drive and bias options are mutually exclusive. 78 79 Peripherals that are remappable will have their pre-defined macros suffixed 80 with the remap option being selected, for example: 81 82 - CAN0_RX_PA11_NORMP: No remap 83 - CAN0_RX_PB8_PRMP: Partial remap 84 - CAN0_RX_PD0_FRMP: Full remap 85 86 It is important that **ALL** pinmux entries share the same remap. For 87 example: 88 89 &pinctrl { 90 can0_default: can0_default { 91 group1 { 92 pinmux = <CAN0_RX_PD0_FRMP>, <CAN0_TX_PD1_FRMP>; 93 /* ^^^^ ^^^^ */ 94 /* CAN0 pins are remapped choosing the full remap option */ 95 }; 96 }; 97 }; 98 99 To link pin configurations with a device, use a pinctrl-N property for some 100 number N, like this example you could place in your board's DTS file: 101 102 #include "board-pinctrl.dtsi" 103 104 &usart0 { 105 pinctrl-0 = <&usart0_default>; 106 pinctrl-1 = <&usart0_sleep>; 107 pinctrl-names = "default", "sleep"; 108 }; 109 110compatible: "gd,gd32-pinctrl-afio" 111 112include: gd,gd32-pinctrl-common.yaml 113 114child-binding: 115 description: | 116 Each child node defines the configuration for a particular state. 117 child-binding: 118 description: | 119 The grandchild nodes group pins that share the same pin configuration. 120 properties: 121 slew-rate: 122 type: string 123 default: "max-speed-2mhz" 124 enum: 125 - "max-speed-10mhz" 126 - "max-speed-2mhz" 127 - "max-speed-50mhz" 128 - "max-speed-highest" 129 description: | 130 Set the maximum speed of a pin. This setting effectively limits the 131 slew rate of the output signal. Defaults to "max-speed-2mhz", the SoC 132 default. The max-speed-highest option may not be available on all SoC 133 variants. If selected and not available the 50 MHz maximum speed will 134 be used instead. Note that usage of max-speed-highest may require 135 enabling the I/O compensation cell (refer to the gd,gd32-afio binding 136 for more details). 137