Lines Matching +full:adc +full:- +full:chan
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* ADC driver for AXP20X and AXP22X PMICs
5 * Quentin Schulz <quentin.schulz@free-electrons.com>
108 .consumer_dev_name = "axp20x-usb-power-supply",
112 .consumer_dev_name = "axp20x-usb-power-supply",
116 .consumer_dev_name = "axp20x-ac-power-supply",
120 .consumer_dev_name = "axp20x-ac-power-supply",
124 .consumer_dev_name = "axp20x-battery-power-supply",
128 .consumer_dev_name = "axp20x-battery-power-supply",
132 .consumer_dev_name = "axp20x-battery-power-supply",
140 .consumer_dev_name = "axp20x-battery-power-supply",
144 .consumer_dev_name = "axp20x-battery-power-supply",
148 .consumer_dev_name = "axp20x-battery-power-supply",
234 struct iio_chan_spec const *chan, int *val) in axp20x_adc_raw() argument
244 if (chan->type == IIO_CURRENT && chan->channel == AXP20X_BATT_DISCHRG_I) in axp20x_adc_raw()
249 *val = axp20x_read_variable_width(info->regmap, chan->address, size); in axp20x_adc_raw()
257 struct iio_chan_spec const *chan, int *val) in axp22x_adc_raw() argument
261 *val = axp20x_read_variable_width(info->regmap, chan->address, 12); in axp22x_adc_raw()
269 struct iio_chan_spec const *chan, int *val) in axp813_adc_raw() argument
273 *val = axp20x_read_variable_width(info->regmap, chan->address, 12); in axp813_adc_raw()
312 return -EINVAL; in axp20x_adc_scale_voltage()
332 return -EINVAL; in axp22x_adc_scale_voltage()
355 return -EINVAL; in axp813_adc_scale_voltage()
379 return -EINVAL; in axp20x_adc_scale_current()
383 static int axp20x_adc_scale(struct iio_chan_spec const *chan, int *val, in axp20x_adc_scale() argument
386 switch (chan->type) { in axp20x_adc_scale()
388 return axp20x_adc_scale_voltage(chan->channel, val, val2); in axp20x_adc_scale()
391 return axp20x_adc_scale_current(chan->channel, val, val2); in axp20x_adc_scale()
398 return -EINVAL; in axp20x_adc_scale()
402 static int axp22x_adc_scale(struct iio_chan_spec const *chan, int *val, in axp22x_adc_scale() argument
405 switch (chan->type) { in axp22x_adc_scale()
407 return axp22x_adc_scale_voltage(chan->channel, val, val2); in axp22x_adc_scale()
418 return -EINVAL; in axp22x_adc_scale()
422 static int axp813_adc_scale(struct iio_chan_spec const *chan, int *val, in axp813_adc_scale() argument
425 switch (chan->type) { in axp813_adc_scale()
427 return axp813_adc_scale_voltage(chan->channel, val, val2); in axp813_adc_scale()
438 return -EINVAL; in axp813_adc_scale()
448 ret = regmap_read(info->regmap, AXP20X_GPIO10_IN_RANGE, val); in axp20x_adc_offset_voltage()
462 return -EINVAL; in axp20x_adc_offset_voltage()
471 struct iio_chan_spec const *chan, int *val) in axp20x_adc_offset() argument
473 switch (chan->type) { in axp20x_adc_offset()
475 return axp20x_adc_offset_voltage(indio_dev, chan->channel, val); in axp20x_adc_offset()
478 *val = -1447; in axp20x_adc_offset()
482 return -EINVAL; in axp20x_adc_offset()
487 struct iio_chan_spec const *chan, int *val, in axp20x_read_raw() argument
492 return axp20x_adc_offset(indio_dev, chan, val); in axp20x_read_raw()
495 return axp20x_adc_scale(chan, val, val2); in axp20x_read_raw()
498 return axp20x_adc_raw(indio_dev, chan, val); in axp20x_read_raw()
501 return -EINVAL; in axp20x_read_raw()
506 struct iio_chan_spec const *chan, int *val, in axp22x_read_raw() argument
512 *val = -2677; in axp22x_read_raw()
516 return axp22x_adc_scale(chan, val, val2); in axp22x_read_raw()
519 return axp22x_adc_raw(indio_dev, chan, val); in axp22x_read_raw()
522 return -EINVAL; in axp22x_read_raw()
527 struct iio_chan_spec const *chan, int *val, in axp813_read_raw() argument
532 *val = -2667; in axp813_read_raw()
536 return axp813_adc_scale(chan, val, val2); in axp813_read_raw()
539 return axp813_adc_raw(indio_dev, chan, val); in axp813_read_raw()
542 return -EINVAL; in axp813_read_raw()
547 struct iio_chan_spec const *chan, int val, int val2, in axp20x_write_raw() argument
555 * for (independently) GPIO0 and GPIO1 when in ADC mode. in axp20x_write_raw()
558 return -EINVAL; in axp20x_write_raw()
561 return -EINVAL; in axp20x_write_raw()
565 switch (chan->channel) { in axp20x_write_raw()
577 return -EINVAL; in axp20x_write_raw()
580 return regmap_update_bits(info->regmap, AXP20X_GPIO10_IN_RANGE, reg, in axp20x_write_raw()
599 return regmap_update_bits(info->regmap, AXP20X_ADC_RATE, in axp20x_adc_rate()
606 return regmap_update_bits(info->regmap, AXP20X_ADC_RATE, in axp22x_adc_rate()
613 return regmap_update_bits(info->regmap, AXP813_ADC_RATE, in axp813_adc_rate()
660 { .compatible = "x-powers,axp209-adc", .data = (void *)&axp20x_data, },
661 { .compatible = "x-powers,axp221-adc", .data = (void *)&axp22x_data, },
662 { .compatible = "x-powers,axp813-adc", .data = (void *)&axp813_data, },
668 { .name = "axp20x-adc", .driver_data = (kernel_ulong_t)&axp20x_data, },
669 { .name = "axp22x-adc", .driver_data = (kernel_ulong_t)&axp22x_data, },
670 { .name = "axp813-adc", .driver_data = (kernel_ulong_t)&axp813_data, },
682 axp20x_dev = dev_get_drvdata(pdev->dev.parent); in axp20x_probe()
684 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info)); in axp20x_probe()
686 return -ENOMEM; in axp20x_probe()
691 info->regmap = axp20x_dev->regmap; in axp20x_probe()
692 indio_dev->modes = INDIO_DIRECT_MODE; in axp20x_probe()
694 if (!dev_fwnode(&pdev->dev)) { in axp20x_probe()
698 info->data = (const struct axp_data *)id->driver_data; in axp20x_probe()
700 struct device *dev = &pdev->dev; in axp20x_probe()
702 info->data = device_get_match_data(dev); in axp20x_probe()
705 indio_dev->name = platform_get_device_id(pdev)->name; in axp20x_probe()
706 indio_dev->info = info->data->iio_info; in axp20x_probe()
707 indio_dev->num_channels = info->data->num_channels; in axp20x_probe()
708 indio_dev->channels = info->data->channels; in axp20x_probe()
711 regmap_write(info->regmap, AXP20X_ADC_EN1, info->data->adc_en1_mask); in axp20x_probe()
713 if (info->data->adc_en2) in axp20x_probe()
715 regmap_update_bits(info->regmap, AXP20X_ADC_EN2, in axp20x_probe()
719 info->data->adc_rate(info, 100); in axp20x_probe()
721 ret = iio_map_array_register(indio_dev, info->data->maps); in axp20x_probe()
723 dev_err(&pdev->dev, "failed to register IIO maps: %d\n", ret); in axp20x_probe()
729 dev_err(&pdev->dev, "could not register the device\n"); in axp20x_probe()
739 regmap_write(info->regmap, AXP20X_ADC_EN1, 0); in axp20x_probe()
741 if (info->data->adc_en2) in axp20x_probe()
742 regmap_write(info->regmap, AXP20X_ADC_EN2, 0); in axp20x_probe()
755 regmap_write(info->regmap, AXP20X_ADC_EN1, 0); in axp20x_remove()
757 if (info->data->adc_en2) in axp20x_remove()
758 regmap_write(info->regmap, AXP20X_ADC_EN2, 0); in axp20x_remove()
765 .name = "axp20x-adc",
775 MODULE_DESCRIPTION("ADC driver for AXP20X and AXP22X PMICs");
776 MODULE_AUTHOR("Quentin Schulz <quentin.schulz@free-electrons.com>");