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: 10324975 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 097AF60467 for ; Thu, 5 Apr 2018 16:35:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED363292DD for ; Thu, 5 Apr 2018 16:35:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1831292F0; Thu, 5 Apr 2018 16:35:34 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF0DC292DD for ; Thu, 5 Apr 2018 16:35:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751332AbeDEQf3 (ORCPT ); Thu, 5 Apr 2018 12:35:29 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:34770 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751259AbeDEQf2 (ORCPT ); Thu, 5 Apr 2018 12:35:28 -0400 Received: by mail-wr0-f194.google.com with SMTP id d17so14065076wre.1; 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=e4FpX9iB2zns/T6+PtnZPEBoqmEi11/Fis7V5iSLF1bdgLz8bsfzM+SwaX10KpXywp wtlZUR4AkllkZu4J4D8yRsDvuO21FviqbRcYiCnCuxiFyy104KTNGWc1w9JQat6Ykrje Y2k5J9eHIeo0fWqy9BydQboqCMa4nO+EniezNbc4ZrOAMFBI45vPEvwtcBHjXk156ZjY zl71XRJCDnD6S1G9b+ceCRMcERV04ZLsivtoe/N4988Y8LpgXwiBtmqcQOqUu5BxDSh4 mz8wNmp42KYWowTFGywK0lJ+a5zE6xor3Jju6o8qbVkcJ8vlGT9Po4IMQIukWIDGYG3s P2fA== X-Gm-Message-State: ALQs6tBPAbY0L/5xoY1jD8b5XCFhsOdP8gvHySQvCCA21MFfu5oyvqkc fjsgBMSOvawihsWrUC9yo8U= 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 Cc: Linus Walleij , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, David Brown , Andy Gross , Sven Eckelmann 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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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 --- --- -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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");