Lines Matching +full:vdd1 +full:- +full:supply

1 // SPDX-License-Identifier: (GPL-2.0-only)
47 /* AD7625_CHAN_SPEC - Define a chan spec structure for a specific chip */
75 * Waveforms containing the last-requested and rounded
85 * EN2 controls the device -3dB bandwidth (and by extension, max
103 /* Indicate whether there is a REFIN supply connected */
189 cnv_wf.duty_length_ns = st->info->timing_spec->conv_high_ns;
191 ret = pwm_round_waveform_might_sleep(st->cnv_pwm, &cnv_wf);
202 st->info->chan_spec.scan_type.realbits,
203 st->ref_clk_rate_hz);
206 clk_gate_wf.duty_offset_ns = st->info->timing_spec->conv_msb_ns;
208 ret = pwm_round_waveform_might_sleep(st->clk_gate_pwm, &clk_gate_wf);
212 st->cnv_wf = cnv_wf;
213 st->clk_gate_wf = clk_gate_wf;
216 target = DIV_ROUND_CLOSEST(st->ref_clk_rate_hz, freq);
217 st->sampling_freq_hz = DIV_ROUND_CLOSEST(st->ref_clk_rate_hz,
231 *val = st->sampling_freq_hz;
236 *val = st->vref_mv;
237 *val2 = chan->scan_type.realbits - 1;
242 return -EINVAL;
256 return -EBUSY;
261 return -EINVAL;
277 "adi,en%d-always-on", i);
278 /* Set the device to 0b0000 (power-down mode) by default */
279 st->en_gpios[i] = devm_gpiod_get_optional(dev, en_gpio_buf,
281 if (IS_ERR(st->en_gpios[i]))
282 return dev_err_probe(dev, PTR_ERR(st->en_gpios[i]),
286 if (st->en_gpios[i] && en_always_on[i])
287 return dev_err_probe(dev, -EINVAL,
288 "cannot have adi,en%d-always-on and en%d-gpios\n", i, i);
291 en_may_be_on[i] = en_always_on[i] || st->en_gpios[i];
292 en_always_off[i] = !en_always_on[i] && !st->en_gpios[i];
299 st->can_power_down = en_may_be_off[1] && en_may_be_off[0] &&
300 st->info->has_power_down_state;
305 st->can_refin = en_may_be_off[1] && en_may_be_on[0];
307 st->can_ref_4v096 = en_may_be_on[1] && en_may_be_off[0];
309 /* Avoid AD796x-specific setup if the part is an AD762x */
316 return dev_err_probe(dev, -EINVAL,
323 st->can_ref_5v = st->can_refin;
326 * specified and not hard-wired, then we can configure it to
329 st->can_narrow_bandwidth = en_may_be_on[2];
331 st->can_wide_bandwidth = en_may_be_off[2];
333 st->can_snooze = en_may_be_on[1] && en_may_be_on[0];
335 st->can_test_pattern = en_may_be_off[3] && en_may_be_on[2] &&
346 gpiod_set_value_cansleep(st->en_gpios[1], 0);
347 gpiod_set_value_cansleep(st->en_gpios[0], 1);
349 gpiod_set_value_cansleep(st->en_gpios[1], 1);
350 gpiod_set_value_cansleep(st->en_gpios[0], 0);
356 gpiod_set_value_cansleep(st->en_gpios[1], 1);
357 gpiod_set_value_cansleep(st->en_gpios[0], 1);
366 if (!st->can_power_down)
367 return -EINVAL;
369 gpiod_set_value_cansleep(st->en_gpios[2], 0);
370 gpiod_set_value_cansleep(st->en_gpios[1], 0);
371 gpiod_set_value_cansleep(st->en_gpios[0], 0);
376 if (!st->can_snooze)
377 return -EINVAL;
379 gpiod_set_value_cansleep(st->en_gpios[1], 1);
380 gpiod_set_value_cansleep(st->en_gpios[0], 1);
385 if (!st->can_narrow_bandwidth)
386 return -EINVAL;
388 gpiod_set_value_cansleep(st->en_gpios[2], 1);
394 if (!st->can_wide_bandwidth)
395 return -EINVAL;
397 gpiod_set_value_cansleep(st->en_gpios[2], 0);
403 if (!st->can_test_pattern)
404 return -EINVAL;
406 gpiod_set_value_cansleep(st->en_gpios[3], 0);
407 gpiod_set_value_cansleep(st->en_gpios[2], 1);
408 gpiod_set_value_cansleep(st->en_gpios[1], 0);
409 gpiod_set_value_cansleep(st->en_gpios[0], 0);
414 return -EINVAL;
423 ret = pwm_set_waveform_might_sleep(st->cnv_pwm, &st->cnv_wf, false);
427 ret = pwm_set_waveform_might_sleep(st->clk_gate_pwm,
428 &st->clk_gate_wf, false);
431 pwm_disable(st->cnv_pwm);
442 pwm_disable(st->clk_gate_pwm);
443 pwm_disable(st->cnv_pwm);
464 st->cnv_pwm = devm_pwm_get(dev, "cnv");
465 if (IS_ERR(st->cnv_pwm))
466 return dev_err_probe(dev, PTR_ERR(st->cnv_pwm),
470 pwm_disable(st->cnv_pwm);
472 st->clk_gate_pwm = devm_pwm_get(dev, "clk_gate");
473 if (IS_ERR(st->clk_gate_pwm))
474 return dev_err_probe(dev, PTR_ERR(st->clk_gate_pwm),
478 pwm_disable(st->clk_gate_pwm);
487 return dev_err_probe(dev, -EINVAL,
490 st->ref_clk_rate_hz = ref_clk_rate_hz;
497 * conditionally-optional (depending on part) REF and REFIN voltages
500 * Power-up info for the device says to bring up vio, then vdd2, then
501 * vdd1, so list them in that order in the regulator_names array.
504 * - internal reference: neither REF or REFIN is connected (invalid for
506 * - internal buffer, external reference: REF not connected, REFIN
508 * - external reference: REF connected, REFIN not connected
513 static const char * const regulator_names[] = { "vio", "vdd2", "vdd1" };
522 if (ret < 0 && ret != -ENODEV)
525 ref_mv = ret == -ENODEV ? 0 : ret / 1000;
528 if (ret < 0 && ret != -ENODEV)
531 st->have_refin = ret != -ENODEV;
533 if (st->have_refin && !st->can_refin)
534 return dev_err_probe(dev, -EINVAL,
537 if (!st->info->has_internal_vref && !st->have_refin && !ref_mv)
538 return dev_err_probe(dev, -EINVAL,
541 if (st->have_refin && ref_mv)
542 return dev_err_probe(dev, -EINVAL,
545 if (ref_mv == 4096 && !st->can_ref_4v096)
546 return dev_err_probe(dev, -EINVAL,
549 if (ref_mv == 5000 && !st->can_ref_5v)
550 return dev_err_probe(dev, -EINVAL,
553 st->vref_mv = ref_mv ?: AD7625_INTERNAL_REF_MV;
560 struct device *dev = &pdev->dev;
568 return -ENOMEM;
572 st->info = device_get_match_data(dev);
573 if (!st->info)
574 return dev_err_probe(dev, -EINVAL, "no chip info\n");
576 if (device_property_read_bool(dev, "adi,no-dco"))
577 return dev_err_probe(dev, -EINVAL,
578 "self-clocked mode not supported\n");
580 if (st->info->has_bandwidth_control)
593 if (!st->info->has_bandwidth_control) {
594 ad7625_set_en_gpios_for_vref(st, st->have_refin, st->vref_mv);
600 if (st->can_wide_bandwidth) {
602 st->have_refin, st->vref_mv);
603 } else if (st->can_narrow_bandwidth) {
605 st->have_refin, st->vref_mv);
607 return dev_err_probe(dev, -EINVAL,
612 return dev_err_probe(dev, -EINVAL,
620 indio_dev->channels = &st->info->chan_spec;
621 indio_dev->num_channels = 1;
622 indio_dev->name = st->info->name;
623 indio_dev->info = &ad7625_info;
624 indio_dev->setup_ops = &ad7625_buffer_setup_ops;
626 st->back = devm_iio_backend_get(dev, NULL);
627 if (IS_ERR(st->back))
628 return dev_err_probe(dev, PTR_ERR(st->back),
631 ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev);
635 ret = devm_iio_backend_enable(dev, st->back);
644 default_sample_freq = st->info->max_sample_freq_hz;
645 if (st->info->has_bandwidth_control && !st->can_wide_bandwidth)