]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/input/touchscreen/tsc2102_ts.c
Fix compile for H2
[linux-2.6-omap-h63xx.git] / drivers / input / touchscreen / tsc2102_ts.c
1 /*
2  * input/touchscreen/tsc2102_ts.c
3  *
4  * Touchscreen input device driver for the TSC 2102 chip.
5  *
6  * Copyright (c) 2006 Andrzej Zaborowski  <balrog@zabor.org>
7  *
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.
12  *
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.
17  *
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
21  */
22
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>
29
30 #include <linux/spi/tsc2102.h>
31
32 struct input_dev *dev;
33
34 static void tsc2102_touch(int touching)
35 {
36         if (!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);
40                 input_sync(dev);
41         }
42
43         input_report_key(dev, BTN_TOUCH, touching);
44 }
45
46 static void tsc2102_coords(int x, int y, int z1, int z2)
47 {
48         int p;
49
50         /* Calculate the touch resistance a la equation #1 */
51         if (z1 != 0)
52                 p = x * (z2 - z1) / (z1 << 4);
53         else
54                 p = 1;
55
56         input_report_abs(dev, ABS_X, x);
57         input_report_abs(dev, ABS_Y, y);
58         input_report_abs(dev, ABS_PRESSURE, p);
59         input_sync(dev);
60 }
61
62 static int tsc2102_ts_probe(struct platform_device *pdev)
63 {
64         int status;
65
66         dev = input_allocate_device();
67         if (!dev)
68                 return -ENOMEM;
69
70         status = tsc2102_touch_cb(tsc2102_touch);
71         if (status) {
72                 input_free_device(dev);
73                 return status;
74         }
75
76         status = tsc2102_coords_cb(tsc2102_coords);
77         if (status) {
78                 tsc2102_touch_cb(0);
79                 input_free_device(dev);
80                 return status;
81         }
82
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;
93
94         status = input_register_device(dev);
95         if (status) {
96                 tsc2102_coords_cb(0);
97                 tsc2102_touch_cb(0);
98                 input_free_device(dev);
99                 return status;
100         }
101
102         printk(KERN_INFO "TSC2102 touchscreen driver initialized\n");
103         return 0;
104 }
105
106 static int tsc2102_ts_remove(struct platform_device *pdev)
107 {
108         tsc2102_touch_cb(0);
109         tsc2102_coords_cb(0);
110         input_unregister_device(dev);
111         input_free_device(dev);
112         return 0;
113 }
114
115 #ifdef CONFIG_PM
116 static int
117 tsc2102_ts_suspend(struct platform_device *pdev, pm_message_t state)
118 {
119         return 0;
120 }
121
122 static int tsc2102_ts_resume(struct platform_device *pdev)
123 {
124         return 0;
125 }
126 #else
127 #define tsc2102_ts_suspend      NULL
128 #define tsc2102_ts_resume       NULL
129 #endif
130
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,
136         .driver         = {
137                 .name   = "tsc2102-ts",
138                 .owner  = THIS_MODULE,
139         },
140 };
141
142 static int __init tsc2102_ts_init(void)
143 {
144         int ret;
145
146         ret = platform_driver_register(&tsc2102_ts_driver);
147         if (ret)
148                 return -ENODEV;
149
150         return 0;
151 }
152
153 static void __exit tsc2102_ts_exit(void)
154 {
155         platform_driver_unregister(&tsc2102_ts_driver);
156 }
157
158 module_init(tsc2102_ts_init);
159 module_exit(tsc2102_ts_exit);
160
161 MODULE_AUTHOR("Andrzej Zaborowski");
162 MODULE_DESCRIPTION("Touchscreen input driver for TI TSC2102.");
163 MODULE_LICENSE("GPL");