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>
This commit is contained in:
parent
bb28da90f4
commit
48bc177441
1 changed files with 41 additions and 0 deletions
|
@ -28,6 +28,7 @@
|
||||||
#include <linux/i2c.h>
|
#include <linux/i2c.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
||||||
|
#include <linux/pm.h>
|
||||||
#include <linux/mod_devicetable.h>
|
#include <linux/mod_devicetable.h>
|
||||||
#include <linux/power_supply.h>
|
#include <linux/power_supply.h>
|
||||||
#include <linux/power/max17042_battery.h>
|
#include <linux/power/max17042_battery.h>
|
||||||
|
@ -721,6 +722,40 @@ static int __devexit max17042_remove(struct i2c_client *client)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_PM
|
||||||
|
static int max17042_suspend(struct device *dev)
|
||||||
|
{
|
||||||
|
struct max17042_chip *chip = dev_get_drvdata(dev);
|
||||||
|
|
||||||
|
/* disable the irq and enable irq_wake
|
||||||
|
* capability to the interrupt line.
|
||||||
|
*/
|
||||||
|
if (chip->client->irq) {
|
||||||
|
disable_irq(chip->client->irq);
|
||||||
|
enable_irq_wake(chip->client->irq);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int max17042_resume(struct device *dev)
|
||||||
|
{
|
||||||
|
struct max17042_chip *chip = dev_get_drvdata(dev);
|
||||||
|
|
||||||
|
if (chip->client->irq) {
|
||||||
|
disable_irq_wake(chip->client->irq);
|
||||||
|
enable_irq(chip->client->irq);
|
||||||
|
/* re-program the SOC thresholds to 1% change */
|
||||||
|
max17042_set_soc_threshold(chip, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define max17042_suspend NULL
|
||||||
|
#define max17042_resume NULL
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_OF
|
#ifdef CONFIG_OF
|
||||||
static const struct of_device_id max17042_dt_match[] = {
|
static const struct of_device_id max17042_dt_match[] = {
|
||||||
{ .compatible = "maxim,max17042" },
|
{ .compatible = "maxim,max17042" },
|
||||||
|
@ -735,10 +770,16 @@ static const struct i2c_device_id max17042_id[] = {
|
||||||
};
|
};
|
||||||
MODULE_DEVICE_TABLE(i2c, max17042_id);
|
MODULE_DEVICE_TABLE(i2c, max17042_id);
|
||||||
|
|
||||||
|
static const struct dev_pm_ops max17042_pm_ops = {
|
||||||
|
.suspend = max17042_suspend,
|
||||||
|
.resume = max17042_resume,
|
||||||
|
};
|
||||||
|
|
||||||
static struct i2c_driver max17042_i2c_driver = {
|
static struct i2c_driver max17042_i2c_driver = {
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "max17042",
|
.name = "max17042",
|
||||||
.of_match_table = of_match_ptr(max17042_dt_match),
|
.of_match_table = of_match_ptr(max17042_dt_match),
|
||||||
|
.pm = &max17042_pm_ops,
|
||||||
},
|
},
|
||||||
.probe = max17042_probe,
|
.probe = max17042_probe,
|
||||||
.remove = __devexit_p(max17042_remove),
|
.remove = __devexit_p(max17042_remove),
|
||||||
|
|
Loading…
Add table
Reference in a new issue