diff options
Diffstat (limited to 'usr')
| -rw-r--r-- | usr/src/dkms_source_tree/applesmc.c | 252 |
1 files changed, 119 insertions, 133 deletions
diff --git a/usr/src/dkms_source_tree/applesmc.c b/usr/src/dkms_source_tree/applesmc.c index 2eb78e3..01071e5 100644 --- a/usr/src/dkms_source_tree/applesmc.c +++ b/usr/src/dkms_source_tree/applesmc.c | |||
| @@ -91,7 +91,7 @@ | |||
| 91 | #define FAN_ID_FMT "F%dID" /* r-o char[16] */ | 91 | #define FAN_ID_FMT "F%dID" /* r-o char[16] */ |
| 92 | 92 | ||
| 93 | /* List of keys used to read/write fan speeds */ | 93 | /* List of keys used to read/write fan speeds */ |
| 94 | static const char *fan_speed_fmt[] = { | 94 | static const char *const fan_speed_fmt[] = { |
| 95 | "F%dAc", /* actual speed */ | 95 | "F%dAc", /* actual speed */ |
| 96 | "F%dMn", /* minimum speed (rw) */ | 96 | "F%dMn", /* minimum speed (rw) */ |
| 97 | "F%dMx", /* maximum speed */ | 97 | "F%dMx", /* maximum speed */ |
| @@ -133,7 +133,8 @@ struct applesmc_entry { | |||
| 133 | char key[5]; /* four-letter key code */ | 133 | char key[5]; /* four-letter key code */ |
| 134 | u8 valid; /* set when entry is successfully read once */ | 134 | u8 valid; /* set when entry is successfully read once */ |
| 135 | u8 len; /* bounded by APPLESMC_MAX_DATA_LENGTH */ | 135 | u8 len; /* bounded by APPLESMC_MAX_DATA_LENGTH */ |
| 136 | char type[5]; /* four-letter type code (padded) */ | 136 | char type[5]; /* four-letter type code */ |
| 137 | u8 flags; /* 0x10: func; 0x40: write; 0x80: read */ | ||
| 137 | }; | 138 | }; |
| 138 | 139 | ||
| 139 | /* Register lookup and registers common to all SMCs */ | 140 | /* Register lookup and registers common to all SMCs */ |
| @@ -144,12 +145,11 @@ static struct applesmc_registers { | |||
| 144 | unsigned int temp_count; /* number of temperature registers */ | 145 | unsigned int temp_count; /* number of temperature registers */ |
| 145 | unsigned int temp_begin; /* temperature lower index bound */ | 146 | unsigned int temp_begin; /* temperature lower index bound */ |
| 146 | unsigned int temp_end; /* temperature upper index bound */ | 147 | unsigned int temp_end; /* temperature upper index bound */ |
| 148 | int num_light_sensors; /* number of light sensors */ | ||
| 147 | bool has_accelerometer; /* has motion sensor */ | 149 | bool has_accelerometer; /* has motion sensor */ |
| 148 | bool has_left_light; /* has left light sensor */ | 150 | bool has_key_backlight; /* has keyboard backlight */ |
| 149 | bool has_right_light; /* has right light sensor */ | ||
| 150 | bool has_key_light; /* has keyboard backlight */ | ||
| 151 | bool init_complete; /* true when fully initialized */ | 151 | bool init_complete; /* true when fully initialized */ |
| 152 | struct applesmc_entry *entry; /* key entries */ | 152 | struct applesmc_entry *cache; /* cached key entries */ |
| 153 | } smcreg; | 153 | } smcreg; |
| 154 | 154 | ||
| 155 | static const int debug; | 155 | static const int debug; |
| @@ -167,7 +167,6 @@ static struct input_polled_dev *applesmc_idev; | |||
| 167 | */ | 167 | */ |
| 168 | static unsigned int key_at_index; | 168 | static unsigned int key_at_index; |
| 169 | 169 | ||
| 170 | |||
| 171 | static struct workqueue_struct *applesmc_led_wq; | 170 | static struct workqueue_struct *applesmc_led_wq; |
| 172 | 171 | ||
| 173 | /* | 172 | /* |
| @@ -311,48 +310,52 @@ static int applesmc_write_entry(const struct applesmc_entry *entry, | |||
| 311 | return ret; | 310 | return ret; |
| 312 | } | 311 | } |
| 313 | 312 | ||
| 314 | static int applesmc_get_entry_by_index(int index, struct applesmc_entry *entry) | 313 | static const struct applesmc_entry *applesmc_get_entry_by_index(int index) |
| 315 | { | 314 | { |
| 316 | struct applesmc_entry *cache = &smcreg.entry[index]; | 315 | struct applesmc_entry *cache = &smcreg.cache[index]; |
| 316 | u8 key[4], info[6]; | ||
| 317 | __be32 be; | 317 | __be32 be; |
| 318 | int ret; | 318 | int ret = 0; |
| 319 | 319 | ||
| 320 | if (cache->valid) { | 320 | if (cache->valid) |
| 321 | memcpy(entry, cache, sizeof(*entry)); | 321 | return cache; |
| 322 | return 0; | ||
| 323 | } | ||
| 324 | 322 | ||
| 325 | mutex_lock(&smcreg.mutex); | 323 | mutex_lock(&smcreg.mutex); |
| 326 | 324 | ||
| 325 | if (cache->valid) | ||
| 326 | goto out; | ||
| 327 | be = cpu_to_be32(index); | 327 | be = cpu_to_be32(index); |
| 328 | ret = read_smc(APPLESMC_GET_KEY_BY_INDEX_CMD, (u8 *)&be, cache->key, 4); | 328 | ret = read_smc(APPLESMC_GET_KEY_BY_INDEX_CMD, (u8 *)&be, key, 4); |
| 329 | if (ret) | 329 | if (ret) |
| 330 | goto out; | 330 | goto out; |
| 331 | ret = read_smc(APPLESMC_GET_KEY_TYPE_CMD, cache->key, &cache->len, 6); | 331 | ret = read_smc(APPLESMC_GET_KEY_TYPE_CMD, key, info, 6); |
| 332 | if (ret) | 332 | if (ret) |
| 333 | goto out; | 333 | goto out; |
| 334 | 334 | ||
| 335 | cache->type[4] = 0; | 335 | memcpy(cache->key, key, 4); |
| 336 | cache->len = info[0]; | ||
| 337 | memcpy(cache->type, &info[1], 4); | ||
| 338 | cache->flags = info[5]; | ||
| 336 | cache->valid = 1; | 339 | cache->valid = 1; |
| 337 | memcpy(entry, cache, sizeof(*entry)); | ||
| 338 | 340 | ||
| 339 | out: | 341 | out: |
| 340 | mutex_unlock(&smcreg.mutex); | 342 | mutex_unlock(&smcreg.mutex); |
| 341 | return ret; | 343 | if (ret) |
| 344 | return ERR_PTR(ret); | ||
| 345 | return cache; | ||
| 342 | } | 346 | } |
| 343 | 347 | ||
| 344 | static int applesmc_get_lower_bound(unsigned int *lo, const char *key) | 348 | static int applesmc_get_lower_bound(unsigned int *lo, const char *key) |
| 345 | { | 349 | { |
| 346 | int begin = 0, end = smcreg.key_count; | 350 | int begin = 0, end = smcreg.key_count; |
| 347 | struct applesmc_entry entry; | 351 | const struct applesmc_entry *entry; |
| 348 | int ret; | ||
| 349 | 352 | ||
| 350 | while (begin != end) { | 353 | while (begin != end) { |
| 351 | int middle = begin + (end - begin) / 2; | 354 | int middle = begin + (end - begin) / 2; |
| 352 | ret = applesmc_get_entry_by_index(middle, &entry); | 355 | entry = applesmc_get_entry_by_index(middle); |
| 353 | if (ret) | 356 | if (IS_ERR(entry)) |
| 354 | return ret; | 357 | return PTR_ERR(entry); |
| 355 | if (strcmp(entry.key, key) < 0) | 358 | if (strcmp(entry->key, key) < 0) |
| 356 | begin = middle + 1; | 359 | begin = middle + 1; |
| 357 | else | 360 | else |
| 358 | end = middle; | 361 | end = middle; |
| @@ -365,15 +368,14 @@ static int applesmc_get_lower_bound(unsigned int *lo, const char *key) | |||
| 365 | static int applesmc_get_upper_bound(unsigned int *hi, const char *key) | 368 | static int applesmc_get_upper_bound(unsigned int *hi, const char *key) |
| 366 | { | 369 | { |
| 367 | int begin = 0, end = smcreg.key_count; | 370 | int begin = 0, end = smcreg.key_count; |
| 368 | struct applesmc_entry entry; | 371 | const struct applesmc_entry *entry; |
| 369 | int ret; | ||
| 370 | 372 | ||
| 371 | while (begin != end) { | 373 | while (begin != end) { |
| 372 | int middle = begin + (end - begin) / 2; | 374 | int middle = begin + (end - begin) / 2; |
| 373 | ret = applesmc_get_entry_by_index(middle, &entry); | 375 | entry = applesmc_get_entry_by_index(middle); |
| 374 | if (ret) | 376 | if (IS_ERR(entry)) |
| 375 | return ret; | 377 | return PTR_ERR(entry); |
| 376 | if (strcmp(key, entry.key) < 0) | 378 | if (strcmp(key, entry->key) < 0) |
| 377 | end = middle; | 379 | end = middle; |
| 378 | else | 380 | else |
| 379 | begin = middle + 1; | 381 | begin = middle + 1; |
| @@ -383,58 +385,54 @@ static int applesmc_get_upper_bound(unsigned int *hi, const char *key) | |||
| 383 | return 0; | 385 | return 0; |
| 384 | } | 386 | } |
| 385 | 387 | ||
| 386 | static int applesmc_get_entry_by_key(const char *key, | 388 | static const struct applesmc_entry *applesmc_get_entry_by_key(const char *key) |
| 387 | struct applesmc_entry *entry) | ||
| 388 | { | 389 | { |
| 389 | int begin, end; | 390 | int begin, end; |
| 390 | int ret; | 391 | int ret; |
| 391 | 392 | ||
| 392 | ret = applesmc_get_lower_bound(&begin, key); | 393 | ret = applesmc_get_lower_bound(&begin, key); |
| 393 | if (ret) | 394 | if (ret) |
| 394 | return ret; | 395 | return ERR_PTR(ret); |
| 395 | ret = applesmc_get_upper_bound(&end, key); | 396 | ret = applesmc_get_upper_bound(&end, key); |
| 396 | if (ret) | 397 | if (ret) |
| 397 | return ret; | 398 | return ERR_PTR(ret); |
| 398 | if (end - begin != 1) | 399 | if (end - begin != 1) |
| 399 | return -EINVAL; | 400 | return ERR_PTR(-EINVAL); |
| 400 | 401 | ||
| 401 | return applesmc_get_entry_by_index(begin, entry); | 402 | return applesmc_get_entry_by_index(begin); |
| 402 | } | 403 | } |
| 403 | 404 | ||
| 404 | static int applesmc_read_key(const char *key, u8 *buffer, u8 len) | 405 | static int applesmc_read_key(const char *key, u8 *buffer, u8 len) |
| 405 | { | 406 | { |
| 406 | struct applesmc_entry entry; | 407 | const struct applesmc_entry *entry; |
| 407 | int ret; | ||
| 408 | 408 | ||
| 409 | ret = applesmc_get_entry_by_key(key, &entry); | 409 | entry = applesmc_get_entry_by_key(key); |
| 410 | if (ret) | 410 | if (IS_ERR(entry)) |
| 411 | return ret; | 411 | return PTR_ERR(entry); |
| 412 | 412 | ||
| 413 | return applesmc_read_entry(&entry, buffer, len); | 413 | return applesmc_read_entry(entry, buffer, len); |
| 414 | } | 414 | } |
| 415 | 415 | ||
| 416 | static int applesmc_write_key(const char *key, const u8 *buffer, u8 len) | 416 | static int applesmc_write_key(const char *key, const u8 *buffer, u8 len) |
| 417 | { | 417 | { |
| 418 | struct applesmc_entry entry; | 418 | const struct applesmc_entry *entry; |
| 419 | int ret; | ||
| 420 | 419 | ||
| 421 | ret = applesmc_get_entry_by_key(key, &entry); | 420 | entry = applesmc_get_entry_by_key(key); |
| 422 | if (ret) | 421 | if (IS_ERR(entry)) |
| 423 | return ret; | 422 | return PTR_ERR(entry); |
| 424 | 423 | ||
| 425 | return applesmc_write_entry(&entry, buffer, len); | 424 | return applesmc_write_entry(entry, buffer, len); |
| 426 | } | 425 | } |
| 427 | 426 | ||
| 428 | static int applesmc_has_key(const char *key, bool *value) | 427 | static int applesmc_has_key(const char *key, bool *value) |
| 429 | { | 428 | { |
| 430 | struct applesmc_entry entry; | 429 | const struct applesmc_entry *entry; |
| 431 | int ret; | ||
| 432 | 430 | ||
| 433 | ret = applesmc_get_entry_by_key(key, &entry); | 431 | entry = applesmc_get_entry_by_key(key); |
| 434 | if (ret && ret != -EINVAL) | 432 | if (IS_ERR(entry) && PTR_ERR(entry) != -EINVAL) |
| 435 | return ret; | 433 | return PTR_ERR(entry); |
| 436 | 434 | ||
| 437 | *value = ret == 0 && entry.len; | 435 | *value = !IS_ERR(entry); |
| 438 | return 0; | 436 | return 0; |
| 439 | } | 437 | } |
| 440 | 438 | ||
| @@ -466,23 +464,20 @@ static int applesmc_read_motion_sensor(int index, s16* value) | |||
| 466 | } | 464 | } |
| 467 | 465 | ||
| 468 | /* | 466 | /* |
| 469 | * applesmc_device_init - initialize the accelerometer. Returns zero on success | 467 | * applesmc_device_init - initialize the accelerometer. Can sleep. |
| 470 | * and negative error code on failure. Can sleep. | ||
| 471 | */ | 468 | */ |
| 472 | static int applesmc_device_init(void) | 469 | static void applesmc_device_init(void) |
| 473 | { | 470 | { |
| 474 | int total, ret = -ENXIO; | 471 | int total; |
| 475 | u8 buffer[2]; | 472 | u8 buffer[2]; |
| 476 | 473 | ||
| 477 | if (!smcreg.has_accelerometer) | 474 | if (!smcreg.has_accelerometer) |
| 478 | return 0; | 475 | return; |
| 479 | 476 | ||
| 480 | for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) { | 477 | for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) { |
| 481 | if (!applesmc_read_key(MOTION_SENSOR_KEY, buffer, 2) && | 478 | if (!applesmc_read_key(MOTION_SENSOR_KEY, buffer, 2) && |
| 482 | (buffer[0] != 0x00 || buffer[1] != 0x00)) { | 479 | (buffer[0] != 0x00 || buffer[1] != 0x00)) |
| 483 | ret = 0; | 480 | return; |
| 484 | goto out; | ||
| 485 | } | ||
| 486 | buffer[0] = 0xe0; | 481 | buffer[0] = 0xe0; |
| 487 | buffer[1] = 0x00; | 482 | buffer[1] = 0x00; |
| 488 | applesmc_write_key(MOTION_SENSOR_KEY, buffer, 2); | 483 | applesmc_write_key(MOTION_SENSOR_KEY, buffer, 2); |
| @@ -490,9 +485,6 @@ static int applesmc_device_init(void) | |||
| 490 | } | 485 | } |
| 491 | 486 | ||
| 492 | pr_warn("failed to init the device\n"); | 487 | pr_warn("failed to init the device\n"); |
| 493 | |||
| 494 | out: | ||
| 495 | return ret; | ||
| 496 | } | 488 | } |
| 497 | 489 | ||
| 498 | /* | 490 | /* |
| @@ -501,7 +493,8 @@ out: | |||
| 501 | static int applesmc_init_smcreg_try(void) | 493 | static int applesmc_init_smcreg_try(void) |
| 502 | { | 494 | { |
| 503 | struct applesmc_registers *s = &smcreg; | 495 | struct applesmc_registers *s = &smcreg; |
| 504 | u8 tmp[4]; | 496 | bool left_light_sensor, right_light_sensor; |
| 497 | u8 tmp[1]; | ||
| 505 | int ret; | 498 | int ret; |
| 506 | 499 | ||
| 507 | if (s->init_complete) | 500 | if (s->init_complete) |
| @@ -513,9 +506,9 @@ static int applesmc_init_smcreg_try(void) | |||
| 513 | if (ret) | 506 | if (ret) |
| 514 | return ret; | 507 | return ret; |
| 515 | 508 | ||
| 516 | if (!s->entry) | 509 | if (!s->cache) |
| 517 | s->entry = kcalloc(s->key_count, sizeof(*s->entry), GFP_KERNEL); | 510 | s->cache = kcalloc(s->key_count, sizeof(*s->cache), GFP_KERNEL); |
| 518 | if (!s->entry) | 511 | if (!s->cache) |
| 519 | return -ENOMEM; | 512 | return -ENOMEM; |
| 520 | 513 | ||
| 521 | ret = applesmc_read_key(FANS_COUNT, tmp, 1); | 514 | ret = applesmc_read_key(FANS_COUNT, tmp, 1); |
| @@ -531,26 +524,27 @@ static int applesmc_init_smcreg_try(void) | |||
| 531 | return ret; | 524 | return ret; |
| 532 | s->temp_count = s->temp_end - s->temp_begin; | 525 | s->temp_count = s->temp_end - s->temp_begin; |
| 533 | 526 | ||
| 534 | ret = applesmc_has_key(LIGHT_SENSOR_LEFT_KEY, &s->has_left_light); | 527 | ret = applesmc_has_key(LIGHT_SENSOR_LEFT_KEY, &left_light_sensor); |
| 535 | if (ret) | 528 | if (ret) |
| 536 | return ret; | 529 | return ret; |
| 537 | ret = applesmc_has_key(LIGHT_SENSOR_RIGHT_KEY, &s->has_right_light); | 530 | ret = applesmc_has_key(LIGHT_SENSOR_RIGHT_KEY, &right_light_sensor); |
| 538 | if (ret) | 531 | if (ret) |
| 539 | return ret; | 532 | return ret; |
| 540 | ret = applesmc_has_key(MOTION_SENSOR_KEY, &s->has_accelerometer); | 533 | ret = applesmc_has_key(MOTION_SENSOR_KEY, &s->has_accelerometer); |
| 541 | if (ret) | 534 | if (ret) |
| 542 | return ret; | 535 | return ret; |
| 543 | ret = applesmc_has_key(BACKLIGHT_KEY, &s->has_key_light); | 536 | ret = applesmc_has_key(BACKLIGHT_KEY, &s->has_key_backlight); |
| 544 | if (ret) | 537 | if (ret) |
| 545 | return ret; | 538 | return ret; |
| 546 | 539 | ||
| 540 | s->num_light_sensors = left_light_sensor + right_light_sensor; | ||
| 547 | s->init_complete = true; | 541 | s->init_complete = true; |
| 548 | 542 | ||
| 549 | pr_info("key=%d fan=%d temp=%d acc=%d, light=%d, keyb=%d\n", | 543 | pr_info("key=%d fan=%d temp=%d acc=%d lux=%d kbd=%d\n", |
| 550 | s->key_count, s->fan_count, s->temp_count, | 544 | s->key_count, s->fan_count, s->temp_count, |
| 551 | s->has_accelerometer, | 545 | s->has_accelerometer, |
| 552 | s->has_left_light + s->has_right_light, | 546 | s->num_light_sensors, |
| 553 | s->has_key_light); | 547 | s->has_key_backlight); |
| 554 | 548 | ||
| 555 | return 0; | 549 | return 0; |
| 556 | } | 550 | } |
| @@ -578,8 +572,8 @@ static int applesmc_init_smcreg(void) | |||
| 578 | 572 | ||
| 579 | static void applesmc_destroy_smcreg(void) | 573 | static void applesmc_destroy_smcreg(void) |
| 580 | { | 574 | { |
| 581 | kfree(smcreg.entry); | 575 | kfree(smcreg.cache); |
| 582 | smcreg.entry = NULL; | 576 | memset(&smcreg, 0, sizeof(smcreg)); |
| 583 | } | 577 | } |
| 584 | 578 | ||
| 585 | /* Device model stuff */ | 579 | /* Device model stuff */ |
| @@ -599,7 +593,7 @@ static int applesmc_probe(struct platform_device *dev) | |||
| 599 | /* Synchronize device with memorized backlight state */ | 593 | /* Synchronize device with memorized backlight state */ |
| 600 | static int applesmc_pm_resume(struct device *dev) | 594 | static int applesmc_pm_resume(struct device *dev) |
| 601 | { | 595 | { |
| 602 | if (smcreg.has_key_light) | 596 | if (smcreg.has_key_backlight) |
| 603 | applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2); | 597 | applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2); |
| 604 | return 0; | 598 | return 0; |
| 605 | } | 599 | } |
| @@ -686,17 +680,19 @@ out: | |||
| 686 | static ssize_t applesmc_light_show(struct device *dev, | 680 | static ssize_t applesmc_light_show(struct device *dev, |
| 687 | struct device_attribute *attr, char *sysfsbuf) | 681 | struct device_attribute *attr, char *sysfsbuf) |
| 688 | { | 682 | { |
| 689 | struct applesmc_entry entry; | 683 | const struct applesmc_entry *entry; |
| 690 | static int data_length; | 684 | static int data_length; |
| 691 | int ret; | 685 | int ret; |
| 692 | u8 left = 0, right = 0; | 686 | u8 left = 0, right = 0; |
| 693 | u8 buffer[10]; | 687 | u8 buffer[10]; |
| 694 | 688 | ||
| 695 | if (!data_length) { | 689 | if (!data_length) { |
| 696 | ret = applesmc_get_entry_by_key(LIGHT_SENSOR_LEFT_KEY, &entry); | 690 | entry = applesmc_get_entry_by_key(LIGHT_SENSOR_LEFT_KEY); |
| 697 | if (ret) | 691 | if (IS_ERR(entry)) |
| 698 | goto out; | 692 | return PTR_ERR(entry); |
| 699 | data_length = clamp_val(entry.len, 0, 10); | 693 | if (entry->len > 10) |
| 694 | return -ENXIO; | ||
| 695 | data_length = entry->len; | ||
| 700 | pr_info("light sensor data length set to %d\n", data_length); | 696 | pr_info("light sensor data length set to %d\n", data_length); |
| 701 | } | 697 | } |
| 702 | 698 | ||
| @@ -724,14 +720,13 @@ static ssize_t applesmc_show_sensor_label(struct device *dev, | |||
| 724 | struct device_attribute *devattr, char *sysfsbuf) | 720 | struct device_attribute *devattr, char *sysfsbuf) |
| 725 | { | 721 | { |
| 726 | int index = smcreg.temp_begin + to_index(devattr); | 722 | int index = smcreg.temp_begin + to_index(devattr); |
| 727 | struct applesmc_entry entry; | 723 | const struct applesmc_entry *entry; |
| 728 | int ret; | ||
| 729 | 724 | ||
| 730 | ret = applesmc_get_entry_by_index(index, &entry); | 725 | entry = applesmc_get_entry_by_index(index); |
| 731 | if (ret) | 726 | if (IS_ERR(entry)) |
| 732 | return ret; | 727 | return PTR_ERR(entry); |
| 733 | 728 | ||
| 734 | return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry.key); | 729 | return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->key); |
| 735 | } | 730 | } |
| 736 | 731 | ||
| 737 | /* Displays degree Celsius * 1000 */ | 732 | /* Displays degree Celsius * 1000 */ |
| @@ -739,26 +734,25 @@ static ssize_t applesmc_show_temperature(struct device *dev, | |||
| 739 | struct device_attribute *devattr, char *sysfsbuf) | 734 | struct device_attribute *devattr, char *sysfsbuf) |
| 740 | { | 735 | { |
| 741 | int index = smcreg.temp_begin + to_index(devattr); | 736 | int index = smcreg.temp_begin + to_index(devattr); |
| 742 | struct applesmc_entry entry; | 737 | const struct applesmc_entry *entry; |
| 743 | int ret; | 738 | int ret; |
| 744 | u8 buffer[2]; | 739 | u8 buffer[2]; |
| 745 | unsigned int temp; | 740 | unsigned int temp; |
| 746 | 741 | ||
| 747 | ret = applesmc_get_entry_by_index(index, &entry); | 742 | entry = applesmc_get_entry_by_index(index); |
| 748 | if (ret) | 743 | if (IS_ERR(entry)) |
| 749 | return ret; | 744 | return PTR_ERR(entry); |
| 750 | if (entry.len > 2) | 745 | if (entry->len > 2) |
| 751 | return -EINVAL; | 746 | return -EINVAL; |
| 752 | 747 | ||
| 753 | ret = applesmc_read_entry(&entry, buffer, entry.len); | 748 | ret = applesmc_read_entry(entry, buffer, entry->len); |
| 754 | if (ret) | 749 | if (ret) |
| 755 | return ret; | 750 | return ret; |
| 756 | 751 | ||
| 757 | if (entry.len == 2) { | 752 | if (entry->len == 2) { |
| 758 | temp = buffer[0]*1000; | 753 | temp = buffer[0] * 1000; |
| 759 | temp += (buffer[1] >> 6) * 250; | 754 | temp += (buffer[1] >> 6) * 250; |
| 760 | } else { | 755 | } else { |
| 761 | /* wild guess */ | ||
| 762 | temp = buffer[0] * 4000; | 756 | temp = buffer[0] * 4000; |
| 763 | } | 757 | } |
| 764 | 758 | ||
| @@ -929,56 +923,53 @@ static ssize_t applesmc_key_count_show(struct device *dev, | |||
| 929 | static ssize_t applesmc_key_at_index_read_show(struct device *dev, | 923 | static ssize_t applesmc_key_at_index_read_show(struct device *dev, |
| 930 | struct device_attribute *attr, char *sysfsbuf) | 924 | struct device_attribute *attr, char *sysfsbuf) |
| 931 | { | 925 | { |
| 932 | struct applesmc_entry entry; | 926 | const struct applesmc_entry *entry; |
| 933 | int ret; | 927 | int ret; |
| 934 | 928 | ||
| 935 | ret = applesmc_get_entry_by_index(key_at_index, &entry); | 929 | entry = applesmc_get_entry_by_index(key_at_index); |
| 936 | if (ret) | 930 | if (IS_ERR(entry)) |
| 937 | return ret; | 931 | return PTR_ERR(entry); |
| 938 | ret = applesmc_read_entry(&entry, sysfsbuf, entry.len); | 932 | ret = applesmc_read_entry(entry, sysfsbuf, entry->len); |
| 939 | if (ret) | 933 | if (ret) |
| 940 | return ret; | 934 | return ret; |
| 941 | 935 | ||
| 942 | return entry.len; | 936 | return entry->len; |
| 943 | } | 937 | } |
| 944 | 938 | ||
| 945 | static ssize_t applesmc_key_at_index_data_length_show(struct device *dev, | 939 | static ssize_t applesmc_key_at_index_data_length_show(struct device *dev, |
| 946 | struct device_attribute *attr, char *sysfsbuf) | 940 | struct device_attribute *attr, char *sysfsbuf) |
| 947 | { | 941 | { |
| 948 | struct applesmc_entry entry; | 942 | const struct applesmc_entry *entry; |
| 949 | int ret; | ||
| 950 | 943 | ||
| 951 | ret = applesmc_get_entry_by_index(key_at_index, &entry); | 944 | entry = applesmc_get_entry_by_index(key_at_index); |
| 952 | if (ret) | 945 | if (IS_ERR(entry)) |
| 953 | return ret; | 946 | return PTR_ERR(entry); |
| 954 | 947 | ||
| 955 | return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", entry.len); | 948 | return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", entry->len); |
| 956 | } | 949 | } |
| 957 | 950 | ||
| 958 | static ssize_t applesmc_key_at_index_type_show(struct device *dev, | 951 | static ssize_t applesmc_key_at_index_type_show(struct device *dev, |
| 959 | struct device_attribute *attr, char *sysfsbuf) | 952 | struct device_attribute *attr, char *sysfsbuf) |
| 960 | { | 953 | { |
| 961 | struct applesmc_entry entry; | 954 | const struct applesmc_entry *entry; |
| 962 | int ret; | ||
| 963 | 955 | ||
| 964 | ret = applesmc_get_entry_by_index(key_at_index, &entry); | 956 | entry = applesmc_get_entry_by_index(key_at_index); |
| 965 | if (ret) | 957 | if (IS_ERR(entry)) |
| 966 | return ret; | 958 | return PTR_ERR(entry); |
| 967 | 959 | ||
| 968 | return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry.type); | 960 | return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->type); |
| 969 | } | 961 | } |
| 970 | 962 | ||
| 971 | static ssize_t applesmc_key_at_index_name_show(struct device *dev, | 963 | static ssize_t applesmc_key_at_index_name_show(struct device *dev, |
| 972 | struct device_attribute *attr, char *sysfsbuf) | 964 | struct device_attribute *attr, char *sysfsbuf) |
| 973 | { | 965 | { |
| 974 | struct applesmc_entry entry; | 966 | const struct applesmc_entry *entry; |
| 975 | int ret; | ||
| 976 | 967 | ||
| 977 | ret = applesmc_get_entry_by_index(key_at_index, &entry); | 968 | entry = applesmc_get_entry_by_index(key_at_index); |
| 978 | if (ret) | 969 | if (IS_ERR(entry)) |
| 979 | return ret; | 970 | return PTR_ERR(entry); |
| 980 | 971 | ||
| 981 | return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry.key); | 972 | return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->key); |
| 982 | } | 973 | } |
| 983 | 974 | ||
| 984 | static ssize_t applesmc_key_at_index_show(struct device *dev, | 975 | static ssize_t applesmc_key_at_index_show(struct device *dev, |
| @@ -1163,21 +1154,21 @@ static void applesmc_release_accelerometer(void) | |||
| 1163 | 1154 | ||
| 1164 | static int applesmc_create_light_sensor(void) | 1155 | static int applesmc_create_light_sensor(void) |
| 1165 | { | 1156 | { |
| 1166 | if (!smcreg.has_left_light) | 1157 | if (!smcreg.num_light_sensors) |
| 1167 | return 0; | 1158 | return 0; |
| 1168 | return applesmc_create_nodes(light_sensor_group, 1); | 1159 | return applesmc_create_nodes(light_sensor_group, 1); |
| 1169 | } | 1160 | } |
| 1170 | 1161 | ||
| 1171 | static void applesmc_release_light_sensor(void) | 1162 | static void applesmc_release_light_sensor(void) |
| 1172 | { | 1163 | { |
| 1173 | if (!smcreg.has_left_light) | 1164 | if (!smcreg.num_light_sensors) |
| 1174 | return; | 1165 | return; |
| 1175 | applesmc_destroy_nodes(light_sensor_group); | 1166 | applesmc_destroy_nodes(light_sensor_group); |
| 1176 | } | 1167 | } |
| 1177 | 1168 | ||
| 1178 | static int applesmc_create_key_backlight(void) | 1169 | static int applesmc_create_key_backlight(void) |
| 1179 | { | 1170 | { |
| 1180 | if (!smcreg.has_key_light) | 1171 | if (!smcreg.has_key_backlight) |
| 1181 | return 0; | 1172 | return 0; |
| 1182 | applesmc_led_wq = create_singlethread_workqueue("applesmc-led"); | 1173 | applesmc_led_wq = create_singlethread_workqueue("applesmc-led"); |
| 1183 | if (!applesmc_led_wq) | 1174 | if (!applesmc_led_wq) |
| @@ -1187,7 +1178,7 @@ static int applesmc_create_key_backlight(void) | |||
| 1187 | 1178 | ||
| 1188 | static void applesmc_release_key_backlight(void) | 1179 | static void applesmc_release_key_backlight(void) |
| 1189 | { | 1180 | { |
| 1190 | if (!smcreg.has_key_light) | 1181 | if (!smcreg.has_key_backlight) |
| 1191 | return; | 1182 | return; |
| 1192 | led_classdev_unregister(&applesmc_backlight); | 1183 | led_classdev_unregister(&applesmc_backlight); |
| 1193 | destroy_workqueue(applesmc_led_wq); | 1184 | destroy_workqueue(applesmc_led_wq); |
| @@ -1195,7 +1186,6 @@ static void applesmc_release_key_backlight(void) | |||
| 1195 | 1186 | ||
| 1196 | static int applesmc_dmi_match(const struct dmi_system_id *id) | 1187 | static int applesmc_dmi_match(const struct dmi_system_id *id) |
| 1197 | { | 1188 | { |
| 1198 | pr_info("%s detected\n", id->ident); | ||
| 1199 | return 1; | 1189 | return 1; |
| 1200 | } | 1190 | } |
| 1201 | 1191 | ||
| @@ -1291,8 +1281,6 @@ static int __init applesmc_init(void) | |||
| 1291 | goto out_light_ledclass; | 1281 | goto out_light_ledclass; |
| 1292 | } | 1282 | } |
| 1293 | 1283 | ||
| 1294 | pr_info("driver successfully loaded\n"); | ||
| 1295 | |||
| 1296 | return 0; | 1284 | return 0; |
| 1297 | 1285 | ||
| 1298 | out_light_ledclass: | 1286 | out_light_ledclass: |
| @@ -1333,8 +1321,6 @@ static void __exit applesmc_exit(void) | |||
| 1333 | platform_device_unregister(pdev); | 1321 | platform_device_unregister(pdev); |
| 1334 | platform_driver_unregister(&applesmc_driver); | 1322 | platform_driver_unregister(&applesmc_driver); |
| 1335 | release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS); | 1323 | release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS); |
| 1336 | |||
| 1337 | pr_info("driver unloaded\n"); | ||
| 1338 | } | 1324 | } |
| 1339 | 1325 | ||
| 1340 | module_init(applesmc_init); | 1326 | module_init(applesmc_init); |
