lm73.c (9a64e8e0ace51b309fdcff4b4754b3649250382a) | lm73.c (0602934f302e016e2ea5dc6951681bfac77455ef) |
---|---|
1/* 2 * LM73 Sensor driver 3 * Based on LM75 4 * 5 * Copyright (C) 2007, CenoSYS (www.cenosys.com). 6 * Copyright (C) 2009, Bollore telecom (www.bolloretelecom.eu). 7 * 8 * Guillaume Ligneul <guillaume.ligneul@gmail.com> --- 35 unchanged lines hidden (view full) --- 44 45static ssize_t set_temp(struct device *dev, struct device_attribute *da, 46 const char *buf, size_t count) 47{ 48 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 49 struct i2c_client *client = to_i2c_client(dev); 50 long temp; 51 short value; | 1/* 2 * LM73 Sensor driver 3 * Based on LM75 4 * 5 * Copyright (C) 2007, CenoSYS (www.cenosys.com). 6 * Copyright (C) 2009, Bollore telecom (www.bolloretelecom.eu). 7 * 8 * Guillaume Ligneul <guillaume.ligneul@gmail.com> --- 35 unchanged lines hidden (view full) --- 44 45static ssize_t set_temp(struct device *dev, struct device_attribute *da, 46 const char *buf, size_t count) 47{ 48 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 49 struct i2c_client *client = to_i2c_client(dev); 50 long temp; 51 short value; |
52 s32 err; |
|
52 53 int status = kstrtol(buf, 10, &temp); 54 if (status < 0) 55 return status; 56 57 /* Write value */ 58 value = (short) SENSORS_LIMIT(temp/250, (LM73_TEMP_MIN*4), 59 (LM73_TEMP_MAX*4)) << 5; | 53 54 int status = kstrtol(buf, 10, &temp); 55 if (status < 0) 56 return status; 57 58 /* Write value */ 59 value = (short) SENSORS_LIMIT(temp/250, (LM73_TEMP_MIN*4), 60 (LM73_TEMP_MAX*4)) << 5; |
60 i2c_smbus_write_word_swapped(client, attr->index, value); 61 return count; | 61 err = i2c_smbus_write_word_swapped(client, attr->index, value); 62 return (err < 0) ? err : count; |
62} 63 64static ssize_t show_temp(struct device *dev, struct device_attribute *da, 65 char *buf) 66{ 67 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 68 struct i2c_client *client = to_i2c_client(dev); | 63} 64 65static ssize_t show_temp(struct device *dev, struct device_attribute *da, 66 char *buf) 67{ 68 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 69 struct i2c_client *client = to_i2c_client(dev); |
70 int temp; 71 72 s32 err = i2c_smbus_read_word_swapped(client, attr->index); 73 if (err < 0) 74 return err; 75 |
|
69 /* use integer division instead of equivalent right shift to 70 guarantee arithmetic shift and preserve the sign */ | 76 /* use integer division instead of equivalent right shift to 77 guarantee arithmetic shift and preserve the sign */ |
71 int temp = ((s16) (i2c_smbus_read_word_swapped(client, 72 attr->index))*250) / 32; 73 return sprintf(buf, "%d\n", temp); | 78 temp = (((s16) err) * 250) / 32; 79 return scnprintf(buf, PAGE_SIZE, "%d\n", temp); |
74} 75 76 77/*-----------------------------------------------------------------------*/ 78 79/* sysfs attributes for hwmon */ 80 81static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, --- 120 unchanged lines hidden --- | 80} 81 82 83/*-----------------------------------------------------------------------*/ 84 85/* sysfs attributes for hwmon */ 86 87static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, --- 120 unchanged lines hidden --- |