diff options
Diffstat (limited to 'drivers/usb/input/gtco.c')
-rw-r--r-- | drivers/usb/input/gtco.c | 634 |
1 files changed, 294 insertions, 340 deletions
diff --git a/drivers/usb/input/gtco.c b/drivers/usb/input/gtco.c index ae756e0afc99..b2ca10f2fe0e 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; |
@@ -225,46 +223,46 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, | |||
225 | __u32 oldval[TAG_GLOB_MAX]; | 223 | __u32 oldval[TAG_GLOB_MAX]; |
226 | 224 | ||
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,214 +337,226 @@ 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 | { |
533 | struct gtco *device; | 543 | struct gtco *device = input_get_drvdata(inputdev); |
534 | device = inputdev->private; | ||
535 | 544 | ||
536 | device->urbinfo->dev = device->usbdev; | 545 | device->urbinfo->dev = device->usbdev; |
537 | if (usb_submit_urb(device->urbinfo, GFP_KERNEL)) { | 546 | if (usb_submit_urb(device->urbinfo, GFP_KERNEL)) |
538 | return -EIO; | 547 | return -EIO; |
539 | } | 548 | |
540 | return 0; | 549 | return 0; |
541 | } | 550 | } |
542 | 551 | ||
543 | /** | 552 | /* |
544 | Called when closing the input device. This will unlink the URB | 553 | * Called when closing the input device. This will unlink the URB |
545 | */ | 554 | */ |
546 | static void gtco_input_close(struct input_dev *inputdev) | 555 | static void gtco_input_close(struct input_dev *inputdev) |
547 | { | 556 | { |
548 | struct gtco *device = inputdev->private; | 557 | struct gtco *device = input_get_drvdata(inputdev); |
549 | 558 | ||
550 | usb_kill_urb(device->urbinfo); | 559 | usb_kill_urb(device->urbinfo); |
551 | |||
552 | } | 560 | } |
553 | 561 | ||
554 | 562 | ||
@@ -560,19 +568,16 @@ static void gtco_input_close(struct input_dev *inputdev) | |||
560 | * placed in the struct gtco structure | 568 | * placed in the struct gtco structure |
561 | * | 569 | * |
562 | */ | 570 | */ |
563 | static void gtco_setup_caps(struct input_dev *inputdev) | 571 | static void gtco_setup_caps(struct input_dev *inputdev) |
564 | { | 572 | { |
565 | struct gtco *device = inputdev->private; | 573 | struct gtco *device = input_get_drvdata(inputdev); |
566 | |||
567 | 574 | ||
568 | /* Which events */ | 575 | /* Which events */ |
569 | inputdev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC); | 576 | inputdev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC); |
570 | 577 | ||
571 | |||
572 | /* Misc event menu block */ | 578 | /* Misc event menu block */ |
573 | inputdev->mscbit[0] = BIT(MSC_SCAN)|BIT(MSC_SERIAL)|BIT(MSC_RAW) ; | 579 | inputdev->mscbit[0] = BIT(MSC_SCAN)|BIT(MSC_SERIAL)|BIT(MSC_RAW) ; |
574 | 580 | ||
575 | |||
576 | /* Absolute values based on HID report info */ | 581 | /* Absolute values based on HID report info */ |
577 | input_set_abs_params(inputdev, ABS_X, device->min_X, device->max_X, | 582 | input_set_abs_params(inputdev, ABS_X, device->min_X, device->max_X, |
578 | 0, 0); | 583 | 0, 0); |
@@ -590,17 +595,12 @@ static void gtco_setup_caps(struct input_dev *inputdev) | |||
590 | input_set_abs_params(inputdev, ABS_PRESSURE, device->minpressure, | 595 | input_set_abs_params(inputdev, ABS_PRESSURE, device->minpressure, |
591 | device->maxpressure, 0, 0); | 596 | device->maxpressure, 0, 0); |
592 | 597 | ||
593 | |||
594 | /* Transducer */ | 598 | /* Transducer */ |
595 | input_set_abs_params(inputdev, ABS_MISC, 0,0xFF, 0, 0); | 599 | input_set_abs_params(inputdev, ABS_MISC, 0, 0xFF, 0, 0); |
596 | |||
597 | } | 600 | } |
598 | 601 | ||
599 | |||
600 | |||
601 | /* USB Routines */ | 602 | /* USB Routines */ |
602 | 603 | ||
603 | |||
604 | /* | 604 | /* |
605 | * URB callback routine. Called when we get IRQ reports from the | 605 | * URB callback routine. Called when we get IRQ reports from the |
606 | * digitizer. | 606 | * digitizer. |
@@ -610,9 +610,7 @@ static void gtco_setup_caps(struct input_dev *inputdev) | |||
610 | */ | 610 | */ |
611 | static void gtco_urb_callback(struct urb *urbinfo) | 611 | static void gtco_urb_callback(struct urb *urbinfo) |
612 | { | 612 | { |
613 | 613 | struct gtco *device = urbinfo->context; | |
614 | |||
615 | struct gtco *device = urbinfo->context; | ||
616 | struct input_dev *inputdev; | 614 | struct input_dev *inputdev; |
617 | int rc; | 615 | int rc; |
618 | u32 val = 0; | 616 | u32 val = 0; |
@@ -621,19 +619,20 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
621 | 619 | ||
622 | inputdev = device->inputdevice; | 620 | inputdev = device->inputdevice; |
623 | 621 | ||
624 | |||
625 | /* Was callback OK? */ | 622 | /* Was callback OK? */ |
626 | if ((urbinfo->status == -ECONNRESET ) || | 623 | if (urbinfo->status == -ECONNRESET || |
627 | (urbinfo->status == -ENOENT ) || | 624 | urbinfo->status == -ENOENT || |
628 | (urbinfo->status == -ESHUTDOWN )){ | 625 | urbinfo->status == -ESHUTDOWN) { |
629 | 626 | ||
630 | /* Shutdown is occurring. Return and don't queue up any more */ | 627 | /* Shutdown is occurring. Return and don't queue up any more */ |
631 | return; | 628 | return; |
632 | } | 629 | } |
633 | 630 | ||
634 | if (urbinfo->status != 0 ) { | 631 | if (urbinfo->status != 0) { |
635 | /* Some unknown error. Hopefully temporary. Just go and */ | 632 | /* |
636 | /* requeue an URB */ | 633 | * Some unknown error. Hopefully temporary. Just go and |
634 | * requeue an URB | ||
635 | */ | ||
637 | goto resubmit; | 636 | goto resubmit; |
638 | } | 637 | } |
639 | 638 | ||
@@ -642,10 +641,9 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
642 | */ | 641 | */ |
643 | 642 | ||
644 | /* PID dependent when we interpret the report */ | 643 | /* PID dependent when we interpret the report */ |
645 | if ((inputdev->id.product == PID_1000 )|| | 644 | if (inputdev->id.product == PID_1000 || |
646 | (inputdev->id.product == PID_1001 )|| | 645 | inputdev->id.product == PID_1001 || |
647 | (inputdev->id.product == PID_1002 )) | 646 | inputdev->id.product == PID_1002) { |
648 | { | ||
649 | 647 | ||
650 | /* | 648 | /* |
651 | * Switch on the report ID | 649 | * Switch on the report ID |
@@ -653,10 +651,10 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
653 | * the report number. We can just fall through the case | 651 | * the report number. We can just fall through the case |
654 | * statements if we start with the highest number report | 652 | * statements if we start with the highest number report |
655 | */ | 653 | */ |
656 | switch(device->buffer[0]){ | 654 | switch (device->buffer[0]) { |
657 | case 5: | 655 | case 5: |
658 | /* Pressure is 9 bits */ | 656 | /* Pressure is 9 bits */ |
659 | val = ((u16)(device->buffer[8]) << 1); | 657 | val = ((u16)(device->buffer[8]) << 1); |
660 | val |= (u16)(device->buffer[7] >> 7); | 658 | val |= (u16)(device->buffer[7] >> 7); |
661 | input_report_abs(inputdev, ABS_PRESSURE, | 659 | input_report_abs(inputdev, ABS_PRESSURE, |
662 | device->buffer[8]); | 660 | device->buffer[8]); |
@@ -664,7 +662,6 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
664 | /* Mask out the Y tilt value used for pressure */ | 662 | /* Mask out the Y tilt value used for pressure */ |
665 | device->buffer[7] = (u8)((device->buffer[7]) & 0x7F); | 663 | device->buffer[7] = (u8)((device->buffer[7]) & 0x7F); |
666 | 664 | ||
667 | |||
668 | /* Fall thru */ | 665 | /* Fall thru */ |
669 | case 4: | 666 | case 4: |
670 | /* Tilt */ | 667 | /* Tilt */ |
@@ -684,11 +681,10 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
684 | input_report_abs(inputdev, ABS_TILT_Y, (s32)valsigned); | 681 | input_report_abs(inputdev, ABS_TILT_Y, (s32)valsigned); |
685 | 682 | ||
686 | /* Fall thru */ | 683 | /* Fall thru */ |
687 | |||
688 | case 2: | 684 | case 2: |
689 | case 3: | 685 | case 3: |
690 | /* Convert buttons, only 5 bits possible */ | 686 | /* Convert buttons, only 5 bits possible */ |
691 | val = (device->buffer[5])&MASK_BUTTON; | 687 | val = (device->buffer[5]) & MASK_BUTTON; |
692 | 688 | ||
693 | /* We don't apply any meaning to the bitmask, | 689 | /* We don't apply any meaning to the bitmask, |
694 | just report */ | 690 | just report */ |
@@ -696,132 +692,109 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
696 | 692 | ||
697 | /* Fall thru */ | 693 | /* Fall thru */ |
698 | case 1: | 694 | case 1: |
699 | |||
700 | /* All reports have X and Y coords in the same place */ | 695 | /* All reports have X and Y coords in the same place */ |
701 | val = le16_to_cpu(get_unaligned((__le16 *) &(device->buffer[1]))); | 696 | val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[1])); |
702 | input_report_abs(inputdev, ABS_X, val); | 697 | input_report_abs(inputdev, ABS_X, val); |
703 | 698 | ||
704 | val = le16_to_cpu(get_unaligned((__le16 *) &(device->buffer[3]))); | 699 | val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[3])); |
705 | input_report_abs(inputdev, ABS_Y, val); | 700 | input_report_abs(inputdev, ABS_Y, val); |
706 | 701 | ||
707 | |||
708 | /* Ditto for proximity bit */ | 702 | /* Ditto for proximity bit */ |
709 | if (device->buffer[5]& MASK_INRANGE){ | 703 | 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); | 704 | input_report_abs(inputdev, ABS_DISTANCE, val); |
715 | 705 | ||
716 | |||
717 | /* Report 1 is an exception to how we handle buttons */ | 706 | /* Report 1 is an exception to how we handle buttons */ |
718 | /* Buttons are an index, not a bitmask */ | 707 | /* Buttons are an index, not a bitmask */ |
719 | if (device->buffer[0] == 1){ | 708 | if (device->buffer[0] == 1) { |
720 | 709 | ||
721 | /* Convert buttons, 5 bit index */ | 710 | /* |
722 | /* Report value of index set as one, | 711 | * Convert buttons, 5 bit index |
723 | the rest as 0 */ | 712 | * Report value of index set as one, |
724 | val = device->buffer[5]& MASK_BUTTON; | 713 | * the rest as 0 |
714 | */ | ||
715 | val = device->buffer[5] & MASK_BUTTON; | ||
725 | dbg("======>>>>>>REPORT 1: val 0x%X(%d)", | 716 | dbg("======>>>>>>REPORT 1: val 0x%X(%d)", |
726 | val,val); | 717 | val, val); |
727 | 718 | ||
728 | /* | 719 | /* |
729 | * We don't apply any meaning to the button | 720 | * We don't apply any meaning to the button |
730 | * index, just report it | 721 | * index, just report it |
731 | */ | 722 | */ |
732 | input_event(inputdev, EV_MSC, MSC_SERIAL, val); | 723 | input_event(inputdev, EV_MSC, MSC_SERIAL, val); |
733 | |||
734 | |||
735 | } | 724 | } |
736 | |||
737 | break; | 725 | break; |
726 | |||
738 | case 7: | 727 | case 7: |
739 | /* Menu blocks */ | 728 | /* Menu blocks */ |
740 | input_event(inputdev, EV_MSC, MSC_SCAN, | 729 | input_event(inputdev, EV_MSC, MSC_SCAN, |
741 | device->buffer[1]); | 730 | device->buffer[1]); |
742 | |||
743 | |||
744 | break; | 731 | break; |
745 | |||
746 | } | 732 | } |
747 | |||
748 | |||
749 | } | 733 | } |
734 | |||
750 | /* Other pid class */ | 735 | /* Other pid class */ |
751 | if ((inputdev->id.product == PID_400 )|| | 736 | if (inputdev->id.product == PID_400 || |
752 | (inputdev->id.product == PID_401 )) | 737 | inputdev->id.product == PID_401) { |
753 | { | ||
754 | 738 | ||
755 | /* Report 2 */ | 739 | /* Report 2 */ |
756 | if (device->buffer[0] == 2){ | 740 | if (device->buffer[0] == 2) { |
757 | /* Menu blocks */ | 741 | /* Menu blocks */ |
758 | input_event(inputdev, EV_MSC, MSC_SCAN, | 742 | input_event(inputdev, EV_MSC, MSC_SCAN, device->buffer[1]); |
759 | device->buffer[1]); | ||
760 | } | 743 | } |
761 | 744 | ||
762 | /* Report 1 */ | 745 | /* Report 1 */ |
763 | if (device->buffer[0] == 1){ | 746 | if (device->buffer[0] == 1) { |
764 | char buttonbyte; | 747 | char buttonbyte; |
765 | 748 | ||
766 | |||
767 | /* IF X max > 64K, we still a bit from the y report */ | 749 | /* IF X max > 64K, we still a bit from the y report */ |
768 | if (device->max_X > 0x10000){ | 750 | if (device->max_X > 0x10000) { |
769 | 751 | ||
770 | val = (u16)(((u16)(device->buffer[2]<<8))|((u8)(device->buffer[1]))); | 752 | val = (u16)(((u16)(device->buffer[2] << 8)) | (u8)device->buffer[1]); |
771 | val |= (u32)(((u8)device->buffer[3]&0x1)<< 16); | 753 | val |= (u32)(((u8)device->buffer[3] & 0x1) << 16); |
772 | 754 | ||
773 | input_report_abs(inputdev, ABS_X, val); | 755 | input_report_abs(inputdev, ABS_X, val); |
774 | 756 | ||
775 | le_buffer[0] = (u8)((u8)(device->buffer[3])>>1); | 757 | le_buffer[0] = (u8)((u8)(device->buffer[3]) >> 1); |
776 | le_buffer[0] |= (u8)((device->buffer[3]&0x1)<<7); | 758 | 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 | 759 | ||
781 | val = le16_to_cpu(get_unaligned((__le16 *)(le_buffer))); | 760 | le_buffer[1] = (u8)(device->buffer[4] >> 1); |
761 | le_buffer[1] |= (u8)((device->buffer[5] & 0x1) << 7); | ||
782 | 762 | ||
763 | val = le16_to_cpu(get_unaligned((__le16 *)le_buffer)); | ||
783 | input_report_abs(inputdev, ABS_Y, val); | 764 | input_report_abs(inputdev, ABS_Y, val); |
784 | 765 | ||
785 | |||
786 | /* | 766 | /* |
787 | * Shift the button byte right by one to | 767 | * Shift the button byte right by one to |
788 | * make it look like the standard report | 768 | * make it look like the standard report |
789 | */ | 769 | */ |
790 | buttonbyte = (device->buffer[5])>>1; | 770 | buttonbyte = device->buffer[5] >> 1; |
791 | }else{ | 771 | } else { |
792 | 772 | ||
793 | val = le16_to_cpu(get_unaligned((__le16 *) (&(device->buffer[1])))); | 773 | val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[1])); |
794 | input_report_abs(inputdev, ABS_X, val); | 774 | input_report_abs(inputdev, ABS_X, val); |
795 | 775 | ||
796 | val = le16_to_cpu(get_unaligned((__le16 *) (&(device->buffer[3])))); | 776 | val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[3])); |
797 | input_report_abs(inputdev, ABS_Y, val); | 777 | input_report_abs(inputdev, ABS_Y, val); |
798 | 778 | ||
799 | buttonbyte = device->buffer[5]; | 779 | buttonbyte = device->buffer[5]; |
800 | |||
801 | } | 780 | } |
802 | 781 | ||
803 | |||
804 | /* BUTTONS and PROXIMITY */ | 782 | /* BUTTONS and PROXIMITY */ |
805 | if (buttonbyte& MASK_INRANGE){ | 783 | val = buttonbyte & MASK_INRANGE ? 1 : 0; |
806 | val = 1; | ||
807 | }else{ | ||
808 | val=0; | ||
809 | } | ||
810 | input_report_abs(inputdev, ABS_DISTANCE, val); | 784 | input_report_abs(inputdev, ABS_DISTANCE, val); |
811 | 785 | ||
812 | /* Convert buttons, only 4 bits possible */ | 786 | /* Convert buttons, only 4 bits possible */ |
813 | val = buttonbyte&0x0F; | 787 | val = buttonbyte & 0x0F; |
814 | #ifdef USE_BUTTONS | 788 | #ifdef USE_BUTTONS |
815 | for ( i=0;i<5;i++){ | 789 | for (i = 0; i < 5; i++) |
816 | input_report_key(inputdev, BTN_DIGI+i,val&(1<<i)); | 790 | input_report_key(inputdev, BTN_DIGI + i, val & (1 << i)); |
817 | } | ||
818 | #else | 791 | #else |
819 | /* We don't apply any meaning to the bitmask, just report */ | 792 | /* We don't apply any meaning to the bitmask, just report */ |
820 | input_event(inputdev, EV_MSC, MSC_SERIAL, val); | 793 | input_event(inputdev, EV_MSC, MSC_SERIAL, val); |
821 | #endif | 794 | #endif |
795 | |||
822 | /* TRANSDUCER */ | 796 | /* TRANSDUCER */ |
823 | input_report_abs(inputdev, ABS_MISC, device->buffer[6]); | 797 | input_report_abs(inputdev, ABS_MISC, device->buffer[6]); |
824 | |||
825 | } | 798 | } |
826 | } | 799 | } |
827 | 800 | ||
@@ -833,10 +806,8 @@ static void gtco_urb_callback(struct urb *urbinfo) | |||
833 | 806 | ||
834 | resubmit: | 807 | resubmit: |
835 | rc = usb_submit_urb(urbinfo, GFP_ATOMIC); | 808 | rc = usb_submit_urb(urbinfo, GFP_ATOMIC); |
836 | if (rc != 0) { | 809 | if (rc != 0) |
837 | err("usb_submit_urb failed rc=0x%x",rc); | 810 | err("usb_submit_urb failed rc=0x%x", rc); |
838 | } | ||
839 | |||
840 | } | 811 | } |
841 | 812 | ||
842 | /* | 813 | /* |
@@ -854,58 +825,46 @@ static int gtco_probe(struct usb_interface *usbinterface, | |||
854 | const struct usb_device_id *id) | 825 | const struct usb_device_id *id) |
855 | { | 826 | { |
856 | 827 | ||
857 | struct gtco *device = NULL; | 828 | struct gtco *gtco; |
858 | char path[PATHLENGTH]; | 829 | struct input_dev *input_dev; |
859 | struct input_dev *inputdev; | ||
860 | struct hid_descriptor *hid_desc; | 830 | struct hid_descriptor *hid_desc; |
861 | char *report; | 831 | char *report = NULL; |
862 | int result=0, retry; | 832 | int result = 0, retry; |
833 | int error; | ||
863 | struct usb_endpoint_descriptor *endpoint; | 834 | struct usb_endpoint_descriptor *endpoint; |
864 | 835 | ||
865 | /* Allocate memory for device structure */ | 836 | /* Allocate memory for device structure */ |
866 | device = kzalloc(sizeof(struct gtco), GFP_KERNEL); | 837 | gtco = kzalloc(sizeof(struct gtco), GFP_KERNEL); |
867 | if (device == NULL) { | 838 | input_dev = input_allocate_device(); |
839 | if (!gtco || !input_dev) { | ||
868 | err("No more memory"); | 840 | err("No more memory"); |
869 | return -ENOMEM; | 841 | error = -ENOMEM; |
842 | goto err_free_devs; | ||
870 | } | 843 | } |
871 | 844 | ||
872 | 845 | /* Set pointer to the input device */ | |
873 | device->inputdevice = input_allocate_device(); | 846 | 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 | 847 | ||
883 | /* Save interface information */ | 848 | /* Save interface information */ |
884 | device->usbdev = usb_get_dev(interface_to_usbdev(usbinterface)); | 849 | gtco->usbdev = usb_get_dev(interface_to_usbdev(usbinterface)); |
885 | |||
886 | 850 | ||
887 | /* Allocate some data for incoming reports */ | 851 | /* Allocate some data for incoming reports */ |
888 | device->buffer = usb_buffer_alloc(device->usbdev, REPORT_MAX_SIZE, | 852 | gtco->buffer = usb_buffer_alloc(gtco->usbdev, REPORT_MAX_SIZE, |
889 | GFP_KERNEL, &(device->buf_dma)); | 853 | GFP_KERNEL, >co->buf_dma); |
890 | if (!device->buffer){ | 854 | if (!gtco->buffer) { |
891 | input_free_device(device->inputdevice); | 855 | err("No more memory for us buffers"); |
892 | kfree(device); | 856 | error = -ENOMEM; |
893 | err("No more memory"); | 857 | goto err_free_devs; |
894 | return -ENOMEM; | ||
895 | } | 858 | } |
896 | 859 | ||
897 | /* Allocate URB for reports */ | 860 | /* Allocate URB for reports */ |
898 | device->urbinfo = usb_alloc_urb(0, GFP_KERNEL); | 861 | gtco->urbinfo = usb_alloc_urb(0, GFP_KERNEL); |
899 | if (!device->urbinfo) { | 862 | if (!gtco->urbinfo) { |
900 | usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, | 863 | 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; | 864 | return -ENOMEM; |
865 | goto err_free_buf; | ||
906 | } | 866 | } |
907 | 867 | ||
908 | |||
909 | /* | 868 | /* |
910 | * The endpoint is always altsetting 0, we know this since we know | 869 | * The endpoint is always altsetting 0, we know this since we know |
911 | * this device only has one interrupt endpoint | 870 | * this device only has one interrupt endpoint |
@@ -913,51 +872,43 @@ static int gtco_probe(struct usb_interface *usbinterface, | |||
913 | endpoint = &usbinterface->altsetting[0].endpoint[0].desc; | 872 | endpoint = &usbinterface->altsetting[0].endpoint[0].desc; |
914 | 873 | ||
915 | /* Some debug */ | 874 | /* Some debug */ |
916 | dbg("gtco # interfaces: %d",usbinterface->num_altsetting); | 875 | dbg("gtco # interfaces: %d", usbinterface->num_altsetting); |
917 | dbg("num endpoints: %d",usbinterface->cur_altsetting->desc.bNumEndpoints); | 876 | dbg("num endpoints: %d", usbinterface->cur_altsetting->desc.bNumEndpoints); |
918 | dbg("interface class: %d",usbinterface->cur_altsetting->desc.bInterfaceClass); | 877 | dbg("interface class: %d", usbinterface->cur_altsetting->desc.bInterfaceClass); |
919 | dbg("endpoint: attribute:0x%x type:0x%x",endpoint->bmAttributes,endpoint->bDescriptorType); | 878 | dbg("endpoint: attribute:0x%x type:0x%x", endpoint->bmAttributes, endpoint->bDescriptorType); |
920 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) | 879 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) |
921 | dbg("endpoint: we have interrupt endpoint\n"); | 880 | dbg("endpoint: we have interrupt endpoint\n"); |
922 | 881 | ||
923 | dbg("endpoint extra len:%d ",usbinterface->altsetting[0].extralen); | 882 | dbg("endpoint extra len:%d ", usbinterface->altsetting[0].extralen); |
924 | |||
925 | |||
926 | 883 | ||
927 | /* | 884 | /* |
928 | * Find the HID descriptor so we can find out the size of the | 885 | * Find the HID descriptor so we can find out the size of the |
929 | * HID report descriptor | 886 | * HID report descriptor |
930 | */ | 887 | */ |
931 | if (usb_get_extra_descriptor(usbinterface->cur_altsetting, | 888 | if (usb_get_extra_descriptor(usbinterface->cur_altsetting, |
932 | HID_DEVICE_TYPE,&hid_desc) != 0){ | 889 | HID_DEVICE_TYPE, &hid_desc) != 0){ |
933 | err("Can't retrieve exta USB descriptor to get hid report descriptor length"); | 890 | err("Can't retrieve exta USB descriptor to get hid report descriptor length"); |
934 | usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, | 891 | error = -EIO; |
935 | device->buffer, device->buf_dma); | 892 | goto err_free_urb; |
936 | input_free_device(device->inputdevice); | ||
937 | kfree(device); | ||
938 | return -EIO; | ||
939 | } | 893 | } |
940 | 894 | ||
941 | dbg("Extra descriptor success: type:%d len:%d", | 895 | dbg("Extra descriptor success: type:%d len:%d", |
942 | hid_desc->bDescriptorType, hid_desc->wDescriptorLength); | 896 | hid_desc->bDescriptorType, hid_desc->wDescriptorLength); |
943 | 897 | ||
944 | if (!(report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL))) { | 898 | report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL); |
945 | usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, | 899 | if (!report) { |
946 | device->buffer, device->buf_dma); | 900 | err("No more memory for report"); |
947 | 901 | error = -ENOMEM; | |
948 | input_free_device(device->inputdevice); | 902 | goto err_free_urb; |
949 | kfree(device); | ||
950 | err("No more memory"); | ||
951 | return -ENOMEM; | ||
952 | } | 903 | } |
953 | 904 | ||
954 | /* Couple of tries to get reply */ | 905 | /* Couple of tries to get reply */ |
955 | for (retry=0;retry<3;retry++) { | 906 | for (retry = 0; retry < 3; retry++) { |
956 | result = usb_control_msg(device->usbdev, | 907 | result = usb_control_msg(gtco->usbdev, |
957 | usb_rcvctrlpipe(device->usbdev, 0), | 908 | usb_rcvctrlpipe(gtco->usbdev, 0), |
958 | USB_REQ_GET_DESCRIPTOR, | 909 | USB_REQ_GET_DESCRIPTOR, |
959 | USB_RECIP_INTERFACE | USB_DIR_IN, | 910 | USB_RECIP_INTERFACE | USB_DIR_IN, |
960 | (REPORT_DEVICE_TYPE << 8), | 911 | REPORT_DEVICE_TYPE << 8, |
961 | 0, /* interface */ | 912 | 0, /* interface */ |
962 | report, | 913 | report, |
963 | hid_desc->wDescriptorLength, | 914 | hid_desc->wDescriptorLength, |
@@ -969,72 +920,76 @@ static int gtco_probe(struct usb_interface *usbinterface, | |||
969 | 920 | ||
970 | /* If we didn't get the report, fail */ | 921 | /* If we didn't get the report, fail */ |
971 | dbg("usb_control_msg result: :%d", result); | 922 | dbg("usb_control_msg result: :%d", result); |
972 | if (result != hid_desc->wDescriptorLength){ | 923 | 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", | 924 | err("Failed to get HID Report Descriptor of size: %d", |
979 | hid_desc->wDescriptorLength); | 925 | hid_desc->wDescriptorLength); |
980 | return -EIO; | 926 | error = -EIO; |
927 | goto err_free_urb; | ||
981 | } | 928 | } |
982 | 929 | ||
983 | |||
984 | /* Now we parse the report */ | 930 | /* Now we parse the report */ |
985 | parse_hid_report_descriptor(device,report,result); | 931 | parse_hid_report_descriptor(gtco, report, result); |
986 | 932 | ||
987 | /* Now we delete it */ | 933 | /* Now we delete it */ |
988 | kfree(report); | 934 | kfree(report); |
989 | 935 | ||
990 | /* Create a device file node */ | 936 | /* Create a device file node */ |
991 | usb_make_path(device->usbdev, path, PATHLENGTH); | 937 | usb_make_path(gtco->usbdev, gtco->usbpath, sizeof(gtco->usbpath)); |
992 | sprintf(device->usbpath, "%s/input0", path); | 938 | strlcat(gtco->usbpath, "/input0", sizeof(gtco->usbpath)); |
993 | |||
994 | 939 | ||
995 | /* Set Input device functions */ | 940 | /* Set Input device functions */ |
996 | inputdev->open = gtco_input_open; | 941 | input_dev->open = gtco_input_open; |
997 | inputdev->close = gtco_input_close; | 942 | input_dev->close = gtco_input_close; |
998 | 943 | ||
999 | /* Set input device information */ | 944 | /* Set input device information */ |
1000 | inputdev->name = "GTCO_CalComp"; | 945 | input_dev->name = "GTCO_CalComp"; |
1001 | inputdev->phys = device->usbpath; | 946 | input_dev->phys = gtco->usbpath; |
1002 | inputdev->private = device; | ||
1003 | 947 | ||
948 | input_set_drvdata(input_dev, gtco); | ||
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->dev.parent = &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,47 +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 | 1004 | ||
1051 | /* Now reverse all the registration stuff */ | 1005 | /* Now reverse all the registration stuff */ |
1052 | if (device) { | 1006 | if (gtco) { |
1053 | input_unregister_device(device->inputdevice); | 1007 | input_unregister_device(gtco->inputdevice); |
1054 | usb_kill_urb(device->urbinfo); | 1008 | usb_kill_urb(gtco->urbinfo); |
1055 | usb_free_urb(device->urbinfo); | 1009 | usb_free_urb(gtco->urbinfo); |
1056 | usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, | 1010 | usb_buffer_free(gtco->usbdev, REPORT_MAX_SIZE, |
1057 | device->buffer, device->buf_dma); | 1011 | gtco->buffer, gtco->buf_dma); |
1058 | kfree(device); | 1012 | kfree(gtco); |
1059 | } | 1013 | } |
1060 | 1014 | ||
1061 | info("gtco driver disconnected"); | 1015 | info("gtco driver disconnected"); |
1062 | } | 1016 | } |
1063 | 1017 | ||
1064 | |||
1065 | /* STANDARD MODULE LOAD ROUTINES */ | 1018 | /* STANDARD MODULE LOAD ROUTINES */ |
1066 | 1019 | ||
1067 | static struct usb_driver gtco_driverinfo_table = { | 1020 | static struct usb_driver gtco_driverinfo_table = { |
1068 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)) | 1021 | .name = "gtco", |
1069 | .owner = THIS_MODULE, | 1022 | .id_table = gtco_usbid_table, |
1070 | #endif | 1023 | .probe = gtco_probe, |
1071 | .name = "gtco", | 1024 | .disconnect = gtco_disconnect, |
1072 | .id_table = gtco_usbid_table, | ||
1073 | .probe = gtco_probe, | ||
1074 | .disconnect = gtco_disconnect, | ||
1075 | }; | 1025 | }; |
1026 | |||
1076 | /* | 1027 | /* |
1077 | * Register this module with the USB subsystem | 1028 | * Register this module with the USB subsystem |
1078 | */ | 1029 | */ |
1079 | static int __init gtco_init(void) | 1030 | static int __init gtco_init(void) |
1080 | { | 1031 | { |
1081 | int rc; | 1032 | int error; |
1082 | rc = usb_register(>co_driverinfo_table); | 1033 | |
1083 | if (rc) { | 1034 | error = usb_register(>co_driverinfo_table); |
1084 | err("usb_register() failed rc=0x%x", rc); | 1035 | if (error) { |
1036 | err("usb_register() failed rc=0x%x", error); | ||
1037 | return error; | ||
1085 | } | 1038 | } |
1086 | printk("GTCO usb driver version: %s",GTCO_VERSION); | 1039 | |
1087 | return rc; | 1040 | printk("GTCO usb driver version: %s", GTCO_VERSION); |
1041 | return 0; | ||
1088 | } | 1042 | } |
1089 | 1043 | ||
1090 | /* | 1044 | /* |
@@ -1095,7 +1049,7 @@ static void __exit gtco_exit(void) | |||
1095 | usb_deregister(>co_driverinfo_table); | 1049 | usb_deregister(>co_driverinfo_table); |
1096 | } | 1050 | } |
1097 | 1051 | ||
1098 | module_init (gtco_init); | 1052 | module_init(gtco_init); |
1099 | module_exit (gtco_exit); | 1053 | module_exit(gtco_exit); |
1100 | 1054 | ||
1101 | MODULE_LICENSE("GPL"); | 1055 | MODULE_LICENSE("GPL"); |