From patchwork Tue Jun 14 18:57:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 9176583 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 481BA60868 for ; Tue, 14 Jun 2016 18:57:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 30DE32824A for ; Tue, 14 Jun 2016 18:57:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 256BD28306; Tue, 14 Jun 2016 18:57:57 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 7E1542824A for ; Tue, 14 Jun 2016 18:57:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932598AbcFNS5n (ORCPT ); Tue, 14 Jun 2016 14:57:43 -0400 Received: from metis.ext.4.pengutronix.de ([92.198.50.35]:41920 "EHLO metis.ext.4.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932575AbcFNS5m (ORCPT ); Tue, 14 Jun 2016 14:57:42 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1bCtWb-0002MA-5s; Tue, 14 Jun 2016 20:57:21 +0200 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.87) (envelope-from ) id 1bCtWZ-0004wI-5S; Tue, 14 Jun 2016 20:57:19 +0200 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Grygorii Strashko , Santosh Shilimkar , Kevin Hilman , Linus Walleij , Alexandre Courbot Cc: linux-omap@vger.kernel.org, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de Subject: [PATCH 1/2 v2] gpio: omap: make gpio numbering deterministical by using of aliases Date: Tue, 14 Jun 2016 20:57:11 +0200 Message-Id: <1465930632-18941-2-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1465930632-18941-1-git-send-email-u.kleine-koenig@pengutronix.de> References: <1465930632-18941-1-git-send-email-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-omap@vger.kernel.org Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Traditionally the n-th gpio device probed by the omap gpio driver got the gpio number range [n*32 .. n*32+31]. When order of the devices probed by the driver changes (which can happen already now when some devices have a pinctrl and so the first probe attempt returns -ENODEV) the numbering changes. To ensure a deterministical numbering use of_alias_get_id to determine the base for a given device. If no respective alias exists fall back to the traditional numbering. For the unusual case where only a part of the gpio devices have a matching alias some of them might fail to probe. But if none of them has an alias or all, there is no conflict which should be good enough to maintain backward compatibility. Signed-off-by: Uwe Kleine-König Acked-by: Tony Lindgren Reviewed-by: Grygorii Strashko --- drivers/gpio/gpio-omap.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c index b98ede78c9d8..4d91792e7266 100644 --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c @@ -1053,9 +1053,26 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc) bank->chip.parent = &omap_mpuio_device.dev; bank->chip.base = OMAP_MPUIO(0); } else { + int gpio_alias_id __maybe_unused; + bank->chip.label = "gpio"; - bank->chip.base = gpio; + +#if defined(CONFIG_OF_GPIO) + /* + * Traditionally the base is given out in first-come-first-serve + * order. This might shuffle the numbering of gpios if the + * probe order changes. So make the base deterministical if the + * device tree specifies alias ids. + */ + gpio_alias_id = of_alias_get_id(bank->chip.of_node, "gpio"); + if (gpio_alias_id >= 0) + bank->chip.base = bank->width * gpio_alias_id; + else +#endif + bank->chip.base = gpio; } + + bank->chip.ngpio = bank->width; ret = gpiochip_add_data(&bank->chip, bank);