Skip to content

Commit 4e2e7cf

Browse files
hsin-hsiungLee Jones
authored andcommitted
mfd: mt6397: Modify suspend/resume behavior
Some pmics don't need backup interrupt settings, so we change to use pm notifier for the pmics which are necessary to store settings. Signed-off-by: Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 8f3d9f3 commit 4e2e7cf

3 files changed

Lines changed: 36 additions & 31 deletions

File tree

‎drivers/mfd/mt6397-core.c‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -100,35 +100,6 @@ static const struct mfd_cell mt6397_devs[] = {
100100
}
101101
};
102102

103-
#ifdef CONFIG_PM_SLEEP
104-
static int mt6397_irq_suspend(struct device *dev)
105-
{
106-
struct mt6397_chip *chip = dev_get_drvdata(dev);
107-
108-
regmap_write(chip->regmap, chip->int_con[0], chip->wake_mask[0]);
109-
regmap_write(chip->regmap, chip->int_con[1], chip->wake_mask[1]);
110-
111-
enable_irq_wake(chip->irq);
112-
113-
return 0;
114-
}
115-
116-
static int mt6397_irq_resume(struct device *dev)
117-
{
118-
struct mt6397_chip *chip = dev_get_drvdata(dev);
119-
120-
regmap_write(chip->regmap, chip->int_con[0], chip->irq_masks_cur[0]);
121-
regmap_write(chip->regmap, chip->int_con[1], chip->irq_masks_cur[1]);
122-
123-
disable_irq_wake(chip->irq);
124-
125-
return 0;
126-
}
127-
#endif
128-
129-
static SIMPLE_DEV_PM_OPS(mt6397_pm_ops, mt6397_irq_suspend,
130-
mt6397_irq_resume);
131-
132103
struct chip_data {
133104
u32 cid_addr;
134105
u32 cid_shift;
@@ -238,7 +209,6 @@ static struct platform_driver mt6397_driver = {
238209
.driver = {
239210
.name = "mt6397",
240211
.of_match_table = of_match_ptr(mt6397_of_match),
241-
.pm = &mt6397_pm_ops,
242212
},
243213
.id_table = mt6397_id,
244214
};

‎drivers/mfd/mt6397-irq.c‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/of_irq.h>
1010
#include <linux/platform_device.h>
1111
#include <linux/regmap.h>
12+
#include <linux/suspend.h>
1213
#include <linux/mfd/mt6323/core.h>
1314
#include <linux/mfd/mt6323/registers.h>
1415
#include <linux/mfd/mt6397/core.h>
@@ -81,7 +82,7 @@ static struct irq_chip mt6397_irq_chip = {
8182
static void mt6397_irq_handle_reg(struct mt6397_chip *mt6397, int reg,
8283
int irqbase)
8384
{
84-
unsigned int status;
85+
unsigned int status = 0;
8586
int i, irq, ret;
8687

8788
ret = regmap_read(mt6397->regmap, reg, &status);
@@ -128,6 +129,36 @@ static const struct irq_domain_ops mt6397_irq_domain_ops = {
128129
.map = mt6397_irq_domain_map,
129130
};
130131

132+
static int mt6397_irq_pm_notifier(struct notifier_block *notifier,
133+
unsigned long pm_event, void *unused)
134+
{
135+
struct mt6397_chip *chip =
136+
container_of(notifier, struct mt6397_chip, pm_nb);
137+
138+
switch (pm_event) {
139+
case PM_SUSPEND_PREPARE:
140+
regmap_write(chip->regmap,
141+
chip->int_con[0], chip->wake_mask[0]);
142+
regmap_write(chip->regmap,
143+
chip->int_con[1], chip->wake_mask[1]);
144+
enable_irq_wake(chip->irq);
145+
break;
146+
147+
case PM_POST_SUSPEND:
148+
regmap_write(chip->regmap,
149+
chip->int_con[0], chip->irq_masks_cur[0]);
150+
regmap_write(chip->regmap,
151+
chip->int_con[1], chip->irq_masks_cur[1]);
152+
disable_irq_wake(chip->irq);
153+
break;
154+
155+
default:
156+
break;
157+
}
158+
159+
return NOTIFY_DONE;
160+
}
161+
131162
int mt6397_irq_init(struct mt6397_chip *chip)
132163
{
133164
int ret;
@@ -159,6 +190,7 @@ int mt6397_irq_init(struct mt6397_chip *chip)
159190
regmap_write(chip->regmap, chip->int_con[0], 0x0);
160191
regmap_write(chip->regmap, chip->int_con[1], 0x0);
161192

193+
chip->pm_nb.notifier_call = mt6397_irq_pm_notifier;
162194
chip->irq_domain = irq_domain_add_linear(chip->dev->of_node,
163195
MT6397_IRQ_NR,
164196
&mt6397_irq_domain_ops,
@@ -177,5 +209,6 @@ int mt6397_irq_init(struct mt6397_chip *chip)
177209
return ret;
178210
}
179211

212+
register_pm_notifier(&chip->pm_nb);
180213
return 0;
181214
}

‎include/linux/mfd/mt6397/core.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define __MFD_MT6397_CORE_H__
99

1010
#include <linux/mutex.h>
11+
#include <linux/notifier.h>
1112

1213
enum chip_id {
1314
MT6323_CHIP_ID = 0x23,
@@ -54,6 +55,7 @@ enum mt6397_irq_numbers {
5455
struct mt6397_chip {
5556
struct device *dev;
5657
struct regmap *regmap;
58+
struct notifier_block pm_nb;
5759
int irq;
5860
struct irq_domain *irq_domain;
5961
struct mutex irqlock;

0 commit comments

Comments
 (0)