From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>,
kernel@pengutronix.de, linux-pwm@vger.kernel.org,
linux-riscv@lists.infradead.org,
Palmer Dabbelt <palmer@dabbelt.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
Yash Shah <yash.shah@sifive.com>,
Atish Patra <atishp@atishpatra.org>,
"Wesley W. Terpstra" <wesley@sifive.com>
Subject: [PATCH 3/7] pwm: sifive: Reduce time the controller lock is held
Date: Thu, 21 Jul 2022 12:31:25 +0200 [thread overview]
Message-ID: <20220721103129.304697-3-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20220721103129.304697-1-u.kleine-koenig@pengutronix.de>
The lock is only to serialize access and update to user_count and
approx_period between different PWMs served by the same pwm_chip.
So the lock needs only to be taken during the check if the (chip global)
period can and/or needs to be changed.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/pwm-sifive.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c
index 91cf90bd4083..6017e311a879 100644
--- a/drivers/pwm/pwm-sifive.c
+++ b/drivers/pwm/pwm-sifive.c
@@ -41,7 +41,7 @@
struct pwm_sifive_ddata {
struct pwm_chip chip;
- struct mutex lock; /* lock to protect user_count */
+ struct mutex lock; /* lock to protect user_count and approx_period */
struct notifier_block notifier;
struct clk *clk;
void __iomem *regs;
@@ -76,6 +76,7 @@ static void pwm_sifive_free(struct pwm_chip *chip, struct pwm_device *pwm)
mutex_unlock(&ddata->lock);
}
+/* Called holding ddata->lock */
static void pwm_sifive_update_clock(struct pwm_sifive_ddata *ddata,
unsigned long rate)
{
@@ -144,7 +145,6 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
return ret;
}
- mutex_lock(&ddata->lock);
cur_state = pwm->state;
enabled = cur_state.enabled;
@@ -163,14 +163,17 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
/* The hardware cannot generate a 100% duty cycle */
frac = min(frac, (1U << PWM_SIFIVE_CMPWIDTH) - 1);
+ mutex_lock(&ddata->lock);
if (state->period != ddata->approx_period) {
if (ddata->user_count != 1) {
+ mutex_unlock(&ddata->lock);
ret = -EBUSY;
goto exit;
}
ddata->approx_period = state->period;
pwm_sifive_update_clock(ddata, clk_get_rate(ddata->clk));
}
+ mutex_unlock(&ddata->lock);
writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm));
@@ -185,7 +188,6 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
exit:
clk_disable(ddata->clk);
- mutex_unlock(&ddata->lock);
return ret;
}
--
2.36.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2022-07-21 10:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-21 10:31 [PATCH 1/7] pwm: sifive: Simplify offset calculation for PWMCMP registers Uwe Kleine-König
2022-07-21 10:31 ` [PATCH 2/7] pwm: sifive: Fold pwm_sifive_enable() into its only caller Uwe Kleine-König
2022-07-21 10:31 ` Uwe Kleine-König [this message]
2022-07-21 10:31 ` [PATCH 4/7] pwm: sifive: Enable clk only after period check in .apply() Uwe Kleine-König
2022-07-21 10:31 ` [PATCH 5/7] pwm: sifive: Simplify clk handling Uwe Kleine-König
2022-07-21 10:31 ` [PATCH 6/7] pwm: sifive: Ensure the clk is enabled exactly one per running PWM Uwe Kleine-König
2022-07-21 20:45 ` Uwe Kleine-König
2022-07-28 17:10 ` Thierry Reding
2022-07-21 10:31 ` [PATCH 7/7] pwm: sifive: Shut down hardware only after pwmchip_remove() completed Uwe Kleine-König
2022-07-22 17:45 ` Emil Renner Berthing
2022-07-28 17:12 ` Thierry Reding
2022-07-28 17:45 ` Conor.Dooley
2022-07-28 17:12 ` [PATCH 1/7] pwm: sifive: Simplify offset calculation for PWMCMP registers Thierry Reding
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=20220721103129.304697-3-u.kleine-koenig@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=atishp@atishpatra.org \
--cc=kernel@pengutronix.de \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=thierry.reding@gmail.com \
--cc=wanjiabing@vivo.com \
--cc=wesley@sifive.com \
--cc=yash.shah@sifive.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;
as well as URLs for NNTP newsgroup(s).