2 * ACPI driver for Topstar notebooks (hotkeys support only)
4 * Copyright (c) 2009 Herton Ronaldo Krzesinski <herton@mandriva.com.br>
6 * Implementation inspired by existing x86 platform drivers, in special
7 * asus/eepc/fujitsu-laptop, thanks to their authors
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <linux/acpi.h>
21 #include <linux/input.h>
22 #include <linux/input/sparse-keymap.h>
24 #define ACPI_TOPSTAR_CLASS "topstar"
27 struct input_dev
*inputdev
;
30 static const struct key_entry topstar_keymap
[] = {
31 { KE_KEY
, 0x80, { KEY_BRIGHTNESSUP
} },
32 { KE_KEY
, 0x81, { KEY_BRIGHTNESSDOWN
} },
33 { KE_KEY
, 0x83, { KEY_VOLUMEUP
} },
34 { KE_KEY
, 0x84, { KEY_VOLUMEDOWN
} },
35 { KE_KEY
, 0x85, { KEY_MUTE
} },
36 { KE_KEY
, 0x86, { KEY_SWITCHVIDEOMODE
} },
37 { KE_KEY
, 0x87, { KEY_F13
} }, /* touchpad enable/disable key */
38 { KE_KEY
, 0x88, { KEY_WLAN
} },
39 { KE_KEY
, 0x8a, { KEY_WWW
} },
40 { KE_KEY
, 0x8b, { KEY_MAIL
} },
41 { KE_KEY
, 0x8c, { KEY_MEDIA
} },
43 /* Known non hotkey events don't handled or that we don't care yet */
49 * 'G key' generate two event codes, convert to only
50 * one event/key code for now, consider replacing by
51 * a switch (3G switch - SW_3G?)
53 { KE_KEY
, 0x96, { KEY_F14
} },
54 { KE_KEY
, 0x97, { KEY_F14
} },
59 static void acpi_topstar_notify(struct acpi_device
*device
, u32 event
)
61 static bool dup_evnt
[2];
63 struct topstar_hkey
*hkey
= acpi_driver_data(device
);
65 /* 0x83 and 0x84 key events comes duplicated... */
66 if (event
== 0x83 || event
== 0x84) {
67 dup
= &dup_evnt
[event
- 0x83];
75 if (!sparse_keymap_report_event(hkey
->inputdev
, event
, 1, true))
76 pr_info("unknown event = 0x%02x\n", event
);
79 static int acpi_topstar_fncx_switch(struct acpi_device
*device
, bool state
)
82 union acpi_object fncx_params
[1] = {
83 { .type
= ACPI_TYPE_INTEGER
}
85 struct acpi_object_list fncx_arg_list
= { 1, &fncx_params
[0] };
87 fncx_params
[0].integer
.value
= state
? 0x86 : 0x87;
88 status
= acpi_evaluate_object(device
->handle
, "FNCX", &fncx_arg_list
, NULL
);
89 if (ACPI_FAILURE(status
)) {
90 pr_err("Unable to switch FNCX notifications\n");
97 static int acpi_topstar_init_hkey(struct topstar_hkey
*hkey
)
99 struct input_dev
*input
;
102 input
= input_allocate_device();
104 pr_err("Unable to allocate input device\n");
108 input
->name
= "Topstar Laptop extra buttons";
109 input
->phys
= "topstar/input0";
110 input
->id
.bustype
= BUS_HOST
;
112 error
= sparse_keymap_setup(input
, topstar_keymap
, NULL
);
114 pr_err("Unable to setup input device keymap\n");
118 error
= input_register_device(input
);
120 pr_err("Unable to register input device\n");
121 goto err_free_keymap
;
124 hkey
->inputdev
= input
;
128 sparse_keymap_free(input
);
130 input_free_device(input
);
134 static int acpi_topstar_add(struct acpi_device
*device
)
136 struct topstar_hkey
*tps_hkey
;
138 tps_hkey
= kzalloc(sizeof(struct topstar_hkey
), GFP_KERNEL
);
142 strcpy(acpi_device_name(device
), "Topstar TPSACPI");
143 strcpy(acpi_device_class(device
), ACPI_TOPSTAR_CLASS
);
145 if (acpi_topstar_fncx_switch(device
, true))
148 if (acpi_topstar_init_hkey(tps_hkey
))
151 device
->driver_data
= tps_hkey
;
159 static int acpi_topstar_remove(struct acpi_device
*device
, int type
)
161 struct topstar_hkey
*tps_hkey
= acpi_driver_data(device
);
163 acpi_topstar_fncx_switch(device
, false);
165 sparse_keymap_free(tps_hkey
->inputdev
);
166 input_unregister_device(tps_hkey
->inputdev
);
172 static const struct acpi_device_id topstar_device_ids
[] = {
176 MODULE_DEVICE_TABLE(acpi
, topstar_device_ids
);
178 static struct acpi_driver acpi_topstar_driver
= {
179 .name
= "Topstar laptop ACPI driver",
180 .class = ACPI_TOPSTAR_CLASS
,
181 .ids
= topstar_device_ids
,
183 .add
= acpi_topstar_add
,
184 .remove
= acpi_topstar_remove
,
185 .notify
= acpi_topstar_notify
,
189 static int __init
topstar_laptop_init(void)
193 ret
= acpi_bus_register_driver(&acpi_topstar_driver
);
197 pr_info("ACPI extras driver loaded\n");
202 static void __exit
topstar_laptop_exit(void)
204 acpi_bus_unregister_driver(&acpi_topstar_driver
);
207 module_init(topstar_laptop_init
);
208 module_exit(topstar_laptop_exit
);
210 MODULE_AUTHOR("Herton Ronaldo Krzesinski");
211 MODULE_DESCRIPTION("Topstar Laptop ACPI Extras driver");
212 MODULE_LICENSE("GPL");