Lines Matching refs:st
176 static int ad7625_set_sampling_freq(struct ad7625_state *st, u32 freq) in ad7625_set_sampling_freq() argument
189 cnv_wf.duty_length_ns = st->info->timing_spec->conv_high_ns; in ad7625_set_sampling_freq()
191 ret = pwm_round_waveform_might_sleep(st->cnv_pwm, &cnv_wf); in ad7625_set_sampling_freq()
202 st->info->chan_spec.scan_type.realbits, in ad7625_set_sampling_freq()
203 st->ref_clk_rate_hz); in ad7625_set_sampling_freq()
206 clk_gate_wf.duty_offset_ns = st->info->timing_spec->conv_msb_ns; in ad7625_set_sampling_freq()
208 ret = pwm_round_waveform_might_sleep(st->clk_gate_pwm, &clk_gate_wf); in ad7625_set_sampling_freq()
212 st->cnv_wf = cnv_wf; in ad7625_set_sampling_freq()
213 st->clk_gate_wf = clk_gate_wf; in ad7625_set_sampling_freq()
216 target = DIV_ROUND_CLOSEST(st->ref_clk_rate_hz, freq); in ad7625_set_sampling_freq()
217 st->sampling_freq_hz = DIV_ROUND_CLOSEST(st->ref_clk_rate_hz, in ad7625_set_sampling_freq()
227 struct ad7625_state *st = iio_priv(indio_dev); in ad7625_read_raw() local
231 *val = st->sampling_freq_hz; in ad7625_read_raw()
236 *val = st->vref_mv; in ad7625_read_raw()
250 struct ad7625_state *st = iio_priv(indio_dev); in ad7625_write_raw() local
255 return ad7625_set_sampling_freq(st, val); in ad7625_write_raw()
262 static int ad7625_parse_mode(struct device *dev, struct ad7625_state *st, in ad7625_parse_mode() argument
276 st->en_gpios[i] = devm_gpiod_get_optional(dev, en_gpio_buf, in ad7625_parse_mode()
278 if (IS_ERR(st->en_gpios[i])) in ad7625_parse_mode()
279 return dev_err_probe(dev, PTR_ERR(st->en_gpios[i]), in ad7625_parse_mode()
283 if (st->en_gpios[i] && en_always_on[i]) in ad7625_parse_mode()
288 en_may_be_on[i] = en_always_on[i] || st->en_gpios[i]; in ad7625_parse_mode()
289 en_always_off[i] = !en_always_on[i] && !st->en_gpios[i]; in ad7625_parse_mode()
296 st->can_power_down = en_may_be_off[1] && en_may_be_off[0] && in ad7625_parse_mode()
297 st->info->has_power_down_state; in ad7625_parse_mode()
302 st->can_refin = en_may_be_off[1] && en_may_be_on[0]; in ad7625_parse_mode()
304 st->can_ref_4v096 = en_may_be_on[1] && en_may_be_off[0]; in ad7625_parse_mode()
320 st->can_ref_5v = st->can_refin; in ad7625_parse_mode()
326 st->can_narrow_bandwidth = en_may_be_on[2]; in ad7625_parse_mode()
328 st->can_wide_bandwidth = en_may_be_off[2]; in ad7625_parse_mode()
330 st->can_snooze = en_may_be_on[1] && en_may_be_on[0]; in ad7625_parse_mode()
332 st->can_test_pattern = en_may_be_off[3] && en_may_be_on[2] && in ad7625_parse_mode()
339 static void ad7625_set_en_gpios_for_vref(struct ad7625_state *st, in ad7625_set_en_gpios_for_vref() argument
343 gpiod_set_value_cansleep(st->en_gpios[1], 0); in ad7625_set_en_gpios_for_vref()
344 gpiod_set_value_cansleep(st->en_gpios[0], 1); in ad7625_set_en_gpios_for_vref()
346 gpiod_set_value_cansleep(st->en_gpios[1], 1); in ad7625_set_en_gpios_for_vref()
347 gpiod_set_value_cansleep(st->en_gpios[0], 0); in ad7625_set_en_gpios_for_vref()
353 gpiod_set_value_cansleep(st->en_gpios[1], 1); in ad7625_set_en_gpios_for_vref()
354 gpiod_set_value_cansleep(st->en_gpios[0], 1); in ad7625_set_en_gpios_for_vref()
358 static int ad7960_set_mode(struct ad7625_state *st, enum ad7960_mode mode, in ad7960_set_mode() argument
363 if (!st->can_power_down) in ad7960_set_mode()
366 gpiod_set_value_cansleep(st->en_gpios[2], 0); in ad7960_set_mode()
367 gpiod_set_value_cansleep(st->en_gpios[1], 0); in ad7960_set_mode()
368 gpiod_set_value_cansleep(st->en_gpios[0], 0); in ad7960_set_mode()
373 if (!st->can_snooze) in ad7960_set_mode()
376 gpiod_set_value_cansleep(st->en_gpios[1], 1); in ad7960_set_mode()
377 gpiod_set_value_cansleep(st->en_gpios[0], 1); in ad7960_set_mode()
382 if (!st->can_narrow_bandwidth) in ad7960_set_mode()
385 gpiod_set_value_cansleep(st->en_gpios[2], 1); in ad7960_set_mode()
386 ad7625_set_en_gpios_for_vref(st, have_refin, ref_mv); in ad7960_set_mode()
391 if (!st->can_wide_bandwidth) in ad7960_set_mode()
394 gpiod_set_value_cansleep(st->en_gpios[2], 0); in ad7960_set_mode()
395 ad7625_set_en_gpios_for_vref(st, have_refin, ref_mv); in ad7960_set_mode()
400 if (!st->can_test_pattern) in ad7960_set_mode()
403 gpiod_set_value_cansleep(st->en_gpios[3], 0); in ad7960_set_mode()
404 gpiod_set_value_cansleep(st->en_gpios[2], 1); in ad7960_set_mode()
405 gpiod_set_value_cansleep(st->en_gpios[1], 0); in ad7960_set_mode()
406 gpiod_set_value_cansleep(st->en_gpios[0], 0); in ad7960_set_mode()
417 struct ad7625_state *st = iio_priv(indio_dev); in ad7625_buffer_preenable() local
420 ret = pwm_set_waveform_might_sleep(st->cnv_pwm, &st->cnv_wf, false); in ad7625_buffer_preenable()
424 ret = pwm_set_waveform_might_sleep(st->clk_gate_pwm, in ad7625_buffer_preenable()
425 &st->clk_gate_wf, false); in ad7625_buffer_preenable()
428 pwm_disable(st->cnv_pwm); in ad7625_buffer_preenable()
437 struct ad7625_state *st = iio_priv(indio_dev); in ad7625_buffer_postdisable() local
439 pwm_disable(st->clk_gate_pwm); in ad7625_buffer_postdisable()
440 pwm_disable(st->cnv_pwm); in ad7625_buffer_postdisable()
456 struct ad7625_state *st) in devm_ad7625_pwm_get() argument
461 st->cnv_pwm = devm_pwm_get(dev, "cnv"); in devm_ad7625_pwm_get()
462 if (IS_ERR(st->cnv_pwm)) in devm_ad7625_pwm_get()
463 return dev_err_probe(dev, PTR_ERR(st->cnv_pwm), in devm_ad7625_pwm_get()
467 pwm_disable(st->cnv_pwm); in devm_ad7625_pwm_get()
469 st->clk_gate_pwm = devm_pwm_get(dev, "clk_gate"); in devm_ad7625_pwm_get()
470 if (IS_ERR(st->clk_gate_pwm)) in devm_ad7625_pwm_get()
471 return dev_err_probe(dev, PTR_ERR(st->clk_gate_pwm), in devm_ad7625_pwm_get()
475 pwm_disable(st->clk_gate_pwm); in devm_ad7625_pwm_get()
487 st->ref_clk_rate_hz = ref_clk_rate_hz; in devm_ad7625_pwm_get()
508 struct ad7625_state *st) in devm_ad7625_regulator_setup() argument
528 st->have_refin = ret != -ENODEV; in devm_ad7625_regulator_setup()
530 if (st->have_refin && !st->can_refin) in devm_ad7625_regulator_setup()
534 if (!st->info->has_internal_vref && !st->have_refin && !ref_mv) in devm_ad7625_regulator_setup()
538 if (st->have_refin && ref_mv) in devm_ad7625_regulator_setup()
542 if (ref_mv == 4096 && !st->can_ref_4v096) in devm_ad7625_regulator_setup()
546 if (ref_mv == 5000 && !st->can_ref_5v) in devm_ad7625_regulator_setup()
550 st->vref_mv = ref_mv ?: AD7625_INTERNAL_REF_MV; in devm_ad7625_regulator_setup()
559 struct ad7625_state *st; in ad7625_probe() local
563 indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); in ad7625_probe()
567 st = iio_priv(indio_dev); in ad7625_probe()
569 st->info = device_get_match_data(dev); in ad7625_probe()
570 if (!st->info) in ad7625_probe()
577 if (st->info->has_bandwidth_control) in ad7625_probe()
578 ret = ad7625_parse_mode(dev, st, 4); in ad7625_probe()
580 ret = ad7625_parse_mode(dev, st, 2); in ad7625_probe()
585 ret = devm_ad7625_regulator_setup(dev, st); in ad7625_probe()
590 if (!st->info->has_bandwidth_control) { in ad7625_probe()
591 ad7625_set_en_gpios_for_vref(st, st->have_refin, st->vref_mv); in ad7625_probe()
597 if (st->can_wide_bandwidth) { in ad7625_probe()
598 ret = ad7960_set_mode(st, AD7960_MODE_WIDE_BANDWIDTH, in ad7625_probe()
599 st->have_refin, st->vref_mv); in ad7625_probe()
600 } else if (st->can_narrow_bandwidth) { in ad7625_probe()
601 ret = ad7960_set_mode(st, AD7960_MODE_NARROW_BANDWIDTH, in ad7625_probe()
602 st->have_refin, st->vref_mv); in ad7625_probe()
613 ret = devm_ad7625_pwm_get(dev, st); in ad7625_probe()
617 indio_dev->channels = &st->info->chan_spec; in ad7625_probe()
619 indio_dev->name = st->info->name; in ad7625_probe()
623 st->back = devm_iio_backend_get(dev, NULL); in ad7625_probe()
624 if (IS_ERR(st->back)) in ad7625_probe()
625 return dev_err_probe(dev, PTR_ERR(st->back), in ad7625_probe()
628 ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev); in ad7625_probe()
632 ret = devm_iio_backend_enable(dev, st->back); in ad7625_probe()
641 default_sample_freq = st->info->max_sample_freq_hz; in ad7625_probe()
642 if (st->info->has_bandwidth_control && !st->can_wide_bandwidth) in ad7625_probe()
645 ret = ad7625_set_sampling_freq(st, default_sample_freq); in ad7625_probe()