Hi Nicolas, Am 17.02.20 um 11:07 schrieb Nicolas Saenz Julienne: > On the Raspberry Pi 4, after a PCI reset, VL805's firmware may either be > loaded directly from an EEPROM or, if not present, by the SoC's > VideCore. Inform VideCore that VL805 was just reset, or defer xhci's > probe if not yet joinable trough the mailbox interface. > > Based on Tim Gover's downstream implementation. > > Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@xxxxxxx> > --- > drivers/usb/host/xhci-pci.c | 50 ++++++++++++++++++++++ > include/soc/bcm2835/raspberrypi-firmware.h | 2 +- > 2 files changed, 51 insertions(+), 1 deletion(-) > > diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c > index 4917c5b033fa..eadace4a9339 100644 > --- a/drivers/usb/host/xhci-pci.c > +++ b/drivers/usb/host/xhci-pci.c > @@ -13,6 +13,8 @@ > #include <linux/module.h> > #include <linux/acpi.h> > > +#include <soc/bcm2835/raspberrypi-firmware.h> > + > #include "xhci.h" > #include "xhci-trace.h" > > @@ -308,6 +310,44 @@ static int xhci_pci_setup(struct usb_hcd *hcd) > return xhci_pci_reinit(xhci, pdev); > } > > +/* > + * On the Raspberry Pi 4, after a PCI reset, VL805's firmware may either be > + * loaded directly from an EEPROM or, if not present, by the SoC's VideCore. > + * Inform VideCore that VL805 was just reset, or defer xhci's probe if not yet > + * joinable trough the mailbox interface. > + */ > +static int raspberrypi_load_vl805_fw(struct pci_dev *pdev) > +{ > +#ifdef CONFIG_RASPBERRYPI_FIRMWARE > + struct device_node *fw_np; > + struct rpi_firmware *fw; > + u32 dev_addr; > + int ret; > + > + fw_np = of_find_compatible_node(NULL, NULL, > + "raspberrypi,bcm2835-firmware"); > + if (!fw_np) > + return 0; > + > + fw = rpi_firmware_get(fw_np); > + of_node_put(fw_np); > + if (!fw) > + return -EPROBE_DEFER; > + > + dev_addr = pdev->bus->number << 20 | PCI_SLOT(pdev->devfn) << 15 | > + PCI_FUNC(pdev->devfn) << 12; > + > + ret = rpi_firmware_property(fw, RPI_FIRMWARE_NOTIFY_XHCI_RESET, > + &dev_addr, sizeof(dev_addr)); > + if (ret) > + return ret; not sure, but there could be a corner case which should be handled differently. In case the Raspberry Pi 4 has an EEPROM for the VL805 firmware but the firmware is too old to handle RPI_FIRMWARE_NOTIFY_XHCI_RESET, we should return with 0. I don't know there is a change to detect this reliable. I just want to mention this. > + > + dev_dbg(&pdev->dev, "loaded Raspberry Pi's VL805 firmware\n"); > + > +#endif > + return 0; > +} > + > /* > * We need to register our own PCI probe function (instead of the USB core's > * function) in order to create a second roothub under xHCI. > @@ -321,6 +361,16 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) > > driver = (struct hc_driver *)id->driver_data; > > + if (dev->vendor == PCI_VENDOR_ID_VIA && dev->device == 0x3483) { > + retval = raspberrypi_load_vl805_fw(dev); > + if (retval) { > + if (retval != -EPROBE_DEFER) > + dev_err(&dev->dev, > + "Failed to load VL805's firmware"); > + return retval; > + } > + } > + > /* Prevent runtime suspending between USB-2 and USB-3 initialization */ > pm_runtime_get_noresume(&dev->dev); > > diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h > index 7800e12ee042..cc9cdbc66403 100644 > --- a/include/soc/bcm2835/raspberrypi-firmware.h > +++ b/include/soc/bcm2835/raspberrypi-firmware.h > @@ -90,7 +90,7 @@ enum rpi_firmware_property_tag { > RPI_FIRMWARE_SET_PERIPH_REG = 0x00038045, > RPI_FIRMWARE_GET_POE_HAT_VAL = 0x00030049, > RPI_FIRMWARE_SET_POE_HAT_VAL = 0x00030050, > - > + RPI_FIRMWARE_NOTIFY_XHCI_RESET = 0x00030058, In past we updated the firmware mailbox property interface in a bunch as a separate patch. So we can avoid those gaps. Best regards Stefan > > /* Dispmanx TAGS */ > RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE = 0x00040001,