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_U810
[KEYMAP_LEN
] __initdata
= {
93 static unsigned short keymap_Stylistic_Tseries
[KEYMAP_LEN
] __initdata
= {
112 static unsigned short keymap_Stylistic_ST5xxx
[KEYMAP_LEN
] __initdata
= {
132 struct input_dev
*idev
;
133 struct fujitsu_config config
;
134 unsigned long prev_keymask
;
143 static u8
fujitsu_ack(void)
145 return inb(fujitsu
.io_base
+ 2);
148 static u8
fujitsu_status(void)
150 return inb(fujitsu
.io_base
+ 6);
153 static u8
fujitsu_read_register(const u8 addr
)
155 outb(addr
, fujitsu
.io_base
);
156 return inb(fujitsu
.io_base
+ 4);
159 static void fujitsu_send_state(void)
162 int dock
, tablet_mode
;
164 state
= fujitsu_read_register(0xdd);
167 if (fujitsu
.config
.quirks
& INVERT_DOCK_STATE_BIT
)
170 if ((fujitsu
.config
.quirks
& FORCE_TABLET_MODE_IF_UNDOCK
) && (!dock
)) {
173 tablet_mode
= state
& 0x01;
174 if (fujitsu
.config
.quirks
& INVERT_TABLET_MODE_BIT
)
175 tablet_mode
= !tablet_mode
;
178 input_report_switch(fujitsu
.idev
, SW_DOCK
, dock
);
179 input_report_switch(fujitsu
.idev
, SW_TABLET_MODE
, tablet_mode
);
180 input_sync(fujitsu
.idev
);
183 static void fujitsu_reset(void)
189 while ((fujitsu_status() & 0x02) && (--timeout
))
192 fujitsu_send_state();
195 static int input_fujitsu_setup(struct device
*parent
, const char *name
,
198 struct input_dev
*idev
;
202 idev
= input_allocate_device();
206 idev
->dev
.parent
= parent
;
209 idev
->id
.bustype
= BUS_HOST
;
210 idev
->id
.vendor
= 0x1734; /* Fujitsu Siemens Computer GmbH */
211 idev
->id
.product
= 0x0001;
212 idev
->id
.version
= 0x0101;
214 idev
->keycode
= fujitsu
.config
.keymap
;
215 idev
->keycodesize
= sizeof(fujitsu
.config
.keymap
[0]);
216 idev
->keycodemax
= ARRAY_SIZE(fujitsu
.config
.keymap
);
218 __set_bit(EV_REP
, idev
->evbit
);
220 for (i
= 0; i
< ARRAY_SIZE(fujitsu
.config
.keymap
); i
++)
221 if (fujitsu
.config
.keymap
[i
])
222 input_set_capability(idev
, EV_KEY
, fujitsu
.config
.keymap
[i
]);
224 input_set_capability(idev
, EV_MSC
, MSC_SCAN
);
226 input_set_capability(idev
, EV_SW
, SW_DOCK
);
227 input_set_capability(idev
, EV_SW
, SW_TABLET_MODE
);
229 error
= input_register_device(idev
);
231 input_free_device(idev
);
239 static void input_fujitsu_remove(void)
241 input_unregister_device(fujitsu
.idev
);
244 static irqreturn_t
fujitsu_interrupt(int irq
, void *dev_id
)
246 unsigned long keymask
, changed
;
247 unsigned int keycode
;
251 if (unlikely(!(fujitsu_status() & 0x01)))
254 fujitsu_send_state();
256 keymask
= fujitsu_read_register(0xde);
257 keymask
|= fujitsu_read_register(0xdf) << 8;
260 changed
= keymask
^ fujitsu
.prev_keymask
;
262 fujitsu
.prev_keymask
= keymask
;
264 for_each_set_bit(i
, &changed
, KEYMAP_LEN
) {
265 keycode
= fujitsu
.config
.keymap
[i
];
266 pressed
= keymask
& changed
& BIT(i
);
269 input_event(fujitsu
.idev
, EV_MSC
, MSC_SCAN
, i
);
271 input_report_key(fujitsu
.idev
, keycode
, pressed
);
272 input_sync(fujitsu
.idev
);
280 static void fujitsu_dmi_common(const struct dmi_system_id
*dmi
)
282 pr_info("%s\n", dmi
->ident
);
283 memcpy(fujitsu
.config
.keymap
, dmi
->driver_data
,
284 sizeof(fujitsu
.config
.keymap
));
287 static int fujitsu_dmi_lifebook(const struct dmi_system_id
*dmi
)
289 fujitsu_dmi_common(dmi
);
290 fujitsu
.config
.quirks
|= INVERT_TABLET_MODE_BIT
;
294 static int fujitsu_dmi_stylistic(const struct dmi_system_id
*dmi
)
296 fujitsu_dmi_common(dmi
);
297 fujitsu
.config
.quirks
|= FORCE_TABLET_MODE_IF_UNDOCK
;
298 fujitsu
.config
.quirks
|= INVERT_DOCK_STATE_BIT
;
302 static const struct dmi_system_id dmi_ids
[] __initconst
= {
304 .callback
= fujitsu_dmi_lifebook
,
305 .ident
= "Fujitsu Siemens P/T Series",
307 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
308 DMI_MATCH(DMI_PRODUCT_NAME
, "LIFEBOOK")
310 .driver_data
= keymap_Lifebook_Tseries
313 .callback
= fujitsu_dmi_lifebook
,
314 .ident
= "Fujitsu Lifebook T Series",
316 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
317 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook T")
319 .driver_data
= keymap_Lifebook_Tseries
322 .callback
= fujitsu_dmi_stylistic
,
323 .ident
= "Fujitsu Siemens Stylistic T Series",
325 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
326 DMI_MATCH(DMI_PRODUCT_NAME
, "Stylistic T")
328 .driver_data
= keymap_Stylistic_Tseries
331 .callback
= fujitsu_dmi_lifebook
,
332 .ident
= "Fujitsu LifeBook U810",
334 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
335 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook U810")
337 .driver_data
= keymap_Lifebook_U810
340 .callback
= fujitsu_dmi_stylistic
,
341 .ident
= "Fujitsu Siemens Stylistic ST5xxx Series",
343 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
344 DMI_MATCH(DMI_PRODUCT_NAME
, "STYLISTIC ST5")
346 .driver_data
= keymap_Stylistic_ST5xxx
349 .callback
= fujitsu_dmi_stylistic
,
350 .ident
= "Fujitsu Siemens Stylistic ST5xxx Series",
352 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
353 DMI_MATCH(DMI_PRODUCT_NAME
, "Stylistic ST5")
355 .driver_data
= keymap_Stylistic_ST5xxx
358 .callback
= fujitsu_dmi_lifebook
,
359 .ident
= "Unknown (using defaults)",
361 DMI_MATCH(DMI_SYS_VENDOR
, ""),
362 DMI_MATCH(DMI_PRODUCT_NAME
, "")
364 .driver_data
= keymap_Lifebook_Tseries
369 static acpi_status
fujitsu_walk_resources(struct acpi_resource
*res
, void *data
)
372 case ACPI_RESOURCE_TYPE_IRQ
:
373 fujitsu
.irq
= res
->data
.irq
.interrupts
[0];
376 case ACPI_RESOURCE_TYPE_IO
:
377 fujitsu
.io_base
= res
->data
.io
.minimum
;
378 fujitsu
.io_length
= res
->data
.io
.address_length
;
381 case ACPI_RESOURCE_TYPE_END_TAG
:
382 if (fujitsu
.irq
&& fujitsu
.io_base
)
392 static int acpi_fujitsu_add(struct acpi_device
*adev
)
400 status
= acpi_walk_resources(adev
->handle
, METHOD_NAME__CRS
,
401 fujitsu_walk_resources
, NULL
);
402 if (ACPI_FAILURE(status
) || !fujitsu
.irq
|| !fujitsu
.io_base
)
405 sprintf(acpi_device_name(adev
), "Fujitsu %s", acpi_device_hid(adev
));
406 sprintf(acpi_device_class(adev
), "%s", ACPI_FUJITSU_CLASS
);
408 snprintf(fujitsu
.phys
, sizeof(fujitsu
.phys
),
409 "%s/input0", acpi_device_hid(adev
));
411 error
= input_fujitsu_setup(&adev
->dev
,
412 acpi_device_name(adev
), fujitsu
.phys
);
416 if (!request_region(fujitsu
.io_base
, fujitsu
.io_length
, MODULENAME
)) {
417 input_fujitsu_remove();
423 error
= request_irq(fujitsu
.irq
, fujitsu_interrupt
,
424 IRQF_SHARED
, MODULENAME
, fujitsu_interrupt
);
426 release_region(fujitsu
.io_base
, fujitsu
.io_length
);
427 input_fujitsu_remove();
434 static int acpi_fujitsu_remove(struct acpi_device
*adev
)
436 free_irq(fujitsu
.irq
, fujitsu_interrupt
);
437 release_region(fujitsu
.io_base
, fujitsu
.io_length
);
438 input_fujitsu_remove();
442 #ifdef CONFIG_PM_SLEEP
443 static int acpi_fujitsu_resume(struct device
*dev
)
450 static SIMPLE_DEV_PM_OPS(acpi_fujitsu_pm
, NULL
, acpi_fujitsu_resume
);
452 static struct acpi_driver acpi_fujitsu_driver
= {
457 .add
= acpi_fujitsu_add
,
458 .remove
= acpi_fujitsu_remove
,
460 .drv
.pm
= &acpi_fujitsu_pm
,
463 static int __init
fujitsu_module_init(void)
467 dmi_check_system(dmi_ids
);
469 error
= acpi_bus_register_driver(&acpi_fujitsu_driver
);
476 static void __exit
fujitsu_module_exit(void)
478 acpi_bus_unregister_driver(&acpi_fujitsu_driver
);
481 module_init(fujitsu_module_init
);
482 module_exit(fujitsu_module_exit
);
484 MODULE_AUTHOR("Robert Gerlach <khnz@gmx.de>");
485 MODULE_DESCRIPTION("Fujitsu tablet pc extras driver");
486 MODULE_LICENSE("GPL");
487 MODULE_VERSION("2.5");
489 MODULE_DEVICE_TABLE(acpi
, fujitsu_ids
);