lantiq: fix broadcasts and vlans in two iface mode
[oweals/openwrt.git] / target / linux / brcm2708 / patches-4.9 / 0023-watchdog-bcm2835-Support-setting-reboot-partition.patch
1 From 0e690096e05c3b4e806381ff38124dbdae3ba877 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= <noralf@tronnes.org>
3 Date: Fri, 7 Oct 2016 16:50:59 +0200
4 Subject: [PATCH] watchdog: bcm2835: Support setting reboot partition
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 The Raspberry Pi firmware looks at the RSTS register to know which
10 partition to boot from. The reboot syscall command
11 LINUX_REBOOT_CMD_RESTART2 supports passing in a string argument.
12
13 Add support for passing in a partition number 0..63 to boot from.
14 Partition 63 is a special partiton indicating halt.
15 If the partition doesn't exist, the firmware falls back to partition 0.
16
17 Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
18 ---
19  drivers/watchdog/bcm2835_wdt.c | 61 +++++++++++++++++++++++++-----------------
20  1 file changed, 36 insertions(+), 25 deletions(-)
21
22 --- a/drivers/watchdog/bcm2835_wdt.c
23 +++ b/drivers/watchdog/bcm2835_wdt.c
24 @@ -35,13 +35,7 @@
25  #define PM_RSTC_WRCFG_SET              0x00000030
26  #define PM_RSTC_WRCFG_FULL_RESET       0x00000020
27  #define PM_RSTC_RESET                  0x00000102
28 -
29 -/*
30 - * The Raspberry Pi firmware uses the RSTS register to know which partiton
31 - * to boot from. The partiton value is spread into bits 0, 2, 4, 6, 8, 10.
32 - * Partiton 63 is a special partition used by the firmware to indicate halt.
33 - */
34 -#define PM_RSTS_RASPBERRYPI_HALT       0x555
35 +#define PM_RSTS_PARTITION_CLR          0xfffffaaa
36  
37  #define SECS_TO_WDOG_TICKS(x) ((x) << 16)
38  #define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
39 @@ -111,15 +105,28 @@ static struct watchdog_device bcm2835_wd
40         .timeout =      WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET),
41  };
42  
43 -static int
44 -bcm2835_restart(struct notifier_block *this, unsigned long mode, void *cmd)
45 +/*
46 + * The Raspberry Pi firmware uses the RSTS register to know which partiton
47 + * to boot from. The partiton value is spread into bits 0, 2, 4, 6, 8, 10.
48 + * Partiton 63 is a special partition used by the firmware to indicate halt.
49 + */
50 +
51 +static void bcm2835_restart(struct bcm2835_wdt *wdt, u8 partition)
52  {
53 -       struct bcm2835_wdt *wdt = container_of(this, struct bcm2835_wdt,
54 -                                              restart_handler);
55 -       u32 val;
56 +       u32 val, rsts;
57 +
58 +       rsts = (partition & BIT(0)) | ((partition & BIT(1)) << 1) |
59 +              ((partition & BIT(2)) << 2) | ((partition & BIT(3)) << 3) |
60 +              ((partition & BIT(4)) << 4) | ((partition & BIT(5)) << 5);
61 +
62 +       val = readl_relaxed(wdt->base + PM_RSTS);
63 +       val &= PM_RSTS_PARTITION_CLR;
64 +       val |= PM_PASSWORD | rsts;
65 +       writel_relaxed(val, wdt->base + PM_RSTS);
66  
67         /* use a timeout of 10 ticks (~150us) */
68         writel_relaxed(10 | PM_PASSWORD, wdt->base + PM_WDOG);
69 +
70         val = readl_relaxed(wdt->base + PM_RSTC);
71         val &= PM_RSTC_WRCFG_CLR;
72         val |= PM_PASSWORD | PM_RSTC_WRCFG_FULL_RESET;
73 @@ -127,6 +134,20 @@ bcm2835_restart(struct notifier_block *t
74  
75         /* No sleeping, possibly atomic. */
76         mdelay(1);
77 +}
78 +
79 +static int bcm2835_restart_notifier_call(struct notifier_block *this,
80 +                                        unsigned long mode, void *cmd)
81 +{
82 +       struct bcm2835_wdt *wdt = container_of(this, struct bcm2835_wdt,
83 +                                              restart_handler);
84 +       unsigned long long val;
85 +       u8 partition = 0;
86 +
87 +       if (cmd && !kstrtoull(cmd, 0, &val) && val <= 63)
88 +               partition = val;
89 +
90 +       bcm2835_restart(wdt, partition);
91  
92         return 0;
93  }
94 @@ -142,19 +163,9 @@ static void bcm2835_power_off(void)
95                 of_find_compatible_node(NULL, NULL, "brcm,bcm2835-pm-wdt");
96         struct platform_device *pdev = of_find_device_by_node(np);
97         struct bcm2835_wdt *wdt = platform_get_drvdata(pdev);
98 -       u32 val;
99 -
100 -       /*
101 -        * We set the watchdog hard reset bit here to distinguish this reset
102 -        * from the normal (full) reset. bootcode.bin will not reboot after a
103 -        * hard reset.
104 -        */
105 -       val = readl_relaxed(wdt->base + PM_RSTS);
106 -       val |= PM_PASSWORD | PM_RSTS_RASPBERRYPI_HALT;
107 -       writel_relaxed(val, wdt->base + PM_RSTS);
108  
109 -       /* Continue with normal reset mechanism */
110 -       bcm2835_restart(&wdt->restart_handler, REBOOT_HARD, NULL);
111 +       /* Partition 63 tells the firmware that this is a halt */
112 +       bcm2835_restart(wdt, 63);
113  }
114  
115  static int bcm2835_wdt_probe(struct platform_device *pdev)
116 @@ -188,7 +199,7 @@ static int bcm2835_wdt_probe(struct plat
117                 return err;
118         }
119  
120 -       wdt->restart_handler.notifier_call = bcm2835_restart;
121 +       wdt->restart_handler.notifier_call = bcm2835_restart_notifier_call;
122         wdt->restart_handler.priority = 128;
123         register_restart_handler(&wdt->restart_handler);
124         if (pm_power_off == NULL)