Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2098388ybl; Thu, 30 Jan 2020 11:19:30 -0800 (PST) X-Google-Smtp-Source: APXvYqwxY1vgoKu5TlHnMV9VJ4RhzIsLQJbdMm+kH8nKsGNayxfROYwfJENrnotfV4mFAM/+bU92 X-Received: by 2002:a9d:7357:: with SMTP id l23mr4604810otk.10.1580411970138; Thu, 30 Jan 2020 11:19:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580411970; cv=none; d=google.com; s=arc-20160816; b=rEoREXt+SH1V5iS+7v6Uyl4jB1G2p5HoyzuHa9unruHCE5BQWYN4fNyY72swQaRtAy kl5X+NzHoSyngLSkb4P5dIfEz1E377EAEo/0PtZrcnJ2WeGtYxZldDHSLYb5ZEr6uFjm X27Pf/KHxredK80jBTSioSJBsrfvm45h6sJ6zEOKB7rTMwtlqRvoRX1h6GV+65DdtnLw mRlcWVBcW6xHUhGHuoumccsVeMkSCxZJZfuJb0SsqHQrx4WV5ESEKcsFcWeyYhFsqDXn tavAHCjWiCuAp5cZ/Ua+VXYKz5jNtSXsjdIGvXOLYWk00nDXQDbwwBLQfPI7Jmcqzv2T 2VnA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wWnLU5A5Hli4HuAPVkW2Pcro0ciQTFD/q75anrQI1ys=; b=mYLUk0EgHrdZbWhZKIu4gx5ZM7HYOtUU1Tu3eLa70T7i6uHWbTgE+8QAhd4xnM5Wmx KPdpxvFITLoMIrjPDkl4RrwSIxgFtz7quzJzYebqmjleMv9t9kD8Keldcuu5eHeRhXDn XYp1YYgRXnn0KbYeK29AyAz6TmWBZ3zLt6XOVgwax/yikEc+vexEyYJjl67v8+Y7NMXa LfqBR7BlLmLvEDFgkrF+ewCsaBz4b2wWtfCnMKm08CUmn05lbZgYWic8WBbVLEopFPKv 4D9g6EucQosYke3miQA4W5SN53p9X+uYdSxQYA9XE7TVs3p/AohDsSADR54h3L0IMFvK Dlvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pEpH8Qh1; 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 u132si978396oie.250.2020.01.30.11.19.18; Thu, 30 Jan 2020 11:19:30 -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; dkim=pass header.i=@kernel.org header.s=default header.b=pEpH8Qh1; 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 S1731102AbgA3Spx (ORCPT + 99 others); Thu, 30 Jan 2020 13:45:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:55466 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731083AbgA3Spp (ORCPT ); Thu, 30 Jan 2020 13:45:45 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 5C91B21734; Thu, 30 Jan 2020 18:45:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580409943; bh=mjJrS8A36FDuKb9fONPOUFh7RpbbhF9DWKvJqd6eeek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pEpH8Qh1CcCxq0iIynqjX/6f+3ZRCA7ZNhy6iXyNui4G82bHTFkEBR/4syR2gG14m GtMdWnWNCK5jIgljLDrJZzftyTbQ+sB9b/0HDUgZWHqOtL1YCBj/jwt1LqMPwKFPX/ m/aC4QrdmGtqWfiBeCs3OocYhgU5GJZSxN/OrU1g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Raul E Rangel , Shyam Sundar S K , Adrian Hunter , Ulf Hansson , Sasha Levin Subject: [PATCH 5.4 092/110] mmc: sdhci-pci: Quirk for AMD SDHC Device 0x7906 Date: Thu, 30 Jan 2020 19:39:08 +0100 Message-Id: <20200130183624.964768848@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200130183613.810054545@linuxfoundation.org> References: <20200130183613.810054545@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Raul E Rangel [ Upstream commit 7a869f00bb15bcefb8804d798a49b086267b03e6 ] AMD SDHC 0x7906 requires a hard reset to clear all internal state. Otherwise it can get into a bad state where the DATA lines are always read as zeros. This change requires firmware that can transition the device into D3Cold for it to work correctly. If the firmware does not support transitioning to D3Cold then the power state transitions are a no-op. Signed-off-by: Raul E Rangel Signed-off-by: Shyam Sundar S K Acked-by: Adrian Hunter Signed-off-by: Ulf Hansson Signed-off-by: Sasha Levin --- drivers/mmc/host/sdhci-pci-core.c | 51 ++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c index 642a9667db4dd..96a163f36a395 100644 --- a/drivers/mmc/host/sdhci-pci-core.c +++ b/drivers/mmc/host/sdhci-pci-core.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -1598,11 +1599,59 @@ static int amd_probe(struct sdhci_pci_chip *chip) return 0; } +static u32 sdhci_read_present_state(struct sdhci_host *host) +{ + return sdhci_readl(host, SDHCI_PRESENT_STATE); +} + +void amd_sdhci_reset(struct sdhci_host *host, u8 mask) +{ + struct sdhci_pci_slot *slot = sdhci_priv(host); + struct pci_dev *pdev = slot->chip->pdev; + u32 present_state; + + /* + * SDHC 0x7906 requires a hard reset to clear all internal state. + * Otherwise it can get into a bad state where the DATA lines are always + * read as zeros. + */ + if (pdev->device == 0x7906 && (mask & SDHCI_RESET_ALL)) { + pci_clear_master(pdev); + + pci_save_state(pdev); + + pci_set_power_state(pdev, PCI_D3cold); + pr_debug("%s: power_state=%u\n", mmc_hostname(host->mmc), + pdev->current_state); + pci_set_power_state(pdev, PCI_D0); + + pci_restore_state(pdev); + + /* + * SDHCI_RESET_ALL says the card detect logic should not be + * reset, but since we need to reset the entire controller + * we should wait until the card detect logic has stabilized. + * + * This normally takes about 40ms. + */ + readx_poll_timeout( + sdhci_read_present_state, + host, + present_state, + present_state & SDHCI_CD_STABLE, + 10000, + 100000 + ); + } + + return sdhci_reset(host, mask); +} + static const struct sdhci_ops amd_sdhci_pci_ops = { .set_clock = sdhci_set_clock, .enable_dma = sdhci_pci_enable_dma, .set_bus_width = sdhci_set_bus_width, - .reset = sdhci_reset, + .reset = amd_sdhci_reset, .set_uhs_signaling = sdhci_set_uhs_signaling, }; -- 2.20.1