Search code examples
linux-kernellinux-device-drivergpio

Control GPIO without Device Tree configure on iMX.6


On old iMX.6 BSP without DT (Device Tree), GPIO is controlled by following code:

#define SABRESD_SHUTDOWN    IMX_GPIO_NR(4, 15)

gpio_request(SABRESD_SHUTDOWN, "shutdown");

gpio_direction_output(SABRESD_SHUTDOWN, 1);
gpio_set_value(SABRESD_SHUTDOWN, 0);

gpio_free(SABRESD_SHUTDOWN);

However on new BSP, I cannot use IMX_GPIO_NR anymore. Instead, of_get_named_gpio provides access to GPIO defined in DT. But it is a little complicated because our product never changes the GPIO ports.

My question is, is it possible to control GPIOs without DT definition (just using the old method)?


Solution

  • First of all, if you are using newer kernel, I would recommend you to port your code to support the latest features. Otherwise - why bothering upgrading the kernel if you are not willing to adapt to it?

    Second, never say never.

    And finally:

    #define IMX_GPIO_NR(bank, nr)           (((bank) - 1) * 32 + (nr))