devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Ivan Mikhaylov <i.mikhaylov@yadro.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-iio <linux-iio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Rob Herring <robh+dt@kernel.org>
Subject: Re: [PATCH v10 2/2] iio: proximity: Add driver support for vcnl3020 proximity sensor
Date: Tue, 21 Apr 2020 23:23:11 +0300	[thread overview]
Message-ID: <CAHp75VdZ=jmQFt68+iniDbhGY9Q-ueT6QzrL82mLmsoGwftxFg@mail.gmail.com> (raw)
In-Reply-To: <20200421194005.6295-3-i.mikhaylov@yadro.com>

On Tue, Apr 21, 2020 at 10:39 PM Ivan Mikhaylov <i.mikhaylov@yadro.com> wrote:
>
> Proximity sensor driver based on light/vcnl4000.c code.
> For now supports only the single on-demand measurement.
>
> The VCNL3020 is a fully integrated proximity sensor. Fully
> integrated means that the infrared emitter is included in the
> package. It has 16-bit resolution. It includes a signal
> processing IC and features standard I2C communication
> interface. It features an interrupt function.

...

> +static int vcnl3020_get_and_apply_property(struct vcnl3020_data *data,
> +                                          const char *prop, u32 reg)
> +{
> +       int rc;
> +       u32 val;
> +
> +       rc = device_property_read_u32(data->dev, prop, &val);
> +       if (rc)
> +               return 0;
> +

> +       /* An example of conversion from uA to reg val:
> +        * 200000 uA == 200 mA == 20
> +        */
> +       if (!strcmp(prop, "vishay,led-current-microamp"))
> +               val /= 10000;

I probably missed the point why this function is needed at all, since
we always call only for a single property.

On top of that, why do we have this nasty strcmp()? Can't we simple do
something like

static int vcnl3020_get_and_apply_property(struct vcnl3020_data *data,
const char *prop, u32 reg, u32 div)
{
...
  val /= div;
...
}

static int vcnl3020_get_and_apply_led_current_property(struct
vcnl3020_data *data)
{
  /*
   * An example of conversion from uA to reg val:
   * 200000 uA == 200 mA == 20
   */
// Note by the way comments style
  return vcnl3020_get_and_apply_property(data, "vishay,led-current-microamp",
                                              VCNL_LED_CURRENT, 10000);
}

?

> +       rc = regmap_write(data->regmap, reg, val);
> +       if (rc) {
> +               dev_err(data->dev, "Error (%d) setting property (%s)\n",
> +                       rc, prop);
> +       }
> +
> +       return rc;
> +}

-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2020-04-21 20:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21 19:40 [PATCH v10 0/2] iio: proximity: driver for vcnl3020 Ivan Mikhaylov
2020-04-21 19:40 ` [PATCH v10 1/2] iio: proximity: provide device tree binding document Ivan Mikhaylov
2020-04-21 19:40 ` [PATCH v10 2/2] iio: proximity: Add driver support for vcnl3020 proximity sensor Ivan Mikhaylov
2020-04-21 20:23   ` Andy Shevchenko [this message]
2020-04-22 12:46     ` Ivan Mikhaylov

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='CAHp75VdZ=jmQFt68+iniDbhGY9Q-ueT6QzrL82mLmsoGwftxFg@mail.gmail.com' \
    --to=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=i.mikhaylov@yadro.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.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).