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 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/bitops.h>
24 #include <linux/ioport.h>
25 #include <linux/acpi.h>
26 #include <linux/device.h>
27 #include <linux/interrupt.h>
28 #include <linux/input.h>
29 #include <linux/delay.h>
30 #include <linux/dmi.h>
32 #define MODULENAME "fujitsu-tablet"
34 #define ACPI_FUJITSU_CLASS "fujitsu"
36 #define INVERT_TABLET_MODE_BIT 0x01
37 #define FORCE_TABLET_MODE_IF_UNDOCK 0x02
41 static const struct acpi_device_id fujitsu_ids
[] = {
47 struct fujitsu_config
{
48 unsigned short keymap
[KEYMAP_LEN
];
52 static unsigned short keymap_Lifebook_Tseries
[KEYMAP_LEN
] __initconst
= {
71 static unsigned short keymap_Lifebook_U810
[KEYMAP_LEN
] __initconst
= {
90 static unsigned short keymap_Stylistic_Tseries
[KEYMAP_LEN
] __initconst
= {
109 static unsigned short keymap_Stylistic_ST5xxx
[KEYMAP_LEN
] __initconst
= {
129 struct input_dev
*idev
;
130 struct fujitsu_config config
;
131 unsigned long prev_keymask
;
140 static u8
fujitsu_ack(void)
142 return inb(fujitsu
.io_base
+ 2);
145 static u8
fujitsu_status(void)
147 return inb(fujitsu
.io_base
+ 6);
150 static u8
fujitsu_read_register(const u8 addr
)
152 outb(addr
, fujitsu
.io_base
);
153 return inb(fujitsu
.io_base
+ 4);
156 static void fujitsu_send_state(void)
159 int dock
, tablet_mode
;
161 state
= fujitsu_read_register(0xdd);
165 if ((fujitsu
.config
.quirks
& FORCE_TABLET_MODE_IF_UNDOCK
) && (!dock
)) {
168 tablet_mode
= state
& 0x01;
169 if (fujitsu
.config
.quirks
& INVERT_TABLET_MODE_BIT
)
170 tablet_mode
= !tablet_mode
;
173 input_report_switch(fujitsu
.idev
, SW_DOCK
, dock
);
174 input_report_switch(fujitsu
.idev
, SW_TABLET_MODE
, tablet_mode
);
175 input_sync(fujitsu
.idev
);
178 static void fujitsu_reset(void)
184 while ((fujitsu_status() & 0x02) && (--timeout
))
187 fujitsu_send_state();
190 static int __devinit
input_fujitsu_setup(struct device
*parent
,
191 const char *name
, const char *phys
)
193 struct input_dev
*idev
;
197 idev
= input_allocate_device();
201 idev
->dev
.parent
= parent
;
204 idev
->id
.bustype
= BUS_HOST
;
205 idev
->id
.vendor
= 0x1734; /* Fujitsu Siemens Computer GmbH */
206 idev
->id
.product
= 0x0001;
207 idev
->id
.version
= 0x0101;
209 idev
->keycode
= fujitsu
.config
.keymap
;
210 idev
->keycodesize
= sizeof(fujitsu
.config
.keymap
[0]);
211 idev
->keycodemax
= ARRAY_SIZE(fujitsu
.config
.keymap
);
213 __set_bit(EV_REP
, idev
->evbit
);
215 for (i
= 0; i
< ARRAY_SIZE(fujitsu
.config
.keymap
); i
++)
216 if (fujitsu
.config
.keymap
[i
])
217 input_set_capability(idev
, EV_KEY
, fujitsu
.config
.keymap
[i
]);
219 input_set_capability(idev
, EV_MSC
, MSC_SCAN
);
221 input_set_capability(idev
, EV_SW
, SW_DOCK
);
222 input_set_capability(idev
, EV_SW
, SW_TABLET_MODE
);
224 input_set_capability(idev
, EV_SW
, SW_DOCK
);
225 input_set_capability(idev
, EV_SW
, SW_TABLET_MODE
);
227 error
= input_register_device(idev
);
229 input_free_device(idev
);
237 static void input_fujitsu_remove(void)
239 input_unregister_device(fujitsu
.idev
);
242 static irqreturn_t
fujitsu_interrupt(int irq
, void *dev_id
)
244 unsigned long keymask
, changed
;
245 unsigned int keycode
;
249 if (unlikely(!(fujitsu_status() & 0x01)))
252 fujitsu_send_state();
254 keymask
= fujitsu_read_register(0xde);
255 keymask
|= fujitsu_read_register(0xdf) << 8;
258 changed
= keymask
^ fujitsu
.prev_keymask
;
260 fujitsu
.prev_keymask
= keymask
;
262 for_each_set_bit(i
, &changed
, KEYMAP_LEN
) {
263 keycode
= fujitsu
.config
.keymap
[i
];
264 pressed
= keymask
& changed
& BIT(i
);
267 input_event(fujitsu
.idev
, EV_MSC
, MSC_SCAN
, i
);
269 input_report_key(fujitsu
.idev
, keycode
, pressed
);
270 input_sync(fujitsu
.idev
);
278 static int __devinit
fujitsu_dmi_default(const struct dmi_system_id
*dmi
)
280 printk(KERN_INFO MODULENAME
": %s\n", dmi
->ident
);
281 memcpy(fujitsu
.config
.keymap
, dmi
->driver_data
,
282 sizeof(fujitsu
.config
.keymap
));
286 static int __devinit
fujitsu_dmi_stylistic(const struct dmi_system_id
*dmi
)
288 fujitsu_dmi_default(dmi
);
289 fujitsu
.config
.quirks
|= FORCE_TABLET_MODE_IF_UNDOCK
;
290 fujitsu
.config
.quirks
|= INVERT_TABLET_MODE_BIT
;
294 static struct dmi_system_id dmi_ids
[] __initconst
= {
296 .callback
= fujitsu_dmi_default
,
297 .ident
= "Fujitsu Siemens P/T Series",
299 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
300 DMI_MATCH(DMI_PRODUCT_NAME
, "LIFEBOOK")
302 .driver_data
= keymap_Lifebook_Tseries
305 .callback
= fujitsu_dmi_default
,
306 .ident
= "Fujitsu Lifebook T Series",
308 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
309 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook T")
311 .driver_data
= keymap_Lifebook_Tseries
314 .callback
= fujitsu_dmi_stylistic
,
315 .ident
= "Fujitsu Siemens Stylistic T Series",
317 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
318 DMI_MATCH(DMI_PRODUCT_NAME
, "Stylistic T")
320 .driver_data
= keymap_Stylistic_Tseries
323 .callback
= fujitsu_dmi_default
,
324 .ident
= "Fujitsu LifeBook U810",
326 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
327 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook U810")
329 .driver_data
= keymap_Lifebook_U810
332 .callback
= fujitsu_dmi_stylistic
,
333 .ident
= "Fujitsu Siemens Stylistic ST5xxx Series",
335 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
336 DMI_MATCH(DMI_PRODUCT_NAME
, "STYLISTIC ST5")
338 .driver_data
= keymap_Stylistic_ST5xxx
341 .callback
= fujitsu_dmi_stylistic
,
342 .ident
= "Fujitsu Siemens Stylistic ST5xxx Series",
344 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
345 DMI_MATCH(DMI_PRODUCT_NAME
, "Stylistic ST5")
347 .driver_data
= keymap_Stylistic_ST5xxx
350 .callback
= fujitsu_dmi_default
,
351 .ident
= "Unknown (using defaults)",
353 DMI_MATCH(DMI_SYS_VENDOR
, ""),
354 DMI_MATCH(DMI_PRODUCT_NAME
, "")
356 .driver_data
= keymap_Lifebook_Tseries
361 static acpi_status __devinit
362 fujitsu_walk_resources(struct acpi_resource
*res
, void *data
)
365 case ACPI_RESOURCE_TYPE_IRQ
:
366 fujitsu
.irq
= res
->data
.irq
.interrupts
[0];
369 case ACPI_RESOURCE_TYPE_IO
:
370 fujitsu
.io_base
= res
->data
.io
.minimum
;
371 fujitsu
.io_length
= res
->data
.io
.address_length
;
374 case ACPI_RESOURCE_TYPE_END_TAG
:
375 if (fujitsu
.irq
&& fujitsu
.io_base
)
385 static int __devinit
acpi_fujitsu_add(struct acpi_device
*adev
)
393 status
= acpi_walk_resources(adev
->handle
, METHOD_NAME__CRS
,
394 fujitsu_walk_resources
, NULL
);
395 if (ACPI_FAILURE(status
) || !fujitsu
.irq
|| !fujitsu
.io_base
)
398 sprintf(acpi_device_name(adev
), "Fujitsu %s", acpi_device_hid(adev
));
399 sprintf(acpi_device_class(adev
), "%s", ACPI_FUJITSU_CLASS
);
401 snprintf(fujitsu
.phys
, sizeof(fujitsu
.phys
),
402 "%s/input0", acpi_device_hid(adev
));
404 error
= input_fujitsu_setup(&adev
->dev
,
405 acpi_device_name(adev
), fujitsu
.phys
);
409 if (!request_region(fujitsu
.io_base
, fujitsu
.io_length
, MODULENAME
)) {
410 input_fujitsu_remove();
416 error
= request_irq(fujitsu
.irq
, fujitsu_interrupt
,
417 IRQF_SHARED
, MODULENAME
, fujitsu_interrupt
);
419 release_region(fujitsu
.io_base
, fujitsu
.io_length
);
420 input_fujitsu_remove();
427 static int __devexit
acpi_fujitsu_remove(struct acpi_device
*adev
, int type
)
429 free_irq(fujitsu
.irq
, fujitsu_interrupt
);
430 release_region(fujitsu
.io_base
, fujitsu
.io_length
);
431 input_fujitsu_remove();
435 static int acpi_fujitsu_resume(struct acpi_device
*adev
)
441 static struct acpi_driver acpi_fujitsu_driver
= {
446 .add
= acpi_fujitsu_add
,
447 .remove
= acpi_fujitsu_remove
,
448 .resume
= acpi_fujitsu_resume
,
452 static int __init
fujitsu_module_init(void)
456 dmi_check_system(dmi_ids
);
458 error
= acpi_bus_register_driver(&acpi_fujitsu_driver
);
465 static void __exit
fujitsu_module_exit(void)
467 acpi_bus_unregister_driver(&acpi_fujitsu_driver
);
470 module_init(fujitsu_module_init
);
471 module_exit(fujitsu_module_exit
);
473 MODULE_AUTHOR("Robert Gerlach <khnz@gmx.de>");
474 MODULE_DESCRIPTION("Fujitsu tablet pc extras driver");
475 MODULE_LICENSE("GPL");
476 MODULE_VERSION("2.4");
478 MODULE_DEVICE_TABLE(acpi
, fujitsu_ids
);