From: giwoong.kim Date: Mon, 20 Aug 2012 12:55:22 +0000 (+0900) Subject: [Title] init the virtio touchscreen driver X-Git-Tag: 2.2.1_release^2~105 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=96f4f4c4ce8ca3d090780c2a28c46d3a85a1c9e5;p=sdk%2Femulator%2Femulator-kernel.git [Title] init the virtio touchscreen driver [Type] feature [Module] Emulator / touch [Priority] major [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- diff --git a/arch/x86/configs/i386_emul_defconfig b/arch/x86/configs/i386_emul_defconfig index 9b8b839bc13e..6f1af114c162 100644 --- a/arch/x86/configs/i386_emul_defconfig +++ b/arch/x86/configs/i386_emul_defconfig @@ -2765,6 +2765,7 @@ CONFIG_MARU=y CONFIG_MARU_LCD=y CONFIG_MARU_CODEC=y CONFIG_MARU_TOUCHSCREEN=y +CONFIG_MARU_VIRTIO_TOUCHSCREEN=y CONFIG_MARU_FB=y CONFIG_MARU_CAMERA=y CONFIG_MARU_BACKLIGHT=y diff --git a/drivers/maru/Kconfig b/drivers/maru/Kconfig index 78e48f432dcc..8313e4e23f24 100644 --- a/drivers/maru/Kconfig +++ b/drivers/maru/Kconfig @@ -11,7 +11,11 @@ config MARU_CODEC depends on MARU != n config MARU_TOUCHSCREEN - tristate "MARU touchscreen driver" + tristate "MARU USB Touchscreen Driver" + depends on MARU != n + +config MARU_VIRTIO_TOUCHSCREEN + tristate "MARU Virtio Touchscreen Driver" depends on MARU != n config MARU_FB diff --git a/drivers/maru/Makefile b/drivers/maru/Makefile index 3b4c39beb183..ddce2ecdf02b 100644 --- a/drivers/maru/Makefile +++ b/drivers/maru/Makefile @@ -1,6 +1,7 @@ obj-$(CONFIG_MARU_LCD) += maru_lcd.o obj-$(CONFIG_MARU_CODEC) += maru_codec.o obj-$(CONFIG_MARU_TOUCHSCREEN) += maru_touchscreen.o +obj-$(CONFIG_MARU_VIRTIO_TOUCHSCREEN) += maru_virtio_touchscreen.o obj-$(CONFIG_MARU_FB) += maru_fb.o obj-$(CONFIG_MARU_CAMERA) += maru_camera.o obj-$(CONFIG_MARU_BACKLIGHT) += maru_bl.o diff --git a/drivers/maru/maru_virtio_touchscreen.c b/drivers/maru/maru_virtio_touchscreen.c old mode 100644 new mode 100755 index 822e2b0d0d34..d214e170832d --- a/drivers/maru/maru_virtio_touchscreen.c +++ b/drivers/maru/maru_virtio_touchscreen.c @@ -38,6 +38,7 @@ #include #include #include +#include #define DEVICE_NAME "virtio-touchscreen" @@ -48,14 +49,62 @@ typedef struct EmulTouchState { uint8_t state; } EmulTouchState; +typedef struct virtio_touchscreen +{ + struct virtio_device *vdev; + struct virtqueue *vq; + + /* The thread servicing the touchscreen */ + struct task_struct *thread; +} virtio_touchscreen; + + +#define MAX_TRKID 6 -static struct virtqueue *vq = NULL; static struct virtio_device_id id_table[] = { { VIRTIO_ID_TOUCHSCREEN, VIRTIO_DEV_ANY_ID }, { 0 }, }; +static int run_touchscreen(void *_vtouchscreen) +{ + virtio_touchscreen *vt = _vtouchscreen; + int count = 0; + + struct scatterlist sg; + EmulTouchState *touch = NULL; + EmulTouchState *buf = kzalloc(sizeof(EmulTouchState), GFP_KERNEL); + buf->x = MAX_TRKID; + + while (!kthread_should_stop()) { + /* publish the real size of the buffer */ + sg_init_one(&sg, buf, sizeof(EmulTouchState)); + + if (virtqueue_add_buf(vt->vq, &sg, 0, 1, (void*)buf, GFP_ATOMIC) >= 0) { + virtqueue_kick(vt->vq); + + while (!(touch = virtqueue_get_buf(vt->vq, &count))) { + cpu_relax(); + } + + if (touch == NULL) { + printk(KERN_INFO "touch is null\n"); + } else { + printk(KERN_INFO "x=%d, y=%d, z=%d, state=%d\n", touch->x, touch->y, touch->z, touch->state); + } + + printk(KERN_INFO "virtio touchscreen remaining capacity of queue = %d\n", count); + } + + } + + printk(KERN_INFO "stop run_touchscreen\n"); + kfree(buf); + + return 0; +} + static void vq_touchscreen_callback(struct virtqueue *vq) { printk(KERN_INFO "vq touchscreen callback\n"); @@ -89,13 +138,21 @@ static struct miscdevice virtio_touchscreen_dev = { static int virtio_touchscreen_probe(struct virtio_device *vdev) { + struct virtio_touchscreen *vt; int ret = 0; printk(KERN_INFO "virtio touchscreen driver is probed.\n"); - vq = virtio_find_single_vq(vdev, NULL, "virtio-touchscreen-vq"); - if (IS_ERR(vq)) { - return PTR_ERR(vq); + vdev->priv = vt = kmalloc(sizeof(*vt), GFP_KERNEL); + if (!vt) { + return -ENOMEM; + } + + vt->vdev = vdev; + + vt->vq = virtio_find_single_vq(vt->vdev, NULL, "virtio-touchscreen-vq"); + if (IS_ERR(vt->vq)) { + return PTR_ERR(vt->vq); } ret = misc_register(&virtio_touchscreen_dev); @@ -105,28 +162,36 @@ static int virtio_touchscreen_probe(struct virtio_device *vdev) } - // temp - vq->callback = vq_touchscreen_callback; + // TODO: + vt->vq->callback = vq_touchscreen_callback; + virtqueue_enable_cb(vt->vq); + + /* thread */ + vt->thread = kthread_run(run_touchscreen, vt, "vtouchscreen"); + if (IS_ERR(vt->thread)) { + kfree(vt); + return PTR_ERR(vt->thread); + } - /* Transfer data */ -#if 0 - if (virtqueue_add_buf(vq, sg_list, out_page, in_page, (void*)1, GFP_ATOMIC) >= 0) { - while (!virtqueue_get_buf(vq, &count)) { - cpu_relax(); - } - } -#endif return 0; } static void __devexit virtio_touchscreen_remove(struct virtio_device *vdev) { + virtio_touchscreen *vt; + printk(KERN_INFO "virtio touchscreen driver is removed.\n"); + vt = vdev->priv; + + kthread_stop(vt->thread); + vdev->config->reset(vdev); // reset device misc_deregister(&virtio_touchscreen_dev); vdev->config->del_vqs(vdev); // clean up the queues + + kfree(vt); } static struct virtio_driver virtio_touchscreen_driver = {