From patchwork Tue Jun 14 10:03:24 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: 9175407 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 ADF7760772 for ; Tue, 14 Jun 2016 10:05:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EA4F28236 for ; Tue, 14 Jun 2016 10:05:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9347C282DC; Tue, 14 Jun 2016 10:05:35 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4279828236 for ; Tue, 14 Jun 2016 10:05:35 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1bClCT-0001yQ-1g; Tue, 14 Jun 2016 10:04:01 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1bClCP-0001iU-LB for linux-arm-kernel@lists.infradead.org; Tue, 14 Jun 2016 10:03:58 +0000 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 1bClBw-0008SC-VX; Tue, 14 Jun 2016 12:03:28 +0200 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.87) (envelope-from ) id 1bClBu-0004UA-HT; Tue, 14 Jun 2016 12:03:26 +0200 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Grygorii Strashko , Santosh Shilimkar , Kevin Hilman , Linus Walleij , Alexandre Courbot Subject: [PATCH] gpio: omap: make gpio numbering deterministical by using of aliases Date: Tue, 14 Jun 2016 12:03:24 +0200 Message-Id: <1465898604-16294-1-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.8.1 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-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160614_030357_887422_56ED56A6 X-CRM114-Status: GOOD ( 14.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-gpio@vger.kernel.org, linux-omap@vger.kernel.org, kernel@pengutronix.de, 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 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 number 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 --- Hello, if you're happy with this patch I can follow up and add the respective aliases to the device trees. Best regards Uwe drivers/gpio/gpio-omap.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c index b98ede78c9d8..6814245a54aa 100644 --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c @@ -1034,6 +1034,7 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc) static int gpio; int irq_base = 0; int ret; + int gpio_alias_id; /* * REVISIT eventually switch from OMAP-specific gpio structs @@ -1056,6 +1057,17 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc) bank->chip.label = "gpio"; bank->chip.base = 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; + bank->chip.ngpio = bank->width; ret = gpiochip_add_data(&bank->chip, bank);