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: 986338 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="cB5TpWgY"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42bjRZ4HQQz9sBj for ; Fri, 19 Oct 2018 08:51:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726566AbeJSFyH (ORCPT ); Fri, 19 Oct 2018 01:54:07 -0400 Received: from mail-vs1-f74.google.com ([209.85.217.74]:55538 "EHLO mail-vs1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726176AbeJSFyH (ORCPT ); Fri, 19 Oct 2018 01:54:07 -0400 Received: by mail-vs1-f74.google.com with SMTP id h129so8528160vsd.22 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=mOACYdH0zBpej/JnDMceF/B2iUB4XRc+2Ckd1HiTGl6dkRK0d0614RnlIBOod0i2ok Le6Cbu37oNCqn7LKXFhn1lKA5KKEOod6Y9IuhjBFk7Q/cQTWnbCFywNFAxZRnWIo/asr yygvThoVfWacsy4lKv7D1pViAAh1xMIITkXRHrph02Mi6qgSK9Y+INm2u162XoMHC2vR JYOZpb7OJnqVzq5S6/QCCit4zcu7j1rkG5Det0Pz8931ombo7CAUZoSeep5TV306IirE VX6hkqpl2Mf0cuMc+QM2YEwerOzHzLCTjQGNMMSpbR8vhtVhgyvSx9ld3sZhuI7iMxCL c6Dw== X-Gm-Message-State: ABuFfoiJ7NtZfyPSLFGD+XCdDPJVCPJ3fUG8ZYelOdrGljl40/+4s7wN PC1ZB+HlQ9ucSI8bEoRAtkHga5UelyE8 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-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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;