aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/lm85.c151
1 files changed, 67 insertions, 84 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 645b98c187c2..c7e10af0173f 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -110,7 +110,7 @@ I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
110 */ 110 */
111 111
112/* IN are scaled acording to built-in resistors */ 112/* IN are scaled acording to built-in resistors */
113static int lm85_scaling[] = { /* .001 Volts */ 113static const int lm85_scaling[] = { /* .001 Volts */
114 2500, 2250, 3300, 5000, 12000, 114 2500, 2250, 3300, 5000, 12000,
115 3300, 1500, 1800 /*EMC6D100*/ 115 3300, 1500, 1800 /*EMC6D100*/
116}; 116};
@@ -164,7 +164,7 @@ static inline u16 FAN_TO_REG(unsigned long val)
164 */ 164 */
165 165
166/* These are the zone temperature range encodings in .001 degree C */ 166/* These are the zone temperature range encodings in .001 degree C */
167static int lm85_range_map[] = { 167static const int lm85_range_map[] = {
168 2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000, 168 2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000,
169 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000 169 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000
170}; 170};
@@ -190,13 +190,8 @@ static int RANGE_TO_REG(int range)
190} 190}
191#define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] 191#define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f]
192 192
193/* These are the Acoustic Enhancement, or Temperature smoothing encodings
194 * NOTE: The enable/disable bit is INCLUDED in these encodings as the
195 * MSB (bit 3, value 8). If the enable bit is 0, the encoded value
196 * is ignored, or set to 0.
197 */
198/* These are the PWM frequency encodings */ 193/* These are the PWM frequency encodings */
199static int lm85_freq_map[] = { /* .1 Hz */ 194static const int lm85_freq_map[] = { /* .1 Hz */
200 100, 150, 230, 300, 380, 470, 620, 940 195 100, 150, 230, 300, 380, 470, 620, 940
201}; 196};
202 197
@@ -209,7 +204,7 @@ static int FREQ_TO_REG(int freq)
209 for (i = 0; i < 7; ++i) 204 for (i = 0; i < 7; ++i)
210 if (freq <= lm85_freq_map[i]) 205 if (freq <= lm85_freq_map[i])
211 break; 206 break;
212 return i & 0x07; 207 return i;
213} 208}
214#define FREQ_FROM_REG(val) lm85_freq_map[(val) & 0x07] 209#define FREQ_FROM_REG(val) lm85_freq_map[(val) & 0x07]
215 210
@@ -225,8 +220,8 @@ static int FREQ_TO_REG(int freq)
225 * -2 -- PWM responds to manual control 220 * -2 -- PWM responds to manual control
226 */ 221 */
227 222
228static int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 }; 223static const int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 };
229#define ZONE_FROM_REG(val) lm85_zone_map[((val) >> 5) & 0x07] 224#define ZONE_FROM_REG(val) lm85_zone_map[(val) >> 5]
230 225
231static int ZONE_TO_REG(int zone) 226static int ZONE_TO_REG(int zone)
232{ 227{
@@ -237,7 +232,7 @@ static int ZONE_TO_REG(int zone)
237 break; 232 break;
238 if (i > 7) /* Not found. */ 233 if (i > 7) /* Not found. */
239 i = 3; /* Always 100% */ 234 i = 3; /* Always 100% */
240 return (i & 0x07) << 5; 235 return i << 5;
241} 236}
242 237
243#define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15) 238#define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15)
@@ -321,7 +316,7 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
321static int lm85_detach_client(struct i2c_client *client); 316static int lm85_detach_client(struct i2c_client *client);
322 317
323static int lm85_read_value(struct i2c_client *client, u8 reg); 318static int lm85_read_value(struct i2c_client *client, u8 reg);
324static int lm85_write_value(struct i2c_client *client, u8 reg, int value); 319static void lm85_write_value(struct i2c_client *client, u8 reg, int value);
325static struct lm85_data *lm85_update_device(struct device *dev); 320static struct lm85_data *lm85_update_device(struct device *dev);
326static void lm85_init_client(struct i2c_client *client); 321static void lm85_init_client(struct i2c_client *client);
327 322
@@ -1095,13 +1090,12 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1095 int kind) 1090 int kind)
1096{ 1091{
1097 int company, verstep; 1092 int company, verstep;
1098 struct i2c_client *new_client = NULL; 1093 struct i2c_client *client;
1099 struct lm85_data *data; 1094 struct lm85_data *data;
1100 int err = 0; 1095 int err = 0;
1101 const char *type_name = ""; 1096 const char *type_name;
1102 1097
1103 if (!i2c_check_functionality(adapter, 1098 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1104 I2C_FUNC_SMBUS_BYTE_DATA)) {
1105 /* We need to be able to do byte I/O */ 1099 /* We need to be able to do byte I/O */
1106 goto ERROR0; 1100 goto ERROR0;
1107 } 1101 }
@@ -1115,21 +1109,20 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1115 goto ERROR0; 1109 goto ERROR0;
1116 } 1110 }
1117 1111
1118 new_client = &data->client; 1112 client = &data->client;
1119 i2c_set_clientdata(new_client, data); 1113 i2c_set_clientdata(client, data);
1120 new_client->addr = address; 1114 client->addr = address;
1121 new_client->adapter = adapter; 1115 client->adapter = adapter;
1122 new_client->driver = &lm85_driver; 1116 client->driver = &lm85_driver;
1123 new_client->flags = 0;
1124 1117
1125 /* Now, we do the remaining detection. */ 1118 /* Now, we do the remaining detection. */
1126 1119
1127 company = lm85_read_value(new_client, LM85_REG_COMPANY); 1120 company = lm85_read_value(client, LM85_REG_COMPANY);
1128 verstep = lm85_read_value(new_client, LM85_REG_VERSTEP); 1121 verstep = lm85_read_value(client, LM85_REG_VERSTEP);
1129 1122
1130 dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with" 1123 dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with"
1131 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", 1124 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1132 i2c_adapter_id(new_client->adapter), new_client->addr, 1125 i2c_adapter_id(client->adapter), client->addr,
1133 company, verstep); 1126 company, verstep);
1134 1127
1135 /* If auto-detecting, Determine the chip type. */ 1128 /* If auto-detecting, Determine the chip type. */
@@ -1196,56 +1189,65 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1196 } 1189 }
1197 1190
1198 /* Fill in the chip specific driver values */ 1191 /* Fill in the chip specific driver values */
1199 if (kind == any_chip) 1192 switch (kind) {
1200 type_name = "lm85"; 1193 case lm85b:
1201 else if (kind == lm85b)
1202 type_name = "lm85b"; 1194 type_name = "lm85b";
1203 else if (kind == lm85c) 1195 break;
1196 case lm85c:
1204 type_name = "lm85c"; 1197 type_name = "lm85c";
1205 else if (kind == adm1027) 1198 break;
1199 case adm1027:
1206 type_name = "adm1027"; 1200 type_name = "adm1027";
1207 else if (kind == adt7463) 1201 break;
1202 case adt7463:
1208 type_name = "adt7463"; 1203 type_name = "adt7463";
1209 else if (kind == emc6d100) 1204 break;
1205 case emc6d100:
1210 type_name = "emc6d100"; 1206 type_name = "emc6d100";
1211 else if (kind == emc6d102) 1207 break;
1208 case emc6d102:
1212 type_name = "emc6d102"; 1209 type_name = "emc6d102";
1213 strlcpy(new_client->name, type_name, I2C_NAME_SIZE); 1210 break;
1211 default:
1212 type_name = "lm85";
1213 }
1214 strlcpy(client->name, type_name, I2C_NAME_SIZE);
1214 1215
1215 /* Fill in the remaining client fields */ 1216 /* Fill in the remaining client fields */
1216 data->type = kind; 1217 data->type = kind;
1217 data->valid = 0;
1218 mutex_init(&data->update_lock); 1218 mutex_init(&data->update_lock);
1219 1219
1220 /* Tell the I2C layer a new client has arrived */ 1220 /* Tell the I2C layer a new client has arrived */
1221 if ((err = i2c_attach_client(new_client))) 1221 err = i2c_attach_client(client);
1222 if (err)
1222 goto ERROR1; 1223 goto ERROR1;
1223 1224
1224 /* Set the VRM version */ 1225 /* Set the VRM version */
1225 data->vrm = vid_which_vrm(); 1226 data->vrm = vid_which_vrm();
1226 1227
1227 /* Initialize the LM85 chip */ 1228 /* Initialize the LM85 chip */
1228 lm85_init_client(new_client); 1229 lm85_init_client(client);
1229 1230
1230 /* Register sysfs hooks */ 1231 /* Register sysfs hooks */
1231 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm85_group))) 1232 err = sysfs_create_group(&client->dev.kobj, &lm85_group);
1233 if (err)
1232 goto ERROR2; 1234 goto ERROR2;
1233 1235
1234 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used 1236 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used
1235 as a sixth digital VID input rather than an analog input. */ 1237 as a sixth digital VID input rather than an analog input. */
1236 data->vid = lm85_read_value(new_client, LM85_REG_VID); 1238 data->vid = lm85_read_value(client, LM85_REG_VID);
1237 if (!(kind == adt7463 && (data->vid & 0x80))) 1239 if (!(kind == adt7463 && (data->vid & 0x80)))
1238 if ((err = sysfs_create_group(&new_client->dev.kobj, 1240 if ((err = sysfs_create_group(&client->dev.kobj,
1239 &lm85_group_in4))) 1241 &lm85_group_in4)))
1240 goto ERROR3; 1242 goto ERROR3;
1241 1243
1242 /* The EMC6D100 has 3 additional voltage inputs */ 1244 /* The EMC6D100 has 3 additional voltage inputs */
1243 if (kind == emc6d100) 1245 if (kind == emc6d100)
1244 if ((err = sysfs_create_group(&new_client->dev.kobj, 1246 if ((err = sysfs_create_group(&client->dev.kobj,
1245 &lm85_group_in567))) 1247 &lm85_group_in567)))
1246 goto ERROR3; 1248 goto ERROR3;
1247 1249
1248 data->hwmon_dev = hwmon_device_register(&new_client->dev); 1250 data->hwmon_dev = hwmon_device_register(&client->dev);
1249 if (IS_ERR(data->hwmon_dev)) { 1251 if (IS_ERR(data->hwmon_dev)) {
1250 err = PTR_ERR(data->hwmon_dev); 1252 err = PTR_ERR(data->hwmon_dev);
1251 goto ERROR3; 1253 goto ERROR3;
@@ -1255,12 +1257,12 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1255 1257
1256 /* Error out and cleanup code */ 1258 /* Error out and cleanup code */
1257 ERROR3: 1259 ERROR3:
1258 sysfs_remove_group(&new_client->dev.kobj, &lm85_group); 1260 sysfs_remove_group(&client->dev.kobj, &lm85_group);
1259 sysfs_remove_group(&new_client->dev.kobj, &lm85_group_in4); 1261 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
1260 if (kind == emc6d100) 1262 if (kind == emc6d100)
1261 sysfs_remove_group(&new_client->dev.kobj, &lm85_group_in567); 1263 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
1262 ERROR2: 1264 ERROR2:
1263 i2c_detach_client(new_client); 1265 i2c_detach_client(client);
1264 ERROR1: 1266 ERROR1:
1265 kfree(data); 1267 kfree(data);
1266 ERROR0: 1268 ERROR0:
@@ -1307,10 +1309,8 @@ static int lm85_read_value(struct i2c_client *client, u8 reg)
1307 return res; 1309 return res;
1308} 1310}
1309 1311
1310static int lm85_write_value(struct i2c_client *client, u8 reg, int value) 1312static void lm85_write_value(struct i2c_client *client, u8 reg, int value)
1311{ 1313{
1312 int res;
1313
1314 switch (reg) { 1314 switch (reg) {
1315 case LM85_REG_FAN(0): /* Write WORD data */ 1315 case LM85_REG_FAN(0): /* Write WORD data */
1316 case LM85_REG_FAN(1): 1316 case LM85_REG_FAN(1):
@@ -1321,16 +1321,13 @@ static int lm85_write_value(struct i2c_client *client, u8 reg, int value)
1321 case LM85_REG_FAN_MIN(2): 1321 case LM85_REG_FAN_MIN(2):
1322 case LM85_REG_FAN_MIN(3): 1322 case LM85_REG_FAN_MIN(3):
1323 /* NOTE: ALARM is read only, so not included here */ 1323 /* NOTE: ALARM is read only, so not included here */
1324 res = i2c_smbus_write_byte_data(client, reg, value & 0xff); 1324 i2c_smbus_write_byte_data(client, reg, value & 0xff);
1325 res |= i2c_smbus_write_byte_data(client, reg + 1, 1325 i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
1326 (value >> 8) & 0xff);
1327 break; 1326 break;
1328 default: /* Write BYTE data */ 1327 default: /* Write BYTE data */
1329 res = i2c_smbus_write_byte_data(client, reg, value); 1328 i2c_smbus_write_byte_data(client, reg, value);
1330 break; 1329 break;
1331 } 1330 }
1332
1333 return res;
1334} 1331}
1335 1332
1336static void lm85_init_client(struct i2c_client *client) 1333static void lm85_init_client(struct i2c_client *client)
@@ -1414,6 +1411,8 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1414 for (i = 0; i <= 3; ++i) { 1411 for (i = 0; i <= 3; ++i) {
1415 data->in[i] = 1412 data->in[i] =
1416 lm85_read_value(client, LM85_REG_IN(i)); 1413 lm85_read_value(client, LM85_REG_IN(i));
1414 data->fan[i] =
1415 lm85_read_value(client, LM85_REG_FAN(i));
1417 } 1416 }
1418 1417
1419 if (!(data->type == adt7463 && (data->vid & 0x80))) { 1418 if (!(data->type == adt7463 && (data->vid & 0x80))) {
@@ -1421,17 +1420,9 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1421 LM85_REG_IN(4)); 1420 LM85_REG_IN(4));
1422 } 1421 }
1423 1422
1424 for (i = 0; i <= 3; ++i) {
1425 data->fan[i] =
1426 lm85_read_value(client, LM85_REG_FAN(i));
1427 }
1428
1429 for (i = 0; i <= 2; ++i) { 1423 for (i = 0; i <= 2; ++i) {
1430 data->temp[i] = 1424 data->temp[i] =
1431 lm85_read_value(client, LM85_REG_TEMP(i)); 1425 lm85_read_value(client, LM85_REG_TEMP(i));
1432 }
1433
1434 for (i = 0; i <= 2; ++i) {
1435 data->pwm[i] = 1426 data->pwm[i] =
1436 lm85_read_value(client, LM85_REG_PWM(i)); 1427 lm85_read_value(client, LM85_REG_PWM(i));
1437 } 1428 }
@@ -1462,13 +1453,13 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1462 EMC6D102_REG_EXTEND_ADC4); 1453 EMC6D102_REG_EXTEND_ADC4);
1463 data->in_ext[0] = ext3 & 0x0f; 1454 data->in_ext[0] = ext3 & 0x0f;
1464 data->in_ext[1] = ext4 & 0x0f; 1455 data->in_ext[1] = ext4 & 0x0f;
1465 data->in_ext[2] = (ext4 >> 4) & 0x0f; 1456 data->in_ext[2] = ext4 >> 4;
1466 data->in_ext[3] = (ext3 >> 4) & 0x0f; 1457 data->in_ext[3] = ext3 >> 4;
1467 data->in_ext[4] = (ext2 >> 4) & 0x0f; 1458 data->in_ext[4] = ext2 >> 4;
1468 1459
1469 data->temp_ext[0] = ext1 & 0x0f; 1460 data->temp_ext[0] = ext1 & 0x0f;
1470 data->temp_ext[1] = ext2 & 0x0f; 1461 data->temp_ext[1] = ext2 & 0x0f;
1471 data->temp_ext[2] = (ext1 >> 4) & 0x0f; 1462 data->temp_ext[2] = ext1 >> 4;
1472 } 1463 }
1473 1464
1474 data->last_reading = jiffies; 1465 data->last_reading = jiffies;
@@ -1484,6 +1475,8 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1484 lm85_read_value(client, LM85_REG_IN_MIN(i)); 1475 lm85_read_value(client, LM85_REG_IN_MIN(i));
1485 data->in_max[i] = 1476 data->in_max[i] =
1486 lm85_read_value(client, LM85_REG_IN_MAX(i)); 1477 lm85_read_value(client, LM85_REG_IN_MAX(i));
1478 data->fan_min[i] =
1479 lm85_read_value(client, LM85_REG_FAN_MIN(i));
1487 } 1480 }
1488 1481
1489 if (!(data->type == adt7463 && (data->vid & 0x80))) { 1482 if (!(data->type == adt7463 && (data->vid & 0x80))) {
@@ -1502,25 +1495,19 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1502 } 1495 }
1503 } 1496 }
1504 1497
1505 for (i = 0; i <= 3; ++i) {
1506 data->fan_min[i] =
1507 lm85_read_value(client, LM85_REG_FAN_MIN(i));
1508 }
1509
1510 for (i = 0; i <= 2; ++i) { 1498 for (i = 0; i <= 2; ++i) {
1499 int val;
1500
1511 data->temp_min[i] = 1501 data->temp_min[i] =
1512 lm85_read_value(client, LM85_REG_TEMP_MIN(i)); 1502 lm85_read_value(client, LM85_REG_TEMP_MIN(i));
1513 data->temp_max[i] = 1503 data->temp_max[i] =
1514 lm85_read_value(client, LM85_REG_TEMP_MAX(i)); 1504 lm85_read_value(client, LM85_REG_TEMP_MAX(i));
1515 }
1516 1505
1517 for (i = 0; i <= 2; ++i) {
1518 int val;
1519 data->autofan[i].config = 1506 data->autofan[i].config =
1520 lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); 1507 lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
1521 val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); 1508 val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
1522 data->autofan[i].freq = val & 0x07; 1509 data->autofan[i].freq = val & 0x07;
1523 data->zone[i].range = (val >> 4) & 0x0f; 1510 data->zone[i].range = val >> 4;
1524 data->autofan[i].min_pwm = 1511 data->autofan[i].min_pwm =
1525 lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); 1512 lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
1526 data->zone[i].limit = 1513 data->zone[i].limit =
@@ -1535,11 +1522,11 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1535 data->autofan[2].min_off = (i & 0x80) != 0; 1522 data->autofan[2].min_off = (i & 0x80) != 0;
1536 1523
1537 i = lm85_read_value(client, LM85_REG_AFAN_HYST1); 1524 i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
1538 data->zone[0].hyst = (i >> 4) & 0x0f; 1525 data->zone[0].hyst = i >> 4;
1539 data->zone[1].hyst = i & 0x0f; 1526 data->zone[1].hyst = i & 0x0f;
1540 1527
1541 i = lm85_read_value(client, LM85_REG_AFAN_HYST2); 1528 i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
1542 data->zone[2].hyst = (i >> 4) & 0x0f; 1529 data->zone[2].hyst = i >> 4;
1543 1530
1544 data->last_config = jiffies; 1531 data->last_config = jiffies;
1545 } /* last_config */ 1532 } /* last_config */
@@ -1562,14 +1549,10 @@ static void __exit sm_lm85_exit(void)
1562 i2c_del_driver(&lm85_driver); 1549 i2c_del_driver(&lm85_driver);
1563} 1550}
1564 1551
1565/* Thanks to Richard Barrington for adding the LM85 to sensors-detect.
1566 * Thanks to Margit Schubert-While <margitsw@t-online.de> for help with
1567 * post 2.7.0 CVS changes.
1568 */
1569MODULE_LICENSE("GPL"); 1552MODULE_LICENSE("GPL");
1570MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, " 1553MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
1571 "Margit Schubert-While <margitsw@t-online.de>, " 1554 "Margit Schubert-While <margitsw@t-online.de>, "
1572 "Justin Thiessen <jthiessen@penguincomputing.com"); 1555 "Justin Thiessen <jthiessen@penguincomputing.com>");
1573MODULE_DESCRIPTION("LM85-B, LM85-C driver"); 1556MODULE_DESCRIPTION("LM85-B, LM85-C driver");
1574 1557
1575module_init(sm_lm85_init); 1558module_init(sm_lm85_init);