From: Raag Jadav <raag.jadav@intel.com>
To: linus.walleij@linaro.org, mika.westerberg@linux.intel.com,
andriy.shevchenko@linux.intel.com
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
mallikarjunappa.sangannavar@intel.com, bala.senthil@intel.com,
Raag Jadav <raag.jadav@intel.com>
Subject: [PATCH v1] pinctrl: intel: refine intel_config_set_pull() function
Date: Tue, 3 Oct 2023 13:48:24 +0530 [thread overview]
Message-ID: <20231003081824.28810-1-raag.jadav@intel.com> (raw)
Improve intel_config_set_pull() implementation in Intel pinctrl driver by:
- Reducing scope of spinlock by moving unneeded operations out of it.
- Utilizing temporary variables for common operations.
- Limiting IO operations to positive cases.
Signed-off-by: Raag Jadav <raag.jadav@intel.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
drivers/pinctrl/intel/pinctrl-intel.c | 41 ++++++++++++++-------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
index f49d6e136018..f9155d94a830 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.c
+++ b/drivers/pinctrl/intel/pinctrl-intel.c
@@ -674,16 +674,8 @@ static int intel_config_set_pull(struct intel_pinctrl *pctrl, unsigned int pin,
unsigned int param = pinconf_to_config_param(config);
unsigned int arg = pinconf_to_config_argument(config);
const struct intel_community *community;
+ u32 term = 0, up = 0, value;
void __iomem *padcfg1;
- u32 value;
-
- community = intel_get_community(pctrl, pin);
- padcfg1 = intel_get_padcfg(pctrl, pin, PADCFG1);
-
- guard(raw_spinlock_irqsave)(&pctrl->lock);
-
- value = readl(padcfg1);
- value &= ~(PADCFG1_TERM_MASK | PADCFG1_TERM_UP);
/* Set default strength value in case none is given */
if (arg == 1)
@@ -696,47 +688,49 @@ static int intel_config_set_pull(struct intel_pinctrl *pctrl, unsigned int pin,
case PIN_CONFIG_BIAS_PULL_UP:
switch (arg) {
case 20000:
- value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT;
+ term = PADCFG1_TERM_20K;
break;
case 5000:
- value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT;
+ term = PADCFG1_TERM_5K;
break;
case 4000:
- value |= PADCFG1_TERM_4K << PADCFG1_TERM_SHIFT;
+ term = PADCFG1_TERM_4K;
break;
case 1000:
- value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT;
+ term = PADCFG1_TERM_1K;
break;
case 833:
- value |= PADCFG1_TERM_833 << PADCFG1_TERM_SHIFT;
+ term = PADCFG1_TERM_833;
break;
default:
return -EINVAL;
}
- value |= PADCFG1_TERM_UP;
+ up = PADCFG1_TERM_UP;
break;
case PIN_CONFIG_BIAS_PULL_DOWN:
+ community = intel_get_community(pctrl, pin);
+
switch (arg) {
case 20000:
- value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT;
+ term = PADCFG1_TERM_20K;
break;
case 5000:
- value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT;
+ term = PADCFG1_TERM_5K;
break;
case 4000:
- value |= PADCFG1_TERM_4K << PADCFG1_TERM_SHIFT;
+ term = PADCFG1_TERM_4K;
break;
case 1000:
if (!(community->features & PINCTRL_FEATURE_1K_PD))
return -EINVAL;
- value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT;
+ term = PADCFG1_TERM_1K;
break;
case 833:
if (!(community->features & PINCTRL_FEATURE_1K_PD))
return -EINVAL;
- value |= PADCFG1_TERM_833 << PADCFG1_TERM_SHIFT;
+ term = PADCFG1_TERM_833;
break;
default:
return -EINVAL;
@@ -748,6 +742,13 @@ static int intel_config_set_pull(struct intel_pinctrl *pctrl, unsigned int pin,
return -EINVAL;
}
+ padcfg1 = intel_get_padcfg(pctrl, pin, PADCFG1);
+
+ guard(raw_spinlock_irqsave)(&pctrl->lock);
+
+ value = readl(padcfg1);
+ value = (value & ~PADCFG1_TERM_MASK) | (term << PADCFG1_TERM_SHIFT);
+ value = (value & ~PADCFG1_TERM_UP) | up;
writel(value, padcfg1);
return 0;
base-commit: cec422ab8c1ef320cba23b7dbf9ea5364b9c8207
--
2.17.1
next reply other threads:[~2023-10-03 8:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-03 8:18 Raag Jadav [this message]
2023-10-03 9:08 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231003081824.28810-1-raag.jadav@intel.com \
--to=raag.jadav@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bala.senthil@intel.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mallikarjunappa.sangannavar@intel.com \
--cc=mika.westerberg@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®