aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorPaul Fox <pgf@laptop.org>2011-02-03 11:27:55 -0500
committerMatthew Garrett <mjg@redhat.com>2011-03-28 06:05:14 -0400
commit89ca11771a4b50ed616ab6c37e0ef333d02f1d47 (patch)
treea0cd71e287e22500abe7848d6e840e9034d3281c /drivers
parent18bcd0c8cb7d85a9063b88ec810dc1cdc0974518 (diff)
OLPC XO-1.5 ebook switch driver
The OLPC XO-1.5 has an ebook switch, triggered when the laptop screen is rotated then folding down, converting the device into ebook form. This switch is exposed through ACPI. Add a driver that exposes it to userspace as an input device. Signed-off-by: Daniel Drake <dsd@laptop.org> Acked-by: Dmitry Torokhov <dtor@mail.ru> Signed-off-by: Matthew Garrett <mjg@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/platform/x86/Kconfig9
-rw-r--r--drivers/platform/x86/Makefile1
-rw-r--r--drivers/platform/x86/xo15-ebook.c181
3 files changed, 191 insertions, 0 deletions
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 222dfb737b11..2f6a37a1d2e6 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -672,4 +672,13 @@ config XO1_RFKILL
672 Support for enabling/disabling the WLAN interface on the OLPC XO-1 672 Support for enabling/disabling the WLAN interface on the OLPC XO-1
673 laptop. 673 laptop.
674 674
675config XO15_EBOOK
676 tristate "OLPC XO-1.5 ebook switch"
677 depends on ACPI && INPUT
678 ---help---
679 Support for the ebook switch on the OLPC XO-1.5 laptop.
680
681 This switch is triggered as the screen is rotated and folded down to
682 convert the device into ebook form.
683
675endif # X86_PLATFORM_DEVICES 684endif # X86_PLATFORM_DEVICES
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index 299aefb3e74c..daa286c9d53a 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -34,4 +34,5 @@ obj-$(CONFIG_RAR_REGISTER) += intel_rar_register.o
34obj-$(CONFIG_INTEL_IPS) += intel_ips.o 34obj-$(CONFIG_INTEL_IPS) += intel_ips.o
35obj-$(CONFIG_GPIO_INTEL_PMIC) += intel_pmic_gpio.o 35obj-$(CONFIG_GPIO_INTEL_PMIC) += intel_pmic_gpio.o
36obj-$(CONFIG_XO1_RFKILL) += xo1-rfkill.o 36obj-$(CONFIG_XO1_RFKILL) += xo1-rfkill.o
37obj-$(CONFIG_XO15_EBOOK) += xo15-ebook.o
37obj-$(CONFIG_IBM_RTL) += ibm_rtl.o 38obj-$(CONFIG_IBM_RTL) += ibm_rtl.o
diff --git a/drivers/platform/x86/xo15-ebook.c b/drivers/platform/x86/xo15-ebook.c
new file mode 100644
index 000000000000..2343bb36e563
--- /dev/null
+++ b/drivers/platform/x86/xo15-ebook.c
@@ -0,0 +1,181 @@
1/*
2 * OLPC XO-1.5 ebook switch driver
3 * (based on generic ACPI button driver)
4 *
5 * Copyright (C) 2009 Paul Fox <pgf@laptop.org>
6 * Copyright (C) 2010 One Laptop per Child
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/types.h>
18#include <linux/input.h>
19#include <acpi/acpi_bus.h>
20#include <acpi/acpi_drivers.h>
21
22#define MODULE_NAME "xo15-ebook"
23#define PREFIX MODULE_NAME ": "
24
25#define XO15_EBOOK_CLASS MODULE_NAME
26#define XO15_EBOOK_TYPE_UNKNOWN 0x00
27#define XO15_EBOOK_NOTIFY_STATUS 0x80
28
29#define XO15_EBOOK_SUBCLASS "ebook"
30#define XO15_EBOOK_HID "XO15EBK"
31#define XO15_EBOOK_DEVICE_NAME "EBook Switch"
32
33ACPI_MODULE_NAME(MODULE_NAME);
34
35MODULE_DESCRIPTION("OLPC XO-1.5 ebook switch driver");
36MODULE_LICENSE("GPL");
37
38static const struct acpi_device_id ebook_device_ids[] = {
39 { XO15_EBOOK_HID, 0 },
40 { "", 0 },
41};
42MODULE_DEVICE_TABLE(acpi, ebook_device_ids);
43
44struct ebook_switch {
45 struct input_dev *input;
46 char phys[32]; /* for input device */
47};
48
49static int ebook_send_state(struct acpi_device *device)
50{
51 struct ebook_switch *button = acpi_driver_data(device);
52 unsigned long long state;
53 acpi_status status;
54
55 status = acpi_evaluate_integer(device->handle, "EBK", NULL, &state);
56 if (ACPI_FAILURE(status))
57 return -EIO;
58
59 /* input layer checks if event is redundant */
60 input_report_switch(button->input, SW_TABLET_MODE, !state);
61 input_sync(button->input);
62 return 0;
63}
64
65static void ebook_switch_notify(struct acpi_device *device, u32 event)
66{
67 switch (event) {
68 case ACPI_FIXED_HARDWARE_EVENT:
69 case XO15_EBOOK_NOTIFY_STATUS:
70 ebook_send_state(device);
71 break;
72 default:
73 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
74 "Unsupported event [0x%x]\n", event));
75 break;
76 }
77}
78
79static int ebook_switch_resume(struct acpi_device *device)
80{
81 return ebook_send_state(device);
82}
83
84static int ebook_switch_add(struct acpi_device *device)
85{
86 struct ebook_switch *button;
87 struct input_dev *input;
88 const char *hid = acpi_device_hid(device);
89 char *name, *class;
90 int error;
91
92 button = kzalloc(sizeof(struct ebook_switch), GFP_KERNEL);
93 if (!button)
94 return -ENOMEM;
95
96 device->driver_data = button;
97
98 button->input = input = input_allocate_device();
99 if (!input) {
100 error = -ENOMEM;
101 goto err_free_button;
102 }
103
104 name = acpi_device_name(device);
105 class = acpi_device_class(device);
106
107 if (strcmp(hid, XO15_EBOOK_HID)) {
108 printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", hid);
109 error = -ENODEV;
110 goto err_free_input;
111 }
112
113 strcpy(name, XO15_EBOOK_DEVICE_NAME);
114 sprintf(class, "%s/%s", XO15_EBOOK_CLASS, XO15_EBOOK_SUBCLASS);
115
116 snprintf(button->phys, sizeof(button->phys), "%s/button/input0", hid);
117
118 input->name = name;
119 input->phys = button->phys;
120 input->id.bustype = BUS_HOST;
121 input->dev.parent = &device->dev;
122
123 input->evbit[0] = BIT_MASK(EV_SW);
124 set_bit(SW_TABLET_MODE, input->swbit);
125
126 error = input_register_device(input);
127 if (error)
128 goto err_free_input;
129
130 ebook_send_state(device);
131
132 if (device->wakeup.flags.valid) {
133 /* Button's GPE is run-wake GPE */
134 acpi_enable_gpe(device->wakeup.gpe_device,
135 device->wakeup.gpe_number);
136 device->wakeup.run_wake_count++;
137 device_set_wakeup_enable(&device->dev, true);
138 }
139
140 return 0;
141
142 err_free_input:
143 input_free_device(input);
144 err_free_button:
145 kfree(button);
146 return error;
147}
148
149static int ebook_switch_remove(struct acpi_device *device, int type)
150{
151 struct ebook_switch *button = acpi_driver_data(device);
152
153 input_unregister_device(button->input);
154 kfree(button);
155 return 0;
156}
157
158static struct acpi_driver xo15_ebook_driver = {
159 .name = MODULE_NAME,
160 .class = XO15_EBOOK_CLASS,
161 .ids = ebook_device_ids,
162 .ops = {
163 .add = ebook_switch_add,
164 .resume = ebook_switch_resume,
165 .remove = ebook_switch_remove,
166 .notify = ebook_switch_notify,
167 },
168};
169
170static int __init xo15_ebook_init(void)
171{
172 return acpi_bus_register_driver(&xo15_ebook_driver);
173}
174
175static void __exit xo15_ebook_exit(void)
176{
177 acpi_bus_unregister_driver(&xo15_ebook_driver);
178}
179
180module_init(xo15_ebook_init);
181module_exit(xo15_ebook_exit);