Lines Matching +full:signal +full:- +full:guard

1 // SPDX-License-Identifier: GPL-2.0
54 if (st->gpio_reset) { in ad7606_reset()
55 gpiod_set_value(st->gpio_reset, 1); in ad7606_reset()
57 gpiod_set_value(st->gpio_reset, 0); in ad7606_reset()
61 return -ENODEV; in ad7606_reset()
73 guard(mutex)(&st->lock); in ad7606_reg_access()
76 ret = st->bops->reg_read(st, reg); in ad7606_reg_access()
82 return st->bops->reg_write(st, reg, writeval); in ad7606_reg_access()
88 unsigned int num = st->chip_info->num_channels - 1; in ad7606_read_samples()
89 u16 *data = st->data; in ad7606_read_samples()
91 return st->bops->read_block(st->dev, num, data); in ad7606_read_samples()
97 struct iio_dev *indio_dev = pf->indio_dev; in ad7606_trigger_handler()
101 guard(mutex)(&st->lock); in ad7606_trigger_handler()
107 iio_push_to_buffers_with_timestamp(indio_dev, st->data, in ad7606_trigger_handler()
110 iio_trigger_notify_done(indio_dev->trig); in ad7606_trigger_handler()
111 /* The rising edge of the CONVST signal starts a new conversion. */ in ad7606_trigger_handler()
112 gpiod_set_value(st->gpio_convst, 1); in ad7606_trigger_handler()
122 gpiod_set_value(st->gpio_convst, 1); in ad7606_scan_direct()
123 ret = wait_for_completion_timeout(&st->completion, in ad7606_scan_direct()
126 ret = -ETIMEDOUT; in ad7606_scan_direct()
132 ret = st->data[ch]; in ad7606_scan_direct()
135 gpiod_set_value(st->gpio_convst, 0); in ad7606_scan_direct()
151 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { in ad7606_read_raw()
152 ret = ad7606_scan_direct(indio_dev, chan->address); in ad7606_read_raw()
160 if (st->sw_mode_en) in ad7606_read_raw()
161 ch = chan->address; in ad7606_read_raw()
163 *val2 = st->scale_avail[st->range[ch]]; in ad7606_read_raw()
166 *val = st->oversampling; in ad7606_read_raw()
169 return -EINVAL; in ad7606_read_raw()
179 len += scnprintf(buf + len, PAGE_SIZE - len, in ad7606_show_avail()
182 buf[len - 1] = '\n'; in ad7606_show_avail()
194 return ad7606_show_avail(buf, st->scale_avail, st->num_scales, true); in in_voltage_scale_available_show()
203 gpiod_set_value(st->gpio_range, val); in ad7606_write_scale_hw()
215 gpiod_set_array_value(st->gpio_os->ndescs, st->gpio_os->desc, in ad7606_write_os_hw()
216 st->gpio_os->info, values); in ad7606_write_os_hw()
219 if (st->chip_info->os_req_reset) in ad7606_write_os_hw()
234 guard(mutex)(&st->lock); in ad7606_write_raw()
238 i = find_closest(val2, st->scale_avail, st->num_scales); in ad7606_write_raw()
239 if (st->sw_mode_en) in ad7606_write_raw()
240 ch = chan->address; in ad7606_write_raw()
241 ret = st->write_scale(indio_dev, ch, i); in ad7606_write_raw()
244 st->range[ch] = i; in ad7606_write_raw()
249 return -EINVAL; in ad7606_write_raw()
250 i = find_closest(val, st->oversampling_avail, in ad7606_write_raw()
251 st->num_os_ratios); in ad7606_write_raw()
252 ret = st->write_os(indio_dev, i); in ad7606_write_raw()
258 return -EINVAL; in ad7606_write_raw()
269 return ad7606_show_avail(buf, st->oversampling_avail, in ad7606_oversampling_ratio_avail()
270 st->num_os_ratios, false); in ad7606_oversampling_ratio_avail()
328 * -SER/PAR
329 * -SEQEN
331 * -WR/BURST
332 * -DB4/SER1W
396 struct device *dev = st->dev; in ad7606_request_gpios()
398 st->gpio_convst = devm_gpiod_get(dev, "adi,conversion-start", in ad7606_request_gpios()
400 if (IS_ERR(st->gpio_convst)) in ad7606_request_gpios()
401 return PTR_ERR(st->gpio_convst); in ad7606_request_gpios()
403 st->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in ad7606_request_gpios()
404 if (IS_ERR(st->gpio_reset)) in ad7606_request_gpios()
405 return PTR_ERR(st->gpio_reset); in ad7606_request_gpios()
407 st->gpio_range = devm_gpiod_get_optional(dev, "adi,range", in ad7606_request_gpios()
409 if (IS_ERR(st->gpio_range)) in ad7606_request_gpios()
410 return PTR_ERR(st->gpio_range); in ad7606_request_gpios()
412 st->gpio_standby = devm_gpiod_get_optional(dev, "standby", in ad7606_request_gpios()
414 if (IS_ERR(st->gpio_standby)) in ad7606_request_gpios()
415 return PTR_ERR(st->gpio_standby); in ad7606_request_gpios()
417 st->gpio_frstdata = devm_gpiod_get_optional(dev, "adi,first-data", in ad7606_request_gpios()
419 if (IS_ERR(st->gpio_frstdata)) in ad7606_request_gpios()
420 return PTR_ERR(st->gpio_frstdata); in ad7606_request_gpios()
422 if (!st->chip_info->oversampling_num) in ad7606_request_gpios()
425 st->gpio_os = devm_gpiod_get_array_optional(dev, in ad7606_request_gpios()
426 "adi,oversampling-ratio", in ad7606_request_gpios()
428 return PTR_ERR_OR_ZERO(st->gpio_os); in ad7606_request_gpios()
432 * The BUSY signal indicates when conversions are in progress, so when a rising
434 * end of the entire conversion process. The falling edge of the BUSY signal
443 gpiod_set_value(st->gpio_convst, 0); in ad7606_interrupt()
444 iio_trigger_poll_nested(st->trig); in ad7606_interrupt()
446 complete(&st->completion); in ad7606_interrupt()
457 if (st->trig != trig) in ad7606_validate_trigger()
458 return -EINVAL; in ad7606_validate_trigger()
467 gpiod_set_value(st->gpio_convst, 1); in ad7606_buffer_postenable()
476 gpiod_set_value(st->gpio_convst, 0); in ad7606_buffer_predisable()
534 return -ENOMEM; in ad7606_probe()
539 st->dev = dev; in ad7606_probe()
540 mutex_init(&st->lock); in ad7606_probe()
541 st->bops = bops; in ad7606_probe()
542 st->base_address = base_address; in ad7606_probe()
543 /* tied to logic low, analog input range is +/- 5V */ in ad7606_probe()
544 st->range[0] = 0; in ad7606_probe()
545 st->oversampling = 1; in ad7606_probe()
546 st->scale_avail = ad7606_scale_avail; in ad7606_probe()
547 st->num_scales = ARRAY_SIZE(ad7606_scale_avail); in ad7606_probe()
554 st->chip_info = &ad7606_chip_info_tbl[id]; in ad7606_probe()
556 if (st->chip_info->oversampling_num) { in ad7606_probe()
557 st->oversampling_avail = st->chip_info->oversampling_avail; in ad7606_probe()
558 st->num_os_ratios = st->chip_info->oversampling_num; in ad7606_probe()
565 if (st->gpio_os) { in ad7606_probe()
566 if (st->gpio_range) in ad7606_probe()
567 indio_dev->info = &ad7606_info_os_and_range; in ad7606_probe()
569 indio_dev->info = &ad7606_info_os; in ad7606_probe()
571 if (st->gpio_range) in ad7606_probe()
572 indio_dev->info = &ad7606_info_range; in ad7606_probe()
574 indio_dev->info = &ad7606_info_no_os_or_range; in ad7606_probe()
576 indio_dev->modes = INDIO_DIRECT_MODE; in ad7606_probe()
577 indio_dev->name = name; in ad7606_probe()
578 indio_dev->channels = st->chip_info->channels; in ad7606_probe()
579 indio_dev->num_channels = st->chip_info->num_channels; in ad7606_probe()
581 init_completion(&st->completion); in ad7606_probe()
585 dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n"); in ad7606_probe()
588 if (st->chip_info->init_delay_ms) { in ad7606_probe()
589 if (msleep_interruptible(st->chip_info->init_delay_ms)) in ad7606_probe()
590 return -ERESTARTSYS; in ad7606_probe()
593 st->write_scale = ad7606_write_scale_hw; in ad7606_probe()
594 st->write_os = ad7606_write_os_hw; in ad7606_probe()
596 if (st->bops->sw_mode_config) in ad7606_probe()
597 st->sw_mode_en = device_property_present(st->dev, in ad7606_probe()
598 "adi,sw-mode"); in ad7606_probe()
600 if (st->sw_mode_en) { in ad7606_probe()
602 st->scale_avail = ad7616_sw_scale_avail; in ad7606_probe()
603 st->num_scales = ARRAY_SIZE(ad7616_sw_scale_avail); in ad7606_probe()
606 memset32(st->range, 2, ARRAY_SIZE(st->range)); in ad7606_probe()
607 indio_dev->info = &ad7606_info_os_range_and_debug; in ad7606_probe()
609 ret = st->bops->sw_mode_config(indio_dev); in ad7606_probe()
614 st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", in ad7606_probe()
615 indio_dev->name, in ad7606_probe()
617 if (!st->trig) in ad7606_probe()
618 return -ENOMEM; in ad7606_probe()
620 st->trig->ops = &ad7606_trigger_ops; in ad7606_probe()
621 iio_trigger_set_drvdata(st->trig, indio_dev); in ad7606_probe()
622 ret = devm_iio_trigger_register(dev, st->trig); in ad7606_probe()
626 indio_dev->trig = iio_trigger_get(st->trig); in ad7606_probe()
654 if (st->gpio_standby) { in ad7606_suspend()
655 gpiod_set_value(st->gpio_range, 1); in ad7606_suspend()
656 gpiod_set_value(st->gpio_standby, 1); in ad7606_suspend()
667 if (st->gpio_standby) { in ad7606_resume()
668 gpiod_set_value(st->gpio_range, st->range[0]); in ad7606_resume()
669 gpiod_set_value(st->gpio_standby, 1); in ad7606_resume()