static int sec_bat_adc_ap_read(int channel) { int data = -1; int ret = 0; switch (channel) { case SEC_BAT_ADC_CHANNEL_CABLE_CHECK: case SEC_BAT_ADC_CHANNEL_BAT_CHECK: break; case SEC_BAT_ADC_CHANNEL_TEMP: case SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT: ret = iio_read_channel_raw(&temp_adc[0], &data); if (ret < 0) pr_info("read channel error[%d]\n", ret); else pr_debug("TEMP ADC(%d)\n", data); break; case SEC_BAT_ADC_CHANNEL_FULL_CHECK: case SEC_BAT_ADC_CHANNEL_VOLTAGE_NOW: case SEC_BAT_ADC_CHANNEL_NUM: break; case SEC_BAT_ADC_CHANNEL_CHG_TEMP: case SEC_BAT_ADC_CHANNEL_INBAT_VOLTAGE: ret = iio_read_channel_raw(&temp_adc[1], &data); if (ret < 0) pr_info("read channel error[%d]\n", ret); else pr_debug("TEMP ADC(%d)\n", data); break; default: break; } return data; }
static int mux_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { struct mux *mux = iio_priv(indio_dev); int idx = chan - mux->chan; int ret; ret = iio_mux_select(mux, idx); if (ret < 0) return ret; switch (mask) { case IIO_CHAN_INFO_RAW: ret = iio_read_channel_raw(mux->parent, val); break; case IIO_CHAN_INFO_SCALE: ret = iio_read_channel_scale(mux->parent, val, val2); break; default: ret = -EINVAL; } iio_mux_deselect(mux); return ret; }
/* * Enables given plates and measures touch parameters using ADC */ static int adc_ts_measure(struct iio_channel *channel, struct gpio_desc *plate_p, struct gpio_desc *plate_m) { int i, value = 0, val = 0; int error; gpiod_set_value(plate_p, 1); gpiod_set_value(plate_m, 1); usleep_range(COLI_TOUCH_MIN_DELAY_US, COLI_TOUCH_MAX_DELAY_US); for (i = 0; i < COLI_TOUCH_NO_OF_AVGS; i++) { error = iio_read_channel_raw(channel, &val); if (error < 0) { value = error; goto error_iio_read; } value += val; } value /= COLI_TOUCH_NO_OF_AVGS; error_iio_read: gpiod_set_value(plate_p, 0); gpiod_set_value(plate_m, 0); return value; }
/** * pmic_read_adc_val - read ADC value of specified sensors * @channel: channel of the sensor to be sampled * @sensor_val: pointer to the charger property to hold sampled value * @chc : battery info pointer * * Returns 0 if success */ static int pmic_read_adc_val(const char *map, const char *name, int *raw_val, struct pmic_fg_info *info) { int ret, val; struct iio_channel *indio_chan; indio_chan = iio_channel_get(NULL, name); if (IS_ERR_OR_NULL(indio_chan)) { ret = PTR_ERR(indio_chan); goto exit; } ret = iio_read_channel_raw(indio_chan, &val); if (ret) { dev_err(&info->pdev->dev, "IIO channel read error\n"); goto err_exit; } dev_dbg(&info->pdev->dev, "adc raw val=%x\n", val); *raw_val = val; err_exit: iio_channel_release(indio_chan); exit: return ret; }
//4 static void hook_work_callback(struct work_struct *work) { int ret,val; struct headset_priv *headset = headset_info; struct rk_headset_pdata *pdata = headset->pdata; static unsigned int old_status = HOOK_UP; ret = iio_read_channel_raw(headset->chan, &val); if (ret < 0) { pr_err("read hook adc channel() error: %d\n", ret); goto out; } else DBG("hook_work_callback read adc value=%d\n",val); if(headset->headset_status == HEADSET_OUT || headset->heatset_irq_working == BUSY || headset->heatset_irq_working == WAIT || pdata->headset_insert_type?gpio_get_value(pdata->headset_gpio) == 0:gpio_get_value(pdata->headset_gpio) > 0) { DBG("Headset is out or waiting for headset is in or out,after same time check HOOK key\n"); goto out; } old_status = headset->hook_status; if(val < HOOK_LEVEL_LOW && val >= 0) headset->hook_status = HOOK_DOWN; else if(val > HOOK_LEVEL_HIGH && val < HOOK_DEFAULT_VAL) headset->hook_status = HOOK_UP; DBG("HOOK status is %s , adc value = %d hook_time = %d\n",headset->hook_status?"down":"up",val,headset->hook_time); if(old_status == headset->hook_status) { DBG("Hook adc read old_status == headset->hook_status=%d hook_time = %d\n",headset->hook_status,headset->hook_time); goto status_error; } if(headset->headset_status == HEADSET_OUT || headset->heatset_irq_working == BUSY || headset->heatset_irq_working == WAIT || (pdata->headset_insert_type?gpio_get_value(pdata->headset_gpio) == 0:gpio_get_value(pdata->headset_gpio) > 0)) { printk("headset is out,HOOK status must discard\n"); goto out; } else { input_report_key(headset->input_dev,HOOK_KEY_CODE,headset->hook_status); input_sync(headset->input_dev); } status_error: schedule_delayed_work(&headset_info->hook_work,msecs_to_jiffies(100)); out:; }
static void hook_once_work(struct work_struct *work) { int ret,val; #ifdef CONFIG_SND_SOC_WM8994 wm8994_headset_mic_detect(true); #endif #if defined (CONFIG_SND_SOC_RT3261) || defined (CONFIG_SND_SOC_RT3224) rt3261_headset_mic_detect(true); #endif #ifdef CONFIG_SND_SOC_RT5631_PHONE rt5631_headset_mic_detect(true); #endif ret = iio_read_channel_raw(headset_info->chan, &val); if (ret < 0) { pr_err("read hook_once_work adc channel() error: %d\n", ret); } else DBG("hook_once_work read adc value: %d\n",val); if(val >= 0 && val < HOOK_LEVEL_LOW) { headset_info->isMic= 0;//No microphone #ifdef CONFIG_SND_SOC_WM8994 wm8994_headset_mic_detect(false); #endif #if defined (CONFIG_SND_SOC_RT3261) || defined (CONFIG_SND_SOC_RT3224) rt3261_headset_mic_detect(false); #endif #ifdef CONFIG_SND_SOC_RT5631_PHONE rt5631_headset_mic_detect(false); #endif } else if(val >= HOOK_LEVEL_HIGH) { headset_info->isMic = 1;//have mic schedule_delayed_work(&headset_info->hook_work,msecs_to_jiffies(100)); } headset_info->cur_headset_status = headset_info->isMic ? BIT_HEADSET:BIT_HEADSET_NO_MIC; switch_set_state(&headset_info->sdev, headset_info->cur_headset_status); DBG("%s notice android headset status = %d\n",__func__,headset_info->cur_headset_status); }
/* * sd_cv_batt_id_resistor - calculate the battery id resistor (Ohm) * return - the resistor value (Ohm) */ int sd_cv_batt_id_resistor() { int ret; int val = 0; int resistor = 0; int adc = 0; int auto_cur_sel = 0; int battid_cursrc = 0; struct iio_channel *indio_chan = NULL; /* Get battid pmic channel */ indio_chan = iio_channel_get(NULL, SDCV_BATTID_CHANNEL_NAME); if (IS_ERR_OR_NULL(indio_chan)) { pr_err("%s: IIO channel get error!!\n", __func__); return -1; } /* Read pmic battid ADC */ #if 0 ret = iio_read_channel_raw(indio_chan, &val); if (ret) { pr_err("%s: unable to read batid", __func__); return -1; } pr_info("%s: IIO channel read Sucess, val=%.3X\n", __func__, val); #endif adc = sd_cv_get_adc_value(SDCV_BATTIDRSLTH_REG, &auto_cur_sel); if (adc < 0 || auto_cur_sel == 0) { pr_err("%s: fail to get batt id result from 0x%X", __func__, SDCV_BATTIDRSLTH_REG); return -1; } pr_info("%s: adc=0x%X, auto_cur_sel=%d\n", __func__, adc, auto_cur_sel); /* The formula for calculating the battery id resistor */ resistor = adc * 293 * 1000 / auto_cur_sel; /* Release adc channel */ iio_channel_release(indio_chan); return resistor; }
int shady_cove_get_id(struct dwc_otg2 *otg) { u8 schgrirq1; struct iio_channel *chan; int ret, rid, id = RID_UNKNOWN; ret = intel_scu_ipc_ioread8(PMIC_SCHGRIRQ1, &schgrirq1); if (ret) { otg_err(otg, "Fail to read id\n"); return id; } /* PMIC_SCHGRIRQ1_SUSBIDDET bit definition: * 0 = RID_A/B/C ; 1 = RID_GND ; 2 = RID_FLOAT */ if (schgrirq1 & PMIC_SCHGRIRQ1_SUSBIDDET(2)) return RID_FLOAT; else if (schgrirq1 & PMIC_SCHGRIRQ1_SUSBIDDET(1)) return RID_GND; chan = iio_channel_get(NULL, "USBID"); if (IS_ERR_OR_NULL(chan)) { otg_err(otg, "%s: Fail to get USBID channel\n", __func__); return id; } ret = iio_read_channel_raw(chan, &rid); if (ret) { otg_err(otg, "%s: Fail to read USBID channel", __func__); goto done; } if ((rid > 11150) && (rid < 13640)) id = RID_A; else if ((rid > 6120) && (rid < 7480)) id = RID_B; else if ((rid > 3285) && (rid < 4015)) id = RID_C; done: iio_channel_release(chan); return id; }
/* * sd_cv_batt_vol - calculate the battery voltage * return - the battery voltage value (mV) */ int sd_cv_batt_vol() { int ret; int val = 0; int volt = 0; int adc = 0; int battid_cursrc = 0; struct iio_channel *indio_chan = NULL; /* Get vbat pmic channel */ indio_chan = iio_channel_get(NULL, SDCV_VBAT_CHANNEL_NAME); if (IS_ERR_OR_NULL(indio_chan)) { pr_err("%s: IIO channel get error!!\n", __func__); return -1; } /* Read pmic vbat ADC */ ret = iio_read_channel_raw(indio_chan, &val); if (ret) { pr_err("%s: unable to read vbat", __func__); return -1; } pr_debug("%s: IIO channel read Sucess, val=%.3X\n", __func__, val); adc = sd_cv_get_adc_value(SDCV_VBATRSLTH_REG, NULL); if (adc < 0) { pr_err("%s: fail to get vbat result from 0x%X", __func__, SDCV_VBATRSLTH_REG); return -1; } pr_debug("%s: adc=0x%X\n", __func__, adc); /* The formula for calculating the battery voltage */ volt = adc * 1250 / 1000; /* Release adc channel */ iio_channel_release(indio_chan); return volt; }
static int sec_bat_adc_ap_read(int channel) { int data = -1; int ret = 0; switch (channel) { case SEC_BAT_ADC_CHANNEL_CABLE_CHECK: case SEC_BAT_ADC_CHANNEL_BAT_CHECK: break; case SEC_BAT_ADC_CHANNEL_TEMP: case SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT: ret = iio_read_channel_raw(&temp_adc[0], &data); if (ret < 0) pr_info("read channel error[%d]\n", ret); else pr_debug("TEMP ADC(%d)\n", data); break; case SEC_BAT_ADC_CHANNEL_FULL_CHECK: case SEC_BAT_ADC_CHANNEL_VOLTAGE_NOW: case SEC_BAT_ADC_CHANNEL_NUM: break; case SEC_BAT_ADC_CHANNEL_CHG_TEMP: ret = iio_read_channel_raw(&temp_adc[1], &data); if (ret < 0) pr_info("read channel error[%d]\n", ret); else pr_debug("TEMP ADC(%d)\n", data); break; case SEC_BAT_ADC_CHANNEL_INBAT_VOLTAGE: ret = iio_read_channel_raw(&temp_adc[2], &data); if (ret < 0) pr_info("read channel error[%d]\n", ret); else pr_debug("INBAT ADC(%d)\n", data); break; #ifdef CONFIG_BATTERY_SWELLING_SELF_DISCHARGING case SEC_BAT_ADC_CHANNEL_DISCHARGING_CHECK: ret = iio_read_channel_raw(&temp_adc[3], &data); if (ret < 0) pr_info("read channel error[%d]\n", ret); else pr_debug("DISCHARGING CHECK(%d)\n", data); break; case SEC_BAT_ADC_CHANNEL_DISCHARGING_NTC: ret = iio_read_channel_raw(&temp_adc[4], &data); if (ret < 0) pr_info("read channel error[%d]\n", ret); else pr_debug("DISCHARGING NTC(%d)\n", data); break; #endif case SEC_BAT_ADC_CHANNEL_WPC_TEMP: ret = iio_read_channel_raw(&temp_adc[5], &data); if (ret < 0) pr_info("read channel error[%d]\n", ret); else pr_debug("WPC TEMP(%d)\n", data); break; default: break; } return data; }