From nobody Thu Nov 14 10:15:09 2024 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 15BF7C433EF for ; Tue, 8 Mar 2022 10:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345689AbiCHKLd (ORCPT ); Tue, 8 Mar 2022 05:11:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345697AbiCHKLQ (ORCPT ); Tue, 8 Mar 2022 05:11:16 -0500 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8095737A32 for ; Tue, 8 Mar 2022 02:10:19 -0800 (PST) Received: by mail-pg1-x529.google.com with SMTP id z4so16000975pgh.12 for ; Tue, 08 Mar 2022 02:10:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AN8AQlXUHY8dzoH7tRwXIxVaLJny20Q1qo/2QYSwxHk=; b=bvMT2jkFovcX32w1PT4TTZsspSO3e8SRTk4q/igiSkmk1cUsE98JgeoEY/AL+dcqqr jS34mDr+t3NiSxzysNh51S4J/5tPFK4zct+75oThi+ZUuqpucK6VNZsvlnz481UDatKe G827DuIdlh6BrRcFNn62siIpYzUjZpPJMfngo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AN8AQlXUHY8dzoH7tRwXIxVaLJny20Q1qo/2QYSwxHk=; b=DBEzVXNo/X6H6VYgECJ0N1tPbE/kJUxXngARja+KBMs/6ZZ+Ft45h4ih7UfUdU76O+ TbEPn0XeoQXloIoown7D/RylLaPN8FKBd1e2Hn8m2ZSQnpBPu/sLYCTeoHmoswpcBGes HKEezPCh/e3eQ/fnJAjDfXmC+5FpmrQzO8Lqv4FiIE4TtXHLsJeVAvBl7f/QXmQHE8T5 MQOl970EHDhTR7FV+UTdQ6LGf6TNTKPuVYZ2dGu6QSq3sLBaBxCkkaBodQczzGfSiRIK Wfl14N9YKYtduvmjXy/vyiq6ByCzvLS3V8YSKgD8jxWVASEtMTrVFA4lzwJqwau9Jpm0 rSxQ== X-Gm-Message-State: AOAM530Ba3zR7tLyb+Cpx5U3uW+zMiFVmsZbGwAjsMShJUFgLjjswmVX BSz/HTCKBuIlgANjGtvzAeKvYg== X-Google-Smtp-Source: ABdhPJwL9D+0SHRBS3XhC6nSpflTUI/0erBZkhgu01psg9Z8qe64mE6poyKANJlHUDzPcjgGtUO/Ag== X-Received: by 2002:a63:2ccb:0:b0:37c:626c:d7e with SMTP id s194-20020a632ccb000000b0037c626c0d7emr13324616pgs.290.1646734218922; Tue, 08 Mar 2022 02:10:18 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:73f8:5e3f:6894:8f44]) by smtp.gmail.com with ESMTPSA id k19-20020a056a00135300b004f734327960sm1707553pfu.106.2022.03.08.02.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 02:10:18 -0800 (PST) From: Chen-Yu Tsai To: Sean Wang , Linus Walleij , Matthias Brugger Cc: Chen-Yu Tsai , linux-mediatek@lists.infradead.org, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AngeloGioacchino Del Regno Subject: [PATCH v2 07/11] pinctrl: mediatek: paris: Rework mtk_pinconf_{get,set} switch/case logic Date: Tue, 8 Mar 2022 18:09:52 +0800 Message-Id: <20220308100956.2750295-8-wenst@chromium.org> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog In-Reply-To: <20220308100956.2750295-1-wenst@chromium.org> References: <20220308100956.2750295-1-wenst@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The current code deals with optional features by testing for the function pointers and returning -ENOTSUPP if it is not valid. This is done for multiple pin config settings and results in the code that handles the supporting cases to get indented by one level. This is aggrevated by the fact that some features require another level of conditionals. Instead of assigning the same error code in all unsupported optional feature cases, simply have that error code as the default, and break out of the switch/case block whenever a feature is unsupported, or an error is returned. This reduces indentation by one level for the useful code. Also replace the goto statements with break statements. The result is the same, as the gotos simply exit the switch/case block, which can also be achieved with a break statement. With the latter the intent is clear and easier to understand. Signed-off-by: Chen-Yu Tsai Reviewed-by: AngeloGioacchino Del Regno --- drivers/pinctrl/mediatek/pinctrl-paris.c | 144 ++++++++++------------- 1 file changed, 61 insertions(+), 83 deletions(-) diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/med= iatek/pinctrl-paris.c index 39487e0c2726..1ea3f3c54ef3 100644 --- a/drivers/pinctrl/mediatek/pinctrl-paris.c +++ b/drivers/pinctrl/mediatek/pinctrl-paris.c @@ -79,37 +79,34 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev, { struct mtk_pinctrl *hw =3D pinctrl_dev_get_drvdata(pctldev); u32 param =3D pinconf_to_config_param(*config); - int pullup, err, reg, ret =3D 1; + int pullup, reg, err =3D -ENOTSUPP, ret =3D 1; const struct mtk_pin_desc *desc; =20 - if (pin >=3D hw->soc->npins) { - err =3D -EINVAL; - goto out; - } + if (pin >=3D hw->soc->npins) + return -EINVAL; + desc =3D (const struct mtk_pin_desc *)&hw->soc->pins[pin]; =20 switch (param) { case PIN_CONFIG_BIAS_DISABLE: case PIN_CONFIG_BIAS_PULL_UP: case PIN_CONFIG_BIAS_PULL_DOWN: - if (hw->soc->bias_get_combo) { - err =3D hw->soc->bias_get_combo(hw, desc, &pullup, &ret); - if (err) - goto out; - if (ret =3D=3D MTK_PUPD_SET_R1R0_00) - ret =3D MTK_DISABLE; - if (param =3D=3D PIN_CONFIG_BIAS_DISABLE) { - if (ret !=3D MTK_DISABLE) - err =3D -EINVAL; - } else if (param =3D=3D PIN_CONFIG_BIAS_PULL_UP) { - if (!pullup || ret =3D=3D MTK_DISABLE) - err =3D -EINVAL; - } else if (param =3D=3D PIN_CONFIG_BIAS_PULL_DOWN) { - if (pullup || ret =3D=3D MTK_DISABLE) - err =3D -EINVAL; - } - } else { - err =3D -ENOTSUPP; + if (!hw->soc->bias_get_combo) + break; + err =3D hw->soc->bias_get_combo(hw, desc, &pullup, &ret); + if (err) + break; + if (ret =3D=3D MTK_PUPD_SET_R1R0_00) + ret =3D MTK_DISABLE; + if (param =3D=3D PIN_CONFIG_BIAS_DISABLE) { + if (ret !=3D MTK_DISABLE) + err =3D -EINVAL; + } else if (param =3D=3D PIN_CONFIG_BIAS_PULL_UP) { + if (!pullup || ret =3D=3D MTK_DISABLE) + err =3D -EINVAL; + } else if (param =3D=3D PIN_CONFIG_BIAS_PULL_DOWN) { + if (pullup || ret =3D=3D MTK_DISABLE) + err =3D -EINVAL; } break; case PIN_CONFIG_SLEW_RATE: @@ -119,7 +116,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev, case PIN_CONFIG_OUTPUT_ENABLE: err =3D mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &ret); if (err) - goto out; + break; /* CONFIG Current direction return value * ------------- ----------------- ---------------------- * OUTPUT_ENABLE output 1 (=3D HW value) @@ -134,23 +131,21 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctlde= v, case PIN_CONFIG_INPUT_SCHMITT_ENABLE: err =3D mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &ret); if (err) - goto out; + break; /* return error when in output mode * because schmitt trigger only work in input mode */ if (ret) { err =3D -EINVAL; - goto out; + break; } =20 err =3D mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SMT, &ret); - break; case PIN_CONFIG_DRIVE_STRENGTH: - if (hw->soc->drive_get) - err =3D hw->soc->drive_get(hw, desc, &ret); - else - err =3D -ENOTSUPP; + if (!hw->soc->drive_get) + break; + err =3D hw->soc->drive_get(hw, desc, &ret); break; case MTK_PIN_CONFIG_TDSEL: case MTK_PIN_CONFIG_RDSEL: @@ -160,23 +155,18 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctlde= v, break; case MTK_PIN_CONFIG_PU_ADV: case MTK_PIN_CONFIG_PD_ADV: - if (hw->soc->adv_pull_get) { - pullup =3D param =3D=3D MTK_PIN_CONFIG_PU_ADV; - err =3D hw->soc->adv_pull_get(hw, desc, pullup, &ret); - } else - err =3D -ENOTSUPP; + if (!hw->soc->adv_pull_get) + break; + pullup =3D param =3D=3D MTK_PIN_CONFIG_PU_ADV; + err =3D hw->soc->adv_pull_get(hw, desc, pullup, &ret); break; case MTK_PIN_CONFIG_DRV_ADV: - if (hw->soc->adv_drive_get) - err =3D hw->soc->adv_drive_get(hw, desc, &ret); - else - err =3D -ENOTSUPP; + if (!hw->soc->adv_drive_get) + break; + err =3D hw->soc->adv_drive_get(hw, desc, &ret); break; - default: - err =3D -ENOTSUPP; } =20 -out: if (!err) *config =3D pinconf_to_config_packed(param, ret); =20 @@ -188,33 +178,29 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctlde= v, unsigned int pin, { struct mtk_pinctrl *hw =3D pinctrl_dev_get_drvdata(pctldev); const struct mtk_pin_desc *desc; - int err =3D 0; + int err =3D -ENOTSUPP; u32 reg; =20 - if (pin >=3D hw->soc->npins) { - err =3D -EINVAL; - goto err; - } + if (pin >=3D hw->soc->npins) + return -EINVAL; + desc =3D (const struct mtk_pin_desc *)&hw->soc->pins[pin]; =20 switch ((u32)param) { case PIN_CONFIG_BIAS_DISABLE: - if (hw->soc->bias_set_combo) - err =3D hw->soc->bias_set_combo(hw, desc, 0, MTK_DISABLE); - else - err =3D -ENOTSUPP; + if (!hw->soc->bias_set_combo) + break; + err =3D hw->soc->bias_set_combo(hw, desc, 0, MTK_DISABLE); break; case PIN_CONFIG_BIAS_PULL_UP: - if (hw->soc->bias_set_combo) - err =3D hw->soc->bias_set_combo(hw, desc, 1, arg); - else - err =3D -ENOTSUPP; + if (!hw->soc->bias_set_combo) + break; + err =3D hw->soc->bias_set_combo(hw, desc, 1, arg); break; case PIN_CONFIG_BIAS_PULL_DOWN: - if (hw->soc->bias_set_combo) - err =3D hw->soc->bias_set_combo(hw, desc, 0, arg); - else - err =3D -ENOTSUPP; + if (!hw->soc->bias_set_combo) + break; + err =3D hw->soc->bias_set_combo(hw, desc, 0, arg); break; case PIN_CONFIG_OUTPUT_ENABLE: err =3D mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, @@ -223,7 +209,7 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev,= unsigned int pin, * does not have SMT control */ if (err !=3D -ENOTSUPP) - goto err; + break; =20 err =3D mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_OUTPUT); @@ -232,7 +218,7 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev,= unsigned int pin, /* regard all non-zero value as enable */ err =3D mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES, !!arg); if (err) - goto err; + break; =20 err =3D mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_INPUT); @@ -245,7 +231,7 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev,= unsigned int pin, err =3D mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO, arg); if (err) - goto err; + break; =20 err =3D mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_OUTPUT); @@ -257,15 +243,14 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctlde= v, unsigned int pin, */ err =3D mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, !arg); if (err) - goto err; + break; =20 err =3D mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, !!arg); break; case PIN_CONFIG_DRIVE_STRENGTH: - if (hw->soc->drive_set) - err =3D hw->soc->drive_set(hw, desc, arg); - else - err =3D -ENOTSUPP; + if (!hw->soc->drive_set) + break; + err =3D hw->soc->drive_set(hw, desc, arg); break; case MTK_PIN_CONFIG_TDSEL: case MTK_PIN_CONFIG_RDSEL: @@ -275,26 +260,19 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctlde= v, unsigned int pin, break; case MTK_PIN_CONFIG_PU_ADV: case MTK_PIN_CONFIG_PD_ADV: - if (hw->soc->adv_pull_set) { - bool pullup; - - pullup =3D param =3D=3D MTK_PIN_CONFIG_PU_ADV; - err =3D hw->soc->adv_pull_set(hw, desc, pullup, - arg); - } else - err =3D -ENOTSUPP; + if (!hw->soc->adv_pull_set) + break; + err =3D hw->soc->adv_pull_set(hw, desc, + (param =3D=3D MTK_PIN_CONFIG_PU_ADV), + arg); break; case MTK_PIN_CONFIG_DRV_ADV: - if (hw->soc->adv_drive_set) - err =3D hw->soc->adv_drive_set(hw, desc, arg); - else - err =3D -ENOTSUPP; + if (!hw->soc->adv_drive_set) + break; + err =3D hw->soc->adv_drive_set(hw, desc, arg); break; - default: - err =3D -ENOTSUPP; } =20 -err: return err; } =20 --=20 2.35.1.616.g0bdcbb4464-goog