Sysfs gpio pin map


anywhere I can find pin mapping for LS to use with linux sysfs gpio in /sys/class/gpio
or should I just go with
for example pin 23 which is GPIO_208: echo 208 > /sys/class/gpio


@ric96, could you also review the schematics:, page 20: IO_CONN, you could see all the GPIOs which are used for LS.

Please let me know if the info is enough?


I am guessing these numbers are representing gpio pins from the Soc, often these are represented by different numbers for linux, referred to as linux gpio or sysfs gpio: I am looking for something like this


I read the info from DTS binding:, and consolidate info with SoC manual:, page 99: GPIO group information;

So we can generate below info:

SOC GPIO Pins -> Linux GPIO
GPIO_1 … GPIO_7 -> GPIO0
GPIO_9 … GPIO_15 -> GPIO1
GPIO_16 … GPIO_23 -> GPIO2
GPIO_24 … GPIO_31 -> GPIO3

GPIO_32 … GPIO_39 -> GPIO4
GPIO_40 … GPIO_47 -> GPIO5
GPIO_48 … GPIO_55 -> GPIO6
GPIO_56 … GPIO_63 -> GPIO7

GPIO_64 … GPIO_71 -> GPIO8
GPIO_72 … GPIO_79 -> GPIO9
GPIO_80 … GPIO_87 -> GPIO10
GPIO_88 … GPIO_95 -> GPIO11
GPIO_96 … GPIO_98 GPIO103 -> GPIO12
GPIO_104 … GPIO_111 -> GPIO13
GPIO_112 … GPIO_119 -> GPIO14
GPIO_120 … GPIO_125 -> GPIO15

GPIO_144 … GPIO_151 -> GPIO18
GPIO_152 … GPIO_155 -> GPIO19
GPIO_160 … GPIO_165 -> GPIO20
GPIO_168 … GPIO_173 -> GPIO21

GPIO_176 … GPIO_181 -> GPIO22
GPIO_184 … GPIO_189 -> GPIO23
GPIO_192 … GPIO_198 -> GPIO24
GPIO_200 … GPIO_203 GPIO_205…GPIO_207 -> GPIO25

GPIO_208 … GPIO_215 -> GPIO26
GPIO_216 … GPIO_221 -> GPIO27


as i understand there are three columns
SOCpin | Linux gpio | Low Speed pin no


@ric96, thanks for sharing the link, could you review the summary for Hikey960 LS pinout:


that’s much easier to understand but still can’t…
does one LS pin have multiple linux pins, and multiple linux min hve different gpios… kinda confused by the commas here

pin 3 is GPIO7 and GPIO 1
and GPIO 7 is also reffered at pin 5,7,9 etc…
or is “7,1” to be taken as the gpio number ?


Sorry for confusion.

Here need note one thing is Hi3660 has 29 GPIO groups (actually in kernel we take them as 29 GPIO controllers), every group (or controller) only support 8 GPIO pins. SoC have 221 GPIO pins, but these pins finally divide into different GPIO controllers; as the doc says, below are formula which is used for calculation:

Group (controller) ID = int(GPIO pin number/8)
Sequence number within the group = mod(GPIO pin number/8)

Let’s use pin 3 as example: its SoC pin name is GPIO_57, it’s located into the GPIO controller is GPIO7 and the index is 1 within GPIO controller. I also updated the excel table for this.


oh cool that makes sense but then how do you toggle them from /sys/class/gpio
echo > /sys/class/gpio/export
what should that number be?


I found now there have bug, though it can toggle GPIO pins :slight_smile:

hikey960:/sys/class/gpio # ls
export gpiochip320 gpiochip368 gpiochip416 gpiochip464 unexport
gpiochip280 gpiochip328 gpiochip376 gpiochip424 gpiochip472
gpiochip288 gpiochip336 gpiochip384 gpiochip432 gpiochip480
gpiochip296 gpiochip344 gpiochip392 gpiochip440 gpiochip488
gpiochip304 gpiochip352 gpiochip400 gpiochip448 gpiochip496
gpiochip312 gpiochip360 gpiochip408 gpiochip456 gpiochip504

So you can that the GPIO is not sequential, I found actually it’s reversed the order, so gpiochip280 is corresponding to GPIO28 controller, gpiochip504 is corresponding to GPIO0 controller, etc. There must have some thing wrong, I will report this to bugs tracking system.

Anyway, you can do a quick try as below, I use GPIO_021 as example, it’s easily to probe with multimeter:

GPIO_021 is registers into gpiochip488 group, so GPIO_021 has logical number is 493:

cd /sys/class/gpio
echo 493 > export
echo out > gpio493/direction
echo 1 > gpio493/value

So I can see the output to high level.


@ric96 I have updated the excel table for Linux GPIO numbers, now it’s easily to map between SoC GPIO number and Linux GPIO number:


wow… thanks a ton this will be extremely useful. I was talking recently with Robert about the possibility of having a dedicate section of the website for pinout diagrams, this indeed helps.


You are welcome. Agree, I also really like the table you shared the link and it inspires me :slight_smile:


Hi Leo-yan,

GPIO_021 is registers into gpiochip488 group, so GPIO_021 has logical number is 493:

Can you please let me know how did you mapped GPIO_021 to gpiochip488 group and derived linux logical number 493?



Hello All,

For accessing GPIOs you can also use libgpiod [1] library. With the help of this library, you need not worry about the pin number mappings and you can just directly use the GPIO names according to the 96Boards CE specification.

For instance, setting GPIO-A can be accomplished using the following command:

gpioset --mode=wait `gpiofind "GPIO-A"`=1

But the patch [2] adding gpio-line-names property is not yet integrated into our release kernel. Will try to get it soon. Once it is landed, you can use the above command to set a GPIO easily.

Also, we are trying to get the same support into MRAA library [3]. PR is still under review.



Coding technique for multiplexed pin configuration

Is it possible to control I2C0_SDA (LS connector pin 17) as GPIO?
I need to force logical 0 for a moment to initialize connected device, then it should be back working as I2C SDA line. Can it be done using mraa library? Should I use name I2C0_SDA or GPIO_184 ?


The pin config/mux is done at device initialization and GPIO_184 is automatically muxed/routed to SDA, you will not be able to use it as GPIO once configured and owned by the driver.

I have no easy solution in mind.

Maybe you could add an ‘init’ pinctrl to the i2c node:

		i2c0: i2c@ffd71000 {
		compatible = "snps,designware-i2c";
		reg = <0x0 0xffd71000 0x0 0x1000>;
		interrupts = <GIC_SPI 118 IRQ_TYPE_LEVEL_HIGH>;
		#address-cells = <1>;
		#size-cells = <0>;
		clock-frequency = <400000>;
		clocks = <&crg_ctrl HI3660_CLK_GATE_I2C0>;
		resets = <&iomcu_rst 0x20 3>;
		pinctrl-names = "default", "init";
		pinctrl-0 = <&i2c0_pmx_func &i2c0_cfg_func>;
              + pinctrl-1 = <&i2c0_sda_down_cfg_func>;
		status = "disabled";

and then configure i2c0_sda_down_cfg_func as gpio output-low.
This should set SDA to 0 during the driver probe.