linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] pwm: Device tree support for PWM polarity.
@ 2012-11-21  7:40 Philip, Avinash
  2012-11-21 16:32 ` Grant Likely
  2012-11-22 21:29 ` Thierry Reding
  0 siblings, 2 replies; 3+ messages in thread
From: Philip, Avinash @ 2012-11-21  7:40 UTC (permalink / raw)
  To: thierry.reding, grant.likely, rob.herring, rob
  Cc: linux-kernel, devicetree-discuss, linux-doc, linux-arm-kernel,
	nsekhar, gururaja.hebbar, Philip, Avinash

Add support for encoding PWM properties in bit encoded form with
of_pwm_xlate_with_flags() function support. Platforms require platform
specific PWM properties has to populate in 3rd cell of the pwm-specifier
and PWM driver should also set .of_xlate support with this function.
Currently PWM property polarity encoded in bit position 0 of the third
cell in pwm-specifier.

Signed-off-by: Philip, Avinash <avinashphilip@ti.com>
---
Changes since v2:
	- Move PWM_SPEC_POLARITY to core.c
	- Remove dummy function

Changes since v1:
	- of_pwm_xlate_with_flags function support added.
	- Documentation update

:100644 100644 73ec962... 04b0dc4... M	Documentation/devicetree/bindings/pwm/pwm.txt
:100644 100644 f5acdaa... 780cb6b... M	drivers/pwm/core.c
:100644 100644 112b314... 6d661f3... M	include/linux/pwm.h
 Documentation/devicetree/bindings/pwm/pwm.txt |   18 +++++++++++++--
 drivers/pwm/core.c                            |   28 +++++++++++++++++++++++++
 include/linux/pwm.h                           |    3 ++
 3 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/pwm/pwm.txt b/Documentation/devicetree/bindings/pwm/pwm.txt
index 73ec962..04b0dc4 100644
--- a/Documentation/devicetree/bindings/pwm/pwm.txt
+++ b/Documentation/devicetree/bindings/pwm/pwm.txt
@@ -37,10 +37,22 @@ device:
 		pwm-names = "backlight";
 	};
 
+Note that in the example above, specifying the "pwm-names" is redundant
+because the name "backlight" would be used as fallback anyway.
+
 pwm-specifier typically encodes the chip-relative PWM number and the PWM
-period in nanoseconds. Note that in the example above, specifying the
-"pwm-names" is redundant because the name "backlight" would be used as
-fallback anyway.
+period in nanoseconds.
+
+Optionally, the pwm-specifier can encode a number of flags in a third cell:
+- bit 0: PWM signal polarity (0: normal polarity, 1: inverse polarity)
+
+Example with optional PWM specifier for inverse polarity
+
+	bl: backlight {
+		pwms = <&pwm 0 5000000 1>;
+		pwm-names = "backlight";
+	};
+
 
 2) PWM controller nodes
 -----------------------
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index f5acdaa..780cb6b 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -32,6 +32,9 @@
 
 #define MAX_PWMS 1024
 
+/* flags in the third cell of the DT PWM specifier */
+#define PWM_SPEC_POLARITY	(1 << 0)
+
 static DEFINE_MUTEX(pwm_lookup_lock);
 static LIST_HEAD(pwm_lookup_list);
 static DEFINE_MUTEX(pwm_lock);
@@ -129,6 +132,31 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
 	return 0;
 }
 
+struct pwm_device *
+of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
+{
+	struct pwm_device *pwm;
+
+	if (pc->of_pwm_n_cells < 3)
+		return ERR_PTR(-EINVAL);
+
+	if (args->args[0] >= pc->npwm)
+		return ERR_PTR(-EINVAL);
+
+	pwm = pwm_request_from_chip(pc, args->args[0], NULL);
+	if (IS_ERR(pwm))
+		return pwm;
+
+	pwm_set_period(pwm, args->args[1]);
+
+	if (args->args[2] & PWM_SPEC_POLARITY)
+		pwm_set_polarity(pwm, PWM_POLARITY_INVERSED);
+	else
+		pwm_set_polarity(pwm, PWM_POLARITY_NORMAL);
+
+	return pwm;
+}
+
 static struct pwm_device *
 of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
 {
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 112b314..6d661f3 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -171,6 +171,9 @@ struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
 					 unsigned int index,
 					 const char *label);
 
+struct pwm_device *of_pwm_xlate_with_flags(struct pwm_chip *pc,
+		const struct of_phandle_args *args);
+
 struct pwm_device *pwm_get(struct device *dev, const char *consumer);
 void pwm_put(struct pwm_device *pwm);
 
-- 
1.7.0.4


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

* Re: [PATCH v3] pwm: Device tree support for PWM polarity.
  2012-11-21  7:40 [PATCH v3] pwm: Device tree support for PWM polarity Philip, Avinash
@ 2012-11-21 16:32 ` Grant Likely
  2012-11-22 21:29 ` Thierry Reding
  1 sibling, 0 replies; 3+ messages in thread
From: Grant Likely @ 2012-11-21 16:32 UTC (permalink / raw)
  To: Philip, Avinash, thierry.reding, rob.herring, rob
  Cc: linux-kernel, devicetree-discuss, linux-doc, linux-arm-kernel,
	nsekhar, gururaja.hebbar, Philip, Avinash

On Wed, 21 Nov 2012 13:10:44 +0530, "Philip, Avinash" <avinashphilip@ti.com> wrote:
> Add support for encoding PWM properties in bit encoded form with
> of_pwm_xlate_with_flags() function support. Platforms require platform
> specific PWM properties has to populate in 3rd cell of the pwm-specifier
> and PWM driver should also set .of_xlate support with this function.
> Currently PWM property polarity encoded in bit position 0 of the third
> cell in pwm-specifier.
> 
> Signed-off-by: Philip, Avinash <avinashphilip@ti.com>

Looks okay to me.

Acked-by: Grant Likely <grant.likely@secretlab.ca>

> ---
> Changes since v2:
> 	- Move PWM_SPEC_POLARITY to core.c
> 	- Remove dummy function
> 
> Changes since v1:
> 	- of_pwm_xlate_with_flags function support added.
> 	- Documentation update
> 
> :100644 100644 73ec962... 04b0dc4... M	Documentation/devicetree/bindings/pwm/pwm.txt
> :100644 100644 f5acdaa... 780cb6b... M	drivers/pwm/core.c
> :100644 100644 112b314... 6d661f3... M	include/linux/pwm.h
>  Documentation/devicetree/bindings/pwm/pwm.txt |   18 +++++++++++++--
>  drivers/pwm/core.c                            |   28 +++++++++++++++++++++++++
>  include/linux/pwm.h                           |    3 ++
>  3 files changed, 46 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/pwm/pwm.txt b/Documentation/devicetree/bindings/pwm/pwm.txt
> index 73ec962..04b0dc4 100644
> --- a/Documentation/devicetree/bindings/pwm/pwm.txt
> +++ b/Documentation/devicetree/bindings/pwm/pwm.txt
> @@ -37,10 +37,22 @@ device:
>  		pwm-names = "backlight";
>  	};
>  
> +Note that in the example above, specifying the "pwm-names" is redundant
> +because the name "backlight" would be used as fallback anyway.
> +
>  pwm-specifier typically encodes the chip-relative PWM number and the PWM
> -period in nanoseconds. Note that in the example above, specifying the
> -"pwm-names" is redundant because the name "backlight" would be used as
> -fallback anyway.
> +period in nanoseconds.
> +
> +Optionally, the pwm-specifier can encode a number of flags in a third cell:
> +- bit 0: PWM signal polarity (0: normal polarity, 1: inverse polarity)
> +
> +Example with optional PWM specifier for inverse polarity
> +
> +	bl: backlight {
> +		pwms = <&pwm 0 5000000 1>;
> +		pwm-names = "backlight";
> +	};
> +
>  
>  2) PWM controller nodes
>  -----------------------
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index f5acdaa..780cb6b 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -32,6 +32,9 @@
>  
>  #define MAX_PWMS 1024
>  
> +/* flags in the third cell of the DT PWM specifier */
> +#define PWM_SPEC_POLARITY	(1 << 0)
> +
>  static DEFINE_MUTEX(pwm_lookup_lock);
>  static LIST_HEAD(pwm_lookup_list);
>  static DEFINE_MUTEX(pwm_lock);
> @@ -129,6 +132,31 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
>  	return 0;
>  }
>  
> +struct pwm_device *
> +of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
> +{
> +	struct pwm_device *pwm;
> +
> +	if (pc->of_pwm_n_cells < 3)
> +		return ERR_PTR(-EINVAL);
> +
> +	if (args->args[0] >= pc->npwm)
> +		return ERR_PTR(-EINVAL);
> +
> +	pwm = pwm_request_from_chip(pc, args->args[0], NULL);
> +	if (IS_ERR(pwm))
> +		return pwm;
> +
> +	pwm_set_period(pwm, args->args[1]);
> +
> +	if (args->args[2] & PWM_SPEC_POLARITY)
> +		pwm_set_polarity(pwm, PWM_POLARITY_INVERSED);
> +	else
> +		pwm_set_polarity(pwm, PWM_POLARITY_NORMAL);
> +
> +	return pwm;
> +}
> +
>  static struct pwm_device *
>  of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
>  {
> diff --git a/include/linux/pwm.h b/include/linux/pwm.h
> index 112b314..6d661f3 100644
> --- a/include/linux/pwm.h
> +++ b/include/linux/pwm.h
> @@ -171,6 +171,9 @@ struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
>  					 unsigned int index,
>  					 const char *label);
>  
> +struct pwm_device *of_pwm_xlate_with_flags(struct pwm_chip *pc,
> +		const struct of_phandle_args *args);
> +
>  struct pwm_device *pwm_get(struct device *dev, const char *consumer);
>  void pwm_put(struct pwm_device *pwm);
>  
> -- 
> 1.7.0.4
> 

-- 
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.

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

* Re: [PATCH v3] pwm: Device tree support for PWM polarity.
  2012-11-21  7:40 [PATCH v3] pwm: Device tree support for PWM polarity Philip, Avinash
  2012-11-21 16:32 ` Grant Likely
@ 2012-11-22 21:29 ` Thierry Reding
  1 sibling, 0 replies; 3+ messages in thread
From: Thierry Reding @ 2012-11-22 21:29 UTC (permalink / raw)
  To: Philip, Avinash
  Cc: grant.likely, rob.herring, rob, linux-kernel, devicetree-discuss,
	linux-doc, linux-arm-kernel, nsekhar, gururaja.hebbar

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

On Wed, Nov 21, 2012 at 01:10:44PM +0530, Philip, Avinash wrote:
> Add support for encoding PWM properties in bit encoded form with
> of_pwm_xlate_with_flags() function support. Platforms require platform
> specific PWM properties has to populate in 3rd cell of the pwm-specifier
> and PWM driver should also set .of_xlate support with this function.
> Currently PWM property polarity encoded in bit position 0 of the third
> cell in pwm-specifier.
> 
> Signed-off-by: Philip, Avinash <avinashphilip@ti.com>

Applied with two minor stylistic cleanups, thanks.

Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

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

end of thread, other threads:[~2012-11-22 21:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-21  7:40 [PATCH v3] pwm: Device tree support for PWM polarity Philip, Avinash
2012-11-21 16:32 ` Grant Likely
2012-11-22 21:29 ` Thierry Reding

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