Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp2806270ima; Mon, 22 Oct 2018 16:41:17 -0700 (PDT) X-Google-Smtp-Source: ACcGV63PMLHZdTzpNxTLslverP08f0pwIiHjfuYaIImLqpVnbOinlF7QH2JzSQmC3TzlMDkABry1 X-Received: by 2002:a62:798e:: with SMTP id u136-v6mr46491301pfc.95.1540251677660; Mon, 22 Oct 2018 16:41:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540251677; cv=none; d=google.com; s=arc-20160816; b=LcDyghMm2wmKMRk1P0B63mUnY09K+sEOGUZjrbZQ8wqVx5mq5Z4k+2m6DLdSS5X00N 8rlqmbWbhGd1LVWWEfnCedEsy5LO9NLb0wkhSDN5RcS1aYIqVA6KhXVr8Ag6b8FjqGvN anKvH4GS0aofQkO8pQkuCx+DFRwEL89NRIy3zIR7TQDkd/+o67SMTrHVVHa45w9pD0kS CASiYBW+AvcRSXmtaYK6BsrUd9R1gZdzm0T+VP8eQEPI2MbygW5DlcB1kK9TPk8kOLQC QyMmwa7ndHeLM4VboaEHKHUuSbmkL5nXFom6GL/9oVTDuhN0y2sgk/mEwnSMK3n8JANO p1qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jWNsEhGTVNZADfIpa9vpBr1MhvmkhQxt6lUoK5SXwpw=; b=iHDVUQHY5aU8G07jrl3Qo3esgUtZrl0JNg+D/so6oBoY3ePT1VKxyyp6yxwtcbF/H9 JlEnW9f2AR/DIgFpqpMcTbno1yxJes/NBUOKp+UdHXHxHJq+x7eNEpQlm2Pp2vPH8Uo9 s82qkD4AsQH+Pz+OH05PKlgBe4NnBiS7LLjrMWreiWwn7HyaQwutmBwnQzkbzG6wUxB/ US4Us7n40soEEIAaO4xrsdHtLuXO3xU+8y6pMowxPF7cfYXR4c08Fz6/NqAkrdCS3BWI fEwfS/vluKflh3QQF1eYxi3aT8Nj4Pa8EBfH7T4tu7m5RjAB03omxnyzmlM/GaChZ9Ab Y+EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=BIEmjcqK; 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 y11-v6si33454794pgj.195.2018.10.22.16.41.01; Mon, 22 Oct 2018 16:41:17 -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=BIEmjcqK; 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 S1726743AbeJWH4Q (ORCPT + 99 others); Tue, 23 Oct 2018 03:56:16 -0400 Received: from mail-yw1-f68.google.com ([209.85.161.68]:45932 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725799AbeJWH4Q (ORCPT ); Tue, 23 Oct 2018 03:56:16 -0400 Received: by mail-yw1-f68.google.com with SMTP id i185-v6so3018214ywa.12 for ; Mon, 22 Oct 2018 16:35:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jWNsEhGTVNZADfIpa9vpBr1MhvmkhQxt6lUoK5SXwpw=; b=BIEmjcqKjeJeT7J7o4As0c1Y0i4lIYb2hEMji/xb6kiFg+t3YK9j4wHojg/3O8A68V 0fIPT8Ql0yz4eFQLKXRhsdeFK6/kVCpEA9Ocvk5lNU90wLXLxA9Jd4zJwiP7AZBBJXTt uCKMVdi/n/5QRZB2xbZqQmS8Cr/ktJmQlnQ74T/79k0YGFERerPk37es9niipxLg1aqw c1POWNgBPrc1j+/w/zdGlamYtPcbL5OlYRPB6vpfz2HQ50M1QjNBjalOdPx6ixL9pbd/ eA1zwjqc3A9EE26v+LjvmTwE68uPNqJ/jD+8PO06AkTKUo5q/EmEQnc//F1hspBembQU XMEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jWNsEhGTVNZADfIpa9vpBr1MhvmkhQxt6lUoK5SXwpw=; b=uX4upCSNm5p9DF6/HmTBlhPwyQHefnUoPao+KKxOACvwTBecftZ+xC5ny7CAeGw+m4 r3TX1g1huHG+MTMh2WslgLONsvveuJgNih2ayghoK3cFcTGQgYDkKeZZpftjxONWDZsO ErO54IqL87TDnPUhWddvRi0FO8JtRcnKPOu4yYpxJ/zU7rL2jOIDPVUS0P6/EeTMABgJ ae1G805DBzoCeebbKlT7qCVEVV63++hBuW7oYfQBHoPaeN4r+gbCw3i/I7EQZ7YX1wJF Sr9jqHyIQ0gefX7FUo8eTG2I/n4GJxu3V0IzCDJ6bODksfbcHveEke7Y4mNdzCcz8CtG 3l+w== X-Gm-Message-State: ABuFfohbg40Bs3OvEWPSGr/4XJ/Moa9mJEFoV0xHMBDHFqPxvRALs6lW 6yG9v7zKJB1hKC0HQSnt9JnN+oL3jEC5DW3ZMw5qeA== X-Received: by 2002:a81:3c15:: with SMTP id j21-v6mr5157405ywa.119.1540251335270; Mon, 22 Oct 2018 16:35:35 -0700 (PDT) MIME-Version: 1.0 References: <20181018215101.169847-1-rajatja@google.com> In-Reply-To: From: Rajat Jain Date: Mon, 22 Oct 2018 16:34:55 -0700 Message-ID: Subject: Re: [PATCH] mmc: sdhci-pci: Try "cd" for card-detect lookup before using NULL To: Andy Shevchenko Cc: "Hunter, Adrian" , 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 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 Hi Andy, Thanks for your review. On Fri, Oct 19, 2018 at 2:13 AM Andy Shevchenko wrote: > > On Fri, Oct 19, 2018 at 12:53 AM Rajat Jain wrote: > > > > 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) > > We have a Link tag for such references. > > > 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. > > card detect is a right term. > > > 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 > > cd-gpios (gpio suffix is a legacy). > > > 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 > > _DSD > > > a successful lookup). > > This is incorrect. _DSD for GPIOs without any accompanying _CRS > doesn't make any sense. > > > 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") > > 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. > > _DSD > > > > > 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 > > _DSD > fairly I can fix the commit log to take care of all your review comments. > > > across other users of this API (other MMC host controller drivers). > > > 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); > > Yes. > > > + if (ret && ret != -EPROBE_DEFER) > > + ret = mmc_gpiod_request_cd(host->mmc, NULL, > > + slot->cd_idx, > > + slot->cd_override_level, > > + 0, NULL); > > And no. Instead of this part you need to provide an ACPI GPIO mapping table. Sure, I am willing to do so, and I tried earlier too. However, certain doubts arose in my mind when I tried that and I posted my questions earlier (https://lkml.org/lkml/2018/9/28/507) but couldn't elicit any response. Unfortunately I still do not have answers. My primary questions are: 1) - It seems that 1 SDHCI device may support multiple slots (looking at the code). It is not clear to me if they could share card detect interrupts, or should have separate ones? Also, the driver may not really know? So should I add 1 or two pins using the devm_acpi_dev_add_driver_gpios(). Is some one familiar with SDHC driver can answer these questions, it shall be great. 2) I'm not really sure what should I set "active_low" to? Isn't this something that should be specified by platform / ACPI too, and driver should just be able to say say choose whatever the ACPI says? struct acpi_gpio_params { unsigned int crs_entry_index; unsigned int line_index; bool active_low; }; Since I do not understand the above two issues, and thus I chose the safest path and not disturb the current code so as not to cause any regressions. Please let me know, and I'm happy to re-spin my patch. Thanks, Rajat > > See examples, like > net/rfkill/rfkill-gpio.c > > (look for acpi_rfkill_default_gpios) > > > if (ret == -EPROBE_DEFER) > > goto remove; > > -- > With Best Regards, > Andy Shevchenko