diff options
Diffstat (limited to 'drivers/input')
25 files changed, 2278 insertions, 16 deletions
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index 1148140d08a1..dee6706038aa 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #define EVDEV_BUFFER_SIZE 64 | 13 | #define EVDEV_BUFFER_SIZE 64 |
14 | 14 | ||
15 | #include <linux/poll.h> | 15 | #include <linux/poll.h> |
16 | #include <linux/sched.h> | ||
16 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
17 | #include <linux/module.h> | 18 | #include <linux/module.h> |
18 | #include <linux/init.h> | 19 | #include <linux/init.h> |
diff --git a/drivers/input/input.c b/drivers/input/input.c index 60a4eaabb7d7..cc763c96fada 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/random.h> | 17 | #include <linux/random.h> |
18 | #include <linux/major.h> | 18 | #include <linux/major.h> |
19 | #include <linux/proc_fs.h> | 19 | #include <linux/proc_fs.h> |
20 | #include <linux/sched.h> | ||
20 | #include <linux/seq_file.h> | 21 | #include <linux/seq_file.h> |
21 | #include <linux/poll.h> | 22 | #include <linux/poll.h> |
22 | #include <linux/device.h> | 23 | #include <linux/device.h> |
@@ -1176,7 +1177,7 @@ static struct attribute_group input_dev_caps_attr_group = { | |||
1176 | .attrs = input_dev_caps_attrs, | 1177 | .attrs = input_dev_caps_attrs, |
1177 | }; | 1178 | }; |
1178 | 1179 | ||
1179 | static struct attribute_group *input_dev_attr_groups[] = { | 1180 | static const struct attribute_group *input_dev_attr_groups[] = { |
1180 | &input_dev_attr_group, | 1181 | &input_dev_attr_group, |
1181 | &input_dev_id_attr_group, | 1182 | &input_dev_id_attr_group, |
1182 | &input_dev_caps_attr_group, | 1183 | &input_dev_caps_attr_group, |
@@ -1304,6 +1305,7 @@ static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env) | |||
1304 | } \ | 1305 | } \ |
1305 | } while (0) | 1306 | } while (0) |
1306 | 1307 | ||
1308 | #ifdef CONFIG_PM | ||
1307 | static void input_dev_reset(struct input_dev *dev, bool activate) | 1309 | static void input_dev_reset(struct input_dev *dev, bool activate) |
1308 | { | 1310 | { |
1309 | if (!dev->event) | 1311 | if (!dev->event) |
@@ -1318,7 +1320,6 @@ static void input_dev_reset(struct input_dev *dev, bool activate) | |||
1318 | } | 1320 | } |
1319 | } | 1321 | } |
1320 | 1322 | ||
1321 | #ifdef CONFIG_PM | ||
1322 | static int input_dev_suspend(struct device *dev) | 1323 | static int input_dev_suspend(struct device *dev) |
1323 | { | 1324 | { |
1324 | struct input_dev *input_dev = to_input_dev(dev); | 1325 | struct input_dev *input_dev = to_input_dev(dev); |
@@ -1358,14 +1359,14 @@ static struct device_type input_dev_type = { | |||
1358 | #endif | 1359 | #endif |
1359 | }; | 1360 | }; |
1360 | 1361 | ||
1361 | static char *input_nodename(struct device *dev) | 1362 | static char *input_devnode(struct device *dev, mode_t *mode) |
1362 | { | 1363 | { |
1363 | return kasprintf(GFP_KERNEL, "input/%s", dev_name(dev)); | 1364 | return kasprintf(GFP_KERNEL, "input/%s", dev_name(dev)); |
1364 | } | 1365 | } |
1365 | 1366 | ||
1366 | struct class input_class = { | 1367 | struct class input_class = { |
1367 | .name = "input", | 1368 | .name = "input", |
1368 | .nodename = input_nodename, | 1369 | .devnode = input_devnode, |
1369 | }; | 1370 | }; |
1370 | EXPORT_SYMBOL_GPL(input_class); | 1371 | EXPORT_SYMBOL_GPL(input_class); |
1371 | 1372 | ||
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c index 901b2525993e..b1bd6dd32286 100644 --- a/drivers/input/joydev.c +++ b/drivers/input/joydev.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/input.h> | 18 | #include <linux/input.h> |
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/major.h> | 20 | #include <linux/major.h> |
21 | #include <linux/sched.h> | ||
21 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
22 | #include <linux/mm.h> | 23 | #include <linux/mm.h> |
23 | #include <linux/miscdevice.h> | 24 | #include <linux/miscdevice.h> |
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c index e9acbe0c9e2a..4452eabbee6d 100644 --- a/drivers/input/keyboard/atkbd.c +++ b/drivers/input/keyboard/atkbd.c | |||
@@ -229,7 +229,7 @@ struct atkbd { | |||
229 | }; | 229 | }; |
230 | 230 | ||
231 | /* | 231 | /* |
232 | * System-specific ketymap fixup routine | 232 | * System-specific keymap fixup routine |
233 | */ | 233 | */ |
234 | static void (*atkbd_platform_fixup)(struct atkbd *, const void *data); | 234 | static void (*atkbd_platform_fixup)(struct atkbd *, const void *data); |
235 | static void *atkbd_platform_fixup_data; | 235 | static void *atkbd_platform_fixup_data; |
diff --git a/drivers/input/keyboard/hilkbd.c b/drivers/input/keyboard/hilkbd.c index e9d639ec283d..5f72440b50c8 100644 --- a/drivers/input/keyboard/hilkbd.c +++ b/drivers/input/keyboard/hilkbd.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/interrupt.h> | 24 | #include <linux/interrupt.h> |
25 | #include <linux/hil.h> | 25 | #include <linux/hil.h> |
26 | #include <linux/io.h> | 26 | #include <linux/io.h> |
27 | #include <linux/sched.h> | ||
27 | #include <linux/spinlock.h> | 28 | #include <linux/spinlock.h> |
28 | #include <asm/irq.h> | 29 | #include <asm/irq.h> |
29 | #ifdef CONFIG_HP300 | 30 | #ifdef CONFIG_HP300 |
diff --git a/drivers/input/keyboard/omap-keypad.c b/drivers/input/keyboard/omap-keypad.c index 87ec7b18ac69..bba85add35a3 100644 --- a/drivers/input/keyboard/omap-keypad.c +++ b/drivers/input/keyboard/omap-keypad.c | |||
@@ -116,7 +116,7 @@ static irqreturn_t omap_kp_interrupt(int irq, void *dev_id) | |||
116 | } | 116 | } |
117 | } else | 117 | } else |
118 | /* disable keyboard interrupt and schedule for handling */ | 118 | /* disable keyboard interrupt and schedule for handling */ |
119 | omap_writew(1, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); | 119 | omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); |
120 | 120 | ||
121 | tasklet_schedule(&kp_tasklet); | 121 | tasklet_schedule(&kp_tasklet); |
122 | 122 | ||
@@ -143,20 +143,20 @@ static void omap_kp_scan_keypad(struct omap_kp *omap_kp, unsigned char *state) | |||
143 | 143 | ||
144 | } else { | 144 | } else { |
145 | /* disable keyboard interrupt and schedule for handling */ | 145 | /* disable keyboard interrupt and schedule for handling */ |
146 | omap_writew(1, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); | 146 | omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); |
147 | 147 | ||
148 | /* read the keypad status */ | 148 | /* read the keypad status */ |
149 | omap_writew(0xff, OMAP_MPUIO_BASE + OMAP_MPUIO_KBC); | 149 | omap_writew(0xff, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBC); |
150 | for (col = 0; col < omap_kp->cols; col++) { | 150 | for (col = 0; col < omap_kp->cols; col++) { |
151 | omap_writew(~(1 << col) & 0xff, | 151 | omap_writew(~(1 << col) & 0xff, |
152 | OMAP_MPUIO_BASE + OMAP_MPUIO_KBC); | 152 | OMAP1_MPUIO_BASE + OMAP_MPUIO_KBC); |
153 | 153 | ||
154 | udelay(omap_kp->delay); | 154 | udelay(omap_kp->delay); |
155 | 155 | ||
156 | state[col] = ~omap_readw(OMAP_MPUIO_BASE + | 156 | state[col] = ~omap_readw(OMAP1_MPUIO_BASE + |
157 | OMAP_MPUIO_KBR_LATCH) & 0xff; | 157 | OMAP_MPUIO_KBR_LATCH) & 0xff; |
158 | } | 158 | } |
159 | omap_writew(0x00, OMAP_MPUIO_BASE + OMAP_MPUIO_KBC); | 159 | omap_writew(0x00, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBC); |
160 | udelay(2); | 160 | udelay(2); |
161 | } | 161 | } |
162 | } | 162 | } |
@@ -234,7 +234,7 @@ static void omap_kp_tasklet(unsigned long data) | |||
234 | for (i = 0; i < omap_kp_data->rows; i++) | 234 | for (i = 0; i < omap_kp_data->rows; i++) |
235 | enable_irq(gpio_to_irq(row_gpios[i])); | 235 | enable_irq(gpio_to_irq(row_gpios[i])); |
236 | } else { | 236 | } else { |
237 | omap_writew(0, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); | 237 | omap_writew(0, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); |
238 | kp_cur_group = -1; | 238 | kp_cur_group = -1; |
239 | } | 239 | } |
240 | } | 240 | } |
@@ -317,7 +317,7 @@ static int __devinit omap_kp_probe(struct platform_device *pdev) | |||
317 | 317 | ||
318 | /* Disable the interrupt for the MPUIO keyboard */ | 318 | /* Disable the interrupt for the MPUIO keyboard */ |
319 | if (!cpu_is_omap24xx()) | 319 | if (!cpu_is_omap24xx()) |
320 | omap_writew(1, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); | 320 | omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); |
321 | 321 | ||
322 | keymap = pdata->keymap; | 322 | keymap = pdata->keymap; |
323 | 323 | ||
@@ -391,7 +391,7 @@ static int __devinit omap_kp_probe(struct platform_device *pdev) | |||
391 | } | 391 | } |
392 | 392 | ||
393 | if (pdata->dbounce) | 393 | if (pdata->dbounce) |
394 | omap_writew(0xff, OMAP_MPUIO_BASE + OMAP_MPUIO_GPIO_DEBOUNCING); | 394 | omap_writew(0xff, OMAP1_MPUIO_BASE + OMAP_MPUIO_GPIO_DEBOUNCING); |
395 | 395 | ||
396 | /* scan current status and enable interrupt */ | 396 | /* scan current status and enable interrupt */ |
397 | omap_kp_scan_keypad(omap_kp, keypad_state); | 397 | omap_kp_scan_keypad(omap_kp, keypad_state); |
@@ -402,7 +402,7 @@ static int __devinit omap_kp_probe(struct platform_device *pdev) | |||
402 | "omap-keypad", omap_kp) < 0) | 402 | "omap-keypad", omap_kp) < 0) |
403 | goto err4; | 403 | goto err4; |
404 | } | 404 | } |
405 | omap_writew(0, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); | 405 | omap_writew(0, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); |
406 | } else { | 406 | } else { |
407 | for (irq_idx = 0; irq_idx < omap_kp->rows; irq_idx++) { | 407 | for (irq_idx = 0; irq_idx < omap_kp->rows; irq_idx++) { |
408 | if (request_irq(gpio_to_irq(row_gpios[irq_idx]), | 408 | if (request_irq(gpio_to_irq(row_gpios[irq_idx]), |
@@ -449,7 +449,7 @@ static int __devexit omap_kp_remove(struct platform_device *pdev) | |||
449 | free_irq(gpio_to_irq(row_gpios[i]), 0); | 449 | free_irq(gpio_to_irq(row_gpios[i]), 0); |
450 | } | 450 | } |
451 | } else { | 451 | } else { |
452 | omap_writew(1, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); | 452 | omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); |
453 | free_irq(omap_kp->irq, 0); | 453 | free_irq(omap_kp->irq, 0); |
454 | } | 454 | } |
455 | 455 | ||
diff --git a/drivers/input/keyboard/sh_keysc.c b/drivers/input/keyboard/sh_keysc.c index 0714bf2c28fc..887af79b7bff 100644 --- a/drivers/input/keyboard/sh_keysc.c +++ b/drivers/input/keyboard/sh_keysc.c | |||
@@ -80,6 +80,9 @@ static irqreturn_t sh_keysc_isr(int irq, void *dev_id) | |||
80 | iowrite16(KYCR2_IRQ_LEVEL | (keyin_set << 8), | 80 | iowrite16(KYCR2_IRQ_LEVEL | (keyin_set << 8), |
81 | priv->iomem_base + KYCR2_OFFS); | 81 | priv->iomem_base + KYCR2_OFFS); |
82 | 82 | ||
83 | if (pdata->kycr2_delay) | ||
84 | udelay(pdata->kycr2_delay); | ||
85 | |||
83 | keys ^= ~0; | 86 | keys ^= ~0; |
84 | keys &= (1 << (sh_keysc_mode[pdata->mode].keyin * | 87 | keys &= (1 << (sh_keysc_mode[pdata->mode].keyin * |
85 | sh_keysc_mode[pdata->mode].keyout)) - 1; | 88 | sh_keysc_mode[pdata->mode].keyout)) - 1; |
diff --git a/drivers/input/keyboard/sunkbd.c b/drivers/input/keyboard/sunkbd.c index 472b56639cdb..a99a04b03ee4 100644 --- a/drivers/input/keyboard/sunkbd.c +++ b/drivers/input/keyboard/sunkbd.c | |||
@@ -27,6 +27,7 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <linux/delay.h> | 29 | #include <linux/delay.h> |
30 | #include <linux/sched.h> | ||
30 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
31 | #include <linux/module.h> | 32 | #include <linux/module.h> |
32 | #include <linux/interrupt.h> | 33 | #include <linux/interrupt.h> |
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index cbe21bc96b52..02f4f8f1db6f 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig | |||
@@ -222,6 +222,23 @@ config INPUT_SGI_BTNS | |||
222 | To compile this driver as a module, choose M here: the | 222 | To compile this driver as a module, choose M here: the |
223 | module will be called sgi_btns. | 223 | module will be called sgi_btns. |
224 | 224 | ||
225 | config INPUT_WINBOND_CIR | ||
226 | tristate "Winbond IR remote control" | ||
227 | depends on X86 && PNP | ||
228 | select NEW_LEDS | ||
229 | select LEDS_CLASS | ||
230 | select BITREVERSE | ||
231 | help | ||
232 | Say Y here if you want to use the IR remote functionality found | ||
233 | in some Winbond SuperI/O chips. Currently only the WPCD376I | ||
234 | chip is supported (included in some Intel Media series motherboards). | ||
235 | |||
236 | IR Receive and wake-on-IR from suspend and power-off is currently | ||
237 | supported. | ||
238 | |||
239 | To compile this driver as a module, choose M here: the module will be | ||
240 | called winbond_cir. | ||
241 | |||
225 | config HP_SDC_RTC | 242 | config HP_SDC_RTC |
226 | tristate "HP SDC Real Time Clock" | 243 | tristate "HP SDC Real Time Clock" |
227 | depends on (GSC || HP300) && SERIO | 244 | depends on (GSC || HP300) && SERIO |
@@ -279,4 +296,24 @@ config INPUT_BFIN_ROTARY | |||
279 | To compile this driver as a module, choose M here: the | 296 | To compile this driver as a module, choose M here: the |
280 | module will be called bfin-rotary. | 297 | module will be called bfin-rotary. |
281 | 298 | ||
299 | config INPUT_WM831X_ON | ||
300 | tristate "WM831X ON pin" | ||
301 | depends on MFD_WM831X | ||
302 | help | ||
303 | Support the ON pin of WM831X PMICs as an input device | ||
304 | reporting power button status. | ||
305 | |||
306 | To compile this driver as a module, choose M here: the module | ||
307 | will be called wm831x_on. | ||
308 | |||
309 | config INPUT_PCAP | ||
310 | tristate "Motorola EZX PCAP misc input events" | ||
311 | depends on EZX_PCAP | ||
312 | help | ||
313 | Say Y here if you want to use Power key and Headphone button | ||
314 | on Motorola EZX phones. | ||
315 | |||
316 | To compile this driver as a module, choose M here: the | ||
317 | module will be called pcap_keys. | ||
318 | |||
282 | endif | 319 | endif |
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 79c1e9a5ea31..a8b84854fb7b 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile | |||
@@ -16,6 +16,7 @@ obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o | |||
16 | obj-$(CONFIG_INPUT_IXP4XX_BEEPER) += ixp4xx-beeper.o | 16 | obj-$(CONFIG_INPUT_IXP4XX_BEEPER) += ixp4xx-beeper.o |
17 | obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o | 17 | obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o |
18 | obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o | 18 | obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o |
19 | obj-$(CONFIG_INPUT_PCAP) += pcap_keys.o | ||
19 | obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o | 20 | obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o |
20 | obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o | 21 | obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o |
21 | obj-$(CONFIG_INPUT_POWERMATE) += powermate.o | 22 | obj-$(CONFIG_INPUT_POWERMATE) += powermate.o |
@@ -25,5 +26,8 @@ obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o | |||
25 | obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o | 26 | obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o |
26 | obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o | 27 | obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o |
27 | obj-$(CONFIG_INPUT_UINPUT) += uinput.o | 28 | obj-$(CONFIG_INPUT_UINPUT) += uinput.o |
29 | obj-$(CONFIG_INPUT_WINBOND_CIR) += winbond-cir.o | ||
28 | obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o | 30 | obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o |
31 | obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o | ||
29 | obj-$(CONFIG_INPUT_YEALINK) += yealink.o | 32 | obj-$(CONFIG_INPUT_YEALINK) += yealink.o |
33 | |||
diff --git a/drivers/input/misc/pcap_keys.c b/drivers/input/misc/pcap_keys.c new file mode 100644 index 000000000000..7ea969347ca9 --- /dev/null +++ b/drivers/input/misc/pcap_keys.c | |||
@@ -0,0 +1,144 @@ | |||
1 | /* | ||
2 | * Input driver for PCAP events: | ||
3 | * * Power key | ||
4 | * * Headphone button | ||
5 | * | ||
6 | * Copyright (c) 2008,2009 Ilya Petrov <ilya.muromec@gmail.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/interrupt.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/input.h> | ||
19 | #include <linux/mfd/ezx-pcap.h> | ||
20 | |||
21 | struct pcap_keys { | ||
22 | struct pcap_chip *pcap; | ||
23 | struct input_dev *input; | ||
24 | }; | ||
25 | |||
26 | /* PCAP2 interrupts us on keypress */ | ||
27 | static irqreturn_t pcap_keys_handler(int irq, void *_pcap_keys) | ||
28 | { | ||
29 | struct pcap_keys *pcap_keys = _pcap_keys; | ||
30 | int pirq = irq_to_pcap(pcap_keys->pcap, irq); | ||
31 | u32 pstat; | ||
32 | |||
33 | ezx_pcap_read(pcap_keys->pcap, PCAP_REG_PSTAT, &pstat); | ||
34 | pstat &= 1 << pirq; | ||
35 | |||
36 | switch (pirq) { | ||
37 | case PCAP_IRQ_ONOFF: | ||
38 | input_report_key(pcap_keys->input, KEY_POWER, !pstat); | ||
39 | break; | ||
40 | case PCAP_IRQ_MIC: | ||
41 | input_report_key(pcap_keys->input, KEY_HP, !pstat); | ||
42 | break; | ||
43 | } | ||
44 | |||
45 | input_sync(pcap_keys->input); | ||
46 | |||
47 | return IRQ_HANDLED; | ||
48 | } | ||
49 | |||
50 | static int __devinit pcap_keys_probe(struct platform_device *pdev) | ||
51 | { | ||
52 | int err = -ENOMEM; | ||
53 | struct pcap_keys *pcap_keys; | ||
54 | struct input_dev *input_dev; | ||
55 | |||
56 | pcap_keys = kmalloc(sizeof(struct pcap_keys), GFP_KERNEL); | ||
57 | if (!pcap_keys) | ||
58 | return err; | ||
59 | |||
60 | pcap_keys->pcap = dev_get_drvdata(pdev->dev.parent); | ||
61 | |||
62 | input_dev = input_allocate_device(); | ||
63 | if (!input_dev) | ||
64 | goto fail; | ||
65 | |||
66 | pcap_keys->input = input_dev; | ||
67 | |||
68 | platform_set_drvdata(pdev, pcap_keys); | ||
69 | input_dev->name = pdev->name; | ||
70 | input_dev->phys = "pcap-keys/input0"; | ||
71 | input_dev->id.bustype = BUS_HOST; | ||
72 | input_dev->dev.parent = &pdev->dev; | ||
73 | |||
74 | __set_bit(EV_KEY, input_dev->evbit); | ||
75 | __set_bit(KEY_POWER, input_dev->keybit); | ||
76 | __set_bit(KEY_HP, input_dev->keybit); | ||
77 | |||
78 | err = input_register_device(input_dev); | ||
79 | if (err) | ||
80 | goto fail_allocate; | ||
81 | |||
82 | err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF), | ||
83 | pcap_keys_handler, 0, "Power key", pcap_keys); | ||
84 | if (err) | ||
85 | goto fail_register; | ||
86 | |||
87 | err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_MIC), | ||
88 | pcap_keys_handler, 0, "Headphone button", pcap_keys); | ||
89 | if (err) | ||
90 | goto fail_pwrkey; | ||
91 | |||
92 | return 0; | ||
93 | |||
94 | fail_pwrkey: | ||
95 | free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF), pcap_keys); | ||
96 | fail_register: | ||
97 | input_unregister_device(input_dev); | ||
98 | goto fail; | ||
99 | fail_allocate: | ||
100 | input_free_device(input_dev); | ||
101 | fail: | ||
102 | kfree(pcap_keys); | ||
103 | return err; | ||
104 | } | ||
105 | |||
106 | static int __devexit pcap_keys_remove(struct platform_device *pdev) | ||
107 | { | ||
108 | struct pcap_keys *pcap_keys = platform_get_drvdata(pdev); | ||
109 | |||
110 | free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF), pcap_keys); | ||
111 | free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_MIC), pcap_keys); | ||
112 | |||
113 | input_unregister_device(pcap_keys->input); | ||
114 | kfree(pcap_keys); | ||
115 | |||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | static struct platform_driver pcap_keys_device_driver = { | ||
120 | .probe = pcap_keys_probe, | ||
121 | .remove = __devexit_p(pcap_keys_remove), | ||
122 | .driver = { | ||
123 | .name = "pcap-keys", | ||
124 | .owner = THIS_MODULE, | ||
125 | } | ||
126 | }; | ||
127 | |||
128 | static int __init pcap_keys_init(void) | ||
129 | { | ||
130 | return platform_driver_register(&pcap_keys_device_driver); | ||
131 | }; | ||
132 | |||
133 | static void __exit pcap_keys_exit(void) | ||
134 | { | ||
135 | platform_driver_unregister(&pcap_keys_device_driver); | ||
136 | }; | ||
137 | |||
138 | module_init(pcap_keys_init); | ||
139 | module_exit(pcap_keys_exit); | ||
140 | |||
141 | MODULE_DESCRIPTION("Motorola PCAP2 input events driver"); | ||
142 | MODULE_AUTHOR("Ilya Petrov <ilya.muromec@gmail.com>"); | ||
143 | MODULE_LICENSE("GPL"); | ||
144 | MODULE_ALIAS("platform:pcap_keys"); | ||
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index c5a49aba418f..d3f57245420a 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c | |||
@@ -30,6 +30,7 @@ | |||
30 | * - first public version | 30 | * - first public version |
31 | */ | 31 | */ |
32 | #include <linux/poll.h> | 32 | #include <linux/poll.h> |
33 | #include <linux/sched.h> | ||
33 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
34 | #include <linux/module.h> | 35 | #include <linux/module.h> |
35 | #include <linux/init.h> | 36 | #include <linux/init.h> |
diff --git a/drivers/input/misc/winbond-cir.c b/drivers/input/misc/winbond-cir.c new file mode 100644 index 000000000000..33309fe44e20 --- /dev/null +++ b/drivers/input/misc/winbond-cir.c | |||
@@ -0,0 +1,1614 @@ | |||
1 | /* | ||
2 | * winbond-cir.c - Driver for the Consumer IR functionality of Winbond | ||
3 | * SuperI/O chips. | ||
4 | * | ||
5 | * Currently supports the Winbond WPCD376i chip (PNP id WEC1022), but | ||
6 | * could probably support others (Winbond WEC102X, NatSemi, etc) | ||
7 | * with minor modifications. | ||
8 | * | ||
9 | * Original Author: David Härdeman <david@hardeman.nu> | ||
10 | * Copyright (C) 2009 David Härdeman <david@hardeman.nu> | ||
11 | * | ||
12 | * Dedicated to Matilda, my newborn daughter, without whose loving attention | ||
13 | * this driver would have been finished in half the time and with a fraction | ||
14 | * of the bugs. | ||
15 | * | ||
16 | * Written using: | ||
17 | * o Winbond WPCD376I datasheet helpfully provided by Jesse Barnes at Intel | ||
18 | * o NatSemi PC87338/PC97338 datasheet (for the serial port stuff) | ||
19 | * o DSDT dumps | ||
20 | * | ||
21 | * Supported features: | ||
22 | * o RC6 | ||
23 | * o Wake-On-CIR functionality | ||
24 | * | ||
25 | * To do: | ||
26 | * o Test NEC and RC5 | ||
27 | * | ||
28 | * Left as an exercise for the reader: | ||
29 | * o Learning (I have neither the hardware, nor the need) | ||
30 | * o IR Transmit (ibid) | ||
31 | * | ||
32 | * This program is free software; you can redistribute it and/or modify | ||
33 | * it under the terms of the GNU General Public License as published by | ||
34 | * the Free Software Foundation; either version 2 of the License, or | ||
35 | * (at your option) any later version. | ||
36 | * | ||
37 | * This program is distributed in the hope that it will be useful, | ||
38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
40 | * GNU General Public License for more details. | ||
41 | * | ||
42 | * You should have received a copy of the GNU General Public License | ||
43 | * along with this program; if not, write to the Free Software | ||
44 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
45 | */ | ||
46 | |||
47 | #include <linux/module.h> | ||
48 | #include <linux/pnp.h> | ||
49 | #include <linux/interrupt.h> | ||
50 | #include <linux/timer.h> | ||
51 | #include <linux/input.h> | ||
52 | #include <linux/leds.h> | ||
53 | #include <linux/list.h> | ||
54 | #include <linux/spinlock.h> | ||
55 | #include <linux/pci_ids.h> | ||
56 | #include <linux/io.h> | ||
57 | #include <linux/bitrev.h> | ||
58 | #include <linux/bitops.h> | ||
59 | |||
60 | #define DRVNAME "winbond-cir" | ||
61 | |||
62 | /* CEIR Wake-Up Registers, relative to data->wbase */ | ||
63 | #define WBCIR_REG_WCEIR_CTL 0x03 /* CEIR Receiver Control */ | ||
64 | #define WBCIR_REG_WCEIR_STS 0x04 /* CEIR Receiver Status */ | ||
65 | #define WBCIR_REG_WCEIR_EV_EN 0x05 /* CEIR Receiver Event Enable */ | ||
66 | #define WBCIR_REG_WCEIR_CNTL 0x06 /* CEIR Receiver Counter Low */ | ||
67 | #define WBCIR_REG_WCEIR_CNTH 0x07 /* CEIR Receiver Counter High */ | ||
68 | #define WBCIR_REG_WCEIR_INDEX 0x08 /* CEIR Receiver Index */ | ||
69 | #define WBCIR_REG_WCEIR_DATA 0x09 /* CEIR Receiver Data */ | ||
70 | #define WBCIR_REG_WCEIR_CSL 0x0A /* CEIR Re. Compare Strlen */ | ||
71 | #define WBCIR_REG_WCEIR_CFG1 0x0B /* CEIR Re. Configuration 1 */ | ||
72 | #define WBCIR_REG_WCEIR_CFG2 0x0C /* CEIR Re. Configuration 2 */ | ||
73 | |||
74 | /* CEIR Enhanced Functionality Registers, relative to data->ebase */ | ||
75 | #define WBCIR_REG_ECEIR_CTS 0x00 /* Enhanced IR Control Status */ | ||
76 | #define WBCIR_REG_ECEIR_CCTL 0x01 /* Infrared Counter Control */ | ||
77 | #define WBCIR_REG_ECEIR_CNT_LO 0x02 /* Infrared Counter LSB */ | ||
78 | #define WBCIR_REG_ECEIR_CNT_HI 0x03 /* Infrared Counter MSB */ | ||
79 | #define WBCIR_REG_ECEIR_IREM 0x04 /* Infrared Emitter Status */ | ||
80 | |||
81 | /* SP3 Banked Registers, relative to data->sbase */ | ||
82 | #define WBCIR_REG_SP3_BSR 0x03 /* Bank Select, all banks */ | ||
83 | /* Bank 0 */ | ||
84 | #define WBCIR_REG_SP3_RXDATA 0x00 /* FIFO RX data (r) */ | ||
85 | #define WBCIR_REG_SP3_TXDATA 0x00 /* FIFO TX data (w) */ | ||
86 | #define WBCIR_REG_SP3_IER 0x01 /* Interrupt Enable */ | ||
87 | #define WBCIR_REG_SP3_EIR 0x02 /* Event Identification (r) */ | ||
88 | #define WBCIR_REG_SP3_FCR 0x02 /* FIFO Control (w) */ | ||
89 | #define WBCIR_REG_SP3_MCR 0x04 /* Mode Control */ | ||
90 | #define WBCIR_REG_SP3_LSR 0x05 /* Link Status */ | ||
91 | #define WBCIR_REG_SP3_MSR 0x06 /* Modem Status */ | ||
92 | #define WBCIR_REG_SP3_ASCR 0x07 /* Aux Status and Control */ | ||
93 | /* Bank 2 */ | ||
94 | #define WBCIR_REG_SP3_BGDL 0x00 /* Baud Divisor LSB */ | ||
95 | #define WBCIR_REG_SP3_BGDH 0x01 /* Baud Divisor MSB */ | ||
96 | #define WBCIR_REG_SP3_EXCR1 0x02 /* Extended Control 1 */ | ||
97 | #define WBCIR_REG_SP3_EXCR2 0x04 /* Extended Control 2 */ | ||
98 | #define WBCIR_REG_SP3_TXFLV 0x06 /* TX FIFO Level */ | ||
99 | #define WBCIR_REG_SP3_RXFLV 0x07 /* RX FIFO Level */ | ||
100 | /* Bank 3 */ | ||
101 | #define WBCIR_REG_SP3_MRID 0x00 /* Module Identification */ | ||
102 | #define WBCIR_REG_SP3_SH_LCR 0x01 /* LCR Shadow */ | ||
103 | #define WBCIR_REG_SP3_SH_FCR 0x02 /* FCR Shadow */ | ||
104 | /* Bank 4 */ | ||
105 | #define WBCIR_REG_SP3_IRCR1 0x02 /* Infrared Control 1 */ | ||
106 | /* Bank 5 */ | ||
107 | #define WBCIR_REG_SP3_IRCR2 0x04 /* Infrared Control 2 */ | ||
108 | /* Bank 6 */ | ||
109 | #define WBCIR_REG_SP3_IRCR3 0x00 /* Infrared Control 3 */ | ||
110 | #define WBCIR_REG_SP3_SIR_PW 0x02 /* SIR Pulse Width */ | ||
111 | /* Bank 7 */ | ||
112 | #define WBCIR_REG_SP3_IRRXDC 0x00 /* IR RX Demod Control */ | ||
113 | #define WBCIR_REG_SP3_IRTXMC 0x01 /* IR TX Mod Control */ | ||
114 | #define WBCIR_REG_SP3_RCCFG 0x02 /* CEIR Config */ | ||
115 | #define WBCIR_REG_SP3_IRCFG1 0x04 /* Infrared Config 1 */ | ||
116 | #define WBCIR_REG_SP3_IRCFG4 0x07 /* Infrared Config 4 */ | ||
117 | |||
118 | /* | ||
119 | * Magic values follow | ||
120 | */ | ||
121 | |||
122 | /* No interrupts for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ | ||
123 | #define WBCIR_IRQ_NONE 0x00 | ||
124 | /* RX data bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ | ||
125 | #define WBCIR_IRQ_RX 0x01 | ||
126 | /* Over/Under-flow bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ | ||
127 | #define WBCIR_IRQ_ERR 0x04 | ||
128 | /* Led enable/disable bit for WBCIR_REG_ECEIR_CTS */ | ||
129 | #define WBCIR_LED_ENABLE 0x80 | ||
130 | /* RX data available bit for WBCIR_REG_SP3_LSR */ | ||
131 | #define WBCIR_RX_AVAIL 0x01 | ||
132 | /* RX disable bit for WBCIR_REG_SP3_ASCR */ | ||
133 | #define WBCIR_RX_DISABLE 0x20 | ||
134 | /* Extended mode enable bit for WBCIR_REG_SP3_EXCR1 */ | ||
135 | #define WBCIR_EXT_ENABLE 0x01 | ||
136 | /* Select compare register in WBCIR_REG_WCEIR_INDEX (bits 5 & 6) */ | ||
137 | #define WBCIR_REGSEL_COMPARE 0x10 | ||
138 | /* Select mask register in WBCIR_REG_WCEIR_INDEX (bits 5 & 6) */ | ||
139 | #define WBCIR_REGSEL_MASK 0x20 | ||
140 | /* Starting address of selected register in WBCIR_REG_WCEIR_INDEX */ | ||
141 | #define WBCIR_REG_ADDR0 0x00 | ||
142 | |||
143 | /* Valid banks for the SP3 UART */ | ||
144 | enum wbcir_bank { | ||
145 | WBCIR_BANK_0 = 0x00, | ||
146 | WBCIR_BANK_1 = 0x80, | ||
147 | WBCIR_BANK_2 = 0xE0, | ||
148 | WBCIR_BANK_3 = 0xE4, | ||
149 | WBCIR_BANK_4 = 0xE8, | ||
150 | WBCIR_BANK_5 = 0xEC, | ||
151 | WBCIR_BANK_6 = 0xF0, | ||
152 | WBCIR_BANK_7 = 0xF4, | ||
153 | }; | ||
154 | |||
155 | /* Supported IR Protocols */ | ||
156 | enum wbcir_protocol { | ||
157 | IR_PROTOCOL_RC5 = 0x0, | ||
158 | IR_PROTOCOL_NEC = 0x1, | ||
159 | IR_PROTOCOL_RC6 = 0x2, | ||
160 | }; | ||
161 | |||
162 | /* Misc */ | ||
163 | #define WBCIR_NAME "Winbond CIR" | ||
164 | #define WBCIR_ID_FAMILY 0xF1 /* Family ID for the WPCD376I */ | ||
165 | #define WBCIR_ID_CHIP 0x04 /* Chip ID for the WPCD376I */ | ||
166 | #define IR_KEYPRESS_TIMEOUT 250 /* FIXME: should be per-protocol? */ | ||
167 | #define INVALID_SCANCODE 0x7FFFFFFF /* Invalid with all protos */ | ||
168 | #define WAKEUP_IOMEM_LEN 0x10 /* Wake-Up I/O Reg Len */ | ||
169 | #define EHFUNC_IOMEM_LEN 0x10 /* Enhanced Func I/O Reg Len */ | ||
170 | #define SP_IOMEM_LEN 0x08 /* Serial Port 3 (IR) Reg Len */ | ||
171 | #define WBCIR_MAX_IDLE_BYTES 10 | ||
172 | |||
173 | static DEFINE_SPINLOCK(wbcir_lock); | ||
174 | static DEFINE_RWLOCK(keytable_lock); | ||
175 | |||
176 | struct wbcir_key { | ||
177 | u32 scancode; | ||
178 | unsigned int keycode; | ||
179 | }; | ||
180 | |||
181 | struct wbcir_keyentry { | ||
182 | struct wbcir_key key; | ||
183 | struct list_head list; | ||
184 | }; | ||
185 | |||
186 | static struct wbcir_key rc6_def_keymap[] = { | ||
187 | { 0x800F0400, KEY_NUMERIC_0 }, | ||
188 | { 0x800F0401, KEY_NUMERIC_1 }, | ||
189 | { 0x800F0402, KEY_NUMERIC_2 }, | ||
190 | { 0x800F0403, KEY_NUMERIC_3 }, | ||
191 | { 0x800F0404, KEY_NUMERIC_4 }, | ||
192 | { 0x800F0405, KEY_NUMERIC_5 }, | ||
193 | { 0x800F0406, KEY_NUMERIC_6 }, | ||
194 | { 0x800F0407, KEY_NUMERIC_7 }, | ||
195 | { 0x800F0408, KEY_NUMERIC_8 }, | ||
196 | { 0x800F0409, KEY_NUMERIC_9 }, | ||
197 | { 0x800F041D, KEY_NUMERIC_STAR }, | ||
198 | { 0x800F041C, KEY_NUMERIC_POUND }, | ||
199 | { 0x800F0410, KEY_VOLUMEUP }, | ||
200 | { 0x800F0411, KEY_VOLUMEDOWN }, | ||
201 | { 0x800F0412, KEY_CHANNELUP }, | ||
202 | { 0x800F0413, KEY_CHANNELDOWN }, | ||
203 | { 0x800F040E, KEY_MUTE }, | ||
204 | { 0x800F040D, KEY_VENDOR }, /* Vista Logo Key */ | ||
205 | { 0x800F041E, KEY_UP }, | ||
206 | { 0x800F041F, KEY_DOWN }, | ||
207 | { 0x800F0420, KEY_LEFT }, | ||
208 | { 0x800F0421, KEY_RIGHT }, | ||
209 | { 0x800F0422, KEY_OK }, | ||
210 | { 0x800F0423, KEY_ESC }, | ||
211 | { 0x800F040F, KEY_INFO }, | ||
212 | { 0x800F040A, KEY_CLEAR }, | ||
213 | { 0x800F040B, KEY_ENTER }, | ||
214 | { 0x800F045B, KEY_RED }, | ||
215 | { 0x800F045C, KEY_GREEN }, | ||
216 | { 0x800F045D, KEY_YELLOW }, | ||
217 | { 0x800F045E, KEY_BLUE }, | ||
218 | { 0x800F045A, KEY_TEXT }, | ||
219 | { 0x800F0427, KEY_SWITCHVIDEOMODE }, | ||
220 | { 0x800F040C, KEY_POWER }, | ||
221 | { 0x800F0450, KEY_RADIO }, | ||
222 | { 0x800F0448, KEY_PVR }, | ||
223 | { 0x800F0447, KEY_AUDIO }, | ||
224 | { 0x800F0426, KEY_EPG }, | ||
225 | { 0x800F0449, KEY_CAMERA }, | ||
226 | { 0x800F0425, KEY_TV }, | ||
227 | { 0x800F044A, KEY_VIDEO }, | ||
228 | { 0x800F0424, KEY_DVD }, | ||
229 | { 0x800F0416, KEY_PLAY }, | ||
230 | { 0x800F0418, KEY_PAUSE }, | ||
231 | { 0x800F0419, KEY_STOP }, | ||
232 | { 0x800F0414, KEY_FASTFORWARD }, | ||
233 | { 0x800F041A, KEY_NEXT }, | ||
234 | { 0x800F041B, KEY_PREVIOUS }, | ||
235 | { 0x800F0415, KEY_REWIND }, | ||
236 | { 0x800F0417, KEY_RECORD }, | ||
237 | }; | ||
238 | |||
239 | /* Registers and other state is protected by wbcir_lock */ | ||
240 | struct wbcir_data { | ||
241 | unsigned long wbase; /* Wake-Up Baseaddr */ | ||
242 | unsigned long ebase; /* Enhanced Func. Baseaddr */ | ||
243 | unsigned long sbase; /* Serial Port Baseaddr */ | ||
244 | unsigned int irq; /* Serial Port IRQ */ | ||
245 | |||
246 | struct input_dev *input_dev; | ||
247 | struct timer_list timer_keyup; | ||
248 | struct led_trigger *rxtrigger; | ||
249 | struct led_trigger *txtrigger; | ||
250 | struct led_classdev led; | ||
251 | |||
252 | u32 last_scancode; | ||
253 | unsigned int last_keycode; | ||
254 | u8 last_toggle; | ||
255 | u8 keypressed; | ||
256 | unsigned long keyup_jiffies; | ||
257 | unsigned int idle_count; | ||
258 | |||
259 | /* RX irdata and parsing state */ | ||
260 | unsigned long irdata[30]; | ||
261 | unsigned int irdata_count; | ||
262 | unsigned int irdata_idle; | ||
263 | unsigned int irdata_off; | ||
264 | unsigned int irdata_error; | ||
265 | |||
266 | /* Protected by keytable_lock */ | ||
267 | struct list_head keytable; | ||
268 | }; | ||
269 | |||
270 | static enum wbcir_protocol protocol = IR_PROTOCOL_RC6; | ||
271 | module_param(protocol, uint, 0444); | ||
272 | MODULE_PARM_DESC(protocol, "IR protocol to use " | ||
273 | "(0 = RC5, 1 = NEC, 2 = RC6A, default)"); | ||
274 | |||
275 | static int invert; /* default = 0 */ | ||
276 | module_param(invert, bool, 0444); | ||
277 | MODULE_PARM_DESC(invert, "Invert the signal from the IR receiver"); | ||
278 | |||
279 | static unsigned int wake_sc = 0x800F040C; | ||
280 | module_param(wake_sc, uint, 0644); | ||
281 | MODULE_PARM_DESC(wake_sc, "Scancode of the power-on IR command"); | ||
282 | |||
283 | static unsigned int wake_rc6mode = 6; | ||
284 | module_param(wake_rc6mode, uint, 0644); | ||
285 | MODULE_PARM_DESC(wake_rc6mode, "RC6 mode for the power-on command " | ||
286 | "(0 = 0, 6 = 6A, default)"); | ||
287 | |||
288 | |||
289 | |||
290 | /***************************************************************************** | ||
291 | * | ||
292 | * UTILITY FUNCTIONS | ||
293 | * | ||
294 | *****************************************************************************/ | ||
295 | |||
296 | /* Caller needs to hold wbcir_lock */ | ||
297 | static void | ||
298 | wbcir_set_bits(unsigned long addr, u8 bits, u8 mask) | ||
299 | { | ||
300 | u8 val; | ||
301 | |||
302 | val = inb(addr); | ||
303 | val = ((val & ~mask) | (bits & mask)); | ||
304 | outb(val, addr); | ||
305 | } | ||
306 | |||
307 | /* Selects the register bank for the serial port */ | ||
308 | static inline void | ||
309 | wbcir_select_bank(struct wbcir_data *data, enum wbcir_bank bank) | ||
310 | { | ||
311 | outb(bank, data->sbase + WBCIR_REG_SP3_BSR); | ||
312 | } | ||
313 | |||
314 | static enum led_brightness | ||
315 | wbcir_led_brightness_get(struct led_classdev *led_cdev) | ||
316 | { | ||
317 | struct wbcir_data *data = container_of(led_cdev, | ||
318 | struct wbcir_data, | ||
319 | led); | ||
320 | |||
321 | if (inb(data->ebase + WBCIR_REG_ECEIR_CTS) & WBCIR_LED_ENABLE) | ||
322 | return LED_FULL; | ||
323 | else | ||
324 | return LED_OFF; | ||
325 | } | ||
326 | |||
327 | static void | ||
328 | wbcir_led_brightness_set(struct led_classdev *led_cdev, | ||
329 | enum led_brightness brightness) | ||
330 | { | ||
331 | struct wbcir_data *data = container_of(led_cdev, | ||
332 | struct wbcir_data, | ||
333 | led); | ||
334 | |||
335 | wbcir_set_bits(data->ebase + WBCIR_REG_ECEIR_CTS, | ||
336 | brightness == LED_OFF ? 0x00 : WBCIR_LED_ENABLE, | ||
337 | WBCIR_LED_ENABLE); | ||
338 | } | ||
339 | |||
340 | /* Manchester encodes bits to RC6 message cells (see wbcir_parse_rc6) */ | ||
341 | static u8 | ||
342 | wbcir_to_rc6cells(u8 val) | ||
343 | { | ||
344 | u8 coded = 0x00; | ||
345 | int i; | ||
346 | |||
347 | val &= 0x0F; | ||
348 | for (i = 0; i < 4; i++) { | ||
349 | if (val & 0x01) | ||
350 | coded |= 0x02 << (i * 2); | ||
351 | else | ||
352 | coded |= 0x01 << (i * 2); | ||
353 | val >>= 1; | ||
354 | } | ||
355 | |||
356 | return coded; | ||
357 | } | ||
358 | |||
359 | |||
360 | |||
361 | /***************************************************************************** | ||
362 | * | ||
363 | * INPUT FUNCTIONS | ||
364 | * | ||
365 | *****************************************************************************/ | ||
366 | |||
367 | static unsigned int | ||
368 | wbcir_do_getkeycode(struct wbcir_data *data, u32 scancode) | ||
369 | { | ||
370 | struct wbcir_keyentry *keyentry; | ||
371 | unsigned int keycode = KEY_RESERVED; | ||
372 | unsigned long flags; | ||
373 | |||
374 | read_lock_irqsave(&keytable_lock, flags); | ||
375 | |||
376 | list_for_each_entry(keyentry, &data->keytable, list) { | ||
377 | if (keyentry->key.scancode == scancode) { | ||
378 | keycode = keyentry->key.keycode; | ||
379 | break; | ||
380 | } | ||
381 | } | ||
382 | |||
383 | read_unlock_irqrestore(&keytable_lock, flags); | ||
384 | return keycode; | ||
385 | } | ||
386 | |||
387 | static int | ||
388 | wbcir_getkeycode(struct input_dev *dev, int scancode, int *keycode) | ||
389 | { | ||
390 | struct wbcir_data *data = input_get_drvdata(dev); | ||
391 | |||
392 | *keycode = (int)wbcir_do_getkeycode(data, (u32)scancode); | ||
393 | return 0; | ||
394 | } | ||
395 | |||
396 | static int | ||
397 | wbcir_setkeycode(struct input_dev *dev, int sscancode, int keycode) | ||
398 | { | ||
399 | struct wbcir_data *data = input_get_drvdata(dev); | ||
400 | struct wbcir_keyentry *keyentry; | ||
401 | struct wbcir_keyentry *new_keyentry; | ||
402 | unsigned long flags; | ||
403 | unsigned int old_keycode = KEY_RESERVED; | ||
404 | u32 scancode = (u32)sscancode; | ||
405 | |||
406 | if (keycode < 0 || keycode > KEY_MAX) | ||
407 | return -EINVAL; | ||
408 | |||
409 | new_keyentry = kmalloc(sizeof(*new_keyentry), GFP_KERNEL); | ||
410 | if (!new_keyentry) | ||
411 | return -ENOMEM; | ||
412 | |||
413 | write_lock_irqsave(&keytable_lock, flags); | ||
414 | |||
415 | list_for_each_entry(keyentry, &data->keytable, list) { | ||
416 | if (keyentry->key.scancode != scancode) | ||
417 | continue; | ||
418 | |||
419 | old_keycode = keyentry->key.keycode; | ||
420 | keyentry->key.keycode = keycode; | ||
421 | |||
422 | if (keyentry->key.keycode == KEY_RESERVED) { | ||
423 | list_del(&keyentry->list); | ||
424 | kfree(keyentry); | ||
425 | } | ||
426 | |||
427 | break; | ||
428 | } | ||
429 | |||
430 | set_bit(keycode, dev->keybit); | ||
431 | |||
432 | if (old_keycode == KEY_RESERVED) { | ||
433 | new_keyentry->key.scancode = scancode; | ||
434 | new_keyentry->key.keycode = keycode; | ||
435 | list_add(&new_keyentry->list, &data->keytable); | ||
436 | } else { | ||
437 | kfree(new_keyentry); | ||
438 | clear_bit(old_keycode, dev->keybit); | ||
439 | list_for_each_entry(keyentry, &data->keytable, list) { | ||
440 | if (keyentry->key.keycode == old_keycode) { | ||
441 | set_bit(old_keycode, dev->keybit); | ||
442 | break; | ||
443 | } | ||
444 | } | ||
445 | } | ||
446 | |||
447 | write_unlock_irqrestore(&keytable_lock, flags); | ||
448 | return 0; | ||
449 | } | ||
450 | |||
451 | /* | ||
452 | * Timer function to report keyup event some time after keydown is | ||
453 | * reported by the ISR. | ||
454 | */ | ||
455 | static void | ||
456 | wbcir_keyup(unsigned long cookie) | ||
457 | { | ||
458 | struct wbcir_data *data = (struct wbcir_data *)cookie; | ||
459 | unsigned long flags; | ||
460 | |||
461 | /* | ||
462 | * data->keyup_jiffies is used to prevent a race condition if a | ||
463 | * hardware interrupt occurs at this point and the keyup timer | ||
464 | * event is moved further into the future as a result. | ||
465 | * | ||
466 | * The timer will then be reactivated and this function called | ||
467 | * again in the future. We need to exit gracefully in that case | ||
468 | * to allow the input subsystem to do its auto-repeat magic or | ||
469 | * a keyup event might follow immediately after the keydown. | ||
470 | */ | ||
471 | |||
472 | spin_lock_irqsave(&wbcir_lock, flags); | ||
473 | |||
474 | if (time_is_after_eq_jiffies(data->keyup_jiffies) && data->keypressed) { | ||
475 | data->keypressed = 0; | ||
476 | led_trigger_event(data->rxtrigger, LED_OFF); | ||
477 | input_report_key(data->input_dev, data->last_keycode, 0); | ||
478 | input_sync(data->input_dev); | ||
479 | } | ||
480 | |||
481 | spin_unlock_irqrestore(&wbcir_lock, flags); | ||
482 | } | ||
483 | |||
484 | static void | ||
485 | wbcir_keydown(struct wbcir_data *data, u32 scancode, u8 toggle) | ||
486 | { | ||
487 | unsigned int keycode; | ||
488 | |||
489 | /* Repeat? */ | ||
490 | if (data->last_scancode == scancode && | ||
491 | data->last_toggle == toggle && | ||
492 | data->keypressed) | ||
493 | goto set_timer; | ||
494 | data->last_scancode = scancode; | ||
495 | |||
496 | /* Do we need to release an old keypress? */ | ||
497 | if (data->keypressed) { | ||
498 | input_report_key(data->input_dev, data->last_keycode, 0); | ||
499 | input_sync(data->input_dev); | ||
500 | data->keypressed = 0; | ||
501 | } | ||
502 | |||
503 | /* Report scancode */ | ||
504 | input_event(data->input_dev, EV_MSC, MSC_SCAN, (int)scancode); | ||
505 | |||
506 | /* Do we know this scancode? */ | ||
507 | keycode = wbcir_do_getkeycode(data, scancode); | ||
508 | if (keycode == KEY_RESERVED) | ||
509 | goto set_timer; | ||
510 | |||
511 | /* Register a keypress */ | ||
512 | input_report_key(data->input_dev, keycode, 1); | ||
513 | data->keypressed = 1; | ||
514 | data->last_keycode = keycode; | ||
515 | data->last_toggle = toggle; | ||
516 | |||
517 | set_timer: | ||
518 | input_sync(data->input_dev); | ||
519 | led_trigger_event(data->rxtrigger, | ||
520 | data->keypressed ? LED_FULL : LED_OFF); | ||
521 | data->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT); | ||
522 | mod_timer(&data->timer_keyup, data->keyup_jiffies); | ||
523 | } | ||
524 | |||
525 | |||
526 | |||
527 | /***************************************************************************** | ||
528 | * | ||
529 | * IR PARSING FUNCTIONS | ||
530 | * | ||
531 | *****************************************************************************/ | ||
532 | |||
533 | /* Resets all irdata */ | ||
534 | static void | ||
535 | wbcir_reset_irdata(struct wbcir_data *data) | ||
536 | { | ||
537 | memset(data->irdata, 0, sizeof(data->irdata)); | ||
538 | data->irdata_count = 0; | ||
539 | data->irdata_off = 0; | ||
540 | data->irdata_error = 0; | ||
541 | } | ||
542 | |||
543 | /* Adds one bit of irdata */ | ||
544 | static void | ||
545 | add_irdata_bit(struct wbcir_data *data, int set) | ||
546 | { | ||
547 | if (data->irdata_count >= sizeof(data->irdata) * 8) { | ||
548 | data->irdata_error = 1; | ||
549 | return; | ||
550 | } | ||
551 | |||
552 | if (set) | ||
553 | __set_bit(data->irdata_count, data->irdata); | ||
554 | data->irdata_count++; | ||
555 | } | ||
556 | |||
557 | /* Gets count bits of irdata */ | ||
558 | static u16 | ||
559 | get_bits(struct wbcir_data *data, int count) | ||
560 | { | ||
561 | u16 val = 0x0; | ||
562 | |||
563 | if (data->irdata_count - data->irdata_off < count) { | ||
564 | data->irdata_error = 1; | ||
565 | return 0x0; | ||
566 | } | ||
567 | |||
568 | while (count > 0) { | ||
569 | val <<= 1; | ||
570 | if (test_bit(data->irdata_off, data->irdata)) | ||
571 | val |= 0x1; | ||
572 | count--; | ||
573 | data->irdata_off++; | ||
574 | } | ||
575 | |||
576 | return val; | ||
577 | } | ||
578 | |||
579 | /* Reads 16 cells and converts them to a byte */ | ||
580 | static u8 | ||
581 | wbcir_rc6cells_to_byte(struct wbcir_data *data) | ||
582 | { | ||
583 | u16 raw = get_bits(data, 16); | ||
584 | u8 val = 0x00; | ||
585 | int bit; | ||
586 | |||
587 | for (bit = 0; bit < 8; bit++) { | ||
588 | switch (raw & 0x03) { | ||
589 | case 0x01: | ||
590 | break; | ||
591 | case 0x02: | ||
592 | val |= (0x01 << bit); | ||
593 | break; | ||
594 | default: | ||
595 | data->irdata_error = 1; | ||
596 | break; | ||
597 | } | ||
598 | raw >>= 2; | ||
599 | } | ||
600 | |||
601 | return val; | ||
602 | } | ||
603 | |||
604 | /* Decodes a number of bits from raw RC5 data */ | ||
605 | static u8 | ||
606 | wbcir_get_rc5bits(struct wbcir_data *data, unsigned int count) | ||
607 | { | ||
608 | u16 raw = get_bits(data, count * 2); | ||
609 | u8 val = 0x00; | ||
610 | int bit; | ||
611 | |||
612 | for (bit = 0; bit < count; bit++) { | ||
613 | switch (raw & 0x03) { | ||
614 | case 0x01: | ||
615 | val |= (0x01 << bit); | ||
616 | break; | ||
617 | case 0x02: | ||
618 | break; | ||
619 | default: | ||
620 | data->irdata_error = 1; | ||
621 | break; | ||
622 | } | ||
623 | raw >>= 2; | ||
624 | } | ||
625 | |||
626 | return val; | ||
627 | } | ||
628 | |||
629 | static void | ||
630 | wbcir_parse_rc6(struct device *dev, struct wbcir_data *data) | ||
631 | { | ||
632 | /* | ||
633 | * Normal bits are manchester coded as follows: | ||
634 | * cell0 + cell1 = logic "0" | ||
635 | * cell1 + cell0 = logic "1" | ||
636 | * | ||
637 | * The IR pulse has the following components: | ||
638 | * | ||
639 | * Leader - 6 * cell1 - discarded | ||
640 | * Gap - 2 * cell0 - discarded | ||
641 | * Start bit - Normal Coding - always "1" | ||
642 | * Mode Bit 2 - 0 - Normal Coding | ||
643 | * Toggle bit - Normal Coding with double bit time, | ||
644 | * e.g. cell0 + cell0 + cell1 + cell1 | ||
645 | * means logic "0". | ||
646 | * | ||
647 | * The rest depends on the mode, the following modes are known: | ||
648 | * | ||
649 | * MODE 0: | ||
650 | * Address Bit 7 - 0 - Normal Coding | ||
651 | * Command Bit 7 - 0 - Normal Coding | ||
652 | * | ||
653 | * MODE 6: | ||
654 | * The above Toggle Bit is used as a submode bit, 0 = A, 1 = B. | ||
655 | * Submode B is for pointing devices, only remotes using submode A | ||
656 | * are supported. | ||
657 | * | ||
658 | * Customer range bit - 0 => Customer = 7 bits, 0...127 | ||
659 | * 1 => Customer = 15 bits, 32768...65535 | ||
660 | * Customer Bits - Normal Coding | ||
661 | * | ||
662 | * Customer codes are allocated by Philips. The rest of the bits | ||
663 | * are customer dependent. The following is commonly used (and the | ||
664 | * only supported config): | ||
665 | * | ||
666 | * Toggle Bit - Normal Coding | ||
667 | * Address Bit 6 - 0 - Normal Coding | ||
668 | * Command Bit 7 - 0 - Normal Coding | ||
669 | * | ||
670 | * All modes are followed by at least 6 * cell0. | ||
671 | * | ||
672 | * MODE 0 msglen: | ||
673 | * 1 * 2 (start bit) + 3 * 2 (mode) + 2 * 2 (toggle) + | ||
674 | * 8 * 2 (address) + 8 * 2 (command) = | ||
675 | * 44 cells | ||
676 | * | ||
677 | * MODE 6A msglen: | ||
678 | * 1 * 2 (start bit) + 3 * 2 (mode) + 2 * 2 (submode) + | ||
679 | * 1 * 2 (customer range bit) + 7/15 * 2 (customer bits) + | ||
680 | * 1 * 2 (toggle bit) + 7 * 2 (address) + 8 * 2 (command) = | ||
681 | * 60 - 76 cells | ||
682 | */ | ||
683 | u8 mode; | ||
684 | u8 toggle; | ||
685 | u16 customer = 0x0; | ||
686 | u8 address; | ||
687 | u8 command; | ||
688 | u32 scancode; | ||
689 | |||
690 | /* Leader mark */ | ||
691 | while (get_bits(data, 1) && !data->irdata_error) | ||
692 | /* Do nothing */; | ||
693 | |||
694 | /* Leader space */ | ||
695 | if (get_bits(data, 1)) { | ||
696 | dev_dbg(dev, "RC6 - Invalid leader space\n"); | ||
697 | return; | ||
698 | } | ||
699 | |||
700 | /* Start bit */ | ||
701 | if (get_bits(data, 2) != 0x02) { | ||
702 | dev_dbg(dev, "RC6 - Invalid start bit\n"); | ||
703 | return; | ||
704 | } | ||
705 | |||
706 | /* Mode */ | ||
707 | mode = get_bits(data, 6); | ||
708 | switch (mode) { | ||
709 | case 0x15: /* 010101 = b000 */ | ||
710 | mode = 0; | ||
711 | break; | ||
712 | case 0x29: /* 101001 = b110 */ | ||
713 | mode = 6; | ||
714 | break; | ||
715 | default: | ||
716 | dev_dbg(dev, "RC6 - Invalid mode\n"); | ||
717 | return; | ||
718 | } | ||
719 | |||
720 | /* Toggle bit / Submode bit */ | ||
721 | toggle = get_bits(data, 4); | ||
722 | switch (toggle) { | ||
723 | case 0x03: | ||
724 | toggle = 0; | ||
725 | break; | ||
726 | case 0x0C: | ||
727 | toggle = 1; | ||
728 | break; | ||
729 | default: | ||
730 | dev_dbg(dev, "RC6 - Toggle bit error\n"); | ||
731 | break; | ||
732 | } | ||
733 | |||
734 | /* Customer */ | ||
735 | if (mode == 6) { | ||
736 | if (toggle != 0) { | ||
737 | dev_dbg(dev, "RC6B - Not Supported\n"); | ||
738 | return; | ||
739 | } | ||
740 | |||
741 | customer = wbcir_rc6cells_to_byte(data); | ||
742 | |||
743 | if (customer & 0x80) { | ||
744 | /* 15 bit customer value */ | ||
745 | customer <<= 8; | ||
746 | customer |= wbcir_rc6cells_to_byte(data); | ||
747 | } | ||
748 | } | ||
749 | |||
750 | /* Address */ | ||
751 | address = wbcir_rc6cells_to_byte(data); | ||
752 | if (mode == 6) { | ||
753 | toggle = address >> 7; | ||
754 | address &= 0x7F; | ||
755 | } | ||
756 | |||
757 | /* Command */ | ||
758 | command = wbcir_rc6cells_to_byte(data); | ||
759 | |||
760 | /* Create scancode */ | ||
761 | scancode = command; | ||
762 | scancode |= address << 8; | ||
763 | scancode |= customer << 16; | ||
764 | |||
765 | /* Last sanity check */ | ||
766 | if (data->irdata_error) { | ||
767 | dev_dbg(dev, "RC6 - Cell error(s)\n"); | ||
768 | return; | ||
769 | } | ||
770 | |||
771 | dev_info(dev, "IR-RC6 ad 0x%02X cm 0x%02X cu 0x%04X " | ||
772 | "toggle %u mode %u scan 0x%08X\n", | ||
773 | address, | ||
774 | command, | ||
775 | customer, | ||
776 | (unsigned int)toggle, | ||
777 | (unsigned int)mode, | ||
778 | scancode); | ||
779 | |||
780 | wbcir_keydown(data, scancode, toggle); | ||
781 | } | ||
782 | |||
783 | static void | ||
784 | wbcir_parse_rc5(struct device *dev, struct wbcir_data *data) | ||
785 | { | ||
786 | /* | ||
787 | * Bits are manchester coded as follows: | ||
788 | * cell1 + cell0 = logic "0" | ||
789 | * cell0 + cell1 = logic "1" | ||
790 | * (i.e. the reverse of RC6) | ||
791 | * | ||
792 | * Start bit 1 - "1" - discarded | ||
793 | * Start bit 2 - Must be inverted to get command bit 6 | ||
794 | * Toggle bit | ||
795 | * Address Bit 4 - 0 | ||
796 | * Command Bit 5 - 0 | ||
797 | */ | ||
798 | u8 toggle; | ||
799 | u8 address; | ||
800 | u8 command; | ||
801 | u32 scancode; | ||
802 | |||
803 | /* Start bit 1 */ | ||
804 | if (!get_bits(data, 1)) { | ||
805 | dev_dbg(dev, "RC5 - Invalid start bit\n"); | ||
806 | return; | ||
807 | } | ||
808 | |||
809 | /* Start bit 2 */ | ||
810 | if (!wbcir_get_rc5bits(data, 1)) | ||
811 | command = 0x40; | ||
812 | else | ||
813 | command = 0x00; | ||
814 | |||
815 | toggle = wbcir_get_rc5bits(data, 1); | ||
816 | address = wbcir_get_rc5bits(data, 5); | ||
817 | command |= wbcir_get_rc5bits(data, 6); | ||
818 | scancode = address << 7 | command; | ||
819 | |||
820 | /* Last sanity check */ | ||
821 | if (data->irdata_error) { | ||
822 | dev_dbg(dev, "RC5 - Invalid message\n"); | ||
823 | return; | ||
824 | } | ||
825 | |||
826 | dev_dbg(dev, "IR-RC5 ad %u cm %u t %u s %u\n", | ||
827 | (unsigned int)address, | ||
828 | (unsigned int)command, | ||
829 | (unsigned int)toggle, | ||
830 | (unsigned int)scancode); | ||
831 | |||
832 | wbcir_keydown(data, scancode, toggle); | ||
833 | } | ||
834 | |||
835 | static void | ||
836 | wbcir_parse_nec(struct device *dev, struct wbcir_data *data) | ||
837 | { | ||
838 | /* | ||
839 | * Each bit represents 560 us. | ||
840 | * | ||
841 | * Leader - 9 ms burst | ||
842 | * Gap - 4.5 ms silence | ||
843 | * Address1 bit 0 - 7 - Address 1 | ||
844 | * Address2 bit 0 - 7 - Address 2 | ||
845 | * Command1 bit 0 - 7 - Command 1 | ||
846 | * Command2 bit 0 - 7 - Command 2 | ||
847 | * | ||
848 | * Note the bit order! | ||
849 | * | ||
850 | * With the old NEC protocol, Address2 was the inverse of Address1 | ||
851 | * and Command2 was the inverse of Command1 and were used as | ||
852 | * an error check. | ||
853 | * | ||
854 | * With NEC extended, Address1 is the LSB of the Address and | ||
855 | * Address2 is the MSB, Command parsing remains unchanged. | ||
856 | * | ||
857 | * A repeat message is coded as: | ||
858 | * Leader - 9 ms burst | ||
859 | * Gap - 2.25 ms silence | ||
860 | * Repeat - 560 us active | ||
861 | */ | ||
862 | u8 address1; | ||
863 | u8 address2; | ||
864 | u8 command1; | ||
865 | u8 command2; | ||
866 | u16 address; | ||
867 | u32 scancode; | ||
868 | |||
869 | /* Leader mark */ | ||
870 | while (get_bits(data, 1) && !data->irdata_error) | ||
871 | /* Do nothing */; | ||
872 | |||
873 | /* Leader space */ | ||
874 | if (get_bits(data, 4)) { | ||
875 | dev_dbg(dev, "NEC - Invalid leader space\n"); | ||
876 | return; | ||
877 | } | ||
878 | |||
879 | /* Repeat? */ | ||
880 | if (get_bits(data, 1)) { | ||
881 | if (!data->keypressed) { | ||
882 | dev_dbg(dev, "NEC - Stray repeat message\n"); | ||
883 | return; | ||
884 | } | ||
885 | |||
886 | dev_dbg(dev, "IR-NEC repeat s %u\n", | ||
887 | (unsigned int)data->last_scancode); | ||
888 | |||
889 | wbcir_keydown(data, data->last_scancode, data->last_toggle); | ||
890 | return; | ||
891 | } | ||
892 | |||
893 | /* Remaining leader space */ | ||
894 | if (get_bits(data, 3)) { | ||
895 | dev_dbg(dev, "NEC - Invalid leader space\n"); | ||
896 | return; | ||
897 | } | ||
898 | |||
899 | address1 = bitrev8(get_bits(data, 8)); | ||
900 | address2 = bitrev8(get_bits(data, 8)); | ||
901 | command1 = bitrev8(get_bits(data, 8)); | ||
902 | command2 = bitrev8(get_bits(data, 8)); | ||
903 | |||
904 | /* Sanity check */ | ||
905 | if (data->irdata_error) { | ||
906 | dev_dbg(dev, "NEC - Invalid message\n"); | ||
907 | return; | ||
908 | } | ||
909 | |||
910 | /* Check command validity */ | ||
911 | if (command1 != ~command2) { | ||
912 | dev_dbg(dev, "NEC - Command bytes mismatch\n"); | ||
913 | return; | ||
914 | } | ||
915 | |||
916 | /* Check for extended NEC protocol */ | ||
917 | address = address1; | ||
918 | if (address1 != ~address2) | ||
919 | address |= address2 << 8; | ||
920 | |||
921 | scancode = address << 8 | command1; | ||
922 | |||
923 | dev_dbg(dev, "IR-NEC ad %u cm %u s %u\n", | ||
924 | (unsigned int)address, | ||
925 | (unsigned int)command1, | ||
926 | (unsigned int)scancode); | ||
927 | |||
928 | wbcir_keydown(data, scancode, !data->last_toggle); | ||
929 | } | ||
930 | |||
931 | |||
932 | |||
933 | /***************************************************************************** | ||
934 | * | ||
935 | * INTERRUPT FUNCTIONS | ||
936 | * | ||
937 | *****************************************************************************/ | ||
938 | |||
939 | static irqreturn_t | ||
940 | wbcir_irq_handler(int irqno, void *cookie) | ||
941 | { | ||
942 | struct pnp_dev *device = cookie; | ||
943 | struct wbcir_data *data = pnp_get_drvdata(device); | ||
944 | struct device *dev = &device->dev; | ||
945 | u8 status; | ||
946 | unsigned long flags; | ||
947 | u8 irdata[8]; | ||
948 | int i; | ||
949 | unsigned int hw; | ||
950 | |||
951 | spin_lock_irqsave(&wbcir_lock, flags); | ||
952 | |||
953 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
954 | |||
955 | status = inb(data->sbase + WBCIR_REG_SP3_EIR); | ||
956 | |||
957 | if (!(status & (WBCIR_IRQ_RX | WBCIR_IRQ_ERR))) { | ||
958 | spin_unlock_irqrestore(&wbcir_lock, flags); | ||
959 | return IRQ_NONE; | ||
960 | } | ||
961 | |||
962 | if (status & WBCIR_IRQ_ERR) | ||
963 | data->irdata_error = 1; | ||
964 | |||
965 | if (!(status & WBCIR_IRQ_RX)) | ||
966 | goto out; | ||
967 | |||
968 | /* Since RXHDLEV is set, at least 8 bytes are in the FIFO */ | ||
969 | insb(data->sbase + WBCIR_REG_SP3_RXDATA, &irdata[0], 8); | ||
970 | |||
971 | for (i = 0; i < sizeof(irdata); i++) { | ||
972 | hw = hweight8(irdata[i]); | ||
973 | if (hw > 4) | ||
974 | add_irdata_bit(data, 0); | ||
975 | else | ||
976 | add_irdata_bit(data, 1); | ||
977 | |||
978 | if (hw == 8) | ||
979 | data->idle_count++; | ||
980 | else | ||
981 | data->idle_count = 0; | ||
982 | } | ||
983 | |||
984 | if (data->idle_count > WBCIR_MAX_IDLE_BYTES) { | ||
985 | /* Set RXINACTIVE... */ | ||
986 | outb(WBCIR_RX_DISABLE, data->sbase + WBCIR_REG_SP3_ASCR); | ||
987 | |||
988 | /* ...and drain the FIFO */ | ||
989 | while (inb(data->sbase + WBCIR_REG_SP3_LSR) & WBCIR_RX_AVAIL) | ||
990 | inb(data->sbase + WBCIR_REG_SP3_RXDATA); | ||
991 | |||
992 | dev_dbg(dev, "IRDATA:\n"); | ||
993 | for (i = 0; i < data->irdata_count; i += BITS_PER_LONG) | ||
994 | dev_dbg(dev, "0x%08lX\n", data->irdata[i/BITS_PER_LONG]); | ||
995 | |||
996 | switch (protocol) { | ||
997 | case IR_PROTOCOL_RC5: | ||
998 | wbcir_parse_rc5(dev, data); | ||
999 | break; | ||
1000 | case IR_PROTOCOL_RC6: | ||
1001 | wbcir_parse_rc6(dev, data); | ||
1002 | break; | ||
1003 | case IR_PROTOCOL_NEC: | ||
1004 | wbcir_parse_nec(dev, data); | ||
1005 | break; | ||
1006 | } | ||
1007 | |||
1008 | wbcir_reset_irdata(data); | ||
1009 | data->idle_count = 0; | ||
1010 | } | ||
1011 | |||
1012 | out: | ||
1013 | spin_unlock_irqrestore(&wbcir_lock, flags); | ||
1014 | return IRQ_HANDLED; | ||
1015 | } | ||
1016 | |||
1017 | |||
1018 | |||
1019 | /***************************************************************************** | ||
1020 | * | ||
1021 | * SUSPEND/RESUME FUNCTIONS | ||
1022 | * | ||
1023 | *****************************************************************************/ | ||
1024 | |||
1025 | static void | ||
1026 | wbcir_shutdown(struct pnp_dev *device) | ||
1027 | { | ||
1028 | struct device *dev = &device->dev; | ||
1029 | struct wbcir_data *data = pnp_get_drvdata(device); | ||
1030 | int do_wake = 1; | ||
1031 | u8 match[11]; | ||
1032 | u8 mask[11]; | ||
1033 | u8 rc6_csl = 0; | ||
1034 | int i; | ||
1035 | |||
1036 | memset(match, 0, sizeof(match)); | ||
1037 | memset(mask, 0, sizeof(mask)); | ||
1038 | |||
1039 | if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) { | ||
1040 | do_wake = 0; | ||
1041 | goto finish; | ||
1042 | } | ||
1043 | |||
1044 | switch (protocol) { | ||
1045 | case IR_PROTOCOL_RC5: | ||
1046 | if (wake_sc > 0xFFF) { | ||
1047 | do_wake = 0; | ||
1048 | dev_err(dev, "RC5 - Invalid wake scancode\n"); | ||
1049 | break; | ||
1050 | } | ||
1051 | |||
1052 | /* Mask = 13 bits, ex toggle */ | ||
1053 | mask[0] = 0xFF; | ||
1054 | mask[1] = 0x17; | ||
1055 | |||
1056 | match[0] = (wake_sc & 0x003F); /* 6 command bits */ | ||
1057 | match[0] |= (wake_sc & 0x0180) >> 1; /* 2 address bits */ | ||
1058 | match[1] = (wake_sc & 0x0E00) >> 9; /* 3 address bits */ | ||
1059 | if (!(wake_sc & 0x0040)) /* 2nd start bit */ | ||
1060 | match[1] |= 0x10; | ||
1061 | |||
1062 | break; | ||
1063 | |||
1064 | case IR_PROTOCOL_NEC: | ||
1065 | if (wake_sc > 0xFFFFFF) { | ||
1066 | do_wake = 0; | ||
1067 | dev_err(dev, "NEC - Invalid wake scancode\n"); | ||
1068 | break; | ||
1069 | } | ||
1070 | |||
1071 | mask[0] = mask[1] = mask[2] = mask[3] = 0xFF; | ||
1072 | |||
1073 | match[1] = bitrev8((wake_sc & 0xFF)); | ||
1074 | match[0] = ~match[1]; | ||
1075 | |||
1076 | match[3] = bitrev8((wake_sc & 0xFF00) >> 8); | ||
1077 | if (wake_sc > 0xFFFF) | ||
1078 | match[2] = bitrev8((wake_sc & 0xFF0000) >> 16); | ||
1079 | else | ||
1080 | match[2] = ~match[3]; | ||
1081 | |||
1082 | break; | ||
1083 | |||
1084 | case IR_PROTOCOL_RC6: | ||
1085 | |||
1086 | if (wake_rc6mode == 0) { | ||
1087 | if (wake_sc > 0xFFFF) { | ||
1088 | do_wake = 0; | ||
1089 | dev_err(dev, "RC6 - Invalid wake scancode\n"); | ||
1090 | break; | ||
1091 | } | ||
1092 | |||
1093 | /* Command */ | ||
1094 | match[0] = wbcir_to_rc6cells(wake_sc >> 0); | ||
1095 | mask[0] = 0xFF; | ||
1096 | match[1] = wbcir_to_rc6cells(wake_sc >> 4); | ||
1097 | mask[1] = 0xFF; | ||
1098 | |||
1099 | /* Address */ | ||
1100 | match[2] = wbcir_to_rc6cells(wake_sc >> 8); | ||
1101 | mask[2] = 0xFF; | ||
1102 | match[3] = wbcir_to_rc6cells(wake_sc >> 12); | ||
1103 | mask[3] = 0xFF; | ||
1104 | |||
1105 | /* Header */ | ||
1106 | match[4] = 0x50; /* mode1 = mode0 = 0, ignore toggle */ | ||
1107 | mask[4] = 0xF0; | ||
1108 | match[5] = 0x09; /* start bit = 1, mode2 = 0 */ | ||
1109 | mask[5] = 0x0F; | ||
1110 | |||
1111 | rc6_csl = 44; | ||
1112 | |||
1113 | } else if (wake_rc6mode == 6) { | ||
1114 | i = 0; | ||
1115 | |||
1116 | /* Command */ | ||
1117 | match[i] = wbcir_to_rc6cells(wake_sc >> 0); | ||
1118 | mask[i++] = 0xFF; | ||
1119 | match[i] = wbcir_to_rc6cells(wake_sc >> 4); | ||
1120 | mask[i++] = 0xFF; | ||
1121 | |||
1122 | /* Address + Toggle */ | ||
1123 | match[i] = wbcir_to_rc6cells(wake_sc >> 8); | ||
1124 | mask[i++] = 0xFF; | ||
1125 | match[i] = wbcir_to_rc6cells(wake_sc >> 12); | ||
1126 | mask[i++] = 0x3F; | ||
1127 | |||
1128 | /* Customer bits 7 - 0 */ | ||
1129 | match[i] = wbcir_to_rc6cells(wake_sc >> 16); | ||
1130 | mask[i++] = 0xFF; | ||
1131 | match[i] = wbcir_to_rc6cells(wake_sc >> 20); | ||
1132 | mask[i++] = 0xFF; | ||
1133 | |||
1134 | if (wake_sc & 0x80000000) { | ||
1135 | /* Customer range bit and bits 15 - 8 */ | ||
1136 | match[i] = wbcir_to_rc6cells(wake_sc >> 24); | ||
1137 | mask[i++] = 0xFF; | ||
1138 | match[i] = wbcir_to_rc6cells(wake_sc >> 28); | ||
1139 | mask[i++] = 0xFF; | ||
1140 | rc6_csl = 76; | ||
1141 | } else if (wake_sc <= 0x007FFFFF) { | ||
1142 | rc6_csl = 60; | ||
1143 | } else { | ||
1144 | do_wake = 0; | ||
1145 | dev_err(dev, "RC6 - Invalid wake scancode\n"); | ||
1146 | break; | ||
1147 | } | ||
1148 | |||
1149 | /* Header */ | ||
1150 | match[i] = 0x93; /* mode1 = mode0 = 1, submode = 0 */ | ||
1151 | mask[i++] = 0xFF; | ||
1152 | match[i] = 0x0A; /* start bit = 1, mode2 = 1 */ | ||
1153 | mask[i++] = 0x0F; | ||
1154 | |||
1155 | } else { | ||
1156 | do_wake = 0; | ||
1157 | dev_err(dev, "RC6 - Invalid wake mode\n"); | ||
1158 | } | ||
1159 | |||
1160 | break; | ||
1161 | |||
1162 | default: | ||
1163 | do_wake = 0; | ||
1164 | break; | ||
1165 | } | ||
1166 | |||
1167 | finish: | ||
1168 | if (do_wake) { | ||
1169 | /* Set compare and compare mask */ | ||
1170 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX, | ||
1171 | WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0, | ||
1172 | 0x3F); | ||
1173 | outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11); | ||
1174 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX, | ||
1175 | WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0, | ||
1176 | 0x3F); | ||
1177 | outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11); | ||
1178 | |||
1179 | /* RC6 Compare String Len */ | ||
1180 | outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL); | ||
1181 | |||
1182 | /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ | ||
1183 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17); | ||
1184 | |||
1185 | /* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */ | ||
1186 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07); | ||
1187 | |||
1188 | /* Set CEIR_EN */ | ||
1189 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01); | ||
1190 | |||
1191 | } else { | ||
1192 | /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ | ||
1193 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07); | ||
1194 | |||
1195 | /* Clear CEIR_EN */ | ||
1196 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01); | ||
1197 | } | ||
1198 | |||
1199 | /* Disable interrupts */ | ||
1200 | outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); | ||
1201 | } | ||
1202 | |||
1203 | static int | ||
1204 | wbcir_suspend(struct pnp_dev *device, pm_message_t state) | ||
1205 | { | ||
1206 | wbcir_shutdown(device); | ||
1207 | return 0; | ||
1208 | } | ||
1209 | |||
1210 | static int | ||
1211 | wbcir_resume(struct pnp_dev *device) | ||
1212 | { | ||
1213 | struct wbcir_data *data = pnp_get_drvdata(device); | ||
1214 | |||
1215 | /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ | ||
1216 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07); | ||
1217 | |||
1218 | /* Clear CEIR_EN */ | ||
1219 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01); | ||
1220 | |||
1221 | /* Enable interrupts */ | ||
1222 | wbcir_reset_irdata(data); | ||
1223 | outb(WBCIR_IRQ_RX | WBCIR_IRQ_ERR, data->sbase + WBCIR_REG_SP3_IER); | ||
1224 | |||
1225 | return 0; | ||
1226 | } | ||
1227 | |||
1228 | |||
1229 | |||
1230 | /***************************************************************************** | ||
1231 | * | ||
1232 | * SETUP/INIT FUNCTIONS | ||
1233 | * | ||
1234 | *****************************************************************************/ | ||
1235 | |||
1236 | static void | ||
1237 | wbcir_cfg_ceir(struct wbcir_data *data) | ||
1238 | { | ||
1239 | u8 tmp; | ||
1240 | |||
1241 | /* Set PROT_SEL, RX_INV, Clear CEIR_EN (needed for the led) */ | ||
1242 | tmp = protocol << 4; | ||
1243 | if (invert) | ||
1244 | tmp |= 0x08; | ||
1245 | outb(tmp, data->wbase + WBCIR_REG_WCEIR_CTL); | ||
1246 | |||
1247 | /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ | ||
1248 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17); | ||
1249 | |||
1250 | /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ | ||
1251 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07); | ||
1252 | |||
1253 | /* Set RC5 cell time to correspond to 36 kHz */ | ||
1254 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CFG1, 0x4A, 0x7F); | ||
1255 | |||
1256 | /* Set IRTX_INV */ | ||
1257 | if (invert) | ||
1258 | outb(0x04, data->ebase + WBCIR_REG_ECEIR_CCTL); | ||
1259 | else | ||
1260 | outb(0x00, data->ebase + WBCIR_REG_ECEIR_CCTL); | ||
1261 | |||
1262 | /* | ||
1263 | * Clear IR LED, set SP3 clock to 24Mhz | ||
1264 | * set SP3_IRRX_SW to binary 01, helpfully not documented | ||
1265 | */ | ||
1266 | outb(0x10, data->ebase + WBCIR_REG_ECEIR_CTS); | ||
1267 | } | ||
1268 | |||
1269 | static int __devinit | ||
1270 | wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id) | ||
1271 | { | ||
1272 | struct device *dev = &device->dev; | ||
1273 | struct wbcir_data *data; | ||
1274 | int err; | ||
1275 | |||
1276 | if (!(pnp_port_len(device, 0) == EHFUNC_IOMEM_LEN && | ||
1277 | pnp_port_len(device, 1) == WAKEUP_IOMEM_LEN && | ||
1278 | pnp_port_len(device, 2) == SP_IOMEM_LEN)) { | ||
1279 | dev_err(dev, "Invalid resources\n"); | ||
1280 | return -ENODEV; | ||
1281 | } | ||
1282 | |||
1283 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
1284 | if (!data) { | ||
1285 | err = -ENOMEM; | ||
1286 | goto exit; | ||
1287 | } | ||
1288 | |||
1289 | pnp_set_drvdata(device, data); | ||
1290 | |||
1291 | data->ebase = pnp_port_start(device, 0); | ||
1292 | data->wbase = pnp_port_start(device, 1); | ||
1293 | data->sbase = pnp_port_start(device, 2); | ||
1294 | data->irq = pnp_irq(device, 0); | ||
1295 | |||
1296 | if (data->wbase == 0 || data->ebase == 0 || | ||
1297 | data->sbase == 0 || data->irq == 0) { | ||
1298 | err = -ENODEV; | ||
1299 | dev_err(dev, "Invalid resources\n"); | ||
1300 | goto exit_free_data; | ||
1301 | } | ||
1302 | |||
1303 | dev_dbg(&device->dev, "Found device " | ||
1304 | "(w: 0x%lX, e: 0x%lX, s: 0x%lX, i: %u)\n", | ||
1305 | data->wbase, data->ebase, data->sbase, data->irq); | ||
1306 | |||
1307 | if (!request_region(data->wbase, WAKEUP_IOMEM_LEN, DRVNAME)) { | ||
1308 | dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", | ||
1309 | data->wbase, data->wbase + WAKEUP_IOMEM_LEN - 1); | ||
1310 | err = -EBUSY; | ||
1311 | goto exit_free_data; | ||
1312 | } | ||
1313 | |||
1314 | if (!request_region(data->ebase, EHFUNC_IOMEM_LEN, DRVNAME)) { | ||
1315 | dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", | ||
1316 | data->ebase, data->ebase + EHFUNC_IOMEM_LEN - 1); | ||
1317 | err = -EBUSY; | ||
1318 | goto exit_release_wbase; | ||
1319 | } | ||
1320 | |||
1321 | if (!request_region(data->sbase, SP_IOMEM_LEN, DRVNAME)) { | ||
1322 | dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", | ||
1323 | data->sbase, data->sbase + SP_IOMEM_LEN - 1); | ||
1324 | err = -EBUSY; | ||
1325 | goto exit_release_ebase; | ||
1326 | } | ||
1327 | |||
1328 | err = request_irq(data->irq, wbcir_irq_handler, | ||
1329 | IRQF_DISABLED, DRVNAME, device); | ||
1330 | if (err) { | ||
1331 | dev_err(dev, "Failed to claim IRQ %u\n", data->irq); | ||
1332 | err = -EBUSY; | ||
1333 | goto exit_release_sbase; | ||
1334 | } | ||
1335 | |||
1336 | led_trigger_register_simple("cir-tx", &data->txtrigger); | ||
1337 | if (!data->txtrigger) { | ||
1338 | err = -ENOMEM; | ||
1339 | goto exit_free_irq; | ||
1340 | } | ||
1341 | |||
1342 | led_trigger_register_simple("cir-rx", &data->rxtrigger); | ||
1343 | if (!data->rxtrigger) { | ||
1344 | err = -ENOMEM; | ||
1345 | goto exit_unregister_txtrigger; | ||
1346 | } | ||
1347 | |||
1348 | data->led.name = "cir::activity"; | ||
1349 | data->led.default_trigger = "cir-rx"; | ||
1350 | data->led.brightness_set = wbcir_led_brightness_set; | ||
1351 | data->led.brightness_get = wbcir_led_brightness_get; | ||
1352 | err = led_classdev_register(&device->dev, &data->led); | ||
1353 | if (err) | ||
1354 | goto exit_unregister_rxtrigger; | ||
1355 | |||
1356 | data->input_dev = input_allocate_device(); | ||
1357 | if (!data->input_dev) { | ||
1358 | err = -ENOMEM; | ||
1359 | goto exit_unregister_led; | ||
1360 | } | ||
1361 | |||
1362 | data->input_dev->evbit[0] = BIT(EV_KEY); | ||
1363 | data->input_dev->name = WBCIR_NAME; | ||
1364 | data->input_dev->phys = "wbcir/cir0"; | ||
1365 | data->input_dev->id.bustype = BUS_HOST; | ||
1366 | data->input_dev->id.vendor = PCI_VENDOR_ID_WINBOND; | ||
1367 | data->input_dev->id.product = WBCIR_ID_FAMILY; | ||
1368 | data->input_dev->id.version = WBCIR_ID_CHIP; | ||
1369 | data->input_dev->getkeycode = wbcir_getkeycode; | ||
1370 | data->input_dev->setkeycode = wbcir_setkeycode; | ||
1371 | input_set_capability(data->input_dev, EV_MSC, MSC_SCAN); | ||
1372 | input_set_drvdata(data->input_dev, data); | ||
1373 | |||
1374 | err = input_register_device(data->input_dev); | ||
1375 | if (err) | ||
1376 | goto exit_free_input; | ||
1377 | |||
1378 | data->last_scancode = INVALID_SCANCODE; | ||
1379 | INIT_LIST_HEAD(&data->keytable); | ||
1380 | setup_timer(&data->timer_keyup, wbcir_keyup, (unsigned long)data); | ||
1381 | |||
1382 | /* Load default keymaps */ | ||
1383 | if (protocol == IR_PROTOCOL_RC6) { | ||
1384 | int i; | ||
1385 | for (i = 0; i < ARRAY_SIZE(rc6_def_keymap); i++) { | ||
1386 | err = wbcir_setkeycode(data->input_dev, | ||
1387 | (int)rc6_def_keymap[i].scancode, | ||
1388 | (int)rc6_def_keymap[i].keycode); | ||
1389 | if (err) | ||
1390 | goto exit_unregister_keys; | ||
1391 | } | ||
1392 | } | ||
1393 | |||
1394 | device_init_wakeup(&device->dev, 1); | ||
1395 | |||
1396 | wbcir_cfg_ceir(data); | ||
1397 | |||
1398 | /* Disable interrupts */ | ||
1399 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
1400 | outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); | ||
1401 | |||
1402 | /* Enable extended mode */ | ||
1403 | wbcir_select_bank(data, WBCIR_BANK_2); | ||
1404 | outb(WBCIR_EXT_ENABLE, data->sbase + WBCIR_REG_SP3_EXCR1); | ||
1405 | |||
1406 | /* | ||
1407 | * Configure baud generator, IR data will be sampled at | ||
1408 | * a bitrate of: (24Mhz * prescaler) / (divisor * 16). | ||
1409 | * | ||
1410 | * The ECIR registers include a flag to change the | ||
1411 | * 24Mhz clock freq to 48Mhz. | ||
1412 | * | ||
1413 | * It's not documented in the specs, but fifo levels | ||
1414 | * other than 16 seems to be unsupported. | ||
1415 | */ | ||
1416 | |||
1417 | /* prescaler 1.0, tx/rx fifo lvl 16 */ | ||
1418 | outb(0x30, data->sbase + WBCIR_REG_SP3_EXCR2); | ||
1419 | |||
1420 | /* Set baud divisor to generate one byte per bit/cell */ | ||
1421 | switch (protocol) { | ||
1422 | case IR_PROTOCOL_RC5: | ||
1423 | outb(0xA7, data->sbase + WBCIR_REG_SP3_BGDL); | ||
1424 | break; | ||
1425 | case IR_PROTOCOL_RC6: | ||
1426 | outb(0x53, data->sbase + WBCIR_REG_SP3_BGDL); | ||
1427 | break; | ||
1428 | case IR_PROTOCOL_NEC: | ||
1429 | outb(0x69, data->sbase + WBCIR_REG_SP3_BGDL); | ||
1430 | break; | ||
1431 | } | ||
1432 | outb(0x00, data->sbase + WBCIR_REG_SP3_BGDH); | ||
1433 | |||
1434 | /* Set CEIR mode */ | ||
1435 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
1436 | outb(0xC0, data->sbase + WBCIR_REG_SP3_MCR); | ||
1437 | inb(data->sbase + WBCIR_REG_SP3_LSR); /* Clear LSR */ | ||
1438 | inb(data->sbase + WBCIR_REG_SP3_MSR); /* Clear MSR */ | ||
1439 | |||
1440 | /* Disable RX demod, run-length encoding/decoding, set freq span */ | ||
1441 | wbcir_select_bank(data, WBCIR_BANK_7); | ||
1442 | outb(0x10, data->sbase + WBCIR_REG_SP3_RCCFG); | ||
1443 | |||
1444 | /* Disable timer */ | ||
1445 | wbcir_select_bank(data, WBCIR_BANK_4); | ||
1446 | outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR1); | ||
1447 | |||
1448 | /* Enable MSR interrupt, Clear AUX_IRX */ | ||
1449 | wbcir_select_bank(data, WBCIR_BANK_5); | ||
1450 | outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR2); | ||
1451 | |||
1452 | /* Disable CRC */ | ||
1453 | wbcir_select_bank(data, WBCIR_BANK_6); | ||
1454 | outb(0x20, data->sbase + WBCIR_REG_SP3_IRCR3); | ||
1455 | |||
1456 | /* Set RX/TX (de)modulation freq, not really used */ | ||
1457 | wbcir_select_bank(data, WBCIR_BANK_7); | ||
1458 | outb(0xF2, data->sbase + WBCIR_REG_SP3_IRRXDC); | ||
1459 | outb(0x69, data->sbase + WBCIR_REG_SP3_IRTXMC); | ||
1460 | |||
1461 | /* Set invert and pin direction */ | ||
1462 | if (invert) | ||
1463 | outb(0x10, data->sbase + WBCIR_REG_SP3_IRCFG4); | ||
1464 | else | ||
1465 | outb(0x00, data->sbase + WBCIR_REG_SP3_IRCFG4); | ||
1466 | |||
1467 | /* Set FIFO thresholds (RX = 8, TX = 3), reset RX/TX */ | ||
1468 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
1469 | outb(0x97, data->sbase + WBCIR_REG_SP3_FCR); | ||
1470 | |||
1471 | /* Clear AUX status bits */ | ||
1472 | outb(0xE0, data->sbase + WBCIR_REG_SP3_ASCR); | ||
1473 | |||
1474 | /* Enable interrupts */ | ||
1475 | outb(WBCIR_IRQ_RX | WBCIR_IRQ_ERR, data->sbase + WBCIR_REG_SP3_IER); | ||
1476 | |||
1477 | return 0; | ||
1478 | |||
1479 | exit_unregister_keys: | ||
1480 | if (!list_empty(&data->keytable)) { | ||
1481 | struct wbcir_keyentry *key; | ||
1482 | struct wbcir_keyentry *keytmp; | ||
1483 | |||
1484 | list_for_each_entry_safe(key, keytmp, &data->keytable, list) { | ||
1485 | list_del(&key->list); | ||
1486 | kfree(key); | ||
1487 | } | ||
1488 | } | ||
1489 | input_unregister_device(data->input_dev); | ||
1490 | /* Can't call input_free_device on an unregistered device */ | ||
1491 | data->input_dev = NULL; | ||
1492 | exit_free_input: | ||
1493 | input_free_device(data->input_dev); | ||
1494 | exit_unregister_led: | ||
1495 | led_classdev_unregister(&data->led); | ||
1496 | exit_unregister_rxtrigger: | ||
1497 | led_trigger_unregister_simple(data->rxtrigger); | ||
1498 | exit_unregister_txtrigger: | ||
1499 | led_trigger_unregister_simple(data->txtrigger); | ||
1500 | exit_free_irq: | ||
1501 | free_irq(data->irq, device); | ||
1502 | exit_release_sbase: | ||
1503 | release_region(data->sbase, SP_IOMEM_LEN); | ||
1504 | exit_release_ebase: | ||
1505 | release_region(data->ebase, EHFUNC_IOMEM_LEN); | ||
1506 | exit_release_wbase: | ||
1507 | release_region(data->wbase, WAKEUP_IOMEM_LEN); | ||
1508 | exit_free_data: | ||
1509 | kfree(data); | ||
1510 | pnp_set_drvdata(device, NULL); | ||
1511 | exit: | ||
1512 | return err; | ||
1513 | } | ||
1514 | |||
1515 | static void __devexit | ||
1516 | wbcir_remove(struct pnp_dev *device) | ||
1517 | { | ||
1518 | struct wbcir_data *data = pnp_get_drvdata(device); | ||
1519 | struct wbcir_keyentry *key; | ||
1520 | struct wbcir_keyentry *keytmp; | ||
1521 | |||
1522 | /* Disable interrupts */ | ||
1523 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
1524 | outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); | ||
1525 | |||
1526 | del_timer_sync(&data->timer_keyup); | ||
1527 | |||
1528 | free_irq(data->irq, device); | ||
1529 | |||
1530 | /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ | ||
1531 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17); | ||
1532 | |||
1533 | /* Clear CEIR_EN */ | ||
1534 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01); | ||
1535 | |||
1536 | /* Clear BUFF_EN, END_EN, MATCH_EN */ | ||
1537 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07); | ||
1538 | |||
1539 | /* This will generate a keyup event if necessary */ | ||
1540 | input_unregister_device(data->input_dev); | ||
1541 | |||
1542 | led_trigger_unregister_simple(data->rxtrigger); | ||
1543 | led_trigger_unregister_simple(data->txtrigger); | ||
1544 | led_classdev_unregister(&data->led); | ||
1545 | |||
1546 | /* This is ok since &data->led isn't actually used */ | ||
1547 | wbcir_led_brightness_set(&data->led, LED_OFF); | ||
1548 | |||
1549 | release_region(data->wbase, WAKEUP_IOMEM_LEN); | ||
1550 | release_region(data->ebase, EHFUNC_IOMEM_LEN); | ||
1551 | release_region(data->sbase, SP_IOMEM_LEN); | ||
1552 | |||
1553 | list_for_each_entry_safe(key, keytmp, &data->keytable, list) { | ||
1554 | list_del(&key->list); | ||
1555 | kfree(key); | ||
1556 | } | ||
1557 | |||
1558 | kfree(data); | ||
1559 | |||
1560 | pnp_set_drvdata(device, NULL); | ||
1561 | } | ||
1562 | |||
1563 | static const struct pnp_device_id wbcir_ids[] = { | ||
1564 | { "WEC1022", 0 }, | ||
1565 | { "", 0 } | ||
1566 | }; | ||
1567 | MODULE_DEVICE_TABLE(pnp, wbcir_ids); | ||
1568 | |||
1569 | static struct pnp_driver wbcir_driver = { | ||
1570 | .name = WBCIR_NAME, | ||
1571 | .id_table = wbcir_ids, | ||
1572 | .probe = wbcir_probe, | ||
1573 | .remove = __devexit_p(wbcir_remove), | ||
1574 | .suspend = wbcir_suspend, | ||
1575 | .resume = wbcir_resume, | ||
1576 | .shutdown = wbcir_shutdown | ||
1577 | }; | ||
1578 | |||
1579 | static int __init | ||
1580 | wbcir_init(void) | ||
1581 | { | ||
1582 | int ret; | ||
1583 | |||
1584 | switch (protocol) { | ||
1585 | case IR_PROTOCOL_RC5: | ||
1586 | case IR_PROTOCOL_NEC: | ||
1587 | case IR_PROTOCOL_RC6: | ||
1588 | break; | ||
1589 | default: | ||
1590 | printk(KERN_ERR DRVNAME ": Invalid protocol argument\n"); | ||
1591 | return -EINVAL; | ||
1592 | } | ||
1593 | |||
1594 | ret = pnp_register_driver(&wbcir_driver); | ||
1595 | if (ret) | ||
1596 | printk(KERN_ERR DRVNAME ": Unable to register driver\n"); | ||
1597 | |||
1598 | return ret; | ||
1599 | } | ||
1600 | |||
1601 | static void __exit | ||
1602 | wbcir_exit(void) | ||
1603 | { | ||
1604 | pnp_unregister_driver(&wbcir_driver); | ||
1605 | } | ||
1606 | |||
1607 | MODULE_AUTHOR("David Härdeman <david@hardeman.nu>"); | ||
1608 | MODULE_DESCRIPTION("Winbond SuperI/O Consumer IR Driver"); | ||
1609 | MODULE_LICENSE("GPL"); | ||
1610 | |||
1611 | module_init(wbcir_init); | ||
1612 | module_exit(wbcir_exit); | ||
1613 | |||
1614 | |||
diff --git a/drivers/input/misc/wm831x-on.c b/drivers/input/misc/wm831x-on.c new file mode 100644 index 000000000000..ba4f5dd7c60e --- /dev/null +++ b/drivers/input/misc/wm831x-on.c | |||
@@ -0,0 +1,163 @@ | |||
1 | /** | ||
2 | * wm831x-on.c - WM831X ON pin driver | ||
3 | * | ||
4 | * Copyright (C) 2009 Wolfson Microelectronics plc | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of the GNU General | ||
7 | * Public License. See the file "COPYING" in the main directory of this | ||
8 | * archive for more details. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #include <linux/module.h> | ||
21 | #include <linux/init.h> | ||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/errno.h> | ||
24 | #include <linux/input.h> | ||
25 | #include <linux/interrupt.h> | ||
26 | #include <linux/platform_device.h> | ||
27 | #include <linux/workqueue.h> | ||
28 | #include <linux/mfd/wm831x/core.h> | ||
29 | |||
30 | struct wm831x_on { | ||
31 | struct input_dev *dev; | ||
32 | struct delayed_work work; | ||
33 | struct wm831x *wm831x; | ||
34 | }; | ||
35 | |||
36 | /* | ||
37 | * The chip gives us an interrupt when the ON pin is asserted but we | ||
38 | * then need to poll to see when the pin is deasserted. | ||
39 | */ | ||
40 | static void wm831x_poll_on(struct work_struct *work) | ||
41 | { | ||
42 | struct wm831x_on *wm831x_on = container_of(work, struct wm831x_on, | ||
43 | work.work); | ||
44 | struct wm831x *wm831x = wm831x_on->wm831x; | ||
45 | int poll, ret; | ||
46 | |||
47 | ret = wm831x_reg_read(wm831x, WM831X_ON_PIN_CONTROL); | ||
48 | if (ret >= 0) { | ||
49 | poll = !(ret & WM831X_ON_PIN_STS); | ||
50 | |||
51 | input_report_key(wm831x_on->dev, KEY_POWER, poll); | ||
52 | input_sync(wm831x_on->dev); | ||
53 | } else { | ||
54 | dev_err(wm831x->dev, "Failed to read ON status: %d\n", ret); | ||
55 | poll = 1; | ||
56 | } | ||
57 | |||
58 | if (poll) | ||
59 | schedule_delayed_work(&wm831x_on->work, 100); | ||
60 | } | ||
61 | |||
62 | static irqreturn_t wm831x_on_irq(int irq, void *data) | ||
63 | { | ||
64 | struct wm831x_on *wm831x_on = data; | ||
65 | |||
66 | schedule_delayed_work(&wm831x_on->work, 0); | ||
67 | |||
68 | return IRQ_HANDLED; | ||
69 | } | ||
70 | |||
71 | static int __devinit wm831x_on_probe(struct platform_device *pdev) | ||
72 | { | ||
73 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); | ||
74 | struct wm831x_on *wm831x_on; | ||
75 | int irq = platform_get_irq(pdev, 0); | ||
76 | int ret; | ||
77 | |||
78 | wm831x_on = kzalloc(sizeof(struct wm831x_on), GFP_KERNEL); | ||
79 | if (!wm831x_on) { | ||
80 | dev_err(&pdev->dev, "Can't allocate data\n"); | ||
81 | return -ENOMEM; | ||
82 | } | ||
83 | |||
84 | wm831x_on->wm831x = wm831x; | ||
85 | INIT_DELAYED_WORK(&wm831x_on->work, wm831x_poll_on); | ||
86 | |||
87 | wm831x_on->dev = input_allocate_device(); | ||
88 | if (!wm831x_on->dev) { | ||
89 | dev_err(&pdev->dev, "Can't allocate input dev\n"); | ||
90 | ret = -ENOMEM; | ||
91 | goto err; | ||
92 | } | ||
93 | |||
94 | wm831x_on->dev->evbit[0] = BIT_MASK(EV_KEY); | ||
95 | wm831x_on->dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER); | ||
96 | wm831x_on->dev->name = "wm831x_on"; | ||
97 | wm831x_on->dev->phys = "wm831x_on/input0"; | ||
98 | wm831x_on->dev->dev.parent = &pdev->dev; | ||
99 | |||
100 | ret = wm831x_request_irq(wm831x, irq, wm831x_on_irq, | ||
101 | IRQF_TRIGGER_RISING, "wm831x_on", wm831x_on); | ||
102 | if (ret < 0) { | ||
103 | dev_err(&pdev->dev, "Unable to request IRQ: %d\n", ret); | ||
104 | goto err_input_dev; | ||
105 | } | ||
106 | ret = input_register_device(wm831x_on->dev); | ||
107 | if (ret) { | ||
108 | dev_dbg(&pdev->dev, "Can't register input device: %d\n", ret); | ||
109 | goto err_irq; | ||
110 | } | ||
111 | |||
112 | platform_set_drvdata(pdev, wm831x_on); | ||
113 | |||
114 | return 0; | ||
115 | |||
116 | err_irq: | ||
117 | wm831x_free_irq(wm831x, irq, NULL); | ||
118 | err_input_dev: | ||
119 | input_free_device(wm831x_on->dev); | ||
120 | err: | ||
121 | kfree(wm831x_on); | ||
122 | return ret; | ||
123 | } | ||
124 | |||
125 | static int __devexit wm831x_on_remove(struct platform_device *pdev) | ||
126 | { | ||
127 | struct wm831x_on *wm831x_on = platform_get_drvdata(pdev); | ||
128 | int irq = platform_get_irq(pdev, 0); | ||
129 | |||
130 | wm831x_free_irq(wm831x_on->wm831x, irq, wm831x_on); | ||
131 | cancel_delayed_work_sync(&wm831x_on->work); | ||
132 | input_unregister_device(wm831x_on->dev); | ||
133 | kfree(wm831x_on); | ||
134 | |||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | static struct platform_driver wm831x_on_driver = { | ||
139 | .probe = wm831x_on_probe, | ||
140 | .remove = __devexit_p(wm831x_on_remove), | ||
141 | .driver = { | ||
142 | .name = "wm831x-on", | ||
143 | .owner = THIS_MODULE, | ||
144 | }, | ||
145 | }; | ||
146 | |||
147 | static int __init wm831x_on_init(void) | ||
148 | { | ||
149 | return platform_driver_register(&wm831x_on_driver); | ||
150 | } | ||
151 | module_init(wm831x_on_init); | ||
152 | |||
153 | static void __exit wm831x_on_exit(void) | ||
154 | { | ||
155 | platform_driver_unregister(&wm831x_on_driver); | ||
156 | } | ||
157 | module_exit(wm831x_on_exit); | ||
158 | |||
159 | MODULE_ALIAS("platform:wm831x-on"); | ||
160 | MODULE_DESCRIPTION("WM831x ON pin"); | ||
161 | MODULE_LICENSE("GPL"); | ||
162 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
163 | |||
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c index 966b8868f792..a13d80f7da17 100644 --- a/drivers/input/mousedev.c +++ b/drivers/input/mousedev.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #define MOUSEDEV_MINORS 32 | 13 | #define MOUSEDEV_MINORS 32 |
14 | #define MOUSEDEV_MIX 31 | 14 | #define MOUSEDEV_MIX 31 |
15 | 15 | ||
16 | #include <linux/sched.h> | ||
16 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
17 | #include <linux/smp_lock.h> | 18 | #include <linux/smp_lock.h> |
18 | #include <linux/poll.h> | 19 | #include <linux/poll.h> |
diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c index 769ba65a585a..f3876acc3e83 100644 --- a/drivers/input/serio/libps2.c +++ b/drivers/input/serio/libps2.c | |||
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | #include <linux/delay.h> | 14 | #include <linux/delay.h> |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/sched.h> | ||
16 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
17 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
18 | #include <linux/input.h> | 19 | #include <linux/input.h> |
diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c index b03009bb7468..27fdaaffbb40 100644 --- a/drivers/input/serio/serio_raw.c +++ b/drivers/input/serio/serio_raw.c | |||
@@ -9,6 +9,7 @@ | |||
9 | * the Free Software Foundation. | 9 | * the Free Software Foundation. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/sched.h> | ||
12 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
13 | #include <linux/smp_lock.h> | 14 | #include <linux/smp_lock.h> |
14 | #include <linux/poll.h> | 15 | #include <linux/poll.h> |
diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c index b9694b6445d0..6d345112bcb7 100644 --- a/drivers/input/serio/serport.c +++ b/drivers/input/serio/serport.c | |||
@@ -15,6 +15,7 @@ | |||
15 | 15 | ||
16 | #include <asm/uaccess.h> | 16 | #include <asm/uaccess.h> |
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/sched.h> | ||
18 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
19 | #include <linux/module.h> | 20 | #include <linux/module.h> |
20 | #include <linux/init.h> | 21 | #include <linux/init.h> |
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 6dfb0a2b0a7d..8cc453c85ea7 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
@@ -521,4 +521,13 @@ config TOUCHSCREEN_W90X900 | |||
521 | To compile this driver as a module, choose M here: the | 521 | To compile this driver as a module, choose M here: the |
522 | module will be called w90p910_ts. | 522 | module will be called w90p910_ts. |
523 | 523 | ||
524 | config TOUCHSCREEN_PCAP | ||
525 | tristate "Motorola PCAP touchscreen" | ||
526 | depends on EZX_PCAP | ||
527 | help | ||
528 | Say Y here if you have a Motorola EZX telephone and | ||
529 | want to enable support for the built-in touchscreen. | ||
530 | |||
531 | To compile this driver as a module, choose M here: the | ||
532 | module will be called pcap_ts. | ||
524 | endif | 533 | endif |
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index a882ca16506b..15fa62cffc77 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile | |||
@@ -41,3 +41,4 @@ obj-$(CONFIG_TOUCHSCREEN_WM97XX_ATMEL) += atmel-wm97xx.o | |||
41 | obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o | 41 | obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o |
42 | obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o | 42 | obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o |
43 | obj-$(CONFIG_TOUCHSCREEN_W90X900) += w90p910_ts.o | 43 | obj-$(CONFIG_TOUCHSCREEN_W90X900) += w90p910_ts.o |
44 | obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o | ||
diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c index ecaeb7e8e75e..eb83939c705e 100644 --- a/drivers/input/touchscreen/ad7877.c +++ b/drivers/input/touchscreen/ad7877.c | |||
@@ -842,3 +842,4 @@ module_exit(ad7877_exit); | |||
842 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | 842 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); |
843 | MODULE_DESCRIPTION("AD7877 touchscreen Driver"); | 843 | MODULE_DESCRIPTION("AD7877 touchscreen Driver"); |
844 | MODULE_LICENSE("GPL"); | 844 | MODULE_LICENSE("GPL"); |
845 | MODULE_ALIAS("spi:ad7877"); | ||
diff --git a/drivers/input/touchscreen/ad7879.c b/drivers/input/touchscreen/ad7879.c index b965101074ec..c21e6d3a8844 100644 --- a/drivers/input/touchscreen/ad7879.c +++ b/drivers/input/touchscreen/ad7879.c | |||
@@ -781,3 +781,4 @@ module_exit(ad7879_exit); | |||
781 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | 781 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); |
782 | MODULE_DESCRIPTION("AD7879(-1) touchscreen Driver"); | 782 | MODULE_DESCRIPTION("AD7879(-1) touchscreen Driver"); |
783 | MODULE_LICENSE("GPL"); | 783 | MODULE_LICENSE("GPL"); |
784 | MODULE_ALIAS("spi:ad7879"); | ||
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index ba9d38c3f412..09c810999b92 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c | |||
@@ -1256,3 +1256,4 @@ module_exit(ads7846_exit); | |||
1256 | 1256 | ||
1257 | MODULE_DESCRIPTION("ADS7846 TouchScreen Driver"); | 1257 | MODULE_DESCRIPTION("ADS7846 TouchScreen Driver"); |
1258 | MODULE_LICENSE("GPL"); | 1258 | MODULE_LICENSE("GPL"); |
1259 | MODULE_ALIAS("spi:ads7846"); | ||
diff --git a/drivers/input/touchscreen/pcap_ts.c b/drivers/input/touchscreen/pcap_ts.c new file mode 100644 index 000000000000..67fcd33595de --- /dev/null +++ b/drivers/input/touchscreen/pcap_ts.c | |||
@@ -0,0 +1,271 @@ | |||
1 | /* | ||
2 | * Driver for Motorola PCAP2 touchscreen as found in the EZX phone platform. | ||
3 | * | ||
4 | * Copyright (C) 2006 Harald Welte <laforge@openezx.org> | ||
5 | * Copyright (C) 2009 Daniel Ribeiro <drwyrm@gmail.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/fs.h> | ||
16 | #include <linux/string.h> | ||
17 | #include <linux/pm.h> | ||
18 | #include <linux/timer.h> | ||
19 | #include <linux/interrupt.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/input.h> | ||
22 | #include <linux/mfd/ezx-pcap.h> | ||
23 | |||
24 | struct pcap_ts { | ||
25 | struct pcap_chip *pcap; | ||
26 | struct input_dev *input; | ||
27 | struct delayed_work work; | ||
28 | u16 x, y; | ||
29 | u16 pressure; | ||
30 | u8 read_state; | ||
31 | }; | ||
32 | |||
33 | #define SAMPLE_DELAY 20 /* msecs */ | ||
34 | |||
35 | #define X_AXIS_MIN 0 | ||
36 | #define X_AXIS_MAX 1023 | ||
37 | #define Y_AXIS_MAX X_AXIS_MAX | ||
38 | #define Y_AXIS_MIN X_AXIS_MIN | ||
39 | #define PRESSURE_MAX X_AXIS_MAX | ||
40 | #define PRESSURE_MIN X_AXIS_MIN | ||
41 | |||
42 | static void pcap_ts_read_xy(void *data, u16 res[2]) | ||
43 | { | ||
44 | struct pcap_ts *pcap_ts = data; | ||
45 | |||
46 | switch (pcap_ts->read_state) { | ||
47 | case PCAP_ADC_TS_M_PRESSURE: | ||
48 | /* pressure reading is unreliable */ | ||
49 | if (res[0] > PRESSURE_MIN && res[0] < PRESSURE_MAX) | ||
50 | pcap_ts->pressure = res[0]; | ||
51 | pcap_ts->read_state = PCAP_ADC_TS_M_XY; | ||
52 | schedule_delayed_work(&pcap_ts->work, 0); | ||
53 | break; | ||
54 | case PCAP_ADC_TS_M_XY: | ||
55 | pcap_ts->y = res[0]; | ||
56 | pcap_ts->x = res[1]; | ||
57 | if (pcap_ts->x <= X_AXIS_MIN || pcap_ts->x >= X_AXIS_MAX || | ||
58 | pcap_ts->y <= Y_AXIS_MIN || pcap_ts->y >= Y_AXIS_MAX) { | ||
59 | /* pen has been released */ | ||
60 | input_report_abs(pcap_ts->input, ABS_PRESSURE, 0); | ||
61 | input_report_key(pcap_ts->input, BTN_TOUCH, 0); | ||
62 | |||
63 | pcap_ts->read_state = PCAP_ADC_TS_M_STANDBY; | ||
64 | schedule_delayed_work(&pcap_ts->work, 0); | ||
65 | } else { | ||
66 | /* pen is touching the screen */ | ||
67 | input_report_abs(pcap_ts->input, ABS_X, pcap_ts->x); | ||
68 | input_report_abs(pcap_ts->input, ABS_Y, pcap_ts->y); | ||
69 | input_report_key(pcap_ts->input, BTN_TOUCH, 1); | ||
70 | input_report_abs(pcap_ts->input, ABS_PRESSURE, | ||
71 | pcap_ts->pressure); | ||
72 | |||
73 | /* switch back to pressure read mode */ | ||
74 | pcap_ts->read_state = PCAP_ADC_TS_M_PRESSURE; | ||
75 | schedule_delayed_work(&pcap_ts->work, | ||
76 | msecs_to_jiffies(SAMPLE_DELAY)); | ||
77 | } | ||
78 | input_sync(pcap_ts->input); | ||
79 | break; | ||
80 | default: | ||
81 | dev_warn(&pcap_ts->input->dev, | ||
82 | "pcap_ts: Warning, unhandled read_state %d\n", | ||
83 | pcap_ts->read_state); | ||
84 | break; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | static void pcap_ts_work(struct work_struct *work) | ||
89 | { | ||
90 | struct delayed_work *dw = container_of(work, struct delayed_work, work); | ||
91 | struct pcap_ts *pcap_ts = container_of(dw, struct pcap_ts, work); | ||
92 | u8 ch[2]; | ||
93 | |||
94 | pcap_set_ts_bits(pcap_ts->pcap, | ||
95 | pcap_ts->read_state << PCAP_ADC_TS_M_SHIFT); | ||
96 | |||
97 | if (pcap_ts->read_state == PCAP_ADC_TS_M_STANDBY) | ||
98 | return; | ||
99 | |||
100 | /* start adc conversion */ | ||
101 | ch[0] = PCAP_ADC_CH_TS_X1; | ||
102 | ch[1] = PCAP_ADC_CH_TS_Y1; | ||
103 | pcap_adc_async(pcap_ts->pcap, PCAP_ADC_BANK_1, 0, ch, | ||
104 | pcap_ts_read_xy, pcap_ts); | ||
105 | } | ||
106 | |||
107 | static irqreturn_t pcap_ts_event_touch(int pirq, void *data) | ||
108 | { | ||
109 | struct pcap_ts *pcap_ts = data; | ||
110 | |||
111 | if (pcap_ts->read_state == PCAP_ADC_TS_M_STANDBY) { | ||
112 | pcap_ts->read_state = PCAP_ADC_TS_M_PRESSURE; | ||
113 | schedule_delayed_work(&pcap_ts->work, 0); | ||
114 | } | ||
115 | return IRQ_HANDLED; | ||
116 | } | ||
117 | |||
118 | static int pcap_ts_open(struct input_dev *dev) | ||
119 | { | ||
120 | struct pcap_ts *pcap_ts = input_get_drvdata(dev); | ||
121 | |||
122 | pcap_ts->read_state = PCAP_ADC_TS_M_STANDBY; | ||
123 | schedule_delayed_work(&pcap_ts->work, 0); | ||
124 | |||
125 | return 0; | ||
126 | } | ||
127 | |||
128 | static void pcap_ts_close(struct input_dev *dev) | ||
129 | { | ||
130 | struct pcap_ts *pcap_ts = input_get_drvdata(dev); | ||
131 | |||
132 | cancel_delayed_work_sync(&pcap_ts->work); | ||
133 | |||
134 | pcap_ts->read_state = PCAP_ADC_TS_M_NONTS; | ||
135 | pcap_set_ts_bits(pcap_ts->pcap, | ||
136 | pcap_ts->read_state << PCAP_ADC_TS_M_SHIFT); | ||
137 | } | ||
138 | |||
139 | static int __devinit pcap_ts_probe(struct platform_device *pdev) | ||
140 | { | ||
141 | struct input_dev *input_dev; | ||
142 | struct pcap_ts *pcap_ts; | ||
143 | int err = -ENOMEM; | ||
144 | |||
145 | pcap_ts = kzalloc(sizeof(*pcap_ts), GFP_KERNEL); | ||
146 | if (!pcap_ts) | ||
147 | return err; | ||
148 | |||
149 | pcap_ts->pcap = dev_get_drvdata(pdev->dev.parent); | ||
150 | platform_set_drvdata(pdev, pcap_ts); | ||
151 | |||
152 | input_dev = input_allocate_device(); | ||
153 | if (!input_dev) | ||
154 | goto fail; | ||
155 | |||
156 | INIT_DELAYED_WORK(&pcap_ts->work, pcap_ts_work); | ||
157 | |||
158 | pcap_ts->read_state = PCAP_ADC_TS_M_NONTS; | ||
159 | pcap_set_ts_bits(pcap_ts->pcap, | ||
160 | pcap_ts->read_state << PCAP_ADC_TS_M_SHIFT); | ||
161 | |||
162 | pcap_ts->input = input_dev; | ||
163 | input_set_drvdata(input_dev, pcap_ts); | ||
164 | |||
165 | input_dev->name = "pcap-touchscreen"; | ||
166 | input_dev->phys = "pcap_ts/input0"; | ||
167 | input_dev->id.bustype = BUS_HOST; | ||
168 | input_dev->id.vendor = 0x0001; | ||
169 | input_dev->id.product = 0x0002; | ||
170 | input_dev->id.version = 0x0100; | ||
171 | input_dev->dev.parent = &pdev->dev; | ||
172 | input_dev->open = pcap_ts_open; | ||
173 | input_dev->close = pcap_ts_close; | ||
174 | |||
175 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); | ||
176 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); | ||
177 | input_set_abs_params(input_dev, ABS_X, X_AXIS_MIN, X_AXIS_MAX, 0, 0); | ||
178 | input_set_abs_params(input_dev, ABS_Y, Y_AXIS_MIN, Y_AXIS_MAX, 0, 0); | ||
179 | input_set_abs_params(input_dev, ABS_PRESSURE, PRESSURE_MIN, | ||
180 | PRESSURE_MAX, 0, 0); | ||
181 | |||
182 | err = input_register_device(pcap_ts->input); | ||
183 | if (err) | ||
184 | goto fail_allocate; | ||
185 | |||
186 | err = request_irq(pcap_to_irq(pcap_ts->pcap, PCAP_IRQ_TS), | ||
187 | pcap_ts_event_touch, 0, "Touch Screen", pcap_ts); | ||
188 | if (err) | ||
189 | goto fail_register; | ||
190 | |||
191 | return 0; | ||
192 | |||
193 | fail_register: | ||
194 | input_unregister_device(input_dev); | ||
195 | goto fail; | ||
196 | fail_allocate: | ||
197 | input_free_device(input_dev); | ||
198 | fail: | ||
199 | kfree(pcap_ts); | ||
200 | |||
201 | return err; | ||
202 | } | ||
203 | |||
204 | static int __devexit pcap_ts_remove(struct platform_device *pdev) | ||
205 | { | ||
206 | struct pcap_ts *pcap_ts = platform_get_drvdata(pdev); | ||
207 | |||
208 | free_irq(pcap_to_irq(pcap_ts->pcap, PCAP_IRQ_TS), pcap_ts); | ||
209 | cancel_delayed_work_sync(&pcap_ts->work); | ||
210 | |||
211 | input_unregister_device(pcap_ts->input); | ||
212 | |||
213 | kfree(pcap_ts); | ||
214 | |||
215 | return 0; | ||
216 | } | ||
217 | |||
218 | #ifdef CONFIG_PM | ||
219 | static int pcap_ts_suspend(struct device *dev) | ||
220 | { | ||
221 | struct pcap_ts *pcap_ts = dev_get_drvdata(dev); | ||
222 | |||
223 | pcap_set_ts_bits(pcap_ts->pcap, PCAP_ADC_TS_REF_LOWPWR); | ||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | static int pcap_ts_resume(struct device *dev) | ||
228 | { | ||
229 | struct pcap_ts *pcap_ts = dev_get_drvdata(dev); | ||
230 | |||
231 | pcap_set_ts_bits(pcap_ts->pcap, | ||
232 | pcap_ts->read_state << PCAP_ADC_TS_M_SHIFT); | ||
233 | return 0; | ||
234 | } | ||
235 | |||
236 | static struct dev_pm_ops pcap_ts_pm_ops = { | ||
237 | .suspend = pcap_ts_suspend, | ||
238 | .resume = pcap_ts_resume, | ||
239 | }; | ||
240 | #define PCAP_TS_PM_OPS (&pcap_ts_pm_ops) | ||
241 | #else | ||
242 | #define PCAP_TS_PM_OPS NULL | ||
243 | #endif | ||
244 | |||
245 | static struct platform_driver pcap_ts_driver = { | ||
246 | .probe = pcap_ts_probe, | ||
247 | .remove = __devexit_p(pcap_ts_remove), | ||
248 | .driver = { | ||
249 | .name = "pcap-ts", | ||
250 | .owner = THIS_MODULE, | ||
251 | .pm = PCAP_TS_PM_OPS, | ||
252 | }, | ||
253 | }; | ||
254 | |||
255 | static int __init pcap_ts_init(void) | ||
256 | { | ||
257 | return platform_driver_register(&pcap_ts_driver); | ||
258 | } | ||
259 | |||
260 | static void __exit pcap_ts_exit(void) | ||
261 | { | ||
262 | platform_driver_unregister(&pcap_ts_driver); | ||
263 | } | ||
264 | |||
265 | module_init(pcap_ts_init); | ||
266 | module_exit(pcap_ts_exit); | ||
267 | |||
268 | MODULE_DESCRIPTION("Motorola PCAP2 touchscreen driver"); | ||
269 | MODULE_AUTHOR("Daniel Ribeiro / Harald Welte"); | ||
270 | MODULE_LICENSE("GPL"); | ||
271 | MODULE_ALIAS("platform:pcap_ts"); | ||
diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c index 252eb11fe9db..f944918466e5 100644 --- a/drivers/input/touchscreen/wm97xx-core.c +++ b/drivers/input/touchscreen/wm97xx-core.c | |||
@@ -561,6 +561,7 @@ static void wm97xx_ts_input_close(struct input_dev *idev) | |||
561 | static int wm97xx_probe(struct device *dev) | 561 | static int wm97xx_probe(struct device *dev) |
562 | { | 562 | { |
563 | struct wm97xx *wm; | 563 | struct wm97xx *wm; |
564 | struct wm97xx_pdata *pdata = dev->platform_data; | ||
564 | int ret = 0, id = 0; | 565 | int ret = 0, id = 0; |
565 | 566 | ||
566 | wm = kzalloc(sizeof(struct wm97xx), GFP_KERNEL); | 567 | wm = kzalloc(sizeof(struct wm97xx), GFP_KERNEL); |
@@ -658,6 +659,7 @@ static int wm97xx_probe(struct device *dev) | |||
658 | } | 659 | } |
659 | platform_set_drvdata(wm->battery_dev, wm); | 660 | platform_set_drvdata(wm->battery_dev, wm); |
660 | wm->battery_dev->dev.parent = dev; | 661 | wm->battery_dev->dev.parent = dev; |
662 | wm->battery_dev->dev.platform_data = pdata; | ||
661 | ret = platform_device_add(wm->battery_dev); | 663 | ret = platform_device_add(wm->battery_dev); |
662 | if (ret < 0) | 664 | if (ret < 0) |
663 | goto batt_reg_err; | 665 | goto batt_reg_err; |
@@ -671,6 +673,7 @@ static int wm97xx_probe(struct device *dev) | |||
671 | } | 673 | } |
672 | platform_set_drvdata(wm->touch_dev, wm); | 674 | platform_set_drvdata(wm->touch_dev, wm); |
673 | wm->touch_dev->dev.parent = dev; | 675 | wm->touch_dev->dev.parent = dev; |
676 | wm->touch_dev->dev.platform_data = pdata; | ||
674 | ret = platform_device_add(wm->touch_dev); | 677 | ret = platform_device_add(wm->touch_dev); |
675 | if (ret < 0) | 678 | if (ret < 0) |
676 | goto touch_reg_err; | 679 | goto touch_reg_err; |