All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudiu Beznea <claudiu.beznea@microchip.com>
To: <thierry.reding@gmail.com>, <robh+dt@kernel.org>,
	<pawel.moll@arm.com>, <mark.rutland@arm.com>,
	<ijc+devicetree@hellion.org.uk>, <galak@codeaurora.org>,
	<boris.brezillon@free-electrons.com>,
	<alexandre.belloni@free-electrons.com>
Cc: <linux-pwm@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	Claudiu Beznea <claudiu.beznea@microchip.com>
Subject: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
Date: Thu, 23 Feb 2017 10:38:40 +0200	[thread overview]
Message-ID: <1487839120-13650-3-git-send-email-claudiu.beznea@microchip.com> (raw)
In-Reply-To: <1487839120-13650-1-git-send-email-claudiu.beznea@microchip.com>

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

WARNING: multiple messages have this Message-ID (diff)
From: Claudiu Beznea <claudiu.beznea@microchip.com>
To: thierry.reding@gmail.com, robh+dt@kernel.org, pawel.moll@arm.com,
	mark.rutland@arm.com, ijc+devicetree@hellion.org.uk,
	galak@codeaurora.org, boris.brezillon@free-electrons.com,
	alexandre.belloni@free-electrons.com
Cc: linux-pwm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Claudiu Beznea <claudiu.beznea@microchip.com>
Subject: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
Date: Thu, 23 Feb 2017 10:38:40 +0200	[thread overview]
Message-ID: <1487839120-13650-3-git-send-email-claudiu.beznea@microchip.com> (raw)
In-Reply-To: <1487839120-13650-1-git-send-email-claudiu.beznea@microchip.com>

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

WARNING: multiple messages have this Message-ID (diff)
From: claudiu.beznea@microchip.com (Claudiu Beznea)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
Date: Thu, 23 Feb 2017 10:38:40 +0200	[thread overview]
Message-ID: <1487839120-13650-3-git-send-email-claudiu.beznea@microchip.com> (raw)
In-Reply-To: <1487839120-13650-1-git-send-email-claudiu.beznea@microchip.com>

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

  parent reply	other threads:[~2017-02-23  8:43 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Claudiu Beznea [this message]
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  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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1487839120-13650-3-git-send-email-claudiu.beznea@microchip.com \
    --to=claudiu.beznea@microchip.com \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=boris.brezillon@free-electrons.com \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.