/** * st_sensors_new_samples_available() - check if more samples came in * @indio_dev: IIO device reference. * @sdata: Sensor data. * * returns: * false - no new samples available or read error * true - new samples available
*/ staticbool st_sensors_new_samples_available(struct iio_dev *indio_dev, struct st_sensor_data *sdata)
{ int ret, status;
/* How would I know if I can't check it? */ if (!sdata->sensor_settings->drdy_irq.stat_drdy.addr) returntrue;
/* No scan mask, no interrupt */ if (!indio_dev->active_scan_mask) returnfalse;
ret = regmap_read(sdata->regmap,
sdata->sensor_settings->drdy_irq.stat_drdy.addr,
&status); if (ret < 0) {
dev_err(indio_dev->dev.parent, "error checking samples available\n"); returnfalse;
}
/* * If this trigger is backed by a hardware interrupt and we have a * status register, check if this IRQ came from us. Notice that * we will process also if st_sensors_new_samples_available() * returns negative: if we can't check status, then poll * unconditionally.
*/ if (sdata->hw_irq_trigger &&
st_sensors_new_samples_available(indio_dev, sdata)) {
iio_trigger_poll_nested(p);
} else {
dev_dbg(indio_dev->dev.parent, "spurious IRQ\n"); return IRQ_NONE;
}
/* * If we have proper level IRQs the handler will be re-entered if * the line is still active, so return here and come back in through * the top half if need be.
*/ if (!sdata->edge_irq) return IRQ_HANDLED;
/* * If we are using edge IRQs, new samples arrived while processing * the IRQ and those may be missed unless we pick them here, so poll * again. If the sensor delivery frequency is very high, this thread * turns into a polled loop handler.
*/ while (sdata->hw_irq_trigger &&
st_sensors_new_samples_available(indio_dev, sdata)) {
dev_dbg(indio_dev->dev.parent, "more samples came in during polling\n");
sdata->hw_timestamp = iio_get_time_ns(indio_dev);
iio_trigger_poll_nested(p);
}
/* * If the IRQ is triggered on falling edge, we need to mark the * interrupt as active low, if the hardware supports this.
*/
irq_trig = irq_get_trigger_type(sdata->irq); switch(irq_trig) { case IRQF_TRIGGER_FALLING: case IRQF_TRIGGER_LOW: if (!sdata->sensor_settings->drdy_irq.addr_ihl) {
dev_err(parent, "falling/low specified for IRQ but hardware supports only rising/high: will request rising/high\n"); if (irq_trig == IRQF_TRIGGER_FALLING)
irq_trig = IRQF_TRIGGER_RISING; if (irq_trig == IRQF_TRIGGER_LOW)
irq_trig = IRQF_TRIGGER_HIGH;
} else { /* Set up INT active low i.e. falling edge */
err = st_sensors_write_data_with_mask(indio_dev,
sdata->sensor_settings->drdy_irq.addr_ihl,
sdata->sensor_settings->drdy_irq.mask_ihl, 1); if (err < 0) return err;
dev_info(parent, "interrupts on the falling edge or active low level\n");
} break; case IRQF_TRIGGER_RISING:
dev_info(parent, "interrupts on the rising edge\n"); break; case IRQF_TRIGGER_HIGH:
dev_info(parent, "interrupts active high level\n"); break; default: /* This is the most preferred mode, if possible */
dev_err(parent, "unsupported IRQ trigger specified (%lx), enforce rising edge\n", irq_trig);
irq_trig = IRQF_TRIGGER_RISING;
}
/* Tell the interrupt handler that we're dealing with edges */ if (irq_trig == IRQF_TRIGGER_FALLING ||
irq_trig == IRQF_TRIGGER_RISING) { if (!sdata->sensor_settings->drdy_irq.stat_drdy.addr) {
dev_err(parent, "edge IRQ not supported w/o stat register.\n"); return -EOPNOTSUPP;
}
sdata->edge_irq = true;
} else { /* * If we're not using edges (i.e. level interrupts) we * just mask off the IRQ, handle one interrupt, then * if the line is still low, we return to the * interrupt handler top half again and start over.
*/
irq_trig |= IRQF_ONESHOT;
}
/* * If the interrupt pin is Open Drain, by definition this * means that the interrupt line may be shared with other * peripherals. But to do this we also need to have a status * register and mask to figure out if this sensor was firing * the IRQ or not, so we can tell the interrupt handle that * it was "our" interrupt.
*/ if (sdata->int_pin_open_drain &&
sdata->sensor_settings->drdy_irq.stat_drdy.addr)
irq_trig |= IRQF_SHARED;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.