gemini: add 4.14 support
[oweals/openwrt.git] / target / linux / gemini / patches-4.14 / 0026-power-gemini-poweroff-Avoid-spurious-poweroff.patch
1 From da443bc125265cae24a0e5f7d1c7bba196a9319f Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Thu, 22 Feb 2018 08:34:35 +0100
4 Subject: [PATCH 26/31] power: gemini-poweroff: Avoid spurious poweroff
5
6 On the D-Link DIR-685 we get spurious poweroff from
7 infrared. Since that block (CIR) doesn't even have a
8 driver this can be safely ignored, we can revisit this
9 code once we have a device supporting CIR.
10
11 On the D-Link DNS-313 we get spurious poweroff from
12 the power button. This appears to be an initialization
13 issue: we need to enable the block (start the state
14 machine) before we clear any dangling IRQ.
15
16 This patch fixes both issues.
17
18 Fixes: f7a388d6cd1c ("power: reset: Add a driver for the Gemini poweroff")
19 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
20 ---
21 ChangeLog v1->v2:
22 - Fix both issues and rename the patch.
23 - Proper commit message with specifics.
24 ---
25  drivers/power/reset/gemini-poweroff.c | 30 +++++++++++++++++-------------
26  1 file changed, 17 insertions(+), 13 deletions(-)
27
28 --- a/drivers/power/reset/gemini-poweroff.c
29 +++ b/drivers/power/reset/gemini-poweroff.c
30 @@ -47,8 +47,12 @@ static irqreturn_t gemini_powerbutton_in
31         val &= 0x70U;
32         switch (val) {
33         case GEMINI_STAT_CIR:
34 -               dev_info(gpw->dev, "infrared poweroff\n");
35 -               orderly_poweroff(true);
36 +               /*
37 +                * We do not yet have a driver for the infrared
38 +                * controller so it can cause spurious poweroff
39 +                * events. Ignore those for now.
40 +                */
41 +               dev_info(gpw->dev, "infrared poweroff - ignored\n");
42                 break;
43         case GEMINI_STAT_RTC:
44                 dev_info(gpw->dev, "RTC poweroff\n");
45 @@ -116,7 +120,17 @@ static int gemini_poweroff_probe(struct
46                 return -ENODEV;
47         }
48  
49 -       /* Clear the power management IRQ */
50 +       /*
51 +        * Enable the power controller. This is crucial on Gemini
52 +        * systems: if this is not done, pressing the power button
53 +        * will result in unconditional poweroff without any warning.
54 +        * This makes the kernel handle the poweroff.
55 +        */
56 +       val = readl(gpw->base + GEMINI_PWC_CTRLREG);
57 +       val |= GEMINI_CTRL_ENABLE;
58 +       writel(val, gpw->base + GEMINI_PWC_CTRLREG);
59 +
60 +       /* Now that the state machine is active, clear the IRQ */
61         val = readl(gpw->base + GEMINI_PWC_CTRLREG);
62         val |= GEMINI_CTRL_IRQ_CLR;
63         writel(val, gpw->base + GEMINI_PWC_CTRLREG);
64 @@ -129,16 +143,6 @@ static int gemini_poweroff_probe(struct
65         pm_power_off = gemini_poweroff;
66         gpw_poweroff = gpw;
67  
68 -       /*
69 -        * Enable the power controller. This is crucial on Gemini
70 -        * systems: if this is not done, pressing the power button
71 -        * will result in unconditional poweroff without any warning.
72 -        * This makes the kernel handle the poweroff.
73 -        */
74 -       val = readl(gpw->base + GEMINI_PWC_CTRLREG);
75 -       val |= GEMINI_CTRL_ENABLE;
76 -       writel(val, gpw->base + GEMINI_PWC_CTRLREG);
77 -
78         dev_info(dev, "Gemini poweroff driver registered\n");
79  
80         return 0;