* [PATCH] leds: Add DT support for leds-pca9532
@ 2012-06-16 14:10 Roland Stigge
2012-06-16 15:06 ` Stephen Warren
0 siblings, 1 reply; 8+ messages in thread
From: Roland Stigge @ 2012-06-16 14:10 UTC (permalink / raw)
To: riku.voipio-X3B1VOXEql0, bryan.wu-Z7WLFzj8eWMS+FvcfC7Uqw,
rpurdie-Fm38FmjxZ/leoWH0uzbU5w, linux-leds-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
aletes.xgr-Re5JQEeQqe8AvxtiuMwx3w,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: Roland Stigge
This patch adds DT support for leds-pca9532.
Signed-off-by: Roland Stigge <stigge-uj/7R2tJ6VmzQB+pC5nmwQ@public.gmane.org>
---
Documentation/devicetree/bindings/leds/leds-pca9532.txt | 43 ++++++++++++++
drivers/leds/leds-pca9532.c | 47 ++++++++++++++++
2 files changed, 90 insertions(+)
--- /dev/null
+++ linux-2.6/Documentation/devicetree/bindings/leds/leds-pca9532.txt
@@ -0,0 +1,43 @@
+NXP PCA9532 LED (incl. GPIO) controller
+
+Required properties:
+- compatible: must be "nxp,pca9532"
+- reg: I2C address
+- gpio-controller: Marks the device node as a GPIO controller.
+- #gpio-cells: Should be 2:
+ 1) pin number
+ 2) optional parameters:
+ - bit 0 specifies polarity (0 for normal, 1 for inverted)
+- nxp,typecodes: groups of 2 bits for each of the 16 pins:
+ 0: None
+ 1: LED
+ 2: Beep
+ 3: GPIO
+- nxp,statecodes: groups of 2 bits for each of the 16 pins:
+ 0: off
+ 1: on
+ 2: pwm0
+ 3: pwm1
+
+Optional properties:
+- nxp,psc: array of 2 numbers: PSC values for the two PWM channels (see datasheet)
+- nxp,pwm: array of 2 numbers: PWM values for the two PWM channels (see datasheet)
+
+Example:
+
+ pca9532: pca9532@60 {
+ compatible = "nxp,pca9532";
+ gpio-controller;
+ #gpio-cells = <2>;
+ nxp,typecodes = <0xffffffff>;
+ nxp,statecodes = <0x00000000>;
+ reg = <0x60>;
+ };
+
+ sd@20098000 {
+ wp-gpios = <&pca9532 5 0>;
+ cd-gpios = <&pca9532 4 0>;
+ cd-inverted;
+ bus-width = <4>;
+ status = "okay";
+ };
--- linux-2.6.orig/drivers/leds/leds-pca9532.c
+++ linux-2.6/drivers/leds/leds-pca9532.c
@@ -21,6 +21,7 @@
#include <linux/workqueue.h>
#include <linux/leds-pca9532.h>
#include <linux/gpio.h>
+#include <linux/of.h>
/* m = num_leds*/
#define PCA9532_REG_INPUT(i) ((i) >> 3)
@@ -444,6 +445,47 @@ exit:
return err;
}
+#ifdef CONFIG_OF
+static struct pca9532_platform_data *pca9532_parse_dt(struct device *dev)
+{
+ struct device_node *np = dev->of_node;
+ struct pca9532_platform_data *pca9532_pdata;
+ u32 typecodes, statecodes;
+ u32 pwm[2];
+ u32 psc[2];
+ int i;
+
+ pca9532_pdata = devm_kzalloc(dev, sizeof(*pca9532_pdata), GFP_KERNEL);
+ if (!pca9532_pdata) {
+ dev_err(dev, "could not allocate memory for platform data\n");
+ return NULL;
+ }
+
+ if (!of_property_read_u32(np, "nxp,typecodes", &typecodes)) {
+ for (i = 0; i < 16; i++)
+ pca9532_pdata->leds[i].type =
+ (typecodes >> (2 * i)) & 0x3;
+ }
+ if (!of_property_read_u32(np, "nxp,statecodes", &statecodes)) {
+ for (i = 0; i < 16; i++)
+ pca9532_pdata->leds[i].state =
+ (statecodes >> (2 * i)) & 0x3;
+ }
+ if (!of_property_read_u32_array(np, "nxp,pwm", &pwm[0], 2)) {
+ for (i = 0; i < 2; i++)
+ pca9532_pdata->pwm[i] = pwm[i];
+ }
+ if (!of_property_read_u32_array(np, "nxp,psc", &psc[0], 2)) {
+ for (i = 0; i < 2; i++)
+ pca9532_pdata->psc[i] = psc[i];
+ }
+
+ pca9532_pdata->gpio_base = -1; /* dynamically assign gpio base */
+
+ return pca9532_pdata;
+}
+#endif
+
static int pca9532_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -451,6 +493,11 @@ static int pca9532_probe(struct i2c_clie
struct pca9532_platform_data *pca9532_pdata = client->dev.platform_data;
int err;
+#ifdef CONFIG_OF
+ if (!pca9532_pdata && client->dev.of_node)
+ pca9532_pdata = pca9532_parse_dt(&client->dev);
+#endif
+
if (!pca9532_pdata)
return -EIO;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] leds: Add DT support for leds-pca9532
2012-06-16 14:10 [PATCH] leds: Add DT support for leds-pca9532 Roland Stigge
@ 2012-06-16 15:06 ` Stephen Warren
2012-06-17 11:51 ` Roland Stigge
0 siblings, 1 reply; 8+ messages in thread
From: Stephen Warren @ 2012-06-16 15:06 UTC (permalink / raw)
To: Roland Stigge
Cc: riku.voipio, bryan.wu, rpurdie, linux-leds, linux-kernel,
devicetree-discuss, aletes.xgr, linux-arm-kernel
On 06/16/2012 08:10 AM, Roland Stigge wrote:
> This patch adds DT support for leds-pca9532.
> +++ linux-2.6/Documentation/devicetree/bindings/leds/leds-pca9532.txt
> +- nxp,typecodes: groups of 2 bits for each of the 16 pins:
> + 0: None
> + 1: LED
> + 2: Beep
> + 3: GPIO
> +- nxp,statecodes: groups of 2 bits for each of the 16 pins:
> + 0: off
> + 1: on
> + 2: pwm0
> + 3: pwm1
> +
> +Optional properties:
> +- nxp,psc: array of 2 numbers: PSC values for the two PWM channels (see datasheet)
> +- nxp,pwm: array of 2 numbers: PWM values for the two PWM channels (see datasheet)
Shouldn't that all be exposed using a combination of the pinctrl
bindings that are in 3.5, and the PWM bindings that should be coming in 3.6?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] leds: Add DT support for leds-pca9532
2012-06-16 15:06 ` Stephen Warren
@ 2012-06-17 11:51 ` Roland Stigge
2012-06-17 18:02 ` Stephen Warren
0 siblings, 1 reply; 8+ messages in thread
From: Roland Stigge @ 2012-06-17 11:51 UTC (permalink / raw)
To: Stephen Warren
Cc: riku.voipio, bryan.wu, rpurdie, linux-leds, linux-kernel,
devicetree-discuss, aletes.xgr, linux-arm-kernel
Hi,
On 16/06/12 17:06, Stephen Warren wrote:
>> +- nxp,typecodes: groups of 2 bits for each of the 16 pins:
>> + 0: None
>> + 1: LED
>> + 2: Beep
>> + 3: GPIO
>> +- nxp,statecodes: groups of 2 bits for each of the 16 pins:
>> + 0: off
>> + 1: on
>> + 2: pwm0
>> + 3: pwm1
>> +
>> +Optional properties:
>> +- nxp,psc: array of 2 numbers: PSC values for the two PWM channels (see datasheet)
>> +- nxp,pwm: array of 2 numbers: PWM values for the two PWM channels (see datasheet)
>
> Shouldn't that all be exposed using a combination of the pinctrl
> bindings that are in 3.5, and the PWM bindings that should be coming in 3.6?
Thanks for the note! I found a pwm tree that should have this at
http://gitorious.org/linux-pwm/linux-pwm
but it gives me server errors. Is there a place where I can have a look?
Thanks in advance,
Roland
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] leds: Add DT support for leds-pca9532
2012-06-17 11:51 ` Roland Stigge
@ 2012-06-17 18:02 ` Stephen Warren
2012-06-19 6:16 ` Thierry Reding
0 siblings, 1 reply; 8+ messages in thread
From: Stephen Warren @ 2012-06-17 18:02 UTC (permalink / raw)
To: Roland Stigge
Cc: riku.voipio, bryan.wu, rpurdie, linux-leds, linux-kernel,
devicetree-discuss, aletes.xgr, linux-arm-kernel, Thierry Reding
On 06/17/2012 05:51 AM, Roland Stigge wrote:
> Hi,
>
> On 16/06/12 17:06, Stephen Warren wrote:
>>> +- nxp,typecodes: groups of 2 bits for each of the 16 pins:
>>> + 0: None
>>> + 1: LED
>>> + 2: Beep
>>> + 3: GPIO
>>> +- nxp,statecodes: groups of 2 bits for each of the 16 pins:
>>> + 0: off
>>> + 1: on
>>> + 2: pwm0
>>> + 3: pwm1
>>> +
>>> +Optional properties:
>>> +- nxp,psc: array of 2 numbers: PSC values for the two PWM channels (see datasheet)
>>> +- nxp,pwm: array of 2 numbers: PWM values for the two PWM channels (see datasheet)
>>
>> Shouldn't that all be exposed using a combination of the pinctrl
>> bindings that are in 3.5, and the PWM bindings that should be coming in 3.6?
>
> Thanks for the note! I found a pwm tree that should have this at
>
> http://gitorious.org/linux-pwm/linux-pwm
>
> but it gives me server errors. Is there a place where I can have a look?
That URL (with http:// replace with git://) did work for me. It seemed a
little slow at first, but did work without issue. I Cc'd Thierry in case
there's any other location available.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] leds: Add DT support for leds-pca9532
2012-06-17 18:02 ` Stephen Warren
@ 2012-06-19 6:16 ` Thierry Reding
0 siblings, 0 replies; 8+ messages in thread
From: Thierry Reding @ 2012-06-19 6:16 UTC (permalink / raw)
To: Stephen Warren
Cc: Roland Stigge, riku.voipio, bryan.wu, rpurdie, linux-leds,
linux-kernel, devicetree-discuss, aletes.xgr, linux-arm-kernel
[-- Attachment #1: Type: text/plain, Size: 1610 bytes --]
On Sun, Jun 17, 2012 at 12:02:55PM -0600, Stephen Warren wrote:
> On 06/17/2012 05:51 AM, Roland Stigge wrote:
> > Hi,
> >
> > On 16/06/12 17:06, Stephen Warren wrote:
> >>> +- nxp,typecodes: groups of 2 bits for each of the 16 pins:
> >>> + 0: None
> >>> + 1: LED
> >>> + 2: Beep
> >>> + 3: GPIO
> >>> +- nxp,statecodes: groups of 2 bits for each of the 16 pins:
> >>> + 0: off
> >>> + 1: on
> >>> + 2: pwm0
> >>> + 3: pwm1
> >>> +
> >>> +Optional properties:
> >>> +- nxp,psc: array of 2 numbers: PSC values for the two PWM channels (see datasheet)
> >>> +- nxp,pwm: array of 2 numbers: PWM values for the two PWM channels (see datasheet)
> >>
> >> Shouldn't that all be exposed using a combination of the pinctrl
> >> bindings that are in 3.5, and the PWM bindings that should be coming in 3.6?
> >
> > Thanks for the note! I found a pwm tree that should have this at
> >
> > http://gitorious.org/linux-pwm/linux-pwm
> >
> > but it gives me server errors. Is there a place where I can have a look?
>
> That URL (with http:// replace with git://) did work for me. It seemed a
> little slow at first, but did work without issue. I Cc'd Thierry in case
> there's any other location available.
There isn't. IIRC, back when I finalized the PWM subsystem during the last
cycle, Arnd Bergmann suggested that I request an account and repository on
kernel.org back when the subsystem was ready. At the time I didn't think
it necessary, but reading this, perhaps it wouldn't be such a bad idea.
kernel.org should have better availability than gitorious.
Thierry
[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] leds: Add DT support for leds-pca9532
@ 2014-09-09 13:28 Roland Stigge
[not found] ` <1410269280-8761-1-git-send-email-stigge-uj/7R2tJ6VmzQB+pC5nmwQ@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Roland Stigge @ 2014-09-09 13:28 UTC (permalink / raw)
To: robh+dt, riku.voipio, cooloney, rpurdie, devicetree, linux-kernel,
linux-leds
Cc: Roland Stigge
This patch adds DT support for leds-pca9532.
Signed-off-by: Roland Stigge <stigge@antcom.de>
---
Applies to v3.17-rc4
Documentation/devicetree/bindings/leds/leds-pca9532.txt | 43 ++++++++++++++
drivers/leds/leds-pca9532.c | 47 ++++++++++++++++
2 files changed, 90 insertions(+)
--- /dev/null
+++ linux-2.6/Documentation/devicetree/bindings/leds/leds-pca9532.txt
@@ -0,0 +1,43 @@
+NXP PCA9532 LED (incl. GPIO) controller
+
+Required properties:
+- compatible: must be "nxp,pca9532"
+- reg: I2C address
+- gpio-controller: Marks the device node as a GPIO controller.
+- #gpio-cells: Should be 2:
+ 1) pin number
+ 2) optional parameters:
+ - bit 0 specifies polarity (0 for normal, 1 for inverted)
+- nxp,typecodes: groups of 2 bits for each of the 16 pins:
+ 0: None
+ 1: LED
+ 2: Beep
+ 3: GPIO
+- nxp,statecodes: groups of 2 bits for each of the 16 pins:
+ 0: off
+ 1: on
+ 2: pwm0
+ 3: pwm1
+
+Optional properties:
+- nxp,psc: array of 2 numbers: PSC values for the two PWM channels (see datasheet)
+- nxp,pwm: array of 2 numbers: PWM values for the two PWM channels (see datasheet)
+
+Example:
+
+ pca9532: pca9532@60 {
+ compatible = "nxp,pca9532";
+ gpio-controller;
+ #gpio-cells = <2>;
+ nxp,typecodes = <0xffffffff>;
+ nxp,statecodes = <0x00000000>;
+ reg = <0x60>;
+ };
+
+ sd@20098000 {
+ wp-gpios = <&pca9532 5 0>;
+ cd-gpios = <&pca9532 4 0>;
+ cd-inverted;
+ bus-width = <4>;
+ status = "okay";
+ };
--- linux-2.6.orig/drivers/leds/leds-pca9532.c
+++ linux-2.6/drivers/leds/leds-pca9532.c
@@ -21,6 +21,7 @@
#include <linux/workqueue.h>
#include <linux/leds-pca9532.h>
#include <linux/gpio.h>
+#include <linux/of.h>
/* m = num_leds*/
#define PCA9532_REG_INPUT(i) ((i) >> 3)
@@ -442,6 +443,45 @@ exit:
return err;
}
+#ifdef CONFIG_OF
+static struct pca9532_platform_data *pca9532_parse_dt(struct device *dev)
+{
+ struct device_node *np = dev->of_node;
+ struct pca9532_platform_data *pca9532_pdata;
+ u32 typecodes, statecodes;
+ u32 pwm[2];
+ u32 psc[2];
+ int i;
+
+ pca9532_pdata = devm_kzalloc(dev, sizeof(*pca9532_pdata), GFP_KERNEL);
+ if (!pca9532_pdata)
+ return NULL;
+
+ if (!of_property_read_u32(np, "nxp,typecodes", &typecodes)) {
+ for (i = 0; i < 16; i++)
+ pca9532_pdata->leds[i].type =
+ (typecodes >> (2 * i)) & 0x3;
+ }
+ if (!of_property_read_u32(np, "nxp,statecodes", &statecodes)) {
+ for (i = 0; i < 16; i++)
+ pca9532_pdata->leds[i].state =
+ (statecodes >> (2 * i)) & 0x3;
+ }
+ if (!of_property_read_u32_array(np, "nxp,pwm", &pwm[0], 2)) {
+ for (i = 0; i < 2; i++)
+ pca9532_pdata->pwm[i] = pwm[i];
+ }
+ if (!of_property_read_u32_array(np, "nxp,psc", &psc[0], 2)) {
+ for (i = 0; i < 2; i++)
+ pca9532_pdata->psc[i] = psc[i];
+ }
+
+ pca9532_pdata->gpio_base = -1; /* dynamically assign gpio base */
+
+ return pca9532_pdata;
+}
+#endif
+
static int pca9532_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -449,6 +489,11 @@ static int pca9532_probe(struct i2c_clie
struct pca9532_platform_data *pca9532_pdata =
dev_get_platdata(&client->dev);
+#ifdef CONFIG_OF
+ if (!pca9532_pdata && client->dev.of_node)
+ pca9532_pdata = pca9532_parse_dt(&client->dev);
+#endif
+
if (!pca9532_pdata)
return -EIO;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] leds: Add DT support for leds-pca9532
[not found] ` <1410269280-8761-1-git-send-email-stigge-uj/7R2tJ6VmzQB+pC5nmwQ@public.gmane.org>
@ 2014-09-09 18:08 ` Arnd Bergmann
2014-09-10 15:22 ` Roland Stigge
0 siblings, 1 reply; 8+ messages in thread
From: Arnd Bergmann @ 2014-09-09 18:08 UTC (permalink / raw)
To: Roland Stigge
Cc: robh+dt-DgEjT+Ai2ygdnm+yROfE0A, riku.voipio-X3B1VOXEql0,
cooloney-Re5JQEeQqe8AvxtiuMwx3w, rpurdie-Fm38FmjxZ/leoWH0uzbU5w,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-leds-u79uwXL29TY76Z2rM5mHXA
On Tuesday 09 September 2014 15:28:00 Roland Stigge wrote:
> +#ifdef CONFIG_OF
> +static struct pca9532_platform_data *pca9532_parse_dt(struct device *dev)
> +{
...
> +
> static int pca9532_probe(struct i2c_client *client,
> const struct i2c_device_id *id)
> {
> @@ -449,6 +489,11 @@ static int pca9532_probe(struct i2c_clie
> struct pca9532_platform_data *pca9532_pdata =
> dev_get_platdata(&client->dev);
>
> +#ifdef CONFIG_OF
> + if (!pca9532_pdata && client->dev.of_node)
> + pca9532_pdata = pca9532_parse_dt(&client->dev);
> +#endif
> +
It would be better to remove the two #ifdef statements and instead
do this in C language as
if (IS_ENABLED(CONFIG_OF) && !pca9532_pdata && client->dev.of_node)
pca9532_pdata = pca9532_parse_dt(&client->dev);
This gives you extra compile-time coverage when CONFIG_OF is not
enabled.
I would probably also remove the !pca9532_pdata check there, since
we rarely do auxdata for new devices these days, but that is a separate
matter, and the check does not hurt.
> + if (!of_property_read_u32_array(np, "nxp,pwm", &pwm[0], 2)) {
> + for (i = 0; i < 2; i++)
> + pca9532_pdata->pwm[i] = pwm[i];
> + }
Is this a full PWM controller? If it is, it would be better to also
provide a #pwm-cells property and register the device with the PWM
subsystem to allow arbitrary users.
If the PWM is only really usable for LED, it's probably enough to
leave this used by the LED subsystem.
Arnd
--
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] 8+ messages in thread
* Re: [PATCH] leds: Add DT support for leds-pca9532
2014-09-09 18:08 ` Arnd Bergmann
@ 2014-09-10 15:22 ` Roland Stigge
0 siblings, 0 replies; 8+ messages in thread
From: Roland Stigge @ 2014-09-10 15:22 UTC (permalink / raw)
To: Arnd Bergmann
Cc: robh+dt, riku.voipio, cooloney, rpurdie, devicetree, linux-kernel,
linux-leds
On 09/09/2014 08:08 PM, Arnd Bergmann wrote:
> Is this a full PWM controller? If it is, it would be better to also
> provide a #pwm-cells property and register the device with the PWM
> subsystem to allow arbitrary users.
>
> If the PWM is only really usable for LED, it's probably enough to
> leave this used by the LED subsystem.
Right, this PWM is really only intended for LED use (as already done w/o
DT).
Sending the updated patch.
Roland
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-09-10 15:22 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-16 14:10 [PATCH] leds: Add DT support for leds-pca9532 Roland Stigge
2012-06-16 15:06 ` Stephen Warren
2012-06-17 11:51 ` Roland Stigge
2012-06-17 18:02 ` Stephen Warren
2012-06-19 6:16 ` Thierry Reding
-- strict thread matches above, loose matches on Subject: below --
2014-09-09 13:28 Roland Stigge
[not found] ` <1410269280-8761-1-git-send-email-stigge-uj/7R2tJ6VmzQB+pC5nmwQ@public.gmane.org>
2014-09-09 18:08 ` Arnd Bergmann
2014-09-10 15:22 ` Roland Stigge
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).