Lines Matching refs:st
52 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()
70 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_reg_access() local
73 mutex_lock(&st->lock); in ad7606_reg_access()
75 ret = st->bops->reg_read(st, reg); in ad7606_reg_access()
81 ret = st->bops->reg_write(st, reg, writeval); in ad7606_reg_access()
84 mutex_unlock(&st->lock); in ad7606_reg_access()
88 static int ad7606_read_samples(struct ad7606_state *st) in ad7606_read_samples() argument
90 unsigned int num = st->chip_info->num_channels - 1; in ad7606_read_samples()
91 u16 *data = st->data; in ad7606_read_samples()
93 return st->bops->read_block(st->dev, num, data); in ad7606_read_samples()
100 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_trigger_handler() local
103 mutex_lock(&st->lock); in ad7606_trigger_handler()
105 ret = ad7606_read_samples(st); in ad7606_trigger_handler()
107 iio_push_to_buffers_with_timestamp(indio_dev, st->data, in ad7606_trigger_handler()
112 gpiod_set_value(st->gpio_convst, 1); in ad7606_trigger_handler()
114 mutex_unlock(&st->lock); in ad7606_trigger_handler()
121 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_scan_direct() local
124 gpiod_set_value(st->gpio_convst, 1); in ad7606_scan_direct()
125 ret = wait_for_completion_timeout(&st->completion, in ad7606_scan_direct()
132 ret = ad7606_read_samples(st); in ad7606_scan_direct()
134 ret = st->data[ch]; in ad7606_scan_direct()
137 gpiod_set_value(st->gpio_convst, 0); in ad7606_scan_direct()
149 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_read_raw() local
165 if (st->sw_mode_en) in ad7606_read_raw()
168 *val2 = st->scale_avail[st->range[ch]]; in ad7606_read_raw()
171 *val = st->oversampling; in ad7606_read_raw()
197 struct ad7606_state *st = iio_priv(indio_dev); in in_voltage_scale_available_show() local
199 return ad7606_show_avail(buf, st->scale_avail, st->num_scales, true); in in_voltage_scale_available_show()
206 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_write_scale_hw() local
208 gpiod_set_value(st->gpio_range, val); in ad7606_write_scale_hw()
215 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_write_os_hw() local
220 gpiod_set_array_value(st->gpio_os->ndescs, st->gpio_os->desc, in ad7606_write_os_hw()
221 st->gpio_os->info, values); in ad7606_write_os_hw()
224 if (st->chip_info->os_req_reset) in ad7606_write_os_hw()
225 ad7606_reset(st); in ad7606_write_os_hw()
236 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_write_raw() local
241 mutex_lock(&st->lock); in ad7606_write_raw()
242 i = find_closest(val2, st->scale_avail, st->num_scales); in ad7606_write_raw()
243 if (st->sw_mode_en) in ad7606_write_raw()
245 ret = st->write_scale(indio_dev, ch, i); in ad7606_write_raw()
247 mutex_unlock(&st->lock); in ad7606_write_raw()
250 st->range[ch] = i; in ad7606_write_raw()
251 mutex_unlock(&st->lock); in ad7606_write_raw()
257 i = find_closest(val, st->oversampling_avail, in ad7606_write_raw()
258 st->num_os_ratios); in ad7606_write_raw()
259 mutex_lock(&st->lock); in ad7606_write_raw()
260 ret = st->write_os(indio_dev, i); in ad7606_write_raw()
262 mutex_unlock(&st->lock); in ad7606_write_raw()
265 st->oversampling = st->oversampling_avail[i]; in ad7606_write_raw()
266 mutex_unlock(&st->lock); in ad7606_write_raw()
279 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_oversampling_ratio_avail() local
281 return ad7606_show_avail(buf, st->oversampling_avail, in ad7606_oversampling_ratio_avail()
282 st->num_os_ratios, false); in ad7606_oversampling_ratio_avail()
406 static int ad7606_request_gpios(struct ad7606_state *st) in ad7606_request_gpios() argument
408 struct device *dev = st->dev; in ad7606_request_gpios()
410 st->gpio_convst = devm_gpiod_get(dev, "adi,conversion-start", in ad7606_request_gpios()
412 if (IS_ERR(st->gpio_convst)) in ad7606_request_gpios()
413 return PTR_ERR(st->gpio_convst); in ad7606_request_gpios()
415 st->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in ad7606_request_gpios()
416 if (IS_ERR(st->gpio_reset)) in ad7606_request_gpios()
417 return PTR_ERR(st->gpio_reset); in ad7606_request_gpios()
419 st->gpio_range = devm_gpiod_get_optional(dev, "adi,range", in ad7606_request_gpios()
421 if (IS_ERR(st->gpio_range)) in ad7606_request_gpios()
422 return PTR_ERR(st->gpio_range); in ad7606_request_gpios()
424 st->gpio_standby = devm_gpiod_get_optional(dev, "standby", in ad7606_request_gpios()
426 if (IS_ERR(st->gpio_standby)) in ad7606_request_gpios()
427 return PTR_ERR(st->gpio_standby); in ad7606_request_gpios()
429 st->gpio_frstdata = devm_gpiod_get_optional(dev, "adi,first-data", in ad7606_request_gpios()
431 if (IS_ERR(st->gpio_frstdata)) in ad7606_request_gpios()
432 return PTR_ERR(st->gpio_frstdata); in ad7606_request_gpios()
434 if (!st->chip_info->oversampling_num) in ad7606_request_gpios()
437 st->gpio_os = devm_gpiod_get_array_optional(dev, in ad7606_request_gpios()
440 return PTR_ERR_OR_ZERO(st->gpio_os); in ad7606_request_gpios()
452 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_interrupt() local
455 gpiod_set_value(st->gpio_convst, 0); in ad7606_interrupt()
456 iio_trigger_poll_nested(st->trig); in ad7606_interrupt()
458 complete(&st->completion); in ad7606_interrupt()
467 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_validate_trigger() local
469 if (st->trig != trig) in ad7606_validate_trigger()
477 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_buffer_postenable() local
479 gpiod_set_value(st->gpio_convst, 1); in ad7606_buffer_postenable()
486 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_buffer_predisable() local
488 gpiod_set_value(st->gpio_convst, 0); in ad7606_buffer_predisable()
540 struct ad7606_state *st; in ad7606_probe() local
544 indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); in ad7606_probe()
548 st = iio_priv(indio_dev); in ad7606_probe()
551 st->dev = dev; in ad7606_probe()
552 mutex_init(&st->lock); in ad7606_probe()
553 st->bops = bops; in ad7606_probe()
554 st->base_address = base_address; in ad7606_probe()
556 st->range[0] = 0; in ad7606_probe()
557 st->oversampling = 1; in ad7606_probe()
558 st->scale_avail = ad7606_scale_avail; in ad7606_probe()
559 st->num_scales = ARRAY_SIZE(ad7606_scale_avail); in ad7606_probe()
566 st->chip_info = &ad7606_chip_info_tbl[id]; in ad7606_probe()
568 if (st->chip_info->oversampling_num) { in ad7606_probe()
569 st->oversampling_avail = st->chip_info->oversampling_avail; in ad7606_probe()
570 st->num_os_ratios = st->chip_info->oversampling_num; in ad7606_probe()
573 ret = ad7606_request_gpios(st); in ad7606_probe()
577 if (st->gpio_os) { in ad7606_probe()
578 if (st->gpio_range) in ad7606_probe()
583 if (st->gpio_range) in ad7606_probe()
590 indio_dev->channels = st->chip_info->channels; in ad7606_probe()
591 indio_dev->num_channels = st->chip_info->num_channels; in ad7606_probe()
593 init_completion(&st->completion); in ad7606_probe()
595 ret = ad7606_reset(st); in ad7606_probe()
597 dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n"); in ad7606_probe()
600 if (st->chip_info->init_delay_ms) { in ad7606_probe()
601 if (msleep_interruptible(st->chip_info->init_delay_ms)) in ad7606_probe()
605 st->write_scale = ad7606_write_scale_hw; in ad7606_probe()
606 st->write_os = ad7606_write_os_hw; in ad7606_probe()
608 if (st->bops->sw_mode_config) in ad7606_probe()
609 st->sw_mode_en = device_property_present(st->dev, in ad7606_probe()
612 if (st->sw_mode_en) { in ad7606_probe()
614 st->scale_avail = ad7616_sw_scale_avail; in ad7606_probe()
615 st->num_scales = ARRAY_SIZE(ad7616_sw_scale_avail); in ad7606_probe()
618 memset32(st->range, 2, ARRAY_SIZE(st->range)); in ad7606_probe()
621 ret = st->bops->sw_mode_config(indio_dev); in ad7606_probe()
626 st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", in ad7606_probe()
629 if (!st->trig) in ad7606_probe()
632 st->trig->ops = &ad7606_trigger_ops; in ad7606_probe()
633 iio_trigger_set_drvdata(st->trig, indio_dev); in ad7606_probe()
634 ret = devm_iio_trigger_register(dev, st->trig); in ad7606_probe()
638 indio_dev->trig = iio_trigger_get(st->trig); in ad7606_probe()
664 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_suspend() local
666 if (st->gpio_standby) { in ad7606_suspend()
667 gpiod_set_value(st->gpio_range, 1); in ad7606_suspend()
668 gpiod_set_value(st->gpio_standby, 1); in ad7606_suspend()
677 struct ad7606_state *st = iio_priv(indio_dev); in ad7606_resume() local
679 if (st->gpio_standby) { in ad7606_resume()
680 gpiod_set_value(st->gpio_range, st->range[0]); in ad7606_resume()
681 gpiod_set_value(st->gpio_standby, 1); in ad7606_resume()
682 ad7606_reset(st); in ad7606_resume()