All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Thierry Reding <thierry.reding@gmail.com>, linux-pwm@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, "Bryan Wu" <cooloney@gmail.com>,
	"Richard Purdie" <rpurdie@rpsys.net>,
	"Jacek Anaszewski" <j.anaszewski@samsung.com>,
	linux-leds@vger.kernel.org, "Heiko Stuebner" <heiko@sntech.de>,
	linux-rockchip@lists.infradead.org,
	"Jingoo Han" <jingoohan1@gmail.com>,
	"Lee Jones" <lee.jones@linaro.org>,
	linux-fbdev@vger.kernel.org, "Mark Brown" <broonie@kernel.org>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Jean-Christophe Plagniol-Villard" <plagnioj@jcrosoft.com>,
	"Tomi Valkeinen" <tomi.valkeinen@ti.com>,
	"Doug Anderson" <dianders@google.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Maxime Ripard" <maxime.ripard@free-electrons.com>,
	"Boris Brezillon" <boris.brezillon@free-electrons.com>
Subject: [PATCH v2 03/10] pwm: move the enabled/disabled info to pwm_state struct
Date: Mon, 20 Jul 2015 17:32:00 +0200	[thread overview]
Message-ID: <1437406327-6207-4-git-send-email-boris.brezillon@free-electrons.com> (raw)
In-Reply-To: <1437406327-6207-1-git-send-email-boris.brezillon@free-electrons.com>

Prepare the transition to PWM atomic update by moving the enabled/disabled
state into the pwm_state struct. This way we can easily update the whole
PWM state by copying the new state in the ->state field.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 drivers/pwm/core.c  | 15 ++++++++++++---
 include/linux/pwm.h |  7 ++++---
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index a6bc8e6..3e830ce 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -474,8 +474,15 @@ EXPORT_SYMBOL_GPL(pwm_set_polarity);
  */
 int pwm_enable(struct pwm_device *pwm)
 {
-	if (pwm && !test_and_set_bit(PWMF_ENABLED, &pwm->flags))
-		return pwm->chip->ops->enable(pwm->chip, pwm);
+	if (pwm && !pwm_is_enabled(pwm)) {
+		int err;
+
+		err = pwm->chip->ops->enable(pwm->chip, pwm);
+		if (!err)
+			pwm->state.enabled = true;
+
+		return err;
+	}
 
 	return pwm ? 0 : -EINVAL;
 }
@@ -487,8 +494,10 @@ EXPORT_SYMBOL_GPL(pwm_enable);
  */
 void pwm_disable(struct pwm_device *pwm)
 {
-	if (pwm && test_and_clear_bit(PWMF_ENABLED, &pwm->flags))
+	if (pwm && pwm_is_enabled(pwm)) {
 		pwm->chip->ops->disable(pwm->chip, pwm);
+		pwm->state.enabled = false;
+	}
 }
 EXPORT_SYMBOL_GPL(pwm_disable);
 
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index fafed26..f4bc034 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -75,8 +75,7 @@ enum pwm_polarity {
 
 enum {
 	PWMF_REQUESTED = 1 << 0,
-	PWMF_ENABLED = 1 << 1,
-	PWMF_EXPORTED = 1 << 2,
+	PWMF_EXPORTED = 1 << 1,
 };
 
 /**
@@ -84,11 +83,13 @@ enum {
  * @period: PWM period (in nanoseconds)
  * @duty_cycle: PWM duty cycle (in nanoseconds)
  * @polarity: PWM polarity
+ * @enabled: PWM enabled status
  */
 struct pwm_state {
 	unsigned int period;
 	unsigned int duty_cycle;
 	enum pwm_polarity polarity;
+	bool enabled;
 };
 
 struct pwm_device {
@@ -104,7 +105,7 @@ struct pwm_device {
 
 static inline bool pwm_is_enabled(const struct pwm_device *pwm)
 {
-	return test_bit(PWMF_ENABLED, &pwm->flags);
+	return pwm->state.enabled;
 }
 
 static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
-- 
1.9.1

WARNING: multiple messages have this Message-ID (diff)
From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 03/10] pwm: move the enabled/disabled info to pwm_state struct
Date: Mon, 20 Jul 2015 15:32:00 +0000	[thread overview]
Message-ID: <1437406327-6207-4-git-send-email-boris.brezillon@free-electrons.com> (raw)
In-Reply-To: <1437406327-6207-1-git-send-email-boris.brezillon@free-electrons.com>

Prepare the transition to PWM atomic update by moving the enabled/disabled
state into the pwm_state struct. This way we can easily update the whole
PWM state by copying the new state in the ->state field.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 drivers/pwm/core.c  | 15 ++++++++++++---
 include/linux/pwm.h |  7 ++++---
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index a6bc8e6..3e830ce 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -474,8 +474,15 @@ EXPORT_SYMBOL_GPL(pwm_set_polarity);
  */
 int pwm_enable(struct pwm_device *pwm)
 {
-	if (pwm && !test_and_set_bit(PWMF_ENABLED, &pwm->flags))
-		return pwm->chip->ops->enable(pwm->chip, pwm);
+	if (pwm && !pwm_is_enabled(pwm)) {
+		int err;
+
+		err = pwm->chip->ops->enable(pwm->chip, pwm);
+		if (!err)
+			pwm->state.enabled = true;
+
+		return err;
+	}
 
 	return pwm ? 0 : -EINVAL;
 }
@@ -487,8 +494,10 @@ EXPORT_SYMBOL_GPL(pwm_enable);
  */
 void pwm_disable(struct pwm_device *pwm)
 {
-	if (pwm && test_and_clear_bit(PWMF_ENABLED, &pwm->flags))
+	if (pwm && pwm_is_enabled(pwm)) {
 		pwm->chip->ops->disable(pwm->chip, pwm);
+		pwm->state.enabled = false;
+	}
 }
 EXPORT_SYMBOL_GPL(pwm_disable);
 
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index fafed26..f4bc034 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -75,8 +75,7 @@ enum pwm_polarity {
 
 enum {
 	PWMF_REQUESTED = 1 << 0,
-	PWMF_ENABLED = 1 << 1,
-	PWMF_EXPORTED = 1 << 2,
+	PWMF_EXPORTED = 1 << 1,
 };
 
 /**
@@ -84,11 +83,13 @@ enum {
  * @period: PWM period (in nanoseconds)
  * @duty_cycle: PWM duty cycle (in nanoseconds)
  * @polarity: PWM polarity
+ * @enabled: PWM enabled status
  */
 struct pwm_state {
 	unsigned int period;
 	unsigned int duty_cycle;
 	enum pwm_polarity polarity;
+	bool enabled;
 };
 
 struct pwm_device {
@@ -104,7 +105,7 @@ struct pwm_device {
 
 static inline bool pwm_is_enabled(const struct pwm_device *pwm)
 {
-	return test_bit(PWMF_ENABLED, &pwm->flags);
+	return pwm->state.enabled;
 }
 
 static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
-- 
1.9.1


WARNING: multiple messages have this Message-ID (diff)
From: boris.brezillon@free-electrons.com (Boris Brezillon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 03/10] pwm: move the enabled/disabled info to pwm_state struct
Date: Mon, 20 Jul 2015 17:32:00 +0200	[thread overview]
Message-ID: <1437406327-6207-4-git-send-email-boris.brezillon@free-electrons.com> (raw)
In-Reply-To: <1437406327-6207-1-git-send-email-boris.brezillon@free-electrons.com>

Prepare the transition to PWM atomic update by moving the enabled/disabled
state into the pwm_state struct. This way we can easily update the whole
PWM state by copying the new state in the ->state field.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 drivers/pwm/core.c  | 15 ++++++++++++---
 include/linux/pwm.h |  7 ++++---
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index a6bc8e6..3e830ce 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -474,8 +474,15 @@ EXPORT_SYMBOL_GPL(pwm_set_polarity);
  */
 int pwm_enable(struct pwm_device *pwm)
 {
-	if (pwm && !test_and_set_bit(PWMF_ENABLED, &pwm->flags))
-		return pwm->chip->ops->enable(pwm->chip, pwm);
+	if (pwm && !pwm_is_enabled(pwm)) {
+		int err;
+
+		err = pwm->chip->ops->enable(pwm->chip, pwm);
+		if (!err)
+			pwm->state.enabled = true;
+
+		return err;
+	}
 
 	return pwm ? 0 : -EINVAL;
 }
@@ -487,8 +494,10 @@ EXPORT_SYMBOL_GPL(pwm_enable);
  */
 void pwm_disable(struct pwm_device *pwm)
 {
-	if (pwm && test_and_clear_bit(PWMF_ENABLED, &pwm->flags))
+	if (pwm && pwm_is_enabled(pwm)) {
 		pwm->chip->ops->disable(pwm->chip, pwm);
+		pwm->state.enabled = false;
+	}
 }
 EXPORT_SYMBOL_GPL(pwm_disable);
 
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index fafed26..f4bc034 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -75,8 +75,7 @@ enum pwm_polarity {
 
 enum {
 	PWMF_REQUESTED = 1 << 0,
-	PWMF_ENABLED = 1 << 1,
-	PWMF_EXPORTED = 1 << 2,
+	PWMF_EXPORTED = 1 << 1,
 };
 
 /**
@@ -84,11 +83,13 @@ enum {
  * @period: PWM period (in nanoseconds)
  * @duty_cycle: PWM duty cycle (in nanoseconds)
  * @polarity: PWM polarity
+ * @enabled: PWM enabled status
  */
 struct pwm_state {
 	unsigned int period;
 	unsigned int duty_cycle;
 	enum pwm_polarity polarity;
+	bool enabled;
 };
 
 struct pwm_device {
@@ -104,7 +105,7 @@ struct pwm_device {
 
 static inline bool pwm_is_enabled(const struct pwm_device *pwm)
 {
-	return test_bit(PWMF_ENABLED, &pwm->flags);
+	return pwm->state.enabled;
 }
 
 static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
-- 
1.9.1

  reply	other threads:[~2015-07-20 15:32 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-20 15:31 [PATCH v2 00/10] pwm: add support for atomic update Boris Brezillon
2015-07-20 15:31 ` Boris Brezillon
2015-07-20 15:31 ` Boris Brezillon
2015-07-20 15:31 ` Boris Brezillon
2015-07-20 15:32 ` Boris Brezillon [this message]
2015-07-20 15:32   ` [PATCH v2 03/10] pwm: move the enabled/disabled info to pwm_state struct Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
     [not found] ` <1437406327-6207-1-git-send-email-boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2015-07-20 15:31   ` [PATCH v2 01/10] pwm: introduce default period and polarity concepts Boris Brezillon
2015-07-20 15:31     ` Boris Brezillon
2015-07-20 15:31     ` Boris Brezillon
2015-07-20 15:31     ` Boris Brezillon
2015-10-06 10:09     ` Alexandre Belloni
2015-10-06 10:09       ` Alexandre Belloni
2015-10-06 10:09       ` Alexandre Belloni
2015-07-20 15:31   ` [PATCH v2 02/10] pwm: define a new pwm_state struct Boris Brezillon
2015-07-20 15:31     ` Boris Brezillon
2015-07-20 15:31     ` Boris Brezillon
2015-07-20 15:31     ` Boris Brezillon
2015-07-20 15:32   ` [PATCH v2 04/10] backlight: pwm_bl: remove useless call to pwm_set_period Boris Brezillon
2015-07-20 15:32     ` Boris Brezillon
2015-07-20 15:32     ` Boris Brezillon
2015-07-20 15:32     ` Boris Brezillon
2015-07-20 15:32 ` [PATCH v2 05/10] pwm: declare a default PWM state Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
2015-07-20 15:32 ` [PATCH v2 06/10] pwm: add the PWM initial state retrieval infra Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
2015-07-20 15:32 ` [PATCH v2 07/10] pwm: add the core infrastructure to allow atomic update Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
2015-07-20 15:32 ` [PATCH v2 08/10] pwm: add information about polarity, duty cycle and period to debugfs Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
2015-07-20 15:32 ` [PATCH v2 09/10] pwm: rockchip: add initial state retrieval Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
2015-07-20 15:32 ` [PATCH v2 10/10] pwm: rockchip: add support for atomic update Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
2015-07-20 15:32   ` Boris Brezillon
2015-07-20 17:19 ` [PATCH v2 00/10] pwm: " Mark Brown
2015-07-20 17:19   ` Mark Brown
2015-07-20 17:19   ` Mark Brown
2015-07-20 19:49   ` Boris Brezillon
2015-07-20 19:49     ` Boris Brezillon
2015-07-20 19:49     ` Boris Brezillon
2015-07-20 20:08     ` Mark Brown
2015-07-20 20:08       ` Mark Brown
2015-07-20 20:08       ` Mark Brown
2015-07-20 20:21       ` Boris Brezillon
2015-07-20 20:21         ` Boris Brezillon
2015-07-20 20:21         ` Boris Brezillon
2015-07-25  6:36 ` Boris Brezillon
2015-07-25  6:36   ` Boris Brezillon
2015-07-25  6:36   ` Boris Brezillon
2015-08-17  7:18   ` Boris Brezillon
2015-08-17  7:18     ` Boris Brezillon
2015-08-17  7:18     ` Boris Brezillon

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=1437406327-6207-4-git-send-email-boris.brezillon@free-electrons.com \
    --to=boris.brezillon@free-electrons.com \
    --cc=broonie@kernel.org \
    --cc=cooloney@gmail.com \
    --cc=dianders@google.com \
    --cc=heiko@sntech.de \
    --cc=j.anaszewski@samsung.com \
    --cc=jingoohan1@gmail.com \
    --cc=lee.jones@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=maxime.ripard@free-electrons.com \
    --cc=plagnioj@jcrosoft.com \
    --cc=rpurdie@rpsys.net \
    --cc=thierry.reding@gmail.com \
    --cc=tomi.valkeinen@ti.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /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.