linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 00/17] pwm: Add support for PWM Capture
@ 2016-08-16  9:34 Lee Jones
  2016-08-16  9:34 ` [PATCH v4 01/17] ARM: dts: STiH407: Supply PWM Capture IRQ Lee Jones
                   ` (17 more replies)
  0 siblings, 18 replies; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:34 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

This patch-set makes use of the new Capture API by supplying PWM
Capture functionality into the already existing STi PWM driver.

v3 => v4:
- Keep DTB backward compatibilty

v2 => v3:
- Supply DT documentation changes
- Submit DTS additions as part of this set
- Default Capture and PWM-out number of channels to 0
  - Do additional checking, to ensure at least one channel is requested
  - Use global locking, instead of lock in device data

v1 => v2:
- API change
- Use a struct to carry the result back to the caller
- Use 'struct pwm' to store device specific data
- Make timeout configurable
- Don't use clear_bit(), instead use raw bit logic
- Propagate return value of platform_get_irq()
- Don't cast to (void *)
- Move to subsystem terminology (channels => devices)
- Remove channel select feature
- Enable Capture IP during capture

Lee Jones (17):
  ARM: dts: STiH407: Supply PWM Capture IRQ
  ARM: dts: STiH407: Declare PWM Capture data lines via Pinctrl
  ARM: dts: STiH416: Supply PWM Capture IRQs
  ARM: dts: STiH416: Declare PWM Capture data lines via Pinctrl
  ARM: dts: STiH416: Define PWM Capture clock
  ARM: dts: STiH416: Define the number of PWM Capture channels
  pwm: sti: Rename channel => device
  pwm: sti: Reorganise register names in preparation for new
    functionality
  pwm: sti: Only request clock rate when you need to
  pwm: sti: Supply PWM Capture register addresses and bit locations
  pwm: sti: Supply PWM Capture clock handling
  pwm: sti: Initialise PWM Capture device data
  pwm: sti: Add support for PWM Capture IRQs
  pwm: sti: Add PWM Capture call-back
  pwm: sti: It's now valid for number of PWM channels to be zero
  pwm: sti: Take the opportunity to conduct a little house keeping
  dt-bindings: pwm: sti: Update DT bindings with recent changes

 Documentation/devicetree/bindings/pwm/pwm-st.txt |   8 +-
 arch/arm/boot/dts/stih407-family.dtsi            |   1 +
 arch/arm/boot/dts/stih407-pinctrl.dtsi           |   3 +
 arch/arm/boot/dts/stih416-pinctrl.dtsi           |   5 +
 arch/arm/boot/dts/stih416.dtsi                   |   8 +-
 drivers/pwm/pwm-sti.c                            | 424 +++++++++++++++++++----
 6 files changed, 373 insertions(+), 76 deletions(-)

-- 
2.9.0

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v4 01/17] ARM: dts: STiH407: Supply PWM Capture IRQ
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
@ 2016-08-16  9:34 ` Lee Jones
  2016-08-16  9:34 ` [PATCH v4 02/17] ARM: dts: STiH407: Declare PWM Capture data lines via Pinctrl Lee Jones
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:34 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 arch/arm/boot/dts/stih407-family.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/boot/dts/stih407-family.dtsi b/arch/arm/boot/dts/stih407-family.dtsi
index 1566830..fd0793e 100644
--- a/arch/arm/boot/dts/stih407-family.dtsi
+++ b/arch/arm/boot/dts/stih407-family.dtsi
@@ -667,6 +667,7 @@
 			compatible	= "st,sti-pwm";
 			#pwm-cells	= <2>;
 			reg		= <0x9810000 0x68>;
+			interrupts      = <GIC_SPI 128 IRQ_TYPE_NONE>;
 			pinctrl-names	= "default";
 			pinctrl-0	= <&pinctrl_pwm0_chan0_default>;
 			clock-names	= "pwm";
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 02/17] ARM: dts: STiH407: Declare PWM Capture data lines via Pinctrl
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
  2016-08-16  9:34 ` [PATCH v4 01/17] ARM: dts: STiH407: Supply PWM Capture IRQ Lee Jones
@ 2016-08-16  9:34 ` Lee Jones
  2016-08-16  9:34 ` [PATCH v4 03/17] ARM: dts: STiH416: Supply PWM Capture IRQs Lee Jones
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:34 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 arch/arm/boot/dts/stih407-pinctrl.dtsi | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm/boot/dts/stih407-pinctrl.dtsi b/arch/arm/boot/dts/stih407-pinctrl.dtsi
index a538ae5..bc22122 100644
--- a/arch/arm/boot/dts/stih407-pinctrl.dtsi
+++ b/arch/arm/boot/dts/stih407-pinctrl.dtsi
@@ -289,10 +289,12 @@
 				pinctrl_pwm1_chan0_default: pwm1-0-default {
 					st,pins {
 						pwm-out = <&pio3 0 ALT1 OUT>;
+						pwm-capturein = <&pio3 2 ALT1 IN>;
 					};
 				};
 				pinctrl_pwm1_chan1_default: pwm1-1-default {
 					st,pins {
+						pwm-capturein = <&pio4 3 ALT1 IN>;
 						pwm-out = <&pio4 4 ALT1 OUT>;
 					};
 				};
@@ -1030,6 +1032,7 @@
 			pwm0 {
 				pinctrl_pwm0_chan0_default: pwm0-0-default {
 					st,pins {
+						pwm-capturein = <&pio31 0 ALT1 IN>;
 						pwm-out = <&pio31 1 ALT1 OUT>;
 					};
 				};
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 03/17] ARM: dts: STiH416: Supply PWM Capture IRQs
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
  2016-08-16  9:34 ` [PATCH v4 01/17] ARM: dts: STiH407: Supply PWM Capture IRQ Lee Jones
  2016-08-16  9:34 ` [PATCH v4 02/17] ARM: dts: STiH407: Declare PWM Capture data lines via Pinctrl Lee Jones
@ 2016-08-16  9:34 ` Lee Jones
  2016-08-16  9:34 ` [PATCH v4 04/17] ARM: dts: STiH416: Declare PWM Capture data lines via Pinctrl Lee Jones
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:34 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 arch/arm/boot/dts/stih416.dtsi | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/boot/dts/stih416.dtsi b/arch/arm/boot/dts/stih416.dtsi
index 0afb4f7..2001d48 100644
--- a/arch/arm/boot/dts/stih416.dtsi
+++ b/arch/arm/boot/dts/stih416.dtsi
@@ -475,6 +475,7 @@
 			status		= "okay";
 			#pwm-cells	= <2>;
 			reg		= <0xfed10000 0x68>;
+			interrupts      = <GIC_SPI 200 IRQ_TYPE_NONE>;
 
 			pinctrl-names	= "default";
 			pinctrl-0 = 	<&pinctrl_pwm0_chan0_default
@@ -493,6 +494,7 @@
 			status		= "disabled";
 			#pwm-cells	= <2>;
 			reg		= <0xfe510000 0x68>;
+			interrupts      = <GIC_SPI 202 IRQ_TYPE_NONE>;
 
 			pinctrl-names	= "default";
 			pinctrl-0	= <&pinctrl_pwm1_chan0_default
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 04/17] ARM: dts: STiH416: Declare PWM Capture data lines via Pinctrl
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (2 preceding siblings ...)
  2016-08-16  9:34 ` [PATCH v4 03/17] ARM: dts: STiH416: Supply PWM Capture IRQs Lee Jones
@ 2016-08-16  9:34 ` Lee Jones
  2016-08-16  9:34 ` [PATCH v4 05/17] ARM: dts: STiH416: Define PWM Capture clock Lee Jones
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:34 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 arch/arm/boot/dts/stih416-pinctrl.dtsi | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/boot/dts/stih416-pinctrl.dtsi b/arch/arm/boot/dts/stih416-pinctrl.dtsi
index 051fc16..252b677 100644
--- a/arch/arm/boot/dts/stih416-pinctrl.dtsi
+++ b/arch/arm/boot/dts/stih416-pinctrl.dtsi
@@ -221,11 +221,14 @@
 				pinctrl_pwm1_chan0_default: pwm1-0-default {
 					st,pins {
 						pwm-out    = <&pio3 0 ALT1 OUT>;
+						pwm-capturein = <&pio3 2 ALT1 IN>;
+
 					};
 				};
 				pinctrl_pwm1_chan1_default: pwm1-1-default {
 					st,pins {
 						pwm-out    = <&pio4 4 ALT1 OUT>;
+						pwm-capturein = <&pio4 3 ALT1 IN>;
 					};
 				};
 				pinctrl_pwm1_chan2_default: pwm1-2-default {
@@ -337,6 +340,7 @@
 				pinctrl_pwm0_chan0_default: pwm0-0-default {
 					st,pins {
 						pwm-out    = <&pio9 7 ALT2 OUT>;
+						pwm-capturein = <&pio9 6 ALT2 IN>;
 					};
 				};
 			};
@@ -576,6 +580,7 @@
 				pinctrl_pwm0_chan1_default: pwm0-1-default {
 					st,pins {
 						pwm-out    = <&pio13 2 ALT2 OUT>;
+						pwm-capturein = <&pio13 1 ALT2 IN>;
 					};
 				};
 				pinctrl_pwm0_chan2_default: pwm0-2-default {
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 05/17] ARM: dts: STiH416: Define PWM Capture clock
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (3 preceding siblings ...)
  2016-08-16  9:34 ` [PATCH v4 04/17] ARM: dts: STiH416: Declare PWM Capture data lines via Pinctrl Lee Jones
@ 2016-08-16  9:34 ` Lee Jones
  2016-08-16  9:34 ` [PATCH v4 06/17] ARM: dts: STiH416: Define the number of PWM Capture channels Lee Jones
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:34 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 arch/arm/boot/dts/stih416.dtsi | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/stih416.dtsi b/arch/arm/boot/dts/stih416.dtsi
index 2001d48..bf15a32 100644
--- a/arch/arm/boot/dts/stih416.dtsi
+++ b/arch/arm/boot/dts/stih416.dtsi
@@ -483,8 +483,9 @@
 					&pinctrl_pwm0_chan2_default
 					&pinctrl_pwm0_chan3_default>;
 
-			clock-names	= "pwm";
-			clocks		= <&clk_sysin>;
+			clock-names	= "pwm", "capture";
+			clocks		= <&clk_sysin>, <&clk_s_a0_ls CLK_ICN_REG>;
+
 			st,pwm-num-chan = <4>;
 		};
 
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 06/17] ARM: dts: STiH416: Define the number of PWM Capture channels
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (4 preceding siblings ...)
  2016-08-16  9:34 ` [PATCH v4 05/17] ARM: dts: STiH416: Define PWM Capture clock Lee Jones
@ 2016-08-16  9:34 ` Lee Jones
  2016-08-16  9:34 ` [PATCH v4 07/17] pwm: sti: Rename channel => device Lee Jones
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:34 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 arch/arm/boot/dts/stih416.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/boot/dts/stih416.dtsi b/arch/arm/boot/dts/stih416.dtsi
index bf15a32..422f9bd 100644
--- a/arch/arm/boot/dts/stih416.dtsi
+++ b/arch/arm/boot/dts/stih416.dtsi
@@ -487,6 +487,7 @@
 			clocks		= <&clk_sysin>, <&clk_s_a0_ls CLK_ICN_REG>;
 
 			st,pwm-num-chan = <4>;
+			st,capture-num-chan = <2>;
 		};
 
 		/* SBC PWM Module */
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 07/17] pwm: sti: Rename channel => device
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (5 preceding siblings ...)
  2016-08-16  9:34 ` [PATCH v4 06/17] ARM: dts: STiH416: Define the number of PWM Capture channels Lee Jones
@ 2016-08-16  9:34 ` Lee Jones
  2016-09-05 10:33   ` Thierry Reding
  2016-08-16  9:34 ` [PATCH v4 08/17] pwm: sti: Reorganise register names in preparation for new functionality Lee Jones
                   ` (10 subsequent siblings)
  17 siblings, 1 reply; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:34 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

This is to bring the terminology used in the STi PWM driver more
into line with the PWM subsystem.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/pwm/pwm-sti.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index 92abbd5..5c7fdd1 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -21,7 +21,7 @@
 #include <linux/slab.h>
 #include <linux/time.h>
 
-#define STI_DS_REG(ch)	(4 * (ch))	/* Channel's Duty Cycle register */
+#define STI_DS_REG(ch)	(4 * (ch))	/* Device's Duty Cycle register */
 #define STI_PWMCR	0x50		/* Control/Config register */
 #define STI_INTEN	0x54		/* Interrupt Enable/Disable register */
 #define PWM_PRESCALE_LOW_MASK		0x0f
@@ -40,7 +40,7 @@ enum {
 
 struct sti_pwm_compat_data {
 	const struct reg_field *reg_fields;
-	unsigned int num_chan;
+	unsigned int num_devs;
 	unsigned int max_pwm_cnt;
 	unsigned int max_prescale;
 };
@@ -130,13 +130,13 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 
 	/* Allow configuration changes if one of the
 	 * following conditions satisfy.
-	 * 1. No channels have been configured.
-	 * 2. Only one channel has been configured and the new request
-	 *    is for the same channel.
-	 * 3. Only one channel has been configured and the new request is
-	 *    for a new channel and period of the new channel is same as
+	 * 1. No devices have been configured.
+	 * 2. Only one device has been configured and the new request
+	 *    is for the same device.
+	 * 3. Only one device has been configured and the new request is
+	 *    for a new device and period of the new device is same as
 	 *    the current configured period.
-	 * 4. More than one channels are configured and period of the new
+	 * 4. More than one devices are configured and period of the new
 	 *    requestis the same as the current period.
 	 */
 	if (!ncfg ||
@@ -201,7 +201,7 @@ static int sti_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
 	int ret = 0;
 
 	/*
-	 * Since we have a common enable for all PWM channels,
+	 * Since we have a common enable for all PWM devices,
 	 * do not enable if already enabled.
 	 */
 	mutex_lock(&pc->sti_pwm_lock);
@@ -259,11 +259,11 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)
 	const struct reg_field *reg_fields;
 	struct device_node *np = dev->of_node;
 	struct sti_pwm_compat_data *cdata = pc->cdata;
-	u32 num_chan;
+	u32 num_devs;
 
-	of_property_read_u32(np, "st,pwm-num-chan", &num_chan);
-	if (num_chan)
-		cdata->num_chan = num_chan;
+	of_property_read_u32(np, "st,pwm-num-chans", &num_devs);
+	if (num_devs)
+		cdata->num_devs = num_devs;
 
 	reg_fields = cdata->reg_fields;
 
@@ -330,7 +330,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	cdata->reg_fields   = &sti_pwm_regfields[0];
 	cdata->max_prescale = 0xff;
 	cdata->max_pwm_cnt  = 255;
-	cdata->num_chan     = 1;
+	cdata->num_devs     = 1;
 
 	pc->cdata = cdata;
 	pc->dev = dev;
@@ -362,7 +362,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	pc->chip.dev = dev;
 	pc->chip.ops = &sti_pwm_ops;
 	pc->chip.base = -1;
-	pc->chip.npwm = pc->cdata->num_chan;
+	pc->chip.npwm = pc->cdata->num_devs;
 	pc->chip.can_sleep = true;
 
 	ret = pwmchip_add(&pc->chip);
@@ -381,7 +381,7 @@ static int sti_pwm_remove(struct platform_device *pdev)
 	struct sti_pwm_chip *pc = platform_get_drvdata(pdev);
 	unsigned int i;
 
-	for (i = 0; i < pc->cdata->num_chan; i++)
+	for (i = 0; i < pc->cdata->num_devs; i++)
 		pwm_disable(&pc->chip.pwms[i]);
 
 	clk_unprepare(pc->clk);
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 08/17] pwm: sti: Reorganise register names in preparation for new functionality
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (6 preceding siblings ...)
  2016-08-16  9:34 ` [PATCH v4 07/17] pwm: sti: Rename channel => device Lee Jones
@ 2016-08-16  9:34 ` Lee Jones
  2016-09-05 10:35   ` Thierry Reding
  2016-08-16  9:35 ` [PATCH v4 09/17] pwm: sti: Only request clock rate when you need to Lee Jones
                   ` (9 subsequent siblings)
  17 siblings, 1 reply; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:34 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

Exciting functionality is on the way to this device.  But
before we can add it, we need to do some basic housekeeping
so the additions can be added cleanly.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/pwm/pwm-sti.c | 76 +++++++++++++++++++++++++++------------------------
 1 file changed, 41 insertions(+), 35 deletions(-)

diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index 5c7fdd1..246df77 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -21,18 +21,22 @@
 #include <linux/slab.h>
 #include <linux/time.h>
 
-#define STI_DS_REG(ch)	(4 * (ch))	/* Device's Duty Cycle register */
-#define STI_PWMCR	0x50		/* Control/Config register */
-#define STI_INTEN	0x54		/* Interrupt Enable/Disable register */
+#define PWM_OUT_VAL(x)	(0x00 + (4 * (x))) /* Device's Duty Cycle register */
+
+#define STI_PWM_CTRL		0x50	/* Control/Config register */
+#define STI_INT_EN		0x54	/* Interrupt Enable/Disable register */
 #define PWM_PRESCALE_LOW_MASK		0x0f
 #define PWM_PRESCALE_HIGH_MASK		0xf0
 
 /* Regfield IDs */
 enum {
+	/* Bits in PWM_CTRL*/
 	PWMCLK_PRESCALE_LOW,
 	PWMCLK_PRESCALE_HIGH,
-	PWM_EN,
-	PWM_INT_EN,
+
+	PWM_OUT_EN,
+
+	PWM_CPT_INT_EN,
 
 	/* Keep last */
 	MAX_REGFIELDS
@@ -47,14 +51,14 @@ struct sti_pwm_compat_data {
 
 struct sti_pwm_chip {
 	struct device *dev;
-	struct clk *clk;
 	unsigned long clk_rate;
+	struct clk *pwm_clk;
 	struct regmap *regmap;
 	struct sti_pwm_compat_data *cdata;
 	struct regmap_field *prescale_low;
 	struct regmap_field *prescale_high;
-	struct regmap_field *pwm_en;
-	struct regmap_field *pwm_int_en;
+	struct regmap_field *pwm_out_en;
+	struct regmap_field *pwm_cpt_int_en;
 	struct pwm_chip chip;
 	struct pwm_device *cur;
 	unsigned long configured;
@@ -64,10 +68,10 @@ struct sti_pwm_chip {
 };
 
 static const struct reg_field sti_pwm_regfields[MAX_REGFIELDS] = {
-	[PWMCLK_PRESCALE_LOW]	= REG_FIELD(STI_PWMCR, 0, 3),
-	[PWMCLK_PRESCALE_HIGH]	= REG_FIELD(STI_PWMCR, 11, 14),
-	[PWM_EN]		= REG_FIELD(STI_PWMCR, 9, 9),
-	[PWM_INT_EN]		= REG_FIELD(STI_INTEN, 0, 0),
+	[PWMCLK_PRESCALE_LOW]	= REG_FIELD(STI_PWM_CTRL, 0, 3),
+	[PWMCLK_PRESCALE_HIGH]	= REG_FIELD(STI_PWM_CTRL, 11, 14),
+	[PWM_OUT_EN]		= REG_FIELD(STI_PWM_CTRL, 9, 9),
+	[PWM_CPT_INT_EN]	= REG_FIELD(STI_INT_EN, 1, 4),
 };
 
 static inline struct sti_pwm_chip *to_sti_pwmchip(struct pwm_chip *chip)
@@ -144,7 +148,7 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	    ((ncfg == 1) && (pwm->hwpwm != cur->hwpwm) && period_same) ||
 	    ((ncfg > 1) && period_same)) {
 		/* Enable clock before writing to PWM registers. */
-		ret = clk_enable(pc->clk);
+		ret = clk_enable(pc->pwm_clk);
 		if (ret)
 			return ret;
 
@@ -174,11 +178,12 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 		 */
 		pwmvalx = cdata->max_pwm_cnt * duty_ns / period_ns;
 
-		ret = regmap_write(pc->regmap, STI_DS_REG(pwm->hwpwm), pwmvalx);
+		ret = regmap_write(pc->regmap,
+				   PWM_OUT_VAL(pwm->hwpwm), pwmvalx);
 		if (ret)
 			goto clk_dis;
 
-		ret = regmap_field_write(pc->pwm_int_en, 0);
+		ret = regmap_field_write(pc->pwm_cpt_int_en, 0);
 
 		set_bit(pwm->hwpwm, &pc->configured);
 		pc->cur = pwm;
@@ -190,7 +195,7 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	}
 
 clk_dis:
-	clk_disable(pc->clk);
+	clk_disable(pc->pwm_clk);
 	return ret;
 }
 
@@ -206,11 +211,11 @@ static int sti_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
 	 */
 	mutex_lock(&pc->sti_pwm_lock);
 	if (!pc->en_count) {
-		ret = clk_enable(pc->clk);
+		ret = clk_enable(pc->pwm_clk);
 		if (ret)
 			goto out;
 
-		ret = regmap_field_write(pc->pwm_en, 1);
+		ret = regmap_field_write(pc->pwm_out_en, 1);
 		if (ret) {
 			dev_err(dev, "failed to enable PWM device:%d\n",
 				pwm->hwpwm);
@@ -232,9 +237,9 @@ static void sti_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
 		mutex_unlock(&pc->sti_pwm_lock);
 		return;
 	}
-	regmap_field_write(pc->pwm_en, 0);
+	regmap_field_write(pc->pwm_out_en, 0);
 
-	clk_disable(pc->clk);
+	clk_disable(pc->pwm_clk);
 	mutex_unlock(&pc->sti_pwm_lock);
 }
 
@@ -277,15 +282,16 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)
 	if (IS_ERR(pc->prescale_high))
 		return PTR_ERR(pc->prescale_high);
 
-	pc->pwm_en = devm_regmap_field_alloc(dev, pc->regmap,
-					     reg_fields[PWM_EN]);
-	if (IS_ERR(pc->pwm_en))
-		return PTR_ERR(pc->pwm_en);
 
-	pc->pwm_int_en = devm_regmap_field_alloc(dev, pc->regmap,
-						 reg_fields[PWM_INT_EN]);
-	if (IS_ERR(pc->pwm_int_en))
-		return PTR_ERR(pc->pwm_int_en);
+	pc->pwm_out_en = devm_regmap_field_alloc(dev, pc->regmap,
+						 reg_fields[PWM_OUT_EN]);
+	if (IS_ERR(pc->pwm_out_en))
+		return PTR_ERR(pc->pwm_out_en);
+
+	pc->pwm_cpt_int_en = devm_regmap_field_alloc(dev, pc->regmap,
+						 reg_fields[PWM_CPT_INT_EN]);
+	if (IS_ERR(pc->pwm_cpt_int_en))
+		return PTR_ERR(pc->pwm_cpt_int_en);
 
 	return 0;
 }
@@ -341,19 +347,19 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	pc->clk = of_clk_get_by_name(dev->of_node, "pwm");
-	if (IS_ERR(pc->clk)) {
+	pc->pwm_clk = of_clk_get_by_name(dev->of_node, "pwm");
+	if (IS_ERR(pc->pwm_clk)) {
 		dev_err(dev, "failed to get PWM clock\n");
-		return PTR_ERR(pc->clk);
+		return PTR_ERR(pc->pwm_clk);
 	}
 
-	pc->clk_rate = clk_get_rate(pc->clk);
+	pc->clk_rate = clk_get_rate(pc->pwm_clk);
 	if (!pc->clk_rate) {
 		dev_err(dev, "failed to get clock rate\n");
 		return -EINVAL;
 	}
 
-	ret = clk_prepare(pc->clk);
+	ret = clk_prepare(pc->pwm_clk);
 	if (ret) {
 		dev_err(dev, "failed to prepare clock\n");
 		return ret;
@@ -367,7 +373,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
 
 	ret = pwmchip_add(&pc->chip);
 	if (ret < 0) {
-		clk_unprepare(pc->clk);
+		clk_unprepare(pc->pwm_clk);
 		return ret;
 	}
 
@@ -384,7 +390,7 @@ static int sti_pwm_remove(struct platform_device *pdev)
 	for (i = 0; i < pc->cdata->num_devs; i++)
 		pwm_disable(&pc->chip.pwms[i]);
 
-	clk_unprepare(pc->clk);
+	clk_unprepare(pc->pwm_clk);
 
 	return pwmchip_remove(&pc->chip);
 }
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 09/17] pwm: sti: Only request clock rate when you need to
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (7 preceding siblings ...)
  2016-08-16  9:34 ` [PATCH v4 08/17] pwm: sti: Reorganise register names in preparation for new functionality Lee Jones
@ 2016-08-16  9:35 ` Lee Jones
  2016-09-05 10:36   ` Thierry Reding
  2016-08-16  9:35 ` [PATCH v4 10/17] pwm: sti: Supply PWM Capture register addresses and bit locations Lee Jones
                   ` (8 subsequent siblings)
  17 siblings, 1 reply; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:35 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

In the original code the clock rate was only obtained during
initialisation; however, the rate may change between then and
its use.  This patch ensures the correct rate is acquired just
before use.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/pwm/pwm-sti.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index 246df77..863d5a9 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -51,7 +51,6 @@ struct sti_pwm_compat_data {
 
 struct sti_pwm_chip {
 	struct device *dev;
-	unsigned long clk_rate;
 	struct clk *pwm_clk;
 	struct regmap *regmap;
 	struct sti_pwm_compat_data *cdata;
@@ -86,13 +85,20 @@ static int sti_pwm_get_prescale(struct sti_pwm_chip *pc, unsigned long period,
 				unsigned int *prescale)
 {
 	struct sti_pwm_compat_data *cdata = pc->cdata;
+	unsigned long clk_rate;
 	unsigned long val;
 	unsigned int ps;
 
+	clk_rate = clk_get_rate(pc->pwm_clk);
+	if (!clk_rate) {
+		dev_err(pc->dev, "failed to get clock rate\n");
+		return -EINVAL;
+	}
+
 	/*
 	 * prescale = ((period_ns * clk_rate) / (10^9 * (max_pwm_count + 1)) - 1
 	 */
-	val = NSEC_PER_SEC / pc->clk_rate;
+	val = NSEC_PER_SEC / clk_rate;
 	val *= cdata->max_pwm_cnt + 1;
 
 	if (period % val) {
@@ -353,12 +359,6 @@ static int sti_pwm_probe(struct platform_device *pdev)
 		return PTR_ERR(pc->pwm_clk);
 	}
 
-	pc->clk_rate = clk_get_rate(pc->pwm_clk);
-	if (!pc->clk_rate) {
-		dev_err(dev, "failed to get clock rate\n");
-		return -EINVAL;
-	}
-
 	ret = clk_prepare(pc->pwm_clk);
 	if (ret) {
 		dev_err(dev, "failed to prepare clock\n");
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 10/17] pwm: sti: Supply PWM Capture register addresses and bit locations
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (8 preceding siblings ...)
  2016-08-16  9:35 ` [PATCH v4 09/17] pwm: sti: Only request clock rate when you need to Lee Jones
@ 2016-08-16  9:35 ` Lee Jones
  2016-09-05 10:41   ` Thierry Reding
  2016-08-16  9:35 ` [PATCH v4 11/17] pwm: sti: Supply PWM Capture clock handling Lee Jones
                   ` (7 subsequent siblings)
  17 siblings, 1 reply; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:35 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/pwm/pwm-sti.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index 863d5a9..f2090c0 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -22,26 +22,48 @@
 #include <linux/time.h>
 
 #define PWM_OUT_VAL(x)	(0x00 + (4 * (x))) /* Device's Duty Cycle register */
+#define PWM_CPT_VAL(x)	(0x10 + (4 * (x))) /* Capture value */
+#define PWM_CPT_EDGE(x) (0x30 + (4 * (x))) /* Edge to capture on */
 
 #define STI_PWM_CTRL		0x50	/* Control/Config register */
 #define STI_INT_EN		0x54	/* Interrupt Enable/Disable register */
+#define STI_INT_STA		0x58	/* Interrupt Status register */
+#define PWM_INT_ACK			0x5c
 #define PWM_PRESCALE_LOW_MASK		0x0f
 #define PWM_PRESCALE_HIGH_MASK		0xf0
+#define PWM_CPT_EDGE_MASK		0x03
+#define PWM_INT_ACK_MASK		0x1ff
+
+#define STI_MAX_CPT_DEVS		4
+#define CPT_DC_MAX			0xff
 
 /* Regfield IDs */
 enum {
 	/* Bits in PWM_CTRL*/
 	PWMCLK_PRESCALE_LOW,
 	PWMCLK_PRESCALE_HIGH,
+	CPTCLK_PRESCALE,
 
 	PWM_OUT_EN,
+	PWM_CPT_EN,
 
 	PWM_CPT_INT_EN,
+	PWM_CPT_INT_STAT,
 
 	/* Keep last */
 	MAX_REGFIELDS
 };
 
+/* Each capture input can be programmed to detect rising-edge, falling-edge,
+ * either edge or neither egde
+ */
+enum sti_cpt_edge {
+	CPT_EDGE_DISABLED,
+	CPT_EDGE_RISING,
+	CPT_EDGE_FALLING,
+	CPT_EDGE_BOTH,
+};
+
 struct sti_pwm_compat_data {
 	const struct reg_field *reg_fields;
 	unsigned int num_devs;
@@ -69,8 +91,11 @@ struct sti_pwm_chip {
 static const struct reg_field sti_pwm_regfields[MAX_REGFIELDS] = {
 	[PWMCLK_PRESCALE_LOW]	= REG_FIELD(STI_PWM_CTRL, 0, 3),
 	[PWMCLK_PRESCALE_HIGH]	= REG_FIELD(STI_PWM_CTRL, 11, 14),
+	[CPTCLK_PRESCALE]	= REG_FIELD(STI_PWM_CTRL, 4, 8),
 	[PWM_OUT_EN]		= REG_FIELD(STI_PWM_CTRL, 9, 9),
+	[PWM_CPT_EN]		= REG_FIELD(STI_PWM_CTRL, 10, 10),
 	[PWM_CPT_INT_EN]	= REG_FIELD(STI_INT_EN, 1, 4),
+	[PWM_CPT_INT_STAT]	= REG_FIELD(STI_INT_STA, 1, 4),
 };
 
 static inline struct sti_pwm_chip *to_sti_pwmchip(struct pwm_chip *chip)
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 11/17] pwm: sti: Supply PWM Capture clock handling
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (9 preceding siblings ...)
  2016-08-16  9:35 ` [PATCH v4 10/17] pwm: sti: Supply PWM Capture register addresses and bit locations Lee Jones
@ 2016-08-16  9:35 ` Lee Jones
  2016-09-05 10:42   ` Thierry Reding
  2016-08-16  9:35 ` [PATCH v4 12/17] pwm: sti: Initialise PWM Capture device data Lee Jones
                   ` (6 subsequent siblings)
  17 siblings, 1 reply; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:35 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

ST's PWM IP is supplied by 2 different clocks.  One for PWM
Output and the other for Capture.  This patch provides clock
handling for the latter.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/pwm/pwm-sti.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index f2090c0..b596783 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -74,6 +74,7 @@ struct sti_pwm_compat_data {
 struct sti_pwm_chip {
 	struct device *dev;
 	struct clk *pwm_clk;
+	struct clk *cpt_clk;
 	struct regmap *regmap;
 	struct sti_pwm_compat_data *cdata;
 	struct regmap_field *prescale_low;
@@ -183,6 +184,10 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 		if (ret)
 			return ret;
 
+		ret = clk_enable(pc->cpt_clk);
+		if (ret)
+			return ret;
+
 		if (!period_same) {
 			ret = sti_pwm_get_prescale(pc, period_ns, &prescale);
 			if (ret)
@@ -227,6 +232,7 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 
 clk_dis:
 	clk_disable(pc->pwm_clk);
+	clk_disable(pc->cpt_clk);
 	return ret;
 }
 
@@ -246,6 +252,10 @@ static int sti_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
 		if (ret)
 			goto out;
 
+		ret = clk_enable(pc->cpt_clk);
+		if (ret)
+			goto out;
+
 		ret = regmap_field_write(pc->pwm_out_en, 1);
 		if (ret) {
 			dev_err(dev, "failed to enable PWM device:%d\n",
@@ -271,6 +281,7 @@ static void sti_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
 	regmap_field_write(pc->pwm_out_en, 0);
 
 	clk_disable(pc->pwm_clk);
+	clk_disable(pc->cpt_clk);
 	mutex_unlock(&pc->sti_pwm_lock);
 }
 
@@ -390,6 +401,18 @@ static int sti_pwm_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	pc->cpt_clk = of_clk_get_by_name(dev->of_node, "capture");
+	if (IS_ERR(pc->cpt_clk)) {
+		dev_err(dev, "failed to get PWM capture clock\n");
+		return PTR_ERR(pc->cpt_clk);
+	}
+
+	ret = clk_prepare(pc->cpt_clk);
+	if (ret) {
+		dev_err(dev, "failed to prepare clock\n");
+		return ret;
+	}
+
 	pc->chip.dev = dev;
 	pc->chip.ops = &sti_pwm_ops;
 	pc->chip.base = -1;
@@ -399,6 +422,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	ret = pwmchip_add(&pc->chip);
 	if (ret < 0) {
 		clk_unprepare(pc->pwm_clk);
+		clk_unprepare(pc->cpt_clk);
 		return ret;
 	}
 
@@ -416,6 +440,7 @@ static int sti_pwm_remove(struct platform_device *pdev)
 		pwm_disable(&pc->chip.pwms[i]);
 
 	clk_unprepare(pc->pwm_clk);
+	clk_unprepare(pc->cpt_clk);
 
 	return pwmchip_remove(&pc->chip);
 }
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 12/17] pwm: sti: Initialise PWM Capture device data
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (10 preceding siblings ...)
  2016-08-16  9:35 ` [PATCH v4 11/17] pwm: sti: Supply PWM Capture clock handling Lee Jones
@ 2016-08-16  9:35 ` Lee Jones
  2016-09-05 10:50   ` Thierry Reding
  2016-08-16  9:35 ` [PATCH v4 13/17] pwm: sti: Add support for PWM Capture IRQs Lee Jones
                   ` (5 subsequent siblings)
  17 siblings, 1 reply; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:35 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

Each PWM Capture device is allocated a structure to hold its own
state.  During a capture the device may be partaking in one of 3
phases.  Initial (rising) phase change, a subsequent (falling)
phase change indicating end of the duty-cycle phase and finally
a final (rising) phase change indicating the end of the period.
The timer value snapshot each event is held in a variable of the
same name, and the phase number (0, 1, 2) is contained in the
index variable.  Other device specific information, such as GPIO
pin, the IRQ wait queue and locking is also contained in the
structure.  This patch initialises this structure for each of
the available devices.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/pwm/pwm-sti.c | 45 ++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 38 insertions(+), 7 deletions(-)

diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index b596783..16c3f4d 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -11,6 +11,7 @@
  */
 
 #include <linux/clk.h>
+#include <linux/interrupt.h>
 #include <linux/math64.h>
 #include <linux/mfd/syscon.h>
 #include <linux/module.h>
@@ -18,8 +19,10 @@
 #include <linux/platform_device.h>
 #include <linux/pwm.h>
 #include <linux/regmap.h>
+#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/time.h>
+#include <linux/wait.h>
 
 #define PWM_OUT_VAL(x)	(0x00 + (4 * (x))) /* Device's Duty Cycle register */
 #define PWM_CPT_VAL(x)	(0x10 + (4 * (x))) /* Capture value */
@@ -64,9 +67,17 @@ enum sti_cpt_edge {
 	CPT_EDGE_BOTH,
 };
 
+struct sti_cpt_ddata {
+	u32 snapshot[3];
+	int index;
+	struct mutex lock;
+	wait_queue_head_t wait;
+};
+
 struct sti_pwm_compat_data {
 	const struct reg_field *reg_fields;
-	unsigned int num_devs;
+	unsigned int pwm_num_devs;
+	unsigned int cpt_num_devs;
 	unsigned int max_pwm_cnt;
 	unsigned int max_prescale;
 };
@@ -307,10 +318,15 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)
 	struct device_node *np = dev->of_node;
 	struct sti_pwm_compat_data *cdata = pc->cdata;
 	u32 num_devs;
+	int ret;
 
-	of_property_read_u32(np, "st,pwm-num-chans", &num_devs);
-	if (num_devs)
-		cdata->num_devs = num_devs;
+	ret = of_property_read_u32(np, "st,pwm-num-chan", &num_devs);
+	if (!ret)
+		cdata->pwm_num_devs = num_devs;
+
+	ret = of_property_read_u32(np, "st,capture-num-chan", &num_devs);
+	if (!ret)
+		cdata->cpt_num_devs = num_devs;
 
 	reg_fields = cdata->reg_fields;
 
@@ -350,6 +366,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	struct sti_pwm_compat_data *cdata;
 	struct sti_pwm_chip *pc;
 	struct resource *res;
+	unsigned int devnum;
 	int ret;
 
 	pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL);
@@ -378,7 +395,8 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	cdata->reg_fields   = &sti_pwm_regfields[0];
 	cdata->max_prescale = 0xff;
 	cdata->max_pwm_cnt  = 255;
-	cdata->num_devs     = 1;
+	cdata->pwm_num_devs = 1;
+	cdata->cpt_num_devs = 0;
 
 	pc->cdata = cdata;
 	pc->dev = dev;
@@ -416,7 +434,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	pc->chip.dev = dev;
 	pc->chip.ops = &sti_pwm_ops;
 	pc->chip.base = -1;
-	pc->chip.npwm = pc->cdata->num_devs;
+	pc->chip.npwm = pc->cdata->pwm_num_devs;
 	pc->chip.can_sleep = true;
 
 	ret = pwmchip_add(&pc->chip);
@@ -426,6 +444,19 @@ static int sti_pwm_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	for (devnum = 0; devnum < cdata->cpt_num_devs; devnum++) {
+		struct sti_cpt_ddata *ddata;
+
+		ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
+		if (!ddata)
+			return -ENOMEM;
+
+		init_waitqueue_head(&ddata->wait);
+		mutex_init(&ddata->lock);
+
+		pwm_set_chip_data(&pc->chip.pwms[devnum], ddata);
+	}
+
 	platform_set_drvdata(pdev, pc);
 
 	return 0;
@@ -436,7 +467,7 @@ static int sti_pwm_remove(struct platform_device *pdev)
 	struct sti_pwm_chip *pc = platform_get_drvdata(pdev);
 	unsigned int i;
 
-	for (i = 0; i < pc->cdata->num_devs; i++)
+	for (i = 0; i < pc->cdata->pwm_num_devs; i++)
 		pwm_disable(&pc->chip.pwms[i]);
 
 	clk_unprepare(pc->pwm_clk);
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 13/17] pwm: sti: Add support for PWM Capture IRQs
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (11 preceding siblings ...)
  2016-08-16  9:35 ` [PATCH v4 12/17] pwm: sti: Initialise PWM Capture device data Lee Jones
@ 2016-08-16  9:35 ` Lee Jones
  2016-09-05 10:53   ` Thierry Reding
  2016-08-16  9:35 ` [PATCH v4 14/17] pwm: sti: Add PWM Capture call-back Lee Jones
                   ` (4 subsequent siblings)
  17 siblings, 1 reply; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:35 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

Here we're requesting the PWM Capture IRQ and supplying the
handler which will be called in the event of an IRQ fire to
handle it.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/pwm/pwm-sti.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 91 insertions(+), 1 deletion(-)

diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index 16c3f4d..4686ba0 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -91,7 +91,9 @@ struct sti_pwm_chip {
 	struct regmap_field *prescale_low;
 	struct regmap_field *prescale_high;
 	struct regmap_field *pwm_out_en;
+	struct regmap_field *pwm_cpt_en;
 	struct regmap_field *pwm_cpt_int_en;
+	struct regmap_field *pwm_cpt_int_stat;
 	struct pwm_chip chip;
 	struct pwm_device *cur;
 	unsigned long configured;
@@ -311,6 +313,76 @@ static const struct pwm_ops sti_pwm_ops = {
 	.owner = THIS_MODULE,
 };
 
+static irqreturn_t sti_pwm_interrupt(int irq, void *data)
+{
+	struct sti_pwm_chip *pc = data;
+	struct device *dev = pc->dev;
+	struct sti_cpt_ddata *ddata;
+	int devicenum;
+	unsigned int cpt_int_stat;
+	unsigned int reg;
+	int ret = IRQ_NONE;
+
+	ret = regmap_field_read(pc->pwm_cpt_int_stat, &cpt_int_stat);
+	if (ret)
+		return ret;
+
+	while (cpt_int_stat) {
+		devicenum = ffs(cpt_int_stat) - 1;
+
+		ddata = pwm_get_chip_data(&pc->chip.pwms[devicenum]);
+
+		/*
+		 * Capture input:
+		 *    _______                   _______
+		 *   |       |                 |       |
+		 * __|       |_________________|       |________
+		 *   ^0      ^1                ^2
+		 *
+		 * Capture start by the first available rising edge
+		 * When a capture event occurs, capture value (CPT_VALx)
+		 * is stored, index incremented, capture edge changed.
+		 *
+		 * After the capture, if the index > 1, we have collected
+		 * the necessary data so we signal the thread waiting for it
+		 * and disable the capture by setting capture edge to none
+		 *
+		 */
+
+		regmap_read(pc->regmap,
+			    PWM_CPT_VAL(devicenum),
+			    &ddata->snapshot[ddata->index]);
+
+		switch (ddata->index) {
+		case 0:
+		case 1:
+			regmap_read(pc->regmap, PWM_CPT_EDGE(devicenum), &reg);
+			reg ^= PWM_CPT_EDGE_MASK;
+			regmap_write(pc->regmap, PWM_CPT_EDGE(devicenum), reg);
+
+			ddata->index++;
+			break;
+		case 2:
+			regmap_write(pc->regmap,
+				     PWM_CPT_EDGE(devicenum),
+				     CPT_EDGE_DISABLED);
+			wake_up(&ddata->wait);
+			break;
+		default:
+			dev_err(dev, "Internal error\n");
+		}
+
+		cpt_int_stat &= ~BIT_MASK(devicenum);
+
+		ret = IRQ_HANDLED;
+	}
+
+	/* Just ACK everything */
+	regmap_write(pc->regmap, PWM_INT_ACK, PWM_INT_ACK_MASK);
+
+	return ret;
+}
+
 static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)
 {
 	struct device *dev = pc->dev;
@@ -351,6 +423,11 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)
 	if (IS_ERR(pc->pwm_cpt_int_en))
 		return PTR_ERR(pc->pwm_cpt_int_en);
 
+	pc->pwm_cpt_int_stat = devm_regmap_field_alloc(dev, pc->regmap,
+						reg_fields[PWM_CPT_INT_STAT]);
+	if (PTR_ERR_OR_ZERO(pc->pwm_cpt_int_stat))
+		return PTR_ERR(pc->pwm_cpt_int_stat);
+
 	return 0;
 }
 
@@ -367,7 +444,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	struct sti_pwm_chip *pc;
 	struct resource *res;
 	unsigned int devnum;
-	int ret;
+	int irq, ret;
 
 	pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL);
 	if (!pc)
@@ -388,6 +465,19 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	if (IS_ERR(pc->regmap))
 		return PTR_ERR(pc->regmap);
 
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "Failed to obtain IRQ\n");
+		return irq;
+	}
+
+	ret = devm_request_irq(&pdev->dev, irq, sti_pwm_interrupt,
+			       0, pdev->name, pc);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to request IRQ\n");
+		return ret;
+	}
+
 	/*
 	 * Setup PWM data with default values: some values could be replaced
 	 * with specific ones provided from Device Tree.
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 14/17] pwm: sti: Add PWM Capture call-back
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (12 preceding siblings ...)
  2016-08-16  9:35 ` [PATCH v4 13/17] pwm: sti: Add support for PWM Capture IRQs Lee Jones
@ 2016-08-16  9:35 ` Lee Jones
  2016-09-05 11:10   ` Thierry Reding
  2016-08-16  9:35 ` [PATCH v4 15/17] pwm: sti: It's now valid for number of PWM channels to be zero Lee Jones
                   ` (3 subsequent siblings)
  17 siblings, 1 reply; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:35 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

Once a PWM Capture has been initiated, the capture call
enables a rising edge detection IRQ, then waits.  Once each
of the 3 phase changes have been recorded the thread then
wakes.  The remaining part of the call carries out the
relevant calculations and passes back a formatted string to
the caller.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/pwm/pwm-sti.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index 4686ba0..fcc80eb 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -24,6 +24,8 @@
 #include <linux/time.h>
 #include <linux/wait.h>
 
+#define SECS_TO_NANOSECS(x) ((x) * 1000 * 1000 * 1000)
+
 #define PWM_OUT_VAL(x)	(0x00 + (4 * (x))) /* Device's Duty Cycle register */
 #define PWM_CPT_VAL(x)	(0x10 + (4 * (x))) /* Capture value */
 #define PWM_CPT_EDGE(x) (0x30 + (4 * (x))) /* Edge to capture on */
@@ -305,7 +307,88 @@ static void sti_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
 	clear_bit(pwm->hwpwm, &pc->configured);
 }
 
+static int sti_pwm_capture(struct pwm_chip *chip, struct pwm_device *pwm,
+			   struct pwm_capture *result, unsigned long timeout)
+{
+	struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
+	struct sti_pwm_compat_data *cdata = pc->cdata;
+	struct sti_cpt_ddata *ddata = pwm_get_chip_data(pwm);
+	struct device *dev = pc->dev;
+	unsigned int effective_ticks;
+	unsigned long long high, low;
+	int ret;
+
+	if (pwm->hwpwm > cdata->cpt_num_devs - 1) {
+		dev_err(dev, "Device %d is not valid\n", pwm->hwpwm);
+		return -EINVAL;
+	}
+
+	mutex_lock(&ddata->lock);
+
+	/* Prepare capture measurement */
+	ddata->index = 0;
+	regmap_write(pc->regmap, PWM_CPT_EDGE(pwm->hwpwm), CPT_EDGE_RISING);
+	regmap_field_write(pc->pwm_cpt_int_en, BIT(pwm->hwpwm));
+
+	/* Enable capture */
+	ret = regmap_field_write(pc->pwm_cpt_en, 1);
+	if (ret) {
+		dev_err(dev, "failed to enable PWM capture %d\n", pwm->hwpwm);
+		goto out;
+	}
+
+	ret = wait_event_interruptible_timeout(ddata->wait,
+					       ddata->index > 1,
+					       msecs_to_jiffies(timeout));
+
+	regmap_write(pc->regmap, PWM_CPT_EDGE(pwm->hwpwm), CPT_EDGE_DISABLED);
+
+	if (ret == -ERESTARTSYS)
+		goto out;
+
+	switch (ddata->index) {
+	case 0:
+	case 1:
+		/*
+		 * Getting here could mean :
+		 *  - input signal is constant of less than 1Hz
+		 *  - there is no input signal at all
+		 *
+		 * In such case the frequency is rounded down to 0
+		 */
+
+		result->period = 0;
+		result->duty_cycle = 0;
+
+		break;
+	case 2:
+		/* We have everying we need */
+		high = ddata->snapshot[1] - ddata->snapshot[0];
+		low  = ddata->snapshot[2] - ddata->snapshot[1];
+
+		effective_ticks = clk_get_rate(pc->cpt_clk);
+
+		result->period = SECS_TO_NANOSECS(high + low);
+		result->period /= effective_ticks;
+
+		result->duty_cycle = SECS_TO_NANOSECS(high);
+		result->duty_cycle /= effective_ticks;
+
+		break;
+	default:
+		dev_err(dev, "Internal error\n");
+	}
+
+out:
+	/* Disable capture */
+	regmap_field_write(pc->pwm_cpt_en, 0);
+
+	mutex_unlock(&ddata->lock);
+	return ret;
+}
+
 static const struct pwm_ops sti_pwm_ops = {
+	.capture = sti_pwm_capture,
 	.config = sti_pwm_config,
 	.enable = sti_pwm_enable,
 	.disable = sti_pwm_disable,
@@ -418,6 +501,11 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)
 	if (IS_ERR(pc->pwm_out_en))
 		return PTR_ERR(pc->pwm_out_en);
 
+	pc->pwm_cpt_en = devm_regmap_field_alloc(dev, pc->regmap,
+						 reg_fields[PWM_CPT_EN]);
+	if (IS_ERR(pc->pwm_cpt_en))
+		return PTR_ERR(pc->pwm_cpt_en);
+
 	pc->pwm_cpt_int_en = devm_regmap_field_alloc(dev, pc->regmap,
 						 reg_fields[PWM_CPT_INT_EN]);
 	if (IS_ERR(pc->pwm_cpt_int_en))
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 15/17] pwm: sti: It's now valid for number of PWM channels to be zero
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (13 preceding siblings ...)
  2016-08-16  9:35 ` [PATCH v4 14/17] pwm: sti: Add PWM Capture call-back Lee Jones
@ 2016-08-16  9:35 ` Lee Jones
  2016-09-05 11:20   ` Thierry Reding
  2016-08-16  9:35 ` [PATCH v4 16/17] pwm: sti: Take the opportunity to conduct a little house keeping Lee Jones
                   ` (2 subsequent siblings)
  17 siblings, 1 reply; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:35 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

Setting up the STI PWM IP as capture only, with zero PWM-out devices
is a perfectly valued configuration.  It is no longer okay to assume
that there must be at least 1 PWM-out devices.  In this patch we make
the default number of PWM-out devices zero and only configure channels
explicitly requested.

Reported-by: Peter Griffin <peter.griffin@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/pwm/pwm-sti.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index fcc80eb..a1319c0 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -483,6 +483,11 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)
 	if (!ret)
 		cdata->cpt_num_devs = num_devs;
 
+	if (cdata->pwm_num_devs && !cdata->cpt_num_devs) {
+		dev_err(dev, "No channels configured\n");
+		return -EINVAL;
+	}
+
 	reg_fields = cdata->reg_fields;
 
 	pc->prescale_low = devm_regmap_field_alloc(dev, pc->regmap,
@@ -573,7 +578,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	cdata->reg_fields   = &sti_pwm_regfields[0];
 	cdata->max_prescale = 0xff;
 	cdata->max_pwm_cnt  = 255;
-	cdata->pwm_num_devs = 1;
+	cdata->pwm_num_devs = 0;
 	cdata->cpt_num_devs = 0;
 
 	pc->cdata = cdata;
@@ -585,6 +590,9 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	if (!cdata->pwm_num_devs)
+		goto skip_pwm;
+
 	pc->pwm_clk = of_clk_get_by_name(dev->of_node, "pwm");
 	if (IS_ERR(pc->pwm_clk)) {
 		dev_err(dev, "failed to get PWM clock\n");
@@ -597,6 +605,10 @@ static int sti_pwm_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+skip_pwm:
+	if (!cdata->cpt_num_devs)
+		goto skip_cpt;
+
 	pc->cpt_clk = of_clk_get_by_name(dev->of_node, "capture");
 	if (IS_ERR(pc->cpt_clk)) {
 		dev_err(dev, "failed to get PWM capture clock\n");
@@ -609,6 +621,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+skip_cpt:
 	pc->chip.dev = dev;
 	pc->chip.ops = &sti_pwm_ops;
 	pc->chip.base = -1;
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 16/17] pwm: sti: Take the opportunity to conduct a little house keeping
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (14 preceding siblings ...)
  2016-08-16  9:35 ` [PATCH v4 15/17] pwm: sti: It's now valid for number of PWM channels to be zero Lee Jones
@ 2016-08-16  9:35 ` Lee Jones
  2016-09-05 11:37   ` Thierry Reding
  2016-08-16  9:35 ` [PATCH v4 17/17] dt-bindings: pwm: sti: Update DT bindings with recent changes Lee Jones
  2016-08-25 11:51 ` [STLinux Kernel] [PATCH v4 00/17] pwm: Add support for PWM Capture Peter Griffin
  17 siblings, 1 reply; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:35 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

This includes fixing some Coding Style issues and re-ordering/
simplifying a little code.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/pwm/pwm-sti.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index a1319c0..3d5b9aa 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -1,8 +1,10 @@
 /*
- * PWM device driver for ST SoCs.
- * Author: Ajit Pal Singh <ajitpal.singh@st.com>
+ * PWM device driver for ST SoCs
+ *
+ * Copyright (C) 2013-2016 STMicroelectronics (R&D) Limited
  *
- * Copyright (C) 2013-2014 STMicroelectronics (R&D) Limited
+ * Author: Ajit Pal Singh <ajitpal.singh@st.com>
+ *         Lee Jones <lee.jones@linaro.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -142,13 +144,13 @@ static int sti_pwm_get_prescale(struct sti_pwm_chip *pc, unsigned long period,
 	val = NSEC_PER_SEC / clk_rate;
 	val *= cdata->max_pwm_cnt + 1;
 
-	if (period % val) {
+	if (period % val)
 		return -EINVAL;
-	} else {
-		ps  = period / val - 1;
-		if (ps > cdata->max_prescale)
-			return -EINVAL;
-	}
+
+	ps  = period / val - 1;
+	if (ps > cdata->max_prescale)
+		return -EINVAL;
+
 	*prescale = ps;
 
 	return 0;
@@ -164,7 +166,7 @@ static int sti_pwm_get_prescale(struct sti_pwm_chip *pc, unsigned long period,
  * 256 values.
  */
 static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
-			 int duty_ns, int period_ns)
+			int duty_ns, int period_ns)
 {
 	struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
 	struct sti_pwm_compat_data *cdata = pc->cdata;
@@ -210,7 +212,7 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 
 			ret =
 			regmap_field_write(pc->prescale_low,
-					   prescale & PWM_PRESCALE_LOW_MASK);
+				prescale & PWM_PRESCALE_LOW_MASK);
 			if (ret)
 				goto clk_dis;
 
@@ -273,7 +275,7 @@ static int sti_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
 
 		ret = regmap_field_write(pc->pwm_out_en, 1);
 		if (ret) {
-			dev_err(dev, "failed to enable PWM device:%d\n",
+			dev_err(dev, "failed to enable PWM device %d\n",
 				pwm->hwpwm);
 			goto out;
 		}
@@ -293,10 +295,12 @@ static void sti_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
 		mutex_unlock(&pc->sti_pwm_lock);
 		return;
 	}
+
 	regmap_field_write(pc->pwm_out_en, 0);
 
 	clk_disable(pc->pwm_clk);
 	clk_disable(pc->cpt_clk);
+
 	mutex_unlock(&pc->sti_pwm_lock);
 }
 
@@ -512,7 +516,7 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)
 		return PTR_ERR(pc->pwm_cpt_en);
 
 	pc->pwm_cpt_int_en = devm_regmap_field_alloc(dev, pc->regmap,
-						 reg_fields[PWM_CPT_INT_EN]);
+						reg_fields[PWM_CPT_INT_EN]);
 	if (IS_ERR(pc->pwm_cpt_int_en))
 		return PTR_ERR(pc->pwm_cpt_int_en);
 
@@ -575,11 +579,11 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	 * Setup PWM data with default values: some values could be replaced
 	 * with specific ones provided from Device Tree.
 	 */
-	cdata->reg_fields   = &sti_pwm_regfields[0];
-	cdata->max_prescale = 0xff;
-	cdata->max_pwm_cnt  = 255;
-	cdata->pwm_num_devs = 0;
-	cdata->cpt_num_devs = 0;
+	cdata->reg_fields	= &sti_pwm_regfields[0];
+	cdata->max_prescale	= 0xff;
+	cdata->max_pwm_cnt	= 255;
+	cdata->pwm_num_devs	= 0;
+	cdata->cpt_num_devs	= 0;
 
 	pc->cdata = cdata;
 	pc->dev = dev;
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 17/17] dt-bindings: pwm: sti: Update DT bindings with recent changes
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (15 preceding siblings ...)
  2016-08-16  9:35 ` [PATCH v4 16/17] pwm: sti: Take the opportunity to conduct a little house keeping Lee Jones
@ 2016-08-16  9:35 ` Lee Jones
  2016-08-18 19:20   ` Rob Herring
  2016-09-05 10:29   ` Thierry Reding
  2016-08-25 11:51 ` [STLinux Kernel] [PATCH v4 00/17] pwm: Add support for PWM Capture Peter Griffin
  17 siblings, 2 replies; 33+ messages in thread
From: Lee Jones @ 2016-08-16  9:35 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: kernel, patrice.chotard, thierry.reding, linux-pwm, devicetree,
	Lee Jones

We're renaming the 'st,pwm-num-chan' binding to 'st,pwm-num-devs' to
be more inline with the naming conventions of the subsystem.  Where
we used to treat each line as a channel, the PWM convention is to
describe them as devices.

The second documentation adaption entails adding support for PWM
capture devices.  A new clock is required as well as an IRQ line.
We're also adding a new property similar to the one described
above, but for capture channels.  Typically, there will be less
capture channels than PWM-out, since all channels have the latter
capability, but only some have capture support.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 Documentation/devicetree/bindings/pwm/pwm-st.txt | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/pwm/pwm-st.txt b/Documentation/devicetree/bindings/pwm/pwm-st.txt
index 84d2fb8..19fce77 100644
--- a/Documentation/devicetree/bindings/pwm/pwm-st.txt
+++ b/Documentation/devicetree/bindings/pwm/pwm-st.txt
@@ -13,13 +13,14 @@ Required parameters:
 - pinctrl-0: 		List of phandles pointing to pin configuration nodes
 			for PWM module.
 			For Pinctrl properties, please refer to [1].
-- clock-names: 		Set to "pwm".
+- clock-names: 		Valid entries are "pwm" and/or "capture".
 - clocks: 		phandle of the clock used by the PWM module.
 			For Clk properties, please refer to [2].
+- interrupts:		IRQ for the Capture device
 
 Optional properties:
-- st,pwm-num-chan:	Number of available channels. If not passed, the driver
-			will consider single channel by default.
+- st,pwm-num-chan:	Number of available PWM channels.  Default is 0.
+- st,capture-num-chan:	Number of available Capture channels.  Default is 0.
 
 [1] Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt
 [2] Documentation/devicetree/bindings/clock/clock-bindings.txt
@@ -38,4 +39,5 @@ pwm1: pwm@fe510000 {
 	clocks = <&clk_sysin>;
 	clock-names = "pwm";
 	st,pwm-num-chan = <4>;
+	st,capture-num-chan = <2>;
 };
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 17/17] dt-bindings: pwm: sti: Update DT bindings with recent changes
  2016-08-16  9:35 ` [PATCH v4 17/17] dt-bindings: pwm: sti: Update DT bindings with recent changes Lee Jones
@ 2016-08-18 19:20   ` Rob Herring
  2016-08-19  8:35     ` Lee Jones
  2016-09-05 10:29   ` Thierry Reding
  1 sibling, 1 reply; 33+ messages in thread
From: Rob Herring @ 2016-08-18 19:20 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, kernel, patrice.chotard,
	thierry.reding, linux-pwm, devicetree

On Tue, Aug 16, 2016 at 10:35:08AM +0100, Lee Jones wrote:
> We're renaming the 'st,pwm-num-chan' binding to 'st,pwm-num-devs' to
> be more inline with the naming conventions of the subsystem.  Where
> we used to treat each line as a channel, the PWM convention is to
> describe them as devices.

This is out of date now. Otherwise, the binding looks fine.

> The second documentation adaption entails adding support for PWM
> capture devices.  A new clock is required as well as an IRQ line.
> We're also adding a new property similar to the one described
> above, but for capture channels.  Typically, there will be less
> capture channels than PWM-out, since all channels have the latter
> capability, but only some have capture support.
> 
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  Documentation/devicetree/bindings/pwm/pwm-st.txt | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 17/17] dt-bindings: pwm: sti: Update DT bindings with recent changes
  2016-08-18 19:20   ` Rob Herring
@ 2016-08-19  8:35     ` Lee Jones
  2016-08-19 12:45       ` Rob Herring
  0 siblings, 1 reply; 33+ messages in thread
From: Lee Jones @ 2016-08-19  8:35 UTC (permalink / raw)
  To: Rob Herring
  Cc: linux-arm-kernel, linux-kernel, kernel, patrice.chotard,
	thierry.reding, linux-pwm, devicetree

On Thu, 18 Aug 2016, Rob Herring wrote:

> On Tue, Aug 16, 2016 at 10:35:08AM +0100, Lee Jones wrote:
> > We're renaming the 'st,pwm-num-chan' binding to 'st,pwm-num-devs' to
> > be more inline with the naming conventions of the subsystem.  Where
> > we used to treat each line as a channel, the PWM convention is to
> > describe them as devices.
> 
> This is out of date now. Otherwise, the binding looks fine.

Yes, you are right.

Perhaps if this is okay with Thierry, he can remove these few lines.
If not, I don't mind re-sending on request.

I'll leave it until I hear otherwise.

> > The second documentation adaption entails adding support for PWM
> > capture devices.  A new clock is required as well as an IRQ line.
> > We're also adding a new property similar to the one described
> > above, but for capture channels.  Typically, there will be less
> > capture channels than PWM-out, since all channels have the latter
> > capability, but only some have capture support.
> > 
> > Signed-off-by: Lee Jones <lee.jones@linaro.org>
> > ---
> >  Documentation/devicetree/bindings/pwm/pwm-st.txt | 8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 17/17] dt-bindings: pwm: sti: Update DT bindings with recent changes
  2016-08-19  8:35     ` Lee Jones
@ 2016-08-19 12:45       ` Rob Herring
  0 siblings, 0 replies; 33+ messages in thread
From: Rob Herring @ 2016-08-19 12:45 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, kernel, Patrice Chotard,
	Thierry Reding, Linux PWM List, devicetree

On Fri, Aug 19, 2016 at 3:35 AM, Lee Jones <lee.jones@linaro.org> wrote:
> On Thu, 18 Aug 2016, Rob Herring wrote:
>
>> On Tue, Aug 16, 2016 at 10:35:08AM +0100, Lee Jones wrote:
>> > We're renaming the 'st,pwm-num-chan' binding to 'st,pwm-num-devs' to
>> > be more inline with the naming conventions of the subsystem.  Where
>> > we used to treat each line as a channel, the PWM convention is to
>> > describe them as devices.
>>
>> This is out of date now. Otherwise, the binding looks fine.
>
> Yes, you are right.
>
> Perhaps if this is okay with Thierry, he can remove these few lines.
> If not, I don't mind re-sending on request.
>
> I'll leave it until I hear otherwise.

Fine with me.

Acked-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [STLinux Kernel] [PATCH v4 00/17] pwm: Add support for PWM Capture
  2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
                   ` (16 preceding siblings ...)
  2016-08-16  9:35 ` [PATCH v4 17/17] dt-bindings: pwm: sti: Update DT bindings with recent changes Lee Jones
@ 2016-08-25 11:51 ` Peter Griffin
  17 siblings, 0 replies; 33+ messages in thread
From: Peter Griffin @ 2016-08-25 11:51 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, linux-pwm, kernel, devicetree,
	thierry.reding

Hi Lee,

On Tue, 16 Aug 2016, Lee Jones wrote:

> This patch-set makes use of the new Capture API by supplying PWM
> Capture functionality into the already existing STi PWM driver.

For the series: -

Acked-by: Peter Griffin <peter.griffin@linaro.org>

Regards,

Peter.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 17/17] dt-bindings: pwm: sti: Update DT bindings with recent changes
  2016-08-16  9:35 ` [PATCH v4 17/17] dt-bindings: pwm: sti: Update DT bindings with recent changes Lee Jones
  2016-08-18 19:20   ` Rob Herring
@ 2016-09-05 10:29   ` Thierry Reding
  1 sibling, 0 replies; 33+ messages in thread
From: Thierry Reding @ 2016-09-05 10:29 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, kernel, patrice.chotard,
	linux-pwm, devicetree

[-- Attachment #1: Type: text/plain, Size: 1098 bytes --]

On Tue, Aug 16, 2016 at 10:35:08AM +0100, Lee Jones wrote:
> We're renaming the 'st,pwm-num-chan' binding to 'st,pwm-num-devs' to
> be more inline with the naming conventions of the subsystem.  Where
> we used to treat each line as a channel, the PWM convention is to
> describe them as devices.
> 
> The second documentation adaption entails adding support for PWM
> capture devices.  A new clock is required as well as an IRQ line.
> We're also adding a new property similar to the one described
> above, but for capture channels.  Typically, there will be less
> capture channels than PWM-out, since all channels have the latter
> capability, but only some have capture support.
> 
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  Documentation/devicetree/bindings/pwm/pwm-st.txt | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)

Applied with a reworded commit message as discussed elsewhere in this
thread. I've also applied this in front of all other patches because I
think of the DT bindings as specifications that drivers implement.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 07/17] pwm: sti: Rename channel => device
  2016-08-16  9:34 ` [PATCH v4 07/17] pwm: sti: Rename channel => device Lee Jones
@ 2016-09-05 10:33   ` Thierry Reding
  0 siblings, 0 replies; 33+ messages in thread
From: Thierry Reding @ 2016-09-05 10:33 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, kernel, patrice.chotard,
	linux-pwm, devicetree

[-- Attachment #1: Type: text/plain, Size: 1099 bytes --]

On Tue, Aug 16, 2016 at 10:34:58AM +0100, Lee Jones wrote:
> This is to bring the terminology used in the STi PWM driver more
> into line with the PWM subsystem.
> 
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/pwm/pwm-sti.c | 32 ++++++++++++++++----------------
>  1 file changed, 16 insertions(+), 16 deletions(-)

Note that it's fine if drivers use different terminology for internals.
Many manuals seem to be using the channel terminology and many drivers
use that. But if you prefer devices that's fine with me.

I've applied this with a minor change, see below.

> diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
[...]
> -	of_property_read_u32(np, "st,pwm-num-chan", &num_chan);
> -	if (num_chan)
> -		cdata->num_chan = num_chan;
> +	of_property_read_u32(np, "st,pwm-num-chans", &num_devs);
> +	if (num_devs)
> +		cdata->num_devs = num_devs;

I kept the "st,pwm-num-chan" as property name here to avoid breaking
backwards compatiblity. This series changes it back to "st,pwm-num-chan"
sometime later in this series anyway.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 08/17] pwm: sti: Reorganise register names in preparation for new functionality
  2016-08-16  9:34 ` [PATCH v4 08/17] pwm: sti: Reorganise register names in preparation for new functionality Lee Jones
@ 2016-09-05 10:35   ` Thierry Reding
  0 siblings, 0 replies; 33+ messages in thread
From: Thierry Reding @ 2016-09-05 10:35 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, kernel, patrice.chotard,
	linux-pwm, devicetree

[-- Attachment #1: Type: text/plain, Size: 456 bytes --]

On Tue, Aug 16, 2016 at 10:34:59AM +0100, Lee Jones wrote:
> Exciting functionality is on the way to this device.  But
> before we can add it, we need to do some basic housekeeping
> so the additions can be added cleanly.
> 
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/pwm/pwm-sti.c | 76 +++++++++++++++++++++++++++------------------------
>  1 file changed, 41 insertions(+), 35 deletions(-)

Applied, thanks.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 09/17] pwm: sti: Only request clock rate when you need to
  2016-08-16  9:35 ` [PATCH v4 09/17] pwm: sti: Only request clock rate when you need to Lee Jones
@ 2016-09-05 10:36   ` Thierry Reding
  0 siblings, 0 replies; 33+ messages in thread
From: Thierry Reding @ 2016-09-05 10:36 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, kernel, patrice.chotard,
	linux-pwm, devicetree

[-- Attachment #1: Type: text/plain, Size: 463 bytes --]

On Tue, Aug 16, 2016 at 10:35:00AM +0100, Lee Jones wrote:
> In the original code the clock rate was only obtained during
> initialisation; however, the rate may change between then and
> its use.  This patch ensures the correct rate is acquired just
> before use.
> 
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/pwm/pwm-sti.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)

Applied, thanks.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 10/17] pwm: sti: Supply PWM Capture register addresses and bit locations
  2016-08-16  9:35 ` [PATCH v4 10/17] pwm: sti: Supply PWM Capture register addresses and bit locations Lee Jones
@ 2016-09-05 10:41   ` Thierry Reding
  0 siblings, 0 replies; 33+ messages in thread
From: Thierry Reding @ 2016-09-05 10:41 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, kernel, patrice.chotard,
	linux-pwm, devicetree

[-- Attachment #1: Type: text/plain, Size: 268 bytes --]

On Tue, Aug 16, 2016 at 10:35:01AM +0100, Lee Jones wrote:
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/pwm/pwm-sti.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)

Applied with a short commit message added.

Thanks,
Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 11/17] pwm: sti: Supply PWM Capture clock handling
  2016-08-16  9:35 ` [PATCH v4 11/17] pwm: sti: Supply PWM Capture clock handling Lee Jones
@ 2016-09-05 10:42   ` Thierry Reding
  0 siblings, 0 replies; 33+ messages in thread
From: Thierry Reding @ 2016-09-05 10:42 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, kernel, patrice.chotard,
	linux-pwm, devicetree

[-- Attachment #1: Type: text/plain, Size: 402 bytes --]

On Tue, Aug 16, 2016 at 10:35:02AM +0100, Lee Jones wrote:
> ST's PWM IP is supplied by 2 different clocks.  One for PWM
> Output and the other for Capture.  This patch provides clock
> handling for the latter.
> 
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/pwm/pwm-sti.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)

Applied, thanks.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 12/17] pwm: sti: Initialise PWM Capture device data
  2016-08-16  9:35 ` [PATCH v4 12/17] pwm: sti: Initialise PWM Capture device data Lee Jones
@ 2016-09-05 10:50   ` Thierry Reding
  0 siblings, 0 replies; 33+ messages in thread
From: Thierry Reding @ 2016-09-05 10:50 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, kernel, patrice.chotard,
	linux-pwm, devicetree

[-- Attachment #1: Type: text/plain, Size: 2404 bytes --]

On Tue, Aug 16, 2016 at 10:35:03AM +0100, Lee Jones wrote:
> Each PWM Capture device is allocated a structure to hold its own
> state.  During a capture the device may be partaking in one of 3
> phases.  Initial (rising) phase change, a subsequent (falling)
> phase change indicating end of the duty-cycle phase and finally
> a final (rising) phase change indicating the end of the period.
> The timer value snapshot each event is held in a variable of the
> same name, and the phase number (0, 1, 2) is contained in the
> index variable.  Other device specific information, such as GPIO
> pin, the IRQ wait queue and locking is also contained in the
> structure.  This patch initialises this structure for each of
> the available devices.
> 
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/pwm/pwm-sti.c | 45 ++++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 38 insertions(+), 7 deletions(-)

Applied this with two small changes. See below.

> diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
[...]
> +struct sti_cpt_ddata {
> +	u32 snapshot[3];
> +	int index;

I made this unsigned int because it never needs to be negative.

> @@ -350,6 +366,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
>  	struct sti_pwm_compat_data *cdata;
>  	struct sti_pwm_chip *pc;
>  	struct resource *res;
> +	unsigned int devnum;

Renamed this variable to "i" because it's...

>  	int ret;
>  
>  	pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL);
> @@ -378,7 +395,8 @@ static int sti_pwm_probe(struct platform_device *pdev)
>  	cdata->reg_fields   = &sti_pwm_regfields[0];
>  	cdata->max_prescale = 0xff;
>  	cdata->max_pwm_cnt  = 255;
> -	cdata->num_devs     = 1;
> +	cdata->pwm_num_devs = 1;
> +	cdata->cpt_num_devs = 0;
>  
>  	pc->cdata = cdata;
>  	pc->dev = dev;
> @@ -416,7 +434,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
>  	pc->chip.dev = dev;
>  	pc->chip.ops = &sti_pwm_ops;
>  	pc->chip.base = -1;
> -	pc->chip.npwm = pc->cdata->num_devs;
> +	pc->chip.npwm = pc->cdata->pwm_num_devs;
>  	pc->chip.can_sleep = true;
>  
>  	ret = pwmchip_add(&pc->chip);
> @@ -426,6 +444,19 @@ static int sti_pwm_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> +	for (devnum = 0; devnum < cdata->cpt_num_devs; devnum++) {

... usage here becomes more idiomatic.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 13/17] pwm: sti: Add support for PWM Capture IRQs
  2016-08-16  9:35 ` [PATCH v4 13/17] pwm: sti: Add support for PWM Capture IRQs Lee Jones
@ 2016-09-05 10:53   ` Thierry Reding
  0 siblings, 0 replies; 33+ messages in thread
From: Thierry Reding @ 2016-09-05 10:53 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, kernel, patrice.chotard,
	linux-pwm, devicetree

[-- Attachment #1: Type: text/plain, Size: 428 bytes --]

On Tue, Aug 16, 2016 at 10:35:04AM +0100, Lee Jones wrote:
> Here we're requesting the PWM Capture IRQ and supplying the
> handler which will be called in the event of an IRQ fire to
> handle it.
> 
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/pwm/pwm-sti.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 91 insertions(+), 1 deletion(-)

Applied, thanks.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 14/17] pwm: sti: Add PWM Capture call-back
  2016-08-16  9:35 ` [PATCH v4 14/17] pwm: sti: Add PWM Capture call-back Lee Jones
@ 2016-09-05 11:10   ` Thierry Reding
  0 siblings, 0 replies; 33+ messages in thread
From: Thierry Reding @ 2016-09-05 11:10 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, kernel, patrice.chotard,
	linux-pwm, devicetree

[-- Attachment #1: Type: text/plain, Size: 1791 bytes --]

On Tue, Aug 16, 2016 at 10:35:05AM +0100, Lee Jones wrote:
> Once a PWM Capture has been initiated, the capture call
> enables a rising edge detection IRQ, then waits.  Once each
> of the 3 phase changes have been recorded the thread then
> wakes.  The remaining part of the call carries out the
> relevant calculations and passes back a formatted string to
> the caller.
> 
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/pwm/pwm-sti.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 88 insertions(+)

Applied with minor changes. See below.

> diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
[...]
> +#define SECS_TO_NANOSECS(x) ((x) * 1000 * 1000 * 1000)

I dropped this in favour of doing the multiplication by NSEC_PER_SEC in
situ.

> +
>  #define PWM_OUT_VAL(x)	(0x00 + (4 * (x))) /* Device's Duty Cycle register */
>  #define PWM_CPT_VAL(x)	(0x10 + (4 * (x))) /* Capture value */
>  #define PWM_CPT_EDGE(x) (0x30 + (4 * (x))) /* Edge to capture on */
> @@ -305,7 +307,88 @@ static void sti_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
>  	clear_bit(pwm->hwpwm, &pc->configured);
>  }
>  
> +static int sti_pwm_capture(struct pwm_chip *chip, struct pwm_device *pwm,
> +			   struct pwm_capture *result, unsigned long timeout)
> +{
> +	struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
> +	struct sti_pwm_compat_data *cdata = pc->cdata;
> +	struct sti_cpt_ddata *ddata = pwm_get_chip_data(pwm);
> +	struct device *dev = pc->dev;
> +	unsigned int effective_ticks;
> +	unsigned long long high, low;
> +	int ret;
> +
> +	if (pwm->hwpwm > cdata->cpt_num_devs - 1) {

Turned this into:

	if (pwm->hwpwm >= cdata->cpt_num_devs) {

because I find that easier to read.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 15/17] pwm: sti: It's now valid for number of PWM channels to be zero
  2016-08-16  9:35 ` [PATCH v4 15/17] pwm: sti: It's now valid for number of PWM channels to be zero Lee Jones
@ 2016-09-05 11:20   ` Thierry Reding
  0 siblings, 0 replies; 33+ messages in thread
From: Thierry Reding @ 2016-09-05 11:20 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, kernel, patrice.chotard,
	linux-pwm, devicetree

[-- Attachment #1: Type: text/plain, Size: 1080 bytes --]

On Tue, Aug 16, 2016 at 10:35:06AM +0100, Lee Jones wrote:
> Setting up the STI PWM IP as capture only, with zero PWM-out devices
> is a perfectly valued configuration.  It is no longer okay to assume
> that there must be at least 1 PWM-out devices.  In this patch we make
> the default number of PWM-out devices zero and only configure channels
> explicitly requested.
> 
> Reported-by: Peter Griffin <peter.griffin@linaro.org>
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/pwm/pwm-sti.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
> index fcc80eb..a1319c0 100644
> --- a/drivers/pwm/pwm-sti.c
> +++ b/drivers/pwm/pwm-sti.c
> @@ -483,6 +483,11 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)
>  	if (!ret)
>  		cdata->cpt_num_devs = num_devs;
>  
> +	if (cdata->pwm_num_devs && !cdata->cpt_num_devs) {

Applied, with this corrected to:

	if (!cdata->pwm_num_devs && !cdata->cpu_num_devs)

as discussed on IRC.

Thanks,
Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 16/17] pwm: sti: Take the opportunity to conduct a little house keeping
  2016-08-16  9:35 ` [PATCH v4 16/17] pwm: sti: Take the opportunity to conduct a little house keeping Lee Jones
@ 2016-09-05 11:37   ` Thierry Reding
  0 siblings, 0 replies; 33+ messages in thread
From: Thierry Reding @ 2016-09-05 11:37 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-arm-kernel, linux-kernel, kernel, patrice.chotard,
	linux-pwm, devicetree

[-- Attachment #1: Type: text/plain, Size: 403 bytes --]

On Tue, Aug 16, 2016 at 10:35:07AM +0100, Lee Jones wrote:
> This includes fixing some Coding Style issues and re-ordering/
> simplifying a little code.
> 
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/pwm/pwm-sti.c | 40 ++++++++++++++++++++++------------------
>  1 file changed, 22 insertions(+), 18 deletions(-)

Applied with a little bikeshedding.

Thanks,
Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2016-09-05 11:38 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-16  9:34 [PATCH v4 00/17] pwm: Add support for PWM Capture Lee Jones
2016-08-16  9:34 ` [PATCH v4 01/17] ARM: dts: STiH407: Supply PWM Capture IRQ Lee Jones
2016-08-16  9:34 ` [PATCH v4 02/17] ARM: dts: STiH407: Declare PWM Capture data lines via Pinctrl Lee Jones
2016-08-16  9:34 ` [PATCH v4 03/17] ARM: dts: STiH416: Supply PWM Capture IRQs Lee Jones
2016-08-16  9:34 ` [PATCH v4 04/17] ARM: dts: STiH416: Declare PWM Capture data lines via Pinctrl Lee Jones
2016-08-16  9:34 ` [PATCH v4 05/17] ARM: dts: STiH416: Define PWM Capture clock Lee Jones
2016-08-16  9:34 ` [PATCH v4 06/17] ARM: dts: STiH416: Define the number of PWM Capture channels Lee Jones
2016-08-16  9:34 ` [PATCH v4 07/17] pwm: sti: Rename channel => device Lee Jones
2016-09-05 10:33   ` Thierry Reding
2016-08-16  9:34 ` [PATCH v4 08/17] pwm: sti: Reorganise register names in preparation for new functionality Lee Jones
2016-09-05 10:35   ` Thierry Reding
2016-08-16  9:35 ` [PATCH v4 09/17] pwm: sti: Only request clock rate when you need to Lee Jones
2016-09-05 10:36   ` Thierry Reding
2016-08-16  9:35 ` [PATCH v4 10/17] pwm: sti: Supply PWM Capture register addresses and bit locations Lee Jones
2016-09-05 10:41   ` Thierry Reding
2016-08-16  9:35 ` [PATCH v4 11/17] pwm: sti: Supply PWM Capture clock handling Lee Jones
2016-09-05 10:42   ` Thierry Reding
2016-08-16  9:35 ` [PATCH v4 12/17] pwm: sti: Initialise PWM Capture device data Lee Jones
2016-09-05 10:50   ` Thierry Reding
2016-08-16  9:35 ` [PATCH v4 13/17] pwm: sti: Add support for PWM Capture IRQs Lee Jones
2016-09-05 10:53   ` Thierry Reding
2016-08-16  9:35 ` [PATCH v4 14/17] pwm: sti: Add PWM Capture call-back Lee Jones
2016-09-05 11:10   ` Thierry Reding
2016-08-16  9:35 ` [PATCH v4 15/17] pwm: sti: It's now valid for number of PWM channels to be zero Lee Jones
2016-09-05 11:20   ` Thierry Reding
2016-08-16  9:35 ` [PATCH v4 16/17] pwm: sti: Take the opportunity to conduct a little house keeping Lee Jones
2016-09-05 11:37   ` Thierry Reding
2016-08-16  9:35 ` [PATCH v4 17/17] dt-bindings: pwm: sti: Update DT bindings with recent changes Lee Jones
2016-08-18 19:20   ` Rob Herring
2016-08-19  8:35     ` Lee Jones
2016-08-19 12:45       ` Rob Herring
2016-09-05 10:29   ` Thierry Reding
2016-08-25 11:51 ` [STLinux Kernel] [PATCH v4 00/17] pwm: Add support for PWM Capture Peter Griffin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).