From patchwork Wed Dec 22 06:43:44 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: 12697053 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 9222EC433F5 for ; Wed, 22 Dec 2021 06:45:16 +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=kSQhd4VuYfwqFzfUWrPyW30Am6rBw0XanZTFqZXyYqE=; b=UdLGeKeldlmE7R rD7uI3UE6Vf11dBlW9nIB/fd5MREivdnnOvYDbsnsZWYvFBRhBkggV69O9Dqz9DwR/xgx42dI6N3D yGhx/wMZpSbpYj7uRsdpwThmir+0b+vTxZBlfennT+1odYsmAjx1L3o6cJ8KGqkcGKJF+lgDBzufn 2pYE9pYie7I3lvM3lyd/1l/aPNNNfFSpQnuMy9U3UZ/abBMNfFCoNiz885mmyboxg8WDBjK+3xeUC 688U6+OtXUFUc/MMZvVGa/s98HxkCpCul0FFivhdzJ4+L6RA9cJvOWKz7T7JFqEXB9dsLDyF6Bxt2 MTkrPoMlSaDgJj9bancQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mzvLu-009MWd-Lj; Wed, 22 Dec 2021 06:43:54 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mzvLq-009MVm-Ni for linux-arm-kernel@lists.infradead.org; Wed, 22 Dec 2021 06:43:52 +0000 Received: by mail-lf1-x136.google.com with SMTP id j11so1422204lfg.3 for ; Tue, 21 Dec 2021 22:43:49 -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=+q+qY2igeSdF0ssEguC8XY/FIG2+rpB39ucmpSGam7s=; b=NQT9MlViQoWPNWoJNs7DQZN9RdKfk1CDt2Q9stUuYoGYqE5ebNHSTTzWAhu3jvxzpQ rFPhbjwWADRe+NCrA+C6iSfeShaKfhXcWuFVoN6/MEU5BDEzec3ujzK3akO0mry/kNa/ 3EkW4CiEA5y6V0dEWGuHF2ClgFkq5VEnqUcJ/X7vI+o+WFSYdKRsflMigbK3YTMWdYAY TMwoJuj0AtLTgA+XyijRu+xTAryW6u9Jr6clLpQ/g7Zr2Z3EVmJxUbdMgSMyANGqFEX2 6q9Qo17k6RI2S2WL6MdyGiNBVNKSDPrFtI0KolK+vcqtKJdsNCWKnSrAxEvqYYbkat7r GZuQ== 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=+q+qY2igeSdF0ssEguC8XY/FIG2+rpB39ucmpSGam7s=; b=A5daGFFCw0GEZe2HWmdDmU6cxbOtkjNvysWG6VEnT/hpW64ZqZ5+nKQcxtDFmJAuJb ODst2JnuKDKNH3uCNRGVTTayfFwITi1HHhQCwe/xoug1t0hpklo66jLHFtxK9zqttjsi gyBtYmLefYxExSljNnNWaMcXulaGs9XqM50yX7wqBFisv/ryuEo/NT5ndGLvK4sBAj6I 2f0OoFMH4x4xDd9/e4TJz81cgN0yJa3wiy3gzDsYzPbsTt28U5NKrvuJsVqhN9yQUqNJ eOJNzPfQnIc2xYI9iONFjdRUAAiFhZDEd8P3N7MCeQ6mpkLV58QgCPEi1cU95oZqkF6U 0AZw== X-Gm-Message-State: AOAM530vanJuwL/q/1YqE880zTN3hvLkfsdqOxs7sLyTO4uyuV28hhds gTJ/LpPsaQprGW1U3BsJpZs= X-Google-Smtp-Source: ABdhPJxvYj7SZCwN80qLM/WHxx0HOV/dgIbPQwqUhkpa9eUGtmTXr4xT89vs7Cuo8D8CNmwpDkFUPA== X-Received: by 2002:a05:6512:3501:: with SMTP id h1mr1442577lfs.513.1640155428094; Tue, 21 Dec 2021 22:43:48 -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 18sm92950ljj.119.2021.12.21.22.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 22:43:47 -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 V3] pinctrl: bcm: ns: use generic groups & functions helpers Date: Wed, 22 Dec 2021 07:43:44 +0100 Message-Id: <20211222064344.14624-1-zajec5@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211117130840.975-1-zajec5@gmail.com> References: <20211117130840.975-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211221_224350_823746_52924DB9 X-CRM114-Status: GOOD ( 23.10 ) 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. "const" had to be dropped from "struct ns_pinctrl_group" @pins to match "struct group_desc" @pins and pinctrl_generic_add_group(). Otherwise it would cause: drivers/pinctrl/bcm/pinctrl-ns.c: In function 'ns_pinctrl_probe': drivers/pinctrl/bcm/pinctrl-ns.c:277:13: warning: passing argument 3 of 'pinctrl_generic_add_group' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 277 | group->pins, group->num_pins, NULL); | ~~~~~^~~~~~ Signed-off-by: Rafał Miłecki --- V2: Use pinctrl_generic_get_group() in .set_mux() cb V3: Don't drop "const" from "ns_pinctrl_function" @groups. It's possible thanks to the commit bd0aae66c482 ("pinctrl: add one more "const" for generic function groups"). This patch depends on above commit for that reason. --- drivers/pinctrl/bcm/Kconfig | 2 + drivers/pinctrl/bcm/pinctrl-ns.c | 163 +++++++++---------------------- 2 files changed, 50 insertions(+), 115 deletions(-) diff --git a/drivers/pinctrl/bcm/Kconfig b/drivers/pinctrl/bcm/Kconfig index 273d2a4f9b10..ea5034cce644 100644 --- a/drivers/pinctrl/bcm/Kconfig +++ b/drivers/pinctrl/bcm/Kconfig @@ -159,6 +159,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..65a86543c58c 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) \ { \ @@ -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,48 +157,22 @@ 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) + unsigned int group_selector) { struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev); + struct group_desc *group; u32 unset = 0; 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]; + group = pinctrl_generic_get_group(pctrl_dev, group_selector); + if (!group) + return -EINVAL; - unset |= BIT(pin_number); - } + for (i = 0; i < group->num_pins; i++) + unset |= BIT(group->pins[i]); tmp = readl(ns_pinctrl->base); tmp &= ~unset; @@ -237,9 +182,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 +212,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 +258,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;