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: 75226 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1307278vqo; Sun, 26 Mar 2023 23:29:53 -0700 (PDT) X-Google-Smtp-Source: AKy350aaVt24VpII4xpNCIhHXszivS56fDZgCjJ6iXA7+qBxzMZpSc8K561ktaNMGG3JFzc911cn X-Received: by 2002:a17:902:cad1:b0:1a0:50bd:31a8 with SMTP id y17-20020a170902cad100b001a050bd31a8mr9388972pld.26.1679898592746; Sun, 26 Mar 2023 23:29:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679898592; cv=pass; d=google.com; s=arc-20160816; b=OdRkLR7IAiz2mgASqjTMRxCkfy8ISnG849kwqEB36Epcr//6jPsSfvu7eO0ENTl9y/ hYeB/tOb9ZAFvQz4J83ZtApACt+9JQQOuG2VT9HckHAAru+sh8hdk2e8Cw4pR/rl8Twa C16/1IwTIbhy2zF5nAtJnjkoKvnAnragM1NyOyUY7DSPoQWtjY2Q7kWAyDROqUKFnpi9 Ni4VwAdsaO+2tXFZV2rvKuphskEhP3z5WF+CE2NhQJ4elHB1fJ5yjlVYou00UHpeUlgb mbaTDNtJJ7fgnJrDFzKWOWjd3NThU7lfRSFONp4bnaPLybIMbvTODqa9iqfRFhgkcPuc 5zOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UvLq29R3cJdMNhrDZYSjsggrvLxGzA+VlJIrGEgigSA=; b=xaoQXShLg7ahx8a5470no4PqCPvz/MpHvXqp4i8eBTJkHdGIkCfr/ALykebOENrHcy XEOWdmkoaU+rY+xeHEzBxClQZvV21upLEHP4XncnbFnutMLedZ/ENCRtKITMgCyo6RGM Csv4baNxzxUL9AFE769mhNRkjSHIBGqMpXaZdCwsIH5qOpWgtgj5BgBUyk3BmvhAWyVg as23vncZBjpVVgoBkCcqS2CQ5oZojXi/B2hhO39NB6NLPrt8T39Ez0WO0pMcYUylocKD hUMUBzm07zG0eh5dizp2r3Nm8D8810hKUmzLb0NAJMmJLhnXXXeTSBTRrR6k9UhaETaE Tj+A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=selector1 header.b=OEVfaKAc; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e13-20020a630f0d000000b0050bc7a9f717si27576589pgl.679.2023.03.26.23.29.40; Sun, 26 Mar 2023 23:29:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=selector1 header.b=OEVfaKAc; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229462AbjC0G2X (ORCPT + 99 others); Mon, 27 Mar 2023 02:28:23 -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+SqNdFFZWa8PrFrFbu/JtPULA+pOsG45MZXMVLqStT1EbGQVKrPAjwhGvKQ9K2rf7IANT/MMmSGL5n0vP4dlSaP+gek6sOFfpKm0o1FwDM/RPoWdquu9u/ttyBqarwWj9jyn9uxWKSQvKvE/KWFrxH90MI+mYZHJPxp0Y/7yLu7Y1TJedX9N7aZojU5NN1IP0baRsBHXXTQDUbLU3AJHwJZsWCSQTKzp8Zqee2RiDgYULgawRQolGWzsRAGF/y29n6zxxnrOa8xGs0vb8990A0Jgcu6eDBVLRtVNpbsKGDKyIK3biYXgWQzwMgCbD0r2RtgxH7SGDv8tMnZX0/3XurEqxxoygbzcyftfA7ljAsK9CSsgioTePr+QS8+YI7XekmCmrfirAkUeHW7i1aivjuiEEiI8ghSsojgremLVAoD6cA7kotdwXKJmTT/vaSrz4NhYVrDKkmdUEUPu93i3vkd1EGy36cT/+yaIGgVGfnlMcOW3zM4nJjLwmDvPMmOXxCJaRc9uZv1HoF3n6e/TvLKaKHNEc2dqswhk7XQKLVfZZNm8KS78v+Da1jmXJ5Nyyw3sn9zg8gLZvXEeMbP26qOmZv7vfA3I9GzRpD62EWrT1MIbT0SCHavKeDf8+NttK5Bzgfi3qAl7E4q5XhSLPHbH4S0W4EXfa7oHMNro3CDUoO77+9Qy/52BR6cbQqMjJo+vIHpglhN+2vGBaVYJp9OV9Lm+hII3OlJLbSoC/1xjpZnyB5saVtEh5+0AD+suoexoIAL+j2Hun3ypBXDCLlSwxrtnuxV6VzdXH+Rj6XiKkRDMjyoS16FLyCuy0h2JJ3nCgjAz+CPYyCu2VizIgdkBizUNKZNh7UPUThk3u5mulL+H5Y0fgMQWkJFyetkV27ZPN/Ypo1GMOSuZ11IXwukBcV12WqjxndYCOTwC6yHNKVGbI01MPfjiAOylx28ECC0m0H6N7ncXsBppbarF/f6NJurdvUxwd3IzdTDvIYMetB5WCBncz5Y4a90CwRLTFbBQ2mmiHKEsGaY6iKjaq6Qm7HEu0noKdhli3d6vHsOptGqRGMPxig4x8YcZ9u+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 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761501346659189828?= X-GMAIL-MSGID: =?utf-8?q?1761501346659189828?= 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: 75228 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1313629vqo; Sun, 26 Mar 2023 23:48:38 -0700 (PDT) X-Google-Smtp-Source: AKy350ZzPLrT53ucBqXMUL/l9naiy/FBieTWqfQKjf60UiMQEfSYRIYMrqX6OY0ifoZKWq9R+h3H X-Received: by 2002:aa7:d582:0:b0:4fd:14d5:bb47 with SMTP id r2-20020aa7d582000000b004fd14d5bb47mr10370982edq.38.1679899718152; Sun, 26 Mar 2023 23:48:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679899718; cv=pass; d=google.com; s=arc-20160816; b=pF2q93bMsTHJmjDYxVZBVgzVneKJUugDVzuuX+ZmkLGMHLEEGPo5gKjdO2qao7Xg4G 6g+xUF1v38UMsidNhzG6zeHM3C5EP5dPFyyHns3cf2CC8Ujgc384HUc+D9ED9EyVadXt ncMW7X2uq40EZAD0lDY5OxohDRj/TEJglNDdgPtaHhWjf4By1sp9l40JrCnM9J3Z+Lbj tV78eswZGts4I7J47wHtxAoPlQAOmfHGlHa6fzMTQp70yucwV8kxHA1nqb0OpMMWmnzk 7HB0vryrWGTy40xHenSqOIiBSZD9QKy+KuyZfNTsXNw9nLemECcqJJ9aBgiMZUtTn2Ih JOXA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gA36rjGQaztJzKACtcCbtTz7Hrsky4bgENUo5JjXWaQ=; b=AptgV0RwSjZ+2bVnITaGQlnUvQ8kajwq4JzMjh0E2XRsKdrjyeLueUi8umpPvNDDK0 ZUBf1DNYYKJTVwE3Cw5Q9kjJ61FuCQNHlAHulwF915umhEGwANTEtddC9o5gpSyYZqJW XqKYd7946uud//bwv7r26r9GfOS/a3XuYCt7W4Zz4Mi2DAP+v2RTKt+aI7DX8irQEtQF JeREoNXxJdChNZKF63Aop6QtkarFhpZ66v+kTb7eE82Aiyr6XMgNHJaidkBqJuXt6v7U 6HG8IsFX/XHyR9MKdJWGjbXZG+s9fprue9SJ3Dbp8tZLWc28CcsHbBHsnYvzNIDq5hWS fwxw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=selector1 header.b=Ejmlyfhx; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n8-20020aa7db48000000b004fd2b59e8c2si26580559edt.549.2023.03.26.23.48.14; Sun, 26 Mar 2023 23:48:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=selector1 header.b=Ejmlyfhx; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232211AbjC0G2f (ORCPT + 99 others); Mon, 27 Mar 2023 02:28:35 -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/xJiE0jvqM+YlzkGwUsfmlQ0DtEsCqTBN8SflT+csU7eNoPtefHctSu5Js3Lz4MKZ+2BB4N1FIoS+PgAzgIMymy5rRBTtrvkaADFtcl0E1bRaFf+cKudjHyZYItdAv2o81gTRjJ6nDwI08p4HJxmyh2j7NcvprhUcSzuo1PWa/mAL5c80gLOtMqh1f/PGB4skKZWx0+1PmgLpM3+R/8s/79c3GQvUg8dQN34Of3yoV/IodMnFX3aBXBSsbEi056YSBEHvlFjw23Ury8a4uslffg0TaDcLWhPKhXhQ8QvaR/b2M8S0snrcM6TMM0RMiidgvPg3iapSioFD1ATVp2tB5qufCz8l5cy7Dv4jl/6iGyEGcSmbkTKj0y2TPyXVtynEpzlFDlLSZaop1ZeIiK7wrg8CLJhu/2pOHurYcwcO04kqFt0HPz1oIEmy8meIUTkElP0jeZTnpKVt7kXskBRszpRn31/fFVAht7FnrPeS7xS80d/+jJqClCbrsXPKUr0uHz0rV64QxkH5XrLbaN3bNcaxk88PlSO2D+RmR+aHeiWZXE5cD2win+MGz1tZo6iB3cUyXLjgxEYP9mokXC56RoIdeOFj1OKvBJk7/ZvqpRZAh8o9L8dRJ2Sg1WQIXx0xUytv6PGYj4d6Fy1adCX+nIvcrrBgYZrCW3Jh3H8pxcy+wFf0/YJrB6Mcu5GnL+/cRxW7o9wzQB8FTKHJca5GHQDRQ9kVECVInM+PrXlx4LjZjT/jJNiz0rOtdw7B9hxJGoRqNCMbZs8ax9gcHxhSC73hKqwC8KXkO9WOR3zn2uenzLrfNPQUW6MMIo5Zvi0zUEsqz6hmvjQPHWz+uQe8YHdbKo4H6o3tawckgBMVIi5z+MiabYJi4WSduTDs/8STgzUpLv+aQWiZknwt/accZOmA/PhBsQLmp9lIA3QqHMrMnqpmp0nWVJqLkKQsjvidyBuxMAzaUIuPmc8IXJOSCpDY5TKWcPhVGRvSDLdf1eHElR/OyhxIE1v67V4rNUGfRRC6fQiwAgsybdEP0= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-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 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761502526696138525?= X-GMAIL-MSGID: =?utf-8?q?1761502526696138525?= 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: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: 75231 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1313825vqo; Sun, 26 Mar 2023 23:49:20 -0700 (PDT) X-Google-Smtp-Source: AKy350amEgNVj5/BzDzmhoDquRuvflLyF3lx2U4oXFdZxZPpC6apeUu+t9/0qhgj5j2o3qiykRBl X-Received: by 2002:aa7:dc10:0:b0:502:1d19:d252 with SMTP id b16-20020aa7dc10000000b005021d19d252mr10031570edu.17.1679899759949; Sun, 26 Mar 2023 23:49:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679899759; cv=pass; d=google.com; s=arc-20160816; b=CuiZZnQdnqJG3H+MRitCTSF7raRECaKjXtg8WiQ0ZzUhyvmKp0uCrFPUM+VSpABMez wZqE6OT4FABh+6dCFsfp0JIFCNyD2+hbjdASZEpZ0bsMJGo5DyJEbz6yfQk0uVqBZ76G ooI1MvzN9/RG8N0kTl0dsmIeV5/PGHCiJRbY5Xl0qhAtTIxgeX4TJP3fyC7KEY9t0Qi+ rbdXdX8B2x8+J8GXoBM1FROl05x4TMNfsuE7TRz+Ha9FAAVDLaM8AGbWBkUm0GaJWG/4 5I9YeUkmFmDudJoznix7Q78+aTN/33/KzhiIeinrpTlOuFApH3ME5juk4KRF05YCUl5X iFgw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fN4oSk/fg6PFOW23zvTHHTxM97j8i0UUQgD086d68p0=; b=Ay03ZCRNA1pMtT9jgSDV1ZanlAjAh2eRENws0cOPK6gVYCFgDNCjexOZt0Ufcc4oFm sMoyQI+KJbtAqhpobG+paJXL0hvEtrMyjvwggmsR81y83WrAowrxVFHjswyrRlpgzUhA J7+HaP9VhCbGWDw59Om323PtGLLJRBtpvUamNwtMqJWdqjDfILtJmSFX6GMoHNx3tCBQ Ei5rhkP54cvCSv/yhAzaOKe7NVDCLhD5VvAjtwDgHZiCaGSHfTkV41jyOpXRCT8ttr/f Ii7fcg0qqpM0wkSpkG8KaVMvQmNaiEVqbKlNEARc7qL+mPvMYkCttmm8N9OMCdxi/agS Lhbw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=selector1 header.b=RulfTfXo; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o21-20020aa7c515000000b005002ebedfc7si11146995edq.403.2023.03.26.23.48.56; Sun, 26 Mar 2023 23:49:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=selector1 header.b=RulfTfXo; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232248AbjC0G3W (ORCPT + 99 others); Mon, 27 Mar 2023 02:29:22 -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/GWymjxv7BYJNhFOQNITnrayj9cMIGi98jHnL6jNiVHSkM4Zt4ZdowN/ClqpRBsW8bd7m87MnthKuBMGF4J4h1qCT2IVgjL0+9CcmF/06vB8UWHwht7OEj61PKGC1DlPfkx8ztbJv5S5hi9wdrRc6hfeCHKw8M8P+H0kgCw0T0l+WNJN4WmjBzWCWHAk+JWX0FurWnrfWFQ5zStEqGd64BGy7XwNqMvYA94TTVNV2b7CDg+TG79xnIni2Tfu57f3W/8oIAUck9VWAuL+BJh4ir/1uy2cW+3p702linisaoJyA4ADzvVcoAH+Xy58nAme1TfsoLpyw+quHnc2D2ymR2KJ2cvpnJvVOCMgf9g7/Mf3Dm1Vp4F8L9tk5sDd76zFRNBUo0ZiSRWbEj1v4/kB5ECpukMjvpjx1EugX5bBZILGo/m+p0DSYyiuCmjUNYfqlY70U68p7NaU81fPJWSMV8ek9cHyewqi9yQ1WNBFscRlpluXqJRe2BYMIIMuuqlpvYlrxpoXXABocU4rxEfVW0ATMtkVSwBYNie3osuNkr0esJuAT07PNqy2QkzO5wMVoOKediM6NadErzJyNYTDAQ6PXYhuFJ40OlHlIA6CHmptXAt3nO75ur9CMKUo7hCWwaQFeQmVRqTadHloyk5meKbIKFEN9Pv/pZ2t5ZQqawT3mlvoCTwOsa89naKOrESMW2hLY65/cPsZa1wgem12IPR9RF/fnxA7nSOloxP1vQDrpK7F3PyWh1oGFB4eJPOl4viXcQafdBqEedStCj9+vLsqJeeTk8EfQwLjbA6S4tf/F4lxKYy91v6Hh10do+XmZY4NgXKK9zh+Rlon6XZbYOeJXGLwFVGHFS13DqU/Glb64sTfhmZh1sO/cSDkGIMleRgToiqr8tuoh9Q2q6G64uxrMmbeGQeXIQU49+L+uWRGPBGo+sA4WnnQNhQq0hHrktnXL/lEPjlK/qUZDJK4e/fYkvafmc42YeOlO8b0qGmaThooRjjCXDHxvP524cNk6xAtED99QICjh+hAPe7lZaOomJQKRYLHEJDIIiM0PvN2FQX92jWytTOUi97rOtaP6RNFPM6KcB1dzvd2DVW8JwxP0E+kEYGsjnsYcml0cHOmJ+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 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761502570812323370?= X-GMAIL-MSGID: =?utf-8?q?1761502570812323370?= 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: 75227 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1310685vqo; Sun, 26 Mar 2023 23:39:18 -0700 (PDT) X-Google-Smtp-Source: AK7set/eLJj/zI2lVALG2t7HjLlemtCn1cK0JRqZXSRn0vEzhzlib8z3vfeFgre6ksd1t8Xv7ENJ X-Received: by 2002:a17:90a:17a9:b0:23f:452c:7a4f with SMTP id q38-20020a17090a17a900b0023f452c7a4fmr11104611pja.46.1679899158190; Sun, 26 Mar 2023 23:39:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679899158; cv=pass; d=google.com; s=arc-20160816; b=hTCbNXhJYvqjHgAFYTnrSVcSNxdmyVkafNzinNhW8WPerfWnEOJX+8QgtT2rnF4fcZ qUu/wZunBgLz9yTPFm9yLda6pvfhFGYMqv69BnMR1tZoQxpJQzEnXBNj5ztWXl7IT8+1 guOjqJ1FiKGrcQiT5f+2y0ODTxBOasy3B3sgGWXIbF6adWp9EtMTvKmXcoNBpdUWJLyJ R+3XYXfDJHlHinCuKptS9NLEXjiyeyhknt2mh0cFBaxuHMpi7k9FZ/8FK9G7hWuV3cVD nMGL1flDww5dV5AilOjBoyLHmEweRTAr+m/QU12S0PG7aUVnpOqmq2bU0SH2bNJaE2Fg uEwg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rpCrTRKeIxUTc7SqgtAcE2DoOoAkUxF6EhYVABTXIo0=; b=DT6AAe1e4nRW+1qjxAqlpY/3v/ldexBUTVTix+d7qXqydwirIrrBxib5conaALcL/f D4HCiZR3WZNAc+PWCFscmVGAhg4MoG7ET/KsYFWAEQYnJ83oQtnfamJKiWg7lH+VHySy l7Br+JlIGVnWX0DXNse8doPAtJ7d0/kkPlFws83R28zaCkdPPxg7q2rb2wU0J9B96p2P SNT46G7EN6lGatqxFOG9a3g83JjD0fhn5OGGNGQoPGAmKbDmXVz/D5PqGxFJxCvWg3/l X92NzAnX7HRZ99LajxlsquDKToApr+S3nKQfzjY1Zayc9OPc46C21p8NlhMPVNpQRKJ/ Vedw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=selector1 header.b=KCDB1z2K; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a17090a718600b002402275fc56si9814063pjk.118.2023.03.26.23.39.03; Sun, 26 Mar 2023 23:39:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=selector1 header.b=KCDB1z2K; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232043AbjC0G3Z (ORCPT + 99 others); Mon, 27 Mar 2023 02:29:25 -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+96DNXvoFedVtGvmdZxMKGQkX10YPqlTDwTHPalVS3B31eaeJkWjTYX9BTDHzCBqIiYSqt3fKaxSRcbKTvUh41t9+SanIakxsQl45YFHasw6EH5rmimdrMnnNGjIS3pgPWmXih9GI16Si/vW05smY5m5oEzX2uk5HGn5p6oK7vHaDlDxD/7/TLXNVK2ycxtSsuBS7wShR1+3ziekPKH3XGsjmVYNuyiFLdgXHAoWRrdNQ8OABikJGqQT2UHF15JmhCg29J4e2YaTB5btgbvDn2+K1l20oD5vO3Un0XVgXfpTUzNpgAEv/OhKAsRa7694t/u3DbsuaB/A4Rauon1dTspVsUNR1EuliQqYvWMnrgZrZmZrCzNhOXZ5PuqRK0bPzdgNoDHV17VVf8tz2xDkQ+Z5xgnfhRd0D4hXzjfPkClBT53vZmRXv2YAzpPFj6UCQJfKMm1sd6bhPvyL66TM0PrxmjZANhZIhmxe9RCnCoS2aCi6OUbvep7mnjBGu1SNnFjPpaWJGyqPc0mn0/Zr17d5SY4dsOhgkG80fhXirJq/R7nP/jbjTZlWSP54riziL7tQV2XthfEjTXVx1aCwoddJ3YT/egCyeSHQonH+JzzwSsvVq/9m3pnBPFtfXvfapmwz1f7C5YDBAd0NQjd2BOPGUXWw9cUymnmi94Pd14Fen0gMp0WvxyHZI+e/sJ922nMZHLh0vQiFhoj7WQoe92kW65kKOuwVSGjjk7kznR0BBB4PRv3dGeYJEQrp4tC9B8tr9O0tgq2/V812Xn+LAyeKEmQZdB34TlpuMl/vIvFm454pBOqpl7lTI4Cgqvc30RMwlCnznOtkX848eQ856/YJufBu1Sb+aHmJp3eBaQUzluH+gkOQCPN1lElftWDAP009CA8q4GkcLz93A+Bzzu583quagqWIvP+dhknzEqml22e/Tfi+RCCmswaq/UE9c09AST3I1E1dvxDhgvtN9IhcUrX0Q6OJhiIHy9+4PbssO+TGBp8aOlR0DewuujrAv6nMFNYpYiYPCBJKBGVxFkWtuP0Su1OaZF1nVEasa/IDWiBYxms96Ncj5whg00PqR5DevtR43315KTNicZvRTgnC3KFpGCRF3cixaVlUddpusDfGyFSvfNWdbLNAuv4QRtlddjaePHQu4CJ9yNJYpw8RAYooB7Le3zyrgLLhoC87O44fLl9UaO7/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 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761501939523086997?= X-GMAIL-MSGID: =?utf-8?q?1761501939523086997?= 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 = {