From patchwork Tue Nov 16 22:42:39 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: 12692801 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 CE464C433F5 for ; Tue, 16 Nov 2021 22:44:20 +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 8E6A561BBD for ; Tue, 16 Nov 2021 22:44:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8E6A561BBD 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: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:In-Reply-To:References: List-Owner; bh=ujXs+q4Wzudbb5TrQH8KwcsulcxBArNGcx0fw0FKNqs=; b=mQ+sZA57LJcS26 zR3UGIpy0bMEKj6WJMgQd4zIxAAAJy0kSkUEg9Kl8v/skCqaVhitOxG6XuR0FozoVZMMWcyo5FZD6 9xQe3Rw4moKuuIt3Yy1FIwnDgh9/lAtKwrKNVkNRpxgp8Dlx21bMbcQqh3OEO6FVb4hzSgDUKPUez /1ZYTN87VDf9eK+hUeQ+wsJ76bA8TooGs4IckKO0mbbvRFM3A+/yB6SjuTOJVar6odiIB+BtmPg2Z f7/8n6MVPFEkuo5tPMqngYOIQR0AiZCcwZUL4FtTzaLsixpb/qkPad5QRbm+LaC1dU7ELviIca7ue uUgo5uCrnIJcJ3fuvT3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mn7AK-002svZ-Qn; Tue, 16 Nov 2021 22:43:01 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mn7AG-002sv3-Oe for linux-arm-kernel@lists.infradead.org; Tue, 16 Nov 2021 22:42:58 +0000 Received: by mail-lj1-x22b.google.com with SMTP id t11so1720930ljh.6 for ; Tue, 16 Nov 2021 14:42:55 -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:mime-version :content-transfer-encoding; bh=b2fbCGZIo6J1F8bF7D8bLRpHTy3x+dgeTeVSdFGaFGg=; b=WxnJGt6v14fbiMfIRNO9SuDtYKF+ic2CZOF+k6Wgv012BHJUYfbGq93sa6Tw9WlUbn UAwBwOnk1lWDxv0UI/qDRqN+b7vhLHKXvggEQ22WAu34IuYZMXvgTlgJL7NVkS07dlvD ydsooNLqNvCHUMD2sGOfq99tm1f9wKV5eQVKMJG/ij9QLzjGkMRFMNB91DRwOHx+pLRo ZQ6umHzooWxRsdIRRFjQz7e4J+rDRDokn3J8u9zFPIG6GWxmm5F9ZeQnxN+1a2GFQtgX D07rXZ4/8uJ5GL92ne83rMT1n0Trhc9OKixOo0rG+U0ejm1yVH4TPYbq4RZBhhA2eD/X 0xPg== 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:mime-version :content-transfer-encoding; bh=b2fbCGZIo6J1F8bF7D8bLRpHTy3x+dgeTeVSdFGaFGg=; b=RJ2tK+x0qbDK4NyNHykML1xQJ7IUlFn0prdD361zKbfDVk5+nTIQmMTRjDU+MvP8yv w3q/A9To9q3OBvvwRx8poXJdhplbZcLe6WmGOwQEdj0Ixkr7KJ1dxbHybwkyZzNov1lQ Xu2OW/tpJ3g/iSp/OOX0zciZs2v6XeHeDa63FO4QE/YyC6afTUAK6sZi3Ih1jL+/Br3m H+0HBvr8EXjVznUNyBWv+U96+cr14Vr+8+R+1/QriL1fb4Jf8EzAHHeu+v/3dEMQGbqP uY3yV/YLwo6vxuVS6QXFeBI9L5q4rfoaZr/k56XrcYqccBWsTgfcU3OmduoVKePIwvs/ 4ISA== X-Gm-Message-State: AOAM5333d/Uf0MLgBBIdbLw+p3Frh+15F2GsiB95JQuKcfbvpdKK6lsu Nalm4/It2aYnvt5f765p4RnAtoNQecQ= X-Google-Smtp-Source: ABdhPJzO7KVpA+MegAnlSL1DJ3hjmXXstnOm8W3sc99k+iFO7CLriSScuV4qF5sjClIt7c1W3p7PeA== X-Received: by 2002:a2e:8455:: with SMTP id u21mr2871829ljh.388.1637102574457; Tue, 16 Nov 2021 14:42:54 -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 b14sm1906006lfs.174.2021.11.16.14.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 14:42:54 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Linus Walleij Cc: Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Florian Fainelli , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH] pinctrl: bcm: ns: use generic groups & functions helpers Date: Tue, 16 Nov 2021 23:42:39 +0100 Message-Id: <20211116224239.9387-1-zajec5@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211116_144256_861998_13FFB561 X-CRM114-Status: GOOD ( 20.34 ) 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 This simplifies ns driver and gets rid of 70 lines of code. Some "const"s had to be dropped to avoid: drivers/pinctrl/bcm/pinctrl-ns.c:274:13: warning: passing argument 3 of 'pinctrl_generic_add_group' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] drivers/pinctrl/bcm/pinctrl-ns.c:284:18: warning: passing argument 3 of 'pinmux_generic_add_function' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] Signed-off-by: Rafał Miłecki --- drivers/pinctrl/bcm/Kconfig | 2 + drivers/pinctrl/bcm/pinctrl-ns.c | 173 ++++++++++--------------------- 2 files changed, 54 insertions(+), 121 deletions(-) diff --git a/drivers/pinctrl/bcm/Kconfig b/drivers/pinctrl/bcm/Kconfig index 8fc1feedd861..5123f4c33854 100644 --- a/drivers/pinctrl/bcm/Kconfig +++ b/drivers/pinctrl/bcm/Kconfig @@ -146,6 +146,8 @@ config PINCTRL_NS depends on OF && (ARCH_BCM_5301X || COMPILE_TEST) select PINMUX select GENERIC_PINCONF + select GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONS default ARCH_BCM_5301X help Say yes here to enable the Broadcom NS SoC pins driver. diff --git a/drivers/pinctrl/bcm/pinctrl-ns.c b/drivers/pinctrl/bcm/pinctrl-ns.c index d7f8175d2c1c..08f0298882ac 100644 --- a/drivers/pinctrl/bcm/pinctrl-ns.c +++ b/drivers/pinctrl/bcm/pinctrl-ns.c @@ -14,6 +14,9 @@ #include #include +#include "../core.h" +#include "../pinmux.h" + #define FLAG_BCM4708 BIT(1) #define FLAG_BCM4709 BIT(2) #define FLAG_BCM53012 BIT(3) @@ -25,10 +28,6 @@ struct ns_pinctrl { void __iomem *base; struct pinctrl_desc pctldesc; - struct ns_pinctrl_group *groups; - unsigned int num_groups; - struct ns_pinctrl_function *functions; - unsigned int num_functions; }; /* @@ -65,22 +64,22 @@ static const struct pinctrl_pin_desc ns_pinctrl_pins[] = { struct ns_pinctrl_group { const char *name; - const unsigned int *pins; + unsigned int *pins; const unsigned int num_pins; unsigned int chipsets; }; -static const unsigned int spi_pins[] = { 0, 1, 2, 3 }; -static const unsigned int i2c_pins[] = { 4, 5 }; -static const unsigned int mdio_pins[] = { 6, 7 }; -static const unsigned int pwm0_pins[] = { 8 }; -static const unsigned int pwm1_pins[] = { 9 }; -static const unsigned int pwm2_pins[] = { 10 }; -static const unsigned int pwm3_pins[] = { 11 }; -static const unsigned int uart1_pins[] = { 12, 13, 14, 15 }; -static const unsigned int uart2_pins[] = { 16, 17 }; -static const unsigned int sdio_pwr_pins[] = { 22 }; -static const unsigned int sdio_1p8v_pins[] = { 23 }; +static unsigned int spi_pins[] = { 0, 1, 2, 3 }; +static unsigned int i2c_pins[] = { 4, 5 }; +static unsigned int mdio_pins[] = { 6, 7 }; +static unsigned int pwm0_pins[] = { 8 }; +static unsigned int pwm1_pins[] = { 9 }; +static unsigned int pwm2_pins[] = { 10 }; +static unsigned int pwm3_pins[] = { 11 }; +static unsigned int uart1_pins[] = { 12, 13, 14, 15 }; +static unsigned int uart2_pins[] = { 16, 17 }; +static unsigned int sdio_pwr_pins[] = { 22 }; +static unsigned int sdio_1p8v_pins[] = { 23 }; #define NS_GROUP(_name, _pins, _chipsets) \ { \ @@ -110,19 +109,19 @@ static const struct ns_pinctrl_group ns_pinctrl_groups[] = { struct ns_pinctrl_function { const char *name; - const char * const *groups; + const char **groups; const unsigned int num_groups; unsigned int chipsets; }; -static const char * const spi_groups[] = { "spi_grp" }; -static const char * const i2c_groups[] = { "i2c_grp" }; -static const char * const mdio_groups[] = { "mdio_grp" }; -static const char * const pwm_groups[] = { "pwm0_grp", "pwm1_grp", "pwm2_grp", - "pwm3_grp" }; -static const char * const uart1_groups[] = { "uart1_grp" }; -static const char * const uart2_groups[] = { "uart2_grp" }; -static const char * const sdio_groups[] = { "sdio_pwr_grp", "sdio_1p8v_grp" }; +static const char *spi_groups[] = { "spi_grp" }; +static const char *i2c_groups[] = { "i2c_grp" }; +static const char *mdio_groups[] = { "mdio_grp" }; +static const char *pwm_groups[] = { "pwm0_grp", "pwm1_grp", "pwm2_grp", + "pwm3_grp" }; +static const char *uart1_groups[] = { "uart1_grp" }; +static const char *uart2_groups[] = { "uart2_grp" }; +static const char *sdio_groups[] = { "sdio_pwr_grp", "sdio_1p8v_grp" }; #define NS_FUNCTION(_name, _groups, _chipsets) \ { \ @@ -146,38 +145,10 @@ static const struct ns_pinctrl_function ns_pinctrl_functions[] = { * Groups code */ -static int ns_pinctrl_get_groups_count(struct pinctrl_dev *pctrl_dev) -{ - struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev); - - return ns_pinctrl->num_groups; -} - -static const char *ns_pinctrl_get_group_name(struct pinctrl_dev *pctrl_dev, - unsigned int selector) -{ - struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev); - - return ns_pinctrl->groups[selector].name; -} - -static int ns_pinctrl_get_group_pins(struct pinctrl_dev *pctrl_dev, - unsigned int selector, - const unsigned int **pins, - unsigned int *num_pins) -{ - struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev); - - *pins = ns_pinctrl->groups[selector].pins; - *num_pins = ns_pinctrl->groups[selector].num_pins; - - return 0; -} - static const struct pinctrl_ops ns_pinctrl_ops = { - .get_groups_count = ns_pinctrl_get_groups_count, - .get_group_name = ns_pinctrl_get_group_name, - .get_group_pins = ns_pinctrl_get_group_pins, + .get_groups_count = pinctrl_generic_get_group_count, + .get_group_name = pinctrl_generic_get_group_name, + .get_group_pins = pinctrl_generic_get_group_pins, .dt_node_to_map = pinconf_generic_dt_node_to_map_group, .dt_free_map = pinconf_generic_dt_free_map, }; @@ -186,34 +157,6 @@ static const struct pinctrl_ops ns_pinctrl_ops = { * Functions code */ -static int ns_pinctrl_get_functions_count(struct pinctrl_dev *pctrl_dev) -{ - struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev); - - return ns_pinctrl->num_functions; -} - -static const char *ns_pinctrl_get_function_name(struct pinctrl_dev *pctrl_dev, - unsigned int selector) -{ - struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev); - - return ns_pinctrl->functions[selector].name; -} - -static int ns_pinctrl_get_function_groups(struct pinctrl_dev *pctrl_dev, - unsigned int selector, - const char * const **groups, - unsigned * const num_groups) -{ - struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev); - - *groups = ns_pinctrl->functions[selector].groups; - *num_groups = ns_pinctrl->functions[selector].num_groups; - - return 0; -} - static int ns_pinctrl_set_mux(struct pinctrl_dev *pctrl_dev, unsigned int func_select, unsigned int grp_select) @@ -223,8 +166,8 @@ static int ns_pinctrl_set_mux(struct pinctrl_dev *pctrl_dev, u32 tmp; int i; - for (i = 0; i < ns_pinctrl->groups[grp_select].num_pins; i++) { - int pin_number = ns_pinctrl->groups[grp_select].pins[i]; + for (i = 0; i < ns_pinctrl_groups[grp_select].num_pins; i++) { + int pin_number = ns_pinctrl_groups[grp_select].pins[i]; unset |= BIT(pin_number); } @@ -237,9 +180,9 @@ static int ns_pinctrl_set_mux(struct pinctrl_dev *pctrl_dev, } static const struct pinmux_ops ns_pinctrl_pmxops = { - .get_functions_count = ns_pinctrl_get_functions_count, - .get_function_name = ns_pinctrl_get_function_name, - .get_function_groups = ns_pinctrl_get_function_groups, + .get_functions_count = pinmux_generic_get_function_count, + .get_function_name = pinmux_generic_get_function_name, + .get_function_groups = pinmux_generic_get_function_groups, .set_mux = ns_pinctrl_set_mux, }; @@ -267,8 +210,6 @@ static int ns_pinctrl_probe(struct platform_device *pdev) struct ns_pinctrl *ns_pinctrl; struct pinctrl_desc *pctldesc; struct pinctrl_pin_desc *pin; - struct ns_pinctrl_group *group; - struct ns_pinctrl_function *function; struct resource *res; int i; @@ -315,43 +256,33 @@ static int ns_pinctrl_probe(struct platform_device *pdev) } } - ns_pinctrl->groups = devm_kcalloc(dev, ARRAY_SIZE(ns_pinctrl_groups), - sizeof(struct ns_pinctrl_group), - GFP_KERNEL); - if (!ns_pinctrl->groups) - return -ENOMEM; - for (i = 0, group = &ns_pinctrl->groups[0]; - i < ARRAY_SIZE(ns_pinctrl_groups); i++) { - const struct ns_pinctrl_group *src = &ns_pinctrl_groups[i]; + /* Register */ - if (src->chipsets & ns_pinctrl->chipset_flag) { - memcpy(group++, src, sizeof(*src)); - ns_pinctrl->num_groups++; - } + ns_pinctrl->pctldev = devm_pinctrl_register(dev, pctldesc, ns_pinctrl); + if (IS_ERR(ns_pinctrl->pctldev)) { + dev_err(dev, "Failed to register pinctrl\n"); + return PTR_ERR(ns_pinctrl->pctldev); } - ns_pinctrl->functions = devm_kcalloc(dev, - ARRAY_SIZE(ns_pinctrl_functions), - sizeof(struct ns_pinctrl_function), - GFP_KERNEL); - if (!ns_pinctrl->functions) - return -ENOMEM; - for (i = 0, function = &ns_pinctrl->functions[0]; - i < ARRAY_SIZE(ns_pinctrl_functions); i++) { - const struct ns_pinctrl_function *src = &ns_pinctrl_functions[i]; + for (i = 0; i < ARRAY_SIZE(ns_pinctrl_groups); i++) { + const struct ns_pinctrl_group *group = &ns_pinctrl_groups[i]; - if (src->chipsets & ns_pinctrl->chipset_flag) { - memcpy(function++, src, sizeof(*src)); - ns_pinctrl->num_functions++; - } + if (!(group->chipsets & ns_pinctrl->chipset_flag)) + continue; + + pinctrl_generic_add_group(ns_pinctrl->pctldev, group->name, + group->pins, group->num_pins, NULL); } - /* Register */ + for (i = 0; i < ARRAY_SIZE(ns_pinctrl_functions); i++) { + const struct ns_pinctrl_function *function = &ns_pinctrl_functions[i]; - ns_pinctrl->pctldev = devm_pinctrl_register(dev, pctldesc, ns_pinctrl); - if (IS_ERR(ns_pinctrl->pctldev)) { - dev_err(dev, "Failed to register pinctrl\n"); - return PTR_ERR(ns_pinctrl->pctldev); + 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;