]> git.karo-electronics.de Git - linux-beck.git/commitdiff
mfd: mt6397: Implement wake handler and suspend/resume to handle wake up event
authorHenry Chen <henryc.chen@mediatek.com>
Mon, 10 Aug 2015 13:10:45 +0000 (21:10 +0800)
committerLee Jones <lee.jones@linaro.org>
Tue, 11 Aug 2015 14:09:11 +0000 (15:09 +0100)
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>
drivers/mfd/mt6397-core.c
include/linux/mfd/mt6397/core.h

index 9ca290fec003f95f4d1977f44a4c759554f5346b..1749c1c9f405a87c4efd5400dd808d2a74e26a2b 100644 (file)
@@ -93,12 +93,31 @@ static void mt6397_irq_enable(struct irq_data *data)
        mt6397->irq_masks_cur[reg] |= BIT(shift);
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int mt6397_irq_set_wake(struct irq_data *irq_data, unsigned int on)
+{
+       struct mt6397_chip *mt6397 = irq_data_get_irq_chip_data(irq_data);
+       int shift = irq_data->hwirq & 0xf;
+       int reg = irq_data->hwirq >> 4;
+
+       if (on)
+               mt6397->wake_mask[reg] |= BIT(shift);
+       else
+               mt6397->wake_mask[reg] &= ~BIT(shift);
+
+       return 0;
+}
+#else
+#define mt6397_irq_set_wake NULL
+#endif
+
 static struct irq_chip mt6397_irq_chip = {
        .name = "mt6397-irq",
        .irq_bus_lock = mt6397_irq_lock,
        .irq_bus_sync_unlock = mt6397_irq_sync_unlock,
        .irq_enable = mt6397_irq_enable,
        .irq_disable = mt6397_irq_disable,
+       .irq_set_wake = mt6397_irq_set_wake,
 };
 
 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)
        return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int mt6397_irq_suspend(struct device *dev)
+{
+       struct mt6397_chip *chip = dev_get_drvdata(dev);
+
+       regmap_write(chip->regmap, MT6397_INT_CON0, chip->wake_mask[0]);
+       regmap_write(chip->regmap, MT6397_INT_CON1, chip->wake_mask[1]);
+
+       enable_irq_wake(chip->irq);
+
+       return 0;
+}
+
+static int mt6397_irq_resume(struct device *dev)
+{
+       struct mt6397_chip *chip = dev_get_drvdata(dev);
+
+       regmap_write(chip->regmap, MT6397_INT_CON0, chip->irq_masks_cur[0]);
+       regmap_write(chip->regmap, MT6397_INT_CON1, chip->irq_masks_cur[1]);
+
+       disable_irq_wake(chip->irq);
+
+       return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(mt6397_pm_ops, mt6397_irq_suspend,
+                       mt6397_irq_resume);
+
 static int mt6397_probe(struct platform_device *pdev)
 {
        int ret;
@@ -233,6 +281,7 @@ static struct platform_driver mt6397_driver = {
        .driver = {
                .name = "mt6397",
                .of_match_table = of_match_ptr(mt6397_of_match),
+               .pm = &mt6397_pm_ops,
        },
 };
 
index cf5265b0d1c1897d120ae6b7a07b9d59ed41e052..45b8e8aa1fbfc2c440a6a5fe2d5cb91c4a7f2bf8 100644 (file)
@@ -57,6 +57,7 @@ struct mt6397_chip {
        int irq;
        struct irq_domain *irq_domain;
        struct mutex irqlock;
+       u16 wake_mask[2];
        u16 irq_masks_cur[2];
        u16 irq_masks_cache[2];
 };