diff options
Diffstat (limited to 'drivers/input/misc')
30 files changed, 1788 insertions, 1924 deletions
diff --git a/drivers/input/misc/88pm860x_onkey.c b/drivers/input/misc/88pm860x_onkey.c index 4cc82826ea6b..3dca3c14510e 100644 --- a/drivers/input/misc/88pm860x_onkey.c +++ b/drivers/input/misc/88pm860x_onkey.c | |||
@@ -74,7 +74,7 @@ static int __devinit pm860x_onkey_probe(struct platform_device *pdev) | |||
74 | info->chip = chip; | 74 | info->chip = chip; |
75 | info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; | 75 | info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; |
76 | info->dev = &pdev->dev; | 76 | info->dev = &pdev->dev; |
77 | info->irq = irq + chip->irq_base; | 77 | info->irq = irq; |
78 | 78 | ||
79 | info->idev = input_allocate_device(); | 79 | info->idev = input_allocate_device(); |
80 | if (!info->idev) { | 80 | if (!info->idev) { |
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index b49e23379723..45dc6aa62ba4 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig | |||
@@ -22,6 +22,16 @@ config INPUT_88PM860X_ONKEY | |||
22 | To compile this driver as a module, choose M here: the module | 22 | To compile this driver as a module, choose M here: the module |
23 | will be called 88pm860x_onkey. | 23 | will be called 88pm860x_onkey. |
24 | 24 | ||
25 | config INPUT_AB8500_PONKEY | ||
26 | tristate "AB8500 Pon (PowerOn) Key" | ||
27 | depends on AB8500_CORE | ||
28 | help | ||
29 | Say Y here to use the PowerOn Key for ST-Ericsson's AB8500 | ||
30 | Mix-Sig PMIC. | ||
31 | |||
32 | To compile this driver as a module, choose M here: the module | ||
33 | will be called ab8500-ponkey. | ||
34 | |||
25 | config INPUT_AD714X | 35 | config INPUT_AD714X |
26 | tristate "Analog Devices AD714x Capacitance Touch Sensor" | 36 | tristate "Analog Devices AD714x Capacitance Touch Sensor" |
27 | help | 37 | help |
@@ -284,24 +294,6 @@ config INPUT_SGI_BTNS | |||
284 | To compile this driver as a module, choose M here: the | 294 | To compile this driver as a module, choose M here: the |
285 | module will be called sgi_btns. | 295 | module will be called sgi_btns. |
286 | 296 | ||
287 | config INPUT_WINBOND_CIR | ||
288 | tristate "Winbond IR remote control" | ||
289 | depends on X86 && PNP | ||
290 | select NEW_LEDS | ||
291 | select LEDS_CLASS | ||
292 | select LEDS_TRIGGERS | ||
293 | select BITREVERSE | ||
294 | help | ||
295 | Say Y here if you want to use the IR remote functionality found | ||
296 | in some Winbond SuperI/O chips. Currently only the WPCD376I | ||
297 | chip is supported (included in some Intel Media series motherboards). | ||
298 | |||
299 | IR Receive and wake-on-IR from suspend and power-off is currently | ||
300 | supported. | ||
301 | |||
302 | To compile this driver as a module, choose M here: the module will be | ||
303 | called winbond_cir. | ||
304 | |||
305 | config HP_SDC_RTC | 297 | config HP_SDC_RTC |
306 | tristate "HP SDC Real Time Clock" | 298 | tristate "HP SDC Real Time Clock" |
307 | depends on (GSC || HP300) && SERIO | 299 | depends on (GSC || HP300) && SERIO |
@@ -338,6 +330,17 @@ config INPUT_PWM_BEEPER | |||
338 | To compile this driver as a module, choose M here: the module will be | 330 | To compile this driver as a module, choose M here: the module will be |
339 | called pwm-beeper. | 331 | called pwm-beeper. |
340 | 332 | ||
333 | config INPUT_PMIC8XXX_PWRKEY | ||
334 | tristate "PMIC8XXX power key support" | ||
335 | depends on MFD_PM8XXX | ||
336 | help | ||
337 | Say Y here if you want support for the PMIC8XXX power key. | ||
338 | |||
339 | If unsure, say N. | ||
340 | |||
341 | To compile this driver as a module, choose M here: the | ||
342 | module will be called pmic8xxx-pwrkey. | ||
343 | |||
341 | config INPUT_GPIO_ROTARY_ENCODER | 344 | config INPUT_GPIO_ROTARY_ENCODER |
342 | tristate "Rotary encoders connected to GPIO pins" | 345 | tristate "Rotary encoders connected to GPIO pins" |
343 | depends on GPIOLIB && GENERIC_GPIO | 346 | depends on GPIOLIB && GENERIC_GPIO |
@@ -438,4 +441,41 @@ config INPUT_ADXL34X_SPI | |||
438 | To compile this driver as a module, choose M here: the | 441 | To compile this driver as a module, choose M here: the |
439 | module will be called adxl34x-spi. | 442 | module will be called adxl34x-spi. |
440 | 443 | ||
444 | config INPUT_CMA3000 | ||
445 | tristate "VTI CMA3000 Tri-axis accelerometer" | ||
446 | help | ||
447 | Say Y here if you want to use VTI CMA3000_D0x Accelerometer | ||
448 | driver | ||
449 | |||
450 | This driver currently only supports I2C interface to the | ||
451 | controller. Also select the I2C method. | ||
452 | |||
453 | If unsure, say N | ||
454 | |||
455 | To compile this driver as a module, choose M here: the | ||
456 | module will be called cma3000_d0x. | ||
457 | |||
458 | config INPUT_CMA3000_I2C | ||
459 | tristate "Support I2C bus connection" | ||
460 | depends on INPUT_CMA3000 && I2C | ||
461 | help | ||
462 | Say Y here if you want to use VTI CMA3000_D0x Accelerometer | ||
463 | through I2C interface. | ||
464 | |||
465 | To compile this driver as a module, choose M here: the | ||
466 | module will be called cma3000_d0x_i2c. | ||
467 | |||
468 | config INPUT_XEN_KBDDEV_FRONTEND | ||
469 | tristate "Xen virtual keyboard and mouse support" | ||
470 | depends on XEN_FBDEV_FRONTEND | ||
471 | default y | ||
472 | select XEN_XENBUS_FRONTEND | ||
473 | help | ||
474 | This driver implements the front-end of the Xen virtual | ||
475 | keyboard and mouse device driver. It communicates with a back-end | ||
476 | in another domain. | ||
477 | |||
478 | To compile this driver as a module, choose M here: the | ||
479 | module will be called xen-kbdfront. | ||
480 | |||
441 | endif | 481 | endif |
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 19ccca78fa76..38efb2cb182b 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile | |||
@@ -5,6 +5,7 @@ | |||
5 | # Each configuration option enables a list of files. | 5 | # Each configuration option enables a list of files. |
6 | 6 | ||
7 | obj-$(CONFIG_INPUT_88PM860X_ONKEY) += 88pm860x_onkey.o | 7 | obj-$(CONFIG_INPUT_88PM860X_ONKEY) += 88pm860x_onkey.o |
8 | obj-$(CONFIG_INPUT_AB8500_PONKEY) += ab8500-ponkey.o | ||
8 | obj-$(CONFIG_INPUT_AD714X) += ad714x.o | 9 | obj-$(CONFIG_INPUT_AD714X) += ad714x.o |
9 | obj-$(CONFIG_INPUT_AD714X_I2C) += ad714x-i2c.o | 10 | obj-$(CONFIG_INPUT_AD714X_I2C) += ad714x-i2c.o |
10 | obj-$(CONFIG_INPUT_AD714X_SPI) += ad714x-spi.o | 11 | obj-$(CONFIG_INPUT_AD714X_SPI) += ad714x-spi.o |
@@ -17,6 +18,8 @@ obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o | |||
17 | obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o | 18 | obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o |
18 | obj-$(CONFIG_INPUT_BFIN_ROTARY) += bfin_rotary.o | 19 | obj-$(CONFIG_INPUT_BFIN_ROTARY) += bfin_rotary.o |
19 | obj-$(CONFIG_INPUT_CM109) += cm109.o | 20 | obj-$(CONFIG_INPUT_CM109) += cm109.o |
21 | obj-$(CONFIG_INPUT_CMA3000) += cma3000_d0x.o | ||
22 | obj-$(CONFIG_INPUT_CMA3000_I2C) += cma3000_d0x_i2c.o | ||
20 | obj-$(CONFIG_INPUT_COBALT_BTNS) += cobalt_btns.o | 23 | obj-$(CONFIG_INPUT_COBALT_BTNS) += cobalt_btns.o |
21 | obj-$(CONFIG_INPUT_DM355EVM) += dm355evm_keys.o | 24 | obj-$(CONFIG_INPUT_DM355EVM) += dm355evm_keys.o |
22 | obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o | 25 | obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o |
@@ -30,6 +33,7 @@ obj-$(CONFIG_INPUT_PCF8574) += pcf8574_keypad.o | |||
30 | obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o | 33 | obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o |
31 | obj-$(CONFIG_INPUT_POWERMATE) += powermate.o | 34 | obj-$(CONFIG_INPUT_POWERMATE) += powermate.o |
32 | obj-$(CONFIG_INPUT_PWM_BEEPER) += pwm-beeper.o | 35 | obj-$(CONFIG_INPUT_PWM_BEEPER) += pwm-beeper.o |
36 | obj-$(CONFIG_INPUT_PMIC8XXX_PWRKEY) += pmic8xxx-pwrkey.o | ||
33 | obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o | 37 | obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o |
34 | obj-$(CONFIG_INPUT_GPIO_ROTARY_ENCODER) += rotary_encoder.o | 38 | obj-$(CONFIG_INPUT_GPIO_ROTARY_ENCODER) += rotary_encoder.o |
35 | obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o | 39 | obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o |
@@ -37,8 +41,8 @@ obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o | |||
37 | obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o | 41 | obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o |
38 | obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o | 42 | obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o |
39 | obj-$(CONFIG_INPUT_UINPUT) += uinput.o | 43 | obj-$(CONFIG_INPUT_UINPUT) += uinput.o |
40 | obj-$(CONFIG_INPUT_WINBOND_CIR) += winbond-cir.o | ||
41 | obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o | 44 | obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o |
42 | obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o | 45 | obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o |
46 | obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o | ||
43 | obj-$(CONFIG_INPUT_YEALINK) += yealink.o | 47 | obj-$(CONFIG_INPUT_YEALINK) += yealink.o |
44 | 48 | ||
diff --git a/drivers/input/misc/ab8500-ponkey.c b/drivers/input/misc/ab8500-ponkey.c new file mode 100644 index 000000000000..3d3288a78fdc --- /dev/null +++ b/drivers/input/misc/ab8500-ponkey.c | |||
@@ -0,0 +1,157 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson SA 2010 | ||
3 | * | ||
4 | * License Terms: GNU General Public License v2 | ||
5 | * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson | ||
6 | * | ||
7 | * AB8500 Power-On Key handler | ||
8 | */ | ||
9 | |||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/platform_device.h> | ||
13 | #include <linux/input.h> | ||
14 | #include <linux/interrupt.h> | ||
15 | #include <linux/mfd/ab8500.h> | ||
16 | #include <linux/slab.h> | ||
17 | |||
18 | /** | ||
19 | * struct ab8500_ponkey - ab8500 ponkey information | ||
20 | * @input_dev: pointer to input device | ||
21 | * @ab8500: ab8500 parent | ||
22 | * @irq_dbf: irq number for falling transition | ||
23 | * @irq_dbr: irq number for rising transition | ||
24 | */ | ||
25 | struct ab8500_ponkey { | ||
26 | struct input_dev *idev; | ||
27 | struct ab8500 *ab8500; | ||
28 | int irq_dbf; | ||
29 | int irq_dbr; | ||
30 | }; | ||
31 | |||
32 | /* AB8500 gives us an interrupt when ONKEY is held */ | ||
33 | static irqreturn_t ab8500_ponkey_handler(int irq, void *data) | ||
34 | { | ||
35 | struct ab8500_ponkey *ponkey = data; | ||
36 | |||
37 | if (irq == ponkey->irq_dbf) | ||
38 | input_report_key(ponkey->idev, KEY_POWER, true); | ||
39 | else if (irq == ponkey->irq_dbr) | ||
40 | input_report_key(ponkey->idev, KEY_POWER, false); | ||
41 | |||
42 | input_sync(ponkey->idev); | ||
43 | |||
44 | return IRQ_HANDLED; | ||
45 | } | ||
46 | |||
47 | static int __devinit ab8500_ponkey_probe(struct platform_device *pdev) | ||
48 | { | ||
49 | struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); | ||
50 | struct ab8500_ponkey *ponkey; | ||
51 | struct input_dev *input; | ||
52 | int irq_dbf, irq_dbr; | ||
53 | int error; | ||
54 | |||
55 | irq_dbf = platform_get_irq_byname(pdev, "ONKEY_DBF"); | ||
56 | if (irq_dbf < 0) { | ||
57 | dev_err(&pdev->dev, "No IRQ for ONKEY_DBF, error=%d\n", irq_dbf); | ||
58 | return irq_dbf; | ||
59 | } | ||
60 | |||
61 | irq_dbr = platform_get_irq_byname(pdev, "ONKEY_DBR"); | ||
62 | if (irq_dbr < 0) { | ||
63 | dev_err(&pdev->dev, "No IRQ for ONKEY_DBR, error=%d\n", irq_dbr); | ||
64 | return irq_dbr; | ||
65 | } | ||
66 | |||
67 | ponkey = kzalloc(sizeof(struct ab8500_ponkey), GFP_KERNEL); | ||
68 | input = input_allocate_device(); | ||
69 | if (!ponkey || !input) { | ||
70 | error = -ENOMEM; | ||
71 | goto err_free_mem; | ||
72 | } | ||
73 | |||
74 | ponkey->idev = input; | ||
75 | ponkey->ab8500 = ab8500; | ||
76 | ponkey->irq_dbf = irq_dbf; | ||
77 | ponkey->irq_dbr = irq_dbr; | ||
78 | |||
79 | input->name = "AB8500 POn(PowerOn) Key"; | ||
80 | input->dev.parent = &pdev->dev; | ||
81 | |||
82 | input_set_capability(input, EV_KEY, KEY_POWER); | ||
83 | |||
84 | error = request_any_context_irq(ponkey->irq_dbf, ab8500_ponkey_handler, | ||
85 | 0, "ab8500-ponkey-dbf", ponkey); | ||
86 | if (error < 0) { | ||
87 | dev_err(ab8500->dev, "Failed to request dbf IRQ#%d: %d\n", | ||
88 | ponkey->irq_dbf, error); | ||
89 | goto err_free_mem; | ||
90 | } | ||
91 | |||
92 | error = request_any_context_irq(ponkey->irq_dbr, ab8500_ponkey_handler, | ||
93 | 0, "ab8500-ponkey-dbr", ponkey); | ||
94 | if (error < 0) { | ||
95 | dev_err(ab8500->dev, "Failed to request dbr IRQ#%d: %d\n", | ||
96 | ponkey->irq_dbr, error); | ||
97 | goto err_free_dbf_irq; | ||
98 | } | ||
99 | |||
100 | error = input_register_device(ponkey->idev); | ||
101 | if (error) { | ||
102 | dev_err(ab8500->dev, "Can't register input device: %d\n", error); | ||
103 | goto err_free_dbr_irq; | ||
104 | } | ||
105 | |||
106 | platform_set_drvdata(pdev, ponkey); | ||
107 | return 0; | ||
108 | |||
109 | err_free_dbr_irq: | ||
110 | free_irq(ponkey->irq_dbr, ponkey); | ||
111 | err_free_dbf_irq: | ||
112 | free_irq(ponkey->irq_dbf, ponkey); | ||
113 | err_free_mem: | ||
114 | input_free_device(input); | ||
115 | kfree(ponkey); | ||
116 | |||
117 | return error; | ||
118 | } | ||
119 | |||
120 | static int __devexit ab8500_ponkey_remove(struct platform_device *pdev) | ||
121 | { | ||
122 | struct ab8500_ponkey *ponkey = platform_get_drvdata(pdev); | ||
123 | |||
124 | free_irq(ponkey->irq_dbf, ponkey); | ||
125 | free_irq(ponkey->irq_dbr, ponkey); | ||
126 | input_unregister_device(ponkey->idev); | ||
127 | kfree(ponkey); | ||
128 | |||
129 | platform_set_drvdata(pdev, NULL); | ||
130 | |||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | static struct platform_driver ab8500_ponkey_driver = { | ||
135 | .driver = { | ||
136 | .name = "ab8500-poweron-key", | ||
137 | .owner = THIS_MODULE, | ||
138 | }, | ||
139 | .probe = ab8500_ponkey_probe, | ||
140 | .remove = __devexit_p(ab8500_ponkey_remove), | ||
141 | }; | ||
142 | |||
143 | static int __init ab8500_ponkey_init(void) | ||
144 | { | ||
145 | return platform_driver_register(&ab8500_ponkey_driver); | ||
146 | } | ||
147 | module_init(ab8500_ponkey_init); | ||
148 | |||
149 | static void __exit ab8500_ponkey_exit(void) | ||
150 | { | ||
151 | platform_driver_unregister(&ab8500_ponkey_driver); | ||
152 | } | ||
153 | module_exit(ab8500_ponkey_exit); | ||
154 | |||
155 | MODULE_LICENSE("GPL v2"); | ||
156 | MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>"); | ||
157 | MODULE_DESCRIPTION("ST-Ericsson AB8500 Power-ON(Pon) Key driver"); | ||
diff --git a/drivers/input/misc/ad714x-i2c.c b/drivers/input/misc/ad714x-i2c.c index 2bef8fa56c94..e21deb1baa8a 100644 --- a/drivers/input/misc/ad714x-i2c.c +++ b/drivers/input/misc/ad714x-i2c.c | |||
@@ -10,23 +10,23 @@ | |||
10 | #include <linux/i2c.h> | 10 | #include <linux/i2c.h> |
11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
12 | #include <linux/types.h> | 12 | #include <linux/types.h> |
13 | #include <linux/pm.h> | ||
13 | #include "ad714x.h" | 14 | #include "ad714x.h" |
14 | 15 | ||
15 | #ifdef CONFIG_PM | 16 | #ifdef CONFIG_PM |
16 | static int ad714x_i2c_suspend(struct i2c_client *client, pm_message_t message) | 17 | static int ad714x_i2c_suspend(struct device *dev) |
17 | { | 18 | { |
18 | return ad714x_disable(i2c_get_clientdata(client)); | 19 | return ad714x_disable(i2c_get_clientdata(to_i2c_client(dev))); |
19 | } | 20 | } |
20 | 21 | ||
21 | static int ad714x_i2c_resume(struct i2c_client *client) | 22 | static int ad714x_i2c_resume(struct device *dev) |
22 | { | 23 | { |
23 | return ad714x_enable(i2c_get_clientdata(client)); | 24 | return ad714x_enable(i2c_get_clientdata(to_i2c_client(dev))); |
24 | } | 25 | } |
25 | #else | ||
26 | # define ad714x_i2c_suspend NULL | ||
27 | # define ad714x_i2c_resume NULL | ||
28 | #endif | 26 | #endif |
29 | 27 | ||
28 | static SIMPLE_DEV_PM_OPS(ad714x_i2c_pm, ad714x_i2c_suspend, ad714x_i2c_resume); | ||
29 | |||
30 | static int ad714x_i2c_write(struct device *dev, unsigned short reg, | 30 | static int ad714x_i2c_write(struct device *dev, unsigned short reg, |
31 | unsigned short data) | 31 | unsigned short data) |
32 | { | 32 | { |
@@ -114,11 +114,10 @@ MODULE_DEVICE_TABLE(i2c, ad714x_id); | |||
114 | static struct i2c_driver ad714x_i2c_driver = { | 114 | static struct i2c_driver ad714x_i2c_driver = { |
115 | .driver = { | 115 | .driver = { |
116 | .name = "ad714x_captouch", | 116 | .name = "ad714x_captouch", |
117 | .pm = &ad714x_i2c_pm, | ||
117 | }, | 118 | }, |
118 | .probe = ad714x_i2c_probe, | 119 | .probe = ad714x_i2c_probe, |
119 | .remove = __devexit_p(ad714x_i2c_remove), | 120 | .remove = __devexit_p(ad714x_i2c_remove), |
120 | .suspend = ad714x_i2c_suspend, | ||
121 | .resume = ad714x_i2c_resume, | ||
122 | .id_table = ad714x_id, | 121 | .id_table = ad714x_id, |
123 | }; | 122 | }; |
124 | 123 | ||
diff --git a/drivers/input/misc/ad714x-spi.c b/drivers/input/misc/ad714x-spi.c index 7f8dedfd1bfe..4120dd549305 100644 --- a/drivers/input/misc/ad714x-spi.c +++ b/drivers/input/misc/ad714x-spi.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/input.h> /* BUS_I2C */ | 9 | #include <linux/input.h> /* BUS_I2C */ |
10 | #include <linux/module.h> | 10 | #include <linux/module.h> |
11 | #include <linux/spi/spi.h> | 11 | #include <linux/spi/spi.h> |
12 | #include <linux/pm.h> | ||
12 | #include <linux/types.h> | 13 | #include <linux/types.h> |
13 | #include "ad714x.h" | 14 | #include "ad714x.h" |
14 | 15 | ||
@@ -16,20 +17,19 @@ | |||
16 | #define AD714x_SPI_READ BIT(10) | 17 | #define AD714x_SPI_READ BIT(10) |
17 | 18 | ||
18 | #ifdef CONFIG_PM | 19 | #ifdef CONFIG_PM |
19 | static int ad714x_spi_suspend(struct spi_device *spi, pm_message_t message) | 20 | static int ad714x_spi_suspend(struct device *dev) |
20 | { | 21 | { |
21 | return ad714x_disable(spi_get_drvdata(spi)); | 22 | return ad714x_disable(spi_get_drvdata(to_spi_device(dev))); |
22 | } | 23 | } |
23 | 24 | ||
24 | static int ad714x_spi_resume(struct spi_device *spi) | 25 | static int ad714x_spi_resume(struct device *dev) |
25 | { | 26 | { |
26 | return ad714x_enable(spi_get_drvdata(spi)); | 27 | return ad714x_enable(spi_get_drvdata(to_spi_device(dev))); |
27 | } | 28 | } |
28 | #else | ||
29 | # define ad714x_spi_suspend NULL | ||
30 | # define ad714x_spi_resume NULL | ||
31 | #endif | 29 | #endif |
32 | 30 | ||
31 | static SIMPLE_DEV_PM_OPS(ad714x_spi_pm, ad714x_spi_suspend, ad714x_spi_resume); | ||
32 | |||
33 | static int ad714x_spi_read(struct device *dev, unsigned short reg, | 33 | static int ad714x_spi_read(struct device *dev, unsigned short reg, |
34 | unsigned short *data) | 34 | unsigned short *data) |
35 | { | 35 | { |
@@ -79,11 +79,10 @@ static struct spi_driver ad714x_spi_driver = { | |||
79 | .driver = { | 79 | .driver = { |
80 | .name = "ad714x_captouch", | 80 | .name = "ad714x_captouch", |
81 | .owner = THIS_MODULE, | 81 | .owner = THIS_MODULE, |
82 | .pm = &ad714x_spi_pm, | ||
82 | }, | 83 | }, |
83 | .probe = ad714x_spi_probe, | 84 | .probe = ad714x_spi_probe, |
84 | .remove = __devexit_p(ad714x_spi_remove), | 85 | .remove = __devexit_p(ad714x_spi_remove), |
85 | .suspend = ad714x_spi_suspend, | ||
86 | .resume = ad714x_spi_resume, | ||
87 | }; | 86 | }; |
88 | 87 | ||
89 | static __init int ad714x_spi_init(void) | 88 | static __init int ad714x_spi_init(void) |
diff --git a/drivers/input/misc/ad714x.c b/drivers/input/misc/ad714x.c index c431d09e401a..c3a62c42cd28 100644 --- a/drivers/input/misc/ad714x.c +++ b/drivers/input/misc/ad714x.c | |||
@@ -79,13 +79,7 @@ struct ad714x_slider_drv { | |||
79 | struct ad714x_wheel_drv { | 79 | struct ad714x_wheel_drv { |
80 | int abs_pos; | 80 | int abs_pos; |
81 | int flt_pos; | 81 | int flt_pos; |
82 | int pre_mean_value; | ||
83 | int pre_highest_stage; | 82 | int pre_highest_stage; |
84 | int pre_mean_value_no_offset; | ||
85 | int mean_value; | ||
86 | int mean_value_no_offset; | ||
87 | int pos_offset; | ||
88 | int pos_ratio; | ||
89 | int highest_stage; | 83 | int highest_stage; |
90 | enum ad714x_device_state state; | 84 | enum ad714x_device_state state; |
91 | struct input_dev *input; | 85 | struct input_dev *input; |
@@ -158,10 +152,10 @@ static void ad714x_use_com_int(struct ad714x_chip *ad714x, | |||
158 | unsigned short data; | 152 | unsigned short data; |
159 | unsigned short mask; | 153 | unsigned short mask; |
160 | 154 | ||
161 | mask = ((1 << (end_stage + 1)) - 1) - (1 << start_stage); | 155 | mask = ((1 << (end_stage + 1)) - 1) - ((1 << start_stage) - 1); |
162 | 156 | ||
163 | ad714x->read(ad714x->dev, STG_COM_INT_EN_REG, &data); | 157 | ad714x->read(ad714x->dev, STG_COM_INT_EN_REG, &data); |
164 | data |= 1 << start_stage; | 158 | data |= 1 << end_stage; |
165 | ad714x->write(ad714x->dev, STG_COM_INT_EN_REG, data); | 159 | ad714x->write(ad714x->dev, STG_COM_INT_EN_REG, data); |
166 | 160 | ||
167 | ad714x->read(ad714x->dev, STG_HIGH_INT_EN_REG, &data); | 161 | ad714x->read(ad714x->dev, STG_HIGH_INT_EN_REG, &data); |
@@ -175,10 +169,10 @@ static void ad714x_use_thr_int(struct ad714x_chip *ad714x, | |||
175 | unsigned short data; | 169 | unsigned short data; |
176 | unsigned short mask; | 170 | unsigned short mask; |
177 | 171 | ||
178 | mask = ((1 << (end_stage + 1)) - 1) - (1 << start_stage); | 172 | mask = ((1 << (end_stage + 1)) - 1) - ((1 << start_stage) - 1); |
179 | 173 | ||
180 | ad714x->read(ad714x->dev, STG_COM_INT_EN_REG, &data); | 174 | ad714x->read(ad714x->dev, STG_COM_INT_EN_REG, &data); |
181 | data &= ~(1 << start_stage); | 175 | data &= ~(1 << end_stage); |
182 | ad714x->write(ad714x->dev, STG_COM_INT_EN_REG, data); | 176 | ad714x->write(ad714x->dev, STG_COM_INT_EN_REG, data); |
183 | 177 | ||
184 | ad714x->read(ad714x->dev, STG_HIGH_INT_EN_REG, &data); | 178 | ad714x->read(ad714x->dev, STG_HIGH_INT_EN_REG, &data); |
@@ -404,7 +398,6 @@ static void ad714x_slider_state_machine(struct ad714x_chip *ad714x, int idx) | |||
404 | ad714x_slider_cal_highest_stage(ad714x, idx); | 398 | ad714x_slider_cal_highest_stage(ad714x, idx); |
405 | ad714x_slider_cal_abs_pos(ad714x, idx); | 399 | ad714x_slider_cal_abs_pos(ad714x, idx); |
406 | ad714x_slider_cal_flt_pos(ad714x, idx); | 400 | ad714x_slider_cal_flt_pos(ad714x, idx); |
407 | |||
408 | input_report_abs(sw->input, ABS_X, sw->flt_pos); | 401 | input_report_abs(sw->input, ABS_X, sw->flt_pos); |
409 | input_report_key(sw->input, BTN_TOUCH, 1); | 402 | input_report_key(sw->input, BTN_TOUCH, 1); |
410 | } else { | 403 | } else { |
@@ -468,104 +461,41 @@ static void ad714x_wheel_cal_sensor_val(struct ad714x_chip *ad714x, int idx) | |||
468 | /* | 461 | /* |
469 | * When the scroll wheel is activated, we compute the absolute position based | 462 | * When the scroll wheel is activated, we compute the absolute position based |
470 | * on the sensor values. To calculate the position, we first determine the | 463 | * on the sensor values. To calculate the position, we first determine the |
471 | * sensor that has the greatest response among the 8 sensors that constitutes | 464 | * sensor that has the greatest response among the sensors that constitutes |
472 | * the scrollwheel. Then we determined the 2 sensors on either sides of the | 465 | * the scrollwheel. Then we determined the sensors on either sides of the |
473 | * sensor with the highest response and we apply weights to these sensors. The | 466 | * sensor with the highest response and we apply weights to these sensors. The |
474 | * result of this computation gives us the mean value which defined by the | 467 | * result of this computation gives us the mean value. |
475 | * following formula: | ||
476 | * For i= second_before_highest_stage to i= second_after_highest_stage | ||
477 | * v += Sensor response(i)*WEIGHT*(i+3) | ||
478 | * w += Sensor response(i) | ||
479 | * Mean_Value=v/w | ||
480 | * pos_on_scrollwheel = (Mean_Value - position_offset) / position_ratio | ||
481 | */ | 468 | */ |
482 | 469 | ||
483 | #define WEIGHT_FACTOR 30 | ||
484 | /* This constant prevents the "PositionOffset" from reaching a big value */ | ||
485 | #define OFFSET_POSITION_CLAMP 120 | ||
486 | static void ad714x_wheel_cal_abs_pos(struct ad714x_chip *ad714x, int idx) | 470 | static void ad714x_wheel_cal_abs_pos(struct ad714x_chip *ad714x, int idx) |
487 | { | 471 | { |
488 | struct ad714x_wheel_plat *hw = &ad714x->hw->wheel[idx]; | 472 | struct ad714x_wheel_plat *hw = &ad714x->hw->wheel[idx]; |
489 | struct ad714x_wheel_drv *sw = &ad714x->sw->wheel[idx]; | 473 | struct ad714x_wheel_drv *sw = &ad714x->sw->wheel[idx]; |
490 | int stage_num = hw->end_stage - hw->start_stage + 1; | 474 | int stage_num = hw->end_stage - hw->start_stage + 1; |
491 | int second_before, first_before, highest, first_after, second_after; | 475 | int first_before, highest, first_after; |
492 | int a_param, b_param; | 476 | int a_param, b_param; |
493 | 477 | ||
494 | /* Calculate Mean value */ | ||
495 | |||
496 | second_before = (sw->highest_stage + stage_num - 2) % stage_num; | ||
497 | first_before = (sw->highest_stage + stage_num - 1) % stage_num; | 478 | first_before = (sw->highest_stage + stage_num - 1) % stage_num; |
498 | highest = sw->highest_stage; | 479 | highest = sw->highest_stage; |
499 | first_after = (sw->highest_stage + stage_num + 1) % stage_num; | 480 | first_after = (sw->highest_stage + stage_num + 1) % stage_num; |
500 | second_after = (sw->highest_stage + stage_num + 2) % stage_num; | ||
501 | |||
502 | if (((sw->highest_stage - hw->start_stage) > 1) && | ||
503 | ((hw->end_stage - sw->highest_stage) > 1)) { | ||
504 | a_param = ad714x->sensor_val[second_before] * | ||
505 | (second_before - hw->start_stage + 3) + | ||
506 | ad714x->sensor_val[first_before] * | ||
507 | (second_before - hw->start_stage + 3) + | ||
508 | ad714x->sensor_val[highest] * | ||
509 | (second_before - hw->start_stage + 3) + | ||
510 | ad714x->sensor_val[first_after] * | ||
511 | (first_after - hw->start_stage + 3) + | ||
512 | ad714x->sensor_val[second_after] * | ||
513 | (second_after - hw->start_stage + 3); | ||
514 | } else { | ||
515 | a_param = ad714x->sensor_val[second_before] * | ||
516 | (second_before - hw->start_stage + 1) + | ||
517 | ad714x->sensor_val[first_before] * | ||
518 | (second_before - hw->start_stage + 2) + | ||
519 | ad714x->sensor_val[highest] * | ||
520 | (second_before - hw->start_stage + 3) + | ||
521 | ad714x->sensor_val[first_after] * | ||
522 | (first_after - hw->start_stage + 4) + | ||
523 | ad714x->sensor_val[second_after] * | ||
524 | (second_after - hw->start_stage + 5); | ||
525 | } | ||
526 | a_param *= WEIGHT_FACTOR; | ||
527 | 481 | ||
528 | b_param = ad714x->sensor_val[second_before] + | 482 | a_param = ad714x->sensor_val[highest] * |
483 | (highest - hw->start_stage) + | ||
484 | ad714x->sensor_val[first_before] * | ||
485 | (highest - hw->start_stage - 1) + | ||
486 | ad714x->sensor_val[first_after] * | ||
487 | (highest - hw->start_stage + 1); | ||
488 | b_param = ad714x->sensor_val[highest] + | ||
529 | ad714x->sensor_val[first_before] + | 489 | ad714x->sensor_val[first_before] + |
530 | ad714x->sensor_val[highest] + | 490 | ad714x->sensor_val[first_after]; |
531 | ad714x->sensor_val[first_after] + | 491 | |
532 | ad714x->sensor_val[second_after]; | 492 | sw->abs_pos = ((hw->max_coord / (hw->end_stage - hw->start_stage)) * |
533 | 493 | a_param) / b_param; | |
534 | sw->pre_mean_value = sw->mean_value; | 494 | |
535 | sw->mean_value = a_param / b_param; | ||
536 | |||
537 | /* Calculate the offset */ | ||
538 | |||
539 | if ((sw->pre_highest_stage == hw->end_stage) && | ||
540 | (sw->highest_stage == hw->start_stage)) | ||
541 | sw->pos_offset = sw->mean_value; | ||
542 | else if ((sw->pre_highest_stage == hw->start_stage) && | ||
543 | (sw->highest_stage == hw->end_stage)) | ||
544 | sw->pos_offset = sw->pre_mean_value; | ||
545 | |||
546 | if (sw->pos_offset > OFFSET_POSITION_CLAMP) | ||
547 | sw->pos_offset = OFFSET_POSITION_CLAMP; | ||
548 | |||
549 | /* Calculate the mean value without the offset */ | ||
550 | |||
551 | sw->pre_mean_value_no_offset = sw->mean_value_no_offset; | ||
552 | sw->mean_value_no_offset = sw->mean_value - sw->pos_offset; | ||
553 | if (sw->mean_value_no_offset < 0) | ||
554 | sw->mean_value_no_offset = 0; | ||
555 | |||
556 | /* Calculate ratio to scale down to NUMBER_OF_WANTED_POSITIONS */ | ||
557 | |||
558 | if ((sw->pre_highest_stage == hw->end_stage) && | ||
559 | (sw->highest_stage == hw->start_stage)) | ||
560 | sw->pos_ratio = (sw->pre_mean_value_no_offset * 100) / | ||
561 | hw->max_coord; | ||
562 | else if ((sw->pre_highest_stage == hw->start_stage) && | ||
563 | (sw->highest_stage == hw->end_stage)) | ||
564 | sw->pos_ratio = (sw->mean_value_no_offset * 100) / | ||
565 | hw->max_coord; | ||
566 | sw->abs_pos = (sw->mean_value_no_offset * 100) / sw->pos_ratio; | ||
567 | if (sw->abs_pos > hw->max_coord) | 495 | if (sw->abs_pos > hw->max_coord) |
568 | sw->abs_pos = hw->max_coord; | 496 | sw->abs_pos = hw->max_coord; |
497 | else if (sw->abs_pos < 0) | ||
498 | sw->abs_pos = 0; | ||
569 | } | 499 | } |
570 | 500 | ||
571 | static void ad714x_wheel_cal_flt_pos(struct ad714x_chip *ad714x, int idx) | 501 | static void ad714x_wheel_cal_flt_pos(struct ad714x_chip *ad714x, int idx) |
@@ -639,9 +569,8 @@ static void ad714x_wheel_state_machine(struct ad714x_chip *ad714x, int idx) | |||
639 | ad714x_wheel_cal_highest_stage(ad714x, idx); | 569 | ad714x_wheel_cal_highest_stage(ad714x, idx); |
640 | ad714x_wheel_cal_abs_pos(ad714x, idx); | 570 | ad714x_wheel_cal_abs_pos(ad714x, idx); |
641 | ad714x_wheel_cal_flt_pos(ad714x, idx); | 571 | ad714x_wheel_cal_flt_pos(ad714x, idx); |
642 | |||
643 | input_report_abs(sw->input, ABS_WHEEL, | 572 | input_report_abs(sw->input, ABS_WHEEL, |
644 | sw->abs_pos); | 573 | sw->flt_pos); |
645 | input_report_key(sw->input, BTN_TOUCH, 1); | 574 | input_report_key(sw->input, BTN_TOUCH, 1); |
646 | } else { | 575 | } else { |
647 | /* When the user lifts off the sensor, configure | 576 | /* When the user lifts off the sensor, configure |
@@ -1149,6 +1078,8 @@ struct ad714x_chip *ad714x_probe(struct device *dev, u16 bus_type, int irq, | |||
1149 | input[alloc_idx]->id.bustype = bus_type; | 1078 | input[alloc_idx]->id.bustype = bus_type; |
1150 | input[alloc_idx]->id.product = ad714x->product; | 1079 | input[alloc_idx]->id.product = ad714x->product; |
1151 | input[alloc_idx]->id.version = ad714x->version; | 1080 | input[alloc_idx]->id.version = ad714x->version; |
1081 | input[alloc_idx]->name = "ad714x_captouch_slider"; | ||
1082 | input[alloc_idx]->dev.parent = dev; | ||
1152 | 1083 | ||
1153 | error = input_register_device(input[alloc_idx]); | 1084 | error = input_register_device(input[alloc_idx]); |
1154 | if (error) | 1085 | if (error) |
@@ -1179,6 +1110,8 @@ struct ad714x_chip *ad714x_probe(struct device *dev, u16 bus_type, int irq, | |||
1179 | input[alloc_idx]->id.bustype = bus_type; | 1110 | input[alloc_idx]->id.bustype = bus_type; |
1180 | input[alloc_idx]->id.product = ad714x->product; | 1111 | input[alloc_idx]->id.product = ad714x->product; |
1181 | input[alloc_idx]->id.version = ad714x->version; | 1112 | input[alloc_idx]->id.version = ad714x->version; |
1113 | input[alloc_idx]->name = "ad714x_captouch_wheel"; | ||
1114 | input[alloc_idx]->dev.parent = dev; | ||
1182 | 1115 | ||
1183 | error = input_register_device(input[alloc_idx]); | 1116 | error = input_register_device(input[alloc_idx]); |
1184 | if (error) | 1117 | if (error) |
@@ -1212,6 +1145,8 @@ struct ad714x_chip *ad714x_probe(struct device *dev, u16 bus_type, int irq, | |||
1212 | input[alloc_idx]->id.bustype = bus_type; | 1145 | input[alloc_idx]->id.bustype = bus_type; |
1213 | input[alloc_idx]->id.product = ad714x->product; | 1146 | input[alloc_idx]->id.product = ad714x->product; |
1214 | input[alloc_idx]->id.version = ad714x->version; | 1147 | input[alloc_idx]->id.version = ad714x->version; |
1148 | input[alloc_idx]->name = "ad714x_captouch_pad"; | ||
1149 | input[alloc_idx]->dev.parent = dev; | ||
1215 | 1150 | ||
1216 | error = input_register_device(input[alloc_idx]); | 1151 | error = input_register_device(input[alloc_idx]); |
1217 | if (error) | 1152 | if (error) |
@@ -1240,6 +1175,8 @@ struct ad714x_chip *ad714x_probe(struct device *dev, u16 bus_type, int irq, | |||
1240 | input[alloc_idx]->id.bustype = bus_type; | 1175 | input[alloc_idx]->id.bustype = bus_type; |
1241 | input[alloc_idx]->id.product = ad714x->product; | 1176 | input[alloc_idx]->id.product = ad714x->product; |
1242 | input[alloc_idx]->id.version = ad714x->version; | 1177 | input[alloc_idx]->id.version = ad714x->version; |
1178 | input[alloc_idx]->name = "ad714x_captouch_button"; | ||
1179 | input[alloc_idx]->dev.parent = dev; | ||
1243 | 1180 | ||
1244 | error = input_register_device(input[alloc_idx]); | 1181 | error = input_register_device(input[alloc_idx]); |
1245 | if (error) | 1182 | if (error) |
@@ -1249,7 +1186,9 @@ struct ad714x_chip *ad714x_probe(struct device *dev, u16 bus_type, int irq, | |||
1249 | } | 1186 | } |
1250 | 1187 | ||
1251 | error = request_threaded_irq(ad714x->irq, NULL, ad714x_interrupt_thread, | 1188 | error = request_threaded_irq(ad714x->irq, NULL, ad714x_interrupt_thread, |
1252 | IRQF_TRIGGER_FALLING, "ad714x_captouch", ad714x); | 1189 | plat_data->irqflags ? |
1190 | plat_data->irqflags : IRQF_TRIGGER_FALLING, | ||
1191 | "ad714x_captouch", ad714x); | ||
1253 | if (error) { | 1192 | if (error) { |
1254 | dev_err(dev, "can't allocate irq %d\n", ad714x->irq); | 1193 | dev_err(dev, "can't allocate irq %d\n", ad714x->irq); |
1255 | goto err_unreg_dev; | 1194 | goto err_unreg_dev; |
diff --git a/drivers/input/misc/adxl34x-i2c.c b/drivers/input/misc/adxl34x-i2c.c index 0779724af7e7..ccacf2bb06a4 100644 --- a/drivers/input/misc/adxl34x-i2c.c +++ b/drivers/input/misc/adxl34x-i2c.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/i2c.h> | 11 | #include <linux/i2c.h> |
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/types.h> | 13 | #include <linux/types.h> |
14 | #include <linux/pm.h> | ||
14 | #include "adxl34x.h" | 15 | #include "adxl34x.h" |
15 | 16 | ||
16 | static int adxl34x_smbus_read(struct device *dev, unsigned char reg) | 17 | static int adxl34x_smbus_read(struct device *dev, unsigned char reg) |
@@ -105,8 +106,9 @@ static int __devexit adxl34x_i2c_remove(struct i2c_client *client) | |||
105 | } | 106 | } |
106 | 107 | ||
107 | #ifdef CONFIG_PM | 108 | #ifdef CONFIG_PM |
108 | static int adxl34x_i2c_suspend(struct i2c_client *client, pm_message_t message) | 109 | static int adxl34x_i2c_suspend(struct device *dev) |
109 | { | 110 | { |
111 | struct i2c_client *client = to_i2c_client(dev); | ||
110 | struct adxl34x *ac = i2c_get_clientdata(client); | 112 | struct adxl34x *ac = i2c_get_clientdata(client); |
111 | 113 | ||
112 | adxl34x_suspend(ac); | 114 | adxl34x_suspend(ac); |
@@ -114,19 +116,20 @@ static int adxl34x_i2c_suspend(struct i2c_client *client, pm_message_t message) | |||
114 | return 0; | 116 | return 0; |
115 | } | 117 | } |
116 | 118 | ||
117 | static int adxl34x_i2c_resume(struct i2c_client *client) | 119 | static int adxl34x_i2c_resume(struct device *dev) |
118 | { | 120 | { |
121 | struct i2c_client *client = to_i2c_client(dev); | ||
119 | struct adxl34x *ac = i2c_get_clientdata(client); | 122 | struct adxl34x *ac = i2c_get_clientdata(client); |
120 | 123 | ||
121 | adxl34x_resume(ac); | 124 | adxl34x_resume(ac); |
122 | 125 | ||
123 | return 0; | 126 | return 0; |
124 | } | 127 | } |
125 | #else | ||
126 | # define adxl34x_i2c_suspend NULL | ||
127 | # define adxl34x_i2c_resume NULL | ||
128 | #endif | 128 | #endif |
129 | 129 | ||
130 | static SIMPLE_DEV_PM_OPS(adxl34x_i2c_pm, adxl34x_i2c_suspend, | ||
131 | adxl34x_i2c_resume); | ||
132 | |||
130 | static const struct i2c_device_id adxl34x_id[] = { | 133 | static const struct i2c_device_id adxl34x_id[] = { |
131 | { "adxl34x", 0 }, | 134 | { "adxl34x", 0 }, |
132 | { } | 135 | { } |
@@ -138,11 +141,10 @@ static struct i2c_driver adxl34x_driver = { | |||
138 | .driver = { | 141 | .driver = { |
139 | .name = "adxl34x", | 142 | .name = "adxl34x", |
140 | .owner = THIS_MODULE, | 143 | .owner = THIS_MODULE, |
144 | .pm = &adxl34x_i2c_pm, | ||
141 | }, | 145 | }, |
142 | .probe = adxl34x_i2c_probe, | 146 | .probe = adxl34x_i2c_probe, |
143 | .remove = __devexit_p(adxl34x_i2c_remove), | 147 | .remove = __devexit_p(adxl34x_i2c_remove), |
144 | .suspend = adxl34x_i2c_suspend, | ||
145 | .resume = adxl34x_i2c_resume, | ||
146 | .id_table = adxl34x_id, | 148 | .id_table = adxl34x_id, |
147 | }; | 149 | }; |
148 | 150 | ||
diff --git a/drivers/input/misc/adxl34x-spi.c b/drivers/input/misc/adxl34x-spi.c index 782de9e89828..f29de22fdda0 100644 --- a/drivers/input/misc/adxl34x-spi.c +++ b/drivers/input/misc/adxl34x-spi.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/input.h> /* BUS_SPI */ | 10 | #include <linux/input.h> /* BUS_SPI */ |
11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
12 | #include <linux/spi/spi.h> | 12 | #include <linux/spi/spi.h> |
13 | #include <linux/pm.h> | ||
13 | #include <linux/types.h> | 14 | #include <linux/types.h> |
14 | #include "adxl34x.h" | 15 | #include "adxl34x.h" |
15 | 16 | ||
@@ -57,7 +58,7 @@ static int adxl34x_spi_read_block(struct device *dev, | |||
57 | return (status < 0) ? status : 0; | 58 | return (status < 0) ? status : 0; |
58 | } | 59 | } |
59 | 60 | ||
60 | static const struct adxl34x_bus_ops adx134x_spi_bops = { | 61 | static const struct adxl34x_bus_ops adxl34x_spi_bops = { |
61 | .bustype = BUS_SPI, | 62 | .bustype = BUS_SPI, |
62 | .write = adxl34x_spi_write, | 63 | .write = adxl34x_spi_write, |
63 | .read = adxl34x_spi_read, | 64 | .read = adxl34x_spi_read, |
@@ -76,7 +77,7 @@ static int __devinit adxl34x_spi_probe(struct spi_device *spi) | |||
76 | 77 | ||
77 | ac = adxl34x_probe(&spi->dev, spi->irq, | 78 | ac = adxl34x_probe(&spi->dev, spi->irq, |
78 | spi->max_speed_hz > MAX_FREQ_NO_FIFODELAY, | 79 | spi->max_speed_hz > MAX_FREQ_NO_FIFODELAY, |
79 | &adx134x_spi_bops); | 80 | &adxl34x_spi_bops); |
80 | 81 | ||
81 | if (IS_ERR(ac)) | 82 | if (IS_ERR(ac)) |
82 | return PTR_ERR(ac); | 83 | return PTR_ERR(ac); |
@@ -94,8 +95,9 @@ static int __devexit adxl34x_spi_remove(struct spi_device *spi) | |||
94 | } | 95 | } |
95 | 96 | ||
96 | #ifdef CONFIG_PM | 97 | #ifdef CONFIG_PM |
97 | static int adxl34x_spi_suspend(struct spi_device *spi, pm_message_t message) | 98 | static int adxl34x_spi_suspend(struct device *dev) |
98 | { | 99 | { |
100 | struct spi_device *spi = to_spi_device(dev); | ||
99 | struct adxl34x *ac = dev_get_drvdata(&spi->dev); | 101 | struct adxl34x *ac = dev_get_drvdata(&spi->dev); |
100 | 102 | ||
101 | adxl34x_suspend(ac); | 103 | adxl34x_suspend(ac); |
@@ -103,29 +105,29 @@ static int adxl34x_spi_suspend(struct spi_device *spi, pm_message_t message) | |||
103 | return 0; | 105 | return 0; |
104 | } | 106 | } |
105 | 107 | ||
106 | static int adxl34x_spi_resume(struct spi_device *spi) | 108 | static int adxl34x_spi_resume(struct device *dev) |
107 | { | 109 | { |
110 | struct spi_device *spi = to_spi_device(dev); | ||
108 | struct adxl34x *ac = dev_get_drvdata(&spi->dev); | 111 | struct adxl34x *ac = dev_get_drvdata(&spi->dev); |
109 | 112 | ||
110 | adxl34x_resume(ac); | 113 | adxl34x_resume(ac); |
111 | 114 | ||
112 | return 0; | 115 | return 0; |
113 | } | 116 | } |
114 | #else | ||
115 | # define adxl34x_spi_suspend NULL | ||
116 | # define adxl34x_spi_resume NULL | ||
117 | #endif | 117 | #endif |
118 | 118 | ||
119 | static SIMPLE_DEV_PM_OPS(adxl34x_spi_pm, adxl34x_spi_suspend, | ||
120 | adxl34x_spi_resume); | ||
121 | |||
119 | static struct spi_driver adxl34x_driver = { | 122 | static struct spi_driver adxl34x_driver = { |
120 | .driver = { | 123 | .driver = { |
121 | .name = "adxl34x", | 124 | .name = "adxl34x", |
122 | .bus = &spi_bus_type, | 125 | .bus = &spi_bus_type, |
123 | .owner = THIS_MODULE, | 126 | .owner = THIS_MODULE, |
127 | .pm = &adxl34x_spi_pm, | ||
124 | }, | 128 | }, |
125 | .probe = adxl34x_spi_probe, | 129 | .probe = adxl34x_spi_probe, |
126 | .remove = __devexit_p(adxl34x_spi_remove), | 130 | .remove = __devexit_p(adxl34x_spi_remove), |
127 | .suspend = adxl34x_spi_suspend, | ||
128 | .resume = adxl34x_spi_resume, | ||
129 | }; | 131 | }; |
130 | 132 | ||
131 | static int __init adxl34x_spi_init(void) | 133 | static int __init adxl34x_spi_init(void) |
diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c index de5900d50788..144ddbdeb9b3 100644 --- a/drivers/input/misc/adxl34x.c +++ b/drivers/input/misc/adxl34x.c | |||
@@ -716,7 +716,7 @@ struct adxl34x *adxl34x_probe(struct device *dev, int irq, | |||
716 | pdata = dev->platform_data; | 716 | pdata = dev->platform_data; |
717 | if (!pdata) { | 717 | if (!pdata) { |
718 | dev_dbg(dev, | 718 | dev_dbg(dev, |
719 | "No platfrom data: Using default initialization\n"); | 719 | "No platform data: Using default initialization\n"); |
720 | pdata = &adxl34x_default_init; | 720 | pdata = &adxl34x_default_init; |
721 | } | 721 | } |
722 | 722 | ||
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c index 23257652b8e8..1de58e8a1b71 100644 --- a/drivers/input/misc/ati_remote2.c +++ b/drivers/input/misc/ati_remote2.c | |||
@@ -483,51 +483,88 @@ static void ati_remote2_complete_key(struct urb *urb) | |||
483 | } | 483 | } |
484 | 484 | ||
485 | static int ati_remote2_getkeycode(struct input_dev *idev, | 485 | static int ati_remote2_getkeycode(struct input_dev *idev, |
486 | unsigned int scancode, unsigned int *keycode) | 486 | struct input_keymap_entry *ke) |
487 | { | 487 | { |
488 | struct ati_remote2 *ar2 = input_get_drvdata(idev); | 488 | struct ati_remote2 *ar2 = input_get_drvdata(idev); |
489 | unsigned int mode; | 489 | unsigned int mode; |
490 | int index; | 490 | int offset; |
491 | 491 | unsigned int index; | |
492 | mode = scancode >> 8; | 492 | unsigned int scancode; |
493 | if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask)) | 493 | |
494 | return -EINVAL; | 494 | if (ke->flags & INPUT_KEYMAP_BY_INDEX) { |
495 | index = ke->index; | ||
496 | if (index >= ATI_REMOTE2_MODES * | ||
497 | ARRAY_SIZE(ati_remote2_key_table)) | ||
498 | return -EINVAL; | ||
499 | |||
500 | mode = ke->index / ARRAY_SIZE(ati_remote2_key_table); | ||
501 | offset = ke->index % ARRAY_SIZE(ati_remote2_key_table); | ||
502 | scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code; | ||
503 | } else { | ||
504 | if (input_scancode_to_scalar(ke, &scancode)) | ||
505 | return -EINVAL; | ||
506 | |||
507 | mode = scancode >> 8; | ||
508 | if (mode > ATI_REMOTE2_PC) | ||
509 | return -EINVAL; | ||
510 | |||
511 | offset = ati_remote2_lookup(scancode & 0xff); | ||
512 | if (offset < 0) | ||
513 | return -EINVAL; | ||
514 | |||
515 | index = mode * ARRAY_SIZE(ati_remote2_key_table) + offset; | ||
516 | } | ||
495 | 517 | ||
496 | index = ati_remote2_lookup(scancode & 0xFF); | 518 | ke->keycode = ar2->keycode[mode][offset]; |
497 | if (index < 0) | 519 | ke->len = sizeof(scancode); |
498 | return -EINVAL; | 520 | memcpy(&ke->scancode, &scancode, sizeof(scancode)); |
521 | ke->index = index; | ||
499 | 522 | ||
500 | *keycode = ar2->keycode[mode][index]; | ||
501 | return 0; | 523 | return 0; |
502 | } | 524 | } |
503 | 525 | ||
504 | static int ati_remote2_setkeycode(struct input_dev *idev, | 526 | static int ati_remote2_setkeycode(struct input_dev *idev, |
505 | unsigned int scancode, unsigned int keycode) | 527 | const struct input_keymap_entry *ke, |
528 | unsigned int *old_keycode) | ||
506 | { | 529 | { |
507 | struct ati_remote2 *ar2 = input_get_drvdata(idev); | 530 | struct ati_remote2 *ar2 = input_get_drvdata(idev); |
508 | unsigned int mode, old_keycode; | 531 | unsigned int mode; |
509 | int index; | 532 | int offset; |
510 | 533 | unsigned int index; | |
511 | mode = scancode >> 8; | 534 | unsigned int scancode; |
512 | if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask)) | 535 | |
513 | return -EINVAL; | 536 | if (ke->flags & INPUT_KEYMAP_BY_INDEX) { |
514 | 537 | if (ke->index >= ATI_REMOTE2_MODES * | |
515 | index = ati_remote2_lookup(scancode & 0xFF); | 538 | ARRAY_SIZE(ati_remote2_key_table)) |
516 | if (index < 0) | 539 | return -EINVAL; |
517 | return -EINVAL; | 540 | |
541 | mode = ke->index / ARRAY_SIZE(ati_remote2_key_table); | ||
542 | offset = ke->index % ARRAY_SIZE(ati_remote2_key_table); | ||
543 | } else { | ||
544 | if (input_scancode_to_scalar(ke, &scancode)) | ||
545 | return -EINVAL; | ||
546 | |||
547 | mode = scancode >> 8; | ||
548 | if (mode > ATI_REMOTE2_PC) | ||
549 | return -EINVAL; | ||
550 | |||
551 | offset = ati_remote2_lookup(scancode & 0xff); | ||
552 | if (offset < 0) | ||
553 | return -EINVAL; | ||
554 | } | ||
518 | 555 | ||
519 | old_keycode = ar2->keycode[mode][index]; | 556 | *old_keycode = ar2->keycode[mode][offset]; |
520 | ar2->keycode[mode][index] = keycode; | 557 | ar2->keycode[mode][offset] = ke->keycode; |
521 | __set_bit(keycode, idev->keybit); | 558 | __set_bit(ke->keycode, idev->keybit); |
522 | 559 | ||
523 | for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) { | 560 | for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) { |
524 | for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) { | 561 | for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) { |
525 | if (ar2->keycode[mode][index] == old_keycode) | 562 | if (ar2->keycode[mode][index] == *old_keycode) |
526 | return 0; | 563 | return 0; |
527 | } | 564 | } |
528 | } | 565 | } |
529 | 566 | ||
530 | __clear_bit(old_keycode, idev->keybit); | 567 | __clear_bit(*old_keycode, idev->keybit); |
531 | 568 | ||
532 | return 0; | 569 | return 0; |
533 | } | 570 | } |
@@ -700,14 +737,17 @@ static ssize_t ati_remote2_store_channel_mask(struct device *dev, | |||
700 | 737 | ||
701 | mutex_lock(&ati_remote2_mutex); | 738 | mutex_lock(&ati_remote2_mutex); |
702 | 739 | ||
703 | if (mask != ar2->channel_mask && !ati_remote2_setup(ar2, mask)) | 740 | if (mask != ar2->channel_mask) { |
704 | ar2->channel_mask = mask; | 741 | r = ati_remote2_setup(ar2, mask); |
742 | if (!r) | ||
743 | ar2->channel_mask = mask; | ||
744 | } | ||
705 | 745 | ||
706 | mutex_unlock(&ati_remote2_mutex); | 746 | mutex_unlock(&ati_remote2_mutex); |
707 | 747 | ||
708 | usb_autopm_put_interface(ar2->intf[0]); | 748 | usb_autopm_put_interface(ar2->intf[0]); |
709 | 749 | ||
710 | return count; | 750 | return r ? r : count; |
711 | } | 751 | } |
712 | 752 | ||
713 | static ssize_t ati_remote2_show_mode_mask(struct device *dev, | 753 | static ssize_t ati_remote2_show_mode_mask(struct device *dev, |
diff --git a/drivers/input/misc/cm109.c b/drivers/input/misc/cm109.c index 2b0eba6619bd..b09c7d127219 100644 --- a/drivers/input/misc/cm109.c +++ b/drivers/input/misc/cm109.c | |||
@@ -259,7 +259,7 @@ static unsigned short keymap_usbph01(int scancode) | |||
259 | 259 | ||
260 | /* | 260 | /* |
261 | * Keymap for ATCom AU-100 | 261 | * Keymap for ATCom AU-100 |
262 | * http://www.atcom.cn/En_products_AU100.html | 262 | * http://www.atcom.cn/products.html |
263 | * http://www.packetizer.com/products/au100/ | 263 | * http://www.packetizer.com/products/au100/ |
264 | * http://www.voip-info.org/wiki/view/AU-100 | 264 | * http://www.voip-info.org/wiki/view/AU-100 |
265 | * | 265 | * |
diff --git a/drivers/input/misc/cma3000_d0x.c b/drivers/input/misc/cma3000_d0x.c new file mode 100644 index 000000000000..1633b6342267 --- /dev/null +++ b/drivers/input/misc/cma3000_d0x.c | |||
@@ -0,0 +1,398 @@ | |||
1 | /* | ||
2 | * VTI CMA3000_D0x Accelerometer driver | ||
3 | * | ||
4 | * Copyright (C) 2010 Texas Instruments | ||
5 | * Author: Hemanth V <hemanthv@ti.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License version 2 as published by | ||
9 | * the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
14 | * more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along with | ||
17 | * this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | #include <linux/types.h> | ||
21 | #include <linux/interrupt.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/input.h> | ||
25 | #include <linux/input/cma3000.h> | ||
26 | |||
27 | #include "cma3000_d0x.h" | ||
28 | |||
29 | #define CMA3000_WHOAMI 0x00 | ||
30 | #define CMA3000_REVID 0x01 | ||
31 | #define CMA3000_CTRL 0x02 | ||
32 | #define CMA3000_STATUS 0x03 | ||
33 | #define CMA3000_RSTR 0x04 | ||
34 | #define CMA3000_INTSTATUS 0x05 | ||
35 | #define CMA3000_DOUTX 0x06 | ||
36 | #define CMA3000_DOUTY 0x07 | ||
37 | #define CMA3000_DOUTZ 0x08 | ||
38 | #define CMA3000_MDTHR 0x09 | ||
39 | #define CMA3000_MDFFTMR 0x0A | ||
40 | #define CMA3000_FFTHR 0x0B | ||
41 | |||
42 | #define CMA3000_RANGE2G (1 << 7) | ||
43 | #define CMA3000_RANGE8G (0 << 7) | ||
44 | #define CMA3000_BUSI2C (0 << 4) | ||
45 | #define CMA3000_MODEMASK (7 << 1) | ||
46 | #define CMA3000_GRANGEMASK (1 << 7) | ||
47 | |||
48 | #define CMA3000_STATUS_PERR 1 | ||
49 | #define CMA3000_INTSTATUS_FFDET (1 << 2) | ||
50 | |||
51 | /* Settling time delay in ms */ | ||
52 | #define CMA3000_SETDELAY 30 | ||
53 | |||
54 | /* Delay for clearing interrupt in us */ | ||
55 | #define CMA3000_INTDELAY 44 | ||
56 | |||
57 | |||
58 | /* | ||
59 | * Bit weights in mg for bit 0, other bits need | ||
60 | * multipy factor 2^n. Eight bit is the sign bit. | ||
61 | */ | ||
62 | #define BIT_TO_2G 18 | ||
63 | #define BIT_TO_8G 71 | ||
64 | |||
65 | struct cma3000_accl_data { | ||
66 | const struct cma3000_bus_ops *bus_ops; | ||
67 | const struct cma3000_platform_data *pdata; | ||
68 | |||
69 | struct device *dev; | ||
70 | struct input_dev *input_dev; | ||
71 | |||
72 | int bit_to_mg; | ||
73 | int irq; | ||
74 | |||
75 | int g_range; | ||
76 | u8 mode; | ||
77 | |||
78 | struct mutex mutex; | ||
79 | bool opened; | ||
80 | bool suspended; | ||
81 | }; | ||
82 | |||
83 | #define CMA3000_READ(data, reg, msg) \ | ||
84 | (data->bus_ops->read(data->dev, reg, msg)) | ||
85 | #define CMA3000_SET(data, reg, val, msg) \ | ||
86 | ((data)->bus_ops->write(data->dev, reg, val, msg)) | ||
87 | |||
88 | /* | ||
89 | * Conversion for each of the eight modes to g, depending | ||
90 | * on G range i.e 2G or 8G. Some modes always operate in | ||
91 | * 8G. | ||
92 | */ | ||
93 | |||
94 | static int mode_to_mg[8][2] = { | ||
95 | { 0, 0 }, | ||
96 | { BIT_TO_8G, BIT_TO_2G }, | ||
97 | { BIT_TO_8G, BIT_TO_2G }, | ||
98 | { BIT_TO_8G, BIT_TO_8G }, | ||
99 | { BIT_TO_8G, BIT_TO_8G }, | ||
100 | { BIT_TO_8G, BIT_TO_2G }, | ||
101 | { BIT_TO_8G, BIT_TO_2G }, | ||
102 | { 0, 0}, | ||
103 | }; | ||
104 | |||
105 | static void decode_mg(struct cma3000_accl_data *data, int *datax, | ||
106 | int *datay, int *dataz) | ||
107 | { | ||
108 | /* Data in 2's complement, convert to mg */ | ||
109 | *datax = ((s8)*datax) * data->bit_to_mg; | ||
110 | *datay = ((s8)*datay) * data->bit_to_mg; | ||
111 | *dataz = ((s8)*dataz) * data->bit_to_mg; | ||
112 | } | ||
113 | |||
114 | static irqreturn_t cma3000_thread_irq(int irq, void *dev_id) | ||
115 | { | ||
116 | struct cma3000_accl_data *data = dev_id; | ||
117 | int datax, datay, dataz; | ||
118 | u8 ctrl, mode, range, intr_status; | ||
119 | |||
120 | intr_status = CMA3000_READ(data, CMA3000_INTSTATUS, "interrupt status"); | ||
121 | if (intr_status < 0) | ||
122 | return IRQ_NONE; | ||
123 | |||
124 | /* Check if free fall is detected, report immediately */ | ||
125 | if (intr_status & CMA3000_INTSTATUS_FFDET) { | ||
126 | input_report_abs(data->input_dev, ABS_MISC, 1); | ||
127 | input_sync(data->input_dev); | ||
128 | } else { | ||
129 | input_report_abs(data->input_dev, ABS_MISC, 0); | ||
130 | } | ||
131 | |||
132 | datax = CMA3000_READ(data, CMA3000_DOUTX, "X"); | ||
133 | datay = CMA3000_READ(data, CMA3000_DOUTY, "Y"); | ||
134 | dataz = CMA3000_READ(data, CMA3000_DOUTZ, "Z"); | ||
135 | |||
136 | ctrl = CMA3000_READ(data, CMA3000_CTRL, "ctrl"); | ||
137 | mode = (ctrl & CMA3000_MODEMASK) >> 1; | ||
138 | range = (ctrl & CMA3000_GRANGEMASK) >> 7; | ||
139 | |||
140 | data->bit_to_mg = mode_to_mg[mode][range]; | ||
141 | |||
142 | /* Interrupt not for this device */ | ||
143 | if (data->bit_to_mg == 0) | ||
144 | return IRQ_NONE; | ||
145 | |||
146 | /* Decode register values to milli g */ | ||
147 | decode_mg(data, &datax, &datay, &dataz); | ||
148 | |||
149 | input_report_abs(data->input_dev, ABS_X, datax); | ||
150 | input_report_abs(data->input_dev, ABS_Y, datay); | ||
151 | input_report_abs(data->input_dev, ABS_Z, dataz); | ||
152 | input_sync(data->input_dev); | ||
153 | |||
154 | return IRQ_HANDLED; | ||
155 | } | ||
156 | |||
157 | static int cma3000_reset(struct cma3000_accl_data *data) | ||
158 | { | ||
159 | int val; | ||
160 | |||
161 | /* Reset sequence */ | ||
162 | CMA3000_SET(data, CMA3000_RSTR, 0x02, "Reset"); | ||
163 | CMA3000_SET(data, CMA3000_RSTR, 0x0A, "Reset"); | ||
164 | CMA3000_SET(data, CMA3000_RSTR, 0x04, "Reset"); | ||
165 | |||
166 | /* Settling time delay */ | ||
167 | mdelay(10); | ||
168 | |||
169 | val = CMA3000_READ(data, CMA3000_STATUS, "Status"); | ||
170 | if (val < 0) { | ||
171 | dev_err(data->dev, "Reset failed\n"); | ||
172 | return val; | ||
173 | } | ||
174 | |||
175 | if (val & CMA3000_STATUS_PERR) { | ||
176 | dev_err(data->dev, "Parity Error\n"); | ||
177 | return -EIO; | ||
178 | } | ||
179 | |||
180 | return 0; | ||
181 | } | ||
182 | |||
183 | static int cma3000_poweron(struct cma3000_accl_data *data) | ||
184 | { | ||
185 | const struct cma3000_platform_data *pdata = data->pdata; | ||
186 | u8 ctrl = 0; | ||
187 | int ret; | ||
188 | |||
189 | if (data->g_range == CMARANGE_2G) { | ||
190 | ctrl = (data->mode << 1) | CMA3000_RANGE2G; | ||
191 | } else if (data->g_range == CMARANGE_8G) { | ||
192 | ctrl = (data->mode << 1) | CMA3000_RANGE8G; | ||
193 | } else { | ||
194 | dev_info(data->dev, | ||
195 | "Invalid G range specified, assuming 8G\n"); | ||
196 | ctrl = (data->mode << 1) | CMA3000_RANGE8G; | ||
197 | } | ||
198 | |||
199 | ctrl |= data->bus_ops->ctrl_mod; | ||
200 | |||
201 | CMA3000_SET(data, CMA3000_MDTHR, pdata->mdthr, | ||
202 | "Motion Detect Threshold"); | ||
203 | CMA3000_SET(data, CMA3000_MDFFTMR, pdata->mdfftmr, | ||
204 | "Time register"); | ||
205 | CMA3000_SET(data, CMA3000_FFTHR, pdata->ffthr, | ||
206 | "Free fall threshold"); | ||
207 | ret = CMA3000_SET(data, CMA3000_CTRL, ctrl, "Mode setting"); | ||
208 | if (ret < 0) | ||
209 | return -EIO; | ||
210 | |||
211 | msleep(CMA3000_SETDELAY); | ||
212 | |||
213 | return 0; | ||
214 | } | ||
215 | |||
216 | static int cma3000_poweroff(struct cma3000_accl_data *data) | ||
217 | { | ||
218 | int ret; | ||
219 | |||
220 | ret = CMA3000_SET(data, CMA3000_CTRL, CMAMODE_POFF, "Mode setting"); | ||
221 | msleep(CMA3000_SETDELAY); | ||
222 | |||
223 | return ret; | ||
224 | } | ||
225 | |||
226 | static int cma3000_open(struct input_dev *input_dev) | ||
227 | { | ||
228 | struct cma3000_accl_data *data = input_get_drvdata(input_dev); | ||
229 | |||
230 | mutex_lock(&data->mutex); | ||
231 | |||
232 | if (!data->suspended) | ||
233 | cma3000_poweron(data); | ||
234 | |||
235 | data->opened = true; | ||
236 | |||
237 | mutex_unlock(&data->mutex); | ||
238 | |||
239 | return 0; | ||
240 | } | ||
241 | |||
242 | static void cma3000_close(struct input_dev *input_dev) | ||
243 | { | ||
244 | struct cma3000_accl_data *data = input_get_drvdata(input_dev); | ||
245 | |||
246 | mutex_lock(&data->mutex); | ||
247 | |||
248 | if (!data->suspended) | ||
249 | cma3000_poweroff(data); | ||
250 | |||
251 | data->opened = false; | ||
252 | |||
253 | mutex_unlock(&data->mutex); | ||
254 | } | ||
255 | |||
256 | void cma3000_suspend(struct cma3000_accl_data *data) | ||
257 | { | ||
258 | mutex_lock(&data->mutex); | ||
259 | |||
260 | if (!data->suspended && data->opened) | ||
261 | cma3000_poweroff(data); | ||
262 | |||
263 | data->suspended = true; | ||
264 | |||
265 | mutex_unlock(&data->mutex); | ||
266 | } | ||
267 | EXPORT_SYMBOL(cma3000_suspend); | ||
268 | |||
269 | |||
270 | void cma3000_resume(struct cma3000_accl_data *data) | ||
271 | { | ||
272 | mutex_lock(&data->mutex); | ||
273 | |||
274 | if (data->suspended && data->opened) | ||
275 | cma3000_poweron(data); | ||
276 | |||
277 | data->suspended = false; | ||
278 | |||
279 | mutex_unlock(&data->mutex); | ||
280 | } | ||
281 | EXPORT_SYMBOL(cma3000_resume); | ||
282 | |||
283 | struct cma3000_accl_data *cma3000_init(struct device *dev, int irq, | ||
284 | const struct cma3000_bus_ops *bops) | ||
285 | { | ||
286 | const struct cma3000_platform_data *pdata = dev->platform_data; | ||
287 | struct cma3000_accl_data *data; | ||
288 | struct input_dev *input_dev; | ||
289 | int rev; | ||
290 | int error; | ||
291 | |||
292 | if (!pdata) { | ||
293 | dev_err(dev, "platform data not found\n"); | ||
294 | error = -EINVAL; | ||
295 | goto err_out; | ||
296 | } | ||
297 | |||
298 | |||
299 | /* if no IRQ return error */ | ||
300 | if (irq == 0) { | ||
301 | error = -EINVAL; | ||
302 | goto err_out; | ||
303 | } | ||
304 | |||
305 | data = kzalloc(sizeof(struct cma3000_accl_data), GFP_KERNEL); | ||
306 | input_dev = input_allocate_device(); | ||
307 | if (!data || !input_dev) { | ||
308 | error = -ENOMEM; | ||
309 | goto err_free_mem; | ||
310 | } | ||
311 | |||
312 | data->dev = dev; | ||
313 | data->input_dev = input_dev; | ||
314 | data->bus_ops = bops; | ||
315 | data->pdata = pdata; | ||
316 | data->irq = irq; | ||
317 | mutex_init(&data->mutex); | ||
318 | |||
319 | data->mode = pdata->mode; | ||
320 | if (data->mode < CMAMODE_DEFAULT || data->mode > CMAMODE_POFF) { | ||
321 | data->mode = CMAMODE_MOTDET; | ||
322 | dev_warn(dev, | ||
323 | "Invalid mode specified, assuming Motion Detect\n"); | ||
324 | } | ||
325 | |||
326 | data->g_range = pdata->g_range; | ||
327 | if (data->g_range != CMARANGE_2G && data->g_range != CMARANGE_8G) { | ||
328 | dev_info(dev, | ||
329 | "Invalid G range specified, assuming 8G\n"); | ||
330 | data->g_range = CMARANGE_8G; | ||
331 | } | ||
332 | |||
333 | input_dev->name = "cma3000-accelerometer"; | ||
334 | input_dev->id.bustype = bops->bustype; | ||
335 | input_dev->open = cma3000_open; | ||
336 | input_dev->close = cma3000_close; | ||
337 | |||
338 | __set_bit(EV_ABS, input_dev->evbit); | ||
339 | |||
340 | input_set_abs_params(input_dev, ABS_X, | ||
341 | -data->g_range, data->g_range, pdata->fuzz_x, 0); | ||
342 | input_set_abs_params(input_dev, ABS_Y, | ||
343 | -data->g_range, data->g_range, pdata->fuzz_y, 0); | ||
344 | input_set_abs_params(input_dev, ABS_Z, | ||
345 | -data->g_range, data->g_range, pdata->fuzz_z, 0); | ||
346 | input_set_abs_params(input_dev, ABS_MISC, 0, 1, 0, 0); | ||
347 | |||
348 | input_set_drvdata(input_dev, data); | ||
349 | |||
350 | error = cma3000_reset(data); | ||
351 | if (error) | ||
352 | goto err_free_mem; | ||
353 | |||
354 | rev = CMA3000_READ(data, CMA3000_REVID, "Revid"); | ||
355 | if (rev < 0) { | ||
356 | error = rev; | ||
357 | goto err_free_mem; | ||
358 | } | ||
359 | |||
360 | pr_info("CMA3000 Accelerometer: Revision %x\n", rev); | ||
361 | |||
362 | error = request_threaded_irq(irq, NULL, cma3000_thread_irq, | ||
363 | pdata->irqflags | IRQF_ONESHOT, | ||
364 | "cma3000_d0x", data); | ||
365 | if (error) { | ||
366 | dev_err(dev, "request_threaded_irq failed\n"); | ||
367 | goto err_free_mem; | ||
368 | } | ||
369 | |||
370 | error = input_register_device(data->input_dev); | ||
371 | if (error) { | ||
372 | dev_err(dev, "Unable to register input device\n"); | ||
373 | goto err_free_irq; | ||
374 | } | ||
375 | |||
376 | return data; | ||
377 | |||
378 | err_free_irq: | ||
379 | free_irq(irq, data); | ||
380 | err_free_mem: | ||
381 | input_free_device(input_dev); | ||
382 | kfree(data); | ||
383 | err_out: | ||
384 | return ERR_PTR(error); | ||
385 | } | ||
386 | EXPORT_SYMBOL(cma3000_init); | ||
387 | |||
388 | void cma3000_exit(struct cma3000_accl_data *data) | ||
389 | { | ||
390 | free_irq(data->irq, data); | ||
391 | input_unregister_device(data->input_dev); | ||
392 | kfree(data); | ||
393 | } | ||
394 | EXPORT_SYMBOL(cma3000_exit); | ||
395 | |||
396 | MODULE_DESCRIPTION("CMA3000-D0x Accelerometer Driver"); | ||
397 | MODULE_LICENSE("GPL"); | ||
398 | MODULE_AUTHOR("Hemanth V <hemanthv@ti.com>"); | ||
diff --git a/drivers/input/misc/cma3000_d0x.h b/drivers/input/misc/cma3000_d0x.h new file mode 100644 index 000000000000..2304ce306e1c --- /dev/null +++ b/drivers/input/misc/cma3000_d0x.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * VTI CMA3000_D0x Accelerometer driver | ||
3 | * | ||
4 | * Copyright (C) 2010 Texas Instruments | ||
5 | * Author: Hemanth V <hemanthv@ti.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License version 2 as published by | ||
9 | * the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
14 | * more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along with | ||
17 | * this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | #ifndef _INPUT_CMA3000_H | ||
21 | #define _INPUT_CMA3000_H | ||
22 | |||
23 | #include <linux/types.h> | ||
24 | #include <linux/input.h> | ||
25 | |||
26 | struct device; | ||
27 | struct cma3000_accl_data; | ||
28 | |||
29 | struct cma3000_bus_ops { | ||
30 | u16 bustype; | ||
31 | u8 ctrl_mod; | ||
32 | int (*read)(struct device *, u8, char *); | ||
33 | int (*write)(struct device *, u8, u8, char *); | ||
34 | }; | ||
35 | |||
36 | struct cma3000_accl_data *cma3000_init(struct device *dev, int irq, | ||
37 | const struct cma3000_bus_ops *bops); | ||
38 | void cma3000_exit(struct cma3000_accl_data *); | ||
39 | void cma3000_suspend(struct cma3000_accl_data *); | ||
40 | void cma3000_resume(struct cma3000_accl_data *); | ||
41 | |||
42 | #endif | ||
diff --git a/drivers/input/misc/cma3000_d0x_i2c.c b/drivers/input/misc/cma3000_d0x_i2c.c new file mode 100644 index 000000000000..d100cc5c5783 --- /dev/null +++ b/drivers/input/misc/cma3000_d0x_i2c.c | |||
@@ -0,0 +1,143 @@ | |||
1 | /* | ||
2 | * Implements I2C interface for VTI CMA300_D0x Accelerometer driver | ||
3 | * | ||
4 | * Copyright (C) 2010 Texas Instruments | ||
5 | * Author: Hemanth V <hemanthv@ti.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License version 2 as published by | ||
9 | * the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
14 | * more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along with | ||
17 | * this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | #include <linux/module.h> | ||
21 | #include <linux/i2c.h> | ||
22 | #include <linux/input/cma3000.h> | ||
23 | #include "cma3000_d0x.h" | ||
24 | |||
25 | static int cma3000_i2c_set(struct device *dev, | ||
26 | u8 reg, u8 val, char *msg) | ||
27 | { | ||
28 | struct i2c_client *client = to_i2c_client(dev); | ||
29 | int ret; | ||
30 | |||
31 | ret = i2c_smbus_write_byte_data(client, reg, val); | ||
32 | if (ret < 0) | ||
33 | dev_err(&client->dev, | ||
34 | "%s failed (%s, %d)\n", __func__, msg, ret); | ||
35 | return ret; | ||
36 | } | ||
37 | |||
38 | static int cma3000_i2c_read(struct device *dev, u8 reg, char *msg) | ||
39 | { | ||
40 | struct i2c_client *client = to_i2c_client(dev); | ||
41 | int ret; | ||
42 | |||
43 | ret = i2c_smbus_read_byte_data(client, reg); | ||
44 | if (ret < 0) | ||
45 | dev_err(&client->dev, | ||
46 | "%s failed (%s, %d)\n", __func__, msg, ret); | ||
47 | return ret; | ||
48 | } | ||
49 | |||
50 | static const struct cma3000_bus_ops cma3000_i2c_bops = { | ||
51 | .bustype = BUS_I2C, | ||
52 | #define CMA3000_BUSI2C (0 << 4) | ||
53 | .ctrl_mod = CMA3000_BUSI2C, | ||
54 | .read = cma3000_i2c_read, | ||
55 | .write = cma3000_i2c_set, | ||
56 | }; | ||
57 | |||
58 | static int __devinit cma3000_i2c_probe(struct i2c_client *client, | ||
59 | const struct i2c_device_id *id) | ||
60 | { | ||
61 | struct cma3000_accl_data *data; | ||
62 | |||
63 | data = cma3000_init(&client->dev, client->irq, &cma3000_i2c_bops); | ||
64 | if (IS_ERR(data)) | ||
65 | return PTR_ERR(data); | ||
66 | |||
67 | i2c_set_clientdata(client, data); | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | static int __devexit cma3000_i2c_remove(struct i2c_client *client) | ||
73 | { | ||
74 | struct cma3000_accl_data *data = i2c_get_clientdata(client); | ||
75 | |||
76 | cma3000_exit(data); | ||
77 | |||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | #ifdef CONFIG_PM | ||
82 | static int cma3000_i2c_suspend(struct device *dev) | ||
83 | { | ||
84 | struct i2c_client *client = to_i2c_client(dev); | ||
85 | struct cma3000_accl_data *data = i2c_get_clientdata(client); | ||
86 | |||
87 | cma3000_suspend(data); | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | static int cma3000_i2c_resume(struct device *dev) | ||
93 | { | ||
94 | struct i2c_client *client = to_i2c_client(dev); | ||
95 | struct cma3000_accl_data *data = i2c_get_clientdata(client); | ||
96 | |||
97 | cma3000_resume(data); | ||
98 | |||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | static const struct dev_pm_ops cma3000_i2c_pm_ops = { | ||
103 | .suspend = cma3000_i2c_suspend, | ||
104 | .resume = cma3000_i2c_resume, | ||
105 | }; | ||
106 | #endif | ||
107 | |||
108 | static const struct i2c_device_id cma3000_i2c_id[] = { | ||
109 | { "cma3000_d01", 0 }, | ||
110 | { }, | ||
111 | }; | ||
112 | |||
113 | MODULE_DEVICE_TABLE(i2c, cma3000_i2c_id); | ||
114 | |||
115 | static struct i2c_driver cma3000_i2c_driver = { | ||
116 | .probe = cma3000_i2c_probe, | ||
117 | .remove = __devexit_p(cma3000_i2c_remove), | ||
118 | .id_table = cma3000_i2c_id, | ||
119 | .driver = { | ||
120 | .name = "cma3000_i2c_accl", | ||
121 | .owner = THIS_MODULE, | ||
122 | #ifdef CONFIG_PM | ||
123 | .pm = &cma3000_i2c_pm_ops, | ||
124 | #endif | ||
125 | }, | ||
126 | }; | ||
127 | |||
128 | static int __init cma3000_i2c_init(void) | ||
129 | { | ||
130 | return i2c_add_driver(&cma3000_i2c_driver); | ||
131 | } | ||
132 | |||
133 | static void __exit cma3000_i2c_exit(void) | ||
134 | { | ||
135 | i2c_del_driver(&cma3000_i2c_driver); | ||
136 | } | ||
137 | |||
138 | module_init(cma3000_i2c_init); | ||
139 | module_exit(cma3000_i2c_exit); | ||
140 | |||
141 | MODULE_DESCRIPTION("CMA3000-D0x Accelerometer I2C Driver"); | ||
142 | MODULE_LICENSE("GPL"); | ||
143 | MODULE_AUTHOR("Hemanth V <hemanthv@ti.com>"); | ||
diff --git a/drivers/input/misc/hp_sdc_rtc.c b/drivers/input/misc/hp_sdc_rtc.c index c19066479057..0b4f54265f62 100644 --- a/drivers/input/misc/hp_sdc_rtc.c +++ b/drivers/input/misc/hp_sdc_rtc.c | |||
@@ -43,7 +43,7 @@ | |||
43 | #include <linux/proc_fs.h> | 43 | #include <linux/proc_fs.h> |
44 | #include <linux/poll.h> | 44 | #include <linux/poll.h> |
45 | #include <linux/rtc.h> | 45 | #include <linux/rtc.h> |
46 | #include <linux/smp_lock.h> | 46 | #include <linux/mutex.h> |
47 | #include <linux/semaphore.h> | 47 | #include <linux/semaphore.h> |
48 | 48 | ||
49 | MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>"); | 49 | MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>"); |
@@ -52,6 +52,7 @@ MODULE_LICENSE("Dual BSD/GPL"); | |||
52 | 52 | ||
53 | #define RTC_VERSION "1.10d" | 53 | #define RTC_VERSION "1.10d" |
54 | 54 | ||
55 | static DEFINE_MUTEX(hp_sdc_rtc_mutex); | ||
55 | static unsigned long epoch = 2000; | 56 | static unsigned long epoch = 2000; |
56 | 57 | ||
57 | static struct semaphore i8042tregs; | 58 | static struct semaphore i8042tregs; |
@@ -104,7 +105,7 @@ static int hp_sdc_rtc_do_read_bbrtc (struct rtc_time *rtctm) | |||
104 | t.endidx = 91; | 105 | t.endidx = 91; |
105 | t.seq = tseq; | 106 | t.seq = tseq; |
106 | t.act.semaphore = &tsem; | 107 | t.act.semaphore = &tsem; |
107 | init_MUTEX_LOCKED(&tsem); | 108 | sema_init(&tsem, 0); |
108 | 109 | ||
109 | if (hp_sdc_enqueue_transaction(&t)) return -1; | 110 | if (hp_sdc_enqueue_transaction(&t)) return -1; |
110 | 111 | ||
@@ -665,9 +666,9 @@ static long hp_sdc_rtc_unlocked_ioctl(struct file *file, | |||
665 | { | 666 | { |
666 | int ret; | 667 | int ret; |
667 | 668 | ||
668 | lock_kernel(); | 669 | mutex_lock(&hp_sdc_rtc_mutex); |
669 | ret = hp_sdc_rtc_ioctl(file, cmd, arg); | 670 | ret = hp_sdc_rtc_ioctl(file, cmd, arg); |
670 | unlock_kernel(); | 671 | mutex_unlock(&hp_sdc_rtc_mutex); |
671 | 672 | ||
672 | return ret; | 673 | return ret; |
673 | } | 674 | } |
@@ -698,7 +699,7 @@ static int __init hp_sdc_rtc_init(void) | |||
698 | return -ENODEV; | 699 | return -ENODEV; |
699 | #endif | 700 | #endif |
700 | 701 | ||
701 | init_MUTEX(&i8042tregs); | 702 | sema_init(&i8042tregs, 1); |
702 | 703 | ||
703 | if ((ret = hp_sdc_request_timer_irq(&hp_sdc_rtc_isr))) | 704 | if ((ret = hp_sdc_request_timer_irq(&hp_sdc_rtc_isr))) |
704 | return ret; | 705 | return ret; |
diff --git a/drivers/input/misc/ixp4xx-beeper.c b/drivers/input/misc/ixp4xx-beeper.c index 9dfd6e5f786f..1f38302a5951 100644 --- a/drivers/input/misc/ixp4xx-beeper.c +++ b/drivers/input/misc/ixp4xx-beeper.c | |||
@@ -69,11 +69,7 @@ static int ixp4xx_spkr_event(struct input_dev *dev, unsigned int type, unsigned | |||
69 | } | 69 | } |
70 | 70 | ||
71 | if (value > 20 && value < 32767) | 71 | if (value > 20 && value < 32767) |
72 | #ifndef FREQ | 72 | count = (IXP4XX_TIMER_FREQ / (value * 4)) - 1; |
73 | count = (ixp4xx_get_board_tick_rate() / (value * 4)) - 1; | ||
74 | #else | ||
75 | count = (FREQ / (value * 4)) - 1; | ||
76 | #endif | ||
77 | 73 | ||
78 | ixp4xx_spkr_control(pin, count); | 74 | ixp4xx_spkr_control(pin, count); |
79 | 75 | ||
diff --git a/drivers/input/misc/keyspan_remote.c b/drivers/input/misc/keyspan_remote.c index a93c525475c6..fc62256c963f 100644 --- a/drivers/input/misc/keyspan_remote.c +++ b/drivers/input/misc/keyspan_remote.c | |||
@@ -312,7 +312,7 @@ static void keyspan_check_data(struct usb_keyspan *remote) | |||
312 | remote->data.tester = remote->data.tester >> 5; | 312 | remote->data.tester = remote->data.tester >> 5; |
313 | remote->data.bits_left -= 5; | 313 | remote->data.bits_left -= 5; |
314 | } else { | 314 | } else { |
315 | err("Bad message recieved, no stop bit found.\n"); | 315 | err("Bad message received, no stop bit found.\n"); |
316 | } | 316 | } |
317 | 317 | ||
318 | dev_dbg(&remote->udev->dev, | 318 | dev_dbg(&remote->udev->dev, |
diff --git a/drivers/input/misc/max8925_onkey.c b/drivers/input/misc/max8925_onkey.c index 80af44608018..7de0ded4ccc3 100644 --- a/drivers/input/misc/max8925_onkey.c +++ b/drivers/input/misc/max8925_onkey.c | |||
@@ -27,27 +27,37 @@ | |||
27 | #include <linux/mfd/max8925.h> | 27 | #include <linux/mfd/max8925.h> |
28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
29 | 29 | ||
30 | #define SW_INPUT (1 << 7) /* 0/1 -- up/down */ | ||
30 | #define HARDRESET_EN (1 << 7) | 31 | #define HARDRESET_EN (1 << 7) |
31 | #define PWREN_EN (1 << 7) | 32 | #define PWREN_EN (1 << 7) |
32 | 33 | ||
33 | struct max8925_onkey_info { | 34 | struct max8925_onkey_info { |
34 | struct input_dev *idev; | 35 | struct input_dev *idev; |
35 | struct i2c_client *i2c; | 36 | struct i2c_client *i2c; |
36 | int irq; | 37 | struct device *dev; |
38 | int irq[2]; | ||
37 | }; | 39 | }; |
38 | 40 | ||
39 | /* | 41 | /* |
40 | * MAX8925 gives us an interrupt when ONKEY is held for 3 seconds. | 42 | * MAX8925 gives us an interrupt when ONKEY is pressed or released. |
41 | * max8925_set_bits() operates I2C bus and may sleep. So implement | 43 | * max8925_set_bits() operates I2C bus and may sleep. So implement |
42 | * it in thread IRQ handler. | 44 | * it in thread IRQ handler. |
43 | */ | 45 | */ |
44 | static irqreturn_t max8925_onkey_handler(int irq, void *data) | 46 | static irqreturn_t max8925_onkey_handler(int irq, void *data) |
45 | { | 47 | { |
46 | struct max8925_onkey_info *info = data; | 48 | struct max8925_onkey_info *info = data; |
47 | 49 | int ret, event; | |
48 | input_report_key(info->idev, KEY_POWER, 1); | 50 | |
51 | ret = max8925_reg_read(info->i2c, MAX8925_ON_OFF_STATUS); | ||
52 | if (ret & SW_INPUT) | ||
53 | event = 1; | ||
54 | else | ||
55 | event = 0; | ||
56 | input_report_key(info->idev, KEY_POWER, event); | ||
49 | input_sync(info->idev); | 57 | input_sync(info->idev); |
50 | 58 | ||
59 | dev_dbg(info->dev, "onkey event:%d\n", event); | ||
60 | |||
51 | /* Enable hardreset to halt if system isn't shutdown on time */ | 61 | /* Enable hardreset to halt if system isn't shutdown on time */ |
52 | max8925_set_bits(info->i2c, MAX8925_SYSENSEL, | 62 | max8925_set_bits(info->i2c, MAX8925_SYSENSEL, |
53 | HARDRESET_EN, HARDRESET_EN); | 63 | HARDRESET_EN, HARDRESET_EN); |
@@ -59,14 +69,42 @@ static int __devinit max8925_onkey_probe(struct platform_device *pdev) | |||
59 | { | 69 | { |
60 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); | 70 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); |
61 | struct max8925_onkey_info *info; | 71 | struct max8925_onkey_info *info; |
62 | int error; | 72 | int irq[2], error; |
73 | |||
74 | irq[0] = platform_get_irq(pdev, 0); | ||
75 | if (irq[0] < 0) { | ||
76 | dev_err(&pdev->dev, "No IRQ resource!\n"); | ||
77 | return -EINVAL; | ||
78 | } | ||
79 | irq[1] = platform_get_irq(pdev, 1); | ||
80 | if (irq[1] < 0) { | ||
81 | dev_err(&pdev->dev, "No IRQ resource!\n"); | ||
82 | return -EINVAL; | ||
83 | } | ||
63 | 84 | ||
64 | info = kzalloc(sizeof(struct max8925_onkey_info), GFP_KERNEL); | 85 | info = kzalloc(sizeof(struct max8925_onkey_info), GFP_KERNEL); |
65 | if (!info) | 86 | if (!info) |
66 | return -ENOMEM; | 87 | return -ENOMEM; |
67 | 88 | ||
68 | info->i2c = chip->i2c; | 89 | info->i2c = chip->i2c; |
69 | info->irq = chip->irq_base + MAX8925_IRQ_GPM_SW_3SEC; | 90 | info->dev = &pdev->dev; |
91 | irq[0] += chip->irq_base; | ||
92 | irq[1] += chip->irq_base; | ||
93 | |||
94 | error = request_threaded_irq(irq[0], NULL, max8925_onkey_handler, | ||
95 | IRQF_ONESHOT, "onkey-down", info); | ||
96 | if (error < 0) { | ||
97 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", | ||
98 | irq[0], error); | ||
99 | goto out; | ||
100 | } | ||
101 | error = request_threaded_irq(irq[1], NULL, max8925_onkey_handler, | ||
102 | IRQF_ONESHOT, "onkey-up", info); | ||
103 | if (error < 0) { | ||
104 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", | ||
105 | irq[1], error); | ||
106 | goto out_irq; | ||
107 | } | ||
70 | 108 | ||
71 | info->idev = input_allocate_device(); | 109 | info->idev = input_allocate_device(); |
72 | if (!info->idev) { | 110 | if (!info->idev) { |
@@ -79,32 +117,29 @@ static int __devinit max8925_onkey_probe(struct platform_device *pdev) | |||
79 | info->idev->phys = "max8925_on/input0"; | 117 | info->idev->phys = "max8925_on/input0"; |
80 | info->idev->id.bustype = BUS_I2C; | 118 | info->idev->id.bustype = BUS_I2C; |
81 | info->idev->dev.parent = &pdev->dev; | 119 | info->idev->dev.parent = &pdev->dev; |
120 | info->irq[0] = irq[0]; | ||
121 | info->irq[1] = irq[1]; | ||
82 | info->idev->evbit[0] = BIT_MASK(EV_KEY); | 122 | info->idev->evbit[0] = BIT_MASK(EV_KEY); |
83 | info->idev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER); | 123 | info->idev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER); |
84 | 124 | ||
85 | error = request_threaded_irq(info->irq, NULL, max8925_onkey_handler, | ||
86 | IRQF_ONESHOT, "onkey", info); | ||
87 | if (error < 0) { | ||
88 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", | ||
89 | info->irq, error); | ||
90 | goto out_irq; | ||
91 | } | ||
92 | 125 | ||
93 | error = input_register_device(info->idev); | 126 | error = input_register_device(info->idev); |
94 | if (error) { | 127 | if (error) { |
95 | dev_err(chip->dev, "Can't register input device: %d\n", error); | 128 | dev_err(chip->dev, "Can't register input device: %d\n", error); |
96 | goto out; | 129 | goto out_reg; |
97 | } | 130 | } |
98 | 131 | ||
99 | platform_set_drvdata(pdev, info); | 132 | platform_set_drvdata(pdev, info); |
100 | 133 | ||
101 | return 0; | 134 | return 0; |
102 | 135 | ||
103 | out: | 136 | out_reg: |
104 | free_irq(info->irq, info); | ||
105 | out_irq: | ||
106 | input_free_device(info->idev); | 137 | input_free_device(info->idev); |
107 | out_input: | 138 | out_input: |
139 | free_irq(info->irq[1], info); | ||
140 | out_irq: | ||
141 | free_irq(info->irq[0], info); | ||
142 | out: | ||
108 | kfree(info); | 143 | kfree(info); |
109 | return error; | 144 | return error; |
110 | } | 145 | } |
@@ -113,7 +148,8 @@ static int __devexit max8925_onkey_remove(struct platform_device *pdev) | |||
113 | { | 148 | { |
114 | struct max8925_onkey_info *info = platform_get_drvdata(pdev); | 149 | struct max8925_onkey_info *info = platform_get_drvdata(pdev); |
115 | 150 | ||
116 | free_irq(info->irq, info); | 151 | free_irq(info->irq[0], info); |
152 | free_irq(info->irq[1], info); | ||
117 | input_unregister_device(info->idev); | 153 | input_unregister_device(info->idev); |
118 | kfree(info); | 154 | kfree(info); |
119 | 155 | ||
diff --git a/drivers/input/misc/pcf8574_keypad.c b/drivers/input/misc/pcf8574_keypad.c index 4b42ffc0532a..08be1a355956 100644 --- a/drivers/input/misc/pcf8574_keypad.c +++ b/drivers/input/misc/pcf8574_keypad.c | |||
@@ -127,14 +127,6 @@ static int __devinit pcf8574_kp_probe(struct i2c_client *client, const struct i2 | |||
127 | idev->id.product = 0x0001; | 127 | idev->id.product = 0x0001; |
128 | idev->id.version = 0x0100; | 128 | idev->id.version = 0x0100; |
129 | 129 | ||
130 | input_set_drvdata(idev, lp); | ||
131 | |||
132 | ret = input_register_device(idev); | ||
133 | if (ret) { | ||
134 | dev_err(&client->dev, "input_register_device() failed\n"); | ||
135 | goto fail_register; | ||
136 | } | ||
137 | |||
138 | lp->laststate = read_state(lp); | 130 | lp->laststate = read_state(lp); |
139 | 131 | ||
140 | ret = request_threaded_irq(client->irq, NULL, pcf8574_kp_irq_handler, | 132 | ret = request_threaded_irq(client->irq, NULL, pcf8574_kp_irq_handler, |
@@ -142,16 +134,21 @@ static int __devinit pcf8574_kp_probe(struct i2c_client *client, const struct i2 | |||
142 | DRV_NAME, lp); | 134 | DRV_NAME, lp); |
143 | if (ret) { | 135 | if (ret) { |
144 | dev_err(&client->dev, "IRQ %d is not free\n", client->irq); | 136 | dev_err(&client->dev, "IRQ %d is not free\n", client->irq); |
145 | goto fail_irq; | 137 | goto fail_free_device; |
138 | } | ||
139 | |||
140 | ret = input_register_device(idev); | ||
141 | if (ret) { | ||
142 | dev_err(&client->dev, "input_register_device() failed\n"); | ||
143 | goto fail_free_irq; | ||
146 | } | 144 | } |
147 | 145 | ||
148 | i2c_set_clientdata(client, lp); | 146 | i2c_set_clientdata(client, lp); |
149 | return 0; | 147 | return 0; |
150 | 148 | ||
151 | fail_irq: | 149 | fail_free_irq: |
152 | input_unregister_device(idev); | 150 | free_irq(client->irq, lp); |
153 | fail_register: | 151 | fail_free_device: |
154 | input_set_drvdata(idev, NULL); | ||
155 | input_free_device(idev); | 152 | input_free_device(idev); |
156 | fail_allocate: | 153 | fail_allocate: |
157 | kfree(lp); | 154 | kfree(lp); |
@@ -172,19 +169,29 @@ static int __devexit pcf8574_kp_remove(struct i2c_client *client) | |||
172 | } | 169 | } |
173 | 170 | ||
174 | #ifdef CONFIG_PM | 171 | #ifdef CONFIG_PM |
175 | static int pcf8574_kp_resume(struct i2c_client *client) | 172 | static int pcf8574_kp_resume(struct device *dev) |
176 | { | 173 | { |
174 | struct i2c_client *client = to_i2c_client(dev); | ||
175 | |||
177 | enable_irq(client->irq); | 176 | enable_irq(client->irq); |
178 | 177 | ||
179 | return 0; | 178 | return 0; |
180 | } | 179 | } |
181 | 180 | ||
182 | static int pcf8574_kp_suspend(struct i2c_client *client, pm_message_t mesg) | 181 | static int pcf8574_kp_suspend(struct device *dev) |
183 | { | 182 | { |
183 | struct i2c_client *client = to_i2c_client(dev); | ||
184 | |||
184 | disable_irq(client->irq); | 185 | disable_irq(client->irq); |
185 | 186 | ||
186 | return 0; | 187 | return 0; |
187 | } | 188 | } |
189 | |||
190 | static const struct dev_pm_ops pcf8574_kp_pm_ops = { | ||
191 | .suspend = pcf8574_kp_suspend, | ||
192 | .resume = pcf8574_kp_resume, | ||
193 | }; | ||
194 | |||
188 | #else | 195 | #else |
189 | # define pcf8574_kp_resume NULL | 196 | # define pcf8574_kp_resume NULL |
190 | # define pcf8574_kp_suspend NULL | 197 | # define pcf8574_kp_suspend NULL |
@@ -200,11 +207,12 @@ static struct i2c_driver pcf8574_kp_driver = { | |||
200 | .driver = { | 207 | .driver = { |
201 | .name = DRV_NAME, | 208 | .name = DRV_NAME, |
202 | .owner = THIS_MODULE, | 209 | .owner = THIS_MODULE, |
210 | #ifdef CONFIG_PM | ||
211 | .pm = &pcf8574_kp_pm_ops, | ||
212 | #endif | ||
203 | }, | 213 | }, |
204 | .probe = pcf8574_kp_probe, | 214 | .probe = pcf8574_kp_probe, |
205 | .remove = __devexit_p(pcf8574_kp_remove), | 215 | .remove = __devexit_p(pcf8574_kp_remove), |
206 | .suspend = pcf8574_kp_suspend, | ||
207 | .resume = pcf8574_kp_resume, | ||
208 | .id_table = pcf8574_kp_id, | 216 | .id_table = pcf8574_kp_id, |
209 | }; | 217 | }; |
210 | 218 | ||
diff --git a/drivers/input/misc/pmic8xxx-pwrkey.c b/drivers/input/misc/pmic8xxx-pwrkey.c new file mode 100644 index 000000000000..b3cfb9c71e66 --- /dev/null +++ b/drivers/input/misc/pmic8xxx-pwrkey.c | |||
@@ -0,0 +1,232 @@ | |||
1 | /* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. | ||
2 | * | ||
3 | * This program is free software; you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License version 2 and | ||
5 | * only version 2 as published by the Free Software Foundation. | ||
6 | * | ||
7 | * This program is distributed in the hope that it will be useful, | ||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | * GNU General Public License for more details. | ||
11 | */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/errno.h> | ||
17 | #include <linux/slab.h> | ||
18 | #include <linux/input.h> | ||
19 | #include <linux/interrupt.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/log2.h> | ||
22 | |||
23 | #include <linux/mfd/pm8xxx/core.h> | ||
24 | #include <linux/input/pmic8xxx-pwrkey.h> | ||
25 | |||
26 | #define PON_CNTL_1 0x1C | ||
27 | #define PON_CNTL_PULL_UP BIT(7) | ||
28 | #define PON_CNTL_TRIG_DELAY_MASK (0x7) | ||
29 | |||
30 | /** | ||
31 | * struct pmic8xxx_pwrkey - pmic8xxx pwrkey information | ||
32 | * @key_press_irq: key press irq number | ||
33 | */ | ||
34 | struct pmic8xxx_pwrkey { | ||
35 | struct input_dev *pwr; | ||
36 | int key_press_irq; | ||
37 | }; | ||
38 | |||
39 | static irqreturn_t pwrkey_press_irq(int irq, void *_pwrkey) | ||
40 | { | ||
41 | struct pmic8xxx_pwrkey *pwrkey = _pwrkey; | ||
42 | |||
43 | input_report_key(pwrkey->pwr, KEY_POWER, 1); | ||
44 | input_sync(pwrkey->pwr); | ||
45 | |||
46 | return IRQ_HANDLED; | ||
47 | } | ||
48 | |||
49 | static irqreturn_t pwrkey_release_irq(int irq, void *_pwrkey) | ||
50 | { | ||
51 | struct pmic8xxx_pwrkey *pwrkey = _pwrkey; | ||
52 | |||
53 | input_report_key(pwrkey->pwr, KEY_POWER, 0); | ||
54 | input_sync(pwrkey->pwr); | ||
55 | |||
56 | return IRQ_HANDLED; | ||
57 | } | ||
58 | |||
59 | #ifdef CONFIG_PM_SLEEP | ||
60 | static int pmic8xxx_pwrkey_suspend(struct device *dev) | ||
61 | { | ||
62 | struct pmic8xxx_pwrkey *pwrkey = dev_get_drvdata(dev); | ||
63 | |||
64 | if (device_may_wakeup(dev)) | ||
65 | enable_irq_wake(pwrkey->key_press_irq); | ||
66 | |||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | static int pmic8xxx_pwrkey_resume(struct device *dev) | ||
71 | { | ||
72 | struct pmic8xxx_pwrkey *pwrkey = dev_get_drvdata(dev); | ||
73 | |||
74 | if (device_may_wakeup(dev)) | ||
75 | disable_irq_wake(pwrkey->key_press_irq); | ||
76 | |||
77 | return 0; | ||
78 | } | ||
79 | #endif | ||
80 | |||
81 | static SIMPLE_DEV_PM_OPS(pm8xxx_pwr_key_pm_ops, | ||
82 | pmic8xxx_pwrkey_suspend, pmic8xxx_pwrkey_resume); | ||
83 | |||
84 | static int __devinit pmic8xxx_pwrkey_probe(struct platform_device *pdev) | ||
85 | { | ||
86 | struct input_dev *pwr; | ||
87 | int key_release_irq = platform_get_irq(pdev, 0); | ||
88 | int key_press_irq = platform_get_irq(pdev, 1); | ||
89 | int err; | ||
90 | unsigned int delay; | ||
91 | u8 pon_cntl; | ||
92 | struct pmic8xxx_pwrkey *pwrkey; | ||
93 | const struct pm8xxx_pwrkey_platform_data *pdata = | ||
94 | dev_get_platdata(&pdev->dev); | ||
95 | |||
96 | if (!pdata) { | ||
97 | dev_err(&pdev->dev, "power key platform data not supplied\n"); | ||
98 | return -EINVAL; | ||
99 | } | ||
100 | |||
101 | if (pdata->kpd_trigger_delay_us > 62500) { | ||
102 | dev_err(&pdev->dev, "invalid power key trigger delay\n"); | ||
103 | return -EINVAL; | ||
104 | } | ||
105 | |||
106 | pwrkey = kzalloc(sizeof(*pwrkey), GFP_KERNEL); | ||
107 | if (!pwrkey) | ||
108 | return -ENOMEM; | ||
109 | |||
110 | pwr = input_allocate_device(); | ||
111 | if (!pwr) { | ||
112 | dev_dbg(&pdev->dev, "Can't allocate power button\n"); | ||
113 | err = -ENOMEM; | ||
114 | goto free_pwrkey; | ||
115 | } | ||
116 | |||
117 | input_set_capability(pwr, EV_KEY, KEY_POWER); | ||
118 | |||
119 | pwr->name = "pmic8xxx_pwrkey"; | ||
120 | pwr->phys = "pmic8xxx_pwrkey/input0"; | ||
121 | pwr->dev.parent = &pdev->dev; | ||
122 | |||
123 | delay = (pdata->kpd_trigger_delay_us << 10) / USEC_PER_SEC; | ||
124 | delay = 1 + ilog2(delay); | ||
125 | |||
126 | err = pm8xxx_readb(pdev->dev.parent, PON_CNTL_1, &pon_cntl); | ||
127 | if (err < 0) { | ||
128 | dev_err(&pdev->dev, "failed reading PON_CNTL_1 err=%d\n", err); | ||
129 | goto free_input_dev; | ||
130 | } | ||
131 | |||
132 | pon_cntl &= ~PON_CNTL_TRIG_DELAY_MASK; | ||
133 | pon_cntl |= (delay & PON_CNTL_TRIG_DELAY_MASK); | ||
134 | if (pdata->pull_up) | ||
135 | pon_cntl |= PON_CNTL_PULL_UP; | ||
136 | else | ||
137 | pon_cntl &= ~PON_CNTL_PULL_UP; | ||
138 | |||
139 | err = pm8xxx_writeb(pdev->dev.parent, PON_CNTL_1, pon_cntl); | ||
140 | if (err < 0) { | ||
141 | dev_err(&pdev->dev, "failed writing PON_CNTL_1 err=%d\n", err); | ||
142 | goto free_input_dev; | ||
143 | } | ||
144 | |||
145 | err = input_register_device(pwr); | ||
146 | if (err) { | ||
147 | dev_dbg(&pdev->dev, "Can't register power key: %d\n", err); | ||
148 | goto free_input_dev; | ||
149 | } | ||
150 | |||
151 | pwrkey->key_press_irq = key_press_irq; | ||
152 | pwrkey->pwr = pwr; | ||
153 | |||
154 | platform_set_drvdata(pdev, pwrkey); | ||
155 | |||
156 | err = request_irq(key_press_irq, pwrkey_press_irq, | ||
157 | IRQF_TRIGGER_RISING, "pmic8xxx_pwrkey_press", pwrkey); | ||
158 | if (err < 0) { | ||
159 | dev_dbg(&pdev->dev, "Can't get %d IRQ for pwrkey: %d\n", | ||
160 | key_press_irq, err); | ||
161 | goto unreg_input_dev; | ||
162 | } | ||
163 | |||
164 | err = request_irq(key_release_irq, pwrkey_release_irq, | ||
165 | IRQF_TRIGGER_RISING, "pmic8xxx_pwrkey_release", pwrkey); | ||
166 | if (err < 0) { | ||
167 | dev_dbg(&pdev->dev, "Can't get %d IRQ for pwrkey: %d\n", | ||
168 | key_release_irq, err); | ||
169 | |||
170 | goto free_press_irq; | ||
171 | } | ||
172 | |||
173 | device_init_wakeup(&pdev->dev, pdata->wakeup); | ||
174 | |||
175 | return 0; | ||
176 | |||
177 | free_press_irq: | ||
178 | free_irq(key_press_irq, NULL); | ||
179 | unreg_input_dev: | ||
180 | platform_set_drvdata(pdev, NULL); | ||
181 | input_unregister_device(pwr); | ||
182 | pwr = NULL; | ||
183 | free_input_dev: | ||
184 | input_free_device(pwr); | ||
185 | free_pwrkey: | ||
186 | kfree(pwrkey); | ||
187 | return err; | ||
188 | } | ||
189 | |||
190 | static int __devexit pmic8xxx_pwrkey_remove(struct platform_device *pdev) | ||
191 | { | ||
192 | struct pmic8xxx_pwrkey *pwrkey = platform_get_drvdata(pdev); | ||
193 | int key_release_irq = platform_get_irq(pdev, 0); | ||
194 | int key_press_irq = platform_get_irq(pdev, 1); | ||
195 | |||
196 | device_init_wakeup(&pdev->dev, 0); | ||
197 | |||
198 | free_irq(key_press_irq, pwrkey); | ||
199 | free_irq(key_release_irq, pwrkey); | ||
200 | input_unregister_device(pwrkey->pwr); | ||
201 | platform_set_drvdata(pdev, NULL); | ||
202 | kfree(pwrkey); | ||
203 | |||
204 | return 0; | ||
205 | } | ||
206 | |||
207 | static struct platform_driver pmic8xxx_pwrkey_driver = { | ||
208 | .probe = pmic8xxx_pwrkey_probe, | ||
209 | .remove = __devexit_p(pmic8xxx_pwrkey_remove), | ||
210 | .driver = { | ||
211 | .name = PM8XXX_PWRKEY_DEV_NAME, | ||
212 | .owner = THIS_MODULE, | ||
213 | .pm = &pm8xxx_pwr_key_pm_ops, | ||
214 | }, | ||
215 | }; | ||
216 | |||
217 | static int __init pmic8xxx_pwrkey_init(void) | ||
218 | { | ||
219 | return platform_driver_register(&pmic8xxx_pwrkey_driver); | ||
220 | } | ||
221 | module_init(pmic8xxx_pwrkey_init); | ||
222 | |||
223 | static void __exit pmic8xxx_pwrkey_exit(void) | ||
224 | { | ||
225 | platform_driver_unregister(&pmic8xxx_pwrkey_driver); | ||
226 | } | ||
227 | module_exit(pmic8xxx_pwrkey_exit); | ||
228 | |||
229 | MODULE_ALIAS("platform:pmic8xxx_pwrkey"); | ||
230 | MODULE_DESCRIPTION("PMIC8XXX Power Key driver"); | ||
231 | MODULE_LICENSE("GPL v2"); | ||
232 | MODULE_AUTHOR("Trilok Soni <tsoni@codeaurora.org>"); | ||
diff --git a/drivers/input/misc/powermate.c b/drivers/input/misc/powermate.c index bf170f6b4422..f45947190e4f 100644 --- a/drivers/input/misc/powermate.c +++ b/drivers/input/misc/powermate.c | |||
@@ -280,7 +280,7 @@ static int powermate_alloc_buffers(struct usb_device *udev, struct powermate_dev | |||
280 | 280 | ||
281 | pm->configcr = kmalloc(sizeof(*(pm->configcr)), GFP_KERNEL); | 281 | pm->configcr = kmalloc(sizeof(*(pm->configcr)), GFP_KERNEL); |
282 | if (!pm->configcr) | 282 | if (!pm->configcr) |
283 | return -1; | 283 | return -ENOMEM; |
284 | 284 | ||
285 | return 0; | 285 | return 0; |
286 | } | 286 | } |
diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index 1f8e0108962e..2c8b84dd9dac 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c | |||
@@ -2,6 +2,7 @@ | |||
2 | * rotary_encoder.c | 2 | * rotary_encoder.c |
3 | * | 3 | * |
4 | * (c) 2009 Daniel Mack <daniel@caiaq.de> | 4 | * (c) 2009 Daniel Mack <daniel@caiaq.de> |
5 | * Copyright (C) 2011 Johan Hovold <jhovold@gmail.com> | ||
5 | * | 6 | * |
6 | * state machine code inspired by code from Tim Ruetz | 7 | * state machine code inspired by code from Tim Ruetz |
7 | * | 8 | * |
@@ -38,52 +39,66 @@ struct rotary_encoder { | |||
38 | 39 | ||
39 | bool armed; | 40 | bool armed; |
40 | unsigned char dir; /* 0 - clockwise, 1 - CCW */ | 41 | unsigned char dir; /* 0 - clockwise, 1 - CCW */ |
42 | |||
43 | char last_stable; | ||
41 | }; | 44 | }; |
42 | 45 | ||
43 | static irqreturn_t rotary_encoder_irq(int irq, void *dev_id) | 46 | static int rotary_encoder_get_state(struct rotary_encoder_platform_data *pdata) |
44 | { | 47 | { |
45 | struct rotary_encoder *encoder = dev_id; | ||
46 | struct rotary_encoder_platform_data *pdata = encoder->pdata; | ||
47 | int a = !!gpio_get_value(pdata->gpio_a); | 48 | int a = !!gpio_get_value(pdata->gpio_a); |
48 | int b = !!gpio_get_value(pdata->gpio_b); | 49 | int b = !!gpio_get_value(pdata->gpio_b); |
49 | int state; | ||
50 | 50 | ||
51 | a ^= pdata->inverted_a; | 51 | a ^= pdata->inverted_a; |
52 | b ^= pdata->inverted_b; | 52 | b ^= pdata->inverted_b; |
53 | state = (a << 1) | b; | ||
54 | 53 | ||
55 | switch (state) { | 54 | return ((a << 1) | b); |
55 | } | ||
56 | 56 | ||
57 | case 0x0: | 57 | static void rotary_encoder_report_event(struct rotary_encoder *encoder) |
58 | if (!encoder->armed) | 58 | { |
59 | break; | 59 | struct rotary_encoder_platform_data *pdata = encoder->pdata; |
60 | 60 | ||
61 | if (pdata->relative_axis) { | 61 | if (pdata->relative_axis) { |
62 | input_report_rel(encoder->input, pdata->axis, | 62 | input_report_rel(encoder->input, |
63 | encoder->dir ? -1 : 1); | 63 | pdata->axis, encoder->dir ? -1 : 1); |
64 | } else { | 64 | } else { |
65 | unsigned int pos = encoder->pos; | 65 | unsigned int pos = encoder->pos; |
66 | 66 | ||
67 | if (encoder->dir) { | 67 | if (encoder->dir) { |
68 | /* turning counter-clockwise */ | 68 | /* turning counter-clockwise */ |
69 | if (pdata->rollover) | ||
70 | pos += pdata->steps; | ||
71 | if (pos) | ||
72 | pos--; | ||
73 | } else { | ||
74 | /* turning clockwise */ | ||
75 | if (pdata->rollover || pos < pdata->steps) | ||
76 | pos++; | ||
77 | } | ||
78 | if (pdata->rollover) | 69 | if (pdata->rollover) |
79 | pos %= pdata->steps; | 70 | pos += pdata->steps; |
80 | encoder->pos = pos; | 71 | if (pos) |
81 | input_report_abs(encoder->input, pdata->axis, | 72 | pos--; |
82 | encoder->pos); | 73 | } else { |
74 | /* turning clockwise */ | ||
75 | if (pdata->rollover || pos < pdata->steps) | ||
76 | pos++; | ||
83 | } | 77 | } |
84 | input_sync(encoder->input); | ||
85 | 78 | ||
86 | encoder->armed = false; | 79 | if (pdata->rollover) |
80 | pos %= pdata->steps; | ||
81 | |||
82 | encoder->pos = pos; | ||
83 | input_report_abs(encoder->input, pdata->axis, encoder->pos); | ||
84 | } | ||
85 | |||
86 | input_sync(encoder->input); | ||
87 | } | ||
88 | |||
89 | static irqreturn_t rotary_encoder_irq(int irq, void *dev_id) | ||
90 | { | ||
91 | struct rotary_encoder *encoder = dev_id; | ||
92 | int state; | ||
93 | |||
94 | state = rotary_encoder_get_state(encoder->pdata); | ||
95 | |||
96 | switch (state) { | ||
97 | case 0x0: | ||
98 | if (encoder->armed) { | ||
99 | rotary_encoder_report_event(encoder); | ||
100 | encoder->armed = false; | ||
101 | } | ||
87 | break; | 102 | break; |
88 | 103 | ||
89 | case 0x1: | 104 | case 0x1: |
@@ -100,11 +115,37 @@ static irqreturn_t rotary_encoder_irq(int irq, void *dev_id) | |||
100 | return IRQ_HANDLED; | 115 | return IRQ_HANDLED; |
101 | } | 116 | } |
102 | 117 | ||
118 | static irqreturn_t rotary_encoder_half_period_irq(int irq, void *dev_id) | ||
119 | { | ||
120 | struct rotary_encoder *encoder = dev_id; | ||
121 | int state; | ||
122 | |||
123 | state = rotary_encoder_get_state(encoder->pdata); | ||
124 | |||
125 | switch (state) { | ||
126 | case 0x00: | ||
127 | case 0x03: | ||
128 | if (state != encoder->last_stable) { | ||
129 | rotary_encoder_report_event(encoder); | ||
130 | encoder->last_stable = state; | ||
131 | } | ||
132 | break; | ||
133 | |||
134 | case 0x01: | ||
135 | case 0x02: | ||
136 | encoder->dir = (encoder->last_stable + state) & 0x01; | ||
137 | break; | ||
138 | } | ||
139 | |||
140 | return IRQ_HANDLED; | ||
141 | } | ||
142 | |||
103 | static int __devinit rotary_encoder_probe(struct platform_device *pdev) | 143 | static int __devinit rotary_encoder_probe(struct platform_device *pdev) |
104 | { | 144 | { |
105 | struct rotary_encoder_platform_data *pdata = pdev->dev.platform_data; | 145 | struct rotary_encoder_platform_data *pdata = pdev->dev.platform_data; |
106 | struct rotary_encoder *encoder; | 146 | struct rotary_encoder *encoder; |
107 | struct input_dev *input; | 147 | struct input_dev *input; |
148 | irq_handler_t handler; | ||
108 | int err; | 149 | int err; |
109 | 150 | ||
110 | if (!pdata) { | 151 | if (!pdata) { |
@@ -175,8 +216,15 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) | |||
175 | } | 216 | } |
176 | 217 | ||
177 | /* request the IRQs */ | 218 | /* request the IRQs */ |
178 | err = request_irq(encoder->irq_a, &rotary_encoder_irq, | 219 | if (pdata->half_period) { |
179 | IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE, | 220 | handler = &rotary_encoder_half_period_irq; |
221 | encoder->last_stable = rotary_encoder_get_state(pdata); | ||
222 | } else { | ||
223 | handler = &rotary_encoder_irq; | ||
224 | } | ||
225 | |||
226 | err = request_irq(encoder->irq_a, handler, | ||
227 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, | ||
180 | DRV_NAME, encoder); | 228 | DRV_NAME, encoder); |
181 | if (err) { | 229 | if (err) { |
182 | dev_err(&pdev->dev, "unable to request IRQ %d\n", | 230 | dev_err(&pdev->dev, "unable to request IRQ %d\n", |
@@ -184,8 +232,8 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) | |||
184 | goto exit_free_gpio_b; | 232 | goto exit_free_gpio_b; |
185 | } | 233 | } |
186 | 234 | ||
187 | err = request_irq(encoder->irq_b, &rotary_encoder_irq, | 235 | err = request_irq(encoder->irq_b, handler, |
188 | IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE, | 236 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, |
189 | DRV_NAME, encoder); | 237 | DRV_NAME, encoder); |
190 | if (err) { | 238 | if (err) { |
191 | dev_err(&pdev->dev, "unable to request IRQ %d\n", | 239 | dev_err(&pdev->dev, "unable to request IRQ %d\n", |
@@ -252,6 +300,5 @@ module_exit(rotary_encoder_exit); | |||
252 | 300 | ||
253 | MODULE_ALIAS("platform:" DRV_NAME); | 301 | MODULE_ALIAS("platform:" DRV_NAME); |
254 | MODULE_DESCRIPTION("GPIO rotary encoder driver"); | 302 | MODULE_DESCRIPTION("GPIO rotary encoder driver"); |
255 | MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); | 303 | MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>, Johan Hovold"); |
256 | MODULE_LICENSE("GPL v2"); | 304 | MODULE_LICENSE("GPL v2"); |
257 | |||
diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c index 8e130bf7d32b..0122f5351577 100644 --- a/drivers/input/misc/sparcspkr.c +++ b/drivers/input/misc/sparcspkr.c | |||
@@ -173,18 +173,16 @@ static int __devinit sparcspkr_probe(struct device *dev) | |||
173 | return 0; | 173 | return 0; |
174 | } | 174 | } |
175 | 175 | ||
176 | static int sparcspkr_shutdown(struct platform_device *dev) | 176 | static void sparcspkr_shutdown(struct platform_device *dev) |
177 | { | 177 | { |
178 | struct sparcspkr_state *state = dev_get_drvdata(&dev->dev); | 178 | struct sparcspkr_state *state = dev_get_drvdata(&dev->dev); |
179 | struct input_dev *input_dev = state->input_dev; | 179 | struct input_dev *input_dev = state->input_dev; |
180 | 180 | ||
181 | /* turn off the speaker */ | 181 | /* turn off the speaker */ |
182 | state->event(input_dev, EV_SND, SND_BELL, 0); | 182 | state->event(input_dev, EV_SND, SND_BELL, 0); |
183 | |||
184 | return 0; | ||
185 | } | 183 | } |
186 | 184 | ||
187 | static int __devinit bbc_beep_probe(struct platform_device *op, const struct of_device_id *match) | 185 | static int __devinit bbc_beep_probe(struct platform_device *op) |
188 | { | 186 | { |
189 | struct sparcspkr_state *state; | 187 | struct sparcspkr_state *state; |
190 | struct bbc_beep_info *info; | 188 | struct bbc_beep_info *info; |
@@ -258,7 +256,7 @@ static const struct of_device_id bbc_beep_match[] = { | |||
258 | {}, | 256 | {}, |
259 | }; | 257 | }; |
260 | 258 | ||
261 | static struct of_platform_driver bbc_beep_driver = { | 259 | static struct platform_driver bbc_beep_driver = { |
262 | .driver = { | 260 | .driver = { |
263 | .name = "bbcbeep", | 261 | .name = "bbcbeep", |
264 | .owner = THIS_MODULE, | 262 | .owner = THIS_MODULE, |
@@ -269,7 +267,7 @@ static struct of_platform_driver bbc_beep_driver = { | |||
269 | .shutdown = sparcspkr_shutdown, | 267 | .shutdown = sparcspkr_shutdown, |
270 | }; | 268 | }; |
271 | 269 | ||
272 | static int __devinit grover_beep_probe(struct platform_device *op, const struct of_device_id *match) | 270 | static int __devinit grover_beep_probe(struct platform_device *op) |
273 | { | 271 | { |
274 | struct sparcspkr_state *state; | 272 | struct sparcspkr_state *state; |
275 | struct grover_beep_info *info; | 273 | struct grover_beep_info *info; |
@@ -340,7 +338,7 @@ static const struct of_device_id grover_beep_match[] = { | |||
340 | {}, | 338 | {}, |
341 | }; | 339 | }; |
342 | 340 | ||
343 | static struct of_platform_driver grover_beep_driver = { | 341 | static struct platform_driver grover_beep_driver = { |
344 | .driver = { | 342 | .driver = { |
345 | .name = "groverbeep", | 343 | .name = "groverbeep", |
346 | .owner = THIS_MODULE, | 344 | .owner = THIS_MODULE, |
@@ -353,12 +351,12 @@ static struct of_platform_driver grover_beep_driver = { | |||
353 | 351 | ||
354 | static int __init sparcspkr_init(void) | 352 | static int __init sparcspkr_init(void) |
355 | { | 353 | { |
356 | int err = of_register_platform_driver(&bbc_beep_driver); | 354 | int err = platform_driver_register(&bbc_beep_driver); |
357 | 355 | ||
358 | if (!err) { | 356 | if (!err) { |
359 | err = of_register_platform_driver(&grover_beep_driver); | 357 | err = platform_driver_register(&grover_beep_driver); |
360 | if (err) | 358 | if (err) |
361 | of_unregister_platform_driver(&bbc_beep_driver); | 359 | platform_driver_unregister(&bbc_beep_driver); |
362 | } | 360 | } |
363 | 361 | ||
364 | return err; | 362 | return err; |
@@ -366,8 +364,8 @@ static int __init sparcspkr_init(void) | |||
366 | 364 | ||
367 | static void __exit sparcspkr_exit(void) | 365 | static void __exit sparcspkr_exit(void) |
368 | { | 366 | { |
369 | of_unregister_platform_driver(&bbc_beep_driver); | 367 | platform_driver_unregister(&bbc_beep_driver); |
370 | of_unregister_platform_driver(&grover_beep_driver); | 368 | platform_driver_unregister(&grover_beep_driver); |
371 | } | 369 | } |
372 | 370 | ||
373 | module_init(sparcspkr_init); | 371 | module_init(sparcspkr_init); |
diff --git a/drivers/input/misc/twl4030-pwrbutton.c b/drivers/input/misc/twl4030-pwrbutton.c index f16972bddca4..38e4b507b94c 100644 --- a/drivers/input/misc/twl4030-pwrbutton.c +++ b/drivers/input/misc/twl4030-pwrbutton.c | |||
@@ -89,7 +89,7 @@ static int __init twl4030_pwrbutton_probe(struct platform_device *pdev) | |||
89 | return 0; | 89 | return 0; |
90 | 90 | ||
91 | free_irq: | 91 | free_irq: |
92 | free_irq(irq, NULL); | 92 | free_irq(irq, pwr); |
93 | free_input_dev: | 93 | free_input_dev: |
94 | input_free_device(pwr); | 94 | input_free_device(pwr); |
95 | return err; | 95 | return err; |
diff --git a/drivers/input/misc/twl4030-vibra.c b/drivers/input/misc/twl4030-vibra.c index 4f9b2afc24e8..014dd4ad0d4f 100644 --- a/drivers/input/misc/twl4030-vibra.c +++ b/drivers/input/misc/twl4030-vibra.c | |||
@@ -271,7 +271,7 @@ static struct platform_driver twl4030_vibra_driver = { | |||
271 | .probe = twl4030_vibra_probe, | 271 | .probe = twl4030_vibra_probe, |
272 | .remove = __devexit_p(twl4030_vibra_remove), | 272 | .remove = __devexit_p(twl4030_vibra_remove), |
273 | .driver = { | 273 | .driver = { |
274 | .name = "twl4030_codec_vibra", | 274 | .name = "twl4030-vibra", |
275 | .owner = THIS_MODULE, | 275 | .owner = THIS_MODULE, |
276 | #ifdef CONFIG_PM | 276 | #ifdef CONFIG_PM |
277 | .pm = &twl4030_vibra_pm_ops, | 277 | .pm = &twl4030_vibra_pm_ops, |
@@ -291,7 +291,7 @@ static void __exit twl4030_vibra_exit(void) | |||
291 | } | 291 | } |
292 | module_exit(twl4030_vibra_exit); | 292 | module_exit(twl4030_vibra_exit); |
293 | 293 | ||
294 | MODULE_ALIAS("platform:twl4030_codec_vibra"); | 294 | MODULE_ALIAS("platform:twl4030-vibra"); |
295 | 295 | ||
296 | MODULE_DESCRIPTION("TWL4030 Vibra driver"); | 296 | MODULE_DESCRIPTION("TWL4030 Vibra driver"); |
297 | MODULE_LICENSE("GPL"); | 297 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 360698553eb5..736056897e50 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/fs.h> | 37 | #include <linux/fs.h> |
38 | #include <linux/miscdevice.h> | 38 | #include <linux/miscdevice.h> |
39 | #include <linux/uinput.h> | 39 | #include <linux/uinput.h> |
40 | #include <linux/input/mt.h> | ||
40 | #include "../input-compat.h" | 41 | #include "../input-compat.h" |
41 | 42 | ||
42 | static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) | 43 | static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) |
@@ -301,10 +302,14 @@ static int uinput_validate_absbits(struct input_dev *dev) | |||
301 | int retval = 0; | 302 | int retval = 0; |
302 | 303 | ||
303 | for (cnt = 0; cnt < ABS_CNT; cnt++) { | 304 | for (cnt = 0; cnt < ABS_CNT; cnt++) { |
305 | int min, max; | ||
304 | if (!test_bit(cnt, dev->absbit)) | 306 | if (!test_bit(cnt, dev->absbit)) |
305 | continue; | 307 | continue; |
306 | 308 | ||
307 | if (input_abs_get_max(dev, cnt) <= input_abs_get_min(dev, cnt)) { | 309 | min = input_abs_get_min(dev, cnt); |
310 | max = input_abs_get_max(dev, cnt); | ||
311 | |||
312 | if ((min != 0 || max != 0) && max <= min) { | ||
308 | printk(KERN_DEBUG | 313 | printk(KERN_DEBUG |
309 | "%s: invalid abs[%02x] min:%d max:%d\n", | 314 | "%s: invalid abs[%02x] min:%d max:%d\n", |
310 | UINPUT_NAME, cnt, | 315 | UINPUT_NAME, cnt, |
@@ -346,8 +351,7 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu | |||
346 | { | 351 | { |
347 | struct uinput_user_dev *user_dev; | 352 | struct uinput_user_dev *user_dev; |
348 | struct input_dev *dev; | 353 | struct input_dev *dev; |
349 | char *name; | 354 | int i; |
350 | int i, size; | ||
351 | int retval; | 355 | int retval; |
352 | 356 | ||
353 | if (count != sizeof(struct uinput_user_dev)) | 357 | if (count != sizeof(struct uinput_user_dev)) |
@@ -361,30 +365,25 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu | |||
361 | 365 | ||
362 | dev = udev->dev; | 366 | dev = udev->dev; |
363 | 367 | ||
364 | user_dev = kmalloc(sizeof(struct uinput_user_dev), GFP_KERNEL); | 368 | user_dev = memdup_user(buffer, sizeof(struct uinput_user_dev)); |
365 | if (!user_dev) | 369 | if (IS_ERR(user_dev)) |
366 | return -ENOMEM; | 370 | return PTR_ERR(user_dev); |
367 | |||
368 | if (copy_from_user(user_dev, buffer, sizeof(struct uinput_user_dev))) { | ||
369 | retval = -EFAULT; | ||
370 | goto exit; | ||
371 | } | ||
372 | 371 | ||
373 | udev->ff_effects_max = user_dev->ff_effects_max; | 372 | udev->ff_effects_max = user_dev->ff_effects_max; |
374 | 373 | ||
375 | size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1; | 374 | /* Ensure name is filled in */ |
376 | if (!size) { | 375 | if (!user_dev->name[0]) { |
377 | retval = -EINVAL; | 376 | retval = -EINVAL; |
378 | goto exit; | 377 | goto exit; |
379 | } | 378 | } |
380 | 379 | ||
381 | kfree(dev->name); | 380 | kfree(dev->name); |
382 | dev->name = name = kmalloc(size, GFP_KERNEL); | 381 | dev->name = kstrndup(user_dev->name, UINPUT_MAX_NAME_SIZE, |
383 | if (!name) { | 382 | GFP_KERNEL); |
383 | if (!dev->name) { | ||
384 | retval = -ENOMEM; | 384 | retval = -ENOMEM; |
385 | goto exit; | 385 | goto exit; |
386 | } | 386 | } |
387 | strlcpy(name, user_dev->name, size); | ||
388 | 387 | ||
389 | dev->id.bustype = user_dev->id.bustype; | 388 | dev->id.bustype = user_dev->id.bustype; |
390 | dev->id.vendor = user_dev->id.vendor; | 389 | dev->id.vendor = user_dev->id.vendor; |
@@ -406,8 +405,7 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu | |||
406 | goto exit; | 405 | goto exit; |
407 | if (test_bit(ABS_MT_SLOT, dev->absbit)) { | 406 | if (test_bit(ABS_MT_SLOT, dev->absbit)) { |
408 | int nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1; | 407 | int nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1; |
409 | input_mt_create_slots(dev, nslot); | 408 | input_mt_init_slots(dev, nslot); |
410 | input_set_events_per_packet(dev, 6 * nslot); | ||
411 | } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) { | 409 | } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) { |
412 | input_set_events_per_packet(dev, 60); | 410 | input_set_events_per_packet(dev, 60); |
413 | } | 411 | } |
@@ -622,7 +620,6 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd, | |||
622 | struct uinput_ff_upload ff_up; | 620 | struct uinput_ff_upload ff_up; |
623 | struct uinput_ff_erase ff_erase; | 621 | struct uinput_ff_erase ff_erase; |
624 | struct uinput_request *req; | 622 | struct uinput_request *req; |
625 | int length; | ||
626 | char *phys; | 623 | char *phys; |
627 | 624 | ||
628 | retval = mutex_lock_interruptible(&udev->mutex); | 625 | retval = mutex_lock_interruptible(&udev->mutex); |
@@ -680,29 +677,24 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd, | |||
680 | retval = uinput_set_bit(arg, swbit, SW_MAX); | 677 | retval = uinput_set_bit(arg, swbit, SW_MAX); |
681 | break; | 678 | break; |
682 | 679 | ||
680 | case UI_SET_PROPBIT: | ||
681 | retval = uinput_set_bit(arg, propbit, INPUT_PROP_MAX); | ||
682 | break; | ||
683 | |||
683 | case UI_SET_PHYS: | 684 | case UI_SET_PHYS: |
684 | if (udev->state == UIST_CREATED) { | 685 | if (udev->state == UIST_CREATED) { |
685 | retval = -EINVAL; | 686 | retval = -EINVAL; |
686 | goto out; | 687 | goto out; |
687 | } | 688 | } |
688 | length = strnlen_user(p, 1024); | 689 | |
689 | if (length <= 0) { | 690 | phys = strndup_user(p, 1024); |
690 | retval = -EFAULT; | 691 | if (IS_ERR(phys)) { |
691 | break; | 692 | retval = PTR_ERR(phys); |
693 | goto out; | ||
692 | } | 694 | } |
695 | |||
693 | kfree(udev->dev->phys); | 696 | kfree(udev->dev->phys); |
694 | udev->dev->phys = phys = kmalloc(length, GFP_KERNEL); | 697 | udev->dev->phys = phys; |
695 | if (!phys) { | ||
696 | retval = -ENOMEM; | ||
697 | break; | ||
698 | } | ||
699 | if (copy_from_user(phys, p, length)) { | ||
700 | udev->dev->phys = NULL; | ||
701 | kfree(phys); | ||
702 | retval = -EFAULT; | ||
703 | break; | ||
704 | } | ||
705 | phys[length - 1] = '\0'; | ||
706 | break; | 698 | break; |
707 | 699 | ||
708 | case UI_BEGIN_FF_UPLOAD: | 700 | case UI_BEGIN_FF_UPLOAD: |
@@ -811,6 +803,7 @@ static const struct file_operations uinput_fops = { | |||
811 | #ifdef CONFIG_COMPAT | 803 | #ifdef CONFIG_COMPAT |
812 | .compat_ioctl = uinput_compat_ioctl, | 804 | .compat_ioctl = uinput_compat_ioctl, |
813 | #endif | 805 | #endif |
806 | .llseek = no_llseek, | ||
814 | }; | 807 | }; |
815 | 808 | ||
816 | static struct miscdevice uinput_misc = { | 809 | static struct miscdevice uinput_misc = { |
diff --git a/drivers/input/misc/winbond-cir.c b/drivers/input/misc/winbond-cir.c deleted file mode 100644 index 64f1de7960c6..000000000000 --- a/drivers/input/misc/winbond-cir.c +++ /dev/null | |||
@@ -1,1608 +0,0 @@ | |||
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 | #include <linux/slab.h> | ||
60 | |||
61 | #define DRVNAME "winbond-cir" | ||
62 | |||
63 | /* CEIR Wake-Up Registers, relative to data->wbase */ | ||
64 | #define WBCIR_REG_WCEIR_CTL 0x03 /* CEIR Receiver Control */ | ||
65 | #define WBCIR_REG_WCEIR_STS 0x04 /* CEIR Receiver Status */ | ||
66 | #define WBCIR_REG_WCEIR_EV_EN 0x05 /* CEIR Receiver Event Enable */ | ||
67 | #define WBCIR_REG_WCEIR_CNTL 0x06 /* CEIR Receiver Counter Low */ | ||
68 | #define WBCIR_REG_WCEIR_CNTH 0x07 /* CEIR Receiver Counter High */ | ||
69 | #define WBCIR_REG_WCEIR_INDEX 0x08 /* CEIR Receiver Index */ | ||
70 | #define WBCIR_REG_WCEIR_DATA 0x09 /* CEIR Receiver Data */ | ||
71 | #define WBCIR_REG_WCEIR_CSL 0x0A /* CEIR Re. Compare Strlen */ | ||
72 | #define WBCIR_REG_WCEIR_CFG1 0x0B /* CEIR Re. Configuration 1 */ | ||
73 | #define WBCIR_REG_WCEIR_CFG2 0x0C /* CEIR Re. Configuration 2 */ | ||
74 | |||
75 | /* CEIR Enhanced Functionality Registers, relative to data->ebase */ | ||
76 | #define WBCIR_REG_ECEIR_CTS 0x00 /* Enhanced IR Control Status */ | ||
77 | #define WBCIR_REG_ECEIR_CCTL 0x01 /* Infrared Counter Control */ | ||
78 | #define WBCIR_REG_ECEIR_CNT_LO 0x02 /* Infrared Counter LSB */ | ||
79 | #define WBCIR_REG_ECEIR_CNT_HI 0x03 /* Infrared Counter MSB */ | ||
80 | #define WBCIR_REG_ECEIR_IREM 0x04 /* Infrared Emitter Status */ | ||
81 | |||
82 | /* SP3 Banked Registers, relative to data->sbase */ | ||
83 | #define WBCIR_REG_SP3_BSR 0x03 /* Bank Select, all banks */ | ||
84 | /* Bank 0 */ | ||
85 | #define WBCIR_REG_SP3_RXDATA 0x00 /* FIFO RX data (r) */ | ||
86 | #define WBCIR_REG_SP3_TXDATA 0x00 /* FIFO TX data (w) */ | ||
87 | #define WBCIR_REG_SP3_IER 0x01 /* Interrupt Enable */ | ||
88 | #define WBCIR_REG_SP3_EIR 0x02 /* Event Identification (r) */ | ||
89 | #define WBCIR_REG_SP3_FCR 0x02 /* FIFO Control (w) */ | ||
90 | #define WBCIR_REG_SP3_MCR 0x04 /* Mode Control */ | ||
91 | #define WBCIR_REG_SP3_LSR 0x05 /* Link Status */ | ||
92 | #define WBCIR_REG_SP3_MSR 0x06 /* Modem Status */ | ||
93 | #define WBCIR_REG_SP3_ASCR 0x07 /* Aux Status and Control */ | ||
94 | /* Bank 2 */ | ||
95 | #define WBCIR_REG_SP3_BGDL 0x00 /* Baud Divisor LSB */ | ||
96 | #define WBCIR_REG_SP3_BGDH 0x01 /* Baud Divisor MSB */ | ||
97 | #define WBCIR_REG_SP3_EXCR1 0x02 /* Extended Control 1 */ | ||
98 | #define WBCIR_REG_SP3_EXCR2 0x04 /* Extended Control 2 */ | ||
99 | #define WBCIR_REG_SP3_TXFLV 0x06 /* TX FIFO Level */ | ||
100 | #define WBCIR_REG_SP3_RXFLV 0x07 /* RX FIFO Level */ | ||
101 | /* Bank 3 */ | ||
102 | #define WBCIR_REG_SP3_MRID 0x00 /* Module Identification */ | ||
103 | #define WBCIR_REG_SP3_SH_LCR 0x01 /* LCR Shadow */ | ||
104 | #define WBCIR_REG_SP3_SH_FCR 0x02 /* FCR Shadow */ | ||
105 | /* Bank 4 */ | ||
106 | #define WBCIR_REG_SP3_IRCR1 0x02 /* Infrared Control 1 */ | ||
107 | /* Bank 5 */ | ||
108 | #define WBCIR_REG_SP3_IRCR2 0x04 /* Infrared Control 2 */ | ||
109 | /* Bank 6 */ | ||
110 | #define WBCIR_REG_SP3_IRCR3 0x00 /* Infrared Control 3 */ | ||
111 | #define WBCIR_REG_SP3_SIR_PW 0x02 /* SIR Pulse Width */ | ||
112 | /* Bank 7 */ | ||
113 | #define WBCIR_REG_SP3_IRRXDC 0x00 /* IR RX Demod Control */ | ||
114 | #define WBCIR_REG_SP3_IRTXMC 0x01 /* IR TX Mod Control */ | ||
115 | #define WBCIR_REG_SP3_RCCFG 0x02 /* CEIR Config */ | ||
116 | #define WBCIR_REG_SP3_IRCFG1 0x04 /* Infrared Config 1 */ | ||
117 | #define WBCIR_REG_SP3_IRCFG4 0x07 /* Infrared Config 4 */ | ||
118 | |||
119 | /* | ||
120 | * Magic values follow | ||
121 | */ | ||
122 | |||
123 | /* No interrupts for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ | ||
124 | #define WBCIR_IRQ_NONE 0x00 | ||
125 | /* RX data bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ | ||
126 | #define WBCIR_IRQ_RX 0x01 | ||
127 | /* Over/Under-flow bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */ | ||
128 | #define WBCIR_IRQ_ERR 0x04 | ||
129 | /* Led enable/disable bit for WBCIR_REG_ECEIR_CTS */ | ||
130 | #define WBCIR_LED_ENABLE 0x80 | ||
131 | /* RX data available bit for WBCIR_REG_SP3_LSR */ | ||
132 | #define WBCIR_RX_AVAIL 0x01 | ||
133 | /* RX disable bit for WBCIR_REG_SP3_ASCR */ | ||
134 | #define WBCIR_RX_DISABLE 0x20 | ||
135 | /* Extended mode enable bit for WBCIR_REG_SP3_EXCR1 */ | ||
136 | #define WBCIR_EXT_ENABLE 0x01 | ||
137 | /* Select compare register in WBCIR_REG_WCEIR_INDEX (bits 5 & 6) */ | ||
138 | #define WBCIR_REGSEL_COMPARE 0x10 | ||
139 | /* Select mask register in WBCIR_REG_WCEIR_INDEX (bits 5 & 6) */ | ||
140 | #define WBCIR_REGSEL_MASK 0x20 | ||
141 | /* Starting address of selected register in WBCIR_REG_WCEIR_INDEX */ | ||
142 | #define WBCIR_REG_ADDR0 0x00 | ||
143 | |||
144 | /* Valid banks for the SP3 UART */ | ||
145 | enum wbcir_bank { | ||
146 | WBCIR_BANK_0 = 0x00, | ||
147 | WBCIR_BANK_1 = 0x80, | ||
148 | WBCIR_BANK_2 = 0xE0, | ||
149 | WBCIR_BANK_3 = 0xE4, | ||
150 | WBCIR_BANK_4 = 0xE8, | ||
151 | WBCIR_BANK_5 = 0xEC, | ||
152 | WBCIR_BANK_6 = 0xF0, | ||
153 | WBCIR_BANK_7 = 0xF4, | ||
154 | }; | ||
155 | |||
156 | /* Supported IR Protocols */ | ||
157 | enum wbcir_protocol { | ||
158 | IR_PROTOCOL_RC5 = 0x0, | ||
159 | IR_PROTOCOL_NEC = 0x1, | ||
160 | IR_PROTOCOL_RC6 = 0x2, | ||
161 | }; | ||
162 | |||
163 | /* Misc */ | ||
164 | #define WBCIR_NAME "Winbond CIR" | ||
165 | #define WBCIR_ID_FAMILY 0xF1 /* Family ID for the WPCD376I */ | ||
166 | #define WBCIR_ID_CHIP 0x04 /* Chip ID for the WPCD376I */ | ||
167 | #define IR_KEYPRESS_TIMEOUT 250 /* FIXME: should be per-protocol? */ | ||
168 | #define INVALID_SCANCODE 0x7FFFFFFF /* Invalid with all protos */ | ||
169 | #define WAKEUP_IOMEM_LEN 0x10 /* Wake-Up I/O Reg Len */ | ||
170 | #define EHFUNC_IOMEM_LEN 0x10 /* Enhanced Func I/O Reg Len */ | ||
171 | #define SP_IOMEM_LEN 0x08 /* Serial Port 3 (IR) Reg Len */ | ||
172 | #define WBCIR_MAX_IDLE_BYTES 10 | ||
173 | |||
174 | static DEFINE_SPINLOCK(wbcir_lock); | ||
175 | static DEFINE_RWLOCK(keytable_lock); | ||
176 | |||
177 | struct wbcir_key { | ||
178 | u32 scancode; | ||
179 | unsigned int keycode; | ||
180 | }; | ||
181 | |||
182 | struct wbcir_keyentry { | ||
183 | struct wbcir_key key; | ||
184 | struct list_head list; | ||
185 | }; | ||
186 | |||
187 | static struct wbcir_key rc6_def_keymap[] = { | ||
188 | { 0x800F0400, KEY_NUMERIC_0 }, | ||
189 | { 0x800F0401, KEY_NUMERIC_1 }, | ||
190 | { 0x800F0402, KEY_NUMERIC_2 }, | ||
191 | { 0x800F0403, KEY_NUMERIC_3 }, | ||
192 | { 0x800F0404, KEY_NUMERIC_4 }, | ||
193 | { 0x800F0405, KEY_NUMERIC_5 }, | ||
194 | { 0x800F0406, KEY_NUMERIC_6 }, | ||
195 | { 0x800F0407, KEY_NUMERIC_7 }, | ||
196 | { 0x800F0408, KEY_NUMERIC_8 }, | ||
197 | { 0x800F0409, KEY_NUMERIC_9 }, | ||
198 | { 0x800F041D, KEY_NUMERIC_STAR }, | ||
199 | { 0x800F041C, KEY_NUMERIC_POUND }, | ||
200 | { 0x800F0410, KEY_VOLUMEUP }, | ||
201 | { 0x800F0411, KEY_VOLUMEDOWN }, | ||
202 | { 0x800F0412, KEY_CHANNELUP }, | ||
203 | { 0x800F0413, KEY_CHANNELDOWN }, | ||
204 | { 0x800F040E, KEY_MUTE }, | ||
205 | { 0x800F040D, KEY_VENDOR }, /* Vista Logo Key */ | ||
206 | { 0x800F041E, KEY_UP }, | ||
207 | { 0x800F041F, KEY_DOWN }, | ||
208 | { 0x800F0420, KEY_LEFT }, | ||
209 | { 0x800F0421, KEY_RIGHT }, | ||
210 | { 0x800F0422, KEY_OK }, | ||
211 | { 0x800F0423, KEY_ESC }, | ||
212 | { 0x800F040F, KEY_INFO }, | ||
213 | { 0x800F040A, KEY_CLEAR }, | ||
214 | { 0x800F040B, KEY_ENTER }, | ||
215 | { 0x800F045B, KEY_RED }, | ||
216 | { 0x800F045C, KEY_GREEN }, | ||
217 | { 0x800F045D, KEY_YELLOW }, | ||
218 | { 0x800F045E, KEY_BLUE }, | ||
219 | { 0x800F045A, KEY_TEXT }, | ||
220 | { 0x800F0427, KEY_SWITCHVIDEOMODE }, | ||
221 | { 0x800F040C, KEY_POWER }, | ||
222 | { 0x800F0450, KEY_RADIO }, | ||
223 | { 0x800F0448, KEY_PVR }, | ||
224 | { 0x800F0447, KEY_AUDIO }, | ||
225 | { 0x800F0426, KEY_EPG }, | ||
226 | { 0x800F0449, KEY_CAMERA }, | ||
227 | { 0x800F0425, KEY_TV }, | ||
228 | { 0x800F044A, KEY_VIDEO }, | ||
229 | { 0x800F0424, KEY_DVD }, | ||
230 | { 0x800F0416, KEY_PLAY }, | ||
231 | { 0x800F0418, KEY_PAUSE }, | ||
232 | { 0x800F0419, KEY_STOP }, | ||
233 | { 0x800F0414, KEY_FASTFORWARD }, | ||
234 | { 0x800F041A, KEY_NEXT }, | ||
235 | { 0x800F041B, KEY_PREVIOUS }, | ||
236 | { 0x800F0415, KEY_REWIND }, | ||
237 | { 0x800F0417, KEY_RECORD }, | ||
238 | }; | ||
239 | |||
240 | /* Registers and other state is protected by wbcir_lock */ | ||
241 | struct wbcir_data { | ||
242 | unsigned long wbase; /* Wake-Up Baseaddr */ | ||
243 | unsigned long ebase; /* Enhanced Func. Baseaddr */ | ||
244 | unsigned long sbase; /* Serial Port Baseaddr */ | ||
245 | unsigned int irq; /* Serial Port IRQ */ | ||
246 | |||
247 | struct input_dev *input_dev; | ||
248 | struct timer_list timer_keyup; | ||
249 | struct led_trigger *rxtrigger; | ||
250 | struct led_trigger *txtrigger; | ||
251 | struct led_classdev led; | ||
252 | |||
253 | u32 last_scancode; | ||
254 | unsigned int last_keycode; | ||
255 | u8 last_toggle; | ||
256 | u8 keypressed; | ||
257 | unsigned long keyup_jiffies; | ||
258 | unsigned int idle_count; | ||
259 | |||
260 | /* RX irdata and parsing state */ | ||
261 | unsigned long irdata[30]; | ||
262 | unsigned int irdata_count; | ||
263 | unsigned int irdata_idle; | ||
264 | unsigned int irdata_off; | ||
265 | unsigned int irdata_error; | ||
266 | |||
267 | /* Protected by keytable_lock */ | ||
268 | struct list_head keytable; | ||
269 | }; | ||
270 | |||
271 | static enum wbcir_protocol protocol = IR_PROTOCOL_RC6; | ||
272 | module_param(protocol, uint, 0444); | ||
273 | MODULE_PARM_DESC(protocol, "IR protocol to use " | ||
274 | "(0 = RC5, 1 = NEC, 2 = RC6A, default)"); | ||
275 | |||
276 | static int invert; /* default = 0 */ | ||
277 | module_param(invert, bool, 0444); | ||
278 | MODULE_PARM_DESC(invert, "Invert the signal from the IR receiver"); | ||
279 | |||
280 | static unsigned int wake_sc = 0x800F040C; | ||
281 | module_param(wake_sc, uint, 0644); | ||
282 | MODULE_PARM_DESC(wake_sc, "Scancode of the power-on IR command"); | ||
283 | |||
284 | static unsigned int wake_rc6mode = 6; | ||
285 | module_param(wake_rc6mode, uint, 0644); | ||
286 | MODULE_PARM_DESC(wake_rc6mode, "RC6 mode for the power-on command " | ||
287 | "(0 = 0, 6 = 6A, default)"); | ||
288 | |||
289 | |||
290 | |||
291 | /***************************************************************************** | ||
292 | * | ||
293 | * UTILITY FUNCTIONS | ||
294 | * | ||
295 | *****************************************************************************/ | ||
296 | |||
297 | /* Caller needs to hold wbcir_lock */ | ||
298 | static void | ||
299 | wbcir_set_bits(unsigned long addr, u8 bits, u8 mask) | ||
300 | { | ||
301 | u8 val; | ||
302 | |||
303 | val = inb(addr); | ||
304 | val = ((val & ~mask) | (bits & mask)); | ||
305 | outb(val, addr); | ||
306 | } | ||
307 | |||
308 | /* Selects the register bank for the serial port */ | ||
309 | static inline void | ||
310 | wbcir_select_bank(struct wbcir_data *data, enum wbcir_bank bank) | ||
311 | { | ||
312 | outb(bank, data->sbase + WBCIR_REG_SP3_BSR); | ||
313 | } | ||
314 | |||
315 | static enum led_brightness | ||
316 | wbcir_led_brightness_get(struct led_classdev *led_cdev) | ||
317 | { | ||
318 | struct wbcir_data *data = container_of(led_cdev, | ||
319 | struct wbcir_data, | ||
320 | led); | ||
321 | |||
322 | if (inb(data->ebase + WBCIR_REG_ECEIR_CTS) & WBCIR_LED_ENABLE) | ||
323 | return LED_FULL; | ||
324 | else | ||
325 | return LED_OFF; | ||
326 | } | ||
327 | |||
328 | static void | ||
329 | wbcir_led_brightness_set(struct led_classdev *led_cdev, | ||
330 | enum led_brightness brightness) | ||
331 | { | ||
332 | struct wbcir_data *data = container_of(led_cdev, | ||
333 | struct wbcir_data, | ||
334 | led); | ||
335 | |||
336 | wbcir_set_bits(data->ebase + WBCIR_REG_ECEIR_CTS, | ||
337 | brightness == LED_OFF ? 0x00 : WBCIR_LED_ENABLE, | ||
338 | WBCIR_LED_ENABLE); | ||
339 | } | ||
340 | |||
341 | /* Manchester encodes bits to RC6 message cells (see wbcir_parse_rc6) */ | ||
342 | static u8 | ||
343 | wbcir_to_rc6cells(u8 val) | ||
344 | { | ||
345 | u8 coded = 0x00; | ||
346 | int i; | ||
347 | |||
348 | val &= 0x0F; | ||
349 | for (i = 0; i < 4; i++) { | ||
350 | if (val & 0x01) | ||
351 | coded |= 0x02 << (i * 2); | ||
352 | else | ||
353 | coded |= 0x01 << (i * 2); | ||
354 | val >>= 1; | ||
355 | } | ||
356 | |||
357 | return coded; | ||
358 | } | ||
359 | |||
360 | |||
361 | |||
362 | /***************************************************************************** | ||
363 | * | ||
364 | * INPUT FUNCTIONS | ||
365 | * | ||
366 | *****************************************************************************/ | ||
367 | |||
368 | static unsigned int | ||
369 | wbcir_do_getkeycode(struct wbcir_data *data, u32 scancode) | ||
370 | { | ||
371 | struct wbcir_keyentry *keyentry; | ||
372 | unsigned int keycode = KEY_RESERVED; | ||
373 | unsigned long flags; | ||
374 | |||
375 | read_lock_irqsave(&keytable_lock, flags); | ||
376 | |||
377 | list_for_each_entry(keyentry, &data->keytable, list) { | ||
378 | if (keyentry->key.scancode == scancode) { | ||
379 | keycode = keyentry->key.keycode; | ||
380 | break; | ||
381 | } | ||
382 | } | ||
383 | |||
384 | read_unlock_irqrestore(&keytable_lock, flags); | ||
385 | return keycode; | ||
386 | } | ||
387 | |||
388 | static int | ||
389 | wbcir_getkeycode(struct input_dev *dev, | ||
390 | unsigned int scancode, unsigned int *keycode) | ||
391 | { | ||
392 | struct wbcir_data *data = input_get_drvdata(dev); | ||
393 | |||
394 | *keycode = wbcir_do_getkeycode(data, scancode); | ||
395 | return 0; | ||
396 | } | ||
397 | |||
398 | static int | ||
399 | wbcir_setkeycode(struct input_dev *dev, | ||
400 | unsigned int scancode, unsigned int keycode) | ||
401 | { | ||
402 | struct wbcir_data *data = input_get_drvdata(dev); | ||
403 | struct wbcir_keyentry *keyentry; | ||
404 | struct wbcir_keyentry *new_keyentry; | ||
405 | unsigned long flags; | ||
406 | unsigned int old_keycode = KEY_RESERVED; | ||
407 | |||
408 | new_keyentry = kmalloc(sizeof(*new_keyentry), GFP_KERNEL); | ||
409 | if (!new_keyentry) | ||
410 | return -ENOMEM; | ||
411 | |||
412 | write_lock_irqsave(&keytable_lock, flags); | ||
413 | |||
414 | list_for_each_entry(keyentry, &data->keytable, list) { | ||
415 | if (keyentry->key.scancode != scancode) | ||
416 | continue; | ||
417 | |||
418 | old_keycode = keyentry->key.keycode; | ||
419 | keyentry->key.keycode = keycode; | ||
420 | |||
421 | if (keyentry->key.keycode == KEY_RESERVED) { | ||
422 | list_del(&keyentry->list); | ||
423 | kfree(keyentry); | ||
424 | } | ||
425 | |||
426 | break; | ||
427 | } | ||
428 | |||
429 | set_bit(keycode, dev->keybit); | ||
430 | |||
431 | if (old_keycode == KEY_RESERVED) { | ||
432 | new_keyentry->key.scancode = scancode; | ||
433 | new_keyentry->key.keycode = keycode; | ||
434 | list_add(&new_keyentry->list, &data->keytable); | ||
435 | } else { | ||
436 | kfree(new_keyentry); | ||
437 | clear_bit(old_keycode, dev->keybit); | ||
438 | list_for_each_entry(keyentry, &data->keytable, list) { | ||
439 | if (keyentry->key.keycode == old_keycode) { | ||
440 | set_bit(old_keycode, dev->keybit); | ||
441 | break; | ||
442 | } | ||
443 | } | ||
444 | } | ||
445 | |||
446 | write_unlock_irqrestore(&keytable_lock, flags); | ||
447 | return 0; | ||
448 | } | ||
449 | |||
450 | /* | ||
451 | * Timer function to report keyup event some time after keydown is | ||
452 | * reported by the ISR. | ||
453 | */ | ||
454 | static void | ||
455 | wbcir_keyup(unsigned long cookie) | ||
456 | { | ||
457 | struct wbcir_data *data = (struct wbcir_data *)cookie; | ||
458 | unsigned long flags; | ||
459 | |||
460 | /* | ||
461 | * data->keyup_jiffies is used to prevent a race condition if a | ||
462 | * hardware interrupt occurs at this point and the keyup timer | ||
463 | * event is moved further into the future as a result. | ||
464 | * | ||
465 | * The timer will then be reactivated and this function called | ||
466 | * again in the future. We need to exit gracefully in that case | ||
467 | * to allow the input subsystem to do its auto-repeat magic or | ||
468 | * a keyup event might follow immediately after the keydown. | ||
469 | */ | ||
470 | |||
471 | spin_lock_irqsave(&wbcir_lock, flags); | ||
472 | |||
473 | if (time_is_after_eq_jiffies(data->keyup_jiffies) && data->keypressed) { | ||
474 | data->keypressed = 0; | ||
475 | led_trigger_event(data->rxtrigger, LED_OFF); | ||
476 | input_report_key(data->input_dev, data->last_keycode, 0); | ||
477 | input_sync(data->input_dev); | ||
478 | } | ||
479 | |||
480 | spin_unlock_irqrestore(&wbcir_lock, flags); | ||
481 | } | ||
482 | |||
483 | static void | ||
484 | wbcir_keydown(struct wbcir_data *data, u32 scancode, u8 toggle) | ||
485 | { | ||
486 | unsigned int keycode; | ||
487 | |||
488 | /* Repeat? */ | ||
489 | if (data->last_scancode == scancode && | ||
490 | data->last_toggle == toggle && | ||
491 | data->keypressed) | ||
492 | goto set_timer; | ||
493 | data->last_scancode = scancode; | ||
494 | |||
495 | /* Do we need to release an old keypress? */ | ||
496 | if (data->keypressed) { | ||
497 | input_report_key(data->input_dev, data->last_keycode, 0); | ||
498 | input_sync(data->input_dev); | ||
499 | data->keypressed = 0; | ||
500 | } | ||
501 | |||
502 | /* Report scancode */ | ||
503 | input_event(data->input_dev, EV_MSC, MSC_SCAN, (int)scancode); | ||
504 | |||
505 | /* Do we know this scancode? */ | ||
506 | keycode = wbcir_do_getkeycode(data, scancode); | ||
507 | if (keycode == KEY_RESERVED) | ||
508 | goto set_timer; | ||
509 | |||
510 | /* Register a keypress */ | ||
511 | input_report_key(data->input_dev, keycode, 1); | ||
512 | data->keypressed = 1; | ||
513 | data->last_keycode = keycode; | ||
514 | data->last_toggle = toggle; | ||
515 | |||
516 | set_timer: | ||
517 | input_sync(data->input_dev); | ||
518 | led_trigger_event(data->rxtrigger, | ||
519 | data->keypressed ? LED_FULL : LED_OFF); | ||
520 | data->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT); | ||
521 | mod_timer(&data->timer_keyup, data->keyup_jiffies); | ||
522 | } | ||
523 | |||
524 | |||
525 | |||
526 | /***************************************************************************** | ||
527 | * | ||
528 | * IR PARSING FUNCTIONS | ||
529 | * | ||
530 | *****************************************************************************/ | ||
531 | |||
532 | /* Resets all irdata */ | ||
533 | static void | ||
534 | wbcir_reset_irdata(struct wbcir_data *data) | ||
535 | { | ||
536 | memset(data->irdata, 0, sizeof(data->irdata)); | ||
537 | data->irdata_count = 0; | ||
538 | data->irdata_off = 0; | ||
539 | data->irdata_error = 0; | ||
540 | data->idle_count = 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_dbg(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 | } | ||
1010 | |||
1011 | out: | ||
1012 | spin_unlock_irqrestore(&wbcir_lock, flags); | ||
1013 | return IRQ_HANDLED; | ||
1014 | } | ||
1015 | |||
1016 | |||
1017 | |||
1018 | /***************************************************************************** | ||
1019 | * | ||
1020 | * SETUP/INIT/SUSPEND/RESUME FUNCTIONS | ||
1021 | * | ||
1022 | *****************************************************************************/ | ||
1023 | |||
1024 | static void | ||
1025 | wbcir_shutdown(struct pnp_dev *device) | ||
1026 | { | ||
1027 | struct device *dev = &device->dev; | ||
1028 | struct wbcir_data *data = pnp_get_drvdata(device); | ||
1029 | int do_wake = 1; | ||
1030 | u8 match[11]; | ||
1031 | u8 mask[11]; | ||
1032 | u8 rc6_csl = 0; | ||
1033 | int i; | ||
1034 | |||
1035 | memset(match, 0, sizeof(match)); | ||
1036 | memset(mask, 0, sizeof(mask)); | ||
1037 | |||
1038 | if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) { | ||
1039 | do_wake = 0; | ||
1040 | goto finish; | ||
1041 | } | ||
1042 | |||
1043 | switch (protocol) { | ||
1044 | case IR_PROTOCOL_RC5: | ||
1045 | if (wake_sc > 0xFFF) { | ||
1046 | do_wake = 0; | ||
1047 | dev_err(dev, "RC5 - Invalid wake scancode\n"); | ||
1048 | break; | ||
1049 | } | ||
1050 | |||
1051 | /* Mask = 13 bits, ex toggle */ | ||
1052 | mask[0] = 0xFF; | ||
1053 | mask[1] = 0x17; | ||
1054 | |||
1055 | match[0] = (wake_sc & 0x003F); /* 6 command bits */ | ||
1056 | match[0] |= (wake_sc & 0x0180) >> 1; /* 2 address bits */ | ||
1057 | match[1] = (wake_sc & 0x0E00) >> 9; /* 3 address bits */ | ||
1058 | if (!(wake_sc & 0x0040)) /* 2nd start bit */ | ||
1059 | match[1] |= 0x10; | ||
1060 | |||
1061 | break; | ||
1062 | |||
1063 | case IR_PROTOCOL_NEC: | ||
1064 | if (wake_sc > 0xFFFFFF) { | ||
1065 | do_wake = 0; | ||
1066 | dev_err(dev, "NEC - Invalid wake scancode\n"); | ||
1067 | break; | ||
1068 | } | ||
1069 | |||
1070 | mask[0] = mask[1] = mask[2] = mask[3] = 0xFF; | ||
1071 | |||
1072 | match[1] = bitrev8((wake_sc & 0xFF)); | ||
1073 | match[0] = ~match[1]; | ||
1074 | |||
1075 | match[3] = bitrev8((wake_sc & 0xFF00) >> 8); | ||
1076 | if (wake_sc > 0xFFFF) | ||
1077 | match[2] = bitrev8((wake_sc & 0xFF0000) >> 16); | ||
1078 | else | ||
1079 | match[2] = ~match[3]; | ||
1080 | |||
1081 | break; | ||
1082 | |||
1083 | case IR_PROTOCOL_RC6: | ||
1084 | |||
1085 | if (wake_rc6mode == 0) { | ||
1086 | if (wake_sc > 0xFFFF) { | ||
1087 | do_wake = 0; | ||
1088 | dev_err(dev, "RC6 - Invalid wake scancode\n"); | ||
1089 | break; | ||
1090 | } | ||
1091 | |||
1092 | /* Command */ | ||
1093 | match[0] = wbcir_to_rc6cells(wake_sc >> 0); | ||
1094 | mask[0] = 0xFF; | ||
1095 | match[1] = wbcir_to_rc6cells(wake_sc >> 4); | ||
1096 | mask[1] = 0xFF; | ||
1097 | |||
1098 | /* Address */ | ||
1099 | match[2] = wbcir_to_rc6cells(wake_sc >> 8); | ||
1100 | mask[2] = 0xFF; | ||
1101 | match[3] = wbcir_to_rc6cells(wake_sc >> 12); | ||
1102 | mask[3] = 0xFF; | ||
1103 | |||
1104 | /* Header */ | ||
1105 | match[4] = 0x50; /* mode1 = mode0 = 0, ignore toggle */ | ||
1106 | mask[4] = 0xF0; | ||
1107 | match[5] = 0x09; /* start bit = 1, mode2 = 0 */ | ||
1108 | mask[5] = 0x0F; | ||
1109 | |||
1110 | rc6_csl = 44; | ||
1111 | |||
1112 | } else if (wake_rc6mode == 6) { | ||
1113 | i = 0; | ||
1114 | |||
1115 | /* Command */ | ||
1116 | match[i] = wbcir_to_rc6cells(wake_sc >> 0); | ||
1117 | mask[i++] = 0xFF; | ||
1118 | match[i] = wbcir_to_rc6cells(wake_sc >> 4); | ||
1119 | mask[i++] = 0xFF; | ||
1120 | |||
1121 | /* Address + Toggle */ | ||
1122 | match[i] = wbcir_to_rc6cells(wake_sc >> 8); | ||
1123 | mask[i++] = 0xFF; | ||
1124 | match[i] = wbcir_to_rc6cells(wake_sc >> 12); | ||
1125 | mask[i++] = 0x3F; | ||
1126 | |||
1127 | /* Customer bits 7 - 0 */ | ||
1128 | match[i] = wbcir_to_rc6cells(wake_sc >> 16); | ||
1129 | mask[i++] = 0xFF; | ||
1130 | match[i] = wbcir_to_rc6cells(wake_sc >> 20); | ||
1131 | mask[i++] = 0xFF; | ||
1132 | |||
1133 | if (wake_sc & 0x80000000) { | ||
1134 | /* Customer range bit and bits 15 - 8 */ | ||
1135 | match[i] = wbcir_to_rc6cells(wake_sc >> 24); | ||
1136 | mask[i++] = 0xFF; | ||
1137 | match[i] = wbcir_to_rc6cells(wake_sc >> 28); | ||
1138 | mask[i++] = 0xFF; | ||
1139 | rc6_csl = 76; | ||
1140 | } else if (wake_sc <= 0x007FFFFF) { | ||
1141 | rc6_csl = 60; | ||
1142 | } else { | ||
1143 | do_wake = 0; | ||
1144 | dev_err(dev, "RC6 - Invalid wake scancode\n"); | ||
1145 | break; | ||
1146 | } | ||
1147 | |||
1148 | /* Header */ | ||
1149 | match[i] = 0x93; /* mode1 = mode0 = 1, submode = 0 */ | ||
1150 | mask[i++] = 0xFF; | ||
1151 | match[i] = 0x0A; /* start bit = 1, mode2 = 1 */ | ||
1152 | mask[i++] = 0x0F; | ||
1153 | |||
1154 | } else { | ||
1155 | do_wake = 0; | ||
1156 | dev_err(dev, "RC6 - Invalid wake mode\n"); | ||
1157 | } | ||
1158 | |||
1159 | break; | ||
1160 | |||
1161 | default: | ||
1162 | do_wake = 0; | ||
1163 | break; | ||
1164 | } | ||
1165 | |||
1166 | finish: | ||
1167 | if (do_wake) { | ||
1168 | /* Set compare and compare mask */ | ||
1169 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX, | ||
1170 | WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0, | ||
1171 | 0x3F); | ||
1172 | outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11); | ||
1173 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX, | ||
1174 | WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0, | ||
1175 | 0x3F); | ||
1176 | outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11); | ||
1177 | |||
1178 | /* RC6 Compare String Len */ | ||
1179 | outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL); | ||
1180 | |||
1181 | /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ | ||
1182 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17); | ||
1183 | |||
1184 | /* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */ | ||
1185 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07); | ||
1186 | |||
1187 | /* Set CEIR_EN */ | ||
1188 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01); | ||
1189 | |||
1190 | } else { | ||
1191 | /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ | ||
1192 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07); | ||
1193 | |||
1194 | /* Clear CEIR_EN */ | ||
1195 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01); | ||
1196 | } | ||
1197 | |||
1198 | /* Disable interrupts */ | ||
1199 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
1200 | outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); | ||
1201 | |||
1202 | /* | ||
1203 | * ACPI will set the HW disable bit for SP3 which means that the | ||
1204 | * output signals are left in an undefined state which may cause | ||
1205 | * spurious interrupts which we need to ignore until the hardware | ||
1206 | * is reinitialized. | ||
1207 | */ | ||
1208 | disable_irq(data->irq); | ||
1209 | } | ||
1210 | |||
1211 | static int | ||
1212 | wbcir_suspend(struct pnp_dev *device, pm_message_t state) | ||
1213 | { | ||
1214 | wbcir_shutdown(device); | ||
1215 | return 0; | ||
1216 | } | ||
1217 | |||
1218 | static void | ||
1219 | wbcir_init_hw(struct wbcir_data *data) | ||
1220 | { | ||
1221 | u8 tmp; | ||
1222 | |||
1223 | /* Disable interrupts */ | ||
1224 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
1225 | outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); | ||
1226 | |||
1227 | /* Set PROT_SEL, RX_INV, Clear CEIR_EN (needed for the led) */ | ||
1228 | tmp = protocol << 4; | ||
1229 | if (invert) | ||
1230 | tmp |= 0x08; | ||
1231 | outb(tmp, data->wbase + WBCIR_REG_WCEIR_CTL); | ||
1232 | |||
1233 | /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ | ||
1234 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17); | ||
1235 | |||
1236 | /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ | ||
1237 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07); | ||
1238 | |||
1239 | /* Set RC5 cell time to correspond to 36 kHz */ | ||
1240 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CFG1, 0x4A, 0x7F); | ||
1241 | |||
1242 | /* Set IRTX_INV */ | ||
1243 | if (invert) | ||
1244 | outb(0x04, data->ebase + WBCIR_REG_ECEIR_CCTL); | ||
1245 | else | ||
1246 | outb(0x00, data->ebase + WBCIR_REG_ECEIR_CCTL); | ||
1247 | |||
1248 | /* | ||
1249 | * Clear IR LED, set SP3 clock to 24Mhz | ||
1250 | * set SP3_IRRX_SW to binary 01, helpfully not documented | ||
1251 | */ | ||
1252 | outb(0x10, data->ebase + WBCIR_REG_ECEIR_CTS); | ||
1253 | |||
1254 | /* Enable extended mode */ | ||
1255 | wbcir_select_bank(data, WBCIR_BANK_2); | ||
1256 | outb(WBCIR_EXT_ENABLE, data->sbase + WBCIR_REG_SP3_EXCR1); | ||
1257 | |||
1258 | /* | ||
1259 | * Configure baud generator, IR data will be sampled at | ||
1260 | * a bitrate of: (24Mhz * prescaler) / (divisor * 16). | ||
1261 | * | ||
1262 | * The ECIR registers include a flag to change the | ||
1263 | * 24Mhz clock freq to 48Mhz. | ||
1264 | * | ||
1265 | * It's not documented in the specs, but fifo levels | ||
1266 | * other than 16 seems to be unsupported. | ||
1267 | */ | ||
1268 | |||
1269 | /* prescaler 1.0, tx/rx fifo lvl 16 */ | ||
1270 | outb(0x30, data->sbase + WBCIR_REG_SP3_EXCR2); | ||
1271 | |||
1272 | /* Set baud divisor to generate one byte per bit/cell */ | ||
1273 | switch (protocol) { | ||
1274 | case IR_PROTOCOL_RC5: | ||
1275 | outb(0xA7, data->sbase + WBCIR_REG_SP3_BGDL); | ||
1276 | break; | ||
1277 | case IR_PROTOCOL_RC6: | ||
1278 | outb(0x53, data->sbase + WBCIR_REG_SP3_BGDL); | ||
1279 | break; | ||
1280 | case IR_PROTOCOL_NEC: | ||
1281 | outb(0x69, data->sbase + WBCIR_REG_SP3_BGDL); | ||
1282 | break; | ||
1283 | } | ||
1284 | outb(0x00, data->sbase + WBCIR_REG_SP3_BGDH); | ||
1285 | |||
1286 | /* Set CEIR mode */ | ||
1287 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
1288 | outb(0xC0, data->sbase + WBCIR_REG_SP3_MCR); | ||
1289 | inb(data->sbase + WBCIR_REG_SP3_LSR); /* Clear LSR */ | ||
1290 | inb(data->sbase + WBCIR_REG_SP3_MSR); /* Clear MSR */ | ||
1291 | |||
1292 | /* Disable RX demod, run-length encoding/decoding, set freq span */ | ||
1293 | wbcir_select_bank(data, WBCIR_BANK_7); | ||
1294 | outb(0x10, data->sbase + WBCIR_REG_SP3_RCCFG); | ||
1295 | |||
1296 | /* Disable timer */ | ||
1297 | wbcir_select_bank(data, WBCIR_BANK_4); | ||
1298 | outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR1); | ||
1299 | |||
1300 | /* Enable MSR interrupt, Clear AUX_IRX */ | ||
1301 | wbcir_select_bank(data, WBCIR_BANK_5); | ||
1302 | outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR2); | ||
1303 | |||
1304 | /* Disable CRC */ | ||
1305 | wbcir_select_bank(data, WBCIR_BANK_6); | ||
1306 | outb(0x20, data->sbase + WBCIR_REG_SP3_IRCR3); | ||
1307 | |||
1308 | /* Set RX/TX (de)modulation freq, not really used */ | ||
1309 | wbcir_select_bank(data, WBCIR_BANK_7); | ||
1310 | outb(0xF2, data->sbase + WBCIR_REG_SP3_IRRXDC); | ||
1311 | outb(0x69, data->sbase + WBCIR_REG_SP3_IRTXMC); | ||
1312 | |||
1313 | /* Set invert and pin direction */ | ||
1314 | if (invert) | ||
1315 | outb(0x10, data->sbase + WBCIR_REG_SP3_IRCFG4); | ||
1316 | else | ||
1317 | outb(0x00, data->sbase + WBCIR_REG_SP3_IRCFG4); | ||
1318 | |||
1319 | /* Set FIFO thresholds (RX = 8, TX = 3), reset RX/TX */ | ||
1320 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
1321 | outb(0x97, data->sbase + WBCIR_REG_SP3_FCR); | ||
1322 | |||
1323 | /* Clear AUX status bits */ | ||
1324 | outb(0xE0, data->sbase + WBCIR_REG_SP3_ASCR); | ||
1325 | |||
1326 | /* Enable interrupts */ | ||
1327 | wbcir_reset_irdata(data); | ||
1328 | outb(WBCIR_IRQ_RX | WBCIR_IRQ_ERR, data->sbase + WBCIR_REG_SP3_IER); | ||
1329 | } | ||
1330 | |||
1331 | static int | ||
1332 | wbcir_resume(struct pnp_dev *device) | ||
1333 | { | ||
1334 | struct wbcir_data *data = pnp_get_drvdata(device); | ||
1335 | |||
1336 | wbcir_init_hw(data); | ||
1337 | enable_irq(data->irq); | ||
1338 | |||
1339 | return 0; | ||
1340 | } | ||
1341 | |||
1342 | static int __devinit | ||
1343 | wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id) | ||
1344 | { | ||
1345 | struct device *dev = &device->dev; | ||
1346 | struct wbcir_data *data; | ||
1347 | int err; | ||
1348 | |||
1349 | if (!(pnp_port_len(device, 0) == EHFUNC_IOMEM_LEN && | ||
1350 | pnp_port_len(device, 1) == WAKEUP_IOMEM_LEN && | ||
1351 | pnp_port_len(device, 2) == SP_IOMEM_LEN)) { | ||
1352 | dev_err(dev, "Invalid resources\n"); | ||
1353 | return -ENODEV; | ||
1354 | } | ||
1355 | |||
1356 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
1357 | if (!data) { | ||
1358 | err = -ENOMEM; | ||
1359 | goto exit; | ||
1360 | } | ||
1361 | |||
1362 | pnp_set_drvdata(device, data); | ||
1363 | |||
1364 | data->ebase = pnp_port_start(device, 0); | ||
1365 | data->wbase = pnp_port_start(device, 1); | ||
1366 | data->sbase = pnp_port_start(device, 2); | ||
1367 | data->irq = pnp_irq(device, 0); | ||
1368 | |||
1369 | if (data->wbase == 0 || data->ebase == 0 || | ||
1370 | data->sbase == 0 || data->irq == 0) { | ||
1371 | err = -ENODEV; | ||
1372 | dev_err(dev, "Invalid resources\n"); | ||
1373 | goto exit_free_data; | ||
1374 | } | ||
1375 | |||
1376 | dev_dbg(&device->dev, "Found device " | ||
1377 | "(w: 0x%lX, e: 0x%lX, s: 0x%lX, i: %u)\n", | ||
1378 | data->wbase, data->ebase, data->sbase, data->irq); | ||
1379 | |||
1380 | if (!request_region(data->wbase, WAKEUP_IOMEM_LEN, DRVNAME)) { | ||
1381 | dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", | ||
1382 | data->wbase, data->wbase + WAKEUP_IOMEM_LEN - 1); | ||
1383 | err = -EBUSY; | ||
1384 | goto exit_free_data; | ||
1385 | } | ||
1386 | |||
1387 | if (!request_region(data->ebase, EHFUNC_IOMEM_LEN, DRVNAME)) { | ||
1388 | dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", | ||
1389 | data->ebase, data->ebase + EHFUNC_IOMEM_LEN - 1); | ||
1390 | err = -EBUSY; | ||
1391 | goto exit_release_wbase; | ||
1392 | } | ||
1393 | |||
1394 | if (!request_region(data->sbase, SP_IOMEM_LEN, DRVNAME)) { | ||
1395 | dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", | ||
1396 | data->sbase, data->sbase + SP_IOMEM_LEN - 1); | ||
1397 | err = -EBUSY; | ||
1398 | goto exit_release_ebase; | ||
1399 | } | ||
1400 | |||
1401 | err = request_irq(data->irq, wbcir_irq_handler, | ||
1402 | IRQF_DISABLED, DRVNAME, device); | ||
1403 | if (err) { | ||
1404 | dev_err(dev, "Failed to claim IRQ %u\n", data->irq); | ||
1405 | err = -EBUSY; | ||
1406 | goto exit_release_sbase; | ||
1407 | } | ||
1408 | |||
1409 | led_trigger_register_simple("cir-tx", &data->txtrigger); | ||
1410 | if (!data->txtrigger) { | ||
1411 | err = -ENOMEM; | ||
1412 | goto exit_free_irq; | ||
1413 | } | ||
1414 | |||
1415 | led_trigger_register_simple("cir-rx", &data->rxtrigger); | ||
1416 | if (!data->rxtrigger) { | ||
1417 | err = -ENOMEM; | ||
1418 | goto exit_unregister_txtrigger; | ||
1419 | } | ||
1420 | |||
1421 | data->led.name = "cir::activity"; | ||
1422 | data->led.default_trigger = "cir-rx"; | ||
1423 | data->led.brightness_set = wbcir_led_brightness_set; | ||
1424 | data->led.brightness_get = wbcir_led_brightness_get; | ||
1425 | err = led_classdev_register(&device->dev, &data->led); | ||
1426 | if (err) | ||
1427 | goto exit_unregister_rxtrigger; | ||
1428 | |||
1429 | data->input_dev = input_allocate_device(); | ||
1430 | if (!data->input_dev) { | ||
1431 | err = -ENOMEM; | ||
1432 | goto exit_unregister_led; | ||
1433 | } | ||
1434 | |||
1435 | data->input_dev->evbit[0] = BIT(EV_KEY); | ||
1436 | data->input_dev->name = WBCIR_NAME; | ||
1437 | data->input_dev->phys = "wbcir/cir0"; | ||
1438 | data->input_dev->id.bustype = BUS_HOST; | ||
1439 | data->input_dev->id.vendor = PCI_VENDOR_ID_WINBOND; | ||
1440 | data->input_dev->id.product = WBCIR_ID_FAMILY; | ||
1441 | data->input_dev->id.version = WBCIR_ID_CHIP; | ||
1442 | data->input_dev->getkeycode = wbcir_getkeycode; | ||
1443 | data->input_dev->setkeycode = wbcir_setkeycode; | ||
1444 | input_set_capability(data->input_dev, EV_MSC, MSC_SCAN); | ||
1445 | input_set_drvdata(data->input_dev, data); | ||
1446 | |||
1447 | err = input_register_device(data->input_dev); | ||
1448 | if (err) | ||
1449 | goto exit_free_input; | ||
1450 | |||
1451 | data->last_scancode = INVALID_SCANCODE; | ||
1452 | INIT_LIST_HEAD(&data->keytable); | ||
1453 | setup_timer(&data->timer_keyup, wbcir_keyup, (unsigned long)data); | ||
1454 | |||
1455 | /* Load default keymaps */ | ||
1456 | if (protocol == IR_PROTOCOL_RC6) { | ||
1457 | int i; | ||
1458 | for (i = 0; i < ARRAY_SIZE(rc6_def_keymap); i++) { | ||
1459 | err = wbcir_setkeycode(data->input_dev, | ||
1460 | (int)rc6_def_keymap[i].scancode, | ||
1461 | (int)rc6_def_keymap[i].keycode); | ||
1462 | if (err) | ||
1463 | goto exit_unregister_keys; | ||
1464 | } | ||
1465 | } | ||
1466 | |||
1467 | device_init_wakeup(&device->dev, 1); | ||
1468 | |||
1469 | wbcir_init_hw(data); | ||
1470 | |||
1471 | return 0; | ||
1472 | |||
1473 | exit_unregister_keys: | ||
1474 | if (!list_empty(&data->keytable)) { | ||
1475 | struct wbcir_keyentry *key; | ||
1476 | struct wbcir_keyentry *keytmp; | ||
1477 | |||
1478 | list_for_each_entry_safe(key, keytmp, &data->keytable, list) { | ||
1479 | list_del(&key->list); | ||
1480 | kfree(key); | ||
1481 | } | ||
1482 | } | ||
1483 | input_unregister_device(data->input_dev); | ||
1484 | /* Can't call input_free_device on an unregistered device */ | ||
1485 | data->input_dev = NULL; | ||
1486 | exit_free_input: | ||
1487 | input_free_device(data->input_dev); | ||
1488 | exit_unregister_led: | ||
1489 | led_classdev_unregister(&data->led); | ||
1490 | exit_unregister_rxtrigger: | ||
1491 | led_trigger_unregister_simple(data->rxtrigger); | ||
1492 | exit_unregister_txtrigger: | ||
1493 | led_trigger_unregister_simple(data->txtrigger); | ||
1494 | exit_free_irq: | ||
1495 | free_irq(data->irq, device); | ||
1496 | exit_release_sbase: | ||
1497 | release_region(data->sbase, SP_IOMEM_LEN); | ||
1498 | exit_release_ebase: | ||
1499 | release_region(data->ebase, EHFUNC_IOMEM_LEN); | ||
1500 | exit_release_wbase: | ||
1501 | release_region(data->wbase, WAKEUP_IOMEM_LEN); | ||
1502 | exit_free_data: | ||
1503 | kfree(data); | ||
1504 | pnp_set_drvdata(device, NULL); | ||
1505 | exit: | ||
1506 | return err; | ||
1507 | } | ||
1508 | |||
1509 | static void __devexit | ||
1510 | wbcir_remove(struct pnp_dev *device) | ||
1511 | { | ||
1512 | struct wbcir_data *data = pnp_get_drvdata(device); | ||
1513 | struct wbcir_keyentry *key; | ||
1514 | struct wbcir_keyentry *keytmp; | ||
1515 | |||
1516 | /* Disable interrupts */ | ||
1517 | wbcir_select_bank(data, WBCIR_BANK_0); | ||
1518 | outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); | ||
1519 | |||
1520 | del_timer_sync(&data->timer_keyup); | ||
1521 | |||
1522 | free_irq(data->irq, device); | ||
1523 | |||
1524 | /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ | ||
1525 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17); | ||
1526 | |||
1527 | /* Clear CEIR_EN */ | ||
1528 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01); | ||
1529 | |||
1530 | /* Clear BUFF_EN, END_EN, MATCH_EN */ | ||
1531 | wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07); | ||
1532 | |||
1533 | /* This will generate a keyup event if necessary */ | ||
1534 | input_unregister_device(data->input_dev); | ||
1535 | |||
1536 | led_trigger_unregister_simple(data->rxtrigger); | ||
1537 | led_trigger_unregister_simple(data->txtrigger); | ||
1538 | led_classdev_unregister(&data->led); | ||
1539 | |||
1540 | /* This is ok since &data->led isn't actually used */ | ||
1541 | wbcir_led_brightness_set(&data->led, LED_OFF); | ||
1542 | |||
1543 | release_region(data->wbase, WAKEUP_IOMEM_LEN); | ||
1544 | release_region(data->ebase, EHFUNC_IOMEM_LEN); | ||
1545 | release_region(data->sbase, SP_IOMEM_LEN); | ||
1546 | |||
1547 | list_for_each_entry_safe(key, keytmp, &data->keytable, list) { | ||
1548 | list_del(&key->list); | ||
1549 | kfree(key); | ||
1550 | } | ||
1551 | |||
1552 | kfree(data); | ||
1553 | |||
1554 | pnp_set_drvdata(device, NULL); | ||
1555 | } | ||
1556 | |||
1557 | static const struct pnp_device_id wbcir_ids[] = { | ||
1558 | { "WEC1022", 0 }, | ||
1559 | { "", 0 } | ||
1560 | }; | ||
1561 | MODULE_DEVICE_TABLE(pnp, wbcir_ids); | ||
1562 | |||
1563 | static struct pnp_driver wbcir_driver = { | ||
1564 | .name = WBCIR_NAME, | ||
1565 | .id_table = wbcir_ids, | ||
1566 | .probe = wbcir_probe, | ||
1567 | .remove = __devexit_p(wbcir_remove), | ||
1568 | .suspend = wbcir_suspend, | ||
1569 | .resume = wbcir_resume, | ||
1570 | .shutdown = wbcir_shutdown | ||
1571 | }; | ||
1572 | |||
1573 | static int __init | ||
1574 | wbcir_init(void) | ||
1575 | { | ||
1576 | int ret; | ||
1577 | |||
1578 | switch (protocol) { | ||
1579 | case IR_PROTOCOL_RC5: | ||
1580 | case IR_PROTOCOL_NEC: | ||
1581 | case IR_PROTOCOL_RC6: | ||
1582 | break; | ||
1583 | default: | ||
1584 | printk(KERN_ERR DRVNAME ": Invalid protocol argument\n"); | ||
1585 | return -EINVAL; | ||
1586 | } | ||
1587 | |||
1588 | ret = pnp_register_driver(&wbcir_driver); | ||
1589 | if (ret) | ||
1590 | printk(KERN_ERR DRVNAME ": Unable to register driver\n"); | ||
1591 | |||
1592 | return ret; | ||
1593 | } | ||
1594 | |||
1595 | static void __exit | ||
1596 | wbcir_exit(void) | ||
1597 | { | ||
1598 | pnp_unregister_driver(&wbcir_driver); | ||
1599 | } | ||
1600 | |||
1601 | MODULE_AUTHOR("David Härdeman <david@hardeman.nu>"); | ||
1602 | MODULE_DESCRIPTION("Winbond SuperI/O Consumer IR Driver"); | ||
1603 | MODULE_LICENSE("GPL"); | ||
1604 | |||
1605 | module_init(wbcir_init); | ||
1606 | module_exit(wbcir_exit); | ||
1607 | |||
1608 | |||
diff --git a/drivers/input/misc/wistron_btns.c b/drivers/input/misc/wistron_btns.c index 12501de0c5cd..52b419348983 100644 --- a/drivers/input/misc/wistron_btns.c +++ b/drivers/input/misc/wistron_btns.c | |||
@@ -274,7 +274,7 @@ static struct key_entry keymap_fs_amilo_pro_v3505[] __initdata = { | |||
274 | { KE_BLUETOOTH, 0x30 }, /* Fn+F10 */ | 274 | { KE_BLUETOOTH, 0x30 }, /* Fn+F10 */ |
275 | { KE_KEY, 0x31, {KEY_MAIL} }, /* mail button */ | 275 | { KE_KEY, 0x31, {KEY_MAIL} }, /* mail button */ |
276 | { KE_KEY, 0x36, {KEY_WWW} }, /* www button */ | 276 | { KE_KEY, 0x36, {KEY_WWW} }, /* www button */ |
277 | { KE_WIFI, 0x78 }, /* satelite dish button */ | 277 | { KE_WIFI, 0x78 }, /* satellite dish button */ |
278 | { KE_END, 0 } | 278 | { KE_END, 0 } |
279 | }; | 279 | }; |
280 | 280 | ||
diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c new file mode 100644 index 000000000000..62bae99424e6 --- /dev/null +++ b/drivers/input/misc/xen-kbdfront.c | |||
@@ -0,0 +1,396 @@ | |||
1 | /* | ||
2 | * Xen para-virtual input device | ||
3 | * | ||
4 | * Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com> | ||
5 | * Copyright (C) 2006-2008 Red Hat, Inc., Markus Armbruster <armbru@redhat.com> | ||
6 | * | ||
7 | * Based on linux/drivers/input/mouse/sermouse.c | ||
8 | * | ||
9 | * This file is subject to the terms and conditions of the GNU General Public | ||
10 | * License. See the file COPYING in the main directory of this archive for | ||
11 | * more details. | ||
12 | */ | ||
13 | |||
14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
15 | |||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/errno.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/input.h> | ||
20 | #include <linux/slab.h> | ||
21 | |||
22 | #include <asm/xen/hypervisor.h> | ||
23 | |||
24 | #include <xen/xen.h> | ||
25 | #include <xen/events.h> | ||
26 | #include <xen/page.h> | ||
27 | #include <xen/grant_table.h> | ||
28 | #include <xen/interface/grant_table.h> | ||
29 | #include <xen/interface/io/fbif.h> | ||
30 | #include <xen/interface/io/kbdif.h> | ||
31 | #include <xen/xenbus.h> | ||
32 | |||
33 | struct xenkbd_info { | ||
34 | struct input_dev *kbd; | ||
35 | struct input_dev *ptr; | ||
36 | struct xenkbd_page *page; | ||
37 | int gref; | ||
38 | int irq; | ||
39 | struct xenbus_device *xbdev; | ||
40 | char phys[32]; | ||
41 | }; | ||
42 | |||
43 | static int xenkbd_remove(struct xenbus_device *); | ||
44 | static int xenkbd_connect_backend(struct xenbus_device *, struct xenkbd_info *); | ||
45 | static void xenkbd_disconnect_backend(struct xenkbd_info *); | ||
46 | |||
47 | /* | ||
48 | * Note: if you need to send out events, see xenfb_do_update() for how | ||
49 | * to do that. | ||
50 | */ | ||
51 | |||
52 | static irqreturn_t input_handler(int rq, void *dev_id) | ||
53 | { | ||
54 | struct xenkbd_info *info = dev_id; | ||
55 | struct xenkbd_page *page = info->page; | ||
56 | __u32 cons, prod; | ||
57 | |||
58 | prod = page->in_prod; | ||
59 | if (prod == page->in_cons) | ||
60 | return IRQ_HANDLED; | ||
61 | rmb(); /* ensure we see ring contents up to prod */ | ||
62 | for (cons = page->in_cons; cons != prod; cons++) { | ||
63 | union xenkbd_in_event *event; | ||
64 | struct input_dev *dev; | ||
65 | event = &XENKBD_IN_RING_REF(page, cons); | ||
66 | |||
67 | dev = info->ptr; | ||
68 | switch (event->type) { | ||
69 | case XENKBD_TYPE_MOTION: | ||
70 | input_report_rel(dev, REL_X, event->motion.rel_x); | ||
71 | input_report_rel(dev, REL_Y, event->motion.rel_y); | ||
72 | if (event->motion.rel_z) | ||
73 | input_report_rel(dev, REL_WHEEL, | ||
74 | -event->motion.rel_z); | ||
75 | break; | ||
76 | case XENKBD_TYPE_KEY: | ||
77 | dev = NULL; | ||
78 | if (test_bit(event->key.keycode, info->kbd->keybit)) | ||
79 | dev = info->kbd; | ||
80 | if (test_bit(event->key.keycode, info->ptr->keybit)) | ||
81 | dev = info->ptr; | ||
82 | if (dev) | ||
83 | input_report_key(dev, event->key.keycode, | ||
84 | event->key.pressed); | ||
85 | else | ||
86 | pr_warning("unhandled keycode 0x%x\n", | ||
87 | event->key.keycode); | ||
88 | break; | ||
89 | case XENKBD_TYPE_POS: | ||
90 | input_report_abs(dev, ABS_X, event->pos.abs_x); | ||
91 | input_report_abs(dev, ABS_Y, event->pos.abs_y); | ||
92 | if (event->pos.rel_z) | ||
93 | input_report_rel(dev, REL_WHEEL, | ||
94 | -event->pos.rel_z); | ||
95 | break; | ||
96 | } | ||
97 | if (dev) | ||
98 | input_sync(dev); | ||
99 | } | ||
100 | mb(); /* ensure we got ring contents */ | ||
101 | page->in_cons = cons; | ||
102 | notify_remote_via_irq(info->irq); | ||
103 | |||
104 | return IRQ_HANDLED; | ||
105 | } | ||
106 | |||
107 | static int __devinit xenkbd_probe(struct xenbus_device *dev, | ||
108 | const struct xenbus_device_id *id) | ||
109 | { | ||
110 | int ret, i, abs; | ||
111 | struct xenkbd_info *info; | ||
112 | struct input_dev *kbd, *ptr; | ||
113 | |||
114 | info = kzalloc(sizeof(*info), GFP_KERNEL); | ||
115 | if (!info) { | ||
116 | xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure"); | ||
117 | return -ENOMEM; | ||
118 | } | ||
119 | dev_set_drvdata(&dev->dev, info); | ||
120 | info->xbdev = dev; | ||
121 | info->irq = -1; | ||
122 | info->gref = -1; | ||
123 | snprintf(info->phys, sizeof(info->phys), "xenbus/%s", dev->nodename); | ||
124 | |||
125 | info->page = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO); | ||
126 | if (!info->page) | ||
127 | goto error_nomem; | ||
128 | |||
129 | if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-abs-pointer", "%d", &abs) < 0) | ||
130 | abs = 0; | ||
131 | if (abs) | ||
132 | xenbus_printf(XBT_NIL, dev->nodename, "request-abs-pointer", "1"); | ||
133 | |||
134 | /* keyboard */ | ||
135 | kbd = input_allocate_device(); | ||
136 | if (!kbd) | ||
137 | goto error_nomem; | ||
138 | kbd->name = "Xen Virtual Keyboard"; | ||
139 | kbd->phys = info->phys; | ||
140 | kbd->id.bustype = BUS_PCI; | ||
141 | kbd->id.vendor = 0x5853; | ||
142 | kbd->id.product = 0xffff; | ||
143 | |||
144 | __set_bit(EV_KEY, kbd->evbit); | ||
145 | for (i = KEY_ESC; i < KEY_UNKNOWN; i++) | ||
146 | __set_bit(i, kbd->keybit); | ||
147 | for (i = KEY_OK; i < KEY_MAX; i++) | ||
148 | __set_bit(i, kbd->keybit); | ||
149 | |||
150 | ret = input_register_device(kbd); | ||
151 | if (ret) { | ||
152 | input_free_device(kbd); | ||
153 | xenbus_dev_fatal(dev, ret, "input_register_device(kbd)"); | ||
154 | goto error; | ||
155 | } | ||
156 | info->kbd = kbd; | ||
157 | |||
158 | /* pointing device */ | ||
159 | ptr = input_allocate_device(); | ||
160 | if (!ptr) | ||
161 | goto error_nomem; | ||
162 | ptr->name = "Xen Virtual Pointer"; | ||
163 | ptr->phys = info->phys; | ||
164 | ptr->id.bustype = BUS_PCI; | ||
165 | ptr->id.vendor = 0x5853; | ||
166 | ptr->id.product = 0xfffe; | ||
167 | |||
168 | if (abs) { | ||
169 | __set_bit(EV_ABS, ptr->evbit); | ||
170 | input_set_abs_params(ptr, ABS_X, 0, XENFB_WIDTH, 0, 0); | ||
171 | input_set_abs_params(ptr, ABS_Y, 0, XENFB_HEIGHT, 0, 0); | ||
172 | } else { | ||
173 | input_set_capability(ptr, EV_REL, REL_X); | ||
174 | input_set_capability(ptr, EV_REL, REL_Y); | ||
175 | } | ||
176 | input_set_capability(ptr, EV_REL, REL_WHEEL); | ||
177 | |||
178 | __set_bit(EV_KEY, ptr->evbit); | ||
179 | for (i = BTN_LEFT; i <= BTN_TASK; i++) | ||
180 | __set_bit(i, ptr->keybit); | ||
181 | |||
182 | ret = input_register_device(ptr); | ||
183 | if (ret) { | ||
184 | input_free_device(ptr); | ||
185 | xenbus_dev_fatal(dev, ret, "input_register_device(ptr)"); | ||
186 | goto error; | ||
187 | } | ||
188 | info->ptr = ptr; | ||
189 | |||
190 | ret = xenkbd_connect_backend(dev, info); | ||
191 | if (ret < 0) | ||
192 | goto error; | ||
193 | |||
194 | return 0; | ||
195 | |||
196 | error_nomem: | ||
197 | ret = -ENOMEM; | ||
198 | xenbus_dev_fatal(dev, ret, "allocating device memory"); | ||
199 | error: | ||
200 | xenkbd_remove(dev); | ||
201 | return ret; | ||
202 | } | ||
203 | |||
204 | static int xenkbd_resume(struct xenbus_device *dev) | ||
205 | { | ||
206 | struct xenkbd_info *info = dev_get_drvdata(&dev->dev); | ||
207 | |||
208 | xenkbd_disconnect_backend(info); | ||
209 | memset(info->page, 0, PAGE_SIZE); | ||
210 | return xenkbd_connect_backend(dev, info); | ||
211 | } | ||
212 | |||
213 | static int xenkbd_remove(struct xenbus_device *dev) | ||
214 | { | ||
215 | struct xenkbd_info *info = dev_get_drvdata(&dev->dev); | ||
216 | |||
217 | xenkbd_disconnect_backend(info); | ||
218 | if (info->kbd) | ||
219 | input_unregister_device(info->kbd); | ||
220 | if (info->ptr) | ||
221 | input_unregister_device(info->ptr); | ||
222 | free_page((unsigned long)info->page); | ||
223 | kfree(info); | ||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | static int xenkbd_connect_backend(struct xenbus_device *dev, | ||
228 | struct xenkbd_info *info) | ||
229 | { | ||
230 | int ret, evtchn; | ||
231 | struct xenbus_transaction xbt; | ||
232 | |||
233 | ret = gnttab_grant_foreign_access(dev->otherend_id, | ||
234 | virt_to_mfn(info->page), 0); | ||
235 | if (ret < 0) | ||
236 | return ret; | ||
237 | info->gref = ret; | ||
238 | |||
239 | ret = xenbus_alloc_evtchn(dev, &evtchn); | ||
240 | if (ret) | ||
241 | goto error_grant; | ||
242 | ret = bind_evtchn_to_irqhandler(evtchn, input_handler, | ||
243 | 0, dev->devicetype, info); | ||
244 | if (ret < 0) { | ||
245 | xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler"); | ||
246 | goto error_evtchan; | ||
247 | } | ||
248 | info->irq = ret; | ||
249 | |||
250 | again: | ||
251 | ret = xenbus_transaction_start(&xbt); | ||
252 | if (ret) { | ||
253 | xenbus_dev_fatal(dev, ret, "starting transaction"); | ||
254 | goto error_irqh; | ||
255 | } | ||
256 | ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu", | ||
257 | virt_to_mfn(info->page)); | ||
258 | if (ret) | ||
259 | goto error_xenbus; | ||
260 | ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref); | ||
261 | if (ret) | ||
262 | goto error_xenbus; | ||
263 | ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u", | ||
264 | evtchn); | ||
265 | if (ret) | ||
266 | goto error_xenbus; | ||
267 | ret = xenbus_transaction_end(xbt, 0); | ||
268 | if (ret) { | ||
269 | if (ret == -EAGAIN) | ||
270 | goto again; | ||
271 | xenbus_dev_fatal(dev, ret, "completing transaction"); | ||
272 | goto error_irqh; | ||
273 | } | ||
274 | |||
275 | xenbus_switch_state(dev, XenbusStateInitialised); | ||
276 | return 0; | ||
277 | |||
278 | error_xenbus: | ||
279 | xenbus_transaction_end(xbt, 1); | ||
280 | xenbus_dev_fatal(dev, ret, "writing xenstore"); | ||
281 | error_irqh: | ||
282 | unbind_from_irqhandler(info->irq, info); | ||
283 | info->irq = -1; | ||
284 | error_evtchan: | ||
285 | xenbus_free_evtchn(dev, evtchn); | ||
286 | error_grant: | ||
287 | gnttab_end_foreign_access_ref(info->gref, 0); | ||
288 | info->gref = -1; | ||
289 | return ret; | ||
290 | } | ||
291 | |||
292 | static void xenkbd_disconnect_backend(struct xenkbd_info *info) | ||
293 | { | ||
294 | if (info->irq >= 0) | ||
295 | unbind_from_irqhandler(info->irq, info); | ||
296 | info->irq = -1; | ||
297 | if (info->gref >= 0) | ||
298 | gnttab_end_foreign_access_ref(info->gref, 0); | ||
299 | info->gref = -1; | ||
300 | } | ||
301 | |||
302 | static void xenkbd_backend_changed(struct xenbus_device *dev, | ||
303 | enum xenbus_state backend_state) | ||
304 | { | ||
305 | struct xenkbd_info *info = dev_get_drvdata(&dev->dev); | ||
306 | int ret, val; | ||
307 | |||
308 | switch (backend_state) { | ||
309 | case XenbusStateInitialising: | ||
310 | case XenbusStateInitialised: | ||
311 | case XenbusStateReconfiguring: | ||
312 | case XenbusStateReconfigured: | ||
313 | case XenbusStateUnknown: | ||
314 | case XenbusStateClosed: | ||
315 | break; | ||
316 | |||
317 | case XenbusStateInitWait: | ||
318 | InitWait: | ||
319 | ret = xenbus_scanf(XBT_NIL, info->xbdev->otherend, | ||
320 | "feature-abs-pointer", "%d", &val); | ||
321 | if (ret < 0) | ||
322 | val = 0; | ||
323 | if (val) { | ||
324 | ret = xenbus_printf(XBT_NIL, info->xbdev->nodename, | ||
325 | "request-abs-pointer", "1"); | ||
326 | if (ret) | ||
327 | pr_warning("xenkbd: can't request abs-pointer"); | ||
328 | } | ||
329 | |||
330 | xenbus_switch_state(dev, XenbusStateConnected); | ||
331 | break; | ||
332 | |||
333 | case XenbusStateConnected: | ||
334 | /* | ||
335 | * Work around xenbus race condition: If backend goes | ||
336 | * through InitWait to Connected fast enough, we can | ||
337 | * get Connected twice here. | ||
338 | */ | ||
339 | if (dev->state != XenbusStateConnected) | ||
340 | goto InitWait; /* no InitWait seen yet, fudge it */ | ||
341 | |||
342 | /* Set input abs params to match backend screen res */ | ||
343 | if (xenbus_scanf(XBT_NIL, info->xbdev->otherend, | ||
344 | "width", "%d", &val) > 0) | ||
345 | input_set_abs_params(info->ptr, ABS_X, 0, val, 0, 0); | ||
346 | |||
347 | if (xenbus_scanf(XBT_NIL, info->xbdev->otherend, | ||
348 | "height", "%d", &val) > 0) | ||
349 | input_set_abs_params(info->ptr, ABS_Y, 0, val, 0, 0); | ||
350 | |||
351 | break; | ||
352 | |||
353 | case XenbusStateClosing: | ||
354 | xenbus_frontend_closed(dev); | ||
355 | break; | ||
356 | } | ||
357 | } | ||
358 | |||
359 | static const struct xenbus_device_id xenkbd_ids[] = { | ||
360 | { "vkbd" }, | ||
361 | { "" } | ||
362 | }; | ||
363 | |||
364 | static struct xenbus_driver xenkbd_driver = { | ||
365 | .name = "vkbd", | ||
366 | .owner = THIS_MODULE, | ||
367 | .ids = xenkbd_ids, | ||
368 | .probe = xenkbd_probe, | ||
369 | .remove = xenkbd_remove, | ||
370 | .resume = xenkbd_resume, | ||
371 | .otherend_changed = xenkbd_backend_changed, | ||
372 | }; | ||
373 | |||
374 | static int __init xenkbd_init(void) | ||
375 | { | ||
376 | if (!xen_pv_domain()) | ||
377 | return -ENODEV; | ||
378 | |||
379 | /* Nothing to do if running in dom0. */ | ||
380 | if (xen_initial_domain()) | ||
381 | return -ENODEV; | ||
382 | |||
383 | return xenbus_register_frontend(&xenkbd_driver); | ||
384 | } | ||
385 | |||
386 | static void __exit xenkbd_cleanup(void) | ||
387 | { | ||
388 | xenbus_unregister_driver(&xenkbd_driver); | ||
389 | } | ||
390 | |||
391 | module_init(xenkbd_init); | ||
392 | module_exit(xenkbd_cleanup); | ||
393 | |||
394 | MODULE_DESCRIPTION("Xen virtual keyboard/pointer device frontend"); | ||
395 | MODULE_LICENSE("GPL"); | ||
396 | MODULE_ALIAS("xen:vkbd"); | ||