Loading drivers/hwmon/qpnp-adc-common.c +47 −4 Original line number Original line Diff line number Diff line Loading @@ -673,6 +673,35 @@ static int32_t qpnp_adc_map_temp_voltage(const struct qpnp_vadc_map_pt *pts, return 0; return 0; } } static int64_t qpnp_adc_scale_absolute_calib(int32_t adc_code, const struct qpnp_adc_properties *adc_properties, const struct qpnp_vadc_chan_properties *chan_properties) { int64_t adc_voltage = 0; bool negative_offset = 0; if (!chan_properties || !chan_properties->offset_gain_numerator || !chan_properties->offset_gain_denominator || !adc_properties) return -EINVAL; adc_voltage = (adc_code - chan_properties->adc_graph[CALIB_ABSOLUTE].adc_gnd) * chan_properties->adc_graph[chan_properties->calib_type].dx; if (adc_voltage < 0) { negative_offset = 1; adc_voltage = -adc_voltage; } do_div(adc_voltage, chan_properties->adc_graph[CALIB_ABSOLUTE].dy); if (negative_offset) adc_voltage = -adc_voltage; adc_voltage += chan_properties->adc_graph[CALIB_ABSOLUTE].dx; return adc_voltage; } static int64_t qpnp_adc_scale_ratiometric_calib(int32_t adc_code, static int64_t qpnp_adc_scale_ratiometric_calib(int32_t adc_code, const struct qpnp_adc_properties *adc_properties, const struct qpnp_adc_properties *adc_properties, const struct qpnp_vadc_chan_properties *chan_properties) const struct qpnp_vadc_chan_properties *chan_properties) Loading Loading @@ -813,9 +842,14 @@ int32_t qpnp_adc_tdkntcg_therm(struct qpnp_vadc_chip *chip, || !adc_chan_result) || !adc_chan_result) return -EINVAL; return -EINVAL; if (chan_properties->calib_type == CALIB_ABSOLUTE) { xo_thm = qpnp_adc_scale_absolute_calib(adc_code, adc_properties, chan_properties); do_div(xo_thm , 1000); } else { xo_thm = qpnp_adc_scale_ratiometric_calib(adc_code, xo_thm = qpnp_adc_scale_ratiometric_calib(adc_code, adc_properties, chan_properties); adc_properties, chan_properties); } qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb, qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb, ARRAY_SIZE(adcmap_100k_104ef_104fb), ARRAY_SIZE(adcmap_100k_104ef_104fb), xo_thm, &adc_chan_result->physical); xo_thm, &adc_chan_result->physical); Loading Loading @@ -992,9 +1026,14 @@ int32_t qpnp_adc_scale_therm_pu2(struct qpnp_vadc_chip *chip, { { int64_t therm_voltage = 0; int64_t therm_voltage = 0; if (chan_properties->calib_type == CALIB_ABSOLUTE) { therm_voltage = qpnp_adc_scale_absolute_calib(adc_code, adc_properties, chan_properties); do_div(therm_voltage , 1000); } else { therm_voltage = qpnp_adc_scale_ratiometric_calib(adc_code, therm_voltage = qpnp_adc_scale_ratiometric_calib(adc_code, adc_properties, chan_properties); adc_properties, chan_properties); } qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb, qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb, ARRAY_SIZE(adcmap_100k_104ef_104fb), ARRAY_SIZE(adcmap_100k_104ef_104fb), therm_voltage, &adc_chan_result->physical); therm_voltage, &adc_chan_result->physical); Loading Loading @@ -1690,6 +1729,10 @@ int qpnp_adc_get_revid_version(struct device *dev) (revid_data->pmic_type == PM8909_V1P1_TYPE) && (revid_data->pmic_type == PM8909_V1P1_TYPE) && (revid_data->pmic_subtype == PM8909_V1P1_SUBTYPE)) (revid_data->pmic_subtype == PM8909_V1P1_SUBTYPE)) return QPNP_REV_ID_8909_1_1; return QPNP_REV_ID_8909_1_1; else if ((revid_data->rev4 == PM8950_V1P0_REV4) && (revid_data->pmic_type == PM8950_V1P0_TYPE) && (revid_data->pmic_subtype == PM8950_V1P0_SUBTYPE)) return QPNP_REV_ID_PM8950_1_0; else else return -EINVAL; return -EINVAL; } } Loading drivers/hwmon/qpnp-adc-voltage.c +25 −0 Original line number Original line Diff line number Diff line Loading @@ -659,6 +659,28 @@ static int32_t qpnp_vadc_version_check(struct qpnp_vadc_chip *dev) return 0; return 0; } } static int32_t qpnp_vadc_channel_post_scaling_calib_check(struct qpnp_vadc_chip *vadc, int channel) { int version, rc = 0; version = qpnp_adc_get_revid_version(vadc->dev); if (version == QPNP_REV_ID_PM8950_1_0) { if ((channel == LR_MUX7_HW_ID) || (channel == P_MUX2_1_1) || (channel == LR_MUX3_XO_THERM) || (channel == LR_MUX3_BUF_XO_THERM_BUF)) { vadc->adc->amux_prop->chan_prop->calib_type = CALIB_ABSOLUTE; return rc; } } return -EINVAL; } #define QPNP_VBAT_COEFF_1 3000 #define QPNP_VBAT_COEFF_1 3000 #define QPNP_VBAT_COEFF_2 45810000 #define QPNP_VBAT_COEFF_2 45810000 #define QPNP_VBAT_COEFF_3 100000 #define QPNP_VBAT_COEFF_3 100000 Loading Loading @@ -1707,6 +1729,9 @@ recalibrate: goto fail_unlock; goto fail_unlock; } } if ((qpnp_vadc_channel_post_scaling_calib_check(vadc, channel)) < 0) pr_debug("Post scaling calib type not updated\n"); vadc_scale_fn[scale_type].chan(vadc, result->adc_code, vadc_scale_fn[scale_type].chan(vadc, result->adc_code, vadc->adc->adc_prop, vadc->adc->amux_prop->chan_prop, result); vadc->adc->adc_prop, vadc->adc->amux_prop->chan_prop, result); Loading drivers/thermal/qpnp-adc-tm.c +11 −1 Original line number Original line Diff line number Diff line Loading @@ -2019,7 +2019,7 @@ int32_t qpnp_adc_tm_channel_measure(struct qpnp_adc_tm_chip *chip, struct qpnp_adc_tm_btm_param *param) struct qpnp_adc_tm_btm_param *param) { { uint32_t channel, dt_index = 0, scale_type = 0; uint32_t channel, dt_index = 0, scale_type = 0; int rc = 0, i = 0; int rc = 0, i = 0, version = 0; bool chan_found = false; bool chan_found = false; if (qpnp_adc_tm_is_valid(chip)) { if (qpnp_adc_tm_is_valid(chip)) { Loading @@ -2035,6 +2035,16 @@ int32_t qpnp_adc_tm_channel_measure(struct qpnp_adc_tm_chip *chip, mutex_lock(&chip->adc->adc_lock); mutex_lock(&chip->adc->adc_lock); channel = param->channel; channel = param->channel; if (channel == VSYS) { version = qpnp_adc_get_revid_version(chip->dev); if (version == QPNP_REV_ID_PM8950_1_0) { pr_debug("Channel not supported\n"); rc = -EINVAL; goto fail_unlock; } } while (i < chip->max_channels_available) { while (i < chip->max_channels_available) { if (chip->adc->adc_channels[i].channel_num == if (chip->adc->adc_channels[i].channel_num == channel) { channel) { Loading include/linux/qpnp/qpnp-adc.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -1098,6 +1098,7 @@ struct qpnp_adc_amux_properties { #define QPNP_REV_ID_8916_2_0 12 #define QPNP_REV_ID_8916_2_0 12 #define QPNP_REV_ID_8909_1_0 13 #define QPNP_REV_ID_8909_1_0 13 #define QPNP_REV_ID_8909_1_1 14 #define QPNP_REV_ID_8909_1_1 14 #define QPNP_REV_ID_PM8950_1_0 16 /* Public API */ /* Public API */ #if defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE) \ #if defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE) \ Loading include/linux/qpnp/qpnp-revid.h +8 −0 Original line number Original line Diff line number Diff line Loading @@ -146,6 +146,14 @@ #define PMI8994_V2P0_TYPE 0x51 #define PMI8994_V2P0_TYPE 0x51 #define PMI8994_V2P0_SUBTYPE 0x0A #define PMI8994_V2P0_SUBTYPE 0x0A #define PM8950_V1P0_REV4 0x01 #define PM8950_V1P0_TYPE 0x51 #define PM8950_V1P0_SUBTYPE 0x10 #define PM8950_V2P0_REV4 0x02 #define PM8950_V2P0_TYPE 0x51 #define PM8950_V2P0_SUBTYPE 0x10 struct pmic_revid_data { struct pmic_revid_data { u8 rev1; u8 rev1; u8 rev2; u8 rev2; Loading Loading
drivers/hwmon/qpnp-adc-common.c +47 −4 Original line number Original line Diff line number Diff line Loading @@ -673,6 +673,35 @@ static int32_t qpnp_adc_map_temp_voltage(const struct qpnp_vadc_map_pt *pts, return 0; return 0; } } static int64_t qpnp_adc_scale_absolute_calib(int32_t adc_code, const struct qpnp_adc_properties *adc_properties, const struct qpnp_vadc_chan_properties *chan_properties) { int64_t adc_voltage = 0; bool negative_offset = 0; if (!chan_properties || !chan_properties->offset_gain_numerator || !chan_properties->offset_gain_denominator || !adc_properties) return -EINVAL; adc_voltage = (adc_code - chan_properties->adc_graph[CALIB_ABSOLUTE].adc_gnd) * chan_properties->adc_graph[chan_properties->calib_type].dx; if (adc_voltage < 0) { negative_offset = 1; adc_voltage = -adc_voltage; } do_div(adc_voltage, chan_properties->adc_graph[CALIB_ABSOLUTE].dy); if (negative_offset) adc_voltage = -adc_voltage; adc_voltage += chan_properties->adc_graph[CALIB_ABSOLUTE].dx; return adc_voltage; } static int64_t qpnp_adc_scale_ratiometric_calib(int32_t adc_code, static int64_t qpnp_adc_scale_ratiometric_calib(int32_t adc_code, const struct qpnp_adc_properties *adc_properties, const struct qpnp_adc_properties *adc_properties, const struct qpnp_vadc_chan_properties *chan_properties) const struct qpnp_vadc_chan_properties *chan_properties) Loading Loading @@ -813,9 +842,14 @@ int32_t qpnp_adc_tdkntcg_therm(struct qpnp_vadc_chip *chip, || !adc_chan_result) || !adc_chan_result) return -EINVAL; return -EINVAL; if (chan_properties->calib_type == CALIB_ABSOLUTE) { xo_thm = qpnp_adc_scale_absolute_calib(adc_code, adc_properties, chan_properties); do_div(xo_thm , 1000); } else { xo_thm = qpnp_adc_scale_ratiometric_calib(adc_code, xo_thm = qpnp_adc_scale_ratiometric_calib(adc_code, adc_properties, chan_properties); adc_properties, chan_properties); } qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb, qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb, ARRAY_SIZE(adcmap_100k_104ef_104fb), ARRAY_SIZE(adcmap_100k_104ef_104fb), xo_thm, &adc_chan_result->physical); xo_thm, &adc_chan_result->physical); Loading Loading @@ -992,9 +1026,14 @@ int32_t qpnp_adc_scale_therm_pu2(struct qpnp_vadc_chip *chip, { { int64_t therm_voltage = 0; int64_t therm_voltage = 0; if (chan_properties->calib_type == CALIB_ABSOLUTE) { therm_voltage = qpnp_adc_scale_absolute_calib(adc_code, adc_properties, chan_properties); do_div(therm_voltage , 1000); } else { therm_voltage = qpnp_adc_scale_ratiometric_calib(adc_code, therm_voltage = qpnp_adc_scale_ratiometric_calib(adc_code, adc_properties, chan_properties); adc_properties, chan_properties); } qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb, qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb, ARRAY_SIZE(adcmap_100k_104ef_104fb), ARRAY_SIZE(adcmap_100k_104ef_104fb), therm_voltage, &adc_chan_result->physical); therm_voltage, &adc_chan_result->physical); Loading Loading @@ -1690,6 +1729,10 @@ int qpnp_adc_get_revid_version(struct device *dev) (revid_data->pmic_type == PM8909_V1P1_TYPE) && (revid_data->pmic_type == PM8909_V1P1_TYPE) && (revid_data->pmic_subtype == PM8909_V1P1_SUBTYPE)) (revid_data->pmic_subtype == PM8909_V1P1_SUBTYPE)) return QPNP_REV_ID_8909_1_1; return QPNP_REV_ID_8909_1_1; else if ((revid_data->rev4 == PM8950_V1P0_REV4) && (revid_data->pmic_type == PM8950_V1P0_TYPE) && (revid_data->pmic_subtype == PM8950_V1P0_SUBTYPE)) return QPNP_REV_ID_PM8950_1_0; else else return -EINVAL; return -EINVAL; } } Loading
drivers/hwmon/qpnp-adc-voltage.c +25 −0 Original line number Original line Diff line number Diff line Loading @@ -659,6 +659,28 @@ static int32_t qpnp_vadc_version_check(struct qpnp_vadc_chip *dev) return 0; return 0; } } static int32_t qpnp_vadc_channel_post_scaling_calib_check(struct qpnp_vadc_chip *vadc, int channel) { int version, rc = 0; version = qpnp_adc_get_revid_version(vadc->dev); if (version == QPNP_REV_ID_PM8950_1_0) { if ((channel == LR_MUX7_HW_ID) || (channel == P_MUX2_1_1) || (channel == LR_MUX3_XO_THERM) || (channel == LR_MUX3_BUF_XO_THERM_BUF)) { vadc->adc->amux_prop->chan_prop->calib_type = CALIB_ABSOLUTE; return rc; } } return -EINVAL; } #define QPNP_VBAT_COEFF_1 3000 #define QPNP_VBAT_COEFF_1 3000 #define QPNP_VBAT_COEFF_2 45810000 #define QPNP_VBAT_COEFF_2 45810000 #define QPNP_VBAT_COEFF_3 100000 #define QPNP_VBAT_COEFF_3 100000 Loading Loading @@ -1707,6 +1729,9 @@ recalibrate: goto fail_unlock; goto fail_unlock; } } if ((qpnp_vadc_channel_post_scaling_calib_check(vadc, channel)) < 0) pr_debug("Post scaling calib type not updated\n"); vadc_scale_fn[scale_type].chan(vadc, result->adc_code, vadc_scale_fn[scale_type].chan(vadc, result->adc_code, vadc->adc->adc_prop, vadc->adc->amux_prop->chan_prop, result); vadc->adc->adc_prop, vadc->adc->amux_prop->chan_prop, result); Loading
drivers/thermal/qpnp-adc-tm.c +11 −1 Original line number Original line Diff line number Diff line Loading @@ -2019,7 +2019,7 @@ int32_t qpnp_adc_tm_channel_measure(struct qpnp_adc_tm_chip *chip, struct qpnp_adc_tm_btm_param *param) struct qpnp_adc_tm_btm_param *param) { { uint32_t channel, dt_index = 0, scale_type = 0; uint32_t channel, dt_index = 0, scale_type = 0; int rc = 0, i = 0; int rc = 0, i = 0, version = 0; bool chan_found = false; bool chan_found = false; if (qpnp_adc_tm_is_valid(chip)) { if (qpnp_adc_tm_is_valid(chip)) { Loading @@ -2035,6 +2035,16 @@ int32_t qpnp_adc_tm_channel_measure(struct qpnp_adc_tm_chip *chip, mutex_lock(&chip->adc->adc_lock); mutex_lock(&chip->adc->adc_lock); channel = param->channel; channel = param->channel; if (channel == VSYS) { version = qpnp_adc_get_revid_version(chip->dev); if (version == QPNP_REV_ID_PM8950_1_0) { pr_debug("Channel not supported\n"); rc = -EINVAL; goto fail_unlock; } } while (i < chip->max_channels_available) { while (i < chip->max_channels_available) { if (chip->adc->adc_channels[i].channel_num == if (chip->adc->adc_channels[i].channel_num == channel) { channel) { Loading
include/linux/qpnp/qpnp-adc.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -1098,6 +1098,7 @@ struct qpnp_adc_amux_properties { #define QPNP_REV_ID_8916_2_0 12 #define QPNP_REV_ID_8916_2_0 12 #define QPNP_REV_ID_8909_1_0 13 #define QPNP_REV_ID_8909_1_0 13 #define QPNP_REV_ID_8909_1_1 14 #define QPNP_REV_ID_8909_1_1 14 #define QPNP_REV_ID_PM8950_1_0 16 /* Public API */ /* Public API */ #if defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE) \ #if defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE) \ Loading
include/linux/qpnp/qpnp-revid.h +8 −0 Original line number Original line Diff line number Diff line Loading @@ -146,6 +146,14 @@ #define PMI8994_V2P0_TYPE 0x51 #define PMI8994_V2P0_TYPE 0x51 #define PMI8994_V2P0_SUBTYPE 0x0A #define PMI8994_V2P0_SUBTYPE 0x0A #define PM8950_V1P0_REV4 0x01 #define PM8950_V1P0_TYPE 0x51 #define PM8950_V1P0_SUBTYPE 0x10 #define PM8950_V2P0_REV4 0x02 #define PM8950_V2P0_TYPE 0x51 #define PM8950_V2P0_SUBTYPE 0x10 struct pmic_revid_data { struct pmic_revid_data { u8 rev1; u8 rev1; u8 rev2; u8 rev2; Loading