diff options
author | Dmitry Torokhov <dtor@insightbb.com> | 2007-04-12 01:33:00 -0400 |
---|---|---|
committer | Dmitry Torokhov <dtor@insightbb.com> | 2007-04-12 01:33:00 -0400 |
commit | 1b726a02d97cef2471521ae6947416f7374c6590 (patch) | |
tree | 0cef6754d4fcfb186e6f5c7ff3e8d2b2b16086e1 /drivers/usb | |
parent | 55d29c98418df737e87dbdfc36c78d3ed99a6698 (diff) |
Input: gtco - handle errors from input_register_device()
Also fix URB leak in gtco_probe error path, formatting fixes.
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/input/gtco.c | 627 |
1 files changed, 289 insertions, 338 deletions
diff --git a/drivers/usb/input/gtco.c b/drivers/usb/input/gtco.c index 203cdc1bbba4..aa9c676ca79a 100644 --- a/drivers/usb/input/gtco.c +++ b/drivers/usb/input/gtco.c | |||
@@ -187,7 +187,6 @@ struct hid_descriptor | |||
187 | 187 | ||
188 | 188 | ||
189 | /* | 189 | /* |
190 | * | ||
191 | * This is an abbreviated parser for the HID Report Descriptor. We | 190 | * This is an abbreviated parser for the HID Report Descriptor. We |
192 | * know what devices we are talking to, so this is by no means meant | 191 | * know what devices we are talking to, so this is by no means meant |
193 | * to be generic. We can make some safe assumptions: | 192 | * to be generic. We can make some safe assumptions: |
@@ -204,7 +203,7 @@ struct hid_descriptor | |||
204 | static void parse_hid_report_descriptor(struct gtco *device, char * report, | 203 | static void parse_hid_report_descriptor(struct gtco *device, char * report, |
205 | int length) | 204 | int length) |
206 | { | 205 | { |
207 | int x,i=0; | 206 | int x, i = 0; |
208 | 207 | ||
209 | /* Tag primitive vars */ | 208 | /* Tag primitive vars */ |
210 | __u8 prefix; | 209 | __u8 prefix; |
@@ -215,7 +214,6 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, | |||
215 | __u16 data16 = 0; | 214 | __u16 data16 = 0; |
216 | __u32 data32 = 0; | 215 | __u32 data32 = 0; |
217 | 216 | ||
218 | |||
219 | /* For parsing logic */ | 217 | /* For parsing logic */ |
220 | int inputnum = 0; | 218 | int inputnum = 0; |
221 | __u32 usage = 0; | 219 | __u32 usage = 0; |
@@ -227,44 +225,44 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, | |||
227 | /* Debug stuff */ | 225 | /* Debug stuff */ |
228 | char maintype='x'; | 226 | char maintype='x'; |
229 | char globtype[12]; | 227 | char globtype[12]; |
230 | int indent=0; | 228 | int indent = 0; |
231 | char indentstr[10]=""; | 229 | char indentstr[10] = ""; |
232 | |||
233 | 230 | ||
234 | 231 | ||
235 | dbg("======>>>>>>PARSE<<<<<<======"); | 232 | dbg("======>>>>>>PARSE<<<<<<======"); |
236 | 233 | ||
237 | /* Walk this report and pull out the info we need */ | 234 | /* Walk this report and pull out the info we need */ |
238 | while (i<length){ | 235 | while (i < length) { |
239 | prefix=report[i]; | 236 | prefix = report[i]; |
240 | 237 | ||
241 | /* Skip over prefix */ | 238 | /* Skip over prefix */ |
242 | i++; | 239 | i++; |
243 | 240 | ||
244 | /* Determine data size and save the data in the proper variable */ | 241 | /* Determine data size and save the data in the proper variable */ |
245 | size = PREF_SIZE(prefix); | 242 | size = PREF_SIZE(prefix); |
246 | switch(size){ | 243 | switch (size) { |
247 | case 1: | 244 | case 1: |
248 | data = report[i]; | 245 | data = report[i]; |
249 | break; | 246 | break; |
250 | case 2: | 247 | case 2: |
251 | data16 = le16_to_cpu(get_unaligned((__le16*)(&(report[i])))); | 248 | data16 = le16_to_cpu(get_unaligned((__le16 *)&report[i])); |
252 | break; | 249 | break; |
253 | case 3: | 250 | case 3: |
254 | size = 4; | 251 | size = 4; |
255 | data32 = le32_to_cpu(get_unaligned((__le32*)(&(report[i])))); | 252 | data32 = le32_to_cpu(get_unaligned((__le32 *)&report[i])); |
253 | break; | ||
256 | } | 254 | } |
257 | 255 | ||
258 | /* Skip size of data */ | 256 | /* Skip size of data */ |
259 | i+=size; | 257 | i += size; |
260 | 258 | ||
261 | /* What we do depends on the tag type */ | 259 | /* What we do depends on the tag type */ |
262 | tag = PREF_TAG(prefix); | 260 | tag = PREF_TAG(prefix); |
263 | type = PREF_TYPE(prefix); | 261 | type = PREF_TYPE(prefix); |
264 | switch(type){ | 262 | switch (type) { |
265 | case TYPE_MAIN: | 263 | case TYPE_MAIN: |
266 | strcpy(globtype,""); | 264 | strcpy(globtype, ""); |
267 | switch(tag){ | 265 | switch (tag) { |
268 | 266 | ||
269 | case TAG_MAIN_INPUT: | 267 | case TAG_MAIN_INPUT: |
270 | /* | 268 | /* |
@@ -274,19 +272,17 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, | |||
274 | * min/max values | 272 | * min/max values |
275 | */ | 273 | */ |
276 | 274 | ||
277 | maintype='I'; | 275 | maintype = 'I'; |
278 | if (data==2){ | 276 | if (data == 2) |
279 | strcpy(globtype,"Variable"); | 277 | strcpy(globtype, "Variable"); |
280 | } | 278 | else if (data == 3) |
281 | if (data==3){ | 279 | strcpy(globtype, "Var|Const"); |
282 | strcpy(globtype,"Var|Const"); | ||
283 | } | ||
284 | 280 | ||
285 | dbg("::::: Saving Report: %d input #%d Max: 0x%X(%d) Min:0x%X(%d) of %d bits", | 281 | dbg("::::: Saving Report: %d input #%d Max: 0x%X(%d) Min:0x%X(%d) of %d bits", |
286 | globalval[TAG_GLOB_REPORT_ID],inputnum, | 282 | globalval[TAG_GLOB_REPORT_ID], inputnum, |
287 | globalval[TAG_GLOB_LOG_MAX],globalval[TAG_GLOB_LOG_MAX], | 283 | globalval[TAG_GLOB_LOG_MAX], globalval[TAG_GLOB_LOG_MAX], |
288 | globalval[TAG_GLOB_LOG_MIN],globalval[TAG_GLOB_LOG_MIN], | 284 | globalval[TAG_GLOB_LOG_MIN], globalval[TAG_GLOB_LOG_MIN], |
289 | (globalval[TAG_GLOB_REPORT_SZ] * globalval[TAG_GLOB_REPORT_CNT])); | 285 | globalval[TAG_GLOB_REPORT_SZ] * globalval[TAG_GLOB_REPORT_CNT]); |
290 | 286 | ||
291 | 287 | ||
292 | /* | 288 | /* |
@@ -295,43 +291,43 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, | |||
295 | that, we look for everything else by | 291 | that, we look for everything else by |
296 | local usage value | 292 | local usage value |
297 | */ | 293 | */ |
298 | switch (inputnum){ | 294 | switch (inputnum) { |
299 | case 0: /* X coord */ | 295 | case 0: /* X coord */ |
300 | dbg("GER: X Usage: 0x%x",usage); | 296 | dbg("GER: X Usage: 0x%x", usage); |
301 | if (device->max_X == 0){ | 297 | if (device->max_X == 0) { |
302 | device->max_X = globalval[TAG_GLOB_LOG_MAX]; | 298 | device->max_X = globalval[TAG_GLOB_LOG_MAX]; |
303 | device->min_X = globalval[TAG_GLOB_LOG_MIN]; | 299 | device->min_X = globalval[TAG_GLOB_LOG_MIN]; |
304 | } | 300 | } |
305 | |||
306 | break; | 301 | break; |
302 | |||
307 | case 1: /* Y coord */ | 303 | case 1: /* Y coord */ |
308 | dbg("GER: Y Usage: 0x%x",usage); | 304 | dbg("GER: Y Usage: 0x%x", usage); |
309 | if (device->max_Y == 0){ | 305 | if (device->max_Y == 0) { |
310 | device->max_Y = globalval[TAG_GLOB_LOG_MAX]; | 306 | device->max_Y = globalval[TAG_GLOB_LOG_MAX]; |
311 | device->min_Y = globalval[TAG_GLOB_LOG_MIN]; | 307 | device->min_Y = globalval[TAG_GLOB_LOG_MIN]; |
312 | } | 308 | } |
313 | break; | 309 | break; |
310 | |||
314 | default: | 311 | default: |
315 | /* Tilt X */ | 312 | /* Tilt X */ |
316 | if (usage == DIGITIZER_USAGE_TILT_X){ | 313 | if (usage == DIGITIZER_USAGE_TILT_X) { |
317 | if (device->maxtilt_X == 0){ | 314 | if (device->maxtilt_X == 0) { |
318 | device->maxtilt_X = globalval[TAG_GLOB_LOG_MAX]; | 315 | device->maxtilt_X = globalval[TAG_GLOB_LOG_MAX]; |
319 | device->mintilt_X = globalval[TAG_GLOB_LOG_MIN]; | 316 | device->mintilt_X = globalval[TAG_GLOB_LOG_MIN]; |
320 | } | 317 | } |
321 | } | 318 | } |
322 | 319 | ||
323 | /* Tilt Y */ | 320 | /* Tilt Y */ |
324 | if (usage == DIGITIZER_USAGE_TILT_Y){ | 321 | if (usage == DIGITIZER_USAGE_TILT_Y) { |
325 | if (device->maxtilt_Y == 0){ | 322 | if (device->maxtilt_Y == 0) { |
326 | device->maxtilt_Y = globalval[TAG_GLOB_LOG_MAX]; | 323 | device->maxtilt_Y = globalval[TAG_GLOB_LOG_MAX]; |
327 | device->mintilt_Y = globalval[TAG_GLOB_LOG_MIN]; | 324 | device->mintilt_Y = globalval[TAG_GLOB_LOG_MIN]; |
328 | } | 325 | } |
329 | } | 326 | } |
330 | 327 | ||
331 | |||
332 | /* Pressure */ | 328 | /* Pressure */ |
333 | if (usage == DIGITIZER_USAGE_TIP_PRESSURE){ | 329 | if (usage == DIGITIZER_USAGE_TIP_PRESSURE) { |
334 | if (device->maxpressure == 0){ | 330 | if (device->maxpressure == 0) { |
335 | device->maxpressure = globalval[TAG_GLOB_LOG_MAX]; | 331 | device->maxpressure = globalval[TAG_GLOB_LOG_MAX]; |
336 | device->minpressure = globalval[TAG_GLOB_LOG_MIN]; | 332 | device->minpressure = globalval[TAG_GLOB_LOG_MIN]; |
337 | } | 333 | } |
@@ -341,192 +337,206 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, | |||
341 | } | 337 | } |
342 | 338 | ||
343 | inputnum++; | 339 | inputnum++; |
344 | |||
345 | |||
346 | break; | 340 | break; |
341 | |||
347 | case TAG_MAIN_OUTPUT: | 342 | case TAG_MAIN_OUTPUT: |
348 | maintype='O'; | 343 | maintype = 'O'; |
349 | break; | 344 | break; |
345 | |||
350 | case TAG_MAIN_FEATURE: | 346 | case TAG_MAIN_FEATURE: |
351 | maintype='F'; | 347 | maintype = 'F'; |
352 | break; | 348 | break; |
349 | |||
353 | case TAG_MAIN_COL_START: | 350 | case TAG_MAIN_COL_START: |
354 | maintype='S'; | 351 | maintype = 'S'; |
355 | 352 | ||
356 | if (data==0){ | 353 | if (data == 0) { |
357 | dbg("======>>>>>> Physical"); | 354 | dbg("======>>>>>> Physical"); |
358 | strcpy(globtype,"Physical"); | 355 | strcpy(globtype, "Physical"); |
359 | }else{ | 356 | } else |
360 | dbg("======>>>>>>"); | 357 | dbg("======>>>>>>"); |
361 | } | ||
362 | 358 | ||
363 | /* Indent the debug output */ | 359 | /* Indent the debug output */ |
364 | indent++; | 360 | indent++; |
365 | for (x=0;x<indent;x++){ | 361 | for (x = 0; x < indent; x++) |
366 | indentstr[x]='-'; | 362 | indentstr[x] = '-'; |
367 | } | 363 | indentstr[x] = 0; |
368 | indentstr[x]=0; | ||
369 | 364 | ||
370 | /* Save global tags */ | 365 | /* Save global tags */ |
371 | for (x=0;x<TAG_GLOB_MAX;x++){ | 366 | for (x = 0; x < TAG_GLOB_MAX; x++) |
372 | oldval[x] = globalval[x]; | 367 | oldval[x] = globalval[x]; |
373 | } | ||
374 | 368 | ||
375 | break; | 369 | break; |
370 | |||
376 | case TAG_MAIN_COL_END: | 371 | case TAG_MAIN_COL_END: |
377 | dbg("<<<<<<======"); | 372 | dbg("<<<<<<======"); |
378 | maintype='E'; | 373 | maintype = 'E'; |
379 | indent--; | 374 | indent--; |
380 | for (x=0;x<indent;x++){ | 375 | for (x = 0; x < indent; x++) |
381 | indentstr[x]='-'; | 376 | indentstr[x] = '-'; |
382 | } | 377 | indentstr[x] = 0; |
383 | indentstr[x]=0; | ||
384 | 378 | ||
385 | /* Copy global tags back */ | 379 | /* Copy global tags back */ |
386 | for (x=0;x<TAG_GLOB_MAX;x++){ | 380 | for (x = 0; x < TAG_GLOB_MAX; x++) |
387 | globalval[x] = oldval[x]; | 381 | globalval[x] = oldval[x]; |
388 | } | ||
389 | 382 | ||
390 | break; | 383 | break; |
391 | } | 384 | } |
392 | 385 | ||
393 | switch (size){ | 386 | switch (size) { |
394 | case 1: | 387 | case 1: |
395 | dbg("%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x", | 388 | dbg("%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x", |
396 | indentstr,tag,maintype,size,globtype,data); | 389 | indentstr, tag, maintype, size, globtype, data); |
397 | break; | 390 | break; |
391 | |||
398 | case 2: | 392 | case 2: |
399 | dbg("%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x", | 393 | dbg("%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x", |
400 | indentstr,tag,maintype,size,globtype, data16); | 394 | indentstr, tag, maintype, size, globtype, data16); |
401 | break; | 395 | break; |
396 | |||
402 | case 4: | 397 | case 4: |
403 | dbg("%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x", | 398 | dbg("%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x", |
404 | indentstr,tag,maintype,size,globtype,data32); | 399 | indentstr, tag, maintype, size, globtype, data32); |
405 | break; | 400 | break; |
406 | } | 401 | } |
407 | break; | 402 | break; |
403 | |||
408 | case TYPE_GLOBAL: | 404 | case TYPE_GLOBAL: |
409 | switch(tag){ | 405 | switch (tag) { |
410 | case TAG_GLOB_USAGE: | 406 | case TAG_GLOB_USAGE: |
411 | /* | 407 | /* |
412 | * First time we hit the global usage tag, | 408 | * First time we hit the global usage tag, |
413 | * it should tell us the type of device | 409 | * it should tell us the type of device |
414 | */ | 410 | */ |
415 | if (device->usage == 0){ | 411 | if (device->usage == 0) |
416 | device->usage = data; | 412 | device->usage = data; |
417 | } | 413 | |
418 | strcpy(globtype,"USAGE"); | 414 | strcpy(globtype, "USAGE"); |
419 | break; | 415 | break; |
420 | case TAG_GLOB_LOG_MIN : | 416 | |
421 | strcpy(globtype,"LOG_MIN"); | 417 | case TAG_GLOB_LOG_MIN: |
418 | strcpy(globtype, "LOG_MIN"); | ||
422 | break; | 419 | break; |
423 | case TAG_GLOB_LOG_MAX : | 420 | |
424 | strcpy(globtype,"LOG_MAX"); | 421 | case TAG_GLOB_LOG_MAX: |
422 | strcpy(globtype, "LOG_MAX"); | ||
425 | break; | 423 | break; |
426 | case TAG_GLOB_PHYS_MIN : | 424 | |
427 | strcpy(globtype,"PHYS_MIN"); | 425 | case TAG_GLOB_PHYS_MIN: |
426 | strcpy(globtype, "PHYS_MIN"); | ||
428 | break; | 427 | break; |
429 | case TAG_GLOB_PHYS_MAX : | 428 | |
430 | strcpy(globtype,"PHYS_MAX"); | 429 | case TAG_GLOB_PHYS_MAX: |
430 | strcpy(globtype, "PHYS_MAX"); | ||
431 | break; | 431 | break; |
432 | case TAG_GLOB_UNIT_EXP : | 432 | |
433 | strcpy(globtype,"EXP"); | 433 | case TAG_GLOB_UNIT_EXP: |
434 | strcpy(globtype, "EXP"); | ||
434 | break; | 435 | break; |
435 | case TAG_GLOB_UNIT : | 436 | |
436 | strcpy(globtype,"UNIT"); | 437 | case TAG_GLOB_UNIT: |
438 | strcpy(globtype, "UNIT"); | ||
437 | break; | 439 | break; |
438 | case TAG_GLOB_REPORT_SZ : | 440 | |
439 | strcpy(globtype,"REPORT_SZ"); | 441 | case TAG_GLOB_REPORT_SZ: |
442 | strcpy(globtype, "REPORT_SZ"); | ||
440 | break; | 443 | break; |
441 | case TAG_GLOB_REPORT_ID : | 444 | |
442 | strcpy(globtype,"REPORT_ID"); | 445 | case TAG_GLOB_REPORT_ID: |
446 | strcpy(globtype, "REPORT_ID"); | ||
443 | /* New report, restart numbering */ | 447 | /* New report, restart numbering */ |
444 | inputnum=0; | 448 | inputnum = 0; |
445 | break; | 449 | break; |
450 | |||
446 | case TAG_GLOB_REPORT_CNT: | 451 | case TAG_GLOB_REPORT_CNT: |
447 | strcpy(globtype,"REPORT_CNT"); | 452 | strcpy(globtype, "REPORT_CNT"); |
448 | break; | 453 | break; |
449 | case TAG_GLOB_PUSH : | 454 | |
450 | strcpy(globtype,"PUSH"); | 455 | case TAG_GLOB_PUSH: |
456 | strcpy(globtype, "PUSH"); | ||
451 | break; | 457 | break; |
458 | |||
452 | case TAG_GLOB_POP: | 459 | case TAG_GLOB_POP: |
453 | strcpy(globtype,"POP"); | 460 | strcpy(globtype, "POP"); |
454 | break; | 461 | break; |
455 | } | 462 | } |
456 | 463 | ||
457 | |||
458 | /* Check to make sure we have a good tag number | 464 | /* Check to make sure we have a good tag number |
459 | so we don't overflow array */ | 465 | so we don't overflow array */ |
460 | if (tag < TAG_GLOB_MAX){ | 466 | if (tag < TAG_GLOB_MAX) { |
461 | switch (size){ | 467 | switch (size) { |
462 | case 1: | 468 | case 1: |
463 | dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x",indentstr,globtype,tag,size,data); | 469 | dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x", |
464 | globalval[tag]=data; | 470 | indentstr, globtype, tag, size, data); |
471 | globalval[tag] = data; | ||
465 | break; | 472 | break; |
473 | |||
466 | case 2: | 474 | case 2: |
467 | dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x",indentstr,globtype,tag,size,data16); | 475 | dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x", |
468 | globalval[tag]=data16; | 476 | indentstr, globtype, tag, size, data16); |
477 | globalval[tag] = data16; | ||
469 | break; | 478 | break; |
479 | |||
470 | case 4: | 480 | case 4: |
471 | dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x",indentstr,globtype,tag,size,data32); | 481 | dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x", |
472 | globalval[tag]=data32; | 482 | indentstr, globtype, tag, size, data32); |
483 | globalval[tag] = data32; | ||
473 | break; | 484 | break; |
474 | } | 485 | } |
475 | }else{ | 486 | } else { |
476 | dbg("%sGLOBALTAG: ILLEGAL TAG:%d SIZE: %d ", | 487 | dbg("%sGLOBALTAG: ILLEGAL TAG:%d SIZE: %d ", |
477 | indentstr,tag,size); | 488 | indentstr, tag, size); |
478 | } | 489 | } |
479 | |||
480 | |||
481 | break; | 490 | break; |
482 | 491 | ||
483 | case TYPE_LOCAL: | 492 | case TYPE_LOCAL: |
484 | switch(tag){ | 493 | switch (tag) { |
485 | case TAG_GLOB_USAGE: | 494 | case TAG_GLOB_USAGE: |
486 | strcpy(globtype,"USAGE"); | 495 | strcpy(globtype, "USAGE"); |
487 | /* Always 1 byte */ | 496 | /* Always 1 byte */ |
488 | usage = data; | 497 | usage = data; |
489 | break; | 498 | break; |
490 | case TAG_GLOB_LOG_MIN : | 499 | |
491 | strcpy(globtype,"MIN"); | 500 | case TAG_GLOB_LOG_MIN: |
501 | strcpy(globtype, "MIN"); | ||
492 | break; | 502 | break; |
493 | case TAG_GLOB_LOG_MAX : | 503 | |
494 | strcpy(globtype,"MAX"); | 504 | case TAG_GLOB_LOG_MAX: |
505 | strcpy(globtype, "MAX"); | ||
495 | break; | 506 | break; |
507 | |||
496 | default: | 508 | default: |
497 | strcpy(globtype,"UNKNOWN"); | 509 | strcpy(globtype, "UNKNOWN"); |
510 | break; | ||
498 | } | 511 | } |
499 | 512 | ||
500 | switch (size){ | 513 | switch (size) { |
501 | case 1: | 514 | case 1: |
502 | dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x", | 515 | dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x", |
503 | indentstr,tag,globtype,size,data); | 516 | indentstr, tag, globtype, size, data); |
504 | break; | 517 | break; |
518 | |||
505 | case 2: | 519 | case 2: |
506 | dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x", | 520 | dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x", |
507 | indentstr,tag,globtype,size,data16); | 521 | indentstr, tag, globtype, size, data16); |
508 | break; | 522 | break; |
523 | |||
509 | case 4: | 524 | case 4: |
510 | dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x", | 525 | dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x", |
511 | indentstr,tag,globtype,size,data32); | 526 | indentstr, tag, globtype, size, data32); |
512 | break; | 527 | break; |
513 | } | 528 | } |
514 | 529 | ||
515 | break; | 530 | break; |
516 | } | 531 | } |
517 | |||
518 | } | 532 | } |
519 | |||
520 | } | 533 | } |
521 | 534 | ||
522 | |||
523 | |||
524 | /* INPUT DRIVER Routines */ | 535 | /* INPUT DRIVER Routines */ |
525 | 536 | ||
526 | |||
527 | /* | 537 | /* |
528 | * Called when opening the input device. This will submit the URB to | 538 | * Called when opening the input device. This will submit the URB to |
529 | * the usb system so we start getting reports | 539 | * the usb system so we start getting reports |
530 | */ | 540 | */ |
531 | static int gtco_input_open(struct input_dev *inputdev) | 541 | static int gtco_input_open(struct input_dev *inputdev) |
532 | { | 542 | { |
@@ -534,21 +544,20 @@ static int gtco_input_open(struct input_dev *inputdev) | |||
534 | device = inputdev->private; | 544 | device = inputdev->private; |
535 | 545 | ||
536 | device->urbinfo->dev = device->usbdev; | 546 | device->urbinfo->dev = device->usbdev; |
537 | if (usb_submit_urb(device->urbinfo, GFP_KERNEL)) { | 547 | if (usb_submit_urb(device->urbinfo, GFP_KERNEL)) |
538 | return -EIO; | 548 | return -EIO; |
539 | } | 549 | |
540 | return 0; | 550 | return 0; |
541 | } | 551 | } |
542 | 552 | ||
543 | /** | 553 | /* |
544 | Called when closing the input device. This will unlink the URB | 554 | * Called when closing the input device. This will unlink the URB |
545 | */ | 555 | */ |
546 | static void gtco_input_close(struct input_dev *inputdev) | 556 | static void gtco_input_close(struct input_dev *inputdev) |
547 | { | 557 | { |
548 | struct gtco *device = inputdev->private; | 558 | struct gtco *device = inputdev->private; |
549 | 559 | ||
550 | usb_kill_urb(device->urbinfo); | 560 | usb_kill_urb(device->urbinfo); |
551 | |||
552 | } | 561 | } |
553 | 562 | ||
554 | 563 | ||
@@ -564,15 +573,12 @@ static void gtco_setup_caps(struct input_dev *inputdev) | |||
564 | { | 573 | { |
565 | struct gtco *device = inputdev->private; | 574 | struct gtco *device = inputdev->private; |
566 | 575 | ||
567 | |||
568 | /* Which events */ | 576 | /* Which events */ |
569 | inputdev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC); | 577 | inputdev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC); |
570 | 578 | ||
571 | |||
572 | /* Misc event menu block */ | 579 | /* Misc event menu block */ |
573 | inputdev->mscbit[0] = BIT(MSC_SCAN)|BIT(MSC_SERIAL)|BIT(MSC_RAW) ; | 580 | inputdev->mscbit[0] = BIT(MSC_SCAN)|BIT(MSC_SERIAL)|BIT(MSC_RAW) ; |
574 | 581 | ||
575 | |||
576 | /* Absolute values based on HID report info */ | 582 | /* Absolute values based on HID report info */ |
577 | input_set_abs_params(inputdev, ABS_X, device->min_X, device->max_X, | 583 | input_set_abs_params(inputdev, ABS_X, device->min_X, device->max_X, |
578 | 0, 0); | 584 | 0, 0); |
@@ -590,17 +596,12 @@ static void gtco_setup_caps(struct input_dev *inputdev) | |||
590 | input_set_abs_params(inputdev, ABS_PRESSURE, device->minpressure, | 596 | input_set_abs_params(inputdev, ABS_PRESSURE, device->minpressure, |
591 | device->maxpressure, 0, 0); | 597 | device->maxpressure, 0, 0); |
592 | 598 | ||
593 | |||
594 | /* Transducer */ | 599 | /* Transducer */ |
595 | input_set_abs_params(inputdev, ABS_MISC, 0,0xFF, 0, 0); | 600 | input_set_abs_params(inputdev, ABS_MISC, 0, 0xFF, 0, 0); |
596 | |||
597 | } | 601 | } |
598 | 602 | ||
599 | |||
600 | |||
601 | /* USB Routines */ | 603 | /* USB Routines */ |
602 | 604 | ||
603 | |||
604 | /* | 605 | /* |
605 | * URB callback routine. Called when we get IRQ reports from the | 606 | * URB callback routine. Called when we get IRQ reports from the |
606 | * digitizer. | 607 | * digitizer. |
@@ -610,9 +611,7 @@ static void gtco_setup_caps(struct input_dev *inputdev) | |||
610 | */ | 611 | */ |
611 | static void gtco_urb_callback(struct urb *urbinfo) | 612 | static void gtco_urb_callback(struct urb *urbinfo) |
612 | { | 613 | { |
613 | 614 | struct gtco *device = urbinfo->context; | |
614 | |||
615 | struct gtco *device = urbinfo->context; | ||
616 | struct input_dev *inputdev; | 615 | struct input_dev *inputdev; |
617 | int rc; | 616 | int rc; |
618 | u32 val = 0; | 617 | u32 val = 0; |
@@ -621,19 +620,20 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
621 | 620 | ||
622 | inputdev = device->inputdevice; | 621 | inputdev = device->inputdevice; |
623 | 622 | ||
624 | |||
625 | /* Was callback OK? */ | 623 | /* Was callback OK? */ |
626 | if ((urbinfo->status == -ECONNRESET ) || | 624 | if (urbinfo->status == -ECONNRESET || |
627 | (urbinfo->status == -ENOENT ) || | 625 | urbinfo->status == -ENOENT || |
628 | (urbinfo->status == -ESHUTDOWN )){ | 626 | urbinfo->status == -ESHUTDOWN) { |
629 | 627 | ||
630 | /* Shutdown is occurring. Return and don't queue up any more */ | 628 | /* Shutdown is occurring. Return and don't queue up any more */ |
631 | return; | 629 | return; |
632 | } | 630 | } |
633 | 631 | ||
634 | if (urbinfo->status != 0 ) { | 632 | if (urbinfo->status != 0) { |
635 | /* Some unknown error. Hopefully temporary. Just go and */ | 633 | /* |
636 | /* requeue an URB */ | 634 | * Some unknown error. Hopefully temporary. Just go and |
635 | * requeue an URB | ||
636 | */ | ||
637 | goto resubmit; | 637 | goto resubmit; |
638 | } | 638 | } |
639 | 639 | ||
@@ -642,10 +642,9 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
642 | */ | 642 | */ |
643 | 643 | ||
644 | /* PID dependent when we interpret the report */ | 644 | /* PID dependent when we interpret the report */ |
645 | if ((inputdev->id.product == PID_1000 )|| | 645 | if (inputdev->id.product == PID_1000 || |
646 | (inputdev->id.product == PID_1001 )|| | 646 | inputdev->id.product == PID_1001 || |
647 | (inputdev->id.product == PID_1002 )) | 647 | inputdev->id.product == PID_1002) { |
648 | { | ||
649 | 648 | ||
650 | /* | 649 | /* |
651 | * Switch on the report ID | 650 | * Switch on the report ID |
@@ -653,10 +652,10 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
653 | * the report number. We can just fall through the case | 652 | * the report number. We can just fall through the case |
654 | * statements if we start with the highest number report | 653 | * statements if we start with the highest number report |
655 | */ | 654 | */ |
656 | switch(device->buffer[0]){ | 655 | switch (device->buffer[0]) { |
657 | case 5: | 656 | case 5: |
658 | /* Pressure is 9 bits */ | 657 | /* Pressure is 9 bits */ |
659 | val = ((u16)(device->buffer[8]) << 1); | 658 | val = ((u16)(device->buffer[8]) << 1); |
660 | val |= (u16)(device->buffer[7] >> 7); | 659 | val |= (u16)(device->buffer[7] >> 7); |
661 | input_report_abs(inputdev, ABS_PRESSURE, | 660 | input_report_abs(inputdev, ABS_PRESSURE, |
662 | device->buffer[8]); | 661 | device->buffer[8]); |
@@ -664,7 +663,6 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
664 | /* Mask out the Y tilt value used for pressure */ | 663 | /* Mask out the Y tilt value used for pressure */ |
665 | device->buffer[7] = (u8)((device->buffer[7]) & 0x7F); | 664 | device->buffer[7] = (u8)((device->buffer[7]) & 0x7F); |
666 | 665 | ||
667 | |||
668 | /* Fall thru */ | 666 | /* Fall thru */ |
669 | case 4: | 667 | case 4: |
670 | /* Tilt */ | 668 | /* Tilt */ |
@@ -684,11 +682,10 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
684 | input_report_abs(inputdev, ABS_TILT_Y, (s32)valsigned); | 682 | input_report_abs(inputdev, ABS_TILT_Y, (s32)valsigned); |
685 | 683 | ||
686 | /* Fall thru */ | 684 | /* Fall thru */ |
687 | |||
688 | case 2: | 685 | case 2: |
689 | case 3: | 686 | case 3: |
690 | /* Convert buttons, only 5 bits possible */ | 687 | /* Convert buttons, only 5 bits possible */ |
691 | val = (device->buffer[5])&MASK_BUTTON; | 688 | val = (device->buffer[5]) & MASK_BUTTON; |
692 | 689 | ||
693 | /* We don't apply any meaning to the bitmask, | 690 | /* We don't apply any meaning to the bitmask, |
694 | just report */ | 691 | just report */ |
@@ -696,132 +693,109 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
696 | 693 | ||
697 | /* Fall thru */ | 694 | /* Fall thru */ |
698 | case 1: | 695 | case 1: |
699 | |||
700 | /* All reports have X and Y coords in the same place */ | 696 | /* All reports have X and Y coords in the same place */ |
701 | val = le16_to_cpu(get_unaligned((__le16 *) &(device->buffer[1]))); | 697 | val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[1])); |
702 | input_report_abs(inputdev, ABS_X, val); | 698 | input_report_abs(inputdev, ABS_X, val); |
703 | 699 | ||
704 | val = le16_to_cpu(get_unaligned((__le16 *) &(device->buffer[3]))); | 700 | val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[3])); |
705 | input_report_abs(inputdev, ABS_Y, val); | 701 | input_report_abs(inputdev, ABS_Y, val); |
706 | 702 | ||
707 | |||
708 | /* Ditto for proximity bit */ | 703 | /* Ditto for proximity bit */ |
709 | if (device->buffer[5]& MASK_INRANGE){ | 704 | val = device->buffer[5] & MASK_INRANGE ? 1 : 0; |
710 | val = 1; | ||
711 | }else{ | ||
712 | val=0; | ||
713 | } | ||
714 | input_report_abs(inputdev, ABS_DISTANCE, val); | 705 | input_report_abs(inputdev, ABS_DISTANCE, val); |
715 | 706 | ||
716 | |||
717 | /* Report 1 is an exception to how we handle buttons */ | 707 | /* Report 1 is an exception to how we handle buttons */ |
718 | /* Buttons are an index, not a bitmask */ | 708 | /* Buttons are an index, not a bitmask */ |
719 | if (device->buffer[0] == 1){ | 709 | if (device->buffer[0] == 1) { |
720 | 710 | ||
721 | /* Convert buttons, 5 bit index */ | 711 | /* |
722 | /* Report value of index set as one, | 712 | * Convert buttons, 5 bit index |
723 | the rest as 0 */ | 713 | * Report value of index set as one, |
724 | val = device->buffer[5]& MASK_BUTTON; | 714 | * the rest as 0 |
715 | */ | ||
716 | val = device->buffer[5] & MASK_BUTTON; | ||
725 | dbg("======>>>>>>REPORT 1: val 0x%X(%d)", | 717 | dbg("======>>>>>>REPORT 1: val 0x%X(%d)", |
726 | val,val); | 718 | val, val); |
727 | 719 | ||
728 | /* | 720 | /* |
729 | * We don't apply any meaning to the button | 721 | * We don't apply any meaning to the button |
730 | * index, just report it | 722 | * index, just report it |
731 | */ | 723 | */ |
732 | input_event(inputdev, EV_MSC, MSC_SERIAL, val); | 724 | input_event(inputdev, EV_MSC, MSC_SERIAL, val); |
733 | |||
734 | |||
735 | } | 725 | } |
736 | |||
737 | break; | 726 | break; |
727 | |||
738 | case 7: | 728 | case 7: |
739 | /* Menu blocks */ | 729 | /* Menu blocks */ |
740 | input_event(inputdev, EV_MSC, MSC_SCAN, | 730 | input_event(inputdev, EV_MSC, MSC_SCAN, |
741 | device->buffer[1]); | 731 | device->buffer[1]); |
742 | |||
743 | |||
744 | break; | 732 | break; |
745 | |||
746 | } | 733 | } |
747 | |||
748 | |||
749 | } | 734 | } |
735 | |||
750 | /* Other pid class */ | 736 | /* Other pid class */ |
751 | if ((inputdev->id.product == PID_400 )|| | 737 | if (inputdev->id.product == PID_400 || |
752 | (inputdev->id.product == PID_401 )) | 738 | inputdev->id.product == PID_401) { |
753 | { | ||
754 | 739 | ||
755 | /* Report 2 */ | 740 | /* Report 2 */ |
756 | if (device->buffer[0] == 2){ | 741 | if (device->buffer[0] == 2) { |
757 | /* Menu blocks */ | 742 | /* Menu blocks */ |
758 | input_event(inputdev, EV_MSC, MSC_SCAN, | 743 | input_event(inputdev, EV_MSC, MSC_SCAN, device->buffer[1]); |
759 | device->buffer[1]); | ||
760 | } | 744 | } |
761 | 745 | ||
762 | /* Report 1 */ | 746 | /* Report 1 */ |
763 | if (device->buffer[0] == 1){ | 747 | if (device->buffer[0] == 1) { |
764 | char buttonbyte; | 748 | char buttonbyte; |
765 | 749 | ||
766 | |||
767 | /* IF X max > 64K, we still a bit from the y report */ | 750 | /* IF X max > 64K, we still a bit from the y report */ |
768 | if (device->max_X > 0x10000){ | 751 | if (device->max_X > 0x10000) { |
769 | 752 | ||
770 | val = (u16)(((u16)(device->buffer[2]<<8))|((u8)(device->buffer[1]))); | 753 | val = (u16)(((u16)(device->buffer[2] << 8)) | (u8)device->buffer[1]); |
771 | val |= (u32)(((u8)device->buffer[3]&0x1)<< 16); | 754 | val |= (u32)(((u8)device->buffer[3] & 0x1) << 16); |
772 | 755 | ||
773 | input_report_abs(inputdev, ABS_X, val); | 756 | input_report_abs(inputdev, ABS_X, val); |
774 | 757 | ||
775 | le_buffer[0] = (u8)((u8)(device->buffer[3])>>1); | 758 | le_buffer[0] = (u8)((u8)(device->buffer[3]) >> 1); |
776 | le_buffer[0] |= (u8)((device->buffer[3]&0x1)<<7); | 759 | le_buffer[0] |= (u8)((device->buffer[3] & 0x1) << 7); |
777 | |||
778 | le_buffer[1] = (u8)(device->buffer[4]>>1); | ||
779 | le_buffer[1] |= (u8)((device->buffer[5]&0x1)<<7); | ||
780 | 760 | ||
781 | val = le16_to_cpu(get_unaligned((__le16 *)(le_buffer))); | 761 | le_buffer[1] = (u8)(device->buffer[4] >> 1); |
762 | le_buffer[1] |= (u8)((device->buffer[5] & 0x1) << 7); | ||
782 | 763 | ||
764 | val = le16_to_cpu(get_unaligned((__le16 *)le_buffer)); | ||
783 | input_report_abs(inputdev, ABS_Y, val); | 765 | input_report_abs(inputdev, ABS_Y, val); |
784 | 766 | ||
785 | |||
786 | /* | 767 | /* |
787 | * Shift the button byte right by one to | 768 | * Shift the button byte right by one to |
788 | * make it look like the standard report | 769 | * make it look like the standard report |
789 | */ | 770 | */ |
790 | buttonbyte = (device->buffer[5])>>1; | 771 | buttonbyte = device->buffer[5] >> 1; |
791 | }else{ | 772 | } else { |
792 | 773 | ||
793 | val = le16_to_cpu(get_unaligned((__le16 *) (&(device->buffer[1])))); | 774 | val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[1])); |
794 | input_report_abs(inputdev, ABS_X, val); | 775 | input_report_abs(inputdev, ABS_X, val); |
795 | 776 | ||
796 | val = le16_to_cpu(get_unaligned((__le16 *) (&(device->buffer[3])))); | 777 | val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[3])); |
797 | input_report_abs(inputdev, ABS_Y, val); | 778 | input_report_abs(inputdev, ABS_Y, val); |
798 | 779 | ||
799 | buttonbyte = device->buffer[5]; | 780 | buttonbyte = device->buffer[5]; |
800 | |||
801 | } | 781 | } |
802 | 782 | ||
803 | |||
804 | /* BUTTONS and PROXIMITY */ | 783 | /* BUTTONS and PROXIMITY */ |
805 | if (buttonbyte& MASK_INRANGE){ | 784 | val = buttonbyte & MASK_INRANGE ? 1 : 0; |
806 | val = 1; | ||
807 | }else{ | ||
808 | val=0; | ||
809 | } | ||
810 | input_report_abs(inputdev, ABS_DISTANCE, val); | 785 | input_report_abs(inputdev, ABS_DISTANCE, val); |
811 | 786 | ||
812 | /* Convert buttons, only 4 bits possible */ | 787 | /* Convert buttons, only 4 bits possible */ |
813 | val = buttonbyte&0x0F; | 788 | val = buttonbyte & 0x0F; |
814 | #ifdef USE_BUTTONS | 789 | #ifdef USE_BUTTONS |
815 | for ( i=0;i<5;i++){ | 790 | for (i = 0; i < 5; i++) |
816 | input_report_key(inputdev, BTN_DIGI+i,val&(1<<i)); | 791 | input_report_key(inputdev, BTN_DIGI + i, val & (1 << i)); |
817 | } | ||
818 | #else | 792 | #else |
819 | /* We don't apply any meaning to the bitmask, just report */ | 793 | /* We don't apply any meaning to the bitmask, just report */ |
820 | input_event(inputdev, EV_MSC, MSC_SERIAL, val); | 794 | input_event(inputdev, EV_MSC, MSC_SERIAL, val); |
821 | #endif | 795 | #endif |
796 | |||
822 | /* TRANSDUCER */ | 797 | /* TRANSDUCER */ |
823 | input_report_abs(inputdev, ABS_MISC, device->buffer[6]); | 798 | input_report_abs(inputdev, ABS_MISC, device->buffer[6]); |
824 | |||
825 | } | 799 | } |
826 | } | 800 | } |
827 | 801 | ||
@@ -833,10 +807,8 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
833 | 807 | ||
834 | resubmit: | 808 | resubmit: |
835 | rc = usb_submit_urb(urbinfo, GFP_ATOMIC); | 809 | rc = usb_submit_urb(urbinfo, GFP_ATOMIC); |
836 | if (rc != 0) { | 810 | if (rc != 0) |
837 | err("usb_submit_urb failed rc=0x%x",rc); | 811 | err("usb_submit_urb failed rc=0x%x", rc); |
838 | } | ||
839 | |||
840 | } | 812 | } |
841 | 813 | ||
842 | /* | 814 | /* |
@@ -854,58 +826,46 @@ static int gtco_probe(struct usb_interface *usbinterface, | |||
854 | const struct usb_device_id *id) | 826 | const struct usb_device_id *id) |
855 | { | 827 | { |
856 | 828 | ||
857 | struct gtco *device = NULL; | 829 | struct gtco *gtco; |
858 | char path[PATHLENGTH]; | 830 | struct input_dev *input_dev; |
859 | struct input_dev *inputdev; | ||
860 | struct hid_descriptor *hid_desc; | 831 | struct hid_descriptor *hid_desc; |
861 | char *report; | 832 | char *report = NULL; |
862 | int result=0, retry; | 833 | int result = 0, retry; |
834 | int error; | ||
863 | struct usb_endpoint_descriptor *endpoint; | 835 | struct usb_endpoint_descriptor *endpoint; |
864 | 836 | ||
865 | /* Allocate memory for device structure */ | 837 | /* Allocate memory for device structure */ |
866 | device = kzalloc(sizeof(struct gtco), GFP_KERNEL); | 838 | gtco = kzalloc(sizeof(struct gtco), GFP_KERNEL); |
867 | if (device == NULL) { | 839 | input_dev = input_allocate_device(); |
840 | if (!gtco || !input_dev) { | ||
868 | err("No more memory"); | 841 | err("No more memory"); |
869 | return -ENOMEM; | 842 | error = -ENOMEM; |
843 | goto err_free_devs; | ||
870 | } | 844 | } |
871 | 845 | ||
872 | 846 | /* Set pointer to the input device */ | |
873 | device->inputdevice = input_allocate_device(); | 847 | gtco->inputdevice = input_dev; |
874 | if (!device->inputdevice){ | ||
875 | kfree(device); | ||
876 | err("No more memory"); | ||
877 | return -ENOMEM; | ||
878 | } | ||
879 | |||
880 | /* Get pointer to the input device */ | ||
881 | inputdev = device->inputdevice; | ||
882 | 848 | ||
883 | /* Save interface information */ | 849 | /* Save interface information */ |
884 | device->usbdev = usb_get_dev(interface_to_usbdev(usbinterface)); | 850 | gtco->usbdev = usb_get_dev(interface_to_usbdev(usbinterface)); |
885 | |||
886 | 851 | ||
887 | /* Allocate some data for incoming reports */ | 852 | /* Allocate some data for incoming reports */ |
888 | device->buffer = usb_buffer_alloc(device->usbdev, REPORT_MAX_SIZE, | 853 | gtco->buffer = usb_buffer_alloc(gtco->usbdev, REPORT_MAX_SIZE, |
889 | GFP_KERNEL, &(device->buf_dma)); | 854 | GFP_KERNEL, >co->buf_dma); |
890 | if (!device->buffer){ | 855 | if (!gtco->buffer) { |
891 | input_free_device(device->inputdevice); | 856 | err("No more memory for us buffers"); |
892 | kfree(device); | 857 | error = -ENOMEM; |
893 | err("No more memory"); | 858 | goto err_free_devs; |
894 | return -ENOMEM; | ||
895 | } | 859 | } |
896 | 860 | ||
897 | /* Allocate URB for reports */ | 861 | /* Allocate URB for reports */ |
898 | device->urbinfo = usb_alloc_urb(0, GFP_KERNEL); | 862 | gtco->urbinfo = usb_alloc_urb(0, GFP_KERNEL); |
899 | if (!device->urbinfo) { | 863 | if (!gtco->urbinfo) { |
900 | usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, | 864 | err("Failed to allocate URB"); |
901 | device->buffer, device->buf_dma); | ||
902 | input_free_device(device->inputdevice); | ||
903 | kfree(device); | ||
904 | err("No more memory"); | ||
905 | return -ENOMEM; | 865 | return -ENOMEM; |
866 | goto err_free_buf; | ||
906 | } | 867 | } |
907 | 868 | ||
908 | |||
909 | /* | 869 | /* |
910 | * The endpoint is always altsetting 0, we know this since we know | 870 | * The endpoint is always altsetting 0, we know this since we know |
911 | * this device only has one interrupt endpoint | 871 | * this device only has one interrupt endpoint |
@@ -913,51 +873,43 @@ static int gtco_probe(struct usb_interface *usbinterface, | |||
913 | endpoint = &usbinterface->altsetting[0].endpoint[0].desc; | 873 | endpoint = &usbinterface->altsetting[0].endpoint[0].desc; |
914 | 874 | ||
915 | /* Some debug */ | 875 | /* Some debug */ |
916 | dbg("gtco # interfaces: %d",usbinterface->num_altsetting); | 876 | dbg("gtco # interfaces: %d", usbinterface->num_altsetting); |
917 | dbg("num endpoints: %d",usbinterface->cur_altsetting->desc.bNumEndpoints); | 877 | dbg("num endpoints: %d", usbinterface->cur_altsetting->desc.bNumEndpoints); |
918 | dbg("interface class: %d",usbinterface->cur_altsetting->desc.bInterfaceClass); | 878 | dbg("interface class: %d", usbinterface->cur_altsetting->desc.bInterfaceClass); |
919 | dbg("endpoint: attribute:0x%x type:0x%x",endpoint->bmAttributes,endpoint->bDescriptorType); | 879 | dbg("endpoint: attribute:0x%x type:0x%x", endpoint->bmAttributes, endpoint->bDescriptorType); |
920 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) | 880 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) |
921 | dbg("endpoint: we have interrupt endpoint\n"); | 881 | dbg("endpoint: we have interrupt endpoint\n"); |
922 | 882 | ||
923 | dbg("endpoint extra len:%d ",usbinterface->altsetting[0].extralen); | 883 | dbg("endpoint extra len:%d ", usbinterface->altsetting[0].extralen); |
924 | |||
925 | |||
926 | 884 | ||
927 | /* | 885 | /* |
928 | * Find the HID descriptor so we can find out the size of the | 886 | * Find the HID descriptor so we can find out the size of the |
929 | * HID report descriptor | 887 | * HID report descriptor |
930 | */ | 888 | */ |
931 | if (usb_get_extra_descriptor(usbinterface->cur_altsetting, | 889 | if (usb_get_extra_descriptor(usbinterface->cur_altsetting, |
932 | HID_DEVICE_TYPE,&hid_desc) != 0){ | 890 | HID_DEVICE_TYPE, &hid_desc) != 0){ |
933 | err("Can't retrieve exta USB descriptor to get hid report descriptor length"); | 891 | err("Can't retrieve exta USB descriptor to get hid report descriptor length"); |
934 | usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, | 892 | error = -EIO; |
935 | device->buffer, device->buf_dma); | 893 | goto err_free_urb; |
936 | input_free_device(device->inputdevice); | ||
937 | kfree(device); | ||
938 | return -EIO; | ||
939 | } | 894 | } |
940 | 895 | ||
941 | dbg("Extra descriptor success: type:%d len:%d", | 896 | dbg("Extra descriptor success: type:%d len:%d", |
942 | hid_desc->bDescriptorType, hid_desc->wDescriptorLength); | 897 | hid_desc->bDescriptorType, hid_desc->wDescriptorLength); |
943 | 898 | ||
944 | if (!(report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL))) { | 899 | report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL); |
945 | usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, | 900 | if (!report) { |
946 | device->buffer, device->buf_dma); | 901 | err("No more memory for report"); |
947 | 902 | error = -ENOMEM; | |
948 | input_free_device(device->inputdevice); | 903 | goto err_free_urb; |
949 | kfree(device); | ||
950 | err("No more memory"); | ||
951 | return -ENOMEM; | ||
952 | } | 904 | } |
953 | 905 | ||
954 | /* Couple of tries to get reply */ | 906 | /* Couple of tries to get reply */ |
955 | for (retry=0;retry<3;retry++) { | 907 | for (retry = 0; retry < 3; retry++) { |
956 | result = usb_control_msg(device->usbdev, | 908 | result = usb_control_msg(gtco->usbdev, |
957 | usb_rcvctrlpipe(device->usbdev, 0), | 909 | usb_rcvctrlpipe(gtco->usbdev, 0), |
958 | USB_REQ_GET_DESCRIPTOR, | 910 | USB_REQ_GET_DESCRIPTOR, |
959 | USB_RECIP_INTERFACE | USB_DIR_IN, | 911 | USB_RECIP_INTERFACE | USB_DIR_IN, |
960 | (REPORT_DEVICE_TYPE << 8), | 912 | REPORT_DEVICE_TYPE << 8, |
961 | 0, /* interface */ | 913 | 0, /* interface */ |
962 | report, | 914 | report, |
963 | hid_desc->wDescriptorLength, | 915 | hid_desc->wDescriptorLength, |
@@ -969,72 +921,75 @@ static int gtco_probe(struct usb_interface *usbinterface, | |||
969 | 921 | ||
970 | /* If we didn't get the report, fail */ | 922 | /* If we didn't get the report, fail */ |
971 | dbg("usb_control_msg result: :%d", result); | 923 | dbg("usb_control_msg result: :%d", result); |
972 | if (result != hid_desc->wDescriptorLength){ | 924 | if (result != hid_desc->wDescriptorLength) { |
973 | kfree(report); | ||
974 | usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, | ||
975 | device->buffer, device->buf_dma); | ||
976 | input_free_device(device->inputdevice); | ||
977 | kfree(device); | ||
978 | err("Failed to get HID Report Descriptor of size: %d", | 925 | err("Failed to get HID Report Descriptor of size: %d", |
979 | hid_desc->wDescriptorLength); | 926 | hid_desc->wDescriptorLength); |
980 | return -EIO; | 927 | error = -EIO; |
928 | goto err_free_urb; | ||
981 | } | 929 | } |
982 | 930 | ||
983 | |||
984 | /* Now we parse the report */ | 931 | /* Now we parse the report */ |
985 | parse_hid_report_descriptor(device,report,result); | 932 | parse_hid_report_descriptor(gtco, report, result); |
986 | 933 | ||
987 | /* Now we delete it */ | 934 | /* Now we delete it */ |
988 | kfree(report); | 935 | kfree(report); |
989 | 936 | ||
990 | /* Create a device file node */ | 937 | /* Create a device file node */ |
991 | usb_make_path(device->usbdev, path, PATHLENGTH); | 938 | usb_make_path(gtco->usbdev, gtco->usbpath, sizeof(gtco->usbpath)); |
992 | sprintf(device->usbpath, "%s/input0", path); | 939 | strlcat(gtco->usbpath, "/input0", sizeof(gtco->usbpath)); |
993 | |||
994 | 940 | ||
995 | /* Set Input device functions */ | 941 | /* Set Input device functions */ |
996 | inputdev->open = gtco_input_open; | 942 | input_dev->open = gtco_input_open; |
997 | inputdev->close = gtco_input_close; | 943 | input_dev->close = gtco_input_close; |
998 | 944 | ||
999 | /* Set input device information */ | 945 | /* Set input device information */ |
1000 | inputdev->name = "GTCO_CalComp"; | 946 | input_dev->name = "GTCO_CalComp"; |
1001 | inputdev->phys = device->usbpath; | 947 | input_dev->phys = gtco->usbpath; |
1002 | inputdev->private = device; | 948 | input_dev->private = gtco; |
1003 | |||
1004 | 949 | ||
1005 | /* Now set up all the input device capabilities */ | 950 | /* Now set up all the input device capabilities */ |
1006 | gtco_setup_caps(inputdev); | 951 | gtco_setup_caps(input_dev); |
1007 | 952 | ||
1008 | /* Set input device required ID information */ | 953 | /* Set input device required ID information */ |
1009 | usb_to_input_id(device->usbdev, &device->inputdevice->id); | 954 | usb_to_input_id(gtco->usbdev, &input_dev->id); |
1010 | inputdev->cdev.dev = &usbinterface->dev; | 955 | input_dev->cdev.dev = &usbinterface->dev; |
1011 | 956 | ||
1012 | /* Setup the URB, it will be posted later on open of input device */ | 957 | /* Setup the URB, it will be posted later on open of input device */ |
1013 | endpoint = &usbinterface->altsetting[0].endpoint[0].desc; | 958 | endpoint = &usbinterface->altsetting[0].endpoint[0].desc; |
1014 | 959 | ||
1015 | usb_fill_int_urb(device->urbinfo, | 960 | usb_fill_int_urb(gtco->urbinfo, |
1016 | device->usbdev, | 961 | gtco->usbdev, |
1017 | usb_rcvintpipe(device->usbdev, | 962 | usb_rcvintpipe(gtco->usbdev, |
1018 | endpoint->bEndpointAddress), | 963 | endpoint->bEndpointAddress), |
1019 | device->buffer, | 964 | gtco->buffer, |
1020 | REPORT_MAX_SIZE, | 965 | REPORT_MAX_SIZE, |
1021 | gtco_urb_callback, | 966 | gtco_urb_callback, |
1022 | device, | 967 | gtco, |
1023 | endpoint->bInterval); | 968 | endpoint->bInterval); |
1024 | 969 | ||
1025 | device->urbinfo->transfer_dma = device->buf_dma; | 970 | gtco->urbinfo->transfer_dma = gtco->buf_dma; |
1026 | device->urbinfo->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 971 | gtco->urbinfo->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1027 | |||
1028 | 972 | ||
1029 | /* Save device pointer in USB interface device */ | 973 | /* Save gtco pointer in USB interface gtco */ |
1030 | usb_set_intfdata(usbinterface, device); | 974 | usb_set_intfdata(usbinterface, gtco); |
1031 | 975 | ||
1032 | /* All done, now register the input device */ | 976 | /* All done, now register the input device */ |
1033 | input_register_device(inputdev); | 977 | error = input_register_device(input_dev); |
978 | if (error) | ||
979 | goto err_free_urb; | ||
1034 | 980 | ||
1035 | info( "gtco driver created usb: %s\n", path); | ||
1036 | return 0; | 981 | return 0; |
1037 | 982 | ||
983 | err_free_urb: | ||
984 | usb_free_urb(gtco->urbinfo); | ||
985 | err_free_buf: | ||
986 | usb_buffer_free(gtco->usbdev, REPORT_MAX_SIZE, | ||
987 | gtco->buffer, gtco->buf_dma); | ||
988 | err_free_devs: | ||
989 | kfree(report); | ||
990 | input_free_device(input_dev); | ||
991 | kfree(gtco); | ||
992 | return error; | ||
1038 | } | 993 | } |
1039 | 994 | ||
1040 | /* | 995 | /* |
@@ -1044,50 +999,46 @@ static int gtco_probe(struct usb_interface *usbinterface, | |||
1044 | */ | 999 | */ |
1045 | static void gtco_disconnect(struct usb_interface *interface) | 1000 | static void gtco_disconnect(struct usb_interface *interface) |
1046 | { | 1001 | { |
1047 | |||
1048 | /* Grab private device ptr */ | 1002 | /* Grab private device ptr */ |
1049 | struct gtco *device = usb_get_intfdata (interface); | 1003 | struct gtco *gtco = usb_get_intfdata(interface); |
1050 | struct input_dev *inputdev; | ||
1051 | |||
1052 | inputdev = device->inputdevice; | ||
1053 | 1004 | ||
1054 | /* Now reverse all the registration stuff */ | 1005 | /* Now reverse all the registration stuff */ |
1055 | if (device) { | 1006 | if (gtco) { |
1056 | input_unregister_device(inputdev); | 1007 | input_unregister_device(gtco->inputdevice); |
1057 | usb_kill_urb(device->urbinfo); | 1008 | usb_kill_urb(gtco->urbinfo); |
1058 | usb_free_urb(device->urbinfo); | 1009 | usb_free_urb(gtco->urbinfo); |
1059 | usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, | 1010 | usb_buffer_free(gtco->usbdev, REPORT_MAX_SIZE, |
1060 | device->buffer, device->buf_dma); | 1011 | gtco->buffer, gtco->buf_dma); |
1061 | kfree(device); | 1012 | kfree(gtco); |
1062 | } | 1013 | } |
1063 | 1014 | ||
1064 | info("gtco driver disconnected"); | 1015 | info("gtco driver disconnected"); |
1065 | } | 1016 | } |
1066 | 1017 | ||
1067 | |||
1068 | /* STANDARD MODULE LOAD ROUTINES */ | 1018 | /* STANDARD MODULE LOAD ROUTINES */ |
1069 | 1019 | ||
1070 | static struct usb_driver gtco_driverinfo_table = { | 1020 | static struct usb_driver gtco_driverinfo_table = { |
1071 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)) | 1021 | .name = "gtco", |
1072 | .owner = THIS_MODULE, | 1022 | .id_table = gtco_usbid_table, |
1073 | #endif | 1023 | .probe = gtco_probe, |
1074 | .name = "gtco", | 1024 | .disconnect = gtco_disconnect, |
1075 | .id_table = gtco_usbid_table, | ||
1076 | .probe = gtco_probe, | ||
1077 | .disconnect = gtco_disconnect, | ||
1078 | }; | 1025 | }; |
1026 | |||
1079 | /* | 1027 | /* |
1080 | * Register this module with the USB subsystem | 1028 | * Register this module with the USB subsystem |
1081 | */ | 1029 | */ |
1082 | static int __init gtco_init(void) | 1030 | static int __init gtco_init(void) |
1083 | { | 1031 | { |
1084 | int rc; | 1032 | int error; |
1085 | rc = usb_register(>co_driverinfo_table); | 1033 | |
1086 | if (rc) { | 1034 | error = usb_register(>co_driverinfo_table); |
1087 | err("usb_register() failed rc=0x%x", rc); | 1035 | if (error) { |
1036 | err("usb_register() failed rc=0x%x", error); | ||
1037 | return error; | ||
1088 | } | 1038 | } |
1089 | printk("GTCO usb driver version: %s",GTCO_VERSION); | 1039 | |
1090 | return rc; | 1040 | printk("GTCO usb driver version: %s", GTCO_VERSION); |
1041 | return 0; | ||
1091 | } | 1042 | } |
1092 | 1043 | ||
1093 | /* | 1044 | /* |
@@ -1098,7 +1049,7 @@ static void __exit gtco_exit(void) | |||
1098 | usb_deregister(>co_driverinfo_table); | 1049 | usb_deregister(>co_driverinfo_table); |
1099 | } | 1050 | } |
1100 | 1051 | ||
1101 | module_init (gtco_init); | 1052 | module_init(gtco_init); |
1102 | module_exit (gtco_exit); | 1053 | module_exit(gtco_exit); |
1103 | 1054 | ||
1104 | MODULE_LICENSE("GPL"); | 1055 | MODULE_LICENSE("GPL"); |