Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4594786ybv; Mon, 17 Feb 2020 02:07:55 -0800 (PST) X-Google-Smtp-Source: APXvYqyOHn0iXKiGSY9I8h/lAKc/m8NFOrRf5vMmrJkRigSPdwm3Lp9KGCBIClinLe7KuUy8cSse X-Received: by 2002:a05:6830:13da:: with SMTP id e26mr10828887otq.97.1581934075473; Mon, 17 Feb 2020 02:07:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581934075; cv=none; d=google.com; s=arc-20160816; b=DAr+kG1+kRC0ZND10Rr936NdkkoiPJKCGa3gHNRVyLQvmXUlMtX7ad6Os65rB4/jR3 JNYr8d6qmpaxTjm6RRjhJwQcD63YklQLn5RH91RjDTC1A2tzJdgFavlVtFsbvGhVeUXO bEdLgmajYSnY1vCUfXeUVf2mEFjKWsYiAoEpj/+iR96COZ0dBzsqqsLAhFwylkG2VmyL lMCATYgGB9Ek53r0nfx2OM+5f4ALD8P6HFQ+2BhOOV+NLIDysjoIYXDagq5V0ScHk5IM jzbYdjOnhoew7Yy/loRtoTJFpUCPpH6IvAUFlbBdH1pTVFkRvXP0jbqd7bzkdraNga92 vR0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=08CgjNK4cdiCQEsJ2eIa/G+UZUyzFmz6CZSITQT7fvE=; b=oe68RzUJlYM9Vg+eE4vIFkPkWwzYdem30GwLkf72W/ktX7vE72a1E9jPuMBEo6X92T o+apg+aZAb8987mTqF4veW8VXY5unCfmSbc5AFg6BSry1L8cP5Hts7qlXckiTqNBR07K vg6JW1vsEaPTiieani8clAauRmHp0LOyViM6185TIRcmSU04iElkGZf5b7ryg6K0JJkN 5uxC+arNvZL5iWHteUYWosbELSaoPNvrYqGJpc1k5fEEaNgfp4ZIToH6ItBpahCPShRr /0EEraPJRiYd6ktm3sFJk8FLfOy+cn5Nypt6YIWq35IgFlRkoDeP1/vNDcm/Gx5b6kCZ MqKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8si3880otg.309.2020.02.17.02.07.42; Mon, 17 Feb 2020 02:07:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729129AbgBQKHM (ORCPT + 99 others); Mon, 17 Feb 2020 05:07:12 -0500 Received: from mx2.suse.de ([195.135.220.15]:42610 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728833AbgBQKHL (ORCPT ); Mon, 17 Feb 2020 05:07:11 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 76A7BAD5C; Mon, 17 Feb 2020 10:07:09 +0000 (UTC) From: Nicolas Saenz Julienne To: Mathias Nyman , Nicolas Saenz Julienne , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com Cc: oneukum@suse.com, phil@raspberrypi.com, tim.gover@raspberrypi.org, Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] usb: xhci-pci: Raspberry Pi FW loader for VIA VL805 Date: Mon, 17 Feb 2020 11:07:00 +0100 Message-Id: <20200217100701.19949-1-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 #include +#include + #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; + + 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, /* Dispmanx TAGS */ RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE = 0x00040001, -- 2.25.0