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); }
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, &temp102_attr_group); /* Reset TMP102 and Stop monitoring*/ tmp102_write_reg(client, TMP102_CONF_REG,(TMP102_RESET|TMP102_CONF_SD)); kfree(tmp102->tpcb); kfree(tmp102); return 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); }
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 ssize_t tmp102_set_temp(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); struct i2c_client *client = to_i2c_client(dev); struct tmp102 *tmp102 = i2c_get_clientdata(client); long val; int status; if (strict_strtol(buf, 10, &val) < 0) return -EINVAL; val = SENSORS_LIMIT(val, -256000, 255000); mutex_lock(&tmp102->lock); tmp102->temp[sda->index] = val; status = tmp102_write_reg(client, tmp102_reg[sda->index], tmp102_mC_to_reg(val)); mutex_unlock(&tmp102->lock); return status ? : count; }
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; }
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; }