Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp3955885imd; Mon, 29 Oct 2018 15:17:52 -0700 (PDT) X-Google-Smtp-Source: AJdET5dtOD9W9ERE6DvphakSB+IxMSjibxm6H06el4ymHD4uqxt4aomhRssrMGUuIrNrL3Bsxh2e X-Received: by 2002:a17:902:3041:: with SMTP id u59-v6mr15377820plb.279.1540851472577; Mon, 29 Oct 2018 15:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540851472; cv=none; d=google.com; s=arc-20160816; b=pMgZWiZtjTu8BQp2R48LfroMgrrtLZJx4+/g2heWxtcVg7Ui6kQc8pcbFseaoDALyc 8+x8It/aTi7t7V8IkDGrp5dgb9bM97YET1MP1nMqCQMXJ9nnHGQUDc7wzC6j4YVie6R0 RLXJwtNHoB6bPNE2dNn6INMfTk21ez727GooheSaCq9BSccthrYAOFvNIqZ2XsMCDTQG KNzIh5ysLfv8lJHCDe6YRTucZBpvKSLMW/hREeUdJlIPwwwrvbixZFUdCGjy2WaSVloH z4eRNoL0imIDuoo1bjpe3O2RoHoQdfKVCQ2iAFuKct9UwzL4h/HD3ZYaH2pfCl55LT0p k3tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=v2rMXvzKWECS79zyMLwtUWxdg5/xyv6bQsMHck8PeHs=; b=ZqPW11Oik5vzI0IuVYx2ZIBe1PwN9ykkLR9+q5IWls2fscmYimmNTmbQbrjSn+HtCZ s4I9XPiLWxqvitQjCIYp6I7sugZ+/rsWnpPgYzWt1g+5H9RoGW5f5WmsVG4HIqK4c5AY vscxAinMFpGu76m0FOf98OMZGedat2G4bzPGXurXrX3ekpQOjVg997We+PcfTuEnin6G w3eVQVrfJjNn74dg/2jRfZ3EGv82Sr8UTimgyNZfYN2MadS3YZXXRQkYZoNnKlBivOOZ vxkrQ/vRbtjcYHeDtHTMCK7lY8Y2QOfiEUQyBhNgaEAyXwsSPkn9TtuVMto8ldpMEQJ9 EtLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LUCJ4X6o; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q17-v6si19968500pge.215.2018.10.29.15.17.36; Mon, 29 Oct 2018 15:17:52 -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=@google.com header.s=20161025 header.b=LUCJ4X6o; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727946AbeJ3HHp (ORCPT + 99 others); Tue, 30 Oct 2018 03:07:45 -0400 Received: from mail-ot1-f74.google.com ([209.85.210.74]:35885 "EHLO mail-ot1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727501AbeJ3HHp (ORCPT ); Tue, 30 Oct 2018 03:07:45 -0400 Received: by mail-ot1-f74.google.com with SMTP id v95so1143532ota.3 for ; Mon, 29 Oct 2018 15:17:06 -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=v2rMXvzKWECS79zyMLwtUWxdg5/xyv6bQsMHck8PeHs=; b=LUCJ4X6onUxUt+WiTRlTWYzC2I5Qs7dVa42ShD2nZxYWJSLPs9VeRT0iXu6rbPPmre qYEDlYXyyIk4zJTU/u7sMPSmX+Iau0sMeoXPV1EwFkfHExPObyFVY+ySelIRTInAASL4 Urg8zM/rexr8FgHKuI1D3e2sSXn0ValX4gAjS/awKJ2Vfd7a3CI/Q5H60Z75cTPTSUx/ 1Q90nK6Tu+zwTlH/8jzH6hWQV5j/KhQq3jPVQLidwTUN2KM3Y/se4EjtdrCf7W6BFbNq wvKGretz1Gu4nBJi7sdj8JxxgtoZIGpR0LlSk3yJ5VUqCnAxzjiz4QISLhFybbTUNrlG tO2A== 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=v2rMXvzKWECS79zyMLwtUWxdg5/xyv6bQsMHck8PeHs=; b=MVc/5fyWOVZd0psjGH5WDETPHwV6AHEqMnB3pHxNX5VscrgKtkGcgjSq4sVCL2EcHf WSXPZeFGuXUDIxSdvBw0GrsUCpzdcSBXbBmzQ0nPWBfOniZDEEctDAGfRTeJO2kpJmCP 7FThUkKQG2AhnSApAPLdp+Mbos45dL6Igz7kXh10D2ZBzmDIoXFDLeOMSskUdnLCLc0b lpPZ/20BX5tWxosrdqM/aiX7hHHvIHLUJM4VUVU+l1IGr/TQx2QK+cg14GffNi8DgqeB 5xKXjGmMGx9mlBFa7lIDFdLDCmycMwH/NWz8SqlZsyAGKyXnCaGcs4ibFa5agNXBTAqJ yWiQ== X-Gm-Message-State: AGRZ1gIQyJNZcCG1SqpSn+1AhaACGRqYp9dCNcoGbQz/RSL3fZuKY8wR MUGxU2hAfFcxrfXBXXBAdv3cM+ZF7LTZ X-Received: by 2002:a9d:6552:: with SMTP id q18mr11827520otl.37.1540851425913; Mon, 29 Oct 2018 15:17:05 -0700 (PDT) Date: Mon, 29 Oct 2018 15:17:01 -0700 In-Reply-To: Message-Id: <20181029221701.51376-1-rajatja@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog Subject: [PATCH v2] mmc: sdhci-pci: Try "cd" for card-detect lookup before using NULL From: Rajat Jain To: adrian.hunter@intel.com, Ulf Hansson , linux-mmc@vger.kernel.org, Linus Walleij , Rajat Jain , Linux Kernel Mailing List , Mika Westerberg , Andy Shevchenko , Dmitry Torokhov , linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, Andy Shevchenko Cc: Rajat Jain Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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: The mmc core provides the mmc_gpiod_request_cd() API to let host drivers request the gpio descriptor for the "card 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-gpios"/"cd-gpio") in _DSD (which internally points 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 (for index based lookup) and _DSD entries (for string based 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-gpios") * 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" appears to be fairly consistent across other users of this API (other MMC host controller drivers). Link: https://lkml.org/lkml/2018/9/25/1113 Signed-off-by: Rajat Jain --- v2: Fix the commit log to take care of Andy's comments. 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; -- 2.19.1.568.g152ad8e336-goog