15 #include <linux/device.h>
17 #include <linux/input.h>
32 #define DRV_NAME "olpc-xo1-sci"
33 #define PFX DRV_NAME ": "
35 static unsigned long acpi_base;
36 static struct input_dev *power_button_idev;
37 static struct input_dev *ebook_switch_idev;
38 static struct input_dev *lid_switch_idev;
43 static bool lid_inverted;
44 static int lid_wake_mode;
52 static const char *
const lid_wake_mode_names[] = {
58 static void battery_status_changed(
void)
68 static void ac_status_changed(
void)
79 static void send_ebook_state(
void)
84 pr_err(
PFX "failed to get ebook state\n");
92 input_sync(ebook_switch_idev);
96 static void flip_lid_inverter(
void)
103 lid_inverted = !lid_inverted;
106 static void detect_lid_state(
void)
130 static void send_lid_state(
void)
136 input_sync(lid_switch_idev);
143 const char *
mode = lid_wake_mode_names[lid_wake_mode];
144 return sprintf(buf,
"%s\n", mode);
151 for (i = 0; i <
ARRAY_SIZE(lid_wake_mode_names); i++) {
152 const char *
mode = lid_wake_mode_names[
i];
173 static void process_sci_queue(
bool propagate_events)
190 battery_status_changed();
207 process_sci_queue(
true);
224 dev_dbg(&pdev->
dev,
"sts %x gpe %x\n", sts, gpe);
231 input_report_key(power_button_idev,
KEY_POWER, 1);
232 input_sync(power_button_idev);
233 input_report_key(power_button_idev,
KEY_POWER, 0);
234 input_sync(power_button_idev);
267 if (device_may_wakeup(&power_button_idev->dev))
272 if (device_may_wakeup(&ebook_switch_idev->dev))
277 if (!device_may_wakeup(&lid_switch_idev->dev)) {
307 battery_status_changed();
318 rdmsr(0x51400020, lo, hi);
319 sci_irq = (lo >> 20) & 15;
322 dev_info(&pdev->
dev,
"SCI is mapped to IRQ %d\n", sci_irq);
325 dev_info(&pdev->
dev,
"SCI unmapped. Mapping to IRQ 3\n");
328 wrmsrl(0x51400020, lo);
338 lo |= 1 << (sci_irq - 8);
349 dev_err(&pdev->
dev,
"can't request interrupt\n");
388 cs5535_pic_unreqz_select_high(7, sci_irq);
393 static void free_ec_sci(
void)
398 static int __devinit setup_lid_events(
void)
430 static void free_lid_events(
void)
439 power_button_idev = input_allocate_device();
440 if (!power_button_idev)
443 power_button_idev->name =
"Power Button";
444 power_button_idev->phys =
DRV_NAME "/input0";
448 power_button_idev->dev.parent = &pdev->
dev;
451 r = input_register_device(power_button_idev);
453 dev_err(&pdev->
dev,
"failed to register power button: %d\n", r);
454 input_free_device(power_button_idev);
460 static void free_power_button(
void)
462 input_unregister_device(power_button_idev);
463 input_free_device(power_button_idev);
470 ebook_switch_idev = input_allocate_device();
471 if (!ebook_switch_idev)
474 ebook_switch_idev->name =
"EBook Switch";
475 ebook_switch_idev->phys =
DRV_NAME "/input1";
479 ebook_switch_idev->dev.parent = &pdev->
dev;
482 r = input_register_device(ebook_switch_idev);
484 dev_err(&pdev->
dev,
"failed to register ebook switch: %d\n", r);
485 input_free_device(ebook_switch_idev);
491 static void free_ebook_switch(
void)
493 input_unregister_device(ebook_switch_idev);
494 input_free_device(ebook_switch_idev);
501 lid_switch_idev = input_allocate_device();
502 if (!lid_switch_idev)
505 lid_switch_idev->name =
"Lid Switch";
506 lid_switch_idev->phys =
DRV_NAME "/input2";
510 lid_switch_idev->dev.parent = &pdev->
dev;
513 r = input_register_device(lid_switch_idev);
515 dev_err(&pdev->
dev,
"failed to register lid switch: %d\n", r);
521 dev_err(&pdev->
dev,
"failed to create wake mode attr: %d\n", r);
522 goto err_create_attr;
528 input_unregister_device(lid_switch_idev);
530 input_free_device(lid_switch_idev);
534 static void free_lid_switch(
void)
537 input_unregister_device(lid_switch_idev);
538 input_free_device(lid_switch_idev);
547 if (!machine_is_olpc())
556 dev_err(&pdev->
dev,
"can't fetch device resource info\n");
559 acpi_base = res->
start;
561 r = setup_power_button(pdev);
565 r = setup_ebook_switch(pdev);
569 r = setup_lid_switch(pdev);
573 r = setup_lid_events();
587 process_sci_queue(
false);
594 r = setup_sci_interrupt(pdev);
632 .name =
"olpc-xo1-sci-acpi",
634 .probe = xo1_sci_probe,
636 .suspend = xo1_sci_suspend,
637 .resume = xo1_sci_resume,
640 static int __init xo1_sci_init(
void)