From: Ivan Mikhaylov <i.mikhaylov@yadro.com>
To: Andy Shevchenko <andy.shevchenko@gmail.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: Wed, 22 Apr 2020 15:46:09 +0300 [thread overview]
Message-ID: <cbed77d750ee2b6fc72cd65daf57f2e3839b69db.camel@yadro.com> (raw)
In-Reply-To: <CAHp75VdZ=jmQFt68+iniDbhGY9Q-ueT6QzrL82mLmsoGwftxFg@mail.gmail.com>
On Tue, 2020-04-21 at 23:23 +0300, Andy Shevchenko wrote:
> 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.
Andy, I'm planning to add more properties but not for now, this driver the
placeholder for upcoming work what I've. And I wanted something like:
rc = vcnl3020_get_and_apply_property(option1);
if (rc)
return rc;
rc = vcnl3020_get_and_apply_property(option2);
if (rc)
return rc;
etc.
And all other work about conversion will be hidden in get_and_apply_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);
> }
>
> ?
I think your approach with wrapper is better, I'll think how I can do that
without additional 'div' param.
Thanks.
prev parent reply other threads:[~2020-04-22 12:45 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
2020-04-22 12:46 ` Ivan Mikhaylov [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=cbed77d750ee2b6fc72cd65daf57f2e3839b69db.camel@yadro.com \
--to=i.mikhaylov@yadro.com \
--cc=andy.shevchenko@gmail.com \
--cc=devicetree@vger.kernel.org \
--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).