This is input device driver and user space application (virtual mouse)

which generates mouse events and sends them via sysfs to GPM server.

Here's step by step instructions:

1. install gpm (General Purpose Mouse interface) package:

#apt-get install gpm

2. load vms module into the kernel:

#insmod ./vms.ko

3. verify driver is initialized (notice new event):

fermat:/home/work/kernel/vms# tail /var/log/syslog
Jul 20 14:19:28 fermat kernel: [  205.740999] PM: Adding info for platform:vms
Jul 20 14:19:28 fermat kernel: [  205.740999] vms_init: registered devices/platform/vms
Jul 20 14:19:28 fermat kernel: [  205.740999] device: 'input13': device_add
Jul 20 14:19:28 fermat kernel: [  205.740999] PM: Adding info for No Bus:input13
Jul 20 14:19:28 fermat kernel: [  205.740999] input: Unspecified device as /class/input/input13
Jul 20 14:19:28 fermat kernel: [  205.749342] device: 'event9': device_add
Jul 20 14:19:28 fermat kernel: [  205.749381] PM: Adding info for No Bus:event9
Jul 20 14:19:28 fermat kernel: [  205.749412] vms_init: VMS driver initialized.
fermat:/home/work/kernel/vms#

4. check that there's new event9 node in /dev/input:

geo@fermat:/home/work/kernel/vms$ l /dev/input
total 0
drwxr-xr-x 2 root root     80 2010-07-20 09:30 by-id
drwxr-xr-x 2 root root    160 2010-07-20 09:30 by-path
crw-rw---- 1 root root 13, 64 2010-07-20 09:30 event0
crw-rw---- 1 root root 13, 65 2010-07-20 09:30 event1
crw-rw---- 1 root root 13, 66 2010-07-20 09:30 event2
crw-rw---- 1 root root 13, 67 2010-07-20 09:30 event3
crw-rw---- 1 root root 13, 68 2010-07-20 09:30 event4
crw-rw---- 1 root root 13, 69 2010-07-20 09:30 event5
crw-rw---- 1 root root 13, 70 2010-07-20 09:30 event6
crw-rw---- 1 root root 13, 71 2010-07-20 09:30 event7
crw-rw---- 1 root root 13, 72 2010-07-20 09:30 event8
crw-rw---- 1 root root 13, 73 2010-07-20 13:37 event9
crw-rw---- 1 root root 13, 63 2010-07-20 09:30 mice
crw-rw---- 1 root root 13, 32 2010-07-20 09:30 mouse0
crw-rw---- 1 root root 13, 33 2010-07-20 09:30 mouse1
geo@fermat:/home/work/kernel/vms$ 
5. verify that new sysfs attributes have been created:

geo@fermat:~$ l /sys/devices/platform/vms
total 0
lrwxrwxrwx 1 root root    0 2010-07-20 14:19 bus -> ../../../bus/platform
-rw-r--r-- 1 root root 4096 2010-07-20 14:19 coords
-r--r--r-- 1 root root 4096 2010-07-20 14:19 modalias
drwxr-xr-x 2 root root    0 2010-07-20 14:19 power
lrwxrwxrwx 1 root root    0 2010-07-20 14:19 subsystem -> ../../../bus/platform
-rw-r--r-- 1 root root 4096 2010-07-20 14:19 uevent
geo@fermat:~$

6. stop gdm:

#/etc/init.d/gdm stop

7. attach GPM server to event interface created by driver:

# gpm -m /dev/input/event9 -t evdev

8. start virtual mouse application:

$./mouse

9. enjoy virtual mouse cursor movements on screen!

10. to observe events/coordinates generated by user space application
while it writes data to /sys/devices/platform/vms/coords use octal dump:

#od -x /dev/input/event9


What happens during initialization is driver first creates simple platform device:

pfm_dev = platform_device_register_simple("vms", -1, NULL, 0);

  if(IS_ERR(pfm_dev))
  {
	PTR_ERR(pfm_dev);
	printk("vms_init: errorn");
  }
  else
	printk("vms_init: registered devices/platform/vmsn");

then creates sysfs group of attributes:

DEVICE_ATTR(coords, 0644, NULL, vms_store);

static struct attribute* vms_attrs[] =
{
  &dev_attr_coords.attr,
  NULL
};

static struct attribute_group vms_attr_group =
{
  .attrs = vms_attrs
};

sysfs_create_group(&pfm_dev->dev.kobj, &vms_attr_group);
and registers itself as input device driver:
vms_dev = input_allocate_device();
  if(!vms_dev)
	printk("vms_init: error in input_allocate_device()n");
When user space mouse application writes data to sysfs node:
sprintf(buffer, "%d %d %d", x, y, 0);
write(fd, buffer, strlen(buffer));

driver generates events containing new x and y coordinates,

wraps them into single evdev packet and sends it

to assigned interface /dev/input/event9:

sscanf(buff, "%d%d", &x, &y);

input_report_rel(vms_dev, REL_X, x);
input_report_rel(vms_dev, REL_Y, y);
input_sync(vms_dev);

GPM server attached to this interface receives evdev packets and acts on it.

You can download driver and mouse app build for Debian GNU/Linux from here.

geo@fermat:/home/work/kernel/vms$ /sbin/modinfo vms.ko
filename:       vms.ko
license:        GPL
author:         George Matveev
description:    virtual mouse input device driver
depends:        
vermagic:       2.6.26 SMP mod_unload modversions PENTIUM4 
geo@fermat:/home/work/kernel/vms$