From 44ca397bcfda83a2b1c3e778c547c05678d7ec69 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Mon, 21 Sep 2009 22:17:57 -0700 Subject: [PATCH] Input: max7359 - use threaded IRQs Convert max7359 driver to use IRQ threading instead of using workqueue. Tested-by: Joonyoung Shim Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/max7359_keypad.c | 48 +++++++++------------------------ 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/drivers/input/keyboard/max7359_keypad.c b/drivers/input/keyboard/max7359_keypad.c index 8b3ee14..3b5b948 100644 --- a/drivers/input/keyboard/max7359_keypad.c +++ b/drivers/input/keyboard/max7359_keypad.c @@ -58,12 +58,8 @@ struct max7359_keypad { /* matrix key code map */ unsigned short keycodes[MAX7359_MAX_KEY_NUM]; - struct work_struct work; - struct input_dev *input_dev; struct i2c_client *client; - - u32 irq; }; static int max7359_write_reg(struct i2c_client *client, u8 reg, u8 val) @@ -106,10 +102,10 @@ static void max7359_build_keycode(struct max7359_keypad *keypad, __clear_bit(KEY_RESERVED, input_dev->keybit); } -static void max7359_worker(struct work_struct *work) +/* runs in an IRQ thread -- can (and will!) sleep */ +static irqreturn_t max7359_interrupt(int irq, void *dev_id) { - struct max7359_keypad *keypad = - container_of(work, struct max7359_keypad, work); + struct max7359_keypad *keypad = dev_id; struct input_dev *input_dev = keypad->input_dev; int val, row, col, release, code; @@ -120,25 +116,13 @@ static void max7359_worker(struct work_struct *work) code = MATRIX_SCAN_CODE(row, col, MAX7359_ROW_SHIFT); + dev_dbg(&keypad->client->dev, + "key[%d:%d] %s\n", row, col, release ? "release" : "press"); + input_event(input_dev, EV_MSC, MSC_SCAN, code); input_report_key(input_dev, keypad->keycodes[code], !release); input_sync(input_dev); - enable_irq(keypad->irq); - - dev_dbg(&keypad->client->dev, "key[%d:%d] %s\n", row, col, - (release ? "release" : "press")); -} - -static irqreturn_t max7359_interrupt(int irq, void *dev_id) -{ - struct max7359_keypad *keypad = dev_id; - - if (!work_pending(&keypad->work)) { - disable_irq_nosync(keypad->irq); - schedule_work(&keypad->work); - } - return IRQ_HANDLED; } @@ -226,8 +210,6 @@ static int __devinit max7359_probe(struct i2c_client *client, keypad->client = client; keypad->input_dev = input_dev; - keypad->irq = client->irq; - INIT_WORK(&keypad->work, max7359_worker); input_dev->name = client->name; input_dev->id.bustype = BUS_I2C; @@ -245,8 +227,9 @@ static int __devinit max7359_probe(struct i2c_client *client, max7359_build_keycode(keypad, keymap_data); - error = request_irq(keypad->irq, max7359_interrupt, - IRQF_TRIGGER_LOW, client->name, keypad); + error = request_threaded_irq(client->irq, NULL, max7359_interrupt, + IRQF_TRIGGER_LOW | IRQF_ONESHOT, + client->name, keypad); if (error) { dev_err(&client->dev, "failed to register interrupt\n"); goto failed_free_mem; @@ -268,7 +251,7 @@ static int __devinit max7359_probe(struct i2c_client *client, return 0; failed_free_irq: - free_irq(keypad->irq, keypad); + free_irq(client->irq, keypad); failed_free_mem: input_free_device(input_dev); kfree(keypad); @@ -279,9 +262,8 @@ static int __devexit max7359_remove(struct i2c_client *client) { struct max7359_keypad *keypad = i2c_get_clientdata(client); - cancel_work_sync(&keypad->work); + free_irq(client->irq, keypad); input_unregister_device(keypad->input_dev); - free_irq(keypad->irq, keypad); i2c_set_clientdata(client, NULL); kfree(keypad); @@ -291,22 +273,18 @@ static int __devexit max7359_remove(struct i2c_client *client) #ifdef CONFIG_PM static int max7359_suspend(struct i2c_client *client, pm_message_t mesg) { - struct max7359_keypad *keypad = i2c_get_clientdata(client); - max7359_fall_deepsleep(client); if (device_may_wakeup(&client->dev)) - enable_irq_wake(keypad->irq); + enable_irq_wake(client->irq); return 0; } static int max7359_resume(struct i2c_client *client) { - struct max7359_keypad *keypad = i2c_get_clientdata(client); - if (device_may_wakeup(&client->dev)) - disable_irq_wake(keypad->irq); + disable_irq_wake(client->irq); /* Restore the default setting */ max7359_take_catnap(client); -- 2.7.4