aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/bt8xx
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/bt8xx')
-rw-r--r--drivers/media/video/bt8xx/Kconfig4
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c48
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c238
-rw-r--r--drivers/media/video/bt8xx/bttv.h1
-rw-r--r--drivers/media/video/bt8xx/bttvp.h34
5 files changed, 204 insertions, 121 deletions
diff --git a/drivers/media/video/bt8xx/Kconfig b/drivers/media/video/bt8xx/Kconfig
index 1a4a89fdf767..7da5c2e1fc12 100644
--- a/drivers/media/video/bt8xx/Kconfig
+++ b/drivers/media/video/bt8xx/Kconfig
@@ -1,10 +1,10 @@
1config VIDEO_BT848 1config VIDEO_BT848
2 tristate "BT848 Video For Linux" 2 tristate "BT848 Video For Linux"
3 depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L2 && INPUT 3 depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L2
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select VIDEO_BTCX 5 select VIDEO_BTCX
6 select VIDEOBUF_DMA_SG 6 select VIDEOBUF_DMA_SG
7 depends on VIDEO_IR 7 depends on RC_CORE
8 select VIDEO_TUNER 8 select VIDEO_TUNER
9 select VIDEO_TVEEPROM 9 select VIDEO_TVEEPROM
10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO 10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 0902ec041c7a..849cd170b821 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -55,7 +55,7 @@
55#include <asm/io.h> 55#include <asm/io.h>
56#include <asm/byteorder.h> 56#include <asm/byteorder.h>
57 57
58#include <media/rds.h> 58#include <media/saa6588.h>
59 59
60 60
61unsigned int bttv_num; /* number of Bt848s in use */ 61unsigned int bttv_num; /* number of Bt848s in use */
@@ -2597,31 +2597,6 @@ static int bttv_s_fmt_vid_overlay(struct file *file, void *priv,
2597 return setup_window_lock(fh, btv, &f->fmt.win, 1); 2597 return setup_window_lock(fh, btv, &f->fmt.win, 1);
2598} 2598}
2599 2599
2600#ifdef CONFIG_VIDEO_V4L1_COMPAT
2601static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
2602{
2603 int retval;
2604 unsigned int i;
2605 struct bttv_fh *fh = priv;
2606
2607 retval = __videobuf_mmap_setup(&fh->cap, gbuffers, gbufsize,
2608 V4L2_MEMORY_MMAP);
2609 if (retval < 0) {
2610 return retval;
2611 }
2612
2613 gbuffers = retval;
2614 memset(mbuf, 0, sizeof(*mbuf));
2615 mbuf->frames = gbuffers;
2616 mbuf->size = gbuffers * gbufsize;
2617
2618 for (i = 0; i < gbuffers; i++)
2619 mbuf->offsets[i] = i * gbufsize;
2620
2621 return 0;
2622}
2623#endif
2624
2625static int bttv_querycap(struct file *file, void *priv, 2600static int bttv_querycap(struct file *file, void *priv,
2626 struct v4l2_capability *cap) 2601 struct v4l2_capability *cap)
2627{ 2602{
@@ -3354,9 +3329,6 @@ static const struct v4l2_ioctl_ops bttv_ioctl_ops = {
3354 .vidioc_streamoff = bttv_streamoff, 3329 .vidioc_streamoff = bttv_streamoff,
3355 .vidioc_g_tuner = bttv_g_tuner, 3330 .vidioc_g_tuner = bttv_g_tuner,
3356 .vidioc_s_tuner = bttv_s_tuner, 3331 .vidioc_s_tuner = bttv_s_tuner,
3357#ifdef CONFIG_VIDEO_V4L1_COMPAT
3358 .vidiocgmbuf = vidiocgmbuf,
3359#endif
3360 .vidioc_g_crop = bttv_g_crop, 3332 .vidioc_g_crop = bttv_g_crop,
3361 .vidioc_s_crop = bttv_s_crop, 3333 .vidioc_s_crop = bttv_s_crop,
3362 .vidioc_g_fbuf = bttv_g_fbuf, 3334 .vidioc_g_fbuf = bttv_g_fbuf,
@@ -3416,7 +3388,7 @@ static int radio_release(struct file *file)
3416{ 3388{
3417 struct bttv_fh *fh = file->private_data; 3389 struct bttv_fh *fh = file->private_data;
3418 struct bttv *btv = fh->btv; 3390 struct bttv *btv = fh->btv;
3419 struct rds_command cmd; 3391 struct saa6588_command cmd;
3420 3392
3421 v4l2_prio_close(&btv->prio, fh->prio); 3393 v4l2_prio_close(&btv->prio, fh->prio);
3422 file->private_data = NULL; 3394 file->private_data = NULL;
@@ -3424,7 +3396,7 @@ static int radio_release(struct file *file)
3424 3396
3425 btv->radio_user--; 3397 btv->radio_user--;
3426 3398
3427 bttv_call_all(btv, core, ioctl, RDS_CMD_CLOSE, &cmd); 3399 bttv_call_all(btv, core, ioctl, SAA6588_CMD_CLOSE, &cmd);
3428 3400
3429 return 0; 3401 return 0;
3430} 3402}
@@ -3551,13 +3523,13 @@ static ssize_t radio_read(struct file *file, char __user *data,
3551{ 3523{
3552 struct bttv_fh *fh = file->private_data; 3524 struct bttv_fh *fh = file->private_data;
3553 struct bttv *btv = fh->btv; 3525 struct bttv *btv = fh->btv;
3554 struct rds_command cmd; 3526 struct saa6588_command cmd;
3555 cmd.block_count = count/3; 3527 cmd.block_count = count/3;
3556 cmd.buffer = data; 3528 cmd.buffer = data;
3557 cmd.instance = file; 3529 cmd.instance = file;
3558 cmd.result = -ENODEV; 3530 cmd.result = -ENODEV;
3559 3531
3560 bttv_call_all(btv, core, ioctl, RDS_CMD_READ, &cmd); 3532 bttv_call_all(btv, core, ioctl, SAA6588_CMD_READ, &cmd);
3561 3533
3562 return cmd.result; 3534 return cmd.result;
3563} 3535}
@@ -3566,11 +3538,11 @@ static unsigned int radio_poll(struct file *file, poll_table *wait)
3566{ 3538{
3567 struct bttv_fh *fh = file->private_data; 3539 struct bttv_fh *fh = file->private_data;
3568 struct bttv *btv = fh->btv; 3540 struct bttv *btv = fh->btv;
3569 struct rds_command cmd; 3541 struct saa6588_command cmd;
3570 cmd.instance = file; 3542 cmd.instance = file;
3571 cmd.event_list = wait; 3543 cmd.event_list = wait;
3572 cmd.result = -ENODEV; 3544 cmd.result = -ENODEV;
3573 bttv_call_all(btv, core, ioctl, RDS_CMD_POLL, &cmd); 3545 bttv_call_all(btv, core, ioctl, SAA6588_CMD_POLL, &cmd);
3574 3546
3575 return cmd.result; 3547 return cmd.result;
3576} 3548}
@@ -4041,9 +4013,6 @@ static irqreturn_t bttv_irq(int irq, void *dev_id)
4041 4013
4042 btv=(struct bttv *)dev_id; 4014 btv=(struct bttv *)dev_id;
4043 4015
4044 if (btv->custom_irq)
4045 handled = btv->custom_irq(btv);
4046
4047 count=0; 4016 count=0;
4048 while (1) { 4017 while (1) {
4049 /* get/clear interrupt status bits */ 4018 /* get/clear interrupt status bits */
@@ -4079,7 +4048,6 @@ static irqreturn_t bttv_irq(int irq, void *dev_id)
4079 btv->field_count++; 4048 btv->field_count++;
4080 4049
4081 if ((astat & BT848_INT_GPINT) && btv->remote) { 4050 if ((astat & BT848_INT_GPINT) && btv->remote) {
4082 wake_up(&btv->gpioq);
4083 bttv_input_irq(btv); 4051 bttv_input_irq(btv);
4084 } 4052 }
4085 4053
@@ -4284,7 +4252,6 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4284 mutex_init(&btv->lock); 4252 mutex_init(&btv->lock);
4285 spin_lock_init(&btv->s_lock); 4253 spin_lock_init(&btv->s_lock);
4286 spin_lock_init(&btv->gpio_lock); 4254 spin_lock_init(&btv->gpio_lock);
4287 init_waitqueue_head(&btv->gpioq);
4288 init_waitqueue_head(&btv->i2c_queue); 4255 init_waitqueue_head(&btv->i2c_queue);
4289 INIT_LIST_HEAD(&btv->c.subs); 4256 INIT_LIST_HEAD(&btv->c.subs);
4290 INIT_LIST_HEAD(&btv->capture); 4257 INIT_LIST_HEAD(&btv->capture);
@@ -4472,7 +4439,6 @@ static void __devexit bttv_remove(struct pci_dev *pci_dev)
4472 4439
4473 /* tell gpio modules we are leaving ... */ 4440 /* tell gpio modules we are leaving ... */
4474 btv->shutdown=1; 4441 btv->shutdown=1;
4475 wake_up(&btv->gpioq);
4476 bttv_input_fini(btv); 4442 bttv_input_fini(btv);
4477 bttv_sub_del_devices(&btv->c); 4443 bttv_sub_del_devices(&btv->c);
4478 4444
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index 6bf05a7dc5f9..97793b960600 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -31,15 +31,9 @@
31 31
32static int ir_debug; 32static int ir_debug;
33module_param(ir_debug, int, 0644); 33module_param(ir_debug, int, 0644);
34static int repeat_delay = 500;
35module_param(repeat_delay, int, 0644);
36static int repeat_period = 33;
37module_param(repeat_period, int, 0644);
38 34
39static int ir_rc5_remote_gap = 885; 35static int ir_rc5_remote_gap = 885;
40module_param(ir_rc5_remote_gap, int, 0644); 36module_param(ir_rc5_remote_gap, int, 0644);
41static int ir_rc5_key_timeout = 200;
42module_param(ir_rc5_key_timeout, int, 0644);
43 37
44#undef dprintk 38#undef dprintk
45#define dprintk(arg...) do { \ 39#define dprintk(arg...) do { \
@@ -55,7 +49,7 @@ module_param(ir_rc5_key_timeout, int, 0644);
55 49
56static void ir_handle_key(struct bttv *btv) 50static void ir_handle_key(struct bttv *btv)
57{ 51{
58 struct card_ir *ir = btv->remote; 52 struct bttv_ir *ir = btv->remote;
59 u32 gpio,data; 53 u32 gpio,data;
60 54
61 /* read gpio value */ 55 /* read gpio value */
@@ -74,23 +68,22 @@ static void ir_handle_key(struct bttv *btv)
74 (gpio & ir->mask_keydown) ? " down" : "", 68 (gpio & ir->mask_keydown) ? " down" : "",
75 (gpio & ir->mask_keyup) ? " up" : ""); 69 (gpio & ir->mask_keyup) ? " up" : "");
76 70
77 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || 71 if ((ir->mask_keydown && (gpio & ir->mask_keydown)) ||
78 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { 72 (ir->mask_keyup && !(gpio & ir->mask_keyup))) {
79 ir_input_keydown(ir->dev, &ir->ir, data); 73 rc_keydown_notimeout(ir->dev, data, 0);
80 } else { 74 } else {
81 /* HACK: Probably, ir->mask_keydown is missing 75 /* HACK: Probably, ir->mask_keydown is missing
82 for this board */ 76 for this board */
83 if (btv->c.type == BTTV_BOARD_WINFAST2000) 77 if (btv->c.type == BTTV_BOARD_WINFAST2000)
84 ir_input_keydown(ir->dev, &ir->ir, data); 78 rc_keydown_notimeout(ir->dev, data, 0);
85 79
86 ir_input_nokey(ir->dev,&ir->ir); 80 rc_keyup(ir->dev);
87 } 81 }
88
89} 82}
90 83
91static void ir_enltv_handle_key(struct bttv *btv) 84static void ir_enltv_handle_key(struct bttv *btv)
92{ 85{
93 struct card_ir *ir = btv->remote; 86 struct bttv_ir *ir = btv->remote;
94 u32 gpio, data, keyup; 87 u32 gpio, data, keyup;
95 88
96 /* read gpio value */ 89 /* read gpio value */
@@ -107,9 +100,9 @@ static void ir_enltv_handle_key(struct bttv *btv)
107 gpio, data, 100 gpio, data,
108 (gpio & ir->mask_keyup) ? " up" : "up/down"); 101 (gpio & ir->mask_keyup) ? " up" : "up/down");
109 102
110 ir_input_keydown(ir->dev, &ir->ir, data); 103 rc_keydown_notimeout(ir->dev, data, 0);
111 if (keyup) 104 if (keyup)
112 ir_input_nokey(ir->dev, &ir->ir); 105 rc_keyup(ir->dev);
113 } else { 106 } else {
114 if ((ir->last_gpio & 1 << 31) == keyup) 107 if ((ir->last_gpio & 1 << 31) == keyup)
115 return; 108 return;
@@ -119,26 +112,30 @@ static void ir_enltv_handle_key(struct bttv *btv)
119 (gpio & ir->mask_keyup) ? " up" : "down"); 112 (gpio & ir->mask_keyup) ? " up" : "down");
120 113
121 if (keyup) 114 if (keyup)
122 ir_input_nokey(ir->dev, &ir->ir); 115 rc_keyup(ir->dev);
123 else 116 else
124 ir_input_keydown(ir->dev, &ir->ir, data); 117 rc_keydown_notimeout(ir->dev, data, 0);
125 } 118 }
126 119
127 ir->last_gpio = data | keyup; 120 ir->last_gpio = data | keyup;
128} 121}
129 122
123static int bttv_rc5_irq(struct bttv *btv);
124
130void bttv_input_irq(struct bttv *btv) 125void bttv_input_irq(struct bttv *btv)
131{ 126{
132 struct card_ir *ir = btv->remote; 127 struct bttv_ir *ir = btv->remote;
133 128
134 if (!ir->polling) 129 if (ir->rc5_gpio)
130 bttv_rc5_irq(btv);
131 else if (!ir->polling)
135 ir_handle_key(btv); 132 ir_handle_key(btv);
136} 133}
137 134
138static void bttv_input_timer(unsigned long data) 135static void bttv_input_timer(unsigned long data)
139{ 136{
140 struct bttv *btv = (struct bttv*)data; 137 struct bttv *btv = (struct bttv*)data;
141 struct card_ir *ir = btv->remote; 138 struct bttv_ir *ir = btv->remote;
142 139
143 if (btv->c.type == BTTV_BOARD_ENLTV_FM_2) 140 if (btv->c.type == BTTV_BOARD_ENLTV_FM_2)
144 ir_enltv_handle_key(btv); 141 ir_enltv_handle_key(btv);
@@ -147,11 +144,109 @@ static void bttv_input_timer(unsigned long data)
147 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); 144 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
148} 145}
149 146
150/* ---------------------------------------------------------------*/ 147/*
148 * FIXME: Nebula digi uses the legacy way to decode RC5, instead of relying
149 * on the rc-core way. As we need to be sure that both IRQ transitions are
150 * properly triggered, Better to touch it only with this hardware for
151 * testing.
152 */
153
154#define RC5_START(x) (((x) >> 12) & 3)
155#define RC5_TOGGLE(x) (((x) >> 11) & 1)
156#define RC5_ADDR(x) (((x) >> 6) & 31)
157#define RC5_INSTR(x) ((x) & 63)
158
159/* decode raw bit pattern to RC5 code */
160static u32 bttv_rc5_decode(unsigned int code)
161{
162 unsigned int org_code = code;
163 unsigned int pair;
164 unsigned int rc5 = 0;
165 int i;
166
167 for (i = 0; i < 14; ++i) {
168 pair = code & 0x3;
169 code >>= 2;
170
171 rc5 <<= 1;
172 switch (pair) {
173 case 0:
174 case 2:
175 break;
176 case 1:
177 rc5 |= 1;
178 break;
179 case 3:
180 dprintk(KERN_INFO DEVNAME ":rc5_decode(%x) bad code\n",
181 org_code);
182 return 0;
183 }
184 }
185 dprintk(KERN_INFO DEVNAME ":"
186 "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
187 "instr=%x\n", rc5, org_code, RC5_START(rc5),
188 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
189 return rc5;
190}
191
192static void bttv_rc5_timer_end(unsigned long data)
193{
194 struct bttv_ir *ir = (struct bttv_ir *)data;
195 struct timeval tv;
196 unsigned long current_jiffies;
197 u32 gap;
198 u32 rc5 = 0;
199
200 /* get time */
201 current_jiffies = jiffies;
202 do_gettimeofday(&tv);
203
204 /* avoid overflow with gap >1s */
205 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
206 gap = 200000;
207 } else {
208 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
209 tv.tv_usec - ir->base_time.tv_usec;
210 }
211
212 /* signal we're ready to start a new code */
213 ir->active = false;
214
215 /* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
216 if (gap < 28000) {
217 dprintk(KERN_INFO DEVNAME ": spurious timer_end\n");
218 return;
219 }
220
221 if (ir->last_bit < 20) {
222 /* ignore spurious codes (caused by light/other remotes) */
223 dprintk(KERN_INFO DEVNAME ": short code: %x\n", ir->code);
224 } else {
225 ir->code = (ir->code << ir->shift_by) | 1;
226 rc5 = bttv_rc5_decode(ir->code);
227
228 /* two start bits? */
229 if (RC5_START(rc5) != ir->start) {
230 printk(KERN_INFO DEVNAME ":"
231 " rc5 start bits invalid: %u\n", RC5_START(rc5));
232
233 /* right address? */
234 } else if (RC5_ADDR(rc5) == ir->addr) {
235 u32 toggle = RC5_TOGGLE(rc5);
236 u32 instr = RC5_INSTR(rc5);
237
238 /* Good code */
239 rc_keydown(ir->dev, instr, toggle);
240 dprintk(KERN_INFO DEVNAME ":"
241 " instruction %x, toggle %x\n",
242 instr, toggle);
243 }
244 }
245}
151 246
152static int bttv_rc5_irq(struct bttv *btv) 247static int bttv_rc5_irq(struct bttv *btv)
153{ 248{
154 struct card_ir *ir = btv->remote; 249 struct bttv_ir *ir = btv->remote;
155 struct timeval tv; 250 struct timeval tv;
156 u32 gpio; 251 u32 gpio;
157 u32 gap; 252 u32 gap;
@@ -160,10 +255,6 @@ static int bttv_rc5_irq(struct bttv *btv)
160 /* read gpio port */ 255 /* read gpio port */
161 gpio = bttv_gpio_read(&btv->c); 256 gpio = bttv_gpio_read(&btv->c);
162 257
163 /* remote IRQ? */
164 if (!(gpio & 0x20))
165 return 0;
166
167 /* get time of bit */ 258 /* get time of bit */
168 current_jiffies = jiffies; 259 current_jiffies = jiffies;
169 do_gettimeofday(&tv); 260 do_gettimeofday(&tv);
@@ -176,6 +267,13 @@ static int bttv_rc5_irq(struct bttv *btv)
176 tv.tv_usec - ir->base_time.tv_usec; 267 tv.tv_usec - ir->base_time.tv_usec;
177 } 268 }
178 269
270 dprintk(KERN_INFO DEVNAME ": RC5 IRQ: gap %d us for %s\n",
271 gap, (gpio & 0x20) ? "mark" : "space");
272
273 /* remote IRQ? */
274 if (!(gpio & 0x20))
275 return 0;
276
179 /* active code => add bit */ 277 /* active code => add bit */
180 if (ir->active) { 278 if (ir->active) {
181 /* only if in the code (otherwise spurious IRQ or timer 279 /* only if in the code (otherwise spurious IRQ or timer
@@ -187,13 +285,12 @@ static int bttv_rc5_irq(struct bttv *btv)
187 } 285 }
188 /* starting new code */ 286 /* starting new code */
189 } else { 287 } else {
190 ir->active = 1; 288 ir->active = true;
191 ir->code = 0; 289 ir->code = 0;
192 ir->base_time = tv; 290 ir->base_time = tv;
193 ir->last_bit = 0; 291 ir->last_bit = 0;
194 292
195 mod_timer(&ir->timer_end, 293 mod_timer(&ir->timer, current_jiffies + msecs_to_jiffies(30));
196 current_jiffies + msecs_to_jiffies(30));
197 } 294 }
198 295
199 /* toggle GPIO pin 4 to reset the irq */ 296 /* toggle GPIO pin 4 to reset the irq */
@@ -204,7 +301,7 @@ static int bttv_rc5_irq(struct bttv *btv)
204 301
205/* ---------------------------------------------------------------------- */ 302/* ---------------------------------------------------------------------- */
206 303
207static void bttv_ir_start(struct bttv *btv, struct card_ir *ir) 304static void bttv_ir_start(struct bttv *btv, struct bttv_ir *ir)
208{ 305{
209 if (ir->polling) { 306 if (ir->polling) {
210 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv); 307 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv);
@@ -212,17 +309,10 @@ static void bttv_ir_start(struct bttv *btv, struct card_ir *ir)
212 add_timer(&ir->timer); 309 add_timer(&ir->timer);
213 } else if (ir->rc5_gpio) { 310 } else if (ir->rc5_gpio) {
214 /* set timer_end for code completion */ 311 /* set timer_end for code completion */
215 init_timer(&ir->timer_end); 312 setup_timer(&ir->timer, bttv_rc5_timer_end, (unsigned long)ir);
216 ir->timer_end.function = ir_rc5_timer_end;
217 ir->timer_end.data = (unsigned long)ir;
218
219 init_timer(&ir->timer_keyup);
220 ir->timer_keyup.function = ir_rc5_timer_keyup;
221 ir->timer_keyup.data = (unsigned long)ir;
222 ir->shift_by = 1; 313 ir->shift_by = 1;
223 ir->start = 3; 314 ir->start = 3;
224 ir->addr = 0x0; 315 ir->addr = 0x0;
225 ir->rc5_key_timeout = ir_rc5_key_timeout;
226 ir->rc5_remote_gap = ir_rc5_remote_gap; 316 ir->rc5_remote_gap = ir_rc5_remote_gap;
227 } 317 }
228} 318}
@@ -237,7 +327,7 @@ static void bttv_ir_stop(struct bttv *btv)
237 if (btv->remote->rc5_gpio) { 327 if (btv->remote->rc5_gpio) {
238 u32 gpio; 328 u32 gpio;
239 329
240 del_timer_sync(&btv->remote->timer_end); 330 del_timer_sync(&btv->remote->timer);
241 flush_scheduled_work(); 331 flush_scheduled_work();
242 332
243 gpio = bttv_gpio_read(&btv->c); 333 gpio = bttv_gpio_read(&btv->c);
@@ -264,6 +354,18 @@ static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
264 return 0; 354 return 0;
265 dprintk(KERN_INFO DEVNAME ": key %02x\n", b); 355 dprintk(KERN_INFO DEVNAME ": key %02x\n", b);
266 356
357 /*
358 * NOTE:
359 * lirc_i2c maps the pv951 code as:
360 * addr = 0x61D6
361 * cmd = bit_reverse (b)
362 * So, it seems that this device uses NEC extended
363 * I decided to not fix the table, due to two reasons:
364 * 1) Without the actual device, this is only a guess;
365 * 2) As the addr is not reported via I2C, nor can be changed,
366 * the device is bound to the vendor-provided RC.
367 */
368
267 *ir_key = b; 369 *ir_key = b;
268 *ir_raw = b; 370 *ir_raw = b;
269 return 1; 371 return 1;
@@ -290,16 +392,15 @@ void __devinit init_bttv_i2c_ir(struct bttv *btv)
290 btv->init_data.name = "PV951"; 392 btv->init_data.name = "PV951";
291 btv->init_data.get_key = get_key_pv951; 393 btv->init_data.get_key = get_key_pv951;
292 btv->init_data.ir_codes = RC_MAP_PV951; 394 btv->init_data.ir_codes = RC_MAP_PV951;
293 btv->init_data.type = IR_TYPE_OTHER;
294 info.addr = 0x4b; 395 info.addr = 0x4b;
295 break; 396 break;
296 default: 397 default:
297 /* 398 /*
298 * The external IR receiver is at i2c address 0x34 (0x35 for 399 * The external IR receiver is at i2c address 0x34 (0x35 for
299 * reads). Future Hauppauge cards will have an internal 400 * reads). Future Hauppauge cards will have an internal
300 * receiver at 0x30 (0x31 for reads). In theory, both can be 401 * receiver at 0x30 (0x31 for reads). In theory, both can be
301 * fitted, and Hauppauge suggest an external overrides an 402 * fitted, and Hauppauge suggest an external overrides an
302 * internal. 403 * internal.
303 * That's why we probe 0x1a (~0x34) first. CB 404 * That's why we probe 0x1a (~0x34) first. CB
304 */ 405 */
305 406
@@ -324,18 +425,17 @@ int __devexit fini_bttv_i2c(struct bttv *btv)
324 425
325int bttv_input_init(struct bttv *btv) 426int bttv_input_init(struct bttv *btv)
326{ 427{
327 struct card_ir *ir; 428 struct bttv_ir *ir;
328 char *ir_codes = NULL; 429 char *ir_codes = NULL;
329 struct input_dev *input_dev; 430 struct rc_dev *rc;
330 u64 ir_type = IR_TYPE_OTHER;
331 int err = -ENOMEM; 431 int err = -ENOMEM;
332 432
333 if (!btv->has_remote) 433 if (!btv->has_remote)
334 return -ENODEV; 434 return -ENODEV;
335 435
336 ir = kzalloc(sizeof(*ir),GFP_KERNEL); 436 ir = kzalloc(sizeof(*ir),GFP_KERNEL);
337 input_dev = input_allocate_device(); 437 rc = rc_allocate_device();
338 if (!ir || !input_dev) 438 if (!ir || !rc)
339 goto err_out_free; 439 goto err_out_free;
340 440
341 /* detect & configure */ 441 /* detect & configure */
@@ -398,8 +498,7 @@ int bttv_input_init(struct bttv *btv)
398 break; 498 break;
399 case BTTV_BOARD_NEBULA_DIGITV: 499 case BTTV_BOARD_NEBULA_DIGITV:
400 ir_codes = RC_MAP_NEBULA; 500 ir_codes = RC_MAP_NEBULA;
401 btv->custom_irq = bttv_rc5_irq; 501 ir->rc5_gpio = true;
402 ir->rc5_gpio = 1;
403 break; 502 break;
404 case BTTV_BOARD_MACHTV_MAGICTV: 503 case BTTV_BOARD_MACHTV_MAGICTV:
405 ir_codes = RC_MAP_APAC_VIEWCOMP; 504 ir_codes = RC_MAP_APAC_VIEWCOMP;
@@ -441,48 +540,43 @@ int bttv_input_init(struct bttv *btv)
441 } 540 }
442 541
443 /* init input device */ 542 /* init input device */
444 ir->dev = input_dev; 543 ir->dev = rc;
445 544
446 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)", 545 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)",
447 btv->c.type); 546 btv->c.type);
448 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", 547 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
449 pci_name(btv->c.pci)); 548 pci_name(btv->c.pci));
450 549
451 err = ir_input_init(input_dev, &ir->ir, ir_type); 550 rc->input_name = ir->name;
452 if (err < 0) 551 rc->input_phys = ir->phys;
453 goto err_out_free; 552 rc->input_id.bustype = BUS_PCI;
454 553 rc->input_id.version = 1;
455 input_dev->name = ir->name;
456 input_dev->phys = ir->phys;
457 input_dev->id.bustype = BUS_PCI;
458 input_dev->id.version = 1;
459 if (btv->c.pci->subsystem_vendor) { 554 if (btv->c.pci->subsystem_vendor) {
460 input_dev->id.vendor = btv->c.pci->subsystem_vendor; 555 rc->input_id.vendor = btv->c.pci->subsystem_vendor;
461 input_dev->id.product = btv->c.pci->subsystem_device; 556 rc->input_id.product = btv->c.pci->subsystem_device;
462 } else { 557 } else {
463 input_dev->id.vendor = btv->c.pci->vendor; 558 rc->input_id.vendor = btv->c.pci->vendor;
464 input_dev->id.product = btv->c.pci->device; 559 rc->input_id.product = btv->c.pci->device;
465 } 560 }
466 input_dev->dev.parent = &btv->c.pci->dev; 561 rc->dev.parent = &btv->c.pci->dev;
562 rc->map_name = ir_codes;
563 rc->driver_name = MODULE_NAME;
467 564
468 btv->remote = ir; 565 btv->remote = ir;
469 bttv_ir_start(btv, ir); 566 bttv_ir_start(btv, ir);
470 567
471 /* all done */ 568 /* all done */
472 err = ir_input_register(btv->remote->dev, ir_codes, NULL, MODULE_NAME); 569 err = rc_register_device(rc);
473 if (err) 570 if (err)
474 goto err_out_stop; 571 goto err_out_stop;
475 572
476 /* the remote isn't as bouncy as a keyboard */
477 ir->dev->rep[REP_DELAY] = repeat_delay;
478 ir->dev->rep[REP_PERIOD] = repeat_period;
479
480 return 0; 573 return 0;
481 574
482 err_out_stop: 575 err_out_stop:
483 bttv_ir_stop(btv); 576 bttv_ir_stop(btv);
484 btv->remote = NULL; 577 btv->remote = NULL;
485 err_out_free: 578 err_out_free:
579 rc_free_device(rc);
486 kfree(ir); 580 kfree(ir);
487 return err; 581 return err;
488} 582}
@@ -493,7 +587,7 @@ void bttv_input_fini(struct bttv *btv)
493 return; 587 return;
494 588
495 bttv_ir_stop(btv); 589 bttv_ir_stop(btv);
496 ir_input_unregister(btv->remote->dev); 590 rc_unregister_device(btv->remote->dev);
497 kfree(btv->remote); 591 kfree(btv->remote);
498 btv->remote = NULL; 592 btv->remote = NULL;
499} 593}
diff --git a/drivers/media/video/bt8xx/bttv.h b/drivers/media/video/bt8xx/bttv.h
index 6fd2a8ebda1e..fd62bf15d779 100644
--- a/drivers/media/video/bt8xx/bttv.h
+++ b/drivers/media/video/bt8xx/bttv.h
@@ -17,7 +17,6 @@
17#include <linux/videodev2.h> 17#include <linux/videodev2.h>
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <media/v4l2-device.h> 19#include <media/v4l2-device.h>
20#include <media/ir-common.h>
21#include <media/i2c-addr.h> 20#include <media/i2c-addr.h>
22#include <media/tuner.h> 21#include <media/tuner.h>
23 22
diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
index d1e26a448ed2..9b776faf0741 100644
--- a/drivers/media/video/bt8xx/bttvp.h
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -41,7 +41,7 @@
41#include <linux/device.h> 41#include <linux/device.h>
42#include <media/videobuf-dma-sg.h> 42#include <media/videobuf-dma-sg.h>
43#include <media/tveeprom.h> 43#include <media/tveeprom.h>
44#include <media/ir-common.h> 44#include <media/rc-core.h>
45#include <media/ir-kbd-i2c.h> 45#include <media/ir-kbd-i2c.h>
46 46
47#include "bt848.h" 47#include "bt848.h"
@@ -120,6 +120,33 @@ struct bttv_format {
120 int hshift,vshift; /* for planar modes */ 120 int hshift,vshift; /* for planar modes */
121}; 121};
122 122
123struct bttv_ir {
124 struct rc_dev *dev;
125 struct timer_list timer;
126
127 char name[32];
128 char phys[32];
129
130 /* Usual gpio signalling */
131 u32 mask_keycode;
132 u32 mask_keydown;
133 u32 mask_keyup;
134 u32 polling;
135 u32 last_gpio;
136 int shift_by;
137 int start; // What should RC5_START() be
138 int addr; // What RC5_ADDR() should be.
139 int rc5_remote_gap;
140
141 /* RC5 gpio */
142 bool rc5_gpio; /* Is RC5 legacy GPIO enabled? */
143 u32 last_bit; /* last raw bit seen */
144 u32 code; /* raw code under construction */
145 struct timeval base_time; /* time of last seen code */
146 bool active; /* building raw code */
147};
148
149
123/* ---------------------------------------------------------- */ 150/* ---------------------------------------------------------- */
124 151
125struct bttv_geometry { 152struct bttv_geometry {
@@ -305,7 +332,6 @@ struct bttv_pll_info {
305/* for gpio-connected remote control */ 332/* for gpio-connected remote control */
306struct bttv_input { 333struct bttv_input {
307 struct input_dev *dev; 334 struct input_dev *dev;
308 struct ir_input_state ir;
309 char name[32]; 335 char name[32];
310 char phys[32]; 336 char phys[32];
311 u32 mask_keycode; 337 u32 mask_keycode;
@@ -338,12 +364,10 @@ struct bttv {
338 struct bttv_pll_info pll; 364 struct bttv_pll_info pll;
339 int triton1; 365 int triton1;
340 int gpioirq; 366 int gpioirq;
341 int (*custom_irq)(struct bttv *btv);
342 367
343 int use_i2c_hw; 368 int use_i2c_hw;
344 369
345 /* old gpio interface */ 370 /* old gpio interface */
346 wait_queue_head_t gpioq;
347 int shutdown; 371 int shutdown;
348 372
349 void (*volume_gpio)(struct bttv *btv, __u16 volume); 373 void (*volume_gpio)(struct bttv *btv, __u16 volume);
@@ -368,7 +392,7 @@ struct bttv {
368 392
369 /* infrared remote */ 393 /* infrared remote */
370 int has_remote; 394 int has_remote;
371 struct card_ir *remote; 395 struct bttv_ir *remote;
372 396
373 /* I2C remote data */ 397 /* I2C remote data */
374 struct IR_i2c_init_data init_data; 398 struct IR_i2c_init_data init_data;