aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm63.c
diff options
context:
space:
mode:
authorDirk Eibach <eibach@gdsys.de>2011-02-09 04:51:34 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2011-02-09 16:45:42 -0500
commit2778fb13ba0fed1b3e4a040e71f7881d399610a3 (patch)
tree20ed43888c87488b7bfe02cd25ff074e85cad850 /drivers/hwmon/lm63.c
parent100b33c8bd8a3235fd0b7948338d6cbb3db3c63d (diff)
hwmon: (lm63) Consider LM64 temperature offset
LM64 has 16 degrees Celsius temperature offset on all remote sensor registers. This was not considered When LM64 support was added to lm63.c. Signed-off-by: Dirk Eibach <eibach@gdsys.de> Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com> Cc: stable@kernel.org
Diffstat (limited to 'drivers/hwmon/lm63.c')
-rw-r--r--drivers/hwmon/lm63.c59
1 files changed, 47 insertions, 12 deletions
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c
index 776aeb3019d2..508cb291f71b 100644
--- a/drivers/hwmon/lm63.c
+++ b/drivers/hwmon/lm63.c
@@ -98,6 +98,9 @@ static const unsigned short normal_i2c[] = { 0x18, 0x4c, 0x4e, I2C_CLIENT_END };
98 * value, it uses signed 8-bit values with LSB = 1 degree Celsius. 98 * value, it uses signed 8-bit values with LSB = 1 degree Celsius.
99 * For remote temperature, low and high limits, it uses signed 11-bit values 99 * For remote temperature, low and high limits, it uses signed 11-bit values
100 * with LSB = 0.125 degree Celsius, left-justified in 16-bit registers. 100 * with LSB = 0.125 degree Celsius, left-justified in 16-bit registers.
101 * For LM64 the actual remote diode temperature is 16 degree Celsius higher
102 * than the register reading. Remote temperature setpoints have to be
103 * adapted accordingly.
101 */ 104 */
102 105
103#define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \ 106#define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \
@@ -165,6 +168,8 @@ struct lm63_data {
165 struct mutex update_lock; 168 struct mutex update_lock;
166 char valid; /* zero until following fields are valid */ 169 char valid; /* zero until following fields are valid */
167 unsigned long last_updated; /* in jiffies */ 170 unsigned long last_updated; /* in jiffies */
171 int kind;
172 int temp2_offset;
168 173
169 /* registers values */ 174 /* registers values */
170 u8 config, config_fan; 175 u8 config, config_fan;
@@ -247,16 +252,34 @@ static ssize_t show_pwm1_enable(struct device *dev, struct device_attribute *dum
247 return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2); 252 return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2);
248} 253}
249 254
250static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr, 255/*
251 char *buf) 256 * There are 8bit registers for both local(temp1) and remote(temp2) sensor.
257 * For remote sensor registers temp2_offset has to be considered,
258 * for local sensor it must not.
259 * So we need separate 8bit accessors for local and remote sensor.
260 */
261static ssize_t show_local_temp8(struct device *dev,
262 struct device_attribute *devattr,
263 char *buf)
252{ 264{
253 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 265 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
254 struct lm63_data *data = lm63_update_device(dev); 266 struct lm63_data *data = lm63_update_device(dev);
255 return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index])); 267 return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index]));
256} 268}
257 269
258static ssize_t set_temp8(struct device *dev, struct device_attribute *dummy, 270static ssize_t show_remote_temp8(struct device *dev,
259 const char *buf, size_t count) 271 struct device_attribute *devattr,
272 char *buf)
273{
274 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
275 struct lm63_data *data = lm63_update_device(dev);
276 return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index])
277 + data->temp2_offset);
278}
279
280static ssize_t set_local_temp8(struct device *dev,
281 struct device_attribute *dummy,
282 const char *buf, size_t count)
260{ 283{
261 struct i2c_client *client = to_i2c_client(dev); 284 struct i2c_client *client = to_i2c_client(dev);
262 struct lm63_data *data = i2c_get_clientdata(client); 285 struct lm63_data *data = i2c_get_clientdata(client);
@@ -274,7 +297,8 @@ static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
274{ 297{
275 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 298 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
276 struct lm63_data *data = lm63_update_device(dev); 299 struct lm63_data *data = lm63_update_device(dev);
277 return sprintf(buf, "%d\n", TEMP11_FROM_REG(data->temp11[attr->index])); 300 return sprintf(buf, "%d\n", TEMP11_FROM_REG(data->temp11[attr->index])
301 + data->temp2_offset);
278} 302}
279 303
280static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, 304static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
@@ -294,7 +318,7 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
294 int nr = attr->index; 318 int nr = attr->index;
295 319
296 mutex_lock(&data->update_lock); 320 mutex_lock(&data->update_lock);
297 data->temp11[nr] = TEMP11_TO_REG(val); 321 data->temp11[nr] = TEMP11_TO_REG(val - data->temp2_offset);
298 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], 322 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2],
299 data->temp11[nr] >> 8); 323 data->temp11[nr] >> 8);
300 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], 324 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1],
@@ -310,6 +334,7 @@ static ssize_t show_temp2_crit_hyst(struct device *dev, struct device_attribute
310{ 334{
311 struct lm63_data *data = lm63_update_device(dev); 335 struct lm63_data *data = lm63_update_device(dev);
312 return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[2]) 336 return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[2])
337 + data->temp2_offset
313 - TEMP8_FROM_REG(data->temp2_crit_hyst)); 338 - TEMP8_FROM_REG(data->temp2_crit_hyst));
314} 339}
315 340
@@ -324,7 +349,7 @@ static ssize_t set_temp2_crit_hyst(struct device *dev, struct device_attribute *
324 long hyst; 349 long hyst;
325 350
326 mutex_lock(&data->update_lock); 351 mutex_lock(&data->update_lock);
327 hyst = TEMP8_FROM_REG(data->temp8[2]) - val; 352 hyst = TEMP8_FROM_REG(data->temp8[2]) + data->temp2_offset - val;
328 i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST, 353 i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST,
329 HYST_TO_REG(hyst)); 354 HYST_TO_REG(hyst));
330 mutex_unlock(&data->update_lock); 355 mutex_unlock(&data->update_lock);
@@ -355,16 +380,21 @@ static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan,
355static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1); 380static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1);
356static DEVICE_ATTR(pwm1_enable, S_IRUGO, show_pwm1_enable, NULL); 381static DEVICE_ATTR(pwm1_enable, S_IRUGO, show_pwm1_enable, NULL);
357 382
358static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp8, NULL, 0); 383static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_local_temp8, NULL, 0);
359static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8, 384static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_local_temp8,
360 set_temp8, 1); 385 set_local_temp8, 1);
361 386
362static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); 387static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0);
363static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11, 388static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11,
364 set_temp11, 1); 389 set_temp11, 1);
365static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11, 390static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11,
366 set_temp11, 2); 391 set_temp11, 2);
367static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp8, NULL, 2); 392/*
393 * On LM63, temp2_crit can be set only once, which should be job
394 * of the bootloader.
395 */
396static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_remote_temp8,
397 NULL, 2);
368static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst, 398static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst,
369 set_temp2_crit_hyst); 399 set_temp2_crit_hyst);
370 400
@@ -479,7 +509,12 @@ static int lm63_probe(struct i2c_client *new_client,
479 data->valid = 0; 509 data->valid = 0;
480 mutex_init(&data->update_lock); 510 mutex_init(&data->update_lock);
481 511
482 /* Initialize the LM63 chip */ 512 /* Set the device type */
513 data->kind = id->driver_data;
514 if (data->kind == lm64)
515 data->temp2_offset = 16000;
516
517 /* Initialize chip */
483 lm63_init_client(new_client); 518 lm63_init_client(new_client);
484 519
485 /* Register sysfs hooks */ 520 /* Register sysfs hooks */