Commit 3d29cdff authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: cobalt_btns - convert to use polldev library

Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
Acked-by: default avatarYoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
parent 0dcd8073
...@@ -43,6 +43,7 @@ config INPUT_M68K_BEEP ...@@ -43,6 +43,7 @@ config INPUT_M68K_BEEP
config INPUT_COBALT_BTNS config INPUT_COBALT_BTNS
tristate "Cobalt button interface" tristate "Cobalt button interface"
depends on MIPS_COBALT depends on MIPS_COBALT
select INPUT_POLLDEV
help help
Say Y here if you want to support MIPS Cobalt button interface. Say Y here if you want to support MIPS Cobalt button interface.
......
...@@ -18,19 +18,17 @@ ...@@ -18,19 +18,17 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include <linux/init.h> #include <linux/init.h>
#include <linux/input.h> #include <linux/input-polldev.h>
#include <linux/ioport.h> #include <linux/ioport.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/jiffies.h>
#include <linux/timer.h>
#define BUTTONS_POLL_INTERVAL 30 /* msec */ #define BUTTONS_POLL_INTERVAL 30 /* msec */
#define BUTTONS_COUNT_THRESHOLD 3 #define BUTTONS_COUNT_THRESHOLD 3
#define BUTTONS_STATUS_MASK 0xfe000000 #define BUTTONS_STATUS_MASK 0xfe000000
struct buttons_dev { struct buttons_dev {
struct input_dev *input; struct input_polled_dev *poll_dev;
void __iomem *reg; void __iomem *reg;
}; };
...@@ -50,16 +48,14 @@ static struct buttons_map buttons_map[] = { ...@@ -50,16 +48,14 @@ static struct buttons_map buttons_map[] = {
{ 0x80000000, KEY_SELECT, }, { 0x80000000, KEY_SELECT, },
}; };
static struct timer_list buttons_timer; static void handle_buttons(struct input_polled_dev *dev)
static void handle_buttons(unsigned long data)
{ {
struct buttons_map *button = buttons_map; struct buttons_map *button = buttons_map;
struct buttons_dev *bdev; struct buttons_dev *bdev = dev->private;
struct input_dev *input = dev->input;
uint32_t status; uint32_t status;
int i; int i;
bdev = (struct buttons_dev *)data;
status = readl(bdev->reg); status = readl(bdev->reg);
status = ~status & BUTTONS_STATUS_MASK; status = ~status & BUTTONS_STATUS_MASK;
...@@ -68,55 +64,45 @@ static void handle_buttons(unsigned long data) ...@@ -68,55 +64,45 @@ static void handle_buttons(unsigned long data)
button->count++; button->count++;
} else { } else {
if (button->count >= BUTTONS_COUNT_THRESHOLD) { if (button->count >= BUTTONS_COUNT_THRESHOLD) {
input_report_key(bdev->input, button->keycode, 0); input_report_key(input, button->keycode, 0);
input_sync(bdev->input); input_sync(input);
} }
button->count = 0; button->count = 0;
} }
if (button->count == BUTTONS_COUNT_THRESHOLD) { if (button->count == BUTTONS_COUNT_THRESHOLD) {
input_report_key(bdev->input, button->keycode, 1); input_report_key(input, button->keycode, 1);
input_sync(bdev->input); input_sync(input);
} }
button++; button++;
} }
mod_timer(&buttons_timer, jiffies + msecs_to_jiffies(BUTTONS_POLL_INTERVAL));
}
static int cobalt_buttons_open(struct input_dev *dev)
{
mod_timer(&buttons_timer, jiffies + msecs_to_jiffies(BUTTONS_POLL_INTERVAL));
return 0;
}
static void cobalt_buttons_close(struct input_dev *dev)
{
del_timer_sync(&buttons_timer);
} }
static int __devinit cobalt_buttons_probe(struct platform_device *pdev) static int __devinit cobalt_buttons_probe(struct platform_device *pdev)
{ {
struct buttons_dev *bdev; struct buttons_dev *bdev;
struct input_polled_dev *poll_dev;
struct input_dev *input; struct input_dev *input;
struct resource *res; struct resource *res;
int error, i; int error, i;
bdev = kzalloc(sizeof(struct buttons_dev), GFP_KERNEL); bdev = kzalloc(sizeof(struct buttons_dev), GFP_KERNEL);
input = input_allocate_device(); poll_dev = input_allocate_polled_device();
if (!bdev || !input) { if (!bdev || !poll_dev) {
error = -ENOMEM; error = -ENOMEM;
goto err_free_mem; goto err_free_mem;
} }
poll_dev->private = bdev;
poll_dev->poll = handle_buttons;
poll_dev->poll_interval = BUTTONS_POLL_INTERVAL;
input = poll_dev->input;
input->name = "Cobalt buttons"; input->name = "Cobalt buttons";
input->phys = "cobalt/input0"; input->phys = "cobalt/input0";
input->id.bustype = BUS_HOST; input->id.bustype = BUS_HOST;
input->cdev.dev = &pdev->dev; input->cdev.dev = &pdev->dev;
input->open = cobalt_buttons_open;
input->close = cobalt_buttons_close;
input->evbit[0] = BIT(EV_KEY); input->evbit[0] = BIT(EV_KEY);
for (i = 0; i < ARRAY_SIZE(buttons_map); i++) { for (i = 0; i < ARRAY_SIZE(buttons_map); i++) {
...@@ -130,13 +116,11 @@ static int __devinit cobalt_buttons_probe(struct platform_device *pdev) ...@@ -130,13 +116,11 @@ static int __devinit cobalt_buttons_probe(struct platform_device *pdev)
goto err_free_mem; goto err_free_mem;
} }
bdev->input = input; bdev->poll_dev = poll_dev;
bdev->reg = ioremap(res->start, res->end - res->start + 1); bdev->reg = ioremap(res->start, res->end - res->start + 1);
dev_set_drvdata(&pdev->dev, bdev); dev_set_drvdata(&pdev->dev, bdev);
setup_timer(&buttons_timer, handle_buttons, (unsigned long)bdev); error = input_register_polled_device(poll_dev);
error = input_register_device(input);
if (error) if (error)
goto err_iounmap; goto err_iounmap;
...@@ -145,7 +129,7 @@ static int __devinit cobalt_buttons_probe(struct platform_device *pdev) ...@@ -145,7 +129,7 @@ static int __devinit cobalt_buttons_probe(struct platform_device *pdev)
err_iounmap: err_iounmap:
iounmap(bdev->reg); iounmap(bdev->reg);
err_free_mem: err_free_mem:
input_free_device(input); input_free_polled_device(poll_dev);
kfree(bdev); kfree(bdev);
dev_set_drvdata(&pdev->dev, NULL); dev_set_drvdata(&pdev->dev, NULL);
return error; return error;
...@@ -156,7 +140,8 @@ static int __devexit cobalt_buttons_remove(struct platform_device *pdev) ...@@ -156,7 +140,8 @@ static int __devexit cobalt_buttons_remove(struct platform_device *pdev)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct buttons_dev *bdev = dev_get_drvdata(dev); struct buttons_dev *bdev = dev_get_drvdata(dev);
input_unregister_device(bdev->input); input_unregister_polled_device(bdev->poll_dev);
input_free_polled_device(bdev->poll_dev);
iounmap(bdev->reg); iounmap(bdev->reg);
kfree(bdev); kfree(bdev);
dev_set_drvdata(dev, NULL); dev_set_drvdata(dev, NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment