From patchwork Thu Oct 18 21:51:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajat Jain X-Patchwork-Id: 10648315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6AE9914E2 for ; Thu, 18 Oct 2018 21:51:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59DEF28CDB for ; Thu, 18 Oct 2018 21:51:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4887C28CD2; Thu, 18 Oct 2018 21:51:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B81BC28CD2 for ; Thu, 18 Oct 2018 21:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726530AbeJSFyH (ORCPT ); Fri, 19 Oct 2018 01:54:07 -0400 Received: from mail-vs1-f73.google.com ([209.85.217.73]:42811 "EHLO mail-vs1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbeJSFyH (ORCPT ); Fri, 19 Oct 2018 01:54:07 -0400 Received: by mail-vs1-f73.google.com with SMTP id j1so14346632vsd.9 for ; Thu, 18 Oct 2018 14:51:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=12a0pPTT0t2IzJ36ztwDZOEfbUvwt5h/3nY2mXK8uJc=; b=cB5TpWgYBTtKOMQv91oq6S6S9p8w1pitUcikiprRdaMczHJWuzo3gl+q02Nudqrd7a K+VrAM+8HPrCMzcrq1kINBnRbSKxyJ5hn2ul4ec+DfutZ4MmyATosrPKVsD5kdnV7DEP e3k2BFJvuJNHJUH+QqXb0Znm+FRrc9XxON9PSQPzlo6F3/1PQSaX87+spEPCFl3frbvF 8O2Mb69sgaCemPYSrklpwAD4AJ1y8WJbuApn22v2mKZ1aRZVpfYRlvUxMlFdV7tGu4hy jNvQUVqS4fBD3UxUpT1ZYWli8y7aKe9I+63zhgWR9Qwz5wowluqbzpJWoiZMNIIFHf0Q Lsbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=12a0pPTT0t2IzJ36ztwDZOEfbUvwt5h/3nY2mXK8uJc=; b=fey72W7wJUrR2A6aB5ZcZaEh4iNoVAa7vFMiqvbtTYYzwDmjBEPJLzVpA+Va1h/OFI 1ifhQ2nC3BVQY0r0IrnHomO9BExgLncw2my668Aa2sXkrD6rVP9HJtUNFV8/gwCWyuoB Cu1f/1PYzGa7FFHlD38edhz/+y0HtMMuEIR26TcGDgMUxRNFnqaW4La0haKVgjFIFCif t3sGbNbDAOFXs6a4zmxNAd3tw8rgpiCkW3mi36/ml2RssON3js8uKgt2s0Q0L9zQ81Ru fV91tJZbyFrc8VBf9gMTbVLYNLiz7cykKADYya6jUTjaTui2I2taTAZAPMhnjQ1e8TNW rDaQ== X-Gm-Message-State: ABuFfogyvYXV4u1xNguQSqDJbibG1J/R1SmAwBj6x4z8ZDi1mZjKSVgR 5WstIMaq6oLZVQqYodenZgPvxFTyhjxl X-Google-Smtp-Source: ACcGV61gfqpFSuyIr4qqAbKGzTlNKLWH6dt6aPWzSlNZ4VAvPqjf1u9eFeYpj1dLiKviQsbUVl3ZpVT+fwNP X-Received: by 2002:ab0:e03:: with SMTP id g3mr24551977uak.4.1539899467277; Thu, 18 Oct 2018 14:51:07 -0700 (PDT) Date: Thu, 18 Oct 2018 14:51:01 -0700 In-Reply-To: Message-Id: <20181018215101.169847-1-rajatja@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog Subject: [PATCH] mmc: sdhci-pci: Try "cd" for card-detect lookup before using NULL From: Rajat Jain To: Adrian Hunter , Ulf Hansson , linux-mmc@vger.kernel.org, Linus Walleij Cc: Rajat Jain , rajatxjain@gmail.com, linux-kernel@vger.kernel.org, Mika Westerberg , Andy Shevchenko , Dmitry Torokhov , linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Problem: The card detect IRQ does not work with modern BIOS (that want to use DSD to provide the card detect GPIO to the driver). Details: (Discussion: https://lkml.org/lkml/2018/9/25/1113) The mmc core provides the mmc_gpiod_request_cd() API to let host drivers request the gpio descriptor for the "card detect" (or carrier detect?) pin. This pin is specified in the ACPI for the SDHC device: * Either as a resource using _CRS. This is a method used by legacy BIOS. (The driver needs to tell which resource index). * Or as a named property ("cd-gpio") in DSD (which may internally point to an entry in _CRS). This way, the driver can lookup using a string. This is what modern BIOS prefer to use. This API finally results in a call to the following code: struct gpio_desc *acpi_find_gpio(..., const char *con_id,...) { ... /* Lookup gpio (using "-gpio") in the _DSD */ ... if (!acpi_can_fallback_to_crs(adev, con_id)) return ERR_PTR(-ENOENT); ... /* Falling back to _CRS is allowed, Lookup gpio in the _CRS */ ... } Note that this means that if the ACPI has _DSD properties, the kernel will never use _CRS for the lookup (Because acpi_can_fallback_to_crs() will always be false for any device hat has _DSD entries). The SDHCI driver is thus currently broken on a modern BIOS (even if BIOS provides both _CRS and DSD entries, either of which could be used for a successful lookup). Ironically, none of these will be used for the lookup currently because: * Since the con_id is NULL, acpi_find_gpio() does not find a matching entry in DSDT. (The DSDT entry has the property name = "cd-gpio") * Because ACPI contains DSDT entries, thus acpi_can_fallback_to_crs() returns false (because device properties have been populated from DSD), thus the _CRS is never used for the lookup. Fix: Try "cd" for lookup in the _DSD before falling back to using NULL so as to try looking up in the _CRS. I've tested this patch successfully with both Legacy BIOS (that provide only _CRS method) as well as modern BIOS (that provide both _CRS and DSD). Also the use of "cd" also appears to be farly consistent across other users of this API (other MMC host controller drivers). Signed-off-by: Rajat Jain --- drivers/mmc/host/sdhci-pci-core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c index 7bfd366d970d..e53333c695b3 100644 --- a/drivers/mmc/host/sdhci-pci-core.c +++ b/drivers/mmc/host/sdhci-pci-core.c @@ -1762,8 +1762,13 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot( device_init_wakeup(&pdev->dev, true); if (slot->cd_idx >= 0) { - ret = mmc_gpiod_request_cd(host->mmc, NULL, slot->cd_idx, + ret = mmc_gpiod_request_cd(host->mmc, "cd", slot->cd_idx, slot->cd_override_level, 0, NULL); + if (ret && ret != -EPROBE_DEFER) + ret = mmc_gpiod_request_cd(host->mmc, NULL, + slot->cd_idx, + slot->cd_override_level, + 0, NULL); if (ret == -EPROBE_DEFER) goto remove;