diff options
Diffstat (limited to 'linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c')
-rw-r--r-- | linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c | 471 |
1 files changed, 324 insertions, 147 deletions
diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c index 409343097..91a0ae19d 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c @@ -24,9 +24,8 @@ #include <linux/string.h> #include <linux/slab.h> #include <linux/firmware.h> -#include <asm/semaphore.h> #include <linux/videodev2.h> -#include <media/cx2341x.h> +#include <asm/semaphore.h> #include "pvrusb2.h" #include "pvrusb2-std.h" #include "pvrusb2-util.h" @@ -132,36 +131,105 @@ MODULE_PARM_DESC(tolerance,"specify stream error tolerance"); /* size of a firmware chunk */ #define FIRMWARE_CHUNK_SIZE 0x2000 +/* 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 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_srate[] = { [PVR2_CVAL_SRATE_48] = "48KHz", [PVR2_CVAL_SRATE_44_1] = "44.1KHz", }; -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 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_input[] = { @@ -278,6 +346,76 @@ static int ctrl_freq_set(struct pvr2_ctrl *cptr,int m,int v) 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 = 0; + } + } 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; @@ -437,6 +575,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, \ @@ -468,19 +609,11 @@ VCREATE_FUNCS(balance) VCREATE_FUNCS(bass) VCREATE_FUNCS(treble) VCREATE_FUNCS(mute) -VCREATE_FUNCS(srate) -VCREATE_FUNCS(audiobitrate) -VCREATE_FUNCS(audiocrc) -VCREATE_FUNCS(audioemphasis) -VCREATE_FUNCS(vbr) -VCREATE_FUNCS(videobitrate) -VCREATE_FUNCS(videopeak) VCREATE_FUNCS(input) VCREATE_FUNCS(audiomode) VCREATE_FUNCS(res_hor) VCREATE_FUNCS(res_ver) -VCREATE_FUNCS(interlace) -VCREATE_FUNCS(audiolayer) +VCREATE_FUNCS(srate) #define MIN_FREQ 55250000L #define MAX_FREQ 850000000L @@ -549,69 +682,7 @@ static const struct pvr2_ctl_info control_defs[] = { .name = "mute", .default_value = 0, DEFREF(mute), - DEFINT(0,1), - },{ - .v4l_id = V4L2_CID_PVR_SRATE, - .desc = "Sample rate", - .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), - },{ - .desc = "Audio Layer", - .name = "audio_layer", - .default_value = 2, - DEFREF(audiolayer), - DEFINT(0,3), - },{ - .v4l_id = V4L2_CID_PVR_AUDIOEMPHASIS, - .desc = "Audio Emphasis", - .name = "audio_emphasis", - .default_value = PVR2_CVAL_AUDIOEMPHASIS_NONE, - DEFREF(audioemphasis), - DEFENUM(control_values_audioemphasis), - },{ - .desc = "Interlace mode", - .name = "interlace", - .internal_id = PVR2_CID_INTERLACE, - .default_value = 0, - DEFREF(interlace), - DEFINT(0,1), - },{ - .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), + DEFBOOL, },{ .desc = "Video Source", .name = "input", @@ -627,6 +698,27 @@ static const struct pvr2_ctl_info control_defs[] = { DEFREF(audiomode), DEFENUM(control_values_audiomode), },{ + .desc = "Horizontal capture resolution", + .name = "resolution_hor", + .internal_id = PVR2_CID_HRES, + .default_value = 720, + DEFREF(res_hor), + DEFINT(320,720), + },{ + .desc = "Vertical capture resolution", + .name = "resolution_ver", + .internal_id = PVR2_CID_VRES, + .default_value = 480, + DEFREF(res_ver), + DEFINT(200,625), + },{ + .v4l_id = V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ, + .desc = "Sample rate", + .name = "srate", + .default_value = PVR2_CVAL_SRATE_48, + DEFREF(srate), + DEFENUM(control_values_srate), + },{ .desc = "Tuner Frequency (Hz)", .name = "frequency", .internal_id = PVR2_CID_FREQUENCY, @@ -655,24 +747,10 @@ static const struct pvr2_ctl_info control_defs[] = { .get_value = ctrl_channelprog_get, DEFINT(0,FREQTABLE_SIZE), },{ - .desc = "Horizontal capture resolution", - .name = "resolution_hor", - .internal_id = PVR2_CID_HRES, - .default_value = 720, - DEFREF(res_hor), - DEFINT(320,720), - },{ - .desc = "Vertical capture resolution", - .name = "resolution_ver", - .internal_id = PVR2_CID_VRES, - .default_value = 480, - DEFREF(res_ver), - DEFINT(200,625), - },{ .desc = "Streaming Enabled", .name = "streaming_enabled", .get_value = ctrl_streamingenabled_get, - DEFINT(0,1), + DEFBOOL, },{ .desc = "USB Speed", .name = "usb_speed", @@ -682,7 +760,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", @@ -732,7 +810,7 @@ static const struct pvr2_ctl_info control_defs[] = { } }; -#define CTRL_COUNT (sizeof(control_defs)/sizeof(control_defs[0])) +#define CTRLDEF_COUNT (sizeof(control_defs)/sizeof(control_defs[0])) const char *pvr2_config_get_name(enum pvr2_config cfg) @@ -956,6 +1034,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*/ @@ -1096,12 +1178,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;" @@ -1450,7 +1533,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"); } @@ -1509,7 +1592,7 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw) pvr2_i2c_core_init(hdw); if (!pvr2_hdw_dev_ok(hdw)) return; - for (idx = 0; idx < CTRL_COUNT; idx++) { + for (idx = 0; idx < CTRLDEF_COUNT; idx++) { cptr = hdw->controls + idx; if (cptr->info->skip_init) continue; if (!cptr->info->set_value) continue; @@ -1651,6 +1734,8 @@ 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 >= @@ -1665,22 +1750,74 @@ 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->controls = kmalloc(sizeof(struct pvr2_ctrl) * CTRL_COUNT, + 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; - memset(hdw->controls,0,sizeof(struct pvr2_ctrl) * CTRL_COUNT); + memset(hdw->controls,0,sizeof(struct pvr2_ctrl) * hdw->control_cnt); hdw->hdw_type = hdw_type; - + for (idx = 0; idx < hdw->control_cnt; idx++) { + cptr = hdw->controls + idx; + cptr->hdw = hdw; + } for (idx = 0; idx < 32; idx++) { hdw->std_mask_ptrs[idx] = hdw->std_mask_names[idx]; } - - for (idx = 0; idx < CTRL_COUNT; idx++) { + for (idx = 0; idx < CTRLDEF_COUNT; idx++) { cptr = hdw->controls + idx; - cptr->hdw = hdw; 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); @@ -1783,6 +1920,7 @@ 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; @@ -1847,7 +1985,8 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw) unit_pointers[hdw->unit_number] = 0; } } while (0); up(&pvr2_unit_sem); - kfree(hdw->controls); + 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); @@ -1953,7 +2092,7 @@ int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw, /* Get the number of defined controls */ unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *hdw) { - return CTRL_COUNT; + return hdw->control_cnt; } @@ -1961,7 +2100,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 >= CTRL_COUNT) return 0; + if (idx >= hdw->control_cnt) return 0; return hdw->controls + idx; } @@ -1975,7 +2114,7 @@ struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *hdw, int i; /* This could be made a lot more efficient, but for now... */ - for (idx = 0; idx < CTRL_COUNT; idx++) { + for (idx = 0; idx < hdw->control_cnt; idx++) { cptr = hdw->controls + idx; i = cptr->info->internal_id; if (i && (i == ctl_id)) return cptr; @@ -1984,7 +2123,7 @@ struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *hdw, } -/* 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; @@ -1992,7 +2131,7 @@ struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *hdw,unsigned int ctl_id int i; /* This could be made a lot more efficient, but for now... */ - for (idx = 0; idx < CTRL_COUNT; idx++) { + for (idx = 0; idx < hdw->control_cnt; idx++) { cptr = hdw->controls + idx; i = cptr->info->v4l_id; if (i && (i == ctl_id)) return cptr; @@ -2001,11 +2140,36 @@ struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *hdw,unsigned int ctl_id } +/* 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 = 0; + 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 0; +} + + 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 ""; @@ -2030,7 +2194,7 @@ int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw) char buf[100]; unsigned int bcnt,ccnt; - for (idx = 0; idx < CTRL_COUNT; idx++) { + for (idx = 0; idx < hdw->control_cnt; idx++) { cptr = hdw->controls + idx; if (cptr->info->is_dirty == 0) continue; if (!cptr->info->is_dirty(cptr)) continue; @@ -2074,37 +2238,45 @@ 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 || +#if 0 /* Don't toggle encoder for now - seems to work better this way */ + hdw->enc_stale || + hdw->srate_dirty || hdw->res_ver_dirty || hdw->res_hor_dirty || - hdw->interlace_dirty || - hdw->vbr_dirty || - hdw->videobitrate_dirty || - hdw->videopeak_dirty || - hdw->audiobitrate_dirty || - hdw->srate_dirty || - hdw->audiolayer_dirty || - hdw->audiocrc_dirty || - hdw->audioemphasis_dirty) { +#endif + 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 appropriate and arrange to broadcast or directly send updates to the client drivers in order to keep everything in sync */ pvr2_i2c_core_check_stale(hdw); - for (idx = 0; idx < CTRL_COUNT; idx++) { + for (idx = 0; idx < hdw->control_cnt; idx++) { cptr = hdw->controls + idx; if (!cptr->info->clear_dirty) continue; cptr->info->clear_dirty(cptr); @@ -2234,11 +2406,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,0); + printk(KERN_INFO "pvrusb2: ================== END STATUS CARD #%d ==================\n", nr); } while (0); LOCK_GIVE(hdw->big_lock); } |