Skip to content

Commit f3151ab

Browse files
henryc-chenLee Jones
authored andcommitted
mfd: mt6397: Implement wake handler and suspend/resume to handle wake up event
Implement .irq_set_wake() to get who is wakeup source and setup on suspend/reumse. Enable mt6393_irq as wake up source properly to pinctrl by enable_irq_wake()/enable_irq_wake(). Signed-off-by: Henry Chen <henryc.chen@mediatek.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent d9c93f5 commit f3151ab

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎drivers/mfd/mt6397-core.c‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,31 @@ static void mt6397_irq_enable(struct irq_data *data)
9393
mt6397->irq_masks_cur[reg] |= BIT(shift);
9494
}
9595

96+
#ifdef CONFIG_PM_SLEEP
97+
static int mt6397_irq_set_wake(struct irq_data *irq_data, unsigned int on)
98+
{
99+
struct mt6397_chip *mt6397 = irq_data_get_irq_chip_data(irq_data);
100+
int shift = irq_data->hwirq & 0xf;
101+
int reg = irq_data->hwirq >> 4;
102+
103+
if (on)
104+
mt6397->wake_mask[reg] |= BIT(shift);
105+
else
106+
mt6397->wake_mask[reg] &= ~BIT(shift);
107+
108+
return 0;
109+
}
110+
#else
111+
#define mt6397_irq_set_wake NULL
112+
#endif
113+
96114
static struct irq_chip mt6397_irq_chip = {
97115
.name = "mt6397-irq",
98116
.irq_bus_lock = mt6397_irq_lock,
99117
.irq_bus_sync_unlock = mt6397_irq_sync_unlock,
100118
.irq_enable = mt6397_irq_enable,
101119
.irq_disable = mt6397_irq_disable,
120+
.irq_set_wake = mt6397_irq_set_wake,
102121
};
103122

104123
static void mt6397_irq_handle_reg(struct mt6397_chip *mt6397, int reg,
@@ -179,6 +198,35 @@ static int mt6397_irq_init(struct mt6397_chip *mt6397)
179198
return 0;
180199
}
181200

201+
#ifdef CONFIG_PM_SLEEP
202+
static int mt6397_irq_suspend(struct device *dev)
203+
{
204+
struct mt6397_chip *chip = dev_get_drvdata(dev);
205+
206+
regmap_write(chip->regmap, MT6397_INT_CON0, chip->wake_mask[0]);
207+
regmap_write(chip->regmap, MT6397_INT_CON1, chip->wake_mask[1]);
208+
209+
enable_irq_wake(chip->irq);
210+
211+
return 0;
212+
}
213+
214+
static int mt6397_irq_resume(struct device *dev)
215+
{
216+
struct mt6397_chip *chip = dev_get_drvdata(dev);
217+
218+
regmap_write(chip->regmap, MT6397_INT_CON0, chip->irq_masks_cur[0]);
219+
regmap_write(chip->regmap, MT6397_INT_CON1, chip->irq_masks_cur[1]);
220+
221+
disable_irq_wake(chip->irq);
222+
223+
return 0;
224+
}
225+
#endif
226+
227+
static SIMPLE_DEV_PM_OPS(mt6397_pm_ops, mt6397_irq_suspend,
228+
mt6397_irq_resume);
229+
182230
static int mt6397_probe(struct platform_device *pdev)
183231
{
184232
int ret;
@@ -233,6 +281,7 @@ static struct platform_driver mt6397_driver = {
233281
.driver = {
234282
.name = "mt6397",
235283
.of_match_table = of_match_ptr(mt6397_of_match),
284+
.pm = &mt6397_pm_ops,
236285
},
237286
};
238287

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct mt6397_chip {
5757
int irq;
5858
struct irq_domain *irq_domain;
5959
struct mutex irqlock;
60+
u16 wake_mask[2];
6061
u16 irq_masks_cur[2];
6162
u16 irq_masks_cache[2];
6263
};

0 commit comments

Comments
 (0)