Wakeup the system from gpio interrupt

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

Wakeup the system from gpio interrupt

3,548 Views
sharmila_devada
Contributor III

Hi,

I am using pcf2127 rtc module in my custom board. The GPIO3_16 is used for rtc alarm interrupt. Now I have to suspend the module and when rtc alarm interrupt comes, it should wake up. I am using below command for suspending the system

echo mem > /sys/power/state

When rtc alarm interrupt comes , the system is not waking up. The configuration I have made in my dts file is as below

gpio-keys {

    compatible = "gpio-keys";

    wakeup {

      label = "wakeup gpio";

      gpios = <&gpio3 16 GPIO_ACTIVE_LOW>;

      linux,code = <29>;

      gpio-key,wakeup;

    };

  };

But the system is not coming out of suspend mode. Please tell me where I am going wrong.

Thank You,

Regards,

Sharmila

0 Kudos
8 Replies

3,027 Views
sharmila_devada
Contributor III

Hi igor,

I have created suspend and resume function in my rtc driver as below

static int pcf2127_rtc_suspend(struct device *dev)
{
        struct pcf2127 *pdata = dev_get_drvdata(dev);

        if (device_may_wakeup(dev))
        {

               printk("pcf2127_rtc_suspend..\r\n");
                enable_irq_wake(irqNumber);
        }

        return 0;
}

static int pcf2127_rtc_resume(struct device *dev)
{
        struct pcf2127 *pdata = dev_get_drvdata(dev);

        if (device_may_wakeup(dev))
        {

               printk("pcf2127_rtc_suspend..\r\n");
                disable_irq_wake(irqNumber);
        }

        return 0;
}

Note : irqNumber is IRQ of GPIO which I got from gpio_to_irq(gpio_number).

when I suspend the system using echo mem > /sys/power/state command I am getting below prints

root@imx8dx_ccu:/usr/bin/ccu# echo mem > /sys/power/state
[   25.205302] PM: suspend entry (deep)
[   25.208888] PM: Syncing filesystems ... done.
[   25.242558] Freezing user space processes ... (elapsed 0.001 seconds) done.
[   25.250873] OOM killer disabled.
[   25.254121] Freezing remaining freezable tasks ... (elapsed 0.007 seconds) done.
[   25.273048] pcf2127_rtc_read_time..
[   25.277080] pcf2127_rtc_suspend..
[   25.280479] irq_set_irq_wake..
[   25.283642] irq_set_irq_wake..
[   25.288329] PM: suspend devices took 0.016 seconds
[   25.295436] Disabling non-boot CPUs ...
[   25.313505] CPU1: shutdown
[   25.316298] psci: CPU1 killed.

But system is not waking up when alarm interrupt comes.

Please provide some input.

Regards,

Sharmila

0 Kudos

3,027 Views
mrcryo
Contributor III

Hi Sharmila,

To use gpio as a wakeup source, one needed to configure pad-wakeup property for gpio node.

In your case it could be like:

/ {

   ...

   gpio-keys {

      compatible = "gpio-keys";

      wakeup {

         label = "wakeup gpio";

         gpios = <&gpio3 16 GPIO_ACTIVE_LOW>;

         linux,code = <KEY_WAKEUP>;

         wakeup-source;

      };

   };

   ...

};

&gpio3 {

   /* total pad wakeup number in gpio3 */

   pad-wakeup-num = <1>;

   /* SC_P_QSPI0A_SCLK, SC_PAD_WAKEUP_LOW_LVL, LINE 16 */

   /*

    * See include/dt-bindings/pinctrl/pads-imx8qxp.h

    * include/soc/imx8/sc/svc/pad/api.h

    * and drivers/gpio/gpio-mxc.c

    */
   pad-wakeup = <163 4 16>;
};

We're able to wake our custom module up with gpio using similar config.

with best regards,
Oleks.
0 Kudos

3,027 Views
sharmila_devada
Contributor III

Thank you,

After enabling pad wakeup, the wake up the system using gpio interrupt is working fine.

0 Kudos

3,027 Views
sharmila_devada
Contributor III

Hi igor,

Thank you for your support.

Our hardware doesn't have Power key option. Please tell me how to wake up the system using rtc interrupt.

Regards,

Sharmila

0 Kudos

3,027 Views
igorpadykov
NXP Employee
NXP Employee

Hi Sharmila

this part is preproduction part and unfortunately has not full support.

Suggest to proceed with extended support of Commercial Support and Engineering Services | NXP 

Best regards
igor

0 Kudos

3,027 Views
igorpadykov
NXP Employee
NXP Employee

Hi Sharmilla

one can check if gpio wakeup linux commits were implemented as mentioned below

Wakeup Source Configuration iMX8QXP/DX 

 dts example:
gpio4: gpio@5d0c0000 {
     compatible = "fsl,imx8qm-gpio", "fsl,imx35-gpio";
     reg = <0x0 0x5d0c0000 0x0 0x10000>;
     interrupts = <GIC_SPI 140 IRQ_TYPE_LEVEL_HIGH>;
     gpio-controller;
     #gpio-cells = <2>;
     power-domains = <&pd_lsio_gpio4>;
     interrupt-controller;
     #interrupt-cells = <2>;
     /* total pad wakeup number in gpio4 */
     pad-wakeup-num = <1>;
     /* SC_P_USDHC1_CD_B, SC_PAD_WAKEUP_LOW_LVL, LINE 22 */
     pad-wakeup = <27 4 22>;
};

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

3,027 Views
sharmila_devada
Contributor III

Hi,

I have made the above changes in my dtsi file and the result is same. Please tell me do I need to add any other changes such that my system will wake from suspend mode when rtc interrupt comes.

Regards,

Sharmila

0 Kudos

3,027 Views
igorpadykov
NXP Employee
NXP Employee

Hi Sharmila

also one can consider onoff pin as wake source:

      sc_pwrkey: sc-powerkey {
        compatible = "fsl,imx8-pwrkey";
        linux,keycode = <KEY_POWER>;
        wakeup-source;
    };

fsl-imx8dx.dtsi\freescale\dts\boot\arm64\arch - linux-imx - i.MX Linux kernel 

Best regards
igor

0 Kudos