Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6372290yba; Wed, 1 May 2019 10:56:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwaEMvlyVAuMoLjZPTQcyCAcBMpD0Wile5YZ0+FeUjJ9LHMcvIWd/p0zazL4vYgGCIBF+Ra X-Received: by 2002:a17:902:8483:: with SMTP id c3mr75602622plo.19.1556733376088; Wed, 01 May 2019 10:56:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556733376; cv=none; d=google.com; s=arc-20160816; b=bzEIFvIqgWavpTGOenNOGWt5V4hmCT+J4lGynu777nDMDzRChdmhDhJQjEfQv66Y07 QvTdZM4YhZE/mLCmSxj8gbnfZ/AeFmjjqVOwk3Q7rZP1Te4jxfn63ThHew8218AehiPm 0Uj1QAwQ+wLfqiznVY4FrunkP4PcuRjs3KueAMwl942aOC+jjcQ+UgQT4wsmB/+GURKj Zll2IKqhfD3bjg1szzL01SROWcBCyTwCGgPRUfz0Dyenq4Tsw7gOactbSJIrEka7v12u OGuudCziyZIkWlN9lXP+/om8EDVNGDg7CUWkVg1o4umgwWsuOXDrdb47j6ONbspZvbl3 yp1w== 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=6ugiQw2wmXsizkXcJVBBH7E80UNKwak/4AnnndV8B0U=; b=xBlqU70Lu29F0tQfb9HzMF6FphmJRI64z9doS1VT2Fex7fvDLmHbWD6Ax/rJxW9Fzm ljHBKt36OeBgqOSVHpK3CmDf22Ah+z4FfiRiGaIf4yivRf+kHn4QXmYvi+VEfVQA3AEo c3lvNaMWYSI7oZCdivkyQp7mANY5b6Wu1y8fzRN1Uj5vA7r32Gb+05L6A+OT4TtgiI99 eVi8793o5KdTLFTdpgwSwgL6FqDCF/BdI5Ue/7qQp5klaI1pEGS7Iq7s7TQo1ReoLkpC CTMZBCp73BbzUY6YHRY5xlPqZVlqUYcvOlsQ0La1H0ZVv6klXc0zPy2ctT+XY42t+/dL o2/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CMlH0fg6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f127si42804199pfc.176.2019.05.01.10.56.00; Wed, 01 May 2019 10:56:16 -0700 (PDT) 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=@chromium.org header.s=google header.b=CMlH0fg6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726316AbfEARzK (ORCPT + 99 others); Wed, 1 May 2019 13:55:10 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:41867 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726069AbfEARzJ (ORCPT ); Wed, 1 May 2019 13:55:09 -0400 Received: by mail-io1-f66.google.com with SMTP id r10so15442606ioc.8 for ; Wed, 01 May 2019 10:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6ugiQw2wmXsizkXcJVBBH7E80UNKwak/4AnnndV8B0U=; b=CMlH0fg6MSe0yGgM9xkAMZ/NyW0I63R3XsYDPFR9TW0ziXvksqmtD1tc1jsCb0vR2o 8BQCaWD2MKxTmoPhVwOofqJnv5lkXWjl4tBhjTy6bXJyCb+I3rjpyimlSyUoTo7OZ1V1 2T1Dx9MIkKmBZ/uEZA/mBMi/oa5EkcJ7iK20w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6ugiQw2wmXsizkXcJVBBH7E80UNKwak/4AnnndV8B0U=; b=Hj2KUnYleLw8HNlM7TsfJAvfaCGKkJVLFqIu1d926xhbIjtr8/SRStJ/t4cT0uBUrB W2tO8He+5w5/dA+vUKPLUaJypY/nwjvOxy++E1Ln5H2/0ZTeKJ9zYjcjOKVS0V+CSYsO gai6tbfvkk+F5rQxUJ9nNKLgmKDQQlR5d4m5WNAgqORs62d8ubesdX9lFy6JpEHivAsF OH4Ek/MS2IwPNgm7Puz7GvygbOcHCvbYpou729ELExhxha1+CxfB0FHnc06+344mGqi5 FmjInkfrr1jBc86OCuQTDd5bM0RyFsmPuvEwD9gN7XKVycq+U4+q75Mee/ozjZUCMO/8 WdKw== X-Gm-Message-State: APjAAAVHjHHQjmuLsHhl5r4zy9s3ex7Wghon6p/7/wk6fF/7kniHrOb0 3qNkZ5Qo+XFAIKZbmm79m6202Q== X-Received: by 2002:a6b:b585:: with SMTP id e127mr621510iof.197.1556733308703; Wed, 01 May 2019 10:55:08 -0700 (PDT) Received: from localhost ([2620:15c:183:0:20b8:dee7:5447:d05]) by smtp.gmail.com with ESMTPSA id f204sm3424627itc.26.2019.05.01.10.55.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 May 2019 10:55:08 -0700 (PDT) From: Raul E Rangel To: linux-mmc@vger.kernel.org Cc: djkurtz@chromium.org, Raul E Rangel , linux-kernel@vger.kernel.org, Adrian Hunter , Ulf Hansson Subject: [RFC PATCH 2/2] mmc: sdhci: Quirk for AMD SDHC Device 0x7906 Date: Wed, 1 May 2019 11:54:57 -0600 Message-Id: <20190501175457.195855-2-rrangel@chromium.org> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog In-Reply-To: <20190501175457.195855-1-rrangel@chromium.org> References: <20190501175457.195855-1-rrangel@chromium.org> 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 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 --- 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 99b0fec2836b..532fbcbd373b 100644 --- a/drivers/mmc/host/sdhci-pci-core.c +++ b/drivers/mmc/host/sdhci-pci-core.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -1498,11 +1499,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.21.0.593.g511ec345e18-goog