2 * Copyright (C) 2006-2012 Robert Gerlach <khnz@gmx.de>
3 * Copyright (C) 2005-2006 Jan Rychter <jan@rychter.com>
5 * You can redistribute and/or modify this program under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12 * Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place Suite 330, Boston, MA 02111-1307, USA.
19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/bitops.h>
26 #include <linux/ioport.h>
27 #include <linux/acpi.h>
28 #include <linux/device.h>
29 #include <linux/interrupt.h>
30 #include <linux/input.h>
31 #include <linux/delay.h>
32 #include <linux/dmi.h>
34 #define MODULENAME "fujitsu-tablet"
36 #define ACPI_FUJITSU_CLASS "fujitsu"
38 #define INVERT_TABLET_MODE_BIT 0x01
39 #define INVERT_DOCK_STATE_BIT 0x02
40 #define FORCE_TABLET_MODE_IF_UNDOCK 0x04
44 static const struct acpi_device_id fujitsu_ids[] = {
50 struct fujitsu_config {
51 unsigned short keymap[KEYMAP_LEN];
55 static unsigned short keymap_Lifebook_Tseries[KEYMAP_LEN] __initdata = {
74 static unsigned short keymap_Lifebook_T901[KEYMAP_LEN] __initdata = {
93 static unsigned short keymap_Lifebook_T902[KEYMAP_LEN] __initdata = {
112 static unsigned short keymap_Lifebook_U810[KEYMAP_LEN] __initdata = {
131 static unsigned short keymap_Stylistic_Tseries[KEYMAP_LEN] __initdata = {
150 static unsigned short keymap_Stylistic_ST5xxx[KEYMAP_LEN] __initdata = {
170 struct input_dev *idev;
171 struct fujitsu_config config;
172 unsigned long prev_keymask;
181 static u8 fujitsu_ack(void)
183 return inb(fujitsu.io_base + 2);
186 static u8 fujitsu_status(void)
188 return inb(fujitsu.io_base + 6);
191 static u8 fujitsu_read_register(const u8 addr)
193 outb(addr, fujitsu.io_base);
194 return inb(fujitsu.io_base + 4);
197 static void fujitsu_send_state(void)
200 int dock, tablet_mode;
202 state = fujitsu_read_register(0xdd);
205 if (fujitsu.config.quirks & INVERT_DOCK_STATE_BIT)
208 if ((fujitsu.config.quirks & FORCE_TABLET_MODE_IF_UNDOCK) && (!dock)) {
211 tablet_mode = state & 0x01;
212 if (fujitsu.config.quirks & INVERT_TABLET_MODE_BIT)
213 tablet_mode = !tablet_mode;
216 input_report_switch(fujitsu.idev, SW_DOCK, dock);
217 input_report_switch(fujitsu.idev, SW_TABLET_MODE, tablet_mode);
218 input_sync(fujitsu.idev);
221 static void fujitsu_reset(void)
227 while ((fujitsu_status() & 0x02) && (--timeout))
230 fujitsu_send_state();
233 static int input_fujitsu_setup(struct device *parent, const char *name,
236 struct input_dev *idev;
240 idev = input_allocate_device();
244 idev->dev.parent = parent;
247 idev->id.bustype = BUS_HOST;
248 idev->id.vendor = 0x1734; /* Fujitsu Siemens Computer GmbH */
249 idev->id.product = 0x0001;
250 idev->id.version = 0x0101;
252 idev->keycode = fujitsu.config.keymap;
253 idev->keycodesize = sizeof(fujitsu.config.keymap[0]);
254 idev->keycodemax = ARRAY_SIZE(fujitsu.config.keymap);
256 __set_bit(EV_REP, idev->evbit);
258 for (i = 0; i < ARRAY_SIZE(fujitsu.config.keymap); i++)
259 if (fujitsu.config.keymap[i])
260 input_set_capability(idev, EV_KEY, fujitsu.config.keymap[i]);
262 input_set_capability(idev, EV_MSC, MSC_SCAN);
264 input_set_capability(idev, EV_SW, SW_DOCK);
265 input_set_capability(idev, EV_SW, SW_TABLET_MODE);
267 error = input_register_device(idev);
269 input_free_device(idev);
277 static void input_fujitsu_remove(void)
279 input_unregister_device(fujitsu.idev);
282 static irqreturn_t fujitsu_interrupt(int irq, void *dev_id)
284 unsigned long keymask, changed;
285 unsigned int keycode;
289 if (unlikely(!(fujitsu_status() & 0x01)))
292 fujitsu_send_state();
294 keymask = fujitsu_read_register(0xde);
295 keymask |= fujitsu_read_register(0xdf) << 8;
298 changed = keymask ^ fujitsu.prev_keymask;
300 fujitsu.prev_keymask = keymask;
302 for_each_set_bit(i, &changed, KEYMAP_LEN) {
303 keycode = fujitsu.config.keymap[i];
304 pressed = keymask & changed & BIT(i);
307 input_event(fujitsu.idev, EV_MSC, MSC_SCAN, i);
309 input_report_key(fujitsu.idev, keycode, pressed);
310 input_sync(fujitsu.idev);
318 static void __init fujitsu_dmi_common(const struct dmi_system_id *dmi)
320 pr_info("%s\n", dmi->ident);
321 memcpy(fujitsu.config.keymap, dmi->driver_data,
322 sizeof(fujitsu.config.keymap));
325 static int __init fujitsu_dmi_lifebook(const struct dmi_system_id *dmi)
327 fujitsu_dmi_common(dmi);
328 fujitsu.config.quirks |= INVERT_TABLET_MODE_BIT;
332 static int __init fujitsu_dmi_stylistic(const struct dmi_system_id *dmi)
334 fujitsu_dmi_common(dmi);
335 fujitsu.config.quirks |= FORCE_TABLET_MODE_IF_UNDOCK;
336 fujitsu.config.quirks |= INVERT_DOCK_STATE_BIT;
340 static const struct dmi_system_id dmi_ids[] __initconst = {
342 .callback = fujitsu_dmi_lifebook,
343 .ident = "Fujitsu Lifebook T901",
345 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
346 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook T901")
348 .driver_data = keymap_Lifebook_T901
351 .callback = fujitsu_dmi_lifebook,
352 .ident = "Fujitsu Lifebook T901",
354 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
355 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK T901")
357 .driver_data = keymap_Lifebook_T901
360 .callback = fujitsu_dmi_lifebook,
361 .ident = "Fujitsu Lifebook T902",
363 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
364 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK T902")
366 .driver_data = keymap_Lifebook_T902
369 .callback = fujitsu_dmi_lifebook,
370 .ident = "Fujitsu Siemens P/T Series",
372 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
373 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK")
375 .driver_data = keymap_Lifebook_Tseries
378 .callback = fujitsu_dmi_lifebook,
379 .ident = "Fujitsu Lifebook T Series",
381 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
382 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook T")
384 .driver_data = keymap_Lifebook_Tseries
387 .callback = fujitsu_dmi_stylistic,
388 .ident = "Fujitsu Siemens Stylistic T Series",
390 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
391 DMI_MATCH(DMI_PRODUCT_NAME, "Stylistic T")
393 .driver_data = keymap_Stylistic_Tseries
396 .callback = fujitsu_dmi_lifebook,
397 .ident = "Fujitsu LifeBook U810",
399 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
400 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook U810")
402 .driver_data = keymap_Lifebook_U810
405 .callback = fujitsu_dmi_stylistic,
406 .ident = "Fujitsu Siemens Stylistic ST5xxx Series",
408 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
409 DMI_MATCH(DMI_PRODUCT_NAME, "STYLISTIC ST5")
411 .driver_data = keymap_Stylistic_ST5xxx
414 .callback = fujitsu_dmi_stylistic,
415 .ident = "Fujitsu Siemens Stylistic ST5xxx Series",
417 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
418 DMI_MATCH(DMI_PRODUCT_NAME, "Stylistic ST5")
420 .driver_data = keymap_Stylistic_ST5xxx
423 .callback = fujitsu_dmi_lifebook,
424 .ident = "Unknown (using defaults)",
426 DMI_MATCH(DMI_SYS_VENDOR, ""),
427 DMI_MATCH(DMI_PRODUCT_NAME, "")
429 .driver_data = keymap_Lifebook_Tseries
434 static acpi_status fujitsu_walk_resources(struct acpi_resource *res, void *data)
437 case ACPI_RESOURCE_TYPE_IRQ:
438 fujitsu.irq = res->data.irq.interrupts[0];
441 case ACPI_RESOURCE_TYPE_IO:
442 fujitsu.io_base = res->data.io.minimum;
443 fujitsu.io_length = res->data.io.address_length;
446 case ACPI_RESOURCE_TYPE_END_TAG:
447 if (fujitsu.irq && fujitsu.io_base)
457 static int acpi_fujitsu_add(struct acpi_device *adev)
465 status = acpi_walk_resources(adev->handle, METHOD_NAME__CRS,
466 fujitsu_walk_resources, NULL);
467 if (ACPI_FAILURE(status) || !fujitsu.irq || !fujitsu.io_base)
470 sprintf(acpi_device_name(adev), "Fujitsu %s", acpi_device_hid(adev));
471 sprintf(acpi_device_class(adev), "%s", ACPI_FUJITSU_CLASS);
473 snprintf(fujitsu.phys, sizeof(fujitsu.phys),
474 "%s/input0", acpi_device_hid(adev));
476 error = input_fujitsu_setup(&adev->dev,
477 acpi_device_name(adev), fujitsu.phys);
481 if (!request_region(fujitsu.io_base, fujitsu.io_length, MODULENAME)) {
482 input_fujitsu_remove();
488 error = request_irq(fujitsu.irq, fujitsu_interrupt,
489 IRQF_SHARED, MODULENAME, fujitsu_interrupt);
491 release_region(fujitsu.io_base, fujitsu.io_length);
492 input_fujitsu_remove();
499 static int acpi_fujitsu_remove(struct acpi_device *adev)
501 free_irq(fujitsu.irq, fujitsu_interrupt);
502 release_region(fujitsu.io_base, fujitsu.io_length);
503 input_fujitsu_remove();
507 #ifdef CONFIG_PM_SLEEP
508 static int acpi_fujitsu_resume(struct device *dev)
515 static SIMPLE_DEV_PM_OPS(acpi_fujitsu_pm, NULL, acpi_fujitsu_resume);
517 static struct acpi_driver acpi_fujitsu_driver = {
522 .add = acpi_fujitsu_add,
523 .remove = acpi_fujitsu_remove,
525 .drv.pm = &acpi_fujitsu_pm,
528 static int __init fujitsu_module_init(void)
532 dmi_check_system(dmi_ids);
534 error = acpi_bus_register_driver(&acpi_fujitsu_driver);
541 static void __exit fujitsu_module_exit(void)
543 acpi_bus_unregister_driver(&acpi_fujitsu_driver);
546 module_init(fujitsu_module_init);
547 module_exit(fujitsu_module_exit);
549 MODULE_AUTHOR("Robert Gerlach <khnz@gmx.de>");
550 MODULE_DESCRIPTION("Fujitsu tablet pc extras driver");
551 MODULE_LICENSE("GPL");
552 MODULE_VERSION("2.5");
554 MODULE_DEVICE_TABLE(acpi, fujitsu_ids);