public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: devicetree@vger.kernel.org, Lars-Peter Clausen <lars@metafoo.de>,
	linux-iio@vger.kernel.org,
	Robin van der Gracht <robin@protonic.nl>,
	linux-kernel@vger.kernel.org,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	David Jander <david@protonic.nl>
Subject: Re: [PATCH v1 1/1] iio: adc: tsc2046: rework the trigger state machine
Date: Sat, 15 Jan 2022 18:14:22 +0000	[thread overview]
Message-ID: <20220115181422.0b622b69@jic23-huawei> (raw)
In-Reply-To: <20220110123903.GC3326@pengutronix.de>

...

> > >  
> > > -static enum hrtimer_restart tsc2046_adc_trig_more(struct hrtimer *hrtimer)
> > > +static enum hrtimer_restart tsc2046_adc_timer(struct hrtimer *hrtimer)
> > >  {
> > >  	struct tsc2046_adc_priv *priv = container_of(hrtimer,
> > >  						     struct tsc2046_adc_priv,
> > >  						     trig_timer);
> > >  	unsigned long flags;
> > >  
> > > -	spin_lock_irqsave(&priv->trig_lock, flags);
> > > -
> > > -	disable_irq_nosync(priv->spi->irq);
> > > -
> > > -	priv->trig_more_count++;
> > > -	iio_trigger_poll(priv->trig);
> > > -
> > > -	spin_unlock_irqrestore(&priv->trig_lock, flags);
> > > +	spin_lock_irqsave(&priv->state_lock, flags);
> > > +	switch (priv->state) {
> > > +	case TSC2046_STATE_ENABLE_IRQ_POLL:
> > > +		/*
> > > +		 * IRQ handler called iio_trigger_poll() to sample ADC.
> > > +		 * Here we
> > > +		 * - re-enable IRQs
> > > +		 * - start hrtimer for timeout if no IRQ will occur
> > > +		 */
> > > +		priv->state = TSC2046_STATE_POLL;
> > > +		enable_irq(priv->spi->irq);  
> > 
> > I comment on this below, but I'm not sure why you don't move the enable_irq()
> > here out of this timer function and then have the first entry of the timer
> > go directly to TSC2046_STATE_POLL after a longer initial wait.  
> 
> Hm... yes. You are right.
> 
> > It's been a long time since I looked at this, so perhaps I'm missing the
> > point.  What you have here works as far as I can see, it just seems to push
> > more than necessary into the state machine.  
> 
> The IRQ line is a level shifter connected to one of channels muxed to the core
> ADC. If we switch internal muxer to different channel, the IRQ line will
> change the state.
> 
> So, we need a trigger which:
> - do not triggers if we do ADC readings.
> - keeps triggering as long as we have some state changes on the IRQ line
> - trigger only with specific rate
> - still triggers for some amount of time after last interrupt event was
>   detected. Current implementation is doing only one extra read.
Ah.. Good explanation, I get the point now :)

Jonathan

      reply	other threads:[~2022-01-15 18:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-07  7:40 [PATCH v1 1/1] iio: adc: tsc2046: rework the trigger state machine Oleksij Rempel
2022-01-09 15:44 ` Jonathan Cameron
2022-01-10 12:39   ` Oleksij Rempel
2022-01-15 18:14     ` Jonathan Cameron [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=20220115181422.0b622b69@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=david@protonic.nl \
    --cc=devicetree@vger.kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=robin@protonic.nl \
    /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