bcm27xx: update patches from RPi foundation
[oweals/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0409-usb-xhci-Raspberry-Pi-FW-loader-for-VIA-VL805.patch
1 From 333c4158645fe8aaacbd644bcdf7bc4c5b93cc26 Mon Sep 17 00:00:00 2001
2 From: Tim Gover <990920+timg236@users.noreply.github.com>
3 Date: Wed, 15 Jan 2020 11:26:19 +0000
4 Subject: [PATCH] usb: xhci: Raspberry Pi FW loader for VIA VL805
5
6 The VL805 FW may either be loaded from an SPI EEPROM or alternatively
7 loaded directly by the VideoCore firmware. A PCI reset will reset
8 the VL805 XHCI controller on the Raspberry Pi4 requiring the firmware
9 to be reloaded if an SPI EEPROM is not present.
10
11 Use a VideoCore mailbox to trigger the loading of the VL805
12 firmware (if necessary) after a PCI reset.
13
14 Signed-off-by: Tim Gover <tim.gover@raspberrypi.org>
15 ---
16  drivers/usb/host/pci-quirks.c              | 31 +++++++++++++++++++++-
17  include/soc/bcm2835/raspberrypi-firmware.h |  2 +-
18  2 files changed, 31 insertions(+), 2 deletions(-)
19
20 --- a/drivers/usb/host/pci-quirks.c
21 +++ b/drivers/usb/host/pci-quirks.c
22 @@ -18,7 +18,7 @@
23  #include <linux/dmi.h>
24  #include "pci-quirks.h"
25  #include "xhci-ext-caps.h"
26 -
27 +#include <soc/bcm2835/raspberrypi-firmware.h>
28  
29  #define UHCI_USBLEGSUP         0xc0            /* legacy support */
30  #define UHCI_USBCMD            0               /* command register */
31 @@ -634,6 +634,32 @@ EXPORT_SYMBOL_GPL(usb_amd_pt_check_port)
32  
33  #endif /* CONFIG_PCI_DISABLE_COMMON_QUIRKS */
34  
35 +/* The VL805 firmware may either be loaded from an EEPROM or by the BIOS into
36 + * memory. If run from memory it must be reloaded after a PCI fundmental reset.
37 + * The Raspberry Pi firmware acts as the BIOS in this case.
38 + */
39 +static void usb_vl805_init(struct pci_dev *pdev)
40 +{
41 +#if IS_ENABLED(CONFIG_RASPBERRYPI_FIRMWARE)
42 +       struct rpi_firmware *fw;
43 +       struct {
44 +               u32 dev_addr;
45 +       } packet;
46 +       int ret;
47 +
48 +       fw = rpi_firmware_get(NULL);
49 +       if (!fw)
50 +               return;
51 +
52 +       packet.dev_addr = (pdev->bus->number << 20) |
53 +               (PCI_SLOT(pdev->devfn) << 15) | (PCI_FUNC(pdev->devfn) << 12);
54 +
55 +       dev_dbg(&pdev->dev, "RPI_FIRMWARE_NOTIFY_XHCI_RESET %x", packet.dev_addr);
56 +       ret = rpi_firmware_property(fw, RPI_FIRMWARE_NOTIFY_XHCI_RESET,
57 +                       &packet, sizeof(packet));
58 +#endif
59 +}
60 +
61  #if IS_ENABLED(CONFIG_USB_UHCI_HCD)
62  
63  /*
64 @@ -1222,6 +1248,9 @@ hc_init:
65         if (pdev->vendor == PCI_VENDOR_ID_INTEL)
66                 usb_enable_intel_xhci_ports(pdev);
67  
68 +       if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483)
69 +               usb_vl805_init(pdev);
70 +
71         op_reg_base = base + XHCI_HC_LENGTH(readl(base));
72  
73         /* Wait for the host controller to be ready before writing any
74 --- a/include/soc/bcm2835/raspberrypi-firmware.h
75 +++ b/include/soc/bcm2835/raspberrypi-firmware.h
76 @@ -95,7 +95,7 @@ enum rpi_firmware_property_tag {
77         RPI_FIRMWARE_SET_PERIPH_REG =                         0x00038045,
78         RPI_FIRMWARE_GET_POE_HAT_VAL =                        0x00030049,
79         RPI_FIRMWARE_SET_POE_HAT_VAL =                        0x00030050,
80 -
81 +       RPI_FIRMWARE_NOTIFY_XHCI_RESET =                      0x00030058,
82  
83         /* Dispmanx TAGS */
84         RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE =                   0x00040001,