aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/input/misc/Kconfig1
-rw-r--r--drivers/input/misc/cobalt_btns.c59
2 files changed, 23 insertions, 37 deletions
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 696c9609d714..1d0d3e765db6 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -43,6 +43,7 @@ config INPUT_M68K_BEEP
43config INPUT_COBALT_BTNS 43config INPUT_COBALT_BTNS
44 tristate "Cobalt button interface" 44 tristate "Cobalt button interface"
45 depends on MIPS_COBALT 45 depends on MIPS_COBALT
46 select INPUT_POLLDEV
46 help 47 help
47 Say Y here if you want to support MIPS Cobalt button interface. 48 Say Y here if you want to support MIPS Cobalt button interface.
48 49
diff --git a/drivers/input/misc/cobalt_btns.c b/drivers/input/misc/cobalt_btns.c
index b9b2d7764e73..064b07936019 100644
--- a/drivers/input/misc/cobalt_btns.c
+++ b/drivers/input/misc/cobalt_btns.c
@@ -18,19 +18,17 @@
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 19 */
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/input.h> 21#include <linux/input-polldev.h>
22#include <linux/ioport.h> 22#include <linux/ioport.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/jiffies.h>
26#include <linux/timer.h>
27 25
28#define BUTTONS_POLL_INTERVAL 30 /* msec */ 26#define BUTTONS_POLL_INTERVAL 30 /* msec */
29#define BUTTONS_COUNT_THRESHOLD 3 27#define BUTTONS_COUNT_THRESHOLD 3
30#define BUTTONS_STATUS_MASK 0xfe000000 28#define BUTTONS_STATUS_MASK 0xfe000000
31 29
32struct buttons_dev { 30struct buttons_dev {
33 struct input_dev *input; 31 struct input_polled_dev *poll_dev;
34 void __iomem *reg; 32 void __iomem *reg;
35}; 33};
36 34
@@ -50,16 +48,14 @@ static struct buttons_map buttons_map[] = {
50 { 0x80000000, KEY_SELECT, }, 48 { 0x80000000, KEY_SELECT, },
51}; 49};
52 50
53static struct timer_list buttons_timer; 51static void handle_buttons(struct input_polled_dev *dev)
54
55static void handle_buttons(unsigned long data)
56{ 52{
57 struct buttons_map *button = buttons_map; 53 struct buttons_map *button = buttons_map;
58 struct buttons_dev *bdev; 54 struct buttons_dev *bdev = dev->private;
55 struct input_dev *input = dev->input;
59 uint32_t status; 56 uint32_t status;
60 int i; 57 int i;
61 58
62 bdev = (struct buttons_dev *)data;
63 status = readl(bdev->reg); 59 status = readl(bdev->reg);
64 status = ~status & BUTTONS_STATUS_MASK; 60 status = ~status & BUTTONS_STATUS_MASK;
65 61
@@ -68,55 +64,45 @@ static void handle_buttons(unsigned long data)
68 button->count++; 64 button->count++;
69 } else { 65 } else {
70 if (button->count >= BUTTONS_COUNT_THRESHOLD) { 66 if (button->count >= BUTTONS_COUNT_THRESHOLD) {
71 input_report_key(bdev->input, button->keycode, 0); 67 input_report_key(input, button->keycode, 0);
72 input_sync(bdev->input); 68 input_sync(input);
73 } 69 }
74 button->count = 0; 70 button->count = 0;
75 } 71 }
76 72
77 if (button->count == BUTTONS_COUNT_THRESHOLD) { 73 if (button->count == BUTTONS_COUNT_THRESHOLD) {
78 input_report_key(bdev->input, button->keycode, 1); 74 input_report_key(input, button->keycode, 1);
79 input_sync(bdev->input); 75 input_sync(input);
80 } 76 }
81 77
82 button++; 78 button++;
83 } 79 }
84
85 mod_timer(&buttons_timer, jiffies + msecs_to_jiffies(BUTTONS_POLL_INTERVAL));
86}
87
88static int cobalt_buttons_open(struct input_dev *dev)
89{
90 mod_timer(&buttons_timer, jiffies + msecs_to_jiffies(BUTTONS_POLL_INTERVAL));
91
92 return 0;
93}
94
95static void cobalt_buttons_close(struct input_dev *dev)
96{
97 del_timer_sync(&buttons_timer);
98} 80}
99 81
100static int __devinit cobalt_buttons_probe(struct platform_device *pdev) 82static int __devinit cobalt_buttons_probe(struct platform_device *pdev)
101{ 83{
102 struct buttons_dev *bdev; 84 struct buttons_dev *bdev;
85 struct input_polled_dev *poll_dev;
103 struct input_dev *input; 86 struct input_dev *input;
104 struct resource *res; 87 struct resource *res;
105 int error, i; 88 int error, i;
106 89
107 bdev = kzalloc(sizeof(struct buttons_dev), GFP_KERNEL); 90 bdev = kzalloc(sizeof(struct buttons_dev), GFP_KERNEL);
108 input = input_allocate_device(); 91 poll_dev = input_allocate_polled_device();
109 if (!bdev || !input) { 92 if (!bdev || !poll_dev) {
110 error = -ENOMEM; 93 error = -ENOMEM;
111 goto err_free_mem; 94 goto err_free_mem;
112 } 95 }
113 96
97 poll_dev->private = bdev;
98 poll_dev->poll = handle_buttons;
99 poll_dev->poll_interval = BUTTONS_POLL_INTERVAL;
100
101 input = poll_dev->input;
114 input->name = "Cobalt buttons"; 102 input->name = "Cobalt buttons";
115 input->phys = "cobalt/input0"; 103 input->phys = "cobalt/input0";
116 input->id.bustype = BUS_HOST; 104 input->id.bustype = BUS_HOST;
117 input->cdev.dev = &pdev->dev; 105 input->cdev.dev = &pdev->dev;
118 input->open = cobalt_buttons_open;
119 input->close = cobalt_buttons_close;
120 106
121 input->evbit[0] = BIT(EV_KEY); 107 input->evbit[0] = BIT(EV_KEY);
122 for (i = 0; i < ARRAY_SIZE(buttons_map); i++) { 108 for (i = 0; i < ARRAY_SIZE(buttons_map); i++) {
@@ -130,13 +116,11 @@ static int __devinit cobalt_buttons_probe(struct platform_device *pdev)
130 goto err_free_mem; 116 goto err_free_mem;
131 } 117 }
132 118
133 bdev->input = input; 119 bdev->poll_dev = poll_dev;
134 bdev->reg = ioremap(res->start, res->end - res->start + 1); 120 bdev->reg = ioremap(res->start, res->end - res->start + 1);
135 dev_set_drvdata(&pdev->dev, bdev); 121 dev_set_drvdata(&pdev->dev, bdev);
136 122
137 setup_timer(&buttons_timer, handle_buttons, (unsigned long)bdev); 123 error = input_register_polled_device(poll_dev);
138
139 error = input_register_device(input);
140 if (error) 124 if (error)
141 goto err_iounmap; 125 goto err_iounmap;
142 126
@@ -145,7 +129,7 @@ static int __devinit cobalt_buttons_probe(struct platform_device *pdev)
145 err_iounmap: 129 err_iounmap:
146 iounmap(bdev->reg); 130 iounmap(bdev->reg);
147 err_free_mem: 131 err_free_mem:
148 input_free_device(input); 132 input_free_polled_device(poll_dev);
149 kfree(bdev); 133 kfree(bdev);
150 dev_set_drvdata(&pdev->dev, NULL); 134 dev_set_drvdata(&pdev->dev, NULL);
151 return error; 135 return error;
@@ -156,7 +140,8 @@ static int __devexit cobalt_buttons_remove(struct platform_device *pdev)
156 struct device *dev = &pdev->dev; 140 struct device *dev = &pdev->dev;
157 struct buttons_dev *bdev = dev_get_drvdata(dev); 141 struct buttons_dev *bdev = dev_get_drvdata(dev);
158 142
159 input_unregister_device(bdev->input); 143 input_unregister_polled_device(bdev->poll_dev);
144 input_free_polled_device(bdev->poll_dev);
160 iounmap(bdev->reg); 145 iounmap(bdev->reg);
161 kfree(bdev); 146 kfree(bdev);
162 dev_set_drvdata(dev, NULL); 147 dev_set_drvdata(dev, NULL);