diff options
author | Ramakrishna Pallala <ramakrishna.pallala@intel.com> | 2012-03-26 16:53:40 -0400 |
---|---|---|
committer | Anton Vorontsov <anton.vorontsov@linaro.org> | 2012-05-04 22:37:37 -0400 |
commit | 48bc177441d68c0ba70631beb544c3d695328d56 (patch) | |
tree | c0f93f8a53a4bf72482be34536571d48e265c7c0 /drivers/power/max17042_battery.c | |
parent | bb28da90f4f973529f81be01547ebde7bf270042 (diff) |
max17042_battery: Add suspend/resume hooks
This patch adds suspend/resume methods to the driver.
In suspend method irq line is disabled to avoid i2c
read/write errors from the interrupt handler as the
i2c bus itself could be in suspend state.
In resume function irq line will be re-enabled.
Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Diffstat (limited to 'drivers/power/max17042_battery.c')
-rw-r--r-- | drivers/power/max17042_battery.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c index 93fd13c9be68..07dee974a70e 100644 --- a/drivers/power/max17042_battery.c +++ b/drivers/power/max17042_battery.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/i2c.h> | 28 | #include <linux/i2c.h> |
29 | #include <linux/delay.h> | 29 | #include <linux/delay.h> |
30 | #include <linux/interrupt.h> | 30 | #include <linux/interrupt.h> |
31 | #include <linux/pm.h> | ||
31 | #include <linux/mod_devicetable.h> | 32 | #include <linux/mod_devicetable.h> |
32 | #include <linux/power_supply.h> | 33 | #include <linux/power_supply.h> |
33 | #include <linux/power/max17042_battery.h> | 34 | #include <linux/power/max17042_battery.h> |
@@ -721,6 +722,40 @@ static int __devexit max17042_remove(struct i2c_client *client) | |||
721 | return 0; | 722 | return 0; |
722 | } | 723 | } |
723 | 724 | ||
725 | #ifdef CONFIG_PM | ||
726 | static int max17042_suspend(struct device *dev) | ||
727 | { | ||
728 | struct max17042_chip *chip = dev_get_drvdata(dev); | ||
729 | |||
730 | /* disable the irq and enable irq_wake | ||
731 | * capability to the interrupt line. | ||
732 | */ | ||
733 | if (chip->client->irq) { | ||
734 | disable_irq(chip->client->irq); | ||
735 | enable_irq_wake(chip->client->irq); | ||
736 | } | ||
737 | |||
738 | return 0; | ||
739 | } | ||
740 | |||
741 | static int max17042_resume(struct device *dev) | ||
742 | { | ||
743 | struct max17042_chip *chip = dev_get_drvdata(dev); | ||
744 | |||
745 | if (chip->client->irq) { | ||
746 | disable_irq_wake(chip->client->irq); | ||
747 | enable_irq(chip->client->irq); | ||
748 | /* re-program the SOC thresholds to 1% change */ | ||
749 | max17042_set_soc_threshold(chip, 1); | ||
750 | } | ||
751 | |||
752 | return 0; | ||
753 | } | ||
754 | #else | ||
755 | #define max17042_suspend NULL | ||
756 | #define max17042_resume NULL | ||
757 | #endif | ||
758 | |||
724 | #ifdef CONFIG_OF | 759 | #ifdef CONFIG_OF |
725 | static const struct of_device_id max17042_dt_match[] = { | 760 | static const struct of_device_id max17042_dt_match[] = { |
726 | { .compatible = "maxim,max17042" }, | 761 | { .compatible = "maxim,max17042" }, |
@@ -735,10 +770,16 @@ static const struct i2c_device_id max17042_id[] = { | |||
735 | }; | 770 | }; |
736 | MODULE_DEVICE_TABLE(i2c, max17042_id); | 771 | MODULE_DEVICE_TABLE(i2c, max17042_id); |
737 | 772 | ||
773 | static const struct dev_pm_ops max17042_pm_ops = { | ||
774 | .suspend = max17042_suspend, | ||
775 | .resume = max17042_resume, | ||
776 | }; | ||
777 | |||
738 | static struct i2c_driver max17042_i2c_driver = { | 778 | static struct i2c_driver max17042_i2c_driver = { |
739 | .driver = { | 779 | .driver = { |
740 | .name = "max17042", | 780 | .name = "max17042", |
741 | .of_match_table = of_match_ptr(max17042_dt_match), | 781 | .of_match_table = of_match_ptr(max17042_dt_match), |
782 | .pm = &max17042_pm_ops, | ||
742 | }, | 783 | }, |
743 | .probe = max17042_probe, | 784 | .probe = max17042_probe, |
744 | .remove = __devexit_p(max17042_remove), | 785 | .remove = __devexit_p(max17042_remove), |