Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1379259

[PATCH v5 20/24] pwm: add the PWM initial state retrieval infra

From Boris Brezillon <boris.brezillon@free-electrons.com>
Newsgroups linux.kernel
Subject [PATCH v5 20/24] pwm: add the PWM initial state retrieval infra
Date 2016-04-14 21:30 +0200
Message-ID <rnV7K-77H-69@gated-at.bofh.it> (permalink)
References <rnUY1-71M-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Add a ->get_state() function to the pwm_ops struct to let PWM drivers
initialize the PWM state attached to a PWM device.

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

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index c2759bc..0e7f687 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -270,6 +270,9 @@ int pwmchip_add_with_polarity(struct pwm_chip *chip,
 		pwm->hwpwm = i;
 		pwm->state.polarity = polarity;
 
+		if (chip->ops->get_state)
+			chip->ops->get_state(chip, pwm, &pwm->state);
+
 		radix_tree_insert(&pwm_tree, pwm->pwm, pwm);
 	}
 
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 7bfeacf..73ca679 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -205,6 +205,29 @@ static inline void pwm_get_args(const struct pwm_device *pwm,
 
 static inline void pwm_apply_args(struct pwm_device *pwm)
 {
+	/*
+	 * PWM users calling pwm_apply_args() expect to have a fresh config
+	 * where the polarity and period are set according to pwm_args info.
+	 * The problem is, polarity can only be changed when the PWM is
+	 * disabled.
+	 *
+	 * PWM drivers supporting hardware readout may declare the PWM device
+	 * as enabled, and prevent polarity setting, which changes from the
+	 * existing behavior, where all PWM devices are declared as disabled
+	 * at startup (even if they are actually enabled), thus authorizing
+	 * polarity setting.
+	 *
+	 * Instead of setting ->enabled to false, we call pwm_disable()
+	 * before pwm_set_polarity() to ensure that everything is configured
+	 * as expected, and the PWM is really disabled when the user request
+	 * it.
+	 *
+	 * Note that PWM users requiring a smooth handover between the
+	 * bootloader and the kernel (like critical regulators controlled by
+	 * PWM devices) will have to switch to the atomic API and avoid calling
+	 * pwm_apply_args().
+	 */
+	pwm_disable(pwm);
 	pwm_set_polarity(pwm, pwm->args.polarity);
 }
 
@@ -216,6 +239,9 @@ static inline void pwm_apply_args(struct pwm_device *pwm)
  * @set_polarity: configure the polarity of this PWM
  * @enable: enable PWM output toggling
  * @disable: disable PWM output toggling
+ * @get_state: get the current PWM state. This function is only
+ *	       called once per PWM device when the PWM chip is
+ *	       registered.
  * @dbg_show: optional routine to show contents in debugfs
  * @owner: helps prevent removal of modules exporting active PWMs
  */
@@ -228,6 +254,8 @@ struct pwm_ops {
 			    enum pwm_polarity polarity);
 	int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm);
 	void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm);
+	void (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm,
+			  struct pwm_state *state);
 #ifdef CONFIG_DEBUG_FS
 	void (*dbg_show)(struct pwm_chip *chip, struct seq_file *s);
 #endif
-- 
2.5.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v5 00/24] pwm: add support for atomic update Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-14 21:30 +0200
  [PATCH v5 02/24] pwm: use pwm_get/set_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-14 21:30 +0200
    Re: [PATCH v5 02/24] pwm: use pwm_get/set_xxx() helpers where appropriate Joachim Eastwood <manabian@gmail.com> - 2016-04-14 21:30 +0200
  [PATCH v5 05/24] input: misc: max77693: use pwm_get_args() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-14 21:30 +0200
  [PATCH v5 18/24] pwm: introduce the pwm_state concept Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-14 21:30 +0200
  [PATCH v5 08/24] fbdev: ssd1307fb: use pwm_get_args() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-14 21:30 +0200
  [PATCH v5 16/24] ARM: explicitly apply PWM config extracted from pwm_args Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-14 21:30 +0200
    Re: [PATCH v5 16/24] ARM: explicitly apply PWM config extracted from  pwm_args Krzysztof Kozlowski <k.kozlowski@samsung.com> - 2016-04-15 10:20 +0200
  [PATCH v5 15/24] drm: i915: explicitly apply PWM config extracted from pwm_args Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-14 21:30 +0200
  [PATCH v5 03/24] clk: pwm: use pwm_get_args() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-14 21:30 +0200
  [PATCH v5 17/24] pwm: keep PWM state in sync with hardware state Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-14 21:30 +0200
  [PATCH v5 20/24] pwm: add the PWM initial state retrieval infra Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-14 21:30 +0200
  [PATCH v5 21/24] pwm: add the core infrastructure to allow atomic update Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-14 21:30 +0200

csiph-web