* [PATCH 1/5] pwm: tegra: Add support for reset control
2016-06-22 11:47 [PATCH 0/5] pwm: Fixes and support for Tegra186 Laxman Dewangan
@ 2016-06-22 11:47 ` Laxman Dewangan
2016-06-22 12:40 ` Thierry Reding
2016-06-22 11:47 ` [PATCH 2/5] pwm: tegra: Allow 100% duty cycle Laxman Dewangan
` (4 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Laxman Dewangan @ 2016-06-22 11:47 UTC (permalink / raw)
To: thierry.reding, robh+dt, swarren, gnurou
Cc: linux-pwm, devicetree, linux-tegra, linux-kernel,
Rohith Seelaboyina, Laxman Dewangan
From: Rohith Seelaboyina <rseelaboyina@nvidia.com>
Add reset control of the PWM controller to reset it before
accessing the PWM register.
Signed-off-by: Rohith Seelaboyina <rseelaboyina@nvidia.com>
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
---
drivers/pwm/pwm-tegra.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
index d4de060..71b9c4d 100644
--- a/drivers/pwm/pwm-tegra.c
+++ b/drivers/pwm/pwm-tegra.c
@@ -29,6 +29,7 @@
#include <linux/pwm.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
+#include <linux/reset.h>
#define PWM_ENABLE (1 << 31)
#define PWM_DUTY_WIDTH 8
@@ -43,6 +44,7 @@ struct tegra_pwm_chip {
struct device *dev;
struct clk *clk;
+ struct reset_control *rstc;
void __iomem *mmio_base;
};
@@ -189,6 +191,14 @@ static int tegra_pwm_probe(struct platform_device *pdev)
if (IS_ERR(pwm->clk))
return PTR_ERR(pwm->clk);
+ pwm->rstc = devm_reset_control_get(&pdev->dev, "pwm");
+ if (IS_ERR(pwm->rstc)) {
+ ret = PTR_ERR(pwm->rstc);
+ dev_err(&pdev->dev, "Reset control is not found: %d\n", ret);
+ return ret;
+ }
+ reset_control_reset(pwm->rstc);
+
pwm->chip.dev = &pdev->dev;
pwm->chip.ops = &tegra_pwm_ops;
pwm->chip.base = -1;
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 1/5] pwm: tegra: Add support for reset control
2016-06-22 11:47 ` [PATCH 1/5] pwm: tegra: Add support for reset control Laxman Dewangan
@ 2016-06-22 12:40 ` Thierry Reding
0 siblings, 0 replies; 12+ messages in thread
From: Thierry Reding @ 2016-06-22 12:40 UTC (permalink / raw)
To: Laxman Dewangan
Cc: robh+dt, swarren, gnurou, linux-pwm, devicetree, linux-tegra,
linux-kernel, Rohith Seelaboyina
[-- Attachment #1: Type: text/plain, Size: 1660 bytes --]
On Wed, Jun 22, 2016 at 05:17:19PM +0530, Laxman Dewangan wrote:
> From: Rohith Seelaboyina <rseelaboyina@nvidia.com>
>
> Add reset control of the PWM controller to reset it before
> accessing the PWM register.
>
> Signed-off-by: Rohith Seelaboyina <rseelaboyina@nvidia.com>
> Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
> ---
> drivers/pwm/pwm-tegra.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
> index d4de060..71b9c4d 100644
> --- a/drivers/pwm/pwm-tegra.c
> +++ b/drivers/pwm/pwm-tegra.c
> @@ -29,6 +29,7 @@
> #include <linux/pwm.h>
> #include <linux/platform_device.h>
> #include <linux/slab.h>
> +#include <linux/reset.h>
>
> #define PWM_ENABLE (1 << 31)
> #define PWM_DUTY_WIDTH 8
> @@ -43,6 +44,7 @@ struct tegra_pwm_chip {
> struct device *dev;
>
> struct clk *clk;
> + struct reset_control *rstc;
Drop the 'c' at the end, for consistency with other drivers.
>
> void __iomem *mmio_base;
> };
> @@ -189,6 +191,14 @@ static int tegra_pwm_probe(struct platform_device *pdev)
> if (IS_ERR(pwm->clk))
> return PTR_ERR(pwm->clk);
>
> + pwm->rstc = devm_reset_control_get(&pdev->dev, "pwm");
> + if (IS_ERR(pwm->rstc)) {
> + ret = PTR_ERR(pwm->rstc);
> + dev_err(&pdev->dev, "Reset control is not found: %d\n", ret);
> + return ret;
> + }
> + reset_control_reset(pwm->rstc);
I think you want reset_control_deassert() here and the call its counter-
part, reset_control_assert(), in tegra_pwm_remove().
No particular need to respin, I can make those changes when I apply.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/5] pwm: tegra: Allow 100% duty cycle
2016-06-22 11:47 [PATCH 0/5] pwm: Fixes and support for Tegra186 Laxman Dewangan
2016-06-22 11:47 ` [PATCH 1/5] pwm: tegra: Add support for reset control Laxman Dewangan
@ 2016-06-22 11:47 ` Laxman Dewangan
2016-06-22 11:47 ` [PATCH 3/5] pwm: tegra: fix overflow when calculating " Laxman Dewangan
` (3 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Laxman Dewangan @ 2016-06-22 11:47 UTC (permalink / raw)
To: thierry.reding, robh+dt, swarren, gnurou
Cc: linux-pwm, devicetree, linux-tegra, linux-kernel,
Victor(Weiguo) Pan, Laxman Dewangan
From: "Victor(Weiguo) Pan" <wpan@nvidia.com>
To get 100% duty cycle (always high), pulse width needs to be
set to 256.
Signed-off-by: Victor(Weiguo) Pan <wpan@nvidia.com>
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
---
drivers/pwm/pwm-tegra.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
index 71b9c4d..575ca8e 100644
--- a/drivers/pwm/pwm-tegra.c
+++ b/drivers/pwm/pwm-tegra.c
@@ -79,7 +79,7 @@ static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
* per (1 << PWM_DUTY_WIDTH) cycles and make sure to round to the
* nearest integer during division.
*/
- c = duty_ns * ((1 << PWM_DUTY_WIDTH) - 1) + period_ns / 2;
+ c = duty_ns * (1 << PWM_DUTY_WIDTH) + period_ns / 2;
do_div(c, period_ns);
val = (u32)c << PWM_DUTY_SHIFT;
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/5] pwm: tegra: fix overflow when calculating duty cycle
2016-06-22 11:47 [PATCH 0/5] pwm: Fixes and support for Tegra186 Laxman Dewangan
2016-06-22 11:47 ` [PATCH 1/5] pwm: tegra: Add support for reset control Laxman Dewangan
2016-06-22 11:47 ` [PATCH 2/5] pwm: tegra: Allow 100% duty cycle Laxman Dewangan
@ 2016-06-22 11:47 ` Laxman Dewangan
2016-06-22 11:47 ` [PATCH 4/5] pwm: tegra: Add DT node compatible for Tegra186 Laxman Dewangan
` (2 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Laxman Dewangan @ 2016-06-22 11:47 UTC (permalink / raw)
To: thierry.reding, robh+dt, swarren, gnurou
Cc: linux-pwm, devicetree, linux-tegra, linux-kernel, Hyong Bin Kim,
Laxman Dewangan
From: Hyong Bin Kim <hyongbink@nvidia.com>
duty_ns * (1 << PWM_DUTY_WIDTH) could overflow in integer calcualtion
when PWM rate is low. Hence do all calculation on unsigned long long
to avoid overflow.
Signed-off-by: Hyong Bin Kim <hyongbink@nvidia.com>
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
---
drivers/pwm/pwm-tegra.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
index 575ca8e..49cefd5 100644
--- a/drivers/pwm/pwm-tegra.c
+++ b/drivers/pwm/pwm-tegra.c
@@ -69,7 +69,7 @@ static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
int duty_ns, int period_ns)
{
struct tegra_pwm_chip *pc = to_tegra_pwm_chip(chip);
- unsigned long long c;
+ unsigned long long c = duty_ns;
unsigned long rate, hz;
u32 val = 0;
int err;
@@ -79,7 +79,8 @@ static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
* per (1 << PWM_DUTY_WIDTH) cycles and make sure to round to the
* nearest integer during division.
*/
- c = duty_ns * (1 << PWM_DUTY_WIDTH) + period_ns / 2;
+ c *= (1 << PWM_DUTY_WIDTH);
+ c += period_ns / 2;
do_div(c, period_ns);
val = (u32)c << PWM_DUTY_SHIFT;
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 4/5] pwm: tegra: Add DT node compatible for Tegra186
2016-06-22 11:47 [PATCH 0/5] pwm: Fixes and support for Tegra186 Laxman Dewangan
` (2 preceding siblings ...)
2016-06-22 11:47 ` [PATCH 3/5] pwm: tegra: fix overflow when calculating " Laxman Dewangan
@ 2016-06-22 11:47 ` Laxman Dewangan
2016-06-22 12:46 ` Thierry Reding
[not found] ` <1466596043-27262-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-07-11 9:31 ` [PATCH 0/5] pwm: Fixes and " Thierry Reding
5 siblings, 1 reply; 12+ messages in thread
From: Laxman Dewangan @ 2016-06-22 11:47 UTC (permalink / raw)
To: thierry.reding, robh+dt, swarren, gnurou
Cc: linux-pwm, devicetree, linux-tegra, linux-kernel, Laxman Dewangan
Tegra186 has 8 different PWM controller and each controller has only
one output. Earlier generation SoCs have the 4 PWM output per controller.
Add DT node compatible for Tegra186.
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
---
Documentation/devicetree/bindings/pwm/nvidia,tegra20-pwm.txt | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/Documentation/devicetree/bindings/pwm/nvidia,tegra20-pwm.txt b/Documentation/devicetree/bindings/pwm/nvidia,tegra20-pwm.txt
index c52f03b..2851b2d 100644
--- a/Documentation/devicetree/bindings/pwm/nvidia,tegra20-pwm.txt
+++ b/Documentation/devicetree/bindings/pwm/nvidia,tegra20-pwm.txt
@@ -1,10 +1,12 @@
Tegra SoC PWFM controller
Required properties:
-- compatible: For Tegra20, must contain "nvidia,tegra20-pwm". For Tegra30,
- must contain "nvidia,tegra30-pwm". Otherwise, must contain
- "nvidia,<chip>-pwm", plus one of the above, where <chip> is tegra114,
- tegra124, tegra132, or tegra210.
+- compatible: For Tegra20, must contain "nvidia,tegra20-pwm".
+ For Tegra30, must contain "nvidia,tegra30-pwm".
+ For Tegra114, Tegra124, Tegra132, Tegra210 must contain
+ "nvidia,<chip>-pwm", plus one of the above, where <chip> is
+ tegra114, tegra124, tegra132, or tegra210.
+ For Tegra186, must contain "nvidia,tegra186-pwm".
- reg: physical base address and length of the controller's registers
- #pwm-cells: should be 2. See pwm.txt in this directory for a description of
the cells format.
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 4/5] pwm: tegra: Add DT node compatible for Tegra186
2016-06-22 11:47 ` [PATCH 4/5] pwm: tegra: Add DT node compatible for Tegra186 Laxman Dewangan
@ 2016-06-22 12:46 ` Thierry Reding
[not found] ` <20160622124614.GG26943-EkSeR96xj6Pcmrwk2tT4+A@public.gmane.org>
0 siblings, 1 reply; 12+ messages in thread
From: Thierry Reding @ 2016-06-22 12:46 UTC (permalink / raw)
To: Rob Herring
Cc: Laxman Dewangan, swarren, gnurou, linux-pwm, devicetree,
linux-tegra, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1826 bytes --]
On Wed, Jun 22, 2016 at 05:17:22PM +0530, Laxman Dewangan wrote:
> Tegra186 has 8 different PWM controller and each controller has only
> one output. Earlier generation SoCs have the 4 PWM output per controller.
>
> Add DT node compatible for Tegra186.
>
> Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
> ---
> Documentation/devicetree/bindings/pwm/nvidia,tegra20-pwm.txt | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/pwm/nvidia,tegra20-pwm.txt b/Documentation/devicetree/bindings/pwm/nvidia,tegra20-pwm.txt
> index c52f03b..2851b2d 100644
> --- a/Documentation/devicetree/bindings/pwm/nvidia,tegra20-pwm.txt
> +++ b/Documentation/devicetree/bindings/pwm/nvidia,tegra20-pwm.txt
> @@ -1,10 +1,12 @@
> Tegra SoC PWFM controller
>
> Required properties:
> -- compatible: For Tegra20, must contain "nvidia,tegra20-pwm". For Tegra30,
> - must contain "nvidia,tegra30-pwm". Otherwise, must contain
> - "nvidia,<chip>-pwm", plus one of the above, where <chip> is tegra114,
> - tegra124, tegra132, or tegra210.
> +- compatible: For Tegra20, must contain "nvidia,tegra20-pwm".
> + For Tegra30, must contain "nvidia,tegra30-pwm".
> + For Tegra114, Tegra124, Tegra132, Tegra210 must contain
> + "nvidia,<chip>-pwm", plus one of the above, where <chip> is
> + tegra114, tegra124, tegra132, or tegra210.
> + For Tegra186, must contain "nvidia,tegra186-pwm".
Rob, I recall discussing this with you a couple of weeks ago, but fail
to remember the outcome and can't find a link to the discussion either.
Wasn't there a new standard way of documenting this kind of compatible
string list?
Or did you say it didn't matter much until we moved to a YAML-based
description?
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <1466596043-27262-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>]
* [PATCH 5/5] pwm: tegra: Add support for Tegra186
[not found] ` <1466596043-27262-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
@ 2016-06-22 11:47 ` Laxman Dewangan
[not found] ` <1466596043-27262-6-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 12+ messages in thread
From: Laxman Dewangan @ 2016-06-22 11:47 UTC (permalink / raw)
To: thierry.reding-Re5JQEeQqe8AvxtiuMwx3w,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A, swarren-3lzwWm7+Weoh9ZMKESR00Q,
gnurou-Re5JQEeQqe8AvxtiuMwx3w
Cc: linux-pwm-u79uwXL29TY76Z2rM5mHXA,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Laxman Dewangan
Tegra186 has PWM controller with only one output instead of
4 output in earlier generation SoCs.
Add support for Tegra186 and find the number of PWM output
based on driver data.
Signed-off-by: Laxman Dewangan <ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
drivers/pwm/pwm-tegra.c | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
index 49cefd5..5547e7d 100644
--- a/drivers/pwm/pwm-tegra.c
+++ b/drivers/pwm/pwm-tegra.c
@@ -26,6 +26,7 @@
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/pwm.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
@@ -37,7 +38,9 @@
#define PWM_SCALE_WIDTH 13
#define PWM_SCALE_SHIFT 0
-#define NUM_PWM 4
+struct tegra_pwm_hwdata {
+ int num_pwm;
+};
struct tegra_pwm_chip {
struct pwm_chip chip;
@@ -47,6 +50,7 @@ struct tegra_pwm_chip {
struct reset_control *rstc;
void __iomem *mmio_base;
+ const struct tegra_pwm_hwdata *hw;
};
static inline struct tegra_pwm_chip *to_tegra_pwm_chip(struct pwm_chip *chip)
@@ -172,9 +176,16 @@ static const struct pwm_ops tegra_pwm_ops = {
static int tegra_pwm_probe(struct platform_device *pdev)
{
struct tegra_pwm_chip *pwm;
+ const struct tegra_pwm_hwdata *hwdata;
struct resource *r;
int ret;
+ hwdata = of_device_get_match_data(&pdev->dev);
+ if (!hwdata) {
+ dev_err(&pdev->dev, "Tegra PWM HW data not found\n");
+ return -ENODEV;
+ }
+
pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
if (!pwm)
return -ENOMEM;
@@ -200,10 +211,11 @@ static int tegra_pwm_probe(struct platform_device *pdev)
}
reset_control_reset(pwm->rstc);
+ pwm->hw = hwdata;
pwm->chip.dev = &pdev->dev;
pwm->chip.ops = &tegra_pwm_ops;
pwm->chip.base = -1;
- pwm->chip.npwm = NUM_PWM;
+ pwm->chip.npwm = pwm->hw->num_pwm;
ret = pwmchip_add(&pwm->chip);
if (ret < 0) {
@@ -222,7 +234,7 @@ static int tegra_pwm_remove(struct platform_device *pdev)
if (WARN_ON(!pc))
return -ENODEV;
- for (i = 0; i < NUM_PWM; i++) {
+ for (i = 0; i < pc->hw->num_pwm; i++) {
struct pwm_device *pwm = &pc->chip.pwms[i];
if (!pwm_is_enabled(pwm))
@@ -237,9 +249,18 @@ static int tegra_pwm_remove(struct platform_device *pdev)
return pwmchip_remove(&pc->chip);
}
+static const struct tegra_pwm_hwdata tegra20_pwm_hw = {
+ .num_pwm = 4,
+};
+
+static const struct tegra_pwm_hwdata tegra186_pwm_hw = {
+ .num_pwm = 1,
+};
+
static const struct of_device_id tegra_pwm_of_match[] = {
- { .compatible = "nvidia,tegra20-pwm" },
- { .compatible = "nvidia,tegra30-pwm" },
+ { .compatible = "nvidia,tegra20-pwm", .data = &tegra20_pwm_hw },
+ { .compatible = "nvidia,tegra30-pwm", .data = &tegra20_pwm_hw },
+ { .compatible = "nvidia,tegra186-pwm", .data = &tegra186_pwm_hw, },
{ }
};
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 0/5] pwm: Fixes and support for Tegra186
2016-06-22 11:47 [PATCH 0/5] pwm: Fixes and support for Tegra186 Laxman Dewangan
` (4 preceding siblings ...)
[not found] ` <1466596043-27262-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
@ 2016-07-11 9:31 ` Thierry Reding
5 siblings, 0 replies; 12+ messages in thread
From: Thierry Reding @ 2016-07-11 9:31 UTC (permalink / raw)
To: Laxman Dewangan
Cc: robh+dt, swarren, gnurou, linux-pwm, devicetree, linux-tegra,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 809 bytes --]
On Wed, Jun 22, 2016 at 05:17:18PM +0530, Laxman Dewangan wrote:
> Have fixes for 100% duty cycle, avoid computation loss for duty
> period calculation and add support the Tegra186.
>
> Hyong Bin Kim (1):
> pwm: tegra: fix overflow when calculating duty cycle
>
> Laxman Dewangan (2):
> pwm: tegra: Add DT node compatible for Tegra186
> pwm: tegra: Add support for Tegra186
>
> Rohith Seelaboyina (1):
> pwm: tegra: Add support for reset control
>
> Victor(Weiguo) Pan (1):
> pwm: tegra: Allow 100% duty cycle
>
> .../devicetree/bindings/pwm/nvidia,tegra20-pwm.txt | 10 +++--
> drivers/pwm/pwm-tegra.c | 46 ++++++++++++++++++----
> 2 files changed, 45 insertions(+), 11 deletions(-)
All of these applied, with some minor changes.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread