All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-input@vger.kernel.org
Cc: Thierry Reding <thierry.reding@gmail.com>,
	linux-kernel@vger.kernel.org,
	David Lechner <david@lechnology.com>,
	Frieder Schrempf <frieder.schrempf@exceet.de>
Subject: [PATCH v2 7/7] Input: pwm-beeper - switch to using "atomic" PWM API
Date: Thu, 19 Jan 2017 14:40:57 -0800	[thread overview]
Message-ID: <20170119224057.9995-7-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20170119224057.9995-1-dmitry.torokhov@gmail.com>

The "atomic" API allows us to configure PWM period and duty cycle and
enable it in one call.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/misc/pwm-beeper.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
index 7b213e0ab06c..3408dc666afa 100644
--- a/drivers/input/misc/pwm-beeper.c
+++ b/drivers/input/misc/pwm-beeper.c
@@ -37,13 +37,16 @@ struct pwm_beeper {
 
 static int pwm_beeper_on(struct pwm_beeper *beeper, unsigned long period)
 {
+	struct pwm_state state;
 	int error;
 
-	error = pwm_config(beeper->pwm, period / 2, period);
-	if (error)
-		return error;
+	pwm_get_state(beeper->pwm, &state);
 
-	error = pwm_enable(beeper->pwm);
+	state.enabled = true;
+	state.period = period;
+	pwm_set_relative_duty_cycle(&state, 50, 100);
+
+	error = pwm_apply_state(beeper->pwm, &state);
 	if (error)
 		return error;
 
@@ -127,6 +130,7 @@ static int pwm_beeper_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct pwm_beeper *beeper;
+	struct pwm_state state;
 	int error;
 
 	beeper = devm_kzalloc(dev, sizeof(*beeper), GFP_KERNEL);
@@ -141,11 +145,14 @@ static int pwm_beeper_probe(struct platform_device *pdev)
 		return error;
 	}
 
-	/*
-	 * FIXME: pwm_apply_args() should be removed when switching to
-	 * the atomic PWM API.
-	 */
-	pwm_apply_args(beeper->pwm);
+	/* Sync up PWM state and ensure it is off. */
+	pwm_init_state(beeper->pwm, &state);
+	state.enabled = false;
+	error = pwm_apply_state(beeper->pwm, &state);
+	if (error) {
+		dev_err(dev, "failed to apply initial pwm state\n");
+		return error;
+	}
 
 	beeper->amplifier = devm_regulator_get(dev, "amp");
 	if (IS_ERR(beeper->amplifier)) {
-- 
2.11.0.483.g087da7b7c-goog

  parent reply	other threads:[~2017-01-19 22:41 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-19 22:40 [PATCH v2 1/7] Input: pwm-beeper - remove calls to legacy pwm_request API Dmitry Torokhov
2017-01-19 22:40 ` [PATCH v2 2/7] Input: pwm-beeper - switch to using managed resources Dmitry Torokhov
2017-01-20 10:10   ` Thierry Reding
2017-01-19 22:40 ` [PATCH v2 3/7] Input: pwm-beeper - use input_set_capability() Dmitry Torokhov
2017-01-20 10:12   ` Thierry Reding
2017-01-19 22:40 ` [PATCH v2 4/7] Input: pwm-beeper - fix race when suspending Dmitry Torokhov
2017-01-20 10:14   ` Thierry Reding
2017-01-19 22:40 ` [PATCH v2 5/7] Input: pwm-beeper - suppress error message on probe defer Dmitry Torokhov
2017-01-20 10:16   ` Thierry Reding
2017-01-20 18:43     ` David Lechner
2017-01-19 22:40 ` [PATCH v2 6/7] Input: pwm-beeper - add optional amplifier regulator Dmitry Torokhov
2017-01-20 10:19   ` Thierry Reding
2017-01-20 17:47     ` Dmitry Torokhov
2017-01-19 22:40 ` Dmitry Torokhov [this message]
2017-01-20 10:23   ` [PATCH v2 7/7] Input: pwm-beeper - switch to using "atomic" PWM API Thierry Reding
2017-01-20 10:08 ` [PATCH v2 1/7] Input: pwm-beeper - remove calls to legacy pwm_request API Thierry Reding
2017-01-20 19:37 ` David Lechner

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=20170119224057.9995-7-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=david@lechnology.com \
    --cc=frieder.schrempf@exceet.de \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thierry.reding@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.