From patchwork Thu Apr 5 16:35:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 10324977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8E66E60467 for ; Thu, 5 Apr 2018 16:36:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D17E292DD for ; Thu, 5 Apr 2018 16:36:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71E40292F1; Thu, 5 Apr 2018 16:36:00 +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=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BFE6A292DD for ; Thu, 5 Apr 2018 16:35:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eTibTdqMyJiaCDwNvsMZ7svvAtinBEZtEGYnqIw4yxU=; b=D8vwFGJEC7xzl0 KdsIHd9+aZdWJMjrAXw+3P8f6D0kf7Mksmt9r41OXLkSkcdN31K/ZnyTmGgT6HdcLzFGJE98oAHF1 ZN98AiqLgATeyOYWkJD7btS1ukUqfLl27uLlbYrsRKz4Thb8GgUtD8UMNTtZQyCZHWKVKkbWjWGx4 MZXRojMq1Uzysg0MnsSZjhKjwnKIxZsCmNT/REci2kzlFBpu/rLRLRy4X7yFWiJhrHqunuclWFQmH PwM3O3NQAHr80hENCL/P7QtWubaZ+UMJhynI9ncDW+LtMqrPPDlqPIVzf4+TDSTPAqJFxYCI8DwAd NQ7TeYBPdwRRWbi+oKlg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f47rY-0003df-Jp; Thu, 05 Apr 2018 16:35:48 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f47rU-0003bt-17 for linux-arm-kernel@lists.infradead.org; Thu, 05 Apr 2018 16:35:46 +0000 Received: by mail-wr0-x242.google.com with SMTP id l49so29449476wrl.4 for ; Thu, 05 Apr 2018 09:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u+xxCFqa91u464XafP58f+UL/r0t9NnzR9iELCvQx/Y=; b=f3Iof91w8egWmd6R14dyVuyci+cJfGoJw8VSUlOKfyUgN5j2h3XFsSVtEL/sRaPnIV DTDyPAsdrTmQsDCIUwu6teGJ7gcuQWcIOxmzQ9kXRfWBkiQpsNETJP6HKElRnM20NFvC U0U3MXaIAAJm4SVgHJzdHimay8t6AbYJQmE6qp9cxwplvxp+TA3UksykuHIvkd0254Ca 0rUyfRp62HdNWCLA63fKRg1q5rVEZGlSNMXlPfSlWD4vzSqpXTG30VC8U/o+j5DJNTog /J0xdMnOKC1BOy64cAmsuzgZ6OCsbknLT5bKJ7vvZeSMQDLC4snmGoL0PjM9Or4OjtRz jA8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u+xxCFqa91u464XafP58f+UL/r0t9NnzR9iELCvQx/Y=; b=XzNIsMrT1wlGa0u7p5b+PnJJ96DsR1JGk/C7fHoKuFsoWCqmg8IjrN3FWYd2iu2FH9 ivCAbicV46pCWznNGzfjLMhs86FEavdPy6YmsxhrmSvVR7QYY5iy/iMRpkNQX7tIsbVb 5UfSP3E5ts/Lz4NDz9okfijEbybOYDx3nuafh2OmyFWq4AM88kulnU3A8QI2JAzEGDsQ 2kpgI24kmpUrhtUzgTb0WBh5MA37yv4R8Pm7gwbTpsokLP7rIzKKVENTDZh6vLm79E9U BjWHH+DSSia+QouTx6HoiBoi7cd++FEHd+bbgEWo2DOy3Y8ejDZsvLPdqYTRx11450RK gu8Q== X-Gm-Message-State: ALQs6tCtQDBvoLKuIqY3W9nREhYaEsjzRabHqXAKmqVexc4WZlrpaOvv 5y/6323bqxE4KQ2SHVjibndxwaMd X-Google-Smtp-Source: AIpwx48M4svV3LHEKheGiIrHZgcBKYZJBR7jTLYHzXpC60SGYgabBT469h1I+uKWygDqccbj3b3MrA== X-Received: by 10.223.166.161 with SMTP id t30mr2515912wrc.1.1522946127060; Thu, 05 Apr 2018 09:35:27 -0700 (PDT) Received: from debian64.daheim (p200300D5FBC4FEFC0000000000000830.dip0.t-ipconnect.de. [2003:d5:fbc4:fefc::830]) by smtp.gmail.com with ESMTPSA id y101sm3000485wmh.10.2018.04.05.09.35.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Apr 2018 09:35:26 -0700 (PDT) Received: from localhost.daheim ([127.0.0.1] helo=debian64.localnet) by debian64.daheim with esmtp (Exim 4.90_1) (envelope-from ) id 1f47rB-0007de-AN; Thu, 05 Apr 2018 18:35:25 +0200 From: Christian Lamparter To: Bjorn Andersson Subject: Re: [PATCH v2] pinctrl: msm: fix gpio-hog related boot issues Date: Thu, 05 Apr 2018 18:35:24 +0200 Message-ID: <2820412.JxDUeWI2ec@debian64> In-Reply-To: <20180402150447.GH510@tuxbook-pro> References: <20180402121005.10080-1-chunkeey@gmail.com> <20180402150447.GH510@tuxbook-pro> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180405_093544_096714_6B749EBF X-CRM114-Status: GOOD ( 20.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-gpio@vger.kernel.org, linux-arm-msm@vger.kernel.org, Linus Walleij , David Brown , Sven Eckelmann , Andy Gross , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Montag, 2. April 2018 17:04:47 CEST Bjorn Andersson wrote: > On Mon 02 Apr 05:10 PDT 2018, Christian Lamparter wrote: > > diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c > > index 495432f3341b..258fa357d946 100644 > > --- a/drivers/pinctrl/qcom/pinctrl-msm.c > > +++ b/drivers/pinctrl/qcom/pinctrl-msm.c > > @@ -831,11 +831,22 @@ static int msm_gpio_init(struct msm_pinctrl *pctrl) > > return ret; > > } > > > > - ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev), 0, 0, chip->ngpio); > > - if (ret) { > > - dev_err(pctrl->dev, "Failed to add pin range\n"); > > - gpiochip_remove(&pctrl->chip); > > - return ret; > > + if (!is_of_node(pctrl->dev->fwnode)) { > > Afaict this still means that if I boot this kernel with yesterday's dtb > (without gpio-ranges) I will not get any gpios. This isn't okay. Ok, fair point. I drop this chunk. > @Linus, I count 24 callers of gpiochip_add_pin_range(). Is this > suggestion reasonable? > > Can we make gpiochip_add_pin_range() check if there's already a > gpio-range and return ok in some way? Looks like Linus is currently really busy updating the gemini target (a lot of work went into it) for OpenWrt. (Kinda funny, because I do help to maintain the apm821xx and the new ipq40xx target over there.) In any case, I implemented your suggestion and it does look reasonable. The gpiolib already uses the gpio_offset as an ID of some sorts. For now I went with a simple ID value check, but this could be extended to a range/intersection check if necessary. But then again, let's not overengineer it. Comments are welcome, I'll wait around till sometime next week before I post v3. Regards, Christian Acked-by: Laxman Dewangan --- --- diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d66de67ef307..21c0f88e1159 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2013,6 +2013,19 @@ int gpiochip_generic_config(struct gpio_chip *chip, unsigned offset, } EXPORT_SYMBOL_GPL(gpiochip_generic_config); +static struct gpio_pin_range *gpiochip_find_by_id(struct gpio_chip *chip, + unsigned int id) +{ + struct gpio_pin_range *pin_range; + struct gpio_device *gdev = chip->gpiodev; + + list_for_each_entry(pin_range, &gdev->pin_ranges, node) { + if (pin_range->range.id == id) + return pin_range; + } + return NULL; +} + #ifdef CONFIG_PINCTRL /** @@ -2030,6 +2043,20 @@ int gpiochip_add_pingroup_range(struct gpio_chip *chip, struct gpio_device *gdev = chip->gpiodev; int ret; + /* + * look if a GPIO range with the same ID has already been registered. + * For pinctrls that are set up through devicetree, the GPIO Range + * might be already set by the the gpio-ranges property. + * (see Documentation/devicetree/bindings/gpio/gpio.txt) + */ + pin_range = gpiochip_find_by_id(chip, gpio_offset); + if (pin_range) { + chip_dbg(chip, "found existing GPIO range %d->%d - skipping\n", + gpio_offset, + gpio_offset + pin_range->range.npins - 1); + return 0; + } + pin_range = kzalloc(sizeof(*pin_range), GFP_KERNEL); if (!pin_range) { chip_err(chip, "failed to allocate pin ranges\n"); @@ -2083,6 +2110,20 @@ int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, struct gpio_device *gdev = chip->gpiodev; int ret; + /* + * look if a GPIO range with the same ID has already been registered. + * For pinctrls that are set up through devicetree, the GPIO Range + * might be already set by the the gpio-ranges property. + * (see Documentation/devicetree/bindings/gpio/gpio.txt) + */ + pin_range = gpiochip_find_by_id(chip, gpio_offset); + if (pin_range) { + chip_dbg(chip, "found existing GPIO range %d->%d - skipping\n", + gpio_offset, + gpio_offset + pin_range->range.npins - 1); + return 0; + } + pin_range = kzalloc(sizeof(*pin_range), GFP_KERNEL); if (!pin_range) { chip_err(chip, "failed to allocate pin ranges\n");