Lines Matching +full:fuel +full:- +full:gauge

1 // SPDX-License-Identifier: GPL-2.0-only
3 * axp288_adc.c - X-Powers AXP288 PMIC ADC Driver
23 * This mask enables all ADCs except for the battery temp-sensor (TS), that is
24 * left as-is to avoid breaking charging on devices without a temp-sensor.
104 IIO_MAP("TS_PIN", "axp288-batt", "axp288-batt-temp"),
105 IIO_MAP("PMIC_TEMP", "axp288-pmic", "axp288-pmic-temp"),
106 IIO_MAP("GPADC", "axp288-gpadc", "axp288-system-temp"),
107 IIO_MAP("BATT_CHG_I", "axp288-chrg", "axp288-chrg-curr"),
108 IIO_MAP("BATT_DISCHRG_I", "axp288-chrg", "axp288-chrg-d-curr"),
109 IIO_MAP("BATT_V", "axp288-batt", "axp288-batt-volt"),
119 return -EIO; in axp288_adc_read_channel()
126 * The current-source used for the battery temp-sensor (TS) is shared
127 * with the GPADC. For proper fuel-gauge and charger operation the TS
128 * current-source needs to be permanently on. But to read the GPADC we
129 * need to temporary switch the TS current-source to ondemand, so that
137 /* No need to switch the current-source if the TS pin is disabled */ in axp288_adc_set_ts()
138 if (!info->ts_enabled) in axp288_adc_set_ts()
145 ret = regmap_update_bits(info->regmap, AXP288_ADC_TS_PIN_CTRL, in axp288_adc_set_ts()
164 mutex_lock(&indio_dev->mlock); in axp288_adc_read_raw()
168 chan->address)) { in axp288_adc_read_raw()
169 dev_err(&indio_dev->dev, "GPADC mode\n"); in axp288_adc_read_raw()
170 ret = -EINVAL; in axp288_adc_read_raw()
173 ret = axp288_adc_read_channel(val, chan->address, info->regmap); in axp288_adc_read_raw()
175 chan->address)) in axp288_adc_read_raw()
176 dev_err(&indio_dev->dev, "TS pin restore\n"); in axp288_adc_read_raw()
179 ret = -EINVAL; in axp288_adc_read_raw()
181 mutex_unlock(&indio_dev->mlock); in axp288_adc_read_raw()
195 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 100S-11IBY"),
209 ret = regmap_update_bits(info->regmap, AXP288_ADC_TS_PIN_CTRL, in axp288_adc_initialize()
211 (uintptr_t)bias_override->driver_data); in axp288_adc_initialize()
217 * Determine if the TS pin is enabled and set the TS current-source in axp288_adc_initialize()
220 ret = regmap_read(info->regmap, AXP20X_ADC_EN1, &adc_enable_val); in axp288_adc_initialize()
225 info->ts_enabled = true; in axp288_adc_initialize()
226 ret = regmap_update_bits(info->regmap, AXP288_ADC_TS_PIN_CTRL, in axp288_adc_initialize()
230 info->ts_enabled = false; in axp288_adc_initialize()
231 ret = regmap_update_bits(info->regmap, AXP288_ADC_TS_PIN_CTRL, in axp288_adc_initialize()
239 return regmap_update_bits(info->regmap, AXP20X_ADC_EN1, in axp288_adc_initialize()
252 struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); in axp288_adc_probe()
254 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info)); in axp288_adc_probe()
256 return -ENOMEM; in axp288_adc_probe()
259 info->irq = platform_get_irq(pdev, 0); in axp288_adc_probe()
260 if (info->irq < 0) in axp288_adc_probe()
261 return info->irq; in axp288_adc_probe()
263 info->regmap = axp20x->regmap; in axp288_adc_probe()
266 * otherwise internal fuel gauge functionality may be affected. in axp288_adc_probe()
270 dev_err(&pdev->dev, "unable to enable ADC device\n"); in axp288_adc_probe()
274 indio_dev->name = pdev->name; in axp288_adc_probe()
275 indio_dev->channels = axp288_adc_channels; in axp288_adc_probe()
276 indio_dev->num_channels = ARRAY_SIZE(axp288_adc_channels); in axp288_adc_probe()
277 indio_dev->info = &axp288_adc_iio_info; in axp288_adc_probe()
278 indio_dev->modes = INDIO_DIRECT_MODE; in axp288_adc_probe()
285 dev_err(&pdev->dev, "unable to register iio device\n"); in axp288_adc_probe()
325 MODULE_DESCRIPTION("X-Powers AXP288 ADC Driver");