diff options
author | Frank Schaefer <fschaefer.oss@googlemail.com> | 2013-12-01 16:06:52 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2013-12-10 13:10:35 -0500 |
commit | f522260993822d82e2c480aa676aa4ca1230d235 (patch) | |
tree | 88e133f503df0b8c1ae8a9f2978b6738cfe98914 /drivers | |
parent | 07e4de3004ecedd67c72708d6c0fe69c51317f79 (diff) |
[media] em28xx: extend the support for device buttons
The current code supports only a single snapshot button assigned to
register 0x0c bit 5. But devices may be equipped with multiple buttons
with different functionalities and they can also be assigned to the
various GPI-ports.
Extend the em28xx-input code to handle multiple buttons assigned to different
GPI-ports / register addresses and bits.
Also make easier to extend the code with further button types.
Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/usb/em28xx/em28xx-cards.c | 20 | ||||
-rw-r--r-- | drivers/media/usb/em28xx/em28xx-input.c | 150 | ||||
-rw-r--r-- | drivers/media/usb/em28xx/em28xx.h | 27 |
3 files changed, 154 insertions, 43 deletions
diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c index a5196697627f..ebb112c17109 100644 --- a/drivers/media/usb/em28xx/em28xx-cards.c +++ b/drivers/media/usb/em28xx/em28xx-cards.c | |||
@@ -413,6 +413,20 @@ static struct em28xx_reg_seq pctv_520e[] = { | |||
413 | }; | 413 | }; |
414 | 414 | ||
415 | /* | 415 | /* |
416 | * Button definitions | ||
417 | */ | ||
418 | static struct em28xx_button std_snapshot_button[] = { | ||
419 | { | ||
420 | .role = EM28XX_BUTTON_SNAPSHOT, | ||
421 | .reg_r = EM28XX_R0C_USBSUSP, | ||
422 | .reg_clearing = EM28XX_R0C_USBSUSP, | ||
423 | .mask = EM28XX_R0C_USBSUSP_SNAPSHOT, | ||
424 | .inverted = 0, | ||
425 | }, | ||
426 | {-1, 0, 0, 0, 0}, | ||
427 | }; | ||
428 | |||
429 | /* | ||
416 | * Board definitions | 430 | * Board definitions |
417 | */ | 431 | */ |
418 | struct em28xx_board em28xx_boards[] = { | 432 | struct em28xx_board em28xx_boards[] = { |
@@ -1391,7 +1405,7 @@ struct em28xx_board em28xx_boards[] = { | |||
1391 | }, | 1405 | }, |
1392 | [EM2820_BOARD_PROLINK_PLAYTV_USB2] = { | 1406 | [EM2820_BOARD_PROLINK_PLAYTV_USB2] = { |
1393 | .name = "SIIG AVTuner-PVR / Pixelview Prolink PlayTV USB 2.0", | 1407 | .name = "SIIG AVTuner-PVR / Pixelview Prolink PlayTV USB 2.0", |
1394 | .has_snapshot_button = 1, | 1408 | .buttons = std_snapshot_button, |
1395 | .tda9887_conf = TDA9887_PRESENT, | 1409 | .tda9887_conf = TDA9887_PRESENT, |
1396 | .tuner_type = TUNER_YMEC_TVF_5533MF, | 1410 | .tuner_type = TUNER_YMEC_TVF_5533MF, |
1397 | .decoder = EM28XX_SAA711X, | 1411 | .decoder = EM28XX_SAA711X, |
@@ -1413,7 +1427,7 @@ struct em28xx_board em28xx_boards[] = { | |||
1413 | }, | 1427 | }, |
1414 | [EM2860_BOARD_SAA711X_REFERENCE_DESIGN] = { | 1428 | [EM2860_BOARD_SAA711X_REFERENCE_DESIGN] = { |
1415 | .name = "EM2860/SAA711X Reference Design", | 1429 | .name = "EM2860/SAA711X Reference Design", |
1416 | .has_snapshot_button = 1, | 1430 | .buttons = std_snapshot_button, |
1417 | .tuner_type = TUNER_ABSENT, | 1431 | .tuner_type = TUNER_ABSENT, |
1418 | .decoder = EM28XX_SAA711X, | 1432 | .decoder = EM28XX_SAA711X, |
1419 | .input = { { | 1433 | .input = { { |
@@ -2841,7 +2855,7 @@ static void request_module_async(struct work_struct *work) | |||
2841 | 2855 | ||
2842 | if (dev->board.has_dvb) | 2856 | if (dev->board.has_dvb) |
2843 | request_module("em28xx-dvb"); | 2857 | request_module("em28xx-dvb"); |
2844 | if (dev->board.has_snapshot_button || | 2858 | if (dev->board.buttons || |
2845 | ((dev->board.ir_codes || dev->board.has_ir_i2c) && !disable_ir)) | 2859 | ((dev->board.ir_codes || dev->board.has_ir_i2c) && !disable_ir)) |
2846 | request_module("em28xx-rc"); | 2860 | request_module("em28xx-rc"); |
2847 | #endif /* CONFIG_MODULES */ | 2861 | #endif /* CONFIG_MODULES */ |
diff --git a/drivers/media/usb/em28xx/em28xx-input.c b/drivers/media/usb/em28xx/em28xx-input.c index ea181e4b68c5..20c6a8ae1462 100644 --- a/drivers/media/usb/em28xx/em28xx-input.c +++ b/drivers/media/usb/em28xx/em28xx-input.c | |||
@@ -31,7 +31,7 @@ | |||
31 | #include "em28xx.h" | 31 | #include "em28xx.h" |
32 | 32 | ||
33 | #define EM28XX_SNAPSHOT_KEY KEY_CAMERA | 33 | #define EM28XX_SNAPSHOT_KEY KEY_CAMERA |
34 | #define EM28XX_SBUTTON_QUERY_INTERVAL 500 | 34 | #define EM28XX_BUTTONS_QUERY_INTERVAL 500 |
35 | 35 | ||
36 | static unsigned int ir_debug; | 36 | static unsigned int ir_debug; |
37 | module_param(ir_debug, int, 0644); | 37 | module_param(ir_debug, int, 0644); |
@@ -470,38 +470,69 @@ static int em28xx_probe_i2c_ir(struct em28xx *dev) | |||
470 | } | 470 | } |
471 | 471 | ||
472 | /********************************************************** | 472 | /********************************************************** |
473 | Handle Webcam snapshot button | 473 | Handle buttons |
474 | **********************************************************/ | 474 | **********************************************************/ |
475 | 475 | ||
476 | static void em28xx_query_sbutton(struct work_struct *work) | 476 | static void em28xx_query_buttons(struct work_struct *work) |
477 | { | 477 | { |
478 | /* Poll the register and see if the button is depressed */ | ||
479 | struct em28xx *dev = | 478 | struct em28xx *dev = |
480 | container_of(work, struct em28xx, sbutton_query_work.work); | 479 | container_of(work, struct em28xx, buttons_query_work.work); |
481 | int ret; | 480 | u8 i, j; |
482 | 481 | int regval; | |
483 | ret = em28xx_read_reg(dev, EM28XX_R0C_USBSUSP); | 482 | bool pressed; |
484 | 483 | ||
485 | if (ret & EM28XX_R0C_USBSUSP_SNAPSHOT) { | 484 | /* Poll and evaluate all addresses */ |
486 | u8 cleared; | 485 | for (i = 0; i < dev->num_button_polling_addresses; i++) { |
487 | /* Button is depressed, clear the register */ | 486 | /* Read value from register */ |
488 | cleared = ((u8) ret) & ~EM28XX_R0C_USBSUSP_SNAPSHOT; | 487 | regval = em28xx_read_reg(dev, dev->button_polling_addresses[i]); |
489 | em28xx_write_regs(dev, EM28XX_R0C_USBSUSP, &cleared, 1); | 488 | if (regval < 0) |
490 | 489 | continue; | |
491 | /* Not emulate the keypress */ | 490 | /* Check states of the buttons and act */ |
492 | input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY, | 491 | j = 0; |
493 | 1); | 492 | while (dev->board.buttons[j].role >= 0 && |
494 | /* Now unpress the key */ | 493 | dev->board.buttons[j].role < EM28XX_NUM_BUTTON_ROLES) { |
495 | input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY, | 494 | struct em28xx_button *button = &dev->board.buttons[j]; |
496 | 0); | 495 | /* Check if button uses the current address */ |
496 | if (button->reg_r != dev->button_polling_addresses[i]) { | ||
497 | j++; | ||
498 | continue; | ||
499 | } | ||
500 | /* Determine if button is pressed */ | ||
501 | pressed = regval & button->mask; | ||
502 | if (button->inverted) | ||
503 | pressed = !pressed; | ||
504 | /* Handle button state */ | ||
505 | if (!pressed) { | ||
506 | j++; | ||
507 | continue; | ||
508 | } | ||
509 | switch (button->role) { | ||
510 | case EM28XX_BUTTON_SNAPSHOT: | ||
511 | /* Emulate the keypress */ | ||
512 | input_report_key(dev->sbutton_input_dev, | ||
513 | EM28XX_SNAPSHOT_KEY, 1); | ||
514 | /* Unpress the key */ | ||
515 | input_report_key(dev->sbutton_input_dev, | ||
516 | EM28XX_SNAPSHOT_KEY, 0); | ||
517 | break; | ||
518 | default: | ||
519 | WARN_ONCE(1, "BUG: unhandled button role."); | ||
520 | } | ||
521 | /* Clear button state (if needed) */ | ||
522 | if (button->reg_clearing) | ||
523 | em28xx_write_reg(dev, button->reg_clearing, | ||
524 | (~regval & button->mask) | ||
525 | | (regval & ~button->mask)); | ||
526 | /* Next button */ | ||
527 | j++; | ||
528 | } | ||
497 | } | 529 | } |
498 | |||
499 | /* Schedule next poll */ | 530 | /* Schedule next poll */ |
500 | schedule_delayed_work(&dev->sbutton_query_work, | 531 | schedule_delayed_work(&dev->buttons_query_work, |
501 | msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL)); | 532 | msecs_to_jiffies(EM28XX_BUTTONS_QUERY_INTERVAL)); |
502 | } | 533 | } |
503 | 534 | ||
504 | static void em28xx_register_snapshot_button(struct em28xx *dev) | 535 | static int em28xx_register_snapshot_button(struct em28xx *dev) |
505 | { | 536 | { |
506 | struct input_dev *input_dev; | 537 | struct input_dev *input_dev; |
507 | int err; | 538 | int err; |
@@ -510,14 +541,13 @@ static void em28xx_register_snapshot_button(struct em28xx *dev) | |||
510 | input_dev = input_allocate_device(); | 541 | input_dev = input_allocate_device(); |
511 | if (!input_dev) { | 542 | if (!input_dev) { |
512 | em28xx_errdev("input_allocate_device failed\n"); | 543 | em28xx_errdev("input_allocate_device failed\n"); |
513 | return; | 544 | return -ENOMEM; |
514 | } | 545 | } |
515 | 546 | ||
516 | usb_make_path(dev->udev, dev->snapshot_button_path, | 547 | usb_make_path(dev->udev, dev->snapshot_button_path, |
517 | sizeof(dev->snapshot_button_path)); | 548 | sizeof(dev->snapshot_button_path)); |
518 | strlcat(dev->snapshot_button_path, "/sbutton", | 549 | strlcat(dev->snapshot_button_path, "/sbutton", |
519 | sizeof(dev->snapshot_button_path)); | 550 | sizeof(dev->snapshot_button_path)); |
520 | INIT_DELAYED_WORK(&dev->sbutton_query_work, em28xx_query_sbutton); | ||
521 | 551 | ||
522 | input_dev->name = "em28xx snapshot button"; | 552 | input_dev->name = "em28xx snapshot button"; |
523 | input_dev->phys = dev->snapshot_button_path; | 553 | input_dev->phys = dev->snapshot_button_path; |
@@ -535,25 +565,71 @@ static void em28xx_register_snapshot_button(struct em28xx *dev) | |||
535 | if (err) { | 565 | if (err) { |
536 | em28xx_errdev("input_register_device failed\n"); | 566 | em28xx_errdev("input_register_device failed\n"); |
537 | input_free_device(input_dev); | 567 | input_free_device(input_dev); |
538 | return; | 568 | return err; |
539 | } | 569 | } |
540 | 570 | ||
541 | dev->sbutton_input_dev = input_dev; | 571 | dev->sbutton_input_dev = input_dev; |
542 | schedule_delayed_work(&dev->sbutton_query_work, | 572 | return 0; |
543 | msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL)); | 573 | } |
544 | return; | ||
545 | 574 | ||
575 | static void em28xx_init_buttons(struct em28xx *dev) | ||
576 | { | ||
577 | u8 i = 0, j = 0; | ||
578 | bool addr_new = 0; | ||
579 | |||
580 | while (dev->board.buttons[i].role >= 0 && | ||
581 | dev->board.buttons[i].role < EM28XX_NUM_BUTTON_ROLES) { | ||
582 | struct em28xx_button *button = &dev->board.buttons[i]; | ||
583 | /* Check if polling address is already on the list */ | ||
584 | addr_new = 1; | ||
585 | for (j = 0; j < dev->num_button_polling_addresses; j++) { | ||
586 | if (button->reg_r == dev->button_polling_addresses[j]) { | ||
587 | addr_new = 0; | ||
588 | break; | ||
589 | } | ||
590 | } | ||
591 | /* Check if max. number of polling addresses is exceeded */ | ||
592 | if (addr_new && dev->num_button_polling_addresses | ||
593 | >= EM28XX_NUM_BUTTON_ADDRESSES_MAX) { | ||
594 | WARN_ONCE(1, "BUG: maximum number of button polling addresses exceeded."); | ||
595 | addr_new = 0; | ||
596 | } | ||
597 | /* Register input device (if needed) */ | ||
598 | if (button->role == EM28XX_BUTTON_SNAPSHOT) { | ||
599 | if (em28xx_register_snapshot_button(dev) < 0) | ||
600 | addr_new = 0; | ||
601 | } | ||
602 | /* Add read address to list of polling addresses */ | ||
603 | if (addr_new) { | ||
604 | unsigned int index = dev->num_button_polling_addresses; | ||
605 | dev->button_polling_addresses[index] = button->reg_r; | ||
606 | dev->num_button_polling_addresses++; | ||
607 | } | ||
608 | /* Next button */ | ||
609 | i++; | ||
610 | } | ||
611 | |||
612 | /* Start polling */ | ||
613 | if (dev->num_button_polling_addresses) { | ||
614 | INIT_DELAYED_WORK(&dev->buttons_query_work, | ||
615 | em28xx_query_buttons); | ||
616 | schedule_delayed_work(&dev->buttons_query_work, | ||
617 | msecs_to_jiffies(EM28XX_BUTTONS_QUERY_INTERVAL)); | ||
618 | } | ||
546 | } | 619 | } |
547 | 620 | ||
548 | static void em28xx_deregister_snapshot_button(struct em28xx *dev) | 621 | static void em28xx_shutdown_buttons(struct em28xx *dev) |
549 | { | 622 | { |
623 | /* Cancel polling */ | ||
624 | cancel_delayed_work_sync(&dev->buttons_query_work); | ||
625 | /* Clear polling addresses list */ | ||
626 | dev->num_button_polling_addresses = 0; | ||
627 | /* Deregister input devices */ | ||
550 | if (dev->sbutton_input_dev != NULL) { | 628 | if (dev->sbutton_input_dev != NULL) { |
551 | em28xx_info("Deregistering snapshot button\n"); | 629 | em28xx_info("Deregistering snapshot button\n"); |
552 | cancel_delayed_work_sync(&dev->sbutton_query_work); | ||
553 | input_unregister_device(dev->sbutton_input_dev); | 630 | input_unregister_device(dev->sbutton_input_dev); |
554 | dev->sbutton_input_dev = NULL; | 631 | dev->sbutton_input_dev = NULL; |
555 | } | 632 | } |
556 | return; | ||
557 | } | 633 | } |
558 | 634 | ||
559 | static int em28xx_ir_init(struct em28xx *dev) | 635 | static int em28xx_ir_init(struct em28xx *dev) |
@@ -564,8 +640,8 @@ static int em28xx_ir_init(struct em28xx *dev) | |||
564 | u64 rc_type; | 640 | u64 rc_type; |
565 | u16 i2c_rc_dev_addr = 0; | 641 | u16 i2c_rc_dev_addr = 0; |
566 | 642 | ||
567 | if (dev->board.has_snapshot_button) | 643 | if (dev->board.buttons) |
568 | em28xx_register_snapshot_button(dev); | 644 | em28xx_init_buttons(dev); |
569 | 645 | ||
570 | if (dev->board.has_ir_i2c) { | 646 | if (dev->board.has_ir_i2c) { |
571 | i2c_rc_dev_addr = em28xx_probe_i2c_ir(dev); | 647 | i2c_rc_dev_addr = em28xx_probe_i2c_ir(dev); |
@@ -688,7 +764,7 @@ static int em28xx_ir_fini(struct em28xx *dev) | |||
688 | { | 764 | { |
689 | struct em28xx_IR *ir = dev->ir; | 765 | struct em28xx_IR *ir = dev->ir; |
690 | 766 | ||
691 | em28xx_deregister_snapshot_button(dev); | 767 | em28xx_shutdown_buttons(dev); |
692 | 768 | ||
693 | /* skip detach on non attached boards */ | 769 | /* skip detach on non attached boards */ |
694 | if (!ir) | 770 | if (!ir) |
diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h index 8003c2f7bb96..e185d00e9044 100644 --- a/drivers/media/usb/em28xx/em28xx.h +++ b/drivers/media/usb/em28xx/em28xx.h | |||
@@ -181,6 +181,9 @@ | |||
181 | /* time in msecs to wait for i2c writes to finish */ | 181 | /* time in msecs to wait for i2c writes to finish */ |
182 | #define EM2800_I2C_XFER_TIMEOUT 20 | 182 | #define EM2800_I2C_XFER_TIMEOUT 20 |
183 | 183 | ||
184 | /* max. number of button state polling addresses */ | ||
185 | #define EM28XX_NUM_BUTTON_ADDRESSES_MAX 5 | ||
186 | |||
184 | enum em28xx_mode { | 187 | enum em28xx_mode { |
185 | EM28XX_SUSPEND, | 188 | EM28XX_SUSPEND, |
186 | EM28XX_ANALOG_MODE, | 189 | EM28XX_ANALOG_MODE, |
@@ -380,6 +383,19 @@ struct em28xx_led { | |||
380 | bool inverted; | 383 | bool inverted; |
381 | }; | 384 | }; |
382 | 385 | ||
386 | enum em28xx_button_role { | ||
387 | EM28XX_BUTTON_SNAPSHOT = 0, | ||
388 | EM28XX_NUM_BUTTON_ROLES, /* must be the last */ | ||
389 | }; | ||
390 | |||
391 | struct em28xx_button { | ||
392 | enum em28xx_button_role role; | ||
393 | u8 reg_r; | ||
394 | u8 reg_clearing; | ||
395 | u8 mask; | ||
396 | bool inverted; | ||
397 | }; | ||
398 | |||
383 | struct em28xx_board { | 399 | struct em28xx_board { |
384 | char *name; | 400 | char *name; |
385 | int vchannels; | 401 | int vchannels; |
@@ -401,7 +417,6 @@ struct em28xx_board { | |||
401 | unsigned int mts_firmware:1; | 417 | unsigned int mts_firmware:1; |
402 | unsigned int max_range_640_480:1; | 418 | unsigned int max_range_640_480:1; |
403 | unsigned int has_dvb:1; | 419 | unsigned int has_dvb:1; |
404 | unsigned int has_snapshot_button:1; | ||
405 | unsigned int is_webcam:1; | 420 | unsigned int is_webcam:1; |
406 | unsigned int valid:1; | 421 | unsigned int valid:1; |
407 | unsigned int has_ir_i2c:1; | 422 | unsigned int has_ir_i2c:1; |
@@ -419,6 +434,9 @@ struct em28xx_board { | |||
419 | 434 | ||
420 | /* LEDs that need to be controlled explicitly */ | 435 | /* LEDs that need to be controlled explicitly */ |
421 | struct em28xx_led *analog_capturing_led; | 436 | struct em28xx_led *analog_capturing_led; |
437 | |||
438 | /* Buttons */ | ||
439 | struct em28xx_button *buttons; | ||
422 | }; | 440 | }; |
423 | 441 | ||
424 | struct em28xx_eeprom { | 442 | struct em28xx_eeprom { |
@@ -648,10 +666,13 @@ struct em28xx { | |||
648 | 666 | ||
649 | enum em28xx_mode mode; | 667 | enum em28xx_mode mode; |
650 | 668 | ||
651 | /* Snapshot button */ | 669 | /* Button state polling */ |
670 | struct delayed_work buttons_query_work; | ||
671 | u8 button_polling_addresses[EM28XX_NUM_BUTTON_ADDRESSES_MAX]; | ||
672 | u8 num_button_polling_addresses; | ||
673 | /* Snapshot button input device */ | ||
652 | char snapshot_button_path[30]; /* path of the input dev */ | 674 | char snapshot_button_path[30]; /* path of the input dev */ |
653 | struct input_dev *sbutton_input_dev; | 675 | struct input_dev *sbutton_input_dev; |
654 | struct delayed_work sbutton_query_work; | ||
655 | 676 | ||
656 | struct em28xx_dvb *dvb; | 677 | struct em28xx_dvb *dvb; |
657 | }; | 678 | }; |