Loading drivers/thermal/qpnp-adc-tm.c +83 −30 Original line number Original line Diff line number Diff line Loading @@ -168,6 +168,7 @@ #define QPNP_MIN_TIME 2000 #define QPNP_MIN_TIME 2000 #define QPNP_MAX_TIME 2100 #define QPNP_MAX_TIME 2100 #define QPNP_RETRY 25 struct qpnp_adc_thr_client_info { struct qpnp_adc_thr_client_info { struct list_head list; struct list_head list; Loading Loading @@ -378,11 +379,33 @@ static int32_t qpnp_adc_tm_enable_if_channel_meas( return rc; return rc; } } static int32_t qpnp_adc_tm_mode_select(struct qpnp_adc_tm_chip *chip, u8 mode_ctl) { int rc; mode_ctl |= (QPNP_ADC_TRIM_EN | QPNP_AMUX_TRIM_EN); /* VADC_BTM current sets mode to recurring measurements */ rc = qpnp_adc_tm_write_reg(chip, QPNP_MODE_CTL, mode_ctl); if (rc < 0) pr_err("adc-tm write mode selection err\n"); return rc; } static int32_t qpnp_adc_tm_req_sts_check(struct qpnp_adc_tm_chip *chip) static int32_t qpnp_adc_tm_req_sts_check(struct qpnp_adc_tm_chip *chip) { { u8 status1; u8 status1 = 0, mode_ctl = 0; int rc, count = 0; int rc, count = 0; /* Re-enable the peripheral */ rc = qpnp_adc_tm_enable(chip); if (rc) { pr_err("adc-tm re-enable peripheral failed\n"); return rc; } /* The VADC_TM bank needs to be disabled for new conversion request */ /* The VADC_TM bank needs to be disabled for new conversion request */ rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS1, &status1); rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS1, &status1); if (rc) { if (rc) { Loading @@ -391,17 +414,34 @@ static int32_t qpnp_adc_tm_req_sts_check(struct qpnp_adc_tm_chip *chip) } } /* Disable the bank if a conversion is occuring */ /* Disable the bank if a conversion is occuring */ while ((status1 & QPNP_STATUS1_REQ_STS) && (count < 5)) { while ((status1 & QPNP_STATUS1_REQ_STS) && (count < QPNP_RETRY)) { rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS1, &status1); if (rc < 0) pr_err("adc-tm disable failed\n"); /* Wait time is based on the optimum sampling rate /* Wait time is based on the optimum sampling rate * and adding enough time buffer to account for ADC conversions * and adding enough time buffer to account for ADC conversions * occuring on different peripheral banks */ * occuring on different peripheral banks */ usleep_range(QPNP_MIN_TIME, QPNP_MAX_TIME); usleep_range(QPNP_MIN_TIME, QPNP_MAX_TIME); rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS1, &status1); if (rc < 0) { pr_err("adc-tm disable failed\n"); return rc; } count++; count++; } } /* Change the mode back to recurring measurement mode */ mode_ctl = ADC_OP_MEASUREMENT_INTERVAL << QPNP_OP_MODE_SHIFT; rc = qpnp_adc_tm_mode_select(chip, mode_ctl); if (rc < 0) { pr_err("adc-tm mode change to recurring failed\n"); return rc; } /* Disable the peripheral */ rc = qpnp_adc_tm_disable(chip); if (rc < 0) { pr_err("adc-tm peripheral disable failed\n"); return rc; } return rc; return rc; } } Loading Loading @@ -452,20 +492,6 @@ static int32_t qpnp_adc_tm_check_revision(struct qpnp_adc_tm_chip *chip, return rc; return rc; } } static int32_t qpnp_adc_tm_mode_select(struct qpnp_adc_tm_chip *chip, u8 mode_ctl) { int rc; mode_ctl |= (QPNP_ADC_TRIM_EN | QPNP_AMUX_TRIM_EN); /* VADC_BTM current sets mode to recurring measurements */ rc = qpnp_adc_tm_write_reg(chip, QPNP_MODE_CTL, mode_ctl); if (rc < 0) pr_err("adc-tm write mode selection err\n"); return rc; } static int32_t qpnp_adc_tm_timer_interval_select( static int32_t qpnp_adc_tm_timer_interval_select( struct qpnp_adc_tm_chip *chip, uint32_t btm_chan, struct qpnp_adc_tm_chip *chip, uint32_t btm_chan, Loading Loading @@ -814,10 +840,18 @@ static int32_t qpnp_adc_tm_channel_configure(struct qpnp_adc_tm_chip *chip, static int32_t qpnp_adc_tm_configure(struct qpnp_adc_tm_chip *chip, static int32_t qpnp_adc_tm_configure(struct qpnp_adc_tm_chip *chip, struct qpnp_adc_amux_properties *chan_prop) struct qpnp_adc_amux_properties *chan_prop) { { u8 decimation = 0, op_cntrl = 0; u8 decimation = 0, op_cntrl = 0, mode_ctl = 0; int rc = 0; int rc = 0; uint32_t btm_chan = 0; uint32_t btm_chan = 0; /* Set measurement in single measurement mode */ mode_ctl = ADC_OP_NORMAL_MODE << QPNP_OP_MODE_SHIFT; rc = qpnp_adc_tm_mode_select(chip, mode_ctl); if (rc < 0) { pr_err("adc-tm single mode select failed\n"); return rc; } /* Disable bank */ /* Disable bank */ rc = qpnp_adc_tm_disable(chip); rc = qpnp_adc_tm_disable(chip); if (rc) if (rc) Loading @@ -830,13 +864,6 @@ static int32_t qpnp_adc_tm_configure(struct qpnp_adc_tm_chip *chip, return rc; return rc; } } /* Set measurement in recurring mode */ rc = qpnp_adc_tm_mode_select(chip, chan_prop->mode_sel); if (rc < 0) { pr_err("adc-tm mode select failed\n"); return rc; } /* Configure AMUX channel select for the corresponding BTM channel*/ /* Configure AMUX channel select for the corresponding BTM channel*/ btm_chan = chan_prop->chan_prop->tm_channel_select; btm_chan = chan_prop->chan_prop->tm_channel_select; rc = qpnp_adc_tm_write_reg(chip, btm_chan, chan_prop->amux_channel); rc = qpnp_adc_tm_write_reg(chip, btm_chan, chan_prop->amux_channel); Loading Loading @@ -932,7 +959,7 @@ static int qpnp_adc_tm_set_mode(struct thermal_zone_device *thermal, struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata; struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata; struct qpnp_adc_tm_chip *chip = adc_tm->chip; struct qpnp_adc_tm_chip *chip = adc_tm->chip; int rc = 0, channel; int rc = 0, channel; u8 sensor_mask = 0; u8 sensor_mask = 0, mode_ctl = 0; if (qpnp_adc_tm_is_valid(chip)) { if (qpnp_adc_tm_is_valid(chip)) { pr_err("invalid device\n"); pr_err("invalid device\n"); Loading Loading @@ -970,6 +997,14 @@ static int qpnp_adc_tm_set_mode(struct thermal_zone_device *thermal, } } } else if (mode == THERMAL_DEVICE_DISABLED) { } else if (mode == THERMAL_DEVICE_DISABLED) { sensor_mask = 1 << adc_tm->sensor_num; sensor_mask = 1 << adc_tm->sensor_num; mode_ctl = ADC_OP_NORMAL_MODE << QPNP_OP_MODE_SHIFT; rc = qpnp_adc_tm_mode_select(chip, mode_ctl); if (rc < 0) { pr_err("adc-tm single mode select failed\n"); return rc; } /* Disable bank */ /* Disable bank */ rc = qpnp_adc_tm_disable(chip); rc = qpnp_adc_tm_disable(chip); if (rc < 0) { if (rc < 0) { Loading Loading @@ -1539,6 +1574,11 @@ static void qpnp_adc_tm_high_thr_work(struct work_struct *work) static irqreturn_t qpnp_adc_tm_high_thr_isr(int irq, void *data) static irqreturn_t qpnp_adc_tm_high_thr_isr(int irq, void *data) { { struct qpnp_adc_tm_chip *chip = data; struct qpnp_adc_tm_chip *chip = data; u8 mode_ctl = 0; mode_ctl = ADC_OP_NORMAL_MODE << QPNP_OP_MODE_SHIFT; /* Set measurement in single measurement mode */ qpnp_adc_tm_mode_select(chip, mode_ctl); qpnp_adc_tm_disable(chip); qpnp_adc_tm_disable(chip); Loading @@ -1563,6 +1603,11 @@ static void qpnp_adc_tm_low_thr_work(struct work_struct *work) static irqreturn_t qpnp_adc_tm_low_thr_isr(int irq, void *data) static irqreturn_t qpnp_adc_tm_low_thr_isr(int irq, void *data) { { struct qpnp_adc_tm_chip *chip = data; struct qpnp_adc_tm_chip *chip = data; u8 mode_ctl = 0; mode_ctl = ADC_OP_NORMAL_MODE << QPNP_OP_MODE_SHIFT; /* Set measurement in single measurement mode */ qpnp_adc_tm_mode_select(chip, mode_ctl); qpnp_adc_tm_disable(chip); qpnp_adc_tm_disable(chip); Loading Loading @@ -1689,7 +1734,7 @@ int32_t qpnp_adc_tm_disable_chan_meas(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, btm_chan_num; uint32_t channel, dt_index = 0, btm_chan_num; u8 sensor_mask = 0; u8 sensor_mask = 0, mode_ctl = 0; int rc = 0; int rc = 0; if (qpnp_adc_tm_is_valid(chip)) if (qpnp_adc_tm_is_valid(chip)) Loading @@ -1697,6 +1742,14 @@ int32_t qpnp_adc_tm_disable_chan_meas(struct qpnp_adc_tm_chip *chip, mutex_lock(&chip->adc->adc_lock); mutex_lock(&chip->adc->adc_lock); /* Set measurement in single measurement mode */ mode_ctl = ADC_OP_NORMAL_MODE << QPNP_OP_MODE_SHIFT; rc = qpnp_adc_tm_mode_select(chip, mode_ctl); if (rc < 0) { pr_err("adc-tm single mode select failed\n"); goto fail; } /* Disable bank */ /* Disable bank */ rc = qpnp_adc_tm_disable(chip); rc = qpnp_adc_tm_disable(chip); if (rc < 0) { if (rc < 0) { Loading Loading
drivers/thermal/qpnp-adc-tm.c +83 −30 Original line number Original line Diff line number Diff line Loading @@ -168,6 +168,7 @@ #define QPNP_MIN_TIME 2000 #define QPNP_MIN_TIME 2000 #define QPNP_MAX_TIME 2100 #define QPNP_MAX_TIME 2100 #define QPNP_RETRY 25 struct qpnp_adc_thr_client_info { struct qpnp_adc_thr_client_info { struct list_head list; struct list_head list; Loading Loading @@ -378,11 +379,33 @@ static int32_t qpnp_adc_tm_enable_if_channel_meas( return rc; return rc; } } static int32_t qpnp_adc_tm_mode_select(struct qpnp_adc_tm_chip *chip, u8 mode_ctl) { int rc; mode_ctl |= (QPNP_ADC_TRIM_EN | QPNP_AMUX_TRIM_EN); /* VADC_BTM current sets mode to recurring measurements */ rc = qpnp_adc_tm_write_reg(chip, QPNP_MODE_CTL, mode_ctl); if (rc < 0) pr_err("adc-tm write mode selection err\n"); return rc; } static int32_t qpnp_adc_tm_req_sts_check(struct qpnp_adc_tm_chip *chip) static int32_t qpnp_adc_tm_req_sts_check(struct qpnp_adc_tm_chip *chip) { { u8 status1; u8 status1 = 0, mode_ctl = 0; int rc, count = 0; int rc, count = 0; /* Re-enable the peripheral */ rc = qpnp_adc_tm_enable(chip); if (rc) { pr_err("adc-tm re-enable peripheral failed\n"); return rc; } /* The VADC_TM bank needs to be disabled for new conversion request */ /* The VADC_TM bank needs to be disabled for new conversion request */ rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS1, &status1); rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS1, &status1); if (rc) { if (rc) { Loading @@ -391,17 +414,34 @@ static int32_t qpnp_adc_tm_req_sts_check(struct qpnp_adc_tm_chip *chip) } } /* Disable the bank if a conversion is occuring */ /* Disable the bank if a conversion is occuring */ while ((status1 & QPNP_STATUS1_REQ_STS) && (count < 5)) { while ((status1 & QPNP_STATUS1_REQ_STS) && (count < QPNP_RETRY)) { rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS1, &status1); if (rc < 0) pr_err("adc-tm disable failed\n"); /* Wait time is based on the optimum sampling rate /* Wait time is based on the optimum sampling rate * and adding enough time buffer to account for ADC conversions * and adding enough time buffer to account for ADC conversions * occuring on different peripheral banks */ * occuring on different peripheral banks */ usleep_range(QPNP_MIN_TIME, QPNP_MAX_TIME); usleep_range(QPNP_MIN_TIME, QPNP_MAX_TIME); rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS1, &status1); if (rc < 0) { pr_err("adc-tm disable failed\n"); return rc; } count++; count++; } } /* Change the mode back to recurring measurement mode */ mode_ctl = ADC_OP_MEASUREMENT_INTERVAL << QPNP_OP_MODE_SHIFT; rc = qpnp_adc_tm_mode_select(chip, mode_ctl); if (rc < 0) { pr_err("adc-tm mode change to recurring failed\n"); return rc; } /* Disable the peripheral */ rc = qpnp_adc_tm_disable(chip); if (rc < 0) { pr_err("adc-tm peripheral disable failed\n"); return rc; } return rc; return rc; } } Loading Loading @@ -452,20 +492,6 @@ static int32_t qpnp_adc_tm_check_revision(struct qpnp_adc_tm_chip *chip, return rc; return rc; } } static int32_t qpnp_adc_tm_mode_select(struct qpnp_adc_tm_chip *chip, u8 mode_ctl) { int rc; mode_ctl |= (QPNP_ADC_TRIM_EN | QPNP_AMUX_TRIM_EN); /* VADC_BTM current sets mode to recurring measurements */ rc = qpnp_adc_tm_write_reg(chip, QPNP_MODE_CTL, mode_ctl); if (rc < 0) pr_err("adc-tm write mode selection err\n"); return rc; } static int32_t qpnp_adc_tm_timer_interval_select( static int32_t qpnp_adc_tm_timer_interval_select( struct qpnp_adc_tm_chip *chip, uint32_t btm_chan, struct qpnp_adc_tm_chip *chip, uint32_t btm_chan, Loading Loading @@ -814,10 +840,18 @@ static int32_t qpnp_adc_tm_channel_configure(struct qpnp_adc_tm_chip *chip, static int32_t qpnp_adc_tm_configure(struct qpnp_adc_tm_chip *chip, static int32_t qpnp_adc_tm_configure(struct qpnp_adc_tm_chip *chip, struct qpnp_adc_amux_properties *chan_prop) struct qpnp_adc_amux_properties *chan_prop) { { u8 decimation = 0, op_cntrl = 0; u8 decimation = 0, op_cntrl = 0, mode_ctl = 0; int rc = 0; int rc = 0; uint32_t btm_chan = 0; uint32_t btm_chan = 0; /* Set measurement in single measurement mode */ mode_ctl = ADC_OP_NORMAL_MODE << QPNP_OP_MODE_SHIFT; rc = qpnp_adc_tm_mode_select(chip, mode_ctl); if (rc < 0) { pr_err("adc-tm single mode select failed\n"); return rc; } /* Disable bank */ /* Disable bank */ rc = qpnp_adc_tm_disable(chip); rc = qpnp_adc_tm_disable(chip); if (rc) if (rc) Loading @@ -830,13 +864,6 @@ static int32_t qpnp_adc_tm_configure(struct qpnp_adc_tm_chip *chip, return rc; return rc; } } /* Set measurement in recurring mode */ rc = qpnp_adc_tm_mode_select(chip, chan_prop->mode_sel); if (rc < 0) { pr_err("adc-tm mode select failed\n"); return rc; } /* Configure AMUX channel select for the corresponding BTM channel*/ /* Configure AMUX channel select for the corresponding BTM channel*/ btm_chan = chan_prop->chan_prop->tm_channel_select; btm_chan = chan_prop->chan_prop->tm_channel_select; rc = qpnp_adc_tm_write_reg(chip, btm_chan, chan_prop->amux_channel); rc = qpnp_adc_tm_write_reg(chip, btm_chan, chan_prop->amux_channel); Loading Loading @@ -932,7 +959,7 @@ static int qpnp_adc_tm_set_mode(struct thermal_zone_device *thermal, struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata; struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata; struct qpnp_adc_tm_chip *chip = adc_tm->chip; struct qpnp_adc_tm_chip *chip = adc_tm->chip; int rc = 0, channel; int rc = 0, channel; u8 sensor_mask = 0; u8 sensor_mask = 0, mode_ctl = 0; if (qpnp_adc_tm_is_valid(chip)) { if (qpnp_adc_tm_is_valid(chip)) { pr_err("invalid device\n"); pr_err("invalid device\n"); Loading Loading @@ -970,6 +997,14 @@ static int qpnp_adc_tm_set_mode(struct thermal_zone_device *thermal, } } } else if (mode == THERMAL_DEVICE_DISABLED) { } else if (mode == THERMAL_DEVICE_DISABLED) { sensor_mask = 1 << adc_tm->sensor_num; sensor_mask = 1 << adc_tm->sensor_num; mode_ctl = ADC_OP_NORMAL_MODE << QPNP_OP_MODE_SHIFT; rc = qpnp_adc_tm_mode_select(chip, mode_ctl); if (rc < 0) { pr_err("adc-tm single mode select failed\n"); return rc; } /* Disable bank */ /* Disable bank */ rc = qpnp_adc_tm_disable(chip); rc = qpnp_adc_tm_disable(chip); if (rc < 0) { if (rc < 0) { Loading Loading @@ -1539,6 +1574,11 @@ static void qpnp_adc_tm_high_thr_work(struct work_struct *work) static irqreturn_t qpnp_adc_tm_high_thr_isr(int irq, void *data) static irqreturn_t qpnp_adc_tm_high_thr_isr(int irq, void *data) { { struct qpnp_adc_tm_chip *chip = data; struct qpnp_adc_tm_chip *chip = data; u8 mode_ctl = 0; mode_ctl = ADC_OP_NORMAL_MODE << QPNP_OP_MODE_SHIFT; /* Set measurement in single measurement mode */ qpnp_adc_tm_mode_select(chip, mode_ctl); qpnp_adc_tm_disable(chip); qpnp_adc_tm_disable(chip); Loading @@ -1563,6 +1603,11 @@ static void qpnp_adc_tm_low_thr_work(struct work_struct *work) static irqreturn_t qpnp_adc_tm_low_thr_isr(int irq, void *data) static irqreturn_t qpnp_adc_tm_low_thr_isr(int irq, void *data) { { struct qpnp_adc_tm_chip *chip = data; struct qpnp_adc_tm_chip *chip = data; u8 mode_ctl = 0; mode_ctl = ADC_OP_NORMAL_MODE << QPNP_OP_MODE_SHIFT; /* Set measurement in single measurement mode */ qpnp_adc_tm_mode_select(chip, mode_ctl); qpnp_adc_tm_disable(chip); qpnp_adc_tm_disable(chip); Loading Loading @@ -1689,7 +1734,7 @@ int32_t qpnp_adc_tm_disable_chan_meas(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, btm_chan_num; uint32_t channel, dt_index = 0, btm_chan_num; u8 sensor_mask = 0; u8 sensor_mask = 0, mode_ctl = 0; int rc = 0; int rc = 0; if (qpnp_adc_tm_is_valid(chip)) if (qpnp_adc_tm_is_valid(chip)) Loading @@ -1697,6 +1742,14 @@ int32_t qpnp_adc_tm_disable_chan_meas(struct qpnp_adc_tm_chip *chip, mutex_lock(&chip->adc->adc_lock); mutex_lock(&chip->adc->adc_lock); /* Set measurement in single measurement mode */ mode_ctl = ADC_OP_NORMAL_MODE << QPNP_OP_MODE_SHIFT; rc = qpnp_adc_tm_mode_select(chip, mode_ctl); if (rc < 0) { pr_err("adc-tm single mode select failed\n"); goto fail; } /* Disable bank */ /* Disable bank */ rc = qpnp_adc_tm_disable(chip); rc = qpnp_adc_tm_disable(chip); if (rc < 0) { if (rc < 0) { Loading