Input: wistron - convert to use input-polldev

Switch to using input-polldev skeleton instead of implementing
polling loop by itself.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
This commit is contained in:
Dmitry Torokhov 2007-05-22 23:48:39 -04:00
parent 389679d8fa
commit c2554c9142
2 changed files with 102 additions and 99 deletions

View File

@ -65,6 +65,7 @@ config INPUT_COBALT_BTNS
config INPUT_WISTRON_BTNS config INPUT_WISTRON_BTNS
tristate "x86 Wistron laptop button interface" tristate "x86 Wistron laptop button interface"
depends on X86 && !X86_64 depends on X86 && !X86_64
select INPUT_POLLDEV
select NEW_LEDS select NEW_LEDS
select LEDS_CLASS select LEDS_CLASS
help help

View File

@ -20,7 +20,7 @@
#include <linux/io.h> #include <linux/io.h>
#include <linux/dmi.h> #include <linux/dmi.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/input.h> #include <linux/input-polldev.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/kernel.h> #include <linux/kernel.h>
@ -28,23 +28,13 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/preempt.h> #include <linux/preempt.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/timer.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/leds.h> #include <linux/leds.h>
/* /* How often we poll keys - msecs */
* Number of attempts to read data from queue per poll; #define POLL_INTERVAL_DEFAULT 500 /* when idle */
* the queue can hold up to 31 entries #define POLL_INTERVAL_BURST 100 /* when a key was recently pressed */
*/
#define MAX_POLL_ITERATIONS 64
#define POLL_FREQUENCY 2 /* Number of polls per second when idle */
#define POLL_FREQUENCY_BURST 10 /* Polls per second when a key was recently pressed */
#if POLL_FREQUENCY_BURST > HZ
#error "POLL_FREQUENCY too high"
#endif
/* BIOS subsystem IDs */ /* BIOS subsystem IDs */
#define WIFI 0x35 #define WIFI 0x35
@ -973,66 +963,23 @@ static int __init select_keymap(void)
/* Input layer interface */ /* Input layer interface */
static struct input_dev *input_dev; static struct input_polled_dev *wistron_idev;
static unsigned long jiffies_last_press;
static int wifi_enabled;
static int bluetooth_enabled;
static int __devinit setup_input_dev(void) static void report_key(struct input_dev *dev, unsigned int keycode)
{ {
const struct key_entry *key; input_report_key(dev, keycode, 1);
int error; input_sync(dev);
input_report_key(dev, keycode, 0);
input_dev = input_allocate_device(); input_sync(dev);
if (!input_dev)
return -ENOMEM;
input_dev->name = "Wistron laptop buttons";
input_dev->phys = "wistron/input0";
input_dev->id.bustype = BUS_HOST;
input_dev->cdev.dev = &wistron_device->dev;
for (key = keymap; key->type != KE_END; key++) {
switch (key->type) {
case KE_KEY:
set_bit(EV_KEY, input_dev->evbit);
set_bit(key->keycode, input_dev->keybit);
break;
case KE_SW:
set_bit(EV_SW, input_dev->evbit);
set_bit(key->sw.code, input_dev->swbit);
break;
default:
;
}
} }
/* reads information flags on KE_END */ static void report_switch(struct input_dev *dev, unsigned int code, int value)
if (key->code & FE_UNTESTED)
printk(KERN_WARNING "Untested laptop multimedia keys, "
"please report success or failure to eric.piel"
"@tremplin-utc.net\n");
error = input_register_device(input_dev);
if (error) {
input_free_device(input_dev);
return error;
}
return 0;
}
static void report_key(unsigned keycode)
{ {
input_report_key(input_dev, keycode, 1); input_report_switch(dev, code, value);
input_sync(input_dev); input_sync(dev);
input_report_key(input_dev, keycode, 0);
input_sync(input_dev);
}
static void report_switch(unsigned code, int value)
{
input_report_switch(input_dev, code, value);
input_sync(input_dev);
} }
@ -1112,15 +1059,6 @@ static inline void wistron_led_resume(void)
led_classdev_resume(&wistron_wifi_led); led_classdev_resume(&wistron_wifi_led);
} }
/* Driver core */
static int wifi_enabled;
static int bluetooth_enabled;
static void poll_bios(unsigned long);
static struct timer_list poll_timer = TIMER_INITIALIZER(poll_bios, 0, 0);
static void handle_key(u8 code) static void handle_key(u8 code)
{ {
const struct key_entry *key; const struct key_entry *key;
@ -1129,11 +1067,12 @@ static void handle_key(u8 code)
if (code == key->code) { if (code == key->code) {
switch (key->type) { switch (key->type) {
case KE_KEY: case KE_KEY:
report_key(key->keycode); report_key(wistron_idev->input, key->keycode);
break; break;
case KE_SW: case KE_SW:
report_switch(key->sw.code, key->sw.value); report_switch(wistron_idev->input,
key->sw.code, key->sw.value);
break; break;
case KE_WIFI: case KE_WIFI:
@ -1152,19 +1091,19 @@ static void handle_key(u8 code)
case KE_END: case KE_END:
break; break;
default: default:
BUG(); BUG();
} }
jiffies_last_press = jiffies;
return; return;
} }
} }
printk(KERN_NOTICE "wistron_btns: Unknown key code %02X\n", code); printk(KERN_NOTICE "wistron_btns: Unknown key code %02X\n", code);
} }
static void poll_bios(unsigned long discard) static void poll_bios(bool discard)
{ {
static unsigned long jiffies_last_press;
unsigned long jiffies_now = jiffies;
u8 qlen; u8 qlen;
u16 val; u16 val;
@ -1173,24 +1112,85 @@ static void poll_bios(unsigned long discard)
if (qlen == 0) if (qlen == 0)
break; break;
val = bios_pop_queue(); val = bios_pop_queue();
if (val != 0 && !discard) { if (val != 0 && !discard)
handle_key((u8)val); handle_key((u8)val);
jiffies_last_press = jiffies_now;
} }
} }
/* Increase precision if user is currently pressing keys (< 2s ago) */ static void wistron_flush(struct input_polled_dev *dev)
if (time_after(jiffies_last_press, jiffies_now - (HZ * 2))) {
mod_timer(&poll_timer, jiffies_now + HZ / POLL_FREQUENCY_BURST); /* Flush stale event queue */
else poll_bios(true);
mod_timer(&poll_timer, jiffies_now + HZ / POLL_FREQUENCY);
} }
static void wistron_poll(struct input_polled_dev *dev)
{
poll_bios(false);
/* Increase poll frequency if user is currently pressing keys (< 2s ago) */
if (time_before(jiffies, jiffies_last_press + 2 * HZ))
dev->poll_interval = POLL_INTERVAL_BURST;
else
dev->poll_interval = POLL_INTERVAL_DEFAULT;
}
static int __devinit setup_input_dev(void)
{
const struct key_entry *key;
struct input_dev *input_dev;
int error;
wistron_idev = input_allocate_polled_device();
if (!wistron_idev)
return -ENOMEM;
wistron_idev->flush = wistron_flush;
wistron_idev->poll = wistron_poll;
wistron_idev->poll_interval = POLL_INTERVAL_DEFAULT;
input_dev = wistron_idev->input;
input_dev->name = "Wistron laptop buttons";
input_dev->phys = "wistron/input0";
input_dev->id.bustype = BUS_HOST;
input_dev->cdev.dev = &wistron_device->dev;
for (key = keymap; key->type != KE_END; key++) {
switch (key->type) {
case KE_KEY:
set_bit(EV_KEY, input_dev->evbit);
set_bit(key->keycode, input_dev->keybit);
break;
case KE_SW:
set_bit(EV_SW, input_dev->evbit);
set_bit(key->sw.code, input_dev->swbit);
break;
default:
break;
}
}
/* reads information flags on KE_END */
if (key->code & FE_UNTESTED)
printk(KERN_WARNING "Untested laptop multimedia keys, "
"please report success or failure to eric.piel"
"@tremplin-utc.net\n");
error = input_register_polled_device(wistron_idev);
if (error) {
input_free_polled_device(wistron_idev);
return error;
}
return 0;
}
/* Driver core */
static int __devinit wistron_probe(struct platform_device *dev) static int __devinit wistron_probe(struct platform_device *dev)
{ {
int err = setup_input_dev(); int err;
if (err)
return err;
bios_attach(); bios_attach();
cmos_address = bios_get_cmos_address(); cmos_address = bios_get_cmos_address();
@ -1218,16 +1218,20 @@ static int __devinit wistron_probe(struct platform_device *dev)
} }
wistron_led_init(&dev->dev); wistron_led_init(&dev->dev);
poll_bios(1); /* Flush stale event queue and arm timer */ err = setup_input_dev();
if (err) {
bios_detach();
return err;
}
return 0; return 0;
} }
static int __devexit wistron_remove(struct platform_device *dev) static int __devexit wistron_remove(struct platform_device *dev)
{ {
del_timer_sync(&poll_timer);
wistron_led_remove(); wistron_led_remove();
input_unregister_device(input_dev); input_unregister_polled_device(wistron_idev);
input_free_polled_device(wistron_idev);
bios_detach(); bios_detach();
return 0; return 0;
@ -1236,8 +1240,6 @@ static int __devexit wistron_remove(struct platform_device *dev)
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int wistron_suspend(struct platform_device *dev, pm_message_t state) static int wistron_suspend(struct platform_device *dev, pm_message_t state)
{ {
del_timer_sync(&poll_timer);
if (have_wifi) if (have_wifi)
bios_set_state(WIFI, 0); bios_set_state(WIFI, 0);
@ -1257,7 +1259,7 @@ static int wistron_resume(struct platform_device *dev)
bios_set_state(BLUETOOTH, bluetooth_enabled); bios_set_state(BLUETOOTH, bluetooth_enabled);
wistron_led_resume(); wistron_led_resume();
poll_bios(1); poll_bios(true);
return 0; return 0;
} }