diff options
-rw-r--r-- | drivers/hwmon/applesmc.c | 241 |
1 files changed, 59 insertions, 182 deletions
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c index 1d7f8aff9982..d4d647522331 100644 --- a/drivers/hwmon/applesmc.c +++ b/drivers/hwmon/applesmc.c | |||
@@ -106,16 +106,6 @@ static const char* fan_speed_keys[] = { | |||
106 | 106 | ||
107 | #define to_index(attr) (to_sensor_dev_attr(attr)->index) | 107 | #define to_index(attr) (to_sensor_dev_attr(attr)->index) |
108 | 108 | ||
109 | /* Structure to be passed to DMI_MATCH function */ | ||
110 | struct dmi_match_data { | ||
111 | /* Indicates whether this computer has an accelerometer. */ | ||
112 | int accelerometer; | ||
113 | /* Indicates whether this computer has light sensors and keyboard backlight. */ | ||
114 | int light; | ||
115 | /* Indicates which temperature sensors set to use. */ | ||
116 | int temperature_set; | ||
117 | }; | ||
118 | |||
119 | /* Dynamic device node attributes */ | 109 | /* Dynamic device node attributes */ |
120 | struct applesmc_dev_attr { | 110 | struct applesmc_dev_attr { |
121 | struct sensor_device_attribute sda; /* hwmon attributes */ | 111 | struct sensor_device_attribute sda; /* hwmon attributes */ |
@@ -146,6 +136,9 @@ static struct applesmc_registers { | |||
146 | unsigned int temp_count; /* number of temperature registers */ | 136 | unsigned int temp_count; /* number of temperature registers */ |
147 | unsigned int temp_begin; /* temperature lower index bound */ | 137 | unsigned int temp_begin; /* temperature lower index bound */ |
148 | unsigned int temp_end; /* temperature upper index bound */ | 138 | unsigned int temp_end; /* temperature upper index bound */ |
139 | int num_light_sensors; /* number of light sensors */ | ||
140 | bool has_accelerometer; /* has motion sensor */ | ||
141 | bool has_key_backlight; /* has keyboard backlight */ | ||
149 | bool init_complete; /* true when fully initialized */ | 142 | bool init_complete; /* true when fully initialized */ |
150 | struct applesmc_entry *cache; /* cached key entries */ | 143 | struct applesmc_entry *cache; /* cached key entries */ |
151 | } smcreg = { | 144 | } smcreg = { |
@@ -161,12 +154,6 @@ static u8 backlight_state[2]; | |||
161 | static struct device *hwmon_dev; | 154 | static struct device *hwmon_dev; |
162 | static struct input_polled_dev *applesmc_idev; | 155 | static struct input_polled_dev *applesmc_idev; |
163 | 156 | ||
164 | /* Indicates whether this computer has an accelerometer. */ | ||
165 | static unsigned int applesmc_accelerometer; | ||
166 | |||
167 | /* Indicates whether this computer has light sensors and keyboard backlight. */ | ||
168 | static unsigned int applesmc_light; | ||
169 | |||
170 | /* The number of fans handled by the driver */ | 157 | /* The number of fans handled by the driver */ |
171 | static unsigned int fans_handled; | 158 | static unsigned int fans_handled; |
172 | 159 | ||
@@ -433,6 +420,18 @@ static int applesmc_write_key(const char *key, const u8 *buffer, u8 len) | |||
433 | return applesmc_write_entry(entry, buffer, len); | 420 | return applesmc_write_entry(entry, buffer, len); |
434 | } | 421 | } |
435 | 422 | ||
423 | static int applesmc_has_key(const char *key, bool *value) | ||
424 | { | ||
425 | const struct applesmc_entry *entry; | ||
426 | |||
427 | entry = applesmc_get_entry_by_key(key); | ||
428 | if (IS_ERR(entry) && PTR_ERR(entry) != -EINVAL) | ||
429 | return PTR_ERR(entry); | ||
430 | |||
431 | *value = !IS_ERR(entry); | ||
432 | return 0; | ||
433 | } | ||
434 | |||
436 | /* | 435 | /* |
437 | * applesmc_read_motion_sensor - Read motion sensor (X, Y or Z). | 436 | * applesmc_read_motion_sensor - Read motion sensor (X, Y or Z). |
438 | */ | 437 | */ |
@@ -468,7 +467,7 @@ static void applesmc_device_init(void) | |||
468 | int total; | 467 | int total; |
469 | u8 buffer[2]; | 468 | u8 buffer[2]; |
470 | 469 | ||
471 | if (!applesmc_accelerometer) | 470 | if (!smcreg.has_accelerometer) |
472 | return; | 471 | return; |
473 | 472 | ||
474 | for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) { | 473 | for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) { |
@@ -506,6 +505,7 @@ static int applesmc_get_fan_count(void) | |||
506 | static int applesmc_init_smcreg_try(void) | 505 | static int applesmc_init_smcreg_try(void) |
507 | { | 506 | { |
508 | struct applesmc_registers *s = &smcreg; | 507 | struct applesmc_registers *s = &smcreg; |
508 | bool left_light_sensor, right_light_sensor; | ||
509 | int ret; | 509 | int ret; |
510 | 510 | ||
511 | if (s->init_complete) | 511 | if (s->init_complete) |
@@ -528,9 +528,27 @@ static int applesmc_init_smcreg_try(void) | |||
528 | return ret; | 528 | return ret; |
529 | s->temp_count = s->temp_end - s->temp_begin; | 529 | s->temp_count = s->temp_end - s->temp_begin; |
530 | 530 | ||
531 | ret = applesmc_has_key(LIGHT_SENSOR_LEFT_KEY, &left_light_sensor); | ||
532 | if (ret) | ||
533 | return ret; | ||
534 | ret = applesmc_has_key(LIGHT_SENSOR_RIGHT_KEY, &right_light_sensor); | ||
535 | if (ret) | ||
536 | return ret; | ||
537 | ret = applesmc_has_key(MOTION_SENSOR_KEY, &s->has_accelerometer); | ||
538 | if (ret) | ||
539 | return ret; | ||
540 | ret = applesmc_has_key(BACKLIGHT_KEY, &s->has_key_backlight); | ||
541 | if (ret) | ||
542 | return ret; | ||
543 | |||
544 | s->num_light_sensors = left_light_sensor + right_light_sensor; | ||
531 | s->init_complete = true; | 545 | s->init_complete = true; |
532 | 546 | ||
533 | pr_info("key=%d temp=%d\n", s->key_count, s->temp_count); | 547 | pr_info("key=%d temp=%d acc=%d lux=%d kbd=%d\n", |
548 | s->key_count, s->temp_count, | ||
549 | s->has_accelerometer, | ||
550 | s->num_light_sensors, | ||
551 | s->has_key_backlight); | ||
534 | 552 | ||
535 | return 0; | 553 | return 0; |
536 | } | 554 | } |
@@ -585,7 +603,7 @@ static int applesmc_probe(struct platform_device *dev) | |||
585 | /* Synchronize device with memorized backlight state */ | 603 | /* Synchronize device with memorized backlight state */ |
586 | static int applesmc_pm_resume(struct device *dev) | 604 | static int applesmc_pm_resume(struct device *dev) |
587 | { | 605 | { |
588 | if (applesmc_light) | 606 | if (smcreg.has_key_backlight) |
589 | applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2); | 607 | applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2); |
590 | return 0; | 608 | return 0; |
591 | } | 609 | } |
@@ -1118,23 +1136,6 @@ static struct applesmc_node_group temp_group[] = { | |||
1118 | /* Module stuff */ | 1136 | /* Module stuff */ |
1119 | 1137 | ||
1120 | /* | 1138 | /* |
1121 | * applesmc_dmi_match - found a match. return one, short-circuiting the hunt. | ||
1122 | */ | ||
1123 | static int applesmc_dmi_match(const struct dmi_system_id *id) | ||
1124 | { | ||
1125 | struct dmi_match_data* dmi_data = id->driver_data; | ||
1126 | pr_info("%s detected:\n", id->ident); | ||
1127 | applesmc_accelerometer = dmi_data->accelerometer; | ||
1128 | pr_info(" - Model %s accelerometer\n", | ||
1129 | applesmc_accelerometer ? "with" : "without"); | ||
1130 | applesmc_light = dmi_data->light; | ||
1131 | pr_info(" - Model %s light sensors and backlight\n", | ||
1132 | applesmc_light ? "with" : "without"); | ||
1133 | |||
1134 | return 1; | ||
1135 | } | ||
1136 | |||
1137 | /* | ||
1138 | * applesmc_destroy_nodes - remove files and free associated memory | 1139 | * applesmc_destroy_nodes - remove files and free associated memory |
1139 | */ | 1140 | */ |
1140 | static void applesmc_destroy_nodes(struct applesmc_node_group *groups) | 1141 | static void applesmc_destroy_nodes(struct applesmc_node_group *groups) |
@@ -1248,165 +1249,38 @@ static void applesmc_release_accelerometer(void) | |||
1248 | input_free_polled_device(applesmc_idev); | 1249 | input_free_polled_device(applesmc_idev); |
1249 | sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); | 1250 | sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); |
1250 | } | 1251 | } |
1251 | 1252 | static int applesmc_dmi_match(const struct dmi_system_id *id) | |
1252 | static __initdata struct dmi_match_data applesmc_dmi_data[] = { | 1253 | { |
1253 | /* MacBook Pro: accelerometer, backlight and temperature set 0 */ | 1254 | return 1; |
1254 | { .accelerometer = 1, .light = 1, .temperature_set = 0 }, | 1255 | } |
1255 | /* MacBook2: accelerometer and temperature set 1 */ | ||
1256 | { .accelerometer = 1, .light = 0, .temperature_set = 1 }, | ||
1257 | /* MacBook: accelerometer and temperature set 2 */ | ||
1258 | { .accelerometer = 1, .light = 0, .temperature_set = 2 }, | ||
1259 | /* MacMini: temperature set 3 */ | ||
1260 | { .accelerometer = 0, .light = 0, .temperature_set = 3 }, | ||
1261 | /* MacPro: temperature set 4 */ | ||
1262 | { .accelerometer = 0, .light = 0, .temperature_set = 4 }, | ||
1263 | /* iMac: temperature set 5 */ | ||
1264 | { .accelerometer = 0, .light = 0, .temperature_set = 5 }, | ||
1265 | /* MacBook3, MacBook4: accelerometer and temperature set 6 */ | ||
1266 | { .accelerometer = 1, .light = 0, .temperature_set = 6 }, | ||
1267 | /* MacBook Air: accelerometer, backlight and temperature set 7 */ | ||
1268 | { .accelerometer = 1, .light = 1, .temperature_set = 7 }, | ||
1269 | /* MacBook Pro 4: accelerometer, backlight and temperature set 8 */ | ||
1270 | { .accelerometer = 1, .light = 1, .temperature_set = 8 }, | ||
1271 | /* MacBook Pro 3: accelerometer, backlight and temperature set 9 */ | ||
1272 | { .accelerometer = 1, .light = 1, .temperature_set = 9 }, | ||
1273 | /* iMac 5: light sensor only, temperature set 10 */ | ||
1274 | { .accelerometer = 0, .light = 0, .temperature_set = 10 }, | ||
1275 | /* MacBook 5: accelerometer, backlight and temperature set 11 */ | ||
1276 | { .accelerometer = 1, .light = 1, .temperature_set = 11 }, | ||
1277 | /* MacBook Pro 5: accelerometer, backlight and temperature set 12 */ | ||
1278 | { .accelerometer = 1, .light = 1, .temperature_set = 12 }, | ||
1279 | /* iMac 8: light sensor only, temperature set 13 */ | ||
1280 | { .accelerometer = 0, .light = 0, .temperature_set = 13 }, | ||
1281 | /* iMac 6: light sensor only, temperature set 14 */ | ||
1282 | { .accelerometer = 0, .light = 0, .temperature_set = 14 }, | ||
1283 | /* MacBook Air 2,1: accelerometer, backlight and temperature set 15 */ | ||
1284 | { .accelerometer = 1, .light = 1, .temperature_set = 15 }, | ||
1285 | /* MacPro3,1: temperature set 16 */ | ||
1286 | { .accelerometer = 0, .light = 0, .temperature_set = 16 }, | ||
1287 | /* iMac 9,1: light sensor only, temperature set 17 */ | ||
1288 | { .accelerometer = 0, .light = 0, .temperature_set = 17 }, | ||
1289 | /* MacBook Pro 2,2: accelerometer, backlight and temperature set 18 */ | ||
1290 | { .accelerometer = 1, .light = 1, .temperature_set = 18 }, | ||
1291 | /* MacBook Pro 5,3: accelerometer, backlight and temperature set 19 */ | ||
1292 | { .accelerometer = 1, .light = 1, .temperature_set = 19 }, | ||
1293 | /* MacBook Pro 5,4: accelerometer, backlight and temperature set 20 */ | ||
1294 | { .accelerometer = 1, .light = 1, .temperature_set = 20 }, | ||
1295 | /* MacBook Pro 6,2: accelerometer, backlight and temperature set 21 */ | ||
1296 | { .accelerometer = 1, .light = 1, .temperature_set = 21 }, | ||
1297 | /* MacBook Pro 7,1: accelerometer, backlight and temperature set 22 */ | ||
1298 | { .accelerometer = 1, .light = 1, .temperature_set = 22 }, | ||
1299 | /* MacBook Air 3,1: accelerometer, backlight and temperature set 23 */ | ||
1300 | { .accelerometer = 0, .light = 0, .temperature_set = 23 }, | ||
1301 | }; | ||
1302 | 1256 | ||
1303 | /* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1". | 1257 | /* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1". |
1304 | * So we need to put "Apple MacBook Pro" before "Apple MacBook". */ | 1258 | * So we need to put "Apple MacBook Pro" before "Apple MacBook". */ |
1305 | static __initdata struct dmi_system_id applesmc_whitelist[] = { | 1259 | static __initdata struct dmi_system_id applesmc_whitelist[] = { |
1306 | { applesmc_dmi_match, "Apple MacBook Air 3", { | ||
1307 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1308 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir3") }, | ||
1309 | &applesmc_dmi_data[23]}, | ||
1310 | { applesmc_dmi_match, "Apple MacBook Air 2", { | ||
1311 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1312 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir2") }, | ||
1313 | &applesmc_dmi_data[15]}, | ||
1314 | { applesmc_dmi_match, "Apple MacBook Air", { | 1260 | { applesmc_dmi_match, "Apple MacBook Air", { |
1315 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | 1261 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), |
1316 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir") }, | 1262 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir") }, |
1317 | &applesmc_dmi_data[7]}, | 1263 | }, |
1318 | { applesmc_dmi_match, "Apple MacBook Pro 7", { | ||
1319 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1320 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro7") }, | ||
1321 | &applesmc_dmi_data[22]}, | ||
1322 | { applesmc_dmi_match, "Apple MacBook Pro 5,4", { | ||
1323 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1324 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,4") }, | ||
1325 | &applesmc_dmi_data[20]}, | ||
1326 | { applesmc_dmi_match, "Apple MacBook Pro 5,3", { | ||
1327 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1328 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,3") }, | ||
1329 | &applesmc_dmi_data[19]}, | ||
1330 | { applesmc_dmi_match, "Apple MacBook Pro 6", { | ||
1331 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1332 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro6") }, | ||
1333 | &applesmc_dmi_data[21]}, | ||
1334 | { applesmc_dmi_match, "Apple MacBook Pro 5", { | ||
1335 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1336 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5") }, | ||
1337 | &applesmc_dmi_data[12]}, | ||
1338 | { applesmc_dmi_match, "Apple MacBook Pro 4", { | ||
1339 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1340 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro4") }, | ||
1341 | &applesmc_dmi_data[8]}, | ||
1342 | { applesmc_dmi_match, "Apple MacBook Pro 3", { | ||
1343 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1344 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3") }, | ||
1345 | &applesmc_dmi_data[9]}, | ||
1346 | { applesmc_dmi_match, "Apple MacBook Pro 2,2", { | ||
1347 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple Computer, Inc."), | ||
1348 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro2,2") }, | ||
1349 | &applesmc_dmi_data[18]}, | ||
1350 | { applesmc_dmi_match, "Apple MacBook Pro", { | 1264 | { applesmc_dmi_match, "Apple MacBook Pro", { |
1351 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | 1265 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), |
1352 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBookPro") }, | 1266 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBookPro") }, |
1353 | &applesmc_dmi_data[0]}, | 1267 | }, |
1354 | { applesmc_dmi_match, "Apple MacBook (v2)", { | ||
1355 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | ||
1356 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBook2") }, | ||
1357 | &applesmc_dmi_data[1]}, | ||
1358 | { applesmc_dmi_match, "Apple MacBook (v3)", { | ||
1359 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | ||
1360 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBook3") }, | ||
1361 | &applesmc_dmi_data[6]}, | ||
1362 | { applesmc_dmi_match, "Apple MacBook 4", { | ||
1363 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1364 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBook4") }, | ||
1365 | &applesmc_dmi_data[6]}, | ||
1366 | { applesmc_dmi_match, "Apple MacBook 5", { | ||
1367 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1368 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5") }, | ||
1369 | &applesmc_dmi_data[11]}, | ||
1370 | { applesmc_dmi_match, "Apple MacBook", { | 1268 | { applesmc_dmi_match, "Apple MacBook", { |
1371 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | 1269 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), |
1372 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBook") }, | 1270 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBook") }, |
1373 | &applesmc_dmi_data[2]}, | 1271 | }, |
1374 | { applesmc_dmi_match, "Apple Macmini", { | 1272 | { applesmc_dmi_match, "Apple Macmini", { |
1375 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | 1273 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), |
1376 | DMI_MATCH(DMI_PRODUCT_NAME,"Macmini") }, | 1274 | DMI_MATCH(DMI_PRODUCT_NAME,"Macmini") }, |
1377 | &applesmc_dmi_data[3]}, | 1275 | }, |
1378 | { applesmc_dmi_match, "Apple MacPro2", { | ||
1379 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | ||
1380 | DMI_MATCH(DMI_PRODUCT_NAME,"MacPro2") }, | ||
1381 | &applesmc_dmi_data[4]}, | ||
1382 | { applesmc_dmi_match, "Apple MacPro3", { | ||
1383 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1384 | DMI_MATCH(DMI_PRODUCT_NAME, "MacPro3") }, | ||
1385 | &applesmc_dmi_data[16]}, | ||
1386 | { applesmc_dmi_match, "Apple MacPro", { | 1276 | { applesmc_dmi_match, "Apple MacPro", { |
1387 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | 1277 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), |
1388 | DMI_MATCH(DMI_PRODUCT_NAME, "MacPro") }, | 1278 | DMI_MATCH(DMI_PRODUCT_NAME, "MacPro") }, |
1389 | &applesmc_dmi_data[4]}, | 1279 | }, |
1390 | { applesmc_dmi_match, "Apple iMac 9,1", { | ||
1391 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple Inc."), | ||
1392 | DMI_MATCH(DMI_PRODUCT_NAME, "iMac9,1") }, | ||
1393 | &applesmc_dmi_data[17]}, | ||
1394 | { applesmc_dmi_match, "Apple iMac 8", { | ||
1395 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1396 | DMI_MATCH(DMI_PRODUCT_NAME, "iMac8") }, | ||
1397 | &applesmc_dmi_data[13]}, | ||
1398 | { applesmc_dmi_match, "Apple iMac 6", { | ||
1399 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1400 | DMI_MATCH(DMI_PRODUCT_NAME, "iMac6") }, | ||
1401 | &applesmc_dmi_data[14]}, | ||
1402 | { applesmc_dmi_match, "Apple iMac 5", { | ||
1403 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1404 | DMI_MATCH(DMI_PRODUCT_NAME, "iMac5") }, | ||
1405 | &applesmc_dmi_data[10]}, | ||
1406 | { applesmc_dmi_match, "Apple iMac", { | 1280 | { applesmc_dmi_match, "Apple iMac", { |
1407 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | 1281 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), |
1408 | DMI_MATCH(DMI_PRODUCT_NAME,"iMac") }, | 1282 | DMI_MATCH(DMI_PRODUCT_NAME,"iMac") }, |
1409 | &applesmc_dmi_data[5]}, | 1283 | }, |
1410 | { .ident = NULL } | 1284 | { .ident = NULL } |
1411 | }; | 1285 | }; |
1412 | 1286 | ||
@@ -1476,18 +1350,20 @@ static int __init applesmc_init(void) | |||
1476 | if (ret) | 1350 | if (ret) |
1477 | goto out_fans; | 1351 | goto out_fans; |
1478 | 1352 | ||
1479 | if (applesmc_accelerometer) { | 1353 | if (smcreg.has_accelerometer) { |
1480 | ret = applesmc_create_accelerometer(); | 1354 | ret = applesmc_create_accelerometer(); |
1481 | if (ret) | 1355 | if (ret) |
1482 | goto out_temperature; | 1356 | goto out_temperature; |
1483 | } | 1357 | } |
1484 | 1358 | ||
1485 | if (applesmc_light) { | 1359 | if (smcreg.num_light_sensors) { |
1486 | /* Add light sensor file */ | 1360 | /* Add light sensor file */ |
1487 | ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_light.attr); | 1361 | ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_light.attr); |
1488 | if (ret) | 1362 | if (ret) |
1489 | goto out_accelerometer; | 1363 | goto out_accelerometer; |
1364 | } | ||
1490 | 1365 | ||
1366 | if (smcreg.has_key_backlight) { | ||
1491 | /* Create the workqueue */ | 1367 | /* Create the workqueue */ |
1492 | applesmc_led_wq = create_singlethread_workqueue("applesmc-led"); | 1368 | applesmc_led_wq = create_singlethread_workqueue("applesmc-led"); |
1493 | if (!applesmc_led_wq) { | 1369 | if (!applesmc_led_wq) { |
@@ -1512,16 +1388,16 @@ static int __init applesmc_init(void) | |||
1512 | return 0; | 1388 | return 0; |
1513 | 1389 | ||
1514 | out_light_ledclass: | 1390 | out_light_ledclass: |
1515 | if (applesmc_light) | 1391 | if (smcreg.has_key_backlight) |
1516 | led_classdev_unregister(&applesmc_backlight); | 1392 | led_classdev_unregister(&applesmc_backlight); |
1517 | out_light_wq: | 1393 | out_light_wq: |
1518 | if (applesmc_light) | 1394 | if (smcreg.has_key_backlight) |
1519 | destroy_workqueue(applesmc_led_wq); | 1395 | destroy_workqueue(applesmc_led_wq); |
1520 | out_light_sysfs: | 1396 | out_light_sysfs: |
1521 | if (applesmc_light) | 1397 | if (smcreg.num_light_sensors) |
1522 | sysfs_remove_file(&pdev->dev.kobj, &dev_attr_light.attr); | 1398 | sysfs_remove_file(&pdev->dev.kobj, &dev_attr_light.attr); |
1523 | out_accelerometer: | 1399 | out_accelerometer: |
1524 | if (applesmc_accelerometer) | 1400 | if (smcreg.has_accelerometer) |
1525 | applesmc_release_accelerometer(); | 1401 | applesmc_release_accelerometer(); |
1526 | out_temperature: | 1402 | out_temperature: |
1527 | applesmc_destroy_nodes(temp_group); | 1403 | applesmc_destroy_nodes(temp_group); |
@@ -1548,12 +1424,13 @@ out: | |||
1548 | static void __exit applesmc_exit(void) | 1424 | static void __exit applesmc_exit(void) |
1549 | { | 1425 | { |
1550 | hwmon_device_unregister(hwmon_dev); | 1426 | hwmon_device_unregister(hwmon_dev); |
1551 | if (applesmc_light) { | 1427 | if (smcreg.has_key_backlight) { |
1552 | led_classdev_unregister(&applesmc_backlight); | 1428 | led_classdev_unregister(&applesmc_backlight); |
1553 | destroy_workqueue(applesmc_led_wq); | 1429 | destroy_workqueue(applesmc_led_wq); |
1554 | sysfs_remove_file(&pdev->dev.kobj, &dev_attr_light.attr); | ||
1555 | } | 1430 | } |
1556 | if (applesmc_accelerometer) | 1431 | if (smcreg.num_light_sensors) |
1432 | sysfs_remove_file(&pdev->dev.kobj, &dev_attr_light.attr); | ||
1433 | if (smcreg.has_accelerometer) | ||
1557 | applesmc_release_accelerometer(); | 1434 | applesmc_release_accelerometer(); |
1558 | applesmc_destroy_nodes(temp_group); | 1435 | applesmc_destroy_nodes(temp_group); |
1559 | while (fans_handled) | 1436 | while (fans_handled) |