Exemplo n.º 1
0
Arquivo: tmp102.c Projeto: Lyude/linux
static int tmp102_read(struct device *dev, enum hwmon_sensor_types type,
		       u32 attr, int channel, long *temp)
{
	struct tmp102 *tmp102 = dev_get_drvdata(dev);
	unsigned int regval;
	int err, reg;

	switch (attr) {
	case hwmon_temp_input:
		/* Is it too early to return a conversion ? */
		if (time_before(jiffies, tmp102->ready_time)) {
			dev_dbg(dev, "%s: Conversion not ready yet..\n", __func__);
			return -EAGAIN;
		}
		reg = TMP102_TEMP_REG;
		break;
	case hwmon_temp_max_hyst:
		reg = TMP102_TLOW_REG;
		break;
	case hwmon_temp_max:
		reg = TMP102_THIGH_REG;
		break;
	default:
		return -EOPNOTSUPP;
	}

	err = regmap_read(tmp102->regmap, reg, &regval);
	if (err < 0)
		return err;
	*temp = tmp102_reg_to_mC(regval);

	return 0;
}
Exemplo n.º 2
0
static struct tmp102 *tmp102_update_device(struct i2c_client *client)
{
	struct tmp102 *tmp102 = i2c_get_clientdata(client);

	mutex_lock(&tmp102->lock);
	if (time_after(jiffies, tmp102->last_update + HZ / 3)) {
		int i;
		for (i = 0; i < ARRAY_SIZE(tmp102->temp); ++i) {
			int status = tmp102_read_reg(client, tmp102_reg[i]);
			if (status > -1)
				tmp102->temp[i] = tmp102_reg_to_mC(status);
		}
		tmp102->last_update = jiffies;
	}
	mutex_unlock(&tmp102->lock);
	return tmp102;
}
Exemplo n.º 3
0
static struct tmp102 *tmp102_update_device(struct device *dev)
{
	struct tmp102 *tmp102 = dev_get_drvdata(dev);
	struct i2c_client *client = tmp102->client;

	mutex_lock(&tmp102->lock);
	if (time_after(jiffies, tmp102->last_update + HZ / 3)) {
		int i;
		for (i = 0; i < ARRAY_SIZE(tmp102->temp); ++i) {
			int status = i2c_smbus_read_word_swapped(client,
								 tmp102_reg[i]);
			if (status > -1)
				tmp102->temp[i] = tmp102_reg_to_mC(status);
		}
		tmp102->last_update = jiffies;
	}
	mutex_unlock(&tmp102->lock);
	return tmp102;
}
static int tmp102_read_current_temp(struct device *dev)
{
	int index = 0;
	struct i2c_client *client = to_i2c_client(dev);
	struct tmp102_temp_sensor *tmp102 = i2c_get_clientdata(client);

	tmp102 = i2c_get_clientdata(client);

	mutex_lock(&tmp102->sensor_mutex);
	if (time_after(jiffies, tmp102->last_update + HZ / 3)) {
		int status = tmp102_read_reg(client, tmp102_reg[index]);
		if (status > -1)
			tmp102->temp[index] = tmp102_reg_to_mC(status);
		tmp102->last_update = jiffies;
	}
	mutex_unlock(&tmp102->sensor_mutex);

	return tmp102->temp[index];
}
Exemplo n.º 5
0
static int tmp102_read_temp(void *dev, int *temp)
{
	struct tmp102 *tmp102 = dev_get_drvdata(dev);
	unsigned int reg;
	int ret;

	if (time_before(jiffies, tmp102->ready_time)) {
		dev_dbg(dev, "%s: Conversion not ready yet..\n", __func__);
		return -EAGAIN;
	}

	ret = regmap_read(tmp102->regmap, TMP102_TEMP_REG, &reg);
	if (ret < 0)
		return ret;

	*temp = tmp102_reg_to_mC(reg);

	return 0;
}
Exemplo n.º 6
0
static ssize_t tmp102_show_temp(struct device *dev,
				struct device_attribute *attr,
				char *buf)
{
	struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
	struct tmp102 *tmp102 = dev_get_drvdata(dev);
	int regaddr = sda->index;
	unsigned int reg;
	int err;

	if (regaddr == TMP102_TEMP_REG &&
	    time_before(jiffies, tmp102->ready_time))
		return -EAGAIN;

	err = regmap_read(tmp102->regmap, regaddr, &reg);
	if (err < 0)
		return err;

	return sprintf(buf, "%d\n", tmp102_reg_to_mC(reg));
}
Exemplo n.º 7
0
static int tmp102_read_current_temp(void)
{
#ifdef USER_SPACE_ALERT
	enum temp_state prev_state;
#endif
	int temp_mC=0;
	struct tmp102_temp_sensor *tmp102=tmp102_data;
	mutex_lock(&tmp102->sensor_mutex);
#ifdef USER_SPACE_ALERT
	prev_state=tmp102->state;
#endif
	if (time_after(jiffies, tmp102->last_update + HZ / 3)) {
		int status = tmp102_read_reg(tmp102->iclient, TMP102_TEMP_REG);
		if (status > -1)
			temp_mC = tmp102_reg_to_mC(status);
			tmp102->temp=temp_mC/1000;
		tmp102->last_update = jiffies;
	}
#ifdef CONFIG_THERMAL_DEBUG
	printk(KERN_DEBUG "%s:%d\n", __func__, tmp102->temp);
#endif
#ifdef USER_SPACE_ALERT
	if(tmp102->temp>=SHUTDOWN_TEMP_THRESHOLD){
		tmp102->state=SHUTDOWN_TEMP_STATE;
	}
	else if(tmp102->temp>=HIGH_TEMP_THRESHOLD){
		tmp102->state=HIGH_TEMP_STATE;
	}else {
		tmp102->state=LOW_TEMP_STATE;
	}
	if(tmp102->state != prev_state)
		tmp102_uevent_send(tmp102);
#endif
	mutex_unlock(&tmp102->sensor_mutex);
	return tmp102->temp;
}