From patchwork Fri Jun 21 08:59:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinod Koul X-Patchwork-Id: 167372 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp465866ilk; Fri, 21 Jun 2019 02:02:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaW0pQZpR6NPekE/w39k2piRLJvmyVuLvwFC+5GEwS5YsMfKfGI7cu8S/2er5g59TbtJCc X-Received: by 2002:a17:90a:9a95:: with SMTP id e21mr5053736pjp.98.1561107762255; Fri, 21 Jun 2019 02:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561107762; cv=none; d=google.com; s=arc-20160816; b=Sjs2IX9ASh45AA4b6DIxaig/gEL0TpWgf4zrIYIalfYMewrzoaagjo282QXCULHo81 xyO2aBU7XPnh2F6w1x7NK/CSzHk1xHs0TyHW5DYpvNnU5voFFD8K4sHqVx/UGl4qnox2 lqa/bvWuLMXtOEPbIv4F0y4YEvh/RORH38llApP1mlR53S8N8Thmat+pe0paXLqUMuWg RexjaF/QMaGu/2TlmAY7EnGrdkbzhrXiJ98o3ieHxI59O/PsEC1zOpiA/Fohu4viXjie rojOrdspQmsdGL9AAH8wBaq8wvBB81S6fW4xGheZzwKqsbqGSb//v7rz0ACxf/GZQycS y93A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kuBwx/6bGpWsnsbtKfoiGzuecAfx7ooENOP3ag7RUWc=; b=eZZoOGD4LCkvRRS0EqaYqUYZL7tN7pqLmivf3w6S4RT8XYlg2CwAqhf/jYgTdOP4N5 VwFm4kkOLq1sVlDuKPbHF/5x3PNNu/HZHrw/cNelXpfj90ctr0te4sNmYP89MK99kx1o WAf9ZTGVKaAPgLGbiqoZnec0x/vfggXI0M/CzeWB1vdRJDiO6dgsLaHZF7OA1AZz1S1Y ajjimhasSZDW8OcVPFshRr2d6X+r6xpTQGSUKmP/zoU3e/smAYm+zvoa9g1XF5VGsPBX JktsBopzIubHB6+nZxia9wtLEeycNsmcHTana9OmOF7xp3KmBCuoo0XozB6FdO5AvoeE 8M7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oJqsQtTB; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y92si2124810plb.318.2019.06.21.02.02.42; Fri, 21 Jun 2019 02:02:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oJqsQtTB; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726529AbfFUJCl (ORCPT + 5 others); Fri, 21 Jun 2019 05:02:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:39246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726055AbfFUJCk (ORCPT ); Fri, 21 Jun 2019 05:02:40 -0400 Received: from localhost.localdomain (unknown [106.201.116.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F0DED21537; Fri, 21 Jun 2019 09:02:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561107759; bh=HPuu6qn99OJuGej92r5a0RCVoKbz0adjX409gX5Fu4A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oJqsQtTBFs6HYV8lb86iyIgWaWG3Inwh63l1x9u2JYCujVBUdUUI7TKHvMAbedV3B IBFpBc7/9MoEWus7Eap2Dbe25qAqdCUaXzkct3NeQMOKupdyUI8aED4f2R8cY9nl7b LtC5goceXr94fNES98FbhP7Ul0slEhwL9ABd+lCA= From: Vinod Koul To: Mathias Nyman , Greg Kroah-Hartman Cc: linux-arm-msm@vger.kernel.org, Bjorn Andersson , Christian Lamparter , Yoshihiro Shimoda , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Christian Lamparter , Vinod Koul Subject: [PATCH v2 2/5] usb: xhci: handle uPD720201 and uPD720202 w/o ROM Date: Fri, 21 Jun 2019 14:29:10 +0530 Message-Id: <20190621085913.8722-3-vkoul@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190621085913.8722-1-vkoul@kernel.org> References: <20190621085913.8722-1-vkoul@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Christian Lamparter This patch adds a firmware check for the uPD720201K8-711-BAC-A and uPD720202K8-711-BAA-A variant. Both of these chips are listed in Renesas' R19UH0078EJ0500 Rev.5.00 "User's Manual: Hardware" as devices which need a firmware in order to work as they do not have support to load the firmware from an external ROM. Currently, the xhci-pci driver is unable to initialize the hcd in this case. Instead it will wait for 30 seconds and cause a timeout in xhci_handshake() and fails. [ 5.116990] xhci_hcd 0000:45:00.0: new USB bus registered ... [ 32.335215] xhci_hcd 0000:45:00.0: can't setup: -110 [ 32.340179] xhci_hcd 0000:45:00.0: USB bus 2 deregistered [ 32.345587] xhci_hcd 0000:45:00.0: init 0000:45:00.0 fail, -110 [ 32.351496] xhci_hcd: probe of 0000:45:00.0 failed with error -110 Cc: Yoshihiro Shimoda Signed-off-by: Christian Lamparter Signed-off-by: Bjorn Andersson Signed-off-by: Vinod Koul --- drivers/usb/host/xhci-pci.c | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) -- 2.20.1 diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 724d0f567d98..65de5e961892 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -711,6 +711,55 @@ static int renesas_fw_download_to_hw(struct pci_dev *pdev, return 1; } +static int renesas_check_if_fw_dl_is_needed(struct pci_dev *pdev) +{ + int err; + u8 fw_state; + + /* + * Only the uPD720201K8-711-BAC-A or uPD720202K8-711-BAA-A + * are listed in R19UH0078EJ0500 Rev.5.00 as devices which + * need a firmware in order to work. + * + * - uPD720202 ES 2.0 sample & CS sample & Mass product, ID is 2. + * - uPD720201 ES 2.0 sample whose revision ID is 2. + * - uPD720201 ES 2.1 sample & CS sample & Mass product, ID is 3. + */ + if (!((pdev->vendor == PCI_VENDOR_ID_RENESAS) && + ((pdev->device == 0x0015 && pdev->revision == 0x02) || + (pdev->device == 0x0014 && + (pdev->revision == 0x02 || pdev->revision == 0x03))))) + return 0; + + /* + * Test if the firmware was uploaded and is running. + * As most BIOSes will initialize the device for us. + */ + err = pci_read_config_byte(pdev, 0xf4, &fw_state); + if (err) + return pcibios_err_to_errno(err); + + /* Check the "Result Code" Bits (6:4) and act accordingly */ + switch (fw_state & 0x70) { + case 0: /* No result yet */ + dev_err(&pdev->dev, "FW is not ready/loaded yet."); + return -ENODEV; + + case BIT(4): /* Success, device should be working. */ + dev_dbg(&pdev->dev, "FW is ready."); + return 0; + + case BIT(5): /* Error State */ + dev_err(&pdev->dev, "HW is in an error state."); + return -ENODEV; + + default: /* All other states are marked as "Reserved states" */ + dev_err(&pdev->dev, "HW is in an invalid state (%x).", + (fw_state & 0x70) >> 4); + return -EINVAL; + } +} + /* called during probe() after chip reset completes */ static int xhci_pci_setup(struct usb_hcd *hcd) { @@ -765,6 +814,11 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) return retval; }; + /* Check if this device is a RENESAS uPD720201/2 device. */ + retval = renesas_check_if_fw_dl_is_needed(dev); + if (retval) + return retval; + driver = (struct hc_driver *)id->driver_data; /* Prevent runtime suspending between USB-2 and USB-3 initialization */ @@ -966,6 +1020,11 @@ static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated) if (pdev->vendor == PCI_VENDOR_ID_INTEL) usb_enable_intel_xhci_ports(pdev); + /* Check if this device is a RENESAS uPD720201/2 device. */ + retval = renesas_check_if_fw_dl_is_needed(pdev); + if (retval) + return retval; + if (xhci->quirks & XHCI_SSIC_PORT_UNUSED) xhci_ssic_port_unused_quirk(hcd, false); From patchwork Fri Jun 21 08:59:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinod Koul X-Patchwork-Id: 167374 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp466090ilk; Fri, 21 Jun 2019 02:02:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwi8AwBfUznISeDN16xQ90T39kL6hamhWTRVScSILyLrcemqjmIWmwpT5X08Qu3qoVyS73g X-Received: by 2002:a63:5d61:: with SMTP id o33mr17395651pgm.114.1561107772542; Fri, 21 Jun 2019 02:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561107772; cv=none; d=google.com; s=arc-20160816; b=pCsjDLYUtLXB3FUnXTtDyTiRWg90RRgLgGXaPF7CdK9yOEBapeLsOqNS+k71F6TGKd Anl9OmCGgudvyqVkcueLB6ZNah4qYsiP3honz3AfPRK2VRgw7b1f2LyDs3MZv5mCl2jL j45MHyQwD23Y8+1m754FraObwJ77CFATwt5sJE2xfcYK3wr1bOzQzvKC8ClV+sAO1p7j ppLkS0cNRzKNiiYUFMrsNhXDwT3nwLzF5/RXH7C0rLCdf1L1EH7wizgKZzDih4WVXaEm nokHs3PzXbXuKFvuOKqbc/xar1rsWBPteeLqWTO0f45TdH9zJIThL/JnN0IY7n+8BEvK xQFg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HTbrhUy2KYUATBxO+u0eJVpVB+CF26blgVf5MSnU6Hc=; b=Rzmp9QomHBk3EUAXmIX+ngAOIyG2yaxv7BBB/rj7PmXrdiWkkVk91GsleR93CyDIt9 RaTD+rwSnW2eQH5PYpHX+ZXK3H+7VEL80pnwtDP37iQ93MgR3AtLC5yH18qKEk6usXj+ 0I2FrpHvBw+PzFefgjTc3MegPABzghcYNl546Ue/2XSyEbUojFudfMe+kmoKhCdVsjPR u3BLUnP4VJwZ79Kwu2RXOGm/frChdEAGD4f84uPaFHEb4LurshScPMgrvzFmuCrYFwOI D1SGs5NaDcBN5ZuAnf6peWXs/WlC6oVaCsBNZam2elWBl6fhhvX9+u8Gelr6QCfYTzzy CYxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bwiB3dti; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m15si2282583pff.267.2019.06.21.02.02.52; Fri, 21 Jun 2019 02:02:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bwiB3dti; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726614AbfFUJCv (ORCPT + 5 others); Fri, 21 Jun 2019 05:02:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:39444 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726597AbfFUJCv (ORCPT ); Fri, 21 Jun 2019 05:02:51 -0400 Received: from localhost.localdomain (unknown [106.201.116.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0AAD121537; Fri, 21 Jun 2019 09:02:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561107769; bh=tTo2Wlvf680AhD4G4TZwBLGKrQJmR21YpnfXx+58EXY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bwiB3dtiO2nHAVh/YgM0Fmg2K0/An4hyL2VRSCPkVNebFN6fruXzYrNxRljTr4C4C 2W6dB/d49arZr0826eQO5B+uz84cnBKZQttY+4e0DAZBzf3oB5zWGy46dh35W8hQzs it+8lgqcVnOv4xtL8KKsUkYYC1tNry0zEQbI4OCA= From: Vinod Koul To: Mathias Nyman , Greg Kroah-Hartman Cc: linux-arm-msm@vger.kernel.org, Bjorn Andersson , Vinod Koul , Yoshihiro Shimoda , Christian Lamparter , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/5] usb: xhci: allow multiple firmware versions Date: Fri, 21 Jun 2019 14:29:13 +0530 Message-Id: <20190621085913.8722-6-vkoul@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190621085913.8722-1-vkoul@kernel.org> References: <20190621085913.8722-1-vkoul@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Allow multiple firmware file versions in table and load them in increasing order as we find them in the file system. Signed-off-by: Vinod Koul Cc: Yoshihiro Shimoda Cc: Christian Lamparter --- drivers/usb/host/xhci-pci.c | 46 +++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 771948ce3d38..1fb890984d6d 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -336,13 +336,19 @@ static const struct renesas_fw_entry { * - uPD720201 ES 2.0 sample whose revision ID is 2. * - uPD720201 ES 2.1 sample & CS sample & Mass product, ID is 3. * - uPD720202 ES 2.0 sample & CS sample & Mass product, ID is 2. + * + * Entry expected_version should be kept in increasing order for a + * chip, so that driver will pick first version and if that fails + * then next one will be picked */ { "K2013080.mem", 0x0014, 0x02, 0x2013 }, { "K2013080.mem", 0x0014, 0x03, 0x2013 }, + { "K2026090.mem", 0x0014, 0x03, 0x2026 }, { "K2013080.mem", 0x0015, 0x02, 0x2013 }, }; MODULE_FIRMWARE("K2013080.mem"); +MODULE_FIRMWARE("K2026090.mem"); static const struct renesas_fw_entry *renesas_needs_fw_dl(struct pci_dev *dev) { @@ -363,6 +369,24 @@ static const struct renesas_fw_entry *renesas_needs_fw_dl(struct pci_dev *dev) return NULL; } +static const struct +renesas_fw_entry *renesas_get_next_entry(struct pci_dev *dev, + const struct renesas_fw_entry *entry) +{ + const struct renesas_fw_entry *next_entry; + size_t i; + + for (i = 0; i < ARRAY_SIZE(renesas_fw_table); i++) { + next_entry = &renesas_fw_table[i]; + if (next_entry->device == dev->device && + next_entry->revision == dev->revision && + next_entry->expected_version > entry->expected_version) + return next_entry; + } + + return NULL; +} + static int renesas_fw_download_image(struct pci_dev *dev, const u32 *fw, size_t step) @@ -709,6 +733,7 @@ struct renesas_fw_ctx { struct pci_dev *pdev; const struct pci_device_id *id; bool resume; + const struct renesas_fw_entry *entry; }; static int xhci_pci_probe(struct pci_dev *pdev, @@ -968,13 +993,29 @@ static void renesas_fw_callback(const struct firmware *fw, struct renesas_fw_ctx *ctx = context; struct pci_dev *pdev = ctx->pdev; struct device *parent = pdev->dev.parent; + const struct renesas_fw_entry *next_entry; bool rom; int err; if (!fw) { dev_err(&pdev->dev, "firmware failed to load\n"); - - goto cleanup; + /* + * we didn't find firmware, check if we have another + * entry for this device + */ + next_entry = renesas_get_next_entry(ctx->pdev, ctx->entry); + if (next_entry) { + ctx->entry = next_entry; + dev_dbg(&pdev->dev, "Found next entry, requesting: %s\n", + next_entry->firmware_name); + request_firmware_nowait(THIS_MODULE, 1, + next_entry->firmware_name, + &pdev->dev, GFP_KERNEL, + ctx, renesas_fw_callback); + return; + } else { + goto cleanup; + } } err = renesas_fw_verify(pdev, fw->data, fw->size); @@ -1072,6 +1113,7 @@ static int renesas_fw_download_to_hw(struct pci_dev *pdev, ctx->pdev = pdev; ctx->resume = do_resume; ctx->id = id; + ctx->entry = entry; pci_dev_get(pdev); err = request_firmware_nowait(THIS_MODULE, 1, entry->firmware_name,