aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/saa7134/saa7134-input.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2010-11-13 14:19:54 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-12-29 05:16:45 -0500
commit6c7e653ff668d939174aa7023736f4a40fd2be08 (patch)
treec8d3a5ffd9b2d6adfaa3ce743ee0d910335b93ac /drivers/media/video/saa7134/saa7134-input.c
parent70de39183a8b5ba0a0cd884ff46c1d81dbe939db (diff)
[media] saa7134: Remove legacy IR decoding logic inside the module
The only IR left still using the old raw decoders on saa7134 is ENCORE FM 5.3. As it is now using the standard rc-core raw decoders, lots of old code can be removed from saa7134. Acked-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/saa7134/saa7134-input.c')
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c219
1 files changed, 2 insertions, 217 deletions
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index 4878f4653faf..72562b8cf3be 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -54,11 +54,8 @@ MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
54#define i2cdprintk(fmt, arg...) if (ir_debug) \ 54#define i2cdprintk(fmt, arg...) if (ir_debug) \
55 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg) 55 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg)
56 56
57/* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */ 57/* Helper function for raw decoding at GPIO16 or GPIO18 */
58static int saa7134_rc5_irq(struct saa7134_dev *dev);
59static int saa7134_nec_irq(struct saa7134_dev *dev);
60static int saa7134_raw_decode_irq(struct saa7134_dev *dev); 58static int saa7134_raw_decode_irq(struct saa7134_dev *dev);
61static void nec_task(unsigned long data);
62 59
63/* -------------------- GPIO generic keycode builder -------------------- */ 60/* -------------------- GPIO generic keycode builder -------------------- */
64 61
@@ -397,12 +394,8 @@ void saa7134_input_irq(struct saa7134_dev *dev)
397 if (!ir->running) 394 if (!ir->running)
398 return; 395 return;
399 396
400 if (ir->nec_gpio) { 397 if (!ir->polling && !ir->raw_decode) {
401 saa7134_nec_irq(dev);
402 } else if (!ir->polling && !ir->rc5_gpio && !ir->raw_decode) {
403 build_key(dev); 398 build_key(dev);
404 } else if (ir->rc5_gpio) {
405 saa7134_rc5_irq(dev);
406 } else if (ir->raw_decode) { 399 } else if (ir->raw_decode) {
407 saa7134_raw_decode_irq(dev); 400 saa7134_raw_decode_irq(dev);
408 } 401 }
@@ -448,17 +441,6 @@ static int __saa7134_ir_start(void *priv)
448 (unsigned long)dev); 441 (unsigned long)dev);
449 ir->timer.expires = jiffies + HZ; 442 ir->timer.expires = jiffies + HZ;
450 add_timer(&ir->timer); 443 add_timer(&ir->timer);
451 } else if (ir->rc5_gpio) {
452 /* set timer_end for code completion */
453 init_timer(&ir->timer_end);
454 ir->timer_end.function = ir_rc5_timer_end;
455 ir->timer_end.data = (unsigned long)ir;
456 ir->shift_by = 2;
457 ir->start = 0x2;
458 ir->addr = 0x17;
459 ir->rc5_remote_gap = ir_rc5_remote_gap;
460 } else if (ir->nec_gpio) {
461 tasklet_init(&ir->tlet, nec_task, (unsigned long)dev);
462 } else if (ir->raw_decode) { 444 } else if (ir->raw_decode) {
463 /* set timer_end for code completion */ 445 /* set timer_end for code completion */
464 init_timer(&ir->timer_end); 446 init_timer(&ir->timer_end);
@@ -486,10 +468,6 @@ static void __saa7134_ir_stop(void *priv)
486 return; 468 return;
487 if (dev->remote->polling) 469 if (dev->remote->polling)
488 del_timer_sync(&dev->remote->timer); 470 del_timer_sync(&dev->remote->timer);
489 else if (ir->rc5_gpio)
490 del_timer_sync(&ir->timer_end);
491 else if (ir->nec_gpio)
492 tasklet_kill(&ir->tlet);
493 else if (ir->raw_decode) { 471 else if (ir->raw_decode) {
494 del_timer_sync(&ir->timer_end); 472 del_timer_sync(&ir->timer_end);
495 ir->active = 0; 473 ir->active = 0;
@@ -531,40 +509,6 @@ static void saa7134_ir_close(struct rc_dev *rc)
531 __saa7134_ir_stop(dev); 509 __saa7134_ir_stop(dev);
532} 510}
533 511
534
535static int saa7134_ir_change_protocol(struct rc_dev *rc, u64 ir_type)
536{
537 struct saa7134_dev *dev = rc->priv;
538 struct card_ir *ir = dev->remote;
539 u32 nec_gpio, rc5_gpio;
540
541 if (ir_type == IR_TYPE_RC5) {
542 dprintk("Changing protocol to RC5\n");
543 nec_gpio = 0;
544 rc5_gpio = 1;
545 } else if (ir_type == IR_TYPE_NEC) {
546 dprintk("Changing protocol to NEC\n");
547 nec_gpio = 1;
548 rc5_gpio = 0;
549 } else {
550 dprintk("IR protocol type %ud is not supported\n",
551 (unsigned)ir_type);
552 return -EINVAL;
553 }
554
555 if (ir->running) {
556 saa7134_ir_stop(dev);
557 ir->nec_gpio = nec_gpio;
558 ir->rc5_gpio = rc5_gpio;
559 saa7134_ir_start(dev);
560 } else {
561 ir->nec_gpio = nec_gpio;
562 ir->rc5_gpio = rc5_gpio;
563 }
564
565 return 0;
566}
567
568int saa7134_input_init1(struct saa7134_dev *dev) 512int saa7134_input_init1(struct saa7134_dev *dev)
569{ 513{
570 struct card_ir *ir; 514 struct card_ir *ir;
@@ -574,10 +518,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
574 u32 mask_keydown = 0; 518 u32 mask_keydown = 0;
575 u32 mask_keyup = 0; 519 u32 mask_keyup = 0;
576 int polling = 0; 520 int polling = 0;
577 int rc5_gpio = 0;
578 int nec_gpio = 0;
579 int raw_decode = 0; 521 int raw_decode = 0;
580 int allow_protocol_change = 0;
581 int err; 522 int err;
582 523
583 if (dev->has_remote != SAA7134_REMOTE_GPIO) 524 if (dev->has_remote != SAA7134_REMOTE_GPIO)
@@ -830,8 +771,6 @@ int saa7134_input_init1(struct saa7134_dev *dev)
830 ir->mask_keydown = mask_keydown; 771 ir->mask_keydown = mask_keydown;
831 ir->mask_keyup = mask_keyup; 772 ir->mask_keyup = mask_keyup;
832 ir->polling = polling; 773 ir->polling = polling;
833 ir->rc5_gpio = rc5_gpio;
834 ir->nec_gpio = nec_gpio;
835 ir->raw_decode = raw_decode; 774 ir->raw_decode = raw_decode;
836 775
837 /* init input device */ 776 /* init input device */
@@ -846,11 +785,6 @@ int saa7134_input_init1(struct saa7134_dev *dev)
846 if (raw_decode) 785 if (raw_decode)
847 rc->driver_type = RC_DRIVER_IR_RAW; 786 rc->driver_type = RC_DRIVER_IR_RAW;
848 787
849 if (!raw_decode && allow_protocol_change) {
850 rc->allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC;
851 rc->change_protocol = saa7134_ir_change_protocol;
852 }
853
854 rc->input_name = ir->name; 788 rc->input_name = ir->name;
855 rc->input_phys = ir->phys; 789 rc->input_phys = ir->phys;
856 rc->input_id.bustype = BUS_PCI; 790 rc->input_id.bustype = BUS_PCI;
@@ -1024,152 +958,3 @@ static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
1024 958
1025 return 1; 959 return 1;
1026} 960}
1027
1028static int saa7134_rc5_irq(struct saa7134_dev *dev)
1029{
1030 struct card_ir *ir = dev->remote;
1031 struct timeval tv;
1032 u32 gap;
1033 unsigned long current_jiffies, timeout;
1034
1035 /* get time of bit */
1036 current_jiffies = jiffies;
1037 do_gettimeofday(&tv);
1038
1039 /* avoid overflow with gap >1s */
1040 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
1041 gap = 200000;
1042 } else {
1043 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
1044 tv.tv_usec - ir->base_time.tv_usec;
1045 }
1046
1047 /* active code => add bit */
1048 if (ir->active) {
1049 /* only if in the code (otherwise spurious IRQ or timer
1050 late) */
1051 if (ir->last_bit < 28) {
1052 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
1053 ir_rc5_remote_gap;
1054 ir->code |= 1 << ir->last_bit;
1055 }
1056 /* starting new code */
1057 } else {
1058 ir->active = 1;
1059 ir->code = 0;
1060 ir->base_time = tv;
1061 ir->last_bit = 0;
1062
1063 timeout = current_jiffies + (500 + 30 * HZ) / 1000;
1064 mod_timer(&ir->timer_end, timeout);
1065 }
1066
1067 return 1;
1068}
1069
1070static void nec_task(unsigned long data)
1071{
1072 struct saa7134_dev *dev = (struct saa7134_dev *) data;
1073 struct card_ir *ir;
1074 struct timeval tv;
1075 int count, pulse, oldpulse, gap;
1076 u32 ircode = 0, not_code = 0;
1077 int ngap = 0;
1078
1079 if (!data) {
1080 printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n");
1081 /* GPIO will be kept disabled */
1082 return;
1083 }
1084
1085 ir = dev->remote;
1086
1087 /* rising SAA7134_GPIO_GPRESCAN reads the status */
1088 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1089 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1090
1091 oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
1092 pulse = oldpulse;
1093
1094 do_gettimeofday(&tv);
1095 ir->base_time = tv;
1096
1097 /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
1098 Unfortunately, using IRQ to decode pulse didn't work, since it uses
1099 a pulse train of 38KHz. This means one pulse on each 52 us
1100 */
1101 do {
1102 /* Wait until the end of pulse/space or 5 ms */
1103 for (count = 0; count < 500; count++) {
1104 udelay(10);
1105 /* rising SAA7134_GPIO_GPRESCAN reads the status */
1106 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1107 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1108 pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)
1109 & ir->mask_keydown;
1110 if (pulse != oldpulse)
1111 break;
1112 }
1113
1114 do_gettimeofday(&tv);
1115 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
1116 tv.tv_usec - ir->base_time.tv_usec;
1117
1118 if (!pulse) {
1119 /* Bit 0 has 560 us, while bit 1 has 1120 us.
1120 Do something only if bit == 1
1121 */
1122 if (ngap && (gap > 560 + 280)) {
1123 unsigned int shift = ngap - 1;
1124
1125 /* Address first, then command */
1126 if (shift < 8) {
1127 shift += 8;
1128 ircode |= 1 << shift;
1129 } else if (shift < 16) {
1130 not_code |= 1 << shift;
1131 } else if (shift < 24) {
1132 shift -= 16;
1133 ircode |= 1 << shift;
1134 } else {
1135 shift -= 24;
1136 not_code |= 1 << shift;
1137 }
1138 }
1139 ngap++;
1140 }
1141
1142
1143 ir->base_time = tv;
1144
1145 /* TIMEOUT - Long pulse */
1146 if (gap >= 5000)
1147 break;
1148 oldpulse = pulse;
1149 } while (ngap < 32);
1150
1151 if (ngap == 32) {
1152 /* FIXME: should check if not_code == ~ircode */
1153 ir->code = ir_extract_bits(ircode, ir->mask_keycode);
1154
1155 dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
1156 ir->code, ircode, not_code);
1157
1158 ir_keydown(ir->dev, ir->code, 0);
1159 } else {
1160 dprintk("Repeat last key\n");
1161 ir_repeat(ir->dev);
1162 }
1163
1164 saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
1165}
1166
1167static int saa7134_nec_irq(struct saa7134_dev *dev)
1168{
1169 struct card_ir *ir = dev->remote;
1170
1171 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
1172 tasklet_schedule(&ir->tlet);
1173
1174 return 1;
1175}