aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2008-11-29 17:38:23 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2008-12-30 06:38:44 -0500
commit67ec09fdf5e05d4670b617256c696348b5df080b (patch)
treefdf5f16f9b20280f83ce10e435d557bcb371934f /drivers
parentca085fb900265b525e3f9fb95fb6d7fd27a302ea (diff)
V4L/DVB (9835): ivtv/ivtvfb: convert to v4l2_device/v4l2_subdev.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/ivtv/ivtv-controls.c16
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c214
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.h52
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c44
-rw-r--r--drivers/media/video/ivtv/ivtv-gpio.c324
-rw-r--r--drivers/media/video/ivtv/ivtv-gpio.h3
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c314
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.h13
-rw-r--r--drivers/media/video/ivtv/ivtv-ioctl.c73
-rw-r--r--drivers/media/video/ivtv/ivtv-routing.c12
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c13
-rw-r--r--drivers/media/video/ivtv/ivtv-vbi.c17
-rw-r--r--drivers/media/video/ivtv/ivtvfb.c91
13 files changed, 503 insertions, 683 deletions
diff --git a/drivers/media/video/ivtv/ivtv-controls.c b/drivers/media/video/ivtv/ivtv-controls.c
index 48e103be718..62aa06f5d16 100644
--- a/drivers/media/video/ivtv/ivtv-controls.c
+++ b/drivers/media/video/ivtv/ivtv-controls.c
@@ -63,7 +63,7 @@ int ivtv_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *qctrl)
63 case V4L2_CID_HUE: 63 case V4L2_CID_HUE:
64 case V4L2_CID_SATURATION: 64 case V4L2_CID_SATURATION:
65 case V4L2_CID_CONTRAST: 65 case V4L2_CID_CONTRAST:
66 if (itv->video_dec_func(itv, VIDIOC_QUERYCTRL, qctrl)) 66 if (v4l2_subdev_call(itv->sd_video, core, queryctrl, qctrl))
67 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED; 67 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
68 return 0; 68 return 0;
69 69
@@ -73,7 +73,7 @@ int ivtv_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *qctrl)
73 case V4L2_CID_AUDIO_BASS: 73 case V4L2_CID_AUDIO_BASS:
74 case V4L2_CID_AUDIO_TREBLE: 74 case V4L2_CID_AUDIO_TREBLE:
75 case V4L2_CID_AUDIO_LOUDNESS: 75 case V4L2_CID_AUDIO_LOUDNESS:
76 if (ivtv_i2c_hw(itv, itv->card->hw_audio_ctrl, VIDIOC_QUERYCTRL, qctrl)) 76 if (v4l2_subdev_call(itv->sd_audio, core, queryctrl, qctrl))
77 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED; 77 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
78 return 0; 78 return 0;
79 79
@@ -122,7 +122,7 @@ static int ivtv_s_ctrl(struct ivtv *itv, struct v4l2_control *vctrl)
122 case V4L2_CID_HUE: 122 case V4L2_CID_HUE:
123 case V4L2_CID_SATURATION: 123 case V4L2_CID_SATURATION:
124 case V4L2_CID_CONTRAST: 124 case V4L2_CID_CONTRAST:
125 return itv->video_dec_func(itv, VIDIOC_S_CTRL, vctrl); 125 return v4l2_subdev_call(itv->sd_video, core, s_ctrl, vctrl);
126 126
127 case V4L2_CID_AUDIO_VOLUME: 127 case V4L2_CID_AUDIO_VOLUME:
128 case V4L2_CID_AUDIO_MUTE: 128 case V4L2_CID_AUDIO_MUTE:
@@ -130,7 +130,7 @@ static int ivtv_s_ctrl(struct ivtv *itv, struct v4l2_control *vctrl)
130 case V4L2_CID_AUDIO_BASS: 130 case V4L2_CID_AUDIO_BASS:
131 case V4L2_CID_AUDIO_TREBLE: 131 case V4L2_CID_AUDIO_TREBLE:
132 case V4L2_CID_AUDIO_LOUDNESS: 132 case V4L2_CID_AUDIO_LOUDNESS:
133 return ivtv_i2c_hw(itv, itv->card->hw_audio_ctrl, VIDIOC_S_CTRL, vctrl); 133 return v4l2_subdev_call(itv->sd_audio, core, s_ctrl, vctrl);
134 134
135 default: 135 default:
136 IVTV_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id); 136 IVTV_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id);
@@ -147,7 +147,7 @@ static int ivtv_g_ctrl(struct ivtv *itv, struct v4l2_control *vctrl)
147 case V4L2_CID_HUE: 147 case V4L2_CID_HUE:
148 case V4L2_CID_SATURATION: 148 case V4L2_CID_SATURATION:
149 case V4L2_CID_CONTRAST: 149 case V4L2_CID_CONTRAST:
150 return itv->video_dec_func(itv, VIDIOC_G_CTRL, vctrl); 150 return v4l2_subdev_call(itv->sd_video, core, g_ctrl, vctrl);
151 151
152 case V4L2_CID_AUDIO_VOLUME: 152 case V4L2_CID_AUDIO_VOLUME:
153 case V4L2_CID_AUDIO_MUTE: 153 case V4L2_CID_AUDIO_MUTE:
@@ -155,7 +155,7 @@ static int ivtv_g_ctrl(struct ivtv *itv, struct v4l2_control *vctrl)
155 case V4L2_CID_AUDIO_BASS: 155 case V4L2_CID_AUDIO_BASS:
156 case V4L2_CID_AUDIO_TREBLE: 156 case V4L2_CID_AUDIO_TREBLE:
157 case V4L2_CID_AUDIO_LOUDNESS: 157 case V4L2_CID_AUDIO_LOUDNESS:
158 return ivtv_i2c_hw(itv, itv->card->hw_audio_ctrl, VIDIOC_G_CTRL, vctrl); 158 return v4l2_subdev_call(itv->sd_audio, core, g_ctrl, vctrl);
159 default: 159 default:
160 IVTV_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id); 160 IVTV_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id);
161 return -EINVAL; 161 return -EINVAL;
@@ -268,7 +268,7 @@ int ivtv_s_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c)
268 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 268 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
269 fmt.fmt.pix.width = itv->params.width / (is_mpeg1 ? 2 : 1); 269 fmt.fmt.pix.width = itv->params.width / (is_mpeg1 ? 2 : 1);
270 fmt.fmt.pix.height = itv->params.height; 270 fmt.fmt.pix.height = itv->params.height;
271 itv->video_dec_func(itv, VIDIOC_S_FMT, &fmt); 271 v4l2_subdev_call(itv->sd_video, video, s_fmt, &fmt);
272 } 272 }
273 err = cx2341x_update(itv, ivtv_api_func, &itv->params, &p); 273 err = cx2341x_update(itv, ivtv_api_func, &itv->params, &p);
274 if (!err && itv->params.stream_vbi_fmt != p.stream_vbi_fmt) 274 if (!err && itv->params.stream_vbi_fmt != p.stream_vbi_fmt)
@@ -279,7 +279,7 @@ int ivtv_s_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c)
279 /* The audio clock of the digitizer must match the codec sample 279 /* The audio clock of the digitizer must match the codec sample
280 rate otherwise you get some very strange effects. */ 280 rate otherwise you get some very strange effects. */
281 if (idx < sizeof(freqs)) 281 if (idx < sizeof(freqs))
282 ivtv_call_i2c_clients(itv, VIDIOC_INT_AUDIO_CLOCK_FREQ, &freqs[idx]); 282 ivtv_call_all(itv, audio, s_clock_freq, freqs[idx]);
283 return err; 283 return err;
284 } 284 }
285 return -EINVAL; 285 return -EINVAL;
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index b69cc1d55e5..08b76295175 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -60,9 +60,6 @@
60#include <media/v4l2-chip-ident.h> 60#include <media/v4l2-chip-ident.h>
61#include "tuner-xc2028.h" 61#include "tuner-xc2028.h"
62 62
63/* var to keep track of the number of array elements in use */
64int ivtv_cards_active;
65
66/* If you have already X v4l cards, then set this to X. This way 63/* If you have already X v4l cards, then set this to X. This way
67 the device numbers stay matched. Example: you have a WinTV card 64 the device numbers stay matched. Example: you have a WinTV card
68 without radio and a PVR-350 with. Normally this would give a 65 without radio and a PVR-350 with. Normally this would give a
@@ -70,12 +67,6 @@ int ivtv_cards_active;
70 setting this to 1 you ensure that radio0 is now also radio1. */ 67 setting this to 1 you ensure that radio0 is now also radio1. */
71int ivtv_first_minor; 68int ivtv_first_minor;
72 69
73/* Master variable for all ivtv info */
74struct ivtv *ivtv_cards[IVTV_MAX_CARDS];
75
76/* Protects ivtv_cards_active */
77DEFINE_SPINLOCK(ivtv_cards_lock);
78
79/* add your revision and whatnot here */ 70/* add your revision and whatnot here */
80static struct pci_device_id ivtv_pci_tbl[] __devinitdata = { 71static struct pci_device_id ivtv_pci_tbl[] __devinitdata = {
81 {PCI_VENDOR_ID_ICOMP, PCI_DEVICE_ID_IVTV15, 72 {PCI_VENDOR_ID_ICOMP, PCI_DEVICE_ID_IVTV15,
@@ -87,6 +78,9 @@ static struct pci_device_id ivtv_pci_tbl[] __devinitdata = {
87 78
88MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl); 79MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
89 80
81/* ivtv instance counter */
82static atomic_t ivtv_instance = ATOMIC_INIT(0);
83
90/* Parameter declarations */ 84/* Parameter declarations */
91static int cardtype[IVTV_MAX_CARDS]; 85static int cardtype[IVTV_MAX_CARDS];
92static int tuner[IVTV_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1, 86static int tuner[IVTV_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
@@ -599,9 +593,9 @@ static void ivtv_process_options(struct ivtv *itv)
599 itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_MPG] = dec_mpg_buffers * 1024; 593 itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_MPG] = dec_mpg_buffers * 1024;
600 itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_YUV] = dec_yuv_buffers * 1024; 594 itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_YUV] = dec_yuv_buffers * 1024;
601 itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_VBI] = dec_vbi_buffers; 595 itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_VBI] = dec_vbi_buffers;
602 itv->options.cardtype = cardtype[itv->num]; 596 itv->options.cardtype = cardtype[itv->instance];
603 itv->options.tuner = tuner[itv->num]; 597 itv->options.tuner = tuner[itv->instance];
604 itv->options.radio = radio[itv->num]; 598 itv->options.radio = radio[itv->instance];
605 itv->options.newi2c = newi2c; 599 itv->options.newi2c = newi2c;
606 if (tunertype < -1 || tunertype > 1) { 600 if (tunertype < -1 || tunertype > 1) {
607 IVTV_WARN("Invalid tunertype argument, will autodetect instead\n"); 601 IVTV_WARN("Invalid tunertype argument, will autodetect instead\n");
@@ -688,7 +682,7 @@ static int __devinit ivtv_init_struct1(struct ivtv *itv)
688 spin_lock_init(&itv->lock); 682 spin_lock_init(&itv->lock);
689 spin_lock_init(&itv->dma_reg_lock); 683 spin_lock_init(&itv->dma_reg_lock);
690 684
691 itv->irq_work_queues = create_singlethread_workqueue(itv->name); 685 itv->irq_work_queues = create_singlethread_workqueue(itv->device.name);
692 if (itv->irq_work_queues == NULL) { 686 if (itv->irq_work_queues == NULL) {
693 IVTV_ERR("Could not create ivtv workqueue\n"); 687 IVTV_ERR("Could not create ivtv workqueue\n");
694 return -1; 688 return -1;
@@ -770,12 +764,6 @@ static void __devinit ivtv_init_struct2(struct ivtv *itv)
770 i = 0; 764 i = 0;
771 itv->active_input = i; 765 itv->active_input = i;
772 itv->audio_input = itv->card->video_inputs[i].audio_index; 766 itv->audio_input = itv->card->video_inputs[i].audio_index;
773 if (itv->card->hw_all & IVTV_HW_CX25840)
774 itv->video_dec_func = ivtv_cx25840;
775 else if (itv->card->hw_all & IVTV_HW_SAA717X)
776 itv->video_dec_func = ivtv_saa717x;
777 else
778 itv->video_dec_func = ivtv_saa7115;
779} 767}
780 768
781static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *dev, 769static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *dev,
@@ -788,21 +776,21 @@ static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *dev,
788 IVTV_DEBUG_INFO("Enabling pci device\n"); 776 IVTV_DEBUG_INFO("Enabling pci device\n");
789 777
790 if (pci_enable_device(dev)) { 778 if (pci_enable_device(dev)) {
791 IVTV_ERR("Can't enable device %d!\n", itv->num); 779 IVTV_ERR("Can't enable device!\n");
792 return -EIO; 780 return -EIO;
793 } 781 }
794 if (pci_set_dma_mask(dev, 0xffffffff)) { 782 if (pci_set_dma_mask(dev, 0xffffffff)) {
795 IVTV_ERR("No suitable DMA available on card %d.\n", itv->num); 783 IVTV_ERR("No suitable DMA available.\n");
796 return -EIO; 784 return -EIO;
797 } 785 }
798 if (!request_mem_region(itv->base_addr, IVTV_ENCODER_SIZE, "ivtv encoder")) { 786 if (!request_mem_region(itv->base_addr, IVTV_ENCODER_SIZE, "ivtv encoder")) {
799 IVTV_ERR("Cannot request encoder memory region on card %d.\n", itv->num); 787 IVTV_ERR("Cannot request encoder memory region.\n");
800 return -EIO; 788 return -EIO;
801 } 789 }
802 790
803 if (!request_mem_region(itv->base_addr + IVTV_REG_OFFSET, 791 if (!request_mem_region(itv->base_addr + IVTV_REG_OFFSET,
804 IVTV_REG_SIZE, "ivtv registers")) { 792 IVTV_REG_SIZE, "ivtv registers")) {
805 IVTV_ERR("Cannot request register memory region on card %d.\n", itv->num); 793 IVTV_ERR("Cannot request register memory region.\n");
806 release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE); 794 release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE);
807 return -EIO; 795 return -EIO;
808 } 796 }
@@ -810,7 +798,7 @@ static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *dev,
810 if (itv->has_cx23415 && 798 if (itv->has_cx23415 &&
811 !request_mem_region(itv->base_addr + IVTV_DECODER_OFFSET, 799 !request_mem_region(itv->base_addr + IVTV_DECODER_OFFSET,
812 IVTV_DECODER_SIZE, "ivtv decoder")) { 800 IVTV_DECODER_SIZE, "ivtv decoder")) {
813 IVTV_ERR("Cannot request decoder memory region on card %d.\n", itv->num); 801 IVTV_ERR("Cannot request decoder memory region.\n");
814 release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE); 802 release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE);
815 release_mem_region(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE); 803 release_mem_region(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE);
816 return -EIO; 804 return -EIO;
@@ -853,69 +841,11 @@ static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *dev,
853 return 0; 841 return 0;
854} 842}
855 843
856#ifdef MODULE
857static u32 ivtv_request_module(struct ivtv *itv, u32 hw,
858 const char *name, u32 id)
859{
860 if ((hw & id) == 0)
861 return hw;
862 if (request_module(name) != 0) {
863 IVTV_ERR("Failed to load module %s\n", name);
864 return hw & ~id;
865 }
866 IVTV_DEBUG_INFO("Loaded module %s\n", name);
867 return hw;
868}
869#endif
870
871static void ivtv_load_and_init_modules(struct ivtv *itv) 844static void ivtv_load_and_init_modules(struct ivtv *itv)
872{ 845{
873 u32 hw = itv->card->hw_all; 846 u32 hw = itv->card->hw_all;
874 unsigned i; 847 unsigned i;
875 848
876#ifdef MODULE
877 /* load modules */
878#ifdef CONFIG_MEDIA_TUNER_MODULE
879 hw = ivtv_request_module(itv, hw, "tuner", IVTV_HW_TUNER);
880#endif
881#ifdef CONFIG_VIDEO_CX25840_MODULE
882 hw = ivtv_request_module(itv, hw, "cx25840", IVTV_HW_CX25840);
883#endif
884#ifdef CONFIG_VIDEO_SAA711X_MODULE
885 hw = ivtv_request_module(itv, hw, "saa7115", IVTV_HW_SAA711X);
886#endif
887#ifdef CONFIG_VIDEO_SAA7127_MODULE
888 hw = ivtv_request_module(itv, hw, "saa7127", IVTV_HW_SAA7127);
889#endif
890#ifdef CONFIG_VIDEO_SAA717X_MODULE
891 hw = ivtv_request_module(itv, hw, "saa717x", IVTV_HW_SAA717X);
892#endif
893#ifdef CONFIG_VIDEO_UPD64031A_MODULE
894 hw = ivtv_request_module(itv, hw, "upd64031a", IVTV_HW_UPD64031A);
895#endif
896#ifdef CONFIG_VIDEO_UPD64083_MODULE
897 hw = ivtv_request_module(itv, hw, "upd64083", IVTV_HW_UPD6408X);
898#endif
899#ifdef CONFIG_VIDEO_MSP3400_MODULE
900 hw = ivtv_request_module(itv, hw, "msp3400", IVTV_HW_MSP34XX);
901#endif
902#ifdef CONFIG_VIDEO_VP27SMPX_MODULE
903 hw = ivtv_request_module(itv, hw, "vp27smpx", IVTV_HW_VP27SMPX);
904#endif
905#ifdef CONFIG_VIDEO_WM8775_MODULE
906 hw = ivtv_request_module(itv, hw, "wm8775", IVTV_HW_WM8775);
907#endif
908#ifdef CONFIG_VIDEO_WM8739_MODULE
909 hw = ivtv_request_module(itv, hw, "wm8739", IVTV_HW_WM8739);
910#endif
911#ifdef CONFIG_VIDEO_CS53L32A_MODULE
912 hw = ivtv_request_module(itv, hw, "cs53l32a", IVTV_HW_CS53L32A);
913#endif
914#ifdef CONFIG_VIDEO_M52790_MODULE
915 hw = ivtv_request_module(itv, hw, "m52790", IVTV_HW_M52790);
916#endif
917#endif
918
919 /* check which i2c devices are actually found */ 849 /* check which i2c devices are actually found */
920 for (i = 0; i < 32; i++) { 850 for (i = 0; i < 32; i++) {
921 u32 device = 1 << i; 851 u32 device = 1 << i;
@@ -927,11 +857,21 @@ static void ivtv_load_and_init_modules(struct ivtv *itv)
927 itv->hw_flags |= device; 857 itv->hw_flags |= device;
928 continue; 858 continue;
929 } 859 }
930 ivtv_i2c_register(itv, i); 860 if (ivtv_i2c_register(itv, i) == 0)
931 if (ivtv_i2c_hw_addr(itv, device) > 0)
932 itv->hw_flags |= device; 861 itv->hw_flags |= device;
933 } 862 }
934 863
864 if (itv->card->hw_all & IVTV_HW_CX25840)
865 itv->sd_video = ivtv_find_hw(itv, IVTV_HW_CX25840);
866 else if (itv->card->hw_all & IVTV_HW_SAA717X)
867 itv->sd_video = ivtv_find_hw(itv, IVTV_HW_SAA717X);
868 else if (itv->card->hw_all & IVTV_HW_SAA7114)
869 itv->sd_video = ivtv_find_hw(itv, IVTV_HW_SAA7114);
870 else
871 itv->sd_video = ivtv_find_hw(itv, IVTV_HW_SAA7115);
872 itv->sd_audio = ivtv_find_hw(itv, itv->card->hw_audio_ctrl);
873 itv->sd_muxer = ivtv_find_hw(itv, itv->card->hw_muxer);
874
935 hw = itv->hw_flags; 875 hw = itv->hw_flags;
936 876
937 if (itv->card->type == IVTV_CARD_CX23416GYC) { 877 if (itv->card->type == IVTV_CARD_CX23416GYC) {
@@ -949,7 +889,7 @@ static void ivtv_load_and_init_modules(struct ivtv *itv)
949 /* The crystal frequency of GVMVPRX is 24.576MHz */ 889 /* The crystal frequency of GVMVPRX is 24.576MHz */
950 crystal_freq.freq = SAA7115_FREQ_24_576_MHZ; 890 crystal_freq.freq = SAA7115_FREQ_24_576_MHZ;
951 crystal_freq.flags = SAA7115_FREQ_FL_UCGC; 891 crystal_freq.flags = SAA7115_FREQ_FL_UCGC;
952 itv->video_dec_func(itv, VIDIOC_INT_S_CRYSTAL_FREQ, &crystal_freq); 892 v4l2_subdev_call(itv->sd_video, video, s_crystal_freq, &crystal_freq);
953 } 893 }
954 894
955 if (hw & IVTV_HW_CX25840) { 895 if (hw & IVTV_HW_CX25840) {
@@ -967,7 +907,7 @@ static void ivtv_load_and_init_modules(struct ivtv *itv)
967 /* determine the exact saa711x model */ 907 /* determine the exact saa711x model */
968 itv->hw_flags &= ~IVTV_HW_SAA711X; 908 itv->hw_flags &= ~IVTV_HW_SAA711X;
969 909
970 ivtv_saa7115(itv, VIDIOC_G_CHIP_IDENT, &v); 910 ivtv_call_hw(itv, IVTV_HW_SAA711X, core, g_chip_ident, &v);
971 if (v.ident == V4L2_IDENT_SAA7114) { 911 if (v.ident == V4L2_IDENT_SAA7114) {
972 itv->hw_flags |= IVTV_HW_SAA7114; 912 itv->hw_flags |= IVTV_HW_SAA7114;
973 /* VBI is not yet supported by the saa7114 driver. */ 913 /* VBI is not yet supported by the saa7114 driver. */
@@ -1001,28 +941,20 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1001 int vbi_buf_size; 941 int vbi_buf_size;
1002 struct ivtv *itv; 942 struct ivtv *itv;
1003 943
1004 spin_lock(&ivtv_cards_lock);
1005
1006 /* Make sure we've got a place for this card */
1007 if (ivtv_cards_active == IVTV_MAX_CARDS) {
1008 printk(KERN_ERR "ivtv: Maximum number of cards detected (%d)\n",
1009 ivtv_cards_active);
1010 spin_unlock(&ivtv_cards_lock);
1011 return -ENOMEM;
1012 }
1013
1014 itv = kzalloc(sizeof(struct ivtv), GFP_ATOMIC); 944 itv = kzalloc(sizeof(struct ivtv), GFP_ATOMIC);
1015 if (itv == NULL) { 945 if (itv == NULL)
1016 spin_unlock(&ivtv_cards_lock);
1017 return -ENOMEM; 946 return -ENOMEM;
1018 }
1019 ivtv_cards[ivtv_cards_active] = itv;
1020 itv->dev = dev; 947 itv->dev = dev;
1021 itv->num = ivtv_cards_active++; 948 itv->instance = atomic_inc_return(&ivtv_instance) - 1;
1022 snprintf(itv->name, sizeof(itv->name), "ivtv%d", itv->num);
1023 IVTV_INFO("Initializing card #%d\n", itv->num);
1024 949
1025 spin_unlock(&ivtv_cards_lock); 950 retval = v4l2_device_register(&dev->dev, &itv->device);
951 if (retval)
952 return retval;
953 /* "ivtv + PCI ID" is a bit of a mouthful, so use
954 "ivtv + instance" instead. */
955 snprintf(itv->device.name, sizeof(itv->device.name),
956 "ivtv%d", itv->instance);
957 IVTV_INFO("Initializing card %d\n", itv->instance);
1026 958
1027 ivtv_process_options(itv); 959 ivtv_process_options(itv);
1028 if (itv->options.cardtype == -1) { 960 if (itv->options.cardtype == -1) {
@@ -1043,8 +975,6 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1043 else if (retval == -ENXIO) 975 else if (retval == -ENXIO)
1044 goto free_mem; 976 goto free_mem;
1045 } 977 }
1046 /* save itv in the pci struct for later use */
1047 pci_set_drvdata(dev, itv);
1048 978
1049 /* map io memory */ 979 /* map io memory */
1050 IVTV_DEBUG_INFO("attempting ioremap at 0x%08x len 0x%08x\n", 980 IVTV_DEBUG_INFO("attempting ioremap at 0x%08x len 0x%08x\n",
@@ -1086,7 +1016,9 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1086 goto free_io; 1016 goto free_io;
1087 } 1017 }
1088 1018
1089 ivtv_gpio_init(itv); 1019 retval = ivtv_gpio_init(itv);
1020 if (retval)
1021 goto free_io;
1090 1022
1091 /* active i2c */ 1023 /* active i2c */
1092 IVTV_DEBUG_INFO("activating i2c...\n"); 1024 IVTV_DEBUG_INFO("activating i2c...\n");
@@ -1095,8 +1027,6 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1095 goto free_io; 1027 goto free_io;
1096 } 1028 }
1097 1029
1098 IVTV_DEBUG_INFO("Active card count: %d.\n", ivtv_cards_active);
1099
1100 if (itv->card->hw_all & IVTV_HW_TVEEPROM) { 1030 if (itv->card->hw_all & IVTV_HW_TVEEPROM) {
1101 /* Based on the model number the cardtype may be changed. 1031 /* Based on the model number the cardtype may be changed.
1102 The PCI IDs are not always reliable. */ 1032 The PCI IDs are not always reliable. */
@@ -1191,7 +1121,7 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1191 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */ 1121 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */
1192 setup.tuner_callback = (setup.type == TUNER_XC2028) ? 1122 setup.tuner_callback = (setup.type == TUNER_XC2028) ?
1193 ivtv_reset_tuner_gpio : NULL; 1123 ivtv_reset_tuner_gpio : NULL;
1194 ivtv_call_i2c_clients(itv, TUNER_SET_TYPE_ADDR, &setup); 1124 ivtv_call_all(itv, tuner, s_type_addr, &setup);
1195 if (setup.type == TUNER_XC2028) { 1125 if (setup.type == TUNER_XC2028) {
1196 static struct xc2028_ctrl ctrl = { 1126 static struct xc2028_ctrl ctrl = {
1197 .fname = XC2028_DEFAULT_FIRMWARE, 1127 .fname = XC2028_DEFAULT_FIRMWARE,
@@ -1201,7 +1131,7 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1201 .tuner = itv->options.tuner, 1131 .tuner = itv->options.tuner,
1202 .priv = &ctrl, 1132 .priv = &ctrl,
1203 }; 1133 };
1204 ivtv_call_i2c_clients(itv, TUNER_SET_CONFIG, &cfg); 1134 ivtv_call_all(itv, tuner, s_config, &cfg);
1205 } 1135 }
1206 } 1136 }
1207 1137
@@ -1210,11 +1140,11 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1210 itv->tuner_std = itv->std; 1140 itv->tuner_std = itv->std;
1211 1141
1212 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) { 1142 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
1213 ivtv_call_i2c_clients(itv, VIDIOC_INT_S_STD_OUTPUT, &itv->std); 1143 ivtv_call_all(itv, video, s_std_output, itv->std);
1214 /* Turn off the output signal. The mpeg decoder is not yet 1144 /* Turn off the output signal. The mpeg decoder is not yet
1215 active so without this you would get a green image until the 1145 active so without this you would get a green image until the
1216 mpeg decoder becomes active. */ 1146 mpeg decoder becomes active. */
1217 ivtv_saa7127(itv, VIDIOC_STREAMOFF, NULL); 1147 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 0);
1218 } 1148 }
1219 1149
1220 /* clear interrupt mask, effectively disabling interrupts */ 1150 /* clear interrupt mask, effectively disabling interrupts */
@@ -1222,7 +1152,7 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1222 1152
1223 /* Register IRQ */ 1153 /* Register IRQ */
1224 retval = request_irq(itv->dev->irq, ivtv_irq_handler, 1154 retval = request_irq(itv->dev->irq, ivtv_irq_handler,
1225 IRQF_SHARED | IRQF_DISABLED, itv->name, (void *)itv); 1155 IRQF_SHARED | IRQF_DISABLED, itv->device.name, (void *)itv);
1226 if (retval) { 1156 if (retval) {
1227 IVTV_ERR("Failed to register irq %d\n", retval); 1157 IVTV_ERR("Failed to register irq %d\n", retval);
1228 goto free_i2c; 1158 goto free_i2c;
@@ -1238,7 +1168,7 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1238 IVTV_ERR("Error %d registering devices\n", retval); 1168 IVTV_ERR("Error %d registering devices\n", retval);
1239 goto free_streams; 1169 goto free_streams;
1240 } 1170 }
1241 IVTV_INFO("Initialized card #%d: %s\n", itv->num, itv->card_name); 1171 IVTV_INFO("Initialized card: %s\n", itv->card_name);
1242 return 0; 1172 return 0;
1243 1173
1244free_streams: 1174free_streams:
@@ -1261,10 +1191,8 @@ err:
1261 retval = -ENODEV; 1191 retval = -ENODEV;
1262 IVTV_ERR("Error %d on initialization\n", retval); 1192 IVTV_ERR("Error %d on initialization\n", retval);
1263 1193
1264 spin_lock(&ivtv_cards_lock); 1194 v4l2_device_unregister(&itv->device);
1265 kfree(ivtv_cards[ivtv_cards_active]); 1195 kfree(itv);
1266 ivtv_cards[ivtv_cards_active] = NULL;
1267 spin_unlock(&ivtv_cards_lock);
1268 return retval; 1196 return retval;
1269} 1197}
1270 1198
@@ -1304,10 +1232,11 @@ int ivtv_init_on_first_open(struct ivtv *itv)
1304 if (itv->card->hw_all & IVTV_HW_CX25840) { 1232 if (itv->card->hw_all & IVTV_HW_CX25840) {
1305 struct v4l2_control ctrl; 1233 struct v4l2_control ctrl;
1306 1234
1235 v4l2_subdev_call(itv->sd_video, core, init, 0);
1307 /* CX25840_CID_ENABLE_PVR150_WORKAROUND */ 1236 /* CX25840_CID_ENABLE_PVR150_WORKAROUND */
1308 ctrl.id = V4L2_CID_PRIVATE_BASE; 1237 ctrl.id = V4L2_CID_PRIVATE_BASE;
1309 ctrl.value = itv->pvr150_workaround; 1238 ctrl.value = itv->pvr150_workaround;
1310 itv->video_dec_func(itv, VIDIOC_S_CTRL, &ctrl); 1239 v4l2_subdev_call(itv->sd_video, core, s_ctrl, &ctrl);
1311 } 1240 }
1312 1241
1313 vf.tuner = 0; 1242 vf.tuner = 0;
@@ -1337,7 +1266,7 @@ int ivtv_init_on_first_open(struct ivtv *itv)
1337 /* Turn on the TV-out: ivtv_init_mpeg_decoder() initializes 1266 /* Turn on the TV-out: ivtv_init_mpeg_decoder() initializes
1338 the mpeg decoder so now the saa7127 receives a proper 1267 the mpeg decoder so now the saa7127 receives a proper
1339 signal. */ 1268 signal. */
1340 ivtv_saa7127(itv, VIDIOC_STREAMON, NULL); 1269 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 1);
1341 ivtv_init_mpeg_decoder(itv); 1270 ivtv_init_mpeg_decoder(itv);
1342 } 1271 }
1343 ivtv_s_std(NULL, &fh, &itv->tuner_std); 1272 ivtv_s_std(NULL, &fh, &itv->tuner_std);
@@ -1362,9 +1291,11 @@ int ivtv_init_on_first_open(struct ivtv *itv)
1362 1291
1363static void ivtv_remove(struct pci_dev *pci_dev) 1292static void ivtv_remove(struct pci_dev *pci_dev)
1364{ 1293{
1365 struct ivtv *itv = pci_get_drvdata(pci_dev); 1294 struct v4l2_device *dev = dev_get_drvdata(&pci_dev->dev);
1295 struct ivtv *itv = to_ivtv(dev);
1296 int i;
1366 1297
1367 IVTV_DEBUG_INFO("Removing Card #%d\n", itv->num); 1298 IVTV_DEBUG_INFO("Removing card\n");
1368 1299
1369 if (test_bit(IVTV_F_I_INITED, &itv->i_flags)) { 1300 if (test_bit(IVTV_F_I_INITED, &itv->i_flags)) {
1370 /* Stop all captures */ 1301 /* Stop all captures */
@@ -1377,7 +1308,7 @@ static void ivtv_remove(struct pci_dev *pci_dev)
1377 1308
1378 /* Turn off the TV-out */ 1309 /* Turn off the TV-out */
1379 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) 1310 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)
1380 ivtv_saa7127(itv, VIDIOC_STREAMOFF, NULL); 1311 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 0);
1381 if (atomic_read(&itv->decoding) > 0) { 1312 if (atomic_read(&itv->decoding) > 0) {
1382 int type; 1313 int type;
1383 1314
@@ -1402,6 +1333,8 @@ static void ivtv_remove(struct pci_dev *pci_dev)
1402 ivtv_streams_cleanup(itv, 1); 1333 ivtv_streams_cleanup(itv, 1);
1403 ivtv_udma_free(itv); 1334 ivtv_udma_free(itv);
1404 1335
1336 v4l2_device_unregister(&itv->device);
1337
1405 exit_ivtv_i2c(itv); 1338 exit_ivtv_i2c(itv);
1406 1339
1407 free_irq(itv->dev->irq, (void *)itv); 1340 free_irq(itv->dev->irq, (void *)itv);
@@ -1413,8 +1346,11 @@ static void ivtv_remove(struct pci_dev *pci_dev)
1413 release_mem_region(itv->base_addr + IVTV_DECODER_OFFSET, IVTV_DECODER_SIZE); 1346 release_mem_region(itv->base_addr + IVTV_DECODER_OFFSET, IVTV_DECODER_SIZE);
1414 1347
1415 pci_disable_device(itv->dev); 1348 pci_disable_device(itv->dev);
1349 for (i = 0; i < IVTV_VBI_FRAMES; i++)
1350 kfree(itv->vbi.sliced_mpeg_data[i]);
1416 1351
1417 IVTV_INFO("Removed %s, card #%d\n", itv->card_name, itv->num); 1352 printk(KERN_INFO "ivtv: Removed %s\n", itv->card_name);
1353 kfree(itv);
1418} 1354}
1419 1355
1420/* define a pci_driver for card detection */ 1356/* define a pci_driver for card detection */
@@ -1427,54 +1363,36 @@ static struct pci_driver ivtv_pci_driver = {
1427 1363
1428static int module_start(void) 1364static int module_start(void)
1429{ 1365{
1430 printk(KERN_INFO "ivtv: Start initialization, version %s\n", IVTV_VERSION); 1366 printk(KERN_INFO "ivtv: Start initialization, version %s\n", IVTV_VERSION);
1431
1432 memset(ivtv_cards, 0, sizeof(ivtv_cards));
1433 1367
1434 /* Validate parameters */ 1368 /* Validate parameters */
1435 if (ivtv_first_minor < 0 || ivtv_first_minor >= IVTV_MAX_CARDS) { 1369 if (ivtv_first_minor < 0 || ivtv_first_minor >= IVTV_MAX_CARDS) {
1436 printk(KERN_ERR "ivtv: Exiting, ivtv_first_minor must be between 0 and %d\n", 1370 printk(KERN_ERR "ivtv: Exiting, ivtv_first_minor must be between 0 and %d\n",
1437 IVTV_MAX_CARDS - 1); 1371 IVTV_MAX_CARDS - 1);
1438 return -1; 1372 return -1;
1439 } 1373 }
1440 1374
1441 if (ivtv_debug < 0 || ivtv_debug > 2047) { 1375 if (ivtv_debug < 0 || ivtv_debug > 2047) {
1442 ivtv_debug = 0; 1376 ivtv_debug = 0;
1443 printk(KERN_INFO "ivtv: Debug value must be >= 0 and <= 2047\n"); 1377 printk(KERN_INFO "ivtv: Debug value must be >= 0 and <= 2047\n");
1444 } 1378 }
1445 1379
1446 if (pci_register_driver(&ivtv_pci_driver)) { 1380 if (pci_register_driver(&ivtv_pci_driver)) {
1447 printk(KERN_ERR "ivtv: Error detecting PCI card\n"); 1381 printk(KERN_ERR "ivtv: Error detecting PCI card\n");
1448 return -ENODEV; 1382 return -ENODEV;
1449 } 1383 }
1450 printk(KERN_INFO "ivtv: End initialization\n"); 1384 printk(KERN_INFO "ivtv: End initialization\n");
1451 return 0; 1385 return 0;
1452} 1386}
1453 1387
1454static void module_cleanup(void) 1388static void module_cleanup(void)
1455{ 1389{
1456 int i, j;
1457
1458 pci_unregister_driver(&ivtv_pci_driver); 1390 pci_unregister_driver(&ivtv_pci_driver);
1459
1460 spin_lock(&ivtv_cards_lock);
1461 for (i = 0; i < ivtv_cards_active; i++) {
1462 if (ivtv_cards[i] == NULL)
1463 continue;
1464 for (j = 0; j < IVTV_VBI_FRAMES; j++) {
1465 kfree(ivtv_cards[i]->vbi.sliced_mpeg_data[j]);
1466 }
1467 kfree(ivtv_cards[i]);
1468 }
1469 spin_unlock(&ivtv_cards_lock);
1470} 1391}
1471 1392
1472/* Note: These symbols are exported because they are used by the ivtvfb 1393/* Note: These symbols are exported because they are used by the ivtvfb
1473 framebuffer module and an infrared module for the IR-blaster. */ 1394 framebuffer module and an infrared module for the IR-blaster. */
1474EXPORT_SYMBOL(ivtv_set_irq_mask); 1395EXPORT_SYMBOL(ivtv_set_irq_mask);
1475EXPORT_SYMBOL(ivtv_cards_active);
1476EXPORT_SYMBOL(ivtv_cards);
1477EXPORT_SYMBOL(ivtv_cards_lock);
1478EXPORT_SYMBOL(ivtv_api); 1396EXPORT_SYMBOL(ivtv_api);
1479EXPORT_SYMBOL(ivtv_vapi); 1397EXPORT_SYMBOL(ivtv_vapi);
1480EXPORT_SYMBOL(ivtv_vapi_result); 1398EXPORT_SYMBOL(ivtv_vapi_result);
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index 3733b2afec5..ce8d9b74357 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -61,6 +61,7 @@
61#include <linux/dvb/audio.h> 61#include <linux/dvb/audio.h>
62#include <media/v4l2-common.h> 62#include <media/v4l2-common.h>
63#include <media/v4l2-ioctl.h> 63#include <media/v4l2-ioctl.h>
64#include <media/v4l2-device.h>
64#include <media/tuner.h> 65#include <media/tuner.h>
65#include <media/cx2341x.h> 66#include <media/cx2341x.h>
66 67
@@ -113,9 +114,6 @@
113#define IVTV_REG_VPU (0x9058) 114#define IVTV_REG_VPU (0x9058)
114#define IVTV_REG_APU (0xA064) 115#define IVTV_REG_APU (0xA064)
115 116
116/* i2c stuff */
117#define I2C_CLIENTS_MAX 16
118
119/* debugging */ 117/* debugging */
120extern int ivtv_debug; 118extern int ivtv_debug;
121 119
@@ -132,12 +130,10 @@ extern int ivtv_debug;
132/* Flag to turn on high volume debugging */ 130/* Flag to turn on high volume debugging */
133#define IVTV_DBGFLG_HIGHVOL (1 << 10) 131#define IVTV_DBGFLG_HIGHVOL (1 << 10)
134 132
135/* NOTE: extra space before comma in 'itv->num , ## args' is required for
136 gcc-2.95, otherwise it won't compile. */
137#define IVTV_DEBUG(x, type, fmt, args...) \ 133#define IVTV_DEBUG(x, type, fmt, args...) \
138 do { \ 134 do { \
139 if ((x) & ivtv_debug) \ 135 if ((x) & ivtv_debug) \
140 printk(KERN_INFO "ivtv%d " type ": " fmt, itv->num , ## args); \ 136 v4l2_info(&itv->device, " " type ": " fmt , ##args); \
141 } while (0) 137 } while (0)
142#define IVTV_DEBUG_WARN(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_WARN, "warn", fmt , ## args) 138#define IVTV_DEBUG_WARN(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_WARN, "warn", fmt , ## args)
143#define IVTV_DEBUG_INFO(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_INFO, "info", fmt , ## args) 139#define IVTV_DEBUG_INFO(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_INFO, "info", fmt , ## args)
@@ -152,8 +148,8 @@ extern int ivtv_debug;
152 148
153#define IVTV_DEBUG_HIGH_VOL(x, type, fmt, args...) \ 149#define IVTV_DEBUG_HIGH_VOL(x, type, fmt, args...) \
154 do { \ 150 do { \
155 if (((x) & ivtv_debug) && (ivtv_debug & IVTV_DBGFLG_HIGHVOL)) \ 151 if (((x) & ivtv_debug) && (ivtv_debug & IVTV_DBGFLG_HIGHVOL)) \
156 printk(KERN_INFO "ivtv%d " type ": " fmt, itv->num , ## args); \ 152 v4l2_info(&itv->device, " " type ": " fmt , ##args); \
157 } while (0) 153 } while (0)
158#define IVTV_DEBUG_HI_WARN(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_WARN, "warn", fmt , ## args) 154#define IVTV_DEBUG_HI_WARN(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_WARN, "warn", fmt , ## args)
159#define IVTV_DEBUG_HI_INFO(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_INFO, "info", fmt , ## args) 155#define IVTV_DEBUG_HI_INFO(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_INFO, "info", fmt , ## args)
@@ -167,9 +163,9 @@ extern int ivtv_debug;
167#define IVTV_DEBUG_HI_YUV(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_YUV, "yuv", fmt , ## args) 163#define IVTV_DEBUG_HI_YUV(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_YUV, "yuv", fmt , ## args)
168 164
169/* Standard kernel messages */ 165/* Standard kernel messages */
170#define IVTV_ERR(fmt, args...) printk(KERN_ERR "ivtv%d: " fmt, itv->num , ## args) 166#define IVTV_ERR(fmt, args...) v4l2_err(&itv->device, fmt , ## args)
171#define IVTV_WARN(fmt, args...) printk(KERN_WARNING "ivtv%d: " fmt, itv->num , ## args) 167#define IVTV_WARN(fmt, args...) v4l2_warn(&itv->device, fmt , ## args)
172#define IVTV_INFO(fmt, args...) printk(KERN_INFO "ivtv%d: " fmt, itv->num , ## args) 168#define IVTV_INFO(fmt, args...) v4l2_info(&itv->device, fmt , ## args)
173 169
174/* output modes (cx23415 only) */ 170/* output modes (cx23415 only) */
175#define OUT_NONE 0 171#define OUT_NONE 0
@@ -596,8 +592,6 @@ struct ivtv_card;
596/* Struct to hold info about ivtv cards */ 592/* Struct to hold info about ivtv cards */
597struct ivtv { 593struct ivtv {
598 /* General fixed card data */ 594 /* General fixed card data */
599 int num; /* board number, -1 during init! */
600 char name[8]; /* board name for printk and interrupts (e.g. 'ivtv0') */
601 struct pci_dev *dev; /* PCI device */ 595 struct pci_dev *dev; /* PCI device */
602 const struct ivtv_card *card; /* card information */ 596 const struct ivtv_card *card; /* card information */
603 const char *card_name; /* full name of the card */ 597 const char *card_name; /* full name of the card */
@@ -609,14 +603,18 @@ struct ivtv {
609 u32 v4l2_cap; /* V4L2 capabilities of card */ 603 u32 v4l2_cap; /* V4L2 capabilities of card */
610 u32 hw_flags; /* hardware description of the board */ 604 u32 hw_flags; /* hardware description of the board */
611 v4l2_std_id tuner_std; /* the norm of the card's tuner (fixed) */ 605 v4l2_std_id tuner_std; /* the norm of the card's tuner (fixed) */
612 /* controlling video decoder function */ 606 struct v4l2_subdev *sd_video; /* controlling video decoder subdev */
613 int (*video_dec_func)(struct ivtv *, unsigned int, void *); 607 struct v4l2_subdev *sd_audio; /* controlling audio subdev */
608 struct v4l2_subdev *sd_muxer; /* controlling audio muxer subdev */
614 u32 base_addr; /* PCI resource base address */ 609 u32 base_addr; /* PCI resource base address */
615 volatile void __iomem *enc_mem; /* pointer to mapped encoder memory */ 610 volatile void __iomem *enc_mem; /* pointer to mapped encoder memory */
616 volatile void __iomem *dec_mem; /* pointer to mapped decoder memory */ 611 volatile void __iomem *dec_mem; /* pointer to mapped decoder memory */
617 volatile void __iomem *reg_mem; /* pointer to mapped registers */ 612 volatile void __iomem *reg_mem; /* pointer to mapped registers */
618 struct ivtv_options options; /* user options */ 613 struct ivtv_options options; /* user options */
619 614
615 struct v4l2_device device;
616 struct v4l2_subdev sd_gpio; /* GPIO sub-device */
617 u16 instance;
620 618
621 /* High-level state info */ 619 /* High-level state info */
622 unsigned long i_flags; /* global ivtv flags */ 620 unsigned long i_flags; /* global ivtv flags */
@@ -676,7 +674,6 @@ struct ivtv {
676 struct i2c_adapter i2c_adap; 674 struct i2c_adapter i2c_adap;
677 struct i2c_algo_bit_data i2c_algo; 675 struct i2c_algo_bit_data i2c_algo;
678 struct i2c_client i2c_client; 676 struct i2c_client i2c_client;
679 struct i2c_client *i2c_clients[I2C_CLIENTS_MAX];/* pointers to all I2C clients */
680 int i2c_state; /* i2c bit state */ 677 int i2c_state; /* i2c bit state */
681 struct mutex i2c_bus_lock; /* lock i2c bus */ 678 struct mutex i2c_bus_lock; /* lock i2c bus */
682 679
@@ -722,11 +719,13 @@ struct ivtv {
722 struct osd_info *osd_info; /* ivtvfb private OSD info */ 719 struct osd_info *osd_info; /* ivtvfb private OSD info */
723}; 720};
724 721
722static inline struct ivtv *to_ivtv(struct v4l2_device *dev)
723{
724 return container_of(dev, struct ivtv, device);
725}
726
725/* Globals */ 727/* Globals */
726extern struct ivtv *ivtv_cards[];
727extern int ivtv_cards_active;
728extern int ivtv_first_minor; 728extern int ivtv_first_minor;
729extern spinlock_t ivtv_cards_lock;
730 729
731/*==============Prototypes==================*/ 730/*==============Prototypes==================*/
732 731
@@ -786,4 +785,19 @@ static inline int ivtv_raw_vbi(const struct ivtv *itv)
786#define write_dec_sync(val, addr) \ 785#define write_dec_sync(val, addr) \
787 do { write_dec(val, addr); read_dec(addr); } while (0) 786 do { write_dec(val, addr); read_dec(addr); } while (0)
788 787
788/* Call the specified callback for all subdevs matching hw (if 0, then
789 match them all). Ignore any errors. */
790#define ivtv_call_hw(itv, hw, o, f, args...) \
791 __v4l2_device_call_subdevs(&(itv)->device, !(hw) || (sd->grp_id & (hw)), o, f , ##args)
792
793#define ivtv_call_all(itv, o, f, args...) ivtv_call_hw(itv, 0, o, f , ##args)
794
795/* Call the specified callback for all subdevs matching hw (if 0, then
796 match them all). If the callback returns an error other than 0 or
797 -ENOIOCTLCMD, then return with that error code. */
798#define ivtv_call_hw_err(itv, hw, o, f, args...) \
799 __v4l2_device_call_subdevs_until_err(&(itv)->device, !(hw) || (sd->grp_id & (hw)), o, f , ##args)
800
801#define ivtv_call_all_err(itv, o, f, args...) ivtv_call_hw_err(itv, 0, o, f , ##args)
802
789#endif 803#endif
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index 1c404e454a3..5eb587592e9 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -155,7 +155,7 @@ static void ivtv_dualwatch(struct ivtv *itv)
155 155
156 new_stereo_mode = itv->params.audio_properties & stereo_mask; 156 new_stereo_mode = itv->params.audio_properties & stereo_mask;
157 memset(&vt, 0, sizeof(vt)); 157 memset(&vt, 0, sizeof(vt));
158 ivtv_call_i2c_clients(itv, VIDIOC_G_TUNER, &vt); 158 ivtv_call_all(itv, tuner, g_tuner, &vt);
159 if (vt.audmode == V4L2_TUNER_MODE_LANG1_LANG2 && (vt.rxsubchans & V4L2_TUNER_SUB_LANG2)) 159 if (vt.audmode == V4L2_TUNER_MODE_LANG1_LANG2 && (vt.rxsubchans & V4L2_TUNER_SUB_LANG2))
160 new_stereo_mode = dual; 160 new_stereo_mode = dual;
161 161
@@ -857,7 +857,7 @@ int ivtv_v4l2_close(struct inode *inode, struct file *filp)
857 /* Mark that the radio is no longer in use */ 857 /* Mark that the radio is no longer in use */
858 clear_bit(IVTV_F_I_RADIO_USER, &itv->i_flags); 858 clear_bit(IVTV_F_I_RADIO_USER, &itv->i_flags);
859 /* Switch tuner to TV */ 859 /* Switch tuner to TV */
860 ivtv_call_i2c_clients(itv, VIDIOC_S_STD, &itv->std); 860 ivtv_call_all(itv, tuner, s_std, itv->std);
861 /* Select correct audio input (i.e. TV tuner or Line in) */ 861 /* Select correct audio input (i.e. TV tuner or Line in) */
862 ivtv_audio_set_io(itv); 862 ivtv_audio_set_io(itv);
863 if (itv->hw_flags & IVTV_HW_SAA711X) 863 if (itv->hw_flags & IVTV_HW_SAA711X)
@@ -865,7 +865,7 @@ int ivtv_v4l2_close(struct inode *inode, struct file *filp)
865 struct v4l2_crystal_freq crystal_freq; 865 struct v4l2_crystal_freq crystal_freq;
866 crystal_freq.freq = SAA7115_FREQ_32_11_MHZ; 866 crystal_freq.freq = SAA7115_FREQ_32_11_MHZ;
867 crystal_freq.flags = 0; 867 crystal_freq.flags = 0;
868 ivtv_saa7115(itv, VIDIOC_INT_S_CRYSTAL_FREQ, &crystal_freq); 868 ivtv_call_hw(itv, IVTV_HW_SAA711X, video, s_crystal_freq, &crystal_freq);
869 } 869 }
870 if (atomic_read(&itv->capturing) > 0) { 870 if (atomic_read(&itv->capturing) > 0) {
871 /* Undo video mute */ 871 /* Undo video mute */
@@ -952,15 +952,14 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
952 /* We have the radio */ 952 /* We have the radio */
953 ivtv_mute(itv); 953 ivtv_mute(itv);
954 /* Switch tuner to radio */ 954 /* Switch tuner to radio */
955 ivtv_call_i2c_clients(itv, AUDC_SET_RADIO, NULL); 955 ivtv_call_all(itv, tuner, s_radio);
956 /* Select the correct audio input (i.e. radio tuner) */ 956 /* Select the correct audio input (i.e. radio tuner) */
957 ivtv_audio_set_io(itv); 957 ivtv_audio_set_io(itv);
958 if (itv->hw_flags & IVTV_HW_SAA711X) 958 if (itv->hw_flags & IVTV_HW_SAA711X) {
959 {
960 struct v4l2_crystal_freq crystal_freq; 959 struct v4l2_crystal_freq crystal_freq;
961 crystal_freq.freq = SAA7115_FREQ_32_11_MHZ; 960 crystal_freq.freq = SAA7115_FREQ_32_11_MHZ;
962 crystal_freq.flags = SAA7115_FREQ_FL_APLL; 961 crystal_freq.flags = SAA7115_FREQ_FL_APLL;
963 ivtv_saa7115(itv, VIDIOC_INT_S_CRYSTAL_FREQ, &crystal_freq); 962 ivtv_call_hw(itv, IVTV_HW_SAA711X, video, s_crystal_freq, &crystal_freq);
964 } 963 }
965 /* Done! Unmute and continue. */ 964 /* Done! Unmute and continue. */
966 ivtv_unmute(itv); 965 ivtv_unmute(itv);
@@ -981,37 +980,18 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
981 980
982int ivtv_v4l2_open(struct inode *inode, struct file *filp) 981int ivtv_v4l2_open(struct inode *inode, struct file *filp)
983{ 982{
984 int res, x, y = 0; 983 int res;
985 struct ivtv *itv = NULL; 984 struct ivtv *itv = NULL;
986 struct ivtv_stream *s = NULL; 985 struct ivtv_stream *s = NULL;
987 int minor = iminor(inode); 986 struct video_device *vdev = video_devdata(filp);
988
989 /* Find which card this open was on */
990 spin_lock(&ivtv_cards_lock);
991 for (x = 0; itv == NULL && x < ivtv_cards_active; x++) {
992 if (ivtv_cards[x] == NULL)
993 continue;
994 /* find out which stream this open was on */
995 for (y = 0; y < IVTV_MAX_STREAMS; y++) {
996 s = &ivtv_cards[x]->streams[y];
997 if (s->v4l2dev && s->v4l2dev->minor == minor) {
998 itv = ivtv_cards[x];
999 break;
1000 }
1001 }
1002 }
1003 spin_unlock(&ivtv_cards_lock);
1004 987
1005 if (itv == NULL) { 988 s = video_get_drvdata(vdev);
1006 /* Couldn't find a device registered 989 itv = s->itv;
1007 on that minor, shouldn't happen! */
1008 printk(KERN_WARNING "No ivtv device found on minor %d\n", minor);
1009 return -ENXIO;
1010 }
1011 990
1012 mutex_lock(&itv->serialize_lock); 991 mutex_lock(&itv->serialize_lock);
1013 if (ivtv_init_on_first_open(itv)) { 992 if (ivtv_init_on_first_open(itv)) {
1014 IVTV_ERR("Failed to initialize on minor %d\n", minor); 993 IVTV_ERR("Failed to initialize on minor %d\n",
994 s->v4l2dev->minor);
1015 mutex_unlock(&itv->serialize_lock); 995 mutex_unlock(&itv->serialize_lock);
1016 return -ENXIO; 996 return -ENXIO;
1017 } 997 }
diff --git a/drivers/media/video/ivtv/ivtv-gpio.c b/drivers/media/video/ivtv/ivtv-gpio.c
index 74a44844cca..dc2850e87a7 100644
--- a/drivers/media/video/ivtv/ivtv-gpio.c
+++ b/drivers/media/video/ivtv/ivtv-gpio.c
@@ -144,22 +144,9 @@ int ivtv_reset_tuner_gpio(void *dev, int component, int cmd, int value)
144 return 0; 144 return 0;
145} 145}
146 146
147void ivtv_gpio_init(struct ivtv *itv) 147static inline struct ivtv *sd_to_ivtv(struct v4l2_subdev *sd)
148{ 148{
149 u16 pin = 0; 149 return container_of(sd, struct ivtv, sd_gpio);
150
151 if (itv->card->xceive_pin)
152 pin = 1 << itv->card->xceive_pin;
153
154 if ((itv->card->gpio_init.direction | pin) == 0)
155 return;
156
157 IVTV_DEBUG_INFO("GPIO initial dir: %08x out: %08x\n",
158 read_reg(IVTV_REG_GPIO_DIR), read_reg(IVTV_REG_GPIO_OUT));
159
160 /* init output data then direction */
161 write_reg(itv->card->gpio_init.initial_value | pin, IVTV_REG_GPIO_OUT);
162 write_reg(itv->card->gpio_init.direction | pin, IVTV_REG_GPIO_DIR);
163} 150}
164 151
165static struct v4l2_queryctrl gpio_ctrl_mute = { 152static struct v4l2_queryctrl gpio_ctrl_mute = {
@@ -173,134 +160,231 @@ static struct v4l2_queryctrl gpio_ctrl_mute = {
173 .flags = 0, 160 .flags = 0,
174}; 161};
175 162
176int ivtv_gpio(struct ivtv *itv, unsigned int command, void *arg) 163static int subdev_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
177{ 164{
178 struct v4l2_tuner *tuner = arg; 165 struct ivtv *itv = sd_to_ivtv(sd);
179 struct v4l2_control *ctrl = arg;
180 struct v4l2_routing *route = arg;
181 u16 mask, data; 166 u16 mask, data;
182 167
183 switch (command) { 168 mask = itv->card->gpio_audio_freq.mask;
184 case VIDIOC_INT_AUDIO_CLOCK_FREQ: 169 switch (freq) {
185 mask = itv->card->gpio_audio_freq.mask; 170 case 32000:
186 switch (*(u32 *)arg) { 171 data = itv->card->gpio_audio_freq.f32000;
187 case 32000: 172 break;
188 data = itv->card->gpio_audio_freq.f32000; 173 case 44100:
189 break; 174 data = itv->card->gpio_audio_freq.f44100;
190 case 44100: 175 break;
191 data = itv->card->gpio_audio_freq.f44100; 176 case 48000:
192 break; 177 default:
193 case 48000: 178 data = itv->card->gpio_audio_freq.f48000;
194 default:
195 data = itv->card->gpio_audio_freq.f48000;
196 break;
197 }
198 break; 179 break;
180 }
181 if (mask)
182 write_reg((read_reg(IVTV_REG_GPIO_OUT) & ~mask) | (data & mask), IVTV_REG_GPIO_OUT);
183 return 0;
184}
199 185
200 case VIDIOC_G_TUNER: 186static int subdev_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
201 mask = itv->card->gpio_audio_detect.mask; 187{
202 if (mask == 0 || (read_reg(IVTV_REG_GPIO_IN) & mask)) 188 struct ivtv *itv = sd_to_ivtv(sd);
203 tuner->rxsubchans = V4L2_TUNER_MODE_STEREO | 189 u16 mask;
204 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; 190
205 else 191 mask = itv->card->gpio_audio_detect.mask;
206 tuner->rxsubchans = V4L2_TUNER_SUB_MONO; 192 if (mask == 0 || (read_reg(IVTV_REG_GPIO_IN) & mask))
207 return 0; 193 vt->rxsubchans = V4L2_TUNER_MODE_STEREO |
194 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
195 else
196 vt->rxsubchans = V4L2_TUNER_SUB_MONO;
197 return 0;
198}
208 199
209 case VIDIOC_S_TUNER: 200static int subdev_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
210 mask = itv->card->gpio_audio_mode.mask; 201{
211 switch (tuner->audmode) { 202 struct ivtv *itv = sd_to_ivtv(sd);
212 case V4L2_TUNER_MODE_LANG1: 203 u16 mask, data;
213 data = itv->card->gpio_audio_mode.lang1;
214 break;
215 case V4L2_TUNER_MODE_LANG2:
216 data = itv->card->gpio_audio_mode.lang2;
217 break;
218 case V4L2_TUNER_MODE_MONO:
219 data = itv->card->gpio_audio_mode.mono;
220 break;
221 case V4L2_TUNER_MODE_STEREO:
222 case V4L2_TUNER_MODE_LANG1_LANG2:
223 default:
224 data = itv->card->gpio_audio_mode.stereo;
225 break;
226 }
227 break;
228 204
229 case AUDC_SET_RADIO: 205 mask = itv->card->gpio_audio_mode.mask;
230 mask = itv->card->gpio_audio_input.mask; 206 switch (vt->audmode) {
231 data = itv->card->gpio_audio_input.radio; 207 case V4L2_TUNER_MODE_LANG1:
208 data = itv->card->gpio_audio_mode.lang1;
209 break;
210 case V4L2_TUNER_MODE_LANG2:
211 data = itv->card->gpio_audio_mode.lang2;
212 break;
213 case V4L2_TUNER_MODE_MONO:
214 data = itv->card->gpio_audio_mode.mono;
232 break; 215 break;
216 case V4L2_TUNER_MODE_STEREO:
217 case V4L2_TUNER_MODE_LANG1_LANG2:
218 default:
219 data = itv->card->gpio_audio_mode.stereo;
220 break;
221 }
222 if (mask)
223 write_reg((read_reg(IVTV_REG_GPIO_OUT) & ~mask) | (data & mask), IVTV_REG_GPIO_OUT);
224 return 0;
225}
226
227static int subdev_s_radio(struct v4l2_subdev *sd)
228{
229 struct ivtv *itv = sd_to_ivtv(sd);
230 u16 mask, data;
231
232 mask = itv->card->gpio_audio_input.mask;
233 data = itv->card->gpio_audio_input.radio;
234 if (mask)
235 write_reg((read_reg(IVTV_REG_GPIO_OUT) & ~mask) | (data & mask), IVTV_REG_GPIO_OUT);
236 return 0;
237}
233 238
234 case VIDIOC_S_STD: 239static int subdev_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
235 mask = itv->card->gpio_audio_input.mask; 240{
241 struct ivtv *itv = sd_to_ivtv(sd);
242 u16 mask, data;
243
244 mask = itv->card->gpio_audio_input.mask;
245 data = itv->card->gpio_audio_input.tuner;
246 if (mask)
247 write_reg((read_reg(IVTV_REG_GPIO_OUT) & ~mask) | (data & mask), IVTV_REG_GPIO_OUT);
248 return 0;
249}
250
251static int subdev_s_audio_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
252{
253 struct ivtv *itv = sd_to_ivtv(sd);
254 u16 mask, data;
255
256 if (route->input > 2)
257 return -EINVAL;
258 mask = itv->card->gpio_audio_input.mask;
259 switch (route->input) {
260 case 0:
236 data = itv->card->gpio_audio_input.tuner; 261 data = itv->card->gpio_audio_input.tuner;
237 break; 262 break;
238 263 case 1:
239 case VIDIOC_INT_S_AUDIO_ROUTING: 264 data = itv->card->gpio_audio_input.linein;
240 if (route->input > 2) 265 break;
241 return -EINVAL; 266 case 2:
242 mask = itv->card->gpio_audio_input.mask; 267 default:
243 switch (route->input) { 268 data = itv->card->gpio_audio_input.radio;
244 case 0:
245 data = itv->card->gpio_audio_input.tuner;
246 break;
247 case 1:
248 data = itv->card->gpio_audio_input.linein;
249 break;
250 case 2:
251 default:
252 data = itv->card->gpio_audio_input.radio;
253 break;
254 }
255 break; 269 break;
270 }
271 if (mask)
272 write_reg((read_reg(IVTV_REG_GPIO_OUT) & ~mask) | (data & mask), IVTV_REG_GPIO_OUT);
273 return 0;
274}
256 275
257 case VIDIOC_G_CTRL: 276static int subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
258 if (ctrl->id != V4L2_CID_AUDIO_MUTE) 277{
259 return -EINVAL; 278 struct ivtv *itv = sd_to_ivtv(sd);
260 mask = itv->card->gpio_audio_mute.mask; 279 u16 mask, data;
261 data = itv->card->gpio_audio_mute.mute;
262 ctrl->value = (read_reg(IVTV_REG_GPIO_OUT) & mask) == data;
263 return 0;
264 280
265 case VIDIOC_S_CTRL: 281 if (ctrl->id != V4L2_CID_AUDIO_MUTE)
266 if (ctrl->id != V4L2_CID_AUDIO_MUTE) 282 return -EINVAL;
267 return -EINVAL; 283 mask = itv->card->gpio_audio_mute.mask;
268 mask = itv->card->gpio_audio_mute.mask; 284 data = itv->card->gpio_audio_mute.mute;
269 data = ctrl->value ? itv->card->gpio_audio_mute.mute : 0; 285 ctrl->value = (read_reg(IVTV_REG_GPIO_OUT) & mask) == data;
270 break; 286 return 0;
287}
271 288
272 case VIDIOC_QUERYCTRL: 289static int subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
273 { 290{
274 struct v4l2_queryctrl *qc = arg; 291 struct ivtv *itv = sd_to_ivtv(sd);
292 u16 mask, data;
275 293
276 if (qc->id != V4L2_CID_AUDIO_MUTE) 294 if (ctrl->id != V4L2_CID_AUDIO_MUTE)
277 return -EINVAL; 295 return -EINVAL;
278 *qc = gpio_ctrl_mute; 296 mask = itv->card->gpio_audio_mute.mask;
279 return 0; 297 data = ctrl->value ? itv->card->gpio_audio_mute.mute : 0;
280 } 298 if (mask)
299 write_reg((read_reg(IVTV_REG_GPIO_OUT) & ~mask) | (data & mask), IVTV_REG_GPIO_OUT);
300 return 0;
301}
302
303static int subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
304{
305 if (qc->id != V4L2_CID_AUDIO_MUTE)
306 return -EINVAL;
307 *qc = gpio_ctrl_mute;
308 return 0;
309}
310
311static int subdev_log_status(struct v4l2_subdev *sd)
312{
313 struct ivtv *itv = sd_to_ivtv(sd);
281 314
282 case VIDIOC_LOG_STATUS: 315 IVTV_INFO("GPIO status: DIR=0x%04x OUT=0x%04x IN=0x%04x\n",
283 IVTV_INFO("GPIO status: DIR=0x%04x OUT=0x%04x IN=0x%04x\n",
284 read_reg(IVTV_REG_GPIO_DIR), read_reg(IVTV_REG_GPIO_OUT), 316 read_reg(IVTV_REG_GPIO_DIR), read_reg(IVTV_REG_GPIO_OUT),
285 read_reg(IVTV_REG_GPIO_IN)); 317 read_reg(IVTV_REG_GPIO_IN));
286 return 0; 318 return 0;
319}
287 320
288 case VIDIOC_INT_S_VIDEO_ROUTING: 321static int subdev_s_video_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
289 if (route->input > 2) /* 0:Tuner 1:Composite 2:S-Video */ 322{
290 return -EINVAL; 323 struct ivtv *itv = sd_to_ivtv(sd);
291 mask = itv->card->gpio_video_input.mask; 324 u16 mask, data;
292 if (route->input == 0)
293 data = itv->card->gpio_video_input.tuner;
294 else if (route->input == 1)
295 data = itv->card->gpio_video_input.composite;
296 else
297 data = itv->card->gpio_video_input.svideo;
298 break;
299 325
300 default: 326 if (route->input > 2) /* 0:Tuner 1:Composite 2:S-Video */
301 return -EINVAL; 327 return -EINVAL;
302 } 328 mask = itv->card->gpio_video_input.mask;
329 if (route->input == 0)
330 data = itv->card->gpio_video_input.tuner;
331 else if (route->input == 1)
332 data = itv->card->gpio_video_input.composite;
333 else
334 data = itv->card->gpio_video_input.svideo;
303 if (mask) 335 if (mask)
304 write_reg((read_reg(IVTV_REG_GPIO_OUT) & ~mask) | (data & mask), IVTV_REG_GPIO_OUT); 336 write_reg((read_reg(IVTV_REG_GPIO_OUT) & ~mask) | (data & mask), IVTV_REG_GPIO_OUT);
305 return 0; 337 return 0;
306} 338}
339
340static const struct v4l2_subdev_core_ops subdev_core_ops = {
341 .log_status = subdev_log_status,
342 .g_ctrl = subdev_g_ctrl,
343 .s_ctrl = subdev_s_ctrl,
344 .queryctrl = subdev_queryctrl,
345};
346
347static const struct v4l2_subdev_tuner_ops subdev_tuner_ops = {
348 .s_std = subdev_s_std,
349 .s_radio = subdev_s_radio,
350 .g_tuner = subdev_g_tuner,
351 .s_tuner = subdev_s_tuner,
352};
353
354static const struct v4l2_subdev_audio_ops subdev_audio_ops = {
355 .s_clock_freq = subdev_s_clock_freq,
356 .s_routing = subdev_s_audio_routing,
357};
358
359static const struct v4l2_subdev_video_ops subdev_video_ops = {
360 .s_routing = subdev_s_video_routing,
361};
362
363static const struct v4l2_subdev_ops subdev_ops = {
364 .core = &subdev_core_ops,
365 .tuner = &subdev_tuner_ops,
366 .audio = &subdev_audio_ops,
367 .video = &subdev_video_ops,
368};
369
370int ivtv_gpio_init(struct ivtv *itv)
371{
372 u16 pin = 0;
373
374 if (itv->card->xceive_pin)
375 pin = 1 << itv->card->xceive_pin;
376
377 if ((itv->card->gpio_init.direction | pin) == 0)
378 return 0;
379
380 IVTV_DEBUG_INFO("GPIO initial dir: %08x out: %08x\n",
381 read_reg(IVTV_REG_GPIO_DIR), read_reg(IVTV_REG_GPIO_OUT));
382
383 /* init output data then direction */
384 write_reg(itv->card->gpio_init.initial_value | pin, IVTV_REG_GPIO_OUT);
385 write_reg(itv->card->gpio_init.direction | pin, IVTV_REG_GPIO_DIR);
386 v4l2_subdev_init(&itv->sd_gpio, &subdev_ops);
387 snprintf(itv->sd_gpio.name, sizeof(itv->sd_gpio.name), "%s-gpio", itv->device.name);
388 itv->sd_gpio.grp_id = IVTV_HW_GPIO;
389 return v4l2_device_register_subdev(&itv->device, &itv->sd_gpio);
390}
diff --git a/drivers/media/video/ivtv/ivtv-gpio.h b/drivers/media/video/ivtv/ivtv-gpio.h
index 48b6291613a..0b5d19c8ecb 100644
--- a/drivers/media/video/ivtv/ivtv-gpio.h
+++ b/drivers/media/video/ivtv/ivtv-gpio.h
@@ -22,9 +22,8 @@
22#define IVTV_GPIO_H 22#define IVTV_GPIO_H
23 23
24/* GPIO stuff */ 24/* GPIO stuff */
25void ivtv_gpio_init(struct ivtv *itv); 25int ivtv_gpio_init(struct ivtv *itv);
26void ivtv_reset_ir_gpio(struct ivtv *itv); 26void ivtv_reset_ir_gpio(struct ivtv *itv);
27int ivtv_reset_tuner_gpio(void *dev, int component, int cmd, int value); 27int ivtv_reset_tuner_gpio(void *dev, int component, int cmd, int value);
28int ivtv_gpio(struct ivtv *itv, unsigned int command, void *arg);
29 28
30#endif 29#endif
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index 41dbbe9621a..ca1d9557945 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -90,26 +90,6 @@
90#define IVTV_M52790_I2C_ADDR 0x48 90#define IVTV_M52790_I2C_ADDR 0x48
91 91
92/* This array should match the IVTV_HW_ defines */ 92/* This array should match the IVTV_HW_ defines */
93static const u8 hw_driverids[] = {
94 I2C_DRIVERID_CX25840,
95 I2C_DRIVERID_SAA711X,
96 I2C_DRIVERID_SAA7127,
97 I2C_DRIVERID_MSP3400,
98 I2C_DRIVERID_TUNER,
99 I2C_DRIVERID_WM8775,
100 I2C_DRIVERID_CS53L32A,
101 I2C_DRIVERID_TVEEPROM,
102 I2C_DRIVERID_SAA711X,
103 I2C_DRIVERID_UPD64031A,
104 I2C_DRIVERID_UPD64083,
105 I2C_DRIVERID_SAA717X,
106 I2C_DRIVERID_WM8739,
107 I2C_DRIVERID_VP27SMPX,
108 I2C_DRIVERID_M52790,
109 0 /* IVTV_HW_GPIO dummy driver ID */
110};
111
112/* This array should match the IVTV_HW_ defines */
113static const u8 hw_addrs[] = { 93static const u8 hw_addrs[] = {
114 IVTV_CX25840_I2C_ADDR, 94 IVTV_CX25840_I2C_ADDR,
115 IVTV_SAA7115_I2C_ADDR, 95 IVTV_SAA7115_I2C_ADDR,
@@ -130,6 +110,26 @@ static const u8 hw_addrs[] = {
130}; 110};
131 111
132/* This array should match the IVTV_HW_ defines */ 112/* This array should match the IVTV_HW_ defines */
113static const char *hw_modules[] = {
114 "cx25840",
115 "saa7115",
116 "saa7127",
117 "msp3400",
118 "tuner",
119 "wm8775",
120 "cs53l32a",
121 NULL,
122 "saa7115",
123 "upd64031a",
124 "upd64083",
125 "saa717x",
126 "wm8739",
127 "vp27smpx",
128 "m52790",
129 NULL
130};
131
132/* This array should match the IVTV_HW_ defines */
133static const char * const hw_devicenames[] = { 133static const char * const hw_devicenames[] = {
134 "cx25840", 134 "cx25840",
135 "saa7115", 135 "saa7115",
@@ -151,80 +151,58 @@ static const char * const hw_devicenames[] = {
151 151
152int ivtv_i2c_register(struct ivtv *itv, unsigned idx) 152int ivtv_i2c_register(struct ivtv *itv, unsigned idx)
153{ 153{
154 struct i2c_board_info info; 154 struct v4l2_subdev *sd;
155 struct i2c_client *c; 155 struct i2c_adapter *adap = &itv->i2c_adap;
156 u8 id; 156 const char *mod = hw_modules[idx];
157 int i; 157 const char *type = hw_devicenames[idx];
158 u32 hw = 1 << idx;
158 159
159 IVTV_DEBUG_I2C("i2c client register\n"); 160 if (idx >= ARRAY_SIZE(hw_addrs))
160 if (idx >= ARRAY_SIZE(hw_driverids) || hw_driverids[idx] == 0)
161 return -1; 161 return -1;
162 id = hw_driverids[idx]; 162 if (hw == IVTV_HW_TUNER) {
163 memset(&info, 0, sizeof(info)); 163 /* special tuner handling */
164 strlcpy(info.type, hw_devicenames[idx], sizeof(info.type)); 164 sd = v4l2_i2c_new_probed_subdev(adap, mod, type,
165 info.addr = hw_addrs[idx]; 165 itv->card_i2c->radio);
166 for (i = 0; itv->i2c_clients[i] && i < I2C_CLIENTS_MAX; i++) {} 166 if (sd)
167 167 sd->grp_id = 1 << idx;
168 if (i == I2C_CLIENTS_MAX) { 168 sd = v4l2_i2c_new_probed_subdev(adap, mod, type,
169 IVTV_ERR("insufficient room for new I2C client!\n"); 169 itv->card_i2c->demod);
170 return -ENOMEM; 170 if (sd)
171 sd->grp_id = 1 << idx;
172 sd = v4l2_i2c_new_probed_subdev(adap, mod, type,
173 itv->card_i2c->tv);
174 if (sd)
175 sd->grp_id = 1 << idx;
176 return sd ? 0 : -1;
171 } 177 }
178 if (!hw_addrs[idx])
179 return -1;
180 if (hw == IVTV_HW_UPD64031A || hw == IVTV_HW_UPD6408X) {
181 unsigned short addrs[2] = { hw_addrs[idx], I2C_CLIENT_END };
172 182
173 if (id != I2C_DRIVERID_TUNER) { 183 sd = v4l2_i2c_new_probed_subdev(adap, mod, type, addrs);
174 if (id == I2C_DRIVERID_UPD64031A || 184 } else {
175 id == I2C_DRIVERID_UPD64083) { 185 sd = v4l2_i2c_new_subdev(adap, mod, type, hw_addrs[idx]);
176 unsigned short addrs[2] = { info.addr, I2C_CLIENT_END };
177
178 c = i2c_new_probed_device(&itv->i2c_adap, &info, addrs);
179 } else
180 c = i2c_new_device(&itv->i2c_adap, &info);
181 if (c && c->driver == NULL)
182 i2c_unregister_device(c);
183 else if (c)
184 itv->i2c_clients[i] = c;
185 return itv->i2c_clients[i] ? 0 : -ENODEV;
186 } 186 }
187 187 if (sd)
188 /* special tuner handling */ 188 sd->grp_id = 1 << idx;
189 c = i2c_new_probed_device(&itv->i2c_adap, &info, itv->card_i2c->radio); 189 return sd ? 0 : -1;
190 if (c && c->driver == NULL)
191 i2c_unregister_device(c);
192 else if (c)
193 itv->i2c_clients[i++] = c;
194 c = i2c_new_probed_device(&itv->i2c_adap, &info, itv->card_i2c->demod);
195 if (c && c->driver == NULL)
196 i2c_unregister_device(c);
197 else if (c)
198 itv->i2c_clients[i++] = c;
199 c = i2c_new_probed_device(&itv->i2c_adap, &info, itv->card_i2c->tv);
200 if (c && c->driver == NULL)
201 i2c_unregister_device(c);
202 else if (c)
203 itv->i2c_clients[i++] = c;
204 return 0;
205}
206
207static int attach_inform(struct i2c_client *client)
208{
209 return 0;
210} 190}
211 191
212static int detach_inform(struct i2c_client *client) 192struct v4l2_subdev *ivtv_find_hw(struct ivtv *itv, u32 hw)
213{ 193{
214 int i; 194 struct v4l2_subdev *result = NULL;
215 struct ivtv *itv = (struct ivtv *)i2c_get_adapdata(client->adapter); 195 struct v4l2_subdev *sd;
216 196
217 IVTV_DEBUG_I2C("i2c client detach\n"); 197 spin_lock(&itv->device.lock);
218 for (i = 0; i < I2C_CLIENTS_MAX; i++) { 198 v4l2_device_for_each_subdev(sd, &itv->device) {
219 if (itv->i2c_clients[i] == client) { 199 if (sd->grp_id == hw) {
220 itv->i2c_clients[i] = NULL; 200 result = sd;
221 break; 201 break;
222 } 202 }
223 } 203 }
224 IVTV_DEBUG_I2C("i2c detach [client=%s,%s]\n", 204 spin_unlock(&itv->device.lock);
225 client->name, (i < I2C_CLIENTS_MAX) ? "ok" : "failed"); 205 return result;
226
227 return 0;
228} 206}
229 207
230/* Set the serial clock line to the desired state */ 208/* Set the serial clock line to the desired state */
@@ -494,7 +472,8 @@ static int ivtv_read(struct ivtv *itv, unsigned char addr, unsigned char *data,
494 intervening stop condition */ 472 intervening stop condition */
495static int ivtv_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num) 473static int ivtv_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
496{ 474{
497 struct ivtv *itv = i2c_get_adapdata(i2c_adap); 475 struct v4l2_device *drv = i2c_get_adapdata(i2c_adap);
476 struct ivtv *itv = to_ivtv(drv);
498 int retval; 477 int retval;
499 int i; 478 int i;
500 479
@@ -530,8 +509,6 @@ static struct i2c_adapter ivtv_i2c_adap_hw_template = {
530 .id = I2C_HW_B_CX2341X, 509 .id = I2C_HW_B_CX2341X,
531 .algo = &ivtv_algo, 510 .algo = &ivtv_algo,
532 .algo_data = NULL, /* filled from template */ 511 .algo_data = NULL, /* filled from template */
533 .client_register = attach_inform,
534 .client_unregister = detach_inform,
535 .owner = THIS_MODULE, 512 .owner = THIS_MODULE,
536}; 513};
537 514
@@ -583,8 +560,6 @@ static struct i2c_adapter ivtv_i2c_adap_template = {
583 .id = I2C_HW_B_CX2341X, 560 .id = I2C_HW_B_CX2341X,
584 .algo = NULL, /* set by i2c-algo-bit */ 561 .algo = NULL, /* set by i2c-algo-bit */
585 .algo_data = NULL, /* filled from template */ 562 .algo_data = NULL, /* filled from template */
586 .client_register = attach_inform,
587 .client_unregister = detach_inform,
588 .owner = THIS_MODULE, 563 .owner = THIS_MODULE,
589}; 564};
590 565
@@ -601,160 +576,6 @@ static struct i2c_client ivtv_i2c_client_template = {
601 .name = "ivtv internal", 576 .name = "ivtv internal",
602}; 577};
603 578
604int ivtv_call_i2c_client(struct ivtv *itv, int addr, unsigned int cmd, void *arg)
605{
606 struct i2c_client *client;
607 int retval;
608 int i;
609
610 IVTV_DEBUG_I2C("call_i2c_client addr=%02x\n", addr);
611 for (i = 0; i < I2C_CLIENTS_MAX; i++) {
612 client = itv->i2c_clients[i];
613 if (client == NULL || client->driver == NULL ||
614 client->driver->command == NULL)
615 continue;
616 if (addr == client->addr) {
617 retval = client->driver->command(client, cmd, arg);
618 return retval;
619 }
620 }
621 if (cmd != VIDIOC_G_CHIP_IDENT)
622 IVTV_ERR("i2c addr 0x%02x not found for command 0x%x\n", addr, cmd);
623 return -ENODEV;
624}
625
626/* Find the i2c device based on the driver ID and return
627 its i2c address or -ENODEV if no matching device was found. */
628static int ivtv_i2c_id_addr(struct ivtv *itv, u32 id)
629{
630 struct i2c_client *client;
631 int retval = -ENODEV;
632 int i;
633
634 for (i = 0; i < I2C_CLIENTS_MAX; i++) {
635 client = itv->i2c_clients[i];
636 if (client == NULL || client->driver == NULL)
637 continue;
638 if (id == client->driver->id) {
639 retval = client->addr;
640 break;
641 }
642 }
643 return retval;
644}
645
646/* Find the i2c device name matching the DRIVERID */
647static const char *ivtv_i2c_id_name(u32 id)
648{
649 int i;
650
651 for (i = 0; i < ARRAY_SIZE(hw_driverids); i++)
652 if (hw_driverids[i] == id)
653 return hw_devicenames[i];
654 return "unknown device";
655}
656
657/* Find the i2c device name matching the IVTV_HW_ flag */
658static const char *ivtv_i2c_hw_name(u32 hw)
659{
660 int i;
661
662 for (i = 0; i < ARRAY_SIZE(hw_driverids); i++)
663 if (1 << i == hw)
664 return hw_devicenames[i];
665 return "unknown device";
666}
667
668/* Find the i2c device matching the IVTV_HW_ flag and return
669 its i2c address or -ENODEV if no matching device was found. */
670int ivtv_i2c_hw_addr(struct ivtv *itv, u32 hw)
671{
672 int i;
673
674 for (i = 0; i < ARRAY_SIZE(hw_driverids); i++)
675 if (1 << i == hw)
676 return ivtv_i2c_id_addr(itv, hw_driverids[i]);
677 return -ENODEV;
678}
679
680/* Calls i2c device based on IVTV_HW_ flag. If hw == 0, then do nothing.
681 If hw == IVTV_HW_GPIO then call the gpio handler. */
682int ivtv_i2c_hw(struct ivtv *itv, u32 hw, unsigned int cmd, void *arg)
683{
684 int addr;
685
686 if (hw == IVTV_HW_GPIO)
687 return ivtv_gpio(itv, cmd, arg);
688 if (hw == 0)
689 return 0;
690
691 addr = ivtv_i2c_hw_addr(itv, hw);
692 if (addr < 0) {
693 IVTV_ERR("i2c hardware 0x%08x (%s) not found for command 0x%x\n",
694 hw, ivtv_i2c_hw_name(hw), cmd);
695 return addr;
696 }
697 return ivtv_call_i2c_client(itv, addr, cmd, arg);
698}
699
700/* Calls i2c device based on I2C driver ID. */
701int ivtv_i2c_id(struct ivtv *itv, u32 id, unsigned int cmd, void *arg)
702{
703 int addr;
704
705 addr = ivtv_i2c_id_addr(itv, id);
706 if (addr < 0) {
707 if (cmd != VIDIOC_G_CHIP_IDENT)
708 IVTV_ERR("i2c ID 0x%08x (%s) not found for command 0x%x\n",
709 id, ivtv_i2c_id_name(id), cmd);
710 return addr;
711 }
712 return ivtv_call_i2c_client(itv, addr, cmd, arg);
713}
714
715int ivtv_cx25840(struct ivtv *itv, unsigned int cmd, void *arg)
716{
717 return ivtv_call_i2c_client(itv, IVTV_CX25840_I2C_ADDR, cmd, arg);
718}
719
720int ivtv_saa7115(struct ivtv *itv, unsigned int cmd, void *arg)
721{
722 return ivtv_call_i2c_client(itv, IVTV_SAA7115_I2C_ADDR, cmd, arg);
723}
724
725int ivtv_saa7127(struct ivtv *itv, unsigned int cmd, void *arg)
726{
727 return ivtv_call_i2c_client(itv, IVTV_SAA7127_I2C_ADDR, cmd, arg);
728}
729EXPORT_SYMBOL(ivtv_saa7127);
730
731int ivtv_saa717x(struct ivtv *itv, unsigned int cmd, void *arg)
732{
733 return ivtv_call_i2c_client(itv, IVTV_SAA717x_I2C_ADDR, cmd, arg);
734}
735
736int ivtv_upd64031a(struct ivtv *itv, unsigned int cmd, void *arg)
737{
738 return ivtv_call_i2c_client(itv, IVTV_UPD64031A_I2C_ADDR, cmd, arg);
739}
740
741int ivtv_upd64083(struct ivtv *itv, unsigned int cmd, void *arg)
742{
743 return ivtv_call_i2c_client(itv, IVTV_UPD64083_I2C_ADDR, cmd, arg);
744}
745
746/* broadcast cmd for all I2C clients and for the gpio subsystem */
747void ivtv_call_i2c_clients(struct ivtv *itv, unsigned int cmd, void *arg)
748{
749 if (itv->i2c_adap.algo == NULL) {
750 IVTV_ERR("Adapter is not set");
751 return;
752 }
753 i2c_clients_command(&itv->i2c_adap, cmd, arg);
754 if (itv->hw_flags & IVTV_HW_GPIO)
755 ivtv_gpio(itv, cmd, arg);
756}
757
758/* init + register i2c algo-bit adapter */ 579/* init + register i2c algo-bit adapter */
759int init_ivtv_i2c(struct ivtv *itv) 580int init_ivtv_i2c(struct ivtv *itv)
760{ 581{
@@ -763,10 +584,9 @@ int init_ivtv_i2c(struct ivtv *itv)
763 /* Sanity checks for the I2C hardware arrays. They must be the 584 /* Sanity checks for the I2C hardware arrays. They must be the
764 * same size and GPIO must be the last entry. 585 * same size and GPIO must be the last entry.
765 */ 586 */
766 if (ARRAY_SIZE(hw_driverids) != ARRAY_SIZE(hw_addrs) || 587 if (ARRAY_SIZE(hw_devicenames) != ARRAY_SIZE(hw_addrs) ||
767 ARRAY_SIZE(hw_devicenames) != ARRAY_SIZE(hw_addrs) || 588 ARRAY_SIZE(hw_devicenames) != ARRAY_SIZE(hw_modules) ||
768 IVTV_HW_GPIO != (1 << (ARRAY_SIZE(hw_addrs) - 1)) || 589 IVTV_HW_GPIO != (1 << (ARRAY_SIZE(hw_addrs) - 1))) {
769 hw_driverids[ARRAY_SIZE(hw_addrs) - 1]) {
770 IVTV_ERR("Mismatched I2C hardware arrays\n"); 590 IVTV_ERR("Mismatched I2C hardware arrays\n");
771 return -ENODEV; 591 return -ENODEV;
772 } 592 }
@@ -783,8 +603,8 @@ int init_ivtv_i2c(struct ivtv *itv)
783 itv->i2c_adap.algo_data = &itv->i2c_algo; 603 itv->i2c_adap.algo_data = &itv->i2c_algo;
784 604
785 sprintf(itv->i2c_adap.name + strlen(itv->i2c_adap.name), " #%d", 605 sprintf(itv->i2c_adap.name + strlen(itv->i2c_adap.name), " #%d",
786 itv->num); 606 itv->instance);
787 i2c_set_adapdata(&itv->i2c_adap, itv); 607 i2c_set_adapdata(&itv->i2c_adap, &itv->device);
788 608
789 memcpy(&itv->i2c_client, &ivtv_i2c_client_template, 609 memcpy(&itv->i2c_client, &ivtv_i2c_client_template,
790 sizeof(struct i2c_client)); 610 sizeof(struct i2c_client));
diff --git a/drivers/media/video/ivtv/ivtv-i2c.h b/drivers/media/video/ivtv/ivtv-i2c.h
index 022978cf533..396928a06a5 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.h
+++ b/drivers/media/video/ivtv/ivtv-i2c.h
@@ -21,19 +21,8 @@
21#ifndef IVTV_I2C_H 21#ifndef IVTV_I2C_H
22#define IVTV_I2C_H 22#define IVTV_I2C_H
23 23
24int ivtv_cx25840(struct ivtv *itv, unsigned int cmd, void *arg);
25int ivtv_saa7115(struct ivtv *itv, unsigned int cmd, void *arg);
26int ivtv_saa7127(struct ivtv *itv, unsigned int cmd, void *arg);
27int ivtv_saa717x(struct ivtv *itv, unsigned int cmd, void *arg);
28int ivtv_upd64031a(struct ivtv *itv, unsigned int cmd, void *arg);
29int ivtv_upd64083(struct ivtv *itv, unsigned int cmd, void *arg);
30
31int ivtv_i2c_hw_addr(struct ivtv *itv, u32 hw);
32int ivtv_i2c_hw(struct ivtv *itv, u32 hw, unsigned int cmd, void *arg);
33int ivtv_i2c_id(struct ivtv *itv, u32 id, unsigned int cmd, void *arg);
34int ivtv_call_i2c_client(struct ivtv *itv, int addr, unsigned int cmd, void *arg);
35void ivtv_call_i2c_clients(struct ivtv *itv, unsigned int cmd, void *arg);
36int ivtv_i2c_register(struct ivtv *itv, unsigned idx); 24int ivtv_i2c_register(struct ivtv *itv, unsigned idx);
25struct v4l2_subdev *ivtv_find_hw(struct ivtv *itv, u32 hw);
37 26
38/* init + register i2c algo-bit adapter */ 27/* init + register i2c algo-bit adapter */
39int init_ivtv_i2c(struct ivtv *itv); 28int init_ivtv_i2c(struct ivtv *itv);
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index 4bae38d21ef..cd990a4b81a 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -393,7 +393,7 @@ static int ivtv_g_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_fo
393 return 0; 393 return 0;
394 } 394 }
395 395
396 itv->video_dec_func(itv, VIDIOC_G_FMT, fmt); 396 v4l2_subdev_call(itv->sd_video, video, s_fmt, fmt);
397 vbifmt->service_set = ivtv_get_service_set(vbifmt); 397 vbifmt->service_set = ivtv_get_service_set(vbifmt);
398 return 0; 398 return 0;
399} 399}
@@ -581,7 +581,7 @@ static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
581 p->height = h; 581 p->height = h;
582 if (p->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1) 582 if (p->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1)
583 fmt->fmt.pix.width /= 2; 583 fmt->fmt.pix.width /= 2;
584 itv->video_dec_func(itv, VIDIOC_S_FMT, fmt); 584 v4l2_subdev_call(itv->sd_video, video, s_fmt, fmt);
585 return ivtv_g_fmt_vid_cap(file, fh, fmt); 585 return ivtv_g_fmt_vid_cap(file, fh, fmt);
586} 586}
587 587
@@ -593,7 +593,7 @@ static int ivtv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f
593 return -EBUSY; 593 return -EBUSY;
594 itv->vbi.sliced_in->service_set = 0; 594 itv->vbi.sliced_in->service_set = 0;
595 itv->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE; 595 itv->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
596 itv->video_dec_func(itv, VIDIOC_S_FMT, fmt); 596 v4l2_subdev_call(itv->sd_video, video, s_fmt, fmt);
597 return ivtv_g_fmt_vbi_cap(file, fh, fmt); 597 return ivtv_g_fmt_vbi_cap(file, fh, fmt);
598} 598}
599 599
@@ -611,7 +611,7 @@ static int ivtv_s_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_fo
611 if (ivtv_raw_vbi(itv) && atomic_read(&itv->capturing) > 0) 611 if (ivtv_raw_vbi(itv) && atomic_read(&itv->capturing) > 0)
612 return -EBUSY; 612 return -EBUSY;
613 itv->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE; 613 itv->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
614 itv->video_dec_func(itv, VIDIOC_S_FMT, fmt); 614 v4l2_subdev_call(itv->sd_video, video, s_fmt, fmt);
615 memcpy(itv->vbi.sliced_in, vbifmt, sizeof(*itv->vbi.sliced_in)); 615 memcpy(itv->vbi.sliced_in, vbifmt, sizeof(*itv->vbi.sliced_in));
616 return 0; 616 return 0;
617} 617}
@@ -685,18 +685,17 @@ static int ivtv_g_chip_ident(struct file *file, void *fh, struct v4l2_chip_ident
685 chip->ident = itv->has_cx23415 ? V4L2_IDENT_CX23415 : V4L2_IDENT_CX23416; 685 chip->ident = itv->has_cx23415 ? V4L2_IDENT_CX23415 : V4L2_IDENT_CX23416;
686 return 0; 686 return 0;
687 } 687 }
688 if (chip->match_type == V4L2_CHIP_MATCH_I2C_DRIVER) 688 if (chip->match_type != V4L2_CHIP_MATCH_I2C_DRIVER &&
689 return ivtv_i2c_id(itv, chip->match_chip, VIDIOC_G_CHIP_IDENT, chip); 689 chip->match_type != V4L2_CHIP_MATCH_I2C_ADDR)
690 if (chip->match_type == V4L2_CHIP_MATCH_I2C_ADDR) 690 return -EINVAL;
691 return ivtv_call_i2c_client(itv, chip->match_chip, VIDIOC_G_CHIP_IDENT, chip); 691 /* TODO: is this correct? */
692 return -EINVAL; 692 return ivtv_call_all_err(itv, core, g_chip_ident, chip);
693} 693}
694 694
695#ifdef CONFIG_VIDEO_ADV_DEBUG 695#ifdef CONFIG_VIDEO_ADV_DEBUG
696static int ivtv_itvc(struct ivtv *itv, unsigned int cmd, void *arg) 696static int ivtv_itvc(struct ivtv *itv, unsigned int cmd, void *arg)
697{ 697{
698 struct v4l2_register *regs = arg; 698 struct v4l2_register *regs = arg;
699 unsigned long flags;
700 volatile u8 __iomem *reg_start; 699 volatile u8 __iomem *reg_start;
701 700
702 if (!capable(CAP_SYS_ADMIN)) 701 if (!capable(CAP_SYS_ADMIN))
@@ -711,12 +710,10 @@ static int ivtv_itvc(struct ivtv *itv, unsigned int cmd, void *arg)
711 else 710 else
712 return -EINVAL; 711 return -EINVAL;
713 712
714 spin_lock_irqsave(&ivtv_cards_lock, flags);
715 if (cmd == VIDIOC_DBG_G_REGISTER) 713 if (cmd == VIDIOC_DBG_G_REGISTER)
716 regs->val = readl(regs->reg + reg_start); 714 regs->val = readl(regs->reg + reg_start);
717 else 715 else
718 writel(regs->val, regs->reg + reg_start); 716 writel(regs->val, regs->reg + reg_start);
719 spin_unlock_irqrestore(&ivtv_cards_lock, flags);
720 return 0; 717 return 0;
721} 718}
722 719
@@ -726,9 +723,10 @@ static int ivtv_g_register(struct file *file, void *fh, struct v4l2_register *re
726 723
727 if (v4l2_chip_match_host(reg->match_type, reg->match_chip)) 724 if (v4l2_chip_match_host(reg->match_type, reg->match_chip))
728 return ivtv_itvc(itv, VIDIOC_DBG_G_REGISTER, reg); 725 return ivtv_itvc(itv, VIDIOC_DBG_G_REGISTER, reg);
729 if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER) 726 /* TODO: subdev errors should not be ignored, this should become a
730 return ivtv_i2c_id(itv, reg->match_chip, VIDIOC_DBG_G_REGISTER, reg); 727 subdev helper function. */
731 return ivtv_call_i2c_client(itv, reg->match_chip, VIDIOC_DBG_G_REGISTER, reg); 728 ivtv_call_all(itv, core, g_register, reg);
729 return 0;
732} 730}
733 731
734static int ivtv_s_register(struct file *file, void *fh, struct v4l2_register *reg) 732static int ivtv_s_register(struct file *file, void *fh, struct v4l2_register *reg)
@@ -737,9 +735,10 @@ static int ivtv_s_register(struct file *file, void *fh, struct v4l2_register *re
737 735
738 if (v4l2_chip_match_host(reg->match_type, reg->match_chip)) 736 if (v4l2_chip_match_host(reg->match_type, reg->match_chip))
739 return ivtv_itvc(itv, VIDIOC_DBG_S_REGISTER, reg); 737 return ivtv_itvc(itv, VIDIOC_DBG_S_REGISTER, reg);
740 if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER) 738 /* TODO: subdev errors should not be ignored, this should become a
741 return ivtv_i2c_id(itv, reg->match_chip, VIDIOC_DBG_S_REGISTER, reg); 739 subdev helper function. */
742 return ivtv_call_i2c_client(itv, reg->match_chip, VIDIOC_DBG_S_REGISTER, reg); 740 ivtv_call_all(itv, core, s_register, reg);
741 return 0;
743} 742}
744#endif 743#endif
745 744
@@ -884,12 +883,6 @@ static int ivtv_s_crop(struct file *file, void *fh, struct v4l2_crop *crop)
884 883
885 streamtype = id->type; 884 streamtype = id->type;
886 885
887 if (ivtv_debug & IVTV_DBGFLG_IOCTL) {
888 printk(KERN_INFO "ivtv%d ioctl: ", itv->num);
889 /* Should be replaced */
890 /* v4l_printk_ioctl(VIDIOC_S_CROP); */
891 }
892
893 if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && 886 if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
894 (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) { 887 (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) {
895 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) { 888 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
@@ -1050,7 +1043,7 @@ static int ivtv_s_output(struct file *file, void *fh, unsigned int outp)
1050 itv->active_output = outp; 1043 itv->active_output = outp;
1051 route.input = SAA7127_INPUT_TYPE_NORMAL; 1044 route.input = SAA7127_INPUT_TYPE_NORMAL;
1052 route.output = itv->card->video_outputs[outp].video_output; 1045 route.output = itv->card->video_outputs[outp].video_output;
1053 ivtv_saa7127(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route); 1046 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_routing, &route);
1054 1047
1055 return 0; 1048 return 0;
1056} 1049}
@@ -1062,7 +1055,7 @@ static int ivtv_g_frequency(struct file *file, void *fh, struct v4l2_frequency *
1062 if (vf->tuner != 0) 1055 if (vf->tuner != 0)
1063 return -EINVAL; 1056 return -EINVAL;
1064 1057
1065 ivtv_call_i2c_clients(itv, VIDIOC_G_FREQUENCY, vf); 1058 ivtv_call_all(itv, tuner, g_frequency, vf);
1066 return 0; 1059 return 0;
1067} 1060}
1068 1061
@@ -1075,7 +1068,7 @@ int ivtv_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
1075 1068
1076 ivtv_mute(itv); 1069 ivtv_mute(itv);
1077 IVTV_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency); 1070 IVTV_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency);
1078 ivtv_call_i2c_clients(itv, VIDIOC_S_FREQUENCY, vf); 1071 ivtv_call_all(itv, tuner, s_frequency, vf);
1079 ivtv_unmute(itv); 1072 ivtv_unmute(itv);
1080 return 0; 1073 return 0;
1081} 1074}
@@ -1123,14 +1116,14 @@ int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std)
1123 IVTV_DEBUG_INFO("Switching standard to %llx.\n", (unsigned long long)itv->std); 1116 IVTV_DEBUG_INFO("Switching standard to %llx.\n", (unsigned long long)itv->std);
1124 1117
1125 /* Tuner */ 1118 /* Tuner */
1126 ivtv_call_i2c_clients(itv, VIDIOC_S_STD, &itv->std); 1119 ivtv_call_all(itv, tuner, s_std, itv->std);
1127 1120
1128 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) { 1121 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
1129 /* set display standard */ 1122 /* set display standard */
1130 itv->std_out = *std; 1123 itv->std_out = *std;
1131 itv->is_out_60hz = itv->is_60hz; 1124 itv->is_out_60hz = itv->is_60hz;
1132 itv->is_out_50hz = itv->is_50hz; 1125 itv->is_out_50hz = itv->is_50hz;
1133 ivtv_call_i2c_clients(itv, VIDIOC_INT_S_STD_OUTPUT, &itv->std_out); 1126 ivtv_call_all(itv, video, s_std_output, itv->std_out);
1134 ivtv_vapi(itv, CX2341X_DEC_SET_STANDARD, 1, itv->is_out_50hz); 1127 ivtv_vapi(itv, CX2341X_DEC_SET_STANDARD, 1, itv->is_out_50hz);
1135 itv->main_rect.left = itv->main_rect.top = 0; 1128 itv->main_rect.left = itv->main_rect.top = 0;
1136 itv->main_rect.width = 720; 1129 itv->main_rect.width = 720;
@@ -1154,7 +1147,7 @@ static int ivtv_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
1154 if (vt->index != 0) 1147 if (vt->index != 0)
1155 return -EINVAL; 1148 return -EINVAL;
1156 1149
1157 ivtv_call_i2c_clients(itv, VIDIOC_S_TUNER, vt); 1150 ivtv_call_all(itv, tuner, s_tuner, vt);
1158 1151
1159 return 0; 1152 return 0;
1160} 1153}
@@ -1166,7 +1159,7 @@ static int ivtv_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
1166 if (vt->index != 0) 1159 if (vt->index != 0)
1167 return -EINVAL; 1160 return -EINVAL;
1168 1161
1169 ivtv_call_i2c_clients(itv, VIDIOC_G_TUNER, vt); 1162 ivtv_call_all(itv, tuner, g_tuner, vt);
1170 1163
1171 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) { 1164 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) {
1172 strlcpy(vt->name, "ivtv Radio Tuner", sizeof(vt->name)); 1165 strlcpy(vt->name, "ivtv Radio Tuner", sizeof(vt->name));
@@ -1444,14 +1437,15 @@ static int ivtv_log_status(struct file *file, void *fh)
1444 struct v4l2_audio audin; 1437 struct v4l2_audio audin;
1445 int i; 1438 int i;
1446 1439
1447 IVTV_INFO("================= START STATUS CARD #%d =================\n", itv->num); 1440 IVTV_INFO("================= START STATUS CARD #%d =================\n",
1441 itv->instance);
1448 IVTV_INFO("Version: %s Card: %s\n", IVTV_VERSION, itv->card_name); 1442 IVTV_INFO("Version: %s Card: %s\n", IVTV_VERSION, itv->card_name);
1449 if (itv->hw_flags & IVTV_HW_TVEEPROM) { 1443 if (itv->hw_flags & IVTV_HW_TVEEPROM) {
1450 struct tveeprom tv; 1444 struct tveeprom tv;
1451 1445
1452 ivtv_read_eeprom(itv, &tv); 1446 ivtv_read_eeprom(itv, &tv);
1453 } 1447 }
1454 ivtv_call_i2c_clients(itv, VIDIOC_LOG_STATUS, NULL); 1448 ivtv_call_all(itv, core, log_status);
1455 ivtv_get_input(itv, itv->active_input, &vidin); 1449 ivtv_get_input(itv, itv->active_input, &vidin);
1456 ivtv_get_audio_input(itv, itv->audio_input, &audin); 1450 ivtv_get_audio_input(itv, itv->audio_input, &audin);
1457 IVTV_INFO("Video Input: %s\n", vidin.name); 1451 IVTV_INFO("Video Input: %s\n", vidin.name);
@@ -1518,7 +1512,7 @@ static int ivtv_log_status(struct file *file, void *fh)
1518 } 1512 }
1519 IVTV_INFO("Tuner: %s\n", 1513 IVTV_INFO("Tuner: %s\n",
1520 test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV"); 1514 test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV");
1521 cx2341x_log_status(&itv->params, itv->name); 1515 cx2341x_log_status(&itv->params, itv->device.name);
1522 IVTV_INFO("Status flags: 0x%08lx\n", itv->i_flags); 1516 IVTV_INFO("Status flags: 0x%08lx\n", itv->i_flags);
1523 for (i = 0; i < IVTV_MAX_STREAMS; i++) { 1517 for (i = 0; i < IVTV_MAX_STREAMS; i++) {
1524 struct ivtv_stream *s = &itv->streams[i]; 1518 struct ivtv_stream *s = &itv->streams[i];
@@ -1530,8 +1524,11 @@ static int ivtv_log_status(struct file *file, void *fh)
1530 (s->buffers * s->buf_size) / 1024, s->buffers); 1524 (s->buffers * s->buf_size) / 1024, s->buffers);
1531 } 1525 }
1532 1526
1533 IVTV_INFO("Read MPG/VBI: %lld/%lld bytes\n", (long long)itv->mpg_data_received, (long long)itv->vbi_data_inserted); 1527 IVTV_INFO("Read MPG/VBI: %lld/%lld bytes\n",
1534 IVTV_INFO("================== END STATUS CARD #%d ==================\n", itv->num); 1528 (long long)itv->mpg_data_received,
1529 (long long)itv->vbi_data_inserted);
1530 IVTV_INFO("================== END STATUS CARD #%d ==================\n",
1531 itv->instance);
1535 1532
1536 return 0; 1533 return 0;
1537} 1534}
@@ -1736,7 +1733,7 @@ static int ivtv_default(struct file *file, void *fh, int cmd, void *arg)
1736 case VIDIOC_INT_S_AUDIO_ROUTING: { 1733 case VIDIOC_INT_S_AUDIO_ROUTING: {
1737 struct v4l2_routing *route = arg; 1734 struct v4l2_routing *route = arg;
1738 1735
1739 ivtv_i2c_hw(itv, itv->card->hw_audio, VIDIOC_INT_S_AUDIO_ROUTING, route); 1736 ivtv_call_hw(itv, itv->card->hw_audio, audio, s_routing, route);
1740 break; 1737 break;
1741 } 1738 }
1742 1739
@@ -1746,7 +1743,7 @@ static int ivtv_default(struct file *file, void *fh, int cmd, void *arg)
1746 if ((val == 0 && itv->options.newi2c) || (val & 0x01)) 1743 if ((val == 0 && itv->options.newi2c) || (val & 0x01))
1747 ivtv_reset_ir_gpio(itv); 1744 ivtv_reset_ir_gpio(itv);
1748 if (val & 0x02) 1745 if (val & 0x02)
1749 itv->video_dec_func(itv, cmd, NULL); 1746 v4l2_subdev_call(itv->sd_video, core, reset, 0);
1750 break; 1747 break;
1751 } 1748 }
1752 1749
diff --git a/drivers/media/video/ivtv/ivtv-routing.c b/drivers/media/video/ivtv/ivtv-routing.c
index 05564919b57..3fd30229449 100644
--- a/drivers/media/video/ivtv/ivtv-routing.c
+++ b/drivers/media/video/ivtv/ivtv-routing.c
@@ -47,13 +47,13 @@ void ivtv_audio_set_io(struct ivtv *itv)
47 route.output = 0; 47 route.output = 0;
48 if (itv->card->hw_muxer & IVTV_HW_M52790) 48 if (itv->card->hw_muxer & IVTV_HW_M52790)
49 route.output = M52790_OUT_STEREO; 49 route.output = M52790_OUT_STEREO;
50 ivtv_i2c_hw(itv, itv->card->hw_muxer, VIDIOC_INT_S_AUDIO_ROUTING, &route); 50 v4l2_subdev_call(itv->sd_muxer, audio, s_routing, &route);
51 51
52 route.input = in->audio_input; 52 route.input = in->audio_input;
53 route.output = 0; 53 route.output = 0;
54 if (itv->card->hw_audio & IVTV_HW_MSP34XX) 54 if (itv->card->hw_audio & IVTV_HW_MSP34XX)
55 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); 55 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
56 ivtv_i2c_hw(itv, itv->card->hw_audio, VIDIOC_INT_S_AUDIO_ROUTING, &route); 56 ivtv_call_hw(itv, itv->card->hw_audio, audio, s_routing, &route);
57} 57}
58 58
59/* Selects the video input and output according to the current 59/* Selects the video input and output according to the current
@@ -66,7 +66,7 @@ void ivtv_video_set_io(struct ivtv *itv)
66 66
67 route.input = itv->card->video_inputs[inp].video_input; 67 route.input = itv->card->video_inputs[inp].video_input;
68 route.output = 0; 68 route.output = 0;
69 itv->video_dec_func(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route); 69 v4l2_subdev_call(itv->sd_video, video, s_routing, &route);
70 70
71 type = itv->card->video_inputs[inp].video_type; 71 type = itv->card->video_inputs[inp].video_type;
72 72
@@ -79,7 +79,7 @@ void ivtv_video_set_io(struct ivtv *itv)
79 } 79 }
80 80
81 if (itv->card->hw_video & IVTV_HW_GPIO) 81 if (itv->card->hw_video & IVTV_HW_GPIO)
82 ivtv_gpio(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route); 82 ivtv_call_hw(itv, IVTV_HW_GPIO, video, s_routing, &route);
83 83
84 if (itv->card->hw_video & IVTV_HW_UPD64031A) { 84 if (itv->card->hw_video & IVTV_HW_UPD64031A) {
85 if (type == IVTV_CARD_INPUT_VID_TUNER || 85 if (type == IVTV_CARD_INPUT_VID_TUNER ||
@@ -92,7 +92,7 @@ void ivtv_video_set_io(struct ivtv *itv)
92 } 92 }
93 route.input |= itv->card->gr_config; 93 route.input |= itv->card->gr_config;
94 94
95 ivtv_upd64031a(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route); 95 ivtv_call_hw(itv, IVTV_HW_UPD64031A, video, s_routing, &route);
96 } 96 }
97 97
98 if (itv->card->hw_video & IVTV_HW_UPD6408X) { 98 if (itv->card->hw_video & IVTV_HW_UPD6408X) {
@@ -110,6 +110,6 @@ void ivtv_video_set_io(struct ivtv *itv)
110 route.input |= UPD64083_EXT_Y_ADC; 110 route.input |= UPD64083_EXT_Y_ADC;
111 } 111 }
112 } 112 }
113 ivtv_upd64083(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route); 113 ivtv_call_hw(itv, IVTV_HW_UPD6408X, video, s_routing, &route);
114 } 114 }
115} 115}
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index 9b7aa79eb26..76279ed30da 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -172,7 +172,7 @@ static int ivtv_prep_dev(struct ivtv *itv, int type)
172{ 172{
173 struct ivtv_stream *s = &itv->streams[type]; 173 struct ivtv_stream *s = &itv->streams[type];
174 int num_offset = ivtv_stream_info[type].num_offset; 174 int num_offset = ivtv_stream_info[type].num_offset;
175 int num = itv->num + ivtv_first_minor + num_offset; 175 int num = itv->instance + ivtv_first_minor + num_offset;
176 176
177 /* These four fields are always initialized. If v4l2dev == NULL, then 177 /* These four fields are always initialized. If v4l2dev == NULL, then
178 this stream is not in use. In that case no other fields but these 178 this stream is not in use. In that case no other fields but these
@@ -205,8 +205,8 @@ static int ivtv_prep_dev(struct ivtv *itv, int type)
205 return -ENOMEM; 205 return -ENOMEM;
206 } 206 }
207 207
208 snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "ivtv%d %s", 208 snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "%s %s",
209 itv->num, s->name); 209 itv->device.name, s->name);
210 210
211 s->v4l2dev->num = num; 211 s->v4l2dev->num = num;
212 s->v4l2dev->parent = &itv->dev->dev; 212 s->v4l2dev->parent = &itv->dev->dev;
@@ -260,6 +260,7 @@ static int ivtv_reg_dev(struct ivtv *itv, int type)
260 if (s_mpg->v4l2dev) 260 if (s_mpg->v4l2dev)
261 num = s_mpg->v4l2dev->num + ivtv_stream_info[type].num_offset; 261 num = s_mpg->v4l2dev->num + ivtv_stream_info[type].num_offset;
262 } 262 }
263 video_set_drvdata(s->v4l2dev, s);
263 264
264 /* Register device. First try the desired minor, then any free one. */ 265 /* Register device. First try the desired minor, then any free one. */
265 if (video_register_device(s->v4l2dev, vfl_type, num)) { 266 if (video_register_device(s->v4l2dev, vfl_type, num)) {
@@ -343,7 +344,7 @@ static void ivtv_vbi_setup(struct ivtv *itv)
343 ivtv_vapi(itv, CX2341X_ENC_SET_VBI_LINE, 5, 0xffff , 0, 0, 0, 0); 344 ivtv_vapi(itv, CX2341X_ENC_SET_VBI_LINE, 5, 0xffff , 0, 0, 0, 0);
344 345
345 /* setup VBI registers */ 346 /* setup VBI registers */
346 itv->video_dec_func(itv, VIDIOC_S_FMT, &itv->vbi.in); 347 v4l2_subdev_call(itv->sd_video, video, s_fmt, &itv->vbi.in);
347 348
348 /* determine number of lines and total number of VBI bytes. 349 /* determine number of lines and total number of VBI bytes.
349 A raw line takes 1443 bytes: 2 * 720 + 4 byte frame header - 1 350 A raw line takes 1443 bytes: 2 * 720 + 4 byte frame header - 1
@@ -577,10 +578,10 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
577 clear_bit(IVTV_F_I_EOS, &itv->i_flags); 578 clear_bit(IVTV_F_I_EOS, &itv->i_flags);
578 579
579 /* Initialize Digitizer for Capture */ 580 /* Initialize Digitizer for Capture */
580 itv->video_dec_func(itv, VIDIOC_STREAMOFF, NULL); 581 v4l2_subdev_call(itv->sd_video, video, s_stream, 0);
581 ivtv_msleep_timeout(300, 1); 582 ivtv_msleep_timeout(300, 1);
582 ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0); 583 ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0);
583 itv->video_dec_func(itv, VIDIOC_STREAMON, NULL); 584 v4l2_subdev_call(itv->sd_video, video, s_stream, 1);
584 } 585 }
585 586
586 /* begin_capture */ 587 /* begin_capture */
diff --git a/drivers/media/video/ivtv/ivtv-vbi.c b/drivers/media/video/ivtv/ivtv-vbi.c
index 4a37a7d2e69..5c5d1c462fe 100644
--- a/drivers/media/video/ivtv/ivtv-vbi.c
+++ b/drivers/media/video/ivtv/ivtv-vbi.c
@@ -21,6 +21,7 @@
21#include "ivtv-i2c.h" 21#include "ivtv-i2c.h"
22#include "ivtv-ioctl.h" 22#include "ivtv-ioctl.h"
23#include "ivtv-queue.h" 23#include "ivtv-queue.h"
24#include "ivtv-cards.h"
24#include "ivtv-vbi.h" 25#include "ivtv-vbi.h"
25 26
26static void ivtv_set_vps(struct ivtv *itv, int enabled) 27static void ivtv_set_vps(struct ivtv *itv, int enabled)
@@ -37,7 +38,7 @@ static void ivtv_set_vps(struct ivtv *itv, int enabled)
37 data.data[9] = itv->vbi.vps_payload.data[2]; 38 data.data[9] = itv->vbi.vps_payload.data[2];
38 data.data[10] = itv->vbi.vps_payload.data[3]; 39 data.data[10] = itv->vbi.vps_payload.data[3];
39 data.data[11] = itv->vbi.vps_payload.data[4]; 40 data.data[11] = itv->vbi.vps_payload.data[4];
40 ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data); 41 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_vbi_data, &data);
41} 42}
42 43
43static void ivtv_set_cc(struct ivtv *itv, int mode, const struct vbi_cc *cc) 44static void ivtv_set_cc(struct ivtv *itv, int mode, const struct vbi_cc *cc)
@@ -51,12 +52,12 @@ static void ivtv_set_cc(struct ivtv *itv, int mode, const struct vbi_cc *cc)
51 data.line = (mode & 1) ? 21 : 0; 52 data.line = (mode & 1) ? 21 : 0;
52 data.data[0] = cc->odd[0]; 53 data.data[0] = cc->odd[0];
53 data.data[1] = cc->odd[1]; 54 data.data[1] = cc->odd[1];
54 ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data); 55 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_vbi_data, &data);
55 data.field = 1; 56 data.field = 1;
56 data.line = (mode & 2) ? 21 : 0; 57 data.line = (mode & 2) ? 21 : 0;
57 data.data[0] = cc->even[0]; 58 data.data[0] = cc->even[0];
58 data.data[1] = cc->even[1]; 59 data.data[1] = cc->even[1];
59 ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data); 60 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_vbi_data, &data);
60} 61}
61 62
62static void ivtv_set_wss(struct ivtv *itv, int enabled, int mode) 63static void ivtv_set_wss(struct ivtv *itv, int enabled, int mode)
@@ -79,7 +80,7 @@ static void ivtv_set_wss(struct ivtv *itv, int enabled, int mode)
79 data.line = enabled ? 23 : 0; 80 data.line = enabled ? 23 : 0;
80 data.data[0] = mode & 0xff; 81 data.data[0] = mode & 0xff;
81 data.data[1] = (mode >> 8) & 0xff; 82 data.data[1] = (mode >> 8) & 0xff;
82 ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data); 83 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_vbi_data, &data);
83} 84}
84 85
85static int odd_parity(u8 c) 86static int odd_parity(u8 c)
@@ -313,7 +314,7 @@ static u32 compress_sliced_buf(struct ivtv *itv, u32 line, u8 *buf, u32 size, u8
313 continue; 314 continue;
314 } 315 }
315 vbi.p = p + 4; 316 vbi.p = p + 4;
316 itv->video_dec_func(itv, VIDIOC_INT_DECODE_VBI_LINE, &vbi); 317 v4l2_subdev_call(itv->sd_video, video, decode_vbi_line, &vbi);
317 if (vbi.type && !(lines & (1 << vbi.line))) { 318 if (vbi.type && !(lines & (1 << vbi.line))) {
318 lines |= 1 << vbi.line; 319 lines |= 1 << vbi.line;
319 itv->vbi.sliced_data[line].id = vbi.type; 320 itv->vbi.sliced_data[line].id = vbi.type;
@@ -437,7 +438,7 @@ void ivtv_vbi_work_handler(struct ivtv *itv)
437 data.id = V4L2_SLICED_WSS_625; 438 data.id = V4L2_SLICED_WSS_625;
438 data.field = 0; 439 data.field = 0;
439 440
440 if (itv->video_dec_func(itv, VIDIOC_INT_G_VBI_DATA, &data) == 0) { 441 if (v4l2_subdev_call(itv->sd_video, video, g_vbi_data, &data) == 0) {
441 ivtv_set_wss(itv, 1, data.data[0] & 0xf); 442 ivtv_set_wss(itv, 1, data.data[0] & 0xf);
442 vi->wss_missing_cnt = 0; 443 vi->wss_missing_cnt = 0;
443 } else if (vi->wss_missing_cnt == 4) { 444 } else if (vi->wss_missing_cnt == 4) {
@@ -451,13 +452,13 @@ void ivtv_vbi_work_handler(struct ivtv *itv)
451 452
452 data.id = V4L2_SLICED_CAPTION_525; 453 data.id = V4L2_SLICED_CAPTION_525;
453 data.field = 0; 454 data.field = 0;
454 if (itv->video_dec_func(itv, VIDIOC_INT_G_VBI_DATA, &data) == 0) { 455 if (v4l2_subdev_call(itv->sd_video, video, g_vbi_data, &data) == 0) {
455 mode |= 1; 456 mode |= 1;
456 cc.odd[0] = data.data[0]; 457 cc.odd[0] = data.data[0];
457 cc.odd[1] = data.data[1]; 458 cc.odd[1] = data.data[1];
458 } 459 }
459 data.field = 1; 460 data.field = 1;
460 if (itv->video_dec_func(itv, VIDIOC_INT_G_VBI_DATA, &data) == 0) { 461 if (v4l2_subdev_call(itv->sd_video, video, g_vbi_data, &data) == 0) {
461 mode |= 2; 462 mode |= 2;
462 cc.even[0] = data.data[0]; 463 cc.even[0] = data.data[0];
463 cc.even[1] = data.data[1]; 464 cc.even[1] = data.data[1];
diff --git a/drivers/media/video/ivtv/ivtvfb.c b/drivers/media/video/ivtv/ivtvfb.c
index 921e281876f..36abd2aef6f 100644
--- a/drivers/media/video/ivtv/ivtvfb.c
+++ b/drivers/media/video/ivtv/ivtvfb.c
@@ -48,6 +48,7 @@
48#endif 48#endif
49 49
50#include "ivtv-driver.h" 50#include "ivtv-driver.h"
51#include "ivtv-cards.h"
51#include "ivtv-i2c.h" 52#include "ivtv-i2c.h"
52#include "ivtv-udma.h" 53#include "ivtv-udma.h"
53#include "ivtv-mailbox.h" 54#include "ivtv-mailbox.h"
@@ -121,15 +122,15 @@ MODULE_LICENSE("GPL");
121#define IVTVFB_DEBUG(x, type, fmt, args...) \ 122#define IVTVFB_DEBUG(x, type, fmt, args...) \
122 do { \ 123 do { \
123 if ((x) & ivtvfb_debug) \ 124 if ((x) & ivtvfb_debug) \
124 printk(KERN_INFO "ivtvfb%d " type ": " fmt, itv->num , ## args); \ 125 printk(KERN_INFO "ivtvfb%d " type ": " fmt, itv->instance , ## args); \
125 } while (0) 126 } while (0)
126#define IVTVFB_DEBUG_WARN(fmt, args...) IVTVFB_DEBUG(IVTVFB_DBGFLG_WARN, "warning", fmt , ## args) 127#define IVTVFB_DEBUG_WARN(fmt, args...) IVTVFB_DEBUG(IVTVFB_DBGFLG_WARN, "warning", fmt , ## args)
127#define IVTVFB_DEBUG_INFO(fmt, args...) IVTVFB_DEBUG(IVTVFB_DBGFLG_INFO, "info", fmt , ## args) 128#define IVTVFB_DEBUG_INFO(fmt, args...) IVTVFB_DEBUG(IVTVFB_DBGFLG_INFO, "info", fmt , ## args)
128 129
129/* Standard kernel messages */ 130/* Standard kernel messages */
130#define IVTVFB_ERR(fmt, args...) printk(KERN_ERR "ivtvfb%d: " fmt, itv->num , ## args) 131#define IVTVFB_ERR(fmt, args...) printk(KERN_ERR "ivtvfb%d: " fmt, itv->instance , ## args)
131#define IVTVFB_WARN(fmt, args...) printk(KERN_WARNING "ivtvfb%d: " fmt, itv->num , ## args) 132#define IVTVFB_WARN(fmt, args...) printk(KERN_WARNING "ivtvfb%d: " fmt, itv->instance , ## args)
132#define IVTVFB_INFO(fmt, args...) printk(KERN_INFO "ivtvfb%d: " fmt, itv->num , ## args) 133#define IVTVFB_INFO(fmt, args...) printk(KERN_INFO "ivtvfb%d: " fmt, itv->instance , ## args)
133 134
134/* --------------------------------------------------------------------- */ 135/* --------------------------------------------------------------------- */
135 136
@@ -895,16 +896,16 @@ static int ivtvfb_blank(int blank_mode, struct fb_info *info)
895 switch (blank_mode) { 896 switch (blank_mode) {
896 case FB_BLANK_UNBLANK: 897 case FB_BLANK_UNBLANK:
897 ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, 1); 898 ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, 1);
898 ivtv_saa7127(itv, VIDIOC_STREAMON, NULL); 899 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 1);
899 break; 900 break;
900 case FB_BLANK_NORMAL: 901 case FB_BLANK_NORMAL:
901 case FB_BLANK_HSYNC_SUSPEND: 902 case FB_BLANK_HSYNC_SUSPEND:
902 case FB_BLANK_VSYNC_SUSPEND: 903 case FB_BLANK_VSYNC_SUSPEND:
903 ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, 0); 904 ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, 0);
904 ivtv_saa7127(itv, VIDIOC_STREAMON, NULL); 905 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 1);
905 break; 906 break;
906 case FB_BLANK_POWERDOWN: 907 case FB_BLANK_POWERDOWN:
907 ivtv_saa7127(itv, VIDIOC_STREAMOFF, NULL); 908 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 0);
908 ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, 0); 909 ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, 0);
909 break; 910 break;
910 } 911 }
@@ -1188,10 +1189,45 @@ static int ivtvfb_init_card(struct ivtv *itv)
1188 1189
1189} 1190}
1190 1191
1192static int __init ivtvfb_callback_init(struct device *dev, void *p)
1193{
1194 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
1195 struct ivtv *itv = container_of(v4l2_dev, struct ivtv, device);
1196
1197 if (itv && (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) {
1198 if (ivtvfb_init_card(itv) == 0) {
1199 IVTVFB_INFO("Framebuffer registered on %s\n",
1200 itv->device.name);
1201 (*(int *)p)++;
1202 }
1203 }
1204 return 0;
1205}
1206
1207static int ivtvfb_callback_cleanup(struct device *dev, void *p)
1208{
1209 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
1210 struct ivtv *itv = container_of(v4l2_dev, struct ivtv, device);
1211
1212 if (itv && (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) {
1213 if (unregister_framebuffer(&itv->osd_info->ivtvfb_info)) {
1214 IVTVFB_WARN("Framebuffer %d is in use, cannot unload\n",
1215 itv->instance);
1216 return 0;
1217 }
1218 IVTVFB_INFO("Unregister framebuffer %d\n", itv->instance);
1219 ivtvfb_blank(FB_BLANK_POWERDOWN, &itv->osd_info->ivtvfb_info);
1220 ivtvfb_release_buffers(itv);
1221 itv->osd_video_pbase = 0;
1222 }
1223 return 0;
1224}
1225
1191static int __init ivtvfb_init(void) 1226static int __init ivtvfb_init(void)
1192{ 1227{
1193 struct ivtv *itv; 1228 struct device_driver *drv;
1194 int i, registered = 0; 1229 int registered = 0;
1230 int err;
1195 1231
1196 if (ivtvfb_card_id < -1 || ivtvfb_card_id >= IVTV_MAX_CARDS) { 1232 if (ivtvfb_card_id < -1 || ivtvfb_card_id >= IVTV_MAX_CARDS) {
1197 printk(KERN_ERR "ivtvfb: ivtvfb_card_id parameter is out of range (valid range: -1 - %d)\n", 1233 printk(KERN_ERR "ivtvfb: ivtvfb_card_id parameter is out of range (valid range: -1 - %d)\n",
@@ -1199,20 +1235,11 @@ static int __init ivtvfb_init(void)
1199 return -EINVAL; 1235 return -EINVAL;
1200 } 1236 }
1201 1237
1202 /* Locate & initialise all cards supporting an OSD. */ 1238 drv = driver_find("ivtv", &pci_bus_type);
1203 for (i = 0; i < ivtv_cards_active; i++) { 1239 err = driver_for_each_device(drv, NULL, &registered, ivtvfb_callback_init);
1204 if (ivtvfb_card_id != -1 && i != ivtvfb_card_id) 1240 put_driver(drv);
1205 continue;
1206 itv = ivtv_cards[i];
1207 if (itv && (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) {
1208 if (ivtvfb_init_card(itv) == 0) {
1209 IVTVFB_INFO("Framebuffer registered on ivtv card id %d\n", i);
1210 registered++;
1211 }
1212 }
1213 }
1214 if (!registered) { 1241 if (!registered) {
1215 printk(KERN_ERR "ivtvfb: no cards found"); 1242 printk(KERN_ERR "ivtvfb: no cards found\n");
1216 return -ENODEV; 1243 return -ENODEV;
1217 } 1244 }
1218 return 0; 1245 return 0;
@@ -1220,24 +1247,14 @@ static int __init ivtvfb_init(void)
1220 1247
1221static void ivtvfb_cleanup(void) 1248static void ivtvfb_cleanup(void)
1222{ 1249{
1223 struct ivtv *itv; 1250 struct device_driver *drv;
1224 int i; 1251 int err;
1225 1252
1226 printk(KERN_INFO "ivtvfb: Unloading framebuffer module\n"); 1253 printk(KERN_INFO "ivtvfb: Unloading framebuffer module\n");
1227 1254
1228 for (i = 0; i < ivtv_cards_active; i++) { 1255 drv = driver_find("ivtv", &pci_bus_type);
1229 itv = ivtv_cards[i]; 1256 err = driver_for_each_device(drv, NULL, NULL, ivtvfb_callback_cleanup);
1230 if (itv && (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) && itv->osd_info) { 1257 put_driver(drv);
1231 if (unregister_framebuffer(&itv->osd_info->ivtvfb_info)) {
1232 IVTVFB_WARN("Framebuffer %d is in use, cannot unload\n", i);
1233 return;
1234 }
1235 IVTVFB_DEBUG_INFO("Unregister framebuffer %d\n", i);
1236 ivtvfb_blank(FB_BLANK_POWERDOWN, &itv->osd_info->ivtvfb_info);
1237 ivtvfb_release_buffers(itv);
1238 itv->osd_video_pbase = 0;
1239 }
1240 }
1241} 1258}
1242 1259
1243module_init(ivtvfb_init); 1260module_init(ivtvfb_init);