Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

The aim of this document is to explain how to setup pins of SP7350 in device-tree source. SP7350 has 106 general purpose IO (GPIO) pins which are multiplexed with other special functions, like eMMC device, SPI-NOR flash, SPI-NAND flash, Ethernet PHY (RGMII or RMII interface), UART, I2C pins, and etc.

...

SP7350 has 106 GPIO pins. ID is from 0 to 105. Name is in form of GPIO(id), like GPIO0, GPIO1, GPIO2, GPIO99, GPIO105, and etc. There are two kinds of GPIO pins. One is 1.8V GPIO pins, and the other is 1.8V/3.0V Dual Voltage IO (DVIO) pins. Beside configure 1.8V or 3.0V power to power supply of a DVIO group in your circuit boards (hardware), you need to setup MS control in device-tree source. Refer to groups of GPIO and DVIO in appendix GPIO Table below in details.

...

Code Block
languagec
typec_pins: pinmux_typec-pins {
    pinsfunction = "GPIO98GPIO";
    functionpins = "GPIOGPIO98";
};
  1. Manipulate GPIO in Linux driver

In above example, property typec-gpios define one GPIO pin to GPIO98 of pin controller, respectively. Linux driver can use function devm_gpiod_get to get GPIO descriptor with the property. 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.

Code Block
languagec
struct gpio_desc *typec_gpio;
:
:
// Get typec_gpio.
typec_gpio = devm_gpiod_get(&pdev->dev, "typec", GPIOD_OUT_HIGH);
if (!IS_ERR(typec_gpio)) {
    printk(KERN_INFO "typec_gpio is at GPIO[%d].\n", desc_to_gpio(typec_gpio));
}
:
:
gpiod_set_value(typec_gpio, 0);
:
  1. Setup and access GPIO using sysfs

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

Code Block
languagebash
~ # cd /sys/class/gpio
/sys/class/gpio # ls
export     gpiochip0  unexport
/sys/class/gpio #

...

Example 1: Set up GPIO0 as output pin using echo command.

First, use echo command to export GPIO0:

Code Block
languagebash
/sys/class/gpio # echo 0 > export
/sys/class/gpio # ls
GPIO0      export     gpiochip0  unexport
/sys/class/gpio #

Folder GPIO0 was created. contents are:

Code Block
languagebash
/sys/class/gpio # ls GPIO0
active_low  direction   subsystem   value
device      power       uevent
/sys/class/gpio #

where active_low, direction and value are control interface.

Use echo command to setup GPIO0 as output port.

Code Block
languagebash
/sys/class/gpio # echo out > GPIO0/direction
/sys/class/gpio # cat GPIO0/direction
out
/sys/class/gpio #

Read-back value of "out" means GPIO0 is set as output port.

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

Code Block
languagebash
/sys/class/gpio # echo 1 > GPIO0/value
/sys/class/gpio # cat GPIO0/value
1
/sys/class/gpio # echo 0 > GPIO0/value
/sys/class/gpio # cat GPIO0/value
0
/sys/class/gpio #

Example 2:Setup GPIO0 as input port.

Code Block
languagebash
/sys/class/gpio # echo 0 > export
/sys/class/gpio # ls
GPIO0 		export     gpiochip0  unexport
/sys/class/gpio # echo in > GPIO0/direction
/sys/class/gpio # cat GPIO0/direction
in
/sys/class/gpio # cat GPIO0/value
1
/sys/class/gpio #

GPIO0 is set as input port and the read-back value of the input port is 1.

Exported GPIO can be unexported:

Code Block
languagebash
/sys/class/gpio # ls
GPIO0      export     gpiochip0  unexport
/sys/class/gpio # echo 0 > unexport
/sys/class/gpio # ls
export     gpiochip0  unexport
/sys/class/gpio #

...

Special Function Pins

Some devices pins of SP7350 are multiplexed to specified pin-group of SP7350. This section explains how to modify device-tree source file to enable pins of those devices.

...