static int isl_read_adc(int channel, int *mv_reading) { int ret; void *h; struct adc_chan_result adc_chan_result; struct completion conv_complete_evt; pr_debug("%s: called for %d\n", __func__, channel); ret = adc_channel_open(channel, &h); if (ret) { pr_err("%s: couldnt open channel %d ret=%d\n", __func__, channel, ret); goto out; } init_completion(&conv_complete_evt); ret = adc_channel_request_conv(h, &conv_complete_evt); if (ret) { pr_err("%s: couldnt request conv channel %d ret=%d\n", __func__, channel, ret); goto out; } ret = wait_for_completion_interruptible(&conv_complete_evt); if (ret) { pr_err("%s: wait interrupted channel %d ret=%d\n", __func__, channel, ret); goto out; } ret = adc_channel_read_result(h, &adc_chan_result); if (ret) { pr_err("%s: couldnt read result channel %d ret=%d\n", __func__, channel, ret); goto out; } ret = adc_channel_close(h); if (ret) pr_err("%s: couldnt close channel %d ret=%d\n", __func__, channel, ret); if (mv_reading) *mv_reading = (int)adc_chan_result.measurement; pr_debug("%s: done for %d\n", __func__, channel); return adc_chan_result.physical; out: *mv_reading = 0; pr_debug("%s: done with error for %d\n", __func__, channel); return -EINVAL; }
static void switch_work_f(struct work_struct *work) { #if 0 int rc, i; u32 res = 0; struct adc_chan_result adc_result; struct pm8058_othc *dd = container_of(work, struct pm8058_othc, switch_work); DECLARE_COMPLETION_ONSTACK(adc_wait); u8 num_adc_samples = dd->switch_config->num_adc_samples; /* sleep for settling time */ msleep(dd->switch_config->voltage_settling_time_ms); for (i = 0; i < num_adc_samples; i++) { rc = adc_channel_request_conv(dd->adc_handle, &adc_wait); if (rc) { pr_err("adc_channel_request_conv failed\n"); goto bail_out; } rc = wait_for_completion_interruptible(&adc_wait); if (rc) { pr_err("wait_for_completion_interruptible failed\n"); goto bail_out; } rc = adc_channel_read_result(dd->adc_handle, &adc_result); if (rc) { pr_err("adc_channel_read_result failed\n"); goto bail_out; } res += adc_result.physical; } bail_out: if (i == num_adc_samples && num_adc_samples != 0) { res /= num_adc_samples; othc_report_switch(dd, res); } else pr_err("Insufficient ADC samples\n"); enable_irq(dd->othc_irq_sw); #endif }
static int check_analog_mpp(int channel,int *mv_reading) // read adc value { int ret; void *h; struct adc_chan_result adc_chan_result; struct completion conv_complete_evt; dbg_func_in(); ret = adc_channel_open(channel, &h); if (ret) { pr_err("%s: couldnt open channel %d ret=%d\n", __func__, channel, ret); goto out; } init_completion(&conv_complete_evt); ret = adc_channel_request_conv(h, &conv_complete_evt); if (ret) { pr_err("%s: couldnt request conv channel %d ret=%d\n", __func__, channel, ret); goto out; } wait_for_completion(&conv_complete_evt); ret = adc_channel_read_result(h, &adc_chan_result); if (ret) { pr_err("%s: couldnt read result channel %d ret=%d\n", __func__, channel, ret); goto out; } ret = adc_channel_close(h); if (ret) { pr_err("%s: couldnt close channel %d ret=%d\n", __func__, channel, ret); } if (mv_reading) *mv_reading = adc_chan_result.measurement; pr_debug("%s: done for %d\n", __func__, channel); dbg_func_out(); return adc_chan_result.physical; out: pr_debug("%s: done for %d\n", __func__, channel); return -EINVAL; }
static int accessory_adc_detect(struct pm8058_othc *dd, int accessory) { int rc; u32 res; struct adc_chan_result accessory_adc_result; DECLARE_COMPLETION_ONSTACK(accessory_adc_wait); rc = adc_channel_request_conv(dd->accessory_adc_handle, &accessory_adc_wait); if (rc) { pr_err("adc_channel_request_conv failed\n"); goto adc_failed; } rc = wait_for_completion_interruptible(&accessory_adc_wait); if (rc) { pr_err("wait_for_completion_interruptible failed\n"); goto adc_failed; } rc = adc_channel_read_result(dd->accessory_adc_handle, &accessory_adc_result); if (rc) { pr_err("adc_channel_read_result failed\n"); goto adc_failed; } res = accessory_adc_result.physical; if (res >= dd->accessory_info[accessory].adc_thres.min_threshold && res <= dd->accessory_info[accessory].adc_thres.max_threshold) { pr_debug("Accessory on ADC detected!, ADC Value = %u\n", res); return 1; } adc_failed: return 0; }
static int pm8058_tz_get_temp(struct thermal_zone_device *thermal, unsigned long *temp) { struct pm8058_tm_device *tm = thermal->devdata; DECLARE_COMPLETION_ONSTACK(wait); struct adc_chan_result adc_result = { .physical = 0lu, }; int rc; if (!tm || !temp) return -EINVAL; *temp = tm->temp; rc = adc_channel_request_conv(tm->adc_handle, &wait); if (rc < 0) { pr_err("%s: adc_channel_request_conv() failed, rc = %d\n", __func__, rc); return rc; } wait_for_completion(&wait); rc = adc_channel_read_result(tm->adc_handle, &adc_result); if (rc < 0) { pr_err("%s: adc_channel_read_result() failed, rc = %d\n", __func__, rc); return rc; } *temp = adc_result.physical; tm->temp = adc_result.physical; return 0; } static int pm8058_tz_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) { struct pm8058_tm_device *tm = thermal->devdata; if (!tm || !mode) return -EINVAL; *mode = tm->mode; return 0; } static int pm8058_tz_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct pm8058_tm_device *tm = thermal->devdata; if (!tm) return -EINVAL; if (mode != tm->mode) { if (mode == THERMAL_DEVICE_ENABLED) pm8058_tm_shutdown_override(tm->pm_chip, SOFTWARE_OVERRIDE_ENABLED); else pm8058_tm_shutdown_override(tm->pm_chip, SOFTWARE_OVERRIDE_DISABLED); } tm->mode = mode; return 0; } static int pm8058_tz_get_trip_type(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) { struct pm8058_tm_device *tm = thermal->devdata; if (!tm || trip < 0 || !type) return -EINVAL; switch (trip) { case PM8058_TRIP_STAGE3: *type = THERMAL_TRIP_CRITICAL; break; case PM8058_TRIP_STAGE2: *type = THERMAL_TRIP_HOT; break; case PM8058_TRIP_STAGE1: *type = THERMAL_TRIP_HOT; break; default: return -EINVAL; } return 0; } static int pm8058_tz_get_trip_temp(struct thermal_zone_device *thermal, int trip, unsigned long *temp) { struct pm8058_tm_device *tm = thermal->devdata; int thresh_temp; if (!tm || trip < 0 || !temp) return -EINVAL; thresh_temp = tm->thresh * PM8058_TEMP_THRESH_STEP + PM8058_TEMP_THRESH_MIN; switch (trip) { case PM8058_TRIP_STAGE3: thresh_temp += 2 * PM8058_TEMP_STAGE_STEP; break; case PM8058_TRIP_STAGE2: thresh_temp += PM8058_TEMP_STAGE_STEP; break; case PM8058_TRIP_STAGE1: break; default: return -EINVAL; } *temp = thresh_temp; return 0; } static int pm8058_tz_get_crit_temp(struct thermal_zone_device *thermal, unsigned long *temp) { struct pm8058_tm_device *tm = thermal->devdata; if (!tm || !temp) return -EINVAL; *temp = tm->thresh * PM8058_TEMP_THRESH_STEP + PM8058_TEMP_THRESH_MIN + 2 * PM8058_TEMP_STAGE_STEP; return 0; } static struct thermal_zone_device_ops pm8058_thermal_zone_ops = { .get_temp = pm8058_tz_get_temp, .get_mode = pm8058_tz_get_mode, .set_mode = pm8058_tz_set_mode, .get_trip_type = pm8058_tz_get_trip_type, .get_trip_temp = pm8058_tz_get_trip_temp, .get_crit_temp = pm8058_tz_get_crit_temp, }; static irqreturn_t pm8058_tm_isr(int irq, void *data) { struct pm8058_tm_device *tm = data; int rc; u8 reg; rc = pm8058_tm_read_ctrl(tm->pm_chip, ®); if (rc < 0) goto isr_handled; tm->stage = (reg & PM8058_TEMP_STATUS_MASK) >> PM8058_TEMP_STATUS_SHIFT; tm->thresh = (reg & PM8058_TEMP_THRESH_MASK) >> PM8058_TEMP_THRESH_SHIFT; if (reg & (PM8058_TEMP_ST2_SD | PM8058_TEMP_ST3_SD)) { reg &= ~(PM8058_TEMP_ST2_SD | PM8058_TEMP_ST3_SD | PM8058_TEMP_STATUS_MASK); pm8058_tm_write_ctrl(tm->pm_chip, reg); } thermal_zone_device_update(tm->tz_dev); /* Notify user space */ if (tm->mode == THERMAL_DEVICE_ENABLED) kobject_uevent(&tm->tz_dev->device.kobj, KOBJ_CHANGE); isr_handled: return IRQ_HANDLED; } static int pm8058_tm_init_reg(struct pm8058_tm_device *tm) { int rc; u8 reg; rc = pm8058_tm_read_ctrl(tm->pm_chip, ®); if (rc < 0) return rc; tm->stage = (reg & PM8058_TEMP_STATUS_MASK) >> PM8058_TEMP_STATUS_SHIFT; tm->temp = 0; /* Use temperature threshold set 0: (105, 125, 145) */ tm->thresh = 0; reg = (tm->thresh << PM8058_TEMP_THRESH_SHIFT) & PM8058_TEMP_THRESH_MASK; rc = pm8058_tm_write_ctrl(tm->pm_chip, reg); if (rc < 0) return rc; /* * Set the PMIC alarm module PWM to have a frequency of 8 Hz. This * helps cut down on the number of unnecessary interrupts fired when * changing between thermal stages. Also, Enable the over temperature * PWM whenever the PMIC is enabled. */ reg = 1 << PM8058_TEMP_PWM_EN_SHIFT | 3 << PM8058_TEMP_PWM_PER_PRE_SHIFT | 3 << PM8058_TEMP_PWM_PER_DIV_SHIFT; rc = pm8058_tm_write_pwm(tm->pm_chip, reg); return rc; }
static int pm8xxx_tz_get_temp_pm8058_adc(struct thermal_zone_device *thermal, unsigned long *temp) { struct pm8xxx_tm_chip *chip = thermal->devdata; DECLARE_COMPLETION_ONSTACK(wait); struct adc_chan_result adc_result = { .physical = 0lu, }; int rc; if (!chip || !temp) return -EINVAL; *temp = chip->temp; rc = adc_channel_request_conv(chip->adc_handle, &wait); if (rc < 0) { pr_err("%s: adc_channel_request_conv() failed, rc = %d\n", __func__, rc); return rc; } wait_for_completion(&wait); rc = adc_channel_read_result(chip->adc_handle, &adc_result); if (rc < 0) { pr_err("%s: adc_channel_read_result() failed, rc = %d\n", __func__, rc); return rc; } *temp = adc_result.physical; chip->temp = adc_result.physical; return 0; } static int pm8xxx_tz_get_temp_pm8xxx_adc(struct thermal_zone_device *thermal, unsigned long *temp) { struct pm8xxx_tm_chip *chip = thermal->devdata; struct pm8xxx_adc_chan_result result = { .physical = 0lu, }; int rc; if (!chip || !temp) return -EINVAL; *temp = chip->temp; rc = pm8xxx_adc_read(chip->cdata.adc_channel, &result); if (rc < 0) { pr_err("%s: adc_channel_read_result() failed, rc = %d\n", chip->cdata.tm_name, rc); return rc; } *temp = result.physical; chip->temp = result.physical; return 0; } static int pm8xxx_tz_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) { struct pm8xxx_tm_chip *chip = thermal->devdata; if (!chip || !mode) return -EINVAL; *mode = chip->mode; return 0; } static int pm8xxx_tz_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct pm8xxx_tm_chip *chip = thermal->devdata; if (!chip) return -EINVAL; /* Mask software override requests if they are not allowed. */ if (!chip->cdata.allow_software_override) mode = THERMAL_DEVICE_DISABLED; if (mode != chip->mode) { if (mode == THERMAL_DEVICE_ENABLED) pm8xxx_tm_shutdown_override(chip, SOFTWARE_OVERRIDE_ENABLED); else pm8xxx_tm_shutdown_override(chip, SOFTWARE_OVERRIDE_DISABLED); } chip->mode = mode; return 0; } static int pm8xxx_tz_get_trip_type(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) { if (trip < 0 || !type) return -EINVAL; switch (trip) { case TRIP_STAGE3: *type = THERMAL_TRIP_CRITICAL; break; case TRIP_STAGE2: *type = THERMAL_TRIP_HOT; break; case TRIP_STAGE1: *type = THERMAL_TRIP_HOT; break; default: return -EINVAL; } return 0; } static int pm8xxx_tz_get_trip_temp(struct thermal_zone_device *thermal, int trip, unsigned long *temp) { struct pm8xxx_tm_chip *chip = thermal->devdata; int thresh_temp; if (!chip || trip < 0 || !temp) return -EINVAL; thresh_temp = chip->thresh * TEMP_THRESH_STEP + TEMP_THRESH_MIN; switch (trip) { case TRIP_STAGE3: thresh_temp += 2 * TEMP_STAGE_STEP; break; case TRIP_STAGE2: thresh_temp += TEMP_STAGE_STEP; break; case TRIP_STAGE1: break; default: return -EINVAL; } *temp = thresh_temp; return 0; } static int pm8xxx_tz_get_crit_temp(struct thermal_zone_device *thermal, unsigned long *temp) { struct pm8xxx_tm_chip *chip = thermal->devdata; if (!chip || !temp) return -EINVAL; *temp = chip->thresh * TEMP_THRESH_STEP + TEMP_THRESH_MIN + 2 * TEMP_STAGE_STEP; return 0; } static struct thermal_zone_device_ops pm8xxx_thermal_zone_ops_no_adc = { .get_temp = pm8xxx_tz_get_temp_no_adc, .get_mode = pm8xxx_tz_get_mode, .set_mode = pm8xxx_tz_set_mode, .get_trip_type = pm8xxx_tz_get_trip_type, .get_trip_temp = pm8xxx_tz_get_trip_temp, .get_crit_temp = pm8xxx_tz_get_crit_temp, }; static struct thermal_zone_device_ops pm8xxx_thermal_zone_ops_pm8xxx_adc = { .get_temp = pm8xxx_tz_get_temp_pm8xxx_adc, .get_mode = pm8xxx_tz_get_mode, .set_mode = pm8xxx_tz_set_mode, .get_trip_type = pm8xxx_tz_get_trip_type, .get_trip_temp = pm8xxx_tz_get_trip_temp, .get_crit_temp = pm8xxx_tz_get_crit_temp, }; static struct thermal_zone_device_ops pm8xxx_thermal_zone_ops_pm8058_adc = { .get_temp = pm8xxx_tz_get_temp_pm8058_adc, .get_mode = pm8xxx_tz_get_mode, .set_mode = pm8xxx_tz_set_mode, .get_trip_type = pm8xxx_tz_get_trip_type, .get_trip_temp = pm8xxx_tz_get_trip_temp, .get_crit_temp = pm8xxx_tz_get_crit_temp, }; static void pm8xxx_tm_work(struct work_struct *work) { struct delayed_work *dwork = container_of(work, struct delayed_work, work); struct pm8xxx_tm_chip *chip = container_of(dwork, struct pm8xxx_tm_chip, irq_work); unsigned long temp = 0; int rc, stage, thresh; u8 reg; rc = pm8xxx_tm_read_ctrl(chip, ®); if (rc < 0) goto bail; /* Clear status bits. */ if (reg & (TEMP_ALARM_CTRL_ST2_SD | TEMP_ALARM_CTRL_ST3_SD)) { reg &= ~(TEMP_ALARM_CTRL_ST2_SD | TEMP_ALARM_CTRL_ST3_SD | TEMP_ALARM_CTRL_STATUS_MASK); pm8xxx_tm_write_ctrl(chip, reg); } stage = (reg & TEMP_ALARM_CTRL_STATUS_MASK) >> TEMP_ALARM_CTRL_STATUS_SHIFT; thresh = (reg & TEMP_ALARM_CTRL_THRESH_MASK) >> TEMP_ALARM_CTRL_THRESH_SHIFT; thermal_zone_device_update(chip->tz_dev); if (stage != chip->prev_stage) { chip->prev_stage = stage; switch (chip->cdata.adc_type) { case PM8XXX_TM_ADC_NONE: rc = pm8xxx_tz_get_temp_no_adc(chip->tz_dev, &temp); break; case PM8XXX_TM_ADC_PM8058_ADC: rc = pm8xxx_tz_get_temp_pm8058_adc(chip->tz_dev, &temp); break; case PM8XXX_TM_ADC_PM8XXX_ADC: rc = pm8xxx_tz_get_temp_pm8xxx_adc(chip->tz_dev, &temp); break; } if (rc < 0) goto bail; pr_crit("%s: PMIC Temp Alarm - stage=%u, threshold=%u, temp=%lu mC\n", chip->cdata.tm_name, stage, thresh, temp); /* Notify user space */ sysfs_notify(&chip->tz_dev->device.kobj, NULL, "type"); } bail: return; } static irqreturn_t pm8xxx_tm_isr(int irq, void *data) { struct pm8xxx_tm_chip *chip = data; schedule_delayed_work(&chip->irq_work, msecs_to_jiffies(STATUS_REGISTER_DELAY_MS) + 1); return IRQ_HANDLED; } static int pm8xxx_tm_init_reg(struct pm8xxx_tm_chip *chip) { int rc; u8 reg; rc = pm8xxx_tm_read_ctrl(chip, ®); if (rc < 0) return rc; chip->stage = (reg & TEMP_ALARM_CTRL_STATUS_MASK) >> TEMP_ALARM_CTRL_STATUS_SHIFT; chip->temp = 0; /* Use temperature threshold set 0: (105, 125, 145) */ chip->thresh = 0; reg = (chip->thresh << TEMP_ALARM_CTRL_THRESH_SHIFT) & TEMP_ALARM_CTRL_THRESH_MASK; rc = pm8xxx_tm_write_ctrl(chip, reg); if (rc < 0) return rc; /* * Set the PMIC temperature alarm module to be always on. This ensures * that die temperature monitoring is active even if CXO is disabled * (i.e. when sleep_b is low). This is necessary since CXO can be * disabled while the system is still heavily loaded. Also, using * the alway-on instead of PWM-enabled configurations ensures that the * die temperature can be measured by the PMIC ADC without reconfiguring * the temperature alarm module first. */ rc = pm8xxx_tm_write_pwm(chip, TEMP_ALARM_PWM_EN_ALWAYS); return rc; } static int pm8xxx_init_adc(struct pm8xxx_tm_chip *chip, bool enable) { int rc = 0; if (chip->cdata.adc_type == PM8XXX_TM_ADC_PM8058_ADC) { if (enable) { rc = adc_channel_open(chip->cdata.adc_channel, &(chip->adc_handle)); if (rc < 0) pr_err("adc_channel_open() failed.\n"); } else { adc_channel_close(chip->adc_handle); } } return rc; }
static int batt_read_adc(int channel, int *mv_reading) { int ret; void *h; struct adc_chan_result adc_chan_result; struct completion conv_complete_evt; #ifdef CONFIG_LGE_PM int wait_ret; #endif pr_debug("%s: called for %d\n", __func__, channel); ret = adc_channel_open(channel, &h); if (ret) { pr_err("%s: couldnt open channel %d ret=%d\n", __func__, channel, ret); goto out; } init_completion(&conv_complete_evt); ret = adc_channel_request_conv(h, &conv_complete_evt); if (ret) { pr_err("%s: couldnt request conv channel %d ret=%d\n", __func__, channel, ret); goto out; } #ifdef CONFIG_LGE_PM wait_ret = wait_for_completion_timeout(&conv_complete_evt, msecs_to_jiffies(MSM_PMIC_ADC_READ_TIMEOUT)); if(wait_ret <= 0) { printk(KERN_ERR "===%s: failed to adc wait for completion!===\n",__func__); goto sanity_out; } #else wait_for_completion(&conv_complete_evt); #endif ret = adc_channel_read_result(h, &adc_chan_result); if (ret) { pr_err("%s: couldnt read result channel %d ret=%d\n", __func__, channel, ret); goto out; } ret = adc_channel_close(h); if (ret) { pr_err("%s: couldnt close channel %d ret=%d\n", __func__, channel, ret); } if (mv_reading) *mv_reading = adc_chan_result.measurement; pr_debug("%s: done for %d\n", __func__, channel); return adc_chan_result.physical; out: pr_debug("%s: done for %d\n", __func__, channel); return -EINVAL; #ifdef CONFIG_LGE_PM sanity_out: pm8058_xoadc_clear_recentQ(); ret = adc_channel_close(h); if (ret) { pr_err("%s: couldnt close channel %d ret=%d\n", __func__, channel, ret); } if(channel == CHANNEL_ADC_BATT_THERM) { printk(KERN_ERR "============== batt temp adc read fail so default temp ===============\n"); if (mv_reading) *mv_reading = MSM_CHARGER_GAUGE_MISSING_TEMP_ADC; return MSM_CHARGER_GAUGE_MISSING_TEMP; } else if(channel == CHANNEL_ADC_ACC) { printk(KERN_ERR "============== ACC adc read fail so default usb ===============\n"); return CHANNEL_ADC_ACC_MISSING; } else { printk(KERN_ERR "============== adc read fail ===============\n"); return -EINVAL; } #endif }
u32 lightsensor_get_adc(int channel) { int ret; void *h; struct adc_chan_result adc_chan_result; struct completion conv_complete_evt; #ifdef CONFIG_SEC_DEBUG_PM8058_ADC static int retry_cnt; #endif pr_debug("%s: called for %d\n", __func__, channel); ret = adc_channel_open(channel, &h); if (ret) { pr_err("%s: couldnt open channel %d ret=%d\n", __func__, channel, ret); goto out; } init_completion(&conv_complete_evt); ret = adc_channel_request_conv(h, &conv_complete_evt); if (ret) { pr_err("%s: couldnt request conv channel %d ret=%d\n", __func__, channel, ret); goto out; } ret = wait_for_completion_interruptible_timeout(&conv_complete_evt, 5*HZ); if (!ret) { pr_err("%s: wait interrupted channel %d ret=%d\n", __func__, channel, ret); #ifdef CONFIG_SEC_DEBUG_PM8058_ADC_VERBOSE adc_dbg_info_timer(0); #else pm8058_xoadc_clear_recentQ(); #ifdef CONFIG_SEC_DEBUG_PM8058_ADC if(retry_cnt++ >= 10) adc_dbg_info_timer(0); #endif #endif goto out; } #ifdef CONFIG_SEC_DEBUG_PM8058_ADC retry_cnt = 0; #endif ret = adc_channel_read_result(h, &adc_chan_result); if (ret) { pr_err("%s: couldnt read result channel %d ret=%d\n", __func__, channel, ret); goto out; } ret = adc_channel_close(h); if (ret) { pr_err("%s: couldnt close channel %d ret=%d\n", __func__, channel, ret); } pr_debug("%s: done for %d\n", __func__, channel); // return adc_chan_result.physical; return adc_chan_result.measurement; out: pr_debug("%s: done for %d\n", __func__, channel); return -EINVAL; }
static int pm8xxx_tz_get_temp_pm8058_adc(struct thermal_zone_device *thermal, unsigned long *temp) { struct pm8xxx_tm_chip *chip = thermal->devdata; DECLARE_COMPLETION_ONSTACK(wait); struct adc_chan_result adc_result = { .physical = 0lu, }; int rc; if (!chip || !temp) return -EINVAL; *temp = chip->temp; rc = adc_channel_request_conv(chip->adc_handle, &wait); if (rc < 0) { pr_err("%s: adc_channel_request_conv() failed, rc = %d\n", __func__, rc); return rc; } wait_for_completion(&wait); rc = adc_channel_read_result(chip->adc_handle, &adc_result); if (rc < 0) { pr_err("%s: adc_channel_read_result() failed, rc = %d\n", __func__, rc); return rc; } *temp = adc_result.physical; chip->temp = adc_result.physical; return 0; } static int pm8xxx_tz_get_temp_pm8xxx_adc(struct thermal_zone_device *thermal, unsigned long *temp) { struct pm8xxx_tm_chip *chip = thermal->devdata; struct pm8xxx_adc_chan_result result = { .physical = 0lu, }; int rc; if (!chip || !temp) return -EINVAL; *temp = chip->temp; rc = pm8xxx_adc_read(chip->cdata.adc_channel, &result); if (rc < 0) { pr_err("%s: adc_channel_read_result() failed, rc = %d\n", chip->cdata.tm_name, rc); return rc; } *temp = result.physical; chip->temp = result.physical; return 0; } static int pm8xxx_tz_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) { struct pm8xxx_tm_chip *chip = thermal->devdata; if (!chip || !mode) return -EINVAL; *mode = chip->mode; return 0; } static int pm8xxx_tz_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct pm8xxx_tm_chip *chip = thermal->devdata; if (!chip) return -EINVAL; if (mode != chip->mode) { if (mode == THERMAL_DEVICE_ENABLED) pm8xxx_tm_shutdown_override(chip, SOFTWARE_OVERRIDE_ENABLED); else pm8xxx_tm_shutdown_override(chip, SOFTWARE_OVERRIDE_DISABLED); } chip->mode = mode; return 0; } static int pm8xxx_tz_get_trip_type(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) { if (trip < 0 || !type) return -EINVAL; switch (trip) { case TRIP_STAGE3: *type = THERMAL_TRIP_CRITICAL; break; case TRIP_STAGE2: *type = THERMAL_TRIP_HOT; break; case TRIP_STAGE1: *type = THERMAL_TRIP_HOT; break; default: return -EINVAL; } return 0; } static int pm8xxx_tz_get_trip_temp(struct thermal_zone_device *thermal, int trip, unsigned long *temp) { struct pm8xxx_tm_chip *chip = thermal->devdata; int thresh_temp; if (!chip || trip < 0 || !temp) return -EINVAL; thresh_temp = chip->thresh * TEMP_THRESH_STEP + TEMP_THRESH_MIN; switch (trip) { case TRIP_STAGE3: thresh_temp += 2 * TEMP_STAGE_STEP; break; case TRIP_STAGE2: thresh_temp += TEMP_STAGE_STEP; break; case TRIP_STAGE1: break; default: return -EINVAL; } *temp = thresh_temp; return 0; } static int pm8xxx_tz_get_crit_temp(struct thermal_zone_device *thermal, unsigned long *temp) { struct pm8xxx_tm_chip *chip = thermal->devdata; if (!chip || !temp) return -EINVAL; *temp = chip->thresh * TEMP_THRESH_STEP + TEMP_THRESH_MIN + 2 * TEMP_STAGE_STEP; return 0; } static struct thermal_zone_device_ops pm8xxx_thermal_zone_ops_no_adc = { .get_temp = pm8xxx_tz_get_temp_no_adc, .get_mode = pm8xxx_tz_get_mode, .set_mode = pm8xxx_tz_set_mode, .get_trip_type = pm8xxx_tz_get_trip_type, .get_trip_temp = pm8xxx_tz_get_trip_temp, .get_crit_temp = pm8xxx_tz_get_crit_temp, }; static struct thermal_zone_device_ops pm8xxx_thermal_zone_ops_pm8xxx_adc = { .get_temp = pm8xxx_tz_get_temp_pm8xxx_adc, .get_mode = pm8xxx_tz_get_mode, .set_mode = pm8xxx_tz_set_mode, .get_trip_type = pm8xxx_tz_get_trip_type, .get_trip_temp = pm8xxx_tz_get_trip_temp, .get_crit_temp = pm8xxx_tz_get_crit_temp, }; static struct thermal_zone_device_ops pm8xxx_thermal_zone_ops_pm8058_adc = { .get_temp = pm8xxx_tz_get_temp_pm8058_adc, .get_mode = pm8xxx_tz_get_mode, .set_mode = pm8xxx_tz_set_mode, .get_trip_type = pm8xxx_tz_get_trip_type, .get_trip_temp = pm8xxx_tz_get_trip_temp, .get_crit_temp = pm8xxx_tz_get_crit_temp, }; static void pm8xxx_tm_work(struct work_struct *work) { struct pm8xxx_tm_chip *chip = container_of(work, struct pm8xxx_tm_chip, irq_work); int rc; u8 reg; rc = pm8xxx_tm_read_ctrl(chip, ®); if (rc < 0) goto bail; if (chip->cdata.adc_type == PM8XXX_TM_ADC_NONE) { rc = pm8xxx_tm_update_temp_no_adc(chip); if (rc < 0) goto bail; pr_info("%s: Temp Alarm - stage=%u, threshold=%u, " "temp=%lu mC\n", chip->cdata.tm_name, chip->stage, chip->thresh, chip->temp); } else { chip->stage = (reg & TEMP_ALARM_CTRL_STATUS_MASK) >> TEMP_ALARM_CTRL_STATUS_SHIFT; chip->thresh = (reg & TEMP_ALARM_CTRL_THRESH_MASK) >> TEMP_ALARM_CTRL_THRESH_SHIFT; pr_info("%s: Temp Alarm - stage=%u, threshold=%u\n", chip->cdata.tm_name, chip->stage, chip->thresh); } /* Clear status bits. */ if (reg & (TEMP_ALARM_CTRL_ST2_SD | TEMP_ALARM_CTRL_ST3_SD)) { reg &= ~(TEMP_ALARM_CTRL_ST2_SD | TEMP_ALARM_CTRL_ST3_SD | TEMP_ALARM_CTRL_STATUS_MASK); pm8xxx_tm_write_ctrl(chip, reg); } thermal_zone_device_update(chip->tz_dev); /* Notify user space */ sysfs_notify(&chip->tz_dev->device.kobj, NULL, "type"); bail: enable_irq(chip->tempstat_irq); enable_irq(chip->overtemp_irq); } static irqreturn_t pm8xxx_tm_isr(int irq, void *data) { struct pm8xxx_tm_chip *chip = data; disable_irq_nosync(chip->tempstat_irq); disable_irq_nosync(chip->overtemp_irq); schedule_work(&chip->irq_work); return IRQ_HANDLED; } static int pm8xxx_tm_init_reg(struct pm8xxx_tm_chip *chip) { int rc; u8 reg; rc = pm8xxx_tm_read_ctrl(chip, ®); if (rc < 0) return rc; chip->stage = (reg & TEMP_ALARM_CTRL_STATUS_MASK) >> TEMP_ALARM_CTRL_STATUS_SHIFT; chip->temp = 0; /* Use temperature threshold set 0: (105, 125, 145) */ chip->thresh = 0; reg = (chip->thresh << TEMP_ALARM_CTRL_THRESH_SHIFT) & TEMP_ALARM_CTRL_THRESH_MASK; rc = pm8xxx_tm_write_ctrl(chip, reg); if (rc < 0) return rc; /* * Set the PMIC alarm module PWM to have a frequency of 8 Hz. This * helps cut down on the number of unnecessary interrupts fired when * changing between thermal stages. Also, Enable the over temperature * PWM whenever the PMIC is enabled. */ reg = (1 << TEMP_ALARM_PWM_EN_SHIFT) | (3 << TEMP_ALARM_PWM_PER_PRE_SHIFT) | (3 << TEMP_ALARM_PWM_PER_DIV_SHIFT); rc = pm8xxx_tm_write_pwm(chip, reg); return rc; } static int pm8xxx_init_adc(struct pm8xxx_tm_chip *chip, bool enable) { int rc = 0; if (chip->cdata.adc_type == PM8XXX_TM_ADC_PM8058_ADC) { if (enable) { rc = adc_channel_open(chip->cdata.adc_channel, &(chip->adc_handle)); if (rc < 0) pr_err("adc_channel_open() failed.\n"); } else { adc_channel_close(chip->adc_handle); } } return rc; }
static int Check_ADC_MPP(int *nValue) { int err=0,ret=0,result=0; void *h; struct adc_chan_result adc_chan_result; //long timeout=0; struct completion conv_complete_evt; struct pm8xxx_mpp_config_data sky_handset_analog_adc = { .type = PM8XXX_MPP_TYPE_A_INPUT, .level = PM8XXX_MPP_AIN_AMUX_CH5, .control = PM8XXX_MPP_AOUT_CTRL_DISABLE, }; mutex_lock(&headset_adc_lock); ret=gpio_get_value_cansleep(hspd->ear_det); if(ret!=hspd->ear_det_active) { printk("EARJACK_DET %d\n",ret); mutex_unlock(&headset_adc_lock); return -1; } #if AT1_BDVER_GE(AT1_WS22) if(hspd->curr_state == MSM_HEADSET) { Remote_Interrupt_Enable(0); msleep(1); } #endif //sys_gpio= PM8901_GPIO_PM_TO_SYS(mpp); //err=pm8058_mpp_config_analog_input(XOADC_MPP_3,PM_MPP_AIN_AMUX_CH5, PM_MPP_AOUT_CTL_DISABLE); err = pm8xxx_mpp_config(PM8058_MPP_PM_TO_SYS(XOADC_MPP_3), &sky_handset_analog_adc); if(err) { printk("pm8058_mpp_config_analog_input() err=%d\n",err); mutex_unlock(&headset_adc_lock); return -1; } ret = adc_channel_open(CHANNEL_ADC_HDSET, &h); if(ret) { printk("couldn't open channel %d ret=%d\n",CHANNEL_ADC_HDSET,ret); mutex_unlock(&headset_adc_lock); return -1; } init_completion(&conv_complete_evt); ret = adc_channel_request_conv(h, &conv_complete_evt); if(ret) { printk("couldn't request convert channel %d ret=%d\n",CHANNEL_ADC_HDSET,ret); result=-2; goto check_adc_out; } wait_for_completion(&conv_complete_evt); /* timeout=wait_for_completion_timeout(&conv_complete_evt,msecs_to_jiffies(100)); if(timeout<=0) { printk("headset ADC timeout\n"); result=-3; goto check_adc_out; } */ ret = adc_channel_read_result(h, &adc_chan_result); if(ret) { printk("could't read result channel %d ret=%d\n",CHANNEL_ADC_HDSET,ret); result=-4; goto check_adc_out; } *nValue=(int)adc_chan_result.measurement; check_adc_out: ret = adc_channel_close(h); if(ret) { printk("could't close channel %d ret=%d\n",CHANNEL_ADC_HDSET,ret); mutex_unlock(&headset_adc_lock); return -1; } #if AT1_BDVER_GE(AT1_WS22) if(hspd->curr_state == MSM_HEADSET) { Remote_Interrupt_Enable(1); } #endif //printk("ADC value=%d, physical=%d\n",(int)adc_chan_result.measurement,adc_chan_result.physical); mutex_unlock(&headset_adc_lock); return result; }
static int semc_battery_read_adc(int channel, int *read_measurement, int *read_physical) { struct power_supply *ps = power_supply_get_by_name(SEMC_BDATA_NAME); struct data_info *di = container_of(ps, struct data_info, bdata_ps); int ret; void *h; struct adc_chan_result adc_chan_result; struct completion conv_complete_evt; if (!read_measurement && !read_physical) return -EINVAL; dev_dbg(di->dev, "called for %d\n", channel); ret = adc_channel_open(channel, &h); if (ret) { dev_err(di->dev, "couldnt open channel %d ret=%d\n", channel, ret); goto out; } init_completion(&conv_complete_evt); ret = adc_channel_request_conv(h, &conv_complete_evt); if (ret) { dev_err(di->dev, "couldnt request conv channel %d ret=%d\n", channel, ret); adc_channel_close(h); goto out; } ret = wait_for_completion_interruptible(&conv_complete_evt); if (ret) { dev_err(di->dev, "wait interrupted channel %d ret=%d\n", channel, ret); adc_channel_close(h); goto out; } ret = adc_channel_read_result(h, &adc_chan_result); if (ret) { dev_err(di->dev, "couldnt read result channel %d ret=%d\n", channel, ret); adc_channel_close(h); goto out; } ret = adc_channel_close(h); if (ret) dev_err(di->dev, "couldnt close channel %d ret=%d\n", channel, ret); if (read_measurement) { *read_measurement = (int)adc_chan_result.measurement; dev_dbg(di->dev, "done for %d measurement=%d\n", channel, *read_measurement); } if (read_physical) { *read_physical = adc_chan_result.physical; dev_dbg(di->dev, "done for %d physical=%d\n", channel, *read_physical); } return ret; out: dev_dbg(di->dev, "done for %d\n", channel); return ret; }