aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip, Avinash <avinashphilip@ti.com>2012-11-21 02:40:44 -0500
committerThierry Reding <thierry.reding@avionic-design.de>2012-11-22 16:47:12 -0500
commit83af24027b3df1af5c5a9aa9adcdcfeb3429d3be (patch)
tree3e104ed41554bb7e97378cc7cc3866c842306dff
parent422470a8265fbb1d182c00ab2421f4b416ab2dba (diff)
pwm: Device tree support for PWM polarity
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> Acked-by: Grant Likely <grant.likely@secretlab.ca> Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
-rw-r--r--Documentation/devicetree/bindings/pwm/pwm.txt17
-rw-r--r--drivers/pwm/core.c28
-rw-r--r--include/linux/pwm.h3
3 files changed, 45 insertions, 3 deletions
diff --git a/Documentation/devicetree/bindings/pwm/pwm.txt b/Documentation/devicetree/bindings/pwm/pwm.txt
index 73ec962bfe8c..06e67247859a 100644
--- a/Documentation/devicetree/bindings/pwm/pwm.txt
+++ b/Documentation/devicetree/bindings/pwm/pwm.txt
@@ -37,10 +37,21 @@ device:
37 pwm-names = "backlight"; 37 pwm-names = "backlight";
38 }; 38 };
39 39
40Note that in the example above, specifying the "pwm-names" is redundant
41because the name "backlight" would be used as fallback anyway.
42
40pwm-specifier typically encodes the chip-relative PWM number and the PWM 43pwm-specifier typically encodes the chip-relative PWM number and the PWM
41period in nanoseconds. Note that in the example above, specifying the 44period in nanoseconds.
42"pwm-names" is redundant because the name "backlight" would be used as 45
43fallback anyway. 46Optionally, the pwm-specifier can encode a number of flags in a third cell:
47- bit 0: PWM signal polarity (0: normal polarity, 1: inverse polarity)
48
49Example with optional PWM specifier for inverse polarity
50
51 bl: backlight {
52 pwms = <&pwm 0 5000000 1>;
53 pwm-names = "backlight";
54 };
44 55
452) PWM controller nodes 562) PWM controller nodes
46----------------------- 57-----------------------
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index f5acdaa52707..780cb6b8a8f0 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -32,6 +32,9 @@
32 32
33#define MAX_PWMS 1024 33#define MAX_PWMS 1024
34 34
35/* flags in the third cell of the DT PWM specifier */
36#define PWM_SPEC_POLARITY (1 << 0)
37
35static DEFINE_MUTEX(pwm_lookup_lock); 38static DEFINE_MUTEX(pwm_lookup_lock);
36static LIST_HEAD(pwm_lookup_list); 39static LIST_HEAD(pwm_lookup_list);
37static DEFINE_MUTEX(pwm_lock); 40static DEFINE_MUTEX(pwm_lock);
@@ -129,6 +132,31 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
129 return 0; 132 return 0;
130} 133}
131 134
135struct pwm_device *
136of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
137{
138 struct pwm_device *pwm;
139
140 if (pc->of_pwm_n_cells < 3)
141 return ERR_PTR(-EINVAL);
142
143 if (args->args[0] >= pc->npwm)
144 return ERR_PTR(-EINVAL);
145
146 pwm = pwm_request_from_chip(pc, args->args[0], NULL);
147 if (IS_ERR(pwm))
148 return pwm;
149
150 pwm_set_period(pwm, args->args[1]);
151
152 if (args->args[2] & PWM_SPEC_POLARITY)
153 pwm_set_polarity(pwm, PWM_POLARITY_INVERSED);
154 else
155 pwm_set_polarity(pwm, PWM_POLARITY_NORMAL);
156
157 return pwm;
158}
159
132static struct pwm_device * 160static struct pwm_device *
133of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args) 161of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
134{ 162{
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 112b31436848..6d661f32e0e4 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,
171 unsigned int index, 171 unsigned int index,
172 const char *label); 172 const char *label);
173 173
174struct pwm_device *of_pwm_xlate_with_flags(struct pwm_chip *pc,
175 const struct of_phandle_args *args);
176
174struct pwm_device *pwm_get(struct device *dev, const char *consumer); 177struct pwm_device *pwm_get(struct device *dev, const char *consumer);
175void pwm_put(struct pwm_device *pwm); 178void pwm_put(struct pwm_device *pwm);
176 179