static int acc_get_adc_accessroy_id(struct s3c_adc_client *padc)
{
	int adc_data;

#if defined(CONFIG_STMPE811_ADC)
	adc_data = stmpe811_get_adc_data(ACCESSORY_ID_ADC_CH);
#else
	adc_data = s3c_adc_read(padc, ACCESSORY_ID_ADC_CH);
#endif
/*	ACC_CONDEV_DBG("[ACC] adc_data = %d..\n",adc_data); */
	return adc_data;
}
static int sec_bat_adc_ap_read(unsigned int channel)
{
	int data = -1;

	switch (channel) {
	case SEC_BAT_ADC_CHANNEL_TEMP:
		data = s3c_adc_read(adc_client, 4);
		break;
	case SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT:
		data = 33000;
		break;
	}

	return data;
}
static int gather_samples(struct s3c_adc_client *client, int num, int channel)
{
	int value, i;

	
	if (num < 1)
		num = 1;

	value = 0;
	for (i = 0; i < num; i++)
		value += s3c_adc_read(client, channel);
	value /= num;

	return value;
}
Example #4
0
/**
 * s3c_hwmon_read_ch - read a value from a given adc channel.
 * @dev: The device.
 * @hwmon: Our state.
 * @channel: The channel we're reading from.
 *
 * Read a value from the @channel with the proper locking and sleep until
 * either the read completes or we timeout awaiting the ADC core to get
 * back to us.
 */
static int s3c_hwmon_read_ch(struct device *dev,
                             struct s3c_hwmon *hwmon, int channel)
{
    int ret;

    ret = mutex_lock_interruptible(&hwmon->lock);
    if (ret < 0)
        return ret;

    dev_dbg(dev, "reading channel %d\n", channel);

    ret = s3c_adc_read(hwmon->client, channel);
    mutex_unlock(&hwmon->lock);

    return ret;
}
static void sec_bat_check_batt_id(void)
{
	int ret = 0;

	ret = s3c_adc_read(adc_client, 4);

	/* SDI: +/-700, ATL: +2000 */
	if (ret > 1700) {
		sec_battery_pdata.vendor = "ATL ATL";
		adonis_battery_data[0].Capacity = 0x4958;
		adonis_battery_data[0].type_str = "ATL";
	}

	pr_err("%s: batt_type(%s), batt_id(%d), cap(0x%x), type(%s)\n",
		__func__, sec_battery_pdata.vendor, ret,
		adonis_battery_data[0].Capacity, adonis_battery_data[0].type_str);
}
Example #6
0
static int lightsensor_get_adcvalue(struct gp2a_data *gp2a)
{
	int i = 0;
	int value = 0;
	int fake_value;
	unsigned int adc_avr_value;

	/* get ADC */
	/* value = gp2a->pdata->light_adc_value(); */

	mutex_lock(&gp2a->adc_mutex);

	value = s3c_adc_read(gp2a->padc, ALS_IOUT_ADC);

	mutex_unlock(&gp2a->adc_mutex);

	if (value < 0) {
		pr_err("%s : ADC Fail, ret = %d", __func__, value);
		value = 0;
	}

	gp2a->adc_total += value;

	adc_avr_value = gp2a->adc_total/ADC_SAMPLE_NUM;

	gp2a->adc_total -= adc_avr_value;

	/* Cut off ADC Value
	 */
#if 1
	if (adc_avr_value < LIGHT_FAKE_LIMIT) {
		fake_value =
			(adc_avr_value < LIGHT_FAKE_THRESHOLD) ?
			0 : 2 * (adc_avr_value) - LIGHT_FAKE_LIMIT;
		adc_avr_value = fake_value;
	}
#else
	if (adc_avr_value < 10) {
		gp2a->adc_total = 0;
		adc_avr_value = 0;
	}
#endif
	return adc_avr_value;
}
static int cp_thm_get_adc_data(struct ssp_data *data)
{
	int adc_data;
	int adc_max = 0;
	int adc_min = 0;
	int adc_total = 0;
	int i;
	int err_value;

	for (i = 0; i < CP_THM_ADC_SAMPLING_CNT; i++) {
		mutex_lock(&data->cp_temp_adc_lock);
		if (data->adc_client)
			adc_data = s3c_adc_read(data->adc_client, data->cp_thm_adc_channel);
		else
			adc_data = 0;
		mutex_unlock(&data->cp_temp_adc_lock);

		if (adc_data < 0) {
			pr_err("[SSP] : %s err(%d) returned, skip read\n",
				__func__, adc_data);
			err_value = adc_data;
			goto err;
		}

		if (i != 0) {
			if (adc_data > adc_max)
				adc_max = adc_data;
			else if (adc_data < adc_min)
				adc_min = adc_data;
		} else {
			adc_max = adc_data;
			adc_min = adc_data;
		}
		adc_total += adc_data;
	}

	return (adc_total - adc_max - adc_min) / (CP_THM_ADC_SAMPLING_CNT - 2);
err:
	return err_value;
}
static int sec_therm_get_adc_data(struct sec_therm_info *info)
{
	int adc_ch;
	int adc_data;
	int adc_max = 0;
	int adc_min = 0;
	int adc_total = 0;
	int i;
	int err_value;

	adc_ch = info->pdata->adc_channel;

	for (i = 0; i < ADC_SAMPLING_CNT; i++) {
		adc_data = s3c_adc_read(info->padc, adc_ch);

		if (adc_data < 0) {
			dev_err(info->dev, "%s : err(%d) returned, skip read\n",
				__func__, adc_data);
			err_value = adc_data;
			goto err;
		}

		if (i != 0) {
			if (adc_data > adc_max)
				adc_max = adc_data;
			else if (adc_data < adc_min)
				adc_min = adc_data;
		} else {
			adc_max = adc_data;
			adc_min = adc_data;
		}
		adc_total += adc_data;
	}

	return (adc_total - adc_max - adc_min) / (ADC_SAMPLING_CNT - 2);
err:
	return err_value;
}
static void sec_bat_check_batt_id(void)
{
	int ret = 0;

	ret = s3c_adc_read(adc_client, 4);

#if !defined(CONFIG_CHAGALL) && !defined(CONFIG_KLIMT)
	/* SDI: +/-700, BYD: +/-1300, ATL: +2000 */
	if (ret > 1700) {
		sec_battery_pdata.vendor = "ATL ATL";
		adonis_battery_data[0].Capacity = 0x4074;
		adonis_battery_data[0].type_str = "ATL";
	} else if (ret > 1000) {
		sec_battery_pdata.vendor = "BYD BYD";
		adonis_battery_data[0].Capacity = 0x4010;
		adonis_battery_data[0].type_str = "BYD";
	}
#endif

	pr_err("%s: batt_type(%s), batt_id(%d), cap(0x%x), type(%s)\n",
		__func__, sec_battery_pdata.vendor, ret,
		adonis_battery_data[0].Capacity, adonis_battery_data[0].type_str);
}
/* Temperature from fuelgauge or adc */
static int battery_get_temper(struct battery_info *info)
{
	union power_supply_propval value;
	int cnt, adc, adc_max, adc_min, adc_total;
	int temper = 0;
	int retry_cnt = 0;
	pr_debug("%s\n", __func__);

	switch (info->pdata->temper_src) {
	case TEMPER_FUELGAUGE:
		info->psy_fuelgauge->get_property(info->psy_fuelgauge,
					  POWER_SUPPLY_PROP_TEMP, &value);
		temper = value.intval;
		break;
	case TEMPER_AP_ADC:
#if defined(CONFIG_MACH_S2PLUS)
		if (system_rev < 2) {
			pr_info("%s: adc fixed as 30.0\n", __func__);
			temper = 300;
			return temper;
		}
#endif
#if defined(CONFIG_S3C_ADC)
		adc = adc_max = adc_min = adc_total = 0;
		for (cnt = 0; cnt < CNT_ADC_SAMPLE; cnt++) {
			do {
				adc = s3c_adc_read(info->adc_client,
							info->pdata->temper_ch);

				if (adc < 0) {
					pr_info("%s: adc read(%d), retry(%d)",
						__func__, adc, retry_cnt);
					retry_cnt++;
					msleep(100);
				}
			} while ((adc < 0) && (retry_cnt <= 5));

			adc_max = MAX(adc, adc_max);
			adc_min = MIN(adc, adc_min);
			adc_total += adc;
			pr_debug("%s: adc(%d), total(%d), max(%d), min(%d), "
					"avg(%d), cnt(%d)\n", __func__,
					adc, adc_total, adc_max, adc_min,
					adc_total / (cnt + 1),  cnt + 1);
		}

		info->battery_temper_adc =
			(adc_total - adc_max - adc_min) / (CNT_ADC_SAMPLE - 2);

		if (info->battery_temper_adc < 0) {
			pr_info("%s: adc read error(%d), temper set as 30.0",
					__func__, info->battery_temper_adc);
			temper = 300;
		} else {
			temper = info->pdata->covert_adc(
					info->battery_temper_adc,
					info->pdata->temper_ch);
		}
#endif
		break;
	case TEMPER_EXT_ADC:
#if defined(CONFIG_STMPE811_ADC)
		temper = stmpe811_get_adc_value(info->pdata->temper_ch);
#endif
		break;
	case TEMPER_UNKNOWN:
	default:
		pr_info("%s: invalid temper src(%d)\n", __func__,
					info->pdata->temper_src);
		temper = 300;
		break;
	}

	pr_debug("%s: temper(%d), source(%d)\n", __func__,
			temper, info->pdata->temper_src);
	return temper;
}
static int samsung_get_bat_adc(void)
{
  return s3c_adc_read(mixtile_adc_bat_info.client, BAT_ADC_CHANNEL);
}
Example #12
0
static int mx_mic_read_adc(struct gpio_switch_data *switch_data)
{
	int ret = s3c_adc_read(switch_data->client,  switch_data->adc_channel);	
	return ret;
}
static int read_ta_adc(enum charge_connector conn, int ta_check_sel)
{
	int adc_max = -1;
	int adc_min = 1 << 11;
	int adc_total = 0;
	int i, j;
	int ret;

	mutex_lock(&manta_bat_adc_lock);

	/* switch to check adc */
	if (conn == CHARGE_CONNECTOR_USB)
		gpio_set_value(GPIO_USB_SEL1, 0);
	else {
		ret = manta_pogo_charge_detect_start(ta_check_sel);
		if (ret < 0) {
			pr_err("%s: Failed to start pogo charger detection\n",
				__func__);
			goto fail_gpio;
		}
	}

	msleep(100);

	for (i = 0; i < ADC_NUM_SAMPLES; i++) {
		ret = s3c_adc_read(ta_adc_client, 0);

		if (ret == -ETIMEDOUT) {
			for (j = 0; j < ADC_LIMIT_ERR_COUNT; j++) {
				msleep(20);
				ret = s3c_adc_read(ta_adc_client, 0);
				if (ret > 0)
					break;
			}
			if (j >= ADC_LIMIT_ERR_COUNT) {
				pr_err("%s: Retry count exceeded\n", __func__);
				goto out;
			}
		} else if (ret < 0) {
			pr_err("%s: Failed read adc value : %d\n",
				__func__, ret);
			goto out;
		}

		if (ret > adc_max)
			adc_max = ret;
		if (ret < adc_min)
			adc_min = ret;

		adc_total += ret;
	}

	ret = (adc_total - adc_max - adc_min) / (ADC_NUM_SAMPLES - 2);

out:
	msleep(50);

	/* switch back to normal */
	if (conn == CHARGE_CONNECTOR_USB)
		gpio_set_value(GPIO_USB_SEL1, 1);
	else
		manta_pogo_charge_detect_end();

fail_gpio:
	mutex_unlock(&manta_bat_adc_lock);
	return ret;
}