Ejemplo n.º 1
0
/*
 *sysfs hook function
 */
static ssize_t adc_read(struct device *dev,
			struct device_attribute *devattr, char *buf) {

	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct bcmpmu59xxx *bcmpmu = gbcmpmu;
	struct bcmpmu_adc_result result;
	int ret = 0;
	int len = 0;

	len += snprintf(buf + len, 30, "SAR READ OF channel = %d", attr->index);
	ret = bcmpmu_adc_read(bcmpmu, attr->index,
						PMU_ADC_REQ_SAR_MODE, &result);
	if (ret < 0)
		return ret;
	/* Powersupply frame work expects temperature to be
	 * reported in Tenth multiple of centigrade. so we are maintaning
	 * the temperature look up table in same manner in board file.
	 * But reporting the same to user confuses.
	 * so again dividing by 10 and reporting*/
	if ((attr->index == PMU_ADC_CHANN_NTC) ||
			(attr->index == PMU_ADC_CHANN_32KTEMP) ||
			(attr->index == PMU_ADC_CHANN_PATEMP) ||
			(attr->index == PMU_ADC_CHANN_DIE_TEMP))
		result.conv = result.conv / 10;

	len += snprintf(buf + len, 30, " raw = 0x%x conv = %d\n",
						result.raw, result.conv);

	len += snprintf(buf + len, 30, "RTM READ OF channel = %d", attr->index);
	ret = bcmpmu_adc_read(bcmpmu, attr->index,
						PMU_ADC_REQ_RTM_MODE, &result);
	if (ret < 0)
		return ret;
	/* Powersupply frame work expects temperature to be
	 * reported in Tenth multiple of centigrade. so we are maintaning
	 * the temperature look up table in same manner in board file.
	 * But reporting the same to user confuses.
	 * so again dividing by 10 and reporting*/
	if ((attr->index == PMU_ADC_CHANN_NTC) ||
			(attr->index == PMU_ADC_CHANN_32KTEMP) ||
			(attr->index == PMU_ADC_CHANN_PATEMP) ||
			(attr->index == PMU_ADC_CHANN_DIE_TEMP))
		result.conv = result.conv / 10;
	len += snprintf(buf + len, 30, " raw = 0x%x conv = %d\n",
						result.raw, result.conv);

	return len;

}
static void  sec_thermistor_bcmpmu_adc_read(struct bcmpmu59xxx *bcmpmu,
				enum bcmpmu_adc_channel channel,
				enum bcmpmu_adc_req req,
				struct bcmpmu_adc_result *result)
{
	int ret = 0;
	int retries = SEC_THERMISTOR_ADC_READ_TRIES;
	static int t_result_conv;

	while (retries--) {
		ret = bcmpmu_adc_read(bcmpmu, channel, req, result);
		if (!ret)
			break;
		msleep(SEC_THERMISTOR_ADC_RETRY_DELAY);
	}

#if 1
	if(retries <= 0)
		result->conv= t_result_conv;
	else
		t_result_conv = result->conv;
#else
	BUG_ON(retries <= 0);
#endif
}
static int bcmpmu_rpc_get_val(struct bcmpmu59xxx *bcmpmu,
				enum bcmpmu_adc_channel channel,
				enum bcmpmu_adc_req req,
				struct bcmpmu_adc_result *result)
{
	int ret;
	int retry = ADC_RETRY;
	while (retry) {
		ret = bcmpmu_adc_read(bcmpmu, channel, req, result);
		if (!ret)
			break;
		retry--;
	}
	return ret;
}
static void  spa_bcmpmu_adc_read(struct bcmpmu59xxx *bcmpmu,
				enum bcmpmu_adc_channel channel,
				enum bcmpmu_adc_req req,
				struct bcmpmu_adc_result *result)
{
	int ret = 0;
	int retries = SPA_ADC_READ_TRIES;

	while (retries--) {
		ret = bcmpmu_adc_read(bcmpmu, channel, req, result);
		if (!ret)
			break;
	}
	BUG_ON(retries <= 0);
}