AnsweredAssumed Answered

GPIO number in iMX8

Question asked by mrigendra chaubey on May 30, 2019
Latest reply on Apr 26, 2020 by mc maddie


I am confused about gpio number calculation, in uboot there is commit on this file



commit 3733fc85c1f29f2d0ac2af42eca64d5939902fe3
Author: Adrian Alonso <>
Date: Tue Mar 8 14:53:31 2016 -0600

MLK-14938-21 mxc_gpio: add support for i.MX8

Add support for iMX8 SoC platforms, and extend to support LSIO GPIO0..GPIO7 ports.
Since the i.MX8 GPIO banks are indexed from 0 not 1 on other i.MX platforms,
so we have to adjust the index accordingly.


where, to calculate gpio number we use this formula,


+/* IMX8 the GPIO index is from 0 not 1 */
+#define IMX_GPIO_NR(port, index) (((port)*32)+((index)&31))
+#endif /* __ASM_ARCH_IMX8_GPIO_H */


But in kernel to get gpio number we are using this formula and it works


#define IMX_GPIO_NR(bank, pin) (480 - (bank * 32) + (pin & 0x1f))


To get gpio3_25 both gives different gpio number. 


Which one is correct? Kindly clarify.