diff mbox series

[v2] pwm: imx: Allow keeping the PWM active during suspend

Message ID 1511015768-14140-1-git-send-email-festevam@gmail.com
State Changes Requested
Headers show
Series [v2] pwm: imx: Allow keeping the PWM active during suspend | expand

Commit Message

Fabio Estevam Nov. 18, 2017, 2:36 p.m. UTC
In some systems it is desirable to keep the PWM active during system
suspend.

One use case is the imx6q-cubox-i board, which has an LED driven by PWM.
When the system goes into suspend the PWM block is disabled by default,
the PWM pin goes to zero and turn on the LED during suspend, which is
not really the behaviour we want to see.

By keeping the PWM enabled during suspend the pwm-leds driver sets
the brightness to zero in suspend and then the LED is turned off as
expected.

Introduce the 'fsl,active-in-suspend' property to indicate that the
PWM will stay active during suspend.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
---
Changes since v1:
- Rename the property to 'fsl,active-in-suspend' to better describe
its purpose.

 Documentation/devicetree/bindings/pwm/imx-pwm.txt | 5 +++++
 drivers/pwm/pwm-imx.c                             | 8 ++++++++
 2 files changed, 13 insertions(+)

Comments

Rob Herring Nov. 20, 2017, 9:19 p.m. UTC | #1
On Sat, Nov 18, 2017 at 12:36:08PM -0200, Fabio Estevam wrote:
> In some systems it is desirable to keep the PWM active during system
> suspend.
> 
> One use case is the imx6q-cubox-i board, which has an LED driven by PWM.
> When the system goes into suspend the PWM block is disabled by default,
> the PWM pin goes to zero and turn on the LED during suspend, which is
> not really the behaviour we want to see.

Seems to me the default behavior should be LEDs are off in suspend and 
you'd add a property to enable them if desired.

You problem to me sounds like something that should be fixed in the pwm 
and/or pwm-led drivers.

> 
> By keeping the PWM enabled during suspend the pwm-leds driver sets
> the brightness to zero in suspend and then the LED is turned off as
> expected.
> 
> Introduce the 'fsl,active-in-suspend' property to indicate that the
> PWM will stay active during suspend.
--
To unsubscribe from this list: send the line "unsubscribe linux-pwm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Fabio Estevam Nov. 20, 2017, 10:41 p.m. UTC | #2
On Mon, Nov 20, 2017 at 7:19 PM, Rob Herring <robh@kernel.org> wrote:

> Seems to me the default behavior should be LEDs are off in suspend and
> you'd add a property to enable them if desired.
>
> You problem to me sounds like something that should be fixed in the pwm
> and/or pwm-led drivers.

pwm-leds does set brightness to 0 in suspend and the fix here is to
make  pwm-imx active during suspend, so that when pwm-leds sets the
brightness to 0, then pwm-imx really goes to logic level 1.

Please note that on imx6qdl-cuboxi the pwm is active low.
--
To unsubscribe from this list: send the line "unsubscribe linux-pwm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Fabio Estevam Nov. 20, 2017, 11:06 p.m. UTC | #3
Hi Rob,

On Mon, Nov 20, 2017 at 7:19 PM, Rob Herring <robh@kernel.org> wrote:

> Seems to me the default behavior should be LEDs are off in suspend and
> you'd add a property to enable them if desired.

Are you suggesting that I set the MX3_PWMCR_STOPEN bit unconditionally?

I see some old version of vendor driver that does exactly that:
http://git.freescale.com/git/cgit.cgi/imx/linux-2.6-imx.git/tree/arch/arm/plat-mxc/pwm.c?h=imx_2.6.35_11.09.01

I can do that and then we do not need to add an extra device tree property.

Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-pwm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

diff --git a/Documentation/devicetree/bindings/pwm/imx-pwm.txt b/Documentation/devicetree/bindings/pwm/imx-pwm.txt
index c61bdf8..ec2a84c 100644
--- a/Documentation/devicetree/bindings/pwm/imx-pwm.txt
+++ b/Documentation/devicetree/bindings/pwm/imx-pwm.txt
@@ -14,6 +14,11 @@  See the clock consumer binding,
 	Documentation/devicetree/bindings/clock/clock-bindings.txt
 - interrupts: The interrupt for the pwm controller
 
+Optional properties:
+- fsl,active-in-suspend: Boolean property that indicates that the PWM block
+			 stays active during system suspend. If not present,
+			 the PWM block stays inactive during suspend.
+
 Example:
 
 pwm1: pwm@53fb4000 {
diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c
index 2ba5c3a..afa1b20 100644
--- a/drivers/pwm/pwm-imx.c
+++ b/drivers/pwm/pwm-imx.c
@@ -35,6 +35,7 @@ 
 #define MX3_PWMSAR			0x0C    /* PWM Sample Register */
 #define MX3_PWMPR			0x10    /* PWM Period Register */
 #define MX3_PWMCR_PRESCALER(x)		((((x) - 1) & 0xFFF) << 4)
+#define MX3_PWMCR_STOPEN		(1 << 25)
 #define MX3_PWMCR_DOZEEN		(1 << 24)
 #define MX3_PWMCR_WAITEN		(1 << 23)
 #define MX3_PWMCR_DBGEN			(1 << 22)
@@ -54,6 +55,7 @@  struct imx_chip {
 	void __iomem	*mmio_base;
 
 	struct pwm_chip	chip;
+	bool active;
 };
 
 #define to_imx_chip(chip)	container_of(chip, struct imx_chip, chip)
@@ -217,6 +219,9 @@  static int imx_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm,
 		if (state->polarity == PWM_POLARITY_INVERSED)
 			cr |= MX3_PWMCR_POUTC;
 
+		if (imx->active)
+			cr |= MX3_PWMCR_STOPEN;
+
 		writel(cr, imx->mmio_base + MX3_PWMCR);
 	} else if (cstate.enabled) {
 		writel(0, imx->mmio_base + MX3_PWMCR);
@@ -264,6 +269,7 @@  static int imx_pwm_probe(struct platform_device *pdev)
 {
 	const struct of_device_id *of_id =
 			of_match_device(imx_pwm_dt_ids, &pdev->dev);
+	struct device_node *np = pdev->dev.of_node;
 	const struct imx_pwm_data *data;
 	struct imx_chip *imx;
 	struct resource *r;
@@ -301,6 +307,8 @@  static int imx_pwm_probe(struct platform_device *pdev)
 	if (IS_ERR(imx->mmio_base))
 		return PTR_ERR(imx->mmio_base);
 
+	imx->active = of_property_read_bool(np, "fsl,active-in-suspend");
+
 	ret = pwmchip_add(&imx->chip);
 	if (ret < 0)
 		return ret;