From patchwork Thu Nov 18 13:21:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12693042 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FCDBC433EF for ; Thu, 18 Nov 2021 13:24:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D6A6561401 for ; Thu, 18 Nov 2021 13:24:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D6A6561401 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DqSWURBoM+MTPQXfdpC+OB1dM/R0LfBo2azwnY2Qe1c=; b=TgYzGXV0TbOdw6 +VOJ9G9+0BPfL45A2rWmLhNunREBKznBUjONqdtPSJoOfJ3ZLFFdMF+sawR5VaHYjjVIJgzgmlXWR Yf+JwPlq6mtqY51H7ueQ+2CGrd0pX9MhoAQbjgU1lmh/5BESfWZ4jYnKAfLNQPu1YbCwlMFIluMyF DuJbuVTG+B3ggIu8L884Zu0Ne+rR9PPjJ23igkDMr4CXDh52oCu2ntTXTy1gdhYq1+fPuHlOy9uap S6mmnISV97r9ZAF1XWK01IBwSsbvGptjLJE5JPX8ScOO+ox2+9AkeHGD4Gpp+2Up+Z4J/67ifDBsh 1zwc+XLXYn1dkJWAVGZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnhNc-007sdx-EF; Thu, 18 Nov 2021 13:23:08 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnhMn-007sOn-Nd for linux-arm-kernel@lists.infradead.org; Thu, 18 Nov 2021 13:22:19 +0000 Received: by mail-lf1-x12f.google.com with SMTP id f18so26015105lfv.6 for ; Thu, 18 Nov 2021 05:22:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9E+oBGu3s/wKY5ZnDLWn9aAASyvfS9O25fFkmrDjZDg=; b=g1VXvm95hleoOSdqO5/XtKVhOGke2/AqUe350SVd0FPK5y50OyVvH63wvhatm0Q9nQ LQ0HJ8VVNo095BvU6FaCp3IXkgm7HvKMCtq2uPP/NX9QZyDkGs04eiGPQbDFGhZjGRBg CxvpM+20YWwMSXyybGyu/TabXBF98/i6604dzFTi33NfmUVzc3dCqvr2wNUzMWTga19E vgR7A60eacjWxywyhxueAlh/omjgWjkapkITe+k4aWx7xqO/ei6xpQltbaywslMEbQJx Y/cJGDn1xNAH1ZS1BKEfEVjKPE5FM8WOIHOGxwjt1PxP99mXkIM6JfbX+I/snjyMjxaO jvRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9E+oBGu3s/wKY5ZnDLWn9aAASyvfS9O25fFkmrDjZDg=; b=bbdnLezgjE/BMTkg1WQOmHOiuN1iKszTgi4yjWsiyeNYkJOXKv0Vvry0gBb2ZINpRp xIfvX/FTW6D3+DytUlBQdc9rnOFQiXZGj/PgEmsfF62S1NRWhhYZb4Uk2Mriz7dij2no YvgUKwGF1H/eUylp0xhlEC8I7pUw9W3Id8iUvBWwmrym600L3yPrrtns+gwKvU9DHDx0 F0JCwiIAeibXC9WeOvxFk4ztYxIX1kKRoCj5NIY0rnhCz0vlF+7YuyAkc4SqTAqJ8Bm2 cKWyuy5aqOarv2yujY+wlDz+TZR7q1kP98HtTIbfLzglvW6E1Pw5QeKjS/Gx9SvHO0hn YDsQ== X-Gm-Message-State: AOAM532c8TBaHWOtm62N2HyLDB3LgdrBhazOoE1rfzqgolJLisfnTm+d vaOjZ1N0nusGmwEDq+GtNf8= X-Google-Smtp-Source: ABdhPJyqcA/lYXMQf4qMh25mqXnzK2hhKOSWdnaKKiSeIuucVGO9wDKOsaCmDI3n0rkyl9XCHJ8AcQ== X-Received: by 2002:a2e:95d6:: with SMTP id y22mr17047762ljh.5.1637241735587; Thu, 18 Nov 2021 05:22:15 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id bp36sm356550lfb.0.2021.11.18.05.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 05:22:15 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Linus Walleij , Rob Herring Cc: Tony Lindgren , Andy Shevchenko , linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Florian Fainelli , bcm-kernel-feedback-list@broadcom.com, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH 4/5] pinctrl: bcm: pinctrl-ns: supoprt DT specified pins, groups & functions Date: Thu, 18 Nov 2021 14:21:51 +0100 Message-Id: <20211118132152.15722-5-zajec5@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211118132152.15722-1-zajec5@gmail.com> References: <20211118132152.15722-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211118_052217_829002_A8241DE5 X-CRM114-Status: GOOD ( 18.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rafał Miłecki It's now possible to specify hardware pins, groups & functions in DT instead of hardcoding that info in a driver. Use pinctrl subsystem helpers to extract that info from DT. Keep hardcoded data as fallback method. Signed-off-by: Rafał Miłecki --- drivers/pinctrl/bcm/pinctrl-ns.c | 90 +++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 30 deletions(-) diff --git a/drivers/pinctrl/bcm/pinctrl-ns.c b/drivers/pinctrl/bcm/pinctrl-ns.c index 0897041b5ef1..48e77ff25d9d 100644 --- a/drivers/pinctrl/bcm/pinctrl-ns.c +++ b/drivers/pinctrl/bcm/pinctrl-ns.c @@ -213,7 +213,11 @@ static int ns_pinctrl_probe(struct platform_device *pdev) struct ns_pinctrl *ns_pinctrl; struct pinctrl_desc *pctldesc; struct pinctrl_pin_desc *pin; + struct device_node *functions; + struct device_node *groups; + struct device_node *pins; struct resource *res; + int err; int i; ns_pinctrl = devm_kzalloc(dev, sizeof(*ns_pinctrl), GFP_KERNEL); @@ -243,19 +247,27 @@ static int ns_pinctrl_probe(struct platform_device *pdev) /* Set pinctrl properties */ - pctldesc->pins = devm_kcalloc(dev, ARRAY_SIZE(ns_pinctrl_pins), - sizeof(struct pinctrl_pin_desc), - GFP_KERNEL); - if (!pctldesc->pins) - return -ENOMEM; - for (i = 0, pin = (struct pinctrl_pin_desc *)&pctldesc->pins[0]; - i < ARRAY_SIZE(ns_pinctrl_pins); i++) { - const struct pinctrl_pin_desc *src = &ns_pinctrl_pins[i]; - unsigned int chipsets = (uintptr_t)src->drv_data; - - if (chipsets & ns_pinctrl->chipset_flag) { - memcpy(pin++, src, sizeof(*src)); - pctldesc->npins++; + pins = of_get_child_by_name(dev->of_node, "pins"); + if (pins) { + err = pinctrl_generic_get_dt_pins(pctldesc, dev); + of_node_put(pins); + if (err) + return err; + } else { + pctldesc->pins = devm_kcalloc(dev, ARRAY_SIZE(ns_pinctrl_pins), + sizeof(struct pinctrl_pin_desc), + GFP_KERNEL); + if (!pctldesc->pins) + return -ENOMEM; + for (i = 0, pin = (struct pinctrl_pin_desc *)&pctldesc->pins[0]; + i < ARRAY_SIZE(ns_pinctrl_pins); i++) { + const struct pinctrl_pin_desc *src = &ns_pinctrl_pins[i]; + unsigned int chipsets = (uintptr_t)src->drv_data; + + if (chipsets & ns_pinctrl->chipset_flag) { + memcpy(pin++, src, sizeof(*src)); + pctldesc->npins++; + } } } @@ -267,25 +279,43 @@ static int ns_pinctrl_probe(struct platform_device *pdev) return PTR_ERR(ns_pinctrl->pctldev); } - for (i = 0; i < ARRAY_SIZE(ns_pinctrl_groups); i++) { - const struct ns_pinctrl_group *group = &ns_pinctrl_groups[i]; - - if (!(group->chipsets & ns_pinctrl->chipset_flag)) - continue; - - pinctrl_generic_add_group(ns_pinctrl->pctldev, group->name, - group->pins, group->num_pins, NULL); + groups = of_get_child_by_name(dev->of_node, "groups"); + if (groups) { + err = pinctrl_generic_get_dt_groups(ns_pinctrl->pctldev); + of_node_put(groups); + if (err) + return err; + } else { + for (i = 0; i < ARRAY_SIZE(ns_pinctrl_groups); i++) { + const struct ns_pinctrl_group *group = &ns_pinctrl_groups[i]; + + if (!(group->chipsets & ns_pinctrl->chipset_flag)) + continue; + + pinctrl_generic_add_group(ns_pinctrl->pctldev, + group->name, group->pins, + group->num_pins, NULL); + } } - for (i = 0; i < ARRAY_SIZE(ns_pinctrl_functions); i++) { - const struct ns_pinctrl_function *function = &ns_pinctrl_functions[i]; - - if (!(function->chipsets & ns_pinctrl->chipset_flag)) - continue; - - pinmux_generic_add_function(ns_pinctrl->pctldev, function->name, - function->groups, - function->num_groups, NULL); + functions = of_get_child_by_name(dev->of_node, "functions"); + if (functions) { + err = pinmux_generic_get_dt_functions(ns_pinctrl->pctldev); + of_node_put(functions); + if (err) + return err; + } else { + for (i = 0; i < ARRAY_SIZE(ns_pinctrl_functions); i++) { + const struct ns_pinctrl_function *function = &ns_pinctrl_functions[i]; + + if (!(function->chipsets & ns_pinctrl->chipset_flag)) + continue; + + pinmux_generic_add_function(ns_pinctrl->pctldev, + function->name, + function->groups, + function->num_groups, NULL); + } } return 0;