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: 10416343 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 03C07600CC for ; Mon, 21 May 2018 20:59:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6FCD28A64 for ; Mon, 21 May 2018 20:59:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA97E28A63; Mon, 21 May 2018 20:59:31 +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=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, MAILING_LIST_MULTI 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 555EA28A63 for ; Mon, 21 May 2018 20:59:31 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=gEWqQqx4PwDFqfQp2xyjo85kI9cx2qdM+gbEbZHJ3oI=; b=ThZEhJrgZCNWwOl8FN6t7Rw1JQ RRQgTQ55iLWa0JJkwvyjeg3V0tbbk49Q3IvlrnFB8Abx6X9MxOb0nKROY288We5KvKiGt9iMuAM/8 n78K4NCo53yzhxfavMLNKqkdcjkhCdPWEizb0ch9WvZhHcuDvPzGnTMjllGv3+OxTk7kQ7BOaphyY TqdXsIO54bCLozVtfMGm+UgHR4p+bDBZGwJVVhzprHdWEkcdQam7KyY2/o38wa9JhXL8vHMuzWgGi HxpG6/yYTIdWpNbbsT74CmV7PTt+gXte8xDiBzuE+tljUuCdye8pO4rW8Z5qsPIXqj/LlB69Vgnil OHiLoZhQ==; 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 1fKrtq-0000xw-GX; Mon, 21 May 2018 20:59:22 +0000 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fKrsS-0008PW-6t for linux-arm-kernel@lists.infradead.org; Mon, 21 May 2018 20:58:19 +0000 Received: by mail-wr0-x244.google.com with SMTP id v60-v6so17289542wrc.7 for ; Mon, 21 May 2018 13:57:44 -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=BKLa63aqBZolvLDE6LTeWnmuTNMQ+AYM2wnAoVkEcm1PqxSaRBawBi6dyTeVJ3Kvqd QDBr18piQZ1j+z3ucoT7mmljwebMqWvAKxnwdXhOldA+lWMHvZpiosYnK2I8WxJN+Y06 Q5+CpmlnHPHBwRUtxT8hMYdEDZi/A3hLwTFI4IclrKr1ZTgPYUrskicvlWU+AZ8i0g4g jLCkjWHuKE3pumomJ1Wct8BmFzGmzrMDxJ8/23i3R8nzFJOpbxr+Xx2QlUwl8fNWreJs T7Gzz94SLeras5EP4LtDlMWO9c3xHZZX2xWNcOThhGPMEkj+8JJxjyqha9WuUz1TUDYw Jn2g== X-Gm-Message-State: ALKqPweSWsgd+2kbsN6vj2yi5yB4HQC4x/ePbyQ6aIy6aXvY1w7M1Sxa N7l+V95tt0nkFmJduemn6wu7T983XWQ= 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180521_135756_267734_0B9F4CCD X-CRM114-Status: GOOD ( 20.59 ) 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: Mark Rutland , Stephen Boyd , Linus Walleij , Bjorn Andersson , David Brown , Rob Herring , Sven Eckelmann , Andy Gross MIME-Version: 1.0 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 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,