From: Jonathan Cameron <jic23@kernel.org>
To: Mathieu Othacehe <m.othacehe@gmail.com>
Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/4] iio: vcnl4000: Add event support for VCNL4010/20.
Date: Sat, 25 Apr 2020 20:47:04 +0100 [thread overview]
Message-ID: <20200425204704.2c4dd1ab@archlinux> (raw)
In-Reply-To: <20200421075532.19192-3-m.othacehe@gmail.com>
On Tue, 21 Apr 2020 09:55:30 +0200
Mathieu Othacehe <m.othacehe@gmail.com> wrote:
> The VCNL4010 and VCNL4020 chips are able to raise interrupts on proximity
> threshold events. Add support for threshold rising and falling events for
> those two chips.
>
> Signed-off-by: Mathieu Othacehe <m.othacehe@gmail.com>
> ---
...
> +
> +static const struct iio_chan_spec vcnl4010_channels[] = {
> + {
> + .type = IIO_LIGHT,
> + .scan_index = -1,
Why introduce scan index here? That's only used for buffers.
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_SCALE),
> + }, {
> + .type = IIO_PROXIMITY,
> + .scan_index = 0,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + .event_spec = vcnl4000_event_spec,
> + .num_event_specs = ARRAY_SIZE(vcnl4000_event_spec),
> + .ext_info = vcnl4000_ext_info,
> + },
> +};
> +
> static const struct iio_info vcnl4000_info = {
> .read_raw = vcnl4000_read_raw,
> };
>
> +static const struct iio_info vcnl4010_info = {
> + .read_raw = vcnl4010_read_raw,
> + .read_event_value = vcnl4010_read_event,
> + .write_event_value = vcnl4010_write_event,
> + .read_event_config = vcnl4010_read_event_config,
> + .write_event_config = vcnl4010_write_event_config,
> +};
> +
> +static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = {
> + [VCNL4000] = {
> + .prod = "VCNL4000",
> + .init = vcnl4000_init,
> + .measure_light = vcnl4000_measure_light,
> + .measure_proximity = vcnl4000_measure_proximity,
> + .set_power_state = vcnl4000_set_power_state,
> + .channels = vcnl4000_channels,
> + .num_channels = ARRAY_SIZE(vcnl4000_channels),
> + .info = &vcnl4000_info,
> + .irq_support = false,
> + },
> + [VCNL4010] = {
> + .prod = "VCNL4010/4020",
> + .init = vcnl4000_init,
> + .measure_light = vcnl4000_measure_light,
> + .measure_proximity = vcnl4000_measure_proximity,
> + .set_power_state = vcnl4000_set_power_state,
> + .channels = vcnl4010_channels,
> + .num_channels = ARRAY_SIZE(vcnl4010_channels),
> + .info = &vcnl4010_info,
> + .irq_support = true,
> + },
> + [VCNL4040] = {
> + .prod = "VCNL4040",
> + .init = vcnl4200_init,
> + .measure_light = vcnl4200_measure_light,
> + .measure_proximity = vcnl4200_measure_proximity,
> + .set_power_state = vcnl4200_set_power_state,
> + .channels = vcnl4000_channels,
> + .num_channels = ARRAY_SIZE(vcnl4000_channels),
> + .info = &vcnl4000_info,
> + .irq_support = false,
> + },
> + [VCNL4200] = {
> + .prod = "VCNL4200",
> + .init = vcnl4200_init,
> + .measure_light = vcnl4200_measure_light,
> + .measure_proximity = vcnl4200_measure_proximity,
> + .set_power_state = vcnl4200_set_power_state,
> + .channels = vcnl4000_channels,
> + .num_channels = ARRAY_SIZE(vcnl4000_channels),
> + .info = &vcnl4000_info,
> + .irq_support = false,
> + },
> +};
> +
> +static irqreturn_t vcnl4010_irq_thread(int irq, void *p)
> +{
> + struct iio_dev *indio_dev = p;
> + struct vcnl4000_data *data = iio_priv(indio_dev);
> + unsigned long isr;
> + int ret;
> +
> + ret = i2c_smbus_read_byte_data(data->client, VCNL4010_ISR);
> + if (ret < 0)
> + goto end;
> +
> + isr = ret;
> +
> + if (isr & VCNL4010_INT_THR) {
> + if (test_bit(VCNL4010_INT_THR_LOW, &isr)) {
> + iio_push_event(indio_dev,
> + IIO_UNMOD_EVENT_CODE(
> + IIO_PROXIMITY,
> + 1,
> + IIO_EV_TYPE_THRESH,
> + IIO_EV_DIR_FALLING),
> + iio_get_time_ns(indio_dev));
> + }
> +
> + if (test_bit(VCNL4010_INT_THR_HIGH, &isr)) {
> + iio_push_event(indio_dev,
> + IIO_UNMOD_EVENT_CODE(
> + IIO_PROXIMITY,
> + 1,
> + IIO_EV_TYPE_THRESH,
> + IIO_EV_DIR_RISING),
> + iio_get_time_ns(indio_dev));
> + }
> +
> + i2c_smbus_write_byte_data(data->client, VCNL4010_ISR,
> + isr & VCNL4010_INT_THR);
> + }
> +
> +end:
> + return IRQ_HANDLED;
> +}
> +
> static int vcnl4000_probe(struct i2c_client *client,
> const struct i2c_device_id *id)
> {
> @@ -486,12 +805,25 @@ static int vcnl4000_probe(struct i2c_client *client,
> data->near_level = 0;
>
> indio_dev->dev.parent = &client->dev;
> - indio_dev->info = &vcnl4000_info;
> - indio_dev->channels = vcnl4000_channels;
> - indio_dev->num_channels = ARRAY_SIZE(vcnl4000_channels);
> + indio_dev->info = data->chip_spec->info;
> + indio_dev->channels = data->chip_spec->channels;
> + indio_dev->num_channels = data->chip_spec->num_channels;
> indio_dev->name = VCNL4000_DRV_NAME;
> indio_dev->modes = INDIO_DIRECT_MODE;
>
> + if (client->irq && data->chip_spec->irq_support) {
> + ret = devm_request_threaded_irq(&client->dev, client->irq,
> + NULL, vcnl4010_irq_thread,
> + IRQF_TRIGGER_FALLING |
> + IRQF_ONESHOT,
> + "vcnl4010_irq",
> + indio_dev);
> + if (ret < 0) {
> + dev_err(&client->dev, "irq request failed\n");
> + return ret;
> + }
> + }
> +
> ret = pm_runtime_set_active(&client->dev);
> if (ret < 0)
> goto fail_poweroff;
next prev parent reply other threads:[~2020-04-25 19:47 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-21 7:55 [PATCH v4 0/4] iio: vcnl: Add interrupts support for VCNL4010/20 Mathieu Othacehe
2020-04-21 7:55 ` [PATCH v4 1/4] iio: vcnl4000: Factorize data reading and writing Mathieu Othacehe
2020-04-21 7:55 ` [PATCH v4 2/4] iio: vcnl4000: Add event support for VCNL4010/20 Mathieu Othacehe
2020-04-21 11:24 ` Andy Shevchenko
2020-04-22 8:02 ` Mathieu Othacehe
2020-04-22 8:25 ` Andy Shevchenko
2020-04-25 19:47 ` Jonathan Cameron [this message]
2020-04-21 7:55 ` [PATCH v4 3/4] iio: vcnl4000: Add sampling frequency " Mathieu Othacehe
2020-04-21 12:22 ` Andy Shevchenko
2020-04-25 15:52 ` Jonathan Cameron
2020-04-25 17:14 ` Andy Shevchenko
2020-04-25 19:49 ` Jonathan Cameron
2020-04-21 7:55 ` [PATCH v4 4/4] iio: vcnl4000: Add buffer " Mathieu Othacehe
2020-04-21 12:27 ` Andy Shevchenko
2020-04-22 8:14 ` Mathieu Othacehe
2020-04-25 16:09 ` Jonathan Cameron
2020-04-25 15:57 ` 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=20200425204704.2c4dd1ab@archlinux \
--to=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=m.othacehe@gmail.com \
--cc=pmeerw@pmeerw.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