linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>,
	Pavel Machek <pavel@ucw.cz>, Dan Murphy <dmurphy@ti.com>,
	Linux LED Subsystem <linux-leds@vger.kernel.org>,
	Sakari Ailus <sakari.ailus@iki.fi>,
	newbytee@protonmail.com, Stephan Gerhold <stephan@gerhold.net>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	phone-devel@vger.kernel.org,
	Sakari Ailus <sakari.ailus@linux.intel.com>
Subject: Re: [PATCH 2/2 v7] leds: rt8515: Add Richtek RT8515 LED driver
Date: Wed, 30 Dec 2020 22:32:42 +0200	[thread overview]
Message-ID: <CAHp75Ve7PWsecWdD000CHmuH8moo6xaH9kqO9xDmQvkphEX4Rg@mail.gmail.com> (raw)
In-Reply-To: <20201201101350.1401956-2-linus.walleij@linaro.org>

On Wed, Dec 2, 2020 at 12:33 AM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> This adds a driver for the Richtek RT8515 dual channel
> torch/flash white LED driver.
>
> This LED driver is found in some mobile phones from
> Samsung such as the GT-S7710 and GT-I8190.
>
> A V4L interface is added.
>
> We do not have a proper datasheet for the RT8515 but
> it turns out that RT9387A has a public datasheet and
> is essentially the same chip. We designed the driver
> in accordance with this datasheet. The day someone
> needs to drive a RT9387A this driver can probably
> easily be augmented to handle that chip too.

...


> +#include <linux/of.h>

As far as I can see you are using fwnode API, so above better to be
replaced with

#include <linux/property.h>

For the ID table you probably need mod_devicetable.h.

...

> +#define RT8515_MIN_IOUT_MA     15
> +#define RT8515_MAX_IOUT_MA     700

MA -> mA ?

...

> +#define RT8515_TIMEOUT_DEFAULT         250000U /* 250ms */
> +#define RT8515_MAX_TIMEOUT_DEFAULT     300000U /* 300ms */

MAX and DEFAULT in the same sentence sound confusing.
Also, instead of comments can you use units in the name, like _US?

(I guess _DEFAULT can be replaced by _US)

...

> +struct rt8515 {
> +       struct device *dev;

> +       struct led_classdev_flash fled;

If you make this first member you will effectively eliminate overhead
of container_of().

> +       struct v4l2_flash *v4l2_flash;

> +};

...


> +       if (brightness == LED_OFF) {
> +               /* Off */
> +               gpiod_set_value(rt->enable_flash, 0);
> +               gpiod_set_value(rt->enable_torch, 0);

These two together are repeated at least three times in the driver, perhaps

static void rt8515_gpio_led_off(... *rt)
{
      gpiod_set_value(rt->enable_flash, 0);
      gpiod_set_value(rt->enable_torch, 0);
}

> +       } else if (brightness < RT8515_TORCH_MAX) {
> +               /* Step it up to movie mode brightness using the flash pin */
> +               rt8515_gpio_brightness_commit(rt->enable_torch, brightness);
> +       } else {
> +               /* Max torch brightness requested */
> +               gpiod_set_value(rt->enable_torch, 1);
> +       }

...

> +       ret1 = fwnode_property_read_u32(rt->dev->fwnode, resistance, &res);
> +       ret2 = fwnode_property_read_u32(led, max_ua_prop, &ua);
> +
> +       /* No info in DT, OK go with hardware maxima */
> +       if (ret1 && ret2) {
> +               max_ma = RT8515_MAX_IOUT_MA;
> +               max_intensity = hw_max;
> +               goto out_assign_max;
> +       }
> +
> +       if (ret1 || ret2) {
> +               dev_err(rt->dev,
> +                       "either %s or %s missing from DT, using HW max\n",
> +                       resistance, max_ua_prop);
> +               max_ma = RT8515_MAX_IOUT_MA;
> +               max_intensity = hw_max;
> +               goto out_assign_max;
> +       }

Dup. Can be rewritten as (taking into account that resistance can't be 0):

       u32 res = 0; /* Can't be 0, used as undefined value */
       ...
       fwnode_property_read_u32(rt->dev->fwnode, resistance, &res);
       ret = fwnode_property_read_u32(led, max_ua_prop, &ua);
       if (ret || res == 0) {
               /* No info in DT, OK go with hardware maxima */
               if (!(ret && res == 0)) {
                  dev_err(rt->dev,
                       "either %s or %s missing from DT, using HW max\n",
// or resistance is 0, the case your original code is missing
                       resistance, max_ua_prop);
               }
               max_ma = RT8515_MAX_IOUT_MA;
               max_intensity = hw_max;
               goto out_assign_max;
      }

But please double check.

> +       /*
> +        * Formula from datasheet, this is the maximum current

the datasheet

> +        * defined by the hardware.
> +        */
> +       max_ma = (5500 * 1000) / res;
> +       /*
> +        * Calculate max intensity (linear scaling)
> +        * Formula is ((ua / 1000) / max_ma) * 100, then simplified
> +        */
> +       max_intensity = (ua / 10) / max_ma;
> +
> +       dev_info(rt->dev,
> +                "current restricted from %u to %u mA, max intensity %d/100\n",
> +                max_ma, (ua / 1000), max_intensity);
> +
> +out_assign_max:
> +       dev_info(rt->dev, "max intensity %d/%d = %d mA\n",
> +                max_intensity, hw_max, max_ma);
> +       *max_intensity_setting = max_intensity;
> +}

...

> +       /* ENF - Enable Flash line */
> +       rt->enable_flash = devm_gpiod_get(dev, "enf", GPIOD_OUT_LOW);
> +       if (IS_ERR(rt->enable_flash)) {

> +               dev_err(dev, "cannot get ENF (enable flash) GPIO\n");
> +               return PTR_ERR(rt->enable_flash);

Shouldn't it be dev_err_probe() to avoid spam in certain cases?

> +       }
> +
> +       /* ENT - Enable Torch line */
> +       rt->enable_torch = devm_gpiod_get(dev, "ent", GPIOD_OUT_LOW);
> +       if (IS_ERR(rt->enable_torch)) {

> +               dev_err(dev, "cannot get ENT (enable torch) GPIO\n");
> +               return PTR_ERR(rt->enable_torch);

Shouldn't it be dev_err_probe() to avoid spam in certain cases?

> +       }

...

> +       rt->v4l2_flash = v4l2_flash_init(dev, child, fled, NULL, &v4l2_sd_cfg);
> +       if (IS_ERR(rt->v4l2_flash)) {
> +               ret = PTR_ERR(rt->v4l2_flash);
> +               dev_err(dev, "failed to register V4L2 flash device (%d)\n",
> +                       ret);
> +               /*
> +                * Continue without the V4L2 flash
> +                * (we still have the classdev)
> +                */
> +       }

> +       return 0;

In conjunction with above can be

return PTR_ERR_OR_ZERO(rt->v4l2_flash);

...

> +static const struct of_device_id rt8515_match[] = {
> +       { .compatible = "richtek,rt8515", },
> +       { /* sentinel */ },

Comma is not needed.

> +};

-- 
With Best Regards,
Andy Shevchenko

  parent reply	other threads:[~2020-12-30 20:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-01 10:13 [PATCH 1/2 v7] dt-bindings: leds: Add DT binding for Richtek RT8515 Linus Walleij
2020-12-01 10:13 ` [PATCH 2/2 v7] leds: rt8515: Add Richtek RT8515 LED driver Linus Walleij
2020-12-30 19:09   ` Pavel Machek
2021-01-01 14:19     ` Linus Walleij
2020-12-30 20:32   ` Andy Shevchenko [this message]
2020-12-09 16:31 ` [PATCH 1/2 v7] dt-bindings: leds: Add DT binding for Richtek RT8515 Rob Herring

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=CAHp75Ve7PWsecWdD000CHmuH8moo6xaH9kqO9xDmQvkphEX4Rg@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=dmurphy@ti.com \
    --cc=jacek.anaszewski@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=newbytee@protonmail.com \
    --cc=pavel@ucw.cz \
    --cc=phone-devel@vger.kernel.org \
    --cc=sakari.ailus@iki.fi \
    --cc=sakari.ailus@linux.intel.com \
    --cc=stephan@gerhold.net \
    /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).