aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Ringel <stefan.ringel@arcor.de>2010-06-20 16:16:52 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-08-02 14:29:31 -0400
commitd064f960650d64e2564cd505a6e40c4ac359b6f3 (patch)
treea3e653ecdcaaa67858f2590fa0ab52fa3fd86712
parentbd0db8c7ad4b9a053e8774f559cb3dae05f73ef6 (diff)
V4L/DVB: tm6000: add ir support
Signed-off-by: Stefan Ringel <stefan.ringel@arcor.de> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/staging/tm6000/Makefile3
-rw-r--r--drivers/staging/tm6000/tm6000-cards.c28
-rw-r--r--drivers/staging/tm6000/tm6000-input.c364
-rw-r--r--drivers/staging/tm6000/tm6000.h9
4 files changed, 402 insertions, 2 deletions
diff --git a/drivers/staging/tm6000/Makefile b/drivers/staging/tm6000/Makefile
index 4129c185da5..77e06bfd2c4 100644
--- a/drivers/staging/tm6000/Makefile
+++ b/drivers/staging/tm6000/Makefile
@@ -2,7 +2,8 @@ tm6000-objs := tm6000-cards.o \
2 tm6000-core.o \ 2 tm6000-core.o \
3 tm6000-i2c.o \ 3 tm6000-i2c.o \
4 tm6000-video.o \ 4 tm6000-video.o \
5 tm6000-stds.o 5 tm6000-stds.o \
6 tm6000-input.o
6 7
7obj-$(CONFIG_VIDEO_TM6000) += tm6000.o 8obj-$(CONFIG_VIDEO_TM6000) += tm6000.o
8obj-$(CONFIG_VIDEO_TM6000_ALSA) += tm6000-alsa.o 9obj-$(CONFIG_VIDEO_TM6000_ALSA) += tm6000-alsa.o
diff --git a/drivers/staging/tm6000/tm6000-cards.c b/drivers/staging/tm6000/tm6000-cards.c
index 48ab5734cde..9d091c34991 100644
--- a/drivers/staging/tm6000/tm6000-cards.c
+++ b/drivers/staging/tm6000/tm6000-cards.c
@@ -29,6 +29,7 @@
29#include <media/tuner.h> 29#include <media/tuner.h>
30#include <media/tvaudio.h> 30#include <media/tvaudio.h>
31#include <media/i2c-addr.h> 31#include <media/i2c-addr.h>
32#include <media/rc-map.h>
32 33
33#include "tm6000.h" 34#include "tm6000.h"
34#include "tm6000-regs.h" 35#include "tm6000-regs.h"
@@ -69,6 +70,8 @@ struct tm6000_board {
69 int demod_addr; /* demodulator address */ 70 int demod_addr; /* demodulator address */
70 71
71 struct tm6000_gpio gpio; 72 struct tm6000_gpio gpio;
73
74 char *ir_codes;
72}; 75};
73 76
74struct tm6000_board tm6000_boards[] = { 77struct tm6000_board tm6000_boards[] = {
@@ -276,6 +279,7 @@ struct tm6000_board tm6000_boards[] = {
276 .dvb_led = TM6010_GPIO_5, 279 .dvb_led = TM6010_GPIO_5,
277 .ir = TM6010_GPIO_0, 280 .ir = TM6010_GPIO_0,
278 }, 281 },
282 .ir_codes = RC_MAP_NEC_TERRATEC_CINERGY_XS,
279 }, 283 },
280 [TM6010_BOARD_TWINHAN_TU501] = { 284 [TM6010_BOARD_TWINHAN_TU501] = {
281 .name = "Twinhan TU501(704D1)", 285 .name = "Twinhan TU501(704D1)",
@@ -361,6 +365,8 @@ int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
361 365
362 switch (command) { 366 switch (command) {
363 case XC2028_RESET_CLK: 367 case XC2028_RESET_CLK:
368 tm6000_ir_wait(dev, 0);
369
364 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 370 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
365 0x02, arg); 371 0x02, arg);
366 msleep(10); 372 msleep(10);
@@ -410,13 +416,14 @@ int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
410 msleep(130); 416 msleep(130);
411 break; 417 break;
412 } 418 }
419
420 tm6000_ir_wait(dev, 1);
413 break; 421 break;
414 case 1: 422 case 1:
415 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 423 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
416 0x02, 0x01); 424 0x02, 0x01);
417 msleep(10); 425 msleep(10);
418 break; 426 break;
419
420 case 2: 427 case 2:
421 rc = tm6000_i2c_reset(dev, 100); 428 rc = tm6000_i2c_reset(dev, 100);
422 break; 429 break;
@@ -636,6 +643,8 @@ static int tm6000_init_dev(struct tm6000_core *dev)
636 643
637 dev->gpio = tm6000_boards[dev->model].gpio; 644 dev->gpio = tm6000_boards[dev->model].gpio;
638 645
646 dev->ir_codes = tm6000_boards[dev->model].ir_codes;
647
639 dev->demod_addr = tm6000_boards[dev->model].demod_addr; 648 dev->demod_addr = tm6000_boards[dev->model].demod_addr;
640 649
641 dev->caps = tm6000_boards[dev->model].caps; 650 dev->caps = tm6000_boards[dev->model].caps;
@@ -684,6 +693,8 @@ static int tm6000_init_dev(struct tm6000_core *dev)
684 tm6000_add_into_devlist(dev); 693 tm6000_add_into_devlist(dev);
685 tm6000_init_extension(dev); 694 tm6000_init_extension(dev);
686 695
696 tm6000_ir_init(dev);
697
687 mutex_unlock(&dev->lock); 698 mutex_unlock(&dev->lock);
688 return 0; 699 return 0;
689 700
@@ -829,6 +840,19 @@ static int tm6000_usb_probe(struct usb_interface *interface,
829 &dev->isoc_out); 840 &dev->isoc_out);
830 } 841 }
831 break; 842 break;
843 case USB_ENDPOINT_XFER_INT:
844 if (!dir_out) {
845 get_max_endpoint(usbdev,
846 &interface->altsetting[i],
847 "INT IN", e,
848 &dev->int_in);
849 } else {
850 get_max_endpoint(usbdev,
851 &interface->altsetting[i],
852 "INT OUT", e,
853 &dev->int_out);
854 }
855 break;
832 } 856 }
833 } 857 }
834 } 858 }
@@ -887,6 +911,8 @@ static void tm6000_usb_disconnect(struct usb_interface *interface)
887 911
888 mutex_lock(&dev->lock); 912 mutex_lock(&dev->lock);
889 913
914 tm6000_ir_fini(dev);
915
890 if (dev->gpio.power_led) { 916 if (dev->gpio.power_led) {
891 switch (dev->model) { 917 switch (dev->model) {
892 case TM6010_BOARD_HAUPPAUGE_900H: 918 case TM6010_BOARD_HAUPPAUGE_900H:
diff --git a/drivers/staging/tm6000/tm6000-input.c b/drivers/staging/tm6000/tm6000-input.c
new file mode 100644
index 00000000000..53336ffee8d
--- /dev/null
+++ b/drivers/staging/tm6000/tm6000-input.c
@@ -0,0 +1,364 @@
1/*
2 tm6000-input.c - driver for TM5600/TM6000/TM6010 USB video capture devices
3
4 Copyright (C) 2010 Stefan Ringel <stefan.ringel@arcor.de>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation version 2
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/delay.h>
23
24#include <linux/input.h>
25#include <linux/usb.h>
26
27#include <media/ir-core.h>
28#include <media/ir-common.h>
29
30#include "tm6000.h"
31#include "tm6000-regs.h"
32
33static unsigned int ir_debug;
34module_param(ir_debug, int, 0644);
35MODULE_PARM_DESC(ir_debug, "enable debug message [IR]");
36
37static unsigned int enable_ir = 1;
38module_param(enable_ir, int, 0644);
39MODULE_PARM_DESC(enable_ir, "enable ir (default is enable");
40
41#undef dprintk
42
43#define dprintk(fmt, arg... ) \
44 if (ir_debug) { \
45 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
46 }
47
48struct tm6000_ir_poll_result {
49 u8 rc_data[4];
50};
51
52struct tm6000_IR {
53 struct tm6000_core *dev;
54 struct ir_input_dev *input;
55 struct ir_input_state ir;
56 char name[32];
57 char phys[32];
58
59 /* poll expernal decoder */
60 int polling;
61 struct delayed_work work;
62 u8 wait:1;
63 struct urb *int_urb;
64 u8 *urb_data;
65 u8 key:1;
66
67 int (*get_key) (struct tm6000_IR *, struct tm6000_ir_poll_result *);
68
69 /* IR device properties */
70 struct ir_dev_props props;
71};
72
73
74void tm6000_ir_wait(struct tm6000_core *dev, u8 state)
75{
76 struct tm6000_IR *ir = dev->ir;
77
78 if (!dev->ir)
79 return;
80
81 if (state)
82 ir->wait = 1;
83 else
84 ir->wait = 0;
85}
86
87
88static int tm6000_ir_config(struct tm6000_IR *ir)
89{
90 struct tm6000_core *dev = ir->dev;
91 u8 buf[10];
92 int rc;
93
94 /* hack */
95 buf[0] = 0xff;
96 buf[1] = 0xff;
97 buf[2] = 0xf2;
98 buf[3] = 0x2b;
99 buf[4] = 0x20;
100 buf[5] = 0x35;
101 buf[6] = 0x60;
102 buf[7] = 0x04;
103 buf[8] = 0xc0;
104 buf[9] = 0x08;
105
106 rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR |
107 USB_RECIP_DEVICE, REQ_00_SET_IR_VALUE, 0, 0, buf, 0x0a);
108 msleep(100);
109
110 if (rc < 0) {
111 printk(KERN_INFO "IR configuration failed");
112 return rc;
113 }
114 return 0;
115}
116
117static void tm6000_ir_urb_received(struct urb *urb)
118{
119 struct tm6000_core *dev = urb->context;
120 struct tm6000_IR *ir = dev->ir;
121 int rc;
122
123 if (urb->status != 0)
124 printk(KERN_INFO "not ready\n");
125 else if (urb->actual_length > 0)
126 memcpy (ir->urb_data, urb->transfer_buffer, urb->actual_length);
127
128 dprintk ("data %02x %02x %02x %02x\n", ir->urb_data[0],
129 ir->urb_data[1], ir->urb_data[2], ir->urb_data[3]);
130
131 ir->key = 1;
132
133 rc = usb_submit_urb(urb, GFP_ATOMIC);
134}
135
136static int default_polling_getkey(struct tm6000_IR *ir,
137 struct tm6000_ir_poll_result *poll_result)
138{
139 struct tm6000_core *dev = ir->dev;
140 int rc;
141 u8 buf[2];
142
143 if(ir->wait && !&dev->int_in) {
144 poll_result->rc_data[0] = 0xff;
145 return 0;
146 }
147
148 if (&dev->int_in) {
149 poll_result->rc_data[0] = ir->urb_data[0];
150 poll_result->rc_data[1] = ir->urb_data[1];
151 } else {
152 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 0);
153 msleep(10);
154 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 1);
155 msleep(10);
156
157 rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR |
158 USB_RECIP_DEVICE, REQ_02_GET_IR_CODE, 0, 0, buf, 1);
159
160 msleep(10);
161
162 dprintk ("read data=%02x\n", buf[0]);
163 if (rc < 0) {
164 return rc;
165 }
166 poll_result->rc_data[0] = buf[0];
167 }
168 return 0;
169}
170
171static void tm6000_ir_handle_key(struct tm6000_IR *ir)
172{
173 int result;
174 struct tm6000_ir_poll_result poll_result;
175
176 /* read the registers containing the IR status */
177 result = ir->get_key(ir, &poll_result);
178 if (result < 0) {
179 printk(KERN_INFO "ir->get_key() failed %d\n", result);
180 return;
181 }
182
183 dprintk("ir->get_key result data=%02x %02x\n",
184 poll_result.rc_data[0], poll_result.rc_data[1]);
185
186 if (poll_result.rc_data[0] != 0xff && ir->key == 1) {
187 ir_input_keydown(ir->input->input_dev, &ir->ir,
188 poll_result.rc_data[0] | poll_result.rc_data[1] << 8);
189
190 ir_input_nokey(ir->input->input_dev, &ir->ir);
191 ir->key = 0;
192 }
193 return;
194}
195
196static void tm6000_ir_work(struct work_struct *work)
197{
198 struct tm6000_IR *ir = container_of(work, struct tm6000_IR, work.work);
199
200 tm6000_ir_handle_key(ir);
201 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
202}
203
204static int tm6000_ir_start(void *priv)
205{
206 struct tm6000_IR *ir = priv;
207
208 INIT_DELAYED_WORK(&ir->work, tm6000_ir_work);
209 schedule_delayed_work(&ir->work, 0);
210
211 return 0;
212}
213
214static void tm6000_ir_stop(void *priv)
215{
216 struct tm6000_IR *ir = priv;
217
218 cancel_delayed_work_sync(&ir->work);
219}
220
221int tm6000_ir_change_protocol(void *priv, u64 ir_type)
222{
223 struct tm6000_IR *ir = priv;
224
225 ir->get_key = default_polling_getkey;
226
227 tm6000_ir_config(ir);
228 /* TODO */
229 return 0;
230}
231
232int tm6000_ir_init(struct tm6000_core *dev)
233{
234 struct tm6000_IR *ir;
235 struct ir_input_dev *ir_input_dev;
236 int err = -ENOMEM;
237 int pipe, size, rc;
238
239 if (!enable_ir)
240 return -ENODEV;
241
242 if (!dev->caps.has_remote)
243 return 0;
244
245 if (!dev->ir_codes)
246 return 0;
247
248 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
249 ir_input_dev = kzalloc(sizeof(*ir_input_dev), GFP_KERNEL);
250 ir_input_dev->input_dev = input_allocate_device();
251 if (!ir || !ir_input_dev || !ir_input_dev->input_dev)
252 goto err_out_free;
253
254 /* record handles to ourself */
255 ir->dev = dev;
256 dev->ir = ir;
257
258 ir->input = ir_input_dev;
259
260 /* input einrichten */
261 ir->props.allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC;
262 ir->props.priv = ir;
263 ir->props.change_protocol = tm6000_ir_change_protocol;
264 ir->props.open = tm6000_ir_start;
265 ir->props.close = tm6000_ir_stop;
266 ir->props.driver_type = RC_DRIVER_SCANCODE;
267
268 ir->polling = 50;
269
270 snprintf(ir->name, sizeof(ir->name), "tm5600/60x0 IR (%s)",
271 dev->name);
272
273 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
274 strlcat(ir->phys, "/input0", sizeof(ir->phys));
275
276 tm6000_ir_change_protocol(ir, IR_TYPE_UNKNOWN);
277 err = ir_input_init(ir_input_dev->input_dev, &ir->ir, IR_TYPE_OTHER);
278 if (err < 0)
279 goto err_out_free;
280
281 ir_input_dev->input_dev->name = ir->name;
282 ir_input_dev->input_dev->phys = ir->phys;
283 ir_input_dev->input_dev->id.bustype = BUS_USB;
284 ir_input_dev->input_dev->id.version = 1;
285 ir_input_dev->input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
286 ir_input_dev->input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
287
288 ir_input_dev->input_dev->dev.parent = &dev->udev->dev;
289
290 if (&dev->int_in) {
291 dprintk("IR over int\n");
292
293 ir->int_urb = usb_alloc_urb(0, GFP_KERNEL);
294
295 pipe = usb_rcvintpipe(dev->udev,
296 dev->int_in.endp->desc.bEndpointAddress
297 & USB_ENDPOINT_NUMBER_MASK);
298
299 size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
300 dprintk("IR max size: %d\n", size);
301
302 ir->int_urb->transfer_buffer = kzalloc(size, GFP_KERNEL);
303 if (ir->int_urb->transfer_buffer == NULL) {
304 usb_free_urb(ir->int_urb);
305 goto err_out_stop;
306 }
307 dprintk("int interval: %d\n", dev->int_in.endp->desc.bInterval);
308 usb_fill_int_urb(ir->int_urb, dev->udev, pipe,
309 ir->int_urb->transfer_buffer, size,
310 tm6000_ir_urb_received, dev,
311 dev->int_in.endp->desc.bInterval);
312 rc = usb_submit_urb(ir->int_urb, GFP_KERNEL);
313 if (rc) {
314 kfree(ir->int_urb->transfer_buffer);
315 usb_free_urb(ir->int_urb);
316 err = rc;
317 goto err_out_stop;
318 }
319 ir->urb_data = kzalloc(size, GFP_KERNEL);
320 }
321
322 /* ir register */
323 err = ir_input_register(ir->input->input_dev, dev->ir_codes,
324 &ir->props, "tm6000");
325 if (err)
326 goto err_out_stop;
327
328 return 0;
329
330err_out_stop:
331 dev->ir = NULL;
332err_out_free:
333 kfree(ir_input_dev);
334 kfree(ir);
335 return err;
336}
337
338int tm6000_ir_fini(struct tm6000_core *dev)
339{
340 struct tm6000_IR *ir = dev->ir;
341
342 /* skip detach on non attached board */
343
344 if (!ir)
345 return 0;
346
347 ir_input_unregister(ir->input->input_dev);
348
349 if (ir->int_urb) {
350 usb_kill_urb(ir->int_urb);
351 kfree(ir->int_urb->transfer_buffer);
352 usb_free_urb(ir->int_urb);
353 ir->int_urb = NULL;
354 kfree(ir->urb_data);
355 ir->urb_data = NULL;
356 }
357
358 kfree(ir->input);
359 ir->input = NULL;
360 kfree(ir);
361 dev->ir = NULL;
362
363 return 0;
364}
diff --git a/drivers/staging/tm6000/tm6000.h b/drivers/staging/tm6000/tm6000.h
index 89862a49520..1ec1bff9b29 100644
--- a/drivers/staging/tm6000/tm6000.h
+++ b/drivers/staging/tm6000/tm6000.h
@@ -171,6 +171,8 @@ struct tm6000_core {
171 171
172 struct tm6000_gpio gpio; 172 struct tm6000_gpio gpio;
173 173
174 char *ir_codes;
175
174 /* Demodulator configuration */ 176 /* Demodulator configuration */
175 int demod_addr; /* demodulator address */ 177 int demod_addr; /* demodulator address */
176 178
@@ -204,6 +206,8 @@ struct tm6000_core {
204 /* audio support */ 206 /* audio support */
205 struct snd_tm6000_card *adev; 207 struct snd_tm6000_card *adev;
206 208
209 struct tm6000_IR *ir;
210
207 /* locks */ 211 /* locks */
208 struct mutex lock; 212 struct mutex lock;
209 213
@@ -211,6 +215,7 @@ struct tm6000_core {
211 struct usb_device *udev; /* the usb device */ 215 struct usb_device *udev; /* the usb device */
212 216
213 struct tm6000_endpoint bulk_in, bulk_out, isoc_in, isoc_out; 217 struct tm6000_endpoint bulk_in, bulk_out, isoc_in, isoc_out;
218 struct tm6000_endpoint int_in, int_out;
214 219
215 /* scaler!=0 if scaler is active*/ 220 /* scaler!=0 if scaler is active*/
216 int scaler; 221 int scaler;
@@ -317,6 +322,10 @@ int tm6000_queue_init(struct tm6000_core *dev);
317/* In tm6000-alsa.c */ 322/* In tm6000-alsa.c */
318/*int tm6000_audio_init(struct tm6000_core *dev, int idx);*/ 323/*int tm6000_audio_init(struct tm6000_core *dev, int idx);*/
319 324
325/* In tm6000-input.c */
326int tm6000_ir_init(struct tm6000_core *dev);
327int tm6000_ir_fini(struct tm6000_core *dev);
328void tm6000_ir_wait(struct tm6000_core *dev, u8 state);
320 329
321/* Debug stuff */ 330/* Debug stuff */
322 331