All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] drivers: pwm: add pwm support for sama5d2
@ 2017-02-23  8:38 ` Claudiu Beznea
  0 siblings, 0 replies; 29+ messages in thread
From: Claudiu Beznea @ 2017-02-23  8:38 UTC (permalink / raw)
  To: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, alexandre.belloni
  Cc: linux-pwm, devicetree, linux-kernel, linux-arm-kernel, Claudiu Beznea

Extend atmel-pwm driver in order to support sama5d2 pwm
specifics. Since the new SoC supports changing of pwm
parameters (period and duty factor) without need to first
disable/enable the pwm channel this series adapt the
existing code in order to let changing of these parameters
for sama5d2.

Claudiu Beznea (2):
  drivers: pwm: pwm-atmel: add support for pwm on sama5d2
  drivers: pwm: pwm-atmel: add support to allow run time changing of
    pwm parameters

 .../devicetree/bindings/pwm/atmel-pwm.txt          |  1 +
 drivers/pwm/pwm-atmel.c                            | 40 ++++++++++++++++++----
 2 files changed, 35 insertions(+), 6 deletions(-)

-- 
2.7.4

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

* [PATCH 0/2] drivers: pwm: add pwm support for sama5d2
@ 2017-02-23  8:38 ` Claudiu Beznea
  0 siblings, 0 replies; 29+ messages in thread
From: Claudiu Beznea @ 2017-02-23  8:38 UTC (permalink / raw)
  To: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, alexandre.belloni
  Cc: linux-pwm, Claudiu Beznea, linux-kernel, linux-arm-kernel, devicetree

Extend atmel-pwm driver in order to support sama5d2 pwm
specifics. Since the new SoC supports changing of pwm
parameters (period and duty factor) without need to first
disable/enable the pwm channel this series adapt the
existing code in order to let changing of these parameters
for sama5d2.

Claudiu Beznea (2):
  drivers: pwm: pwm-atmel: add support for pwm on sama5d2
  drivers: pwm: pwm-atmel: add support to allow run time changing of
    pwm parameters

 .../devicetree/bindings/pwm/atmel-pwm.txt          |  1 +
 drivers/pwm/pwm-atmel.c                            | 40 ++++++++++++++++++----
 2 files changed, 35 insertions(+), 6 deletions(-)

-- 
2.7.4

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

* [PATCH 0/2] drivers: pwm: add pwm support for sama5d2
@ 2017-02-23  8:38 ` Claudiu Beznea
  0 siblings, 0 replies; 29+ messages in thread
From: Claudiu Beznea @ 2017-02-23  8:38 UTC (permalink / raw)
  To: linux-arm-kernel

Extend atmel-pwm driver in order to support sama5d2 pwm
specifics. Since the new SoC supports changing of pwm
parameters (period and duty factor) without need to first
disable/enable the pwm channel this series adapt the
existing code in order to let changing of these parameters
for sama5d2.

Claudiu Beznea (2):
  drivers: pwm: pwm-atmel: add support for pwm on sama5d2
  drivers: pwm: pwm-atmel: add support to allow run time changing of
    pwm parameters

 .../devicetree/bindings/pwm/atmel-pwm.txt          |  1 +
 drivers/pwm/pwm-atmel.c                            | 40 ++++++++++++++++++----
 2 files changed, 35 insertions(+), 6 deletions(-)

-- 
2.7.4

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

* [PATCH 1/2] drivers: pwm: pwm-atmel: add support for pwm on sama5d2
  2017-02-23  8:38 ` Claudiu Beznea
  (?)
@ 2017-02-23  8:38   ` Claudiu Beznea
  -1 siblings, 0 replies; 29+ messages in thread
From: Claudiu Beznea @ 2017-02-23  8:38 UTC (permalink / raw)
  To: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, alexandre.belloni
  Cc: linux-pwm, devicetree, linux-kernel, linux-arm-kernel, Claudiu Beznea

Enable PWM on sama5d2 by adding atmel_pwm_config_v3().
This, simply, sets the period and duty factor registers.

Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 Documentation/devicetree/bindings/pwm/atmel-pwm.txt |  1 +
 drivers/pwm/pwm-atmel.c                             | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
index 02331b9..c8c831d 100644
--- a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
+++ b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
@@ -4,6 +4,7 @@ Required properties:
   - compatible: should be one of:
     - "atmel,at91sam9rl-pwm"
     - "atmel,sama5d3-pwm"
+    - "atmel,sama5d2-pwm"
   - reg: physical base address and length of the controller's registers
   - #pwm-cells: Should be 3. See pwm.txt in this directory for a
     description of the cells format.
diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 0e4bd4e..4406639 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -207,6 +207,15 @@ static void atmel_pwm_config_v2(struct pwm_chip *chip, struct pwm_device *pwm,
 	}
 }
 
+static void atmel_pwm_config_v3(struct pwm_chip *chip, struct pwm_device *pwm,
+				unsigned long dty, unsigned long prd)
+{
+	struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
+
+	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CDTY, dty);
+	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CPRD, prd);
+}
+
 static int atmel_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
 				  enum pwm_polarity polarity)
 {
@@ -295,6 +304,10 @@ static const struct atmel_pwm_data atmel_pwm_data_v2 = {
 	.config = atmel_pwm_config_v2,
 };
 
+static const struct atmel_pwm_data atmel_pwm_data_v3 = {
+	.config = atmel_pwm_config_v3,
+};
+
 static const struct platform_device_id atmel_pwm_devtypes[] = {
 	{
 		.name = "at91sam9rl-pwm",
@@ -316,6 +329,9 @@ static const struct of_device_id atmel_pwm_dt_ids[] = {
 		.compatible = "atmel,sama5d3-pwm",
 		.data = &atmel_pwm_data_v2,
 	}, {
+		.compatible = "atmel,sama5d2-pwm",
+		.data = &atmel_pwm_data_v3,
+	}, {
 		/* sentinel */
 	},
 };
-- 
2.7.4

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

* [PATCH 1/2] drivers: pwm: pwm-atmel: add support for pwm on sama5d2
@ 2017-02-23  8:38   ` Claudiu Beznea
  0 siblings, 0 replies; 29+ messages in thread
From: Claudiu Beznea @ 2017-02-23  8:38 UTC (permalink / raw)
  To: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, alexandre.belloni
  Cc: linux-pwm, Claudiu Beznea, linux-kernel, linux-arm-kernel, devicetree

Enable PWM on sama5d2 by adding atmel_pwm_config_v3().
This, simply, sets the period and duty factor registers.

Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 Documentation/devicetree/bindings/pwm/atmel-pwm.txt |  1 +
 drivers/pwm/pwm-atmel.c                             | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
index 02331b9..c8c831d 100644
--- a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
+++ b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
@@ -4,6 +4,7 @@ Required properties:
   - compatible: should be one of:
     - "atmel,at91sam9rl-pwm"
     - "atmel,sama5d3-pwm"
+    - "atmel,sama5d2-pwm"
   - reg: physical base address and length of the controller's registers
   - #pwm-cells: Should be 3. See pwm.txt in this directory for a
     description of the cells format.
diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 0e4bd4e..4406639 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -207,6 +207,15 @@ static void atmel_pwm_config_v2(struct pwm_chip *chip, struct pwm_device *pwm,
 	}
 }
 
+static void atmel_pwm_config_v3(struct pwm_chip *chip, struct pwm_device *pwm,
+				unsigned long dty, unsigned long prd)
+{
+	struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
+
+	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CDTY, dty);
+	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CPRD, prd);
+}
+
 static int atmel_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
 				  enum pwm_polarity polarity)
 {
@@ -295,6 +304,10 @@ static const struct atmel_pwm_data atmel_pwm_data_v2 = {
 	.config = atmel_pwm_config_v2,
 };
 
+static const struct atmel_pwm_data atmel_pwm_data_v3 = {
+	.config = atmel_pwm_config_v3,
+};
+
 static const struct platform_device_id atmel_pwm_devtypes[] = {
 	{
 		.name = "at91sam9rl-pwm",
@@ -316,6 +329,9 @@ static const struct of_device_id atmel_pwm_dt_ids[] = {
 		.compatible = "atmel,sama5d3-pwm",
 		.data = &atmel_pwm_data_v2,
 	}, {
+		.compatible = "atmel,sama5d2-pwm",
+		.data = &atmel_pwm_data_v3,
+	}, {
 		/* sentinel */
 	},
 };
-- 
2.7.4

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

* [PATCH 1/2] drivers: pwm: pwm-atmel: add support for pwm on sama5d2
@ 2017-02-23  8:38   ` Claudiu Beznea
  0 siblings, 0 replies; 29+ messages in thread
From: Claudiu Beznea @ 2017-02-23  8:38 UTC (permalink / raw)
  To: linux-arm-kernel

Enable PWM on sama5d2 by adding atmel_pwm_config_v3().
This, simply, sets the period and duty factor registers.

Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 Documentation/devicetree/bindings/pwm/atmel-pwm.txt |  1 +
 drivers/pwm/pwm-atmel.c                             | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
index 02331b9..c8c831d 100644
--- a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
+++ b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
@@ -4,6 +4,7 @@ Required properties:
   - compatible: should be one of:
     - "atmel,at91sam9rl-pwm"
     - "atmel,sama5d3-pwm"
+    - "atmel,sama5d2-pwm"
   - reg: physical base address and length of the controller's registers
   - #pwm-cells: Should be 3. See pwm.txt in this directory for a
     description of the cells format.
diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 0e4bd4e..4406639 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -207,6 +207,15 @@ static void atmel_pwm_config_v2(struct pwm_chip *chip, struct pwm_device *pwm,
 	}
 }
 
+static void atmel_pwm_config_v3(struct pwm_chip *chip, struct pwm_device *pwm,
+				unsigned long dty, unsigned long prd)
+{
+	struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
+
+	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CDTY, dty);
+	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CPRD, prd);
+}
+
 static int atmel_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
 				  enum pwm_polarity polarity)
 {
@@ -295,6 +304,10 @@ static const struct atmel_pwm_data atmel_pwm_data_v2 = {
 	.config = atmel_pwm_config_v2,
 };
 
+static const struct atmel_pwm_data atmel_pwm_data_v3 = {
+	.config = atmel_pwm_config_v3,
+};
+
 static const struct platform_device_id atmel_pwm_devtypes[] = {
 	{
 		.name = "at91sam9rl-pwm",
@@ -316,6 +329,9 @@ static const struct of_device_id atmel_pwm_dt_ids[] = {
 		.compatible = "atmel,sama5d3-pwm",
 		.data = &atmel_pwm_data_v2,
 	}, {
+		.compatible = "atmel,sama5d2-pwm",
+		.data = &atmel_pwm_data_v3,
+	}, {
 		/* sentinel */
 	},
 };
-- 
2.7.4

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

* [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
  2017-02-23  8:38 ` Claudiu Beznea
  (?)
@ 2017-02-23  8:38   ` Claudiu Beznea
  -1 siblings, 0 replies; 29+ messages in thread
From: Claudiu Beznea @ 2017-02-23  8:38 UTC (permalink / raw)
  To: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, alexandre.belloni
  Cc: linux-pwm, devicetree, linux-kernel, linux-arm-kernel, Claudiu Beznea

sama5d2 supports changing of pwm parameters like period and
duty factor without first to disable pwm. Since pwm code
is supported by more than one SoC add allow_runtime_cfg
parameter to atmel_pwm_chip data structure. This will be
filled statically for every SoC, saved in pwm specific
structure at probing time and checked while configuring
the device. Based on this, pwm clock will not be
enabled/disabled while configuring if it still enabled.

Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 4406639..9e1dece 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -68,6 +68,8 @@ struct atmel_pwm_chip {
 
 	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
 		       unsigned long dty, unsigned long prd);
+
+	bool allow_runtime_cfg;
 };
 
 static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
@@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	u32 val;
 	int ret;
 
-	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
+	if (!atmel_pwm->allow_runtime_cfg &&
+	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
 		dev_err(chip->dev, "cannot change PWM period while enabled\n");
 		return -EBUSY;
 	}
@@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	do_div(div, period_ns);
 	dty = prd - div;
 
-	ret = clk_enable(atmel_pwm->clk);
-	if (ret) {
-		dev_err(chip->dev, "failed to enable PWM clock\n");
-		return ret;
+	if (!pwm_is_enabled(pwm)) {
+		ret = clk_enable(atmel_pwm->clk);
+		if (ret) {
+			dev_err(chip->dev, "failed to enable PWM clock\n");
+			return ret;
+		}
 	}
 
 	/* It is necessary to preserve CPOL, inside CMR */
@@ -155,7 +160,9 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm);
 	mutex_unlock(&atmel_pwm->isr_lock);
 
-	clk_disable(atmel_pwm->clk);
+	if (!pwm_is_enabled(pwm))
+		clk_disable(atmel_pwm->clk);
+
 	return ret;
 }
 
@@ -294,18 +301,22 @@ static const struct pwm_ops atmel_pwm_ops = {
 struct atmel_pwm_data {
 	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
 		       unsigned long dty, unsigned long prd);
+	bool allow_runtime_cfg;
 };
 
 static const struct atmel_pwm_data atmel_pwm_data_v1 = {
 	.config = atmel_pwm_config_v1,
+	.allow_runtime_cfg = false,
 };
 
 static const struct atmel_pwm_data atmel_pwm_data_v2 = {
 	.config = atmel_pwm_config_v2,
+	.allow_runtime_cfg = false,
 };
 
 static const struct atmel_pwm_data atmel_pwm_data_v3 = {
 	.config = atmel_pwm_config_v3,
+	.allow_runtime_cfg = true,
 };
 
 static const struct platform_device_id atmel_pwm_devtypes[] = {
@@ -399,6 +410,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
 	atmel_pwm->chip.npwm = 4;
 	atmel_pwm->chip.can_sleep = true;
 	atmel_pwm->config = data->config;
+	atmel_pwm->allow_runtime_cfg = data->allow_runtime_cfg;
 	atmel_pwm->updated_pwms = 0;
 	mutex_init(&atmel_pwm->isr_lock);
 
-- 
2.7.4

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

* [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
@ 2017-02-23  8:38   ` Claudiu Beznea
  0 siblings, 0 replies; 29+ messages in thread
From: Claudiu Beznea @ 2017-02-23  8:38 UTC (permalink / raw)
  To: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, alexandre.belloni
  Cc: linux-pwm, devicetree, linux-kernel, linux-arm-kernel, Claudiu Beznea

sama5d2 supports changing of pwm parameters like period and
duty factor without first to disable pwm. Since pwm code
is supported by more than one SoC add allow_runtime_cfg
parameter to atmel_pwm_chip data structure. This will be
filled statically for every SoC, saved in pwm specific
structure at probing time and checked while configuring
the device. Based on this, pwm clock will not be
enabled/disabled while configuring if it still enabled.

Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 4406639..9e1dece 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -68,6 +68,8 @@ struct atmel_pwm_chip {
 
 	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
 		       unsigned long dty, unsigned long prd);
+
+	bool allow_runtime_cfg;
 };
 
 static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
@@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	u32 val;
 	int ret;
 
-	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
+	if (!atmel_pwm->allow_runtime_cfg &&
+	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
 		dev_err(chip->dev, "cannot change PWM period while enabled\n");
 		return -EBUSY;
 	}
@@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	do_div(div, period_ns);
 	dty = prd - div;
 
-	ret = clk_enable(atmel_pwm->clk);
-	if (ret) {
-		dev_err(chip->dev, "failed to enable PWM clock\n");
-		return ret;
+	if (!pwm_is_enabled(pwm)) {
+		ret = clk_enable(atmel_pwm->clk);
+		if (ret) {
+			dev_err(chip->dev, "failed to enable PWM clock\n");
+			return ret;
+		}
 	}
 
 	/* It is necessary to preserve CPOL, inside CMR */
@@ -155,7 +160,9 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm);
 	mutex_unlock(&atmel_pwm->isr_lock);
 
-	clk_disable(atmel_pwm->clk);
+	if (!pwm_is_enabled(pwm))
+		clk_disable(atmel_pwm->clk);
+
 	return ret;
 }
 
@@ -294,18 +301,22 @@ static const struct pwm_ops atmel_pwm_ops = {
 struct atmel_pwm_data {
 	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
 		       unsigned long dty, unsigned long prd);
+	bool allow_runtime_cfg;
 };
 
 static const struct atmel_pwm_data atmel_pwm_data_v1 = {
 	.config = atmel_pwm_config_v1,
+	.allow_runtime_cfg = false,
 };
 
 static const struct atmel_pwm_data atmel_pwm_data_v2 = {
 	.config = atmel_pwm_config_v2,
+	.allow_runtime_cfg = false,
 };
 
 static const struct atmel_pwm_data atmel_pwm_data_v3 = {
 	.config = atmel_pwm_config_v3,
+	.allow_runtime_cfg = true,
 };
 
 static const struct platform_device_id atmel_pwm_devtypes[] = {
@@ -399,6 +410,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
 	atmel_pwm->chip.npwm = 4;
 	atmel_pwm->chip.can_sleep = true;
 	atmel_pwm->config = data->config;
+	atmel_pwm->allow_runtime_cfg = data->allow_runtime_cfg;
 	atmel_pwm->updated_pwms = 0;
 	mutex_init(&atmel_pwm->isr_lock);
 
-- 
2.7.4

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

* [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
@ 2017-02-23  8:38   ` Claudiu Beznea
  0 siblings, 0 replies; 29+ messages in thread
From: Claudiu Beznea @ 2017-02-23  8:38 UTC (permalink / raw)
  To: linux-arm-kernel

sama5d2 supports changing of pwm parameters like period and
duty factor without first to disable pwm. Since pwm code
is supported by more than one SoC add allow_runtime_cfg
parameter to atmel_pwm_chip data structure. This will be
filled statically for every SoC, saved in pwm specific
structure at probing time and checked while configuring
the device. Based on this, pwm clock will not be
enabled/disabled while configuring if it still enabled.

Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 4406639..9e1dece 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -68,6 +68,8 @@ struct atmel_pwm_chip {
 
 	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
 		       unsigned long dty, unsigned long prd);
+
+	bool allow_runtime_cfg;
 };
 
 static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
@@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	u32 val;
 	int ret;
 
-	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
+	if (!atmel_pwm->allow_runtime_cfg &&
+	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
 		dev_err(chip->dev, "cannot change PWM period while enabled\n");
 		return -EBUSY;
 	}
@@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	do_div(div, period_ns);
 	dty = prd - div;
 
-	ret = clk_enable(atmel_pwm->clk);
-	if (ret) {
-		dev_err(chip->dev, "failed to enable PWM clock\n");
-		return ret;
+	if (!pwm_is_enabled(pwm)) {
+		ret = clk_enable(atmel_pwm->clk);
+		if (ret) {
+			dev_err(chip->dev, "failed to enable PWM clock\n");
+			return ret;
+		}
 	}
 
 	/* It is necessary to preserve CPOL, inside CMR */
@@ -155,7 +160,9 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm);
 	mutex_unlock(&atmel_pwm->isr_lock);
 
-	clk_disable(atmel_pwm->clk);
+	if (!pwm_is_enabled(pwm))
+		clk_disable(atmel_pwm->clk);
+
 	return ret;
 }
 
@@ -294,18 +301,22 @@ static const struct pwm_ops atmel_pwm_ops = {
 struct atmel_pwm_data {
 	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
 		       unsigned long dty, unsigned long prd);
+	bool allow_runtime_cfg;
 };
 
 static const struct atmel_pwm_data atmel_pwm_data_v1 = {
 	.config = atmel_pwm_config_v1,
+	.allow_runtime_cfg = false,
 };
 
 static const struct atmel_pwm_data atmel_pwm_data_v2 = {
 	.config = atmel_pwm_config_v2,
+	.allow_runtime_cfg = false,
 };
 
 static const struct atmel_pwm_data atmel_pwm_data_v3 = {
 	.config = atmel_pwm_config_v3,
+	.allow_runtime_cfg = true,
 };
 
 static const struct platform_device_id atmel_pwm_devtypes[] = {
@@ -399,6 +410,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
 	atmel_pwm->chip.npwm = 4;
 	atmel_pwm->chip.can_sleep = true;
 	atmel_pwm->config = data->config;
+	atmel_pwm->allow_runtime_cfg = data->allow_runtime_cfg;
 	atmel_pwm->updated_pwms = 0;
 	mutex_init(&atmel_pwm->isr_lock);
 
-- 
2.7.4

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

* Re: [PATCH 1/2] drivers: pwm: pwm-atmel: add support for pwm on sama5d2
  2017-02-23  8:38   ` Claudiu Beznea
  (?)
@ 2017-02-23  9:16     ` Alexandre Belloni
  -1 siblings, 0 replies; 29+ messages in thread
From: Alexandre Belloni @ 2017-02-23  9:16 UTC (permalink / raw)
  To: Claudiu Beznea
  Cc: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, linux-pwm, devicetree,
	linux-kernel, linux-arm-kernel

On 23/02/2017 at 10:38:39 +0200, Claudiu Beznea wrote:
> Enable PWM on sama5d2 by adding atmel_pwm_config_v3().
> This, simply, sets the period and duty factor registers.
> 
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

> ---
>  Documentation/devicetree/bindings/pwm/atmel-pwm.txt |  1 +
>  drivers/pwm/pwm-atmel.c                             | 16 ++++++++++++++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
> index 02331b9..c8c831d 100644
> --- a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
> +++ b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
> @@ -4,6 +4,7 @@ Required properties:
>    - compatible: should be one of:
>      - "atmel,at91sam9rl-pwm"
>      - "atmel,sama5d3-pwm"
> +    - "atmel,sama5d2-pwm"
>    - reg: physical base address and length of the controller's registers
>    - #pwm-cells: Should be 3. See pwm.txt in this directory for a
>      description of the cells format.
> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> index 0e4bd4e..4406639 100644
> --- a/drivers/pwm/pwm-atmel.c
> +++ b/drivers/pwm/pwm-atmel.c
> @@ -207,6 +207,15 @@ static void atmel_pwm_config_v2(struct pwm_chip *chip, struct pwm_device *pwm,
>  	}
>  }
>  
> +static void atmel_pwm_config_v3(struct pwm_chip *chip, struct pwm_device *pwm,
> +				unsigned long dty, unsigned long prd)
> +{
> +	struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
> +
> +	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CDTY, dty);
> +	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CPRD, prd);
> +}
> +
>  static int atmel_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
>  				  enum pwm_polarity polarity)
>  {
> @@ -295,6 +304,10 @@ static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>  	.config = atmel_pwm_config_v2,
>  };
>  
> +static const struct atmel_pwm_data atmel_pwm_data_v3 = {
> +	.config = atmel_pwm_config_v3,
> +};
> +
>  static const struct platform_device_id atmel_pwm_devtypes[] = {
>  	{
>  		.name = "at91sam9rl-pwm",
> @@ -316,6 +329,9 @@ static const struct of_device_id atmel_pwm_dt_ids[] = {
>  		.compatible = "atmel,sama5d3-pwm",
>  		.data = &atmel_pwm_data_v2,
>  	}, {
> +		.compatible = "atmel,sama5d2-pwm",
> +		.data = &atmel_pwm_data_v3,
> +	}, {
>  		/* sentinel */
>  	},
>  };
> -- 
> 2.7.4
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* Re: [PATCH 1/2] drivers: pwm: pwm-atmel: add support for pwm on sama5d2
@ 2017-02-23  9:16     ` Alexandre Belloni
  0 siblings, 0 replies; 29+ messages in thread
From: Alexandre Belloni @ 2017-02-23  9:16 UTC (permalink / raw)
  To: Claudiu Beznea
  Cc: mark.rutland, boris.brezillon, pawel.moll, ijc+devicetree,
	linux-kernel, robh+dt, devicetree, thierry.reding, linux-pwm,
	galak, linux-arm-kernel

On 23/02/2017 at 10:38:39 +0200, Claudiu Beznea wrote:
> Enable PWM on sama5d2 by adding atmel_pwm_config_v3().
> This, simply, sets the period and duty factor registers.
> 
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

> ---
>  Documentation/devicetree/bindings/pwm/atmel-pwm.txt |  1 +
>  drivers/pwm/pwm-atmel.c                             | 16 ++++++++++++++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
> index 02331b9..c8c831d 100644
> --- a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
> +++ b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
> @@ -4,6 +4,7 @@ Required properties:
>    - compatible: should be one of:
>      - "atmel,at91sam9rl-pwm"
>      - "atmel,sama5d3-pwm"
> +    - "atmel,sama5d2-pwm"
>    - reg: physical base address and length of the controller's registers
>    - #pwm-cells: Should be 3. See pwm.txt in this directory for a
>      description of the cells format.
> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> index 0e4bd4e..4406639 100644
> --- a/drivers/pwm/pwm-atmel.c
> +++ b/drivers/pwm/pwm-atmel.c
> @@ -207,6 +207,15 @@ static void atmel_pwm_config_v2(struct pwm_chip *chip, struct pwm_device *pwm,
>  	}
>  }
>  
> +static void atmel_pwm_config_v3(struct pwm_chip *chip, struct pwm_device *pwm,
> +				unsigned long dty, unsigned long prd)
> +{
> +	struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
> +
> +	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CDTY, dty);
> +	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CPRD, prd);
> +}
> +
>  static int atmel_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
>  				  enum pwm_polarity polarity)
>  {
> @@ -295,6 +304,10 @@ static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>  	.config = atmel_pwm_config_v2,
>  };
>  
> +static const struct atmel_pwm_data atmel_pwm_data_v3 = {
> +	.config = atmel_pwm_config_v3,
> +};
> +
>  static const struct platform_device_id atmel_pwm_devtypes[] = {
>  	{
>  		.name = "at91sam9rl-pwm",
> @@ -316,6 +329,9 @@ static const struct of_device_id atmel_pwm_dt_ids[] = {
>  		.compatible = "atmel,sama5d3-pwm",
>  		.data = &atmel_pwm_data_v2,
>  	}, {
> +		.compatible = "atmel,sama5d2-pwm",
> +		.data = &atmel_pwm_data_v3,
> +	}, {
>  		/* sentinel */
>  	},
>  };
> -- 
> 2.7.4
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* [PATCH 1/2] drivers: pwm: pwm-atmel: add support for pwm on sama5d2
@ 2017-02-23  9:16     ` Alexandre Belloni
  0 siblings, 0 replies; 29+ messages in thread
From: Alexandre Belloni @ 2017-02-23  9:16 UTC (permalink / raw)
  To: linux-arm-kernel

On 23/02/2017 at 10:38:39 +0200, Claudiu Beznea wrote:
> Enable PWM on sama5d2 by adding atmel_pwm_config_v3().
> This, simply, sets the period and duty factor registers.
> 
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

> ---
>  Documentation/devicetree/bindings/pwm/atmel-pwm.txt |  1 +
>  drivers/pwm/pwm-atmel.c                             | 16 ++++++++++++++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
> index 02331b9..c8c831d 100644
> --- a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
> +++ b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
> @@ -4,6 +4,7 @@ Required properties:
>    - compatible: should be one of:
>      - "atmel,at91sam9rl-pwm"
>      - "atmel,sama5d3-pwm"
> +    - "atmel,sama5d2-pwm"
>    - reg: physical base address and length of the controller's registers
>    - #pwm-cells: Should be 3. See pwm.txt in this directory for a
>      description of the cells format.
> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> index 0e4bd4e..4406639 100644
> --- a/drivers/pwm/pwm-atmel.c
> +++ b/drivers/pwm/pwm-atmel.c
> @@ -207,6 +207,15 @@ static void atmel_pwm_config_v2(struct pwm_chip *chip, struct pwm_device *pwm,
>  	}
>  }
>  
> +static void atmel_pwm_config_v3(struct pwm_chip *chip, struct pwm_device *pwm,
> +				unsigned long dty, unsigned long prd)
> +{
> +	struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
> +
> +	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CDTY, dty);
> +	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CPRD, prd);
> +}
> +
>  static int atmel_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
>  				  enum pwm_polarity polarity)
>  {
> @@ -295,6 +304,10 @@ static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>  	.config = atmel_pwm_config_v2,
>  };
>  
> +static const struct atmel_pwm_data atmel_pwm_data_v3 = {
> +	.config = atmel_pwm_config_v3,
> +};
> +
>  static const struct platform_device_id atmel_pwm_devtypes[] = {
>  	{
>  		.name = "at91sam9rl-pwm",
> @@ -316,6 +329,9 @@ static const struct of_device_id atmel_pwm_dt_ids[] = {
>  		.compatible = "atmel,sama5d3-pwm",
>  		.data = &atmel_pwm_data_v2,
>  	}, {
> +		.compatible = "atmel,sama5d2-pwm",
> +		.data = &atmel_pwm_data_v3,
> +	}, {
>  		/* sentinel */
>  	},
>  };
> -- 
> 2.7.4
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
@ 2017-02-23  9:21     ` Alexandre Belloni
  0 siblings, 0 replies; 29+ messages in thread
From: Alexandre Belloni @ 2017-02-23  9:21 UTC (permalink / raw)
  To: Claudiu Beznea
  Cc: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, linux-pwm, devicetree,
	linux-kernel, linux-arm-kernel

On 23/02/2017 at 10:38:40 +0200, Claudiu Beznea wrote:
> sama5d2 supports changing of pwm parameters like period and
> duty factor without first to disable pwm. Since pwm code
> is supported by more than one SoC add allow_runtime_cfg
> parameter to atmel_pwm_chip data structure. This will be
> filled statically for every SoC, saved in pwm specific
> structure at probing time and checked while configuring
> the device. Based on this, pwm clock will not be
> enabled/disabled while configuring if it still enabled.
> 
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
>  drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
>  1 file changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> index 4406639..9e1dece 100644
> --- a/drivers/pwm/pwm-atmel.c
> +++ b/drivers/pwm/pwm-atmel.c
> @@ -68,6 +68,8 @@ struct atmel_pwm_chip {
>  
>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>  		       unsigned long dty, unsigned long prd);
> +
> +	bool allow_runtime_cfg;
>  };
>  
>  static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
> @@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  	u32 val;
>  	int ret;
>  
> -	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
> +	if (!atmel_pwm->allow_runtime_cfg &&
> +	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
>  		dev_err(chip->dev, "cannot change PWM period while enabled\n");
>  		return -EBUSY;
>  	}
> @@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  	do_div(div, period_ns);
>  	dty = prd - div;
>  
> -	ret = clk_enable(atmel_pwm->clk);
> -	if (ret) {
> -		dev_err(chip->dev, "failed to enable PWM clock\n");
> -		return ret;
> +	if (!pwm_is_enabled(pwm)) {
> +		ret = clk_enable(atmel_pwm->clk);
> +		if (ret) {
> +			dev_err(chip->dev, "failed to enable PWM clock\n");
> +			return ret;
> +		}
>  	}
>  

It is probably worth switching to atomic PWM instead of changing this
function. This would simplify the whole driver.

>  	/* It is necessary to preserve CPOL, inside CMR */
> @@ -155,7 +160,9 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  	atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm);
>  	mutex_unlock(&atmel_pwm->isr_lock);
>  
> -	clk_disable(atmel_pwm->clk);
> +	if (!pwm_is_enabled(pwm))
> +		clk_disable(atmel_pwm->clk);
> +
>  	return ret;
>  }
>  
> @@ -294,18 +301,22 @@ static const struct pwm_ops atmel_pwm_ops = {
>  struct atmel_pwm_data {
>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>  		       unsigned long dty, unsigned long prd);
> +	bool allow_runtime_cfg;
>  };
>  
>  static const struct atmel_pwm_data atmel_pwm_data_v1 = {
>  	.config = atmel_pwm_config_v1,
> +	.allow_runtime_cfg = false,

This is useless as it is false even if not explicitly set.

>  };
>  
>  static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>  	.config = atmel_pwm_config_v2,
> +	.allow_runtime_cfg = false,

ditto.

>  };
>  
>  static const struct atmel_pwm_data atmel_pwm_data_v3 = {
>  	.config = atmel_pwm_config_v3,
> +	.allow_runtime_cfg = true,
>  };
>  
>  static const struct platform_device_id atmel_pwm_devtypes[] = {
> @@ -399,6 +410,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
>  	atmel_pwm->chip.npwm = 4;
>  	atmel_pwm->chip.can_sleep = true;
>  	atmel_pwm->config = data->config;
> +	atmel_pwm->allow_runtime_cfg = data->allow_runtime_cfg;

It is probably worth having a pointer to the atmel_pwm_data instead of
having to copy all the members.

>  	atmel_pwm->updated_pwms = 0;
>  	mutex_init(&atmel_pwm->isr_lock);
>  
> -- 
> 2.7.4
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
@ 2017-02-23  9:21     ` Alexandre Belloni
  0 siblings, 0 replies; 29+ messages in thread
From: Alexandre Belloni @ 2017-02-23  9:21 UTC (permalink / raw)
  To: Claudiu Beznea
  Cc: thierry.reding-Re5JQEeQqe8AvxtiuMwx3w,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	galak-sgV2jX0FEOL9JmXXK+q4OQ,
	boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	linux-pwm-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On 23/02/2017 at 10:38:40 +0200, Claudiu Beznea wrote:
> sama5d2 supports changing of pwm parameters like period and
> duty factor without first to disable pwm. Since pwm code
> is supported by more than one SoC add allow_runtime_cfg
> parameter to atmel_pwm_chip data structure. This will be
> filled statically for every SoC, saved in pwm specific
> structure at probing time and checked while configuring
> the device. Based on this, pwm clock will not be
> enabled/disabled while configuring if it still enabled.
> 
> Signed-off-by: Claudiu Beznea <claudiu.beznea-UWL1GkI3JZL3oGB3hsPCZA@public.gmane.org>
> ---
>  drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
>  1 file changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> index 4406639..9e1dece 100644
> --- a/drivers/pwm/pwm-atmel.c
> +++ b/drivers/pwm/pwm-atmel.c
> @@ -68,6 +68,8 @@ struct atmel_pwm_chip {
>  
>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>  		       unsigned long dty, unsigned long prd);
> +
> +	bool allow_runtime_cfg;
>  };
>  
>  static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
> @@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  	u32 val;
>  	int ret;
>  
> -	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
> +	if (!atmel_pwm->allow_runtime_cfg &&
> +	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
>  		dev_err(chip->dev, "cannot change PWM period while enabled\n");
>  		return -EBUSY;
>  	}
> @@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  	do_div(div, period_ns);
>  	dty = prd - div;
>  
> -	ret = clk_enable(atmel_pwm->clk);
> -	if (ret) {
> -		dev_err(chip->dev, "failed to enable PWM clock\n");
> -		return ret;
> +	if (!pwm_is_enabled(pwm)) {
> +		ret = clk_enable(atmel_pwm->clk);
> +		if (ret) {
> +			dev_err(chip->dev, "failed to enable PWM clock\n");
> +			return ret;
> +		}
>  	}
>  

It is probably worth switching to atomic PWM instead of changing this
function. This would simplify the whole driver.

>  	/* It is necessary to preserve CPOL, inside CMR */
> @@ -155,7 +160,9 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  	atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm);
>  	mutex_unlock(&atmel_pwm->isr_lock);
>  
> -	clk_disable(atmel_pwm->clk);
> +	if (!pwm_is_enabled(pwm))
> +		clk_disable(atmel_pwm->clk);
> +
>  	return ret;
>  }
>  
> @@ -294,18 +301,22 @@ static const struct pwm_ops atmel_pwm_ops = {
>  struct atmel_pwm_data {
>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>  		       unsigned long dty, unsigned long prd);
> +	bool allow_runtime_cfg;
>  };
>  
>  static const struct atmel_pwm_data atmel_pwm_data_v1 = {
>  	.config = atmel_pwm_config_v1,
> +	.allow_runtime_cfg = false,

This is useless as it is false even if not explicitly set.

>  };
>  
>  static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>  	.config = atmel_pwm_config_v2,
> +	.allow_runtime_cfg = false,

ditto.

>  };
>  
>  static const struct atmel_pwm_data atmel_pwm_data_v3 = {
>  	.config = atmel_pwm_config_v3,
> +	.allow_runtime_cfg = true,
>  };
>  
>  static const struct platform_device_id atmel_pwm_devtypes[] = {
> @@ -399,6 +410,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
>  	atmel_pwm->chip.npwm = 4;
>  	atmel_pwm->chip.can_sleep = true;
>  	atmel_pwm->config = data->config;
> +	atmel_pwm->allow_runtime_cfg = data->allow_runtime_cfg;

It is probably worth having a pointer to the atmel_pwm_data instead of
having to copy all the members.

>  	atmel_pwm->updated_pwms = 0;
>  	mutex_init(&atmel_pwm->isr_lock);
>  
> -- 
> 2.7.4
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
@ 2017-02-23  9:21     ` Alexandre Belloni
  0 siblings, 0 replies; 29+ messages in thread
From: Alexandre Belloni @ 2017-02-23  9:21 UTC (permalink / raw)
  To: linux-arm-kernel

On 23/02/2017 at 10:38:40 +0200, Claudiu Beznea wrote:
> sama5d2 supports changing of pwm parameters like period and
> duty factor without first to disable pwm. Since pwm code
> is supported by more than one SoC add allow_runtime_cfg
> parameter to atmel_pwm_chip data structure. This will be
> filled statically for every SoC, saved in pwm specific
> structure at probing time and checked while configuring
> the device. Based on this, pwm clock will not be
> enabled/disabled while configuring if it still enabled.
> 
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
>  drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
>  1 file changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> index 4406639..9e1dece 100644
> --- a/drivers/pwm/pwm-atmel.c
> +++ b/drivers/pwm/pwm-atmel.c
> @@ -68,6 +68,8 @@ struct atmel_pwm_chip {
>  
>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>  		       unsigned long dty, unsigned long prd);
> +
> +	bool allow_runtime_cfg;
>  };
>  
>  static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
> @@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  	u32 val;
>  	int ret;
>  
> -	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
> +	if (!atmel_pwm->allow_runtime_cfg &&
> +	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
>  		dev_err(chip->dev, "cannot change PWM period while enabled\n");
>  		return -EBUSY;
>  	}
> @@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  	do_div(div, period_ns);
>  	dty = prd - div;
>  
> -	ret = clk_enable(atmel_pwm->clk);
> -	if (ret) {
> -		dev_err(chip->dev, "failed to enable PWM clock\n");
> -		return ret;
> +	if (!pwm_is_enabled(pwm)) {
> +		ret = clk_enable(atmel_pwm->clk);
> +		if (ret) {
> +			dev_err(chip->dev, "failed to enable PWM clock\n");
> +			return ret;
> +		}
>  	}
>  

It is probably worth switching to atomic PWM instead of changing this
function. This would simplify the whole driver.

>  	/* It is necessary to preserve CPOL, inside CMR */
> @@ -155,7 +160,9 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  	atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm);
>  	mutex_unlock(&atmel_pwm->isr_lock);
>  
> -	clk_disable(atmel_pwm->clk);
> +	if (!pwm_is_enabled(pwm))
> +		clk_disable(atmel_pwm->clk);
> +
>  	return ret;
>  }
>  
> @@ -294,18 +301,22 @@ static const struct pwm_ops atmel_pwm_ops = {
>  struct atmel_pwm_data {
>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>  		       unsigned long dty, unsigned long prd);
> +	bool allow_runtime_cfg;
>  };
>  
>  static const struct atmel_pwm_data atmel_pwm_data_v1 = {
>  	.config = atmel_pwm_config_v1,
> +	.allow_runtime_cfg = false,

This is useless as it is false even if not explicitly set.

>  };
>  
>  static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>  	.config = atmel_pwm_config_v2,
> +	.allow_runtime_cfg = false,

ditto.

>  };
>  
>  static const struct atmel_pwm_data atmel_pwm_data_v3 = {
>  	.config = atmel_pwm_config_v3,
> +	.allow_runtime_cfg = true,
>  };
>  
>  static const struct platform_device_id atmel_pwm_devtypes[] = {
> @@ -399,6 +410,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
>  	atmel_pwm->chip.npwm = 4;
>  	atmel_pwm->chip.can_sleep = true;
>  	atmel_pwm->config = data->config;
> +	atmel_pwm->allow_runtime_cfg = data->allow_runtime_cfg;

It is probably worth having a pointer to the atmel_pwm_data instead of
having to copy all the members.

>  	atmel_pwm->updated_pwms = 0;
>  	mutex_init(&atmel_pwm->isr_lock);
>  
> -- 
> 2.7.4
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
  2017-02-23  9:21     ` Alexandre Belloni
  (?)
@ 2017-02-23 10:25       ` m18063
  -1 siblings, 0 replies; 29+ messages in thread
From: m18063 @ 2017-02-23 10:25 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, linux-pwm, devicetree,
	linux-kernel, linux-arm-kernel

Hi,


On 23.02.2017 11:21, Alexandre Belloni wrote:
> On 23/02/2017 at 10:38:40 +0200, Claudiu Beznea wrote:
>> sama5d2 supports changing of pwm parameters like period and
>> duty factor without first to disable pwm. Since pwm code
>> is supported by more than one SoC add allow_runtime_cfg
>> parameter to atmel_pwm_chip data structure. This will be
>> filled statically for every SoC, saved in pwm specific
>> structure at probing time and checked while configuring
>> the device. Based on this, pwm clock will not be
>> enabled/disabled while configuring if it still enabled.
>>
>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>> ---
>>  drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
>>  1 file changed, 18 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
>> index 4406639..9e1dece 100644
>> --- a/drivers/pwm/pwm-atmel.c
>> +++ b/drivers/pwm/pwm-atmel.c
>> @@ -68,6 +68,8 @@ struct atmel_pwm_chip {
>>  
>>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>>  		       unsigned long dty, unsigned long prd);
>> +
>> +	bool allow_runtime_cfg;
>>  };
>>  
>>  static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
>> @@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	u32 val;
>>  	int ret;
>>  
>> -	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
>> +	if (!atmel_pwm->allow_runtime_cfg &&
>> +	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
>>  		dev_err(chip->dev, "cannot change PWM period while enabled\n");
>>  		return -EBUSY;
>>  	}
>> @@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	do_div(div, period_ns);
>>  	dty = prd - div;
>>  
>> -	ret = clk_enable(atmel_pwm->clk);
>> -	if (ret) {
>> -		dev_err(chip->dev, "failed to enable PWM clock\n");
>> -		return ret;
>> +	if (!pwm_is_enabled(pwm)) {
>> +		ret = clk_enable(atmel_pwm->clk);
>> +		if (ret) {
>> +			dev_err(chip->dev, "failed to enable PWM clock\n");
>> +			return ret;
>> +		}
>>  	}
>>  
> It is probably worth switching to atomic PWM instead of changing this
> function. This would simplify the whole driver.
I was thinking to switch to atomic PWM in a future patch.
>
>>  	/* It is necessary to preserve CPOL, inside CMR */
>> @@ -155,7 +160,9 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm);
>>  	mutex_unlock(&atmel_pwm->isr_lock);
>>  
>> -	clk_disable(atmel_pwm->clk);
>> +	if (!pwm_is_enabled(pwm))
>> +		clk_disable(atmel_pwm->clk);
>> +
>>  	return ret;
>>  }
>>  
>> @@ -294,18 +301,22 @@ static const struct pwm_ops atmel_pwm_ops = {
>>  struct atmel_pwm_data {
>>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>>  		       unsigned long dty, unsigned long prd);
>> +	bool allow_runtime_cfg;
>>  };
>>  
>>  static const struct atmel_pwm_data atmel_pwm_data_v1 = {
>>  	.config = atmel_pwm_config_v1,
>> +	.allow_runtime_cfg = false,
> This is useless as it is false even if not explicitly set.
Ok. I will do it in v2.
>
>>  };
>>  
>>  static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>>  	.config = atmel_pwm_config_v2,
>> +	.allow_runtime_cfg = false,
> ditto.
>
>>  };
>>  
>>  static const struct atmel_pwm_data atmel_pwm_data_v3 = {
>>  	.config = atmel_pwm_config_v3,
>> +	.allow_runtime_cfg = true,
>>  };
>>  
>>  static const struct platform_device_id atmel_pwm_devtypes[] = {
>> @@ -399,6 +410,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
>>  	atmel_pwm->chip.npwm = 4;
>>  	atmel_pwm->chip.can_sleep = true;
>>  	atmel_pwm->config = data->config;
>> +	atmel_pwm->allow_runtime_cfg = data->allow_runtime_cfg;
> It is probably worth having a pointer to the atmel_pwm_data instead of
> having to copy all the members.
Ok. I will do it in v2.
>
>>  	atmel_pwm->updated_pwms = 0;
>>  	mutex_init(&atmel_pwm->isr_lock);
>>  
>> -- 
>> 2.7.4
>>

Thank you,
Claudiu Beznea

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

* Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
@ 2017-02-23 10:25       ` m18063
  0 siblings, 0 replies; 29+ messages in thread
From: m18063 @ 2017-02-23 10:25 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, linux-pwm, devicetree,
	linux-kernel, linux-arm-kernel

Hi,


On 23.02.2017 11:21, Alexandre Belloni wrote:
> On 23/02/2017 at 10:38:40 +0200, Claudiu Beznea wrote:
>> sama5d2 supports changing of pwm parameters like period and
>> duty factor without first to disable pwm. Since pwm code
>> is supported by more than one SoC add allow_runtime_cfg
>> parameter to atmel_pwm_chip data structure. This will be
>> filled statically for every SoC, saved in pwm specific
>> structure at probing time and checked while configuring
>> the device. Based on this, pwm clock will not be
>> enabled/disabled while configuring if it still enabled.
>>
>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>> ---
>>  drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
>>  1 file changed, 18 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
>> index 4406639..9e1dece 100644
>> --- a/drivers/pwm/pwm-atmel.c
>> +++ b/drivers/pwm/pwm-atmel.c
>> @@ -68,6 +68,8 @@ struct atmel_pwm_chip {
>>  
>>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>>  		       unsigned long dty, unsigned long prd);
>> +
>> +	bool allow_runtime_cfg;
>>  };
>>  
>>  static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
>> @@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	u32 val;
>>  	int ret;
>>  
>> -	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
>> +	if (!atmel_pwm->allow_runtime_cfg &&
>> +	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
>>  		dev_err(chip->dev, "cannot change PWM period while enabled\n");
>>  		return -EBUSY;
>>  	}
>> @@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	do_div(div, period_ns);
>>  	dty = prd - div;
>>  
>> -	ret = clk_enable(atmel_pwm->clk);
>> -	if (ret) {
>> -		dev_err(chip->dev, "failed to enable PWM clock\n");
>> -		return ret;
>> +	if (!pwm_is_enabled(pwm)) {
>> +		ret = clk_enable(atmel_pwm->clk);
>> +		if (ret) {
>> +			dev_err(chip->dev, "failed to enable PWM clock\n");
>> +			return ret;
>> +		}
>>  	}
>>  
> It is probably worth switching to atomic PWM instead of changing this
> function. This would simplify the whole driver.
I was thinking to switch to atomic PWM in a future patch.
>
>>  	/* It is necessary to preserve CPOL, inside CMR */
>> @@ -155,7 +160,9 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm);
>>  	mutex_unlock(&atmel_pwm->isr_lock);
>>  
>> -	clk_disable(atmel_pwm->clk);
>> +	if (!pwm_is_enabled(pwm))
>> +		clk_disable(atmel_pwm->clk);
>> +
>>  	return ret;
>>  }
>>  
>> @@ -294,18 +301,22 @@ static const struct pwm_ops atmel_pwm_ops = {
>>  struct atmel_pwm_data {
>>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>>  		       unsigned long dty, unsigned long prd);
>> +	bool allow_runtime_cfg;
>>  };
>>  
>>  static const struct atmel_pwm_data atmel_pwm_data_v1 = {
>>  	.config = atmel_pwm_config_v1,
>> +	.allow_runtime_cfg = false,
> This is useless as it is false even if not explicitly set.
Ok. I will do it in v2.
>
>>  };
>>  
>>  static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>>  	.config = atmel_pwm_config_v2,
>> +	.allow_runtime_cfg = false,
> ditto.
>
>>  };
>>  
>>  static const struct atmel_pwm_data atmel_pwm_data_v3 = {
>>  	.config = atmel_pwm_config_v3,
>> +	.allow_runtime_cfg = true,
>>  };
>>  
>>  static const struct platform_device_id atmel_pwm_devtypes[] = {
>> @@ -399,6 +410,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
>>  	atmel_pwm->chip.npwm = 4;
>>  	atmel_pwm->chip.can_sleep = true;
>>  	atmel_pwm->config = data->config;
>> +	atmel_pwm->allow_runtime_cfg = data->allow_runtime_cfg;
> It is probably worth having a pointer to the atmel_pwm_data instead of
> having to copy all the members.
Ok. I will do it in v2.
>
>>  	atmel_pwm->updated_pwms = 0;
>>  	mutex_init(&atmel_pwm->isr_lock);
>>  
>> -- 
>> 2.7.4
>>

Thank you,
Claudiu Beznea

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

* [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
@ 2017-02-23 10:25       ` m18063
  0 siblings, 0 replies; 29+ messages in thread
From: m18063 @ 2017-02-23 10:25 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,


On 23.02.2017 11:21, Alexandre Belloni wrote:
> On 23/02/2017 at 10:38:40 +0200, Claudiu Beznea wrote:
>> sama5d2 supports changing of pwm parameters like period and
>> duty factor without first to disable pwm. Since pwm code
>> is supported by more than one SoC add allow_runtime_cfg
>> parameter to atmel_pwm_chip data structure. This will be
>> filled statically for every SoC, saved in pwm specific
>> structure at probing time and checked while configuring
>> the device. Based on this, pwm clock will not be
>> enabled/disabled while configuring if it still enabled.
>>
>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>> ---
>>  drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
>>  1 file changed, 18 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
>> index 4406639..9e1dece 100644
>> --- a/drivers/pwm/pwm-atmel.c
>> +++ b/drivers/pwm/pwm-atmel.c
>> @@ -68,6 +68,8 @@ struct atmel_pwm_chip {
>>  
>>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>>  		       unsigned long dty, unsigned long prd);
>> +
>> +	bool allow_runtime_cfg;
>>  };
>>  
>>  static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
>> @@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	u32 val;
>>  	int ret;
>>  
>> -	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
>> +	if (!atmel_pwm->allow_runtime_cfg &&
>> +	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
>>  		dev_err(chip->dev, "cannot change PWM period while enabled\n");
>>  		return -EBUSY;
>>  	}
>> @@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	do_div(div, period_ns);
>>  	dty = prd - div;
>>  
>> -	ret = clk_enable(atmel_pwm->clk);
>> -	if (ret) {
>> -		dev_err(chip->dev, "failed to enable PWM clock\n");
>> -		return ret;
>> +	if (!pwm_is_enabled(pwm)) {
>> +		ret = clk_enable(atmel_pwm->clk);
>> +		if (ret) {
>> +			dev_err(chip->dev, "failed to enable PWM clock\n");
>> +			return ret;
>> +		}
>>  	}
>>  
> It is probably worth switching to atomic PWM instead of changing this
> function. This would simplify the whole driver.
I was thinking to switch to atomic PWM in a future patch.
>
>>  	/* It is necessary to preserve CPOL, inside CMR */
>> @@ -155,7 +160,9 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm);
>>  	mutex_unlock(&atmel_pwm->isr_lock);
>>  
>> -	clk_disable(atmel_pwm->clk);
>> +	if (!pwm_is_enabled(pwm))
>> +		clk_disable(atmel_pwm->clk);
>> +
>>  	return ret;
>>  }
>>  
>> @@ -294,18 +301,22 @@ static const struct pwm_ops atmel_pwm_ops = {
>>  struct atmel_pwm_data {
>>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>>  		       unsigned long dty, unsigned long prd);
>> +	bool allow_runtime_cfg;
>>  };
>>  
>>  static const struct atmel_pwm_data atmel_pwm_data_v1 = {
>>  	.config = atmel_pwm_config_v1,
>> +	.allow_runtime_cfg = false,
> This is useless as it is false even if not explicitly set.
Ok. I will do it in v2.
>
>>  };
>>  
>>  static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>>  	.config = atmel_pwm_config_v2,
>> +	.allow_runtime_cfg = false,
> ditto.
>
>>  };
>>  
>>  static const struct atmel_pwm_data atmel_pwm_data_v3 = {
>>  	.config = atmel_pwm_config_v3,
>> +	.allow_runtime_cfg = true,
>>  };
>>  
>>  static const struct platform_device_id atmel_pwm_devtypes[] = {
>> @@ -399,6 +410,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
>>  	atmel_pwm->chip.npwm = 4;
>>  	atmel_pwm->chip.can_sleep = true;
>>  	atmel_pwm->config = data->config;
>> +	atmel_pwm->allow_runtime_cfg = data->allow_runtime_cfg;
> It is probably worth having a pointer to the atmel_pwm_data instead of
> having to copy all the members.
Ok. I will do it in v2.
>
>>  	atmel_pwm->updated_pwms = 0;
>>  	mutex_init(&atmel_pwm->isr_lock);
>>  
>> -- 
>> 2.7.4
>>

Thank you,
Claudiu Beznea

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

* Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
  2017-02-23 10:25       ` m18063
  (?)
@ 2017-02-23 10:32         ` Boris Brezillon
  -1 siblings, 0 replies; 29+ messages in thread
From: Boris Brezillon @ 2017-02-23 10:32 UTC (permalink / raw)
  To: m18063
  Cc: Alexandre Belloni, thierry.reding, robh+dt, pawel.moll,
	mark.rutland, ijc+devicetree, galak, linux-pwm, devicetree,
	linux-kernel, linux-arm-kernel

Hi Claudiu,

On Thu, 23 Feb 2017 12:25:58 +0200
m18063 <Claudiu.Beznea@microchip.com> wrote:

> Hi,
> 
> 
> On 23.02.2017 11:21, Alexandre Belloni wrote:
> > On 23/02/2017 at 10:38:40 +0200, Claudiu Beznea wrote:  
> >> sama5d2 supports changing of pwm parameters like period and
> >> duty factor without first to disable pwm. Since pwm code
> >> is supported by more than one SoC add allow_runtime_cfg
> >> parameter to atmel_pwm_chip data structure. This will be
> >> filled statically for every SoC, saved in pwm specific
> >> structure at probing time and checked while configuring
> >> the device. Based on this, pwm clock will not be
> >> enabled/disabled while configuring if it still enabled.
> >>
> >> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> >> ---
> >>  drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
> >>  1 file changed, 18 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> >> index 4406639..9e1dece 100644
> >> --- a/drivers/pwm/pwm-atmel.c
> >> +++ b/drivers/pwm/pwm-atmel.c
> >> @@ -68,6 +68,8 @@ struct atmel_pwm_chip {
> >>  
> >>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
> >>  		       unsigned long dty, unsigned long prd);
> >> +
> >> +	bool allow_runtime_cfg;
> >>  };
> >>  
> >>  static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
> >> @@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> >>  	u32 val;
> >>  	int ret;
> >>  
> >> -	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
> >> +	if (!atmel_pwm->allow_runtime_cfg &&
> >> +	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
> >>  		dev_err(chip->dev, "cannot change PWM period while enabled\n");
> >>  		return -EBUSY;
> >>  	}
> >> @@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> >>  	do_div(div, period_ns);
> >>  	dty = prd - div;
> >>  
> >> -	ret = clk_enable(atmel_pwm->clk);
> >> -	if (ret) {
> >> -		dev_err(chip->dev, "failed to enable PWM clock\n");
> >> -		return ret;
> >> +	if (!pwm_is_enabled(pwm)) {
> >> +		ret = clk_enable(atmel_pwm->clk);
> >> +		if (ret) {
> >> +			dev_err(chip->dev, "failed to enable PWM clock\n");
> >> +			return ret;
> >> +		}
> >>  	}
> >>    
> > It is probably worth switching to atomic PWM instead of changing this
> > function. This would simplify the whole driver.  
> I was thinking to switch to atomic PWM in a future patch.

Actually, I think it's better to do it before adding support for the
new IP (even before patch 1), but maybe I'm the only one to think
so :-).

Note that switching to the atomic API is not a big (actually, it should
even simplify the code).

Regards,

Boris

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

* Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
@ 2017-02-23 10:32         ` Boris Brezillon
  0 siblings, 0 replies; 29+ messages in thread
From: Boris Brezillon @ 2017-02-23 10:32 UTC (permalink / raw)
  To: m18063
  Cc: Alexandre Belloni, thierry.reding, robh+dt, pawel.moll,
	mark.rutland, ijc+devicetree, galak, linux-pwm, devicetree,
	linux-kernel, linux-arm-kernel

Hi Claudiu,

On Thu, 23 Feb 2017 12:25:58 +0200
m18063 <Claudiu.Beznea@microchip.com> wrote:

> Hi,
> 
> 
> On 23.02.2017 11:21, Alexandre Belloni wrote:
> > On 23/02/2017 at 10:38:40 +0200, Claudiu Beznea wrote:  
> >> sama5d2 supports changing of pwm parameters like period and
> >> duty factor without first to disable pwm. Since pwm code
> >> is supported by more than one SoC add allow_runtime_cfg
> >> parameter to atmel_pwm_chip data structure. This will be
> >> filled statically for every SoC, saved in pwm specific
> >> structure at probing time and checked while configuring
> >> the device. Based on this, pwm clock will not be
> >> enabled/disabled while configuring if it still enabled.
> >>
> >> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> >> ---
> >>  drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
> >>  1 file changed, 18 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> >> index 4406639..9e1dece 100644
> >> --- a/drivers/pwm/pwm-atmel.c
> >> +++ b/drivers/pwm/pwm-atmel.c
> >> @@ -68,6 +68,8 @@ struct atmel_pwm_chip {
> >>  
> >>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
> >>  		       unsigned long dty, unsigned long prd);
> >> +
> >> +	bool allow_runtime_cfg;
> >>  };
> >>  
> >>  static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
> >> @@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> >>  	u32 val;
> >>  	int ret;
> >>  
> >> -	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
> >> +	if (!atmel_pwm->allow_runtime_cfg &&
> >> +	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
> >>  		dev_err(chip->dev, "cannot change PWM period while enabled\n");
> >>  		return -EBUSY;
> >>  	}
> >> @@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> >>  	do_div(div, period_ns);
> >>  	dty = prd - div;
> >>  
> >> -	ret = clk_enable(atmel_pwm->clk);
> >> -	if (ret) {
> >> -		dev_err(chip->dev, "failed to enable PWM clock\n");
> >> -		return ret;
> >> +	if (!pwm_is_enabled(pwm)) {
> >> +		ret = clk_enable(atmel_pwm->clk);
> >> +		if (ret) {
> >> +			dev_err(chip->dev, "failed to enable PWM clock\n");
> >> +			return ret;
> >> +		}
> >>  	}
> >>    
> > It is probably worth switching to atomic PWM instead of changing this
> > function. This would simplify the whole driver.  
> I was thinking to switch to atomic PWM in a future patch.

Actually, I think it's better to do it before adding support for the
new IP (even before patch 1), but maybe I'm the only one to think
so :-).

Note that switching to the atomic API is not a big (actually, it should
even simplify the code).

Regards,

Boris

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

* [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
@ 2017-02-23 10:32         ` Boris Brezillon
  0 siblings, 0 replies; 29+ messages in thread
From: Boris Brezillon @ 2017-02-23 10:32 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Claudiu,

On Thu, 23 Feb 2017 12:25:58 +0200
m18063 <Claudiu.Beznea@microchip.com> wrote:

> Hi,
> 
> 
> On 23.02.2017 11:21, Alexandre Belloni wrote:
> > On 23/02/2017 at 10:38:40 +0200, Claudiu Beznea wrote:  
> >> sama5d2 supports changing of pwm parameters like period and
> >> duty factor without first to disable pwm. Since pwm code
> >> is supported by more than one SoC add allow_runtime_cfg
> >> parameter to atmel_pwm_chip data structure. This will be
> >> filled statically for every SoC, saved in pwm specific
> >> structure at probing time and checked while configuring
> >> the device. Based on this, pwm clock will not be
> >> enabled/disabled while configuring if it still enabled.
> >>
> >> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> >> ---
> >>  drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
> >>  1 file changed, 18 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> >> index 4406639..9e1dece 100644
> >> --- a/drivers/pwm/pwm-atmel.c
> >> +++ b/drivers/pwm/pwm-atmel.c
> >> @@ -68,6 +68,8 @@ struct atmel_pwm_chip {
> >>  
> >>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
> >>  		       unsigned long dty, unsigned long prd);
> >> +
> >> +	bool allow_runtime_cfg;
> >>  };
> >>  
> >>  static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
> >> @@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> >>  	u32 val;
> >>  	int ret;
> >>  
> >> -	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
> >> +	if (!atmel_pwm->allow_runtime_cfg &&
> >> +	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
> >>  		dev_err(chip->dev, "cannot change PWM period while enabled\n");
> >>  		return -EBUSY;
> >>  	}
> >> @@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> >>  	do_div(div, period_ns);
> >>  	dty = prd - div;
> >>  
> >> -	ret = clk_enable(atmel_pwm->clk);
> >> -	if (ret) {
> >> -		dev_err(chip->dev, "failed to enable PWM clock\n");
> >> -		return ret;
> >> +	if (!pwm_is_enabled(pwm)) {
> >> +		ret = clk_enable(atmel_pwm->clk);
> >> +		if (ret) {
> >> +			dev_err(chip->dev, "failed to enable PWM clock\n");
> >> +			return ret;
> >> +		}
> >>  	}
> >>    
> > It is probably worth switching to atomic PWM instead of changing this
> > function. This would simplify the whole driver.  
> I was thinking to switch to atomic PWM in a future patch.

Actually, I think it's better to do it before adding support for the
new IP (even before patch 1), but maybe I'm the only one to think
so :-).

Note that switching to the atomic API is not a big (actually, it should
even simplify the code).

Regards,

Boris

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

* Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
  2017-02-23 10:25       ` m18063
@ 2017-02-23 10:32         ` Alexandre Belloni
  -1 siblings, 0 replies; 29+ messages in thread
From: Alexandre Belloni @ 2017-02-23 10:32 UTC (permalink / raw)
  To: m18063
  Cc: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, linux-pwm, devicetree,
	linux-kernel, linux-arm-kernel

On 23/02/2017 at 12:25:58 +0200, m18063 wrote:
> > It is probably worth switching to atomic PWM instead of changing this
> > function. This would simplify the whole driver.
> I was thinking to switch to atomic PWM in a future patch.

Then why wait ?


-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
@ 2017-02-23 10:32         ` Alexandre Belloni
  0 siblings, 0 replies; 29+ messages in thread
From: Alexandre Belloni @ 2017-02-23 10:32 UTC (permalink / raw)
  To: linux-arm-kernel

On 23/02/2017 at 12:25:58 +0200, m18063 wrote:
> > It is probably worth switching to atomic PWM instead of changing this
> > function. This would simplify the whole driver.
> I was thinking to switch to atomic PWM in a future patch.

Then why wait ?


-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
@ 2017-02-23 15:22           ` m18063
  0 siblings, 0 replies; 29+ messages in thread
From: m18063 @ 2017-02-23 15:22 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, linux-pwm, devicetree,
	linux-kernel, linux-arm-kernel


On 23.02.2017 12:32, Alexandre Belloni wrote:
> On 23/02/2017 at 12:25:58 +0200, m18063 wrote:
>>> It is probably worth switching to atomic PWM instead of changing this
>>> function. This would simplify the whole driver.
>> I was thinking to switch to atomic PWM in a future patch.
> Then why wait ?
>
>
I wanted to do it in progressively:
- enable the support for SAMA5d2
- make it work based on what is currently implemented
- add atomic PWM support.

Anyway, please ignore this patch. I will do it in atomic
PWM way.

Thank you,
Claudiu

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

* Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
@ 2017-02-23 15:22           ` m18063
  0 siblings, 0 replies; 29+ messages in thread
From: m18063 @ 2017-02-23 15:22 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: thierry.reding-Re5JQEeQqe8AvxtiuMwx3w,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	galak-sgV2jX0FEOL9JmXXK+q4OQ,
	boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	linux-pwm-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r


On 23.02.2017 12:32, Alexandre Belloni wrote:
> On 23/02/2017 at 12:25:58 +0200, m18063 wrote:
>>> It is probably worth switching to atomic PWM instead of changing this
>>> function. This would simplify the whole driver.
>> I was thinking to switch to atomic PWM in a future patch.
> Then why wait ?
>
>
I wanted to do it in progressively:
- enable the support for SAMA5d2
- make it work based on what is currently implemented
- add atomic PWM support.

Anyway, please ignore this patch. I will do it in atomic
PWM way.

Thank you,
Claudiu

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
@ 2017-02-23 15:22           ` m18063
  0 siblings, 0 replies; 29+ messages in thread
From: m18063 @ 2017-02-23 15:22 UTC (permalink / raw)
  To: linux-arm-kernel


On 23.02.2017 12:32, Alexandre Belloni wrote:
> On 23/02/2017 at 12:25:58 +0200, m18063 wrote:
>>> It is probably worth switching to atomic PWM instead of changing this
>>> function. This would simplify the whole driver.
>> I was thinking to switch to atomic PWM in a future patch.
> Then why wait ?
>
>
I wanted to do it in progressively:
- enable the support for SAMA5d2
- make it work based on what is currently implemented
- add atomic PWM support.

Anyway, please ignore this patch. I will do it in atomic
PWM way.

Thank you,
Claudiu

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

* Re: [PATCH 1/2] drivers: pwm: pwm-atmel: add support for pwm on sama5d2
  2017-02-23  9:16     ` Alexandre Belloni
  (?)
@ 2017-02-27 15:23       ` m18063
  -1 siblings, 0 replies; 29+ messages in thread
From: m18063 @ 2017-02-27 15:23 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, linux-pwm, devicetree,
	linux-kernel, linux-arm-kernel

Hi,
Please ignore this patch also. I will resend it after
switching to atomic PWM.

Thank you,
Claudiu Beznea


On 23.02.2017 11:16, Alexandre Belloni wrote:
> On 23/02/2017 at 10:38:39 +0200, Claudiu Beznea wrote:
>> Enable PWM on sama5d2 by adding atmel_pwm_config_v3().
>> This, simply, sets the period and duty factor registers.
>>
>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
>
>> ---
>>  Documentation/devicetree/bindings/pwm/atmel-pwm.txt |  1 +
>>  drivers/pwm/pwm-atmel.c                             | 16 ++++++++++++++++
>>  2 files changed, 17 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
>> index 02331b9..c8c831d 100644
>> --- a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
>> +++ b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
>> @@ -4,6 +4,7 @@ Required properties:
>>    - compatible: should be one of:
>>      - "atmel,at91sam9rl-pwm"
>>      - "atmel,sama5d3-pwm"
>> +    - "atmel,sama5d2-pwm"
>>    - reg: physical base address and length of the controller's registers
>>    - #pwm-cells: Should be 3. See pwm.txt in this directory for a
>>      description of the cells format.
>> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
>> index 0e4bd4e..4406639 100644
>> --- a/drivers/pwm/pwm-atmel.c
>> +++ b/drivers/pwm/pwm-atmel.c
>> @@ -207,6 +207,15 @@ static void atmel_pwm_config_v2(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	}
>>  }
>>  
>> +static void atmel_pwm_config_v3(struct pwm_chip *chip, struct pwm_device *pwm,
>> +				unsigned long dty, unsigned long prd)
>> +{
>> +	struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
>> +
>> +	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CDTY, dty);
>> +	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CPRD, prd);
>> +}
>> +
>>  static int atmel_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
>>  				  enum pwm_polarity polarity)
>>  {
>> @@ -295,6 +304,10 @@ static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>>  	.config = atmel_pwm_config_v2,
>>  };
>>  
>> +static const struct atmel_pwm_data atmel_pwm_data_v3 = {
>> +	.config = atmel_pwm_config_v3,
>> +};
>> +
>>  static const struct platform_device_id atmel_pwm_devtypes[] = {
>>  	{
>>  		.name = "at91sam9rl-pwm",
>> @@ -316,6 +329,9 @@ static const struct of_device_id atmel_pwm_dt_ids[] = {
>>  		.compatible = "atmel,sama5d3-pwm",
>>  		.data = &atmel_pwm_data_v2,
>>  	}, {
>> +		.compatible = "atmel,sama5d2-pwm",
>> +		.data = &atmel_pwm_data_v3,
>> +	}, {
>>  		/* sentinel */
>>  	},
>>  };
>> -- 
>> 2.7.4
>>

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

* Re: [PATCH 1/2] drivers: pwm: pwm-atmel: add support for pwm on sama5d2
@ 2017-02-27 15:23       ` m18063
  0 siblings, 0 replies; 29+ messages in thread
From: m18063 @ 2017-02-27 15:23 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: thierry.reding, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak, boris.brezillon, linux-pwm, devicetree,
	linux-kernel, linux-arm-kernel

Hi,
Please ignore this patch also. I will resend it after
switching to atomic PWM.

Thank you,
Claudiu Beznea


On 23.02.2017 11:16, Alexandre Belloni wrote:
> On 23/02/2017 at 10:38:39 +0200, Claudiu Beznea wrote:
>> Enable PWM on sama5d2 by adding atmel_pwm_config_v3().
>> This, simply, sets the period and duty factor registers.
>>
>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
>
>> ---
>>  Documentation/devicetree/bindings/pwm/atmel-pwm.txt |  1 +
>>  drivers/pwm/pwm-atmel.c                             | 16 ++++++++++++++++
>>  2 files changed, 17 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
>> index 02331b9..c8c831d 100644
>> --- a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
>> +++ b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
>> @@ -4,6 +4,7 @@ Required properties:
>>    - compatible: should be one of:
>>      - "atmel,at91sam9rl-pwm"
>>      - "atmel,sama5d3-pwm"
>> +    - "atmel,sama5d2-pwm"
>>    - reg: physical base address and length of the controller's registers
>>    - #pwm-cells: Should be 3. See pwm.txt in this directory for a
>>      description of the cells format.
>> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
>> index 0e4bd4e..4406639 100644
>> --- a/drivers/pwm/pwm-atmel.c
>> +++ b/drivers/pwm/pwm-atmel.c
>> @@ -207,6 +207,15 @@ static void atmel_pwm_config_v2(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	}
>>  }
>>  
>> +static void atmel_pwm_config_v3(struct pwm_chip *chip, struct pwm_device *pwm,
>> +				unsigned long dty, unsigned long prd)
>> +{
>> +	struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
>> +
>> +	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CDTY, dty);
>> +	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CPRD, prd);
>> +}
>> +
>>  static int atmel_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
>>  				  enum pwm_polarity polarity)
>>  {
>> @@ -295,6 +304,10 @@ static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>>  	.config = atmel_pwm_config_v2,
>>  };
>>  
>> +static const struct atmel_pwm_data atmel_pwm_data_v3 = {
>> +	.config = atmel_pwm_config_v3,
>> +};
>> +
>>  static const struct platform_device_id atmel_pwm_devtypes[] = {
>>  	{
>>  		.name = "at91sam9rl-pwm",
>> @@ -316,6 +329,9 @@ static const struct of_device_id atmel_pwm_dt_ids[] = {
>>  		.compatible = "atmel,sama5d3-pwm",
>>  		.data = &atmel_pwm_data_v2,
>>  	}, {
>> +		.compatible = "atmel,sama5d2-pwm",
>> +		.data = &atmel_pwm_data_v3,
>> +	}, {
>>  		/* sentinel */
>>  	},
>>  };
>> -- 
>> 2.7.4
>>

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

* [PATCH 1/2] drivers: pwm: pwm-atmel: add support for pwm on sama5d2
@ 2017-02-27 15:23       ` m18063
  0 siblings, 0 replies; 29+ messages in thread
From: m18063 @ 2017-02-27 15:23 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,
Please ignore this patch also. I will resend it after
switching to atomic PWM.

Thank you,
Claudiu Beznea


On 23.02.2017 11:16, Alexandre Belloni wrote:
> On 23/02/2017 at 10:38:39 +0200, Claudiu Beznea wrote:
>> Enable PWM on sama5d2 by adding atmel_pwm_config_v3().
>> This, simply, sets the period and duty factor registers.
>>
>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
>
>> ---
>>  Documentation/devicetree/bindings/pwm/atmel-pwm.txt |  1 +
>>  drivers/pwm/pwm-atmel.c                             | 16 ++++++++++++++++
>>  2 files changed, 17 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
>> index 02331b9..c8c831d 100644
>> --- a/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
>> +++ b/Documentation/devicetree/bindings/pwm/atmel-pwm.txt
>> @@ -4,6 +4,7 @@ Required properties:
>>    - compatible: should be one of:
>>      - "atmel,at91sam9rl-pwm"
>>      - "atmel,sama5d3-pwm"
>> +    - "atmel,sama5d2-pwm"
>>    - reg: physical base address and length of the controller's registers
>>    - #pwm-cells: Should be 3. See pwm.txt in this directory for a
>>      description of the cells format.
>> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
>> index 0e4bd4e..4406639 100644
>> --- a/drivers/pwm/pwm-atmel.c
>> +++ b/drivers/pwm/pwm-atmel.c
>> @@ -207,6 +207,15 @@ static void atmel_pwm_config_v2(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	}
>>  }
>>  
>> +static void atmel_pwm_config_v3(struct pwm_chip *chip, struct pwm_device *pwm,
>> +				unsigned long dty, unsigned long prd)
>> +{
>> +	struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
>> +
>> +	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CDTY, dty);
>> +	atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CPRD, prd);
>> +}
>> +
>>  static int atmel_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
>>  				  enum pwm_polarity polarity)
>>  {
>> @@ -295,6 +304,10 @@ static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>>  	.config = atmel_pwm_config_v2,
>>  };
>>  
>> +static const struct atmel_pwm_data atmel_pwm_data_v3 = {
>> +	.config = atmel_pwm_config_v3,
>> +};
>> +
>>  static const struct platform_device_id atmel_pwm_devtypes[] = {
>>  	{
>>  		.name = "at91sam9rl-pwm",
>> @@ -316,6 +329,9 @@ static const struct of_device_id atmel_pwm_dt_ids[] = {
>>  		.compatible = "atmel,sama5d3-pwm",
>>  		.data = &atmel_pwm_data_v2,
>>  	}, {
>> +		.compatible = "atmel,sama5d2-pwm",
>> +		.data = &atmel_pwm_data_v3,
>> +	}, {
>>  		/* sentinel */
>>  	},
>>  };
>> -- 
>> 2.7.4
>>

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

end of thread, other threads:[~2017-02-27 15:28 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-23  8:38 [PATCH 0/2] drivers: pwm: add pwm support for sama5d2 Claudiu Beznea
2017-02-23  8:38 ` Claudiu Beznea
2017-02-23  8:38 ` Claudiu Beznea
2017-02-23  8:38 ` [PATCH 1/2] drivers: pwm: pwm-atmel: add support for pwm on sama5d2 Claudiu Beznea
2017-02-23  8:38   ` Claudiu Beznea
2017-02-23  8:38   ` Claudiu Beznea
2017-02-23  9:16   ` Alexandre Belloni
2017-02-23  9:16     ` Alexandre Belloni
2017-02-23  9:16     ` Alexandre Belloni
2017-02-27 15:23     ` m18063
2017-02-27 15:23       ` m18063
2017-02-27 15:23       ` m18063
2017-02-23  8:38 ` [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters Claudiu Beznea
2017-02-23  8:38   ` Claudiu Beznea
2017-02-23  8:38   ` Claudiu Beznea
2017-02-23  9:21   ` Alexandre Belloni
2017-02-23  9:21     ` Alexandre Belloni
2017-02-23  9:21     ` Alexandre Belloni
2017-02-23 10:25     ` m18063
2017-02-23 10:25       ` m18063
2017-02-23 10:25       ` m18063
2017-02-23 10:32       ` Boris Brezillon
2017-02-23 10:32         ` Boris Brezillon
2017-02-23 10:32         ` Boris Brezillon
2017-02-23 10:32       ` Alexandre Belloni
2017-02-23 10:32         ` Alexandre Belloni
2017-02-23 15:22         ` m18063
2017-02-23 15:22           ` m18063
2017-02-23 15:22           ` m18063

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.