]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/usb/input/mtouchusb.c
Remove obsolete #include <linux/config.h>
[mirror_ubuntu-jammy-kernel.git] / drivers / usb / input / mtouchusb.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 * mtouchusb.c -- Driver for Microtouch (Now 3M) USB Touchscreens
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 * Based upon original work by Radoslaw Garbacz (usb-support@ite.pl)
19 * (http://freshmeat.net/projects/3mtouchscreendriver)
20 *
21 * History
22 *
23 * 0.3 & 0.4 2002 (TEJ) tejohnson@yahoo.com
24 * Updated to 2.4.18, then 2.4.19
25 * Old version still relied on stealing a minor
26 *
27 * 0.5 02/26/2004 (TEJ) tejohnson@yahoo.com
28 * Complete rewrite using Linux Input in 2.6.3
29 * Unfortunately no calibration support at this time
30 *
31 * 1.4 04/25/2004 (TEJ) tejohnson@yahoo.com
32 * Changed reset from standard USB dev reset to vendor reset
33 * Changed data sent to host from compensated to raw coordinates
34 * Eliminated vendor/product module params
093cf723 35 * Performed multiple successful tests with an EXII-5010UC
1da177e4
LT
36 *
37 * 1.5 02/27/2005 ddstreet@ieee.org
38 * Added module parameter to select raw or hw-calibrated coordinate reporting
39 *
40 *****************************************************************************/
41
1da177e4
LT
42#include <linux/kernel.h>
43#include <linux/slab.h>
1da177e4
LT
44#include <linux/module.h>
45#include <linux/init.h>
ae0dadcf 46#include <linux/usb/input.h>
1da177e4
LT
47
48#define MTOUCHUSB_MIN_XC 0x0
49#define MTOUCHUSB_MAX_RAW_XC 0x4000
50#define MTOUCHUSB_MAX_CALIB_XC 0xffff
51#define MTOUCHUSB_XC_FUZZ 0x0
52#define MTOUCHUSB_XC_FLAT 0x0
53#define MTOUCHUSB_MIN_YC 0x0
54#define MTOUCHUSB_MAX_RAW_YC 0x4000
55#define MTOUCHUSB_MAX_CALIB_YC 0xffff
56#define MTOUCHUSB_YC_FUZZ 0x0
57#define MTOUCHUSB_YC_FLAT 0x0
58
59#define MTOUCHUSB_ASYNC_REPORT 1
60#define MTOUCHUSB_RESET 7
61#define MTOUCHUSB_REPORT_DATA_SIZE 11
62#define MTOUCHUSB_REQ_CTRLLR_ID 10
63
64#define MTOUCHUSB_GET_RAW_XC(data) (data[8]<<8 | data[7])
65#define MTOUCHUSB_GET_CALIB_XC(data) (data[4]<<8 | data[3])
66#define MTOUCHUSB_GET_RAW_YC(data) (data[10]<<8 | data[9])
67#define MTOUCHUSB_GET_CALIB_YC(data) (data[6]<<8 | data[5])
68#define MTOUCHUSB_GET_XC(data) (raw_coordinates ? \
69 MTOUCHUSB_GET_RAW_XC(data) : \
70 MTOUCHUSB_GET_CALIB_XC(data))
71#define MTOUCHUSB_GET_YC(data) (raw_coordinates ? \
72 MTOUCHUSB_GET_RAW_YC(data) : \
73 MTOUCHUSB_GET_CALIB_YC(data))
74#define MTOUCHUSB_GET_TOUCHED(data) ((data[2] & 0x40) ? 1:0)
75
76#define DRIVER_VERSION "v1.5"
77#define DRIVER_AUTHOR "Todd E. Johnson, tejohnson@yahoo.com"
78#define DRIVER_DESC "3M USB Touchscreen Driver"
79#define DRIVER_LICENSE "GPL"
80
81static int raw_coordinates = 1;
82
83module_param(raw_coordinates, bool, S_IRUGO | S_IWUSR);
84MODULE_PARM_DESC(raw_coordinates, "report raw coordinate values (y, default) or hardware-calibrated coordinate values (n)");
85
86struct mtouch_usb {
8baf9ed4
DT
87 unsigned char *data;
88 dma_addr_t data_dma;
89 struct urb *irq;
90 struct usb_device *udev;
c5b7c7c3 91 struct input_dev *input;
8baf9ed4
DT
92 char name[128];
93 char phys[64];
1da177e4
LT
94};
95
8baf9ed4
DT
96static struct usb_device_id mtouchusb_devices[] = {
97 { USB_DEVICE(0x0596, 0x0001) },
98 { }
1da177e4
LT
99};
100
101static void mtouchusb_irq(struct urb *urb, struct pt_regs *regs)
102{
8baf9ed4
DT
103 struct mtouch_usb *mtouch = urb->context;
104 int retval;
105
106 switch (urb->status) {
107 case 0:
108 /* success */
109 break;
110 case -ETIMEDOUT:
111 /* this urb is timing out */
112 dbg("%s - urb timed out - was the device unplugged?",
113 __FUNCTION__);
114 return;
115 case -ECONNRESET:
116 case -ENOENT:
117 case -ESHUTDOWN:
118 /* this urb is terminated, clean up */
119 dbg("%s - urb shutting down with status: %d",
120 __FUNCTION__, urb->status);
121 return;
122 default:
123 dbg("%s - nonzero urb status received: %d",
124 __FUNCTION__, urb->status);
125 goto exit;
126 }
127
c5b7c7c3
DT
128 input_regs(mtouch->input, regs);
129 input_report_key(mtouch->input, BTN_TOUCH,
8baf9ed4 130 MTOUCHUSB_GET_TOUCHED(mtouch->data));
c5b7c7c3
DT
131 input_report_abs(mtouch->input, ABS_X, MTOUCHUSB_GET_XC(mtouch->data));
132 input_report_abs(mtouch->input, ABS_Y,
1da177e4 133 (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC)
8baf9ed4 134 - MTOUCHUSB_GET_YC(mtouch->data));
c5b7c7c3 135 input_sync(mtouch->input);
1da177e4
LT
136
137exit:
8baf9ed4
DT
138 retval = usb_submit_urb(urb, GFP_ATOMIC);
139 if (retval)
140 err("%s - usb_submit_urb failed with result: %d",
141 __FUNCTION__, retval);
1da177e4
LT
142}
143
8baf9ed4 144static int mtouchusb_open(struct input_dev *input)
1da177e4 145{
8baf9ed4 146 struct mtouch_usb *mtouch = input->private;
1da177e4 147
8baf9ed4 148 mtouch->irq->dev = mtouch->udev;
1da177e4 149
65cde54b 150 if (usb_submit_urb(mtouch->irq, GFP_ATOMIC))
8baf9ed4 151 return -EIO;
1da177e4 152
8baf9ed4 153 return 0;
1da177e4
LT
154}
155
8baf9ed4 156static void mtouchusb_close(struct input_dev *input)
1da177e4 157{
8baf9ed4 158 struct mtouch_usb *mtouch = input->private;
1da177e4 159
65cde54b 160 usb_kill_urb(mtouch->irq);
1da177e4
LT
161}
162
163static int mtouchusb_alloc_buffers(struct usb_device *udev, struct mtouch_usb *mtouch)
164{
8baf9ed4 165 dbg("%s - called", __FUNCTION__);
1da177e4 166
8baf9ed4
DT
167 mtouch->data = usb_buffer_alloc(udev, MTOUCHUSB_REPORT_DATA_SIZE,
168 SLAB_ATOMIC, &mtouch->data_dma);
1da177e4 169
8baf9ed4
DT
170 if (!mtouch->data)
171 return -1;
1da177e4 172
8baf9ed4 173 return 0;
1da177e4
LT
174}
175
176static void mtouchusb_free_buffers(struct usb_device *udev, struct mtouch_usb *mtouch)
177{
8baf9ed4 178 dbg("%s - called", __FUNCTION__);
1da177e4 179
8baf9ed4
DT
180 if (mtouch->data)
181 usb_buffer_free(udev, MTOUCHUSB_REPORT_DATA_SIZE,
182 mtouch->data, mtouch->data_dma);
1da177e4
LT
183}
184
185static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
186{
8baf9ed4 187 struct mtouch_usb *mtouch;
c5b7c7c3 188 struct input_dev *input_dev;
8baf9ed4
DT
189 struct usb_host_interface *interface;
190 struct usb_endpoint_descriptor *endpoint;
191 struct usb_device *udev = interface_to_usbdev(intf);
8baf9ed4
DT
192 int nRet;
193
194 dbg("%s - called", __FUNCTION__);
195
196 dbg("%s - setting interface", __FUNCTION__);
197 interface = intf->cur_altsetting;
198
199 dbg("%s - setting endpoint", __FUNCTION__);
200 endpoint = &interface->endpoint[0].desc;
201
c5b7c7c3
DT
202 mtouch = kzalloc(sizeof(struct mtouch_usb), GFP_KERNEL);
203 input_dev = input_allocate_device();
204 if (!mtouch || !input_dev) {
8baf9ed4 205 err("%s - Out of memory.", __FUNCTION__);
c5b7c7c3 206 goto fail1;
8baf9ed4
DT
207 }
208
8baf9ed4 209 dbg("%s - allocating buffers", __FUNCTION__);
c5b7c7c3
DT
210 if (mtouchusb_alloc_buffers(udev, mtouch))
211 goto fail2;
8baf9ed4 212
c5b7c7c3
DT
213 mtouch->udev = udev;
214 mtouch->input = input_dev;
1da177e4
LT
215
216 if (udev->manufacturer)
c5b7c7c3
DT
217 strlcpy(mtouch->name, udev->manufacturer, sizeof(mtouch->name));
218
219 if (udev->product) {
220 if (udev->manufacturer)
221 strlcat(mtouch->name, " ", sizeof(mtouch->name));
222 strlcat(mtouch->name, udev->product, sizeof(mtouch->name));
223 }
1da177e4 224
8baf9ed4 225 if (!strlen(mtouch->name))
c5b7c7c3
DT
226 snprintf(mtouch->name, sizeof(mtouch->name),
227 "USB Touchscreen %04x:%04x",
228 le16_to_cpu(udev->descriptor.idVendor),
229 le16_to_cpu(udev->descriptor.idProduct));
230
231 usb_make_path(udev, mtouch->phys, sizeof(mtouch->phys));
232 strlcpy(mtouch->phys, "/input0", sizeof(mtouch->phys));
233
234 input_dev->name = mtouch->name;
235 input_dev->phys = mtouch->phys;
236 usb_to_input_id(udev, &input_dev->id);
237 input_dev->cdev.dev = &intf->dev;
238 input_dev->private = mtouch;
239
240 input_dev->open = mtouchusb_open;
241 input_dev->close = mtouchusb_close;
242
243 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
244 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
245 input_set_abs_params(input_dev, ABS_X, MTOUCHUSB_MIN_XC,
246 raw_coordinates ? MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC,
247 MTOUCHUSB_XC_FUZZ, MTOUCHUSB_XC_FLAT);
248 input_set_abs_params(input_dev, ABS_Y, MTOUCHUSB_MIN_YC,
249 raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC,
250 MTOUCHUSB_YC_FUZZ, MTOUCHUSB_YC_FLAT);
8baf9ed4
DT
251
252 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0),
253 MTOUCHUSB_RESET,
254 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
255 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
256 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
257 __FUNCTION__, nRet);
258
259 dbg("%s - usb_alloc_urb: mtouch->irq", __FUNCTION__);
260 mtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
261 if (!mtouch->irq) {
262 dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__);
c5b7c7c3 263 goto fail2;
8baf9ed4
DT
264 }
265
266 dbg("%s - usb_fill_int_urb", __FUNCTION__);
267 usb_fill_int_urb(mtouch->irq, mtouch->udev,
268 usb_rcvintpipe(mtouch->udev, 0x81),
269 mtouch->data, MTOUCHUSB_REPORT_DATA_SIZE,
270 mtouchusb_irq, mtouch, endpoint->bInterval);
271
272 dbg("%s - input_register_device", __FUNCTION__);
c5b7c7c3 273 input_register_device(mtouch->input);
8baf9ed4
DT
274
275 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0),
276 MTOUCHUSB_ASYNC_REPORT,
277 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
278 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
279 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
280 __FUNCTION__, nRet);
281
8baf9ed4 282 usb_set_intfdata(intf, mtouch);
8baf9ed4 283 return 0;
c5b7c7c3
DT
284
285fail2: mtouchusb_free_buffers(udev, mtouch);
286fail1: input_free_device(input_dev);
287 kfree(mtouch);
288 return -ENOMEM;
1da177e4
LT
289}
290
291static void mtouchusb_disconnect(struct usb_interface *intf)
292{
8baf9ed4
DT
293 struct mtouch_usb *mtouch = usb_get_intfdata(intf);
294
295 dbg("%s - called", __FUNCTION__);
296 usb_set_intfdata(intf, NULL);
297 if (mtouch) {
298 dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__);
299 usb_kill_urb(mtouch->irq);
c5b7c7c3 300 input_unregister_device(mtouch->input);
8baf9ed4
DT
301 usb_free_urb(mtouch->irq);
302 mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch);
303 kfree(mtouch);
304 }
1da177e4
LT
305}
306
8baf9ed4 307MODULE_DEVICE_TABLE(usb, mtouchusb_devices);
1da177e4
LT
308
309static struct usb_driver mtouchusb_driver = {
8baf9ed4
DT
310 .name = "mtouchusb",
311 .probe = mtouchusb_probe,
312 .disconnect = mtouchusb_disconnect,
313 .id_table = mtouchusb_devices,
1da177e4
LT
314};
315
8baf9ed4
DT
316static int __init mtouchusb_init(void)
317{
318 dbg("%s - called", __FUNCTION__);
319 return usb_register(&mtouchusb_driver);
1da177e4
LT
320}
321
8baf9ed4
DT
322static void __exit mtouchusb_cleanup(void)
323{
324 dbg("%s - called", __FUNCTION__);
325 usb_deregister(&mtouchusb_driver);
1da177e4
LT
326}
327
328module_init(mtouchusb_init);
329module_exit(mtouchusb_cleanup);
330
8baf9ed4
DT
331MODULE_AUTHOR(DRIVER_AUTHOR);
332MODULE_DESCRIPTION(DRIVER_DESC);
1da177e4 333MODULE_LICENSE("GPL");