Sysfs gpio pin map


#1

anywhere I can find pin mapping for LS to use with linux sysfs gpio in /sys/class/gpio
or should I just go with http://www.96boards.org/documentation/ConsumerEdition/HiKey960/HardwareDocs/HardwareUserManual.md/
for example pin 23 which is GPIO_208: echo 208 > /sys/class/gpio


#2

@ric96, could you also review the schematics: https://github.com/96boards/documentation/blob/master/ConsumerEdition/HiKey960/HardwareDocs/HiKey960_Schematics.pdf, page 20: IO_CONN, you could see all the GPIOs which are used for LS.

Please let me know if the info is enough?


#3

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 https://up-community.org/wiki/Pinout


#4

I read the info from DTS binding: http://archive.armlinux.org.uk/lurker/message/20170614.082323.17817b21.en.html, and consolidate info with SoC manual: https://github.com/96boards/documentation/blob/master/ConsumerEdition/HiKey960/HardwareDocs/HiKey960_SoC_Reference_Manual.pdf, 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


#5

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


#6

@ric96, thanks for sharing the link, could you review the summary for Hikey960 LS pinout: https://docs.google.com/spreadsheets/d/1QVfI1AaRO_7IhSM3HMSSj1HewlzR2BxVlQXW7sU54K8/edit?usp=sharing


#7

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 ?


#8

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.


#9

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?


#10

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.


#11

@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: https://docs.google.com/spreadsheets/d/1QVfI1AaRO_7IhSM3HMSSj1HewlzR2BxVlQXW7sU54K8/edit?usp=sharing


#12

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.


#13

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


#14

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?

Thanks


#15

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.

Thanks,
Mani

[1] https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/
[2] https://patchwork.kernel.org/patch/9978653/
[3] https://github.com/intel-iot-devkit/mraa


Coding technique for multiplexed pin configuration