aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/input/mtouchusb.c
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@pobox.com>2005-10-28 18:48:57 -0400
committerJeff Garzik <jgarzik@pobox.com>2005-10-28 18:48:57 -0400
commit596c96ba06e5d56e72451e02f93f4e15e17458df (patch)
tree78bc640acacb8faeb621c51296e99dbb0533a147 /drivers/usb/input/mtouchusb.c
parentad18b0ea089928367185e13d11424aea91d4b41f (diff)
parent20731945ae743034353a88c307920d1f16cf8ac8 (diff)
Merge branch 'master'
Diffstat (limited to 'drivers/usb/input/mtouchusb.c')
-rw-r--r--drivers/usb/input/mtouchusb.c111
1 files changed, 55 insertions, 56 deletions
diff --git a/drivers/usb/input/mtouchusb.c b/drivers/usb/input/mtouchusb.c
index ff9275057a18..7fce526560ca 100644
--- a/drivers/usb/input/mtouchusb.c
+++ b/drivers/usb/input/mtouchusb.c
@@ -98,7 +98,7 @@ struct mtouch_usb {
98 dma_addr_t data_dma; 98 dma_addr_t data_dma;
99 struct urb *irq; 99 struct urb *irq;
100 struct usb_device *udev; 100 struct usb_device *udev;
101 struct input_dev input; 101 struct input_dev *input;
102 char name[128]; 102 char name[128];
103 char phys[64]; 103 char phys[64];
104}; 104};
@@ -135,14 +135,14 @@ static void mtouchusb_irq(struct urb *urb, struct pt_regs *regs)
135 goto exit; 135 goto exit;
136 } 136 }
137 137
138 input_regs(&mtouch->input, regs); 138 input_regs(mtouch->input, regs);
139 input_report_key(&mtouch->input, BTN_TOUCH, 139 input_report_key(mtouch->input, BTN_TOUCH,
140 MTOUCHUSB_GET_TOUCHED(mtouch->data)); 140 MTOUCHUSB_GET_TOUCHED(mtouch->data));
141 input_report_abs(&mtouch->input, ABS_X, MTOUCHUSB_GET_XC(mtouch->data)); 141 input_report_abs(mtouch->input, ABS_X, MTOUCHUSB_GET_XC(mtouch->data));
142 input_report_abs(&mtouch->input, ABS_Y, 142 input_report_abs(mtouch->input, ABS_Y,
143 (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC) 143 (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC)
144 - MTOUCHUSB_GET_YC(mtouch->data)); 144 - MTOUCHUSB_GET_YC(mtouch->data));
145 input_sync(&mtouch->input); 145 input_sync(mtouch->input);
146 146
147exit: 147exit:
148 retval = usb_submit_urb(urb, GFP_ATOMIC); 148 retval = usb_submit_urb(urb, GFP_ATOMIC);
@@ -195,10 +195,10 @@ static void mtouchusb_free_buffers(struct usb_device *udev, struct mtouch_usb *m
195static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id) 195static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
196{ 196{
197 struct mtouch_usb *mtouch; 197 struct mtouch_usb *mtouch;
198 struct input_dev *input_dev;
198 struct usb_host_interface *interface; 199 struct usb_host_interface *interface;
199 struct usb_endpoint_descriptor *endpoint; 200 struct usb_endpoint_descriptor *endpoint;
200 struct usb_device *udev = interface_to_usbdev(intf); 201 struct usb_device *udev = interface_to_usbdev(intf);
201 char path[64];
202 int nRet; 202 int nRet;
203 203
204 dbg("%s - called", __FUNCTION__); 204 dbg("%s - called", __FUNCTION__);
@@ -209,57 +209,55 @@ static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_i
209 dbg("%s - setting endpoint", __FUNCTION__); 209 dbg("%s - setting endpoint", __FUNCTION__);
210 endpoint = &interface->endpoint[0].desc; 210 endpoint = &interface->endpoint[0].desc;
211 211
212 if (!(mtouch = kmalloc(sizeof(struct mtouch_usb), GFP_KERNEL))) { 212 mtouch = kzalloc(sizeof(struct mtouch_usb), GFP_KERNEL);
213 input_dev = input_allocate_device();
214 if (!mtouch || !input_dev) {
213 err("%s - Out of memory.", __FUNCTION__); 215 err("%s - Out of memory.", __FUNCTION__);
214 return -ENOMEM; 216 goto fail1;
215 } 217 }
216 218
217 memset(mtouch, 0, sizeof(struct mtouch_usb));
218 mtouch->udev = udev;
219
220 dbg("%s - allocating buffers", __FUNCTION__); 219 dbg("%s - allocating buffers", __FUNCTION__);
221 if (mtouchusb_alloc_buffers(udev, mtouch)) { 220 if (mtouchusb_alloc_buffers(udev, mtouch))
222 mtouchusb_free_buffers(udev, mtouch); 221 goto fail2;
223 kfree(mtouch);
224 return -ENOMEM;
225 }
226 222
227 mtouch->input.private = mtouch; 223 mtouch->udev = udev;
228 mtouch->input.open = mtouchusb_open; 224 mtouch->input = input_dev;
229 mtouch->input.close = mtouchusb_close;
230
231 usb_make_path(udev, path, 64);
232 sprintf(mtouch->phys, "%s/input0", path);
233
234 mtouch->input.name = mtouch->name;
235 mtouch->input.phys = mtouch->phys;
236 usb_to_input_id(udev, &mtouch->input.id);
237 mtouch->input.dev = &intf->dev;
238
239 mtouch->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
240 mtouch->input.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
241 mtouch->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
242
243 /* Used to Scale Compensated Data and Flip Y */
244 mtouch->input.absmin[ABS_X] = MTOUCHUSB_MIN_XC;
245 mtouch->input.absmax[ABS_X] = raw_coordinates ?
246 MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC;
247 mtouch->input.absfuzz[ABS_X] = MTOUCHUSB_XC_FUZZ;
248 mtouch->input.absflat[ABS_X] = MTOUCHUSB_XC_FLAT;
249 mtouch->input.absmin[ABS_Y] = MTOUCHUSB_MIN_YC;
250 mtouch->input.absmax[ABS_Y] = raw_coordinates ?
251 MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC;
252 mtouch->input.absfuzz[ABS_Y] = MTOUCHUSB_YC_FUZZ;
253 mtouch->input.absflat[ABS_Y] = MTOUCHUSB_YC_FLAT;
254 225
255 if (udev->manufacturer) 226 if (udev->manufacturer)
256 strcat(mtouch->name, udev->manufacturer); 227 strlcpy(mtouch->name, udev->manufacturer, sizeof(mtouch->name));
257 if (udev->product) 228
258 sprintf(mtouch->name, "%s %s", mtouch->name, udev->product); 229 if (udev->product) {
230 if (udev->manufacturer)
231 strlcat(mtouch->name, " ", sizeof(mtouch->name));
232 strlcat(mtouch->name, udev->product, sizeof(mtouch->name));
233 }
259 234
260 if (!strlen(mtouch->name)) 235 if (!strlen(mtouch->name))
261 sprintf(mtouch->name, "USB Touchscreen %04x:%04x", 236 snprintf(mtouch->name, sizeof(mtouch->name),
262 mtouch->input.id.vendor, mtouch->input.id.product); 237 "USB Touchscreen %04x:%04x",
238 le16_to_cpu(udev->descriptor.idVendor),
239 le16_to_cpu(udev->descriptor.idProduct));
240
241 usb_make_path(udev, mtouch->phys, sizeof(mtouch->phys));
242 strlcpy(mtouch->phys, "/input0", sizeof(mtouch->phys));
243
244 input_dev->name = mtouch->name;
245 input_dev->phys = mtouch->phys;
246 usb_to_input_id(udev, &input_dev->id);
247 input_dev->cdev.dev = &intf->dev;
248 input_dev->private = mtouch;
249
250 input_dev->open = mtouchusb_open;
251 input_dev->close = mtouchusb_close;
252
253 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
254 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
255 input_set_abs_params(input_dev, ABS_X, MTOUCHUSB_MIN_XC,
256 raw_coordinates ? MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC,
257 MTOUCHUSB_XC_FUZZ, MTOUCHUSB_XC_FLAT);
258 input_set_abs_params(input_dev, ABS_Y, MTOUCHUSB_MIN_YC,
259 raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC,
260 MTOUCHUSB_YC_FUZZ, MTOUCHUSB_YC_FLAT);
263 261
264 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0), 262 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0),
265 MTOUCHUSB_RESET, 263 MTOUCHUSB_RESET,
@@ -272,9 +270,7 @@ static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_i
272 mtouch->irq = usb_alloc_urb(0, GFP_KERNEL); 270 mtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
273 if (!mtouch->irq) { 271 if (!mtouch->irq) {
274 dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__); 272 dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__);
275 mtouchusb_free_buffers(udev, mtouch); 273 goto fail2;
276 kfree(mtouch);
277 return -ENOMEM;
278 } 274 }
279 275
280 dbg("%s - usb_fill_int_urb", __FUNCTION__); 276 dbg("%s - usb_fill_int_urb", __FUNCTION__);
@@ -284,7 +280,7 @@ static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_i
284 mtouchusb_irq, mtouch, endpoint->bInterval); 280 mtouchusb_irq, mtouch, endpoint->bInterval);
285 281
286 dbg("%s - input_register_device", __FUNCTION__); 282 dbg("%s - input_register_device", __FUNCTION__);
287 input_register_device(&mtouch->input); 283 input_register_device(mtouch->input);
288 284
289 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0), 285 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0),
290 MTOUCHUSB_ASYNC_REPORT, 286 MTOUCHUSB_ASYNC_REPORT,
@@ -293,10 +289,13 @@ static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_i
293 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d", 289 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
294 __FUNCTION__, nRet); 290 __FUNCTION__, nRet);
295 291
296 printk(KERN_INFO "input: %s on %s\n", mtouch->name, path);
297 usb_set_intfdata(intf, mtouch); 292 usb_set_intfdata(intf, mtouch);
298
299 return 0; 293 return 0;
294
295fail2: mtouchusb_free_buffers(udev, mtouch);
296fail1: input_free_device(input_dev);
297 kfree(mtouch);
298 return -ENOMEM;
300} 299}
301 300
302static void mtouchusb_disconnect(struct usb_interface *intf) 301static void mtouchusb_disconnect(struct usb_interface *intf)
@@ -308,7 +307,7 @@ static void mtouchusb_disconnect(struct usb_interface *intf)
308 if (mtouch) { 307 if (mtouch) {
309 dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__); 308 dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__);
310 usb_kill_urb(mtouch->irq); 309 usb_kill_urb(mtouch->irq);
311 input_unregister_device(&mtouch->input); 310 input_unregister_device(mtouch->input);
312 usb_free_urb(mtouch->irq); 311 usb_free_urb(mtouch->irq);
313 mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch); 312 mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch);
314 kfree(mtouch); 313 kfree(mtouch);