Path: blob/master/drivers/input/touchscreen/touchit213.c
15111 views
/*1* Sahara TouchIT-213 serial touchscreen driver2*3* Copyright (c) 2007-2008 Claudio Nieder <[email protected]>4*5* Based on Touchright driver (drivers/input/touchscreen/touchright.c)6* Copyright (c) 2006 Rick Koch <[email protected]>7* Copyright (c) 2004 Vojtech Pavlik8* and Dan Streetman <[email protected]>9*/1011/*12* This program is free software; you can redistribute it and/or modify it13* under the terms of the GNU General Public License version 2 as published14* by the Free Software Foundation.15*/1617#include <linux/errno.h>18#include <linux/kernel.h>19#include <linux/module.h>20#include <linux/slab.h>21#include <linux/input.h>22#include <linux/serio.h>23#include <linux/init.h>2425#define DRIVER_DESC "Sahara TouchIT-213 serial touchscreen driver"2627MODULE_AUTHOR("Claudio Nieder <[email protected]>");28MODULE_DESCRIPTION(DRIVER_DESC);29MODULE_LICENSE("GPL");3031/*32* Definitions & global arrays.33*/3435/*36* Data is received through COM1 at 9600bit/s,8bit,no parity in packets37* of 5 byte each.38*39* +--------+ +--------+ +--------+ +--------+ +--------+40* |1000000p| |0xxxxxxx| |0xxxxxxx| |0yyyyyyy| |0yyyyyyy|41* +--------+ +--------+ +--------+ +--------+ +--------+42* MSB LSB MSB LSB43*44* The value of p is 1 as long as the screen is touched and 0 when45* reporting the location where touching stopped, e.g. where the pen was46* lifted from the screen.47*48* When holding the screen in landscape mode as the BIOS text output is49* presented, x is the horizontal axis with values growing from left to50* right and y is the vertical axis with values growing from top to51* bottom.52*53* When holding the screen in portrait mode with the Sahara logo in its54* correct position, x ist the vertical axis with values growing from55* top to bottom and y is the horizontal axis with values growing from56* right to left.57*/5859#define T213_FORMAT_TOUCH_BIT 0x0160#define T213_FORMAT_STATUS_BYTE 0x8061#define T213_FORMAT_STATUS_MASK ~T213_FORMAT_TOUCH_BIT6263/*64* On my Sahara Touch-IT 213 I have observed x values from 0 to 0x7f065* and y values from 0x1d to 0x7e9, so the actual measurement is66* probably done with an 11 bit precision.67*/68#define T213_MIN_XC 069#define T213_MAX_XC 0x07ff70#define T213_MIN_YC 071#define T213_MAX_YC 0x07ff7273/*74* Per-touchscreen data.75*/7677struct touchit213 {78struct input_dev *dev;79struct serio *serio;80int idx;81unsigned char csum;82unsigned char data[5];83char phys[32];84};8586static irqreturn_t touchit213_interrupt(struct serio *serio,87unsigned char data, unsigned int flags)88{89struct touchit213 *touchit213 = serio_get_drvdata(serio);90struct input_dev *dev = touchit213->dev;9192touchit213->data[touchit213->idx] = data;9394switch (touchit213->idx++) {95case 0:96if ((touchit213->data[0] & T213_FORMAT_STATUS_MASK) !=97T213_FORMAT_STATUS_BYTE) {98pr_debug("unsynchronized data: 0x%02x\n", data);99touchit213->idx = 0;100}101break;102103case 4:104touchit213->idx = 0;105input_report_abs(dev, ABS_X,106(touchit213->data[1] << 7) | touchit213->data[2]);107input_report_abs(dev, ABS_Y,108(touchit213->data[3] << 7) | touchit213->data[4]);109input_report_key(dev, BTN_TOUCH,110touchit213->data[0] & T213_FORMAT_TOUCH_BIT);111input_sync(dev);112break;113}114115return IRQ_HANDLED;116}117118/*119* touchit213_disconnect() is the opposite of touchit213_connect()120*/121122static void touchit213_disconnect(struct serio *serio)123{124struct touchit213 *touchit213 = serio_get_drvdata(serio);125126input_get_device(touchit213->dev);127input_unregister_device(touchit213->dev);128serio_close(serio);129serio_set_drvdata(serio, NULL);130input_put_device(touchit213->dev);131kfree(touchit213);132}133134/*135* touchit213_connect() is the routine that is called when someone adds a136* new serio device that supports the Touchright protocol and registers it as137* an input device.138*/139140static int touchit213_connect(struct serio *serio, struct serio_driver *drv)141{142struct touchit213 *touchit213;143struct input_dev *input_dev;144int err;145146touchit213 = kzalloc(sizeof(struct touchit213), GFP_KERNEL);147input_dev = input_allocate_device();148if (!touchit213 || !input_dev) {149err = -ENOMEM;150goto fail1;151}152153touchit213->serio = serio;154touchit213->dev = input_dev;155snprintf(touchit213->phys, sizeof(touchit213->phys),156"%s/input0", serio->phys);157158input_dev->name = "Sahara Touch-iT213 Serial TouchScreen";159input_dev->phys = touchit213->phys;160input_dev->id.bustype = BUS_RS232;161input_dev->id.vendor = SERIO_TOUCHIT213;162input_dev->id.product = 0;163input_dev->id.version = 0x0100;164input_dev->dev.parent = &serio->dev;165input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);166input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);167input_set_abs_params(touchit213->dev, ABS_X,168T213_MIN_XC, T213_MAX_XC, 0, 0);169input_set_abs_params(touchit213->dev, ABS_Y,170T213_MIN_YC, T213_MAX_YC, 0, 0);171172serio_set_drvdata(serio, touchit213);173174err = serio_open(serio, drv);175if (err)176goto fail2;177178err = input_register_device(touchit213->dev);179if (err)180goto fail3;181182return 0;183184fail3: serio_close(serio);185fail2: serio_set_drvdata(serio, NULL);186fail1: input_free_device(input_dev);187kfree(touchit213);188return err;189}190191/*192* The serio driver structure.193*/194195static struct serio_device_id touchit213_serio_ids[] = {196{197.type = SERIO_RS232,198.proto = SERIO_TOUCHIT213,199.id = SERIO_ANY,200.extra = SERIO_ANY,201},202{ 0 }203};204205MODULE_DEVICE_TABLE(serio, touchit213_serio_ids);206207static struct serio_driver touchit213_drv = {208.driver = {209.name = "touchit213",210},211.description = DRIVER_DESC,212.id_table = touchit213_serio_ids,213.interrupt = touchit213_interrupt,214.connect = touchit213_connect,215.disconnect = touchit213_disconnect,216};217218/*219* The functions for inserting/removing us as a module.220*/221222static int __init touchit213_init(void)223{224return serio_register_driver(&touchit213_drv);225}226227static void __exit touchit213_exit(void)228{229serio_unregister_driver(&touchit213_drv);230}231232module_init(touchit213_init);233module_exit(touchit213_exit);234235236