From: Jacek Anaszewski <jacek.anaszewski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: "Cédric Le Goater" <clg-Bxea+6Xhats@public.gmane.org>,
linux-leds-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Richard Purdie <rpurdie-Fm38FmjxZ/leoWH0uzbU5w@public.gmane.org>,
Pavel Machek <pavel-+ZI9xUNit7I@public.gmane.org>,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
Linus Walleij
<linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
Joel Stanley <joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org>
Subject: Re: [PATCH v2 1/4] leds: pca955x: add device tree support
Date: Sun, 6 Aug 2017 23:42:27 +0200 [thread overview]
Message-ID: <83142a40-1aba-6f8f-57a2-6542e7e91ecf@gmail.com> (raw)
In-Reply-To: <1501589349-5681-2-git-send-email-clg-Bxea+6Xhats@public.gmane.org>
Hi Cedric,
Thanks for the updated patch set.
Please refer below to my comments.
On 08/01/2017 02:09 PM, Cédric Le Goater wrote:
> It will be used in a following patch to define different operation
> modes for each pin.
>
> Signed-off-by: Cédric Le Goater <clg-Bxea+6Xhats@public.gmane.org>
> ---
> drivers/leds/leds-pca955x.c | 89 ++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 84 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
> index 9a873118ea5f..3afd481a760f 100644
> --- a/drivers/leds/leds-pca955x.c
> +++ b/drivers/leds/leds-pca955x.c
> @@ -41,14 +41,17 @@
> */
>
> #include <linux/acpi.h>
> -#include <linux/module.h>
> -#include <linux/delay.h>
> -#include <linux/string.h>
> #include <linux/ctype.h>
> -#include <linux/leds.h>
> +#include <linux/delay.h>
> #include <linux/err.h>
> +#include <linux/gpio.h>
> #include <linux/i2c.h>
> +#include <linux/leds.h>
> +#include <linux/module.h>
> +#include <linux/of_device.h>
> +#include <linux/of.h>
> #include <linux/slab.h>
> +#include <linux/string.h>
>
> /* LED select registers determine the source that drives LED outputs */
> #define PCA955X_LS_LED_ON 0x0 /* Output LOW */
> @@ -122,6 +125,12 @@ struct pca955x_led {
> struct led_classdev led_cdev;
> int led_num; /* 0 .. 15 potentially */
> char name[32];
> + const char *default_trigger;
> +};
> +
> +struct pca955x_platform_data {
> + struct pca955x_led *leds;
> + int num_leds;
> };
>
> /* 8 bits per input register */
> @@ -250,6 +259,70 @@ static int pca955x_led_set(struct led_classdev *led_cdev,
> return 0;
> }
>
> +#if IS_ENABLED(CONFIG_OF)
> +static struct pca955x_platform_data *
> +pca955x_pdata_of_init(struct i2c_client *client, struct pca955x_chipdef *chip)
> +{
> + struct device_node *np = client->dev.of_node;
> + struct device_node *child;
> + struct pca955x_platform_data *pdata;
> + int count;
> +
> + count = of_get_child_count(np);
> + if (!count || count > chip->bits)
> + return ERR_PTR(-ENODEV);
> +
> + pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
> + if (!pdata)
> + return ERR_PTR(-ENOMEM);
> +
> + pdata->leds = devm_kzalloc(&client->dev,
> + sizeof(struct pca955x_led) * chip->bits,
> + GFP_KERNEL);
> + if (!pdata->leds)
> + return ERR_PTR(-ENOMEM);
> +
> + for_each_child_of_node(np, child) {
> + const char *name;
> + u32 reg;
> + int res;
> +
> + res = of_property_read_u32(child, "reg", ®);
> + if ((res != 0) || (reg >= chip->bits))
> + continue;
> +
> + if (of_property_read_string(child, "label", &name))
> + name = child->name;
> +
> + snprintf(pdata->leds[reg].name, sizeof(pdata->leds[reg].name),
> + "%s", name);
> +
> + of_property_read_string(child, "linux,default-trigger",
> + &pdata->leds[reg].default_trigger);
> + }
> +
> + pdata->num_leds = chip->bits;
> +
> + return pdata;
> +}
> +
> +static const struct of_device_id of_pca955x_match[] = {
> + { .compatible = "nxp,pca9550", .data = (void *)pca9550 },
> + { .compatible = "nxp,pca9551", .data = (void *)pca9551 },
> + { .compatible = "nxp,pca9552", .data = (void *)pca9552 },
> + { .compatible = "nxp,pca9553", .data = (void *)pca9553 },
> + {},
> +};
> +
> +MODULE_DEVICE_TABLE(of, of_pca955x_match);
> +#else
> +static struct pca955x_platform_data *
> +pca955x_pdata_of_init(struct i2c_client *client, struct pca955x_chipdef *chip)
> +{
> + return ERR_PTR(-ENODEV);
> +}
> +#endif
> +
> static int pca955x_probe(struct i2c_client *client,
> const struct i2c_device_id *id)
> {
> @@ -257,8 +330,8 @@ static int pca955x_probe(struct i2c_client *client,
> struct pca955x_led *pca955x_led;
> struct pca955x_chipdef *chip;
> struct i2c_adapter *adapter;
> - struct led_platform_data *pdata;
> int i, err;
> + struct pca955x_platform_data *pdata;
>
> if (id) {
> chip = &pca955x_chipdefs[id->driver_data];
> @@ -272,6 +345,11 @@ static int pca955x_probe(struct i2c_client *client,
> }
> adapter = to_i2c_adapter(client->dev.parent);
> pdata = dev_get_platdata(&client->dev);
> + if (!pdata) {
> + pdata = pca955x_pdata_of_init(client, chip);
> + if (IS_ERR(pdata))
> + return PTR_ERR(pdata);
> + }
Since from this moment pdata should be in every case available you
could get rid of "if (pdata) check" right after
"if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))".
> /* Make sure the slave address / chip type combo given is possible */
> if ((client->addr & ~((1 << chip->slv_addr_shift) - 1)) !=
> @@ -378,6 +456,7 @@ static struct i2c_driver pca955x_driver = {
> .driver = {
> .name = "leds-pca955x",
> .acpi_match_table = ACPI_PTR(pca955x_acpi_ids),
> + .of_match_table = of_match_ptr(of_pca955x_match),
> },
> .probe = pca955x_probe,
> .remove = pca955x_remove,
>
--
Best regards,
Jacek Anaszewski
--
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
next prev parent reply other threads:[~2017-08-06 21:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-01 12:09 [PATCH v2 0/4] leds: pca955x: add GPIO support Cédric Le Goater
2017-08-01 12:09 ` [PATCH v2 1/4] leds: pca955x: add device tree support Cédric Le Goater
[not found] ` <1501589349-5681-2-git-send-email-clg-Bxea+6Xhats@public.gmane.org>
2017-08-06 21:42 ` Jacek Anaszewski [this message]
2017-08-07 9:03 ` Cédric Le Goater
[not found] ` <1501589349-5681-1-git-send-email-clg-Bxea+6Xhats@public.gmane.org>
2017-08-01 12:09 ` [PATCH v2 2/4] leds: pca955x: use devm_led_classdev_register Cédric Le Goater
2017-08-01 12:09 ` [PATCH v2 3/4] leds: pca955x: add GPIO support Cédric Le Goater
2017-08-06 21:42 ` Jacek Anaszewski
2017-08-07 9:09 ` Cédric Le Goater
2017-08-07 16:45 ` Jacek Anaszewski
2017-08-01 12:09 ` [PATCH v2 4/4] dt-bindings leds: add pca955x Cédric Le Goater
2017-08-02 11:33 ` [PATCH v2 0/4] leds: pca955x: add GPIO support Pavel Machek
2017-08-02 11:57 ` Cédric Le Goater
2017-08-02 12:48 ` Pavel Machek
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=83142a40-1aba-6f8f-57a2-6542e7e91ecf@gmail.com \
--to=jacek.anaszewski-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=clg-Bxea+6Xhats@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org \
--cc=linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-leds-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=pavel-+ZI9xUNit7I@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=rpurdie-Fm38FmjxZ/leoWH0uzbU5w@public.gmane.org \
/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 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).