Lines Matching +full:threshold +full:- +full:detector

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Holt Integrated Circuits HI-8435 threshold detector driver
24 /* Register offsets for HI-8435 */
50 unsigned threshold_lo[2]; /* GND-Open and Supply-Open thresholds */
51 unsigned threshold_hi[2]; /* GND-Open and Supply-Open thresholds */
58 return spi_write_then_read(priv->spi, &reg, 1, val, 1); in hi8435_readb()
67 ret = spi_write_then_read(priv->spi, &reg, 1, &be_val, 2); in hi8435_readw()
79 ret = spi_write_then_read(priv->spi, &reg, 1, &be_val, 4); in hi8435_readl()
87 priv->reg_buffer[0] = reg | HI8435_WRITE_OPCODE; in hi8435_writeb()
88 priv->reg_buffer[1] = val; in hi8435_writeb()
90 return spi_write(priv->spi, priv->reg_buffer, 2); in hi8435_writeb()
95 priv->reg_buffer[0] = reg | HI8435_WRITE_OPCODE; in hi8435_writew()
96 priv->reg_buffer[1] = (val >> 8) & 0xff; in hi8435_writew()
97 priv->reg_buffer[2] = val & 0xff; in hi8435_writew()
99 return spi_write(priv->spi, priv->reg_buffer, 3); in hi8435_writew()
115 *val = !!(tmp & BIT(chan->channel)); in hi8435_read_raw()
118 return -EINVAL; in hi8435_read_raw()
129 return !!(priv->event_scan_mask & BIT(chan->channel)); in hi8435_read_event_config()
145 if (tmp & BIT(chan->channel)) in hi8435_write_event_config()
146 priv->event_prev_val |= BIT(chan->channel); in hi8435_write_event_config()
148 priv->event_prev_val &= ~BIT(chan->channel); in hi8435_write_event_config()
150 priv->event_scan_mask |= BIT(chan->channel); in hi8435_write_event_config()
152 priv->event_scan_mask &= ~BIT(chan->channel); in hi8435_write_event_config()
173 /* Supply-Open or GND-Open sensing mode */ in hi8435_read_event_value()
174 mode = !!(psen & BIT(chan->channel / 8)); in hi8435_read_event_value()
182 *val = ((reg & 0xff) - (reg >> 8)) / 2; in hi8435_read_event_value()
205 /* Supply-Open or GND-Open sensing mode */ in hi8435_write_event_value()
206 mode = !!(psen & BIT(chan->channel / 8)); in hi8435_write_event_value()
214 /* falling threshold range 2..21V, hysteresis minimum 2V */ in hi8435_write_event_value()
215 if (val < 2 || val > 21 || (val + 2) > priv->threshold_hi[mode]) in hi8435_write_event_value()
216 return -EINVAL; in hi8435_write_event_value()
218 if (val == priv->threshold_lo[mode]) in hi8435_write_event_value()
221 priv->threshold_lo[mode] = val; in hi8435_write_event_value()
224 if ((priv->threshold_hi[mode] - priv->threshold_lo[mode]) % 2) in hi8435_write_event_value()
225 priv->threshold_hi[mode]--; in hi8435_write_event_value()
227 /* rising threshold range 3..22V, hysteresis minimum 2V */ in hi8435_write_event_value()
228 if (val < 3 || val > 22 || val < (priv->threshold_lo[mode] + 2)) in hi8435_write_event_value()
229 return -EINVAL; in hi8435_write_event_value()
231 if (val == priv->threshold_hi[mode]) in hi8435_write_event_value()
234 priv->threshold_hi[mode] = val; in hi8435_write_event_value()
237 if ((priv->threshold_hi[mode] - priv->threshold_lo[mode]) % 2) in hi8435_write_event_value()
238 priv->threshold_lo[mode]++; in hi8435_write_event_value()
242 mutex_lock(&priv->lock); in hi8435_write_event_value()
247 mutex_unlock(&priv->lock); in hi8435_write_event_value()
252 reg = priv->threshold_hi[mode] - priv->threshold_lo[mode]; in hi8435_write_event_value()
254 /* threshold center */ in hi8435_write_event_value()
255 reg |= (priv->threshold_hi[mode] + priv->threshold_lo[mode]); in hi8435_write_event_value()
260 mutex_unlock(&priv->lock); in hi8435_write_event_value()
311 return !!(reg & BIT(chan->channel / 8)); in hi8435_get_sensing_mode()
322 mutex_lock(&priv->lock); in hi8435_set_sensing_mode()
326 mutex_unlock(&priv->lock); in hi8435_set_sensing_mode()
330 reg &= ~BIT(chan->channel / 8); in hi8435_set_sensing_mode()
332 reg |= BIT(chan->channel / 8); in hi8435_set_sensing_mode()
336 mutex_unlock(&priv->lock); in hi8435_set_sensing_mode()
341 static const char * const hi8435_sensing_modes[] = { "GND-Open",
342 "Supply-Open" };
418 unsigned int status = priv->event_prev_val ^ val; in hi8435_iio_push_event()
423 for_each_set_bit(i, &priv->event_scan_mask, 32) { in hi8435_iio_push_event()
434 priv->event_prev_val = val; in hi8435_iio_push_event()
440 struct iio_dev *idev = pf->indio_dev; in hi8435_trigger_handler()
452 iio_trigger_notify_done(idev->trig); in hi8435_trigger_handler()
469 idev = devm_iio_device_alloc(&spi->dev, sizeof(*priv)); in hi8435_probe()
471 return -ENOMEM; in hi8435_probe()
474 priv->spi = spi; in hi8435_probe()
476 reset_gpio = devm_gpiod_get(&spi->dev, NULL, GPIOD_OUT_LOW); in hi8435_probe()
486 mutex_init(&priv->lock); in hi8435_probe()
488 idev->name = spi_get_device_id(spi)->name; in hi8435_probe()
489 idev->modes = INDIO_DIRECT_MODE; in hi8435_probe()
490 idev->info = &hi8435_info; in hi8435_probe()
491 idev->channels = hi8435_channels; in hi8435_probe()
492 idev->num_channels = ARRAY_SIZE(hi8435_channels); in hi8435_probe()
495 priv->event_scan_mask = ~(0); in hi8435_probe()
497 * There is a restriction in the chip - the hysteresis can not be odd. in hi8435_probe()
504 * Set threshold low voltage to 2V, threshold high voltage to 4V in hi8435_probe()
505 * for both GND-Open and Supply-Open sensing modes. in hi8435_probe()
507 priv->threshold_lo[0] = priv->threshold_lo[1] = 2; in hi8435_probe()
508 priv->threshold_hi[0] = priv->threshold_hi[1] = 4; in hi8435_probe()
516 ret = devm_add_action_or_reset(&spi->dev, in hi8435_probe()
522 return devm_iio_device_register(&spi->dev, idev); in hi8435_probe()
549 MODULE_DESCRIPTION("HI-8435 threshold detector");