arm: rpi: Add function to trigger VL805's firmware load 30/240330/2
authorMarek Szyprowski <m.szyprowski@samsung.com>
Wed, 5 Aug 2020 10:03:14 +0000 (12:03 +0200)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 6 Aug 2020 01:59:16 +0000 (01:59 +0000)
On the Raspberry Pi 4, after a PCI reset, VL805's (a xHCI chip) firmware
may either be loaded directly from an EEPROM or, if not present, by the
SoC's VideCore (the SoC's co-processor). Introduce the function that
informs VideCore that VL805 may need its firmware loaded.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
[mszyprow: backport of https://patchwork.ozlabs.org/project/uboot/list/?series=174860&state=%2A&archive=both
 the final mainline patch depends on DTS changes not present in vendor tree]
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Change-Id: I565a81e49c0684cfc2500ecb203ed4233cce4e14

arch/arm/mach-bcm283x/include/mach/mbox.h
arch/arm/mach-bcm283x/include/mach/msg.h
arch/arm/mach-bcm283x/msg.c

index a4df9bf..7063163 100644 (file)
@@ -491,6 +491,19 @@ struct bcm2835_mbox_tag_set_palette {
        } body;
 };
 
+#define BCM2835_MBOX_TAG_NOTIFY_XHCI_RESET          0x00030058
+
+struct bcm2835_mbox_tag_pci_dev_addr {
+       struct bcm2835_mbox_tag_hdr tag_hdr;
+       union {
+               struct {
+                       u32 dev_addr;
+               } req;
+               struct {
+               } resp;
+       } body;
+};
+
 #define BCM2835_MBOX_TAG_GET_RSTS              0x00040011
 
 struct bcm2835_mbox_tag_get_rsts {
index 4afb086..f5213dd 100644 (file)
@@ -48,4 +48,11 @@ int bcm2835_set_video_params(int *widthp, int *heightp, int depth_bpp,
                             int pixel_order, int alpha_mode, ulong *fb_basep,
                             ulong *fb_sizep, int *pitchp);
 
+/**
+ * bcm2711_notify_vl805_reset() - get vl805's firmware loaded
+ *
+ * @return 0 if OK, -EIO on error
+ */
+int bcm2711_notify_vl805_reset(void);
+
 #endif
index 94b7528..f8ef531 100644 (file)
@@ -40,6 +40,12 @@ struct msg_setup {
        u32 end_tag;
 };
 
+struct msg_notify_vl805_reset {
+       struct bcm2835_mbox_hdr hdr;
+       struct bcm2835_mbox_tag_pci_dev_addr dev_addr;
+       u32 end_tag;
+};
+
 int bcm2835_power_on_module(u32 module)
 {
        ALLOC_CACHE_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1);
@@ -151,3 +157,42 @@ int bcm2835_set_video_params(int *widthp, int *heightp, int depth_bpp,
 
        return 0;
 }
+
+/*
+ * The Raspberry Pi 4 gets its USB functionality from VL805, a PCIe chip that
+ * implements xHCI. After a PCI reset, VL805's firmware may either be loaded
+ * directly from an EEPROM or, if not present, by the SoC's co-processor,
+ * VideoCore. RPi4's VideoCore OS contains both the non public firmware load
+ * logic and the VL805 firmware blob. This function triggers the aforementioned
+ * process.
+ */
+int bcm2711_notify_vl805_reset(void)
+{
+       ALLOC_CACHE_ALIGN_BUFFER(struct msg_notify_vl805_reset,
+                                msg_notify_vl805_reset, 1);
+       int ret;
+
+       BCM2835_MBOX_INIT_HDR(msg_notify_vl805_reset);
+       BCM2835_MBOX_INIT_TAG(&msg_notify_vl805_reset->dev_addr,
+                             NOTIFY_XHCI_RESET);
+
+       /*
+        * The pci device address is expected like this:
+        *
+        *   PCI_BUS << 20 | PCI_SLOT << 15 | PCI_FUNC << 12
+        *
+        * But since RPi4's PCIe setup is hardwired, we know the address in
+        * advance.
+        */
+       msg_notify_vl805_reset->dev_addr.body.req.dev_addr = 0x100000;
+
+       ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
+                                    &msg_notify_vl805_reset->hdr);
+       if (ret) {
+               printf("bcm2711: Faild to load vl805's firmware, %d\n", ret);
+               return -EIO;
+       }
+
+       return 0;
+}
+