brcm2708: add linux 4.19 support
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.19 / 950-0017-watchdog-bcm2835-Support-setting-reboot-partition.patch
1 From 3091f3a65590ab446e9c637377efa55dc3b8996f 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 017/703] 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 | 49 +++++++++++++++++++---------------
20 1 file changed, 27 insertions(+), 22 deletions(-)
21
22 --- a/drivers/watchdog/bcm2835_wdt.c
23 +++ b/drivers/watchdog/bcm2835_wdt.c
24 @@ -31,13 +31,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 partition
31 - * to boot from. The partition value is spread into bits 0, 2, 4, 6, 8, 10.
32 - * Partition 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 @@ -94,9 +88,24 @@ static unsigned int bcm2835_wdt_get_time
40 return WDOG_TICKS_TO_SECS(ret & PM_WDOG_TIME_SET);
41 }
42
43 -static void __bcm2835_restart(struct bcm2835_wdt *wdt)
44 +/*
45 + * The Raspberry Pi firmware uses the RSTS register to know which partiton
46 + * to boot from. The partiton value is spread into bits 0, 2, 4, 6, 8, 10.
47 + * Partiton 63 is a special partition used by the firmware to indicate halt.
48 + */
49 +
50 +static void __bcm2835_restart(struct bcm2835_wdt *wdt, u8 partition)
51 {
52 - u32 val;
53 + u32 val, rsts;
54 +
55 + rsts = (partition & BIT(0)) | ((partition & BIT(1)) << 1) |
56 + ((partition & BIT(2)) << 2) | ((partition & BIT(3)) << 3) |
57 + ((partition & BIT(4)) << 4) | ((partition & BIT(5)) << 5);
58 +
59 + val = readl_relaxed(wdt->base + PM_RSTS);
60 + val &= PM_RSTS_PARTITION_CLR;
61 + val |= PM_PASSWORD | rsts;
62 + writel_relaxed(val, wdt->base + PM_RSTS);
63
64 /* use a timeout of 10 ticks (~150us) */
65 writel_relaxed(10 | PM_PASSWORD, wdt->base + PM_WDOG);
66 @@ -114,7 +123,13 @@ static int bcm2835_restart(struct watchd
67 {
68 struct bcm2835_wdt *wdt = watchdog_get_drvdata(wdog);
69
70 - __bcm2835_restart(wdt);
71 + unsigned long long val;
72 + u8 partition = 0;
73 +
74 + if (data && !kstrtoull(data, 0, &val) && val <= 63)
75 + partition = val;
76 +
77 + __bcm2835_restart(wdt, partition);
78
79 return 0;
80 }
81 @@ -152,19 +167,9 @@ static void bcm2835_power_off(void)
82 of_find_compatible_node(NULL, NULL, "brcm,bcm2835-pm-wdt");
83 struct platform_device *pdev = of_find_device_by_node(np);
84 struct bcm2835_wdt *wdt = platform_get_drvdata(pdev);
85 - u32 val;
86 -
87 - /*
88 - * We set the watchdog hard reset bit here to distinguish this reset
89 - * from the normal (full) reset. bootcode.bin will not reboot after a
90 - * hard reset.
91 - */
92 - val = readl_relaxed(wdt->base + PM_RSTS);
93 - val |= PM_PASSWORD | PM_RSTS_RASPBERRYPI_HALT;
94 - writel_relaxed(val, wdt->base + PM_RSTS);
95
96 - /* Continue with normal reset mechanism */
97 - __bcm2835_restart(wdt);
98 + /* Partition 63 tells the firmware that this is a halt */
99 + __bcm2835_restart(wdt, 63);
100 }
101
102 static int bcm2835_wdt_probe(struct platform_device *pdev)