2 * tsc210x_ts.c - touchscreen input device for TI TSC210x chips
4 * Copyright (c) 2006-2007 Andrzej Zaborowski <balrog@zabor.org>
6 * This package is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This package is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this package; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <linux/errno.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/input.h>
25 #include <linux/init.h>
26 #include <linux/platform_device.h>
28 #include <linux/spi/tsc210x.h>
32 * The sensor ADC on tsc210x chips is most often used with the smart
33 * touchscreen controller. Those controllers can be made to improve
34 * sample quality directly by multi-sampling and by taking the mean or
35 * median of various numbers of samples. They also take X, Y, and
36 * pressure measurements automatically, so this driver has relatively
39 * There are a few chips in this family that don't have quite the same
40 * touchscreen interface, e.g. no "median" mode.
43 static void tsc210x_touch(void *context, int touching)
45 struct input_dev *dev = context;
48 input_report_abs(dev, ABS_X, 0);
49 input_report_abs(dev, ABS_Y, 0);
50 input_report_abs(dev, ABS_PRESSURE, 0);
54 input_report_key(dev, BTN_TOUCH, touching);
57 static void tsc210x_coords(void *context, int x, int y, int z1, int z2)
59 struct input_dev *dev = context;
62 /* Calculate the touch resistance a la equation #1 */
64 p = x * (z2 - z1) / (z1 << 4);
68 input_report_abs(dev, ABS_X, x);
69 input_report_abs(dev, ABS_Y, y);
70 input_report_abs(dev, ABS_PRESSURE, p);
74 static int tsc210x_ts_probe(struct platform_device *pdev)
77 struct input_dev *dev;
79 dev = input_allocate_device();
83 status = tsc210x_touch_cb(pdev->dev.parent, tsc210x_touch, dev);
85 input_free_device(dev);
89 status = tsc210x_coords_cb(pdev->dev.parent, tsc210x_coords, dev);
91 tsc210x_touch_cb(pdev->dev.parent, NULL, NULL);
92 input_free_device(dev);
96 dev->name = "TSC210x Touchscreen";
97 dev->dev.parent = &pdev->dev;
98 dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
99 dev->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
100 dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
101 dev->phys = "tsc210x/input0";
102 dev->id.bustype = BUS_HOST;
103 dev->id.vendor = 0x0001;
104 dev->id.product = 0x2100;
105 dev->id.version = 0x0001;
107 status = input_register_device(dev);
109 tsc210x_coords_cb(pdev->dev.parent, NULL, NULL);
110 tsc210x_touch_cb(pdev->dev.parent, NULL, NULL);
111 input_free_device(dev);
115 platform_set_drvdata(pdev, dev);
116 printk(KERN_INFO "TSC210x touchscreen initialised\n");
120 static int __exit tsc210x_ts_remove(struct platform_device *pdev)
122 struct input_dev *dev = platform_get_drvdata(pdev);
124 tsc210x_touch_cb(pdev->dev.parent, NULL, NULL);
125 tsc210x_coords_cb(pdev->dev.parent, NULL, NULL);
126 platform_set_drvdata(pdev, NULL);
127 input_unregister_device(dev);
128 input_free_device(dev);
133 static struct platform_driver tsc210x_ts_driver = {
134 .probe = tsc210x_ts_probe,
135 .remove = __exit_p(tsc210x_ts_remove),
136 /* Nothing to do on suspend/resume */
138 .name = "tsc210x-ts",
139 .owner = THIS_MODULE,
143 static int __init tsc210x_ts_init(void)
145 /* can't use driver_probe() here since the parent device
146 * gets registered "late"
148 return platform_driver_register(&tsc210x_ts_driver);
150 module_init(tsc210x_ts_init);
152 static void __exit tsc210x_ts_exit(void)
154 platform_driver_unregister(&tsc210x_ts_driver);
156 module_exit(tsc210x_ts_exit);
158 MODULE_AUTHOR("Andrzej Zaborowski");
159 MODULE_DESCRIPTION("Touchscreen input driver for TI TSC2101/2102.");
160 MODULE_LICENSE("GPL");