izumitomonori Posted October 4, 2016 Share Posted October 4, 2016 Dear Experts, I would like to ask how I can determine GPIO port# of /sys/class/gpio/gpiochip# in PetaLinux. Here is my design environment.Board: ZYBOTools: Vivado 2015.4, SDK 2015.4, PetaLinux 2015.4 My design includes a GPIO module with two ports in PL part as follows. axi_gpio_0: gpio@41200000 { #gpio-cells = <2>; compatible = "xlnx,xps-gpio-1.00.a"; gpio-controller ; reg = <0x41200000 0x10000>; : After building PetaLinux boot image, I got the followings: root@plzybotr:~# ls /sys/class/gpio export gpiochip842 gpiochip874 gpiochip906 unexport root@plzybotr:~# cat /sys/class/gpio/gpiochip842/label /amba_pl/gpio@41200000 root@plzybotr:~# cat /sys/class/gpio/gpiochip842/ngpio 32 root@plzybotr:~# cat /sys/class/gpio/gpiochip874/label /amba_pl/gpio@41200000 root@plzybotr:~# cat /sys/class/gpio/gpiochip874/ngpio 32 root@plzybotr:~# cat /sys/class/gpio/gpiochip906/label zynq_gpio root@plzybotr:~# cat /sys/class/gpio/gpiochip906/ngpio 118 I found that 874 is Port#1 and 842 is Port#2 of axi_gpio_0 by "trials and errors". It would be much appreciated if you would give me any advices and/or hints to determine the mapping between the GPIO numbers and ports without trials and errors. Thanks in advance. Best regards, Tom IZUMI Link to comment Share on other sites More sharing options...
AndrewHolzer Posted October 6, 2016 Share Posted October 6, 2016 Hello Izumitomonori, I had to do some digging but found an answer here. If you read the second paragraph underneath Using the GPIO driver from User Space, you'll find a formula that you can use to calculate the GPIO port number. These ports shouldn't change unless you make changes to the device tree itself, or the Vivado project you created. If you have any further questions, I'll be more than happy to help you answer them. AndrewHolzer Link to comment Share on other sites More sharing options...
izumitomonori Posted October 10, 2016 Author Share Posted October 10, 2016 Dear AndrewHolzer, Thank your very much for the valuable information. Solving the equations in the paragraph: base_gpio = +ARCH_NR_GPIOS -ZYNQ_GPIO_NR_GPIOS allocated_gpios = +ARCH_NR_GPIOS -base_gpio other_gpio = +allocated_gpios -ZYNQ_GPIO_NR_GPIOS gpio_offset = +base_gpio +other_gpio I got... base_gpio = +ARCH_NR_GPIOS -ZYNQ_GPIO_NR_GPIOS allocated_gpios = +ZYNQ_GPIO_NR_GPIOS other_gpio = 0 gpio_offset = +ARCH_NR_GPIOS -ZYNQ_GPIO_NR_GPIOS ...Hmm.... I should make some misunderstandings. But anyway, the website says the number is calculated by some formula based on the devicetree, so I think I could assume a rule on the number. I can determine the module with /sys/class/gpio/gpiochip*/label and it seems that the numbers for ports are given in descending order. I conclude that I can guess with the hints and if it is critical to know the port position I use /dev/uio instead of /sys/class/gpio. Again, thanks for your kind help. Best regards, Tom IZUMI Link to comment Share on other sites More sharing options...
Question
izumitomonori
Dear Experts,
I would like to ask how I can determine GPIO port# of /sys/class/gpio/gpiochip# in PetaLinux.
Here is my design environment.
Board: ZYBO
Tools: Vivado 2015.4, SDK 2015.4, PetaLinux 2015.4
My design includes a GPIO module with two ports in PL part as follows.
axi_gpio_0: gpio@41200000 {
#gpio-cells = <2>;
compatible = "xlnx,xps-gpio-1.00.a";
gpio-controller ;
reg = <0x41200000 0x10000>;
:
After building PetaLinux boot image, I got the followings:
root@plzybotr:~# ls /sys/class/gpio
export gpiochip842 gpiochip874 gpiochip906 unexport
root@plzybotr:~# cat /sys/class/gpio/gpiochip842/label
/amba_pl/gpio@41200000
root@plzybotr:~# cat /sys/class/gpio/gpiochip842/ngpio
32
root@plzybotr:~# cat /sys/class/gpio/gpiochip874/label
/amba_pl/gpio@41200000
root@plzybotr:~# cat /sys/class/gpio/gpiochip874/ngpio
32
root@plzybotr:~# cat /sys/class/gpio/gpiochip906/label
zynq_gpio
root@plzybotr:~# cat /sys/class/gpio/gpiochip906/ngpio
118
I found that 874 is Port#1 and 842 is Port#2 of axi_gpio_0 by "trials and errors".
It would be much appreciated if you would give me any advices and/or hints to determine the mapping between the GPIO numbers and ports without trials and errors.
Thanks in advance.
Best regards,
Tom IZUMI
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.