From patchwork Tue Oct 25 01:47:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 79111 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp2875936qge; Mon, 24 Oct 2016 18:45:56 -0700 (PDT) X-Received: by 10.99.244.18 with SMTP id g18mr28632068pgi.129.1477359956576; Mon, 24 Oct 2016 18:45:56 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8si6336048pao.287.2016.10.24.18.45.56; Mon, 24 Oct 2016 18:45:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758075AbcJYBpz (ORCPT + 4 others); Mon, 24 Oct 2016 21:45:55 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:57959 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756439AbcJYBpy (ORCPT ); Mon, 24 Oct 2016 21:45:54 -0400 Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-07.nifty.com with ESMTP id u9P1jKXP021399; Tue, 25 Oct 2016 10:45:20 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com u9P1jKXP021399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1477359921; bh=slvh90UWejRcCMxCS1aP04fxhpSd+PPpysk4kKvrDJQ=; h=From:To:Cc:Subject:Date:From; b=JxZnmIsp+D2ikVgR6WL7wUmWlnqJkKk06QBU0dL4PNesJds3glMmDwXCMseMP6opp sGMjRtyy6XDdIzDuRfCqUL48NA3R11aq/n0T4pC5ShwWYz7MN3zVAxJPBoIJ2B1T2m q+zS50m7nF4alV1FxhDu/EZXyqTMy57JetZRiIR7u/3jh1ovC+5jnxIsQm+WbL+5kb OWAMRNIVJ71657Z8owD6cDfSuH/BkcrnL9m80Ekdldzb+ANhHs+/ZBCt3750FUHCaz IBg7OAF/f6BbcArthga+4IoCJfIv+FfuNKZIzSMkUHOkh/WA54vOeOYhU1ZHwmBkh5 N05HlQC26g9Sw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-gpio@vger.kernel.org Cc: Linus Walleij , Vladimir Zapolskiy , Alexandre Courbot , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2] gpio: of: fix GPIO drivers with multiple gpio_chip for a single node Date: Tue, 25 Oct 2016 10:47:44 +0900 Message-Id: <1477360064-6644-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Sylvain Lemieux reports the LPC32xx GPIO driver is broken since commit 762c2e46c059 ("gpio: of: remove of_gpiochip_and_xlate() and struct gg_data"). Probably, gpio-etraxfs.c and gpio-davinci.c are broken too. Those drivers register multiple gpio_chip that are associated to a single OF node, and their own .of_xlate() checks if the passed gpio_chip is valid. Now, the problem is of_find_gpiochip_by_node() returns the first gpio_chip found to match the given node. So, .of_xlate() fails, except for the first GPIO bank. Reverting the commit could be a solution, but I do not want to go back to the mess of struct gg_data. Another solution here is to take the match by a node pointer and the success of .of_xlate(). It is a bit clumsy to call .of_xlate twice; for gpio_chip matching and for really getting the gpio_desc index. Perhaps, our long-term goal might be to convert the drivers to single chip registration, but this commit will solve the problem until then. Fixes: 762c2e46c059 ("gpio: of: remove of_gpiochip_and_xlate() and struct gg_data") Signed-off-by: Masahiro Yamada Reported-by: Sylvain Lemieux Tested-by: David Lechner --- Changes in v2: - correcton pointed out by Sylvain: chip->of_xlate(chip, gpiospec, NULL) >= 0 drivers/gpio/gpiolib-of.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index ecad3f0..193f15d 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -26,14 +26,18 @@ #include "gpiolib.h" -static int of_gpiochip_match_node(struct gpio_chip *chip, void *data) +static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data) { - return chip->gpiodev->dev.of_node == data; + struct of_phandle_args *gpiospec = data; + + return chip->gpiodev->dev.of_node == gpiospec->np && + chip->of_xlate(chip, gpiospec, NULL) >= 0; } -static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np) +static struct gpio_chip *of_find_gpiochip_by_xlate( + struct of_phandle_args *gpiospec) { - return gpiochip_find(np, of_gpiochip_match_node); + return gpiochip_find(gpiospec, of_gpiochip_match_node_and_xlate); } static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, @@ -79,7 +83,7 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, return ERR_PTR(ret); } - chip = of_find_gpiochip_by_node(gpiospec.np); + chip = of_find_gpiochip_by_xlate(&gpiospec); if (!chip) { desc = ERR_PTR(-EPROBE_DEFER); goto out;