linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Parthiban Nallathambi <pn@denx.de>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald <pmeerw@pmeerw.net>,
	Rob Herring <robh+dt@kernel.org>,
	linux-iio <linux-iio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	devicetree <devicetree@vger.kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	wd@denx.de, sbabic@denx.de, Heiko Schocher <hs@denx.de>
Subject: Re: [PATCH v4 2/3] iio: light: Add support for vishay vcnl4035
Date: Fri, 3 Aug 2018 21:55:29 +0100	[thread overview]
Message-ID: <20180803215529.2069df4f@archlinux> (raw)
In-Reply-To: <CAHp75VcR7aaUkNJdARMvnkuzxfODwVhHFH0Hm94hsENbShtO3A@mail.gmail.com>

On Thu, 2 Aug 2018 22:34:14 +0300
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Thu, Aug 2, 2018 at 9:27 PM, Parthiban Nallathambi <pn@denx.de> wrote:
> > Add support for VCNL4035, which is capable of Ambient light
> > sensing (ALS) and proximity function. This patch adds support
> > only for ALS function  
> 
> > +#include <linux/module.h>
> > +#include <linux/i2c.h>
> > +#include <linux/bitops.h>
> > +#include <linux/regmap.h>
> > +#include <linux/pm_runtime.h>  
> 
> Sort?
> 
> > +#include <linux/iio/iio.h>
> > +#include <linux/iio/sysfs.h>
> > +#include <linux/iio/events.h>
> > +#include <linux/iio/buffer.h>
> > +#include <linux/iio/trigger.h>
> > +#include <linux/iio/trigger_consumer.h>
> > +#include <linux/iio/triggered_buffer.h>  
> 
> Ditto.
> 
> > +       if (reg & (VCNL4035_INT_ALS_IF_H_MASK | VCNL4035_INT_ALS_IF_L_MASK))
> > +               return true;
> > +       else
> > +               return false;  
> 
> return !!(reg & ...); ?
> 
> > +static irqreturn_t vcnl4035_drdy_irq_thread(int irq, void *private)
> > +{
> > +       struct iio_dev *indio_dev = private;
> > +       struct vcnl4035_data *data = iio_priv(indio_dev);
> > +  
> 
> > +       if (vcnl4035_is_triggered(data)) {  
> 
> Here is negative conditional suits.
> 
> > +#ifndef CONFIG_PM  
> 
> Why?
> 
> > +       ret = vcnl4035_set_als_power_state(data, VCNL4035_MODE_ALS_ENABLE);
> > +       if (ret < 0)
> > +               return ret;
> > +#endif  
> 
> > +               pr_err("regmap_write default THDH returned %d\n", ret);  
> 
> dev_err()
> 
> > +               pr_err("regmap_write default THDL returned %d\n", ret);  
> 
> Ditto.
> 
> 
> > +       ret = pm_runtime_set_active(&client->dev);
> > +       if (ret < 0)
> > +               goto fail_poweroff;
> > +
> > +       pm_runtime_enable(&client->dev);
> > +       pm_runtime_set_autosuspend_delay(&client->dev, VCNL4035_SLEEP_DELAY_MS);
> > +       pm_runtime_use_autosuspend(&client->dev);  
> 
> Usually we do this after we probed the device.
I'm not sure we should.  The docs are fairly clear on this:

"In order to use autosuspend, subsystems or drivers must call
pm_runtime_use_autosuspend() (preferably before registering the device), and
thereafter they should use the various *_autosuspend() helper functions instead
of the non-autosuspend counterparts:" (Documentation/runtime_pm.txt)

It also makes more logical sense to have removed the userspace interfaces before
unwinding this as then we don't have annoying races around the inevitable
set_suspended.

> 
> > +       if (client->irq) {  
> 
> First of all, it can be negative.
> Second, care to factor out this rather long branch to a separate function?
> 
> > +               if (ret < 0) {
> > +                       dev_err(&client->dev, "request irq %d for trigger0 failed\n",
> > +                               client->irq);
> > +                       goto fail_buffer_clean;
> > +                       }  
> 
> Indentation.
> 
> > +       }  
> 
> So, do I understand correctly that IRQ is optional for this device?
> 
> 
> 
> > +#ifdef CONFIG_PM
> > +static int vcnl4035_runtime_suspend(struct device *dev)  
> 
> Perhaps __maybe_unused
> 
> > +static int vcnl4035_runtime_resume(struct device *dev)  
> 
> Ditto.
> 
> > +{
> > +       struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> > +       struct vcnl4035_data *data = iio_priv(indio_dev);
> > +       int ret;
> > +
> > +       regcache_sync(data->regmap);
> > +       ret = vcnl4035_set_als_power_state(data, VCNL4035_MODE_ALS_ENABLE);
> > +       if (ret < 0)
> > +               return ret;  
> 
> + blank line
> 
> > +       /* wait for 1 ALS integration cycle */
> > +       msleep(data->als_it_val * 100);
> > +
> > +       return 0;
> > +}
> > +#endif  
> 
> > +static const struct of_device_id vcnl4035_of_match[] = {
> > +       { .compatible = "vishay,vcnl4035", },
> > +       { },  
> 
> Better w/o comma.
> 
> > +};
> > +MODULE_DEVICE_TABLE(of, vcnl4035_of_match);  
> 
> > +
> > +static const struct i2c_device_id vcnl4035_id[] = {
> > +       { "vcnl4035", 0 },
> > +       { }
> > +};
> > +MODULE_DEVICE_TABLE(i2c, vcnl4035_id);  
> 
> Are you expecting legacy code to use this? I would rather switch to
> ->probe_new() and also remove this.  
> 


  reply	other threads:[~2018-08-03 20:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-02 18:27 [PATCH v4 1/3] iio: Add modifier for white light Parthiban Nallathambi
2018-08-02 18:27 ` [PATCH v4 2/3] iio: light: Add support for vishay vcnl4035 Parthiban Nallathambi
2018-08-02 19:29   ` Peter Meerwald-Stadler
2018-08-02 19:34   ` Andy Shevchenko
2018-08-03 20:55     ` Jonathan Cameron [this message]
2018-08-02 18:27 ` [PATCH v4 3/3] iio: light: Add device tree binding " Parthiban Nallathambi
2018-08-02 19:30 ` [PATCH v4 1/3] iio: Add modifier for white light Peter Meerwald-Stadler
2018-08-03 10:44   ` Parthiban Nallathambi
2018-08-03 11:38     ` Peter Meerwald-Stadler
2018-08-03 20:34       ` Jonathan Cameron

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=20180803215529.2069df4f@archlinux \
    --to=jic23@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hs@denx.de \
    --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=matthias.bgg@gmail.com \
    --cc=pmeerw@pmeerw.net \
    --cc=pn@denx.de \
    --cc=robh+dt@kernel.org \
    --cc=sbabic@denx.de \
    --cc=wd@denx.de \
    /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).