From patchwork Mon May 21 20:57:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 10416331 X-Patchwork-Delegate: agross@codeaurora.org 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 333676053B for ; Mon, 21 May 2018 20:57:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 212F328A60 for ; Mon, 21 May 2018 20:57:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12CF728A62; Mon, 21 May 2018 20:57:53 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 56A7B28A60 for ; Mon, 21 May 2018 20:57:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751523AbeEUU5u (ORCPT ); Mon, 21 May 2018 16:57:50 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:34239 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751214AbeEUU5o (ORCPT ); Mon, 21 May 2018 16:57:44 -0400 Received: by mail-wr0-f194.google.com with SMTP id j1-v6so6340873wrm.1; Mon, 21 May 2018 13:57:43 -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 :in-reply-to:references; bh=BppZUp8Muj/bD7c/+SlZsXKrwKEbkwqAs4P9e67lWTc=; b=E/SrOxlBTQwOl0uceuvAQCYOBoPO8zfA8QY8uDAmUnHVG1AlHMTDV/seQjLXPiMwj6 TObv/psYmkj4APscqhigxZ/CZJh4zmro2MCDp+BbDzIRMG+vHR80Gjpwhq97jhdi4jZ/ ZJJhWrAbhJmffO+LReSJXtc5enDyYmXwSRBPemJ/wk3HlkjHgl7/pNXaN1HMvmC9k0WU bM71HJdANmE6e3sOuyCCRM4ulBRmbPdhLdI3T8UN23K7N//J930ycxCJ5k5k9SOTo0iu UL+hJB+YhVCS/Ko6s+WvIITiGcowPB/RgQBAiyrFFoO9ff9WkkgDl4LWQnCSWQC/fKwl 4TVA== 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:in-reply-to:references; bh=BppZUp8Muj/bD7c/+SlZsXKrwKEbkwqAs4P9e67lWTc=; b=gglrx4h3l6Lhog5goSAnshp6/JOXL2coTaglZppSfPVjXCjVYoG2F1iDKNj8DvaRjM CwACaQ6S1d2hgWegroSipHSG/JtFQYWHUz7Uc/ClaAVGvG/Ir5PlaSHzBSh28Qp0XgWQ ptpazWIbGWo5pTJYvsbRr+ewfgq3uEdLhRLqptguXXuVG6isrzoK0pZZakgjyf82CK76 FhgWCfbBypA3WA+b4Uy0jeezWfI30DxsstDrLKly1y2lAr5JUtHMo9yqnKAodgLqTekX 73GsYNLBGqHJOolklGdxHXguzfQDltvzvJ3/QyjQ4SmlnYL1YDDUWSXCt5gH6xFSGlup v6Xw== X-Gm-Message-State: ALKqPwcfD0dYaFDUCi92Hs0Gvq9LBBTM/df9hNs8l9eJhmLqt5vu8ZDP Bvb53AgmAAdFEHAEcAXAvVk= X-Google-Smtp-Source: AB8JxZqNTjHRoe1+JmMduAs1wftduilLvG1SnMSNmyvkSgHNaeJ63mPd0Jr2aKJp0kFpkBTDCfkaPQ== X-Received: by 2002:adf:b0e2:: with SMTP id j31-v6mr15365616wra.263.1526936262423; Mon, 21 May 2018 13:57:42 -0700 (PDT) Received: from debian64.daheim (p5B0D7D7A.dip0.t-ipconnect.de. [91.13.125.122]) by smtp.gmail.com with ESMTPSA id h8-v6sm11275007wmc.16.2018.05.21.13.57.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 May 2018 13:57:41 -0700 (PDT) Received: from chuck by debian64.daheim with local (Exim 4.91) (envelope-from ) id 1fKrsB-00064u-I4; Mon, 21 May 2018 22:57:39 +0200 From: Christian Lamparter To: linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org Cc: Bjorn Andersson , Linus Walleij , Stephen Boyd , David Brown , Rob Herring , Mark Rutland , Andy Gross , Sven Eckelmann Subject: [PATCH v5 2/4] pinctrl: msm: fix gpio-hog related boot issues Date: Mon, 21 May 2018 22:57:37 +0200 Message-Id: <270904bcbf03a6b6ac3150f4a7daa15aa7e97586.1526935804.git.chunkeey@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <910e5a85a6a8020069996e2ff397c93e9c5fe18c.1526935804.git.chunkeey@gmail.com> References: <910e5a85a6a8020069996e2ff397c93e9c5fe18c.1526935804.git.chunkeey@gmail.com> In-Reply-To: <910e5a85a6a8020069996e2ff397c93e9c5fe18c.1526935804.git.chunkeey@gmail.com> References: <910e5a85a6a8020069996e2ff397c93e9c5fe18c.1526935804.git.chunkeey@gmail.com> 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 Sven Eckelmann reported an issue with the current IPQ4019 pinctrl. Setting up any gpio-hog in the device-tree for his device would "kill the bootup completely": | [ 0.477838] msm_serial 78af000.serial: could not find pctldev for node /soc/pinctrl@1000000/serial_pinmux, deferring probe | [ 0.499828] spi_qup 78b5000.spi: could not find pctldev for node /soc/pinctrl@1000000/spi_0_pinmux, deferring probe | [ 1.298883] requesting hog GPIO enable USB2 power (chip 1000000.pinctrl, offset 58) failed, -517 | [ 1.299609] gpiochip_add_data: GPIOs 0..99 (1000000.pinctrl) failed to register | [ 1.308589] ipq4019-pinctrl 1000000.pinctrl: Failed register gpiochip | [ 1.316586] msm_serial 78af000.serial: could not find pctldev for node /soc/pinctrl@1000000/serial_pinmux, deferring probe | [ 1.322415] spi_qup 78b5000.spi: could not find pctldev for node /soc/pinctrl@1000000/spi_0_pinmux, deferri This was also verified on a RT-AC58U (IPQ4018) which would no longer boot, if a gpio-hog was specified. (Tried forcing the USB LED PIN (GPIO0) to high.). The problem is that Pinctrl+GPIO registration is currently peformed in the following order in pinctrl-msm.c: 1. pinctrl_register() 2. gpiochip_add() 3. gpiochip_add_pin_range() The actual error code -517 == -EPROBE_DEFER is coming from pinctrl_get_device_gpio_range(), which is called through: gpiochip_add of_gpiochip_add of_gpiochip_scan_gpios gpiod_hog gpiochip_request_own_desc __gpiod_request chip->request gpiochip_generic_request pinctrl_gpio_request pinctrl_get_device_gpio_range pinctrl_get_device_gpio_range() is unable to find any valid pin ranges, since nothing has been added to the pinctrldev_list yet. so the range can't be found, and the operation fails with -EPROBE_DEFER. This patch fixes the issue by adding the "gpio-ranges" property to the pinctrl device node of all upstream Qcom SoC. The pin ranges are then added by the gpio core. In order to remain compatible with older, existing DTs (and ACPI) a check for the "gpio-ranges" property has been added to msm_gpio_init(). This prevents the driver of adding the same entry to the pinctrldev_list twice. Reported-by: Sven Eckelmann Tested-by: Sven Eckelmann [ipq4019] Reviewed-by: Bjorn Andersson Signed-off-by: Christian Lamparter --- drivers/pinctrl/qcom/pinctrl-msm.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c index ad80a17c9990..ace2bfbf1bee 100644 --- a/drivers/pinctrl/qcom/pinctrl-msm.c +++ b/drivers/pinctrl/qcom/pinctrl-msm.c @@ -890,11 +890,24 @@ 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; + /* + * For DeviceTree-supported systems, the gpio core checks the + * pinctrl's device node for the "gpio-ranges" property. + * If it is present, it takes care of adding the pin ranges + * for the driver. In this case the driver can skip ahead. + * + * In order to remain compatible with older, existing DeviceTree + * files which don't set the "gpio-ranges" property or systems that + * utilize ACPI the driver has to call gpiochip_add_pin_range(). + */ + if (!of_property_read_bool(pctrl->dev->of_node, "gpio-ranges")) { + 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; + } } ret = gpiochip_irqchip_add(chip,