aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video')
-rw-r--r--drivers/media/video/cafe_ccic.c6
-rw-r--r--drivers/media/video/compat_ioctl32.c5
-rw-r--r--drivers/media/video/cx18/Kconfig2
-rw-r--r--drivers/media/video/cx18/cx18-driver.c17
-rw-r--r--drivers/media/video/cx18/cx18-driver.h20
-rw-r--r--drivers/media/video/cx18/cx18-dvb.c23
-rw-r--r--drivers/media/video/cx18/cx18-dvb.h1
-rw-r--r--drivers/media/video/cx18/cx18-io.c17
-rw-r--r--drivers/media/video/cx18/cx18-io.h17
-rw-r--r--drivers/media/video/cx18/cx18-irq.c96
-rw-r--r--drivers/media/video/cx18/cx18-irq.h4
-rw-r--r--drivers/media/video/cx18/cx18-mailbox.c6
-rw-r--r--drivers/media/video/cx18/cx18-queue.c14
-rw-r--r--drivers/media/video/cx18/cx18-scb.h40
-rw-r--r--drivers/media/video/cx23885/Kconfig4
-rw-r--r--drivers/media/video/cx88/Kconfig2
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c12
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c5
-rw-r--r--drivers/media/video/cx88/cx88-mpeg.c28
-rw-r--r--drivers/media/video/cx88/cx88-video.c10
-rw-r--r--drivers/media/video/cx88/cx88.h1
-rw-r--r--drivers/media/video/em28xx/em28xx-audio.c33
-rw-r--r--drivers/media/video/em28xx/em28xx-core.c58
-rw-r--r--drivers/media/video/em28xx/em28xx-i2c.c10
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c143
-rw-r--r--drivers/media/video/em28xx/em28xx.h6
-rw-r--r--drivers/media/video/gspca/Kconfig144
-rw-r--r--drivers/media/video/gspca/conex.c3
-rw-r--r--drivers/media/video/gspca/finepix.c8
-rw-r--r--drivers/media/video/gspca/gspca.c60
-rw-r--r--drivers/media/video/gspca/gspca.h6
-rw-r--r--drivers/media/video/gspca/pac7311.c3
-rw-r--r--drivers/media/video/gspca/spca501.c3
-rw-r--r--drivers/media/video/gspca/spca505.c4
-rw-r--r--drivers/media/video/gspca/spca561.c3
-rw-r--r--drivers/media/video/gspca/vc032x.c3
-rw-r--r--drivers/media/video/gspca/zc3xx.c15
-rw-r--r--drivers/media/video/ivtv/Kconfig5
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c26
-rw-r--r--drivers/media/video/pvrusb2/Kconfig2
-rw-r--r--drivers/media/video/s2255drv.c2
-rw-r--r--drivers/media/video/saa7110.c4
-rw-r--r--drivers/media/video/saa7134/Kconfig4
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c3
-rw-r--r--drivers/media/video/tvaudio.c231
-rw-r--r--drivers/media/video/usbvideo/ibmcam.c12
46 files changed, 686 insertions, 435 deletions
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index a8c068e1de1c..1740b9ebdcef 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -1476,12 +1476,9 @@ static int cafe_v4l_open(struct inode *inode, struct file *filp)
1476{ 1476{
1477 struct cafe_camera *cam; 1477 struct cafe_camera *cam;
1478 1478
1479 lock_kernel();
1480 cam = cafe_find_dev(iminor(inode)); 1479 cam = cafe_find_dev(iminor(inode));
1481 if (cam == NULL) { 1480 if (cam == NULL)
1482 unlock_kernel();
1483 return -ENODEV; 1481 return -ENODEV;
1484 }
1485 filp->private_data = cam; 1482 filp->private_data = cam;
1486 1483
1487 mutex_lock(&cam->s_mutex); 1484 mutex_lock(&cam->s_mutex);
@@ -1493,7 +1490,6 @@ static int cafe_v4l_open(struct inode *inode, struct file *filp)
1493 } 1490 }
1494 (cam->users)++; 1491 (cam->users)++;
1495 mutex_unlock(&cam->s_mutex); 1492 mutex_unlock(&cam->s_mutex);
1496 unlock_kernel();
1497 return 0; 1493 return 0;
1498} 1494}
1499 1495
diff --git a/drivers/media/video/compat_ioctl32.c b/drivers/media/video/compat_ioctl32.c
index bd5d9de5a008..0ea85a05e5c0 100644
--- a/drivers/media/video/compat_ioctl32.c
+++ b/drivers/media/video/compat_ioctl32.c
@@ -831,7 +831,7 @@ long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
831{ 831{
832 int ret = -ENOIOCTLCMD; 832 int ret = -ENOIOCTLCMD;
833 833
834 if (!file->f_op->ioctl) 834 if (!file->f_op->ioctl && !file->f_op->unlocked_ioctl)
835 return ret; 835 return ret;
836 836
837 switch (cmd) { 837 switch (cmd) {
@@ -867,6 +867,7 @@ long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
867 case VIDIOC_STREAMON32: 867 case VIDIOC_STREAMON32:
868 case VIDIOC_STREAMOFF32: 868 case VIDIOC_STREAMOFF32:
869 case VIDIOC_G_PARM: 869 case VIDIOC_G_PARM:
870 case VIDIOC_S_PARM:
870 case VIDIOC_G_STD: 871 case VIDIOC_G_STD:
871 case VIDIOC_S_STD: 872 case VIDIOC_S_STD:
872 case VIDIOC_G_TUNER: 873 case VIDIOC_G_TUNER:
@@ -885,6 +886,8 @@ long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
885 case VIDIOC_S_INPUT32: 886 case VIDIOC_S_INPUT32:
886 case VIDIOC_TRY_FMT32: 887 case VIDIOC_TRY_FMT32:
887 case VIDIOC_S_HW_FREQ_SEEK: 888 case VIDIOC_S_HW_FREQ_SEEK:
889 case VIDIOC_ENUM_FRAMESIZES:
890 case VIDIOC_ENUM_FRAMEINTERVALS:
888 ret = do_video_ioctl(file, cmd, arg); 891 ret = do_video_ioctl(file, cmd, arg);
889 break; 892 break;
890 893
diff --git a/drivers/media/video/cx18/Kconfig b/drivers/media/video/cx18/Kconfig
index ef48565de7f1..8940b5387dec 100644
--- a/drivers/media/video/cx18/Kconfig
+++ b/drivers/media/video/cx18/Kconfig
@@ -9,7 +9,7 @@ config VIDEO_CX18
9 select VIDEO_CX2341X 9 select VIDEO_CX2341X
10 select VIDEO_CS5345 10 select VIDEO_CS5345
11 select DVB_S5H1409 if !DVB_FE_CUSTOMISE 11 select DVB_S5H1409 if !DVB_FE_CUSTOMISE
12 select MEDIA_TUNER_MXL5005S if !DVB_FE_CUSTOMISE 12 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMIZE
13 ---help--- 13 ---help---
14 This is a video4linux driver for Conexant cx23418 based 14 This is a video4linux driver for Conexant cx23418 based
15 PCI combo video recorder devices. 15 PCI combo video recorder devices.
diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
index 7a1a7830a6b3..7874d9790a51 100644
--- a/drivers/media/video/cx18/cx18-driver.c
+++ b/drivers/media/video/cx18/cx18-driver.c
@@ -448,7 +448,14 @@ static int __devinit cx18_init_struct1(struct cx18 *cx)
448 mutex_init(&cx->gpio_lock); 448 mutex_init(&cx->gpio_lock);
449 449
450 spin_lock_init(&cx->lock); 450 spin_lock_init(&cx->lock);
451 spin_lock_init(&cx->dma_reg_lock); 451
452 cx->work_queue = create_singlethread_workqueue(cx->name);
453 if (cx->work_queue == NULL) {
454 CX18_ERR("Could not create work queue\n");
455 return -1;
456 }
457
458 INIT_WORK(&cx->work, cx18_work_handler);
452 459
453 /* start counting open_id at 1 */ 460 /* start counting open_id at 1 */
454 cx->open_id = 1; 461 cx->open_id = 1;
@@ -581,10 +588,10 @@ static void cx18_load_and_init_modules(struct cx18 *cx)
581 588
582#ifdef MODULE 589#ifdef MODULE
583 /* load modules */ 590 /* load modules */
584#ifndef CONFIG_MEDIA_TUNER 591#ifdef CONFIG_MEDIA_TUNER_MODULE
585 hw = cx18_request_module(cx, hw, "tuner", CX18_HW_TUNER); 592 hw = cx18_request_module(cx, hw, "tuner", CX18_HW_TUNER);
586#endif 593#endif
587#ifndef CONFIG_VIDEO_CS5345 594#ifdef CONFIG_VIDEO_CS5345_MODULE
588 hw = cx18_request_module(cx, hw, "cs5345", CX18_HW_CS5345); 595 hw = cx18_request_module(cx, hw, "cs5345", CX18_HW_CS5345);
589#endif 596#endif
590#endif 597#endif
@@ -832,6 +839,7 @@ free_map:
832free_mem: 839free_mem:
833 release_mem_region(cx->base_addr, CX18_MEM_SIZE); 840 release_mem_region(cx->base_addr, CX18_MEM_SIZE);
834free_workqueue: 841free_workqueue:
842 destroy_workqueue(cx->work_queue);
835err: 843err:
836 if (retval == 0) 844 if (retval == 0)
837 retval = -ENODEV; 845 retval = -ENODEV;
@@ -932,6 +940,9 @@ static void cx18_remove(struct pci_dev *pci_dev)
932 940
933 cx18_halt_firmware(cx); 941 cx18_halt_firmware(cx);
934 942
943 flush_workqueue(cx->work_queue);
944 destroy_workqueue(cx->work_queue);
945
935 cx18_streams_cleanup(cx, 1); 946 cx18_streams_cleanup(cx, 1);
936 947
937 exit_cx18_i2c(cx); 948 exit_cx18_i2c(cx);
diff --git a/drivers/media/video/cx18/cx18-driver.h b/drivers/media/video/cx18/cx18-driver.h
index a4b1708fafe7..bbdd5f25041d 100644
--- a/drivers/media/video/cx18/cx18-driver.h
+++ b/drivers/media/video/cx18/cx18-driver.h
@@ -199,12 +199,15 @@ struct cx18_options {
199#define CX18_F_S_APPL_IO 8 /* this stream is used read/written by an application */ 199#define CX18_F_S_APPL_IO 8 /* this stream is used read/written by an application */
200 200
201/* per-cx18, i_flags */ 201/* per-cx18, i_flags */
202#define CX18_F_I_LOADED_FW 0 /* Loaded the firmware the first time */ 202#define CX18_F_I_LOADED_FW 0 /* Loaded firmware 1st time */
203#define CX18_F_I_EOS 4 /* End of encoder stream reached */ 203#define CX18_F_I_EOS 4 /* End of encoder stream */
204#define CX18_F_I_RADIO_USER 5 /* The radio tuner is selected */ 204#define CX18_F_I_RADIO_USER 5 /* radio tuner is selected */
205#define CX18_F_I_ENC_PAUSED 13 /* the encoder is paused */ 205#define CX18_F_I_ENC_PAUSED 13 /* the encoder is paused */
206#define CX18_F_I_INITED 21 /* set after first open */ 206#define CX18_F_I_HAVE_WORK 15 /* there is work to be done */
207#define CX18_F_I_FAILED 22 /* set if first open failed */ 207#define CX18_F_I_WORK_HANDLER_DVB 18 /* work to be done for DVB */
208#define CX18_F_I_INITED 21 /* set after first open */
209#define CX18_F_I_FAILED 22 /* set if first open failed */
210#define CX18_F_I_WORK_INITED 23 /* worker thread initialized */
208 211
209/* These are the VBI types as they appear in the embedded VBI private packets. */ 212/* These are the VBI types as they appear in the embedded VBI private packets. */
210#define CX18_SLICED_TYPE_TELETEXT_B (1) 213#define CX18_SLICED_TYPE_TELETEXT_B (1)
@@ -402,8 +405,6 @@ struct cx18 {
402 spinlock_t lock; /* lock access to this struct */ 405 spinlock_t lock; /* lock access to this struct */
403 int search_pack_header; 406 int search_pack_header;
404 407
405 spinlock_t dma_reg_lock; /* lock access to DMA engine registers */
406
407 int open_id; /* incremented each time an open occurs, used as 408 int open_id; /* incremented each time an open occurs, used as
408 unique ID. Starts at 1, so 0 can be used as 409 unique ID. Starts at 1, so 0 can be used as
409 uninitialized value in the stream->id. */ 410 uninitialized value in the stream->id. */
@@ -433,6 +434,9 @@ struct cx18 {
433 /* when the current DMA is finished this queue is woken up */ 434 /* when the current DMA is finished this queue is woken up */
434 wait_queue_head_t dma_waitq; 435 wait_queue_head_t dma_waitq;
435 436
437 struct workqueue_struct *work_queue;
438 struct work_struct work;
439
436 /* i2c */ 440 /* i2c */
437 struct i2c_adapter i2c_adap[2]; 441 struct i2c_adapter i2c_adap[2];
438 struct i2c_algo_bit_data i2c_algo[2]; 442 struct i2c_algo_bit_data i2c_algo[2];
diff --git a/drivers/media/video/cx18/cx18-dvb.c b/drivers/media/video/cx18/cx18-dvb.c
index afc694e7bdb2..4542e2e5e3d7 100644
--- a/drivers/media/video/cx18/cx18-dvb.c
+++ b/drivers/media/video/cx18/cx18-dvb.c
@@ -23,6 +23,8 @@
23#include "cx18-dvb.h" 23#include "cx18-dvb.h"
24#include "cx18-io.h" 24#include "cx18-io.h"
25#include "cx18-streams.h" 25#include "cx18-streams.h"
26#include "cx18-queue.h"
27#include "cx18-scb.h"
26#include "cx18-cards.h" 28#include "cx18-cards.h"
27#include "s5h1409.h" 29#include "s5h1409.h"
28#include "mxl5005s.h" 30#include "mxl5005s.h"
@@ -300,3 +302,24 @@ static int dvb_register(struct cx18_stream *stream)
300 302
301 return ret; 303 return ret;
302} 304}
305
306void cx18_dvb_work_handler(struct cx18 *cx)
307{
308 struct cx18_buffer *buf;
309 struct cx18_stream *s = &cx->streams[CX18_ENC_STREAM_TYPE_TS];
310
311 while ((buf = cx18_dequeue(s, &s->q_full)) != NULL) {
312 if (s->dvb.enabled)
313 dvb_dmx_swfilter(&s->dvb.demux, buf->buf,
314 buf->bytesused);
315
316 cx18_enqueue(s, buf, &s->q_free);
317 cx18_buf_sync_for_device(s, buf);
318 if (s->handle == CX18_INVALID_TASK_HANDLE) /* FIXME: improve */
319 continue;
320
321 cx18_vapi(cx, CX18_CPU_DE_SET_MDL, 5, s->handle,
322 (void __iomem *)&cx->scb->cpu_mdl[buf->id] - cx->enc_mem,
323 1, buf->id, s->buf_size);
324 }
325}
diff --git a/drivers/media/video/cx18/cx18-dvb.h b/drivers/media/video/cx18/cx18-dvb.h
index bf8d8f6f5455..bbdcefc87f28 100644
--- a/drivers/media/video/cx18/cx18-dvb.h
+++ b/drivers/media/video/cx18/cx18-dvb.h
@@ -23,3 +23,4 @@
23 23
24int cx18_dvb_register(struct cx18_stream *stream); 24int cx18_dvb_register(struct cx18_stream *stream);
25void cx18_dvb_unregister(struct cx18_stream *stream); 25void cx18_dvb_unregister(struct cx18_stream *stream);
26void cx18_dvb_work_handler(struct cx18 *cx);
diff --git a/drivers/media/video/cx18/cx18-io.c b/drivers/media/video/cx18/cx18-io.c
index 700ab9439c16..220fae8d4ad7 100644
--- a/drivers/media/video/cx18/cx18-io.c
+++ b/drivers/media/video/cx18/cx18-io.c
@@ -88,6 +88,19 @@ void cx18_writel_retry(struct cx18 *cx, u32 val, void __iomem *addr)
88 cx18_log_write_retries(cx, i, addr); 88 cx18_log_write_retries(cx, i, addr);
89} 89}
90 90
91void _cx18_writel_expect(struct cx18 *cx, u32 val, void __iomem *addr,
92 u32 eval, u32 mask)
93{
94 int i;
95 eval &= mask;
96 for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
97 cx18_writel_noretry(cx, val, addr);
98 if (eval == (cx18_readl_noretry(cx, addr) & mask))
99 break;
100 }
101 cx18_log_write_retries(cx, i, addr);
102}
103
91void cx18_writew_retry(struct cx18 *cx, u16 val, void __iomem *addr) 104void cx18_writew_retry(struct cx18 *cx, u16 val, void __iomem *addr)
92{ 105{
93 int i; 106 int i;
@@ -218,7 +231,7 @@ void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count)
218void cx18_sw1_irq_enable(struct cx18 *cx, u32 val) 231void cx18_sw1_irq_enable(struct cx18 *cx, u32 val)
219{ 232{
220 u32 r; 233 u32 r;
221 cx18_write_reg(cx, val, SW1_INT_STATUS); 234 cx18_write_reg_expect(cx, val, SW1_INT_STATUS, ~val, val);
222 r = cx18_read_reg(cx, SW1_INT_ENABLE_PCI); 235 r = cx18_read_reg(cx, SW1_INT_ENABLE_PCI);
223 cx18_write_reg(cx, r | val, SW1_INT_ENABLE_PCI); 236 cx18_write_reg(cx, r | val, SW1_INT_ENABLE_PCI);
224} 237}
@@ -233,7 +246,7 @@ void cx18_sw1_irq_disable(struct cx18 *cx, u32 val)
233void cx18_sw2_irq_enable(struct cx18 *cx, u32 val) 246void cx18_sw2_irq_enable(struct cx18 *cx, u32 val)
234{ 247{
235 u32 r; 248 u32 r;
236 cx18_write_reg(cx, val, SW2_INT_STATUS); 249 cx18_write_reg_expect(cx, val, SW2_INT_STATUS, ~val, val);
237 r = cx18_read_reg(cx, SW2_INT_ENABLE_PCI); 250 r = cx18_read_reg(cx, SW2_INT_ENABLE_PCI);
238 cx18_write_reg(cx, r | val, SW2_INT_ENABLE_PCI); 251 cx18_write_reg(cx, r | val, SW2_INT_ENABLE_PCI);
239} 252}
diff --git a/drivers/media/video/cx18/cx18-io.h b/drivers/media/video/cx18/cx18-io.h
index 287a5e8bf67b..425244453ea7 100644
--- a/drivers/media/video/cx18/cx18-io.h
+++ b/drivers/media/video/cx18/cx18-io.h
@@ -133,6 +133,8 @@ static inline void cx18_writel(struct cx18 *cx, u32 val, void __iomem *addr)
133 cx18_writel_noretry(cx, val, addr); 133 cx18_writel_noretry(cx, val, addr);
134} 134}
135 135
136void _cx18_writel_expect(struct cx18 *cx, u32 val, void __iomem *addr,
137 u32 eval, u32 mask);
136 138
137static inline 139static inline
138void cx18_writew_noretry(struct cx18 *cx, u16 val, void __iomem *addr) 140void cx18_writew_noretry(struct cx18 *cx, u16 val, void __iomem *addr)
@@ -271,6 +273,21 @@ static inline void cx18_write_reg(struct cx18 *cx, u32 val, u32 reg)
271 cx18_write_reg_noretry(cx, val, reg); 273 cx18_write_reg_noretry(cx, val, reg);
272} 274}
273 275
276static inline void _cx18_write_reg_expect(struct cx18 *cx, u32 val, u32 reg,
277 u32 eval, u32 mask)
278{
279 _cx18_writel_expect(cx, val, cx->reg_mem + reg, eval, mask);
280}
281
282static inline void cx18_write_reg_expect(struct cx18 *cx, u32 val, u32 reg,
283 u32 eval, u32 mask)
284{
285 if (cx18_retry_mmio)
286 _cx18_write_reg_expect(cx, val, reg, eval, mask);
287 else
288 cx18_write_reg_noretry(cx, val, reg);
289}
290
274 291
275static inline u32 cx18_read_reg_noretry(struct cx18 *cx, u32 reg) 292static inline u32 cx18_read_reg_noretry(struct cx18 *cx, u32 reg)
276{ 293{
diff --git a/drivers/media/video/cx18/cx18-irq.c b/drivers/media/video/cx18/cx18-irq.c
index 360330f5463f..5fbfbd0f1493 100644
--- a/drivers/media/video/cx18/cx18-irq.c
+++ b/drivers/media/video/cx18/cx18-irq.c
@@ -29,8 +29,20 @@
29#include "cx18-mailbox.h" 29#include "cx18-mailbox.h"
30#include "cx18-vbi.h" 30#include "cx18-vbi.h"
31#include "cx18-scb.h" 31#include "cx18-scb.h"
32#include "cx18-dvb.h"
32 33
33#define DMA_MAGIC_COOKIE 0x000001fe 34void cx18_work_handler(struct work_struct *work)
35{
36 struct cx18 *cx = container_of(work, struct cx18, work);
37 if (test_and_clear_bit(CX18_F_I_WORK_INITED, &cx->i_flags)) {
38 struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
39 /* This thread must use the FIFO scheduler as it
40 * is realtime sensitive. */
41 sched_setscheduler(current, SCHED_FIFO, &param);
42 }
43 if (test_and_clear_bit(CX18_F_I_WORK_HANDLER_DVB, &cx->i_flags))
44 cx18_dvb_work_handler(cx);
45}
34 46
35static void epu_dma_done(struct cx18 *cx, struct cx18_mailbox *mb) 47static void epu_dma_done(struct cx18 *cx, struct cx18_mailbox *mb)
36{ 48{
@@ -67,17 +79,11 @@ static void epu_dma_done(struct cx18 *cx, struct cx18_mailbox *mb)
67 if (buf) { 79 if (buf) {
68 cx18_buf_sync_for_cpu(s, buf); 80 cx18_buf_sync_for_cpu(s, buf);
69 if (s->type == CX18_ENC_STREAM_TYPE_TS && s->dvb.enabled) { 81 if (s->type == CX18_ENC_STREAM_TYPE_TS && s->dvb.enabled) {
70 /* process the buffer here */ 82 CX18_DEBUG_HI_DMA("TS recv bytesused = %d\n",
71 CX18_DEBUG_HI_DMA("TS recv and sent bytesused=%d\n",
72 buf->bytesused);
73
74 dvb_dmx_swfilter(&s->dvb.demux, buf->buf,
75 buf->bytesused); 83 buf->bytesused);
76 84
77 cx18_buf_sync_for_device(s, buf); 85 set_bit(CX18_F_I_WORK_HANDLER_DVB, &cx->i_flags);
78 cx18_vapi(cx, CX18_CPU_DE_SET_MDL, 5, s->handle, 86 set_bit(CX18_F_I_HAVE_WORK, &cx->i_flags);
79 (void __iomem *)&cx->scb->cpu_mdl[buf->id] - cx->enc_mem,
80 1, buf->id, s->buf_size);
81 } else 87 } else
82 set_bit(CX18_F_B_NEED_BUF_SWAP, &buf->b_flags); 88 set_bit(CX18_F_B_NEED_BUF_SWAP, &buf->b_flags);
83 } else { 89 } else {
@@ -109,7 +115,7 @@ static void epu_debug(struct cx18 *cx, struct cx18_mailbox *mb)
109 CX18_INFO("FW version: %s\n", p - 1); 115 CX18_INFO("FW version: %s\n", p - 1);
110} 116}
111 117
112static void hpu_cmd(struct cx18 *cx, u32 sw1) 118static void epu_cmd(struct cx18 *cx, u32 sw1)
113{ 119{
114 struct cx18_mailbox mb; 120 struct cx18_mailbox mb;
115 121
@@ -125,12 +131,31 @@ static void hpu_cmd(struct cx18 *cx, u32 sw1)
125 epu_debug(cx, &mb); 131 epu_debug(cx, &mb);
126 break; 132 break;
127 default: 133 default:
128 CX18_WARN("Unexpected mailbox command %08x\n", mb.cmd); 134 CX18_WARN("Unknown CPU_TO_EPU mailbox command %#08x\n",
135 mb.cmd);
129 break; 136 break;
130 } 137 }
131 } 138 }
132 if (sw1 & (IRQ_APU_TO_EPU | IRQ_HPU_TO_EPU)) 139
133 CX18_WARN("Unexpected interrupt %08x\n", sw1); 140 if (sw1 & IRQ_APU_TO_EPU) {
141 cx18_memcpy_fromio(cx, &mb, &cx->scb->apu2epu_mb, sizeof(mb));
142 CX18_WARN("Unknown APU_TO_EPU mailbox command %#08x\n", mb.cmd);
143 }
144
145 if (sw1 & IRQ_HPU_TO_EPU) {
146 cx18_memcpy_fromio(cx, &mb, &cx->scb->hpu2epu_mb, sizeof(mb));
147 CX18_WARN("Unknown HPU_TO_EPU mailbox command %#08x\n", mb.cmd);
148 }
149}
150
151static void xpu_ack(struct cx18 *cx, u32 sw2)
152{
153 if (sw2 & IRQ_CPU_TO_EPU_ACK)
154 wake_up(&cx->mb_cpu_waitq);
155 if (sw2 & IRQ_APU_TO_EPU_ACK)
156 wake_up(&cx->mb_apu_waitq);
157 if (sw2 & IRQ_HPU_TO_EPU_ACK)
158 wake_up(&cx->mb_hpu_waitq);
134} 159}
135 160
136irqreturn_t cx18_irq_handler(int irq, void *dev_id) 161irqreturn_t cx18_irq_handler(int irq, void *dev_id)
@@ -140,43 +165,36 @@ irqreturn_t cx18_irq_handler(int irq, void *dev_id)
140 u32 sw2, sw2_mask; 165 u32 sw2, sw2_mask;
141 u32 hw2, hw2_mask; 166 u32 hw2, hw2_mask;
142 167
143 spin_lock(&cx->dma_reg_lock); 168 sw1_mask = cx18_read_reg(cx, SW1_INT_ENABLE_PCI);
144 169 sw1 = cx18_read_reg(cx, SW1_INT_STATUS) & sw1_mask;
170 sw2_mask = cx18_read_reg(cx, SW2_INT_ENABLE_PCI);
171 sw2 = cx18_read_reg(cx, SW2_INT_STATUS) & sw2_mask;
145 hw2_mask = cx18_read_reg(cx, HW2_INT_MASK5_PCI); 172 hw2_mask = cx18_read_reg(cx, HW2_INT_MASK5_PCI);
146 hw2 = cx18_read_reg(cx, HW2_INT_CLR_STATUS) & hw2_mask; 173 hw2 = cx18_read_reg(cx, HW2_INT_CLR_STATUS) & hw2_mask;
147 sw2_mask = cx18_read_reg(cx, SW2_INT_ENABLE_PCI) | IRQ_EPU_TO_HPU_ACK;
148 sw2 = cx18_read_reg(cx, SW2_INT_STATUS) & sw2_mask;
149 sw1_mask = cx18_read_reg(cx, SW1_INT_ENABLE_PCI) | IRQ_EPU_TO_HPU;
150 sw1 = cx18_read_reg(cx, SW1_INT_STATUS) & sw1_mask;
151 174
152 cx18_write_reg(cx, sw2&sw2_mask, SW2_INT_STATUS); 175 if (sw1)
153 cx18_write_reg(cx, sw1&sw1_mask, SW1_INT_STATUS); 176 cx18_write_reg_expect(cx, sw1, SW1_INT_STATUS, ~sw1, sw1);
154 cx18_write_reg(cx, hw2&hw2_mask, HW2_INT_CLR_STATUS); 177 if (sw2)
178 cx18_write_reg_expect(cx, sw2, SW2_INT_STATUS, ~sw2, sw2);
179 if (hw2)
180 cx18_write_reg_expect(cx, hw2, HW2_INT_CLR_STATUS, ~hw2, hw2);
155 181
156 if (sw1 || sw2 || hw2) 182 if (sw1 || sw2 || hw2)
157 CX18_DEBUG_HI_IRQ("SW1: %x SW2: %x HW2: %x\n", sw1, sw2, hw2); 183 CX18_DEBUG_HI_IRQ("SW1: %x SW2: %x HW2: %x\n", sw1, sw2, hw2);
158 184
159 /* To do: interrupt-based I2C handling 185 /* To do: interrupt-based I2C handling
160 if (hw2 & 0x00c00000) { 186 if (hw2 & (HW2_I2C1_INT|HW2_I2C2_INT)) {
161 } 187 }
162 */ 188 */
163 189
164 if (sw2) { 190 if (sw2)
165 if (sw2 & (cx18_readl(cx, &cx->scb->cpu2hpu_irq_ack) | 191 xpu_ack(cx, sw2);
166 cx18_readl(cx, &cx->scb->cpu2epu_irq_ack)))
167 wake_up(&cx->mb_cpu_waitq);
168 if (sw2 & (cx18_readl(cx, &cx->scb->apu2hpu_irq_ack) |
169 cx18_readl(cx, &cx->scb->apu2epu_irq_ack)))
170 wake_up(&cx->mb_apu_waitq);
171 if (sw2 & cx18_readl(cx, &cx->scb->epu2hpu_irq_ack))
172 wake_up(&cx->mb_epu_waitq);
173 if (sw2 & cx18_readl(cx, &cx->scb->hpu2epu_irq_ack))
174 wake_up(&cx->mb_hpu_waitq);
175 }
176 192
177 if (sw1) 193 if (sw1)
178 hpu_cmd(cx, sw1); 194 epu_cmd(cx, sw1);
179 spin_unlock(&cx->dma_reg_lock); 195
196 if (test_and_clear_bit(CX18_F_I_HAVE_WORK, &cx->i_flags))
197 queue_work(cx->work_queue, &cx->work);
180 198
181 return (hw2 | sw1 | sw2) ? IRQ_HANDLED : IRQ_NONE; 199 return (sw1 || sw2 || hw2) ? IRQ_HANDLED : IRQ_NONE;
182} 200}
diff --git a/drivers/media/video/cx18/cx18-irq.h b/drivers/media/video/cx18/cx18-irq.h
index 379f704f5cba..6173ca3bc9e4 100644
--- a/drivers/media/video/cx18/cx18-irq.h
+++ b/drivers/media/video/cx18/cx18-irq.h
@@ -32,6 +32,4 @@
32 32
33irqreturn_t cx18_irq_handler(int irq, void *dev_id); 33irqreturn_t cx18_irq_handler(int irq, void *dev_id);
34 34
35void cx18_irq_work_handler(struct work_struct *work); 35void cx18_work_handler(struct work_struct *work);
36void cx18_dma_stream_dec_prepare(struct cx18_stream *s, u32 offset, int lock);
37void cx18_unfinished_dma(unsigned long arg);
diff --git a/drivers/media/video/cx18/cx18-mailbox.c b/drivers/media/video/cx18/cx18-mailbox.c
index 9d18dd22de76..acff7dfb60df 100644
--- a/drivers/media/video/cx18/cx18-mailbox.c
+++ b/drivers/media/video/cx18/cx18-mailbox.c
@@ -83,7 +83,7 @@ static const struct cx18_api_info api_info[] = {
83 API_ENTRY(CPU, CX18_CPU_DE_SET_MDL_ACK, 0), 83 API_ENTRY(CPU, CX18_CPU_DE_SET_MDL_ACK, 0),
84 API_ENTRY(CPU, CX18_CPU_DE_SET_MDL, API_FAST), 84 API_ENTRY(CPU, CX18_CPU_DE_SET_MDL, API_FAST),
85 API_ENTRY(CPU, CX18_APU_RESETAI, API_FAST), 85 API_ENTRY(CPU, CX18_APU_RESETAI, API_FAST),
86 API_ENTRY(CPU, CX18_CPU_DE_RELEASE_MDL, 0), 86 API_ENTRY(CPU, CX18_CPU_DE_RELEASE_MDL, API_SLOW),
87 API_ENTRY(0, 0, 0), 87 API_ENTRY(0, 0, 0),
88}; 88};
89 89
@@ -176,7 +176,7 @@ long cx18_mb_ack(struct cx18 *cx, const struct cx18_mailbox *mb)
176 176
177 cx18_setup_page(cx, SCB_OFFSET); 177 cx18_setup_page(cx, SCB_OFFSET);
178 cx18_write_sync(cx, mb->request, &ack_mb->ack); 178 cx18_write_sync(cx, mb->request, &ack_mb->ack);
179 cx18_write_reg(cx, ack_irq, SW2_INT_SET); 179 cx18_write_reg_expect(cx, ack_irq, SW2_INT_SET, ack_irq, ack_irq);
180 return 0; 180 return 0;
181} 181}
182 182
@@ -225,7 +225,7 @@ static int cx18_api_call(struct cx18 *cx, u32 cmd, int args, u32 data[])
225 } 225 }
226 if (info->flags & API_FAST) 226 if (info->flags & API_FAST)
227 timeout /= 2; 227 timeout /= 2;
228 cx18_write_reg(cx, irq, SW1_INT_SET); 228 cx18_write_reg_expect(cx, irq, SW1_INT_SET, irq, irq);
229 229
230 while (!sig && cx18_readl(cx, &mb->ack) != cx18_readl(cx, &mb->request) 230 while (!sig && cx18_readl(cx, &mb->ack) != cx18_readl(cx, &mb->request)
231 && cnt < 660) { 231 && cnt < 660) {
diff --git a/drivers/media/video/cx18/cx18-queue.c b/drivers/media/video/cx18/cx18-queue.c
index a33ba04a2686..174682c2582f 100644
--- a/drivers/media/video/cx18/cx18-queue.c
+++ b/drivers/media/video/cx18/cx18-queue.c
@@ -88,15 +88,13 @@ struct cx18_buffer *cx18_queue_get_buf_irq(struct cx18_stream *s, u32 id,
88 88
89 if (buf->id != id) 89 if (buf->id != id)
90 continue; 90 continue;
91
91 buf->bytesused = bytesused; 92 buf->bytesused = bytesused;
92 /* the transport buffers are handled differently, 93 atomic_dec(&s->q_free.buffers);
93 they are not moved to the full queue */ 94 atomic_inc(&s->q_full.buffers);
94 if (s->type != CX18_ENC_STREAM_TYPE_TS) { 95 s->q_full.bytesused += buf->bytesused;
95 atomic_dec(&s->q_free.buffers); 96 list_move_tail(&buf->list, &s->q_full.list);
96 atomic_inc(&s->q_full.buffers); 97
97 s->q_full.bytesused += buf->bytesused;
98 list_move_tail(&buf->list, &s->q_full.list);
99 }
100 spin_unlock(&s->qlock); 98 spin_unlock(&s->qlock);
101 return buf; 99 return buf;
102 } 100 }
diff --git a/drivers/media/video/cx18/cx18-scb.h b/drivers/media/video/cx18/cx18-scb.h
index 86b4cb15d163..594713bbed68 100644
--- a/drivers/media/video/cx18/cx18-scb.h
+++ b/drivers/media/video/cx18/cx18-scb.h
@@ -128,22 +128,22 @@ struct cx18_scb {
128 u32 apu2cpu_irq; 128 u32 apu2cpu_irq;
129 /* Value to write to register SW2 register set (0xC7003140) after the 129 /* Value to write to register SW2 register set (0xC7003140) after the
130 command is cleared */ 130 command is cleared */
131 u32 apu2cpu_irq_ack; 131 u32 cpu2apu_irq_ack;
132 u32 reserved2[13]; 132 u32 reserved2[13];
133 133
134 u32 hpu2cpu_mb_offset; 134 u32 hpu2cpu_mb_offset;
135 u32 hpu2cpu_irq; 135 u32 hpu2cpu_irq;
136 u32 hpu2cpu_irq_ack; 136 u32 cpu2hpu_irq_ack;
137 u32 reserved3[13]; 137 u32 reserved3[13];
138 138
139 u32 ppu2cpu_mb_offset; 139 u32 ppu2cpu_mb_offset;
140 u32 ppu2cpu_irq; 140 u32 ppu2cpu_irq;
141 u32 ppu2cpu_irq_ack; 141 u32 cpu2ppu_irq_ack;
142 u32 reserved4[13]; 142 u32 reserved4[13];
143 143
144 u32 epu2cpu_mb_offset; 144 u32 epu2cpu_mb_offset;
145 u32 epu2cpu_irq; 145 u32 epu2cpu_irq;
146 u32 epu2cpu_irq_ack; 146 u32 cpu2epu_irq_ack;
147 u32 reserved5[13]; 147 u32 reserved5[13];
148 u32 reserved6[8]; 148 u32 reserved6[8];
149 149
@@ -153,22 +153,22 @@ struct cx18_scb {
153 u32 reserved11[7]; 153 u32 reserved11[7];
154 u32 cpu2apu_mb_offset; 154 u32 cpu2apu_mb_offset;
155 u32 cpu2apu_irq; 155 u32 cpu2apu_irq;
156 u32 cpu2apu_irq_ack; 156 u32 apu2cpu_irq_ack;
157 u32 reserved12[13]; 157 u32 reserved12[13];
158 158
159 u32 hpu2apu_mb_offset; 159 u32 hpu2apu_mb_offset;
160 u32 hpu2apu_irq; 160 u32 hpu2apu_irq;
161 u32 hpu2apu_irq_ack; 161 u32 apu2hpu_irq_ack;
162 u32 reserved13[13]; 162 u32 reserved13[13];
163 163
164 u32 ppu2apu_mb_offset; 164 u32 ppu2apu_mb_offset;
165 u32 ppu2apu_irq; 165 u32 ppu2apu_irq;
166 u32 ppu2apu_irq_ack; 166 u32 apu2ppu_irq_ack;
167 u32 reserved14[13]; 167 u32 reserved14[13];
168 168
169 u32 epu2apu_mb_offset; 169 u32 epu2apu_mb_offset;
170 u32 epu2apu_irq; 170 u32 epu2apu_irq;
171 u32 epu2apu_irq_ack; 171 u32 apu2epu_irq_ack;
172 u32 reserved15[13]; 172 u32 reserved15[13];
173 u32 reserved16[8]; 173 u32 reserved16[8];
174 174
@@ -178,22 +178,22 @@ struct cx18_scb {
178 u32 reserved21[7]; 178 u32 reserved21[7];
179 u32 cpu2hpu_mb_offset; 179 u32 cpu2hpu_mb_offset;
180 u32 cpu2hpu_irq; 180 u32 cpu2hpu_irq;
181 u32 cpu2hpu_irq_ack; 181 u32 hpu2cpu_irq_ack;
182 u32 reserved22[13]; 182 u32 reserved22[13];
183 183
184 u32 apu2hpu_mb_offset; 184 u32 apu2hpu_mb_offset;
185 u32 apu2hpu_irq; 185 u32 apu2hpu_irq;
186 u32 apu2hpu_irq_ack; 186 u32 hpu2apu_irq_ack;
187 u32 reserved23[13]; 187 u32 reserved23[13];
188 188
189 u32 ppu2hpu_mb_offset; 189 u32 ppu2hpu_mb_offset;
190 u32 ppu2hpu_irq; 190 u32 ppu2hpu_irq;
191 u32 ppu2hpu_irq_ack; 191 u32 hpu2ppu_irq_ack;
192 u32 reserved24[13]; 192 u32 reserved24[13];
193 193
194 u32 epu2hpu_mb_offset; 194 u32 epu2hpu_mb_offset;
195 u32 epu2hpu_irq; 195 u32 epu2hpu_irq;
196 u32 epu2hpu_irq_ack; 196 u32 hpu2epu_irq_ack;
197 u32 reserved25[13]; 197 u32 reserved25[13];
198 u32 reserved26[8]; 198 u32 reserved26[8];
199 199
@@ -203,22 +203,22 @@ struct cx18_scb {
203 u32 reserved31[7]; 203 u32 reserved31[7];
204 u32 cpu2ppu_mb_offset; 204 u32 cpu2ppu_mb_offset;
205 u32 cpu2ppu_irq; 205 u32 cpu2ppu_irq;
206 u32 cpu2ppu_irq_ack; 206 u32 ppu2cpu_irq_ack;
207 u32 reserved32[13]; 207 u32 reserved32[13];
208 208
209 u32 apu2ppu_mb_offset; 209 u32 apu2ppu_mb_offset;
210 u32 apu2ppu_irq; 210 u32 apu2ppu_irq;
211 u32 apu2ppu_irq_ack; 211 u32 ppu2apu_irq_ack;
212 u32 reserved33[13]; 212 u32 reserved33[13];
213 213
214 u32 hpu2ppu_mb_offset; 214 u32 hpu2ppu_mb_offset;
215 u32 hpu2ppu_irq; 215 u32 hpu2ppu_irq;
216 u32 hpu2ppu_irq_ack; 216 u32 ppu2hpu_irq_ack;
217 u32 reserved34[13]; 217 u32 reserved34[13];
218 218
219 u32 epu2ppu_mb_offset; 219 u32 epu2ppu_mb_offset;
220 u32 epu2ppu_irq; 220 u32 epu2ppu_irq;
221 u32 epu2ppu_irq_ack; 221 u32 ppu2epu_irq_ack;
222 u32 reserved35[13]; 222 u32 reserved35[13];
223 u32 reserved36[8]; 223 u32 reserved36[8];
224 224
@@ -228,22 +228,22 @@ struct cx18_scb {
228 u32 reserved41[7]; 228 u32 reserved41[7];
229 u32 cpu2epu_mb_offset; 229 u32 cpu2epu_mb_offset;
230 u32 cpu2epu_irq; 230 u32 cpu2epu_irq;
231 u32 cpu2epu_irq_ack; 231 u32 epu2cpu_irq_ack;
232 u32 reserved42[13]; 232 u32 reserved42[13];
233 233
234 u32 apu2epu_mb_offset; 234 u32 apu2epu_mb_offset;
235 u32 apu2epu_irq; 235 u32 apu2epu_irq;
236 u32 apu2epu_irq_ack; 236 u32 epu2apu_irq_ack;
237 u32 reserved43[13]; 237 u32 reserved43[13];
238 238
239 u32 hpu2epu_mb_offset; 239 u32 hpu2epu_mb_offset;
240 u32 hpu2epu_irq; 240 u32 hpu2epu_irq;
241 u32 hpu2epu_irq_ack; 241 u32 epu2hpu_irq_ack;
242 u32 reserved44[13]; 242 u32 reserved44[13];
243 243
244 u32 ppu2epu_mb_offset; 244 u32 ppu2epu_mb_offset;
245 u32 ppu2epu_irq; 245 u32 ppu2epu_irq;
246 u32 ppu2epu_irq_ack; 246 u32 epu2ppu_irq_ack;
247 u32 reserved45[13]; 247 u32 reserved45[13];
248 u32 reserved46[8]; 248 u32 reserved46[8];
249 249
diff --git a/drivers/media/video/cx23885/Kconfig b/drivers/media/video/cx23885/Kconfig
index 8c1b7fa47a41..00f1e2e8889e 100644
--- a/drivers/media/video/cx23885/Kconfig
+++ b/drivers/media/video/cx23885/Kconfig
@@ -11,16 +11,16 @@ config VIDEO_CX23885
11 select VIDEO_CX25840 11 select VIDEO_CX25840
12 select VIDEO_CX2341X 12 select VIDEO_CX2341X
13 select DVB_DIB7000P if !DVB_FE_CUSTOMISE 13 select DVB_DIB7000P if !DVB_FE_CUSTOMISE
14 select MEDIA_TUNER_MT2131 if !DVB_FE_CUSTOMISE
15 select DVB_S5H1409 if !DVB_FE_CUSTOMISE 14 select DVB_S5H1409 if !DVB_FE_CUSTOMISE
16 select DVB_S5H1411 if !DVB_FE_CUSTOMISE 15 select DVB_S5H1411 if !DVB_FE_CUSTOMISE
17 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 16 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
18 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 17 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
18 select DVB_TDA10048 if !DVB_FE_CUSTOMIZE
19 select MEDIA_TUNER_MT2131 if !MEDIA_TUNER_CUSTOMIZE
19 select MEDIA_TUNER_XC2028 if !DVB_FE_CUSTOMIZE 20 select MEDIA_TUNER_XC2028 if !DVB_FE_CUSTOMIZE
20 select MEDIA_TUNER_TDA8290 if !DVB_FE_CUSTOMIZE 21 select MEDIA_TUNER_TDA8290 if !DVB_FE_CUSTOMIZE
21 select MEDIA_TUNER_TDA18271 if !DVB_FE_CUSTOMIZE 22 select MEDIA_TUNER_TDA18271 if !DVB_FE_CUSTOMIZE
22 select MEDIA_TUNER_XC5000 if !DVB_FE_CUSTOMIZE 23 select MEDIA_TUNER_XC5000 if !DVB_FE_CUSTOMIZE
23 select DVB_TDA10048 if !DVB_FE_CUSTOMIZE
24 ---help--- 24 ---help---
25 This is a video4linux driver for Conexant 23885 based 25 This is a video4linux driver for Conexant 23885 based
26 TV cards. 26 TV cards.
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index 0b9e5fac6239..b0f837588e01 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -56,12 +56,12 @@ config VIDEO_CX88_DVB
56 select DVB_NXT200X if !DVB_FE_CUSTOMISE 56 select DVB_NXT200X if !DVB_FE_CUSTOMISE
57 select DVB_CX24123 if !DVB_FE_CUSTOMISE 57 select DVB_CX24123 if !DVB_FE_CUSTOMISE
58 select DVB_ISL6421 if !DVB_FE_CUSTOMISE 58 select DVB_ISL6421 if !DVB_FE_CUSTOMISE
59 select MEDIA_TUNER_SIMPLE if !DVB_FE_CUSTOMISE
60 select DVB_S5H1411 if !DVB_FE_CUSTOMISE 59 select DVB_S5H1411 if !DVB_FE_CUSTOMISE
61 select DVB_CX24116 if !DVB_FE_CUSTOMISE 60 select DVB_CX24116 if !DVB_FE_CUSTOMISE
62 select DVB_STV0299 if !DVB_FE_CUSTOMISE 61 select DVB_STV0299 if !DVB_FE_CUSTOMISE
63 select DVB_STV0288 if !DVB_FE_CUSTOMISE 62 select DVB_STV0288 if !DVB_FE_CUSTOMISE
64 select DVB_STB6000 if !DVB_FE_CUSTOMISE 63 select DVB_STB6000 if !DVB_FE_CUSTOMISE
64 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE
65 ---help--- 65 ---help---
66 This adds support for DVB/ATSC cards based on the 66 This adds support for DVB/ATSC cards based on the
67 Conexant 2388x chip. 67 Conexant 2388x chip.
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index 078be6319556..d3ae5b4dfca7 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -1078,7 +1078,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
1078 } 1078 }
1079 } 1079 }
1080 1080
1081 if (blackbird_initialize_codec(dev) < 0) { 1081 if (!atomic_read(&dev->core->mpeg_users) && blackbird_initialize_codec(dev) < 0) {
1082 if (drv) 1082 if (drv)
1083 drv->request_release(drv); 1083 drv->request_release(drv);
1084 unlock_kernel(); 1084 unlock_kernel();
@@ -1109,6 +1109,8 @@ static int mpeg_open(struct inode *inode, struct file *file)
1109 fh->mpegq.field); 1109 fh->mpegq.field);
1110 unlock_kernel(); 1110 unlock_kernel();
1111 1111
1112 atomic_inc(&dev->core->mpeg_users);
1113
1112 return 0; 1114 return 0;
1113} 1115}
1114 1116
@@ -1118,7 +1120,7 @@ static int mpeg_release(struct inode *inode, struct file *file)
1118 struct cx8802_dev *dev = fh->dev; 1120 struct cx8802_dev *dev = fh->dev;
1119 struct cx8802_driver *drv = NULL; 1121 struct cx8802_driver *drv = NULL;
1120 1122
1121 if (dev->mpeg_active) 1123 if (dev->mpeg_active && atomic_read(&dev->core->mpeg_users) == 1)
1122 blackbird_stop_codec(dev); 1124 blackbird_stop_codec(dev);
1123 1125
1124 cx8802_cancel_buffers(fh->dev); 1126 cx8802_cancel_buffers(fh->dev);
@@ -1138,6 +1140,8 @@ static int mpeg_release(struct inode *inode, struct file *file)
1138 if (drv) 1140 if (drv)
1139 drv->request_release(drv); 1141 drv->request_release(drv);
1140 1142
1143 atomic_dec(&dev->core->mpeg_users);
1144
1141 return 0; 1145 return 0;
1142} 1146}
1143 1147
@@ -1158,6 +1162,10 @@ static unsigned int
1158mpeg_poll(struct file *file, struct poll_table_struct *wait) 1162mpeg_poll(struct file *file, struct poll_table_struct *wait)
1159{ 1163{
1160 struct cx8802_fh *fh = file->private_data; 1164 struct cx8802_fh *fh = file->private_data;
1165 struct cx8802_dev *dev = fh->dev;
1166
1167 if (!dev->mpeg_active)
1168 blackbird_start_codec(file, fh);
1161 1169
1162 return videobuf_poll_stream(file, &fh->mpegq, wait); 1170 return videobuf_poll_stream(file, &fh->mpegq, wait);
1163} 1171}
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index cf6c30d4e545..309ca5e68063 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -598,6 +598,11 @@ static int dvb_register(struct cx8802_dev *dev)
598 struct videobuf_dvb_frontend *fe0, *fe1 = NULL; 598 struct videobuf_dvb_frontend *fe0, *fe1 = NULL;
599 int mfe_shared = 0; /* bus not shared by default */ 599 int mfe_shared = 0; /* bus not shared by default */
600 600
601 if (0 != core->i2c_rc) {
602 printk(KERN_ERR "%s/2: no i2c-bus available, cannot attach dvb drivers\n", core->name);
603 goto frontend_detach;
604 }
605
601 /* Get the first frontend */ 606 /* Get the first frontend */
602 fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1); 607 fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
603 if (!fe0) 608 if (!fe0)
diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c
index a1c435b4b1cd..3ebdcd1d83f8 100644
--- a/drivers/media/video/cx88/cx88-mpeg.c
+++ b/drivers/media/video/cx88/cx88-mpeg.c
@@ -769,10 +769,6 @@ static int __devinit cx8802_probe(struct pci_dev *pci_dev,
769 struct cx8802_dev *dev; 769 struct cx8802_dev *dev;
770 struct cx88_core *core; 770 struct cx88_core *core;
771 int err; 771 int err;
772#if defined(CONFIG_VIDEO_CX88_DVB) || defined(CONFIG_VIDEO_CX88_DVB_MODULE)
773 struct videobuf_dvb_frontend *demod;
774 int i;
775#endif
776 772
777 /* general setup */ 773 /* general setup */
778 core = cx88_core_get(pci_dev); 774 core = cx88_core_get(pci_dev);
@@ -803,15 +799,21 @@ static int __devinit cx8802_probe(struct pci_dev *pci_dev,
803 mutex_init(&dev->frontends.lock); 799 mutex_init(&dev->frontends.lock);
804 INIT_LIST_HEAD(&dev->frontends.felist); 800 INIT_LIST_HEAD(&dev->frontends.felist);
805 801
806 if (core->board.num_frontends) 802 if (core->board.num_frontends) {
807 printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__, core->board.num_frontends); 803 struct videobuf_dvb_frontend *fe;
808 804 int i;
809 for (i = 1; i <= core->board.num_frontends; i++) { 805
810 demod = videobuf_dvb_alloc_frontend(&dev->frontends, i); 806 printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
811 if(demod == NULL) { 807 core->board.num_frontends);
812 printk(KERN_ERR "%s() failed to alloc\n", __func__); 808 for (i = 1; i <= core->board.num_frontends; i++) {
813 err = -ENOMEM; 809 fe = videobuf_dvb_alloc_frontend(&dev->frontends, i);
814 goto fail_free; 810 if(fe == NULL) {
811 printk(KERN_ERR "%s() failed to alloc\n",
812 __func__);
813 videobuf_dvb_dealloc_frontends(&dev->frontends);
814 err = -ENOMEM;
815 goto fail_free;
816 }
815 } 817 }
816 } 818 }
817#endif 819#endif
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 61265fd04d56..b96ce991d968 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -1216,8 +1216,12 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1216 struct cx8800_fh *fh = priv; 1216 struct cx8800_fh *fh = priv;
1217 struct cx8800_dev *dev = fh->dev; 1217 struct cx8800_dev *dev = fh->dev;
1218 1218
1219 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) 1219 /* We should remember that this driver also supports teletext, */
1220 /* so we have to test if the v4l2_buf_type is VBI capture data. */
1221 if (unlikely((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
1222 (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)))
1220 return -EINVAL; 1223 return -EINVAL;
1224
1221 if (unlikely(i != fh->type)) 1225 if (unlikely(i != fh->type))
1222 return -EINVAL; 1226 return -EINVAL;
1223 1227
@@ -1232,8 +1236,10 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1232 struct cx8800_dev *dev = fh->dev; 1236 struct cx8800_dev *dev = fh->dev;
1233 int err, res; 1237 int err, res;
1234 1238
1235 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1239 if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
1240 (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
1236 return -EINVAL; 1241 return -EINVAL;
1242
1237 if (i != fh->type) 1243 if (i != fh->type)
1238 return -EINVAL; 1244 return -EINVAL;
1239 1245
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index 76207c2856b7..f4240965be32 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -352,6 +352,7 @@ struct cx88_core {
352 /* various v4l controls */ 352 /* various v4l controls */
353 u32 freq; 353 u32 freq;
354 atomic_t users; 354 atomic_t users;
355 atomic_t mpeg_users;
355 356
356 /* cx88-video needs to access cx8802 for hybrid tuner pll access. */ 357 /* cx88-video needs to access cx8802 for hybrid tuner pll access. */
357 struct cx8802_dev *dvbdev; 358 struct cx8802_dev *dvbdev;
diff --git a/drivers/media/video/em28xx/em28xx-audio.c b/drivers/media/video/em28xx/em28xx-audio.c
index ac3292d7646c..7a8d49ef646e 100644
--- a/drivers/media/video/em28xx/em28xx-audio.c
+++ b/drivers/media/video/em28xx/em28xx-audio.c
@@ -62,7 +62,7 @@ static int em28xx_isoc_audio_deinit(struct em28xx *dev)
62 62
63 dprintk("Stopping isoc\n"); 63 dprintk("Stopping isoc\n");
64 for (i = 0; i < EM28XX_AUDIO_BUFS; i++) { 64 for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
65 usb_kill_urb(dev->adev->urb[i]); 65 usb_unlink_urb(dev->adev->urb[i]);
66 usb_free_urb(dev->adev->urb[i]); 66 usb_free_urb(dev->adev->urb[i]);
67 dev->adev->urb[i] = NULL; 67 dev->adev->urb[i] = NULL;
68 } 68 }
@@ -75,7 +75,6 @@ static void em28xx_audio_isocirq(struct urb *urb)
75 struct em28xx *dev = urb->context; 75 struct em28xx *dev = urb->context;
76 int i; 76 int i;
77 unsigned int oldptr; 77 unsigned int oldptr;
78 unsigned long flags;
79 int period_elapsed = 0; 78 int period_elapsed = 0;
80 int status; 79 int status;
81 unsigned char *cp; 80 unsigned char *cp;
@@ -96,9 +95,21 @@ static void em28xx_audio_isocirq(struct urb *urb)
96 if (!length) 95 if (!length)
97 continue; 96 continue;
98 97
99 spin_lock_irqsave(&dev->adev->slock, flags);
100
101 oldptr = dev->adev->hwptr_done_capture; 98 oldptr = dev->adev->hwptr_done_capture;
99 if (oldptr + length >= runtime->buffer_size) {
100 unsigned int cnt =
101 runtime->buffer_size - oldptr;
102 memcpy(runtime->dma_area + oldptr * stride, cp,
103 cnt * stride);
104 memcpy(runtime->dma_area, cp + cnt * stride,
105 length * stride - cnt * stride);
106 } else {
107 memcpy(runtime->dma_area + oldptr * stride, cp,
108 length * stride);
109 }
110
111 snd_pcm_stream_lock(substream);
112
102 dev->adev->hwptr_done_capture += length; 113 dev->adev->hwptr_done_capture += length;
103 if (dev->adev->hwptr_done_capture >= 114 if (dev->adev->hwptr_done_capture >=
104 runtime->buffer_size) 115 runtime->buffer_size)
@@ -113,19 +124,7 @@ static void em28xx_audio_isocirq(struct urb *urb)
113 period_elapsed = 1; 124 period_elapsed = 1;
114 } 125 }
115 126
116 spin_unlock_irqrestore(&dev->adev->slock, flags); 127 snd_pcm_stream_unlock(substream);
117
118 if (oldptr + length >= runtime->buffer_size) {
119 unsigned int cnt =
120 runtime->buffer_size - oldptr;
121 memcpy(runtime->dma_area + oldptr * stride, cp,
122 cnt * stride);
123 memcpy(runtime->dma_area, cp + cnt * stride,
124 length * stride - cnt * stride);
125 } else {
126 memcpy(runtime->dma_area + oldptr * stride, cp,
127 length * stride);
128 }
129 } 128 }
130 if (period_elapsed) 129 if (period_elapsed)
131 snd_pcm_period_elapsed(substream); 130 snd_pcm_period_elapsed(substream);
diff --git a/drivers/media/video/em28xx/em28xx-core.c b/drivers/media/video/em28xx/em28xx-core.c
index 5d837c16ee22..15e2b525310d 100644
--- a/drivers/media/video/em28xx/em28xx-core.c
+++ b/drivers/media/video/em28xx/em28xx-core.c
@@ -69,19 +69,33 @@ int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
69 int ret, byte; 69 int ret, byte;
70 70
71 if (dev->state & DEV_DISCONNECTED) 71 if (dev->state & DEV_DISCONNECTED)
72 return(-ENODEV); 72 return -ENODEV;
73
74 if (len > URB_MAX_CTRL_SIZE)
75 return -EINVAL;
73 76
74 em28xx_regdbg("req=%02x, reg=%02x ", req, reg); 77 em28xx_regdbg("req=%02x, reg=%02x ", req, reg);
75 78
79 mutex_lock(&dev->ctrl_urb_lock);
76 ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), req, 80 ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), req,
77 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 81 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
78 0x0000, reg, buf, len, HZ); 82 0x0000, reg, dev->urb_buf, len, HZ);
83 if (ret < 0) {
84 if (reg_debug)
85 printk(" failed!\n");
86 mutex_unlock(&dev->ctrl_urb_lock);
87 return ret;
88 }
89
90 if (len)
91 memcpy(buf, dev->urb_buf, len);
92
93 mutex_unlock(&dev->ctrl_urb_lock);
79 94
80 if (reg_debug) { 95 if (reg_debug) {
81 printk(ret < 0 ? " failed!\n" : "%02x values: ", ret); 96 printk("%02x values: ", ret);
82 for (byte = 0; byte < len; byte++) 97 for (byte = 0; byte < len; byte++)
83 printk(" %02x", (unsigned char)buf[byte]); 98 printk(" %02x", (unsigned char)buf[byte]);
84
85 printk("\n"); 99 printk("\n");
86 } 100 }
87 101
@@ -102,16 +116,20 @@ int em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg)
102 116
103 em28xx_regdbg("req=%02x, reg=%02x:", req, reg); 117 em28xx_regdbg("req=%02x, reg=%02x:", req, reg);
104 118
119 mutex_lock(&dev->ctrl_urb_lock);
105 ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), req, 120 ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), req,
106 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 121 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
107 0x0000, reg, &val, 1, HZ); 122 0x0000, reg, dev->urb_buf, 1, HZ);
108 123 val = dev->urb_buf[0];
109 if (reg_debug) 124 mutex_unlock(&dev->ctrl_urb_lock);
110 printk(ret < 0 ? " failed!\n" :
111 "%02x\n", (unsigned char) val);
112 125
113 if (ret < 0) 126 if (ret < 0) {
127 printk(" failed!\n");
114 return ret; 128 return ret;
129 }
130
131 if (reg_debug)
132 printk("%02x\n", (unsigned char) val);
115 133
116 return val; 134 return val;
117} 135}
@@ -130,19 +148,13 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
130{ 148{
131 int ret; 149 int ret;
132 150
133 /*usb_control_msg seems to expect a kmalloced buffer */
134 unsigned char *bufs;
135
136 if (dev->state & DEV_DISCONNECTED) 151 if (dev->state & DEV_DISCONNECTED)
137 return -ENODEV; 152 return -ENODEV;
138 153
139 if (len < 1) 154 if ((len < 1) || (len > URB_MAX_CTRL_SIZE))
140 return -EINVAL; 155 return -EINVAL;
141 156
142 bufs = kmalloc(len, GFP_KERNEL);
143
144 em28xx_regdbg("req=%02x reg=%02x:", req, reg); 157 em28xx_regdbg("req=%02x reg=%02x:", req, reg);
145
146 if (reg_debug) { 158 if (reg_debug) {
147 int i; 159 int i;
148 for (i = 0; i < len; ++i) 160 for (i = 0; i < len; ++i)
@@ -150,16 +162,16 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
150 printk("\n"); 162 printk("\n");
151 } 163 }
152 164
153 if (!bufs) 165 mutex_lock(&dev->ctrl_urb_lock);
154 return -ENOMEM; 166 memcpy(dev->urb_buf, buf, len);
155 memcpy(bufs, buf, len);
156 ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), req, 167 ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), req,
157 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 168 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
158 0x0000, reg, bufs, len, HZ); 169 0x0000, reg, dev->urb_buf, len, HZ);
170 mutex_unlock(&dev->ctrl_urb_lock);
171
159 if (dev->wait_after_write) 172 if (dev->wait_after_write)
160 msleep(dev->wait_after_write); 173 msleep(dev->wait_after_write);
161 174
162 kfree(bufs);
163 return ret; 175 return ret;
164} 176}
165 177
@@ -270,6 +282,8 @@ static int em28xx_set_audio_source(struct em28xx *dev)
270 break; 282 break;
271 case EM28XX_AMUX_LINE_IN: 283 case EM28XX_AMUX_LINE_IN:
272 input = EM28XX_AUDIO_SRC_LINE; 284 input = EM28XX_AUDIO_SRC_LINE;
285 video = disable;
286 line = enable;
273 break; 287 break;
274 case EM28XX_AMUX_AC97_VIDEO: 288 case EM28XX_AMUX_AC97_VIDEO:
275 input = EM28XX_AUDIO_SRC_LINE; 289 input = EM28XX_AUDIO_SRC_LINE;
diff --git a/drivers/media/video/em28xx/em28xx-i2c.c b/drivers/media/video/em28xx/em28xx-i2c.c
index 3bab56b997fc..2360c61ddca9 100644
--- a/drivers/media/video/em28xx/em28xx-i2c.c
+++ b/drivers/media/video/em28xx/em28xx-i2c.c
@@ -337,9 +337,9 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
337 /* Check if board has eeprom */ 337 /* Check if board has eeprom */
338 err = i2c_master_recv(&dev->i2c_client, &buf, 0); 338 err = i2c_master_recv(&dev->i2c_client, &buf, 0);
339 if (err < 0) { 339 if (err < 0) {
340 em28xx_errdev("%s: i2c_master_recv failed! err [%d]\n", 340 em28xx_errdev("board has no eeprom\n");
341 __func__, err); 341 memset(eedata, 0, len);
342 return err; 342 return -ENODEV;
343 } 343 }
344 344
345 buf = 0; 345 buf = 0;
@@ -609,14 +609,16 @@ int em28xx_i2c_register(struct em28xx *dev)
609 dev->i2c_client.adapter = &dev->i2c_adap; 609 dev->i2c_client.adapter = &dev->i2c_adap;
610 610
611 retval = em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata)); 611 retval = em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata));
612 if (retval < 0) { 612 if ((retval < 0) && (retval != -ENODEV)) {
613 em28xx_errdev("%s: em28xx_i2_eeprom failed! retval [%d]\n", 613 em28xx_errdev("%s: em28xx_i2_eeprom failed! retval [%d]\n",
614 __func__, retval); 614 __func__, retval);
615
615 return retval; 616 return retval;
616 } 617 }
617 618
618 if (i2c_scan) 619 if (i2c_scan)
619 em28xx_do_i2c_scan(dev); 620 em28xx_do_i2c_scan(dev);
621
620 return 0; 622 return 0;
621} 623}
622 624
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index a1ab2ef45578..4ea1f1e04897 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -73,6 +73,7 @@ MODULE_DESCRIPTION(DRIVER_DESC);
73MODULE_LICENSE("GPL"); 73MODULE_LICENSE("GPL");
74 74
75static LIST_HEAD(em28xx_devlist); 75static LIST_HEAD(em28xx_devlist);
76static DEFINE_MUTEX(em28xx_devlist_mutex);
76 77
77static unsigned int card[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; 78static unsigned int card[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
78static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; 79static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
@@ -548,10 +549,11 @@ static int em28xx_config(struct em28xx *dev)
548static void em28xx_config_i2c(struct em28xx *dev) 549static void em28xx_config_i2c(struct em28xx *dev)
549{ 550{
550 struct v4l2_routing route; 551 struct v4l2_routing route;
552 int zero = 0;
551 553
552 route.input = INPUT(dev->ctl_input)->vmux; 554 route.input = INPUT(dev->ctl_input)->vmux;
553 route.output = 0; 555 route.output = 0;
554 em28xx_i2c_call_clients(dev, VIDIOC_INT_RESET, NULL); 556 em28xx_i2c_call_clients(dev, VIDIOC_INT_RESET, &zero);
555 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route); 557 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route);
556 em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL); 558 em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL);
557} 559}
@@ -1519,7 +1521,7 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
1519 struct em28xx_fh *fh; 1521 struct em28xx_fh *fh;
1520 enum v4l2_buf_type fh_type = 0; 1522 enum v4l2_buf_type fh_type = 0;
1521 1523
1522 lock_kernel(); 1524 mutex_lock(&em28xx_devlist_mutex);
1523 list_for_each_entry(h, &em28xx_devlist, devlist) { 1525 list_for_each_entry(h, &em28xx_devlist, devlist) {
1524 if (h->vdev->minor == minor) { 1526 if (h->vdev->minor == minor) {
1525 dev = h; 1527 dev = h;
@@ -1535,10 +1537,11 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
1535 dev = h; 1537 dev = h;
1536 } 1538 }
1537 } 1539 }
1538 if (NULL == dev) { 1540 mutex_unlock(&em28xx_devlist_mutex);
1539 unlock_kernel(); 1541 if (NULL == dev)
1540 return -ENODEV; 1542 return -ENODEV;
1541 } 1543
1544 mutex_lock(&dev->lock);
1542 1545
1543 em28xx_videodbg("open minor=%d type=%s users=%d\n", 1546 em28xx_videodbg("open minor=%d type=%s users=%d\n",
1544 minor, v4l2_type_names[fh_type], dev->users); 1547 minor, v4l2_type_names[fh_type], dev->users);
@@ -1547,10 +1550,9 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
1547 fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL); 1550 fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL);
1548 if (!fh) { 1551 if (!fh) {
1549 em28xx_errdev("em28xx-video.c: Out of memory?!\n"); 1552 em28xx_errdev("em28xx-video.c: Out of memory?!\n");
1550 unlock_kernel(); 1553 mutex_unlock(&dev->lock);
1551 return -ENOMEM; 1554 return -ENOMEM;
1552 } 1555 }
1553 mutex_lock(&dev->lock);
1554 fh->dev = dev; 1556 fh->dev = dev;
1555 fh->radio = radio; 1557 fh->radio = radio;
1556 fh->type = fh_type; 1558 fh->type = fh_type;
@@ -1584,7 +1586,6 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
1584 sizeof(struct em28xx_buffer), fh); 1586 sizeof(struct em28xx_buffer), fh);
1585 1587
1586 mutex_unlock(&dev->lock); 1588 mutex_unlock(&dev->lock);
1587 unlock_kernel();
1588 1589
1589 return errCode; 1590 return errCode;
1590} 1591}
@@ -1871,6 +1872,7 @@ int em28xx_register_extension(struct em28xx_ops *ops)
1871{ 1872{
1872 struct em28xx *dev = NULL; 1873 struct em28xx *dev = NULL;
1873 1874
1875 mutex_lock(&em28xx_devlist_mutex);
1874 mutex_lock(&em28xx_extension_devlist_lock); 1876 mutex_lock(&em28xx_extension_devlist_lock);
1875 list_add_tail(&ops->next, &em28xx_extension_devlist); 1877 list_add_tail(&ops->next, &em28xx_extension_devlist);
1876 list_for_each_entry(dev, &em28xx_devlist, devlist) { 1878 list_for_each_entry(dev, &em28xx_devlist, devlist) {
@@ -1879,6 +1881,7 @@ int em28xx_register_extension(struct em28xx_ops *ops)
1879 } 1881 }
1880 printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name); 1882 printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name);
1881 mutex_unlock(&em28xx_extension_devlist_lock); 1883 mutex_unlock(&em28xx_extension_devlist_lock);
1884 mutex_unlock(&em28xx_devlist_mutex);
1882 return 0; 1885 return 0;
1883} 1886}
1884EXPORT_SYMBOL(em28xx_register_extension); 1887EXPORT_SYMBOL(em28xx_register_extension);
@@ -1887,6 +1890,7 @@ void em28xx_unregister_extension(struct em28xx_ops *ops)
1887{ 1890{
1888 struct em28xx *dev = NULL; 1891 struct em28xx *dev = NULL;
1889 1892
1893 mutex_lock(&em28xx_devlist_mutex);
1890 list_for_each_entry(dev, &em28xx_devlist, devlist) { 1894 list_for_each_entry(dev, &em28xx_devlist, devlist) {
1891 if (dev) 1895 if (dev)
1892 ops->fini(dev); 1896 ops->fini(dev);
@@ -1896,6 +1900,7 @@ void em28xx_unregister_extension(struct em28xx_ops *ops)
1896 printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name); 1900 printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name);
1897 list_del(&ops->next); 1901 list_del(&ops->next);
1898 mutex_unlock(&em28xx_extension_devlist_lock); 1902 mutex_unlock(&em28xx_extension_devlist_lock);
1903 mutex_unlock(&em28xx_devlist_mutex);
1899} 1904}
1900EXPORT_SYMBOL(em28xx_unregister_extension); 1905EXPORT_SYMBOL(em28xx_unregister_extension);
1901 1906
@@ -1921,6 +1926,60 @@ static struct video_device *em28xx_vdev_init(struct em28xx *dev,
1921} 1926}
1922 1927
1923 1928
1929static int register_analog_devices(struct em28xx *dev)
1930{
1931 int ret;
1932
1933 /* allocate and fill video video_device struct */
1934 dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, "video");
1935 if (!dev->vdev) {
1936 em28xx_errdev("cannot allocate video_device.\n");
1937 return -ENODEV;
1938 }
1939
1940 /* register v4l2 video video_device */
1941 ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
1942 video_nr[dev->devno]);
1943 if (ret) {
1944 em28xx_errdev("unable to register video device (error=%i).\n",
1945 ret);
1946 return ret;
1947 }
1948
1949 /* Allocate and fill vbi video_device struct */
1950 dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template, "vbi");
1951
1952 /* register v4l2 vbi video_device */
1953 ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
1954 vbi_nr[dev->devno]);
1955 if (ret < 0) {
1956 em28xx_errdev("unable to register vbi device\n");
1957 return ret;
1958 }
1959
1960 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) {
1961 dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template, "radio");
1962 if (!dev->radio_dev) {
1963 em28xx_errdev("cannot allocate video_device.\n");
1964 return -ENODEV;
1965 }
1966 ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
1967 radio_nr[dev->devno]);
1968 if (ret < 0) {
1969 em28xx_errdev("can't register radio device\n");
1970 return ret;
1971 }
1972 em28xx_info("Registered radio device as /dev/radio%d\n",
1973 dev->radio_dev->num);
1974 }
1975
1976 em28xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n",
1977 dev->vdev->num, dev->vbi_dev->num);
1978
1979 return 0;
1980}
1981
1982
1924/* 1983/*
1925 * em28xx_init_dev() 1984 * em28xx_init_dev()
1926 * allocates and inits the device structs, registers i2c bus and v4l device 1985 * allocates and inits the device structs, registers i2c bus and v4l device
@@ -1936,6 +1995,7 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1936 1995
1937 dev->udev = udev; 1996 dev->udev = udev;
1938 mutex_init(&dev->lock); 1997 mutex_init(&dev->lock);
1998 mutex_init(&dev->ctrl_urb_lock);
1939 spin_lock_init(&dev->slock); 1999 spin_lock_init(&dev->slock);
1940 init_waitqueue_head(&dev->open); 2000 init_waitqueue_head(&dev->open);
1941 init_waitqueue_head(&dev->wait_frame); 2001 init_waitqueue_head(&dev->wait_frame);
@@ -1953,8 +2013,6 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1953 errCode = em28xx_config(dev); 2013 errCode = em28xx_config(dev);
1954 if (errCode) { 2014 if (errCode) {
1955 em28xx_errdev("error configuring device\n"); 2015 em28xx_errdev("error configuring device\n");
1956 em28xx_devused &= ~(1<<dev->devno);
1957 kfree(dev);
1958 return -ENOMEM; 2016 return -ENOMEM;
1959 } 2017 }
1960 2018
@@ -2001,50 +2059,6 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
2001 return errCode; 2059 return errCode;
2002 } 2060 }
2003 2061
2004 list_add_tail(&dev->devlist, &em28xx_devlist);
2005
2006 /* allocate and fill video video_device struct */
2007 dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, "video");
2008 if (NULL == dev->vdev) {
2009 em28xx_errdev("cannot allocate video_device.\n");
2010 goto fail_unreg;
2011 }
2012
2013 /* register v4l2 video video_device */
2014 retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
2015 video_nr[dev->devno]);
2016 if (retval) {
2017 em28xx_errdev("unable to register video device (error=%i).\n",
2018 retval);
2019 goto fail_unreg;
2020 }
2021
2022 /* Allocate and fill vbi video_device struct */
2023 dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template, "vbi");
2024 /* register v4l2 vbi video_device */
2025 if (video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
2026 vbi_nr[dev->devno]) < 0) {
2027 em28xx_errdev("unable to register vbi device\n");
2028 retval = -ENODEV;
2029 goto fail_unreg;
2030 }
2031
2032 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) {
2033 dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template, "radio");
2034 if (NULL == dev->radio_dev) {
2035 em28xx_errdev("cannot allocate video_device.\n");
2036 goto fail_unreg;
2037 }
2038 retval = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
2039 radio_nr[dev->devno]);
2040 if (retval < 0) {
2041 em28xx_errdev("can't register radio device\n");
2042 goto fail_unreg;
2043 }
2044 em28xx_info("Registered radio device as /dev/radio%d\n",
2045 dev->radio_dev->num);
2046 }
2047
2048 /* init video dma queues */ 2062 /* init video dma queues */
2049 INIT_LIST_HEAD(&dev->vidq.active); 2063 INIT_LIST_HEAD(&dev->vidq.active);
2050 INIT_LIST_HEAD(&dev->vidq.queued); 2064 INIT_LIST_HEAD(&dev->vidq.queued);
@@ -2071,8 +2085,14 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
2071 2085
2072 video_mux(dev, 0); 2086 video_mux(dev, 0);
2073 2087
2074 em28xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n", 2088 mutex_lock(&em28xx_devlist_mutex);
2075 dev->vdev->num, dev->vbi_dev->num); 2089 list_add_tail(&dev->devlist, &em28xx_devlist);
2090 retval = register_analog_devices(dev);
2091 if (retval < 0) {
2092 em28xx_release_resources(dev);
2093 mutex_unlock(&em28xx_devlist_mutex);
2094 goto fail_reg_devices;
2095 }
2076 2096
2077 mutex_lock(&em28xx_extension_devlist_lock); 2097 mutex_lock(&em28xx_extension_devlist_lock);
2078 if (!list_empty(&em28xx_extension_devlist)) { 2098 if (!list_empty(&em28xx_extension_devlist)) {
@@ -2082,13 +2102,12 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
2082 } 2102 }
2083 } 2103 }
2084 mutex_unlock(&em28xx_extension_devlist_lock); 2104 mutex_unlock(&em28xx_extension_devlist_lock);
2105 mutex_unlock(&em28xx_devlist_mutex);
2085 2106
2086 return 0; 2107 return 0;
2087 2108
2088fail_unreg: 2109fail_reg_devices:
2089 em28xx_release_resources(dev);
2090 mutex_unlock(&dev->lock); 2110 mutex_unlock(&dev->lock);
2091 kfree(dev);
2092 return retval; 2111 return retval;
2093} 2112}
2094 2113
@@ -2231,8 +2250,12 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2231 2250
2232 /* allocate device struct */ 2251 /* allocate device struct */
2233 retval = em28xx_init_dev(&dev, udev, nr); 2252 retval = em28xx_init_dev(&dev, udev, nr);
2234 if (retval) 2253 if (retval) {
2254 em28xx_devused &= ~(1<<dev->devno);
2255 kfree(dev);
2256
2235 return retval; 2257 return retval;
2258 }
2236 2259
2237 em28xx_info("Found %s\n", em28xx_boards[dev->model].name); 2260 em28xx_info("Found %s\n", em28xx_boards[dev->model].name);
2238 2261
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index 82781178e0a3..5956e9b3062f 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -102,6 +102,9 @@
102#define EM28XX_MIN_BUF 4 102#define EM28XX_MIN_BUF 4
103#define EM28XX_DEF_BUF 8 103#define EM28XX_DEF_BUF 8
104 104
105/*Limits the max URB message size */
106#define URB_MAX_CTRL_SIZE 80
107
105/* Params for validated field */ 108/* Params for validated field */
106#define EM28XX_BOARD_NOT_VALIDATED 1 109#define EM28XX_BOARD_NOT_VALIDATED 1
107#define EM28XX_BOARD_VALIDATED 0 110#define EM28XX_BOARD_VALIDATED 0
@@ -430,6 +433,7 @@ struct em28xx {
430 433
431 /* locks */ 434 /* locks */
432 struct mutex lock; 435 struct mutex lock;
436 struct mutex ctrl_urb_lock; /* protects urb_buf */
433 /* spinlock_t queue_lock; */ 437 /* spinlock_t queue_lock; */
434 struct list_head inqueue, outqueue; 438 struct list_head inqueue, outqueue;
435 wait_queue_head_t open, wait_frame, wait_stream; 439 wait_queue_head_t open, wait_frame, wait_stream;
@@ -451,6 +455,8 @@ struct em28xx {
451 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */ 455 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
452 struct urb *urb[EM28XX_NUM_BUFS]; /* urb for isoc transfers */ 456 struct urb *urb[EM28XX_NUM_BUFS]; /* urb for isoc transfers */
453 char *transfer_buffer[EM28XX_NUM_BUFS]; /* transfer buffers for isoc transfer */ 457 char *transfer_buffer[EM28XX_NUM_BUFS]; /* transfer buffers for isoc transfer */
458 char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */
459
454 /* helper funcs that call usb_control_msg */ 460 /* helper funcs that call usb_control_msg */
455 int (*em28xx_write_regs) (struct em28xx *dev, u16 reg, 461 int (*em28xx_write_regs) (struct em28xx *dev, u16 reg,
456 char *buf, int len); 462 char *buf, int len);
diff --git a/drivers/media/video/gspca/Kconfig b/drivers/media/video/gspca/Kconfig
index 4d0817471c9f..6b557c057fac 100644
--- a/drivers/media/video/gspca/Kconfig
+++ b/drivers/media/video/gspca/Kconfig
@@ -3,16 +3,16 @@ menuconfig USB_GSPCA
3 depends on VIDEO_V4L2 3 depends on VIDEO_V4L2
4 default m 4 default m
5 ---help--- 5 ---help---
6 Say Y here if you want to enable selecting webcams based 6 Say Y here if you want to enable selecting webcams based
7 on the GSPCA framework. 7 on the GSPCA framework.
8 8
9 See <file:Documentation/video4linux/gspca.txt> for more info. 9 See <file:Documentation/video4linux/gspca.txt> for more info.
10 10
11 This driver uses the Video For Linux API. You must say Y or M to 11 This driver uses the Video For Linux API. You must say Y or M to
12 "Video For Linux" to use this driver. 12 "Video For Linux" to use this driver.
13 13
14 To compile this driver as modules, choose M here: the 14 To compile this driver as modules, choose M here: the
15 modules will be called gspca_main. 15 modules will be called gspca_main.
16 16
17 17
18if USB_GSPCA && VIDEO_V4L2 18if USB_GSPCA && VIDEO_V4L2
@@ -23,190 +23,190 @@ config USB_GSPCA_CONEX
23 tristate "Conexant Camera Driver" 23 tristate "Conexant Camera Driver"
24 depends on VIDEO_V4L2 && USB_GSPCA 24 depends on VIDEO_V4L2 && USB_GSPCA
25 help 25 help
26 Say Y here if you want support for cameras based on the Conexant chip. 26 Say Y here if you want support for cameras based on the Conexant chip.
27 27
28 To compile this driver as a module, choose M here: the 28 To compile this driver as a module, choose M here: the
29 module will be called gspca_conex. 29 module will be called gspca_conex.
30 30
31config USB_GSPCA_ETOMS 31config USB_GSPCA_ETOMS
32 tristate "Etoms USB Camera Driver" 32 tristate "Etoms USB Camera Driver"
33 depends on VIDEO_V4L2 && USB_GSPCA 33 depends on VIDEO_V4L2 && USB_GSPCA
34 help 34 help
35 Say Y here if you want support for cameras based on the Etoms chip. 35 Say Y here if you want support for cameras based on the Etoms chip.
36 36
37 To compile this driver as a module, choose M here: the 37 To compile this driver as a module, choose M here: the
38 module will be called gspca_etoms. 38 module will be called gspca_etoms.
39 39
40config USB_GSPCA_FINEPIX 40config USB_GSPCA_FINEPIX
41 tristate "Fujifilm FinePix USB V4L2 driver" 41 tristate "Fujifilm FinePix USB V4L2 driver"
42 depends on VIDEO_V4L2 && USB_GSPCA 42 depends on VIDEO_V4L2 && USB_GSPCA
43 help 43 help
44 Say Y here if you want support for cameras based on the FinePix chip. 44 Say Y here if you want support for cameras based on the FinePix chip.
45 45
46 To compile this driver as a module, choose M here: the 46 To compile this driver as a module, choose M here: the
47 module will be called gspca_finepix. 47 module will be called gspca_finepix.
48 48
49config USB_GSPCA_MARS 49config USB_GSPCA_MARS
50 tristate "Mars USB Camera Driver" 50 tristate "Mars USB Camera Driver"
51 depends on VIDEO_V4L2 && USB_GSPCA 51 depends on VIDEO_V4L2 && USB_GSPCA
52 help 52 help
53 Say Y here if you want support for cameras based on the Mars chip. 53 Say Y here if you want support for cameras based on the Mars chip.
54 54
55 To compile this driver as a module, choose M here: the 55 To compile this driver as a module, choose M here: the
56 module will be called gspca_mars. 56 module will be called gspca_mars.
57 57
58config USB_GSPCA_OV519 58config USB_GSPCA_OV519
59 tristate "OV519 USB Camera Driver" 59 tristate "OV519 USB Camera Driver"
60 depends on VIDEO_V4L2 && USB_GSPCA 60 depends on VIDEO_V4L2 && USB_GSPCA
61 help 61 help
62 Say Y here if you want support for cameras based on the OV519 chip. 62 Say Y here if you want support for cameras based on the OV519 chip.
63 63
64 To compile this driver as a module, choose M here: the 64 To compile this driver as a module, choose M here: the
65 module will be called gspca_ov519. 65 module will be called gspca_ov519.
66 66
67config USB_GSPCA_PAC207 67config USB_GSPCA_PAC207
68 tristate "Pixart PAC207 USB Camera Driver" 68 tristate "Pixart PAC207 USB Camera Driver"
69 depends on VIDEO_V4L2 && USB_GSPCA 69 depends on VIDEO_V4L2 && USB_GSPCA
70 help 70 help
71 Say Y here if you want support for cameras based on the PAC207 chip. 71 Say Y here if you want support for cameras based on the PAC207 chip.
72 72
73 To compile this driver as a module, choose M here: the 73 To compile this driver as a module, choose M here: the
74 module will be called gspca_pac207. 74 module will be called gspca_pac207.
75 75
76config USB_GSPCA_PAC7311 76config USB_GSPCA_PAC7311
77 tristate "Pixart PAC7311 USB Camera Driver" 77 tristate "Pixart PAC7311 USB Camera Driver"
78 depends on VIDEO_V4L2 && USB_GSPCA 78 depends on VIDEO_V4L2 && USB_GSPCA
79 help 79 help
80 Say Y here if you want support for cameras based on the PAC7311 chip. 80 Say Y here if you want support for cameras based on the PAC7311 chip.
81 81
82 To compile this driver as a module, choose M here: the 82 To compile this driver as a module, choose M here: the
83 module will be called gspca_pac7311. 83 module will be called gspca_pac7311.
84 84
85config USB_GSPCA_SONIXB 85config USB_GSPCA_SONIXB
86 tristate "SN9C102 USB Camera Driver" 86 tristate "SN9C102 USB Camera Driver"
87 depends on VIDEO_V4L2 && USB_GSPCA 87 depends on VIDEO_V4L2 && USB_GSPCA
88 help 88 help
89 Say Y here if you want support for cameras based on the SONIXB chip. 89 Say Y here if you want support for cameras based on the SONIXB chip.
90 90
91 To compile this driver as a module, choose M here: the 91 To compile this driver as a module, choose M here: the
92 module will be called gspca_sonixb. 92 module will be called gspca_sonixb.
93 93
94config USB_GSPCA_SONIXJ 94config USB_GSPCA_SONIXJ
95 tristate "SONIX JPEG USB Camera Driver" 95 tristate "SONIX JPEG USB Camera Driver"
96 depends on VIDEO_V4L2 && USB_GSPCA 96 depends on VIDEO_V4L2 && USB_GSPCA
97 help 97 help
98 Say Y here if you want support for cameras based on the SONIXJ chip. 98 Say Y here if you want support for cameras based on the SONIXJ chip.
99 99
100 To compile this driver as a module, choose M here: the 100 To compile this driver as a module, choose M here: the
101 module will be called gspca_sonixj 101 module will be called gspca_sonixj
102 102
103config USB_GSPCA_SPCA500 103config USB_GSPCA_SPCA500
104 tristate "SPCA500 USB Camera Driver" 104 tristate "SPCA500 USB Camera Driver"
105 depends on VIDEO_V4L2 && USB_GSPCA 105 depends on VIDEO_V4L2 && USB_GSPCA
106 help 106 help
107 Say Y here if you want support for cameras based on the SPCA500 chip. 107 Say Y here if you want support for cameras based on the SPCA500 chip.
108 108
109 To compile this driver as a module, choose M here: the 109 To compile this driver as a module, choose M here: the
110 module will be called gspca_spca500. 110 module will be called gspca_spca500.
111 111
112config USB_GSPCA_SPCA501 112config USB_GSPCA_SPCA501
113 tristate "SPCA501 USB Camera Driver" 113 tristate "SPCA501 USB Camera Driver"
114 depends on VIDEO_V4L2 && USB_GSPCA 114 depends on VIDEO_V4L2 && USB_GSPCA
115 help 115 help
116 Say Y here if you want support for cameras based on the SPCA501 chip. 116 Say Y here if you want support for cameras based on the SPCA501 chip.
117 117
118 To compile this driver as a module, choose M here: the 118 To compile this driver as a module, choose M here: the
119 module will be called gspca_spca501. 119 module will be called gspca_spca501.
120 120
121config USB_GSPCA_SPCA505 121config USB_GSPCA_SPCA505
122 tristate "SPCA505 USB Camera Driver" 122 tristate "SPCA505 USB Camera Driver"
123 depends on VIDEO_V4L2 && USB_GSPCA 123 depends on VIDEO_V4L2 && USB_GSPCA
124 help 124 help
125 Say Y here if you want support for cameras based on the SPCA505 chip. 125 Say Y here if you want support for cameras based on the SPCA505 chip.
126 126
127 To compile this driver as a module, choose M here: the 127 To compile this driver as a module, choose M here: the
128 module will be called gspca_spca505. 128 module will be called gspca_spca505.
129 129
130config USB_GSPCA_SPCA506 130config USB_GSPCA_SPCA506
131 tristate "SPCA506 USB Camera Driver" 131 tristate "SPCA506 USB Camera Driver"
132 depends on VIDEO_V4L2 && USB_GSPCA 132 depends on VIDEO_V4L2 && USB_GSPCA
133 help 133 help
134 Say Y here if you want support for cameras based on the SPCA506 chip. 134 Say Y here if you want support for cameras based on the SPCA506 chip.
135 135
136 To compile this driver as a module, choose M here: the 136 To compile this driver as a module, choose M here: the
137 module will be called gspca_spca506. 137 module will be called gspca_spca506.
138 138
139config USB_GSPCA_SPCA508 139config USB_GSPCA_SPCA508
140 tristate "SPCA508 USB Camera Driver" 140 tristate "SPCA508 USB Camera Driver"
141 depends on VIDEO_V4L2 && USB_GSPCA 141 depends on VIDEO_V4L2 && USB_GSPCA
142 help 142 help
143 Say Y here if you want support for cameras based on the SPCA508 chip. 143 Say Y here if you want support for cameras based on the SPCA508 chip.
144 144
145 To compile this driver as a module, choose M here: the 145 To compile this driver as a module, choose M here: the
146 module will be called gspca_spca508. 146 module will be called gspca_spca508.
147 147
148config USB_GSPCA_SPCA561 148config USB_GSPCA_SPCA561
149 tristate "SPCA561 USB Camera Driver" 149 tristate "SPCA561 USB Camera Driver"
150 depends on VIDEO_V4L2 && USB_GSPCA 150 depends on VIDEO_V4L2 && USB_GSPCA
151 help 151 help
152 Say Y here if you want support for cameras based on the SPCA561 chip. 152 Say Y here if you want support for cameras based on the SPCA561 chip.
153 153
154 To compile this driver as a module, choose M here: the 154 To compile this driver as a module, choose M here: the
155 module will be called gspca_spca561. 155 module will be called gspca_spca561.
156 156
157config USB_GSPCA_STK014 157config USB_GSPCA_STK014
158 tristate "Syntek DV4000 (STK014) USB Camera Driver" 158 tristate "Syntek DV4000 (STK014) USB Camera Driver"
159 depends on VIDEO_V4L2 && USB_GSPCA 159 depends on VIDEO_V4L2 && USB_GSPCA
160 help 160 help
161 Say Y here if you want support for cameras based on the STK014 chip. 161 Say Y here if you want support for cameras based on the STK014 chip.
162 162
163 To compile this driver as a module, choose M here: the 163 To compile this driver as a module, choose M here: the
164 module will be called gspca_stk014. 164 module will be called gspca_stk014.
165 165
166config USB_GSPCA_SUNPLUS 166config USB_GSPCA_SUNPLUS
167 tristate "SUNPLUS USB Camera Driver" 167 tristate "SUNPLUS USB Camera Driver"
168 depends on VIDEO_V4L2 && USB_GSPCA 168 depends on VIDEO_V4L2 && USB_GSPCA
169 help 169 help
170 Say Y here if you want support for cameras based on the Sunplus 170 Say Y here if you want support for cameras based on the Sunplus
171 SPCA504(abc) SPCA533 SPCA536 chips. 171 SPCA504(abc) SPCA533 SPCA536 chips.
172 172
173 To compile this driver as a module, choose M here: the 173 To compile this driver as a module, choose M here: the
174 module will be called gspca_spca5xx. 174 module will be called gspca_spca5xx.
175 175
176config USB_GSPCA_T613 176config USB_GSPCA_T613
177 tristate "T613 (JPEG Compliance) USB Camera Driver" 177 tristate "T613 (JPEG Compliance) USB Camera Driver"
178 depends on VIDEO_V4L2 && USB_GSPCA 178 depends on VIDEO_V4L2 && USB_GSPCA
179 help 179 help
180 Say Y here if you want support for cameras based on the T613 chip. 180 Say Y here if you want support for cameras based on the T613 chip.
181 181
182 To compile this driver as a module, choose M here: the 182 To compile this driver as a module, choose M here: the
183 module will be called gspca_t613. 183 module will be called gspca_t613.
184 184
185config USB_GSPCA_TV8532 185config USB_GSPCA_TV8532
186 tristate "TV8532 USB Camera Driver" 186 tristate "TV8532 USB Camera Driver"
187 depends on VIDEO_V4L2 && USB_GSPCA 187 depends on VIDEO_V4L2 && USB_GSPCA
188 help 188 help
189 Say Y here if you want support for cameras based on the TV8531 chip. 189 Say Y here if you want support for cameras based on the TV8531 chip.
190 190
191 To compile this driver as a module, choose M here: the 191 To compile this driver as a module, choose M here: the
192 module will be called gspca_tv8532. 192 module will be called gspca_tv8532.
193 193
194config USB_GSPCA_VC032X 194config USB_GSPCA_VC032X
195 tristate "VC032X USB Camera Driver" 195 tristate "VC032X USB Camera Driver"
196 depends on VIDEO_V4L2 && USB_GSPCA 196 depends on VIDEO_V4L2 && USB_GSPCA
197 help 197 help
198 Say Y here if you want support for cameras based on the VC032X chip. 198 Say Y here if you want support for cameras based on the VC032X chip.
199 199
200 To compile this driver as a module, choose M here: the 200 To compile this driver as a module, choose M here: the
201 module will be called gspca_vc032x. 201 module will be called gspca_vc032x.
202 202
203config USB_GSPCA_ZC3XX 203config USB_GSPCA_ZC3XX
204 tristate "VC3xx USB Camera Driver" 204 tristate "ZC3XX USB Camera Driver"
205 depends on VIDEO_V4L2 && USB_GSPCA 205 depends on VIDEO_V4L2 && USB_GSPCA
206 help 206 help
207 Say Y here if you want support for cameras based on the ZC3XX chip. 207 Say Y here if you want support for cameras based on the ZC3XX chip.
208 208
209 To compile this driver as a module, choose M here: the 209 To compile this driver as a module, choose M here: the
210 module will be called gspca_zc3xx. 210 module will be called gspca_zc3xx.
211 211
212endif 212endif
diff --git a/drivers/media/video/gspca/conex.c b/drivers/media/video/gspca/conex.c
index a9d51ba7c57c..de28354ea5ba 100644
--- a/drivers/media/video/gspca/conex.c
+++ b/drivers/media/video/gspca/conex.c
@@ -846,10 +846,13 @@ static int sd_start(struct gspca_dev *gspca_dev)
846 return 0; 846 return 0;
847} 847}
848 848
849/* called on streamoff with alt 0 and on disconnect */
849static void sd_stop0(struct gspca_dev *gspca_dev) 850static void sd_stop0(struct gspca_dev *gspca_dev)
850{ 851{
851 int retry = 50; 852 int retry = 50;
852 853
854 if (!gspca_dev->present)
855 return;
853 reg_w_val(gspca_dev, 0x0000, 0x00); 856 reg_w_val(gspca_dev, 0x0000, 0x00);
854 reg_r(gspca_dev, 0x0002, 1); 857 reg_r(gspca_dev, 0x0002, 1);
855 reg_w_val(gspca_dev, 0x0053, 0x00); 858 reg_w_val(gspca_dev, 0x0053, 0x00);
diff --git a/drivers/media/video/gspca/finepix.c b/drivers/media/video/gspca/finepix.c
index 65d3cbfe6b27..607942fd7970 100644
--- a/drivers/media/video/gspca/finepix.c
+++ b/drivers/media/video/gspca/finepix.c
@@ -276,6 +276,12 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
276 /* Stop the state machine */ 276 /* Stop the state machine */
277 if (dev->state != FPIX_NOP) 277 if (dev->state != FPIX_NOP)
278 wait_for_completion(&dev->can_close); 278 wait_for_completion(&dev->can_close);
279}
280
281/* called on streamoff with alt 0 and disconnect */
282static void sd_stop0(struct gspca_dev *gspca_dev)
283{
284 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
279 285
280 usb_free_urb(dev->control_urb); 286 usb_free_urb(dev->control_urb);
281 dev->control_urb = NULL; 287 dev->control_urb = NULL;
@@ -385,6 +391,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
385error: 391error:
386 /* Free the ressources */ 392 /* Free the ressources */
387 sd_stopN(gspca_dev); 393 sd_stopN(gspca_dev);
394 sd_stop0(gspca_dev);
388 return ret; 395 return ret;
389} 396}
390 397
@@ -425,6 +432,7 @@ static const struct sd_desc sd_desc = {
425 .init = sd_init, 432 .init = sd_init,
426 .start = sd_start, 433 .start = sd_start,
427 .stopN = sd_stopN, 434 .stopN = sd_stopN,
435 .stop0 = sd_stop0,
428}; 436};
429 437
430/* -- device connect -- */ 438/* -- device connect -- */
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index e48fbfc8ad05..02a6e9ef0337 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -646,15 +646,14 @@ static void gspca_stream_off(struct gspca_dev *gspca_dev)
646{ 646{
647 gspca_dev->streaming = 0; 647 gspca_dev->streaming = 0;
648 atomic_set(&gspca_dev->nevent, 0); 648 atomic_set(&gspca_dev->nevent, 0);
649 if (gspca_dev->present) { 649 if (gspca_dev->present
650 if (gspca_dev->sd_desc->stopN) 650 && gspca_dev->sd_desc->stopN)
651 gspca_dev->sd_desc->stopN(gspca_dev); 651 gspca_dev->sd_desc->stopN(gspca_dev);
652 destroy_urbs(gspca_dev); 652 destroy_urbs(gspca_dev);
653 gspca_set_alt0(gspca_dev); 653 gspca_set_alt0(gspca_dev);
654 if (gspca_dev->sd_desc->stop0) 654 if (gspca_dev->sd_desc->stop0)
655 gspca_dev->sd_desc->stop0(gspca_dev); 655 gspca_dev->sd_desc->stop0(gspca_dev);
656 PDEBUG(D_STREAM, "stream off OK"); 656 PDEBUG(D_STREAM, "stream off OK");
657 }
658} 657}
659 658
660static void gspca_set_default_mode(struct gspca_dev *gspca_dev) 659static void gspca_set_default_mode(struct gspca_dev *gspca_dev)
@@ -863,7 +862,7 @@ static int dev_open(struct inode *inode, struct file *file)
863 int ret; 862 int ret;
864 863
865 PDEBUG(D_STREAM, "%s open", current->comm); 864 PDEBUG(D_STREAM, "%s open", current->comm);
866 gspca_dev = (struct gspca_dev *) video_devdata(file); 865 gspca_dev = video_drvdata(file);
867 if (mutex_lock_interruptible(&gspca_dev->queue_lock)) 866 if (mutex_lock_interruptible(&gspca_dev->queue_lock))
868 return -ERESTARTSYS; 867 return -ERESTARTSYS;
869 if (!gspca_dev->present) { 868 if (!gspca_dev->present) {
@@ -875,6 +874,13 @@ static int dev_open(struct inode *inode, struct file *file)
875 ret = -EBUSY; 874 ret = -EBUSY;
876 goto out; 875 goto out;
877 } 876 }
877
878 /* protect the subdriver against rmmod */
879 if (!try_module_get(gspca_dev->module)) {
880 ret = -ENODEV;
881 goto out;
882 }
883
878 gspca_dev->users++; 884 gspca_dev->users++;
879 885
880 /* one more user */ 886 /* one more user */
@@ -884,10 +890,10 @@ static int dev_open(struct inode *inode, struct file *file)
884#ifdef GSPCA_DEBUG 890#ifdef GSPCA_DEBUG
885 /* activate the v4l2 debug */ 891 /* activate the v4l2 debug */
886 if (gspca_debug & D_V4L2) 892 if (gspca_debug & D_V4L2)
887 gspca_dev->vdev.debug |= V4L2_DEBUG_IOCTL 893 gspca_dev->vdev->debug |= V4L2_DEBUG_IOCTL
888 | V4L2_DEBUG_IOCTL_ARG; 894 | V4L2_DEBUG_IOCTL_ARG;
889 else 895 else
890 gspca_dev->vdev.debug &= ~(V4L2_DEBUG_IOCTL 896 gspca_dev->vdev->debug &= ~(V4L2_DEBUG_IOCTL
891 | V4L2_DEBUG_IOCTL_ARG); 897 | V4L2_DEBUG_IOCTL_ARG);
892#endif 898#endif
893 ret = 0; 899 ret = 0;
@@ -921,6 +927,7 @@ static int dev_close(struct inode *inode, struct file *file)
921 gspca_dev->memory = GSPCA_MEMORY_NO; 927 gspca_dev->memory = GSPCA_MEMORY_NO;
922 } 928 }
923 file->private_data = NULL; 929 file->private_data = NULL;
930 module_put(gspca_dev->module);
924 mutex_unlock(&gspca_dev->queue_lock); 931 mutex_unlock(&gspca_dev->queue_lock);
925 932
926 PDEBUG(D_STREAM, "close done"); 933 PDEBUG(D_STREAM, "close done");
@@ -1257,10 +1264,10 @@ static int vidioc_s_jpegcomp(struct file *file, void *priv,
1257 struct gspca_dev *gspca_dev = priv; 1264 struct gspca_dev *gspca_dev = priv;
1258 int ret; 1265 int ret;
1259 1266
1260 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
1261 return -ERESTARTSYS;
1262 if (!gspca_dev->sd_desc->set_jcomp) 1267 if (!gspca_dev->sd_desc->set_jcomp)
1263 return -EINVAL; 1268 return -EINVAL;
1269 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
1270 return -ERESTARTSYS;
1264 ret = gspca_dev->sd_desc->set_jcomp(gspca_dev, jpegcomp); 1271 ret = gspca_dev->sd_desc->set_jcomp(gspca_dev, jpegcomp);
1265 mutex_unlock(&gspca_dev->usb_lock); 1272 mutex_unlock(&gspca_dev->usb_lock);
1266 return ret; 1273 return ret;
@@ -1748,11 +1755,6 @@ out:
1748 return ret; 1755 return ret;
1749} 1756}
1750 1757
1751static void dev_release(struct video_device *vfd)
1752{
1753 /* nothing */
1754}
1755
1756static struct file_operations dev_fops = { 1758static struct file_operations dev_fops = {
1757 .owner = THIS_MODULE, 1759 .owner = THIS_MODULE,
1758 .open = dev_open, 1760 .open = dev_open,
@@ -1800,7 +1802,7 @@ static struct video_device gspca_template = {
1800 .name = "gspca main driver", 1802 .name = "gspca main driver",
1801 .fops = &dev_fops, 1803 .fops = &dev_fops,
1802 .ioctl_ops = &dev_ioctl_ops, 1804 .ioctl_ops = &dev_ioctl_ops,
1803 .release = dev_release, /* mandatory */ 1805 .release = video_device_release,
1804 .minor = -1, 1806 .minor = -1,
1805}; 1807};
1806 1808
@@ -1869,17 +1871,18 @@ int gspca_dev_probe(struct usb_interface *intf,
1869 init_waitqueue_head(&gspca_dev->wq); 1871 init_waitqueue_head(&gspca_dev->wq);
1870 1872
1871 /* init video stuff */ 1873 /* init video stuff */
1872 memcpy(&gspca_dev->vdev, &gspca_template, sizeof gspca_template); 1874 gspca_dev->vdev = video_device_alloc();
1873 gspca_dev->vdev.parent = &dev->dev; 1875 memcpy(gspca_dev->vdev, &gspca_template, sizeof gspca_template);
1874 memcpy(&gspca_dev->fops, &dev_fops, sizeof gspca_dev->fops); 1876 gspca_dev->vdev->parent = &dev->dev;
1875 gspca_dev->vdev.fops = &gspca_dev->fops; 1877 gspca_dev->module = module;
1876 gspca_dev->fops.owner = module; /* module protection */
1877 gspca_dev->present = 1; 1878 gspca_dev->present = 1;
1878 ret = video_register_device(&gspca_dev->vdev, 1879 video_set_drvdata(gspca_dev->vdev, gspca_dev);
1880 ret = video_register_device(gspca_dev->vdev,
1879 VFL_TYPE_GRABBER, 1881 VFL_TYPE_GRABBER,
1880 video_nr); 1882 video_nr);
1881 if (ret < 0) { 1883 if (ret < 0) {
1882 err("video_register_device err %d", ret); 1884 err("video_register_device err %d", ret);
1885 video_device_release(gspca_dev->vdev);
1883 goto out; 1886 goto out;
1884 } 1887 }
1885 1888
@@ -1887,7 +1890,8 @@ int gspca_dev_probe(struct usb_interface *intf,
1887 PDEBUG(D_PROBE, "probe ok"); 1890 PDEBUG(D_PROBE, "probe ok");
1888 return 0; 1891 return 0;
1889out: 1892out:
1890 kref_put(&gspca_dev->kref, gspca_delete); 1893 kfree(gspca_dev->usb_buf);
1894 kfree(gspca_dev);
1891 return ret; 1895 return ret;
1892} 1896}
1893EXPORT_SYMBOL(gspca_dev_probe); 1897EXPORT_SYMBOL(gspca_dev_probe);
@@ -1905,7 +1909,7 @@ void gspca_disconnect(struct usb_interface *intf)
1905 usb_set_intfdata(intf, NULL); 1909 usb_set_intfdata(intf, NULL);
1906 1910
1907/* We don't want people trying to open up the device */ 1911/* We don't want people trying to open up the device */
1908 video_unregister_device(&gspca_dev->vdev); 1912 video_unregister_device(gspca_dev->vdev);
1909 1913
1910 gspca_dev->present = 0; 1914 gspca_dev->present = 0;
1911 gspca_dev->streaming = 0; 1915 gspca_dev->streaming = 0;
diff --git a/drivers/media/video/gspca/gspca.h b/drivers/media/video/gspca/gspca.h
index 1d9dc90b4791..d25e8d69373b 100644
--- a/drivers/media/video/gspca/gspca.h
+++ b/drivers/media/video/gspca/gspca.h
@@ -97,7 +97,7 @@ struct sd_desc {
97 cam_pkt_op pkt_scan; 97 cam_pkt_op pkt_scan;
98/* optional operations */ 98/* optional operations */
99 cam_v_op stopN; /* called on stream off - main alt */ 99 cam_v_op stopN; /* called on stream off - main alt */
100 cam_v_op stop0; /* called on stream off - alt 0 */ 100 cam_v_op stop0; /* called on stream off & disconnect - alt 0 */
101 cam_v_op dq_callback; /* called when a frame has been dequeued */ 101 cam_v_op dq_callback; /* called when a frame has been dequeued */
102 cam_jpg_op get_jcomp; 102 cam_jpg_op get_jcomp;
103 cam_jpg_op set_jcomp; 103 cam_jpg_op set_jcomp;
@@ -120,8 +120,8 @@ struct gspca_frame {
120}; 120};
121 121
122struct gspca_dev { 122struct gspca_dev {
123 struct video_device vdev; /* !! must be the first item */ 123 struct video_device *vdev;
124 struct file_operations fops; 124 struct module *module; /* subdriver handling the device */
125 struct usb_device *dev; 125 struct usb_device *dev;
126 struct kref kref; 126 struct kref kref;
127 struct file *capt_file; /* file doing video capture */ 127 struct file *capt_file; /* file doing video capture */
diff --git a/drivers/media/video/gspca/pac7311.c b/drivers/media/video/gspca/pac7311.c
index e5ff9a6199ef..fbd45e235d97 100644
--- a/drivers/media/video/gspca/pac7311.c
+++ b/drivers/media/video/gspca/pac7311.c
@@ -749,10 +749,13 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
749 reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */ 749 reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
750} 750}
751 751
752/* called on streamoff with alt 0 and on disconnect */
752static void sd_stop0(struct gspca_dev *gspca_dev) 753static void sd_stop0(struct gspca_dev *gspca_dev)
753{ 754{
754 struct sd *sd = (struct sd *) gspca_dev; 755 struct sd *sd = (struct sd *) gspca_dev;
755 756
757 if (!gspca_dev->present)
758 return;
756 if (sd->sensor == SENSOR_PAC7302) { 759 if (sd->sensor == SENSOR_PAC7302) {
757 reg_w(gspca_dev, 0xff, 0x01); 760 reg_w(gspca_dev, 0xff, 0x01);
758 reg_w(gspca_dev, 0x78, 0x40); 761 reg_w(gspca_dev, 0x78, 0x40);
diff --git a/drivers/media/video/gspca/spca501.c b/drivers/media/video/gspca/spca501.c
index b742f260c7ca..e29954c1c38c 100644
--- a/drivers/media/video/gspca/spca501.c
+++ b/drivers/media/video/gspca/spca501.c
@@ -2022,8 +2022,11 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
2022 reg_write(gspca_dev->dev, SPCA501_REG_CTLRL, 0x01, 0x00); 2022 reg_write(gspca_dev->dev, SPCA501_REG_CTLRL, 0x01, 0x00);
2023} 2023}
2024 2024
2025/* called on streamoff with alt 0 and on disconnect */
2025static void sd_stop0(struct gspca_dev *gspca_dev) 2026static void sd_stop0(struct gspca_dev *gspca_dev)
2026{ 2027{
2028 if (!gspca_dev->present)
2029 return;
2027 reg_write(gspca_dev->dev, SPCA501_REG_CTLRL, 0x05, 0x00); 2030 reg_write(gspca_dev->dev, SPCA501_REG_CTLRL, 0x05, 0x00);
2028} 2031}
2029 2032
diff --git a/drivers/media/video/gspca/spca505.c b/drivers/media/video/gspca/spca505.c
index b345749213cf..895b9fe4018c 100644
--- a/drivers/media/video/gspca/spca505.c
+++ b/drivers/media/video/gspca/spca505.c
@@ -742,8 +742,12 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
742 reg_write(gspca_dev->dev, 0x02, 0x00, 0x00); 742 reg_write(gspca_dev->dev, 0x02, 0x00, 0x00);
743} 743}
744 744
745/* called on streamoff with alt 0 and on disconnect */
745static void sd_stop0(struct gspca_dev *gspca_dev) 746static void sd_stop0(struct gspca_dev *gspca_dev)
746{ 747{
748 if (!gspca_dev->present)
749 return;
750
747 /* This maybe reset or power control */ 751 /* This maybe reset or power control */
748 reg_write(gspca_dev->dev, 0x03, 0x03, 0x20); 752 reg_write(gspca_dev->dev, 0x03, 0x03, 0x20);
749 reg_write(gspca_dev->dev, 0x03, 0x01, 0x0); 753 reg_write(gspca_dev->dev, 0x03, 0x01, 0x0);
diff --git a/drivers/media/video/gspca/spca561.c b/drivers/media/video/gspca/spca561.c
index 020a03c466c1..c3de4e44123d 100644
--- a/drivers/media/video/gspca/spca561.c
+++ b/drivers/media/video/gspca/spca561.c
@@ -766,10 +766,13 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
766 } 766 }
767} 767}
768 768
769/* called on streamoff with alt 0 and on disconnect */
769static void sd_stop0(struct gspca_dev *gspca_dev) 770static void sd_stop0(struct gspca_dev *gspca_dev)
770{ 771{
771 struct sd *sd = (struct sd *) gspca_dev; 772 struct sd *sd = (struct sd *) gspca_dev;
772 773
774 if (!gspca_dev->present)
775 return;
773 if (sd->chip_revision == Rev012A) { 776 if (sd->chip_revision == Rev012A) {
774 reg_w_val(gspca_dev->dev, 0x8118, 0x29); 777 reg_w_val(gspca_dev->dev, 0x8118, 0x29);
775 reg_w_val(gspca_dev->dev, 0x8114, 0x08); 778 reg_w_val(gspca_dev->dev, 0x8114, 0x08);
diff --git a/drivers/media/video/gspca/vc032x.c b/drivers/media/video/gspca/vc032x.c
index be46d9232540..17af353ddd1c 100644
--- a/drivers/media/video/gspca/vc032x.c
+++ b/drivers/media/video/gspca/vc032x.c
@@ -1633,10 +1633,13 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1633 reg_w(dev, 0xa0, 0x09, 0xb003); 1633 reg_w(dev, 0xa0, 0x09, 0xb003);
1634} 1634}
1635 1635
1636/* called on streamoff with alt 0 and on disconnect */
1636static void sd_stop0(struct gspca_dev *gspca_dev) 1637static void sd_stop0(struct gspca_dev *gspca_dev)
1637{ 1638{
1638 struct usb_device *dev = gspca_dev->dev; 1639 struct usb_device *dev = gspca_dev->dev;
1639 1640
1641 if (!gspca_dev->present)
1642 return;
1640 reg_w(dev, 0x89, 0xffff, 0xffff); 1643 reg_w(dev, 0x89, 0xffff, 0xffff);
1641} 1644}
1642 1645
diff --git a/drivers/media/video/gspca/zc3xx.c b/drivers/media/video/gspca/zc3xx.c
index d0a4451dc46f..0befacf49855 100644
--- a/drivers/media/video/gspca/zc3xx.c
+++ b/drivers/media/video/gspca/zc3xx.c
@@ -2266,7 +2266,7 @@ static const struct usb_action hdcs2020b_NoFliker[] = {
2266 {} 2266 {}
2267}; 2267};
2268 2268
2269static const struct usb_action hv7131bxx_Initial[] = { 2269static const struct usb_action hv7131bxx_Initial[] = { /* 320x240 */
2270 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 2270 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
2271 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, 2271 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT},
2272 {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT}, 2272 {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT},
@@ -2290,7 +2290,7 @@ static const struct usb_action hv7131bxx_Initial[] = {
2290 {0xaa, 0x14, 0x0001}, 2290 {0xaa, 0x14, 0x0001},
2291 {0xaa, 0x15, 0x00e8}, 2291 {0xaa, 0x15, 0x00e8},
2292 {0xaa, 0x16, 0x0002}, 2292 {0xaa, 0x16, 0x0002},
2293 {0xaa, 0x17, 0x0086}, 2293 {0xaa, 0x17, 0x0086}, /* 00,17,88,aa */
2294 {0xaa, 0x31, 0x0038}, 2294 {0xaa, 0x31, 0x0038},
2295 {0xaa, 0x32, 0x0038}, 2295 {0xaa, 0x32, 0x0038},
2296 {0xaa, 0x33, 0x0038}, 2296 {0xaa, 0x33, 0x0038},
@@ -2309,7 +2309,7 @@ static const struct usb_action hv7131bxx_Initial[] = {
2309 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05}, 2309 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
2310 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, 2310 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
2311 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, 2311 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
2312 {0xaa, 0x02, 0x0080}, /* {0xaa, 0x02, 0x0090}; */ 2312 {0xaa, 0x02, 0x0090}, /* 00,02,80,aa */
2313 {0xa1, 0x01, 0x0002}, 2313 {0xa1, 0x01, 0x0002},
2314 {0xa0, 0x00, ZC3XX_R092_I2CADDRESSSELECT}, 2314 {0xa0, 0x00, ZC3XX_R092_I2CADDRESSSELECT},
2315 {0xa0, 0x02, ZC3XX_R090_I2CCOMMAND}, 2315 {0xa0, 0x02, ZC3XX_R090_I2CCOMMAND},
@@ -2374,7 +2374,7 @@ static const struct usb_action hv7131bxx_Initial[] = {
2374 {} 2374 {}
2375}; 2375};
2376 2376
2377static const struct usb_action hv7131bxx_InitialScale[] = { 2377static const struct usb_action hv7131bxx_InitialScale[] = { /* 640x480*/
2378 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 2378 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
2379 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, 2379 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT},
2380 {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT}, 2380 {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT},
@@ -6388,6 +6388,8 @@ static void setbrightness(struct gspca_dev *gspca_dev)
6388/*fixme: is it really write to 011d and 018d for all other sensors? */ 6388/*fixme: is it really write to 011d and 018d for all other sensors? */
6389 brightness = sd->brightness; 6389 brightness = sd->brightness;
6390 reg_w(gspca_dev->dev, brightness, 0x011d); 6390 reg_w(gspca_dev->dev, brightness, 0x011d);
6391 if (sd->sensor == SENSOR_HV7131B)
6392 return;
6391 if (brightness < 0x70) 6393 if (brightness < 0x70)
6392 brightness += 0x10; 6394 brightness += 0x10;
6393 else 6395 else
@@ -6529,6 +6531,7 @@ static void setquality(struct gspca_dev *gspca_dev)
6529 6531
6530 switch (sd->sensor) { 6532 switch (sd->sensor) {
6531 case SENSOR_GC0305: 6533 case SENSOR_GC0305:
6534 case SENSOR_HV7131B:
6532 case SENSOR_OV7620: 6535 case SENSOR_OV7620:
6533 case SENSOR_PO2030: 6536 case SENSOR_PO2030:
6534 return; 6537 return;
@@ -7209,7 +7212,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
7209 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 7212 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
7210 zc3_init = init_tb[(int) sd->sensor][mode]; 7213 zc3_init = init_tb[(int) sd->sensor][mode];
7211 switch (sd->sensor) { 7214 switch (sd->sensor) {
7212 case SENSOR_HV7131B:
7213 case SENSOR_HV7131C: 7215 case SENSOR_HV7131C:
7214 zcxx_probeSensor(gspca_dev); 7216 zcxx_probeSensor(gspca_dev);
7215 break; 7217 break;
@@ -7334,10 +7336,13 @@ static int sd_start(struct gspca_dev *gspca_dev)
7334 return 0; 7336 return 0;
7335} 7337}
7336 7338
7339/* called on streamoff with alt 0 and on disconnect */
7337static void sd_stop0(struct gspca_dev *gspca_dev) 7340static void sd_stop0(struct gspca_dev *gspca_dev)
7338{ 7341{
7339 struct sd *sd = (struct sd *) gspca_dev; 7342 struct sd *sd = (struct sd *) gspca_dev;
7340 7343
7344 if (!gspca_dev->present)
7345 return;
7341 send_unknown(gspca_dev->dev, sd->sensor); 7346 send_unknown(gspca_dev->dev, sd->sensor);
7342} 7347}
7343 7348
diff --git a/drivers/media/video/ivtv/Kconfig b/drivers/media/video/ivtv/Kconfig
index 0069898bddab..c46bfb1569e3 100644
--- a/drivers/media/video/ivtv/Kconfig
+++ b/drivers/media/video/ivtv/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_IVTV 1config VIDEO_IVTV
2 tristate "Conexant cx23416/cx23415 MPEG encoder/decoder support" 2 tristate "Conexant cx23416/cx23415 MPEG encoder/decoder support"
3 depends on VIDEO_V4L1 && VIDEO_V4L2 && PCI && I2C && EXPERIMENTAL 3 depends on VIDEO_V4L2 && PCI && I2C
4 depends on INPUT # due to VIDEO_IR 4 depends on INPUT # due to VIDEO_IR
5 select I2C_ALGOBIT 5 select I2C_ALGOBIT
6 select VIDEO_IR 6 select VIDEO_IR
@@ -12,7 +12,6 @@ config VIDEO_IVTV
12 select VIDEO_SAA711X 12 select VIDEO_SAA711X
13 select VIDEO_SAA717X 13 select VIDEO_SAA717X
14 select VIDEO_SAA7127 14 select VIDEO_SAA7127
15 select VIDEO_TVAUDIO
16 select VIDEO_CS53L32A 15 select VIDEO_CS53L32A
17 select VIDEO_M52790 16 select VIDEO_M52790
18 select VIDEO_WM8775 17 select VIDEO_WM8775
@@ -32,7 +31,7 @@ config VIDEO_IVTV
32 31
33config VIDEO_FB_IVTV 32config VIDEO_FB_IVTV
34 tristate "Conexant cx23415 framebuffer support" 33 tristate "Conexant cx23415 framebuffer support"
35 depends on VIDEO_IVTV && FB && EXPERIMENTAL 34 depends on VIDEO_IVTV && FB
36 select FB_CFB_FILLRECT 35 select FB_CFB_FILLRECT
37 select FB_CFB_COPYAREA 36 select FB_CFB_COPYAREA
38 select FB_CFB_IMAGEBLIT 37 select FB_CFB_IMAGEBLIT
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index d36485023b68..b69cc1d55e5b 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -875,43 +875,43 @@ static void ivtv_load_and_init_modules(struct ivtv *itv)
875 875
876#ifdef MODULE 876#ifdef MODULE
877 /* load modules */ 877 /* load modules */
878#ifndef CONFIG_MEDIA_TUNER 878#ifdef CONFIG_MEDIA_TUNER_MODULE
879 hw = ivtv_request_module(itv, hw, "tuner", IVTV_HW_TUNER); 879 hw = ivtv_request_module(itv, hw, "tuner", IVTV_HW_TUNER);
880#endif 880#endif
881#ifndef CONFIG_VIDEO_CX25840 881#ifdef CONFIG_VIDEO_CX25840_MODULE
882 hw = ivtv_request_module(itv, hw, "cx25840", IVTV_HW_CX25840); 882 hw = ivtv_request_module(itv, hw, "cx25840", IVTV_HW_CX25840);
883#endif 883#endif
884#ifndef CONFIG_VIDEO_SAA711X 884#ifdef CONFIG_VIDEO_SAA711X_MODULE
885 hw = ivtv_request_module(itv, hw, "saa7115", IVTV_HW_SAA711X); 885 hw = ivtv_request_module(itv, hw, "saa7115", IVTV_HW_SAA711X);
886#endif 886#endif
887#ifndef CONFIG_VIDEO_SAA7127 887#ifdef CONFIG_VIDEO_SAA7127_MODULE
888 hw = ivtv_request_module(itv, hw, "saa7127", IVTV_HW_SAA7127); 888 hw = ivtv_request_module(itv, hw, "saa7127", IVTV_HW_SAA7127);
889#endif 889#endif
890#ifndef CONFIG_VIDEO_SAA717X 890#ifdef CONFIG_VIDEO_SAA717X_MODULE
891 hw = ivtv_request_module(itv, hw, "saa717x", IVTV_HW_SAA717X); 891 hw = ivtv_request_module(itv, hw, "saa717x", IVTV_HW_SAA717X);
892#endif 892#endif
893#ifndef CONFIG_VIDEO_UPD64031A 893#ifdef CONFIG_VIDEO_UPD64031A_MODULE
894 hw = ivtv_request_module(itv, hw, "upd64031a", IVTV_HW_UPD64031A); 894 hw = ivtv_request_module(itv, hw, "upd64031a", IVTV_HW_UPD64031A);
895#endif 895#endif
896#ifndef CONFIG_VIDEO_UPD64083 896#ifdef CONFIG_VIDEO_UPD64083_MODULE
897 hw = ivtv_request_module(itv, hw, "upd64083", IVTV_HW_UPD6408X); 897 hw = ivtv_request_module(itv, hw, "upd64083", IVTV_HW_UPD6408X);
898#endif 898#endif
899#ifndef CONFIG_VIDEO_MSP3400 899#ifdef CONFIG_VIDEO_MSP3400_MODULE
900 hw = ivtv_request_module(itv, hw, "msp3400", IVTV_HW_MSP34XX); 900 hw = ivtv_request_module(itv, hw, "msp3400", IVTV_HW_MSP34XX);
901#endif 901#endif
902#ifndef CONFIG_VIDEO_VP27SMPX 902#ifdef CONFIG_VIDEO_VP27SMPX_MODULE
903 hw = ivtv_request_module(itv, hw, "vp27smpx", IVTV_HW_VP27SMPX); 903 hw = ivtv_request_module(itv, hw, "vp27smpx", IVTV_HW_VP27SMPX);
904#endif 904#endif
905#ifndef CONFIG_VIDEO_WM8775 905#ifdef CONFIG_VIDEO_WM8775_MODULE
906 hw = ivtv_request_module(itv, hw, "wm8775", IVTV_HW_WM8775); 906 hw = ivtv_request_module(itv, hw, "wm8775", IVTV_HW_WM8775);
907#endif 907#endif
908#ifndef CONFIG_VIDEO_WM8739 908#ifdef CONFIG_VIDEO_WM8739_MODULE
909 hw = ivtv_request_module(itv, hw, "wm8739", IVTV_HW_WM8739); 909 hw = ivtv_request_module(itv, hw, "wm8739", IVTV_HW_WM8739);
910#endif 910#endif
911#ifndef CONFIG_VIDEO_CS53L32A 911#ifdef CONFIG_VIDEO_CS53L32A_MODULE
912 hw = ivtv_request_module(itv, hw, "cs53l32a", IVTV_HW_CS53L32A); 912 hw = ivtv_request_module(itv, hw, "cs53l32a", IVTV_HW_CS53L32A);
913#endif 913#endif
914#ifndef CONFIG_VIDEO_M52790 914#ifdef CONFIG_VIDEO_M52790_MODULE
915 hw = ivtv_request_module(itv, hw, "m52790", IVTV_HW_M52790); 915 hw = ivtv_request_module(itv, hw, "m52790", IVTV_HW_M52790);
916#endif 916#endif
917#endif 917#endif
diff --git a/drivers/media/video/pvrusb2/Kconfig b/drivers/media/video/pvrusb2/Kconfig
index 19eb274c9cd0..854c2a885358 100644
--- a/drivers/media/video/pvrusb2/Kconfig
+++ b/drivers/media/video/pvrusb2/Kconfig
@@ -42,7 +42,7 @@ config VIDEO_PVRUSB2_DVB
42 select DVB_S5H1411 if !DVB_FE_CUSTOMISE 42 select DVB_S5H1411 if !DVB_FE_CUSTOMISE
43 select DVB_TDA10048 if !DVB_FE_CUSTOMIZE 43 select DVB_TDA10048 if !DVB_FE_CUSTOMIZE
44 select MEDIA_TUNER_TDA18271 if !DVB_FE_CUSTOMIZE 44 select MEDIA_TUNER_TDA18271 if !DVB_FE_CUSTOMIZE
45 select MEDIA_TUNER_SIMPLE if !DVB_FE_CUSTOMISE 45 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE
46 select MEDIA_TUNER_TDA8290 if !DVB_FE_CUSTOMIZE 46 select MEDIA_TUNER_TDA8290 if !DVB_FE_CUSTOMIZE
47 ---help--- 47 ---help---
48 48
diff --git a/drivers/media/video/s2255drv.c b/drivers/media/video/s2255drv.c
index 5272926db73e..3c3f8cf73108 100644
--- a/drivers/media/video/s2255drv.c
+++ b/drivers/media/video/s2255drv.c
@@ -192,7 +192,7 @@ struct s2255_dmaqueue {
192#define S2255_FW_FAILED 3 192#define S2255_FW_FAILED 3
193#define S2255_FW_DISCONNECTING 4 193#define S2255_FW_DISCONNECTING 4
194 194
195#define S2255_FW_MARKER 0x22552f2f 195#define S2255_FW_MARKER cpu_to_le32(0x22552f2f)
196/* 2255 read states */ 196/* 2255 read states */
197#define S2255_READ_IDLE 0 197#define S2255_READ_IDLE 0
198#define S2255_READ_FRAME 1 198#define S2255_READ_FRAME 1
diff --git a/drivers/media/video/saa7110.c b/drivers/media/video/saa7110.c
index adf2ba79496a..37860698f782 100644
--- a/drivers/media/video/saa7110.c
+++ b/drivers/media/video/saa7110.c
@@ -47,7 +47,7 @@ module_param(debug, int, 0);
47MODULE_PARM_DESC(debug, "Debug level (0-1)"); 47MODULE_PARM_DESC(debug, "Debug level (0-1)");
48 48
49#define SAA7110_MAX_INPUT 9 /* 6 CVBS, 3 SVHS */ 49#define SAA7110_MAX_INPUT 9 /* 6 CVBS, 3 SVHS */
50#define SAA7110_MAX_OUTPUT 0 /* its a decoder only */ 50#define SAA7110_MAX_OUTPUT 1 /* 1 YUV */
51 51
52#define SAA7110_NR_REG 0x35 52#define SAA7110_NR_REG 0x35
53 53
@@ -327,7 +327,7 @@ saa7110_command (struct i2c_client *client,
327 327
328 case DECODER_SET_INPUT: 328 case DECODER_SET_INPUT:
329 v = *(int *) arg; 329 v = *(int *) arg;
330 if (v < 0 || v > SAA7110_MAX_INPUT) { 330 if (v < 0 || v >= SAA7110_MAX_INPUT) {
331 v4l_dbg(1, debug, client, "input=%d not available\n", v); 331 v4l_dbg(1, debug, client, "input=%d not available\n", v);
332 return -EINVAL; 332 return -EINVAL;
333 } 333 }
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index 7021bbf5897b..fc2164e28e76 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -34,9 +34,9 @@ config VIDEO_SAA7134_DVB
34 select DVB_NXT200X if !DVB_FE_CUSTOMISE 34 select DVB_NXT200X if !DVB_FE_CUSTOMISE
35 select DVB_TDA10086 if !DVB_FE_CUSTOMISE 35 select DVB_TDA10086 if !DVB_FE_CUSTOMISE
36 select DVB_TDA826X if !DVB_FE_CUSTOMISE 36 select DVB_TDA826X if !DVB_FE_CUSTOMISE
37 select MEDIA_TUNER_TDA827X if !DVB_FE_CUSTOMISE
38 select DVB_ISL6421 if !DVB_FE_CUSTOMISE 37 select DVB_ISL6421 if !DVB_FE_CUSTOMISE
39 select MEDIA_TUNER_SIMPLE if !DVB_FE_CUSTOMISE 38 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMIZE
39 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE
40 ---help--- 40 ---help---
41 This adds support for DVB cards based on the 41 This adds support for DVB cards based on the
42 Philips saa7134 chip. 42 Philips saa7134 chip.
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 249184452949..dfbe08a9ad9b 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -941,7 +941,8 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
941 dev->name,(unsigned long long)pci_resource_start(pci_dev,0)); 941 dev->name,(unsigned long long)pci_resource_start(pci_dev,0));
942 goto fail1; 942 goto fail1;
943 } 943 }
944 dev->lmmio = ioremap(pci_resource_start(pci_dev,0), 0x1000); 944 dev->lmmio = ioremap(pci_resource_start(pci_dev, 0),
945 pci_resource_len(pci_dev, 0));
945 dev->bmmio = (__u8 __iomem *)dev->lmmio; 946 dev->bmmio = (__u8 __iomem *)dev->lmmio;
946 if (NULL == dev->lmmio) { 947 if (NULL == dev->lmmio) {
947 err = -EIO; 948 err = -EIO;
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index b59e47272abf..3720f0e03a16 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * experimental driver for simple i2c audio chips. 2 * Driver for simple i2c audio chips.
3 * 3 *
4 * Copyright (c) 2000 Gerd Knorr 4 * Copyright (c) 2000 Gerd Knorr
5 * based on code by: 5 * based on code by:
@@ -7,6 +7,10 @@
7 * Steve VanDeBogart (vandebo@uclink.berkeley.edu) 7 * Steve VanDeBogart (vandebo@uclink.berkeley.edu)
8 * Greg Alexander (galexand@acm.org) 8 * Greg Alexander (galexand@acm.org)
9 * 9 *
10 * Copyright(c) 2005-2008 Mauro Carvalho Chehab
11 * - Some cleanups, code fixes, etc
12 * - Convert it to V4L2 API
13 *
10 * This code is placed under the terms of the GNU General Public License 14 * This code is placed under the terms of the GNU General Public License
11 * 15 *
12 * OPTIONS: 16 * OPTIONS:
@@ -30,6 +34,7 @@
30 34
31#include <media/tvaudio.h> 35#include <media/tvaudio.h>
32#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h>
33#include <media/v4l2-chip-ident.h> 38#include <media/v4l2-chip-ident.h>
34#include <media/v4l2-i2c-drv-legacy.h> 39#include <media/v4l2-i2c-drv-legacy.h>
35 40
@@ -58,7 +63,6 @@ typedef int (*checkit)(struct CHIPSTATE*);
58typedef int (*initialize)(struct CHIPSTATE*); 63typedef int (*initialize)(struct CHIPSTATE*);
59typedef int (*getmode)(struct CHIPSTATE*); 64typedef int (*getmode)(struct CHIPSTATE*);
60typedef void (*setmode)(struct CHIPSTATE*, int mode); 65typedef void (*setmode)(struct CHIPSTATE*, int mode);
61typedef void (*checkmode)(struct CHIPSTATE*);
62 66
63/* i2c command */ 67/* i2c command */
64typedef struct AUDIOCMD { 68typedef struct AUDIOCMD {
@@ -79,6 +83,7 @@ struct CHIPDESC {
79#define CHIP_HAS_VOLUME 1 83#define CHIP_HAS_VOLUME 1
80#define CHIP_HAS_BASSTREBLE 2 84#define CHIP_HAS_BASSTREBLE 2
81#define CHIP_HAS_INPUTSEL 4 85#define CHIP_HAS_INPUTSEL 4
86#define CHIP_NEED_CHECKMODE 8
82 87
83 /* various i2c command sequences */ 88 /* various i2c command sequences */
84 audiocmd init; 89 audiocmd init;
@@ -96,23 +101,20 @@ struct CHIPDESC {
96 getmode getmode; 101 getmode getmode;
97 setmode setmode; 102 setmode setmode;
98 103
99 /* check / autoswitch audio after channel switches */
100 checkmode checkmode;
101
102 /* input switch register + values for v4l inputs */ 104 /* input switch register + values for v4l inputs */
103 int inputreg; 105 int inputreg;
104 int inputmap[4]; 106 int inputmap[4];
105 int inputmute; 107 int inputmute;
106 int inputmask; 108 int inputmask;
107}; 109};
108static struct CHIPDESC chiplist[];
109 110
110/* current state of the chip */ 111/* current state of the chip */
111struct CHIPSTATE { 112struct CHIPSTATE {
112 struct i2c_client *c; 113 struct i2c_client *c;
113 114
114 /* index into CHIPDESC array */ 115 /* chip-specific description - should point to
115 int type; 116 an entry at CHIPDESC table */
117 struct CHIPDESC *desc;
116 118
117 /* shadow register set */ 119 /* shadow register set */
118 audiocmd shadow; 120 audiocmd shadow;
@@ -152,7 +154,7 @@ static int chip_write(struct CHIPSTATE *chip, int subaddr, int val)
152{ 154{
153 unsigned char buffer[2]; 155 unsigned char buffer[2];
154 156
155 if (-1 == subaddr) { 157 if (subaddr < 0) {
156 v4l_dbg(1, debug, chip->c, "%s: chip_write: 0x%x\n", 158 v4l_dbg(1, debug, chip->c, "%s: chip_write: 0x%x\n",
157 chip->c->name, val); 159 chip->c->name, val);
158 chip->shadow.bytes[1] = val; 160 chip->shadow.bytes[1] = val;
@@ -163,6 +165,13 @@ static int chip_write(struct CHIPSTATE *chip, int subaddr, int val)
163 return -1; 165 return -1;
164 } 166 }
165 } else { 167 } else {
168 if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) {
169 v4l_info(chip->c,
170 "Tried to access a non-existent register: %d\n",
171 subaddr);
172 return -EINVAL;
173 }
174
166 v4l_dbg(1, debug, chip->c, "%s: chip_write: reg%d=0x%x\n", 175 v4l_dbg(1, debug, chip->c, "%s: chip_write: reg%d=0x%x\n",
167 chip->c->name, subaddr, val); 176 chip->c->name, subaddr, val);
168 chip->shadow.bytes[subaddr+1] = val; 177 chip->shadow.bytes[subaddr+1] = val;
@@ -177,12 +186,20 @@ static int chip_write(struct CHIPSTATE *chip, int subaddr, int val)
177 return 0; 186 return 0;
178} 187}
179 188
180static int chip_write_masked(struct CHIPSTATE *chip, int subaddr, int val, int mask) 189static int chip_write_masked(struct CHIPSTATE *chip,
190 int subaddr, int val, int mask)
181{ 191{
182 if (mask != 0) { 192 if (mask != 0) {
183 if (-1 == subaddr) { 193 if (subaddr < 0) {
184 val = (chip->shadow.bytes[1] & ~mask) | (val & mask); 194 val = (chip->shadow.bytes[1] & ~mask) | (val & mask);
185 } else { 195 } else {
196 if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) {
197 v4l_info(chip->c,
198 "Tried to access a non-existent register: %d\n",
199 subaddr);
200 return -EINVAL;
201 }
202
186 val = (chip->shadow.bytes[subaddr+1] & ~mask) | (val & mask); 203 val = (chip->shadow.bytes[subaddr+1] & ~mask) | (val & mask);
187 } 204 }
188 } 205 }
@@ -228,6 +245,15 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd)
228 if (0 == cmd->count) 245 if (0 == cmd->count)
229 return 0; 246 return 0;
230 247
248 if (cmd->count + cmd->bytes[0] - 1 >= ARRAY_SIZE(chip->shadow.bytes)) {
249 v4l_info(chip->c,
250 "Tried to access a non-existent register range: %d to %d\n",
251 cmd->bytes[0] + 1, cmd->bytes[0] + cmd->count - 1);
252 return -EINVAL;
253 }
254
255 /* FIXME: it seems that the shadow bytes are wrong bellow !*/
256
231 /* update our shadow register set; print bytes if (debug > 0) */ 257 /* update our shadow register set; print bytes if (debug > 0) */
232 v4l_dbg(1, debug, chip->c, "%s: chip_cmd(%s): reg=%d, data:", 258 v4l_dbg(1, debug, chip->c, "%s: chip_cmd(%s): reg=%d, data:",
233 chip->c->name, name,cmd->bytes[0]); 259 chip->c->name, name,cmd->bytes[0]);
@@ -263,7 +289,8 @@ static void chip_thread_wake(unsigned long data)
263static int chip_thread(void *data) 289static int chip_thread(void *data)
264{ 290{
265 struct CHIPSTATE *chip = data; 291 struct CHIPSTATE *chip = data;
266 struct CHIPDESC *desc = chiplist + chip->type; 292 struct CHIPDESC *desc = chip->desc;
293 int mode;
267 294
268 v4l_dbg(1, debug, chip->c, "%s: thread started\n", chip->c->name); 295 v4l_dbg(1, debug, chip->c, "%s: thread started\n", chip->c->name);
269 set_freezable(); 296 set_freezable();
@@ -282,7 +309,26 @@ static int chip_thread(void *data)
282 continue; 309 continue;
283 310
284 /* have a look what's going on */ 311 /* have a look what's going on */
285 desc->checkmode(chip); 312 mode = desc->getmode(chip);
313 if (mode == chip->prevmode)
314 continue;
315
316 /* chip detected a new audio mode - set it */
317 v4l_dbg(1, debug, chip->c, "%s: thread checkmode\n",
318 chip->c->name);
319
320 chip->prevmode = mode;
321
322 if (mode & V4L2_TUNER_MODE_STEREO)
323 desc->setmode(chip, V4L2_TUNER_MODE_STEREO);
324 if (mode & V4L2_TUNER_MODE_LANG1_LANG2)
325 desc->setmode(chip, V4L2_TUNER_MODE_STEREO);
326 else if (mode & V4L2_TUNER_MODE_LANG1)
327 desc->setmode(chip, V4L2_TUNER_MODE_LANG1);
328 else if (mode & V4L2_TUNER_MODE_LANG2)
329 desc->setmode(chip, V4L2_TUNER_MODE_LANG2);
330 else
331 desc->setmode(chip, V4L2_TUNER_MODE_MONO);
286 332
287 /* schedule next check */ 333 /* schedule next check */
288 mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000)); 334 mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000));
@@ -292,29 +338,6 @@ static int chip_thread(void *data)
292 return 0; 338 return 0;
293} 339}
294 340
295static void generic_checkmode(struct CHIPSTATE *chip)
296{
297 struct CHIPDESC *desc = chiplist + chip->type;
298 int mode = desc->getmode(chip);
299
300 if (mode == chip->prevmode)
301 return;
302
303 v4l_dbg(1, debug, chip->c, "%s: thread checkmode\n", chip->c->name);
304 chip->prevmode = mode;
305
306 if (mode & V4L2_TUNER_MODE_STEREO)
307 desc->setmode(chip,V4L2_TUNER_MODE_STEREO);
308 if (mode & V4L2_TUNER_MODE_LANG1_LANG2)
309 desc->setmode(chip,V4L2_TUNER_MODE_STEREO);
310 else if (mode & V4L2_TUNER_MODE_LANG1)
311 desc->setmode(chip,V4L2_TUNER_MODE_LANG1);
312 else if (mode & V4L2_TUNER_MODE_LANG2)
313 desc->setmode(chip,V4L2_TUNER_MODE_LANG2);
314 else
315 desc->setmode(chip,V4L2_TUNER_MODE_MONO);
316}
317
318/* ---------------------------------------------------------------------- */ 341/* ---------------------------------------------------------------------- */
319/* audio chip descriptions - defines+functions for tda9840 */ 342/* audio chip descriptions - defines+functions for tda9840 */
320 343
@@ -777,7 +800,7 @@ static struct tda9874a_MODES {
777 char *name; 800 char *name;
778 audiocmd cmd; 801 audiocmd cmd;
779} tda9874a_modelist[9] = { 802} tda9874a_modelist[9] = {
780 { "A2, B/G", 803 { "A2, B/G", /* default */
781 { 9, { TDA9874A_C1FRA, 0x72,0x95,0x55, 0x77,0xA0,0x00, 0x00,0x00 }} }, 804 { 9, { TDA9874A_C1FRA, 0x72,0x95,0x55, 0x77,0xA0,0x00, 0x00,0x00 }} },
782 { "A2, M (Korea)", 805 { "A2, M (Korea)",
783 { 9, { TDA9874A_C1FRA, 0x5D,0xC0,0x00, 0x62,0x6A,0xAA, 0x20,0x22 }} }, 806 { 9, { TDA9874A_C1FRA, 0x5D,0xC0,0x00, 0x62,0x6A,0xAA, 0x20,0x22 }} },
@@ -791,7 +814,7 @@ static struct tda9874a_MODES {
791 { 9, { TDA9874A_C1FRA, 0x7D,0x00,0x00, 0x88,0x8A,0xAA, 0x08,0x33 }} }, 814 { 9, { TDA9874A_C1FRA, 0x7D,0x00,0x00, 0x88,0x8A,0xAA, 0x08,0x33 }} },
792 { "NICAM, B/G", 815 { "NICAM, B/G",
793 { 9, { TDA9874A_C1FRA, 0x72,0x95,0x55, 0x79,0xEA,0xAA, 0x08,0x33 }} }, 816 { 9, { TDA9874A_C1FRA, 0x72,0x95,0x55, 0x79,0xEA,0xAA, 0x08,0x33 }} },
794 { "NICAM, D/K", /* default */ 817 { "NICAM, D/K",
795 { 9, { TDA9874A_C1FRA, 0x87,0x6A,0xAA, 0x79,0xEA,0xAA, 0x08,0x33 }} }, 818 { 9, { TDA9874A_C1FRA, 0x87,0x6A,0xAA, 0x79,0xEA,0xAA, 0x08,0x33 }} },
796 { "NICAM, L", 819 { "NICAM, L",
797 { 9, { TDA9874A_C1FRA, 0x87,0x6A,0xAA, 0x79,0xEA,0xAA, 0x09,0x33 }} } 820 { 9, { TDA9874A_C1FRA, 0x87,0x6A,0xAA, 0x79,0xEA,0xAA, 0x09,0x33 }} }
@@ -981,7 +1004,7 @@ static int tda9874a_initialize(struct CHIPSTATE *chip)
981{ 1004{
982 if (tda9874a_SIF > 2) 1005 if (tda9874a_SIF > 2)
983 tda9874a_SIF = 1; 1006 tda9874a_SIF = 1;
984 if (tda9874a_STD > 8) 1007 if (tda9874a_STD >= ARRAY_SIZE(tda9874a_modelist))
985 tda9874a_STD = 0; 1008 tda9874a_STD = 0;
986 if(tda9874a_AMSEL > 1) 1009 if(tda9874a_AMSEL > 1)
987 tda9874a_AMSEL = 0; 1010 tda9874a_AMSEL = 0;
@@ -1089,7 +1112,7 @@ static int tda8425_shift12(int val) { return (val >> 12) | 0xf0; }
1089 1112
1090static int tda8425_initialize(struct CHIPSTATE *chip) 1113static int tda8425_initialize(struct CHIPSTATE *chip)
1091{ 1114{
1092 struct CHIPDESC *desc = chiplist + chip->type; 1115 struct CHIPDESC *desc = chip->desc;
1093 int inputmap[4] = { /* tuner */ TDA8425_S1_CH2, /* radio */ TDA8425_S1_CH1, 1116 int inputmap[4] = { /* tuner */ TDA8425_S1_CH2, /* radio */ TDA8425_S1_CH1,
1094 /* extern */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF}; 1117 /* extern */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF};
1095 1118
@@ -1259,27 +1282,28 @@ static struct CHIPDESC chiplist[] = {
1259 .addr_lo = I2C_ADDR_TDA9840 >> 1, 1282 .addr_lo = I2C_ADDR_TDA9840 >> 1,
1260 .addr_hi = I2C_ADDR_TDA9840 >> 1, 1283 .addr_hi = I2C_ADDR_TDA9840 >> 1,
1261 .registers = 5, 1284 .registers = 5,
1285 .flags = CHIP_NEED_CHECKMODE,
1262 1286
1287 /* callbacks */
1263 .checkit = tda9840_checkit, 1288 .checkit = tda9840_checkit,
1264 .getmode = tda9840_getmode, 1289 .getmode = tda9840_getmode,
1265 .setmode = tda9840_setmode, 1290 .setmode = tda9840_setmode,
1266 .checkmode = generic_checkmode,
1267 1291
1268 .init = { 2, { TDA9840_TEST, TDA9840_TEST_INT1SN 1292 .init = { 2, { TDA9840_TEST, TDA9840_TEST_INT1SN
1269 /* ,TDA9840_SW, TDA9840_MONO */} } 1293 /* ,TDA9840_SW, TDA9840_MONO */} }
1270 }, 1294 },
1271 { 1295 {
1272 .name = "tda9873h", 1296 .name = "tda9873h",
1273 .checkit = tda9873_checkit,
1274 .insmodopt = &tda9873, 1297 .insmodopt = &tda9873,
1275 .addr_lo = I2C_ADDR_TDA985x_L >> 1, 1298 .addr_lo = I2C_ADDR_TDA985x_L >> 1,
1276 .addr_hi = I2C_ADDR_TDA985x_H >> 1, 1299 .addr_hi = I2C_ADDR_TDA985x_H >> 1,
1277 .registers = 3, 1300 .registers = 3,
1278 .flags = CHIP_HAS_INPUTSEL, 1301 .flags = CHIP_HAS_INPUTSEL | CHIP_NEED_CHECKMODE,
1279 1302
1303 /* callbacks */
1304 .checkit = tda9873_checkit,
1280 .getmode = tda9873_getmode, 1305 .getmode = tda9873_getmode,
1281 .setmode = tda9873_setmode, 1306 .setmode = tda9873_setmode,
1282 .checkmode = generic_checkmode,
1283 1307
1284 .init = { 4, { TDA9873_SW, 0xa4, 0x06, 0x03 } }, 1308 .init = { 4, { TDA9873_SW, 0xa4, 0x06, 0x03 } },
1285 .inputreg = TDA9873_SW, 1309 .inputreg = TDA9873_SW,
@@ -1290,15 +1314,16 @@ static struct CHIPDESC chiplist[] = {
1290 }, 1314 },
1291 { 1315 {
1292 .name = "tda9874h/a", 1316 .name = "tda9874h/a",
1293 .checkit = tda9874a_checkit,
1294 .initialize = tda9874a_initialize,
1295 .insmodopt = &tda9874a, 1317 .insmodopt = &tda9874a,
1296 .addr_lo = I2C_ADDR_TDA9874 >> 1, 1318 .addr_lo = I2C_ADDR_TDA9874 >> 1,
1297 .addr_hi = I2C_ADDR_TDA9874 >> 1, 1319 .addr_hi = I2C_ADDR_TDA9874 >> 1,
1320 .flags = CHIP_NEED_CHECKMODE,
1298 1321
1322 /* callbacks */
1323 .initialize = tda9874a_initialize,
1324 .checkit = tda9874a_checkit,
1299 .getmode = tda9874a_getmode, 1325 .getmode = tda9874a_getmode,
1300 .setmode = tda9874a_setmode, 1326 .setmode = tda9874a_setmode,
1301 .checkmode = generic_checkmode,
1302 }, 1327 },
1303 { 1328 {
1304 .name = "tda9850", 1329 .name = "tda9850",
@@ -1324,10 +1349,11 @@ static struct CHIPDESC chiplist[] = {
1324 .rightreg = TDA9855_VR, 1349 .rightreg = TDA9855_VR,
1325 .bassreg = TDA9855_BA, 1350 .bassreg = TDA9855_BA,
1326 .treblereg = TDA9855_TR, 1351 .treblereg = TDA9855_TR,
1352
1353 /* callbacks */
1327 .volfunc = tda9855_volume, 1354 .volfunc = tda9855_volume,
1328 .bassfunc = tda9855_bass, 1355 .bassfunc = tda9855_bass,
1329 .treblefunc = tda9855_treble, 1356 .treblefunc = tda9855_treble,
1330
1331 .getmode = tda985x_getmode, 1357 .getmode = tda985x_getmode,
1332 .setmode = tda985x_setmode, 1358 .setmode = tda985x_setmode,
1333 1359
@@ -1348,6 +1374,8 @@ static struct CHIPDESC chiplist[] = {
1348 .rightreg = TEA6300_VL, 1374 .rightreg = TEA6300_VL,
1349 .bassreg = TEA6300_BA, 1375 .bassreg = TEA6300_BA,
1350 .treblereg = TEA6300_TR, 1376 .treblereg = TEA6300_TR,
1377
1378 /* callbacks */
1351 .volfunc = tea6300_shift10, 1379 .volfunc = tea6300_shift10,
1352 .bassfunc = tea6300_shift12, 1380 .bassfunc = tea6300_shift12,
1353 .treblefunc = tea6300_shift12, 1381 .treblefunc = tea6300_shift12,
@@ -1358,7 +1386,6 @@ static struct CHIPDESC chiplist[] = {
1358 }, 1386 },
1359 { 1387 {
1360 .name = "tea6320", 1388 .name = "tea6320",
1361 .initialize = tea6320_initialize,
1362 .insmodopt = &tea6320, 1389 .insmodopt = &tea6320,
1363 .addr_lo = I2C_ADDR_TEA6300 >> 1, 1390 .addr_lo = I2C_ADDR_TEA6300 >> 1,
1364 .addr_hi = I2C_ADDR_TEA6300 >> 1, 1391 .addr_hi = I2C_ADDR_TEA6300 >> 1,
@@ -1369,6 +1396,9 @@ static struct CHIPDESC chiplist[] = {
1369 .rightreg = TEA6320_V, 1396 .rightreg = TEA6320_V,
1370 .bassreg = TEA6320_BA, 1397 .bassreg = TEA6320_BA,
1371 .treblereg = TEA6320_TR, 1398 .treblereg = TEA6320_TR,
1399
1400 /* callbacks */
1401 .initialize = tea6320_initialize,
1372 .volfunc = tea6320_volume, 1402 .volfunc = tea6320_volume,
1373 .bassfunc = tea6320_shift11, 1403 .bassfunc = tea6320_shift11,
1374 .treblefunc = tea6320_shift11, 1404 .treblefunc = tea6320_shift11,
@@ -1401,16 +1431,18 @@ static struct CHIPDESC chiplist[] = {
1401 .rightreg = TDA8425_VR, 1431 .rightreg = TDA8425_VR,
1402 .bassreg = TDA8425_BA, 1432 .bassreg = TDA8425_BA,
1403 .treblereg = TDA8425_TR, 1433 .treblereg = TDA8425_TR,
1434
1435 /* callbacks */
1436 .initialize = tda8425_initialize,
1404 .volfunc = tda8425_shift10, 1437 .volfunc = tda8425_shift10,
1405 .bassfunc = tda8425_shift12, 1438 .bassfunc = tda8425_shift12,
1406 .treblefunc = tda8425_shift12, 1439 .treblefunc = tda8425_shift12,
1440 .setmode = tda8425_setmode,
1407 1441
1408 .inputreg = TDA8425_S1, 1442 .inputreg = TDA8425_S1,
1409 .inputmap = { TDA8425_S1_CH1, TDA8425_S1_CH1, TDA8425_S1_CH1 }, 1443 .inputmap = { TDA8425_S1_CH1, TDA8425_S1_CH1, TDA8425_S1_CH1 },
1410 .inputmute = TDA8425_S1_OFF, 1444 .inputmute = TDA8425_S1_OFF,
1411 1445
1412 .setmode = tda8425_setmode,
1413 .initialize = tda8425_initialize,
1414 }, 1446 },
1415 { 1447 {
1416 .name = "pic16c54 (PV951)", 1448 .name = "pic16c54 (PV951)",
@@ -1434,10 +1466,11 @@ static struct CHIPDESC chiplist[] = {
1434 .addr_lo = I2C_ADDR_TDA9840 >> 1, 1466 .addr_lo = I2C_ADDR_TDA9840 >> 1,
1435 .addr_hi = I2C_ADDR_TDA9840 >> 1, 1467 .addr_hi = I2C_ADDR_TDA9840 >> 1,
1436 .registers = 2, 1468 .registers = 2,
1469 .flags = CHIP_NEED_CHECKMODE,
1437 1470
1471 /* callbacks */
1438 .getmode = ta8874z_getmode, 1472 .getmode = ta8874z_getmode,
1439 .setmode = ta8874z_setmode, 1473 .setmode = ta8874z_setmode,
1440 .checkmode = generic_checkmode,
1441 1474
1442 .init = {2, { TA8874Z_MONO_SET, TA8874Z_SEPARATION_DEFAULT}}, 1475 .init = {2, { TA8874Z_MONO_SET, TA8874Z_SEPARATION_DEFAULT}},
1443 }, 1476 },
@@ -1481,6 +1514,7 @@ static int chip_probe(struct i2c_client *client, const struct i2c_device_id *id)
1481 } 1514 }
1482 if (desc->name == NULL) { 1515 if (desc->name == NULL) {
1483 v4l_dbg(1, debug, client, "no matching chip description found\n"); 1516 v4l_dbg(1, debug, client, "no matching chip description found\n");
1517 kfree(chip);
1484 return -EIO; 1518 return -EIO;
1485 } 1519 }
1486 v4l_info(client, "%s found @ 0x%x (%s)\n", desc->name, client->addr<<1, client->adapter->name); 1520 v4l_info(client, "%s found @ 0x%x (%s)\n", desc->name, client->addr<<1, client->adapter->name);
@@ -1494,7 +1528,7 @@ static int chip_probe(struct i2c_client *client, const struct i2c_device_id *id)
1494 /* fill required data structures */ 1528 /* fill required data structures */
1495 if (!id) 1529 if (!id)
1496 strlcpy(client->name, desc->name, I2C_NAME_SIZE); 1530 strlcpy(client->name, desc->name, I2C_NAME_SIZE);
1497 chip->type = desc-chiplist; 1531 chip->desc = desc;
1498 chip->shadow.count = desc->registers+1; 1532 chip->shadow.count = desc->registers+1;
1499 chip->prevmode = -1; 1533 chip->prevmode = -1;
1500 chip->audmode = V4L2_TUNER_MODE_LANG1; 1534 chip->audmode = V4L2_TUNER_MODE_LANG1;
@@ -1506,20 +1540,49 @@ static int chip_probe(struct i2c_client *client, const struct i2c_device_id *id)
1506 chip_cmd(chip,"init",&desc->init); 1540 chip_cmd(chip,"init",&desc->init);
1507 1541
1508 if (desc->flags & CHIP_HAS_VOLUME) { 1542 if (desc->flags & CHIP_HAS_VOLUME) {
1509 chip->left = desc->leftinit ? desc->leftinit : 65535; 1543 if (!desc->volfunc) {
1510 chip->right = desc->rightinit ? desc->rightinit : 65535; 1544 /* This shouldn't be happen. Warn user, but keep working
1511 chip_write(chip,desc->leftreg,desc->volfunc(chip->left)); 1545 without volume controls
1512 chip_write(chip,desc->rightreg,desc->volfunc(chip->right)); 1546 */
1547 v4l_info(chip->c, "volume callback undefined!\n");
1548 desc->flags &= ~CHIP_HAS_VOLUME;
1549 } else {
1550 chip->left = desc->leftinit ? desc->leftinit : 65535;
1551 chip->right = desc->rightinit ? desc->rightinit : 65535;
1552 chip_write(chip, desc->leftreg,
1553 desc->volfunc(chip->left));
1554 chip_write(chip, desc->rightreg,
1555 desc->volfunc(chip->right));
1556 }
1513 } 1557 }
1514 if (desc->flags & CHIP_HAS_BASSTREBLE) { 1558 if (desc->flags & CHIP_HAS_BASSTREBLE) {
1515 chip->treble = desc->trebleinit ? desc->trebleinit : 32768; 1559 if (!desc->bassfunc || !desc->treblefunc) {
1516 chip->bass = desc->bassinit ? desc->bassinit : 32768; 1560 /* This shouldn't be happen. Warn user, but keep working
1517 chip_write(chip,desc->bassreg,desc->bassfunc(chip->bass)); 1561 without bass/treble controls
1518 chip_write(chip,desc->treblereg,desc->treblefunc(chip->treble)); 1562 */
1563 v4l_info(chip->c, "bass/treble callbacks undefined!\n");
1564 desc->flags &= ~CHIP_HAS_BASSTREBLE;
1565 } else {
1566 chip->treble = desc->trebleinit ?
1567 desc->trebleinit : 32768;
1568 chip->bass = desc->bassinit ?
1569 desc->bassinit : 32768;
1570 chip_write(chip, desc->bassreg,
1571 desc->bassfunc(chip->bass));
1572 chip_write(chip, desc->treblereg,
1573 desc->treblefunc(chip->treble));
1574 }
1519 } 1575 }
1520 1576
1521 chip->thread = NULL; 1577 chip->thread = NULL;
1522 if (desc->checkmode) { 1578 if (desc->flags & CHIP_NEED_CHECKMODE) {
1579 if (!desc->getmode || !desc->setmode) {
1580 /* This shouldn't be happen. Warn user, but keep working
1581 without kthread
1582 */
1583 v4l_info(chip->c, "set/get mode callbacks undefined!\n");
1584 return 0;
1585 }
1523 /* start async thread */ 1586 /* start async thread */
1524 init_timer(&chip->wt); 1587 init_timer(&chip->wt);
1525 chip->wt.function = chip_thread_wake; 1588 chip->wt.function = chip_thread_wake;
@@ -1552,7 +1615,7 @@ static int chip_remove(struct i2c_client *client)
1552static int tvaudio_get_ctrl(struct CHIPSTATE *chip, 1615static int tvaudio_get_ctrl(struct CHIPSTATE *chip,
1553 struct v4l2_control *ctrl) 1616 struct v4l2_control *ctrl)
1554{ 1617{
1555 struct CHIPDESC *desc = chiplist + chip->type; 1618 struct CHIPDESC *desc = chip->desc;
1556 1619
1557 switch (ctrl->id) { 1620 switch (ctrl->id) {
1558 case V4L2_CID_AUDIO_MUTE: 1621 case V4L2_CID_AUDIO_MUTE:
@@ -1576,13 +1639,13 @@ static int tvaudio_get_ctrl(struct CHIPSTATE *chip,
1576 return 0; 1639 return 0;
1577 } 1640 }
1578 case V4L2_CID_AUDIO_BASS: 1641 case V4L2_CID_AUDIO_BASS:
1579 if (desc->flags & CHIP_HAS_BASSTREBLE) 1642 if (!(desc->flags & CHIP_HAS_BASSTREBLE))
1580 break; 1643 break;
1581 ctrl->value = chip->bass; 1644 ctrl->value = chip->bass;
1582 return 0; 1645 return 0;
1583 case V4L2_CID_AUDIO_TREBLE: 1646 case V4L2_CID_AUDIO_TREBLE:
1584 if (desc->flags & CHIP_HAS_BASSTREBLE) 1647 if (!(desc->flags & CHIP_HAS_BASSTREBLE))
1585 return -EINVAL; 1648 break;
1586 ctrl->value = chip->treble; 1649 ctrl->value = chip->treble;
1587 return 0; 1650 return 0;
1588 } 1651 }
@@ -1592,7 +1655,7 @@ static int tvaudio_get_ctrl(struct CHIPSTATE *chip,
1592static int tvaudio_set_ctrl(struct CHIPSTATE *chip, 1655static int tvaudio_set_ctrl(struct CHIPSTATE *chip,
1593 struct v4l2_control *ctrl) 1656 struct v4l2_control *ctrl)
1594{ 1657{
1595 struct CHIPDESC *desc = chiplist + chip->type; 1658 struct CHIPDESC *desc = chip->desc;
1596 1659
1597 switch (ctrl->id) { 1660 switch (ctrl->id) {
1598 case V4L2_CID_AUDIO_MUTE: 1661 case V4L2_CID_AUDIO_MUTE:
@@ -1642,16 +1705,15 @@ static int tvaudio_set_ctrl(struct CHIPSTATE *chip,
1642 return 0; 1705 return 0;
1643 } 1706 }
1644 case V4L2_CID_AUDIO_BASS: 1707 case V4L2_CID_AUDIO_BASS:
1645 if (desc->flags & CHIP_HAS_BASSTREBLE) 1708 if (!(desc->flags & CHIP_HAS_BASSTREBLE))
1646 break; 1709 break;
1647 chip->bass = ctrl->value; 1710 chip->bass = ctrl->value;
1648 chip_write(chip,desc->bassreg,desc->bassfunc(chip->bass)); 1711 chip_write(chip,desc->bassreg,desc->bassfunc(chip->bass));
1649 1712
1650 return 0; 1713 return 0;
1651 case V4L2_CID_AUDIO_TREBLE: 1714 case V4L2_CID_AUDIO_TREBLE:
1652 if (desc->flags & CHIP_HAS_BASSTREBLE) 1715 if (!(desc->flags & CHIP_HAS_BASSTREBLE))
1653 return -EINVAL; 1716 break;
1654
1655 chip->treble = ctrl->value; 1717 chip->treble = ctrl->value;
1656 chip_write(chip,desc->treblereg,desc->treblefunc(chip->treble)); 1718 chip_write(chip,desc->treblereg,desc->treblefunc(chip->treble));
1657 1719
@@ -1668,9 +1730,12 @@ static int chip_command(struct i2c_client *client,
1668 unsigned int cmd, void *arg) 1730 unsigned int cmd, void *arg)
1669{ 1731{
1670 struct CHIPSTATE *chip = i2c_get_clientdata(client); 1732 struct CHIPSTATE *chip = i2c_get_clientdata(client);
1671 struct CHIPDESC *desc = chiplist + chip->type; 1733 struct CHIPDESC *desc = chip->desc;
1672 1734
1673 v4l_dbg(1, debug, chip->c, "%s: chip_command 0x%x\n", chip->c->name, cmd); 1735 if (debug > 0) {
1736 v4l_i2c_print_ioctl(chip->c, cmd);
1737 printk("\n");
1738 }
1674 1739
1675 switch (cmd) { 1740 switch (cmd) {
1676 case AUDC_SET_RADIO: 1741 case AUDC_SET_RADIO:
@@ -1695,7 +1760,7 @@ static int chip_command(struct i2c_client *client,
1695 break; 1760 break;
1696 case V4L2_CID_AUDIO_BASS: 1761 case V4L2_CID_AUDIO_BASS:
1697 case V4L2_CID_AUDIO_TREBLE: 1762 case V4L2_CID_AUDIO_TREBLE:
1698 if (desc->flags & CHIP_HAS_BASSTREBLE) 1763 if (!(desc->flags & CHIP_HAS_BASSTREBLE))
1699 return -EINVAL; 1764 return -EINVAL;
1700 break; 1765 break;
1701 default: 1766 default:
@@ -1792,12 +1857,20 @@ static int chip_command(struct i2c_client *client,
1792 break; 1857 break;
1793 case VIDIOC_S_FREQUENCY: 1858 case VIDIOC_S_FREQUENCY:
1794 chip->mode = 0; /* automatic */ 1859 chip->mode = 0; /* automatic */
1795 if (desc->checkmode && desc->setmode) { 1860
1861 /* For chips that provide getmode and setmode, and doesn't
1862 automatically follows the stereo carrier, a kthread is
1863 created to set the audio standard. In this case, when then
1864 the video channel is changed, tvaudio starts on MONO mode.
1865 After waiting for 2 seconds, the kernel thread is called,
1866 to follow whatever audio standard is pointed by the
1867 audio carrier.
1868 */
1869 if (chip->thread) {
1796 desc->setmode(chip,V4L2_TUNER_MODE_MONO); 1870 desc->setmode(chip,V4L2_TUNER_MODE_MONO);
1797 if (chip->prevmode != V4L2_TUNER_MODE_MONO) 1871 if (chip->prevmode != V4L2_TUNER_MODE_MONO)
1798 chip->prevmode = -1; /* reset previous mode */ 1872 chip->prevmode = -1; /* reset previous mode */
1799 mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000)); 1873 mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000));
1800 /* the thread will call checkmode() later */
1801 } 1874 }
1802 break; 1875 break;
1803 1876
@@ -1836,9 +1909,3 @@ static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1836 .legacy_probe = chip_legacy_probe, 1909 .legacy_probe = chip_legacy_probe,
1837 .id_table = chip_id, 1910 .id_table = chip_id,
1838}; 1911};
1839
1840/*
1841 * Local variables:
1842 * c-basic-offset: 8
1843 * End:
1844 */
diff --git a/drivers/media/video/usbvideo/ibmcam.c b/drivers/media/video/usbvideo/ibmcam.c
index 28421d386f1e..c710bcd1df48 100644
--- a/drivers/media/video/usbvideo/ibmcam.c
+++ b/drivers/media/video/usbvideo/ibmcam.c
@@ -3695,7 +3695,7 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
3695 unsigned char video_ep = 0; 3695 unsigned char video_ep = 0;
3696 3696
3697 if (debug >= 1) 3697 if (debug >= 1)
3698 dev_info(&uvd->dev->dev, "ibmcam_probe(%p,%u.)\n", intf, ifnum); 3698 dev_info(&dev->dev, "ibmcam_probe(%p,%u.)\n", intf, ifnum);
3699 3699
3700 /* We don't handle multi-config cameras */ 3700 /* We don't handle multi-config cameras */
3701 if (dev->descriptor.bNumConfigurations != 1) 3701 if (dev->descriptor.bNumConfigurations != 1)
@@ -3746,7 +3746,7 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
3746 brand = "IBM PC Camera"; /* a.k.a. Xirlink C-It */ 3746 brand = "IBM PC Camera"; /* a.k.a. Xirlink C-It */
3747 break; 3747 break;
3748 } 3748 }
3749 dev_info(&uvd->dev->dev, 3749 dev_info(&dev->dev,
3750 "%s USB camera found (model %d, rev. 0x%04x)\n", 3750 "%s USB camera found (model %d, rev. 0x%04x)\n",
3751 brand, model, le16_to_cpu(dev->descriptor.bcdDevice)); 3751 brand, model, le16_to_cpu(dev->descriptor.bcdDevice));
3752 } while (0); 3752 } while (0);
@@ -3754,7 +3754,7 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
3754 /* Validate found interface: must have one ISO endpoint */ 3754 /* Validate found interface: must have one ISO endpoint */
3755 nas = intf->num_altsetting; 3755 nas = intf->num_altsetting;
3756 if (debug > 0) 3756 if (debug > 0)
3757 dev_info(&uvd->dev->dev, "Number of alternate settings=%d.\n", 3757 dev_info(&dev->dev, "Number of alternate settings=%d.\n",
3758 nas); 3758 nas);
3759 if (nas < 2) { 3759 if (nas < 2) {
3760 err("Too few alternate settings for this camera!"); 3760 err("Too few alternate settings for this camera!");
@@ -3799,7 +3799,7 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
3799 actInterface = i; 3799 actInterface = i;
3800 maxPS = le16_to_cpu(endpoint->wMaxPacketSize); 3800 maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
3801 if (debug > 0) 3801 if (debug > 0)
3802 dev_info(&uvd->dev->dev, 3802 dev_info(&dev->dev,
3803 "Active setting=%d. " 3803 "Active setting=%d. "
3804 "maxPS=%d.\n", i, maxPS); 3804 "maxPS=%d.\n", i, maxPS);
3805 } else 3805 } else
@@ -3840,7 +3840,7 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
3840 RESTRICT_TO_RANGE(framerate, 0, 5); 3840 RESTRICT_TO_RANGE(framerate, 0, 5);
3841 break; 3841 break;
3842 default: 3842 default:
3843 dev_info(&uvd->dev->dev, "IBM camera: using 320x240\n"); 3843 dev_info(&dev->dev, "IBM camera: using 320x240\n");
3844 size = SIZE_320x240; 3844 size = SIZE_320x240;
3845 /* No break here */ 3845 /* No break here */
3846 case SIZE_320x240: 3846 case SIZE_320x240:
@@ -3869,7 +3869,7 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
3869 canvasY = 120; 3869 canvasY = 120;
3870 break; 3870 break;
3871 default: 3871 default:
3872 dev_info(&uvd->dev->dev, "IBM NetCamera: using 176x144\n"); 3872 dev_info(&dev->dev, "IBM NetCamera: using 176x144\n");
3873 size = SIZE_176x144; 3873 size = SIZE_176x144;
3874 /* No break here */ 3874 /* No break here */
3875 case SIZE_176x144: 3875 case SIZE_176x144: