From patchwork Mon Mar 27 06:27:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chester Lin X-Patchwork-Id: 668408 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4379C7619A for ; Mon, 27 Mar 2023 06:28:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232192AbjC0G2W (ORCPT ); Mon, 27 Mar 2023 02:28:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232211AbjC0G2T (ORCPT ); Mon, 27 Mar 2023 02:28:19 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2064.outbound.protection.outlook.com [40.107.20.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8C2435BE; Sun, 26 Mar 2023 23:28:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YXiukYbFbNeC3QzGvvs+6URc4CJ9KLXiMmrYYlzcBe1dNK2gTsI4t8cYHjkxyUwotr6l6P7cLPEZCdEFjhauzgk2kqSDTz/g4Nyi2uqCKxfGkOCekubzGJWapxo2ta27keLnBF7PLuvAKm577IBiZYf04zh9/QulcDGgbDBN9P7PS6m+NzqxlAPumNt+z8UpBVZpT9BdHmt+z2ZIfia2G0td65SZ2+D3JGm5z6KbC1u7dAAbJ/ceL/RvlHtxfhWLtqf5VUTgdblZ2JsHjIE64NWo+hlefRKRyvDXWIa0l8Bor3Loa0NYdU8PP1XaAB7MUL8TBqqiXv2FDuCkZ0mXWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UvLq29R3cJdMNhrDZYSjsggrvLxGzA+VlJIrGEgigSA=; b=TvqsxIhSUkCpwDLadhWUqb3HQZJLDWUaeDmf1kN12HriigQv7IXnEhPz29zr34Xicyd90t/grZNP8+N8zDekphBycvOq8jXVSy1+f4qlZULVyhCo5D9mlSkT51lEj+ATIuwiywFaCQCnEzPd0l9iCJdEcfPmWt29MyzjeO6WbG/2FOwlbs1ZAqy+N1+vodbKFS039V788jAThgMl/gX4218rtWr4RF0AcWqWwCbjX1lIfh5XMcl+bV9TmEDPdbHst9bdtDa1XjtbGRp28+ZPkr1iDAsTEbLMyiJa721xcwWfQWqc6YX9KEpYg1ATCkidh3s+eA7dyutkbLCxoC6VmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UvLq29R3cJdMNhrDZYSjsggrvLxGzA+VlJIrGEgigSA=; b=OEVfaKAcmQ+Mxi8KL/Za+jpmbbg+nOO2QbH2HxsibhlzdlqSh6wvtoG4H+Zyo3HXMtEtjUw8IPzTCXppx8HVvNUAdLQUzWKZ5ncquo1dbkSrabDgl55rsMiV+8jwf6cwI2WT7CVjo41E2NBfoUBd7dOleOhELMY5fC/4ZebEJ26ltuNK8/Yk/3w59TGeVDlB8CjOnXy0/guJ+rpNqXMOleZaj5sOrODUYY51hkVuH77ZLt+sXxxMd78l/QCdRfelePLYWsQiOwTqhAtCDOoRKDzjDti59zQbB7gf+fB6otvw83eUV9adlVtWyd9DB94/WHvOAKxeTgf0/nYTWBnklw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3439.eurprd04.prod.outlook.com (2603:10a6:803:4::13) by DBBPR04MB7930.eurprd04.prod.outlook.com (2603:10a6:10:1ea::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.30; Mon, 27 Mar 2023 06:28:14 +0000 Received: from VI1PR0402MB3439.eurprd04.prod.outlook.com ([fe80::6802:b2c3:5f12:8f9f]) by VI1PR0402MB3439.eurprd04.prod.outlook.com ([fe80::6802:b2c3:5f12:8f9f%2]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 06:28:14 +0000 From: Chester Lin To: Linus Walleij , Andy Shevchenko Cc: Chester Lin , NXP S32 Linux Team , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ghennadi Procopciuc , Andrei Stefanescu , Radu Pirea , =?utf-8?q?Andreas_F=C3=A4rber?= , Matthias Brugger Subject: [PATCH v5 1/5] pinctrl: s32: refine error/return/config checks and simplify driver codes Date: Mon, 27 Mar 2023 14:27:50 +0800 Message-Id: <20230327062754.3326-2-clin@suse.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230327062754.3326-1-clin@suse.com> References: <20230327062754.3326-1-clin@suse.com> X-ClientProxiedBy: TY2PR06CA0016.apcprd06.prod.outlook.com (2603:1096:404:42::28) To VI1PR0402MB3439.eurprd04.prod.outlook.com (2603:10a6:803:4::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0402MB3439:EE_|DBBPR04MB7930:EE_ X-MS-Office365-Filtering-Correlation-Id: 51498c8a-4693-4c9c-e1c8-08db2e8c717e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +v4Eov5sEhdeIZYQ0T+qhyyXUNvLWiaxCLLdL/8S71ewsdB/D/m7RvBjAWfKT01KRndDHLzvea0vA45r5Wnaunhy+//n0MD6fgVf4VhC0sPBWXuO3z1VUY01/ODykNTSoGZSpe/OHAj2bFopQoa1jurZvEOs2/6NWFo6oguS0/meoyL7SZFsEwzieomVLkmvc8/ve51Fh/T6F93pLvrTeytopPYRbK7dpCfcnZdYlGW8kSUwiVd/BOBgdsS6li2JE9kLbErWQZiG563Y/JgeAXJrni2l91Bb+UCj6N94qc9yr5ydSuH38Cm/Z6W+Cbr8slTQIn8TPvuk0QwkJ+YMA0YdQfXxTbin8R1WuadJaxUuyeH7aeodPXzgxSu7wwl+gDTsMblvnv1GCeakM0ZxsjBA7BLTBoz6AWxLOnnkVSlROI0JTh4msgXam/su/NvPqfKAt82mrgcYq8fej0S56Gq8B9/SQnkz6U6FgX1WaglRe1wwf9HQNv0bMUA47mM+dwGiAaIuB1wyGDlyoTVrNoXi68z1+ioT3cb/bSmflNpKqVqRFRYnvgxPBJReTNGH X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR0402MB3439.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(39860400002)(376002)(396003)(346002)(366004)(136003)(451199021)(316002)(110136005)(54906003)(478600001)(5660300002)(8936002)(36756003)(86362001)(38100700002)(7416002)(30864003)(2906002)(4326008)(66556008)(66476007)(8676002)(66946007)(41300700001)(107886003)(6666004)(186003)(6512007)(6506007)(1076003)(26005)(2616005)(83380400001)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eTzDX2D/P26DYSpSlFKyc/n2IuvnJ/bEGGtc3FcTxKgtRPpUBKORmdad97LuO6rCpLe2hhE7UFwr4njRlka8X+4JTgp0T77QxG6dfQqYDoOrznJ8bg0y3A9TF0p3FmvrvUGEHVvD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xig4x8YcZ9u+At67R0B1zkVi+pDt0ZHupBLRVJxoCUnNgieYstOAlSseRhQLixNAdE2cATU6qmNFHEP1LaCvqKoKIotFgxpWJ8iDU/nWDO3M9f8Ns5S5l2q0HSaV7PVSI7qVMXt6iR0nlHNPiiKvQ1n2LXwHo0jDYATY3f4cu0NSwrLcMyq6bWhZrmOwRGVdKKGrIMi9eLnuj/rS5Jua1AlqakfwLVhHQiViAEWIOiRG97vPC9JyOYsL2fXm6VZ0191YYDTLwWJvnLaGT4tpMQ1kPyQebjZU2VlAlYJg1ouOiMCU9L9e+Xtr/5TFgb2KFF7gON8Gd2kCLIJyaX7bBGGOhzt6buI1K/g6fUGgjp0T+wxc= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51498c8a-4693-4c9c-e1c8-08db2e8c717e X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3439.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 06:28:13.9059 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gUzKCLR5KrU9Uza7eF73EfwmXxtyZvnq4UrO6voW6nhu9jYvkZKX0W42N496OYlE X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7930 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Improve error/return code handlings and config checks in order to have better reliability and simplify driver codes such as removing/changing improper macros, blanks, print formats and helper calls. Signed-off-by: Chester Lin Reviewed-by: Andy Shevchenko --- (No change since v2) drivers/pinctrl/nxp/pinctrl-s32cc.c | 141 +++++++++++++++------------- drivers/pinctrl/nxp/pinctrl-s32g2.c | 4 +- 2 files changed, 76 insertions(+), 69 deletions(-) diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c index e1da332433a3..f698e1a240ef 100644 --- a/drivers/pinctrl/nxp/pinctrl-s32cc.c +++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c @@ -28,7 +28,8 @@ #include "../pinctrl-utils.h" #include "pinctrl-s32.h" -#define S32_PIN_ID_MASK GENMASK(31, 4) +#define S32_PIN_ID_SHIFT 4 +#define S32_PIN_ID_MASK GENMASK(31, S32_PIN_ID_SHIFT) #define S32_MSCR_SSS_MASK GENMASK(2, 0) #define S32_MSCR_PUS BIT(12) @@ -46,7 +47,7 @@ static struct regmap_config s32_regmap_config = { static u32 get_pin_no(u32 pinmux) { - return (pinmux & S32_PIN_ID_MASK) >> __ffs(S32_PIN_ID_MASK); + return (pinmux & S32_PIN_ID_MASK) >> S32_PIN_ID_SHIFT; } static u32 get_pin_func(u32 pinmux) @@ -108,7 +109,7 @@ s32_get_region(struct pinctrl_dev *pctldev, unsigned int pin) unsigned int mem_regions = ipctl->info->mem_regions; unsigned int i; - for (i = 0; i < mem_regions; ++i) { + for (i = 0; i < mem_regions; i++) { pin_range = ipctl->regions[i].pin_range; if (pin >= pin_range->start && pin <= pin_range->end) return &ipctl->regions[i]; @@ -224,8 +225,7 @@ static int s32_dt_group_node_to_map(struct pinctrl_dev *pctldev, n_pins = of_property_count_elems_of_size(np, "pinmux", sizeof(u32)); if (n_pins < 0) { - dev_warn(dev, "Unable to find 'pinmux' property in node %s.\n", - np->name); + dev_warn(dev, "Can't find 'pinmux' property in node %pOFn\n", np); } else if (!n_pins) { return -EINVAL; } @@ -317,20 +317,25 @@ static int s32_pmx_set(struct pinctrl_dev *pctldev, unsigned int selector, info->functions[selector].name, grp->name); /* Check beforehand so we don't have a partial config. */ - for (i = 0; i < grp->npins; ++i) { + for (i = 0; i < grp->npins; i++) { if (s32_check_pin(pctldev, grp->pin_ids[i]) != 0) { - dev_err(info->dev, "invalid pin: %d in group: %d\n", + dev_err(info->dev, "invalid pin: %u in group: %u\n", grp->pin_ids[i], group); return -EINVAL; } } - for (i = 0, ret = 0; i < grp->npins && !ret; ++i) { + for (i = 0, ret = 0; i < grp->npins && !ret; i++) { ret = s32_regmap_update(pctldev, grp->pin_ids[i], S32_MSCR_SSS_MASK, grp->pin_sss[i]); + if (ret) { + dev_err(info->dev, "Failed to set pin %u\n", + grp->pin_ids[i]); + return ret; + } } - return ret; + return 0; } static int s32_pmx_get_funcs_count(struct pinctrl_dev *pctldev) @@ -375,8 +380,8 @@ static int s32_pmx_gpio_request_enable(struct pinctrl_dev *pctldev, int ret; ret = s32_regmap_read(pctldev, offset, &config); - if (ret != 0) - return -EINVAL; + if (ret) + return ret; /* Save current configuration */ gpio_pin = kmalloc(sizeof(*gpio_pin), GFP_KERNEL); @@ -387,7 +392,7 @@ static int s32_pmx_gpio_request_enable(struct pinctrl_dev *pctldev, gpio_pin->config = config; spin_lock_irqsave(&ipctl->gpio_configs_lock, flags); - list_add(&(gpio_pin->list), &(ipctl->gpio_configs)); + list_add(&gpio_pin->list, &ipctl->gpio_configs); spin_unlock_irqrestore(&ipctl->gpio_configs_lock, flags); /* GPIO pin means SSS = 0 */ @@ -401,23 +406,20 @@ static void s32_pmx_gpio_disable_free(struct pinctrl_dev *pctldev, unsigned int offset) { struct s32_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); - struct list_head *pos, *tmp; - struct gpio_pin_config *gpio_pin; + struct gpio_pin_config *gpio_pin, *tmp; unsigned long flags; int ret; spin_lock_irqsave(&ipctl->gpio_configs_lock, flags); - list_for_each_safe(pos, tmp, &ipctl->gpio_configs) { - gpio_pin = list_entry(pos, struct gpio_pin_config, list); - + list_for_each_entry_safe(gpio_pin, tmp, &ipctl->gpio_configs, list) { if (gpio_pin->pin_id == offset) { ret = s32_regmap_write(pctldev, gpio_pin->pin_id, gpio_pin->config); if (ret != 0) goto unlock; - list_del(pos); + list_del(&gpio_pin->list); kfree(gpio_pin); break; } @@ -461,7 +463,8 @@ static const int support_slew[] = {208, -1, -1, -1, 166, 150, 133, 83}; static int s32_get_slew_regval(int arg) { - int i; + unsigned int i; + /* Translate a real slew rate (MHz) to a register value */ for (i = 0; i < ARRAY_SIZE(support_slew); i++) { if (arg == support_slew[i]) @@ -542,10 +545,11 @@ static int s32_pinconf_mscr_update(struct pinctrl_dev *pctldev, unsigned int config = 0, mask = 0; int i, ret; - if (s32_check_pin(pctldev, pin_id) != 0) - return -EINVAL; + ret = s32_check_pin(pctldev, pin_id); + if (ret) + return ret; - dev_dbg(ipctl->dev, "pinconf set pin %s with %d configs\n", + dev_dbg(ipctl->dev, "pinconf set pin %s with %u configs\n", pin_get_name(pctldev, pin_id), num_configs); for (i = 0; i < num_configs; i++) { @@ -559,11 +563,9 @@ static int s32_pinconf_mscr_update(struct pinctrl_dev *pctldev, if (!config && !mask) return 0; - ret = s32_regmap_update(pctldev, pin_id, mask, config); + dev_dbg(ipctl->dev, "update: pin %u cfg 0x%x\n", pin_id, config); - dev_dbg(ipctl->dev, "update: pin %d cfg 0x%x\n", pin_id, config); - - return ret; + return s32_regmap_update(pctldev, pin_id, mask, config); } static int s32_pinconf_get(struct pinctrl_dev *pctldev, @@ -604,10 +606,13 @@ static void s32_pinconf_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, unsigned int pin_id) { unsigned int config; - int ret = s32_regmap_read(pctldev, pin_id, &config); + int ret; - if (!ret) - seq_printf(s, "0x%x", config); + ret = s32_regmap_read(pctldev, pin_id, &config); + if (ret) + return; + + seq_printf(s, "0x%x", config); } static void s32_pinconf_group_dbg_show(struct pinctrl_dev *pctldev, @@ -710,7 +715,7 @@ int s32_pinctrl_resume(struct device *dev) } #endif -static void s32_pinctrl_parse_groups(struct device_node *np, +static int s32_pinctrl_parse_groups(struct device_node *np, struct s32_pin_group *grp, struct s32_pinctrl_soc_info *info) { @@ -722,21 +727,20 @@ static void s32_pinctrl_parse_groups(struct device_node *np, dev = info->dev; - dev_dbg(dev, "group: %s\n", np->name); + dev_dbg(dev, "group: %pOFn\n", np); /* Initialise group */ grp->name = np->name; npins = of_property_count_elems_of_size(np, "pinmux", sizeof(u32)); - if (npins < 0) { dev_err(dev, "Failed to read 'pinmux' property in node %s.\n", - np->name); - return; + grp->name); + return -EINVAL; } if (!npins) { - dev_err(dev, "The group %s has no pins.\n", np->name); - return; + dev_err(dev, "The group %s has no pins.\n", grp->name); + return -EINVAL; } grp->npins = npins; @@ -745,12 +749,8 @@ static void s32_pinctrl_parse_groups(struct device_node *np, sizeof(unsigned int), GFP_KERNEL); grp->pin_sss = devm_kcalloc(info->dev, grp->npins, sizeof(unsigned int), GFP_KERNEL); - - if (!grp->pin_ids || !grp->pin_sss) { - dev_err(dev, "Failed to allocate memory for the group %s.\n", - np->name); - return; - } + if (!grp->pin_ids || !grp->pin_sss) + return -ENOMEM; i = 0; of_property_for_each_u32(np, "pinmux", prop, p, pinmux) { @@ -761,9 +761,11 @@ static void s32_pinctrl_parse_groups(struct device_node *np, grp->pin_ids[i], grp->pin_sss[i]); i++; } + + return 0; } -static void s32_pinctrl_parse_functions(struct device_node *np, +static int s32_pinctrl_parse_functions(struct device_node *np, struct s32_pinctrl_soc_info *info, u32 index) { @@ -771,8 +773,9 @@ static void s32_pinctrl_parse_functions(struct device_node *np, struct s32_pmx_func *func; struct s32_pin_group *grp; u32 i = 0; + int ret = 0; - dev_dbg(info->dev, "parse function(%d): %s\n", index, np->name); + dev_dbg(info->dev, "parse function(%u): %pOFn\n", index, np); func = &info->functions[index]; @@ -780,18 +783,24 @@ static void s32_pinctrl_parse_functions(struct device_node *np, func->name = np->name; func->num_groups = of_get_child_count(np); if (func->num_groups == 0) { - dev_err(info->dev, "no groups defined in %s\n", np->full_name); - return; + dev_err(info->dev, "no groups defined in %pOF\n", np); + return -EINVAL; } - func->groups = devm_kzalloc(info->dev, - func->num_groups * sizeof(char *), GFP_KERNEL); + func->groups = devm_kcalloc(info->dev, func->num_groups, + sizeof(*func->groups), GFP_KERNEL); + if (!func->groups) + return -ENOMEM; for_each_child_of_node(np, child) { func->groups[i] = child->name; grp = &info->groups[info->grp_index++]; - s32_pinctrl_parse_groups(child, grp, info); + ret = s32_pinctrl_parse_groups(child, grp, info); + if (ret) + return ret; i++; } + + return 0; } static int s32_pinctrl_probe_dt(struct platform_device *pdev, @@ -804,6 +813,7 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev, struct regmap *map; void __iomem *base; int mem_regions = info->mem_regions; + int ret; u32 nfuncs = 0; u32 i = 0; @@ -815,13 +825,12 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev, return -EINVAL; } - ipctl->regions = devm_kzalloc(&pdev->dev, - mem_regions * sizeof(*(ipctl->regions)), - GFP_KERNEL); + ipctl->regions = devm_kcalloc(&pdev->dev, mem_regions, + sizeof(*ipctl->regions), GFP_KERNEL); if (!ipctl->regions) return -ENOMEM; - for (i = 0; i < mem_regions; ++i) { + for (i = 0; i < mem_regions; i++) { base = devm_platform_get_and_ioremap_resource(pdev, i, &res); if (IS_ERR(base)) return PTR_ERR(base); @@ -851,24 +860,26 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev, } info->nfunctions = nfuncs; - info->functions = devm_kzalloc(&pdev->dev, - nfuncs * sizeof(struct s32_pmx_func), - GFP_KERNEL); + info->functions = devm_kcalloc(&pdev->dev, nfuncs, + sizeof(*info->functions), GFP_KERNEL); if (!info->functions) return -ENOMEM; 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 s32_pin_group), - GFP_KERNEL); + + info->groups = devm_kcalloc(&pdev->dev, info->ngroups, + sizeof(*info->groups), GFP_KERNEL); if (!info->groups) return -ENOMEM; i = 0; - for_each_child_of_node(np, child) - s32_pinctrl_parse_functions(child, info, i++); + for_each_child_of_node(np, child) { + ret = s32_pinctrl_parse_functions(child, info, i++); + if (ret) + return ret; + } return 0; } @@ -923,11 +934,9 @@ int s32_pinctrl_probe(struct platform_device *pdev, ipctl->pctl = devm_pinctrl_register(&pdev->dev, s32_pinctrl_desc, ipctl); - - if (IS_ERR(ipctl->pctl)) { - dev_err(&pdev->dev, "could not register s32 pinctrl driver\n"); - return PTR_ERR(ipctl->pctl); - } + if (IS_ERR(ipctl->pctl)) + return dev_err_probe(&pdev->dev, PTR_ERR(ipctl->pctl), + "could not register s32 pinctrl driver\n"); #ifdef CONFIG_PM_SLEEP saved_context = &ipctl->saved_context; diff --git a/drivers/pinctrl/nxp/pinctrl-s32g2.c b/drivers/pinctrl/nxp/pinctrl-s32g2.c index 5028f4adc389..d9f3ff6794ea 100644 --- a/drivers/pinctrl/nxp/pinctrl-s32g2.c +++ b/drivers/pinctrl/nxp/pinctrl-s32g2.c @@ -757,14 +757,12 @@ static const struct dev_pm_ops s32g_pinctrl_pm_ops = { static struct platform_driver s32g_pinctrl_driver = { .driver = { .name = "s32g-siul2-pinctrl", - .owner = THIS_MODULE, .of_match_table = s32_pinctrl_of_match, - .pm = &s32g_pinctrl_pm_ops, + .pm = pm_sleep_ptr(&s32g_pinctrl_pm_ops), .suppress_bind_attrs = true, }, .probe = s32g_pinctrl_probe, }; - builtin_platform_driver(s32g_pinctrl_driver); MODULE_AUTHOR("Matthew Nunez "); From patchwork Mon Mar 27 06:27:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chester Lin X-Patchwork-Id: 667671 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0C83C7619A for ; Mon, 27 Mar 2023 06:28:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232183AbjC0G2e (ORCPT ); Mon, 27 Mar 2023 02:28:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230089AbjC0G2d (ORCPT ); Mon, 27 Mar 2023 02:28:33 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2064.outbound.protection.outlook.com [40.107.20.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92C6D49C2; Sun, 26 Mar 2023 23:28:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DK0/OiWRVlSLAdqWGJ3P/cKNB5KJJ5IrZCTITTa7NLYh5omcwv90gAs5nC+IgAel0H7srXJH84wKYIMijYb/TlQtwWhULAC8jp3bytIzBfqF35Dhir0FH7MyTo983GsumhFwHW9X2e4ipTjEFCEQ1kWlUY2717QUUDCyHjDCYDiHSsAh+JfHXMfXLkFNnAO9DL/rbSjWPsdZ+aDCb51Ml02rIxgpbTzKmt2knG0vumq5Bzth9amOdL5thEM69rPL/NSdoLpplBOmfyPzw0Barbo/Turnue5V1Wzon9PAFUJ1GDyBrD1IJk9Fq55H1/+ZyJQvJUvHAII/SwvoccdYiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gA36rjGQaztJzKACtcCbtTz7Hrsky4bgENUo5JjXWaQ=; b=hoHIvSc8lE9ciT4HzrWkkS+8eOC6ngHT4xvyabkH7F81E1m5m6O7tAumFz6gvBbZKmRODaWGAAkASW//ue1/d7eUvWCPtSPTbRoBFryB8rBvxbPELjtG13pQE9/7ZeHRjv/GZjtLOm/FltFtAmttUdtd8P2D3FCsiPJqTMDca/RDvOzBn2c+YnEahms+pnOx76yHqRJ9ZA31PNQuqECCqnrLXlXKlVwos374DgMMY8wpYIjKiHc+xo2acig6nLUoJnvBdfLNzGJdjPwsvWWYKPHY/jMao+BX4zy9fx9IVM75ps7i51sAc0CmUjgZeRdMMtyF8tQfqmcGNuLkQTMsBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gA36rjGQaztJzKACtcCbtTz7Hrsky4bgENUo5JjXWaQ=; b=EjmlyfhxqQ6xmQYo7sLTZ6kHhXAELt8Yqs0y4mkFg3/Znf2P00KWHO0fgF47FyWjyVhWkh9xhvUmi274e1P19dnqJ6DAwTp4zhED+f27JiAxTd51uq9f2BLwwCbvXtkgZ/MQZzQtH/yaRWQBQyKgM2KGT5afvRmnvXr5F2Vg2LDonsUyELpySHs3sOcfzoecMhXgl/IFekVyBs0DibO/3K3yaYlFqMkRBNQUfYTW2QjhloezoQanBq1CI6vLJmqrwd/UkrAsbJdSLyqsPZYxNeHhVn10jN7V4N9Dyiz3yehILcz7SD5jrUxuL/Q27pDD18dGi9wvXTWvmRQd8RtOsw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3439.eurprd04.prod.outlook.com (2603:10a6:803:4::13) by DBBPR04MB7930.eurprd04.prod.outlook.com (2603:10a6:10:1ea::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.30; Mon, 27 Mar 2023 06:28:23 +0000 Received: from VI1PR0402MB3439.eurprd04.prod.outlook.com ([fe80::6802:b2c3:5f12:8f9f]) by VI1PR0402MB3439.eurprd04.prod.outlook.com ([fe80::6802:b2c3:5f12:8f9f%2]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 06:28:23 +0000 From: Chester Lin To: Linus Walleij , Andy Shevchenko Cc: Chester Lin , NXP S32 Linux Team , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ghennadi Procopciuc , Andrei Stefanescu , Radu Pirea , =?utf-8?q?Andreas_F=C3=A4rber?= , Matthias Brugger Subject: [PATCH v5 2/5] pinctrl: s32cc: refactor pin config parsing Date: Mon, 27 Mar 2023 14:27:51 +0800 Message-Id: <20230327062754.3326-3-clin@suse.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230327062754.3326-1-clin@suse.com> References: <20230327062754.3326-1-clin@suse.com> X-ClientProxiedBy: TY2PR06CA0003.apcprd06.prod.outlook.com (2603:1096:404:42::15) To VI1PR0402MB3439.eurprd04.prod.outlook.com (2603:10a6:803:4::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0402MB3439:EE_|DBBPR04MB7930:EE_ X-MS-Office365-Filtering-Correlation-Id: d431e439-dc67-4518-8405-08db2e8c7710 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fA7jQepgrMfM8MyfU8nJceDhqkTAkdTLB9tdjJa9fXjcCa4YDIPws4AcX/k83WeAB7uSHOACLd//FADM1K8pf63NcMpgFaw9sCgOUwvpaspnB4RU5poelxjd1hVYXMI4PqLaW7l69oCTHeescloCyl3Z8i3vKwwPSt2ZJII3tx7K4k1rQBhuZ0n2KoYAn1J2n4awDgssvgI/LsTarJ6z9auzeJ1IBvN2HGcgqhcglr5bzgoqJu/RcuN8d6p0rwnEcZoHVcXnEZt2BYK1C9LWlGDySB8hWaFs7tM+P5RZmE/P5l/I93baTG294q69C2FwEd/xp1WSdMbzBcQLL8EyjgZvSP2prsStzZ2P97X81soqkpV0gdkMJlnPfrUrQDpsXGtIwfj5gu4NT/D88Eeh2kRtNarMY8FrSKNEG2R/XQ0BTlFiNMuo5AI7UUJd2TA9rOoL2UPTmyR9VrNTZE8bZnfl7nw8OnctVXWX+OsPg8Zp3Ek7KeZTCCrTqUuDolYKhrkil1+OXP0Re+EpDOMlk9qD1mMHIVn0D1ctvEc8xymYVjgPUOCu1cV62GCHMl6L X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR0402MB3439.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(39860400002)(376002)(396003)(346002)(366004)(136003)(451199021)(316002)(110136005)(54906003)(478600001)(5660300002)(8936002)(36756003)(86362001)(38100700002)(7416002)(2906002)(4326008)(66556008)(66476007)(8676002)(66946007)(41300700001)(107886003)(6666004)(186003)(6512007)(6506007)(1076003)(26005)(2616005)(83380400001)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SDfMjMR6aOF7O5Z2wnOKJdtJP7c1+EAI8QUqm4M/PpTd7srO1o0phGccIvK1uRfbty7wVayD+QQ5FQjPgqyQW9vILOyv4WszBWPksIHKk4pwiYaO7gzYoyN3NRl8iAYhk+fNuA1GyQwIhcQ4NRUZYAmI9PjPEnEEf9xjYrCIONY0SDZONXefBnGflfRs2XoV/JpQai5lG8ENpPnsv9yDHwrJbFhHFEg4M38K2PfTOvTxbM5NUzol8i+Hi+CoUd48OK1FY5akIOBkPZrDgQ1cTWEgv1Qsvbr7U5Lr7AeqbV1as6/QHEJm1SIay3junkPUsBfUDPf+xH4umR4z+D5T2HX96Okuy9D8/5aksB7zBAl0IyA3YCfpelTomD86e4xX9KK2dFUpXTG0xdN3pVAiHWf6/IA5d30vZU1YE2p/dIn0GgE0J9FI5Dmi2XfZRVhwvY/23lU7hytbY6vfsdqBbcc6gI1qGU4Le1m04hWKuaLfmkTx2qqjbFcvb1EzOVRJhWauWCotQWt3T2DY5e5T/O2KY/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ant-Network-Message-Id: d431e439-dc67-4518-8405-08db2e8c7710 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3439.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 06:28:23.2645 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: FP2k0MtQaWXGakHQiSO9Ecmeb3zd9w7mBBZ370DpmbxTVb1/YN+S25QmtSxX27sq X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7930 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Move common codes into smaller inline functions and remove argument checks that are not actually used by pull up/down bits in the S32 MSCR register. Signed-off-by: Chester Lin Reviewed-by: Andy Shevchenko --- (No change since v3) drivers/pinctrl/nxp/pinctrl-s32cc.c | 52 ++++++++++++++++++----------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c index f698e1a240ef..36f323f87785 100644 --- a/drivers/pinctrl/nxp/pinctrl-s32cc.c +++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c @@ -474,11 +474,38 @@ static int s32_get_slew_regval(int arg) return -EINVAL; } -static int s32_get_pin_conf(enum pin_config_param param, u32 arg, - unsigned int *mask, unsigned int *config) +static inline void s32_pin_set_pull(enum pin_config_param param, + unsigned int *mask, unsigned int *config) { + switch (param) { + case PIN_CONFIG_BIAS_DISABLE: + case PIN_CONFIG_BIAS_HIGH_IMPEDANCE: + *config &= ~(S32_MSCR_PUS | S32_MSCR_PUE); + break; + case PIN_CONFIG_BIAS_PULL_UP: + *config |= S32_MSCR_PUS | S32_MSCR_PUE; + break; + case PIN_CONFIG_BIAS_PULL_DOWN: + *config &= ~S32_MSCR_PUS; + *config |= S32_MSCR_PUE; + break; + default: + return; + } + + *mask |= S32_MSCR_PUS | S32_MSCR_PUE; +} + +static int s32_parse_pincfg(unsigned long pincfg, unsigned int *mask, + unsigned int *config) +{ + enum pin_config_param param; + u32 arg; int ret; + param = pinconf_to_config_param(pincfg); + arg = pinconf_to_config_argument(pincfg); + switch (param) { /* All pins are persistent over suspend */ case PIN_CONFIG_PERSIST_STATE: @@ -508,26 +535,15 @@ static int s32_get_pin_conf(enum pin_config_param param, u32 arg, *config |= S32_MSCR_SRE((u32)ret); *mask |= S32_MSCR_SRE(~0); break; + case PIN_CONFIG_BIAS_DISABLE: case PIN_CONFIG_BIAS_PULL_UP: - if (arg) - *config |= S32_MSCR_PUS; - else - *config &= ~S32_MSCR_PUS; - fallthrough; case PIN_CONFIG_BIAS_PULL_DOWN: - if (arg) - *config |= S32_MSCR_PUE; - else - *config &= ~S32_MSCR_PUE; - *mask |= S32_MSCR_PUE | S32_MSCR_PUS; + s32_pin_set_pull(param, mask, config); break; case PIN_CONFIG_BIAS_HIGH_IMPEDANCE: *config &= ~(S32_MSCR_ODE | S32_MSCR_OBE | S32_MSCR_IBE); *mask |= S32_MSCR_ODE | S32_MSCR_OBE | S32_MSCR_IBE; - fallthrough; - case PIN_CONFIG_BIAS_DISABLE: - *config &= ~(S32_MSCR_PUS | S32_MSCR_PUE); - *mask |= S32_MSCR_PUS | S32_MSCR_PUE; + s32_pin_set_pull(param, mask, config); break; default: return -EOPNOTSUPP; @@ -553,9 +569,7 @@ static int s32_pinconf_mscr_update(struct pinctrl_dev *pctldev, pin_get_name(pctldev, pin_id), num_configs); for (i = 0; i < num_configs; i++) { - ret = s32_get_pin_conf(pinconf_to_config_param(configs[i]), - pinconf_to_config_argument(configs[i]), - &mask, &config); + ret = s32_parse_pincfg(configs[i], &mask, &config); if (ret) return ret; } From patchwork Mon Mar 27 06:27:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chester Lin X-Patchwork-Id: 668407 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08D6BC7619A for ; Mon, 27 Mar 2023 06:29:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232220AbjC0G26 (ORCPT ); Mon, 27 Mar 2023 02:28:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230104AbjC0G25 (ORCPT ); Mon, 27 Mar 2023 02:28:57 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2071.outbound.protection.outlook.com [40.107.20.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39BDB49D9; Sun, 26 Mar 2023 23:28:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I4q4ysG7/8CaUggGYm3nB6eivh6qVH8sYSVy0mr1vpmPtAVt+p3NOEJ7MUDLZTE6N9XvPadeUTtDHMd++GOO+sc0ZloyqsarrYAvkoxY++tEJIQ0f99b9vBcVsX3qEhZxwB9l/cqhS+TnbYuIPHsopw/gCeXL0UqVUmIivqUxjJGkyayDmWNPVNG/LRo2SS+8bNi0yQPFVZoqR/hpzs/X2e5ig/GV0jqGVSScy/E+fZjiCXK1DQ0vj+XyUVa98Pfx+m3UFN2WfEsKKZr1L4EqqOmywAvVRCgocCQooaRIwdpsDgFRATGZSMILFYQufGy5VLwZBlCoAv6kVDbZsVNEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4ZRs/jyzaHHU9yyQ5B/+4/wBwOdzvv9NMFuYlMaN61Y=; b=Krj/hp16fFisPNnhb2nSeF9kZRRKuylroXTEoRnW7k28I8ZeMEkMKafWL2JElB+/kYFGGGayz/kQbs7L5uk4jarZNRH5sUuATafP5yesYEX63I8qcs9ASLB7W+sPrNYu67JFi2T7r6yrdnOGaVnrVGTayVgDYIBt9KA/DJIogTwD5yRxcRrcd5/lBhyD90lBkstwb2SD3ShaOcRJcX8dHYSk04xn+bEz0Yl+9jRK218EDpA0TxkoHDMydcbffEPCDBIMjYtQdquk98YHVmyoaZicu4XFRCsS/zqa3TymMbeIMH5bbP8wZ4kP70K35GFyI3gywsjbe7ZmFZrhelhE2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4ZRs/jyzaHHU9yyQ5B/+4/wBwOdzvv9NMFuYlMaN61Y=; b=0okwNQGduJ1v+RwX/nDowZ9pcY7B4z2CG9d3BjnqKvXRXaM8LQC3lHTnq8QfrZnFouYqrG9yyyMtiDe+E0HWn1cO0HYRcdMa7gW7A6TTd7Nnpea5/Fwqc9KFlIesscN0D5ICM5mMhvh+I4qXrYEcwaLFReERSPfNPZYMv0VxqfhstGMXkW+ExLw3BFIuStqWKUfl9dmNVgB7Viv2/CYCK6mmOmQiUtcbwDozYAAQIsvjKLQ2YOBEGpQcFnXO42XONnPxOy0G2BPsiQudtLI4IMSnNZaOMOlqgB9I+7IENhTHgn251eTCUHW83Cz0GF/JmbSIc/Oi8sq+MqNaNjwTLQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3439.eurprd04.prod.outlook.com (2603:10a6:803:4::13) by DBBPR04MB7930.eurprd04.prod.outlook.com (2603:10a6:10:1ea::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.30; Mon, 27 Mar 2023 06:28:38 +0000 Received: from VI1PR0402MB3439.eurprd04.prod.outlook.com ([fe80::6802:b2c3:5f12:8f9f]) by VI1PR0402MB3439.eurprd04.prod.outlook.com ([fe80::6802:b2c3:5f12:8f9f%2]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 06:28:38 +0000 From: Chester Lin To: Linus Walleij , Andy Shevchenko Cc: Chester Lin , NXP S32 Linux Team , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ghennadi Procopciuc , Andrei Stefanescu , Radu Pirea , =?utf-8?q?Andreas_F=C3=A4rber?= , Matthias Brugger Subject: [PATCH v5 3/5] pinctrl: s32cc: embed generic struct pingroup Date: Mon, 27 Mar 2023 14:27:52 +0800 Message-Id: <20230327062754.3326-4-clin@suse.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230327062754.3326-1-clin@suse.com> References: <20230327062754.3326-1-clin@suse.com> X-ClientProxiedBy: TY2PR06CA0020.apcprd06.prod.outlook.com (2603:1096:404:42::32) To VI1PR0402MB3439.eurprd04.prod.outlook.com (2603:10a6:803:4::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0402MB3439:EE_|DBBPR04MB7930:EE_ X-MS-Office365-Filtering-Correlation-Id: 5bf65ed5-a50f-4429-f32a-08db2e8c7fa8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cHTxKETHY4fJRVrYeciwle8J0/2I8dHTfsAO2IK9E7iX86aarRcL5Go6SusGAK+ARs5+Gp/UCZD8pI9kOICyNQhqiE8cI+ow+KB6+QJGqtropUrCUEtBlhr036UHmTkop7UaX9KDpdUxxxNowTrDPxmff4VOIHPdUNapfm36LupV8oXLhp2BQAUTlEWTW4QUkG8U4cawiVjmFLcljVN+MZ7lGgMbXaMwrn89wARzZqdf38Y0sMzZI9k57K2Z1yeV2k34WbmnMBBdJMXIk6xs3gmiyMkLgxTHHCseUU4UKQNc21sISbE9AvdlxmCZ75dIW2SfUSKSOgvI5q4Nky7E7U9alzK1SZH/Kf2MA8UAOZKWwa8Mtpr7GuHHk063DTHdRnbBmnmwn6zFIE9iCbrRvy6/KRfnzukaQjwbSQBUvO+KlCITRsQ7Ctf8jaUqrHxQ0BdG6I7WZ8sMgNgm9KmpeqxvD40ZBLjLPOwWYpTGwwqqPYRGuUFL/4S6fEHcLooXkEj3oKKFY6s7iiZonEOo+eSatG1hYusTYyk2hkNEZg+RQmMOBVU7mlxHrIyIx+YodgW0wOKqAzRiT+WpiQhwK/2xDpUBX5+y73KxcwGZPDg= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR0402MB3439.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(39860400002)(376002)(396003)(346002)(366004)(136003)(451199021)(316002)(110136005)(54906003)(478600001)(5660300002)(8936002)(36756003)(86362001)(38100700002)(7416002)(2906002)(4326008)(66556008)(66476007)(8676002)(66946007)(41300700001)(107886003)(6666004)(186003)(6512007)(6506007)(1076003)(26005)(2616005)(83380400001)(6486002)(41533002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pqjYKtTgArjJdnupBOoIYAu5f3vstHRTJJ2WIC1E6ChbJpsku6H5ddne3Pkgr6w4gSUTzYRMN1jmiPKcFn5rFHR5tI1GaqcGnSiRTo8npLSX6tawePau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y2f1ds8psSqWst9ZaQgBKz/zv571nnRTHKOpvuL5j5HgrPn99U8sL5VY8Y0cIDwVN4eiq4cK9xJDw+Uv/qV+vXNcmt5vBqsb6LfRHNsti+m5FrmET5CoJvbHO6H6SysLTzArMZrLcwBiV7y3r3536mFtIc1BEiCuyz5izJF/BedFyVfOgDqRs4Z32US8P/v9nCOaZu1MP2f7BIpw2/YaC3RC2dOOxEP94H6+a8UlQ1uxJxUMXaH8l5PpKKseRDEIXRyRPVXi/yCAJDUeEY6svo0PbNBnrmK9KG+pdKe7v1oVs06k8MvLLg8k/IdnbDxwEUwuQLBszzZm0tm7eZqVQdskBl4r5+sgoLShmrnnEfxhLjthVf41h9wC0SEc1uN7AQ= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5bf65ed5-a50f-4429-f32a-08db2e8c7fa8 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3439.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 06:28:37.9197 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nCwRXumwoYj2PnuGY/p5xNT60Us7unrisAaZEtu2ytIx2WWSEXvDpV5wD02jFyjB X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7930 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Use generic data structure to describe pin control groups in S32 SoC family and drop duplicated struct members. Suggested-by: Andy Shevchenko Signed-off-by: Chester Lin Reviewed-by: Andy Shevchenko --- (No change since v3) drivers/pinctrl/nxp/pinctrl-s32.h | 12 ++---- drivers/pinctrl/nxp/pinctrl-s32cc.c | 57 +++++++++++++++-------------- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/drivers/pinctrl/nxp/pinctrl-s32.h b/drivers/pinctrl/nxp/pinctrl-s32.h index 545bf16b988d..850cd668f406 100644 --- a/drivers/pinctrl/nxp/pinctrl-s32.h +++ b/drivers/pinctrl/nxp/pinctrl-s32.h @@ -15,16 +15,12 @@ struct platform_device; /** * struct s32_pin_group - describes an S32 pin group - * @name: the name of this specific pin group - * @npins: the number of pins in this group array, i.e. the number of - * elements in pin_ids and pin_sss so we can iterate over that array - * @pin_ids: an array of pin IDs in this group - * @pin_sss: an array of source signal select configs paired with pin_ids + * @data: generic data describes group name, number of pins, and a pin array in + this group. + * @pin_sss: an array of source signal select configs paired with pin array. */ struct s32_pin_group { - const char *name; - unsigned int npins; - unsigned int *pin_ids; + struct pingroup data; unsigned int *pin_sss; }; diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c index 36f323f87785..e65c88162d7f 100644 --- a/drivers/pinctrl/nxp/pinctrl-s32cc.c +++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c @@ -188,7 +188,7 @@ static const char *s32_get_group_name(struct pinctrl_dev *pctldev, struct s32_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); const struct s32_pinctrl_soc_info *info = ipctl->info; - return info->groups[selector].name; + return info->groups[selector].data.name; } static int s32_get_group_pins(struct pinctrl_dev *pctldev, @@ -198,8 +198,8 @@ static int s32_get_group_pins(struct pinctrl_dev *pctldev, struct s32_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); const struct s32_pinctrl_soc_info *info = ipctl->info; - *pins = info->groups[selector].pin_ids; - *npins = info->groups[selector].npins; + *pins = info->groups[selector].data.pins; + *npins = info->groups[selector].data.npins; return 0; } @@ -314,23 +314,23 @@ static int s32_pmx_set(struct pinctrl_dev *pctldev, unsigned int selector, grp = &info->groups[group]; dev_dbg(ipctl->dev, "set mux for function %s group %s\n", - info->functions[selector].name, grp->name); + info->functions[selector].name, grp->data.name); /* Check beforehand so we don't have a partial config. */ - for (i = 0; i < grp->npins; i++) { - if (s32_check_pin(pctldev, grp->pin_ids[i]) != 0) { + for (i = 0; i < grp->data.npins; i++) { + if (s32_check_pin(pctldev, grp->data.pins[i]) != 0) { dev_err(info->dev, "invalid pin: %u in group: %u\n", - grp->pin_ids[i], group); + grp->data.pins[i], group); return -EINVAL; } } - for (i = 0, ret = 0; i < grp->npins && !ret; i++) { - ret = s32_regmap_update(pctldev, grp->pin_ids[i], + for (i = 0, ret = 0; i < grp->data.npins && !ret; i++) { + ret = s32_regmap_update(pctldev, grp->data.pins[i], S32_MSCR_SSS_MASK, grp->pin_sss[i]); if (ret) { dev_err(info->dev, "Failed to set pin %u\n", - grp->pin_ids[i]); + grp->data.pins[i]); return ret; } } @@ -606,8 +606,8 @@ static int s32_pconf_group_set(struct pinctrl_dev *pctldev, unsigned int selecto int i, ret; grp = &info->groups[selector]; - for (i = 0; i < grp->npins; i++) { - ret = s32_pinconf_mscr_update(pctldev, grp->pin_ids[i], + for (i = 0; i < grp->data.npins; i++) { + ret = s32_pinconf_mscr_update(pctldev, grp->data.pins[i], configs, num_configs); if (ret) return ret; @@ -641,9 +641,9 @@ static void s32_pinconf_group_dbg_show(struct pinctrl_dev *pctldev, seq_puts(s, "\n"); grp = &info->groups[selector]; - for (i = 0; i < grp->npins; i++) { - name = pin_get_name(pctldev, grp->pin_ids[i]); - ret = s32_regmap_read(pctldev, grp->pin_ids[i], &config); + for (i = 0; i < grp->data.npins; i++) { + name = pin_get_name(pctldev, grp->data.pins[i]); + ret = s32_regmap_read(pctldev, grp->data.pins[i], &config); if (ret) return; seq_printf(s, "%s: 0x%x\n", name, config); @@ -736,6 +736,7 @@ static int s32_pinctrl_parse_groups(struct device_node *np, const __be32 *p; struct device *dev; struct property *prop; + unsigned int *pins, *sss; int i, npins; u32 pinmux; @@ -744,38 +745,38 @@ static int s32_pinctrl_parse_groups(struct device_node *np, dev_dbg(dev, "group: %pOFn\n", np); /* Initialise group */ - grp->name = np->name; + grp->data.name = np->name; npins = of_property_count_elems_of_size(np, "pinmux", sizeof(u32)); if (npins < 0) { dev_err(dev, "Failed to read 'pinmux' property in node %s.\n", - grp->name); + grp->data.name); return -EINVAL; } if (!npins) { - dev_err(dev, "The group %s has no pins.\n", grp->name); + dev_err(dev, "The group %s has no pins.\n", grp->data.name); return -EINVAL; } - grp->npins = npins; + grp->data.npins = npins; - grp->pin_ids = devm_kcalloc(info->dev, grp->npins, - sizeof(unsigned int), GFP_KERNEL); - grp->pin_sss = devm_kcalloc(info->dev, grp->npins, - sizeof(unsigned int), GFP_KERNEL); - if (!grp->pin_ids || !grp->pin_sss) + pins = devm_kcalloc(info->dev, npins, sizeof(*pins), GFP_KERNEL); + sss = devm_kcalloc(info->dev, npins, sizeof(*sss), GFP_KERNEL); + if (!pins || !sss) return -ENOMEM; i = 0; of_property_for_each_u32(np, "pinmux", prop, p, pinmux) { - grp->pin_ids[i] = get_pin_no(pinmux); - grp->pin_sss[i] = get_pin_func(pinmux); + pins[i] = get_pin_no(pinmux); + sss[i] = get_pin_func(pinmux); - dev_dbg(info->dev, "pin-id: 0x%x, sss: 0x%x", - grp->pin_ids[i], grp->pin_sss[i]); + dev_dbg(info->dev, "pin: 0x%x, sss: 0x%x", pins[i], sss[i]); i++; } + grp->data.pins = pins; + grp->pin_sss = sss; + return 0; } From patchwork Mon Mar 27 06:27:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chester Lin X-Patchwork-Id: 667670 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E97B5C7619A for ; Mon, 27 Mar 2023 06:29:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231950AbjC0G3V (ORCPT ); Mon, 27 Mar 2023 02:29:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232071AbjC0G3U (ORCPT ); Mon, 27 Mar 2023 02:29:20 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2071.outbound.protection.outlook.com [40.107.20.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82D6346BC; Sun, 26 Mar 2023 23:28:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AmWrdSz18eS+akcJ+Ad2W1rHiMuZP48RnLe5Qhs3kho7apUhQS+BGU2E+zOp6WheRHuMOqC2RD8i4EzNX71K84iCEof8igrfiCQdNN+b7x+GPBV6W2siljjc3oQDIz/N1Fbg6qAl+DrlcnqLEHPOR4KMHFWtWe8MbjQ1lTZ0M0DLfku+/LmiwrSV/fkQfKyOCxJUBlmcbF0UVg6uT4CyHK+svgbeymIFRbqaG7kQSf6VAjjf+RnVaXFPxulTWX0KgkjimKziRc819lng+67nPr7IRJuJsiEXhywgEe+Vi/2LMqGKsjtQDIW0zbPNwPr3CpjBlcEoI0ZuuQfFHdVCmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fN4oSk/fg6PFOW23zvTHHTxM97j8i0UUQgD086d68p0=; b=DwZf4fRSizcXMmXEl32sLHKi5zYx7XE5zxker9q12N3zTzBJm8WAZlcrtY35KmHCXC56J/u8VI9GtWtlIP4R1f9XsSyQJIUo/Az6+XDNYgoOMnVzEJmIWPY8prTjqMQWIYOdPEsdBZqa6V2WQ7GQL4bNXiF0pzFm/5UBHQjU1fFtQeoTy8iyvof09BrKmomcOK1Gw7WtRrGzHuLv9fo72eBqc0QoYUUdcLkkmrzhK3F3DRf/5NczcxPmTRu39ymRIl5rojxzDRZ7QCErAP31ID4eHKTteRDYJ1yjafRtRifspwNd/0HjWJXLw2GKofyKuEFgia8ELNiYQok9PVulYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fN4oSk/fg6PFOW23zvTHHTxM97j8i0UUQgD086d68p0=; b=RulfTfXoQRGsdRYjSVXKnI12GeFriDIBxz5xgCGbHFtk4uvH+wajeNyNLis6TWmb+Tf7de9DSIH7ar6SEWPqipWDHIYHyNpAPMcEpuetkxS5NxzV3paANbq5nC/VHVaj7Lz8mlIPzNSqWLwtCxWzwCW13pGTY4Mke2CLtP6ZGsOV23JSYhIEktRXqnMQI1v3yWWhDz2Qz4AX7Un80w4xc8zJ5xuemtNv/g/o2eebJ5bYjP88vyjKphKKyICOhJUwaKh8QYwqWP8kF8avQ03WwOQzB/zz33ZLHGAV1oCNU9PSgSegL+d3n2nzNk8m9b11t4JlmP2uSpAQa1/Jw4KSmg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3439.eurprd04.prod.outlook.com (2603:10a6:803:4::13) by DBBPR04MB7930.eurprd04.prod.outlook.com (2603:10a6:10:1ea::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.30; Mon, 27 Mar 2023 06:28:47 +0000 Received: from VI1PR0402MB3439.eurprd04.prod.outlook.com ([fe80::6802:b2c3:5f12:8f9f]) by VI1PR0402MB3439.eurprd04.prod.outlook.com ([fe80::6802:b2c3:5f12:8f9f%2]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 06:28:47 +0000 From: Chester Lin To: Linus Walleij , Andy Shevchenko Cc: Chester Lin , NXP S32 Linux Team , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ghennadi Procopciuc , Andrei Stefanescu , Radu Pirea , =?utf-8?q?Andreas_F=C3=A4rber?= , Matthias Brugger Subject: [PATCH v5 4/5] pinctrl: s32cc: Use generic struct data to describe pin function Date: Mon, 27 Mar 2023 14:27:53 +0800 Message-Id: <20230327062754.3326-5-clin@suse.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230327062754.3326-1-clin@suse.com> References: <20230327062754.3326-1-clin@suse.com> X-ClientProxiedBy: TY2PR06CA0004.apcprd06.prod.outlook.com (2603:1096:404:42::16) To VI1PR0402MB3439.eurprd04.prod.outlook.com (2603:10a6:803:4::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0402MB3439:EE_|DBBPR04MB7930:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ce31f70-f071-4686-55fa-08db2e8c857d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wpNhkx2Wg+60O6Nje15ghYLqqjDUaMXlSviXiLkFiA3M1PyR7G2mvcVD85SLSKIe0SVxhmm3opF9AVc3v6d3btSTaIOlOV7GeVogswlP7uNQxCXNtKSs+c1FR97151mYuFdFs31WHI1cnB3+YmrL3I9FXNx3WDjIMKHxG1igY17TgM6G9bCNFc8QW7Mz02kDdlcmL05ZxQrHFRcJny2NFSayuwWUOv/bpMX2X9vOkdQFZigChaEkcJHZi/oPCTdayk1k7DOVHdAyS9Nd+1NzLt+7VC/tIdXuTpp0kNWRWhh8FdDGAv7eoaipLtvrA/0mB16TmUIwPNDxhPZ5gqCVP5JL0QAH0BRzX0oGl2ZfljkGhWDT3yDCeSU1FOJeWBA7cgn7gpnjb10ZxbKX/8XfT7m7oej1pyhPjWphksMFaS2ay+Gz/e7Akhm8ts5Z7LflpYXhRoHHb09mynUM4VyANBLugrABYvqVbNgA9yt/lrVLnnqX3V7/g2aKgWLzQU+rA/vUd6XOOtnZLOYr4VUsKCCCqibr/rqTZzp1uXWz3I2BDtpQ82tPT2kcZDwEzWuKyEEP6xGf7Q2fN9unHcwapcKkZyTDrCMqOWNY31FtOuY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR0402MB3439.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(39860400002)(376002)(396003)(346002)(366004)(136003)(451199021)(316002)(110136005)(54906003)(478600001)(5660300002)(8936002)(36756003)(86362001)(38100700002)(7416002)(2906002)(4326008)(66556008)(66476007)(8676002)(66946007)(41300700001)(107886003)(6666004)(186003)(6512007)(6506007)(1076003)(26005)(2616005)(83380400001)(6486002)(41533002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: y+pAZPUX+WHnikZ1eTtjmunUzFPVJ9u2GDcO5FH1msr1a9plv/s9CHeJ6HwpqdMT74gMFOojN23PlnC8WI0Pk4839cp/B3Z0DqCEszHI9uwLwp1YtPCqGMqdMxaSSUaAZCeGNuS7dtOx3ImDlrDgBpqB4vEEK3kIg+7vE448g2cbwQn6uPapcBSWUGdORca5O5K+k90qzXsSU+m8XpuRvTzhSqBHIbIctFb5VjSrHzN6XyJLLCLMg8vmKA5/o0tkpZq9LRJDEpyKCCO10zYEv38JPuDaGzxHuhzjPC3gETvCzZWh9fomfbmiP3zYdCi9VU07ZUoUN8R/1xqXoKYQhX2nG4/y0AINH+5nKxUXP15S8pFg8mbd5bkQ/Ph6LhipVVpkN1hT7WN+2/GWymjxv7BYJNhFOQNITnrayj9cMIGi98jHnL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0cHOmJ+GxxUj3gxdNE6WzyyQI88iQi6YET9piVQ/NPfiDuzMm0XB5E0= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ce31f70-f071-4686-55fa-08db2e8c857d X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3439.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 06:28:47.6377 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5QJqKXnsyNCiPe5k4Va6vf5PSPNenJoSoUHo8kq6sb4epe0QrscWrDsJrYvgTT2/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7930 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Replace struct s32_pmx_func with generic struct pinfunction since they have the same data fields. Suggested-by: Andy Shevchenko Signed-off-by: Chester Lin Reviewed-by: Andy Shevchenko --- (No change since v3) drivers/pinctrl/nxp/pinctrl-s32.h | 14 +------------- drivers/pinctrl/nxp/pinctrl-s32cc.c | 18 +++++++++++------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/drivers/pinctrl/nxp/pinctrl-s32.h b/drivers/pinctrl/nxp/pinctrl-s32.h index 850cd668f406..2f7aecd462e4 100644 --- a/drivers/pinctrl/nxp/pinctrl-s32.h +++ b/drivers/pinctrl/nxp/pinctrl-s32.h @@ -24,18 +24,6 @@ struct s32_pin_group { unsigned int *pin_sss; }; -/** - * struct s32_pmx_func - describes S32 pinmux functions - * @name: the name of this specific function - * @groups: corresponding pin groups - * @num_groups: the number of groups - */ -struct s32_pmx_func { - const char *name; - const char **groups; - unsigned int num_groups; -}; - /** * struct s32_pin_range - pin ID range for each memory region. * @start: start pin ID @@ -52,7 +40,7 @@ struct s32_pinctrl_soc_info { unsigned int npins; struct s32_pin_group *groups; unsigned int ngroups; - struct s32_pmx_func *functions; + struct pinfunction *functions; unsigned int nfunctions; unsigned int grp_index; const struct s32_pin_range *mem_pin_ranges; diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c index e65c88162d7f..8373468719b6 100644 --- a/drivers/pinctrl/nxp/pinctrl-s32cc.c +++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c @@ -364,7 +364,7 @@ static int s32_pmx_get_groups(struct pinctrl_dev *pctldev, const struct s32_pinctrl_soc_info *info = ipctl->info; *groups = info->functions[selector].groups; - *num_groups = info->functions[selector].num_groups; + *num_groups = info->functions[selector].ngroups; return 0; } @@ -785,8 +785,9 @@ static int s32_pinctrl_parse_functions(struct device_node *np, u32 index) { struct device_node *child; - struct s32_pmx_func *func; + struct pinfunction *func; struct s32_pin_group *grp; + const char **groups; u32 i = 0; int ret = 0; @@ -796,18 +797,19 @@ static int s32_pinctrl_parse_functions(struct device_node *np, /* Initialise function */ func->name = np->name; - func->num_groups = of_get_child_count(np); - if (func->num_groups == 0) { + func->ngroups = of_get_child_count(np); + if (func->ngroups == 0) { dev_err(info->dev, "no groups defined in %pOF\n", np); return -EINVAL; } - func->groups = devm_kcalloc(info->dev, func->num_groups, + + groups = devm_kcalloc(info->dev, func->ngroups, sizeof(*func->groups), GFP_KERNEL); - if (!func->groups) + if (!groups) return -ENOMEM; for_each_child_of_node(np, child) { - func->groups[i] = child->name; + groups[i] = child->name; grp = &info->groups[info->grp_index++]; ret = s32_pinctrl_parse_groups(child, grp, info); if (ret) @@ -815,6 +817,8 @@ static int s32_pinctrl_parse_functions(struct device_node *np, i++; } + func->groups = groups; + return 0; } From patchwork Mon Mar 27 06:27:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chester Lin X-Patchwork-Id: 668406 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFEB2C761AF for ; Mon, 27 Mar 2023 06:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232269AbjC0G3X (ORCPT ); Mon, 27 Mar 2023 02:29:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232224AbjC0G3V (ORCPT ); Mon, 27 Mar 2023 02:29:21 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2050.outbound.protection.outlook.com [40.107.7.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C2474C32; Sun, 26 Mar 2023 23:29:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OA/7qBbr7h7emEUOYGkaf7gmG78FOU+GsiHAM7/kHS1CLslTZ38aBWOUM+GNv/wbar7YgViBRx/TvVE+lExwGUIUOdi9ELWv5pTb/pvtwskPIKCYFSfPJdE993v9D+VrpPF/C08O7NH/Cy6IDpQpUMhLIXFthkT7Uo2VyxQjSBC0/Xri1rpeRpyXlC1o1dI/3u30B7v2NjmmSzw2FN8xrMlhbCGytBksJx2hAQ6caA+huHwMytWnu8HNHQ9qmMYYZirDkJ5UM78K5qhl84regq2o4D/7p0BoX4KjYbzNVn8oBZWhUrWXAHUODSFM6ydmX4XhviZVz7DPARPA+eDlbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rpCrTRKeIxUTc7SqgtAcE2DoOoAkUxF6EhYVABTXIo0=; b=KW4VHfi0H0gwP40I7tmKuWD0c9SFo/NG7B4XQKgC4ysnQRkiDA2Su6BcYWe9KISDjFHgl5WFR+oze5SWJkD2QU48BZoGh4M2H1fZohHa0W6FSZV+a55B5HVRvHR5IMOUrqYfIA+k/4rPZtc6t5UEjqjJYqPymKbv+d6AyCReIq77vQhMP0LIZEIsLeOt1DuY0amxjQEdUJY3B/cYyVX+CBxR1zU7IdH7ZODFT7Sz6/W22l5NkRDERu6GvZnkjxNTtA4bw6/liHlbSTbOuXtPCuc7VW5zSioL6z+M0kd77Da/l4c41nxnKIyAaLjybWeE5FrJfMPrz1bQjj+7wjI0WA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rpCrTRKeIxUTc7SqgtAcE2DoOoAkUxF6EhYVABTXIo0=; b=KCDB1z2KdLo+AfUDDqgh9OZItUrSvJQeY7oMY+da/Z/ZoSZ2hU4VF2K28d2Rj4buo3iEUmaPWDjUHHRrN4DlCOBiTpKuQUrKbxXmONm1togFniWHtvckSJCpT/+ubQ2U4tMp+SIAwW0eeRE0a7I+seouPZ58zEY/qqlzTLqfLdddUFsHyuhe0OZ0Z5vPYVPBeIluGRIWM2W77X6QjmkX7JAJtzgTQagN2sMCzj8dyJRb53jUE9k7V/C+PbaODdSXtvnOFq3jtXaCLCXC3YQjvW1nr2mZJR6ikYcghkStkNgdwqwi9wh/m+owoyabNchqHnUEXbTCjFt4p8gyThIuFg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3439.eurprd04.prod.outlook.com (2603:10a6:803:4::13) by DU2PR04MB8982.eurprd04.prod.outlook.com (2603:10a6:10:2e1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.30; Mon, 27 Mar 2023 06:28:57 +0000 Received: from VI1PR0402MB3439.eurprd04.prod.outlook.com ([fe80::6802:b2c3:5f12:8f9f]) by VI1PR0402MB3439.eurprd04.prod.outlook.com ([fe80::6802:b2c3:5f12:8f9f%2]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 06:28:56 +0000 From: Chester Lin To: Linus Walleij , Andy Shevchenko Cc: Chester Lin , NXP S32 Linux Team , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ghennadi Procopciuc , Andrei Stefanescu , Radu Pirea , =?utf-8?q?Andreas_F=C3=A4rber?= , Matthias Brugger Subject: [PATCH v5 5/5] pinctrl: s32: separate const device data from struct s32_pinctrl_soc_info Date: Mon, 27 Mar 2023 14:27:54 +0800 Message-Id: <20230327062754.3326-6-clin@suse.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230327062754.3326-1-clin@suse.com> References: <20230327062754.3326-1-clin@suse.com> X-ClientProxiedBy: TY2PR06CA0008.apcprd06.prod.outlook.com (2603:1096:404:42::20) To VI1PR0402MB3439.eurprd04.prod.outlook.com (2603:10a6:803:4::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0402MB3439:EE_|DU2PR04MB8982:EE_ X-MS-Office365-Filtering-Correlation-Id: 25fadcd5-25a7-4353-d142-08db2e8c8b07 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W7wEADk2ck0PtKoTEjlo/7HbOqSuXuTOJGgFNRXrjvNZJfJm4RJC9yjnIRSVt6BLacXWmEJP1ItorbgiEFKXUBzLfB4oPHc9gwwdcvEJ7wn2Z4iyquxK/Z5dKoSXgbouSafLg10kt83Up0yTcuTiWbP+6M74SjA0NqMK2G8aK5tlf/ykAxp82hLaML/Y4+9G4RJcU85knWh247GUn1sG+OehgpXUhjgN9QKQh1vRcIjQFcKfX42WUROhnUhvXedLqHH9UN0A+V97M70BLgPDFljhTtF5q3dtO31s+p51zVVEhlJuM+wcQjsVxsbJFNV5qEZLgF1+ESGeg2GgPuzMh0NcA4tRlU9CX32B8an7nV13FV+aaEHcuc5Ule7PDvcqr6u9o4Ek8aLYWhF/aGpM7KSCVtVH/BxtWjFLEz30/3uvJAk2aUHPnkoQG0RDh09V8IIw8CP0q88u7z2Cyf/cH1GnCY7YjrA+8j6c5fL3YeFgaICtSUaPQApclR2TWPrErGLFnLixL2lAnObknFRX/rGoBKA7CSaKZ+8pvnPH+gFBVga4rSGFVltmbjqWUDxA X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR0402MB3439.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(39860400002)(376002)(396003)(346002)(366004)(136003)(451199021)(316002)(110136005)(54906003)(478600001)(5660300002)(8936002)(36756003)(86362001)(38100700002)(7416002)(2906002)(4326008)(66556008)(66476007)(8676002)(66946007)(41300700001)(107886003)(186003)(6512007)(6506007)(1076003)(26005)(2616005)(83380400001)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lyEXe2g40nGxfXsx5l2olvu5rowNCmMOvbgBRdN5R3k5iF1f+M3zOdjtMbSVDr/OsY34P8lsofqp/ur8iUnipM8ET+e4AXChHknSIe1UTWnW+wjN4UG8N0FbB1HCc8frvbI09SqFn64XHsNB7eVnR9z27PpH2fMwbkkELX1xijxszUGQEWCRJOXKXm8vrs33NgKHgQqNHu7CJBqhQ+96DNXvoFedVtGvmdZxMKGQkX10YPqlTDwT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FSvfNWdbLNAuv4QRtlddjaePHQu4CJ9yNJYpw8RAYooB7Le3zyrgLLhoC87O44fLl9UaO7/ZxXVwnKCHrJ/Ph1onuCW2drkcRBZPAsuXbeooy4hrRF/xvUlHh5zaoaIN3UPkpmAl04cb1Na57SeDvKgmSVkC9agn1OBJz9NPSYGx0ub5g9v2p9xXUAObU3QUqTJ2282KSUtGBfLyIVF5oF2B0FVUUyt9KY/I45EiA= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25fadcd5-25a7-4353-d142-08db2e8c8b07 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3439.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 06:28:56.8088 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5fCJgXvtS2CwO/YXpJSb7fo2/kWf0Z6QnAp6RzEhSIU6ksyTLMoFp2+oHCJQH56N X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8982 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The .data field in struct of_device_id is used as a const member so it's inappropriate to attach struct s32_pinctrl_soc_info with of_device_id because some members in s32_pinctrl_soc_info need to be filled by pinctrl-s32cc at runtime. For this reason, struct s32_pinctrl_soc_info must be allocated in pinctrl-s32cc and then create a new struct s32_pinctrl_soc_data in order to represent const .data in of_device_id. To combine these two structures, a s32_pinctrl_soc_data pointer is introduced in s32_pinctrl_soc_info. Besides, use of_device_get_match_data() instead of of_match_device() since the driver only needs to retrieve the .data from of_device_id. Suggested-by: Andy Shevchenko Signed-off-by: Chester Lin Reviewed-by: Andy Shevchenko --- Changes in v5: - Remove unnecessary (void *) type casting found in pinctrl-s32g2. Changes in v4: - Retrieve the matched device data by calling of_device_get_match_data() and remove unnecessary type casting. (Merged from the previous v3 series [PATCH v3 1/6]) drivers/pinctrl/nxp/pinctrl-s32.h | 14 +++++++++----- drivers/pinctrl/nxp/pinctrl-s32cc.c | 30 +++++++++++++++++------------ drivers/pinctrl/nxp/pinctrl-s32g2.c | 14 +++++--------- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/drivers/pinctrl/nxp/pinctrl-s32.h b/drivers/pinctrl/nxp/pinctrl-s32.h index 2f7aecd462e4..add3c77ddfed 100644 --- a/drivers/pinctrl/nxp/pinctrl-s32.h +++ b/drivers/pinctrl/nxp/pinctrl-s32.h @@ -34,24 +34,28 @@ struct s32_pin_range { unsigned int end; }; -struct s32_pinctrl_soc_info { - struct device *dev; +struct s32_pinctrl_soc_data { const struct pinctrl_pin_desc *pins; unsigned int npins; + const struct s32_pin_range *mem_pin_ranges; + unsigned int mem_regions; +}; + +struct s32_pinctrl_soc_info { + struct device *dev; + const struct s32_pinctrl_soc_data *soc_data; struct s32_pin_group *groups; unsigned int ngroups; struct pinfunction *functions; unsigned int nfunctions; unsigned int grp_index; - const struct s32_pin_range *mem_pin_ranges; - unsigned int mem_regions; }; #define S32_PINCTRL_PIN(pin) PINCTRL_PIN(pin, #pin) #define S32_PIN_RANGE(_start, _end) { .start = _start, .end = _end } int s32_pinctrl_probe(struct platform_device *pdev, - struct s32_pinctrl_soc_info *info); + const struct s32_pinctrl_soc_data *soc_data); int s32_pinctrl_resume(struct device *dev); int s32_pinctrl_suspend(struct device *dev); #endif /* __DRIVERS_PINCTRL_S32_H */ diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c index 8373468719b6..41e024160f36 100644 --- a/drivers/pinctrl/nxp/pinctrl-s32cc.c +++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c @@ -106,7 +106,7 @@ s32_get_region(struct pinctrl_dev *pctldev, unsigned int pin) { struct s32_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); const struct s32_pin_range *pin_range; - unsigned int mem_regions = ipctl->info->mem_regions; + unsigned int mem_regions = ipctl->info->soc_data->mem_regions; unsigned int i; for (i = 0; i < mem_regions; i++) { @@ -688,8 +688,8 @@ int s32_pinctrl_suspend(struct device *dev) int ret; unsigned int config; - for (i = 0; i < info->npins; i++) { - pin = &info->pins[i]; + for (i = 0; i < info->soc_data->npins; i++) { + pin = &info->soc_data->pins[i]; if (!s32_pinctrl_should_save(ipctl, pin->number)) continue; @@ -713,8 +713,8 @@ int s32_pinctrl_resume(struct device *dev) struct s32_pinctrl_context *saved_context = &ipctl->saved_context; int ret, i; - for (i = 0; i < info->npins; i++) { - pin = &info->pins[i]; + for (i = 0; i < info->soc_data->npins; i++) { + pin = &info->soc_data->pins[i]; if (!s32_pinctrl_should_save(ipctl, pin->number)) continue; @@ -831,7 +831,7 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev, struct resource *res; struct regmap *map; void __iomem *base; - int mem_regions = info->mem_regions; + unsigned int mem_regions = info->soc_data->mem_regions; int ret; u32 nfuncs = 0; u32 i = 0; @@ -869,7 +869,7 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev, } ipctl->regions[i].map = map; - ipctl->regions[i].pin_range = &info->mem_pin_ranges[i]; + ipctl->regions[i].pin_range = &info->soc_data->mem_pin_ranges[i]; } nfuncs = of_get_child_count(np); @@ -904,20 +904,26 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev, } int s32_pinctrl_probe(struct platform_device *pdev, - struct s32_pinctrl_soc_info *info) + const struct s32_pinctrl_soc_data *soc_data) { struct s32_pinctrl *ipctl; int ret; struct pinctrl_desc *s32_pinctrl_desc; + struct s32_pinctrl_soc_info *info; #ifdef CONFIG_PM_SLEEP struct s32_pinctrl_context *saved_context; #endif - if (!info || !info->pins || !info->npins) { + if (!soc_data || !soc_data->pins || !soc_data->npins) { dev_err(&pdev->dev, "wrong pinctrl info\n"); return -EINVAL; } + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + info->soc_data = soc_data; info->dev = &pdev->dev; /* Create state holders etc for this driver */ @@ -938,8 +944,8 @@ int s32_pinctrl_probe(struct platform_device *pdev, return -ENOMEM; s32_pinctrl_desc->name = dev_name(&pdev->dev); - s32_pinctrl_desc->pins = info->pins; - s32_pinctrl_desc->npins = info->npins; + s32_pinctrl_desc->pins = info->soc_data->pins; + s32_pinctrl_desc->npins = info->soc_data->npins; s32_pinctrl_desc->pctlops = &s32_pctrl_ops; s32_pinctrl_desc->pmxops = &s32_pmx_ops; s32_pinctrl_desc->confops = &s32_pinconf_ops; @@ -960,7 +966,7 @@ int s32_pinctrl_probe(struct platform_device *pdev, #ifdef CONFIG_PM_SLEEP saved_context = &ipctl->saved_context; saved_context->pads = - devm_kcalloc(&pdev->dev, info->npins, + devm_kcalloc(&pdev->dev, info->soc_data->npins, sizeof(*saved_context->pads), GFP_KERNEL); if (!saved_context->pads) diff --git a/drivers/pinctrl/nxp/pinctrl-s32g2.c b/drivers/pinctrl/nxp/pinctrl-s32g2.c index d9f3ff6794ea..4d01e9a2a23e 100644 --- a/drivers/pinctrl/nxp/pinctrl-s32g2.c +++ b/drivers/pinctrl/nxp/pinctrl-s32g2.c @@ -721,7 +721,7 @@ static const struct s32_pin_range s32_pin_ranges_siul2[] = { S32_PIN_RANGE(942, 1007), }; -static struct s32_pinctrl_soc_info s32_pinctrl_info = { +static struct s32_pinctrl_soc_data s32_pinctrl_data = { .pins = s32_pinctrl_pads_siul2, .npins = ARRAY_SIZE(s32_pinctrl_pads_siul2), .mem_pin_ranges = s32_pin_ranges_siul2, @@ -730,9 +730,8 @@ static struct s32_pinctrl_soc_info s32_pinctrl_info = { static const struct of_device_id s32_pinctrl_of_match[] = { { - .compatible = "nxp,s32g2-siul2-pinctrl", - .data = (void *) &s32_pinctrl_info, + .data = &s32_pinctrl_data, }, { /* sentinel */ } }; @@ -740,14 +739,11 @@ MODULE_DEVICE_TABLE(of, s32_pinctrl_of_match); static int s32g_pinctrl_probe(struct platform_device *pdev) { - const struct of_device_id *of_id = - of_match_device(s32_pinctrl_of_match, &pdev->dev); + const struct s32_pinctrl_soc_data *soc_data; - if (!of_id) - return -ENODEV; + soc_data = of_device_get_match_data(&pdev->dev); - return s32_pinctrl_probe - (pdev, (struct s32_pinctrl_soc_info *) of_id->data); + return s32_pinctrl_probe(pdev, soc_data); } static const struct dev_pm_ops s32g_pinctrl_pm_ops = {