From patchwork Wed Mar 22 17:15:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 9639573 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 00FD7602CB for ; Wed, 22 Mar 2017 17:15:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1A3528478 for ; Wed, 22 Mar 2017 17:15:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E660F28485; Wed, 22 Mar 2017 17:15:56 +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_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 4830528478 for ; Wed, 22 Mar 2017 17:15: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: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:In-Reply-To:References: List-Owner; bh=Gj9yhhgYvWI0dp34af4TCcxJR/y1IED6sfeP0PFitZw=; b=iBO+SaypEJnbMx wAs9BVugKAq5VLQKpGvY0sg003SPgO+kDMrr+7GpePW1py0XQr/nI6m5ME7SFiDB6eldQBHii5k4h Mq4JnR9sDFIFtfxB6qm4HhGWe/2HMlmRZdo5iwoRRVj51C/idlw3KJcBD9Lwquoui5P3GyyweEF/p P9bBRHfEPgMdPDZe5ccKuLKJtAA/ESndHfftxTXoxmwAYPTJ9sX2tlGLzB6sIRBSa7MfDhy9Ez0d8 PkL2GPfvNgHUS+3I0jXyEOZwIXrsgxfvdH61eqPkXptvFx5qPCR3IjYDBfQvaE5Qq/Zp1EqTJSNoA nF4sXWb5cbh0JMmfJU0A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cqjrX-0004Oo-4v; Wed, 22 Mar 2017 17:15:55 +0000 Received: from mx0b-001ae601.pphosted.com ([67.231.152.168]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cqjqi-00024T-ED for linux-arm-kernel@lists.infradead.org; Wed, 22 Mar 2017 17:15:07 +0000 Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2MHEH97007566; Wed, 22 Mar 2017 12:14:39 -0500 Authentication-Results: ppops.net; spf=none smtp.mailfrom=ckeepax@opensource.wolfsonmicro.com Received: from mail3.cirrus.com ([87.246.76.56]) by mx0b-001ae601.pphosted.com with ESMTP id 29b9w033kd-1; Wed, 22 Mar 2017 12:14:39 -0500 Received: from EX17.ad.cirrus.com (ex17.ad.cirrus.com [172.20.9.81]) by mail3.cirrus.com (Postfix) with ESMTP id 71BAB611CE6F; Wed, 22 Mar 2017 12:16:10 -0500 (CDT) Received: from imbe.wolfsonmicro.main (198.61.95.81) by EX17.ad.cirrus.com (172.20.9.81) with Microsoft SMTP Server id 14.3.301.0; Wed, 22 Mar 2017 17:14:38 +0000 Received: from algalon.ad.cirrus.com (algalon.ad.cirrus.com [198.90.223.36]) by imbe.wolfsonmicro.main (8.14.4/8.14.4) with ESMTP id v2MHDvi9017824; Wed, 22 Mar 2017 17:13:57 GMT From: Charles Keepax To: , , Subject: [PATCH v3 1/2] pinctrl: samsung: Register pinctrl before GPIO Date: Wed, 22 Mar 2017 17:15:34 +0000 Message-ID: <1490202935-4708-1-git-send-email-ckeepax@opensource.wolfsonmicro.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703220150 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170322_101504_847816_9DB9DB08 X-CRM114-Status: GOOD ( 15.10 ) 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-samsung-soc@vger.kernel.org, linus.walleij@linaro.org, patches@opensource.wolfsonmicro.com, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, 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 If we request a GPIO hog, then gpiochip_add_data will attempt to request some of its own GPIOs. The driver also uses gpiochip_generic_request which means that for any GPIO request to succeed the pinctrl needs to be registered. Currently however the driver registers the GPIO and then the pinctrl meaning all GPIO hog requests will fail, which then in turn causes the whole driver to fail probe. Fix this up by ensuring we register the pinctrl first. This does require us to manually set the GPIO base for the pinctrl. Fortunately the driver already assigns a fixed GPIO base, in samsung_gpiolib_register, and uses the same calculation it does for the pin_base. Meaning the two will always be the same and allowing us to reuse the pinbase and avoid the issue. Although currently there are no users of GPIO hogs in mainline there are plenty of Samsung based boards that are widely used for development purposes of other hardware. Indeed we hit this issue whilst attaching some additional hardware to an Arndale system. Signed-off-by: Charles Keepax --- Changes since v2: - Squash in fix to set the GPIO base on the pin_bank. drivers/pinctrl/samsung/pinctrl-samsung.c | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c index f9ddba7..5d53370 100644 --- a/drivers/pinctrl/samsung/pinctrl-samsung.c +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c @@ -884,7 +884,7 @@ static int samsung_pinctrl_register(struct platform_device *pdev, pin_bank->grange.id = bank; pin_bank->grange.pin_base = drvdata->pin_base + pin_bank->pin_base; - pin_bank->grange.base = pin_bank->gpio_chip.base; + pin_bank->grange.base = pin_bank->grange.pin_base; pin_bank->grange.npins = pin_bank->gpio_chip.ngpio; pin_bank->grange.gc = &pin_bank->gpio_chip; pinctrl_add_gpio_range(drvdata->pctl_dev, &pin_bank->grange); @@ -893,6 +893,19 @@ static int samsung_pinctrl_register(struct platform_device *pdev, return 0; } +/* unregister the pinctrl interface with the pinctrl subsystem */ +static int samsung_pinctrl_unregister(struct platform_device *pdev, + struct samsung_pinctrl_drv_data *drvdata) +{ + struct samsung_pin_bank *bank = drvdata->pin_banks; + int i; + + for (i = 0; i < drvdata->nr_banks; ++i, ++bank) + pinctrl_remove_gpio_range(drvdata->pctl_dev, &bank->grange); + + return 0; +} + static const struct gpio_chip samsung_gpiolib_chip = { .request = gpiochip_generic_request, .free = gpiochip_generic_free, @@ -917,7 +930,7 @@ static int samsung_gpiolib_register(struct platform_device *pdev, bank->gpio_chip = samsung_gpiolib_chip; gc = &bank->gpio_chip; - gc->base = drvdata->pin_base + bank->pin_base; + gc->base = bank->grange.base; gc->ngpio = bank->nr_pins; gc->parent = &pdev->dev; gc->of_node = bank->of_node; @@ -939,19 +952,6 @@ static int samsung_gpiolib_register(struct platform_device *pdev, return ret; } -/* unregister the gpiolib interface with the gpiolib subsystem */ -static int samsung_gpiolib_unregister(struct platform_device *pdev, - struct samsung_pinctrl_drv_data *drvdata) -{ - struct samsung_pin_bank *bank = drvdata->pin_banks; - int i; - - for (i = 0; i < drvdata->nr_banks; ++i, ++bank) - gpiochip_remove(&bank->gpio_chip); - - return 0; -} - /* retrieve the soc specific data */ static const struct samsung_pin_ctrl * samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d, @@ -1062,13 +1062,13 @@ static int samsung_pinctrl_probe(struct platform_device *pdev) return PTR_ERR(drvdata->retention_ctrl); } - ret = samsung_gpiolib_register(pdev, drvdata); + ret = samsung_pinctrl_register(pdev, drvdata); if (ret) return ret; - ret = samsung_pinctrl_register(pdev, drvdata); + ret = samsung_gpiolib_register(pdev, drvdata); if (ret) { - samsung_gpiolib_unregister(pdev, drvdata); + samsung_pinctrl_unregister(pdev, drvdata); return ret; }