From patchwork Fri Oct 30 16:33:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 7528141 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EF4319F399 for ; Fri, 30 Oct 2015 16:34:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DAA1520732 for ; Fri, 30 Oct 2015 16:34:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B078920737 for ; Fri, 30 Oct 2015 16:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752472AbbJ3Qdr (ORCPT ); Fri, 30 Oct 2015 12:33:47 -0400 Received: from mail-qg0-f47.google.com ([209.85.192.47]:34751 "EHLO mail-qg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754016AbbJ3Qdn (ORCPT ); Fri, 30 Oct 2015 12:33:43 -0400 Received: by qgem9 with SMTP id m9so65715612qge.1; Fri, 30 Oct 2015 09:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=be3B7/g8zgz2zVbWHJdjo4bCcOLXRVCkV0b7qf/YXME=; b=nWq34XhXquBW8IiILL2MDM+fMIvJd12FP2R7Cb4kBkMmLoOoeZiwVIiUygrqqJoGA5 v8MCY5rqDx7hainZIqdOnKaKoNPQlwHK4ebig3GwB5VSpHKartrhXxC6OcYU5JOQqkTr 6goaS1rEvcTEw5+YloJ8oFy5U9yeNIpl1KE9cCG2wXKRiXmRH4U/sa48mnehw50OwZOF rkbgsyDr4OndosP9CWdBxgyByS4+SqsWxxc6Zzc/O2AkuVENFh8oJx+yahl75o3lOSBN MKWNVNaSMM+8a19CaevnNk5g7eL9OOFAbtVFThhtoJA+Y4XG2q+aWrX3ui4Smsry5Po6 QChw== X-Received: by 10.140.216.213 with SMTP id m204mr11796762qhb.34.1446222822949; Fri, 30 Oct 2015 09:33:42 -0700 (PDT) Received: from localhost ([64.88.227.134]) by smtp.gmail.com with ESMTPSA id 23sm2793545qhy.6.2015.10.30.09.33.40 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 30 Oct 2015 09:33:41 -0700 (PDT) Date: Fri, 30 Oct 2015 09:33:28 -0700 From: Dmitry Torokhov To: "mika.westerberg@linux.intel.com" Cc: "Tirdea, Irina" , Bastien Nocera , Aleksei Mamlin , Karsten Merker , "linux-input@vger.kernel.org" , Mark Rutland , "Purdila, Octavian" , "linux-kernel@vger.kernel.org" , "devicetree@vger.kernel.org" , "Dolca, Robert" Subject: Re: [PATCH v9 2/9] Input: goodix - reset device at init Message-ID: <20151030163328.GA17589@dtor-pixel> References: <20151012164819.GA4010@dtor-ws> <1F3AC3675D538145B1661F571FE1805F2F0FE432@irsmsx105.ger.corp.intel.com> <20151013070824.GA22304@dtor-ws> <1F3AC3675D538145B1661F571FE1805F2F0FE683@irsmsx105.ger.corp.intel.com> <20151013100724.GG1492@lahna.fi.intel.com> <20151014062303.GC20406@dtor-ws> <20151014111820.GV1492@lahna.fi.intel.com> <20151014134403.GA25691@lahna.fi.intel.com> <1F3AC3675D538145B1661F571FE1805F2F101AC0@irsmsx105.ger.corp.intel.com> <20151019145239.GA1526@lahna.fi.intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20151019145239.GA1526@lahna.fi.intel.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Oct 19, 2015 at 05:52:39PM +0300, mika.westerberg@linux.intel.com wrote: > On Mon, Oct 19, 2015 at 02:32:24PM +0000, Tirdea, Irina wrote: > > > > > > > -----Original Message----- > > > From: linux-input-owner@vger.kernel.org [mailto:linux-input-owner@vger.kernel.org] On Behalf Of > > > mika.westerberg@linux.intel.com > > > Sent: 14 October, 2015 16:44 > > > To: Dmitry Torokhov > > > Cc: Tirdea, Irina; Bastien Nocera; Aleksei Mamlin; Karsten Merker; linux-input@vger.kernel.org; Mark Rutland; Purdila, Octavian; linux- > > > kernel@vger.kernel.org; devicetree@vger.kernel.org > > > Subject: Re: [PATCH v9 2/9] Input: goodix - reset device at init > > > > > > On Wed, Oct 14, 2015 at 02:18:20PM +0300, mika.westerberg@linux.intel.com wrote: > > > > On Tue, Oct 13, 2015 at 11:23:03PM -0700, Dmitry Torokhov wrote: > > > > > I understand why one might use acpi_dev_add_driver_gpios() to augment > > > > > data in ACPI, however here we have completely different issue: driver > > > > > that expects named gpios gets returned gpio that has nothing to do with > > > > > what it requested, because gpiolib acpi code always falls back to > > > > > unnamed gpio if it does not find named gpio. That can be acceptable if > > > > > driver uses the same con_id for all requests to gpiolib, but is not > > > > > working when driver supplies different con_ids. > > > > > > > > Right, the ACPI fallback ignores con_id completely and uses only the > > > > index. > > > > > > > > AFAIK there is only one driver using ACPI _CRS index method: > > > > sdhci-[acpi|pci].c. If we can convert that to use acpi_dev_add_driver_gpios() > > > > to feed names for card detection GPIOs, I think we can remove the > > > > fallback alltogether in favor of named GPIOs for ACPI. > > > > > > Nah, there seems to be several drivers relying on this already :-/ > > > > Would it be possible to add an optional parameter to the GPIO API > > to specify whether we want to fall back to indexed GPIOs for ACPI? > > I don't think it's a good idea to add ACPI specifics to generic APIs. > > I went through ACPI enabled drivers calling GPIO APIs and majority of > them are doing this: > > static int stk8312_gpio_probe(struct i2c_client *client) > { > struct device *dev; > struct gpio_desc *gpio; > int ret; > > if (!client) > return -EINVAL; > > dev = &client->dev; > > /* data ready gpio interrupt pin */ > gpio = devm_gpiod_get_index(dev, STK8312_GPIO, 0, GPIOD_IN); > if (IS_ERR(gpio)) { > dev_err(dev, "acpi gpio get index failed\n"); > return PTR_ERR(gpio); > } > > ret = gpiod_to_irq(gpio); > dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); > > return ret; > } > > We can drop all this because I2C core already handles GpioInt -> interrupt > number translation. > > Few drivers are doing something more complex but I think we can still convert > them to use acpi_dev_add_driver_gpios() and eventually get rid of the whole > _CRS index lookup. cpi_dev_add_driver_gpios() does not really help with generic drivers (unless we keep adding more and more board specific data to them). How about we keep track of names used and only allow conversion for the first name used, like in the patch below? diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 5db3445..4ae5447 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1738,6 +1738,45 @@ static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, return desc; } +struct acpi_gpio_lookup { + struct list_head node; + struct device *dev; + const char *con_id; +}; + +static DEFINE_MUTEX(acpi_gpio_lookup_lock); +static LIST_HEAD(acpi_gpio_lookup_list); + +static bool acpi_can_fallback_crs(struct device *dev, const char *con_id) +{ + struct acpi_gpio_lookup *l, *lookup = NULL; + + mutex_lock(&acpi_gpio_lookup_lock); + + list_for_each_entry(l, &acpi_gpio_lookup_list, node) { + if (l->dev == dev) { + lookup = l; + break; + } + } + + if (!lookup) { + lookup = kmalloc(sizeof(*lookup), GFP_KERNEL); + if (lookup) { + lookup->dev = dev; + lookup->con_id = con_id; + list_add_tail(&lookup->node, &acpi_gpio_lookup_list); + } + } + + mutex_lock(&acpi_gpio_lookup_lock); + + return lookup && + ((!lookup->con_id && !con_id) || + (lookup->con_id && con_id && + strcmp(lookup->con_id, con_id) == 0)); +} + static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id, unsigned int idx, enum gpio_lookup_flags *flags) @@ -1765,7 +1804,8 @@ static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id, /* Then from plain _CRS GPIOs */ if (IS_ERR(desc)) { - desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info); + if (acpi_can_fallback_crs(dev, con_id)) + desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info); if (IS_ERR(desc)) return desc; }