Lines Matching full:st
51 static int ad7606_reset(struct ad7606_state *st) in ad7606_reset() argument
53 if (st->gpio_reset) { in ad7606_reset()
54 gpiod_set_value(st->gpio_reset, 1); in ad7606_reset()
56 gpiod_set_value(st->gpio_reset, 0); in ad7606_reset()
68 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_reg_access() local
71 mutex_lock(&st->lock); in ad7606_reg_access()
73 ret = st->bops->reg_read(st, reg); in ad7606_reg_access()
79 ret = st->bops->reg_write(st, reg, writeval); in ad7606_reg_access()
82 mutex_unlock(&st->lock); in ad7606_reg_access()
86 static int ad7606_read_samples(struct ad7606_state *st) in ad7606_read_samples() argument
88 unsigned int num = st->chip_info->num_channels - 1; in ad7606_read_samples()
89 u16 *data = st->data; in ad7606_read_samples()
102 if (st->gpio_frstdata) { in ad7606_read_samples()
103 ret = st->bops->read_block(st->dev, 1, data); in ad7606_read_samples()
107 if (!gpiod_get_value(st->gpio_frstdata)) { in ad7606_read_samples()
108 ad7606_reset(st); in ad7606_read_samples()
116 return st->bops->read_block(st->dev, num, data); in ad7606_read_samples()
123 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_trigger_handler() local
126 mutex_lock(&st->lock); in ad7606_trigger_handler()
128 ret = ad7606_read_samples(st); in ad7606_trigger_handler()
130 iio_push_to_buffers_with_timestamp(indio_dev, st->data, in ad7606_trigger_handler()
135 gpiod_set_value(st->gpio_convst, 1); in ad7606_trigger_handler()
137 mutex_unlock(&st->lock); in ad7606_trigger_handler()
144 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_scan_direct() local
147 gpiod_set_value(st->gpio_convst, 1); in ad7606_scan_direct()
148 ret = wait_for_completion_timeout(&st->completion, in ad7606_scan_direct()
155 ret = ad7606_read_samples(st); in ad7606_scan_direct()
157 ret = st->data[ch]; in ad7606_scan_direct()
160 gpiod_set_value(st->gpio_convst, 0); in ad7606_scan_direct()
172 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_read_raw() local
188 if (st->sw_mode_en) in ad7606_read_raw()
191 *val2 = st->scale_avail[st->range[ch]]; in ad7606_read_raw()
194 *val = st->oversampling; in ad7606_read_raw()
220 struct ad7606_state *st = iio_priv(indio_dev); in in_voltage_scale_available_show() local
222 return ad7606_show_avail(buf, st->scale_avail, st->num_scales, true); in in_voltage_scale_available_show()
229 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_write_scale_hw() local
231 gpiod_set_value(st->gpio_range, val); in ad7606_write_scale_hw()
238 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_write_os_hw() local
243 gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc, in ad7606_write_os_hw()
244 st->gpio_os->info, values); in ad7606_write_os_hw()
247 if (st->chip_info->os_req_reset) in ad7606_write_os_hw()
248 ad7606_reset(st); in ad7606_write_os_hw()
259 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_write_raw() local
264 mutex_lock(&st->lock); in ad7606_write_raw()
265 i = find_closest(val2, st->scale_avail, st->num_scales); in ad7606_write_raw()
266 if (st->sw_mode_en) in ad7606_write_raw()
268 ret = st->write_scale(indio_dev, ch, i); in ad7606_write_raw()
270 mutex_unlock(&st->lock); in ad7606_write_raw()
273 st->range[ch] = i; in ad7606_write_raw()
274 mutex_unlock(&st->lock); in ad7606_write_raw()
280 i = find_closest(val, st->oversampling_avail, in ad7606_write_raw()
281 st->num_os_ratios); in ad7606_write_raw()
282 mutex_lock(&st->lock); in ad7606_write_raw()
283 ret = st->write_os(indio_dev, i); in ad7606_write_raw()
285 mutex_unlock(&st->lock); in ad7606_write_raw()
288 st->oversampling = st->oversampling_avail[i]; in ad7606_write_raw()
289 mutex_unlock(&st->lock); in ad7606_write_raw()
302 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_oversampling_ratio_avail() local
304 return ad7606_show_avail(buf, st->oversampling_avail, in ad7606_oversampling_ratio_avail()
305 st->num_os_ratios, false); in ad7606_oversampling_ratio_avail()
429 static int ad7606_request_gpios(struct ad7606_state *st) in ad7606_request_gpios() argument
431 struct device *dev = st->dev; in ad7606_request_gpios()
433 st->gpio_convst = devm_gpiod_get(dev, "adi,conversion-start", in ad7606_request_gpios()
435 if (IS_ERR(st->gpio_convst)) in ad7606_request_gpios()
436 return PTR_ERR(st->gpio_convst); in ad7606_request_gpios()
438 st->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in ad7606_request_gpios()
439 if (IS_ERR(st->gpio_reset)) in ad7606_request_gpios()
440 return PTR_ERR(st->gpio_reset); in ad7606_request_gpios()
442 st->gpio_range = devm_gpiod_get_optional(dev, "adi,range", in ad7606_request_gpios()
444 if (IS_ERR(st->gpio_range)) in ad7606_request_gpios()
445 return PTR_ERR(st->gpio_range); in ad7606_request_gpios()
447 st->gpio_standby = devm_gpiod_get_optional(dev, "standby", in ad7606_request_gpios()
449 if (IS_ERR(st->gpio_standby)) in ad7606_request_gpios()
450 return PTR_ERR(st->gpio_standby); in ad7606_request_gpios()
452 st->gpio_frstdata = devm_gpiod_get_optional(dev, "adi,first-data", in ad7606_request_gpios()
454 if (IS_ERR(st->gpio_frstdata)) in ad7606_request_gpios()
455 return PTR_ERR(st->gpio_frstdata); in ad7606_request_gpios()
457 if (!st->chip_info->oversampling_num) in ad7606_request_gpios()
460 st->gpio_os = devm_gpiod_get_array_optional(dev, in ad7606_request_gpios()
463 return PTR_ERR_OR_ZERO(st->gpio_os); in ad7606_request_gpios()
475 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_interrupt() local
478 gpiod_set_value(st->gpio_convst, 0); in ad7606_interrupt()
479 iio_trigger_poll_chained(st->trig); in ad7606_interrupt()
481 complete(&st->completion); in ad7606_interrupt()
490 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_validate_trigger() local
492 if (st->trig != trig) in ad7606_validate_trigger()
500 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_buffer_postenable() local
502 gpiod_set_value(st->gpio_convst, 1); in ad7606_buffer_postenable()
509 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_buffer_predisable() local
511 gpiod_set_value(st->gpio_convst, 0); in ad7606_buffer_predisable()
561 struct ad7606_state *st = data; in ad7606_regulator_disable() local
563 regulator_disable(st->reg); in ad7606_regulator_disable()
570 struct ad7606_state *st; in ad7606_probe() local
574 indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); in ad7606_probe()
578 st = iio_priv(indio_dev); in ad7606_probe()
581 st->dev = dev; in ad7606_probe()
582 mutex_init(&st->lock); in ad7606_probe()
583 st->bops = bops; in ad7606_probe()
584 st->base_address = base_address; in ad7606_probe()
586 st->range[0] = 0; in ad7606_probe()
587 st->oversampling = 1; in ad7606_probe()
588 st->scale_avail = ad7606_scale_avail; in ad7606_probe()
589 st->num_scales = ARRAY_SIZE(ad7606_scale_avail); in ad7606_probe()
591 st->reg = devm_regulator_get(dev, "avcc"); in ad7606_probe()
592 if (IS_ERR(st->reg)) in ad7606_probe()
593 return PTR_ERR(st->reg); in ad7606_probe()
595 ret = regulator_enable(st->reg); in ad7606_probe()
601 ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st); in ad7606_probe()
605 st->chip_info = &ad7606_chip_info_tbl[id]; in ad7606_probe()
607 if (st->chip_info->oversampling_num) { in ad7606_probe()
608 st->oversampling_avail = st->chip_info->oversampling_avail; in ad7606_probe()
609 st->num_os_ratios = st->chip_info->oversampling_num; in ad7606_probe()
612 ret = ad7606_request_gpios(st); in ad7606_probe()
616 if (st->gpio_os) { in ad7606_probe()
617 if (st->gpio_range) in ad7606_probe()
622 if (st->gpio_range) in ad7606_probe()
629 indio_dev->channels = st->chip_info->channels; in ad7606_probe()
630 indio_dev->num_channels = st->chip_info->num_channels; in ad7606_probe()
632 init_completion(&st->completion); in ad7606_probe()
634 ret = ad7606_reset(st); in ad7606_probe()
636 dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n"); in ad7606_probe()
639 if (st->chip_info->init_delay_ms) { in ad7606_probe()
640 if (msleep_interruptible(st->chip_info->init_delay_ms)) in ad7606_probe()
644 st->write_scale = ad7606_write_scale_hw; in ad7606_probe()
645 st->write_os = ad7606_write_os_hw; in ad7606_probe()
647 if (st->bops->sw_mode_config) in ad7606_probe()
648 st->sw_mode_en = device_property_present(st->dev, in ad7606_probe()
651 if (st->sw_mode_en) { in ad7606_probe()
653 st->scale_avail = ad7616_sw_scale_avail; in ad7606_probe()
654 st->num_scales = ARRAY_SIZE(ad7616_sw_scale_avail); in ad7606_probe()
657 memset32(st->range, 2, ARRAY_SIZE(st->range)); in ad7606_probe()
660 ret = st->bops->sw_mode_config(indio_dev); in ad7606_probe()
665 st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", in ad7606_probe()
667 if (!st->trig) in ad7606_probe()
670 st->trig->ops = &ad7606_trigger_ops; in ad7606_probe()
671 st->trig->dev.parent = dev; in ad7606_probe()
672 iio_trigger_set_drvdata(st->trig, indio_dev); in ad7606_probe()
673 ret = devm_iio_trigger_register(dev, st->trig); in ad7606_probe()
677 indio_dev->trig = iio_trigger_get(st->trig); in ad7606_probe()
703 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_suspend() local
705 if (st->gpio_standby) { in ad7606_suspend()
706 gpiod_set_value(st->gpio_range, 1); in ad7606_suspend()
707 gpiod_set_value(st->gpio_standby, 0); in ad7606_suspend()
716 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_resume() local
718 if (st->gpio_standby) { in ad7606_resume()
719 gpiod_set_value(st->gpio_range, st->range[0]); in ad7606_resume()
720 gpiod_set_value(st->gpio_standby, 1); in ad7606_resume()
721 ad7606_reset(st); in ad7606_resume()