]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/media/video/pvrusb2/pvrusb2-hdw.c
V4L/DVB (4595): Remove CONFIG_VIDEO_PVRUSB2_24XXX from pvrusb2 driver
[karo-tx-linux.git] / drivers / media / video / pvrusb2 / pvrusb2-hdw.c
index e8ea472fe2d0e6402af0b1983d6603ad0dc3b0e7..6ab6fd187340db617583cd63326074225fedba69 100644 (file)
@@ -38,9 +38,7 @@
 
 struct usb_device_id pvr2_device_table[] = {
        [PVR2_HDW_TYPE_29XXX] = { USB_DEVICE(0x2040, 0x2900) },
-#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
        [PVR2_HDW_TYPE_24XXX] = { USB_DEVICE(0x2040, 0x2400) },
-#endif
        { }
 };
 
@@ -48,9 +46,7 @@ MODULE_DEVICE_TABLE(usb, pvr2_device_table);
 
 static const char *pvr2_device_names[] = {
        [PVR2_HDW_TYPE_29XXX] = "WinTV PVR USB2 Model Category 29xxxx",
-#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
        [PVR2_HDW_TYPE_24XXX] = "WinTV PVR USB2 Model Category 24xxxx",
-#endif
 };
 
 struct pvr2_string_table {
@@ -58,22 +54,18 @@ struct pvr2_string_table {
        unsigned int cnt;
 };
 
-#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
 // Names of other client modules to request for 24xxx model hardware
 static const char *pvr2_client_24xxx[] = {
        "cx25840",
        "tuner",
-       "tda9887",
        "wm8775",
 };
-#endif
 
 // Names of other client modules to request for 29xxx model hardware
 static const char *pvr2_client_29xxx[] = {
        "msp3400",
        "saa7115",
        "tuner",
-       "tda9887",
 };
 
 static struct pvr2_string_table pvr2_client_lists[] = {
@@ -81,16 +73,14 @@ static struct pvr2_string_table pvr2_client_lists[] = {
                pvr2_client_29xxx,
                sizeof(pvr2_client_29xxx)/sizeof(pvr2_client_29xxx[0]),
        },
-#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
        [PVR2_HDW_TYPE_24XXX] = {
                pvr2_client_24xxx,
                sizeof(pvr2_client_24xxx)/sizeof(pvr2_client_24xxx[0]),
        },
-#endif
 };
 
-static struct pvr2_hdw *unit_pointers[PVR_NUM] = {[ 0 ... PVR_NUM-1 ] = 0};
-DECLARE_MUTEX(pvr2_unit_sem);
+static struct pvr2_hdw *unit_pointers[PVR_NUM] = {[ 0 ... PVR_NUM-1 ] = NULL};
+static DECLARE_MUTEX(pvr2_unit_sem);
 
 static int ctlchg = 0;
 static int initusbreset = 1;
@@ -130,39 +120,108 @@ MODULE_PARM_DESC(tolerance,"specify stream error tolerance");
 /* size of a firmware chunk */
 #define FIRMWARE_CHUNK_SIZE 0x2000
 
-
-static const char *control_values_srate[] = {
-       [PVR2_CVAL_SRATE_48]   = "48KHz",
-       [PVR2_CVAL_SRATE_44_1] = "44.1KHz",
+/* Define the list of additional controls we'll dynamically construct based
+   on query of the cx2341x module. */
+struct pvr2_mpeg_ids {
+       const char *strid;
+       int id;
 };
-
-
-static const char *control_values_audiobitrate[] = {
-       [PVR2_CVAL_AUDIOBITRATE_384] = "384kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_320] = "320kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_256] = "256kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_224] = "224kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_192] = "192kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_160] = "160kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_128] = "128kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_112] = "112kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_96]  = "96kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_80]  = "80kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_64]  = "64kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_56]  = "56kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_48]  = "48kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_32]  = "32kb/s",
-       [PVR2_CVAL_AUDIOBITRATE_VBR] = "VBR",
+static const struct pvr2_mpeg_ids mpeg_ids[] = {
+       {
+               .strid = "audio_layer",
+               .id = V4L2_CID_MPEG_AUDIO_ENCODING,
+       },{
+               .strid = "audio_bitrate",
+               .id = V4L2_CID_MPEG_AUDIO_L2_BITRATE,
+       },{
+               /* Already using audio_mode elsewhere :-( */
+               .strid = "mpeg_audio_mode",
+               .id = V4L2_CID_MPEG_AUDIO_MODE,
+       },{
+               .strid = "mpeg_audio_mode_extension",
+               .id = V4L2_CID_MPEG_AUDIO_MODE_EXTENSION,
+       },{
+               .strid = "audio_emphasis",
+               .id = V4L2_CID_MPEG_AUDIO_EMPHASIS,
+       },{
+               .strid = "audio_crc",
+               .id = V4L2_CID_MPEG_AUDIO_CRC,
+       },{
+               .strid = "video_aspect",
+               .id = V4L2_CID_MPEG_VIDEO_ASPECT,
+       },{
+               .strid = "video_b_frames",
+               .id = V4L2_CID_MPEG_VIDEO_B_FRAMES,
+       },{
+               .strid = "video_gop_size",
+               .id = V4L2_CID_MPEG_VIDEO_GOP_SIZE,
+       },{
+               .strid = "video_gop_closure",
+               .id = V4L2_CID_MPEG_VIDEO_GOP_CLOSURE,
+       },{
+               .strid = "video_pulldown",
+               .id = V4L2_CID_MPEG_VIDEO_PULLDOWN,
+       },{
+               .strid = "video_bitrate_mode",
+               .id = V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
+       },{
+               .strid = "video_bitrate",
+               .id = V4L2_CID_MPEG_VIDEO_BITRATE,
+       },{
+               .strid = "video_bitrate_peak",
+               .id = V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
+       },{
+               .strid = "video_temporal_decimation",
+               .id = V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION,
+       },{
+               .strid = "stream_type",
+               .id = V4L2_CID_MPEG_STREAM_TYPE,
+       },{
+               .strid = "video_spatial_filter_mode",
+               .id = V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE,
+       },{
+               .strid = "video_spatial_filter",
+               .id = V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER,
+       },{
+               .strid = "video_luma_spatial_filter_type",
+               .id = V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE,
+       },{
+               .strid = "video_chroma_spatial_filter_type",
+               .id = V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE,
+       },{
+               .strid = "video_temporal_filter_mode",
+               .id = V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE,
+       },{
+               .strid = "video_temporal_filter",
+               .id = V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER,
+       },{
+               .strid = "video_median_filter_type",
+               .id = V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE,
+       },{
+               .strid = "video_luma_median_filter_top",
+               .id = V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP,
+       },{
+               .strid = "video_luma_median_filter_bottom",
+               .id = V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM,
+       },{
+               .strid = "video_chroma_median_filter_top",
+               .id = V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP,
+       },{
+               .strid = "video_chroma_median_filter_bottom",
+               .id = V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM,
+       }
 };
+#define MPEGDEF_COUNT (sizeof(mpeg_ids)/sizeof(mpeg_ids[0]))
 
 
-static const char *control_values_audioemphasis[] = {
-       [PVR2_CVAL_AUDIOEMPHASIS_NONE]  = "None",
-       [PVR2_CVAL_AUDIOEMPHASIS_50_15] = "50/15us",
-       [PVR2_CVAL_AUDIOEMPHASIS_CCITT] = "CCITT J.17",
+static const char *control_values_srate[] = {
+       [V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100]   = "44.1 kHz",
+       [V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000]   = "48 kHz",
+       [V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000]   = "32 kHz",
 };
 
 
+
 static const char *control_values_input[] = {
        [PVR2_CVAL_INPUT_TV]        = "television",  /*xawtv needs this name*/
        [PVR2_CVAL_INPUT_RADIO]     = "radio",
@@ -195,6 +254,25 @@ static const char *control_values_subsystem[] = {
        [PVR2_SUBSYS_B_ENC_RUN] = "enc_run",
 };
 
+static int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl);
+static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw);
+static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw);
+static unsigned int pvr2_hdw_get_signal_status_internal(struct pvr2_hdw *hdw);
+static void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw);
+static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw);
+static void pvr2_hdw_render_useless_unlocked(struct pvr2_hdw *hdw);
+static void pvr2_hdw_subsys_bit_chg_no_lock(struct pvr2_hdw *hdw,
+                                           unsigned long msk,
+                                           unsigned long val);
+static void pvr2_hdw_subsys_stream_bit_chg_no_lock(struct pvr2_hdw *hdw,
+                                                  unsigned long msk,
+                                                  unsigned long val);
+static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
+                               unsigned int timeout,int probe_fl,
+                               void *write_data,unsigned int write_len,
+                               void *read_data,unsigned int read_len);
+static int pvr2_write_u16(struct pvr2_hdw *hdw, u16 data, int res);
+static int pvr2_write_u8(struct pvr2_hdw *hdw, u8 data, int res);
 
 static int ctrl_channelfreq_get(struct pvr2_ctrl *cptr,int *vp)
 {
@@ -277,6 +355,98 @@ static int ctrl_freq_set(struct pvr2_ctrl *cptr,int m,int v)
        return 0;
 }
 
+static int ctrl_hres_max_get(struct pvr2_ctrl *cptr,int *vp)
+{
+       /* If we're dealing with a 24xxx device, force the horizontal
+          maximum to be 720 no matter what, since we can't get the device
+          to work properly with any other value.  Otherwise just return
+          the normal value. */
+       *vp = cptr->info->def.type_int.max_value;
+       if (cptr->hdw->hdw_type == PVR2_HDW_TYPE_24XXX) *vp = 720;
+       return 0;
+}
+
+static int ctrl_hres_min_get(struct pvr2_ctrl *cptr,int *vp)
+{
+       /* If we're dealing with a 24xxx device, force the horizontal
+          minimum to be 720 no matter what, since we can't get the device
+          to work properly with any other value.  Otherwise just return
+          the normal value. */
+       *vp = cptr->info->def.type_int.min_value;
+       if (cptr->hdw->hdw_type == PVR2_HDW_TYPE_24XXX) *vp = 720;
+       return 0;
+}
+
+static int ctrl_cx2341x_is_dirty(struct pvr2_ctrl *cptr)
+{
+       return cptr->hdw->enc_stale != 0;
+}
+
+static void ctrl_cx2341x_clear_dirty(struct pvr2_ctrl *cptr)
+{
+       cptr->hdw->enc_stale = 0;
+}
+
+static int ctrl_cx2341x_get(struct pvr2_ctrl *cptr,int *vp)
+{
+       int ret;
+       struct v4l2_ext_controls cs;
+       struct v4l2_ext_control c1;
+       memset(&cs,0,sizeof(cs));
+       memset(&c1,0,sizeof(c1));
+       cs.controls = &c1;
+       cs.count = 1;
+       c1.id = cptr->info->v4l_id;
+       ret = cx2341x_ext_ctrls(&cptr->hdw->enc_ctl_state,&cs,
+                               VIDIOC_G_EXT_CTRLS);
+       if (ret) return ret;
+       *vp = c1.value;
+       return 0;
+}
+
+static int ctrl_cx2341x_set(struct pvr2_ctrl *cptr,int m,int v)
+{
+       int ret;
+       struct v4l2_ext_controls cs;
+       struct v4l2_ext_control c1;
+       memset(&cs,0,sizeof(cs));
+       memset(&c1,0,sizeof(c1));
+       cs.controls = &c1;
+       cs.count = 1;
+       c1.id = cptr->info->v4l_id;
+       c1.value = v;
+       ret = cx2341x_ext_ctrls(&cptr->hdw->enc_ctl_state,&cs,
+                               VIDIOC_S_EXT_CTRLS);
+       if (ret) return ret;
+       cptr->hdw->enc_stale = !0;
+       return 0;
+}
+
+static unsigned int ctrl_cx2341x_getv4lflags(struct pvr2_ctrl *cptr)
+{
+       struct v4l2_queryctrl qctrl;
+       struct pvr2_ctl_info *info;
+       qctrl.id = cptr->info->v4l_id;
+       cx2341x_ctrl_query(&cptr->hdw->enc_ctl_state,&qctrl);
+       /* Strip out the const so we can adjust a function pointer.  It's
+          OK to do this here because we know this is a dynamically created
+          control, so the underlying storage for the info pointer is (a)
+          private to us, and (b) not in read-only storage.  Either we do
+          this or we significantly complicate the underlying control
+          implementation. */
+       info = (struct pvr2_ctl_info *)(cptr->info);
+       if (qctrl.flags & V4L2_CTRL_FLAG_READ_ONLY) {
+               if (info->set_value) {
+                       info->set_value = NULL;
+               }
+       } else {
+               if (!(info->set_value)) {
+                       info->set_value = ctrl_cx2341x_set;
+               }
+       }
+       return qctrl.flags;
+}
+
 static int ctrl_streamingenabled_get(struct pvr2_ctrl *cptr,int *vp)
 {
        *vp = cptr->hdw->flag_streaming_enabled;
@@ -436,6 +606,9 @@ static void ctrl_stdenumcur_clear_dirty(struct pvr2_ctrl *cptr)
        .def.type_enum.count = (sizeof(tab)/sizeof((tab)[0])), \
        .def.type_enum.value_names = tab
 
+#define DEFBOOL \
+       .type = pvr2_ctl_bool
+
 #define DEFMASK(msk,tab) \
        .type = pvr2_ctl_bitmask, \
        .def.type_bitmask.valid_bits = msk, \
@@ -472,14 +645,6 @@ VCREATE_FUNCS(audiomode)
 VCREATE_FUNCS(res_hor)
 VCREATE_FUNCS(res_ver)
 VCREATE_FUNCS(srate)
-VCREATE_FUNCS(audiobitrate)
-VCREATE_FUNCS(audiocrc)
-VCREATE_FUNCS(audioemphasis)
-VCREATE_FUNCS(vbr)
-VCREATE_FUNCS(videobitrate)
-VCREATE_FUNCS(videopeak)
-VCREATE_FUNCS(interlace)
-VCREATE_FUNCS(audiolayer)
 
 #define MIN_FREQ 55250000L
 #define MAX_FREQ 850000000L
@@ -548,7 +713,7 @@ static const struct pvr2_ctl_info control_defs[] = {
                .name = "mute",
                .default_value = 0,
                DEFREF(mute),
-               DEFINT(0,1),
+               DEFBOOL,
        },{
                .desc = "Video Source",
                .name = "input",
@@ -570,6 +735,10 @@ static const struct pvr2_ctl_info control_defs[] = {
                .default_value = 720,
                DEFREF(res_hor),
                DEFINT(320,720),
+               /* Hook in check for clamp on horizontal resolution in
+                  order to avoid unsolved problem involving cx25840. */
+               .get_max_value = ctrl_hres_max_get,
+               .get_min_value = ctrl_hres_min_get,
        },{
                .desc = "Vertical capture resolution",
                .name = "resolution_ver",
@@ -578,67 +747,12 @@ static const struct pvr2_ctl_info control_defs[] = {
                DEFREF(res_ver),
                DEFINT(200,625),
        },{
-               .v4l_id = V4L2_CID_PVR_SRATE,
-               .desc = "Sample rate",
+               .v4l_id = V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ,
+               .default_value = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000,
+               .desc = "Audio Sampling Frequency",
                .name = "srate",
-               .default_value = PVR2_CVAL_SRATE_48,
                DEFREF(srate),
                DEFENUM(control_values_srate),
-       },{
-               .v4l_id = V4L2_CID_PVR_AUDIOBITRATE,
-               .desc = "Audio Bitrate",
-               .name = "audio_bitrate",
-               .default_value = PVR2_CVAL_AUDIOBITRATE_224,
-               DEFREF(audiobitrate),
-               DEFENUM(control_values_audiobitrate),
-       },{
-               .v4l_id = V4L2_CID_PVR_AUDIOCRC,
-               .desc = "Audio CRC",
-               .name = "audio_crc",
-               .default_value = 1,
-               DEFREF(audiocrc),
-               DEFINT(0,1),
-       },{
-               .v4l_id = V4L2_CID_PVR_AUDIOEMPHASIS,
-               .desc = "Audio Emphasis",
-               .name = "audio_emphasis",
-               .default_value = PVR2_CVAL_AUDIOEMPHASIS_NONE,
-               DEFREF(audioemphasis),
-               DEFENUM(control_values_audioemphasis),
-       },{
-               .v4l_id = V4L2_CID_PVR_VBR,
-               .desc = "Variable video bitrate",
-               .name = "vbr",
-               .default_value = 0,
-               DEFREF(vbr),
-               DEFINT(0,1),
-       },{
-               .v4l_id = V4L2_CID_PVR_VIDEOBITRATE,
-               .desc = "Average video bitrate",
-               .name = "video_average_bitrate",
-               .default_value = 6000000,
-               DEFREF(videobitrate),
-               DEFINT(500000,20000000),
-       },{
-               .v4l_id = V4L2_CID_PVR_VIDEOPEAK,
-               .desc = "Peak video bitrate",
-               .name = "video_peak_bitrate",
-               .default_value = 6000000,
-               DEFREF(videopeak),
-               DEFINT(500000,20000000),
-       },{
-               .desc = "Interlace mode",
-               .name = "interlace",
-               .internal_id = PVR2_CID_INTERLACE,
-               .default_value = 0,
-               DEFREF(interlace),
-               DEFINT(0,1),
-       },{
-               .desc = "Audio Layer",
-               .name = "audio_layer",
-               .default_value = 2,
-               DEFREF(audiolayer),
-               DEFINT(0,3),
        },{
                .desc = "Tuner Frequency (Hz)",
                .name = "frequency",
@@ -671,7 +785,7 @@ static const struct pvr2_ctl_info control_defs[] = {
                .desc = "Streaming Enabled",
                .name = "streaming_enabled",
                .get_value = ctrl_streamingenabled_get,
-               DEFINT(0,1),
+               DEFBOOL,
        },{
                .desc = "USB Speed",
                .name = "usb_speed",
@@ -681,7 +795,7 @@ static const struct pvr2_ctl_info control_defs[] = {
                .desc = "Signal Present",
                .name = "signal_present",
                .get_value = ctrl_signal_get,
-               DEFINT(0,1),
+               DEFBOOL,
        },{
                .desc = "Video Standards Available Mask",
                .name = "video_standard_mask_available",
@@ -757,15 +871,6 @@ unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *hdw)
        return hdw->serial_number;
 }
 
-
-struct pvr2_hdw *pvr2_hdw_find(int unit_number)
-{
-       if (unit_number < 0) return 0;
-       if (unit_number >= PVR_NUM) return 0;
-       return unit_pointers[unit_number];
-}
-
-
 int pvr2_hdw_get_unit_number(struct pvr2_hdw *hdw)
 {
        return hdw->unit_number;
@@ -839,9 +944,9 @@ static int pvr2_locate_firmware(struct pvr2_hdw *hdw,
  * is not suitable for an usb transaction.
  *
  */
-int pvr2_upload_firmware1(struct pvr2_hdw *hdw)
+static int pvr2_upload_firmware1(struct pvr2_hdw *hdw)
 {
-       const struct firmware *fw_entry = 0;
+       const struct firmware *fw_entry = NULL;
        void  *fw_ptr;
        unsigned int pipe;
        int ret;
@@ -849,22 +954,18 @@ int pvr2_upload_firmware1(struct pvr2_hdw *hdw)
        static const char *fw_files_29xxx[] = {
                "v4l-pvrusb2-29xxx-01.fw",
        };
-#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
        static const char *fw_files_24xxx[] = {
                "v4l-pvrusb2-24xxx-01.fw",
        };
-#endif
        static const struct pvr2_string_table fw_file_defs[] = {
                [PVR2_HDW_TYPE_29XXX] = {
                        fw_files_29xxx,
                        sizeof(fw_files_29xxx)/sizeof(fw_files_29xxx[0]),
                },
-#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
                [PVR2_HDW_TYPE_24XXX] = {
                        fw_files_24xxx,
                        sizeof(fw_files_24xxx)/sizeof(fw_files_24xxx[0]),
                },
-#endif
        };
        hdw->fw1_state = FW1_STATE_FAILED; // default result
 
@@ -937,7 +1038,7 @@ int pvr2_upload_firmware1(struct pvr2_hdw *hdw)
 
 int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
 {
-       const struct firmware *fw_entry = 0;
+       const struct firmware *fw_entry = NULL;
        void  *fw_ptr;
        unsigned int pipe, fw_len, fw_done;
        int actual_length;
@@ -955,6 +1056,10 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
        if (ret < 0) return ret;
        fwidx = ret;
        ret = 0;
+       /* Since we're about to completely reinitialize the encoder,
+          invalidate our cached copy of its configuration state.  Next
+          time we configure the encoder, then we'll fully configure it. */
+       hdw->enc_cur_valid = 0;
 
        /* First prepare firmware loading */
        ret |= pvr2_write_register(hdw, 0x0048, 0xffffffff); /*interrupt mask*/
@@ -1084,8 +1189,9 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
   reconfigure and start over.
 
 */
-void pvr2_hdw_subsys_bit_chg_no_lock(struct pvr2_hdw *hdw,
-                                    unsigned long msk,unsigned long val)
+static void pvr2_hdw_subsys_bit_chg_no_lock(struct pvr2_hdw *hdw,
+                                           unsigned long msk,
+                                           unsigned long val)
 {
        unsigned long nmsk;
        unsigned long vmsk;
@@ -1095,12 +1201,13 @@ void pvr2_hdw_subsys_bit_chg_no_lock(struct pvr2_hdw *hdw,
        if (!hdw->flag_ok) return;
 
        msk &= PVR2_SUBSYS_ALL;
+       nmsk = (hdw->subsys_enabled_mask & ~msk) | (val & msk);
+       nmsk &= PVR2_SUBSYS_ALL;
 
        for (;;) {
                tryCount++;
-               vmsk = hdw->subsys_enabled_mask & PVR2_SUBSYS_ALL;
-               nmsk = (vmsk & ~msk) | (val & msk);
-               if (!(nmsk ^ vmsk)) break;
+               if (!((nmsk ^ hdw->subsys_enabled_mask) &
+                     PVR2_SUBSYS_ALL)) break;
                if (tryCount > 4) {
                        pvr2_trace(PVR2_TRACE_ERROR_LEGS,
                                   "Too many retries when configuring device;"
@@ -1235,18 +1342,6 @@ void pvr2_hdw_subsys_bit_chg(struct pvr2_hdw *hdw,
 }
 
 
-void pvr2_hdw_subsys_bit_set(struct pvr2_hdw *hdw,unsigned long msk)
-{
-       pvr2_hdw_subsys_bit_chg(hdw,msk,msk);
-}
-
-
-void pvr2_hdw_subsys_bit_clr(struct pvr2_hdw *hdw,unsigned long msk)
-{
-       pvr2_hdw_subsys_bit_chg(hdw,msk,0);
-}
-
-
 unsigned long pvr2_hdw_subsys_get(struct pvr2_hdw *hdw)
 {
        return hdw->subsys_enabled_mask;
@@ -1259,9 +1354,9 @@ unsigned long pvr2_hdw_subsys_stream_get(struct pvr2_hdw *hdw)
 }
 
 
-void pvr2_hdw_subsys_stream_bit_chg_no_lock(struct pvr2_hdw *hdw,
-                                           unsigned long msk,
-                                           unsigned long val)
+static void pvr2_hdw_subsys_stream_bit_chg_no_lock(struct pvr2_hdw *hdw,
+                                                  unsigned long msk,
+                                                  unsigned long val)
 {
        unsigned long val2;
        msk &= PVR2_SUBSYS_ALL;
@@ -1283,7 +1378,7 @@ void pvr2_hdw_subsys_stream_bit_chg(struct pvr2_hdw *hdw,
 }
 
 
-int pvr2_hdw_set_streaming_no_lock(struct pvr2_hdw *hdw,int enableFl)
+static int pvr2_hdw_set_streaming_no_lock(struct pvr2_hdw *hdw,int enableFl)
 {
        if ((!enableFl) == !(hdw->flag_streaming_enabled)) return 0;
        if (enableFl) {
@@ -1317,8 +1412,8 @@ int pvr2_hdw_set_streaming(struct pvr2_hdw *hdw,int enable_flag)
 }
 
 
-int pvr2_hdw_set_stream_type_no_lock(struct pvr2_hdw *hdw,
-                                    enum pvr2_config config)
+static int pvr2_hdw_set_stream_type_no_lock(struct pvr2_hdw *hdw,
+                                           enum pvr2_config config)
 {
        unsigned long sm = hdw->subsys_enabled_mask;
        if (!hdw->flag_ok) return -EIO;
@@ -1449,7 +1544,7 @@ static void pvr2_hdw_setup_std(struct pvr2_hdw *hdw)
                return;
        }
 
-       pvr2_trace(PVR2_TRACE_EEPROM,
+       pvr2_trace(PVR2_TRACE_ERROR_LEGS,
                   "Unable to select a viable initial video standard");
 }
 
@@ -1650,13 +1745,15 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
        int valid_std_mask;
        struct pvr2_ctrl *cptr;
        __u8 ifnum;
+       struct v4l2_queryctrl qctrl;
+       struct pvr2_ctl_info *ciptr;
 
        hdw_type = devid - pvr2_device_table;
        if (hdw_type >=
            sizeof(pvr2_device_names)/sizeof(pvr2_device_names[0])) {
                pvr2_trace(PVR2_TRACE_ERROR_LEGS,
                           "Bogus device type of %u reported",hdw_type);
-               return 0;
+               return NULL;
        }
 
        hdw = kmalloc(sizeof(*hdw),GFP_KERNEL);
@@ -1664,8 +1761,10 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
                   hdw,pvr2_device_names[hdw_type]);
        if (!hdw) goto fail;
        memset(hdw,0,sizeof(*hdw));
+       cx2341x_fill_defaults(&hdw->enc_ctl_state);
 
        hdw->control_cnt = CTRLDEF_COUNT;
+       hdw->control_cnt += MPEGDEF_COUNT;
        hdw->controls = kmalloc(sizeof(struct pvr2_ctrl) * hdw->control_cnt,
                                GFP_KERNEL);
        if (!hdw->controls) goto fail;
@@ -1682,6 +1781,54 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
                cptr = hdw->controls + idx;
                cptr->info = control_defs+idx;
        }
+       /* Define and configure additional controls from cx2341x module. */
+       hdw->mpeg_ctrl_info = kmalloc(
+               sizeof(*(hdw->mpeg_ctrl_info)) * MPEGDEF_COUNT, GFP_KERNEL);
+       if (!hdw->mpeg_ctrl_info) goto fail;
+       memset(hdw->mpeg_ctrl_info,0,
+              sizeof(*(hdw->mpeg_ctrl_info)) * MPEGDEF_COUNT);
+       for (idx = 0; idx < MPEGDEF_COUNT; idx++) {
+               cptr = hdw->controls + idx + CTRLDEF_COUNT;
+               ciptr = &(hdw->mpeg_ctrl_info[idx].info);
+               ciptr->desc = hdw->mpeg_ctrl_info[idx].desc;
+               ciptr->name = mpeg_ids[idx].strid;
+               ciptr->v4l_id = mpeg_ids[idx].id;
+               ciptr->skip_init = !0;
+               ciptr->get_value = ctrl_cx2341x_get;
+               ciptr->get_v4lflags = ctrl_cx2341x_getv4lflags;
+               ciptr->is_dirty = ctrl_cx2341x_is_dirty;
+               if (!idx) ciptr->clear_dirty = ctrl_cx2341x_clear_dirty;
+               qctrl.id = ciptr->v4l_id;
+               cx2341x_ctrl_query(&hdw->enc_ctl_state,&qctrl);
+               if (!(qctrl.flags & V4L2_CTRL_FLAG_READ_ONLY)) {
+                       ciptr->set_value = ctrl_cx2341x_set;
+               }
+               strncpy(hdw->mpeg_ctrl_info[idx].desc,qctrl.name,
+                       PVR2_CTLD_INFO_DESC_SIZE);
+               hdw->mpeg_ctrl_info[idx].desc[PVR2_CTLD_INFO_DESC_SIZE-1] = 0;
+               ciptr->default_value = qctrl.default_value;
+               switch (qctrl.type) {
+               default:
+               case V4L2_CTRL_TYPE_INTEGER:
+                       ciptr->type = pvr2_ctl_int;
+                       ciptr->def.type_int.min_value = qctrl.minimum;
+                       ciptr->def.type_int.max_value = qctrl.maximum;
+                       break;
+               case V4L2_CTRL_TYPE_BOOLEAN:
+                       ciptr->type = pvr2_ctl_bool;
+                       break;
+               case V4L2_CTRL_TYPE_MENU:
+                       ciptr->type = pvr2_ctl_enum;
+                       ciptr->def.type_enum.value_names =
+                               cx2341x_ctrl_get_menu(ciptr->v4l_id);
+                       for (cnt1 = 0;
+                            ciptr->def.type_enum.value_names[cnt1] != NULL;
+                            cnt1++) { }
+                       ciptr->def.type_enum.count = cnt1;
+                       break;
+               }
+               cptr->info = ciptr;
+       }
 
        // Initialize video standard enum dynamic control
        cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_STDENUM);
@@ -1784,40 +1931,41 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
                if (hdw->ctl_read_buffer) kfree(hdw->ctl_read_buffer);
                if (hdw->ctl_write_buffer) kfree(hdw->ctl_write_buffer);
                if (hdw->controls) kfree(hdw->controls);
+               if (hdw->mpeg_ctrl_info) kfree(hdw->mpeg_ctrl_info);
                kfree(hdw);
        }
-       return 0;
+       return NULL;
 }
 
 
 /* Remove _all_ associations between this driver and the underlying USB
    layer. */
-void pvr2_hdw_remove_usb_stuff(struct pvr2_hdw *hdw)
+static void pvr2_hdw_remove_usb_stuff(struct pvr2_hdw *hdw)
 {
        if (hdw->flag_disconnected) return;
        pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_remove_usb_stuff: hdw=%p",hdw);
        if (hdw->ctl_read_urb) {
                usb_kill_urb(hdw->ctl_read_urb);
                usb_free_urb(hdw->ctl_read_urb);
-               hdw->ctl_read_urb = 0;
+               hdw->ctl_read_urb = NULL;
        }
        if (hdw->ctl_write_urb) {
                usb_kill_urb(hdw->ctl_write_urb);
                usb_free_urb(hdw->ctl_write_urb);
-               hdw->ctl_write_urb = 0;
+               hdw->ctl_write_urb = NULL;
        }
        if (hdw->ctl_read_buffer) {
                kfree(hdw->ctl_read_buffer);
-               hdw->ctl_read_buffer = 0;
+               hdw->ctl_read_buffer = NULL;
        }
        if (hdw->ctl_write_buffer) {
                kfree(hdw->ctl_write_buffer);
-               hdw->ctl_write_buffer = 0;
+               hdw->ctl_write_buffer = NULL;
        }
        pvr2_hdw_render_useless_unlocked(hdw);
        hdw->flag_disconnected = !0;
-       hdw->usb_dev = 0;
-       hdw->usb_intf = 0;
+       hdw->usb_dev = NULL;
+       hdw->usb_intf = NULL;
 }
 
 
@@ -1827,11 +1975,11 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
        pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_destroy: hdw=%p",hdw);
        if (hdw->fw_buffer) {
                kfree(hdw->fw_buffer);
-               hdw->fw_buffer = 0;
+               hdw->fw_buffer = NULL;
        }
        if (hdw->vid_stream) {
                pvr2_stream_destroy(hdw->vid_stream);
-               hdw->vid_stream = 0;
+               hdw->vid_stream = NULL;
        }
        if (hdw->audio_stat) {
                hdw->audio_stat->detach(hdw->audio_stat->ctxt);
@@ -1845,10 +1993,11 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
                if ((hdw->unit_number >= 0) &&
                    (hdw->unit_number < PVR_NUM) &&
                    (unit_pointers[hdw->unit_number] == hdw)) {
-                       unit_pointers[hdw->unit_number] = 0;
+                       unit_pointers[hdw->unit_number] = NULL;
                }
        } while (0); up(&pvr2_unit_sem);
        if (hdw->controls) kfree(hdw->controls);
+       if (hdw->mpeg_ctrl_info) kfree(hdw->mpeg_ctrl_info);
        if (hdw->std_defs) kfree(hdw->std_defs);
        if (hdw->std_enum_names) kfree(hdw->std_enum_names);
        kfree(hdw);
@@ -1881,7 +2030,7 @@ void pvr2_hdw_disconnect(struct pvr2_hdw *hdw)
 
 // Attempt to autoselect an appropriate value for std_enum_cur given
 // whatever is currently in std_mask_cur
-void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw)
+static void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw)
 {
        unsigned int idx;
        for (idx = 1; idx < hdw->std_enum_cnt; idx++) {
@@ -1896,7 +2045,7 @@ void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw)
 
 // Calculate correct set of enumerated standards based on currently known
 // set of available standards bits.
-void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw)
+static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw)
 {
        struct v4l2_standard *newstd;
        unsigned int std_cnt;
@@ -1906,12 +2055,12 @@ void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw)
 
        if (hdw->std_defs) {
                kfree(hdw->std_defs);
-               hdw->std_defs = 0;
+               hdw->std_defs = NULL;
        }
        hdw->std_enum_cnt = 0;
        if (hdw->std_enum_names) {
                kfree(hdw->std_enum_names);
-               hdw->std_enum_names = 0;
+               hdw->std_enum_names = NULL;
        }
 
        if (!std_cnt) {
@@ -1962,7 +2111,7 @@ unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *hdw)
 struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_index(struct pvr2_hdw *hdw,
                                             unsigned int idx)
 {
-       if (idx >= hdw->control_cnt) return 0;
+       if (idx >= hdw->control_cnt) return NULL;
        return hdw->controls + idx;
 }
 
@@ -1981,11 +2130,11 @@ struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *hdw,
                i = cptr->info->internal_id;
                if (i && (i == ctl_id)) return cptr;
        }
-       return 0;
+       return NULL;
 }
 
 
-/* Given an ID, retrieve the control structure associated with it. */
+/* Given a V4L ID, retrieve the control structure associated with it. */
 struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *hdw,unsigned int ctl_id)
 {
        struct pvr2_ctrl *cptr;
@@ -1998,7 +2147,31 @@ struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *hdw,unsigned int ctl_id
                i = cptr->info->v4l_id;
                if (i && (i == ctl_id)) return cptr;
        }
-       return 0;
+       return NULL;
+}
+
+
+/* Given a V4L ID for its immediate predecessor, retrieve the control
+   structure associated with it. */
+struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *hdw,
+                                           unsigned int ctl_id)
+{
+       struct pvr2_ctrl *cptr,*cp2;
+       unsigned int idx;
+       int i;
+
+       /* This could be made a lot more efficient, but for now... */
+       cp2 = NULL;
+       for (idx = 0; idx < hdw->control_cnt; idx++) {
+               cptr = hdw->controls + idx;
+               i = cptr->info->v4l_id;
+               if (!i) continue;
+               if (i <= ctl_id) continue;
+               if (cp2 && (cp2->info->v4l_id < i)) continue;
+               cp2 = cptr;
+       }
+       return cp2;
+       return NULL;
 }
 
 
@@ -2007,6 +2180,7 @@ static const char *get_ctrl_typename(enum pvr2_ctl_type tp)
        switch (tp) {
        case pvr2_ctl_int: return "integer";
        case pvr2_ctl_enum: return "enum";
+       case pvr2_ctl_bool: return "boolean";
        case pvr2_ctl_bitmask: return "bitmask";
        }
        return "";
@@ -2020,7 +2194,7 @@ static const char *get_ctrl_typename(enum pvr2_ctl_type tp)
    state(s) back to their previous value before this function was called.
    Thus we can automatically reconfigure affected pieces of the driver as
    controls are changed. */
-int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
+static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
 {
        unsigned long saved_subsys_mask = hdw->subsys_enabled_mask;
        unsigned long stale_subsys_mask = 0;
@@ -2075,30 +2249,34 @@ int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
                        hdw->res_ver_val = nvres;
                        hdw->res_ver_dirty = !0;
                }
-               if (!hdw->interlace_val) {
-                       hdw->interlace_val = 0;
-                       hdw->interlace_dirty = !0;
-               }
        }
 
        if (hdw->std_dirty ||
-           hdw->interlace_dirty ||
-           hdw->vbr_dirty ||
-           hdw->videobitrate_dirty ||
-           hdw->videopeak_dirty ||
-           hdw->audiobitrate_dirty ||
-           hdw->audiolayer_dirty ||
-           hdw->audiocrc_dirty ||
-           hdw->audioemphasis_dirty ||
+           hdw->enc_stale ||
            hdw->srate_dirty ||
            hdw->res_ver_dirty ||
-           hdw->res_hor_dirty) {
+           hdw->res_hor_dirty ||
+           0) {
                /* If any of this changes, then the encoder needs to be
                   reconfigured, and we need to reset the stream. */
                stale_subsys_mask |= (1<<PVR2_SUBSYS_B_ENC_CFG);
-               stale_subsys_mask |= hdw->subsys_stream_mask;
        }
 
+       if (hdw->srate_dirty) {
+               /* Write new sample rate into control structure since
+                * the master copy is stale.  We must track srate
+                * separate from the mpeg control structure because
+                * other logic also uses this value. */
+               struct v4l2_ext_controls cs;
+               struct v4l2_ext_control c1;
+               memset(&cs,0,sizeof(cs));
+               memset(&c1,0,sizeof(c1));
+               cs.controls = &c1;
+               cs.count = 1;
+               c1.id = V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ;
+               c1.value = hdw->srate_val;
+               cx2341x_ext_ctrls(&hdw->enc_ctl_state,&cs,VIDIOC_S_EXT_CTRLS);
+       }
 
        /* Scan i2c core at this point - before we clear all the dirty
           bits.  Various parts of the i2c core will notice dirty bits as
@@ -2157,15 +2335,6 @@ void pvr2_hdw_poll_trigger_unlocked(struct pvr2_hdw *hdw)
        }
 }
 
-
-void pvr2_hdw_poll_trigger(struct pvr2_hdw *hdw)
-{
-       LOCK_TAKE(hdw->big_lock); do {
-               pvr2_hdw_poll_trigger_unlocked(hdw);
-       } while (0); LOCK_GIVE(hdw->big_lock);
-}
-
-
 /* Return name for this driver instance */
 const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *hdw)
 {
@@ -2174,7 +2343,7 @@ const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *hdw)
 
 
 /* Return bit mask indicating signal status */
-unsigned int pvr2_hdw_get_signal_status_internal(struct pvr2_hdw *hdw)
+static unsigned int pvr2_hdw_get_signal_status_internal(struct pvr2_hdw *hdw)
 {
        unsigned int msk = 0;
        switch (hdw->input_val) {
@@ -2236,11 +2405,16 @@ struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *hp)
 
 void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw)
 {
+       int nr = pvr2_hdw_get_unit_number(hdw);
        LOCK_TAKE(hdw->big_lock); do {
                hdw->log_requested = !0;
+               printk(KERN_INFO "pvrusb2: =================  START STATUS CARD #%d  =================\n", nr);
                pvr2_i2c_core_check_stale(hdw);
                hdw->log_requested = 0;
                pvr2_i2c_core_sync(hdw);
+               pvr2_trace(PVR2_TRACE_INFO,"cx2341x config:");
+               cx2341x_log_status(&hdw->enc_ctl_state, "pvrusb2");
+               printk(KERN_INFO "pvrusb2: ==================  END STATUS CARD #%d  ==================\n", nr);
        } while (0); LOCK_GIVE(hdw->big_lock);
 }
 
@@ -2256,7 +2430,7 @@ void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *hdw, int enable_flag)
                        pvr2_trace(PVR2_TRACE_FIRMWARE,
                                   "Cleaning up after CPU firmware fetch");
                        kfree(hdw->fw_buffer);
-                       hdw->fw_buffer = 0;
+                       hdw->fw_buffer = NULL;
                        hdw->fw_size = 0;
                        /* Now release the CPU.  It will disconnect and
                           reconnect later. */
@@ -2351,22 +2525,6 @@ void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *hdw,int v)
 }
 
 
-void pvr2_reset_ctl_endpoints(struct pvr2_hdw *hdw)
-{
-       if (!hdw->usb_dev) return;
-       usb_settoggle(hdw->usb_dev, PVR2_CTL_WRITE_ENDPOINT & 0xf,
-                     !(PVR2_CTL_WRITE_ENDPOINT & USB_DIR_IN), 0);
-       usb_settoggle(hdw->usb_dev, PVR2_CTL_READ_ENDPOINT & 0xf,
-                     !(PVR2_CTL_READ_ENDPOINT & USB_DIR_IN), 0);
-       usb_clear_halt(hdw->usb_dev,
-                      usb_rcvbulkpipe(hdw->usb_dev,
-                                      PVR2_CTL_READ_ENDPOINT & 0x7f));
-       usb_clear_halt(hdw->usb_dev,
-                      usb_sndbulkpipe(hdw->usb_dev,
-                                      PVR2_CTL_WRITE_ENDPOINT & 0x7f));
-}
-
-
 static void pvr2_ctl_write_complete(struct urb *urb, struct pt_regs *regs)
 {
        struct pvr2_hdw *hdw = urb->context;
@@ -2400,10 +2558,14 @@ static void pvr2_ctl_timeout(unsigned long data)
 }
 
 
-int pvr2_send_request_ex(struct pvr2_hdw *hdw,
-                        unsigned int timeout,int probe_fl,
-                        void *write_data,unsigned int write_len,
-                        void *read_data,unsigned int read_len)
+/* Issue a command and get a response from the device.  This extended
+   version includes a probe flag (which if set means that device errors
+   should not be logged or treated as fatal) and a timeout in jiffies.
+   This can be used to non-lethally probe the health of endpoint 1. */
+static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
+                               unsigned int timeout,int probe_fl,
+                               void *write_data,unsigned int write_len,
+                               void *read_data,unsigned int read_len)
 {
        unsigned int idx;
        int status = 0;
@@ -2658,7 +2820,7 @@ int pvr2_write_register(struct pvr2_hdw *hdw, u16 reg, u32 data)
 }
 
 
-int pvr2_read_register(struct pvr2_hdw *hdw, u16 reg, u32 *data)
+static int pvr2_read_register(struct pvr2_hdw *hdw, u16 reg, u32 *data)
 {
        int ret = 0;
 
@@ -2682,7 +2844,7 @@ int pvr2_read_register(struct pvr2_hdw *hdw, u16 reg, u32 *data)
 }
 
 
-int pvr2_write_u16(struct pvr2_hdw *hdw, u16 data, int res)
+static int pvr2_write_u16(struct pvr2_hdw *hdw, u16 data, int res)
 {
        int ret;
 
@@ -2699,7 +2861,7 @@ int pvr2_write_u16(struct pvr2_hdw *hdw, u16 data, int res)
 }
 
 
-int pvr2_write_u8(struct pvr2_hdw *hdw, u8 data, int res)
+static int pvr2_write_u8(struct pvr2_hdw *hdw, u8 data, int res)
 {
        int ret;
 
@@ -2715,13 +2877,13 @@ int pvr2_write_u8(struct pvr2_hdw *hdw, u8 data, int res)
 }
 
 
-void pvr2_hdw_render_useless_unlocked(struct pvr2_hdw *hdw)
+static void pvr2_hdw_render_useless_unlocked(struct pvr2_hdw *hdw)
 {
        if (!hdw->flag_ok) return;
        pvr2_trace(PVR2_TRACE_INIT,"render_useless");
        hdw->flag_ok = 0;
        if (hdw->vid_stream) {
-               pvr2_stream_setup(hdw->vid_stream,0,0,0);
+               pvr2_stream_setup(hdw->vid_stream,NULL,0,0);
        }
        hdw->flag_streaming_enabled = 0;
        hdw->subsys_enabled_mask = 0;
@@ -2740,7 +2902,7 @@ void pvr2_hdw_device_reset(struct pvr2_hdw *hdw)
 {
        int ret;
        pvr2_trace(PVR2_TRACE_INIT,"Performing a device reset...");
-       ret = usb_lock_device_for_reset(hdw->usb_dev,0);
+       ret = usb_lock_device_for_reset(hdw->usb_dev,NULL);
        if (ret == 1) {
                ret = usb_reset_device(hdw->usb_dev);
                usb_unlock_device(hdw->usb_dev);
@@ -2789,7 +2951,7 @@ int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *hdw)
                pvr2_trace(PVR2_TRACE_INIT,"Requesting uproc hard reset");
                hdw->flag_ok = !0;
                hdw->cmd_buffer[0] = 0xdd;
-               status = pvr2_send_request(hdw,hdw->cmd_buffer,1,0,0);
+               status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0);
        } while (0); LOCK_GIVE(hdw->ctl_lock);
        return status;
 }
@@ -2801,7 +2963,7 @@ int pvr2_hdw_cmd_powerup(struct pvr2_hdw *hdw)
        LOCK_TAKE(hdw->ctl_lock); do {
                pvr2_trace(PVR2_TRACE_INIT,"Requesting powerup");
                hdw->cmd_buffer[0] = 0xde;
-               status = pvr2_send_request(hdw,hdw->cmd_buffer,1,0,0);
+               status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0);
        } while (0); LOCK_GIVE(hdw->ctl_lock);
        return status;
 }
@@ -2828,12 +2990,13 @@ int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *hdw)
 }
 
 
-int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl)
+/* Stop / start video stream transport */
+static int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl)
 {
        int status;
        LOCK_TAKE(hdw->ctl_lock); do {
                hdw->cmd_buffer[0] = (runFl ? 0x36 : 0x37);
-               status = pvr2_send_request(hdw,hdw->cmd_buffer,1,0,0);
+               status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0);
        } while (0); LOCK_GIVE(hdw->ctl_lock);
        if (!status) {
                hdw->subsys_enabled_mask =
@@ -2926,7 +3089,8 @@ int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val)
 }
 
 
-int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw)
+/* Find I2C address of eeprom */
+static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw)
 {
        int result;
        LOCK_TAKE(hdw->ctl_lock); do {