From: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Dzmitry Sankouski <dsankouski@gmail.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
linux-input@vger.kernel.org, linux-pwm@vger.kernel.org
Subject: [PATCH] Input: max77693 - Convert to atomic pwm operation
Date: Mon, 30 Jun 2025 12:38:50 +0200 [thread overview]
Message-ID: <20250630103851.2069952-2-u.kleine-koenig@baylibre.com> (raw)
The driver called pwm_config() and pwm_enable() separately. Today both
are wrappers for pwm_apply_might_sleep() and it's more effective to call
this function directly and only once. Also don't configure the
duty_cycle and period if the next operation is to disable the PWM so
configure the PWM in max77693_haptic_enable().
With the direct use of pwm_apply_might_sleep() the need to call
pwm_apply_args() in .probe() is now gone, too, so drop this one.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
Hello,
the motivation for this patch is getting rid of pwm_config(),
pwm_enable() and pwm_apply_args(). I plan to remove these once all
callers are fixed to use pwm_apply_might_sleep().
Best regards
Uwe
drivers/input/misc/max77693-haptic.c | 41 ++++++----------------------
1 file changed, 8 insertions(+), 33 deletions(-)
diff --git a/drivers/input/misc/max77693-haptic.c b/drivers/input/misc/max77693-haptic.c
index 1dfd7b95a4ce..ecb3e8d541c3 100644
--- a/drivers/input/misc/max77693-haptic.c
+++ b/drivers/input/misc/max77693-haptic.c
@@ -66,23 +66,6 @@ struct max77693_haptic {
struct work_struct work;
};
-static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic)
-{
- struct pwm_args pargs;
- int delta;
- int error;
-
- pwm_get_args(haptic->pwm_dev, &pargs);
- delta = (pargs.period + haptic->pwm_duty) / 2;
- error = pwm_config(haptic->pwm_dev, delta, pargs.period);
- if (error) {
- dev_err(haptic->dev, "failed to configure pwm: %d\n", error);
- return error;
- }
-
- return 0;
-}
-
static int max77843_haptic_bias(struct max77693_haptic *haptic, bool on)
{
int error;
@@ -167,17 +150,22 @@ static int max77693_haptic_lowsys(struct max77693_haptic *haptic, bool enable)
static void max77693_haptic_enable(struct max77693_haptic *haptic)
{
int error;
+ struct pwm_state state;
- if (haptic->enabled)
- return;
+ pwm_init_state(haptic->pwm_dev, &state);
+ state.duty_cycle = (state.period + haptic->pwm_duty) / 2;
+ state.enabled = true;
- error = pwm_enable(haptic->pwm_dev);
+ error = pwm_apply_might_sleep(haptic->pwm_dev, &state);
if (error) {
dev_err(haptic->dev,
"failed to enable haptic pwm device: %d\n", error);
return;
}
+ if (haptic->enabled)
+ return;
+
error = max77693_haptic_lowsys(haptic, true);
if (error)
goto err_enable_lowsys;
@@ -224,13 +212,6 @@ static void max77693_haptic_play_work(struct work_struct *work)
{
struct max77693_haptic *haptic =
container_of(work, struct max77693_haptic, work);
- int error;
-
- error = max77693_haptic_set_duty_cycle(haptic);
- if (error) {
- dev_err(haptic->dev, "failed to set duty cycle: %d\n", error);
- return;
- }
if (haptic->magnitude)
max77693_haptic_enable(haptic);
@@ -340,12 +321,6 @@ static int max77693_haptic_probe(struct platform_device *pdev)
return PTR_ERR(haptic->pwm_dev);
}
- /*
- * FIXME: pwm_apply_args() should be removed when switching to the
- * atomic PWM API.
- */
- pwm_apply_args(haptic->pwm_dev);
-
haptic->motor_reg = devm_regulator_get(&pdev->dev, "haptic");
if (IS_ERR(haptic->motor_reg)) {
dev_err(&pdev->dev, "failed to get regulator\n");
base-commit: 1343433ed38923a21425c602e92120a1f1db5f7a
--
2.49.0
next reply other threads:[~2025-06-30 10:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-30 10:38 Uwe Kleine-König [this message]
2025-06-30 19:23 ` [PATCH] Input: max77693 - Convert to atomic pwm operation Dmitry Torokhov
2025-07-01 5:49 ` Uwe Kleine-König
2025-07-01 18:06 ` Dmitry Torokhov
2025-07-02 6:02 ` Uwe Kleine-König
2025-07-29 20:04 ` Uwe Kleine-König
2025-08-07 4:33 ` Dmitry Torokhov
2025-08-07 6:42 ` Uwe Kleine-König
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=20250630103851.2069952-2-u.kleine-koenig@baylibre.com \
--to=u.kleine-koenig@baylibre.com \
--cc=dmitry.torokhov@gmail.com \
--cc=dsankouski@gmail.com \
--cc=krzk@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=m.szyprowski@samsung.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