Lines Matching refs:st
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()
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()
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_nested(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()
564 struct ad7606_state *st; in ad7606_probe() local
568 indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); in ad7606_probe()
572 st = iio_priv(indio_dev); in ad7606_probe()
575 st->dev = dev; in ad7606_probe()
576 mutex_init(&st->lock); in ad7606_probe()
577 st->bops = bops; in ad7606_probe()
578 st->base_address = base_address; in ad7606_probe()
580 st->range[0] = 0; in ad7606_probe()
581 st->oversampling = 1; in ad7606_probe()
582 st->scale_avail = ad7606_scale_avail; in ad7606_probe()
583 st->num_scales = ARRAY_SIZE(ad7606_scale_avail); in ad7606_probe()
590 st->chip_info = &ad7606_chip_info_tbl[id]; in ad7606_probe()
592 if (st->chip_info->oversampling_num) { in ad7606_probe()
593 st->oversampling_avail = st->chip_info->oversampling_avail; in ad7606_probe()
594 st->num_os_ratios = st->chip_info->oversampling_num; in ad7606_probe()
597 ret = ad7606_request_gpios(st); in ad7606_probe()
601 if (st->gpio_os) { in ad7606_probe()
602 if (st->gpio_range) in ad7606_probe()
607 if (st->gpio_range) in ad7606_probe()
614 indio_dev->channels = st->chip_info->channels; in ad7606_probe()
615 indio_dev->num_channels = st->chip_info->num_channels; in ad7606_probe()
617 init_completion(&st->completion); in ad7606_probe()
619 ret = ad7606_reset(st); in ad7606_probe()
621 dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n"); in ad7606_probe()
624 if (st->chip_info->init_delay_ms) { in ad7606_probe()
625 if (msleep_interruptible(st->chip_info->init_delay_ms)) in ad7606_probe()
629 st->write_scale = ad7606_write_scale_hw; in ad7606_probe()
630 st->write_os = ad7606_write_os_hw; in ad7606_probe()
632 if (st->bops->sw_mode_config) in ad7606_probe()
633 st->sw_mode_en = device_property_present(st->dev, in ad7606_probe()
636 if (st->sw_mode_en) { in ad7606_probe()
638 st->scale_avail = ad7616_sw_scale_avail; in ad7606_probe()
639 st->num_scales = ARRAY_SIZE(ad7616_sw_scale_avail); in ad7606_probe()
642 memset32(st->range, 2, ARRAY_SIZE(st->range)); in ad7606_probe()
645 ret = st->bops->sw_mode_config(indio_dev); in ad7606_probe()
650 st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", in ad7606_probe()
653 if (!st->trig) in ad7606_probe()
656 st->trig->ops = &ad7606_trigger_ops; in ad7606_probe()
657 iio_trigger_set_drvdata(st->trig, indio_dev); in ad7606_probe()
658 ret = devm_iio_trigger_register(dev, st->trig); in ad7606_probe()
662 indio_dev->trig = iio_trigger_get(st->trig); in ad7606_probe()
688 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_suspend() local
690 if (st->gpio_standby) { in ad7606_suspend()
691 gpiod_set_value(st->gpio_range, 1); in ad7606_suspend()
692 gpiod_set_value(st->gpio_standby, 0); in ad7606_suspend()
701 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_resume() local
703 if (st->gpio_standby) { in ad7606_resume()
704 gpiod_set_value(st->gpio_range, st->range[0]); in ad7606_resume()
705 gpiod_set_value(st->gpio_standby, 1); in ad7606_resume()
706 ad7606_reset(st); in ad7606_resume()