Lines Matching +full:1 +full:st

45 	1, 2, 4, 8, 16, 32, 64,
49 1, 2, 4, 8, 16, 32, 64, 128,
52 static int ad7606_reset(struct ad7606_state *st) in ad7606_reset() argument
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()
69 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_reg_access() local
72 mutex_lock(&st->lock); in ad7606_reg_access()
74 ret = st->bops->reg_read(st, reg); in ad7606_reg_access()
80 ret = st->bops->reg_write(st, reg, writeval); in ad7606_reg_access()
83 mutex_unlock(&st->lock); in ad7606_reg_access()
87 static int ad7606_read_samples(struct ad7606_state *st) in ad7606_read_samples() argument
89 unsigned int num = st->chip_info->num_channels - 1; in ad7606_read_samples()
90 u16 *data = st->data; in ad7606_read_samples()
103 if (st->gpio_frstdata) { in ad7606_read_samples()
104 ret = st->bops->read_block(st->dev, 1, data); in ad7606_read_samples()
108 if (!gpiod_get_value(st->gpio_frstdata)) { in ad7606_read_samples()
109 ad7606_reset(st); in ad7606_read_samples()
117 return st->bops->read_block(st->dev, num, data); in ad7606_read_samples()
124 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_trigger_handler() local
127 mutex_lock(&st->lock); in ad7606_trigger_handler()
129 ret = ad7606_read_samples(st); in ad7606_trigger_handler()
131 iio_push_to_buffers_with_timestamp(indio_dev, st->data, in ad7606_trigger_handler()
136 gpiod_set_value(st->gpio_convst, 1); in ad7606_trigger_handler()
138 mutex_unlock(&st->lock); in ad7606_trigger_handler()
145 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_scan_direct() local
148 gpiod_set_value(st->gpio_convst, 1); in ad7606_scan_direct()
149 ret = wait_for_completion_timeout(&st->completion, in ad7606_scan_direct()
156 ret = ad7606_read_samples(st); in ad7606_scan_direct()
158 ret = st->data[ch]; in ad7606_scan_direct()
161 gpiod_set_value(st->gpio_convst, 0); in ad7606_scan_direct()
173 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_read_raw() local
189 if (st->sw_mode_en) in ad7606_read_raw()
192 *val2 = st->scale_avail[st->range[ch]]; in ad7606_read_raw()
195 *val = st->oversampling; in ad7606_read_raw()
211 buf[len - 1] = '\n'; in ad7606_show_avail()
221 struct ad7606_state *st = iio_priv(indio_dev); in in_voltage_scale_available_show() local
223 return ad7606_show_avail(buf, st->scale_avail, st->num_scales, true); in in_voltage_scale_available_show()
230 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_write_scale_hw() local
232 gpiod_set_value(st->gpio_range, val); in ad7606_write_scale_hw()
239 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_write_os_hw() local
244 gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc, in ad7606_write_os_hw()
245 st->gpio_os->info, values); in ad7606_write_os_hw()
248 if (st->chip_info->os_req_reset) in ad7606_write_os_hw()
249 ad7606_reset(st); in ad7606_write_os_hw()
260 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_write_raw() local
265 mutex_lock(&st->lock); in ad7606_write_raw()
266 i = find_closest(val2, st->scale_avail, st->num_scales); in ad7606_write_raw()
267 if (st->sw_mode_en) in ad7606_write_raw()
269 ret = st->write_scale(indio_dev, ch, i); in ad7606_write_raw()
271 mutex_unlock(&st->lock); in ad7606_write_raw()
274 st->range[ch] = i; in ad7606_write_raw()
275 mutex_unlock(&st->lock); in ad7606_write_raw()
281 i = find_closest(val, st->oversampling_avail, in ad7606_write_raw()
282 st->num_os_ratios); in ad7606_write_raw()
283 mutex_lock(&st->lock); in ad7606_write_raw()
284 ret = st->write_os(indio_dev, i); in ad7606_write_raw()
286 mutex_unlock(&st->lock); in ad7606_write_raw()
289 st->oversampling = st->oversampling_avail[i]; in ad7606_write_raw()
290 mutex_unlock(&st->lock); in ad7606_write_raw()
303 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_oversampling_ratio_avail() local
305 return ad7606_show_avail(buf, st->oversampling_avail, in ad7606_oversampling_ratio_avail()
306 st->num_os_ratios, false); in ad7606_oversampling_ratio_avail()
343 AD7605_CHANNEL(1),
351 AD7606_CHANNEL(1),
373 AD7606_CHANNEL(1),
430 static int ad7606_request_gpios(struct ad7606_state *st) in ad7606_request_gpios() argument
432 struct device *dev = st->dev; in ad7606_request_gpios()
434 st->gpio_convst = devm_gpiod_get(dev, "adi,conversion-start", in ad7606_request_gpios()
436 if (IS_ERR(st->gpio_convst)) in ad7606_request_gpios()
437 return PTR_ERR(st->gpio_convst); in ad7606_request_gpios()
439 st->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in ad7606_request_gpios()
440 if (IS_ERR(st->gpio_reset)) in ad7606_request_gpios()
441 return PTR_ERR(st->gpio_reset); in ad7606_request_gpios()
443 st->gpio_range = devm_gpiod_get_optional(dev, "adi,range", in ad7606_request_gpios()
445 if (IS_ERR(st->gpio_range)) in ad7606_request_gpios()
446 return PTR_ERR(st->gpio_range); in ad7606_request_gpios()
448 st->gpio_standby = devm_gpiod_get_optional(dev, "standby", in ad7606_request_gpios()
450 if (IS_ERR(st->gpio_standby)) in ad7606_request_gpios()
451 return PTR_ERR(st->gpio_standby); in ad7606_request_gpios()
453 st->gpio_frstdata = devm_gpiod_get_optional(dev, "adi,first-data", in ad7606_request_gpios()
455 if (IS_ERR(st->gpio_frstdata)) in ad7606_request_gpios()
456 return PTR_ERR(st->gpio_frstdata); in ad7606_request_gpios()
458 if (!st->chip_info->oversampling_num) in ad7606_request_gpios()
461 st->gpio_os = devm_gpiod_get_array_optional(dev, in ad7606_request_gpios()
464 return PTR_ERR_OR_ZERO(st->gpio_os); in ad7606_request_gpios()
476 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_interrupt() local
479 gpiod_set_value(st->gpio_convst, 0); in ad7606_interrupt()
480 iio_trigger_poll_chained(st->trig); in ad7606_interrupt()
482 complete(&st->completion); in ad7606_interrupt()
491 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_validate_trigger() local
493 if (st->trig != trig) in ad7606_validate_trigger()
501 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_buffer_postenable() local
503 gpiod_set_value(st->gpio_convst, 1); in ad7606_buffer_postenable()
510 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_buffer_predisable() local
512 gpiod_set_value(st->gpio_convst, 0); in ad7606_buffer_predisable()
562 struct ad7606_state *st = data; in ad7606_regulator_disable() local
564 regulator_disable(st->reg); in ad7606_regulator_disable()
571 struct ad7606_state *st; in ad7606_probe() local
575 indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); in ad7606_probe()
579 st = iio_priv(indio_dev); in ad7606_probe()
582 st->dev = dev; in ad7606_probe()
583 mutex_init(&st->lock); in ad7606_probe()
584 st->bops = bops; in ad7606_probe()
585 st->base_address = base_address; in ad7606_probe()
587 st->range[0] = 0; in ad7606_probe()
588 st->oversampling = 1; in ad7606_probe()
589 st->scale_avail = ad7606_scale_avail; in ad7606_probe()
590 st->num_scales = ARRAY_SIZE(ad7606_scale_avail); in ad7606_probe()
592 st->reg = devm_regulator_get(dev, "avcc"); in ad7606_probe()
593 if (IS_ERR(st->reg)) in ad7606_probe()
594 return PTR_ERR(st->reg); in ad7606_probe()
596 ret = regulator_enable(st->reg); in ad7606_probe()
602 ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st); in ad7606_probe()
606 st->chip_info = &ad7606_chip_info_tbl[id]; in ad7606_probe()
608 if (st->chip_info->oversampling_num) { in ad7606_probe()
609 st->oversampling_avail = st->chip_info->oversampling_avail; in ad7606_probe()
610 st->num_os_ratios = st->chip_info->oversampling_num; in ad7606_probe()
613 ret = ad7606_request_gpios(st); in ad7606_probe()
617 if (st->gpio_os) { in ad7606_probe()
618 if (st->gpio_range) in ad7606_probe()
623 if (st->gpio_range) in ad7606_probe()
630 indio_dev->channels = st->chip_info->channels; in ad7606_probe()
631 indio_dev->num_channels = st->chip_info->num_channels; in ad7606_probe()
633 init_completion(&st->completion); in ad7606_probe()
635 ret = ad7606_reset(st); in ad7606_probe()
637 dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n"); in ad7606_probe()
640 if (st->chip_info->init_delay_ms) { in ad7606_probe()
641 if (msleep_interruptible(st->chip_info->init_delay_ms)) in ad7606_probe()
645 st->write_scale = ad7606_write_scale_hw; in ad7606_probe()
646 st->write_os = ad7606_write_os_hw; in ad7606_probe()
648 if (st->bops->sw_mode_config) in ad7606_probe()
649 st->sw_mode_en = device_property_present(st->dev, in ad7606_probe()
652 if (st->sw_mode_en) { in ad7606_probe()
654 st->scale_avail = ad7616_sw_scale_avail; in ad7606_probe()
655 st->num_scales = ARRAY_SIZE(ad7616_sw_scale_avail); in ad7606_probe()
658 memset32(st->range, 2, ARRAY_SIZE(st->range)); in ad7606_probe()
661 ret = st->bops->sw_mode_config(indio_dev); in ad7606_probe()
666 st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", in ad7606_probe()
669 if (!st->trig) in ad7606_probe()
672 st->trig->ops = &ad7606_trigger_ops; in ad7606_probe()
673 iio_trigger_set_drvdata(st->trig, indio_dev); in ad7606_probe()
674 ret = devm_iio_trigger_register(dev, st->trig); in ad7606_probe()
678 indio_dev->trig = iio_trigger_get(st->trig); in ad7606_probe()
704 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_suspend() local
706 if (st->gpio_standby) { in ad7606_suspend()
707 gpiod_set_value(st->gpio_range, 1); in ad7606_suspend()
708 gpiod_set_value(st->gpio_standby, 0); in ad7606_suspend()
717 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_resume() local
719 if (st->gpio_standby) { in ad7606_resume()
720 gpiod_set_value(st->gpio_range, st->range[0]); in ad7606_resume()
721 gpiod_set_value(st->gpio_standby, 1); in ad7606_resume()
722 ad7606_reset(st); in ad7606_resume()