bcm27xx: update patches from RPi foundation
[oweals/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0114-firmware-raspberrypi-Notify-firmware-of-a-reboot.patch
1 From 3386d22d3b3bcb202ef186d699d9dddfa681e13b Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Sat, 12 May 2018 21:35:43 +0100
4 Subject: [PATCH] firmware/raspberrypi: Notify firmware of a reboot
5
6 Register for reboot notifications, sending RPI_FIRMWARE_NOTIFY_REBOOT
7 over the mailbox interface on reception.
8
9 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
10 ---
11  drivers/firmware/raspberrypi.c | 40 +++++++++++++++++++++++++++++++++-
12  1 file changed, 39 insertions(+), 1 deletion(-)
13
14 --- a/drivers/firmware/raspberrypi.c
15 +++ b/drivers/firmware/raspberrypi.c
16 @@ -12,6 +12,7 @@
17  #include <linux/of_platform.h>
18  #include <linux/platform_device.h>
19  #include <linux/slab.h>
20 +#include <linux/reboot.h>
21  #include <soc/bcm2835/raspberrypi-firmware.h>
22  
23  #define MBOX_MSG(chan, data28)         (((data28) & ~0xf) | ((chan) & 0xf))
24 @@ -177,6 +178,26 @@ int rpi_firmware_property(struct rpi_fir
25  }
26  EXPORT_SYMBOL_GPL(rpi_firmware_property);
27  
28 +static int rpi_firmware_notify_reboot(struct notifier_block *nb,
29 +                                     unsigned long action,
30 +                                     void *data)
31 +{
32 +       struct rpi_firmware *fw;
33 +       struct platform_device *pdev = g_pdev;
34 +
35 +       if (!pdev)
36 +               return 0;
37 +
38 +       fw = platform_get_drvdata(pdev);
39 +       if (!fw)
40 +               return 0;
41 +
42 +       (void)rpi_firmware_property(fw, RPI_FIRMWARE_NOTIFY_REBOOT,
43 +                                   0, 0);
44 +
45 +       return 0;
46 +}
47 +
48  static void
49  rpi_firmware_print_firmware_revision(struct rpi_firmware *fw)
50  {
51 @@ -307,15 +328,32 @@ static struct platform_driver rpi_firmwa
52         .remove         = rpi_firmware_remove,
53  };
54  
55 +static struct notifier_block rpi_firmware_reboot_notifier = {
56 +       .notifier_call = rpi_firmware_notify_reboot,
57 +};
58 +
59  static int __init rpi_firmware_init(void)
60  {
61 -       return platform_driver_register(&rpi_firmware_driver);
62 +       int ret = register_reboot_notifier(&rpi_firmware_reboot_notifier);
63 +       if (ret)
64 +               goto out1;
65 +       ret = platform_driver_register(&rpi_firmware_driver);
66 +       if (ret)
67 +               goto out2;
68 +
69 +       return 0;
70 +
71 +out2:
72 +       unregister_reboot_notifier(&rpi_firmware_reboot_notifier);
73 +out1:
74 +       return ret;
75  }
76  subsys_initcall(rpi_firmware_init);
77  
78  static void __init rpi_firmware_exit(void)
79  {
80         platform_driver_unregister(&rpi_firmware_driver);
81 +       unregister_reboot_notifier(&rpi_firmware_reboot_notifier);
82  }
83  module_exit(rpi_firmware_exit);
84