How to setup pins of SP7021 in device-tree source

How to setup pins of SP7021 in device-tree source

The aim of this document is to explain how to setup pins of SP7021 in device-tree source. SP7021 has 99 general purpose IO (GPIO) pins which are multiplexed with other special functions, like eMMC device, SPI-NOR flash, SPI-NAND flash, Ethernet phy, UART, I2C control pins, and etc. Some special function pins are multiplexed on specified pins group while some special function pins are fully multiplexed on anyone pin of GPIO8 ~ GPIO72. The following sections will explain how to setup GPIOs and special function pins in device-tree source file in Linux.

Source files of SP7021 can be got from GitHub. Refer to https://github.com/sunplus-plus1/SP7021 or 2. HOW TO GET SOURCE FILE AND PACKAGE.

Please note that to comply with Linux rules, after version 5.10.59, 4 property-names of pin node of SP7021 are changed as shown in table below:

5.4.35

5.10.59

5.4.35

5.10.59

sppctl,function

function

sppctl,groups

groups

sppctl,pins

sunplus,pins

sppctl,zero_func

sunplus,zerofunc

1. Device-tree source

Device-tree source (dts) files of SP7021 are put in folder linux/kernel/arch/arm/boot/dts/. Here lists all files for SP7021 boards:

Boards

Device-tree source files

Boards

Device-tree source files

Sunplus SP7021 Ev board

sp7021-ev.dts

Tibbo LTPP3G2 board

sp7021-ltpp3g2revD.dts

Sunplus SP7021 Demo board (V1/V2)

sp7021-demov2.dts

Sunplus SP7021 Demo board (V3)

sp7021-demov3.dts

BananaPi BPI-F2S board

sp7021-bpi-f2s.dts

BananaPi BPI-F2P board

sp7021-bpi-f2p.dts

A file is shared with all SP7021 boards:

sp7021-common.dtsi

2. GPIO

SP7021 has 99 general purpose IO (GPIO) pins. Most of them are multiplexed with other special function pins. The session explains how to modify device-tree source file to set up GPIO pins as digital input or output pins.

2.1 Define GPIO in device-tree source file

Every device should have a node in device-tree source (dts) file in Linux. Property pinctrl-0 (or pinctrl-1, pinctrl-2,… if a device has more states) is used to point at pin configuration node within pin controller (node pinctl@9c000100 in SP7021). Pin configuration nodes (sub-nodes in node pinctl@9c000100) define the actual pins assignment.

To set up GPIOs as digital input or output pins for a device, users need to add properties pinctrl-names and pinctrl-0 to a node (device) in device-tree source file. For example,

mipicsi0: mipicsirx@9c005280 { : : pinctrl-names = "default"; pinctrl-0 = <&mipicsi0_pins>; cam_gpio0-gpios = <&pctl 92 GPIO_ACTIVE_HIGH>; cam_gpio1-gpios = <&pctl 93 GPIO_ACTIVE_HIGH>; : : };

where property pinctrl-0 sets up pins of mipicsirx@9c005280 device for “default” state. It is a handle (an address) to sub-node of pin-controller node.

Property cam_gpio0-gpios and cam_gpio1-gpios define two GPIO pins to GPIO92 and GPIO93 of pin controller, respectively. Linux driver can get GPIO descriptors using the two properties. pctl is a handle (an address) to pin controller.

The following device-tree source of SP7021 shows definitions of sub-node pinmux_mipicsi0-pins of node pinctl@9c000100.

pctl: pinctl@9c000100 { : : mipicsi0_pins: pinmux_mipicsi0-pins { sunplus,pins = < SPPCTL_IOPAD(92, SPPCTL_PCTL_G_GPIO, 0, SPPCTL_PCTL_L_OU1) SPPCTL_IOPAD(93, SPPCTL_PCTL_G_GPIO, 0, SPPCTL_PCTL_L_OU1) >; }; : : }

Property sunplus,pins defines all pins of a device. Each pin is defined by macro SPPCTL_IOPAD. The fisrt item

SPPCTL_IOPAD(92, SPPCTL_PCTL_G_GPIO, 0, SPPCTL_PCTL_L_OU1)

defines that GPIO92 pin as digital output pin and by default output LOW.

The second item

SPPCTL_IOPAD(93, SPPCTL_PCTL_G_GPIO, 0, SPPCTL_PCTL_L_OU1)

defines that GPIO93 pin as digital output pin and by default output LOW.

The first argument of SPPCTL_IOPAD is GPIO number which device function pin is going to multiplex. The second argument of SPPCTL_IOPAD should be SPPCTL_PCTL_G_GPIO for general purpose digital input output pins. The third argument should always be 0. The fourth define the type general purpose input output pin. Support pin type of general purpose input output are listed below:

Support type

Description

Support type

Description

SPPCTL_PCTL_L_INV

Invert input value

SPPCTL_PCTL_L_OUT

Enable output pin, output LOW by default

SPPCTL_PCTL_L_OU1

Enable output pin, output HIGH by default

SPPCTL_PCTL_L_ONV

Invert output value

SPPCTL_PCTL_L_ODR

Open-drain output.

By default (The fourth argument is 0.), general digital input output pin is an input pin. Add or OR above defines to change type of input or output. Note that SPPCTL_PCTL_L_OUT and SPPCTL_PCTL_L_OU1 cannot be OR-ed together (SPPCTL_PCTL_L_OUT|SPPCTL_PCTL_L_OU1).

2.2 Manipulate GPIO in Linux drivers

In above example, property cam_gpio0-gpios and cam_gpio1-gpios define two GPIO pins to GPIO92 and GPIO93 of pin controller, respectively. Linux drivers can use function devm_gpiod_get to GPIO descriptors using the two properties. Use gpiod_set_value to set value to GPIO or use gpiod_get_value to get value from GPIO. Refer to the following C example code.

struct gpio_desc *cam_gpio0; struct gpio_desc *cam_gpio1; : : // Get cam_gpio0. cam_gpio0 = devm_gpiod_get(&pdev->dev, "cam_gpio0", GPIOD_OUT_HIGH); if (!IS_ERR(cam_gpio0)) { printk(KERN_INFO "cam_gpio0 is at G_MX[%d].\n", desc_to_gpio(cam_gpio0)); } // Get cam_gpio1. cam_gpio1 = devm_gpiod_get(&pdev->dev, "cam_gpio1", GPIOD_OUT_HIGH); if (!IS_ERR(cam_gpio1)) { printk(KERN_INFO "cam_gpio1 is at G_MX[%d].\n", desc_to_gpio(cam_gpio1)); } : : gpiod_set_value(cam_gpio0, 0); gpiod_set_value(cam_gpio1, 0); :

2.3 Setup and access GPIO using sysfs

Users can setup and access GPIO using sysfs interface. Path of gpio of sysfs is /sys/class/gpio. Go to the folder and use ls command to list contents:

~ # cd /sys/class/gpio /sys/class/gpio # ls export gpiochip0 unexport /sys/class/gpio #

where export and unexport are write-only control interface. gpiochip0 is a GPIO controller (a “gpio_chip instance).

For example, you can set up GPIO16 (P2_00) as output pin using echo command. First, use echo command to export GPIO16:

/sys/class/gpio # echo 16 > export /sys/class/gpio # ls P2_00 export gpiochip0 unexport /sys/class/gpio #

where folder P2_00 (GPIO16) was created. Contents of P2_00 are:

/sys/class/gpio # ls P2_00 active_low direction subsystem value device power uevent /sys/class/gpio #

where active_low, direction and value are control interface.

Next, use echo command to setup GPIO16 as output port.

/sys/class/gpio # echo out > P2_00/direction /sys/class/gpio # cat P2_00/direction out /sys/class/gpio #

where read-back value of “out” means P2_00 (GPIO16) is set as output port.

Next, use echo command to write values to the port.

/sys/class/gpio # echo 1 > P2_00/value /sys/class/gpio # cat P2_00/value 1 /sys/class/gpio # echo 0 > P2_00/value /sys/class/gpio # cat P2_00/value 0 /sys/class/gpio #

Another example is setup GPIO17 (P2_01) as input port.

/sys/class/gpio # echo 17 > export /sys/class/gpio # ls P2_00 P2_01 export gpiochip0 unexport /sys/class/gpio # echo in > P2_01/direction /sys/class/gpio # cat P2_01/direction in /sys/class/gpio # cat P2_01/value 1 /sys/class/gpio #

GPIO17 (P2_01) is set as input port and the read-back value of the input port is 1.

Exported GPIO can be unexported:

/sys/class/gpio # ls P2_00 P2_01 export gpiochip0 unexport /sys/class/gpio # echo 16 > unexport /sys/class/gpio # echo 17 > unexport /sys/class/gpio # ls export gpiochip0 unexport /sys/class/gpio #

3. Special function pins

Some devices pins of SP7021 are multiplexed to specified pin-group of SP7021. The session explains how to modify device-tree source file to enable pins of those devices.

Every device should have a node in device-tree source (dts) file in Linux. Property pinctrl-0 (or pinctrl-1, pinctrl-2,… if a device has more states) is used to point at pin configuration node within pin controller (node pinctl@9c000100 in SP7021). Pin configuration nodes (sub-nodes in node pinctl@9c000100) define the actual pins assignment.

3.1 SPI-NOR flash

Pins of SPI-NOR flash of SP7021, [CLK, D1, CSN, D0], can be multiplexed to pin-group GPIO [83, 84, 86, 87] or pin-group GPIO [78, 79, 81, 76] when 1-bit or 2-bit mode is used. It’s 4-bit pins [D2, D3] can be multiplexed to pin-group GPIO [82, 85] or pin-group GPIO [77, 80].

To set up SPI-NOR flash pins, users need to add properties pinctrl-names and pinctrl-0 to SPI-NOR flash node spinor@9c000b00 in device-tree source file. For example,

sp_spinor0: spinor@9c000b00 { : pinctrl-names = "default"; pinctrl-0 = <&spi_flash2_mux &spi_fla4b2_mux>; : };

Property pinctrl-0 sets up pin-group of SPI-NOR flash for “default” state. It contains two items. The first is for pin-group [CLK, D1, CSN, D0] for 1-bit and 2-bit mode, the second is for 4-bit mode pin-group [D2, D3]. Both are handles (an address) to sub-nodes of pin-controller node.

The following device-tree source of SP7021 shows definitions of sub-nodes pinmux_spi_flash2-pins, pinmux_spi_flash2-pins, pinmux_spi_fla4b1-pins and pinmux_spi_fla4b2-pins of node pinctl@9c000100.

pctl: pinctl@9c000100 { : : spi_flash1_mux: pinmux_spi_flash1-pins { function = "SPI_FLASH"; groups = "SPI_FLASH1"; }; spi_flash2_mux: pinmux_spi_flash2-pins { function = "SPI_FLASH"; groups = "SPI_FLASH2"; }; spi_fla4b2_mux: pinmux_spi_fla4b1-pins { function = "SPI_FLASH_4BIT"; groups = "SPI_FLASH_4BIT1"; }; spi_fla4b1_mux: pinmux_spi_fla4b2-pins { function = "SPI_FLASH_4BIT"; groups = "SPI_FLASH_4BIT2"; }; : : }

String“SPI_FLASH1” is defined for pin-group GPIO [83, 84, 86, 87] and “SPI_FLASH2” is defined for pin-group GPIO [78, 79, 81, 76] for 1-bit or 2-bit mode. String “SPI_FLASH_4BIT1” is defined for pin-group GPIO [82, 85] and string “SPI_FLASH_4BIT2” is pin-group GPIO [77, 80] for 4-bit mode.

Property

pinctrl-0 = <&spi_flash2_mux &spi_fla4b2_mux>;

actually sets pins of SPI-NOR flash [CLK, D1, CSN, D0] to GPIO [78, 79, 81, 76] and [D2, D3] to GPIO [77, 80], respectively.

3.2 SPI-NAND flash

Pins of SPI-NAND flash of SP7021, [D0, D2, CLK, D1, D3, CSN], can be multiplexed to pin-group GPIO [76, 77, 78, 79, 80, 81]. To set up SPI-NAND flash pins, users need to add properties pinctrl-names and pinctrl-0 to SPI-NAND flash node spinand@9c002b80 in device-tree source file. For example,

spinand0: spinand@9c002b80 { : pinctrl-names = "default"; pinctrl-0 = <&pins_spinand0>; : };

Property pinctrl-0 sets up pin-group of SPI-NAND flash for “default” state. It is a handle (an address) to sub-node of pin-controller node.

The following device-tree source of SP7021 shows definition of sub-nodes pinmux_spinand0-pins of node pinctl@9c000100.

pctl: pinctl@9c000100 { : : pins_spinand0: pinmux_spinand0-pins { function = "SPI_NAND"; groups = "SPI_NAND"; }; : : }

String“SPI_NAND” is defined for the only pin-group of SPI-NAND flash. That is, GPIO [76, 77, 78, 79, 80, 81].

Property

pinctrl-0 = <&pins_spinand0>;

actually sets pins of SPI-NAND flash [D0, D2, CLK, D1, D3, CSN] to GPIO [76, 77, 78, 79, 80, 81].

3.3 eMMC device

Pins of eMMC device of SP7021, [CMD, D5, D3, D4, D0, D1, CLK, D2, D7, D6], can be multiplexed to pin-group GPIO [72, 73, 74, 75, 76, 77, 78, 79, 80, 81]. To set up eMMC device pins, users need to add properties pinctrl-names and pinctrl-0 to eMMC device node mmc@9c003b00 in device-tree source file. For example,

mmc0: mmc@9c003b00 { : pinctrl-names = "default"; pinctrl-0 = <&emmc_mux>; : };

Property pinctrl-0 sets up pin-group of eMMC device for “default” state. It is a handle (an address) to sub-node of pin-controller node.

The following device-tree source of SP7021 shows definition of sub-nodes pinmux_emmc-pins of node pinctl@9c000100.

pctl: pinctl@9c000100 { : : emmc_mux: pinmux_emmc-pins { function = "CARD0_EMMC"; groups = "CARD0_EMMC"; }; : : }

String“CARD0_EMMC” is defined for the only pin-group of eMMC device. That is, GPIO [72, 73, 74, 75, 76, 77, 78, 79, 80, 81].

Property

pinctrl-0 = <&emmc_mux>;

actually sets pins of eMMC device [CMD, D5, D3, D4, D0, D1, CLK, D2, D7, D6] to GPIO [72, 73, 74, 75, 76, 77, 78, 79, 80, 81].

3.4 SD Card

Pins of SD card of SP7021, [D1, D0, CLK, CMD, D3, D2], can be multiplexed to pin-group GPIO [65, 66, 67, 68, 69, 70]. To set up SD card pins, users need to add properties pinctrl-names and pinctrl-0 to SD card node sdcard@9c003e80 in device-tree source file. For example,

mmc1: sdcard@9c003e80 { : pinctrl-names = "default"; pinctrl-0 = <&mmc1_mux &mmc1_mux_cd>; : };

Property pinctrl-0 sets up pin-group of SD card for “default” state. It contains two items. The first is for pin-group of SD card, the second is for a GPIO for card detection (CD pin) of SD card. Both are handles (an address) to sub-nodes of pin-controller node.

The following device-tree source of SP7021 shows definitions of sub-nodes pinmux_mmc1-pins and pinmux_mmc1_cd-pins of node pinctl@9c000100.

pctl: pinctl@9c000100 { : : mmc1_mux: pinmux_mmc1-pins { function = "SD_CARD"; groups = "SD_CARD"; }; mmc1_mux_cd: pinmux_mmc1_cd-pins { sunplus,pins = < SPPCTL_IOPAD(91, SPPCTL_PCTL_G_GPIO, 0, 0) >; }; : : }

String“SD_CARD” is defined for the only pin-group of SD card. That is, GPIO [65, 66, 67, 68, 69, 70]. Node pinmux_mmc1_cd-pins defines GPIO91 as general purpose input pin. Refer to session 1. GIPO for detail.

Property

pinctrl-0 = <&mmc1_mux, &mmc1_mux_cd>;

actually sets pins of SD card [D1, D0, CLK, CMD, D3, D2] to GPIO [65, 66, 67, 68, 69, 70] and set GPIO [91] as input pin for card detection (CD).

3.5 UART0 device

Pins of UART0 device of SP7021, [TXD, RXD], can be multiplexed to pin-group GPIO [88, 89]. To set up UART0 device pins, users need to add properties pinctrl-names and pinctrl-0 to UART0 device node serial@9c000900 in device-tree source file. For example,

uart0: serial@9c000900 { : pinctrl-names = "default"; pinctrl-0 = <&pins_uart0>; : };

Property pinctrl-0 sets up pin-group of UART0 device for “default” state. It is a handle (an address) to sub-node of pin-controller node.

The following device-tree source of SP7021 shows definition of sub-nodes pinmux_uart0-pins of node pinctl@9c000100.

pctl: pinctl@9c000100 { : : pins_uart0: pinmux_uart0-pins { function = "UA0"; groups = "UA0"; }; : : }

String“UA0” is defined for the only pin-group of UART0 device. That is, GPIO [88, 89].

Property

pinctrl-0 = <&pins_uart0>;

actually sets pins of UART0 device flash [TXD, RXD] to GPIO [88, 89].

3.6 HDMI-TX

Control pins of HDMI-TX of SP7021, [HPD, SCL, SDA], can be multiplexed to pin-group GPIO [86, 97, 98], pin-group GPIO [67, 70, 69] or pin-group GPIO [60, 63, 62].

To set up HDMI-TX control pins, users need to add properties pinctrl-names and pinctrl-0 to HDMI-TX device node display@9c005c80 in device-tree source file. For example,

sp_display: display@9c005c80 { : pinctrl-names = "default"; pinctrl-0 = <&hdmi_A_tx3>; : };

Property pinctrl-0 sets up pin-group of HDMI-TX device for “default” state. It is a handle (an address) to sub-node of pin-controller node.

The following device-tree source of SP7021 shows definitions of sub-nodes pinmux_hdmi_tx1-pins, pinmux_hdmi_tx2-pins and pinmux_hdmi_tx3-pins of node pinctl@9c000100.

pctl: pinctl@9c000100 { : : hdmi_A_tx1: pinmux_hdmi_tx1-pins { function = "HDMI_TX"; groups = "HDMI_TX1"; }; hdmi_A_tx2: pinmux_hdmi_tx2-pins { function = "HDMI_TX"; groups = "HDMI_TX2"; }; hdmi_A_tx3: pinmux_hdmi_tx3-pins { function = "HDMI_TX"; groups = "HDMI_TX3"; }; : : }

String“HDMI_TX1” is defined for pin-group GPIO [86, 97, 98], “HDMI_TX2“ is defined for pin-group GPIO [67, 70, 69] and “HDMI_TX3” is defined for pin-group GPIO [60, 63, 62].

Property

pinctrl-0 = <&hdmi_A_tx3>;

actually sets control pins of HDMI-TX device [HPD, SCL, SDA] to GPIO [60, 63, 62].

4. Fully-multiplexed special function pins

Some devices of SP7021 support fully-multiplex pins. This means control pins of those devices can be multiplexed to any of GPIO pin from GPIO[8] to GPIO[71]. The session explains how to modify device-tree source file to enable pins of those devices.

Every device should have a node in device-tree source (dts) file in Linux. Property pinctrl-0 (or pinctrl-1, pinctrl-2,… if a device has more states) is used to point at pin configuration node within pin controller (node pinctl@9c000100 in SP7021). Pin configuration nodes (sub-nodes in node pinctl@9c000100) define the actual pins assignment.

The following devices of SP7021 support fully-multiplex: 2-port Ethernet (Layer 2 Switch, L2SW), SDIO, PWM (8-bit), ICM0~3, SPIM0~3, SPIS0~3, I2C0~I2C3, UART1~4, Timer0~3 and Interrupt (8-bit).

4.1 Ethernet

2 port Ethernet device have 22 pins totally. They are CLK_OUT, MAC_SMI_MDC, MAC_SMI_MDIO, LED_FLASH0, LED_FLASH1, LED_ON0, LED_ON1, P0_MAC_RMII_TXEN, P0_MAC_RMII_TXD0, P0_MAC_RMII_TXD1, P0_MAC_RMII_CRSDV, P0_MAC_RMII_RXD0, P0_MAC_RMII_RXD1, P0_MAC_RMII_RXER, P1_MAC_RMII_TXEN, P1_MAC_RMII_TXD0, P1_MAC_RMII_TXD1, P1_MAC_RMII_CRSDV, P1_MAC_RMII_RXD0, P1_MAC_RMII_RXD1, P1_MAC_RMII_RXER, and DAISY_MODE. All pins can be multiplexed to any pins of GPIO from GPIO[8] to GPIO[71]. Here lists the pin define used in device-tree source file:

MUXF_L2SW_CLK_OUT MUXF_L2SW_MAC_SMI_MDC MUXF_L2SW_MAC_SMI_MDIO MUXF_L2SW_LED_FLASH0 MUXF_L2SW_LED_FLASH1 MUXF_L2SW_LED_ON0 MUXF_L2SW_LED_ON1 MUXF_L2SW_P0_MAC_RMII_TXEN MUXF_L2SW_P0_MAC_RMII_TXD0 MUXF_L2SW_P0_MAC_RMII_TXD1 MUXF_L2SW_P0_MAC_RMII_CRSDV MUXF_L2SW_P0_MAC_RMII_RXD0 MUXF_L2SW_P0_MAC_RMII_RXD1 MUXF_L2SW_P0_MAC_RMII_RXER MUXF_L2SW_P1_MAC_RMII_TXEN MUXF_L2SW_P1_MAC_RMII_TXD0 MUXF_L2SW_P1_MAC_RMII_TXD1 MUXF_L2SW_P1_MAC_RMII_CRSDV MUXF_L2SW_P1_MAC_RMII_RXD0 MUXF_L2SW_P1_MAC_RMII_RXD1 MUXF_L2SW_P1_MAC_RMII_RXER MUXF_DAISY_MODE

To set up Ethernet pins, users need to add properties pinctrl-names and pinctrl-0 to Ethernet node l2sw@9c108000 in device-tree source file. For example,

l2sw: l2sw@9c108000 { : pinctrl-names = "default"; pinctrl-0 = <&l2sw_pins>; : };

Property pinctrl-0 sets up pins of Ethernet for “default” state. It is a handle (an address) to sub-node of pin-controller node.

The following device-tree source of SP7021 shows definitions of sub-node pinmux_l2sw-pins of node pinctl@9c000100.

pctl: pinctl@9c000100 { : : l2sw_pins: pinmux_l2sw-pins { sunplus,pins = < SPPCTL_IOPAD(40, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_CLK_OUT, 0) SPPCTL_IOPAD(41, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_MAC_SMI_MDC, 0) SPPCTL_IOPAD(42, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_MAC_SMI_MDIO, 0) SPPCTL_IOPAD(43, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P0_MAC_RMII_TXEN, 0) SPPCTL_IOPAD(44, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P0_MAC_RMII_TXD0, 0) SPPCTL_IOPAD(45, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P0_MAC_RMII_TXD1, 0) SPPCTL_IOPAD(46, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P0_MAC_RMII_CRSDV, 0) SPPCTL_IOPAD(47, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P0_MAC_RMII_RXD0, 0) SPPCTL_IOPAD(48, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P0_MAC_RMII_RXD1, 0) SPPCTL_IOPAD(49, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P1_MAC_RMII_TXEN, 0) SPPCTL_IOPAD(50, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P1_MAC_RMII_TXD0, 0) SPPCTL_IOPAD(51, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P1_MAC_RMII_TXD1, 0) SPPCTL_IOPAD(52, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P1_MAC_RMII_CRSDV, 0) SPPCTL_IOPAD(53, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P1_MAC_RMII_RXD0, 0) SPPCTL_IOPAD(54, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P1_MAC_RMII_RXD1, 0) >; sunplus,zerofunc = < MUXF_L2SW_LED_FLASH0 MUXF_L2SW_LED_FLASH1 MUXF_L2SW_LED_ON0 MUXF_L2SW_LED_ON1 MUXF_L2SW_P0_MAC_RMII_RXER MUXF_L2SW_P1_MAC_RMII_RXER MUXF_DAISY_MODE >; }; : : }

The pins of 2-port Ethernet are multiplexed as shown in the table:

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

CLK_OUT

40

P0_MAC_RMII_TXD1

45

P1_MAC_RMII_TXD0

50

MAC_SMI_MDC

41

P0_MAC_RMII_CRSDV

46

P1_MAC_RMII_TXD1

51

MAC_SMI_MDIO

42

P0_MAC_RMII_RXD0

47

P1_MAC_RMII_CRSDV

52

P0_MAC_RMII_TXEN

43

P0_MAC_RMII_RXD1

48

P1_MAC_RMII_RXD0

53

P0_MAC_RMII_TXD0

44

P1_MAC_RMII_TXEN

49

P1_MAC_RMII_RXD1

54

where function pins with prefix P0_ are for port 0 and with prefix P1_ are for port 1.

Property sunplus,pins defines all pins of a device. Each pin is defined by macro SPPCTL_IOPAD. For example, the first item

SPPCTL_IOPAD(40, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_CLK_OUT, 0)

defines that Ethernet clock pin, MUXF_L2SW_CLK_OUT (CLK_OUT), and it is multiplexed to GPIO[40].

The first argument of SPPCTL_IOPAD is GPIO number which device function pin is going to multiplex. The second argument of SPPCTL_IOPAD should be SPPCTL_PCTL_G_PMUX for fully-multiplex pins. The third argument of SPPCTL_IOPAD is function pin of a device. Fourth argument should always be 0.

Property sunplus,zerofunc defines all unused pins. Each unused pin should be added in the list. This make sure the unused pins will be output to any GPIO [8] to [71] accidentally.

The following device-tree source of SP7021 shows another example of definitions of sub-node pinmux_l2sw-pins of node pinctl@9c000100.

pctl: pinctl@9c000100 { : : l2sw_pins: pinmux_l2sw-pins { sunplus,pins = < SPPCTL_IOPAD(30, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_CLK_OUT, 0) SPPCTL_IOPAD(31, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_MAC_SMI_MDC, 0) SPPCTL_IOPAD(32, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_MAC_SMI_MDIO, 0) SPPCTL_IOPAD(33, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P0_MAC_RMII_TXEN, 0) SPPCTL_IOPAD(34, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P0_MAC_RMII_TXD0, 0) SPPCTL_IOPAD(35, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P0_MAC_RMII_TXD1, 0) SPPCTL_IOPAD(36, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P0_MAC_RMII_CRSDV, 0) SPPCTL_IOPAD(37, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P0_MAC_RMII_RXD0, 0) SPPCTL_IOPAD(38, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P0_MAC_RMII_RXD1, 0) >; }; : : }

The pins of port 0 of Ethernet are multiplexed as shown in the table:

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

CLK_OUT

30

P0_MAC_RMII_TXEN

33

P0_MAC_RMII_CRSDV

36

MAC_SMI_MDC

31

P0_MAC_RMII_TXD0

34

P0_MAC_RMII_RXD0

37

MAC_SMI_MDIO

32

P0_MAC_RMII_TXD1

35

P0_MAC_RMII_RXD1

38

where function pins with prefix P0_ are for port 0. Only port 0 of Ethernet is multiplexed to GPIO pins.

If only port 1 of Ethernet is going to be multiplexed to GPIO pins, the definitions of sub-node pinmux_l2sw-pins of node pinctl@9c000100. should look like, for example, this:

pctl: pinctl@9c000100 { : : l2sw_pins: pinmux_l2sw-pins { sunplus,pins = < SPPCTL_IOPAD(60, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_CLK_OUT, 0) SPPCTL_IOPAD(61, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_MAC_SMI_MDC, 0) SPPCTL_IOPAD(62, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_MAC_SMI_MDIO, 0) SPPCTL_IOPAD(63, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P1_MAC_RMII_TXEN, 0) SPPCTL_IOPAD(64, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P1_MAC_RMII_TXD0, 0) SPPCTL_IOPAD(65, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P1_MAC_RMII_TXD1, 0) SPPCTL_IOPAD(66, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P1_MAC_RMII_CRSDV, 0) SPPCTL_IOPAD(67, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P1_MAC_RMII_RXD0, 0) SPPCTL_IOPAD(68, SPPCTL_PCTL_G_PMUX, MUXF_L2SW_P1_MAC_RMII_RXD1, 0) >; }; : : }

The pins of port 1 of Ethernet are defined as shown in the table:

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

CLK_OUT

60

P1_MAC_RMII_TXEN

63

P1_MAC_RMII_CRSDV

66

MAC_SMI_MDC

61

P1_MAC_RMII_TXD0

64

P1_MAC_RMII_RXD0

67

MAC_SMI_MDIO

62

P1_MAC_RMII_TXD1

65

P1_MAC_RMII_RXD1

68

where function pins with prefix P1_ are for port 1. Only port 1 of Ethernet is multiplexed to GPIO pins.

4.2 SDIO interface

SDIO interface have 6 pins totally. They are CLK, CMD, D0, D1, D2, and D3. All pins can be multiplexed to any pins of GPIO from GPIO[8] to GPIO[71]. Here lists the pin define used in device-tree source file:

MUXF_SDIO_CLK MUXF_SDIO_CMD MUXF_SDIO_D0 MUXF_SDIO_D1 MUXF_SDIO_D2 MUXF_SDIO_D3

To set up SDIO interface pins, users need to add properties pinctrl-names and pinctrl-0 to SDIO node sdio@9c008400 in device-tree source file. For example,

sdio: sdio@9c008400 { : pinctrl-names = "default"; pinctrl-0 = <&pins_sdio>; : };

Property pinctrl-0 sets up pins of SDIO interface for “default” state. It is a handle (an address) to sub-node of pin-controller node.

The following device-tree source of SP7021 shows definitions of sub-node pinmux_sdio-pins of node pinctl@9c000100.

pctl: pinctl@9c000100 { : : pins_sdio: pinmux_sdio-pins { sunplus,pins = < SPPCTL_IOPAD(20, SPPCTL_PCTL_G_PMUX, MUXF_SDIO_CLK, 0) SPPCTL_IOPAD(21, SPPCTL_PCTL_G_PMUX, MUXF_SDIO_CMD, 0) SPPCTL_IOPAD(22, SPPCTL_PCTL_G_PMUX, MUXF_SDIO_D0, 0) SPPCTL_IOPAD(23, SPPCTL_PCTL_G_PMUX, MUXF_SDIO_D1, 0) SPPCTL_IOPAD(24, SPPCTL_PCTL_G_PMUX, MUXF_SDIO_D2, 0) SPPCTL_IOPAD(25, SPPCTL_PCTL_G_PMUX, MUXF_SDIO_D3, 0) >; }; : : }

The pins of SDIO interface are multiplexed as shown in the table:

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

Function Pins

GPIO

SDIO_CLK

20

SDIO_D0

22

SDIO_D2

24