static int tmp102_temp_sensor_resume(struct i2c_client *client)
{
	int conf = tmp102_read_reg(client, TMP102_CONF_REG);

	if (conf < 0)
		return conf;
	conf &= ~TMP102_CONF_SD;

	return tmp102_write_reg(client, TMP102_CONF_REG, conf);
}
static int tmp102_temp_sensor_suspend(struct i2c_client *client,
			pm_message_t mesg)
{
	int conf = tmp102_read_reg(client, TMP102_CONF_REG);

	if (conf < 0)
		return conf;
	conf |= TMP102_CONF_SD;

	return tmp102_write_reg(client, TMP102_CONF_REG, conf);
}
Example #3
0
static int tmp102_resume(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);
	int config;

	config = tmp102_read_reg(client, TMP102_CONF_REG);
	if (config < 0)
		return config;

	config &= ~TMP102_CONF_SD;
	return tmp102_write_reg(client, TMP102_CONF_REG, config);
}
Example #4
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;
}
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];
}
static int __devexit tmp102_temp_sensor_remove(struct i2c_client *client)
{
	struct tmp102_temp_sensor *tmp102 = i2c_get_clientdata(client);

	sysfs_remove_group(&client->dev.kobj, &tmp102_temp_sensor_attr_group);

	/* Stop monitoring if device was stopped originally */
	if (tmp102->config_orig & TMP102_CONF_SD) {
		int config;

		config = tmp102_read_reg(client, TMP102_CONF_REG);
		if (config >= 0)
			tmp102_write_reg(client, TMP102_CONF_REG,
					 config | TMP102_CONF_SD);
	}

	kfree(tmp102);

	return 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;
}
static int __devinit tmp102_temp_sensor_probe(
		struct i2c_client *client, const struct i2c_device_id *id)
{
	struct tmp102_temp_sensor *tmp102;
	int ret = 0;
#ifdef CONFIG_THERMAL_DEBUG
	printk(KERN_DEBUG "%s\n", __func__);
#endif
	if (!i2c_check_functionality(client->adapter,
				     I2C_FUNC_SMBUS_WORD_DATA)) {
		dev_err(&client->dev, "adapter doesn't support SMBus word "
			"transactions\n");

		return -ENODEV;
	}

	tmp102 = kzalloc(sizeof(struct tmp102_temp_sensor), GFP_KERNEL);
	if (!tmp102)
		return -ENOMEM;

	mutex_init(&tmp102->sensor_mutex);

	tmp102->iclient = client;
	tmp102->dev = &client->dev;

	kobject_uevent(&client->dev.kobj, KOBJ_ADD);
	i2c_set_clientdata(client, tmp102);

	ret = tmp102_read_reg(client, TMP102_CONF_REG);
	if (ret < 0) {
		dev_err(&client->dev, "error reading config register\n");
		goto free_err;
	}
	tmp102->config_orig = ret;
	ret = tmp102_write_reg(client, TMP102_CONF_REG, TMP102_CONFIG);
	if (ret < 0) {
		dev_err(&client->dev, "error writing config register\n");
		goto restore_config_err;
	}
	ret = tmp102_read_reg(client, TMP102_CONF_REG);
	if (ret < 0) {
		dev_err(&client->dev, "error reading config register\n");
		goto restore_config_err;
	}
	ret &= ~TMP102_CONFIG_RD_ONLY;
	if (ret != TMP102_CONFIG) {
		dev_err(&client->dev, "config settings did not stick\n");
		ret = -ENODEV;
		goto restore_config_err;
	}
	tmp102->last_update = jiffies - HZ;
	mutex_init(&tmp102->sensor_mutex);

	ret = sysfs_create_group(&client->dev.kobj,
		&tmp102_temp_sensor_attr_group);
	if (ret)
		goto sysfs_create_err;

	tmp102->therm_fw = kzalloc(sizeof(struct thermal_dev), GFP_KERNEL);
	if (tmp102->therm_fw) {
		tmp102->therm_fw->name = TMP102_SENSOR_NAME;
		tmp102->therm_fw->domain_name = "pcb";
		tmp102->therm_fw->dev = tmp102->dev;
		tmp102->therm_fw->dev_ops = &tmp102_temp_sensor_ops;
		thermal_sensor_dev_register(tmp102->therm_fw);
	} else {
		ret = -ENOMEM;
		goto therm_fw_alloc_err;
	}

	dev_info(&client->dev, "initialized\n");

	return 0;

sysfs_create_err:
	thermal_sensor_dev_unregister(tmp102->therm_fw);
	kfree(tmp102->therm_fw);
restore_config_err:
	tmp102_write_reg(client, TMP102_CONF_REG, tmp102->config_orig);
therm_fw_alloc_err:
free_err:
	mutex_destroy(&tmp102->sensor_mutex);
	kfree(tmp102);

	return ret;
}
static int __devinit tmp102_temp_sensor_probe(
		struct i2c_client *client, const struct i2c_device_id *id)
{
	int ret = 0;
	struct tmp102_temp_sensor *tmp102;
#ifdef CONFIG_THERMAL_DEBUG
	printk(KERN_DEBUG "%s\n", __func__);
#endif
	if (!i2c_check_functionality(client->adapter,
				     I2C_FUNC_SMBUS_WORD_DATA)) {
		dev_err(&client->dev, "adapter doesn't support SMBus word "
			"transactions\n");

		return -ENODEV;
	}

	tmp102 = kzalloc(sizeof(struct tmp102_temp_sensor), GFP_KERNEL);
	if (!tmp102)
		return -ENOMEM;

	tmp102_data=tmp102;
	mutex_init(&tmp102->sensor_mutex);
	tmp102->iclient = client;

	i2c_set_clientdata(client, tmp102);
	/*Reset TMP102*/
	tmp102_write_reg(client, TMP102_CONF_REG,TMP102_RESET);
	if (ret < 0) {
		dev_err(&client->dev, "error writing config register\n");
		goto free_err;;
	}
	/*Config TMP102*/
	ret = tmp102_write_reg(client, TMP102_CONF_REG, TMP102_CONFIG);
	if (ret < 0) {
		dev_err(&client->dev, "error writing config register\n");
		goto restore_config_err;
	}
	/*Verify config*/
	ret = tmp102_read_reg(client, TMP102_CONF_REG);
	if (ret < 0) {
		dev_err(&client->dev, "error reading config register\n");
		goto restore_config_err;
	}
#ifdef CONFIG_THERMAL_DEBUG
	printk(KERN_DEBUG "config=0x%X\n", ret);
#endif
	ret &= ~TMP102_CONFIG_RD_ONLY;
	if (ret != TMP102_CONFIG) {
		dev_err(&client->dev, "config settings did not stick\n");
		ret = -ENODEV;
		goto restore_config_err;
	}

	tmp102->last_update = jiffies - HZ;
	tmp102->temp=DEFAULT_TEMPERATURE;
	tmp102->state=LOW_TEMP_STATE;

	ret = sysfs_create_group(&client->dev.kobj, &temp102_attr_group);
	if (ret){
		dev_err(&client->dev, "unable to create attribute\n");
		goto sysfs_create_err;
	}

	tmp102->tpcb=kzalloc(sizeof(struct pcb_sens), GFP_KERNEL);
	if(tmp102->tpcb){
		tmp102->tpcb->update_temp=tmp102_read_current_temp;
		omap4_duty_pcb_register(tmp102->tpcb);
	}else {
		ret = -ENOMEM;
		goto tpcb_alloc_err;
	}

	dev_info(&client->dev, "initialized\n");

	return 0;

tpcb_alloc_err:
	sysfs_remove_group(&client->dev.kobj, &temp102_attr_group);
sysfs_create_err:
restore_config_err:
	tmp102_write_reg(client, TMP102_CONF_REG,(TMP102_RESET|TMP102_CONF_SD));
free_err:
	mutex_destroy(&tmp102->sensor_mutex);
	kfree(tmp102);

	return ret;
}
Example #10
0
static int __devinit tmp102_probe(struct i2c_client *client,
				  const struct i2c_device_id *id)
{
	struct tmp102 *tmp102;
	int status;

	if (!i2c_check_functionality(client->adapter,
				     I2C_FUNC_SMBUS_WORD_DATA)) {
		dev_err(&client->dev, "adapter doesn't support SMBus word "
			"transactions\n");
		return -ENODEV;
	}

	tmp102 = kzalloc(sizeof(*tmp102), GFP_KERNEL);
	if (!tmp102) {
		dev_dbg(&client->dev, "kzalloc failed\n");
		return -ENOMEM;
	}
	i2c_set_clientdata(client, tmp102);

	status = tmp102_read_reg(client, TMP102_CONF_REG);
	if (status < 0) {
		dev_err(&client->dev, "error reading config register\n");
		goto fail_free;
	}
	tmp102->config_orig = status;
	status = tmp102_write_reg(client, TMP102_CONF_REG, TMP102_CONFIG);
	if (status < 0) {
		dev_err(&client->dev, "error writing config register\n");
		goto fail_restore_config;
	}
	status = tmp102_read_reg(client, TMP102_CONF_REG);
	if (status < 0) {
		dev_err(&client->dev, "error reading config register\n");
		goto fail_restore_config;
	}
	status &= ~TMP102_CONFIG_RD_ONLY;
	if (status != TMP102_CONFIG) {
		dev_err(&client->dev, "config settings did not stick\n");
		status = -ENODEV;
		goto fail_restore_config;
	}
	tmp102->last_update = jiffies - HZ;
	mutex_init(&tmp102->lock);

	status = sysfs_create_group(&client->dev.kobj, &tmp102_attr_group);
	if (status) {
		dev_dbg(&client->dev, "could not create sysfs files\n");
		goto fail_restore_config;
	}
	tmp102->hwmon_dev = hwmon_device_register(&client->dev);
	if (IS_ERR(tmp102->hwmon_dev)) {
		dev_dbg(&client->dev, "unable to register hwmon device\n");
		status = PTR_ERR(tmp102->hwmon_dev);
		goto fail_remove_sysfs;
	}

	dev_info(&client->dev, "initialized\n");

	return 0;

fail_remove_sysfs:
	sysfs_remove_group(&client->dev.kobj, &tmp102_attr_group);
fail_restore_config:
	tmp102_write_reg(client, TMP102_CONF_REG, tmp102->config_orig);
fail_free:
	kfree(tmp102);

	return status;
}