devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Vaittinen, Matti" <Matti.Vaittinen@fi.rohmeurope.com>
Cc: Matti Vaittinen <mazziesaccount@gmail.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>,
	Shreeya Patel <shreeya.patel@collabora.com>,
	Zhigang Shi <Zhigang.Shi@liteon.com>,
	Paul Gazzillo <paul@pgazz.com>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Andi Shyti <andi.shyti@kernel.org>
Subject: Re: [PATCH v3 4/5] iio: light: ROHM BU27008 color sensor
Date: Sun, 7 May 2023 15:22:36 +0100	[thread overview]
Message-ID: <20230507152236.46aba096@jic23-huawei> (raw)
In-Reply-To: <91463df1-5aba-484a-92ea-f8979ec30535@fi.rohmeurope.com>


> >   
> >> +
> >> +	if (i2c->irq) {
> >> +		ret = devm_iio_triggered_buffer_setup(dev, idev,
> >> +						      &iio_pollfunc_store_time,
> >> +						      bu27008_trigger_handler,
> >> +						      &bu27008_buffer_ops);
> >> +		if (ret)
> >> +			return dev_err_probe(dev, ret,
> >> +				     "iio_triggered_buffer_setup_ext FAIL\n");
> >> +
> >> +		itrig = devm_iio_trigger_alloc(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(dev, GFP_KERNEL, "%s-bu27008",
> >> +				      dev_name(dev));
> >> +
> >> +		ret = devm_request_threaded_irq(dev, i2c->irq,
> >> +						iio_pollfunc_store_time,  
> > 
> > This is on the wrong irq.   
> 
> Seems like I have some homework to do :)
> 
> Right. I now see I pass the iio_pollfunc_store_time() as top half for 
> both the "real IRQ" generated by the device (here), as well as a 
> top-half for the devm_iio_triggered_buffer_setup(). Ideally I like the 
> idea of taking the timestamp in the top half for the device-generated 
> IRQ as it is closer the moment HW did acquire the sample - but it really 
> would make no difference here (even if I did it correctly).

It's the matter of few function calls later.  So trivial timing wise.

> 
>   iio_pollfunc_store_time is used with the trigger not
> > here.  Basically what happens is the caller of iio_poll_trigger() fires the input
> > to a software irq chip that then signals all the of the downstream irqs (which
> > are the individual consumers of the triggers).  If that's triggered from the
> > top half / non threaded bit of the interrupt the iio_pollfunc_store_time()
> > will be called in that non threaded context before the individual threads
> > for the trigger consumer are started.  
> 
> Oh. So, you mean the iio_pollfunc_store_time() is automatically called 
> already before kicking the SW-IRQ? So we don't need it in 
> devm_iio_triggered_buffer_setup() anymore?

No.  Whatever you register as the top half of the poll_func in the call
to devm_iio_triggered_buffer_setup() will be called as part of the SW irq
chip handling - not this isn't a SW-IRQ at all, it's just some demultiplexing
code.  The top half of an IIO poll func runs in the the trigger interrupt handler
(under iio_trigger_poll) before those in turn start their own interrupt threads
to handle whatever you registered as the threads in devm_iio_trigger_buffer_setup()

> 
> > If there is nothing to do in the actual interrupt as it's a data ready
> > only signal, then you should just call iio_trigger_poll() in the top half and
> > use devm_request_irq() only as there is no thread in this interrupt (though
> > there is one for the interrupt below the software interrupt chip).  
> 
> I haven't tested this yet so please ignore me if I am writing nonsense - 
> but... The BU27008 will keep the IRQ line asserted until a register is 
> read. We can't read the register form HW-IRQ so we need to keep the IRQ 
> disabled until the threaded trigger handler is ran. With the setup we 
> have here, the IRQF_ONESHOT, took care of this. I assume that changing 
> to call the iio_poll_trigger() from top-half means I need to explicitly 
> disable the IRQ and re-enable it at the end of the trigger thread after 
> reading the register which debounces the IRQ line?

Hmm. I'm trying to remember how this works (wrote this a very long time ago).
I'm fairly sure it's not an issue because we use IRQF_ONESHOT down one level
so exercise the same prevention of the threads triggering multiple times etc.
https://elixir.bootlin.com/linux/latest/source/drivers/iio/buffer/industrialio-triggered-buffer.c#L57

It doesn't matter if the device interrupt fires again as it will still be masked
at our software irqchip level and will then get queued up and the thread will
run again.

> 
> > 
> >   
> >> +						&bu27008_irq_thread_handler,
> >> +						IRQF_ONESHOT, name, idev->pollfunc);
> >> +		if (ret)
> >> +			return dev_err_probe(dev, ret,
> >> +					     "Could not request IRQ\n");
> >> +
> >> +
> >> +		ret = devm_iio_trigger_register(dev, itrig);
> >> +		if (ret)
> >> +			return dev_err_probe(dev, ret,
> >> +					     "Trigger registration failed\n");
> >> +	} else {
> >> +		dev_warn(dev, "No IRQ configured\n");  
> > 
> > Why is it a warning?  Either driver works without an IRQ, or it doesn't.
> > dev_dbg() or dev_info() at most.  
> 
> Some of it works. Well, maybe I'll change it to tell that device works 
> in raw_read only mode.
> 
> Thanks again for the help!
> 
> Yours,
> 	-- Matti
> 


  reply	other threads:[~2023-05-07 14:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-26  8:06 [PATCH v3 0/5] Support ROHM BU27008 RGB sensor Matti Vaittinen
2023-04-26  8:07 ` [PATCH v3 1/5] dt-bindings: iio: light: ROHM BU27008 Matti Vaittinen
2023-04-26  8:07 ` [PATCH v3 2/5] iio: trigger: Add simple trigger_validation helper Matti Vaittinen
2023-04-26  8:08 ` [PATCH v3 3/5] iio: kx022a: Use new iio_validate_own_trigger() Matti Vaittinen
2023-04-26  8:08 ` [PATCH v3 4/5] iio: light: ROHM BU27008 color sensor Matti Vaittinen
2023-05-01 14:20   ` Jonathan Cameron
2023-05-02  8:07     ` Vaittinen, Matti
2023-05-07 14:22       ` Jonathan Cameron [this message]
2023-05-07 16:13         ` Matti Vaittinen
2023-05-13 17:26           ` Jonathan Cameron
2023-05-02 20:40   ` Andy Shevchenko
2023-05-03  5:11     ` Vaittinen, Matti
2023-05-07 14:24       ` Jonathan Cameron
2023-05-07 15:49         ` Matti Vaittinen
2023-05-08 12:41         ` Andy Shevchenko
2023-05-08 12:48           ` Matti Vaittinen
2023-04-26  8:08 ` [PATCH v3 5/5] MAINTAINERS: Add ROHM BU27008 Matti Vaittinen

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=20230507152236.46aba096@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Matti.Vaittinen@fi.rohmeurope.com \
    --cc=Zhigang.Shi@liteon.com \
    --cc=andi.shyti@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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).