aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/misc
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-03-20 01:27:06 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-20 01:27:06 -0400
commita952baa034ae7c2e4a66932005cbc7ebbccfe28d (patch)
treeff5abe0c77f5b129946300677d9b57b00d926a1e /drivers/input/misc
parent5bab188a316718a26346cdb25c4cc6b319f8f907 (diff)
parent97eb3f24352ec6632c2127b35d8087d2a809a9b9 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (64 commits) Input: tsc2005 - remove 'disable' sysfs attribute Input: tsc2005 - add open/close Input: tsc2005 - handle read errors from SPI layer Input: tsc2005 - do not rearm timer in hardirq handler Input: tsc2005 - don't use work for 'pen up' handling Input: tsc2005 - do not use 0 in place of NULL Input: tsc2005 - use true/false for boolean variables Input: tsc2005 - hide selftest attribute if we can't reset Input: tsc2005 - rework driver initialization code Input: tsc2005 - set up bus type in input device Input: tsc2005 - set up parent device Input: tsc2005 - clear driver data after unbinding Input: tsc2005 - add module description Input: tsc2005 - remove driver banner message Input: tsc2005 - remove incorrect module alias Input: tsc2005 - convert to using dev_pm_ops Input: tsc2005 - use spi_get/set_drvdata() Input: introduce tsc2005 driver Input: xen-kbdfront - move to drivers/input/misc Input: xen-kbdfront - add grant reference for shared page ...
Diffstat (limited to 'drivers/input/misc')
-rw-r--r--drivers/input/misc/Kconfig13
-rw-r--r--drivers/input/misc/Makefile1
-rw-r--r--drivers/input/misc/ad714x-i2c.c17
-rw-r--r--drivers/input/misc/ad714x-spi.c17
-rw-r--r--drivers/input/misc/adxl34x-i2c.c16
-rw-r--r--drivers/input/misc/adxl34x-spi.c20
-rw-r--r--drivers/input/misc/ati_remote2.c4
-rw-r--r--drivers/input/misc/uinput.c48
-rw-r--r--drivers/input/misc/xen-kbdfront.c385
9 files changed, 453 insertions, 68 deletions
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index b0c6772851a9..f9cf0881b0e3 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -454,4 +454,17 @@ config INPUT_CMA3000_I2C
454 To compile this driver as a module, choose M here: the 454 To compile this driver as a module, choose M here: the
455 module will be called cma3000_d0x_i2c. 455 module will be called cma3000_d0x_i2c.
456 456
457config INPUT_XEN_KBDDEV_FRONTEND
458 tristate "Xen virtual keyboard and mouse support"
459 depends on XEN_FBDEV_FRONTEND
460 default y
461 select XEN_XENBUS_FRONTEND
462 help
463 This driver implements the front-end of the Xen virtual
464 keyboard and mouse device driver. It communicates with a back-end
465 in another domain.
466
467 To compile this driver as a module, choose M here: the
468 module will be called xen-kbdfront.
469
457endif 470endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 9b4797112c9a..e3f7984e6274 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -42,5 +42,6 @@ obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o
42obj-$(CONFIG_INPUT_UINPUT) += uinput.o 42obj-$(CONFIG_INPUT_UINPUT) += uinput.o
43obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o 43obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o
44obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o 44obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
45obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o
45obj-$(CONFIG_INPUT_YEALINK) += yealink.o 46obj-$(CONFIG_INPUT_YEALINK) += yealink.o
46 47
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
16static int ad714x_i2c_suspend(struct i2c_client *client, pm_message_t message) 17static 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
21static int ad714x_i2c_resume(struct i2c_client *client) 22static 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
28static SIMPLE_DEV_PM_OPS(ad714x_i2c_pm, ad714x_i2c_suspend, ad714x_i2c_resume);
29
30static int ad714x_i2c_write(struct device *dev, unsigned short reg, 30static 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);
114static struct i2c_driver ad714x_i2c_driver = { 114static 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
19static int ad714x_spi_suspend(struct spi_device *spi, pm_message_t message) 20static 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
24static int ad714x_spi_resume(struct spi_device *spi) 25static 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
31static SIMPLE_DEV_PM_OPS(ad714x_spi_pm, ad714x_spi_suspend, ad714x_spi_resume);
32
33static int ad714x_spi_read(struct device *dev, unsigned short reg, 33static 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
89static __init int ad714x_spi_init(void) 88static __init int ad714x_spi_init(void)
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
16static int adxl34x_smbus_read(struct device *dev, unsigned char reg) 17static 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
108static int adxl34x_i2c_suspend(struct i2c_client *client, pm_message_t message) 109static 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
117static int adxl34x_i2c_resume(struct i2c_client *client) 119static 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
130static SIMPLE_DEV_PM_OPS(adxl34x_i2c_pm, adxl34x_i2c_suspend,
131 adxl34x_i2c_resume);
132
130static const struct i2c_device_id adxl34x_id[] = { 133static 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
60static const struct adxl34x_bus_ops adx134x_spi_bops = { 61static 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
97static int adxl34x_spi_suspend(struct spi_device *spi, pm_message_t message) 98static 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
106static int adxl34x_spi_resume(struct spi_device *spi) 108static 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
119static SIMPLE_DEV_PM_OPS(adxl34x_spi_pm, adxl34x_spi_suspend,
120 adxl34x_spi_resume);
121
119static struct spi_driver adxl34x_driver = { 122static 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
131static int __init adxl34x_spi_init(void) 133static int __init adxl34x_spi_init(void)
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index 0b0e9be63542..9ccdb82d869a 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -612,8 +612,8 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2)
612 idev->open = ati_remote2_open; 612 idev->open = ati_remote2_open;
613 idev->close = ati_remote2_close; 613 idev->close = ati_remote2_close;
614 614
615 idev->getkeycode_new = ati_remote2_getkeycode; 615 idev->getkeycode = ati_remote2_getkeycode;
616 idev->setkeycode_new = ati_remote2_setkeycode; 616 idev->setkeycode = ati_remote2_setkeycode;
617 617
618 idev->name = ar2->name; 618 idev->name = ar2->name;
619 idev->phys = ar2->phys; 619 idev->phys = ar2->phys;
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 82542a1c1098..364bdf43a381 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -347,8 +347,7 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
347{ 347{
348 struct uinput_user_dev *user_dev; 348 struct uinput_user_dev *user_dev;
349 struct input_dev *dev; 349 struct input_dev *dev;
350 char *name; 350 int i;
351 int i, size;
352 int retval; 351 int retval;
353 352
354 if (count != sizeof(struct uinput_user_dev)) 353 if (count != sizeof(struct uinput_user_dev))
@@ -362,30 +361,25 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
362 361
363 dev = udev->dev; 362 dev = udev->dev;
364 363
365 user_dev = kmalloc(sizeof(struct uinput_user_dev), GFP_KERNEL); 364 user_dev = memdup_user(buffer, sizeof(struct uinput_user_dev));
366 if (!user_dev) 365 if (IS_ERR(user_dev))
367 return -ENOMEM; 366 return PTR_ERR(user_dev);
368
369 if (copy_from_user(user_dev, buffer, sizeof(struct uinput_user_dev))) {
370 retval = -EFAULT;
371 goto exit;
372 }
373 367
374 udev->ff_effects_max = user_dev->ff_effects_max; 368 udev->ff_effects_max = user_dev->ff_effects_max;
375 369
376 size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1; 370 /* Ensure name is filled in */
377 if (!size) { 371 if (!user_dev->name[0]) {
378 retval = -EINVAL; 372 retval = -EINVAL;
379 goto exit; 373 goto exit;
380 } 374 }
381 375
382 kfree(dev->name); 376 kfree(dev->name);
383 dev->name = name = kmalloc(size, GFP_KERNEL); 377 dev->name = kstrndup(user_dev->name, UINPUT_MAX_NAME_SIZE,
384 if (!name) { 378 GFP_KERNEL);
379 if (!dev->name) {
385 retval = -ENOMEM; 380 retval = -ENOMEM;
386 goto exit; 381 goto exit;
387 } 382 }
388 strlcpy(name, user_dev->name, size);
389 383
390 dev->id.bustype = user_dev->id.bustype; 384 dev->id.bustype = user_dev->id.bustype;
391 dev->id.vendor = user_dev->id.vendor; 385 dev->id.vendor = user_dev->id.vendor;
@@ -622,7 +616,6 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
622 struct uinput_ff_upload ff_up; 616 struct uinput_ff_upload ff_up;
623 struct uinput_ff_erase ff_erase; 617 struct uinput_ff_erase ff_erase;
624 struct uinput_request *req; 618 struct uinput_request *req;
625 int length;
626 char *phys; 619 char *phys;
627 620
628 retval = mutex_lock_interruptible(&udev->mutex); 621 retval = mutex_lock_interruptible(&udev->mutex);
@@ -689,24 +682,15 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
689 retval = -EINVAL; 682 retval = -EINVAL;
690 goto out; 683 goto out;
691 } 684 }
692 length = strnlen_user(p, 1024); 685
693 if (length <= 0) { 686 phys = strndup_user(p, 1024);
694 retval = -EFAULT; 687 if (IS_ERR(phys)) {
695 break; 688 retval = PTR_ERR(phys);
689 goto out;
696 } 690 }
691
697 kfree(udev->dev->phys); 692 kfree(udev->dev->phys);
698 udev->dev->phys = phys = kmalloc(length, GFP_KERNEL); 693 udev->dev->phys = phys;
699 if (!phys) {
700 retval = -ENOMEM;
701 break;
702 }
703 if (copy_from_user(phys, p, length)) {
704 udev->dev->phys = NULL;
705 kfree(phys);
706 retval = -EFAULT;
707 break;
708 }
709 phys[length - 1] = '\0';
710 break; 694 break;
711 695
712 case UI_BEGIN_FF_UPLOAD: 696 case UI_BEGIN_FF_UPLOAD:
diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
new file mode 100644
index 000000000000..7077f9bf5ead
--- /dev/null
+++ b/drivers/input/misc/xen-kbdfront.c
@@ -0,0 +1,385 @@
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
33struct 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
43static int xenkbd_remove(struct xenbus_device *);
44static int xenkbd_connect_backend(struct xenbus_device *, struct xenkbd_info *);
45static 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
52static 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
107static 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
204static 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
213static 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
227static 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
292static 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
302static 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 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:
318InitWait:
319 xenbus_switch_state(dev, XenbusStateConnected);
320 break;
321
322 case XenbusStateConnected:
323 /*
324 * Work around xenbus race condition: If backend goes
325 * through InitWait to Connected fast enough, we can
326 * get Connected twice here.
327 */
328 if (dev->state != XenbusStateConnected)
329 goto InitWait; /* no InitWait seen yet, fudge it */
330
331 /* Set input abs params to match backend screen res */
332 if (xenbus_scanf(XBT_NIL, info->xbdev->otherend,
333 "width", "%d", &val) > 0)
334 input_set_abs_params(info->ptr, ABS_X, 0, val, 0, 0);
335
336 if (xenbus_scanf(XBT_NIL, info->xbdev->otherend,
337 "height", "%d", &val) > 0)
338 input_set_abs_params(info->ptr, ABS_Y, 0, val, 0, 0);
339
340 break;
341
342 case XenbusStateClosing:
343 xenbus_frontend_closed(dev);
344 break;
345 }
346}
347
348static const struct xenbus_device_id xenkbd_ids[] = {
349 { "vkbd" },
350 { "" }
351};
352
353static struct xenbus_driver xenkbd_driver = {
354 .name = "vkbd",
355 .owner = THIS_MODULE,
356 .ids = xenkbd_ids,
357 .probe = xenkbd_probe,
358 .remove = xenkbd_remove,
359 .resume = xenkbd_resume,
360 .otherend_changed = xenkbd_backend_changed,
361};
362
363static int __init xenkbd_init(void)
364{
365 if (!xen_pv_domain())
366 return -ENODEV;
367
368 /* Nothing to do if running in dom0. */
369 if (xen_initial_domain())
370 return -ENODEV;
371
372 return xenbus_register_frontend(&xenkbd_driver);
373}
374
375static void __exit xenkbd_cleanup(void)
376{
377 xenbus_unregister_driver(&xenkbd_driver);
378}
379
380module_init(xenkbd_init);
381module_exit(xenkbd_cleanup);
382
383MODULE_DESCRIPTION("Xen virtual keyboard/pointer device frontend");
384MODULE_LICENSE("GPL");
385MODULE_ALIAS("xen:vkbd");