diff options
author | Marcel Ziswiler <marcel.ziswiler@toradex.com> | 2013-01-07 14:20:43 +0100 |
---|---|---|
committer | Marcel Ziswiler <marcel.ziswiler@toradex.com> | 2013-01-07 14:22:20 +0100 |
commit | 7cea39b9b7c6c82f74b5e624a534c4c2a3b5e317 (patch) | |
tree | 85063a638084e5eb39f9016773e7d42638f10abf | |
parent | fc0642e73de36ea93ddb7ec93ab4d896e52f0e9a (diff) |
hwmon: lm95245: add probe callback and remote OS hooks
In order to allow integrating with external thermal throttling code add
a probe callback and remote over-temperature shutdown hooks.
-rw-r--r-- | drivers/hwmon/lm95245.c | 54 | ||||
-rw-r--r-- | include/linux/lm95245.h | 4 |
2 files changed, 45 insertions, 13 deletions
diff --git a/drivers/hwmon/lm95245.c b/drivers/hwmon/lm95245.c index 33c8e35a67be..24e50f5c157c 100644 --- a/drivers/hwmon/lm95245.c +++ b/drivers/hwmon/lm95245.c @@ -237,12 +237,9 @@ static unsigned long lm95245_set_conversion_rate(struct i2c_client *client, } /* Sysfs stuff */ -static ssize_t show_input(struct device *dev, struct device_attribute *attr, - char *buf) +void thermal_get_temp(struct device *dev, int *temp, int index) { struct lm95245_data *data = lm95245_update_device(dev); - int temp; - int index = to_sensor_dev_attr(attr)->index; /* * Local temp is always signed @@ -250,11 +247,26 @@ static ssize_t show_input(struct device *dev, struct device_attribute *attr, * use signed calculation for remote if signed bit is set */ if (index == INDEX_LOCAL_TEMP || data->regs[index + OFFSET_HIGH_SIGNED] & 0x80) - temp = temp_from_reg_signed(data->regs[index + OFFSET_HIGH_SIGNED], + *temp = temp_from_reg_signed(data->regs[index + OFFSET_HIGH_SIGNED], data->regs[index + OFFSET_LOW_SIGNED]); else - temp = temp_from_reg_unsigned(data->regs[index + OFFSET_HIGH_UNSIGNED], + *temp = temp_from_reg_unsigned(data->regs[index + OFFSET_HIGH_UNSIGNED], data->regs[index + OFFSET_LOW_UNSIGNED]); +} + +void lm95245_thermal_get_temp(struct device *dev, int *temp) +{ + thermal_get_temp(dev, temp, INDEX_REMOTE_TEMP); +} +EXPORT_SYMBOL(lm95245_thermal_get_temp); + +static ssize_t show_input(struct device *dev, struct device_attribute *attr, + char *buf) +{ + int temp = 0; + int index = to_sensor_dev_attr(attr)->index; + + thermal_get_temp(dev, &temp, index); return snprintf(buf, PAGE_SIZE - 1, "%d\n", temp); } @@ -269,16 +281,10 @@ static ssize_t show_limit(struct device *dev, struct device_attribute *attr, data->regs[index] * 1000); } -static ssize_t set_limit(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) +void thermal_set_limit(struct device *dev, int val, int index) { struct i2c_client *client = to_i2c_client(dev); struct lm95245_data *data = i2c_get_clientdata(client); - int index = to_sensor_dev_attr(attr)->index; - unsigned long val; - - if (strict_strtoul(buf, 10, &val) < 0) - return -EINVAL; val /= 1000; @@ -291,6 +297,24 @@ static ssize_t set_limit(struct device *dev, struct device_attribute *attr, i2c_smbus_write_byte_data(client, lm95245_reg_address[index], val); mutex_unlock(&data->update_lock); +} + +void lm95245_thermal_set_limit(struct device *dev, int val) +{ + thermal_set_limit(dev, val, INDEX_REMOTE_OS_LIMIT); +} +EXPORT_SYMBOL(lm95245_thermal_set_limit); + +static ssize_t set_limit(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + int index = to_sensor_dev_attr(attr)->index; + unsigned long val; + + if (strict_strtoul(buf, 10, &val) < 0) + return -EINVAL; + + thermal_set_limit(dev, (int)val, index); return count; } @@ -521,6 +545,10 @@ static int lm95245_probe(struct i2c_client *new_client, goto exit_remove_files; } + /* Notify callback that probe is done */ + if (new_client->dev.platform_data && ((struct lm95245_platform_data*)(new_client->dev.platform_data))->probe_callback) + ((struct lm95245_platform_data*)(new_client->dev.platform_data))->probe_callback(&new_client->dev); + return 0; exit_remove_files: diff --git a/include/linux/lm95245.h b/include/linux/lm95245.h index b9290c7708b2..cdc6846a901f 100644 --- a/include/linux/lm95245.h +++ b/include/linux/lm95245.h @@ -25,6 +25,10 @@ struct lm95245_platform_data { bool enable_os_pin; + void (*probe_callback)(struct device *dev); }; +void lm95245_thermal_get_temp(struct device *dev, int *temp); +void lm95245_thermal_set_limit(struct device *dev, int temp); + #endif /* _LINUX_LM95245_H */ |