From patchwork Wed Nov 24 23:04:38 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: 12693596 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 4EC73C433F5 for ; Wed, 24 Nov 2021 23:07:42 +0000 (UTC) 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=xLO6CUKkQQMmwAhVl9LLi7Ui/KyB7lgPVlHGjZk3nFw=; b=fVXj3bjMMFNORQ M6IdprlrUX29MnMbojT850k6MtQAj972mjy/I74RVhLAuaYVo7Z5rZRMQaDONhPqwxKkqDGPnpgAh I2v0fC4wJXroQWLuqew99dBOvlyvOnEvH/mtvNiQOLHq0RgEUdHdimkGKmxvY0DMO87NsjuPxfeCK KHX7/888Pf42XI/k0nAZMQvD2ZQa4C8BiP2U9OgTZvX+iLy5J2bSd3cHWOXUytx+f8SGnLKSxaz64 7s1beepnX5xwasueCR3ouvaXenoIikgNT5IQJhbLu1iMj8cPwTRig6L3DADopbGkktvUu1EmiG3JW J2DN3IQWjKM65FVz6J/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mq1L7-0061E1-14; Wed, 24 Nov 2021 23:06:09 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mq1K1-0060uU-Td for linux-arm-kernel@lists.infradead.org; Wed, 24 Nov 2021 23:05:03 +0000 Received: by mail-lf1-x131.google.com with SMTP id b1so11177723lfs.13 for ; Wed, 24 Nov 2021 15:05:01 -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=F+wTJaDM5r+kBEnKzSjdLDhTIMgT1zwrllSdQA6Fd8c=; b=GAcDYwPz9LSENEq26U7TEJnu6ce9k/4l2vXsfG9xKZjxo8q93jC+Eus++WIDCdLORm zRHYDw+2TK48X2NRzeY8Dm6gWWoZu0TPJRBOVIFaepkjyOzU7nBLlsQtC7Dv01TZ/zlW xZbtJ1pckfWxeRzXBGO4b32ioqsDT7zF/kXP5BTNnV/ysyURA505gvVNXBo2KFxfDaMc eWLuAGaSrja2fTXgkIFzqXWlb3FjnJH9ZuNvek935eCPQ9YFo5kfIkpEH5KacDuq0787 orInYbewu19bnL4v+tqLC8vUySuQKrbc6O1hxiwdRd2Tz1eelXOWuu+i58rEcBO35YDv k8CQ== 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=F+wTJaDM5r+kBEnKzSjdLDhTIMgT1zwrllSdQA6Fd8c=; b=BiTXtREBCbUC04YpdOZ+aoiXEwKlGkxeW9nDZV3QAWaMHpni8NXSr9h2kV6Uhu+NOR ACS+8XDeEd1HuJIxRCQVJZM5DfhTfzdH18P55aScXM5T433nHyUPLNPHG9SrernkVIRC mRF2FMLSKy1E5/BuWXRoph5C7h/xSVyPOkpsSRjRjFjpOQI1Zfo/c01vv/II+fKG11u4 QPOsviwr61YjTH5QBOExw5wIJ+QZDUH858c8X3wi85KrAaSG9T/Qf9p0KZuMtTsrzC19 fTOGQPrjABoN5QPgk74tNt4y6//EkJAki5oEIf/hl3eVJXXGyF3+Zu/TMMIVE0vytYFp mp/A== X-Gm-Message-State: AOAM532egSkRyWlh9AqblxWS+PhR/wUbZj1o1ujbOaScYLKlH1L7yGdO n2xDN6wGSBH6qZ2wMkLonSs= X-Google-Smtp-Source: ABdhPJwu/Bw6vmmNeIOw2NrUsgPlQvnNVaCKt3cFrezWklnMjvvFXnXK5qx9O+hzEH9Qtt3+e1/LMA== X-Received: by 2002:ac2:5388:: with SMTP id g8mr19570402lfh.382.1637795100285; Wed, 24 Nov 2021 15:05:00 -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 t15sm106243lfp.181.2021.11.24.15.04.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 15:05:00 -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 V2 5/6] pinctrl: bcm: pinctrl-ns: supoprt DT specified pins, groups & functions Date: Thu, 25 Nov 2021 00:04:38 +0100 Message-Id: <20211124230439.17531-6-zajec5@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211124230439.17531-1-zajec5@gmail.com> References: <20211124230439.17531-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211124_150502_013384_DE110D4B X-CRM114-Status: GOOD ( 18.28 ) 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..9036d62c806f 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_load_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_load_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_load_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;