From patchwork Fri Apr 10 14:22:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Pargmann X-Patchwork-Id: 6197441 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 614D09F2E9 for ; Fri, 10 Apr 2015 14:47:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6BE17203EB for ; Fri, 10 Apr 2015 14:47:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 68C6B203DB for ; Fri, 10 Apr 2015 14:47:48 +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 1YgaBB-0007Lm-D8; Fri, 10 Apr 2015 14:45:09 +0000 Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YgaB2-0006yI-2L for linux-arm-kernel@lists.infradead.org; Fri, 10 Apr 2015 14:45:01 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1YgaAW-0000ww-7o; Fri, 10 Apr 2015 16:44:28 +0200 Received: from mpa by dude.hi.pengutronix.de with local (Exim 4.84) (envelope-from ) id 1YgZpU-00010z-R5; Fri, 10 Apr 2015 16:22:44 +0200 From: Markus Pargmann To: Linus Walleij Subject: [PATCH v2] pinctrl: imx: Allow parsing DT without function nodes Date: Fri, 10 Apr 2015 16:22:38 +0200 Message-Id: <1428675758-15335-1-git-send-email-mpa@pengutronix.de> X-Mailer: git-send-email 2.1.4 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: mpa@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-20150410_074500_349586_90E222A5 X-CRM114-Status: GOOD ( 19.13 ) X-Spam-Score: -0.0 (/) Cc: Fabio Estevam , Stefan Agner , kernel@pengutronix.de, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Markus Pargmann , Shawn Guo , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The old format to define pinctrl settings for imx in DT has two hierarchy levels. The first level are function device nodes. The second level are pingroups which contain a property fsl,pins. The original intention was to define all pin functions in a single dtsi file and just reference the correct ones in the board files. This idea was rejected some time ago leading to the current design to have all the pinfunctions defined in the board files. So we don't need the function device nodes anymore. This patch changes the pinctrl driver to accept devicetrees which do not have the first hierarchy level, function device nodes. For example karo-tx25 already has such a devicetree. Old devicetrees are still parsed and supported. Signed-off-by: Markus Pargmann Acked-by: Uwe Kleine-König Acked-by: Shawn Guo --- I fixed the detection of the old and new format in v2. There is now a dedicated function which searches for the first occurence of 'fsl,pins' in a child node or a child's child node. If child is found, it is assumed that there are no function device nodes. Best Regards, Markus drivers/pinctrl/freescale/pinctrl-imx.c | 55 +++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c index 2cc400b0a26b..62c38ab23489 100644 --- a/drivers/pinctrl/freescale/pinctrl-imx.c +++ b/drivers/pinctrl/freescale/pinctrl-imx.c @@ -606,6 +606,29 @@ static int imx_pinctrl_parse_functions(struct device_node *np, return 0; } +/* + * Check if the DT contains pins in the direct child nodes. This indicates the + * newer DT format to store pins. This function returns true if the first found + * fsl,pins property is in a child of np. Otherwise false is returned. + */ +static bool imx_pinctrl_dt_is_flat_functions(struct device_node *np) +{ + struct device_node *function_np; + struct device_node *pinctrl_np; + + for_each_child_of_node(np, function_np) { + if (of_property_read_bool(function_np, "fsl,pins")) + return true; + + for_each_child_of_node(function_np, pinctrl_np) { + if (of_property_read_bool(pinctrl_np, "fsl,pins")) + return false; + } + } + + return true; +} + static int imx_pinctrl_probe_dt(struct platform_device *pdev, struct imx_pinctrl_soc_info *info) { @@ -613,14 +636,20 @@ static int imx_pinctrl_probe_dt(struct platform_device *pdev, struct device_node *child; u32 nfuncs = 0; u32 i = 0; + bool flat_funcs; if (!np) return -ENODEV; - nfuncs = of_get_child_count(np); - if (nfuncs <= 0) { - dev_err(&pdev->dev, "no functions defined\n"); - return -EINVAL; + flat_funcs = imx_pinctrl_dt_is_flat_functions(np); + if (flat_funcs) { + nfuncs = 1; + } else { + nfuncs = of_get_child_count(np); + if (nfuncs <= 0) { + dev_err(&pdev->dev, "no functions defined\n"); + return -EINVAL; + } } info->nfunctions = nfuncs; @@ -629,16 +658,24 @@ static int imx_pinctrl_probe_dt(struct platform_device *pdev, if (!info->functions) return -ENOMEM; - info->ngroups = 0; - for_each_child_of_node(np, child) - info->ngroups += of_get_child_count(child); + if (flat_funcs) { + info->ngroups = of_get_child_count(np); + } else { + info->ngroups = 0; + for_each_child_of_node(np, child) + info->ngroups += of_get_child_count(child); + } info->groups = devm_kzalloc(&pdev->dev, info->ngroups * sizeof(struct imx_pin_group), GFP_KERNEL); if (!info->groups) return -ENOMEM; - for_each_child_of_node(np, child) - imx_pinctrl_parse_functions(child, info, i++); + if (flat_funcs) { + imx_pinctrl_parse_functions(np, info, 0); + } else { + for_each_child_of_node(np, child) + imx_pinctrl_parse_functions(child, info, i++); + } return 0; }