From: Dan Murphy <dmurphy@ti.com>
To: Oleh Kravchenko <oleg@kaa.org.ua>, <devicetree@vger.kernel.org>,
<linux-leds@vger.kernel.org>, <jacek.anaszewski@gmail.com>,
<pavel@ucw.cz>
Subject: Re: [PATCH v7 2/2] leds: add LED driver for EL15203000 board
Date: Wed, 11 Sep 2019 14:49:52 -0500 [thread overview]
Message-ID: <7a6fbf7c-56d4-e8af-c2f2-0a22f987f724@ti.com> (raw)
In-Reply-To: <20190909071632.14392-3-oleg@kaa.org.ua>
Oleh
On 9/9/19 2:16 AM, Oleh Kravchenko wrote:
> This patch adds a LED class driver for the LEDs found on
> the Crane Merchandising System EL15203000 LEDs board
> (aka RED LEDs board).
> Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
> ---
> .../testing/sysfs-class-led-driver-el15203000 | 32 ++
> drivers/leds/Kconfig | 13 +
> drivers/leds/Makefile | 1 +
> drivers/leds/leds-el15203000.c | 356 ++++++++++++++++++
> 4 files changed, 402 insertions(+)
> create mode 100644 Documentation/ABI/testing/sysfs-class-led-driver-el15203000
> create mode 100644 drivers/leds/leds-el15203000.c
[...]
> +
> +static int el15203000_pattern_set_P(struct led_classdev *ldev,
> + struct led_pattern *pattern,
> + u32 len, int repeat)
> +{
> + struct el15203000_led *led = container_of(ldev,
> + struct el15203000_led,
> + ldev);
> +
> + if (repeat > 0)
> + return -EINVAL;
> +
> + if (is_cascade(pattern, len, false, false)) {
> + dev_dbg(led->priv->dev, "Cascade mode for 0x%02x(%c)",
> + led->reg, led->reg);
> +
> + return el15203000_cmd(led, EL_PIPE_CASCADE);
> + } else if (is_cascade(pattern, len, true, false)) {
> + dev_dbg(led->priv->dev, "Inverse cascade mode for 0x%02x(%c)",
> + led->reg, led->reg);
> +
> + return el15203000_cmd(led, EL_PIPE_INV_CASCADE);
> + } else if (is_bounce(pattern, len, false)) {
> + dev_dbg(led->priv->dev, "Bounce mode for 0x%02x(%c)",
> + led->reg, led->reg);
> +
> + return el15203000_cmd(led, EL_PIPE_BOUNCE);
> + } else if (is_bounce(pattern, len, true)) {
> + dev_dbg(led->priv->dev, "Inverse bounce mode for 0x%02x(%c)",
> + led->reg, led->reg);
> +
> + return el15203000_cmd(led, EL_PIPE_INV_BOUNCE);
> + }
> +
nitpicking a bit not a blocker just some clean up
maybe remove the dev_dbg statements and just set a local variable to the
pipe cmd
if (is_cascade(pattern, len, false, false))
pipe_cmd = EL_PIPE_CASCADE;
else if (is_cascade(pattern, len, true, false))
pipe_cmd = EL_PIPE_INV_CASCADE;
else
return -EINVAL;
return el15203000_cmd(led, pipe_cmd0:
> + return -EINVAL;
> +}
> +
> +static int el15203000_pattern_clear(struct led_classdev *ldev)
> +{
> + struct el15203000_led *led = container_of(ldev,
> + struct el15203000_led,
> + ldev);
> +
> + return el15203000_cmd(led, EL_OFF);
> +}
> +
> +static int el15203000_probe_dt(struct el15203000 *priv)
> +{
> + struct el15203000_led *led = priv->leds;
> + struct fwnode_handle *child;
> + int ret;
> +
> + device_for_each_child_node(priv->dev, child) {
> + struct led_init_data init_data = {};
> +
> + ret = fwnode_property_read_u32(child, "reg", &led->reg);
> + if (ret) {
> + dev_err(priv->dev, "LED without ID number");
> + fwnode_handle_put(child);
> +
> + return ret;
> + }
> +
> + if (led->reg > U8_MAX) {
> + dev_err(priv->dev, "LED value %d is invalid", led->reg);
> + fwnode_handle_put(child);
> +
> + return -EINVAL;
> + }
> +
> + fwnode_property_read_string(child, "linux,default-trigger",
> + &led->ldev.default_trigger);
> +
> + led->priv = priv;
> + led->ldev.max_brightness = LED_ON;
> + led->ldev.brightness_set_blocking = el15203000_set_blocking;
> +
> + if (led->reg == 'S') {
> + led->ldev.pattern_set = el15203000_pattern_set_S;
> + led->ldev.pattern_clear = el15203000_pattern_clear;
> + } else if (led->reg == 'P') {
> + led->ldev.pattern_set = el15203000_pattern_set_P;
> + led->ldev.pattern_clear = el15203000_pattern_clear;
> + }
> +
> + init_data.fwnode = child;
> + ret = devm_led_classdev_register_ext(priv->dev, &led->ldev,
> + &init_data);
> + if (ret) {
> + dev_err(priv->dev,
> + "failed to register LED device %s, err %d",
> + led->ldev.name, ret);
> + fwnode_handle_put(child);
> +
> + return ret;
> + }
> +
> + led++;
> + }
> +
> + return ret;
> +}
> +
> +static int el15203000_probe(struct spi_device *spi)
> +{
> + struct el15203000 *priv;
> + size_t count;
> + int ret;
> +
> + count = device_get_child_node_count(&spi->dev);
> + if (!count) {
> + dev_err(&spi->dev, "LEDs are not defined in device tree!");
> + return -ENODEV;
> + }
> +
> + priv = devm_kzalloc(&spi->dev, struct_size(priv, leds, count),
> + GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + mutex_init(&priv->lock);
> + priv->count = count;
> + priv->dev = &spi->dev;
> + priv->spi = spi;
> + priv->delay = jiffies -
> + usecs_to_jiffies(EL_FW_DELAY_USEC);
> +
> + ret = el15203000_probe_dt(priv);
> + if (ret)
> + return ret;
> +
> + spi_set_drvdata(spi, priv);
> +
> + return 0;
Another nitpick again just some clean up.
Set spi_set_drvdata before you call the probe_dt then return on
el15203000_probe_dt this will allow you to eliminate the local ret variable.
so it would look like this:
spi_set_drvdata(spi, priv);
return el15203000_probe_dt(priv);
Otherwise
Reviewed-by: Dan Murphy <dmurphy@ti.com>
<snip>
prev parent reply other threads:[~2019-09-11 19:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-09 7:16 v7 EL15203000 Oleh Kravchenko
2019-09-09 7:16 ` [PATCH v7 1/2] dt-bindings: Add docs for EL15203000 Oleh Kravchenko
2019-09-11 19:48 ` Dan Murphy
2019-09-11 21:09 ` Jacek Anaszewski
2019-09-09 7:16 ` [PATCH v7 2/2] leds: add LED driver for EL15203000 board Oleh Kravchenko
2019-09-11 19:49 ` Dan Murphy [this message]
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=7a6fbf7c-56d4-e8af-c2f2-0a22f987f724@ti.com \
--to=dmurphy@ti.com \
--cc=devicetree@vger.kernel.org \
--cc=jacek.anaszewski@gmail.com \
--cc=linux-leds@vger.kernel.org \
--cc=oleg@kaa.org.ua \
--cc=pavel@ucw.cz \
/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).