aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/staging/cx25821/Makefile8
-rw-r--r--drivers/staging/cx25821/cx25821-audio-upstream.c12
-rw-r--r--drivers/staging/cx25821/cx25821-core.c48
-rw-r--r--drivers/staging/cx25821/cx25821-medusa-video.c4
-rw-r--r--drivers/staging/cx25821/cx25821-video-upstream-ch2.c56
-rw-r--r--drivers/staging/cx25821/cx25821-video-upstream.c78
-rw-r--r--drivers/staging/cx25821/cx25821-video.c642
7 files changed, 424 insertions, 424 deletions
diff --git a/drivers/staging/cx25821/Makefile b/drivers/staging/cx25821/Makefile
index 877d9a4fa6a7..d0eb16eac092 100644
--- a/drivers/staging/cx25821/Makefile
+++ b/drivers/staging/cx25821/Makefile
@@ -1,8 +1,8 @@
1cx25821-objs := cx25821-core.o cx25821-cards.o cx25821-i2c.o \ 1cx25821-objs := cx25821-core.o cx25821-cards.o cx25821-i2c.o \
2 cx25821-gpio.o cx25821-medusa-video.o \ 2 cx25821-gpio.o cx25821-medusa-video.o \
3 cx25821-video.o cx25821-video-upstream.o \ 3 cx25821-video.o cx25821-video-upstream.o \
4 cx25821-video-upstream-ch2.o \ 4 cx25821-video-upstream-ch2.o \
5 cx25821-audio-upstream.o 5 cx25821-audio-upstream.o
6 6
7obj-$(CONFIG_VIDEO_CX25821) += cx25821.o 7obj-$(CONFIG_VIDEO_CX25821) += cx25821.o
8obj-$(CONFIG_VIDEO_CX25821_ALSA) += cx25821-alsa.o 8obj-$(CONFIG_VIDEO_CX25821_ALSA) += cx25821-alsa.o
diff --git a/drivers/staging/cx25821/cx25821-audio-upstream.c b/drivers/staging/cx25821/cx25821-audio-upstream.c
index 8d03768ea09a..cdff49f409f2 100644
--- a/drivers/staging/cx25821/cx25821-audio-upstream.c
+++ b/drivers/staging/cx25821/cx25821-audio-upstream.c
@@ -106,7 +106,7 @@ static __le32 *cx25821_risc_field_upstream_audio(struct cx25821_dev *dev,
106{ 106{
107 unsigned int line; 107 unsigned int line;
108 struct sram_channel *sram_ch = 108 struct sram_channel *sram_ch =
109 dev->channels[dev->_audio_upstream_channel_select].sram_channels; 109 dev->channels[dev->_audio_upstream_channel_select].sram_channels;
110 int offset = 0; 110 int offset = 0;
111 111
112 /* scan lines */ 112 /* scan lines */
@@ -217,7 +217,7 @@ void cx25821_free_memory_audio(struct cx25821_dev *dev)
217void cx25821_stop_upstream_audio(struct cx25821_dev *dev) 217void cx25821_stop_upstream_audio(struct cx25821_dev *dev)
218{ 218{
219 struct sram_channel *sram_ch = 219 struct sram_channel *sram_ch =
220 dev->channels[AUDIO_UPSTREAM_SRAM_CHANNEL_B].sram_channels; 220 dev->channels[AUDIO_UPSTREAM_SRAM_CHANNEL_B].sram_channels;
221 u32 tmp = 0; 221 u32 tmp = 0;
222 222
223 if (!dev->_audio_is_running) { 223 if (!dev->_audio_is_running) {
@@ -353,9 +353,9 @@ static void cx25821_audioups_handler(struct work_struct *work)
353 } 353 }
354 354
355 cx25821_get_audio_data(dev, 355 cx25821_get_audio_data(dev,
356 dev->channels[dev-> 356 dev->channels[dev->
357 _audio_upstream_channel_select]. 357 _audio_upstream_channel_select].
358 sram_channels); 358 sram_channels);
359} 359}
360 360
361int cx25821_openfile_audio(struct cx25821_dev *dev, 361int cx25821_openfile_audio(struct cx25821_dev *dev,
@@ -609,7 +609,7 @@ static irqreturn_t cx25821_upstream_irq_audio(int irq, void *dev_id)
609 return -1; 609 return -1;
610 610
611 sram_ch = dev->channels[dev->_audio_upstream_channel_select]. 611 sram_ch = dev->channels[dev->_audio_upstream_channel_select].
612 sram_channels; 612 sram_channels;
613 613
614 msk_stat = cx_read(sram_ch->int_mstat); 614 msk_stat = cx_read(sram_ch->int_mstat);
615 audio_status = cx_read(sram_ch->int_stat); 615 audio_status = cx_read(sram_ch->int_stat);
diff --git a/drivers/staging/cx25821/cx25821-core.c b/drivers/staging/cx25821/cx25821-core.c
index 0963d5745b50..be44195783d4 100644
--- a/drivers/staging/cx25821/cx25821-core.c
+++ b/drivers/staging/cx25821/cx25821-core.c
@@ -781,14 +781,14 @@ static void cx25821_shutdown(struct cx25821_dev *dev)
781 781
782 /* Disable Video A/B activity */ 782 /* Disable Video A/B activity */
783 for (i = 0; i < VID_CHANNEL_NUM; i++) { 783 for (i = 0; i < VID_CHANNEL_NUM; i++) {
784 cx_write(dev->channels[i].sram_channels->dma_ctl, 0); 784 cx_write(dev->channels[i].sram_channels->dma_ctl, 0);
785 cx_write(dev->channels[i].sram_channels->int_msk, 0); 785 cx_write(dev->channels[i].sram_channels->int_msk, 0);
786 } 786 }
787 787
788 for (i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J; 788 for (i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J;
789 i++) { 789 i++) {
790 cx_write(dev->channels[i].sram_channels->dma_ctl, 0); 790 cx_write(dev->channels[i].sram_channels->dma_ctl, 0);
791 cx_write(dev->channels[i].sram_channels->int_msk, 0); 791 cx_write(dev->channels[i].sram_channels->int_msk, 0);
792 } 792 }
793 793
794 /* Disable Audio activity */ 794 /* Disable Audio activity */
@@ -806,9 +806,9 @@ void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel_select,
806 u32 format) 806 u32 format)
807{ 807{
808 if (channel_select <= 7 && channel_select >= 0) { 808 if (channel_select <= 7 && channel_select >= 0) {
809 cx_write(dev->channels[channel_select]. 809 cx_write(dev->channels[channel_select].
810 sram_channels->pix_frmt, format); 810 sram_channels->pix_frmt, format);
811 dev->channels[channel_select].pixel_formats = format; 811 dev->channels[channel_select].pixel_formats = format;
812 } 812 }
813} 813}
814 814
@@ -829,7 +829,7 @@ static void cx25821_initialize(struct cx25821_dev *dev)
829 cx_write(PCI_INT_STAT, 0xffffffff); 829 cx_write(PCI_INT_STAT, 0xffffffff);
830 830
831 for (i = 0; i < VID_CHANNEL_NUM; i++) 831 for (i = 0; i < VID_CHANNEL_NUM; i++)
832 cx_write(dev->channels[i].sram_channels->int_stat, 0xffffffff); 832 cx_write(dev->channels[i].sram_channels->int_stat, 0xffffffff);
833 833
834 cx_write(AUD_A_INT_STAT, 0xffffffff); 834 cx_write(AUD_A_INT_STAT, 0xffffffff);
835 cx_write(AUD_B_INT_STAT, 0xffffffff); 835 cx_write(AUD_B_INT_STAT, 0xffffffff);
@@ -843,22 +843,22 @@ static void cx25821_initialize(struct cx25821_dev *dev)
843 mdelay(100); 843 mdelay(100);
844 844
845 for (i = 0; i < VID_CHANNEL_NUM; i++) { 845 for (i = 0; i < VID_CHANNEL_NUM; i++) {
846 cx25821_set_vip_mode(dev, dev->channels[i].sram_channels); 846 cx25821_set_vip_mode(dev, dev->channels[i].sram_channels);
847 cx25821_sram_channel_setup(dev, dev->channels[i].sram_channels, 847 cx25821_sram_channel_setup(dev, dev->channels[i].sram_channels,
848 1440, 0); 848 1440, 0);
849 dev->channels[i].pixel_formats = PIXEL_FRMT_422; 849 dev->channels[i].pixel_formats = PIXEL_FRMT_422;
850 dev->channels[i].use_cif_resolution = FALSE; 850 dev->channels[i].use_cif_resolution = FALSE;
851 } 851 }
852 852
853 /* Probably only affect Downstream */ 853 /* Probably only affect Downstream */
854 for (i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J; 854 for (i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J;
855 i++) { 855 i++) {
856 cx25821_set_vip_mode(dev, dev->channels[i].sram_channels); 856 cx25821_set_vip_mode(dev, dev->channels[i].sram_channels);
857 } 857 }
858 858
859 cx25821_sram_channel_setup_audio(dev, 859 cx25821_sram_channel_setup_audio(dev,
860 dev->channels[SRAM_CH08].sram_channels, 860 dev->channels[SRAM_CH08].sram_channels,
861 128, 0); 861 128, 0);
862 862
863 cx25821_gpio_init(dev); 863 cx25821_gpio_init(dev);
864} 864}
@@ -932,7 +932,7 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
932 /* Apply a sensible clock frequency for the PCIe bridge */ 932 /* Apply a sensible clock frequency for the PCIe bridge */
933 dev->clk_freq = 28000000; 933 dev->clk_freq = 28000000;
934 for (i = 0; i < MAX_VID_CHANNEL_NUM; i++) 934 for (i = 0; i < MAX_VID_CHANNEL_NUM; i++)
935 dev->channels[i].sram_channels = &cx25821_sram_channels[i]; 935 dev->channels[i].sram_channels = &cx25821_sram_channels[i];
936 936
937 if (dev->nr > 1) 937 if (dev->nr > 1)
938 CX25821_INFO("dev->nr > 1!"); 938 CX25821_INFO("dev->nr > 1!");
@@ -1004,22 +1004,22 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
1004 cx25821_card_setup(dev); 1004 cx25821_card_setup(dev);
1005 1005
1006 if (medusa_video_init(dev) < 0) 1006 if (medusa_video_init(dev) < 0)
1007 CX25821_ERR("%s() Failed to initialize medusa!\n" 1007 CX25821_ERR("%s() Failed to initialize medusa!\n"
1008 , __func__); 1008 , __func__);
1009 1009
1010 cx25821_video_register(dev); 1010 cx25821_video_register(dev);
1011 1011
1012 /* register IOCTL device */ 1012 /* register IOCTL device */
1013 dev->ioctl_dev = 1013 dev->ioctl_dev =
1014 cx25821_vdev_init(dev, dev->pci, &cx25821_videoioctl_template, 1014 cx25821_vdev_init(dev, dev->pci, &cx25821_videoioctl_template,
1015 "video"); 1015 "video");
1016 1016
1017 if (video_register_device 1017 if (video_register_device
1018 (dev->ioctl_dev, VFL_TYPE_GRABBER, VIDEO_IOCTL_CH) < 0) { 1018 (dev->ioctl_dev, VFL_TYPE_GRABBER, VIDEO_IOCTL_CH) < 0) {
1019 cx25821_videoioctl_unregister(dev); 1019 cx25821_videoioctl_unregister(dev);
1020 printk(KERN_ERR 1020 printk(KERN_ERR
1021 "%s() Failed to register video adapter for IOCTL, so \ 1021 "%s() Failed to register video adapter for IOCTL, so \
1022 unregistering videoioctl device.\n", __func__); 1022 unregistering videoioctl device.\n", __func__);
1023 } 1023 }
1024 1024
1025 cx25821_dev_checkrevision(dev); 1025 cx25821_dev_checkrevision(dev);
@@ -1342,8 +1342,8 @@ static irqreturn_t cx25821_irq(int irq, void *dev_id)
1342 1342
1343 for (i = 0; i < VID_CHANNEL_NUM; i++) { 1343 for (i = 0; i < VID_CHANNEL_NUM; i++) {
1344 if (pci_status & mask[i]) { 1344 if (pci_status & mask[i]) {
1345 vid_status = cx_read(dev->channels[i]. 1345 vid_status = cx_read(dev->channels[i].
1346 sram_channels->int_stat); 1346 sram_channels->int_stat);
1347 1347
1348 if (vid_status) 1348 if (vid_status)
1349 handled += 1349 handled +=
diff --git a/drivers/staging/cx25821/cx25821-medusa-video.c b/drivers/staging/cx25821/cx25821-medusa-video.c
index 09fd1196f626..ef9f2b82a860 100644
--- a/drivers/staging/cx25821/cx25821-medusa-video.c
+++ b/drivers/staging/cx25821/cx25821-medusa-video.c
@@ -830,8 +830,8 @@ int medusa_video_init(struct cx25821_dev *dev)
830 value = cx25821_i2c_read(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, &tmp); 830 value = cx25821_i2c_read(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, &tmp);
831 value &= 0x83FFFFFF; 831 value &= 0x83FFFFFF;
832 ret_val = 832 ret_val =
833 cx25821_i2c_write(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, 833 cx25821_i2c_write(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL,
834 value | 0x10000000); 834 value | 0x10000000);
835 835
836 if (ret_val < 0) 836 if (ret_val < 0)
837 goto error; 837 goto error;
diff --git a/drivers/staging/cx25821/cx25821-video-upstream-ch2.c b/drivers/staging/cx25821/cx25821-video-upstream-ch2.c
index af47ec4f96db..d12dbb572e8b 100644
--- a/drivers/staging/cx25821/cx25821-video-upstream-ch2.c
+++ b/drivers/staging/cx25821/cx25821-video-upstream-ch2.c
@@ -84,7 +84,7 @@ static __le32 *cx25821_risc_field_upstream_ch2(struct cx25821_dev *dev,
84{ 84{
85 unsigned int line, i; 85 unsigned int line, i;
86 struct sram_channel *sram_ch = 86 struct sram_channel *sram_ch =
87 dev->channels[dev->_channel2_upstream_select].sram_channels; 87 dev->channels[dev->_channel2_upstream_select].sram_channels;
88 int dist_betwn_starts = bpl * 2; 88 int dist_betwn_starts = bpl * 2;
89 89
90 /* sync instruction */ 90 /* sync instruction */
@@ -110,11 +110,11 @@ static __le32 *cx25821_risc_field_upstream_ch2(struct cx25821_dev *dev,
110 offset += dist_betwn_starts; 110 offset += dist_betwn_starts;
111 } 111 }
112 112
113 /* 113 /*
114 check if we need to enable the FIFO after the first 4 lines 114 check if we need to enable the FIFO after the first 4 lines
115 For the upstream video channel, the risc engine will enable 115 For the upstream video channel, the risc engine will enable
116 the FIFO. 116 the FIFO.
117 */ 117 */
118 if (fifo_enable && line == 3) { 118 if (fifo_enable && line == 3) {
119 *(rp++) = RISC_WRITECR; 119 *(rp++) = RISC_WRITECR;
120 *(rp++) = sram_ch->dma_ctl; 120 *(rp++) = sram_ch->dma_ctl;
@@ -177,7 +177,7 @@ int cx25821_risc_buffer_upstream_ch2(struct cx25821_dev *dev,
177 177
178 fifo_enable = FIFO_DISABLE; 178 fifo_enable = FIFO_DISABLE;
179 179
180 /* Even field */ 180 /* Even field */
181 rp = cx25821_risc_field_upstream_ch2(dev, rp, 181 rp = cx25821_risc_field_upstream_ch2(dev, rp,
182 dev-> 182 dev->
183 _data_buf_phys_addr_ch2 + 183 _data_buf_phys_addr_ch2 +
@@ -195,10 +195,10 @@ int cx25821_risc_buffer_upstream_ch2(struct cx25821_dev *dev,
195 risc_phys_jump_addr = dev->_dma_phys_start_addr_ch2; 195 risc_phys_jump_addr = dev->_dma_phys_start_addr_ch2;
196 } 196 }
197 197
198 /* 198 /*
199 Loop to 2ndFrameRISC or to Start of 199 Loop to 2ndFrameRISC or to Start of
200 Risc program & generate IRQ 200 Risc program & generate IRQ
201 */ 201 */
202 *(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag); 202 *(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag);
203 *(rp++) = cpu_to_le32(risc_phys_jump_addr); 203 *(rp++) = cpu_to_le32(risc_phys_jump_addr);
204 *(rp++) = cpu_to_le32(0); 204 *(rp++) = cpu_to_le32(0);
@@ -210,7 +210,7 @@ int cx25821_risc_buffer_upstream_ch2(struct cx25821_dev *dev,
210void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev) 210void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev)
211{ 211{
212 struct sram_channel *sram_ch = 212 struct sram_channel *sram_ch =
213 dev->channels[VID_UPSTREAM_SRAM_CHANNEL_J].sram_channels; 213 dev->channels[VID_UPSTREAM_SRAM_CHANNEL_J].sram_channels;
214 u32 tmp = 0; 214 u32 tmp = 0;
215 215
216 if (!dev->_is_running_ch2) { 216 if (!dev->_is_running_ch2) {
@@ -377,8 +377,8 @@ static void cx25821_vidups_handler_ch2(struct work_struct *work)
377 } 377 }
378 378
379 cx25821_get_frame_ch2(dev, 379 cx25821_get_frame_ch2(dev,
380 dev->channels[dev-> 380 dev->channels[dev->
381 _channel2_upstream_select].sram_channels); 381 _channel2_upstream_select].sram_channels);
382} 382}
383 383
384int cx25821_openfile_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch) 384int cx25821_openfile_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch)
@@ -550,13 +550,13 @@ int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num,
550 __le32 *rp; 550 __le32 *rp;
551 551
552 if (status & FLD_VID_SRC_RISC1) { 552 if (status & FLD_VID_SRC_RISC1) {
553 /* We should only process one program per call */ 553 /* We should only process one program per call */
554 u32 prog_cnt = cx_read(channel->gpcnt); 554 u32 prog_cnt = cx_read(channel->gpcnt);
555 555
556 /* 556 /*
557 Since we've identified our IRQ, clear our bits from the 557 Since we've identified our IRQ, clear our bits from the
558 interrupt mask and interrupt status registers 558 interrupt mask and interrupt status registers
559 */ 559 */
560 int_msk_tmp = cx_read(channel->int_msk); 560 int_msk_tmp = cx_read(channel->int_msk);
561 cx_write(channel->int_msk, int_msk_tmp & ~_intr_msk); 561 cx_write(channel->int_msk, int_msk_tmp & ~_intr_msk);
562 cx_write(channel->int_stat, _intr_msk); 562 cx_write(channel->int_stat, _intr_msk);
@@ -597,7 +597,7 @@ int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num,
597 FIFO_DISABLE, 597 FIFO_DISABLE,
598 ODD_FIELD); 598 ODD_FIELD);
599 599
600 /* Jump to Even Risc program of 1st Frame */ 600 /* Jump to Even Risc program of 1st Frame */
601 *(rp++) = cpu_to_le32(RISC_JUMP); 601 *(rp++) = cpu_to_le32(RISC_JUMP);
602 *(rp++) = cpu_to_le32(risc_phys_jump_addr); 602 *(rp++) = cpu_to_le32(risc_phys_jump_addr);
603 *(rp++) = cpu_to_le32(0); 603 *(rp++) = cpu_to_le32(0);
@@ -668,8 +668,8 @@ static void cx25821_set_pixelengine_ch2(struct cx25821_dev *dev,
668 cx_write(ch->vid_fmt_ctl, value); 668 cx_write(ch->vid_fmt_ctl, value);
669 669
670 /* 670 /*
671 set number of active pixels in each line. Default is 720 671 set number of active pixels in each line. Default is 720
672 pixels in both NTSC and PAL format 672 pixels in both NTSC and PAL format
673 */ 673 */
674 cx_write(ch->vid_active_ctl1, width); 674 cx_write(ch->vid_active_ctl1, width);
675 675
@@ -695,15 +695,15 @@ int cx25821_start_video_dma_upstream_ch2(struct cx25821_dev *dev,
695 int err = 0; 695 int err = 0;
696 696
697 /* 697 /*
698 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface 698 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface
699 for channel A-C 699 for channel A-C
700 */ 700 */
701 tmp = cx_read(VID_CH_MODE_SEL); 701 tmp = cx_read(VID_CH_MODE_SEL);
702 cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF); 702 cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
703 703
704 /* 704 /*
705 Set the physical start address of the RISC program in the initial 705 Set the physical start address of the RISC program in the initial
706 program counter(IPC) member of the cmds. 706 program counter(IPC) member of the cmds.
707 */ 707 */
708 cx_write(sram_ch->cmds_start + 0, dev->_dma_phys_addr_ch2); 708 cx_write(sram_ch->cmds_start + 0, dev->_dma_phys_addr_ch2);
709 cx_write(sram_ch->cmds_start + 4, 0); /* Risc IPC High 64 bits 63-32 */ 709 cx_write(sram_ch->cmds_start + 4, 0); /* Risc IPC High 64 bits 63-32 */
@@ -770,8 +770,8 @@ int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select,
770 return -ENOMEM; 770 return -ENOMEM;
771 } 771 }
772 /* 772 /*
773 656/VIP SRC Upstream Channel I & J and 7 - 773 656/VIP SRC Upstream Channel I & J and 7 -
774 Host Bus Interface for channel A-C 774 Host Bus Interface for channel A-C
775 */ 775 */
776 tmp = cx_read(VID_CH_MODE_SEL); 776 tmp = cx_read(VID_CH_MODE_SEL);
777 cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF); 777 cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
diff --git a/drivers/staging/cx25821/cx25821-video-upstream.c b/drivers/staging/cx25821/cx25821-video-upstream.c
index 386debf39556..756a820a76cb 100644
--- a/drivers/staging/cx25821/cx25821-video-upstream.c
+++ b/drivers/staging/cx25821/cx25821-video-upstream.c
@@ -134,7 +134,7 @@ static __le32 *cx25821_risc_field_upstream(struct cx25821_dev *dev, __le32 * rp,
134{ 134{
135 unsigned int line, i; 135 unsigned int line, i;
136 struct sram_channel *sram_ch = 136 struct sram_channel *sram_ch =
137 dev->channels[dev->_channel_upstream_select].sram_channels; 137 dev->channels[dev->_channel_upstream_select].sram_channels;
138 int dist_betwn_starts = bpl * 2; 138 int dist_betwn_starts = bpl * 2;
139 139
140 /* sync instruction */ 140 /* sync instruction */
@@ -253,7 +253,7 @@ int cx25821_risc_buffer_upstream(struct cx25821_dev *dev,
253void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev) 253void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev)
254{ 254{
255 struct sram_channel *sram_ch = 255 struct sram_channel *sram_ch =
256 dev->channels[VID_UPSTREAM_SRAM_CHANNEL_I].sram_channels; 256 dev->channels[VID_UPSTREAM_SRAM_CHANNEL_I].sram_channels;
257 u32 tmp = 0; 257 u32 tmp = 0;
258 258
259 if (!dev->_is_running) { 259 if (!dev->_is_running) {
@@ -346,23 +346,23 @@ int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch)
346 346
347 if (IS_ERR(myfile)) { 347 if (IS_ERR(myfile)) {
348 const int open_errno = -PTR_ERR(myfile); 348 const int open_errno = -PTR_ERR(myfile);
349 printk(KERN_ERR 349 printk(KERN_ERR
350 "%s(): ERROR opening file(%s) with errno = %d!\n", 350 "%s(): ERROR opening file(%s) with errno = %d!\n",
351 __func__, dev->_filename, open_errno); 351 __func__, dev->_filename, open_errno);
352 return PTR_ERR(myfile); 352 return PTR_ERR(myfile);
353 } else { 353 } else {
354 if (!(myfile->f_op)) { 354 if (!(myfile->f_op)) {
355 printk(KERN_ERR 355 printk(KERN_ERR
356 "%s: File has no file operations registered!", 356 "%s: File has no file operations registered!",
357 __func__); 357 __func__);
358 filp_close(myfile, NULL); 358 filp_close(myfile, NULL);
359 return -EIO; 359 return -EIO;
360 } 360 }
361 361
362 if (!myfile->f_op->read) { 362 if (!myfile->f_op->read) {
363 printk(KERN_ERR 363 printk(KERN_ERR
364 "%s: File has no READ operations registered!", 364 "%s: File has no READ operations registered!",
365 __func__); 365 __func__);
366 filp_close(myfile, NULL); 366 filp_close(myfile, NULL);
367 return -EIO; 367 return -EIO;
368 } 368 }
@@ -389,8 +389,8 @@ int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch)
389 389
390 if (vfs_read_retval < line_size) { 390 if (vfs_read_retval < line_size) {
391 printk(KERN_INFO 391 printk(KERN_INFO
392 "Done: exit %s() since no more bytes to \ 392 "Done: exit %s() since no more bytes to \
393 read from Video file.\n", 393 read from Video file.\n",
394 __func__); 394 __func__);
395 break; 395 break;
396 } 396 }
@@ -415,15 +415,15 @@ static void cx25821_vidups_handler(struct work_struct *work)
415 container_of(work, struct cx25821_dev, _irq_work_entry); 415 container_of(work, struct cx25821_dev, _irq_work_entry);
416 416
417 if (!dev) { 417 if (!dev) {
418 printk(KERN_ERR 418 printk(KERN_ERR
419 "ERROR %s(): since container_of(work_struct) FAILED!\n", 419 "ERROR %s(): since container_of(work_struct) FAILED!\n",
420 __func__); 420 __func__);
421 return; 421 return;
422 } 422 }
423 423
424 cx25821_get_frame(dev, 424 cx25821_get_frame(dev,
425 dev->channels[dev->_channel_upstream_select]. 425 dev->channels[dev->_channel_upstream_select].
426 sram_channels); 426 sram_channels);
427} 427}
428 428
429int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch) 429int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
@@ -443,22 +443,22 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
443 443
444 if (IS_ERR(myfile)) { 444 if (IS_ERR(myfile)) {
445 const int open_errno = -PTR_ERR(myfile); 445 const int open_errno = -PTR_ERR(myfile);
446 printk(KERN_ERR "%s(): ERROR opening file(%s) with errno = %d!\n", 446 printk(KERN_ERR "%s(): ERROR opening file(%s) with errno = %d!\n",
447 __func__, dev->_filename, open_errno); 447 __func__, dev->_filename, open_errno);
448 return PTR_ERR(myfile); 448 return PTR_ERR(myfile);
449 } else { 449 } else {
450 if (!(myfile->f_op)) { 450 if (!(myfile->f_op)) {
451 printk(KERN_ERR 451 printk(KERN_ERR
452 "%s: File has no file operations registered!", 452 "%s: File has no file operations registered!",
453 __func__); 453 __func__);
454 filp_close(myfile, NULL); 454 filp_close(myfile, NULL);
455 return -EIO; 455 return -EIO;
456 } 456 }
457 457
458 if (!myfile->f_op->read) { 458 if (!myfile->f_op->read) {
459 printk(KERN_ERR 459 printk(KERN_ERR
460 "%s: File has no READ operations registered! \ 460 "%s: File has no READ operations registered! \
461 Returning.", 461 Returning.",
462 __func__); 462 __func__);
463 filp_close(myfile, NULL); 463 filp_close(myfile, NULL);
464 return -EIO; 464 return -EIO;
@@ -488,8 +488,8 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
488 488
489 if (vfs_read_retval < line_size) { 489 if (vfs_read_retval < line_size) {
490 printk(KERN_INFO 490 printk(KERN_INFO
491 "Done: exit %s() since no more \ 491 "Done: exit %s() since no more \
492 bytes to read from Video file.\n", 492 bytes to read from Video file.\n",
493 __func__); 493 __func__);
494 break; 494 break;
495 } 495 }
@@ -535,8 +535,8 @@ int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev,
535 535
536 if (!dev->_dma_virt_addr) { 536 if (!dev->_dma_virt_addr) {
537 printk 537 printk
538 (KERN_ERR "cx25821: FAILED to allocate memory for Risc \ 538 (KERN_ERR "cx25821: FAILED to allocate memory for Risc \
539 buffer! Returning.\n"); 539 buffer! Returning.\n");
540 return -ENOMEM; 540 return -ENOMEM;
541 } 541 }
542 542
@@ -557,8 +557,8 @@ int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev,
557 557
558 if (!dev->_data_buf_virt_addr) { 558 if (!dev->_data_buf_virt_addr) {
559 printk 559 printk
560 (KERN_ERR "cx25821: FAILED to allocate memory for data \ 560 (KERN_ERR "cx25821: FAILED to allocate memory for data \
561 buffer! Returning.\n"); 561 buffer! Returning.\n");
562 return -ENOMEM; 562 return -ENOMEM;
563 } 563 }
564 564
@@ -653,16 +653,16 @@ int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num,
653 } else { 653 } else {
654 if (status & FLD_VID_SRC_UF) 654 if (status & FLD_VID_SRC_UF)
655 printk 655 printk
656 (KERN_ERR "%s: Video Received Underflow Error \ 656 (KERN_ERR "%s: Video Received Underflow Error \
657 Interrupt!\n", __func__); 657 Interrupt!\n", __func__);
658 658
659 if (status & FLD_VID_SRC_SYNC) 659 if (status & FLD_VID_SRC_SYNC)
660 printk(KERN_ERR "%s: Video Received Sync Error \ 660 printk(KERN_ERR "%s: Video Received Sync Error \
661 Interrupt!\n", __func__); 661 Interrupt!\n", __func__);
662 662
663 if (status & FLD_VID_SRC_OPC_ERR) 663 if (status & FLD_VID_SRC_OPC_ERR)
664 printk(KERN_ERR "%s: Video Received OpCode Error \ 664 printk(KERN_ERR "%s: Video Received OpCode Error \
665 Interrupt!\n", __func__); 665 Interrupt!\n", __func__);
666 } 666 }
667 667
668 if (dev->_file_status == END_OF_FILE) { 668 if (dev->_file_status == END_OF_FILE) {
@@ -818,8 +818,8 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select,
818 818
819 if (!dev->_irq_queues) { 819 if (!dev->_irq_queues) {
820 printk 820 printk
821 (KERN_ERR "cx25821: create_singlethread_workqueue() for \ 821 (KERN_ERR "cx25821: create_singlethread_workqueue() for \
822 Video FAILED!\n"); 822 Video FAILED!\n");
823 return -ENOMEM; 823 return -ENOMEM;
824 } 824 }
825 /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for 825 /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for
diff --git a/drivers/staging/cx25821/cx25821-video.c b/drivers/staging/cx25821/cx25821-video.c
index 90210b775c98..1d5e8796d383 100644
--- a/drivers/staging/cx25821/cx25821-video.c
+++ b/drivers/staging/cx25821/cx25821-video.c
@@ -410,8 +410,8 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
410 if (status & FLD_VID_DST_RISC1) { 410 if (status & FLD_VID_DST_RISC1) {
411 spin_lock(&dev->slock); 411 spin_lock(&dev->slock);
412 count = cx_read(channel->gpcnt); 412 count = cx_read(channel->gpcnt);
413 cx25821_video_wakeup(dev, 413 cx25821_video_wakeup(dev,
414 &dev->channels[channel->i].vidq, count); 414 &dev->channels[channel->i].vidq, count);
415 spin_unlock(&dev->slock); 415 spin_unlock(&dev->slock);
416 handled++; 416 handled++;
417 } 417 }
@@ -420,9 +420,9 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
420 if (status & 0x10) { 420 if (status & 0x10) {
421 dprintk(2, "stopper video\n"); 421 dprintk(2, "stopper video\n");
422 spin_lock(&dev->slock); 422 spin_lock(&dev->slock);
423 cx25821_restart_video_queue(dev, 423 cx25821_restart_video_queue(dev,
424 &dev->channels[channel->i].vidq, 424 &dev->channels[channel->i].vidq,
425 channel); 425 channel);
426 spin_unlock(&dev->slock); 426 spin_unlock(&dev->slock);
427 handled++; 427 handled++;
428 } 428 }
@@ -446,17 +446,17 @@ void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num)
446 cx_clear(PCI_INT_MSK, 1); 446 cx_clear(PCI_INT_MSK, 1);
447 447
448 if (dev->channels[chan_num].video_dev) { 448 if (dev->channels[chan_num].video_dev) {
449 if (video_is_registered(dev->channels[chan_num].video_dev)) 449 if (video_is_registered(dev->channels[chan_num].video_dev))
450 video_unregister_device( 450 video_unregister_device(
451 dev->channels[chan_num].video_dev); 451 dev->channels[chan_num].video_dev);
452 else 452 else
453 video_device_release( 453 video_device_release(
454 dev->channels[chan_num].video_dev); 454 dev->channels[chan_num].video_dev);
455 455
456 dev->channels[chan_num].video_dev = NULL; 456 dev->channels[chan_num].video_dev = NULL;
457 457
458 btcx_riscmem_free(dev->pci, 458 btcx_riscmem_free(dev->pci,
459 &dev->channels[chan_num].vidq.stopper); 459 &dev->channels[chan_num].vidq.stopper);
460 460
461 printk(KERN_WARNING "device %d released!\n", chan_num); 461 printk(KERN_WARNING "device %d released!\n", chan_num);
462 } 462 }
@@ -469,52 +469,52 @@ int cx25821_video_register(struct cx25821_dev *dev)
469 int i; 469 int i;
470 470
471 struct video_device cx25821_video_device = { 471 struct video_device cx25821_video_device = {
472 .name = "cx25821-video", 472 .name = "cx25821-video",
473 .fops = &video_fops, 473 .fops = &video_fops,
474 .minor = -1, 474 .minor = -1,
475 .ioctl_ops = &video_ioctl_ops, 475 .ioctl_ops = &video_ioctl_ops,
476 .tvnorms = CX25821_NORMS, 476 .tvnorms = CX25821_NORMS,
477 .current_norm = V4L2_STD_NTSC_M, 477 .current_norm = V4L2_STD_NTSC_M,
478 }; 478 };
479 479
480 spin_lock_init(&dev->slock); 480 spin_lock_init(&dev->slock);
481 481
482 for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; ++i) { 482 for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; ++i) {
483 cx25821_init_controls(dev, i); 483 cx25821_init_controls(dev, i);
484 484
485 cx25821_risc_stopper(dev->pci, 485 cx25821_risc_stopper(dev->pci,
486 &dev->channels[i].vidq.stopper, 486 &dev->channels[i].vidq.stopper,
487 dev->channels[i].sram_channels->dma_ctl, 487 dev->channels[i].sram_channels->dma_ctl,
488 0x11, 0); 488 0x11, 0);
489 489
490 dev->channels[i].sram_channels = &cx25821_sram_channels[i]; 490 dev->channels[i].sram_channels = &cx25821_sram_channels[i];
491 dev->channels[i].video_dev = NULL; 491 dev->channels[i].video_dev = NULL;
492 dev->channels[i].resources = 0; 492 dev->channels[i].resources = 0;
493 493
494 cx_write(dev->channels[i].sram_channels->int_stat, 494 cx_write(dev->channels[i].sram_channels->int_stat,
495 0xffffffff); 495 0xffffffff);
496 496
497 INIT_LIST_HEAD(&dev->channels[i].vidq.active); 497 INIT_LIST_HEAD(&dev->channels[i].vidq.active);
498 INIT_LIST_HEAD(&dev->channels[i].vidq.queued); 498 INIT_LIST_HEAD(&dev->channels[i].vidq.queued);
499 499
500 dev->channels[i].timeout_data.dev = dev; 500 dev->channels[i].timeout_data.dev = dev;
501 dev->channels[i].timeout_data.channel = 501 dev->channels[i].timeout_data.channel =
502 &cx25821_sram_channels[i]; 502 &cx25821_sram_channels[i];
503 dev->channels[i].vidq.timeout.function = 503 dev->channels[i].vidq.timeout.function =
504 cx25821_vid_timeout; 504 cx25821_vid_timeout;
505 dev->channels[i].vidq.timeout.data = 505 dev->channels[i].vidq.timeout.data =
506 (unsigned long)&dev->channels[i].timeout_data; 506 (unsigned long)&dev->channels[i].timeout_data;
507 init_timer(&dev->channels[i].vidq.timeout); 507 init_timer(&dev->channels[i].vidq.timeout);
508 508
509 /* register v4l devices */ 509 /* register v4l devices */
510 dev->channels[i].video_dev = cx25821_vdev_init(dev, 510 dev->channels[i].video_dev = cx25821_vdev_init(dev,
511 dev->pci, &cx25821_video_device, "video"); 511 dev->pci, &cx25821_video_device, "video");
512 512
513 err = video_register_device(dev->channels[i].video_dev, 513 err = video_register_device(dev->channels[i].video_dev,
514 VFL_TYPE_GRABBER, video_nr[dev->nr]); 514 VFL_TYPE_GRABBER, video_nr[dev->nr]);
515 515
516 if (err < 0) 516 if (err < 0)
517 goto fail_unreg; 517 goto fail_unreg;
518 518
519 } 519 }
520 520
@@ -603,29 +603,29 @@ int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
603 channel_opened = (channel_opened < 0 603 channel_opened = (channel_opened < 0
604 || channel_opened > 7) ? 7 : channel_opened; 604 || channel_opened > 7) ? 7 : channel_opened;
605 605
606 if (dev->channels[channel_opened] 606 if (dev->channels[channel_opened]
607 .pixel_formats == PIXEL_FRMT_411) 607 .pixel_formats == PIXEL_FRMT_411)
608 buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3; 608 buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3;
609 else 609 else
610 buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width); 610 buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width);
611 611
612 if (dev->channels[channel_opened] 612 if (dev->channels[channel_opened]
613 .pixel_formats == PIXEL_FRMT_411) { 613 .pixel_formats == PIXEL_FRMT_411) {
614 bpl_local = buf->bpl; 614 bpl_local = buf->bpl;
615 } else { 615 } else {
616 bpl_local = buf->bpl; /* Default */ 616 bpl_local = buf->bpl; /* Default */
617 617
618 if (channel_opened >= 0 && channel_opened <= 7) { 618 if (channel_opened >= 0 && channel_opened <= 7) {
619 if (dev->channels[channel_opened] 619 if (dev->channels[channel_opened]
620 .use_cif_resolution) { 620 .use_cif_resolution) {
621 if (dev->tvnorm & V4L2_STD_PAL_BG 621 if (dev->tvnorm & V4L2_STD_PAL_BG
622 || dev->tvnorm & V4L2_STD_PAL_DK) 622 || dev->tvnorm & V4L2_STD_PAL_DK)
623 bpl_local = 352 << 1; 623 bpl_local = 352 << 1;
624 else 624 else
625 bpl_local = 625 bpl_local =
626 dev->channels[channel_opened]. 626 dev->channels[channel_opened].
627 cif_width << 627 cif_width <<
628 1; 628 1;
629 } 629 }
630 } 630 }
631 } 631 }
@@ -723,7 +723,7 @@ int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma)
723static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) 723static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
724{ 724{
725 struct cx25821_buffer *buf = 725 struct cx25821_buffer *buf =
726 container_of(vb, struct cx25821_buffer, vb); 726 container_of(vb, struct cx25821_buffer, vb);
727 struct cx25821_buffer *prev; 727 struct cx25821_buffer *prev;
728 struct cx25821_fh *fh = vq->priv_data; 728 struct cx25821_fh *fh = vq->priv_data;
729 struct cx25821_dev *dev = fh->dev; 729 struct cx25821_dev *dev = fh->dev;
@@ -737,51 +737,51 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
737 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]); 737 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
738 738
739 if (!list_empty(&q->queued)) { 739 if (!list_empty(&q->queued)) {
740 list_add_tail(&buf->vb.queue, &q->queued); 740 list_add_tail(&buf->vb.queue, &q->queued);
741 buf->vb.state = VIDEOBUF_QUEUED; 741 buf->vb.state = VIDEOBUF_QUEUED;
742 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, 742 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
743 buf->vb.i); 743 buf->vb.i);
744 744
745 } else if (list_empty(&q->active)) { 745 } else if (list_empty(&q->active)) {
746 list_add_tail(&buf->vb.queue, &q->active); 746 list_add_tail(&buf->vb.queue, &q->active);
747 cx25821_start_video_dma(dev, q, buf, 747 cx25821_start_video_dma(dev, q, buf,
748 dev->channels[fh->channel_id]. 748 dev->channels[fh->channel_id].
749 sram_channels); 749 sram_channels);
750 buf->vb.state = VIDEOBUF_ACTIVE; 750 buf->vb.state = VIDEOBUF_ACTIVE;
751 buf->count = q->count++; 751 buf->count = q->count++;
752 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); 752 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
753 dprintk(2, 753 dprintk(2,
754 "[%p/%d] buffer_queue - first active, buf cnt = %d, \ 754 "[%p/%d] buffer_queue - first active, buf cnt = %d, \
755 q->count = %d\n", 755 q->count = %d\n",
756 buf, buf->vb.i, buf->count, q->count); 756 buf, buf->vb.i, buf->count, q->count);
757 } else { 757 } else {
758 prev = 758 prev =
759 list_entry(q->active.prev, struct cx25821_buffer, vb.queue); 759 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
760 if (prev->vb.width == buf->vb.width 760 if (prev->vb.width == buf->vb.width
761 && prev->vb.height == buf->vb.height 761 && prev->vb.height == buf->vb.height
762 && prev->fmt == buf->fmt) { 762 && prev->fmt == buf->fmt) {
763 list_add_tail(&buf->vb.queue, &q->active); 763 list_add_tail(&buf->vb.queue, &q->active);
764 buf->vb.state = VIDEOBUF_ACTIVE; 764 buf->vb.state = VIDEOBUF_ACTIVE;
765 buf->count = q->count++; 765 buf->count = q->count++;
766 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 766 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
767 767
768 /* 64 bit bits 63-32 */ 768 /* 64 bit bits 63-32 */
769 prev->risc.jmp[2] = cpu_to_le32(0); 769 prev->risc.jmp[2] = cpu_to_le32(0);
770 dprintk(2, 770 dprintk(2,
771 "[%p/%d] buffer_queue - append to active, \ 771 "[%p/%d] buffer_queue - append to active, \
772 buf->count=%d\n", 772 buf->count=%d\n",
773 buf, buf->vb.i, buf->count); 773 buf, buf->vb.i, buf->count);
774 774
775 } else { 775 } else {
776 list_add_tail(&buf->vb.queue, &q->queued); 776 list_add_tail(&buf->vb.queue, &q->queued);
777 buf->vb.state = VIDEOBUF_QUEUED; 777 buf->vb.state = VIDEOBUF_QUEUED;
778 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, 778 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
779 buf->vb.i); 779 buf->vb.i);
780 } 780 }
781 } 781 }
782 782
783 if (list_empty(&q->active)) 783 if (list_empty(&q->active))
784 dprintk(2, "active queue empty!\n"); 784 dprintk(2, "active queue empty!\n");
785} 785}
786 786
787static struct videobuf_queue_ops cx25821_video_qops = { 787static struct videobuf_queue_ops cx25821_video_qops = {
@@ -804,33 +804,33 @@ static int video_open(struct file *file)
804 int i; 804 int i;
805 805
806 dprintk(1, "open dev=%s type=%s\n", 806 dprintk(1, "open dev=%s type=%s\n",
807 video_device_node_name(vdev), 807 video_device_node_name(vdev),
808 v4l2_type_names[type]); 808 v4l2_type_names[type]);
809 809
810 /* allocate + initialize per filehandle data */ 810 /* allocate + initialize per filehandle data */
811 fh = kzalloc(sizeof(*fh), GFP_KERNEL); 811 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
812 if (NULL == fh) 812 if (NULL == fh)
813 return -ENOMEM; 813 return -ENOMEM;
814 814
815 lock_kernel(); 815 lock_kernel();
816 816
817 list_for_each(list, &cx25821_devlist) 817 list_for_each(list, &cx25821_devlist)
818 { 818 {
819 h = list_entry(list, struct cx25821_dev, devlist); 819 h = list_entry(list, struct cx25821_dev, devlist);
820 820
821 for (i = 0; i < MAX_VID_CHANNEL_NUM; i++) { 821 for (i = 0; i < MAX_VID_CHANNEL_NUM; i++) {
822 if (h->channels[i].video_dev && 822 if (h->channels[i].video_dev &&
823 h->channels[i].video_dev->minor == minor) { 823 h->channels[i].video_dev->minor == minor) {
824 dev = h; 824 dev = h;
825 ch_id = i; 825 ch_id = i;
826 type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 826 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
827 } 827 }
828 } 828 }
829 } 829 }
830 830
831 if (NULL == dev) { 831 if (NULL == dev) {
832 unlock_kernel(); 832 unlock_kernel();
833 return -ENODEV; 833 return -ENODEV;
834 } 834 }
835 835
836 file->private_data = fh; 836 file->private_data = fh;
@@ -840,23 +840,23 @@ static int video_open(struct file *file)
840 fh->channel_id = ch_id; 840 fh->channel_id = ch_id;
841 841
842 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK) 842 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
843 fh->height = 576; 843 fh->height = 576;
844 else 844 else
845 fh->height = 480; 845 fh->height = 480;
846 846
847 dev->channel_opened = fh->channel_id; 847 dev->channel_opened = fh->channel_id;
848 pix_format = 848 pix_format =
849 (dev->channels[ch_id].pixel_formats == 849 (dev->channels[ch_id].pixel_formats ==
850 PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV; 850 PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
851 fh->fmt = format_by_fourcc(pix_format); 851 fh->fmt = format_by_fourcc(pix_format);
852 852
853 v4l2_prio_open(&dev->channels[ch_id].prio, &fh->prio); 853 v4l2_prio_open(&dev->channels[ch_id].prio, &fh->prio);
854 854
855 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops, 855 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
856 &dev->pci->dev, &dev->slock, 856 &dev->pci->dev, &dev->slock,
857 V4L2_BUF_TYPE_VIDEO_CAPTURE, 857 V4L2_BUF_TYPE_VIDEO_CAPTURE,
858 V4L2_FIELD_INTERLACED, 858 V4L2_FIELD_INTERLACED,
859 sizeof(struct cx25821_buffer), fh); 859 sizeof(struct cx25821_buffer), fh);
860 860
861 dprintk(1, "post videobuf_queue_init()\n"); 861 dprintk(1, "post videobuf_queue_init()\n");
862 unlock_kernel(); 862 unlock_kernel();
@@ -865,59 +865,59 @@ static int video_open(struct file *file)
865} 865}
866 866
867static ssize_t video_read(struct file *file, char __user * data, size_t count, 867static ssize_t video_read(struct file *file, char __user * data, size_t count,
868 loff_t *ppos) 868 loff_t *ppos)
869{ 869{
870 struct cx25821_fh *fh = file->private_data; 870 struct cx25821_fh *fh = file->private_data;
871 871
872 switch (fh->type) { 872 switch (fh->type) {
873 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 873 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
874 if (cx25821_res_locked(fh, RESOURCE_VIDEO0)) 874 if (cx25821_res_locked(fh, RESOURCE_VIDEO0))
875 return -EBUSY; 875 return -EBUSY;
876 876
877 return videobuf_read_one(&fh->vidq, data, count, ppos, 877 return videobuf_read_one(&fh->vidq, data, count, ppos,
878 file->f_flags & O_NONBLOCK); 878 file->f_flags & O_NONBLOCK);
879 879
880 default: 880 default:
881 BUG(); 881 BUG();
882 return 0; 882 return 0;
883 } 883 }
884} 884}
885 885
886static unsigned int video_poll(struct file *file, 886static unsigned int video_poll(struct file *file,
887 struct poll_table_struct *wait) 887 struct poll_table_struct *wait)
888{ 888{
889 struct cx25821_fh *fh = file->private_data; 889 struct cx25821_fh *fh = file->private_data;
890 struct cx25821_buffer *buf; 890 struct cx25821_buffer *buf;
891 891
892 if (cx25821_res_check(fh, RESOURCE_VIDEO0)) { 892 if (cx25821_res_check(fh, RESOURCE_VIDEO0)) {
893 /* streaming capture */ 893 /* streaming capture */
894 if (list_empty(&fh->vidq.stream)) 894 if (list_empty(&fh->vidq.stream))
895 return POLLERR; 895 return POLLERR;
896 buf = list_entry(fh->vidq.stream.next, 896 buf = list_entry(fh->vidq.stream.next,
897 struct cx25821_buffer, vb.stream); 897 struct cx25821_buffer, vb.stream);
898 } else { 898 } else {
899 /* read() capture */ 899 /* read() capture */
900 buf = (struct cx25821_buffer *)fh->vidq.read_buf; 900 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
901 if (NULL == buf) 901 if (NULL == buf)
902 return POLLERR; 902 return POLLERR;
903 } 903 }
904 904
905 poll_wait(file, &buf->vb.done, wait); 905 poll_wait(file, &buf->vb.done, wait);
906 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) { 906 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
907 if (buf->vb.state == VIDEOBUF_DONE) { 907 if (buf->vb.state == VIDEOBUF_DONE) {
908 struct cx25821_dev *dev = fh->dev; 908 struct cx25821_dev *dev = fh->dev;
909 909
910 if (dev && dev->channels[fh->channel_id] 910 if (dev && dev->channels[fh->channel_id]
911 .use_cif_resolution) { 911 .use_cif_resolution) {
912 u8 cam_id = *((char *)buf->vb.baddr + 3); 912 u8 cam_id = *((char *)buf->vb.baddr + 3);
913 memcpy((char *)buf->vb.baddr, 913 memcpy((char *)buf->vb.baddr,
914 (char *)buf->vb.baddr + (fh->width * 2), 914 (char *)buf->vb.baddr + (fh->width * 2),
915 (fh->width * 2)); 915 (fh->width * 2));
916 *((char *)buf->vb.baddr + 3) = cam_id; 916 *((char *)buf->vb.baddr + 3) = cam_id;
917 } 917 }
918 } 918 }
919 919
920 return POLLIN | POLLRDNORM; 920 return POLLIN | POLLRDNORM;
921 } 921 }
922 922
923 return 0; 923 return 0;
@@ -933,13 +933,13 @@ static int video_release(struct file *file)
933 933
934 /* stop video capture */ 934 /* stop video capture */
935 if (cx25821_res_check(fh, RESOURCE_VIDEO0)) { 935 if (cx25821_res_check(fh, RESOURCE_VIDEO0)) {
936 videobuf_queue_cancel(&fh->vidq); 936 videobuf_queue_cancel(&fh->vidq);
937 cx25821_res_free(dev, fh, RESOURCE_VIDEO0); 937 cx25821_res_free(dev, fh, RESOURCE_VIDEO0);
938 } 938 }
939 939
940 if (fh->vidq.read_buf) { 940 if (fh->vidq.read_buf) {
941 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf); 941 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
942 kfree(fh->vidq.read_buf); 942 kfree(fh->vidq.read_buf);
943 } 943 }
944 944
945 videobuf_mmap_free(&fh->vidq); 945 videobuf_mmap_free(&fh->vidq);
@@ -957,14 +957,14 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
957 struct cx25821_dev *dev = fh->dev; 957 struct cx25821_dev *dev = fh->dev;
958 958
959 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) 959 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
960 return -EINVAL; 960 return -EINVAL;
961 961
962 if (unlikely(i != fh->type)) 962 if (unlikely(i != fh->type))
963 return -EINVAL; 963 return -EINVAL;
964 964
965 if (unlikely(!cx25821_res_get(dev, fh, 965 if (unlikely(!cx25821_res_get(dev, fh,
966 cx25821_get_resource(fh, RESOURCE_VIDEO0)))) 966 cx25821_get_resource(fh, RESOURCE_VIDEO0))))
967 return -EBUSY; 967 return -EBUSY;
968 968
969 return videobuf_streamon(get_queue(fh)); 969 return videobuf_streamon(get_queue(fh));
970} 970}
@@ -976,20 +976,20 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
976 int err, res; 976 int err, res;
977 977
978 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 978 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
979 return -EINVAL; 979 return -EINVAL;
980 if (i != fh->type) 980 if (i != fh->type)
981 return -EINVAL; 981 return -EINVAL;
982 982
983 res = cx25821_get_resource(fh, RESOURCE_VIDEO0); 983 res = cx25821_get_resource(fh, RESOURCE_VIDEO0);
984 err = videobuf_streamoff(get_queue(fh)); 984 err = videobuf_streamoff(get_queue(fh));
985 if (err < 0) 985 if (err < 0)
986 return err; 986 return err;
987 cx25821_res_free(dev, fh, res); 987 cx25821_res_free(dev, fh, res);
988 return 0; 988 return 0;
989} 989}
990 990
991static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 991static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
992 struct v4l2_format *f) 992 struct v4l2_format *f)
993{ 993{
994 struct cx25821_fh *fh = priv; 994 struct cx25821_fh *fh = priv;
995 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 995 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
@@ -997,48 +997,48 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
997 int pix_format = PIXEL_FRMT_422; 997 int pix_format = PIXEL_FRMT_422;
998 998
999 if (fh) { 999 if (fh) {
1000 err = v4l2_prio_check(&dev->channels[fh->channel_id] 1000 err = v4l2_prio_check(&dev->channels[fh->channel_id]
1001 .prio, fh->prio); 1001 .prio, fh->prio);
1002 if (0 != err) 1002 if (0 != err)
1003 return err; 1003 return err;
1004 } 1004 }
1005 1005
1006 dprintk(2, "%s()\n", __func__); 1006 dprintk(2, "%s()\n", __func__);
1007 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f); 1007 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
1008 1008
1009 if (0 != err) 1009 if (0 != err)
1010 return err; 1010 return err;
1011 1011
1012 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat); 1012 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1013 fh->vidq.field = f->fmt.pix.field; 1013 fh->vidq.field = f->fmt.pix.field;
1014 1014
1015 /* check if width and height is valid based on set standard */ 1015 /* check if width and height is valid based on set standard */
1016 if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) 1016 if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm))
1017 fh->width = f->fmt.pix.width; 1017 fh->width = f->fmt.pix.width;
1018 1018
1019 if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) 1019 if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm))
1020 fh->height = f->fmt.pix.height; 1020 fh->height = f->fmt.pix.height;
1021 1021
1022 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) 1022 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
1023 pix_format = PIXEL_FRMT_411; 1023 pix_format = PIXEL_FRMT_411;
1024 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) 1024 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
1025 pix_format = PIXEL_FRMT_422; 1025 pix_format = PIXEL_FRMT_422;
1026 else 1026 else
1027 return -EINVAL; 1027 return -EINVAL;
1028 1028
1029 cx25821_set_pixel_format(dev, SRAM_CH00, pix_format); 1029 cx25821_set_pixel_format(dev, SRAM_CH00, pix_format);
1030 1030
1031 /* check if cif resolution */ 1031 /* check if cif resolution */
1032 if (fh->width == 320 || fh->width == 352) 1032 if (fh->width == 320 || fh->width == 352)
1033 dev->channels[fh->channel_id].use_cif_resolution = 1; 1033 dev->channels[fh->channel_id].use_cif_resolution = 1;
1034 else 1034 else
1035 dev->channels[fh->channel_id].use_cif_resolution = 0; 1035 dev->channels[fh->channel_id].use_cif_resolution = 0;
1036 1036
1037 dev->channels[fh->channel_id].cif_width = fh->width; 1037 dev->channels[fh->channel_id].cif_width = fh->width;
1038 medusa_set_resolution(dev, fh->width, SRAM_CH00); 1038 medusa_set_resolution(dev, fh->width, SRAM_CH00);
1039 1039
1040 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, 1040 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
1041 fh->height, fh->vidq.field); 1041 fh->height, fh->vidq.field);
1042 cx25821_call_all(dev, video, s_fmt, f); 1042 cx25821_call_all(dev, video, s_fmt, f);
1043 1043
1044 return 0; 1044 return 0;
@@ -1064,33 +1064,33 @@ static int vidioc_log_status(struct file *file, void *priv)
1064 char name[32 + 2]; 1064 char name[32 + 2];
1065 1065
1066 struct sram_channel *sram_ch = dev->channels[fh->channel_id] 1066 struct sram_channel *sram_ch = dev->channels[fh->channel_id]
1067 .sram_channels; 1067 .sram_channels;
1068 u32 tmp = 0; 1068 u32 tmp = 0;
1069 1069
1070 snprintf(name, sizeof(name), "%s/2", dev->name); 1070 snprintf(name, sizeof(name), "%s/2", dev->name);
1071 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n", 1071 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
1072 dev->name); 1072 dev->name);
1073 cx25821_call_all(dev, core, log_status); 1073 cx25821_call_all(dev, core, log_status);
1074 tmp = cx_read(sram_ch->dma_ctl); 1074 tmp = cx_read(sram_ch->dma_ctl);
1075 printk(KERN_INFO "Video input 0 is %s\n", 1075 printk(KERN_INFO "Video input 0 is %s\n",
1076 (tmp & 0x11) ? "streaming" : "stopped"); 1076 (tmp & 0x11) ? "streaming" : "stopped");
1077 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n", 1077 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
1078 dev->name); 1078 dev->name);
1079 return 0; 1079 return 0;
1080} 1080}
1081 1081
1082static int vidioc_s_ctrl(struct file *file, void *priv, 1082static int vidioc_s_ctrl(struct file *file, void *priv,
1083 struct v4l2_control *ctl) 1083 struct v4l2_control *ctl)
1084{ 1084{
1085 struct cx25821_fh *fh = priv; 1085 struct cx25821_fh *fh = priv;
1086 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 1086 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1087 int err; 1087 int err;
1088 1088
1089 if (fh) { 1089 if (fh) {
1090 err = v4l2_prio_check(&dev->channels[fh->channel_id] 1090 err = v4l2_prio_check(&dev->channels[fh->channel_id]
1091 .prio, fh->prio); 1091 .prio, fh->prio);
1092 if (0 != err) 1092 if (0 != err)
1093 return err; 1093 return err;
1094 } 1094 }
1095 1095
1096 return cx25821_set_control(dev, ctl, fh->channel_id); 1096 return cx25821_set_control(dev, ctl, fh->channel_id);
@@ -1246,7 +1246,7 @@ int cx25821_vidioc_s_priority(struct file *file, void *f, enum v4l2_priority pri
1246 struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev; 1246 struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev;
1247 1247
1248 return v4l2_prio_change(&dev->channels[fh->channel_id] 1248 return v4l2_prio_change(&dev->channels[fh->channel_id]
1249 .prio, &fh->prio, prio); 1249 .prio, &fh->prio, prio);
1250} 1250}
1251 1251
1252#ifdef TUNER_FLAG 1252#ifdef TUNER_FLAG
@@ -1259,8 +1259,8 @@ int cx25821_vidioc_s_std(struct file *file, void *priv, v4l2_std_id * tvnorms)
1259 dprintk(1, "%s()\n", __func__); 1259 dprintk(1, "%s()\n", __func__);
1260 1260
1261 if (fh) { 1261 if (fh) {
1262 err = v4l2_prio_check(&dev->channels[fh->channel_id] 1262 err = v4l2_prio_check(&dev->channels[fh->channel_id]
1263 .prio, fh->prio); 1263 .prio, fh->prio);
1264 if (0 != err) 1264 if (0 != err)
1265 return err; 1265 return err;
1266 } 1266 }
@@ -1330,8 +1330,8 @@ int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i)
1330 dprintk(1, "%s(%d)\n", __func__, i); 1330 dprintk(1, "%s(%d)\n", __func__, i);
1331 1331
1332 if (fh) { 1332 if (fh) {
1333 err = v4l2_prio_check(&dev->channels[fh->channel_id] 1333 err = v4l2_prio_check(&dev->channels[fh->channel_id]
1334 .prio, fh->prio); 1334 .prio, fh->prio);
1335 if (0 != err) 1335 if (0 != err)
1336 return err; 1336 return err;
1337 } 1337 }
@@ -1382,14 +1382,14 @@ int cx25821_vidioc_s_frequency(struct file *file, void *priv, struct v4l2_freque
1382 int err; 1382 int err;
1383 1383
1384 if (fh) { 1384 if (fh) {
1385 dev = fh->dev; 1385 dev = fh->dev;
1386 err = v4l2_prio_check(&dev->channels[fh->channel_id] 1386 err = v4l2_prio_check(&dev->channels[fh->channel_id]
1387 .prio, fh->prio); 1387 .prio, fh->prio);
1388 if (0 != err) 1388 if (0 != err)
1389 return err; 1389 return err;
1390 } else { 1390 } else {
1391 printk(KERN_ERR "Invalid fh pointer!\n"); 1391 printk(KERN_ERR "Invalid fh pointer!\n");
1392 return -EINVAL; 1392 return -EINVAL;
1393 } 1393 }
1394 1394
1395 return cx25821_set_freq(dev, f); 1395 return cx25821_set_freq(dev, f);
@@ -1451,8 +1451,8 @@ int cx25821_vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1451 int err; 1451 int err;
1452 1452
1453 if (fh) { 1453 if (fh) {
1454 err = v4l2_prio_check(&dev->channels[fh->channel_id] 1454 err = v4l2_prio_check(&dev->channels[fh->channel_id]
1455 .prio, fh->prio); 1455 .prio, fh->prio);
1456 if (0 != err) 1456 if (0 != err)
1457 return err; 1457 return err;
1458 } 1458 }
@@ -1560,16 +1560,16 @@ int cx25821_vidioc_g_ctrl(struct file *file, void *priv, struct v4l2_control *ct
1560 return -EINVAL; 1560 return -EINVAL;
1561 switch (ctl->id) { 1561 switch (ctl->id) {
1562 case V4L2_CID_BRIGHTNESS: 1562 case V4L2_CID_BRIGHTNESS:
1563 ctl->value = dev->channels[fh->channel_id].ctl_bright; 1563 ctl->value = dev->channels[fh->channel_id].ctl_bright;
1564 break; 1564 break;
1565 case V4L2_CID_HUE: 1565 case V4L2_CID_HUE:
1566 ctl->value = dev->channels[fh->channel_id].ctl_hue; 1566 ctl->value = dev->channels[fh->channel_id].ctl_hue;
1567 break; 1567 break;
1568 case V4L2_CID_CONTRAST: 1568 case V4L2_CID_CONTRAST:
1569 ctl->value = dev->channels[fh->channel_id].ctl_contrast; 1569 ctl->value = dev->channels[fh->channel_id].ctl_contrast;
1570 break; 1570 break;
1571 case V4L2_CID_SATURATION: 1571 case V4L2_CID_SATURATION:
1572 ctl->value = dev->channels[fh->channel_id].ctl_saturation; 1572 ctl->value = dev->channels[fh->channel_id].ctl_saturation;
1573 break; 1573 break;
1574 } 1574 }
1575 return 0; 1575 return 0;
@@ -1603,19 +1603,19 @@ int cx25821_set_control(struct cx25821_dev *dev,
1603 1603
1604 switch (ctl->id) { 1604 switch (ctl->id) {
1605 case V4L2_CID_BRIGHTNESS: 1605 case V4L2_CID_BRIGHTNESS:
1606 dev->channels[chan_num].ctl_bright = ctl->value; 1606 dev->channels[chan_num].ctl_bright = ctl->value;
1607 medusa_set_brightness(dev, ctl->value, chan_num); 1607 medusa_set_brightness(dev, ctl->value, chan_num);
1608 break; 1608 break;
1609 case V4L2_CID_HUE: 1609 case V4L2_CID_HUE:
1610 dev->channels[chan_num].ctl_hue = ctl->value; 1610 dev->channels[chan_num].ctl_hue = ctl->value;
1611 medusa_set_hue(dev, ctl->value, chan_num); 1611 medusa_set_hue(dev, ctl->value, chan_num);
1612 break; 1612 break;
1613 case V4L2_CID_CONTRAST: 1613 case V4L2_CID_CONTRAST:
1614 dev->channels[chan_num].ctl_contrast = ctl->value; 1614 dev->channels[chan_num].ctl_contrast = ctl->value;
1615 medusa_set_contrast(dev, ctl->value, chan_num); 1615 medusa_set_contrast(dev, ctl->value, chan_num);
1616 break; 1616 break;
1617 case V4L2_CID_SATURATION: 1617 case V4L2_CID_SATURATION:
1618 dev->channels[chan_num].ctl_saturation = ctl->value; 1618 dev->channels[chan_num].ctl_saturation = ctl->value;
1619 medusa_set_saturation(dev, ctl->value, chan_num); 1619 medusa_set_saturation(dev, ctl->value, chan_num);
1620 break; 1620 break;
1621 } 1621 }
@@ -1661,8 +1661,8 @@ int cx25821_vidioc_s_crop(struct file *file, void *priv, struct v4l2_crop *crop)
1661 int err; 1661 int err;
1662 1662
1663 if (fh) { 1663 if (fh) {
1664 err = v4l2_prio_check(&dev->channels[fh->channel_id]. 1664 err = v4l2_prio_check(&dev->channels[fh->channel_id].
1665 prio, fh->prio); 1665 prio, fh->prio);
1666 if (0 != err) 1666 if (0 != err)
1667 return err; 1667 return err;
1668 } 1668 }
@@ -1722,7 +1722,7 @@ int cx25821_is_valid_height(u32 height, v4l2_std_id tvnorm)
1722} 1722}
1723 1723
1724static long video_ioctl_upstream9(struct file *file, unsigned int cmd, 1724static long video_ioctl_upstream9(struct file *file, unsigned int cmd,
1725 unsigned long arg) 1725 unsigned long arg)
1726{ 1726{
1727 struct cx25821_fh *fh = file->private_data; 1727 struct cx25821_fh *fh = file->private_data;
1728 struct cx25821_dev *dev = fh->dev; 1728 struct cx25821_dev *dev = fh->dev;
@@ -1732,17 +1732,17 @@ static long video_ioctl_upstream9(struct file *file, unsigned int cmd,
1732 data_from_user = (struct upstream_user_struct *)arg; 1732 data_from_user = (struct upstream_user_struct *)arg;
1733 1733
1734 if (!data_from_user) { 1734 if (!data_from_user) {
1735 printk 1735 printk
1736 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n", 1736 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
1737 __func__); 1737 __func__);
1738 return 0; 1738 return 0;
1739 } 1739 }
1740 1740
1741 command = data_from_user->command; 1741 command = data_from_user->command;
1742 1742
1743 if (command != UPSTREAM_START_VIDEO && 1743 if (command != UPSTREAM_START_VIDEO &&
1744 command != UPSTREAM_STOP_VIDEO) 1744 command != UPSTREAM_STOP_VIDEO)
1745 return 0; 1745 return 0;
1746 1746
1747 dev->input_filename = data_from_user->input_filename; 1747 dev->input_filename = data_from_user->input_filename;
1748 dev->input_audiofilename = data_from_user->input_filename; 1748 dev->input_audiofilename = data_from_user->input_filename;
@@ -1753,19 +1753,19 @@ static long video_ioctl_upstream9(struct file *file, unsigned int cmd,
1753 1753
1754 switch (command) { 1754 switch (command) {
1755 case UPSTREAM_START_VIDEO: 1755 case UPSTREAM_START_VIDEO:
1756 cx25821_start_upstream_video_ch1(dev, data_from_user); 1756 cx25821_start_upstream_video_ch1(dev, data_from_user);
1757 break; 1757 break;
1758 1758
1759 case UPSTREAM_STOP_VIDEO: 1759 case UPSTREAM_STOP_VIDEO:
1760 cx25821_stop_upstream_video_ch1(dev); 1760 cx25821_stop_upstream_video_ch1(dev);
1761 break; 1761 break;
1762 } 1762 }
1763 1763
1764 return 0; 1764 return 0;
1765} 1765}
1766 1766
1767static long video_ioctl_upstream10(struct file *file, unsigned int cmd, 1767static long video_ioctl_upstream10(struct file *file, unsigned int cmd,
1768 unsigned long arg) 1768 unsigned long arg)
1769{ 1769{
1770 struct cx25821_fh *fh = file->private_data; 1770 struct cx25821_fh *fh = file->private_data;
1771 struct cx25821_dev *dev = fh->dev; 1771 struct cx25821_dev *dev = fh->dev;
@@ -1775,17 +1775,17 @@ static long video_ioctl_upstream10(struct file *file, unsigned int cmd,
1775 data_from_user = (struct upstream_user_struct *)arg; 1775 data_from_user = (struct upstream_user_struct *)arg;
1776 1776
1777 if (!data_from_user) { 1777 if (!data_from_user) {
1778 printk 1778 printk
1779 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n", 1779 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
1780 __func__); 1780 __func__);
1781 return 0; 1781 return 0;
1782 } 1782 }
1783 1783
1784 command = data_from_user->command; 1784 command = data_from_user->command;
1785 1785
1786 if (command != UPSTREAM_START_VIDEO && 1786 if (command != UPSTREAM_START_VIDEO &&
1787 command != UPSTREAM_STOP_VIDEO) 1787 command != UPSTREAM_STOP_VIDEO)
1788 return 0; 1788 return 0;
1789 1789
1790 dev->input_filename_ch2 = data_from_user->input_filename; 1790 dev->input_filename_ch2 = data_from_user->input_filename;
1791 dev->input_audiofilename = data_from_user->input_filename; 1791 dev->input_audiofilename = data_from_user->input_filename;
@@ -1796,19 +1796,19 @@ static long video_ioctl_upstream10(struct file *file, unsigned int cmd,
1796 1796
1797 switch (command) { 1797 switch (command) {
1798 case UPSTREAM_START_VIDEO: 1798 case UPSTREAM_START_VIDEO:
1799 cx25821_start_upstream_video_ch2(dev, data_from_user); 1799 cx25821_start_upstream_video_ch2(dev, data_from_user);
1800 break; 1800 break;
1801 1801
1802 case UPSTREAM_STOP_VIDEO: 1802 case UPSTREAM_STOP_VIDEO:
1803 cx25821_stop_upstream_video_ch2(dev); 1803 cx25821_stop_upstream_video_ch2(dev);
1804 break; 1804 break;
1805 } 1805 }
1806 1806
1807 return 0; 1807 return 0;
1808} 1808}
1809 1809
1810static long video_ioctl_upstream11(struct file *file, unsigned int cmd, 1810static long video_ioctl_upstream11(struct file *file, unsigned int cmd,
1811 unsigned long arg) 1811 unsigned long arg)
1812{ 1812{
1813 struct cx25821_fh *fh = file->private_data; 1813 struct cx25821_fh *fh = file->private_data;
1814 struct cx25821_dev *dev = fh->dev; 1814 struct cx25821_dev *dev = fh->dev;
@@ -1818,17 +1818,17 @@ static long video_ioctl_upstream11(struct file *file, unsigned int cmd,
1818 data_from_user = (struct upstream_user_struct *)arg; 1818 data_from_user = (struct upstream_user_struct *)arg;
1819 1819
1820 if (!data_from_user) { 1820 if (!data_from_user) {
1821 printk 1821 printk
1822 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n", 1822 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
1823 __func__); 1823 __func__);
1824 return 0; 1824 return 0;
1825 } 1825 }
1826 1826
1827 command = data_from_user->command; 1827 command = data_from_user->command;
1828 1828
1829 if (command != UPSTREAM_START_AUDIO && 1829 if (command != UPSTREAM_START_AUDIO &&
1830 command != UPSTREAM_STOP_AUDIO) 1830 command != UPSTREAM_STOP_AUDIO)
1831 return 0; 1831 return 0;
1832 1832
1833 dev->input_filename = data_from_user->input_filename; 1833 dev->input_filename = data_from_user->input_filename;
1834 dev->input_audiofilename = data_from_user->input_filename; 1834 dev->input_audiofilename = data_from_user->input_filename;
@@ -1839,19 +1839,19 @@ static long video_ioctl_upstream11(struct file *file, unsigned int cmd,
1839 1839
1840 switch (command) { 1840 switch (command) {
1841 case UPSTREAM_START_AUDIO: 1841 case UPSTREAM_START_AUDIO:
1842 cx25821_start_upstream_audio(dev, data_from_user); 1842 cx25821_start_upstream_audio(dev, data_from_user);
1843 break; 1843 break;
1844 1844
1845 case UPSTREAM_STOP_AUDIO: 1845 case UPSTREAM_STOP_AUDIO:
1846 cx25821_stop_upstream_audio(dev); 1846 cx25821_stop_upstream_audio(dev);
1847 break; 1847 break;
1848 } 1848 }
1849 1849
1850 return 0; 1850 return 0;
1851} 1851}
1852 1852
1853static long video_ioctl_set(struct file *file, unsigned int cmd, 1853static long video_ioctl_set(struct file *file, unsigned int cmd,
1854 unsigned long arg) 1854 unsigned long arg)
1855{ 1855{
1856 struct cx25821_fh *fh = file->private_data; 1856 struct cx25821_fh *fh = file->private_data;
1857 struct cx25821_dev *dev = fh->dev; 1857 struct cx25821_dev *dev = fh->dev;
@@ -1865,101 +1865,101 @@ static long video_ioctl_set(struct file *file, unsigned int cmd,
1865 data_from_user = (struct downstream_user_struct *)arg; 1865 data_from_user = (struct downstream_user_struct *)arg;
1866 1866
1867 if (!data_from_user) { 1867 if (!data_from_user) {
1868 printk( 1868 printk(
1869 "cx25821 in %s(): User data is INVALID. Returning.\n", 1869 "cx25821 in %s(): User data is INVALID. Returning.\n",
1870 __func__); 1870 __func__);
1871 return 0; 1871 return 0;
1872 } 1872 }
1873 1873
1874 command = data_from_user->command; 1874 command = data_from_user->command;
1875 1875
1876 if (command != SET_VIDEO_STD && command != SET_PIXEL_FORMAT 1876 if (command != SET_VIDEO_STD && command != SET_PIXEL_FORMAT
1877 && command != ENABLE_CIF_RESOLUTION && command != REG_READ 1877 && command != ENABLE_CIF_RESOLUTION && command != REG_READ
1878 && command != REG_WRITE && command != MEDUSA_READ 1878 && command != REG_WRITE && command != MEDUSA_READ
1879 && command != MEDUSA_WRITE) { 1879 && command != MEDUSA_WRITE) {
1880 return 0; 1880 return 0;
1881 } 1881 }
1882 1882
1883 switch (command) { 1883 switch (command) {
1884 case SET_VIDEO_STD: 1884 case SET_VIDEO_STD:
1885 dev->tvnorm = 1885 dev->tvnorm =
1886 !strcmp(data_from_user->vid_stdname, 1886 !strcmp(data_from_user->vid_stdname,
1887 "PAL") ? V4L2_STD_PAL_BG : V4L2_STD_NTSC_M; 1887 "PAL") ? V4L2_STD_PAL_BG : V4L2_STD_NTSC_M;
1888 medusa_set_videostandard(dev); 1888 medusa_set_videostandard(dev);
1889 break; 1889 break;
1890 1890
1891 case SET_PIXEL_FORMAT: 1891 case SET_PIXEL_FORMAT:
1892 selected_channel = data_from_user->decoder_select; 1892 selected_channel = data_from_user->decoder_select;
1893 pix_format = data_from_user->pixel_format; 1893 pix_format = data_from_user->pixel_format;
1894 1894
1895 if (!(selected_channel <= 7 && selected_channel >= 0)) { 1895 if (!(selected_channel <= 7 && selected_channel >= 0)) {
1896 selected_channel -= 4; 1896 selected_channel -= 4;
1897 selected_channel = selected_channel % 8; 1897 selected_channel = selected_channel % 8;
1898 } 1898 }
1899 1899
1900 if (selected_channel >= 0) 1900 if (selected_channel >= 0)
1901 cx25821_set_pixel_format(dev, selected_channel, 1901 cx25821_set_pixel_format(dev, selected_channel,
1902 pix_format); 1902 pix_format);
1903 1903
1904 break; 1904 break;
1905 1905
1906 case ENABLE_CIF_RESOLUTION: 1906 case ENABLE_CIF_RESOLUTION:
1907 selected_channel = data_from_user->decoder_select; 1907 selected_channel = data_from_user->decoder_select;
1908 cif_enable = data_from_user->cif_resolution_enable; 1908 cif_enable = data_from_user->cif_resolution_enable;
1909 cif_width = data_from_user->cif_width; 1909 cif_width = data_from_user->cif_width;
1910 1910
1911 if (cif_enable) { 1911 if (cif_enable) {
1912 if (dev->tvnorm & V4L2_STD_PAL_BG 1912 if (dev->tvnorm & V4L2_STD_PAL_BG
1913 || dev->tvnorm & V4L2_STD_PAL_DK) 1913 || dev->tvnorm & V4L2_STD_PAL_DK)
1914 width = 352; 1914 width = 352;
1915 else 1915 else
1916 width = (cif_width == 320 1916 width = (cif_width == 320
1917 || cif_width == 352) ? cif_width : 320; 1917 || cif_width == 352) ? cif_width : 320;
1918 } 1918 }
1919 1919
1920 if (!(selected_channel <= 7 && selected_channel >= 0)) { 1920 if (!(selected_channel <= 7 && selected_channel >= 0)) {
1921 selected_channel -= 4; 1921 selected_channel -= 4;
1922 selected_channel = selected_channel % 8; 1922 selected_channel = selected_channel % 8;
1923 } 1923 }
1924 1924
1925 if (selected_channel <= 7 && selected_channel >= 0) { 1925 if (selected_channel <= 7 && selected_channel >= 0) {
1926 dev->channels[selected_channel]. 1926 dev->channels[selected_channel].
1927 use_cif_resolution = cif_enable; 1927 use_cif_resolution = cif_enable;
1928 dev->channels[selected_channel].cif_width = width; 1928 dev->channels[selected_channel].cif_width = width;
1929 } else { 1929 } else {
1930 for (i = 0; i < VID_CHANNEL_NUM; i++) { 1930 for (i = 0; i < VID_CHANNEL_NUM; i++) {
1931 dev->channels[i].use_cif_resolution = 1931 dev->channels[i].use_cif_resolution =
1932 cif_enable; 1932 cif_enable;
1933 dev->channels[i].cif_width = width; 1933 dev->channels[i].cif_width = width;
1934 } 1934 }
1935 } 1935 }
1936 1936
1937 medusa_set_resolution(dev, width, selected_channel); 1937 medusa_set_resolution(dev, width, selected_channel);
1938 break; 1938 break;
1939 case REG_READ: 1939 case REG_READ:
1940 data_from_user->reg_data = cx_read(data_from_user->reg_address); 1940 data_from_user->reg_data = cx_read(data_from_user->reg_address);
1941 break; 1941 break;
1942 case REG_WRITE: 1942 case REG_WRITE:
1943 cx_write(data_from_user->reg_address, data_from_user->reg_data); 1943 cx_write(data_from_user->reg_address, data_from_user->reg_data);
1944 break; 1944 break;
1945 case MEDUSA_READ: 1945 case MEDUSA_READ:
1946 value = 1946 value =
1947 cx25821_i2c_read(&dev->i2c_bus[0], 1947 cx25821_i2c_read(&dev->i2c_bus[0],
1948 (u16) data_from_user->reg_address, 1948 (u16) data_from_user->reg_address,
1949 &data_from_user->reg_data); 1949 &data_from_user->reg_data);
1950 break; 1950 break;
1951 case MEDUSA_WRITE: 1951 case MEDUSA_WRITE:
1952 cx25821_i2c_write(&dev->i2c_bus[0], 1952 cx25821_i2c_write(&dev->i2c_bus[0],
1953 (u16) data_from_user->reg_address, 1953 (u16) data_from_user->reg_address,
1954 data_from_user->reg_data); 1954 data_from_user->reg_data);
1955 break; 1955 break;
1956 } 1956 }
1957 1957
1958 return 0; 1958 return 0;
1959} 1959}
1960 1960
1961static long cx25821_video_ioctl(struct file *file, 1961static long cx25821_video_ioctl(struct file *file,
1962 unsigned int cmd, unsigned long arg) 1962 unsigned int cmd, unsigned long arg)
1963{ 1963{
1964 int ret = 0; 1964 int ret = 0;
1965 1965
@@ -1967,15 +1967,15 @@ static long cx25821_video_ioctl(struct file *file,
1967 1967
1968 /* check to see if it's the video upstream */ 1968 /* check to see if it's the video upstream */
1969 if (fh->channel_id == SRAM_CH09) { 1969 if (fh->channel_id == SRAM_CH09) {
1970 ret = video_ioctl_upstream9(file, cmd, arg); 1970 ret = video_ioctl_upstream9(file, cmd, arg);
1971 return ret; 1971 return ret;
1972 } else if (fh->channel_id == SRAM_CH10) { 1972 } else if (fh->channel_id == SRAM_CH10) {
1973 ret = video_ioctl_upstream10(file, cmd, arg); 1973 ret = video_ioctl_upstream10(file, cmd, arg);
1974 return ret; 1974 return ret;
1975 } else if (fh->channel_id == SRAM_CH11) { 1975 } else if (fh->channel_id == SRAM_CH11) {
1976 ret = video_ioctl_upstream11(file, cmd, arg); 1976 ret = video_ioctl_upstream11(file, cmd, arg);
1977 ret = video_ioctl_set(file, cmd, arg); 1977 ret = video_ioctl_set(file, cmd, arg);
1978 return ret; 1978 return ret;
1979 } 1979 }
1980 1980
1981 return video_ioctl2(file, cmd, arg); 1981 return video_ioctl2(file, cmd, arg);
@@ -2036,9 +2036,9 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2036}; 2036};
2037 2037
2038struct video_device cx25821_videoioctl_template = { 2038struct video_device cx25821_videoioctl_template = {
2039 .name = "cx25821-videoioctl", 2039 .name = "cx25821-videoioctl",
2040 .fops = &video_fops, 2040 .fops = &video_fops,
2041 .ioctl_ops = &video_ioctl_ops, 2041 .ioctl_ops = &video_ioctl_ops,
2042 .tvnorms = CX25821_NORMS, 2042 .tvnorms = CX25821_NORMS,
2043 .current_norm = V4L2_STD_NTSC_M, 2043 .current_norm = V4L2_STD_NTSC_M,
2044}; 2044};