... > > > > > > -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