aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAzael Avalos <coproscefalo@gmail.com>2014-03-25 22:38:30 -0400
committerMatthew Garrett <matthew.garrett@nebula.com>2014-04-06 12:58:13 -0400
commitfdb79081fec4a57e124b34f983aac566e210220f (patch)
tree4e683d8eaee2f1e8b9aed37a95baab72d96c740d
parent84a6273f04fd19cad189c8327d0c3c17a053ab8b (diff)
toshiba_acpi: Adapt Illumination code to use SCI
Change the toshiba_illumination_* code to use the newly introduced SCI functions, making the code more robust in detecting Illumination capabilities properly, since it was only opening the SCI and the return value was never checked for errors or actual Illumination support. Signed-off-by: Azael Avalos <coproscefalo@gmail.com> Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
-rw-r--r--drivers/platform/x86/toshiba_acpi.c94
1 files changed, 34 insertions, 60 deletions
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index c4680037bbfd..6ed5be030d58 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -100,6 +100,7 @@ MODULE_LICENSE("GPL");
100#define SCI_OPEN_CLOSE_OK 0x0044 100#define SCI_OPEN_CLOSE_OK 0x0044
101#define SCI_ALREADY_OPEN 0x8100 101#define SCI_ALREADY_OPEN 0x8100
102#define SCI_NOT_OPENED 0x8200 102#define SCI_NOT_OPENED 0x8200
103#define SCI_INPUT_DATA_ERROR 0x8300
103#define SCI_NOT_PRESENT 0x8600 104#define SCI_NOT_PRESENT 0x8600
104 105
105/* registers */ 106/* registers */
@@ -110,6 +111,7 @@ MODULE_LICENSE("GPL");
110#define HCI_HOTKEY_EVENT 0x001e 111#define HCI_HOTKEY_EVENT 0x001e
111#define HCI_LCD_BRIGHTNESS 0x002a 112#define HCI_LCD_BRIGHTNESS 0x002a
112#define HCI_WIRELESS 0x0056 113#define HCI_WIRELESS 0x0056
114#define SCI_ILLUMINATION 0x014e
113 115
114/* field definitions */ 116/* field definitions */
115#define HCI_HOTKEY_DISABLE 0x0b 117#define HCI_HOTKEY_DISABLE 0x0b
@@ -362,18 +364,23 @@ static acpi_status sci_write(struct toshiba_acpi_dev *dev, u32 reg,
362/* Illumination support */ 364/* Illumination support */
363static int toshiba_illumination_available(struct toshiba_acpi_dev *dev) 365static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
364{ 366{
365 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 }; 367 u32 in[HCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
366 u32 out[HCI_WORDS]; 368 u32 out[HCI_WORDS];
367 acpi_status status; 369 acpi_status status;
368 370
369 in[0] = 0xf100; 371 if (!sci_open(dev))
372 return 0;
373
370 status = hci_raw(dev, in, out); 374 status = hci_raw(dev, in, out);
371 if (ACPI_FAILURE(status)) { 375 sci_close(dev);
376 if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
377 pr_err("ACPI call to query Illumination support failed\n");
378 return 0;
379 } else if (out[0] == HCI_NOT_SUPPORTED || out[1] != 1) {
372 pr_info("Illumination device not available\n"); 380 pr_info("Illumination device not available\n");
373 return 0; 381 return 0;
374 } 382 }
375 in[0] = 0xf400; 383
376 status = hci_raw(dev, in, out);
377 return 1; 384 return 1;
378} 385}
379 386
@@ -382,82 +389,49 @@ static void toshiba_illumination_set(struct led_classdev *cdev,
382{ 389{
383 struct toshiba_acpi_dev *dev = container_of(cdev, 390 struct toshiba_acpi_dev *dev = container_of(cdev,
384 struct toshiba_acpi_dev, led_dev); 391 struct toshiba_acpi_dev, led_dev);
385 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 }; 392 u32 state, result;
386 u32 out[HCI_WORDS];
387 acpi_status status; 393 acpi_status status;
388 394
389 /* First request : initialize communication. */ 395 /* First request : initialize communication. */
390 in[0] = 0xf100; 396 if (!sci_open(dev))
391 status = hci_raw(dev, in, out);
392 if (ACPI_FAILURE(status)) {
393 pr_info("Illumination device not available\n");
394 return; 397 return;
395 }
396 398
397 if (brightness) { 399 /* Switch the illumination on/off */
398 /* Switch the illumination on */ 400 state = brightness ? 1 : 0;
399 in[0] = 0xf400; 401 status = sci_write(dev, SCI_ILLUMINATION, state, &result);
400 in[1] = 0x14e; 402 sci_close(dev);
401 in[2] = 1; 403 if (ACPI_FAILURE(status)) {
402 status = hci_raw(dev, in, out); 404 pr_err("ACPI call for illumination failed\n");
403 if (ACPI_FAILURE(status)) { 405 return;
404 pr_info("ACPI call for illumination failed\n"); 406 } else if (result == HCI_NOT_SUPPORTED) {
405 return; 407 pr_info("Illumination not supported\n");
406 } 408 return;
407 } else {
408 /* Switch the illumination off */
409 in[0] = 0xf400;
410 in[1] = 0x14e;
411 in[2] = 0;
412 status = hci_raw(dev, in, out);
413 if (ACPI_FAILURE(status)) {
414 pr_info("ACPI call for illumination failed.\n");
415 return;
416 }
417 } 409 }
418
419 /* Last request : close communication. */
420 in[0] = 0xf200;
421 in[1] = 0;
422 in[2] = 0;
423 hci_raw(dev, in, out);
424} 410}
425 411
426static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev) 412static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
427{ 413{
428 struct toshiba_acpi_dev *dev = container_of(cdev, 414 struct toshiba_acpi_dev *dev = container_of(cdev,
429 struct toshiba_acpi_dev, led_dev); 415 struct toshiba_acpi_dev, led_dev);
430 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 }; 416 u32 state, result;
431 u32 out[HCI_WORDS];
432 acpi_status status; 417 acpi_status status;
433 enum led_brightness result;
434 418
435 /* First request : initialize communication. */ 419 /* First request : initialize communication. */
436 in[0] = 0xf100; 420 if (!sci_open(dev))
437 status = hci_raw(dev, in, out);
438 if (ACPI_FAILURE(status)) {
439 pr_info("Illumination device not available\n");
440 return LED_OFF; 421 return LED_OFF;
441 }
442 422
443 /* Check the illumination */ 423 /* Check the illumination */
444 in[0] = 0xf300; 424 status = sci_read(dev, SCI_ILLUMINATION, &state, &result);
445 in[1] = 0x14e; 425 sci_close(dev);
446 status = hci_raw(dev, in, out); 426 if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
447 if (ACPI_FAILURE(status)) { 427 pr_err("ACPI call for illumination failed\n");
448 pr_info("ACPI call for illumination failed.\n"); 428 return LED_OFF;
429 } else if (result == HCI_NOT_SUPPORTED) {
430 pr_info("Illumination not supported\n");
449 return LED_OFF; 431 return LED_OFF;
450 } 432 }
451 433
452 result = out[2] ? LED_FULL : LED_OFF; 434 return state ? LED_FULL : LED_OFF;
453
454 /* Last request : close communication. */
455 in[0] = 0xf200;
456 in[1] = 0;
457 in[2] = 0;
458 hci_raw(dev, in, out);
459
460 return result;
461} 435}
462 436
463/* Bluetooth rfkill handlers */ 437/* Bluetooth rfkill handlers */