Lines Matching +full:axp221 +full:- +full:adc

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* ADC driver for AXP20X and AXP22X PMICs
5 * Quentin Schulz <quentin.schulz@free-electrons.com>
160 .consumer_dev_name = "axp20x-usb-power-supply",
164 .consumer_dev_name = "axp20x-usb-power-supply",
168 .consumer_dev_name = "axp20x-ac-power-supply",
172 .consumer_dev_name = "axp20x-ac-power-supply",
176 .consumer_dev_name = "axp20x-battery-power-supply",
180 .consumer_dev_name = "axp20x-battery-power-supply",
184 .consumer_dev_name = "axp20x-battery-power-supply",
192 .consumer_dev_name = "axp20x-battery-power-supply",
196 .consumer_dev_name = "axp20x-battery-power-supply",
200 .consumer_dev_name = "axp20x-battery-power-supply",
208 .consumer_dev_name = "axp20x-usb-power-supply",
212 .consumer_dev_name = "axp20x-battery-power-supply",
216 .consumer_dev_name = "axp20x-battery-power-supply",
367 if (chan->type == IIO_CURRENT && in axp192_adc_raw()
368 (chan->channel == AXP192_BATT_CHRG_I || in axp192_adc_raw()
369 chan->channel == AXP192_BATT_DISCHRG_I)) in axp192_adc_raw()
374 ret = axp20x_read_variable_width(info->regmap, chan->address, size); in axp192_adc_raw()
393 if (chan->type == IIO_CURRENT && chan->channel == AXP20X_BATT_DISCHRG_I) in axp20x_adc_raw()
398 ret = axp20x_read_variable_width(info->regmap, chan->address, size); in axp20x_adc_raw()
412 ret = axp20x_read_variable_width(info->regmap, chan->address, 12); in axp22x_adc_raw()
428 * A generic "ADC data" channel is used for TS, tdie, vmid, in axp717_adc_raw()
432 switch (chan->channel) { in axp717_adc_raw()
434 regmap_write(info->regmap, AXP717_ADC_DATA_SEL, in axp717_adc_raw()
438 regmap_write(info->regmap, AXP717_ADC_DATA_SEL, in axp717_adc_raw()
442 regmap_write(info->regmap, AXP717_ADC_DATA_SEL, in axp717_adc_raw()
446 regmap_write(info->regmap, AXP717_ADC_DATA_SEL, in axp717_adc_raw()
455 * register reserved and the remaining bits as the ADC value. in axp717_adc_raw()
457 ret = regmap_bulk_read(info->regmap, chan->address, bulk_reg, 2); in axp717_adc_raw()
471 ret = axp20x_read_variable_width(info->regmap, chan->address, 12); in axp813_adc_raw()
513 return -EINVAL; in axp192_adc_scale_voltage()
549 return -EINVAL; in axp20x_adc_scale_voltage()
569 return -EINVAL; in axp22x_adc_scale_voltage()
592 return -EINVAL; in axp813_adc_scale_voltage()
616 return -EINVAL; in axp20x_adc_scale_current()
623 switch (chan->type) { in axp192_adc_scale()
625 return axp192_adc_scale_voltage(chan->channel, val, val2); in axp192_adc_scale()
630 * therefore we can re-use the scaling function. in axp192_adc_scale()
632 return axp20x_adc_scale_current(chan->channel, val, val2); in axp192_adc_scale()
639 return -EINVAL; in axp192_adc_scale()
646 switch (chan->type) { in axp20x_adc_scale()
648 return axp20x_adc_scale_voltage(chan->channel, val, val2); in axp20x_adc_scale()
651 return axp20x_adc_scale_current(chan->channel, val, val2); in axp20x_adc_scale()
658 return -EINVAL; in axp20x_adc_scale()
665 switch (chan->type) { in axp22x_adc_scale()
667 return axp22x_adc_scale_voltage(chan->channel, val, val2); in axp22x_adc_scale()
678 return -EINVAL; in axp22x_adc_scale()
685 switch (chan->type) { in axp717_adc_scale()
699 return -EINVAL; in axp717_adc_scale()
706 switch (chan->type) { in axp813_adc_scale()
708 return axp813_adc_scale_voltage(chan->channel, val, val2); in axp813_adc_scale()
719 return -EINVAL; in axp813_adc_scale()
730 ret = regmap_read(info->regmap, AXP192_GPIO30_IN_RANGE, &regval); in axp192_adc_offset_voltage()
752 return -EINVAL; in axp192_adc_offset_voltage()
766 ret = regmap_read(info->regmap, AXP20X_GPIO10_IN_RANGE, &regval); in axp20x_adc_offset_voltage()
780 return -EINVAL; in axp20x_adc_offset_voltage()
790 switch (chan->type) { in axp192_adc_offset()
792 return axp192_adc_offset_voltage(indio_dev, chan->channel, val); in axp192_adc_offset()
795 *val = -1447; in axp192_adc_offset()
799 return -EINVAL; in axp192_adc_offset()
806 switch (chan->type) { in axp20x_adc_offset()
808 return axp20x_adc_offset_voltage(indio_dev, chan->channel, val); in axp20x_adc_offset()
811 *val = -1447; in axp20x_adc_offset()
815 return -EINVAL; in axp20x_adc_offset()
834 return -EINVAL; in axp192_read_raw()
853 return -EINVAL; in axp20x_read_raw()
864 *val = -2677; in axp22x_read_raw()
874 return -EINVAL; in axp22x_read_raw()
890 return -EINVAL; in axp717_read_raw()
900 *val = -2667; in axp813_read_raw()
910 return -EINVAL; in axp813_read_raw()
923 * for (independently) GPIO0-3 when in ADC mode. in axp192_write_raw()
926 return -EINVAL; in axp192_write_raw()
929 return -EINVAL; in axp192_write_raw()
931 switch (chan->channel) { in axp192_write_raw()
953 return -EINVAL; in axp192_write_raw()
956 return regmap_update_bits(info->regmap, AXP192_GPIO30_IN_RANGE, regmask, regval); in axp192_write_raw()
968 * for (independently) GPIO0 and GPIO1 when in ADC mode. in axp20x_write_raw()
971 return -EINVAL; in axp20x_write_raw()
974 return -EINVAL; in axp20x_write_raw()
976 switch (chan->channel) { in axp20x_write_raw()
988 return -EINVAL; in axp20x_write_raw()
991 return regmap_update_bits(info->regmap, AXP20X_GPIO10_IN_RANGE, regmask, regval); in axp20x_write_raw()
1018 return regmap_update_bits(info->regmap, AXP20X_ADC_RATE, in axp20x_adc_rate()
1025 return regmap_update_bits(info->regmap, AXP20X_ADC_RATE, in axp22x_adc_rate()
1032 return regmap_update_bits(info->regmap, AXP813_ADC_RATE, in axp813_adc_rate()
1102 { .compatible = "x-powers,axp192-adc", .data = (void *)&axp192_data, },
1103 { .compatible = "x-powers,axp209-adc", .data = (void *)&axp20x_data, },
1104 { .compatible = "x-powers,axp221-adc", .data = (void *)&axp22x_data, },
1105 { .compatible = "x-powers,axp717-adc", .data = (void *)&axp717_data, },
1106 { .compatible = "x-powers,axp813-adc", .data = (void *)&axp813_data, },
1112 { .name = "axp192-adc", .driver_data = (kernel_ulong_t)&axp192_data, },
1113 { .name = "axp20x-adc", .driver_data = (kernel_ulong_t)&axp20x_data, },
1114 { .name = "axp22x-adc", .driver_data = (kernel_ulong_t)&axp22x_data, },
1115 { .name = "axp717-adc", .driver_data = (kernel_ulong_t)&axp717_data, },
1116 { .name = "axp813-adc", .driver_data = (kernel_ulong_t)&axp813_data, },
1128 axp20x_dev = dev_get_drvdata(pdev->dev.parent); in axp20x_probe()
1130 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info)); in axp20x_probe()
1132 return -ENOMEM; in axp20x_probe()
1137 info->regmap = axp20x_dev->regmap; in axp20x_probe()
1138 indio_dev->modes = INDIO_DIRECT_MODE; in axp20x_probe()
1140 if (!dev_fwnode(&pdev->dev)) { in axp20x_probe()
1144 info->data = (const struct axp_data *)id->driver_data; in axp20x_probe()
1146 struct device *dev = &pdev->dev; in axp20x_probe()
1148 info->data = device_get_match_data(dev); in axp20x_probe()
1151 indio_dev->name = platform_get_device_id(pdev)->name; in axp20x_probe()
1152 indio_dev->info = info->data->iio_info; in axp20x_probe()
1153 indio_dev->num_channels = info->data->num_channels; in axp20x_probe()
1154 indio_dev->channels = info->data->channels; in axp20x_probe()
1157 regmap_write(info->regmap, info->data->adc_en1, in axp20x_probe()
1158 info->data->adc_en1_mask); in axp20x_probe()
1160 if (info->data->adc_en2_mask) in axp20x_probe()
1161 regmap_set_bits(info->regmap, info->data->adc_en2, in axp20x_probe()
1162 info->data->adc_en2_mask); in axp20x_probe()
1165 if (info->data->adc_rate) in axp20x_probe()
1166 info->data->adc_rate(info, 100); in axp20x_probe()
1168 ret = iio_map_array_register(indio_dev, info->data->maps); in axp20x_probe()
1170 dev_err(&pdev->dev, "failed to register IIO maps: %d\n", ret); in axp20x_probe()
1176 dev_err(&pdev->dev, "could not register the device\n"); in axp20x_probe()
1186 regmap_write(info->regmap, info->data->adc_en1, 0); in axp20x_probe()
1188 if (info->data->adc_en2_mask) in axp20x_probe()
1189 regmap_write(info->regmap, info->data->adc_en2, 0); in axp20x_probe()
1202 regmap_write(info->regmap, info->data->adc_en1, 0); in axp20x_remove()
1204 if (info->data->adc_en2_mask) in axp20x_remove()
1205 regmap_write(info->regmap, info->data->adc_en2, 0); in axp20x_remove()
1210 .name = "axp20x-adc",
1220 MODULE_DESCRIPTION("ADC driver for AXP20X and AXP22X PMICs");
1221 MODULE_AUTHOR("Quentin Schulz <quentin.schulz@free-electrons.com>");