How i can i use and configure GPIO pin on iMX6qSabreSD platfrom

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How i can i use and configure GPIO pin on iMX6qSabreSD platfrom

8,914 Views
chintakanisiva
Contributor II

Hi All,

I am using the SPI interface on iMX6qSabreSD platform to integrate WIFI device. I am successfully integrated SPI interface.

Now i want to use one GPIO pin on iMX6 platform to use as an interrupt.But unfortunately i am unable to find the unused GPIO pins on iMX6QSabreSD platform.

I have tried to use one GPIO pin which is being used for volume button but not succeeded.

Can any one please help me how to configure GPIO pin on iMX6qSabreSD platform and which pin can i use for GPIO.And please provide required changes need to be done in the board specific files to configure GPIO pin.

Your input is very appreciated.

Thanks in Advance.

Siva

Labels (3)
9 Replies

2,124 Views
AnsonHuang
NXP Employee
NXP Employee

Hi, Siva

     To use a GPIO, first you need to find a pin that is not used on your board, as you said, the pn which is being usedor volume button, it is controller by gpio button driver, so your try failed. I am not sure what do you want for a GPIO, just want to controler this GPIO to output high/low level, or want to use it as an input and enable its interrupt? If you can NOT find an unused GPIO on sabreSD board, maybe you can try using the debug LED pin, as far as I know, this pin is not used by any module.

     1. If you want to config a GPIO to output high/low level, you can refer to our v3.0.35 code, take the PCIE power control pin as an example, you need to config this pin as GPIO mode via setting IOMUX, code is as below, set this pin to GPIO mode, then control it to output high/low level via gpio APIs.

     arch/arm/mach-mx6/board-mx6q_sabresd.h:   below set pin EIM_D19 to GPIO mode

     MX6Q_PAD_EIM_D19__GPIO_3_19, /* PCIE_PWR_EN */

     arch/arm/mach-mx6/board-mx6q_sabresd.c:

1502 static void pcie_3v3_power(void)

1503 {

1504         /* disable PCIE_3V3 first */

1505         gpio_request(SABRESD_PCIE_PWR_EN, "pcie_3v3_en");

1506         gpio_direction_output(SABRESD_PCIE_PWR_EN, 0);

1507         mdelay(10);

1508         /* enable PCIE_3V3 again */

1509         gpio_set_value(SABRESD_PCIE_PWR_EN, 1);

1510         gpio_free(SABRESD_PCIE_PWR_EN);

1511 }

     2. If you want to use an GPIO to receive interrupt, then you can refer to SD card detect code:

   arch/arm/mach-mx6/board-mx6q_sabresd.h: below set NANDF_D0 to GPIO mode

      MX6Q_PAD_NANDF_D0__GPIO_2_0,            /* SD3_CD */

  arch/arm/mach-mx6/board-mx6q_sabresd.c:

230 static const struct esdhc_platform_data mx6q_sabresd_sd3_data __initconst = {

231         .cd_gpio = SABRESD_SD3_CD,

232         .wp_gpio = SABRESD_SD3_WP,

233         .keep_power_at_suspend = 1,

234         .support_8bit = 1,

235         .delay_line = 0,

236         .cd_type = ESDHC_CD_CONTROLLER,

237 };

     drivers/mmc/host/sdhci-esdhc-imx.c:

898                 err = gpio_request_one(boarddata->cd_gpio, GPIOF_IN, "ESDHC_CD");

899                 if (err) {

900                         dev_warn(mmc_dev(host->mmc),

901                                 "no card-detect pin available!\n");

902                         goto no_card_detect_pin;

903                 }

904

905                 err = request_irq(gpio_to_irq(boarddata->cd_gpio), cd_irq,

906                                  IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,

907                                  mmc_hostname(host->mmc), host);

908                 if (err) {

909                         dev_warn(mmc_dev(host->mmc), "request irq error\n");

910                         goto no_card_detect_irq;

911                 }

2,124 Views
chintakanisiva
Contributor II

Hi Yongcai Huang,

Thanks for your quick reply,

Yes, I want to use GPIO as an interrupt pin. You mentioned we can use "debug LED pin" as normal GPIO, Could you please suggest where i can find that pin on iMX6qSabreSD hardware platform.


Thanks in Advance.

Ch.Siva

0 Kudos

2,124 Views
AnsonHuang
NXP Employee
NXP Employee

Hi, SIva

     Using GPIO as an interrupt pin, what module's interrupt? is it to receive signal from external wifi chip? You did NOT describe your purpose clearly. What is the purpose of GPIO you want, use it as an input or output? to what module?

     You can look into the i.MX6Q SabreSD board's schematic, it is in page 21, USR_DEF_RED_LED, but this pin is connected to an LED, so you need to do hardware rework?

0 Kudos

2,125 Views
chintakanisiva
Contributor II

I want to use an input interrupt pin to processor.(Yes, it is receive signal from external wifi chip).

You mentioned now it configured as an output LED pin.Is there any changes are required in the kernel source to make it as input pin.

Please suggest on it.

Thanks in Advance,

Ch.Siva

0 Kudos

2,125 Views
AnsonHuang
NXP Employee
NXP Employee

Hi, Siva

     in arch/arm/mach-mx6/board-mx6q_sabresd.c, this pin is used as charge LED, you need to remove below code in this file. Then add a gpio into spi_imx_master struct, then pass this pin to spi driver, then you can refer to uSDHC's card detect pin I pasted uppper into your spi driver. Then it should work. And, make sure you do hardware rework first, cut this pin from LED and connect this pin to your wifi card,. You can refer to arch/arm/mach-mx6/board-mx6q_sabresd.c 's SABRESD_SD3_CD, see how it pass to uSDHC driver, and look into drivers/mmc/host/sdhci-esdhc-imx.c: to see how it set this pin to input and enable its interrupt and request irq for this GPIO, then you should see cpu executing the interrupt handle when this pin is triggered.

     Refer to esdhc_platform_data's struct, add "unsigned int cd_gpio;" to spi_imx_master struct, then

    

      195 #define SABRESD_CHARGE_NOW      IMX_GPIO_NR(1, 2)

1556 static struct gpio_led imx6q_gpio_leds[] = {

1557         GPIO_LED(SABRESD_CHARGE_NOW, "chg_now_led", 0, 1,

1558                 "charger-charging"),

1559 /* For the latest B4 board, this GPIO_1 is connected to POR_B,

1560 which will reset the whole board if this pin's level is changed,

1561 so, for the latest board, we have to avoid using this pin as

1562 GPIO.

1563         GPIO_LED(SABRESD_CHARGE_DONE, "chg_done_led", 0, 1,

1564                         "charger-full"),

1565 */

1566 };

diff --git a/arch/arm/mach-mx6/board-mx6q_sabresd.c b/arch/arm/mach-mx6/board-mx6q_sabresd.c

index 3f9a845..fe2eadc 100644

--- a/arch/arm/mach-mx6/board-mx6q_sabresd.c

+++ b/arch/arm/mach-mx6/board-mx6q_sabresd.c

@@ -192,7 +192,6 @@

#define SABRESD_EPDC_PMIC_WAKE IMX_GPIO_NR(3, 20)

#define SABRESD_EPDC_PMIC_INT  IMX_GPIO_NR(2, 25)

#define SABRESD_EPDC_VCOM      IMX_GPIO_NR(3, 17)

-#define SABRESD_CHARGE_NOW     IMX_GPIO_NR(1, 2)

#define SABRESD_CHARGE_DONE    IMX_GPIO_NR(1, 1)

#define SABRESD_ELAN_CE                IMX_GPIO_NR(2, 18)

#define SABRESD_ELAN_RST       IMX_GPIO_NR(3, 8)

@@ -305,6 +304,7 @@ static int mx6q_sabresd_spi_cs[] = {

};

     Below is the patch of setting GPIO and passing GPIO into spi driver, you need to add GPIO operation in your spi driver, refer to drivers/mmc/host/sdhci-esdhc-imx.c:

static const struct spi_imx_master mx6q_sabresd_spi_data __initconst = {

+       .wifi_gpio      = SABRESD_USR_DEF_RED_LED

        .chipselect     = mx6q_sabresd_spi_cs,

        .num_chipselect = ARRAY_SIZE(mx6q_sabresd_spi_cs),

};

@@ -1554,8 +1554,6 @@ static void gps_power_on(bool on)

  * GPIO_LED(SABRESD_CHARGE_DONE, "chg_detect", 0, 1, "ac-online"),

  */

static struct gpio_led imx6q_gpio_leds[] = {

-       GPIO_LED(SABRESD_CHARGE_NOW, "chg_now_led", 0, 1,

-               "charger-charging"),

diff --git a/arch/arm/plat-mxc/include/mach/spi.h b/arch/arm/plat-mxc/include/mach/spi.h

index 08be445..d61cb09 100644

--- a/arch/arm/plat-mxc/include/mach/spi.h

+++ b/arch/arm/plat-mxc/include/mach/spi.h

@@ -18,6 +18,7 @@

  * @num_chipselect: ARRAY_SIZE(chipselect)

  */

struct spi_imx_master {

+       unsigned int wifi_gpio;

        int     *chipselect;

        int     num_chipselect;

};

0 Kudos

2,125 Views
chintakanisiva
Contributor II

Hi Yongcai Huang,

Provided information is very helpful for me. Still i am facing the issue to make the GPIO(SABRESD_USR_DEF_RED_LED) as an interrupt.

The below is the crash information during the WIFI driver installation, Could you suggest what could be the reason for this issue.And is there any thing i have missed.

Thanks in Advance,

Ch.Siva

ganges_ssp_bus_init: Failed to request interrupt -22

------------[ cut here ]------------

WARNING: at kernel/irq/manage.c:1182 __free_irq+0x9c/0x1b4()

Trying to free already-free IRQ 2

Modules linked in: rsi_master(+) rsi_client(P)

[<8004929c>] (unwind_backtrace+0x0/0xfc) from [<80076f98>] (warn_slowpath_common+0x4c/0x64)

[<80076f98>] (warn_slowpath_common+0x4c/0x64) from [<80077044>] (warn_slowpath_fmt+0x30/0x40)

[<80077044>] (warn_slowpath_fmt+0x30/0x40) from [<800af610>] (__free_irq+0x9c/0x1b4)

[<800af610>] (__free_irq+0x9c/0x1b4) from [<800af768>] (free_irq+0x40/0x88)

[<800af768>] (free_irq+0x40/0x88) from [<7f06d960>] (ganges_spi_deinit+0x28/0x38 [rsi_master])

[<7f06d960>] (ganges_spi_deinit+0x28/0x38 [rsi_master]) from [<7f06ecbc>] (ganges_probe+0x1d8/0x5c0 [rsi_master])

[<7f06ecbc>] (ganges_probe+0x1d8/0x5c0 [rsi_master]) from [<803048e4>] (spi_drv_probe+0x18/0x1c)

[<803048e4>] (spi_drv_probe+0x18/0x1c) from [<802a667c>] (driver_probe_device+0x98/0x1a4)

[<802a667c>] (driver_probe_device+0x98/0x1a4) from [<802a6814>] (__driver_attach+0x8c/0x90)

[<802a6814>] (__driver_attach+0x8c/0x90) from [<802a5ebc>] (bus_for_each_dev+0x60/0x8c)

[<802a5ebc>] (bus_for_each_dev+0x60/0x8c) from [<802a5848>] (bus_add_driver+0x184/0x25c)

[<802a5848>] (bus_add_driver+0x184/0x25c) from [<802a6e08>] (driver_register+0x78/0x13c)

[<802a6e08>] (driver_register+0x78/0x13c) from [<7f076010>] (init_module+0x10/0x64 [rsi_master])

[<7f076010>] (init_module+0x10/0x64 [rsi_master]) from [<8003c4c4>] (do_one_initcall+0x30/0x16c)

[<8003c4c4>] (do_one_initcall+0x30/0x16c) from [<800ab8ac>] (sys_init_module+0x84/0x19c)

[<800ab8ac>] (sys_init_module+0x84/0x19c) from [<80042580>] (ret_fast_syscall+0x0/0x30)

---[ end trace 36ae56cc5262a5d4 ]---

kernel BUG at mm/slub.c:2949!

Unable to handle kernel NULL pointer dereference at virtual address 00000000

pgd = ba288000

0 Kudos

2,124 Views
AnsonHuang
NXP Employee
NXP Employee

Hi, Siva

     apparently, the ganges_ssp_bus_init request irq falied, then the following code try to free this irq, it is an already-free IRQ, so kernel BUG. You should check why it request irq fail first.

0 Kudos

2,124 Views
chintakanisiva
Contributor II

Hi Yongcai Huang,

You provided information is very helpful to me.I have resolved that crash issue by making the GPIO free before converting the GPIO as an IRQ(gpio_to_irq).
Now i am able to configure and get the interrupt properly form the configured GPIO.This interrupt status reading when it is "rising-edge" state(We check the rising edge state by using the  flag "IRQF_SHARED |IRQF_TRIGGER_RISING").

Thanks a lot for your support.

Ch.Siva

0 Kudos

2,125 Views
AnsonHuang
NXP Employee
NXP Employee

Hi, Siva

     Very happy to hear this good news, if you do NOT have other questions, can you check the correct answer and close this topic? Thanks!

0 Kudos