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",
228 struct iio_chan_spec const *chan, int *val) in axp20x_adc_raw() argument
238 if (chan->type == IIO_CURRENT && chan->channel == AXP20X_BATT_DISCHRG_I) in axp20x_adc_raw()
243 *val = axp20x_read_variable_width(info->regmap, chan->address, size); in axp20x_adc_raw()
251 struct iio_chan_spec const *chan, int *val) in axp22x_adc_raw() argument
261 if (chan->type == IIO_CURRENT && chan->channel == AXP22X_BATT_DISCHRG_I) in axp22x_adc_raw()
266 *val = axp20x_read_variable_width(info->regmap, chan->address, size); in axp22x_adc_raw()
274 struct iio_chan_spec const *chan, int *val) in axp813_adc_raw() argument
278 *val = axp20x_read_variable_width(info->regmap, chan->address, 12); in axp813_adc_raw()
311 return -EINVAL; in axp20x_adc_scale_voltage()
329 return -EINVAL; in axp813_adc_scale_voltage()
353 return -EINVAL; in axp20x_adc_scale_current()
357 static int axp20x_adc_scale(struct iio_chan_spec const *chan, int *val, in axp20x_adc_scale() argument
360 switch (chan->type) { in axp20x_adc_scale()
362 return axp20x_adc_scale_voltage(chan->channel, val, val2); in axp20x_adc_scale()
365 return axp20x_adc_scale_current(chan->channel, val, val2); in axp20x_adc_scale()
372 return -EINVAL; in axp20x_adc_scale()
376 static int axp22x_adc_scale(struct iio_chan_spec const *chan, int *val, in axp22x_adc_scale() argument
379 switch (chan->type) { in axp22x_adc_scale()
381 if (chan->channel != AXP22X_BATT_V) in axp22x_adc_scale()
382 return -EINVAL; in axp22x_adc_scale()
398 return -EINVAL; in axp22x_adc_scale()
402 static int axp813_adc_scale(struct iio_chan_spec const *chan, int *val, in axp813_adc_scale() argument
405 switch (chan->type) { in axp813_adc_scale()
407 return axp813_adc_scale_voltage(chan->channel, val, val2); in axp813_adc_scale()
418 return -EINVAL; in axp813_adc_scale()
428 ret = regmap_read(info->regmap, AXP20X_GPIO10_IN_RANGE, val); in axp20x_adc_offset_voltage()
442 return -EINVAL; in axp20x_adc_offset_voltage()
451 struct iio_chan_spec const *chan, int *val) in axp20x_adc_offset() argument
453 switch (chan->type) { in axp20x_adc_offset()
455 return axp20x_adc_offset_voltage(indio_dev, chan->channel, val); in axp20x_adc_offset()
458 *val = -1447; in axp20x_adc_offset()
462 return -EINVAL; in axp20x_adc_offset()
467 struct iio_chan_spec const *chan, int *val, in axp20x_read_raw() argument
472 return axp20x_adc_offset(indio_dev, chan, val); in axp20x_read_raw()
475 return axp20x_adc_scale(chan, val, val2); in axp20x_read_raw()
478 return axp20x_adc_raw(indio_dev, chan, val); in axp20x_read_raw()
481 return -EINVAL; in axp20x_read_raw()
486 struct iio_chan_spec const *chan, int *val, in axp22x_read_raw() argument
491 *val = -2677; in axp22x_read_raw()
495 return axp22x_adc_scale(chan, val, val2); in axp22x_read_raw()
498 return axp22x_adc_raw(indio_dev, chan, val); in axp22x_read_raw()
501 return -EINVAL; in axp22x_read_raw()
506 struct iio_chan_spec const *chan, int *val, in axp813_read_raw() argument
511 *val = -2667; in axp813_read_raw()
515 return axp813_adc_scale(chan, val, val2); in axp813_read_raw()
518 return axp813_adc_raw(indio_dev, chan, val); in axp813_read_raw()
521 return -EINVAL; in axp813_read_raw()
526 struct iio_chan_spec const *chan, int val, int val2, in axp20x_write_raw() argument
534 * for (independently) GPIO0 and GPIO1 when in ADC mode. in axp20x_write_raw()
537 return -EINVAL; in axp20x_write_raw()
540 return -EINVAL; in axp20x_write_raw()
544 switch (chan->channel) { in axp20x_write_raw()
556 return -EINVAL; in axp20x_write_raw()
559 return regmap_update_bits(info->regmap, AXP20X_GPIO10_IN_RANGE, reg, in axp20x_write_raw()
578 return regmap_update_bits(info->regmap, AXP20X_ADC_RATE, in axp20x_adc_rate()
585 return regmap_update_bits(info->regmap, AXP20X_ADC_RATE, in axp22x_adc_rate()
592 return regmap_update_bits(info->regmap, AXP813_ADC_RATE, in axp813_adc_rate()
639 { .compatible = "x-powers,axp209-adc", .data = (void *)&axp20x_data, },
640 { .compatible = "x-powers,axp221-adc", .data = (void *)&axp22x_data, },
641 { .compatible = "x-powers,axp813-adc", .data = (void *)&axp813_data, },
647 { .name = "axp20x-adc", .driver_data = (kernel_ulong_t)&axp20x_data, },
648 { .name = "axp22x-adc", .driver_data = (kernel_ulong_t)&axp22x_data, },
649 { .name = "axp813-adc", .driver_data = (kernel_ulong_t)&axp813_data, },
661 axp20x_dev = dev_get_drvdata(pdev->dev.parent); in axp20x_probe()
663 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info)); in axp20x_probe()
665 return -ENOMEM; in axp20x_probe()
670 info->regmap = axp20x_dev->regmap; in axp20x_probe()
671 indio_dev->modes = INDIO_DIRECT_MODE; in axp20x_probe()
673 if (!dev_fwnode(&pdev->dev)) { in axp20x_probe()
677 info->data = (const struct axp_data *)id->driver_data; in axp20x_probe()
679 struct device *dev = &pdev->dev; in axp20x_probe()
681 info->data = device_get_match_data(dev); in axp20x_probe()
684 indio_dev->name = platform_get_device_id(pdev)->name; in axp20x_probe()
685 indio_dev->info = info->data->iio_info; in axp20x_probe()
686 indio_dev->num_channels = info->data->num_channels; in axp20x_probe()
687 indio_dev->channels = info->data->channels; in axp20x_probe()
690 regmap_write(info->regmap, AXP20X_ADC_EN1, info->data->adc_en1_mask); in axp20x_probe()
692 if (info->data->adc_en2) in axp20x_probe()
694 regmap_update_bits(info->regmap, AXP20X_ADC_EN2, in axp20x_probe()
698 info->data->adc_rate(info, 100); in axp20x_probe()
700 ret = iio_map_array_register(indio_dev, info->data->maps); in axp20x_probe()
702 dev_err(&pdev->dev, "failed to register IIO maps: %d\n", ret); in axp20x_probe()
708 dev_err(&pdev->dev, "could not register the device\n"); in axp20x_probe()
718 regmap_write(info->regmap, AXP20X_ADC_EN1, 0); in axp20x_probe()
720 if (info->data->adc_en2) in axp20x_probe()
721 regmap_write(info->regmap, AXP20X_ADC_EN2, 0); in axp20x_probe()
734 regmap_write(info->regmap, AXP20X_ADC_EN1, 0); in axp20x_remove()
736 if (info->data->adc_en2) in axp20x_remove()
737 regmap_write(info->regmap, AXP20X_ADC_EN2, 0); in axp20x_remove()
744 .name = "axp20x-adc",
754 MODULE_DESCRIPTION("ADC driver for AXP20X and AXP22X PMICs");
755 MODULE_AUTHOR("Quentin Schulz <quentin.schulz@free-electrons.com>");