aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-05-04 16:44:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-05-04 16:44:38 -0400
commite72a5d1ceb1c5cbe39c35c1c7a7f5909cbe8451a (patch)
treea076a1699561126f40afa80ead5b5276284c8a83 /drivers/hwmon
parentbd932ae1bd655979d0d765108721951051f0837d (diff)
parent3fbc81e3c0257c756c0955bcb291374d74c11f61 (diff)
Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging
Pull hwmon update from Jean Delvare: "Only lm75 driver updates this time" * 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging: hwmon: (lm75) Add support for the Dallas/Maxim DS7505 hwmon: (lm75) Tune resolution and sample time per chip hwmon: (lm75) Prepare to support per-chip resolution and sample time hwmon: (lm75) Per-chip configuration register initialization
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/Kconfig2
-rw-r--r--drivers/hwmon/lm75.c92
2 files changed, 86 insertions, 8 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 9c333d471433..0428e8a74b19 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -630,7 +630,7 @@ config SENSORS_LM75
630 temperature sensor chip, with models including: 630 temperature sensor chip, with models including:
631 631
632 - Analog Devices ADT75 632 - Analog Devices ADT75
633 - Dallas Semiconductor DS75 and DS1775 633 - Dallas Semiconductor DS75, DS1775 and DS7505
634 - Maxim MAX6625 and MAX6626 634 - Maxim MAX6625 and MAX6626
635 - Microchip MCP980x 635 - Microchip MCP980x
636 - National Semiconductor LM75, LM75A 636 - National Semiconductor LM75, LM75A
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 291edfff55bf..c03b490bba81 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -38,6 +38,7 @@ enum lm75_type { /* keep sorted in alphabetical order */
38 adt75, 38 adt75,
39 ds1775, 39 ds1775,
40 ds75, 40 ds75,
41 ds7505,
41 lm75, 42 lm75,
42 lm75a, 43 lm75a,
43 max6625, 44 max6625,
@@ -71,9 +72,12 @@ struct lm75_data {
71 struct device *hwmon_dev; 72 struct device *hwmon_dev;
72 struct mutex update_lock; 73 struct mutex update_lock;
73 u8 orig_conf; 74 u8 orig_conf;
75 u8 resolution; /* In bits, between 9 and 12 */
76 u8 resolution_limits;
74 char valid; /* !=0 if registers are valid */ 77 char valid; /* !=0 if registers are valid */
75 unsigned long last_updated; /* In jiffies */ 78 unsigned long last_updated; /* In jiffies */
76 u16 temp[3]; /* Register values, 79 unsigned long sample_time; /* In jiffies */
80 s16 temp[3]; /* Register values,
77 0 = input 81 0 = input
78 1 = max 82 1 = max
79 2 = hyst */ 83 2 = hyst */
@@ -93,12 +97,15 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *da,
93{ 97{
94 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 98 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
95 struct lm75_data *data = lm75_update_device(dev); 99 struct lm75_data *data = lm75_update_device(dev);
100 long temp;
96 101
97 if (IS_ERR(data)) 102 if (IS_ERR(data))
98 return PTR_ERR(data); 103 return PTR_ERR(data);
99 104
100 return sprintf(buf, "%d\n", 105 temp = ((data->temp[attr->index] >> (16 - data->resolution)) * 1000)
101 LM75_TEMP_FROM_REG(data->temp[attr->index])); 106 >> (data->resolution - 8);
107
108 return sprintf(buf, "%ld\n", temp);
102} 109}
103 110
104static ssize_t set_temp(struct device *dev, struct device_attribute *da, 111static ssize_t set_temp(struct device *dev, struct device_attribute *da,
@@ -110,13 +117,25 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
110 int nr = attr->index; 117 int nr = attr->index;
111 long temp; 118 long temp;
112 int error; 119 int error;
120 u8 resolution;
113 121
114 error = kstrtol(buf, 10, &temp); 122 error = kstrtol(buf, 10, &temp);
115 if (error) 123 if (error)
116 return error; 124 return error;
117 125
126 /*
127 * Resolution of limit registers is assumed to be the same as the
128 * temperature input register resolution unless given explicitly.
129 */
130 if (attr->index && data->resolution_limits)
131 resolution = data->resolution_limits;
132 else
133 resolution = data->resolution;
134
118 mutex_lock(&data->update_lock); 135 mutex_lock(&data->update_lock);
119 data->temp[nr] = LM75_TEMP_TO_REG(temp); 136 temp = clamp_val(temp, LM75_TEMP_MIN, LM75_TEMP_MAX);
137 data->temp[nr] = DIV_ROUND_CLOSEST(temp << (resolution - 8),
138 1000) << (16 - resolution);
120 lm75_write_value(client, LM75_REG_TEMP[nr], data->temp[nr]); 139 lm75_write_value(client, LM75_REG_TEMP[nr], data->temp[nr]);
121 mutex_unlock(&data->update_lock); 140 mutex_unlock(&data->update_lock);
122 return count; 141 return count;
@@ -151,6 +170,7 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
151 int status; 170 int status;
152 u8 set_mask, clr_mask; 171 u8 set_mask, clr_mask;
153 int new; 172 int new;
173 enum lm75_type kind = id->driver_data;
154 174
155 if (!i2c_check_functionality(client->adapter, 175 if (!i2c_check_functionality(client->adapter,
156 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) 176 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
@@ -167,8 +187,65 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
167 * Then tweak to be more precise when appropriate. 187 * Then tweak to be more precise when appropriate.
168 */ 188 */
169 set_mask = 0; 189 set_mask = 0;
170 clr_mask = (1 << 0) /* continuous conversions */ 190 clr_mask = LM75_SHUTDOWN; /* continuous conversions */
171 | (1 << 6) | (1 << 5); /* 9-bit mode */ 191
192 switch (kind) {
193 case adt75:
194 clr_mask |= 1 << 5; /* not one-shot mode */
195 data->resolution = 12;
196 data->sample_time = HZ / 8;
197 break;
198 case ds1775:
199 case ds75:
200 case stds75:
201 clr_mask |= 3 << 5;
202 set_mask |= 2 << 5; /* 11-bit mode */
203 data->resolution = 11;
204 data->sample_time = HZ;
205 break;
206 case ds7505:
207 set_mask |= 3 << 5; /* 12-bit mode */
208 data->resolution = 12;
209 data->sample_time = HZ / 4;
210 break;
211 case lm75:
212 case lm75a:
213 data->resolution = 9;
214 data->sample_time = HZ / 2;
215 break;
216 case max6625:
217 data->resolution = 9;
218 data->sample_time = HZ / 4;
219 break;
220 case max6626:
221 data->resolution = 12;
222 data->resolution_limits = 9;
223 data->sample_time = HZ / 4;
224 break;
225 case tcn75:
226 data->resolution = 9;
227 data->sample_time = HZ / 8;
228 break;
229 case mcp980x:
230 data->resolution_limits = 9;
231 /* fall through */
232 case tmp100:
233 case tmp101:
234 set_mask |= 3 << 5; /* 12-bit mode */
235 data->resolution = 12;
236 data->sample_time = HZ;
237 clr_mask |= 1 << 7; /* not one-shot mode */
238 break;
239 case tmp105:
240 case tmp175:
241 case tmp275:
242 case tmp75:
243 set_mask |= 3 << 5; /* 12-bit mode */
244 clr_mask |= 1 << 7; /* not one-shot mode */
245 data->resolution = 12;
246 data->sample_time = HZ / 2;
247 break;
248 }
172 249
173 /* configure as specified */ 250 /* configure as specified */
174 status = lm75_read_value(client, LM75_REG_CONF); 251 status = lm75_read_value(client, LM75_REG_CONF);
@@ -218,6 +295,7 @@ static const struct i2c_device_id lm75_ids[] = {
218 { "adt75", adt75, }, 295 { "adt75", adt75, },
219 { "ds1775", ds1775, }, 296 { "ds1775", ds1775, },
220 { "ds75", ds75, }, 297 { "ds75", ds75, },
298 { "ds7505", ds7505, },
221 { "lm75", lm75, }, 299 { "lm75", lm75, },
222 { "lm75a", lm75a, }, 300 { "lm75a", lm75a, },
223 { "max6625", max6625, }, 301 { "max6625", max6625, },
@@ -407,7 +485,7 @@ static struct lm75_data *lm75_update_device(struct device *dev)
407 485
408 mutex_lock(&data->update_lock); 486 mutex_lock(&data->update_lock);
409 487
410 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 488 if (time_after(jiffies, data->last_updated + data->sample_time)
411 || !data->valid) { 489 || !data->valid) {
412 int i; 490 int i;
413 dev_dbg(&client->dev, "Starting lm75 update\n"); 491 dev_dbg(&client->dev, "Starting lm75 update\n");