From patchwork Fri Mar 24 14:36:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chester Lin X-Patchwork-Id: 74578 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp677141vqo; Fri, 24 Mar 2023 07:41:20 -0700 (PDT) X-Google-Smtp-Source: AKy350a5fTO+CV+qSXOFguf/Q6onlYubtJNkk5tOnb3FFxtS6ATjK3ssxS63cuUZM0A78MYLmdUK X-Received: by 2002:a17:90b:4d0d:b0:233:cd29:f168 with SMTP id mw13-20020a17090b4d0d00b00233cd29f168mr3424870pjb.24.1679668880047; Fri, 24 Mar 2023 07:41:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679668880; cv=pass; d=google.com; s=arc-20160816; b=uFjNdmax0YxCLS3tTBNrCr47yjb5gsjdCA+TPv4nNhGGOpLS0c+s+M9cvyLmx0BQNm 4Ss0bp1WGN0xmlGXONnu2b4Ei7Wn86qCuJ0hZ64lP7tVpRVaoXkFRy4iKwj6k1geU8Y3 uGnzOMxOZdJHOwzq3AoUOayeJlHolKler2z69S8lrL9VloQlObu4gGVlOZTnRS+AyLzN 6pxEtNOTyz8H3UGx1XMZ5Opg0hU+lmIE/EGKHr23+mTdcdHZoaduN532klaib0HBxsa3 Qg7Ygf+3CKM1nKxS0IcbU7LcRKoIJ2/aCNyZ1RsgjmC6uJGbVe7QCiOlEToZmOSpsfcO v3oQ== 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=bd4Vj6VlCDu9iCL9B3NbYzXdmrjQlgQnCRfmHlIi9DZlgiL13IjF9+mei+Xo07HTcK qy34gNVPOTqbHw9k7O4SxwnQmJuhRFe4K8JEDNgGmodLRvCL5g3Jrsh+X9gqItJQEg0G v7SOOlwx/wi5Fdxfx71QE3h65R7AQGnj/qw75MtxQ9hxyc5CgY3Yi+nfq2fXFEeFbDkO zAsdMa17nQP1NiMRP3NgB9KkkBBUaAxyTIkeSjZa8PWwI8Dx8q3IP0xm4AT3VHWSQYEs kU4Q7HwDvlkQqJC+J3zKLLPJ1awjAG/68pOtfiSyiO5dpmYOne/bD9jO0DGuIJg3jFuh t92w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=selector1 header.b=2Fu3lyJa; 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 a8-20020a17090a740800b00233ea6a32c7si4473890pjg.112.2023.03.24.07.41.07; Fri, 24 Mar 2023 07:41:20 -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=2Fu3lyJa; 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 S231889AbjCXOhj (ORCPT + 99 others); Fri, 24 Mar 2023 10:37:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231955AbjCXOhg (ORCPT ); Fri, 24 Mar 2023 10:37:36 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2084.outbound.protection.outlook.com [40.107.22.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC4712279C; Fri, 24 Mar 2023 07:37:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MxqusOopXuo6MS1IsrLhD8CN6EqZIKBlcMprOhvdMJpkjsZWfa6x9I093gkH84JLE5yddRyDpt1Y3ItJwRHcqfWkiXodpraYQh7YaCLyK26SXqovCi2QciFYBq9oXm0nkXFK9+3LLJqsqFJomWCv8Qh3SkW0zYrXV6i+nWCEeRkyhpWX2wSEQ1MZ2k8cS3s2JDWRP3M4XbfvbG3MFuIqZJQ699VslEF7s1YI19IK9bMbVKrBAWGUIcGN8eS7PzvoFe/IrJ8JmbpjXG+TWiZS4QwbiRwhzAmG8qjdcCLidFNcuRP6uUx3UZFWbEqxYhRK8Pe/rvfGayTlrfBSmL6sKg== 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=X2rKnAKdk0+E3TjnwBKJL0IDmWvVyYx+vL+0TcC6YmlJFEKWwgPA+cvSrYm+/Mi4wJ+5UvpS0vm9oyUdKievjsW1XBnEjgh+qGVKhTZmcp6rKgDpxOXruulvdqhSs0yKYmssQdQG5IOYvtLZZG42g7IYaCj0hGj9nL5MWhIL6gvGN7Htv3n8PY66EcznreyEBynjp8Kqzah9bEFyB9G16v1+GZ5s5BOW1lKi+O6IbxummJsk4r3v/BTumEB/UdZ6g0kxcmWQQZQZEHXpd379Y/F37Tk04M9ZR5qstw3kO6rpLpWeMyO63usdS4HBa54eGxWbIiUGElpcipOLrtE0Kw== 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=2Fu3lyJaLu1IzPNf9895q/8CnMPl75yc3owaEm8Zzv8NMxLFtY8btZGtDGIpZB4phEmX/+K+yc1DLokqgHIuv5N969KwhTOWDtZc/dF3cCHeN409xrQ8ywSz/3RWqp7ZGO2ke7dxusPQBA6E/AXmiI+ExdIFNMAwX0zCAJaT211XsviqIL/2gZAD/NcL4N4suUEwufSgpNUJcojwXd63AuIU2dF5h1bQoX67bvb3n3/qXh7F4zncBc3s/p9DsFfOkWm810IdEojzaJuNY3VEEUkvCaTzmxLmPl8sS7GbdMVxmQ+AUYojc50BMyxWIa6Y3Uo/CuKpY/FBeg2mx7bt6g== 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 VE1PR04MB7454.eurprd04.prod.outlook.com (2603:10a6:800:1a8::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Fri, 24 Mar 2023 14:37:30 +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.038; Fri, 24 Mar 2023 14:37:30 +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 v4 2/5] pinctrl: s32cc: refactor pin config parsing Date: Fri, 24 Mar 2023 22:36:23 +0800 Message-Id: <20230324143626.16336-3-clin@suse.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230324143626.16336-1-clin@suse.com> References: <20230324143626.16336-1-clin@suse.com> X-ClientProxiedBy: TYCP301CA0053.JPNP301.PROD.OUTLOOK.COM (2603:1096:400:384::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_|VE1PR04MB7454:EE_ X-MS-Office365-Filtering-Correlation-Id: 36c981a7-8f04-46e3-f94b-08db2c754c1e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: knLGLmZi2zQQCS+w3YAVDp/9PVIaMkThwhTpaC+7EEjXKUbxrbRXqxsuF7MnTz1x22IGIS/dUrcm2HlnNsWq2a2SMw35C20yZQwoHUIjnvU1fayQfsuREt/TO1lTNGMjUUwJcptvcG9PePGv4gNWwvxnovJUSY0/ji7atCBCj1aDfEA3O1eqHFHB5xSOOqRmzSx8GsWS9cmyf1et+BUYbzDAegk+1Jq021qZhVIcN4LcQh3bVUJfQRcMTyCFV22SN9CHVngW87vhrBc9NKZYMY4ImEPlRTVWiRgr44O2RCyW9hl0lM6BJtn42AH/GqgFdeYLcMJ5/KlCU85qMd0m6FX8qlIG4tQUkKb8cYb3m73CHhrzxbo5qMvh8yxtjf3hMOtsJXG2vXHnl7UI+F5a38ebCzEQnCiV/mx056kK2Gjp5Z+mE3PaI6z+kzqGYZBkp1pHDObhfrT9onIoIQGqeM6oiviUF25/9NZX0GK/Rb4/C6pMyR+eMSE2/CELjFQGTzwqxsjJWlXPJlOV9mYaTPNezxVsm+udjq1CzuP3zE/kdZ+L4GBtHtN/kDl3AFqjNxiogixR9BOUtM3aJ6e5zpJkqe5Pf77/EsMyFj6Qv3J/cv/x0mIt00ElgEiK1WMagqfvnW2e16Pml8+dCMuahQ== 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:(13230025)(346002)(396003)(366004)(136003)(376002)(39850400004)(451199018)(8936002)(66946007)(66476007)(66556008)(41300700001)(4326008)(86362001)(8676002)(36756003)(38100700002)(6506007)(1076003)(6512007)(6666004)(26005)(83380400001)(186003)(2616005)(107886003)(316002)(6486002)(54906003)(110136005)(478600001)(5660300002)(7416002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZCf9oSMpr+4NN50ONOZgam782YTns7Y/YeGRrle6p19uZFH1S84W4K9y4xhU+vdCe/zI2Y4MjR7Z1TK4ICK5ahcwNuTOwepfgZsHqus0qN8dWWfKvb4A/keWLIr4rlploKQNOdnNRzNHGZ6mAUv6FilsrlZreymWcUl+dOkJOeB40/zns7JHgcnrkssvzaslkk4u4UazROyK1l9g25VpIk9BzyNe0EsWN65HjW/tqpwB78PonrFgmmXoRYPagyN1V2YS09LS93pH1LSCqXNBpXCiJEoAmW+lfddK6ab9gOXidkRDL+31khUfiL8t+jQypuzYTaMqF/zZjCUboYhNYEHNki0BtcQWJtT9O5xBN/BG7bzffEP9Qd6zVJYWT4wZ8D86oI0lqDzeKqAhgszZ2VLL+vSFk6v9kxLeLam7l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A9+6GlBe+aB4nQKtxpakmmrGuZ3gTI3ctoG3G4CYwez1ZM1ji5SurN2qQdXlmVcrVAE= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36c981a7-8f04-46e3-f94b-08db2c754c1e X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3439.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2023 14:37:30.6388 (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: /2kBnO8EySvmRCcbw+xJHp8Xc/1MzHeOqEw/wqzIq6xjLTRRZRu2Zk+ItiR0kuq9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7454 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?1761260475691651209?= X-GMAIL-MSGID: =?utf-8?q?1761260475691651209?= 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; }