devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Matti Vaittinen <mazziesaccount@gmail.com>
Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Zhigang Shi <Zhigang.Shi@liteon.com>,
	Paul Gazzillo <paul@pgazz.com>,
	Shreeya Patel <shreeya.patel@collabora.com>,
	Dmitry Osipenko <dmitry.osipenko@collabora.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 4/5] iio: light: ROHM BU27008 color sensor
Date: Sat, 20 May 2023 17:44:22 +0100	[thread overview]
Message-ID: <20230520174422.4313cd83@jic23-huawei> (raw)
In-Reply-To: <2594162f0e44148cffb1fb05f1d6edfde6bd11bc.1683541225.git.mazziesaccount@gmail.com>

On Mon, 8 May 2023 13:39:29 +0300
Matti Vaittinen <mazziesaccount@gmail.com> wrote:

> The ROHM BU27008 is a sensor with 5 photodiodes (red, green, blue, clear
> and IR) with four configurable channels. Red and green being always
> available and two out of the rest three (blue, clear, IR) can be
> selected to be simultaneously measured. Typical application is adjusting
> LCD backlight of TVs, mobile phones and tablet PCs.
> 
> Add initial support for the ROHM BU27008 color sensor.
>  - raw_read() of RGB and clear channels
>  - triggered buffer w/ DRDY interrtupt
> 
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> 
> ---
> 
> Please, check the way trigger handling is now implemented. I've verified
> it works for one user-space user, but I am no longer confident on how
> the triggers are intended to be used.
> 
> When testing the trigger passing iio_trigger_generic_data_rdy_poll() as
> a handler in devm_request_irq() I saw an IRQ storm. The threaded handler
> given in devm_iio_triggered_buffer_setup() [bu27008_trigger_handler()] got
> never called and system hung just looping in
> iio_trigger_generic_data_rdy_poll(). Hence, this version disables the
> IRQ in the handler registered at devm_request_irq(), before cascading
> into iio_trigger_poll(). IRQ is now re-enabled in trigger's .reenable
> callback. Feedback is appreciated!

What you have makes sense to me.

A few trivial things inline I'll tidy up whilst applying.


> +static int bu27008_trigger_set_state(struct iio_trigger *trig,
> +				     bool state)
> +{
> +	struct bu27008_data *data = iio_trigger_get_drvdata(trig);
> +	int ret = 0;

No need to initialize ret.

> +
> +	if (state)
> +		ret = bu27008_set_drdy_irq(data, BU27008_INT_EN);
> +	else
> +		ret = bu27008_set_drdy_irq(data, BU27008_INT_DIS);
> +	if (ret)
> +		dev_err(data->dev, "Failed to set trigger state\n");
> +
> +	return ret;
> +}
> +
> +static void bu27008_trigger_reenable(struct iio_trigger *trig)
> +{
> +	struct bu27008_data *data = iio_trigger_get_drvdata(trig);
> +
> +	enable_irq(data->irq);
> +}


> +static irqreturn_t bu27008_data_rdy_poll(int irq, void *private)
> +{
> +	/*
> +	 * The BU27008 keeps IRQ asserted until we read the VALID bit from
> +	 * a register. We need to keep the IRQ disabled until this

Half sentence.   If this is all that comes up I'll change it to.

We need to keep the IRQ disable until then.

> +	 */
> +	disable_irq_nosync(irq);
> +	iio_trigger_poll(private);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int bu27008_setup_trigger(struct bu27008_data *data, struct iio_dev *idev)
> +{
> +	struct iio_trigger *itrig;
> +	char *name;
> +	int ret;
> +
> +	ret = devm_iio_triggered_buffer_setup(data->dev, idev,
> +					      &iio_pollfunc_store_time,
> +					      bu27008_trigger_handler,
> +					      &bu27008_buffer_ops);
> +	if (ret)
> +		return dev_err_probe(data->dev, ret,
> +			     "iio_triggered_buffer_setup_ext FAIL\n");
> +
> +	itrig = devm_iio_trigger_alloc(data->dev, "%sdata-rdy-dev%d",
> +				       idev->name, iio_device_id(idev));
> +	if (!itrig)
> +		return -ENOMEM;
> +
> +	data->trig = itrig;
> +
> +	itrig->ops = &bu27008_trigger_ops;
> +	iio_trigger_set_drvdata(itrig, data);
> +
> +	name = devm_kasprintf(data->dev, GFP_KERNEL, "%s-bu27008",
> +			      dev_name(data->dev));
> +
> +	ret = devm_request_irq(data->dev, data->irq,
> +			       &bu27008_data_rdy_poll,
> +			       0, name, itrig);
> +	if (ret)
> +		return dev_err_probe(data->dev, ret, "Could not request IRQ\n");
> +
> +	ret = devm_iio_trigger_register(data->dev, itrig);
> +	if (ret)
> +		return dev_err_probe(data->dev, ret,
> +				     "Trigger registration failed\n");
> +
> +	/* set default trigger */
> +	idev->trig = iio_trigger_get(itrig);
> +
> +	return 0;
> +}


  reply	other threads:[~2023-05-20 16:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08 10:30 [PATCH v5 0/5] Support ROHM BU27008 RGB sensor Matti Vaittinen
2023-05-08 10:30 ` [PATCH v5 1/5] dt-bindings: iio: light: ROHM BU27008 Matti Vaittinen
2023-05-08 10:31 ` [PATCH v5 2/5] iio: trigger: Add simple trigger_validation helper Matti Vaittinen
2023-05-08 10:31 ` [PATCH v5 3/5] iio: kx022a: Use new iio_validate_own_trigger() Matti Vaittinen
2023-05-08 10:39 ` [PATCH v5 4/5] iio: light: ROHM BU27008 color sensor Matti Vaittinen
2023-05-20 16:44   ` Jonathan Cameron [this message]
2023-05-08 10:39 ` [PATCH v5 5/5] MAINTAINERS: Add ROHM BU27008 Matti Vaittinen
2023-05-20 16:46 ` [PATCH v5 0/5] Support ROHM BU27008 RGB sensor Jonathan Cameron
2023-06-09 12:46 ` Matti Vaittinen
2023-06-09 17:19   ` Jonathan Cameron
2023-06-12  6:36     ` Vaittinen, Matti

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=20230520174422.4313cd83@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Zhigang.Shi@liteon.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.osipenko@collabora.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=mazziesaccount@gmail.com \
    --cc=paul@pgazz.com \
    --cc=robh+dt@kernel.org \
    --cc=shreeya.patel@collabora.com \
    /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).