linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] dt-bindings: Add Raspberry Pi compatible string for watchdog
@ 2015-06-09 10:21 Noralf Trønnes
  2015-06-09 10:21 ` [PATCH 2/3] watchdog: bcm2835: Add poweroff code for the Raspberry Pi Noralf Trønnes
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Noralf Trønnes @ 2015-06-09 10:21 UTC (permalink / raw)
  To: linux-arm-kernel

The Raspberry Pi has changed how it's firmware detects a poweroff
and needs special handling for this.

Signed-off-by: Noralf Tr?nnes <noralf@tronnes.org>
---
 Documentation/devicetree/bindings/watchdog/brcm,bcm2835-pm-wdog.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/watchdog/brcm,bcm2835-pm-wdog.txt b/Documentation/devicetree/bindings/watchdog/brcm,bcm2835-pm-wdog.txt
index f801d71..1a80931 100644
--- a/Documentation/devicetree/bindings/watchdog/brcm,bcm2835-pm-wdog.txt
+++ b/Documentation/devicetree/bindings/watchdog/brcm,bcm2835-pm-wdog.txt
@@ -2,7 +2,8 @@ BCM2835 Watchdog timer
 
 Required properties:
 
-- compatible : should be "brcm,bcm2835-pm-wdt"
+- compatible : should be "brcm,raspberrypi-pm-wdt" for the Raspberry Pi and
+	       "brcm,bcm2835-pm-wdt" for others.
 - reg : Specifies base physical address and size of the registers.
 
 Optional properties:
-- 
2.2.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] watchdog: bcm2835: Add poweroff code for the Raspberry Pi
  2015-06-09 10:21 [PATCH 1/3] dt-bindings: Add Raspberry Pi compatible string for watchdog Noralf Trønnes
@ 2015-06-09 10:21 ` Noralf Trønnes
  2015-06-12 11:26   ` Stefan Wahren
  2015-06-12 12:23   ` Guenter Roeck
  2015-06-09 10:21 ` [PATCH 3/3] ARM: dts: bcm2835-rpi: Add "brcm, raspberrypi-pm-wdt" to wdt compatible Noralf Trønnes
  2015-06-13  6:46 ` [PATCH 1/3] dt-bindings: Add Raspberry Pi compatible string for watchdog Jeff Epler
  2 siblings, 2 replies; 7+ messages in thread
From: Noralf Trønnes @ 2015-06-09 10:21 UTC (permalink / raw)
  To: linux-arm-kernel

This adds a new poweroff function to the watchdog driver for the
Raspberry Pi. Currently poweroff/halt results in a reboot.

The Raspberry Pi firmware uses the RSTS register to know which
partiton to boot from. The partiton value is spread into bits
0, 2, 4, 6, 8, 10. Partiton 63 is a special partition used by
the firmware to indicate halt.

The firmware made this change in 19 Aug 2013 and was matched
by the downstream commit:
Changes for new NOOBS multi partition booting from gsh

Signed-off-by: Noralf Tr?nnes <noralf@tronnes.org>
---
 drivers/watchdog/bcm2835_wdt.c | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/drivers/watchdog/bcm2835_wdt.c b/drivers/watchdog/bcm2835_wdt.c
index 7116968..fdf0d7d 100644
--- a/drivers/watchdog/bcm2835_wdt.c
+++ b/drivers/watchdog/bcm2835_wdt.c
@@ -36,6 +36,13 @@
 #define PM_RSTC_WRCFG_FULL_RESET	0x00000020
 #define PM_RSTC_RESET			0x00000102
 
+/*
+ * The Raspberry Pi firmware uses the RSTS register to know which partiton
+ * to boot from. The partiton value is spread into bits 0, 2, 4, 6, 8, 10.
+ * Partiton 63 is a special partition used by the firmware to indicate halt.
+ */
+#define PM_RSTS_RASPBERRYPI_HALT	0x555
+
 #define SECS_TO_WDOG_TICKS(x) ((x) << 16)
 #define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
 
@@ -159,6 +166,24 @@ static void bcm2835_power_off(void)
 	bcm2835_restart(&wdt->restart_handler, REBOOT_HARD, NULL);
 }
 
+static void rpi_power_off(void)
+{
+	struct device_node *np =
+		of_find_compatible_node(NULL, NULL, "brcm,raspberrypi-pm-wdt");
+	struct platform_device *pdev = of_find_device_by_node(np);
+	struct bcm2835_wdt *wdt = platform_get_drvdata(pdev);
+	u32 val;
+
+	val = readl_relaxed(wdt->base + PM_RSTS);
+	val |= PM_PASSWORD | PM_RSTS_RASPBERRYPI_HALT;
+	writel_relaxed(val, wdt->base + PM_RSTS);
+
+	/* Continue with normal reset mechanism */
+	bcm2835_restart(&wdt->restart_handler, REBOOT_HARD, NULL);
+}
+
+static const struct of_device_id bcm2835_wdt_of_match[];
+
 static int bcm2835_wdt_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -192,8 +217,12 @@ static int bcm2835_wdt_probe(struct platform_device *pdev)
 	wdt->restart_handler.notifier_call = bcm2835_restart;
 	wdt->restart_handler.priority = 128;
 	register_restart_handler(&wdt->restart_handler);
-	if (pm_power_off == NULL)
-		pm_power_off = bcm2835_power_off;
+	if (!pm_power_off) {
+		const struct of_device_id *match;
+
+		match = of_match_node(bcm2835_wdt_of_match, pdev->dev.of_node);
+		pm_power_off = match->data;
+	}
 
 	dev_info(dev, "Broadcom BCM2835 watchdog timer");
 	return 0;
@@ -204,7 +233,7 @@ static int bcm2835_wdt_remove(struct platform_device *pdev)
 	struct bcm2835_wdt *wdt = platform_get_drvdata(pdev);
 
 	unregister_restart_handler(&wdt->restart_handler);
-	if (pm_power_off == bcm2835_power_off)
+	if (pm_power_off == bcm2835_power_off || pm_power_off == rpi_power_off)
 		pm_power_off = NULL;
 	watchdog_unregister_device(&bcm2835_wdt_wdd);
 	iounmap(wdt->base);
@@ -218,7 +247,8 @@ static void bcm2835_wdt_shutdown(struct platform_device *pdev)
 }
 
 static const struct of_device_id bcm2835_wdt_of_match[] = {
-	{ .compatible = "brcm,bcm2835-pm-wdt", },
+	{ .compatible = "brcm,bcm2835-pm-wdt", .data = bcm2835_power_off },
+	{ .compatible = "brcm,raspberrypi-pm-wdt", .data = rpi_power_off },
 	{},
 };
 MODULE_DEVICE_TABLE(of, bcm2835_wdt_of_match);
-- 
2.2.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] ARM: dts: bcm2835-rpi: Add "brcm, raspberrypi-pm-wdt" to wdt compatible
  2015-06-09 10:21 [PATCH 1/3] dt-bindings: Add Raspberry Pi compatible string for watchdog Noralf Trønnes
  2015-06-09 10:21 ` [PATCH 2/3] watchdog: bcm2835: Add poweroff code for the Raspberry Pi Noralf Trønnes
@ 2015-06-09 10:21 ` Noralf Trønnes
  2015-06-13  6:46 ` [PATCH 1/3] dt-bindings: Add Raspberry Pi compatible string for watchdog Jeff Epler
  2 siblings, 0 replies; 7+ messages in thread
From: Noralf Trønnes @ 2015-06-09 10:21 UTC (permalink / raw)
  To: linux-arm-kernel

The Raspberry Pi uses a new value for halt in the PM_RSTS watchdog
register. Expand the compatible string to cover this.

Signed-off-by: Noralf Tr?nnes <noralf@tronnes.org>
---
 arch/arm/boot/dts/bcm2835-rpi.dtsi | 4 ++++
 arch/arm/boot/dts/bcm2835.dtsi     | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/bcm2835-rpi.dtsi b/arch/arm/boot/dts/bcm2835-rpi.dtsi
index 46780bb..feb1282 100644
--- a/arch/arm/boot/dts/bcm2835-rpi.dtsi
+++ b/arch/arm/boot/dts/bcm2835-rpi.dtsi
@@ -16,6 +16,10 @@
 	};
 };
 
+&watchdog {
+	compatible = "brcm,raspberrypi-pm-wdt", "brcm,bcm2835-pm-wdt";
+};
+
 &gpio {
 	pinctrl-names = "default";
 
diff --git a/arch/arm/boot/dts/bcm2835.dtsi b/arch/arm/boot/dts/bcm2835.dtsi
index 301c73f..3445bb3 100644
--- a/arch/arm/boot/dts/bcm2835.dtsi
+++ b/arch/arm/boot/dts/bcm2835.dtsi
@@ -52,7 +52,7 @@
 			#interrupt-cells = <2>;
 		};
 
-		watchdog at 7e100000 {
+		watchdog: watchdog at 7e100000 {
 			compatible = "brcm,bcm2835-pm-wdt";
 			reg = <0x7e100000 0x28>;
 		};
-- 
2.2.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] watchdog: bcm2835: Add poweroff code for the Raspberry Pi
  2015-06-09 10:21 ` [PATCH 2/3] watchdog: bcm2835: Add poweroff code for the Raspberry Pi Noralf Trønnes
@ 2015-06-12 11:26   ` Stefan Wahren
  2015-06-12 12:18     ` Guenter Roeck
  2015-06-12 12:23   ` Guenter Roeck
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Wahren @ 2015-06-12 11:26 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Noralf,

Am 09.06.2015 um 12:21 schrieb Noralf Tr?nnes:
> This adds a new poweroff function to the watchdog driver for the
> Raspberry Pi. Currently poweroff/halt results in a reboot.
>
> [...]
>
> +static void rpi_power_off(void)
> +{
> +	struct device_node *np =
> +		of_find_compatible_node(NULL, NULL, "brcm,raspberrypi-pm-wdt");
> +	struct platform_device *pdev = of_find_device_by_node(np);
> +	struct bcm2835_wdt *wdt = platform_get_drvdata(pdev);
> +	u32 val;
> +
> +	val = readl_relaxed(wdt->base + PM_RSTS);

do you think it's safe here to assume wdt could never be NULL?

May be it's necessary to send the series to the watchdog / bcm2835 
maintainers to get more feedback.

Regards
Stefan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] watchdog: bcm2835: Add poweroff code for the Raspberry Pi
  2015-06-12 11:26   ` Stefan Wahren
@ 2015-06-12 12:18     ` Guenter Roeck
  0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2015-06-12 12:18 UTC (permalink / raw)
  To: linux-arm-kernel

On 06/12/2015 04:26 AM, Stefan Wahren wrote:
> Hi Noralf,
>
> Am 09.06.2015 um 12:21 schrieb Noralf Tr?nnes:
>> This adds a new poweroff function to the watchdog driver for the
>> Raspberry Pi. Currently poweroff/halt results in a reboot.
>>
>> [...]
>>
>> +static void rpi_power_off(void)
>> +{
>> +    struct device_node *np =
>> +        of_find_compatible_node(NULL, NULL, "brcm,raspberrypi-pm-wdt");
>> +    struct platform_device *pdev = of_find_device_by_node(np);
>> +    struct bcm2835_wdt *wdt = platform_get_drvdata(pdev);
>> +    u32 val;
>> +
>> +    val = readl_relaxed(wdt->base + PM_RSTS);
>
> do you think it's safe here to assume wdt could never be NULL?
>

If the call is made, the driver must be instantiated. We can therefore assume
that neither np, pdev, nor wdt is NULL. If one of those is NULL, it would be
a bug, which should not be ignored.

Guenter

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] watchdog: bcm2835: Add poweroff code for the Raspberry Pi
  2015-06-09 10:21 ` [PATCH 2/3] watchdog: bcm2835: Add poweroff code for the Raspberry Pi Noralf Trønnes
  2015-06-12 11:26   ` Stefan Wahren
@ 2015-06-12 12:23   ` Guenter Roeck
  1 sibling, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2015-06-12 12:23 UTC (permalink / raw)
  To: linux-arm-kernel

On 06/09/2015 03:21 AM, Noralf Tr?nnes wrote:
> This adds a new poweroff function to the watchdog driver for the
> Raspberry Pi. Currently poweroff/halt results in a reboot.
>
> The Raspberry Pi firmware uses the RSTS register to know which
> partiton to boot from. The partiton value is spread into bits
> 0, 2, 4, 6, 8, 10. Partiton 63 is a special partition used by
> the firmware to indicate halt.
>
> The firmware made this change in 19 Aug 2013 and was matched
> by the downstream commit:
> Changes for new NOOBS multi partition booting from gsh
>
> Signed-off-by: Noralf Tr?nnes <noralf@tronnes.org>

This poweroff handler stuff is getting really messy :-(.

Nothing we can do about that here, so

Acked-by: Guenter Roeck <linux@roeck-us.net>

Guenter

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] dt-bindings: Add Raspberry Pi compatible string for watchdog
  2015-06-09 10:21 [PATCH 1/3] dt-bindings: Add Raspberry Pi compatible string for watchdog Noralf Trønnes
  2015-06-09 10:21 ` [PATCH 2/3] watchdog: bcm2835: Add poweroff code for the Raspberry Pi Noralf Trønnes
  2015-06-09 10:21 ` [PATCH 3/3] ARM: dts: bcm2835-rpi: Add "brcm, raspberrypi-pm-wdt" to wdt compatible Noralf Trønnes
@ 2015-06-13  6:46 ` Jeff Epler
  2 siblings, 0 replies; 7+ messages in thread
From: Jeff Epler @ 2015-06-13  6:46 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Jun 09, 2015 at 12:21:43PM +0200, Noralf Tr?nnes wrote:
> The Raspberry Pi has changed how it's firmware detects a poweroff
                                   ^^^^ trivial typo, should be "its"
.. just in case this can be fixed before it lands in a tree.

Jeff

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-06-13  6:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-09 10:21 [PATCH 1/3] dt-bindings: Add Raspberry Pi compatible string for watchdog Noralf Trønnes
2015-06-09 10:21 ` [PATCH 2/3] watchdog: bcm2835: Add poweroff code for the Raspberry Pi Noralf Trønnes
2015-06-12 11:26   ` Stefan Wahren
2015-06-12 12:18     ` Guenter Roeck
2015-06-12 12:23   ` Guenter Roeck
2015-06-09 10:21 ` [PATCH 3/3] ARM: dts: bcm2835-rpi: Add "brcm, raspberrypi-pm-wdt" to wdt compatible Noralf Trønnes
2015-06-13  6:46 ` [PATCH 1/3] dt-bindings: Add Raspberry Pi compatible string for watchdog Jeff Epler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).