2 * input/touchscreen/tsc2102_ts.c
4 * Touchscreen input device driver for the TSC 2102 chip.
6 * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This package is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this package; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <linux/errno.h>
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/input.h>
27 #include <linux/init.h>
28 #include <linux/platform_device.h>
30 #include <linux/spi/tsc2102.h>
32 struct input_dev *dev;
34 static void tsc2102_touch(int touching)
37 input_report_abs(dev, ABS_X, 0);
38 input_report_abs(dev, ABS_Y, 0);
39 input_report_abs(dev, ABS_PRESSURE, 0);
43 input_report_key(dev, BTN_TOUCH, touching);
46 static void tsc2102_coords(int x, int y, int z1, int z2)
50 /* Calculate the touch resistance a la equation #1 */
52 p = x * (z2 - z1) / (z1 << 4);
56 input_report_abs(dev, ABS_X, x);
57 input_report_abs(dev, ABS_Y, y);
58 input_report_abs(dev, ABS_PRESSURE, p);
62 static int tsc2102_ts_probe(struct platform_device *pdev)
66 dev = input_allocate_device();
70 status = tsc2102_touch_cb(tsc2102_touch);
72 input_free_device(dev);
76 status = tsc2102_coords_cb(tsc2102_coords);
79 input_free_device(dev);
83 dev->name = "TSC2102 Touchscreen";
84 dev->cdev.dev = &pdev->dev;
85 dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
86 dev->keybit[LONG(BTN_TOUCH)] |= BIT(BTN_TOUCH);
87 dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
88 dev->phys = "tsc2102/input0";
89 dev->id.bustype = BUS_HOST;
90 dev->id.vendor = 0x0001;
91 dev->id.product = 0x2102;
92 dev->id.version = 0x0001;
94 status = input_register_device(dev);
98 input_free_device(dev);
102 printk(KERN_INFO "TSC2102 touchscreen driver initialized\n");
106 static int tsc2102_ts_remove(struct platform_device *pdev)
109 tsc2102_coords_cb(0);
110 input_unregister_device(dev);
111 input_free_device(dev);
117 tsc2102_ts_suspend(struct platform_device *pdev, pm_message_t state)
122 static int tsc2102_ts_resume(struct platform_device *pdev)
127 #define tsc2102_ts_suspend NULL
128 #define tsc2102_ts_resume NULL
131 static struct platform_driver tsc2102_ts_driver = {
132 .probe = tsc2102_ts_probe,
133 .remove = tsc2102_ts_remove,
134 .suspend = tsc2102_ts_suspend,
135 .resume = tsc2102_ts_resume,
137 .name = "tsc2102-ts",
138 .owner = THIS_MODULE,
142 static int __init tsc2102_ts_init(void)
146 ret = platform_driver_register(&tsc2102_ts_driver);
153 static void __exit tsc2102_ts_exit(void)
155 platform_driver_unregister(&tsc2102_ts_driver);
158 module_init(tsc2102_ts_init);
159 module_exit(tsc2102_ts_exit);
161 MODULE_AUTHOR("Andrzej Zaborowski");
162 MODULE_DESCRIPTION("Touchscreen input driver for TI TSC2102.");
163 MODULE_LICENSE("GPL");