Path: blob/master/drivers/input/touchscreen/gunze.c
15112 views
/*1* Copyright (c) 2000-2001 Vojtech Pavlik2*/34/*5* Gunze AHL-51S touchscreen driver for Linux6*/78/*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, write to the Free Software21* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA22*23* Should you need to contact me, the author, you can do so either by24* e-mail - mail your message to <[email protected]>, or by paper mail:25* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic26*/2728#include <linux/errno.h>29#include <linux/kernel.h>30#include <linux/module.h>31#include <linux/slab.h>32#include <linux/input.h>33#include <linux/serio.h>34#include <linux/init.h>3536#define DRIVER_DESC "Gunze AHL-51S touchscreen driver"3738MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");39MODULE_DESCRIPTION(DRIVER_DESC);40MODULE_LICENSE("GPL");4142/*43* Definitions & global arrays.44*/4546#define GUNZE_MAX_LENGTH 104748/*49* Per-touchscreen data.50*/5152struct gunze {53struct input_dev *dev;54struct serio *serio;55int idx;56unsigned char data[GUNZE_MAX_LENGTH];57char phys[32];58};5960static void gunze_process_packet(struct gunze* gunze)61{62struct input_dev *dev = gunze->dev;6364if (gunze->idx != GUNZE_MAX_LENGTH || gunze->data[5] != ',' ||65(gunze->data[0] != 'T' && gunze->data[0] != 'R')) {66printk(KERN_WARNING "gunze.c: bad packet: >%.*s<\n", GUNZE_MAX_LENGTH, gunze->data);67return;68}6970input_report_abs(dev, ABS_X, simple_strtoul(gunze->data + 1, NULL, 10));71input_report_abs(dev, ABS_Y, 1024 - simple_strtoul(gunze->data + 6, NULL, 10));72input_report_key(dev, BTN_TOUCH, gunze->data[0] == 'T');73input_sync(dev);74}7576static irqreturn_t gunze_interrupt(struct serio *serio,77unsigned char data, unsigned int flags)78{79struct gunze* gunze = serio_get_drvdata(serio);8081if (data == '\r') {82gunze_process_packet(gunze);83gunze->idx = 0;84} else {85if (gunze->idx < GUNZE_MAX_LENGTH)86gunze->data[gunze->idx++] = data;87}88return IRQ_HANDLED;89}9091/*92* gunze_disconnect() is the opposite of gunze_connect()93*/9495static void gunze_disconnect(struct serio *serio)96{97struct gunze *gunze = serio_get_drvdata(serio);9899input_get_device(gunze->dev);100input_unregister_device(gunze->dev);101serio_close(serio);102serio_set_drvdata(serio, NULL);103input_put_device(gunze->dev);104kfree(gunze);105}106107/*108* gunze_connect() is the routine that is called when someone adds a109* new serio device that supports Gunze protocol and registers it as110* an input device.111*/112113static int gunze_connect(struct serio *serio, struct serio_driver *drv)114{115struct gunze *gunze;116struct input_dev *input_dev;117int err;118119gunze = kzalloc(sizeof(struct gunze), GFP_KERNEL);120input_dev = input_allocate_device();121if (!gunze || !input_dev) {122err = -ENOMEM;123goto fail1;124}125126gunze->serio = serio;127gunze->dev = input_dev;128snprintf(gunze->phys, sizeof(serio->phys), "%s/input0", serio->phys);129130input_dev->name = "Gunze AHL-51S TouchScreen";131input_dev->phys = gunze->phys;132input_dev->id.bustype = BUS_RS232;133input_dev->id.vendor = SERIO_GUNZE;134input_dev->id.product = 0x0051;135input_dev->id.version = 0x0100;136input_dev->dev.parent = &serio->dev;137input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);138input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);139input_set_abs_params(input_dev, ABS_X, 24, 1000, 0, 0);140input_set_abs_params(input_dev, ABS_Y, 24, 1000, 0, 0);141142serio_set_drvdata(serio, gunze);143144err = serio_open(serio, drv);145if (err)146goto fail2;147148err = input_register_device(gunze->dev);149if (err)150goto fail3;151152return 0;153154fail3: serio_close(serio);155fail2: serio_set_drvdata(serio, NULL);156fail1: input_free_device(input_dev);157kfree(gunze);158return err;159}160161/*162* The serio driver structure.163*/164165static struct serio_device_id gunze_serio_ids[] = {166{167.type = SERIO_RS232,168.proto = SERIO_GUNZE,169.id = SERIO_ANY,170.extra = SERIO_ANY,171},172{ 0 }173};174175MODULE_DEVICE_TABLE(serio, gunze_serio_ids);176177static struct serio_driver gunze_drv = {178.driver = {179.name = "gunze",180},181.description = DRIVER_DESC,182.id_table = gunze_serio_ids,183.interrupt = gunze_interrupt,184.connect = gunze_connect,185.disconnect = gunze_disconnect,186};187188/*189* The functions for inserting/removing us as a module.190*/191192static int __init gunze_init(void)193{194return serio_register_driver(&gunze_drv);195}196197static void __exit gunze_exit(void)198{199serio_unregister_driver(&gunze_drv);200}201202module_init(gunze_init);203module_exit(gunze_exit);204205206