Path: blob/master/drivers/input/touchscreen/inexio.c
15111 views
/*1* iNexio serial touchscreen driver2*3* Copyright (c) 2008 Richard Lemon4* Based on the mtouch driver (c) Vojtech Pavlik and Dan Streetman5*6*/78/*9* This program is free software; you can redistribute it and/or modify it10* under the terms of the GNU General Public License version 2 as published by11* the Free Software Foundation.12*/1314/*15* 2008/06/19 Richard Lemon <[email protected]>16* Copied mtouch.c and edited for iNexio protocol17*/1819#include <linux/errno.h>20#include <linux/kernel.h>21#include <linux/module.h>22#include <linux/slab.h>23#include <linux/input.h>24#include <linux/serio.h>25#include <linux/init.h>2627#define DRIVER_DESC "iNexio serial touchscreen driver"2829MODULE_AUTHOR("Richard Lemon <[email protected]>");30MODULE_DESCRIPTION(DRIVER_DESC);31MODULE_LICENSE("GPL");3233/*34* Definitions & global arrays.35*/3637#define INEXIO_FORMAT_TOUCH_BIT 0x0138#define INEXIO_FORMAT_LENGTH 539#define INEXIO_RESPONSE_BEGIN_BYTE 0x804041/* todo: check specs for max length of all responses */42#define INEXIO_MAX_LENGTH 164344#define INEXIO_MIN_XC 045#define INEXIO_MAX_XC 0x3fff46#define INEXIO_MIN_YC 047#define INEXIO_MAX_YC 0x3fff4849#define INEXIO_GET_XC(data) (((data[1])<<7) | data[2])50#define INEXIO_GET_YC(data) (((data[3])<<7) | data[4])51#define INEXIO_GET_TOUCHED(data) (INEXIO_FORMAT_TOUCH_BIT & data[0])5253/*54* Per-touchscreen data.55*/5657struct inexio {58struct input_dev *dev;59struct serio *serio;60int idx;61unsigned char data[INEXIO_MAX_LENGTH];62char phys[32];63};6465static void inexio_process_data(struct inexio *pinexio)66{67struct input_dev *dev = pinexio->dev;6869if (INEXIO_FORMAT_LENGTH == ++pinexio->idx) {70input_report_abs(dev, ABS_X, INEXIO_GET_XC(pinexio->data));71input_report_abs(dev, ABS_Y, INEXIO_GET_YC(pinexio->data));72input_report_key(dev, BTN_TOUCH, INEXIO_GET_TOUCHED(pinexio->data));73input_sync(dev);7475pinexio->idx = 0;76}77}7879static irqreturn_t inexio_interrupt(struct serio *serio,80unsigned char data, unsigned int flags)81{82struct inexio* pinexio = serio_get_drvdata(serio);8384pinexio->data[pinexio->idx] = data;8586if (INEXIO_RESPONSE_BEGIN_BYTE&pinexio->data[0])87inexio_process_data(pinexio);88else89printk(KERN_DEBUG "inexio.c: unknown/unsynchronized data from device, byte %x\n",pinexio->data[0]);9091return IRQ_HANDLED;92}9394/*95* inexio_disconnect() is the opposite of inexio_connect()96*/9798static void inexio_disconnect(struct serio *serio)99{100struct inexio* pinexio = serio_get_drvdata(serio);101102input_get_device(pinexio->dev);103input_unregister_device(pinexio->dev);104serio_close(serio);105serio_set_drvdata(serio, NULL);106input_put_device(pinexio->dev);107kfree(pinexio);108}109110/*111* inexio_connect() is the routine that is called when someone adds a112* new serio device that supports iNexio protocol and registers it as113* an input device. This is usually accomplished using inputattach.114*/115116static int inexio_connect(struct serio *serio, struct serio_driver *drv)117{118struct inexio *pinexio;119struct input_dev *input_dev;120int err;121122pinexio = kzalloc(sizeof(struct inexio), GFP_KERNEL);123input_dev = input_allocate_device();124if (!pinexio || !input_dev) {125err = -ENOMEM;126goto fail1;127}128129pinexio->serio = serio;130pinexio->dev = input_dev;131snprintf(pinexio->phys, sizeof(pinexio->phys), "%s/input0", serio->phys);132133input_dev->name = "iNexio Serial TouchScreen";134input_dev->phys = pinexio->phys;135input_dev->id.bustype = BUS_RS232;136input_dev->id.vendor = SERIO_INEXIO;137input_dev->id.product = 0;138input_dev->id.version = 0x0001;139input_dev->dev.parent = &serio->dev;140input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);141input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);142input_set_abs_params(pinexio->dev, ABS_X, INEXIO_MIN_XC, INEXIO_MAX_XC, 0, 0);143input_set_abs_params(pinexio->dev, ABS_Y, INEXIO_MIN_YC, INEXIO_MAX_YC, 0, 0);144145serio_set_drvdata(serio, pinexio);146147err = serio_open(serio, drv);148if (err)149goto fail2;150151err = input_register_device(pinexio->dev);152if (err)153goto fail3;154155return 0;156157fail3: serio_close(serio);158fail2: serio_set_drvdata(serio, NULL);159fail1: input_free_device(input_dev);160kfree(pinexio);161return err;162}163164/*165* The serio driver structure.166*/167168static struct serio_device_id inexio_serio_ids[] = {169{170.type = SERIO_RS232,171.proto = SERIO_INEXIO,172.id = SERIO_ANY,173.extra = SERIO_ANY,174},175{ 0 }176};177178MODULE_DEVICE_TABLE(serio, inexio_serio_ids);179180static struct serio_driver inexio_drv = {181.driver = {182.name = "inexio",183},184.description = DRIVER_DESC,185.id_table = inexio_serio_ids,186.interrupt = inexio_interrupt,187.connect = inexio_connect,188.disconnect = inexio_disconnect,189};190191/*192* The functions for inserting/removing us as a module.193*/194195static int __init inexio_init(void)196{197return serio_register_driver(&inexio_drv);198}199200static void __exit inexio_exit(void)201{202serio_unregister_driver(&inexio_drv);203}204205module_init(inexio_init);206module_exit(inexio_exit);207208209