Making Battery charger gpio as Wakeup-Source

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

Making Battery charger gpio as Wakeup-Source

4,713 Views
prasannakulkarni
Contributor IV

Hi All,

       I am facing a issue in setting battery charger gpio as wakeup-source on imx6q-sabresd Android naugat. following are the code snapshots.

In fuel-Gauge driver : we are using max17040_battery.c file and adopted the same features from sabresd_battery.c driver.

related code has been added in the suspend and resume routines.

#ifdef CONFIG_PM_SLEEP

static int max17040_suspend(struct device *dev)
{
        struct i2c_client *client = to_i2c_client(dev);
        struct max17040_chip *chip = i2c_get_clientdata(client);
        int irq,error;
        if(device_may_wakeup(&client->dev))
        {

                 printk("Inside3__suspend__ ===============> %s \n", __func__);
                irq = gpio_to_irq(max17040_get_gpio(chip->client));
                error = enable_irq_wake(irq);
          }    
        cancel_delayed_work(&chip->work);
        return 0;
}

static int max17040_resume(struct device *dev)
{
        struct i2c_client *client = to_i2c_client(dev);
        struct max17040_chip *chip = i2c_get_clientdata(client);
        int irq,error;
         printk("Inside1__resume__ ===============> %s \n", __func__);
        if(device_may_wakeup(&client->dev))
        {
                printk("Inside2 __resume__ ===============> %s \n", __func__);
                irq = gpio_to_irq(max17040_get_gpio(chip->client));
                error = disable_irq_wake(irq);
        }
        queue_delayed_work(system_power_efficient_wq, &chip->work,
                           MAX17040_DELAY);
        return 0;
}

static SIMPLE_DEV_PM_OPS(max17040_pm_ops, max17040_suspend, max17040_resume);

-------------------------------------------------------------------------------------------------------------------------------------

Code from DTS file

        battery: max17040@36 {
               compatible = "maxim,max17040";
               pinctrl-names = "default";
               reg = <0x36>;
               chg_input = <&gpio2 24 1>;
                wakeup-source;
                fsl,dcm_always_high;
                fsl,dc_valid;
                fsl,usb_valid;
                fsl,adc_disable;
                status = "okay";
       };

The issue is interrupts are getting generated properly when I insert/remove the charger, but device is not waking up.

it tries to resume for a while but goes to suspend immediately. I have put prints also in the suspend and resume routines they are getting printed during resume/suspend (via Power button).

I have checked the sysfs path sys/class/power_supply/max17040-ac/power/wakeup it shows "enabled".

But it is not wakingup the device. kindly help me in solving this issue. 

Labels (3)
0 Kudos
Reply
14 Replies

3,636 Views
prasannakulkarni
Contributor IV

No.... it didnt work for me.

partially it tries to wakeup then goes for suspend. some bug may be

0 Kudos
Reply

3,636 Views
prasannakulkarni
Contributor IV

Hi igorpadykov,

 If that is the case then in drivers/power/supply/sabresd_battery.c file why following code is written in suspend and resume functions

static int max8903_suspend(struct platform_device *pdev,
pm_message_t state)
{
struct max8903_data *data = platform_get_drvdata(pdev);
int irq;
if (data) {
struct max8903_pdata *pdata = data->pdata;
if (pdata) {
if (pdata->dc_valid) {
irq = gpio_to_irq(pdata->dok);
enable_irq_wake(irq);
}
if (pdata->usb_valid) {
irq = gpio_to_irq(pdata->uok);
enable_irq_wake(irq);
}
cancel_delayed_work(&data->work);
}
}
return 0;
}

static int max8903_resume(struct platform_device *pdev)
{
struct max8903_data *data = platform_get_drvdata(pdev);
bool ta_in;
bool usb_in;
int irq;
if (data) {
struct max8903_pdata *pdata = data->pdata;
if (pdata) {
ta_in = gpio_get_value(pdata->dok) ? false : true;
usb_in = gpio_get_value(pdata->uok) ? false : true;
if (ta_in != data->ta_in) {
data->ta_in = ta_in;
pr_info("TA(DC-IN) Charger %s.\n", ta_in ?
"Connected" : "Disconnected");
max8903_charger_update_status(data);
power_supply_changed(&data->psy);
}
if (usb_in != data->usb_in) {
data->usb_in = usb_in;
pr_info("USB Charger %s.\n", usb_in ?
"Connected" : "Disconnected");
max8903_charger_update_status(data);
power_supply_changed(&data->usb);
}
if (pdata->dc_valid) {
irq = gpio_to_irq(pdata->dok);
disable_irq_wake(irq);
}
if (pdata->usb_valid) {
irq = gpio_to_irq(pdata->uok);
disable_irq_wake(irq);
}
schedule_delayed_work(&data->work, BATTERY_UPDATE_INTERVAL);
}
}
return 0;

}

0 Kudos
Reply

3,636 Views
igorpadykov
NXP Employee
NXP Employee

in that example seems dok_input = <&gpio4 13 1>;

used for interrupt, please check linux/arch/arm/boot/dts/imx6sl-evk.dts

linux-imx.git - i.MX Linux Kernel 

Best regards
igor

0 Kudos
Reply

3,636 Views
prasannakulkarni
Contributor IV

Hi igorpadykov,

I have seen that dts file.

battery: max8903@0 {           compatible = "fsl,max8903-charger";           pinctrl-names = "default";           dok_input = <&gpio4 13 1>;          uok_input = <&gpio4 13 1>;          chg_input = <&gpio4 15 1>;           flt_input = <&gpio4 14 1>;           fsl,dcm_always_high;           fsl,dc_valid;           fsl,adc_disable;           status = "okay";      }

   No where they have made it as wakeup-source in this dts file. I also implemented in the same way in max17040_battery.c file the gpio is requested as IRQ interrupt.  In the previous reply I have given snapshot of max17040_battery.c suspend and resume routines and our imx6qdl_sabresd.dts files. I don't find any difference between my implementation and sabresd_battery.c code. in fact in my dts I have mentioned wake-source for chg_input gpio which is not there in imx6sl-evk.dts.

0 Kudos
Reply

3,636 Views
sharmila_devada
Contributor III

Hi,

I am facing the similar issue. whether you are able to wake the system using gpio interrupt. If so please share the procedure.

Regards,

Sharmila

0 Kudos
Reply

3,636 Views
prasannakulkarni
Contributor IV

No.... it didnt work for me.

partially it tries to wakeup then goes for suspend. some bug may be

0 Kudos
Reply

3,636 Views
igorpadykov
NXP Employee
NXP Employee

Hi Prasanna

gpio interrupt usage is documented in 
linux/Documentation/devicetree/bindings/input/gpio-keys.txt

and one can try to test gpio wake using dts example in

linux/arch/arm/boot/dts/imx6q-pop-arm2.dts

linux-imx.git - i.MX Linux Kernel 

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

0 Kudos
Reply

3,636 Views
prasannakulkarni
Contributor IV

Hi  igorpadykov ,

        I have gone through the files mentioned by you, but I did'nt get any helpful info. is there any reference where as gpio is made as wakeup-source? except power-button it comes under gpio-keys. So what is the syntax to make gpio [like in my case battery-charger gpio ] as a wakeup-source. i have handled it properly in driver as well as dts file.

       Issue is it triggers the interrupts tries to wakeup the device but goes to suspend again. following are the logs

Suspend log

-------------------------

PM: suspend entry 1970-01-01 01:30:08.910751001 UTC
PM: Syncing filesystems ... done.
Freezing user space processes ... PM: Wakeup pending, aborting suspend
last active wakeup source: PowerManagerService.Broadcasts
Freezing of tasks aborted after 0.009 seconds
Restarting tasks ... done.
PM: suspend exit 1970-01-01 01:30:09.012628001 UTC
PM: suspend entry 1970-01-01 01:30:09.117321668 UTC
PM: Syncing filesystems ... done.
Freezing user space processes ... (elapsed 0.002 seconds) done.
Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
Suspending console(s) (use no_console_suspend to debug)

Resume log

-------------------------------------------
PM: suspend of devices complete after 100.328 msecs
PM: suspend devices took 0.100 seconds
PM: late suspend of devices complete after 1.085 msecs
PM: noirq suspend of devices complete after 1.118 msecs
Disabling non-boot CPUs ...
CPU1: shutdown
CPU0: update max cpu_capacity 1024
CPU2: shutdown
CPU0: update max cpu_capacity 1024
CPU3: shutdown
Resume caused by IRQ 101
Enabling non-boot CPUs ...
CPU1 is up
CPU0: update max cpu_capacity 1024
CPU2 is up
CPU2: update max cpu_capacity 1024
CPU3 is up
PM: noirq resume of devices complete after 0.920 msecs
PM: early resume of devices complete after 0.654 msecs
CPU3: update max cpu_capacity 1024
Suspended for 10.259 seconds
PM: resume of devices complete after 78.949 msecs
PM: resume devices took 0.080 seconds
Restarting tasks ... done.
PM: suspend exit 1970-01-01 01:30:20.152607667 UTC
PM: suspend entry 1970-01-01 01:30:20.257315667 UTC
PM: Syncing filesystems ... done.
Freezing user space processes ... (elapsed 0.002 seconds) done.
Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
Suspending console(s) (use no_console_suspend to debug)

 

So device goes back to sleep mode...

0 Kudos
Reply

3,636 Views
igorpadykov
NXP Employee
NXP Employee

Hi Prasanna

yes there is reference where as gpio is made as wakeup-source:

gpios = <&gpio3 30 1>;
linux,code = <116>;
gpio-key,wakeup;

linux/arch/arm/boot/dts/imx6q-pop-arm2.dts

linux-imx.git - i.MX Linux Kernel 

Best regards
igor

0 Kudos
Reply

3,636 Views
prasannakulkarni
Contributor IV

Hi igorpadykov,

    linux/arch/arm/boot/dts/imx6q-pop-arm2.dts reference did'nt help me. atleast with my following config, it is creating interrupts and try to resume. With arm2.dts config. there are  no symptoms of interrupts and the device will not respond for charger insertion.

battery: max17040@36 {
               compatible = "maxim,max17040";
               pinctrl-names = "default";
               reg = <0x36>;
               chg_input = <&gpio2 24 1>;
                wakeup-source;
                fsl,dcm_always_high;
                fsl,dc_valid;
                fsl,usb_valid;
                fsl,adc_disable;
                status = "okay";
       };

0 Kudos
Reply

3,636 Views
igorpadykov
NXP Employee
NXP Employee

Hi Prasanna

could you try with linux:

wake up from sleep on gpio interrupt 

Best regards
igor

0 Kudos
Reply

3,636 Views
prasannakulkarni
Contributor IV

Hi igorpadykov,

   All those links talks about gpio-keys like Power-Button, Volume-up/Down.  In my case it is different. It is a simple gpio not a gpio-key.  The moment if I insert the battery charger [AC] device should wakeup from suspend.

 

0 Kudos
Reply

3,636 Views
igorpadykov
NXP Employee
NXP Employee

from documentation seems only "gpio-key" supports wake.

You can also post this issue on kernel mail list:

Majordomo Lists at VGER.KERNEL.ORG 

Best regards
igor

0 Kudos
Reply

3,636 Views
igorpadykov
NXP Employee
NXP Employee

please check linux/Documentation/devicetree/bindings/input/ for available wake

choices: there is no "simple gpio".

Best regards
igor

0 Kudos
Reply