/* * This mask enables all ADCs except for the battery temp-sensor (TS), that is * left as-is to avoid breaking charging on devices without a temp-sensor.
*/ #define AXP288_ADC_EN_MASK 0xF0 #define AXP288_ADC_TS_ENABLE 0x01
struct axp288_adc_info { int irq; struct regmap *regmap; /* lock to protect against multiple access to the device */ struct mutex lock; bool ts_enabled;
};
/* * The current-source used for the battery temp-sensor (TS) is shared * with the GPADC. For proper fuel-gauge and charger operation the TS * current-source needs to be permanently on. But to read the GPADC we * need to temporary switch the TS current-source to ondemand, so that * the GPADC can use it, otherwise we will always read an all 0 value.
*/ staticint axp288_adc_set_ts(struct axp288_adc_info *info, unsignedint mode, unsignedlong address)
{ int ret;
/* No need to switch the current-source if the TS pin is disabled */ if (!info->ts_enabled) return 0;
/* Channels other than GPADC do not need the current source */ if (address != AXP288_GP_ADC_H) return 0;
ret = regmap_update_bits(info->regmap, AXP288_ADC_TS_PIN_CTRL,
AXP288_ADC_TS_CURRENT_ON_OFF_MASK, mode); if (ret) return ret;
/* When switching to the GPADC pin give things some time to settle */ if (mode == AXP288_ADC_TS_CURRENT_ON_ONDEMAND)
usleep_range(6000, 10000);
return 0;
}
staticint axp288_adc_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask)
{ int ret; struct axp288_adc_info *info = iio_priv(indio_dev);
mutex_lock(&info->lock); switch (mask) { case IIO_CHAN_INFO_RAW: if (axp288_adc_set_ts(info, AXP288_ADC_TS_CURRENT_ON_ONDEMAND,
chan->address)) {
dev_err(&indio_dev->dev, "GPADC mode\n");
ret = -EINVAL; break;
}
ret = axp288_adc_read_channel(val, chan->address, info->regmap); if (axp288_adc_set_ts(info, AXP288_ADC_TS_CURRENT_ON,
chan->address))
dev_err(&indio_dev->dev, "TS pin restore\n"); break; default:
ret = -EINVAL;
}
mutex_unlock(&info->lock);
return ret;
}
/* * We rely on the machine's firmware to correctly setup the TS pin bias current * at boot. This lists systems with broken fw where we need to set it ourselves.
*/ staticconststruct dmi_system_id axp288_adc_ts_bias_override[] = {
{ /* Lenovo Ideapad 100S (11 inch) */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 100S-11IBY"),
},
.driver_data = (void *)(uintptr_t)AXP288_ADC_TS_BIAS_80UA,
},
{ /* Nuvision Solo 10 Draw */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "TMAX"),
DMI_MATCH(DMI_PRODUCT_NAME, "TM101W610L"),
},
.driver_data = (void *)(uintptr_t)AXP288_ADC_TS_BIAS_80UA,
},
{ }
};
bias_override = dmi_first_match(axp288_adc_ts_bias_override); if (bias_override) {
ret = regmap_update_bits(info->regmap, AXP288_ADC_TS_PIN_CTRL,
AXP288_ADC_TS_BIAS_MASK,
(uintptr_t)bias_override->driver_data); if (ret) return ret;
}
/* * Determine if the TS pin is enabled and set the TS current-source * accordingly.
*/
ret = regmap_read(info->regmap, AXP20X_ADC_EN1, &adc_enable_val); if (ret) return ret;
if (adc_enable_val & AXP288_ADC_TS_ENABLE) {
info->ts_enabled = true;
ret = regmap_update_bits(info->regmap, AXP288_ADC_TS_PIN_CTRL,
AXP288_ADC_TS_CURRENT_ON_OFF_MASK,
AXP288_ADC_TS_CURRENT_ON);
} else {
info->ts_enabled = false;
ret = regmap_update_bits(info->regmap, AXP288_ADC_TS_PIN_CTRL,
AXP288_ADC_TS_CURRENT_ON_OFF_MASK,
AXP288_ADC_TS_CURRENT_OFF);
} if (ret) return ret;
/* Turn on the ADC for all channels except TS, leave TS as is */ return regmap_set_bits(info->regmap, AXP20X_ADC_EN1,
AXP288_ADC_EN_MASK);
}
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info)); if (!indio_dev) return -ENOMEM;
info = iio_priv(indio_dev);
info->irq = platform_get_irq(pdev, 0); if (info->irq < 0) return info->irq;
info->regmap = axp20x->regmap; /* * Set ADC to enabled state at all time, including system suspend. * otherwise internal fuel gauge functionality may be affected.
*/
ret = axp288_adc_initialize(info); if (ret) {
dev_err(&pdev->dev, "unable to enable ADC device\n"); return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.