aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-10-17 11:51:14 -0400
committerJean Delvare <khali@mahadeva.delvare>2008-10-17 11:51:14 -0400
commit8a0795d9b8ce2247f9b34da81f8a229702c90f2d (patch)
treeb2ec51a5db0709b1ba63d87ce4985ea4d39d5173 /drivers/hwmon
parent86010c982db2030aad2c31f178b208964f5f6806 (diff)
hwmon: (lm85) Support different PWM frequency tables
The Analog Devices and SMSC devices supported by the lm85 driver do not have the same PWM frequency table as the National Semiconductor devices. Add support for per-device frequency tables. Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Herbert Poetzl <herbert@13thfloor.at>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/lm85.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index c323c2b89808..3a84dc863df0 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -5,6 +5,7 @@
5 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> 5 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
6 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> 6 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
7 Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> 7 Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
8 Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org>
8 9
9 Chip details at <http://www.national.com/ds/LM/LM85.pdf> 10 Chip details at <http://www.national.com/ds/LM/LM85.pdf>
10 11
@@ -192,20 +193,27 @@ static int RANGE_TO_REG(int range)
192 193
193/* These are the PWM frequency encodings */ 194/* These are the PWM frequency encodings */
194static const int lm85_freq_map[8] = { /* 1 Hz */ 195static const int lm85_freq_map[8] = { /* 1 Hz */
195 10, 15, 23, 30, 38, 47, 62, 94 196 10, 15, 23, 30, 38, 47, 61, 94
197};
198static const int adm1027_freq_map[8] = { /* 1 Hz */
199 11, 15, 22, 29, 35, 44, 59, 88
196}; 200};
197 201
198static int FREQ_TO_REG(int freq) 202static int FREQ_TO_REG(const int *map, int freq)
199{ 203{
200 int i; 204 int i;
201 205
202 /* Find the closest match */ 206 /* Find the closest match */
203 for (i = 0; i < 7; ++i) 207 for (i = 0; i < 7; ++i)
204 if (freq <= (lm85_freq_map[i] + lm85_freq_map[i + 1]) / 2) 208 if (freq <= (map[i] + map[i + 1]) / 2)
205 break; 209 break;
206 return i; 210 return i;
207} 211}
208#define FREQ_FROM_REG(val) lm85_freq_map[(val) & 0x07] 212
213static int FREQ_FROM_REG(const int *map, u8 reg)
214{
215 return map[reg & 0x07];
216}
209 217
210/* Since we can't use strings, I'm abusing these numbers 218/* Since we can't use strings, I'm abusing these numbers
211 * to stand in for the following meanings: 219 * to stand in for the following meanings:
@@ -283,6 +291,7 @@ struct lm85_autofan {
283struct lm85_data { 291struct lm85_data {
284 struct i2c_client client; 292 struct i2c_client client;
285 struct device *hwmon_dev; 293 struct device *hwmon_dev;
294 const int *freq_map;
286 enum chips type; 295 enum chips type;
287 296
288 struct mutex update_lock; 297 struct mutex update_lock;
@@ -532,7 +541,8 @@ static ssize_t show_pwm_freq(struct device *dev,
532{ 541{
533 int nr = to_sensor_dev_attr(attr)->index; 542 int nr = to_sensor_dev_attr(attr)->index;
534 struct lm85_data *data = lm85_update_device(dev); 543 struct lm85_data *data = lm85_update_device(dev);
535 return sprintf(buf, "%d\n", FREQ_FROM_REG(data->pwm_freq[nr])); 544 return sprintf(buf, "%d\n", FREQ_FROM_REG(data->freq_map,
545 data->pwm_freq[nr]));
536} 546}
537 547
538static ssize_t set_pwm_freq(struct device *dev, 548static ssize_t set_pwm_freq(struct device *dev,
@@ -544,7 +554,7 @@ static ssize_t set_pwm_freq(struct device *dev,
544 long val = simple_strtol(buf, NULL, 10); 554 long val = simple_strtol(buf, NULL, 10);
545 555
546 mutex_lock(&data->update_lock); 556 mutex_lock(&data->update_lock);
547 data->pwm_freq[nr] = FREQ_TO_REG(val); 557 data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val);
548 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), 558 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
549 (data->zone[nr].range << 4) 559 (data->zone[nr].range << 4)
550 | data->pwm_freq[nr]); 560 | data->pwm_freq[nr]);
@@ -1184,24 +1194,31 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1184 switch (kind) { 1194 switch (kind) {
1185 case lm85b: 1195 case lm85b:
1186 type_name = "lm85b"; 1196 type_name = "lm85b";
1197 data->freq_map = lm85_freq_map;
1187 break; 1198 break;
1188 case lm85c: 1199 case lm85c:
1189 type_name = "lm85c"; 1200 type_name = "lm85c";
1201 data->freq_map = lm85_freq_map;
1190 break; 1202 break;
1191 case adm1027: 1203 case adm1027:
1192 type_name = "adm1027"; 1204 type_name = "adm1027";
1205 data->freq_map = adm1027_freq_map;
1193 break; 1206 break;
1194 case adt7463: 1207 case adt7463:
1195 type_name = "adt7463"; 1208 type_name = "adt7463";
1209 data->freq_map = adm1027_freq_map;
1196 break; 1210 break;
1197 case emc6d100: 1211 case emc6d100:
1198 type_name = "emc6d100"; 1212 type_name = "emc6d100";
1213 data->freq_map = adm1027_freq_map;
1199 break; 1214 break;
1200 case emc6d102: 1215 case emc6d102:
1201 type_name = "emc6d102"; 1216 type_name = "emc6d102";
1217 data->freq_map = adm1027_freq_map;
1202 break; 1218 break;
1203 default: 1219 default:
1204 type_name = "lm85"; 1220 type_name = "lm85";
1221 data->freq_map = lm85_freq_map;
1205 } 1222 }
1206 strlcpy(client->name, type_name, I2C_NAME_SIZE); 1223 strlcpy(client->name, type_name, I2C_NAME_SIZE);
1207 1224