aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/applesmc.c
diff options
context:
space:
mode:
authorAlex Murray <murray.alex@gmail.com>2010-05-27 13:58:54 -0400
committerJean Delvare <khali@linux-fr.org>2010-05-27 13:58:54 -0400
commitfa5575cff92eb43f467b9b00468d70d073e8b3d2 (patch)
treef0ef51ed03fd78f45c2d1ea8e4bd5932a76b89b4 /drivers/hwmon/applesmc.c
parent405eaa1c1d045cdd872802fc515f638573984880 (diff)
hwmon: (applesmc) Add temperature sensor labels to sysfs interface
The Apple SMC uses a systematic labeling scheme for the hardware temperature sensors. This scheme is currently hidden from userland. Since the sensor set, and consequently the numbering, differs between models, an extensive database of configurations is required for an application such as fan control. This patch adds the SMC labels to the hwmon sysfs interface, allowing applications to use the sensors more intelligibly. [rydberg@euromail.se: fixed error handling] Signed-off-by: Alex Murray <murray.alex@gmail.com> Signed-off-by: Henrik Rydberg <rydberg@euromail.se> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/applesmc.c')
-rw-r--r--drivers/hwmon/applesmc.c148
1 files changed, 147 insertions, 1 deletions
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index 57c033169ac2..b6598aa557a0 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -660,6 +660,17 @@ out:
660 return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", left, right); 660 return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", left, right);
661} 661}
662 662
663/* Displays sensor key as label */
664static ssize_t applesmc_show_sensor_label(struct device *dev,
665 struct device_attribute *devattr, char *sysfsbuf)
666{
667 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
668 const char *key =
669 temperature_sensors_sets[applesmc_temperature_set][attr->index];
670
671 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", key);
672}
673
663/* Displays degree Celsius * 1000 */ 674/* Displays degree Celsius * 1000 */
664static ssize_t applesmc_show_temperature(struct device *dev, 675static ssize_t applesmc_show_temperature(struct device *dev,
665 struct device_attribute *devattr, char *sysfsbuf) 676 struct device_attribute *devattr, char *sysfsbuf)
@@ -1127,6 +1138,86 @@ static const struct attribute_group fan_attribute_groups[] = {
1127/* 1138/*
1128 * Temperature sensors sysfs entries. 1139 * Temperature sensors sysfs entries.
1129 */ 1140 */
1141static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO,
1142 applesmc_show_sensor_label, NULL, 0);
1143static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO,
1144 applesmc_show_sensor_label, NULL, 1);
1145static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO,
1146 applesmc_show_sensor_label, NULL, 2);
1147static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO,
1148 applesmc_show_sensor_label, NULL, 3);
1149static SENSOR_DEVICE_ATTR(temp5_label, S_IRUGO,
1150 applesmc_show_sensor_label, NULL, 4);
1151static SENSOR_DEVICE_ATTR(temp6_label, S_IRUGO,
1152 applesmc_show_sensor_label, NULL, 5);
1153static SENSOR_DEVICE_ATTR(temp7_label, S_IRUGO,
1154 applesmc_show_sensor_label, NULL, 6);
1155static SENSOR_DEVICE_ATTR(temp8_label, S_IRUGO,
1156 applesmc_show_sensor_label, NULL, 7);
1157static SENSOR_DEVICE_ATTR(temp9_label, S_IRUGO,
1158 applesmc_show_sensor_label, NULL, 8);
1159static SENSOR_DEVICE_ATTR(temp10_label, S_IRUGO,
1160 applesmc_show_sensor_label, NULL, 9);
1161static SENSOR_DEVICE_ATTR(temp11_label, S_IRUGO,
1162 applesmc_show_sensor_label, NULL, 10);
1163static SENSOR_DEVICE_ATTR(temp12_label, S_IRUGO,
1164 applesmc_show_sensor_label, NULL, 11);
1165static SENSOR_DEVICE_ATTR(temp13_label, S_IRUGO,
1166 applesmc_show_sensor_label, NULL, 12);
1167static SENSOR_DEVICE_ATTR(temp14_label, S_IRUGO,
1168 applesmc_show_sensor_label, NULL, 13);
1169static SENSOR_DEVICE_ATTR(temp15_label, S_IRUGO,
1170 applesmc_show_sensor_label, NULL, 14);
1171static SENSOR_DEVICE_ATTR(temp16_label, S_IRUGO,
1172 applesmc_show_sensor_label, NULL, 15);
1173static SENSOR_DEVICE_ATTR(temp17_label, S_IRUGO,
1174 applesmc_show_sensor_label, NULL, 16);
1175static SENSOR_DEVICE_ATTR(temp18_label, S_IRUGO,
1176 applesmc_show_sensor_label, NULL, 17);
1177static SENSOR_DEVICE_ATTR(temp19_label, S_IRUGO,
1178 applesmc_show_sensor_label, NULL, 18);
1179static SENSOR_DEVICE_ATTR(temp20_label, S_IRUGO,
1180 applesmc_show_sensor_label, NULL, 19);
1181static SENSOR_DEVICE_ATTR(temp21_label, S_IRUGO,
1182 applesmc_show_sensor_label, NULL, 20);
1183static SENSOR_DEVICE_ATTR(temp22_label, S_IRUGO,
1184 applesmc_show_sensor_label, NULL, 21);
1185static SENSOR_DEVICE_ATTR(temp23_label, S_IRUGO,
1186 applesmc_show_sensor_label, NULL, 22);
1187static SENSOR_DEVICE_ATTR(temp24_label, S_IRUGO,
1188 applesmc_show_sensor_label, NULL, 23);
1189static SENSOR_DEVICE_ATTR(temp25_label, S_IRUGO,
1190 applesmc_show_sensor_label, NULL, 24);
1191static SENSOR_DEVICE_ATTR(temp26_label, S_IRUGO,
1192 applesmc_show_sensor_label, NULL, 25);
1193static SENSOR_DEVICE_ATTR(temp27_label, S_IRUGO,
1194 applesmc_show_sensor_label, NULL, 26);
1195static SENSOR_DEVICE_ATTR(temp28_label, S_IRUGO,
1196 applesmc_show_sensor_label, NULL, 27);
1197static SENSOR_DEVICE_ATTR(temp29_label, S_IRUGO,
1198 applesmc_show_sensor_label, NULL, 28);
1199static SENSOR_DEVICE_ATTR(temp30_label, S_IRUGO,
1200 applesmc_show_sensor_label, NULL, 29);
1201static SENSOR_DEVICE_ATTR(temp31_label, S_IRUGO,
1202 applesmc_show_sensor_label, NULL, 30);
1203static SENSOR_DEVICE_ATTR(temp32_label, S_IRUGO,
1204 applesmc_show_sensor_label, NULL, 31);
1205static SENSOR_DEVICE_ATTR(temp33_label, S_IRUGO,
1206 applesmc_show_sensor_label, NULL, 32);
1207static SENSOR_DEVICE_ATTR(temp34_label, S_IRUGO,
1208 applesmc_show_sensor_label, NULL, 33);
1209static SENSOR_DEVICE_ATTR(temp35_label, S_IRUGO,
1210 applesmc_show_sensor_label, NULL, 34);
1211static SENSOR_DEVICE_ATTR(temp36_label, S_IRUGO,
1212 applesmc_show_sensor_label, NULL, 35);
1213static SENSOR_DEVICE_ATTR(temp37_label, S_IRUGO,
1214 applesmc_show_sensor_label, NULL, 36);
1215static SENSOR_DEVICE_ATTR(temp38_label, S_IRUGO,
1216 applesmc_show_sensor_label, NULL, 37);
1217static SENSOR_DEVICE_ATTR(temp39_label, S_IRUGO,
1218 applesmc_show_sensor_label, NULL, 38);
1219static SENSOR_DEVICE_ATTR(temp40_label, S_IRUGO,
1220 applesmc_show_sensor_label, NULL, 39);
1130static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, 1221static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
1131 applesmc_show_temperature, NULL, 0); 1222 applesmc_show_temperature, NULL, 0);
1132static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, 1223static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO,
@@ -1208,6 +1299,50 @@ static SENSOR_DEVICE_ATTR(temp39_input, S_IRUGO,
1208static SENSOR_DEVICE_ATTR(temp40_input, S_IRUGO, 1299static SENSOR_DEVICE_ATTR(temp40_input, S_IRUGO,
1209 applesmc_show_temperature, NULL, 39); 1300 applesmc_show_temperature, NULL, 39);
1210 1301
1302static struct attribute *label_attributes[] = {
1303 &sensor_dev_attr_temp1_label.dev_attr.attr,
1304 &sensor_dev_attr_temp2_label.dev_attr.attr,
1305 &sensor_dev_attr_temp3_label.dev_attr.attr,
1306 &sensor_dev_attr_temp4_label.dev_attr.attr,
1307 &sensor_dev_attr_temp5_label.dev_attr.attr,
1308 &sensor_dev_attr_temp6_label.dev_attr.attr,
1309 &sensor_dev_attr_temp7_label.dev_attr.attr,
1310 &sensor_dev_attr_temp8_label.dev_attr.attr,
1311 &sensor_dev_attr_temp9_label.dev_attr.attr,
1312 &sensor_dev_attr_temp10_label.dev_attr.attr,
1313 &sensor_dev_attr_temp11_label.dev_attr.attr,
1314 &sensor_dev_attr_temp12_label.dev_attr.attr,
1315 &sensor_dev_attr_temp13_label.dev_attr.attr,
1316 &sensor_dev_attr_temp14_label.dev_attr.attr,
1317 &sensor_dev_attr_temp15_label.dev_attr.attr,
1318 &sensor_dev_attr_temp16_label.dev_attr.attr,
1319 &sensor_dev_attr_temp17_label.dev_attr.attr,
1320 &sensor_dev_attr_temp18_label.dev_attr.attr,
1321 &sensor_dev_attr_temp19_label.dev_attr.attr,
1322 &sensor_dev_attr_temp20_label.dev_attr.attr,
1323 &sensor_dev_attr_temp21_label.dev_attr.attr,
1324 &sensor_dev_attr_temp22_label.dev_attr.attr,
1325 &sensor_dev_attr_temp23_label.dev_attr.attr,
1326 &sensor_dev_attr_temp24_label.dev_attr.attr,
1327 &sensor_dev_attr_temp25_label.dev_attr.attr,
1328 &sensor_dev_attr_temp26_label.dev_attr.attr,
1329 &sensor_dev_attr_temp27_label.dev_attr.attr,
1330 &sensor_dev_attr_temp28_label.dev_attr.attr,
1331 &sensor_dev_attr_temp29_label.dev_attr.attr,
1332 &sensor_dev_attr_temp30_label.dev_attr.attr,
1333 &sensor_dev_attr_temp31_label.dev_attr.attr,
1334 &sensor_dev_attr_temp32_label.dev_attr.attr,
1335 &sensor_dev_attr_temp33_label.dev_attr.attr,
1336 &sensor_dev_attr_temp34_label.dev_attr.attr,
1337 &sensor_dev_attr_temp35_label.dev_attr.attr,
1338 &sensor_dev_attr_temp36_label.dev_attr.attr,
1339 &sensor_dev_attr_temp37_label.dev_attr.attr,
1340 &sensor_dev_attr_temp38_label.dev_attr.attr,
1341 &sensor_dev_attr_temp39_label.dev_attr.attr,
1342 &sensor_dev_attr_temp40_label.dev_attr.attr,
1343 NULL
1344};
1345
1211static struct attribute *temperature_attributes[] = { 1346static struct attribute *temperature_attributes[] = {
1212 &sensor_dev_attr_temp1_input.dev_attr.attr, 1347 &sensor_dev_attr_temp1_input.dev_attr.attr,
1213 &sensor_dev_attr_temp2_input.dev_attr.attr, 1348 &sensor_dev_attr_temp2_input.dev_attr.attr,
@@ -1255,6 +1390,10 @@ static struct attribute *temperature_attributes[] = {
1255static const struct attribute_group temperature_attributes_group = 1390static const struct attribute_group temperature_attributes_group =
1256 { .attrs = temperature_attributes }; 1391 { .attrs = temperature_attributes };
1257 1392
1393static const struct attribute_group label_attributes_group = {
1394 .attrs = label_attributes
1395};
1396
1258/* Module stuff */ 1397/* Module stuff */
1259 1398
1260/* 1399/*
@@ -1556,7 +1695,8 @@ static int __init applesmc_init(void)
1556 for (i = 0; 1695 for (i = 0;
1557 temperature_sensors_sets[applesmc_temperature_set][i] != NULL; 1696 temperature_sensors_sets[applesmc_temperature_set][i] != NULL;
1558 i++) { 1697 i++) {
1559 if (temperature_attributes[i] == NULL) { 1698 if (temperature_attributes[i] == NULL ||
1699 label_attributes[i] == NULL) {
1560 printk(KERN_ERR "applesmc: More temperature sensors " 1700 printk(KERN_ERR "applesmc: More temperature sensors "
1561 "in temperature_sensors_sets (at least %i)" 1701 "in temperature_sensors_sets (at least %i)"
1562 "than available sysfs files in " 1702 "than available sysfs files in "
@@ -1568,6 +1708,10 @@ static int __init applesmc_init(void)
1568 temperature_attributes[i]); 1708 temperature_attributes[i]);
1569 if (ret) 1709 if (ret)
1570 goto out_temperature; 1710 goto out_temperature;
1711 ret = sysfs_create_file(&pdev->dev.kobj,
1712 label_attributes[i]);
1713 if (ret)
1714 goto out_temperature;
1571 } 1715 }
1572 1716
1573 if (applesmc_accelerometer) { 1717 if (applesmc_accelerometer) {
@@ -1618,6 +1762,7 @@ out_accelerometer:
1618 if (applesmc_accelerometer) 1762 if (applesmc_accelerometer)
1619 applesmc_release_accelerometer(); 1763 applesmc_release_accelerometer();
1620out_temperature: 1764out_temperature:
1765 sysfs_remove_group(&pdev->dev.kobj, &label_attributes_group);
1621 sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group); 1766 sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group);
1622out_fans: 1767out_fans:
1623 while (fans_handled) 1768 while (fans_handled)
@@ -1647,6 +1792,7 @@ static void __exit applesmc_exit(void)
1647 } 1792 }
1648 if (applesmc_accelerometer) 1793 if (applesmc_accelerometer)
1649 applesmc_release_accelerometer(); 1794 applesmc_release_accelerometer();
1795 sysfs_remove_group(&pdev->dev.kobj, &label_attributes_group);
1650 sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group); 1796 sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group);
1651 while (fans_handled) 1797 while (fans_handled)
1652 sysfs_remove_group(&pdev->dev.kobj, 1798 sysfs_remove_group(&pdev->dev.kobj,