21 #include <linux/errno.h>
22 #include <linux/string.h>
23 #include <linux/slab.h>
24 #include <linux/module.h>
26 #include <linux/videodev2.h>
45 #define TV_MIN_FREQ 55250000L
46 #define TV_MAX_FREQ 850000000L
50 #define TIME_MSEC_DECODER_WAIT 50
54 #define TIME_MSEC_DECODER_STABILIZATION_WAIT 300
58 #define TIME_MSEC_ENCODER_WAIT 50
65 #define TIME_MSEC_ENCODER_OK 250
71 static int procreload;
75 static int init_pause_msec;
78 MODULE_PARM_DESC(ctlchg,
"0=optimize ctl change 1=always accept new ctl value");
83 "Attempt init failure recovery with firmware reload");
92 static int default_tv_freq = 61250000
L;
94 static int default_radio_freq = 104300000
L;
101 #define PVR2_CTL_WRITE_ENDPOINT 0x01
102 #define PVR2_CTL_READ_ENDPOINT 0x81
104 #define PVR2_GPIO_IN 0x9008
105 #define PVR2_GPIO_OUT 0x900c
106 #define PVR2_GPIO_DIR 0x9020
108 #define trace_firmware(...) pvr2_trace(PVR2_TRACE_FIRMWARE,__VA_ARGS__)
110 #define PVR2_FIRMWARE_ENDPOINT 0x02
113 #define FIRMWARE_CHUNK_SIZE 0x2000
126 static const char *module_names[] = {
137 static const unsigned char *module_i2c_addresses[] = {
148 static const char *ir_scheme_names[] = {
165 .strid =
"audio_layer",
168 .strid =
"audio_bitrate",
172 .strid =
"mpeg_audio_mode",
175 .strid =
"mpeg_audio_mode_extension",
178 .strid =
"audio_emphasis",
181 .strid =
"audio_crc",
184 .strid =
"video_aspect",
187 .strid =
"video_b_frames",
190 .strid =
"video_gop_size",
193 .strid =
"video_gop_closure",
196 .strid =
"video_bitrate_mode",
199 .strid =
"video_bitrate",
202 .strid =
"video_bitrate_peak",
205 .strid =
"video_temporal_decimation",
208 .strid =
"stream_type",
211 .strid =
"video_spatial_filter_mode",
214 .strid =
"video_spatial_filter",
217 .strid =
"video_luma_spatial_filter_type",
220 .strid =
"video_chroma_spatial_filter_type",
223 .strid =
"video_temporal_filter_mode",
226 .strid =
"video_temporal_filter",
229 .strid =
"video_median_filter_type",
232 .strid =
"video_luma_median_filter_top",
235 .strid =
"video_luma_median_filter_bottom",
238 .strid =
"video_chroma_median_filter_top",
241 .strid =
"video_chroma_median_filter_bottom",
245 #define MPEGDEF_COUNT ARRAY_SIZE(mpeg_ids)
248 static const char *control_values_srate[] = {
256 static const char *control_values_input[] = {
265 static const char *control_values_audiomode[] = {
274 static const char *control_values_hsm[] = {
281 static const char *pvr2_state_names[] = {
326 static int pvr2_hdw_set_input(
struct pvr2_hdw *hdw,
int v);
327 static void pvr2_hdw_state_sched(
struct pvr2_hdw *);
328 static int pvr2_hdw_state_eval(
struct pvr2_hdw *);
329 static void pvr2_hdw_set_cur_freq(
struct pvr2_hdw *,
unsigned long);
332 static int pvr2_hdw_untrip_unlocked(
struct pvr2_hdw *);
333 static void pvr2_hdw_state_log_state(
struct pvr2_hdw *);
334 static int pvr2_hdw_cmd_usbstream(
struct pvr2_hdw *hdw,
int runFl);
335 static int pvr2_hdw_commit_setup(
struct pvr2_hdw *hdw);
336 static int pvr2_hdw_get_eeprom_addr(
struct pvr2_hdw *hdw);
337 static void pvr2_hdw_quiescent_timeout(
unsigned long);
338 static void pvr2_hdw_decoder_stabilization_timeout(
unsigned long);
339 static void pvr2_hdw_encoder_wait_timeout(
unsigned long);
340 static void pvr2_hdw_encoder_run_timeout(
unsigned long);
341 static int pvr2_issue_simple_cmd(
struct pvr2_hdw *,
u32);
342 static int pvr2_send_request_ex(
struct pvr2_hdw *hdw,
343 unsigned int timeout,
int probe_fl,
344 void *write_data,
unsigned int write_len,
345 void *read_data,
unsigned int read_len);
346 static int pvr2_hdw_check_cropcap(
struct pvr2_hdw *hdw);
349 static void trace_stbit(
const char *
name,
int val)
352 "State bit %s <-- %s",
353 name,(val ?
"true" :
"false"));
356 static int ctrl_channelfreq_get(
struct pvr2_ctrl *cptr,
int *vp)
367 static int ctrl_channelfreq_set(
struct pvr2_ctrl *cptr,
int m,
int v)
389 static int ctrl_channelprog_get(
struct pvr2_ctrl *cptr,
int *vp)
391 *vp = cptr->
hdw->freqProgSlot;
395 static int ctrl_channelprog_set(
struct pvr2_ctrl *cptr,
int m,
int v)
404 static int ctrl_channel_get(
struct pvr2_ctrl *cptr,
int *vp)
411 static int ctrl_channel_set(
struct pvr2_ctrl *cptr,
int m,
int slotId)
419 pvr2_hdw_set_cur_freq(hdw,freq);
429 static int ctrl_freq_get(
struct pvr2_ctrl *cptr,
int *vp)
435 static int ctrl_freq_is_dirty(
struct pvr2_ctrl *cptr)
437 return cptr->
hdw->freqDirty != 0;
440 static void ctrl_freq_clear_dirty(
struct pvr2_ctrl *cptr)
442 cptr->
hdw->freqDirty = 0;
445 static int ctrl_freq_set(
struct pvr2_ctrl *cptr,
int m,
int v)
447 pvr2_hdw_set_cur_freq(cptr->
hdw,v);
451 static int ctrl_cropl_min_get(
struct pvr2_ctrl *cptr,
int *
left)
454 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
462 static int ctrl_cropl_max_get(
struct pvr2_ctrl *cptr,
int *left)
465 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
470 if (cap->
bounds.width > cptr->
hdw->cropw_val) {
471 *left += cap->
bounds.width - cptr->
hdw->cropw_val;
476 static int ctrl_cropt_min_get(
struct pvr2_ctrl *cptr,
int *
top)
479 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
487 static int ctrl_cropt_max_get(
struct pvr2_ctrl *cptr,
int *top)
490 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
495 if (cap->
bounds.height > cptr->
hdw->croph_val) {
496 *top += cap->
bounds.height - cptr->
hdw->croph_val;
504 int stat, bleftend, cleft;
506 stat = pvr2_hdw_check_cropcap(cptr->
hdw);
511 cleft = cptr->
hdw->cropl_val;
513 *width = cleft < bleftend ? bleftend-cleft : 0;
520 int stat, btopend, ctop;
522 stat = pvr2_hdw_check_cropcap(cptr->
hdw);
527 ctop = cptr->
hdw->cropt_val;
529 *height = ctop < btopend ? btopend-ctop : 0;
533 static int ctrl_get_cropcapbl(
struct pvr2_ctrl *cptr,
int *val)
536 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
544 static int ctrl_get_cropcapbt(
struct pvr2_ctrl *cptr,
int *val)
547 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
555 static int ctrl_get_cropcapbw(
struct pvr2_ctrl *cptr,
int *val)
558 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
566 static int ctrl_get_cropcapbh(
struct pvr2_ctrl *cptr,
int *val)
569 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
573 *val = cap->
bounds.height;
577 static int ctrl_get_cropcapdl(
struct pvr2_ctrl *cptr,
int *val)
580 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
588 static int ctrl_get_cropcapdt(
struct pvr2_ctrl *cptr,
int *val)
591 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
599 static int ctrl_get_cropcapdw(
struct pvr2_ctrl *cptr,
int *val)
602 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
610 static int ctrl_get_cropcapdh(
struct pvr2_ctrl *cptr,
int *val)
613 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
621 static int ctrl_get_cropcappan(
struct pvr2_ctrl *cptr,
int *val)
624 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
632 static int ctrl_get_cropcappad(
struct pvr2_ctrl *cptr,
int *val)
635 int stat = pvr2_hdw_check_cropcap(cptr->
hdw);
643 static int ctrl_vres_max_get(
struct pvr2_ctrl *cptr,
int *vp)
654 static int ctrl_vres_min_get(
struct pvr2_ctrl *cptr,
int *vp)
657 if (cptr->
hdw->hdw_desc->flag_has_cx25840) {
665 static int ctrl_get_input(
struct pvr2_ctrl *cptr,
int *vp)
667 *vp = cptr->
hdw->input_val;
671 static int ctrl_check_input(
struct pvr2_ctrl *cptr,
int v)
673 return ((1 << v) & cptr->
hdw->input_allowed_mask) != 0;
676 static int ctrl_set_input(
struct pvr2_ctrl *cptr,
int m,
int v)
678 return pvr2_hdw_set_input(cptr->
hdw,v);
681 static int ctrl_isdirty_input(
struct pvr2_ctrl *cptr)
683 return cptr->
hdw->input_dirty != 0;
686 static void ctrl_cleardirty_input(
struct pvr2_ctrl *cptr)
688 cptr->
hdw->input_dirty = 0;
692 static int ctrl_freq_max_get(
struct pvr2_ctrl *cptr,
int *vp)
714 static int ctrl_freq_min_get(
struct pvr2_ctrl *cptr,
int *vp)
736 static int ctrl_cx2341x_is_dirty(
struct pvr2_ctrl *cptr)
738 return cptr->
hdw->enc_stale != 0;
741 static void ctrl_cx2341x_clear_dirty(
struct pvr2_ctrl *cptr)
743 cptr->
hdw->enc_stale = 0;
744 cptr->
hdw->enc_unsafe_stale = 0;
747 static int ctrl_cx2341x_get(
struct pvr2_ctrl *cptr,
int *vp)
756 c1.id = cptr->
info->v4l_id;
764 static int ctrl_cx2341x_set(
struct pvr2_ctrl *cptr,
int m,
int v)
774 c1.id = cptr->
info->v4l_id;
795 static unsigned int ctrl_cx2341x_getv4lflags(
struct pvr2_ctrl *cptr)
799 qctrl.id = cptr->
info->v4l_id;
820 static int ctrl_streamingenabled_get(
struct pvr2_ctrl *cptr,
int *vp)
822 *vp = cptr->
hdw->state_pipeline_req;
826 static int ctrl_masterstate_get(
struct pvr2_ctrl *cptr,
int *vp)
828 *vp = cptr->
hdw->master_state;
832 static int ctrl_hsm_get(
struct pvr2_ctrl *cptr,
int *vp)
841 static int ctrl_stddetect_get(
struct pvr2_ctrl *cptr,
int *vp)
843 *vp = pvr2_hdw_get_detected_std(cptr->
hdw);
847 static int ctrl_stdavail_get(
struct pvr2_ctrl *cptr,
int *vp)
849 *vp = cptr->
hdw->std_mask_avail;
853 static int ctrl_stdavail_set(
struct pvr2_ctrl *cptr,
int m,
int v)
858 ns = (ns & ~m) | (v & m);
865 static int ctrl_std_val_to_sym(
struct pvr2_ctrl *cptr,
int msk,
int val,
866 char *bufPtr,
unsigned int bufSize,
873 static int ctrl_std_sym_to_val(
struct pvr2_ctrl *cptr,
874 const char *bufPtr,
unsigned int bufSize,
880 if (ret < 0)
return ret;
881 if (mskp) *mskp =
id;
882 if (valp) *valp =
id;
886 static int ctrl_stdcur_get(
struct pvr2_ctrl *cptr,
int *vp)
888 *vp = cptr->
hdw->std_mask_cur;
892 static int ctrl_stdcur_set(
struct pvr2_ctrl *cptr,
int m,
int v)
897 ns = (ns & ~m) | (v & m);
904 static int ctrl_stdcur_is_dirty(
struct pvr2_ctrl *cptr)
906 return cptr->
hdw->std_dirty != 0;
909 static void ctrl_stdcur_clear_dirty(
struct pvr2_ctrl *cptr)
911 cptr->
hdw->std_dirty = 0;
914 static int ctrl_signal_get(
struct pvr2_ctrl *cptr,
int *vp)
922 static int ctrl_audio_modes_present_get(
struct pvr2_ctrl *cptr,
int *vp)
925 unsigned int subchan;
946 #define DEFINT(vmin,vmax) \
947 .type = pvr2_ctl_int, \
948 .def.type_int.min_value = vmin, \
949 .def.type_int.max_value = vmax
951 #define DEFENUM(tab) \
952 .type = pvr2_ctl_enum, \
953 .def.type_enum.count = ARRAY_SIZE(tab), \
954 .def.type_enum.value_names = tab
957 .type = pvr2_ctl_bool
959 #define DEFMASK(msk,tab) \
960 .type = pvr2_ctl_bitmask, \
961 .def.type_bitmask.valid_bits = msk, \
962 .def.type_bitmask.bit_names = tab
964 #define DEFREF(vname) \
965 .set_value = ctrl_set_##vname, \
966 .get_value = ctrl_get_##vname, \
967 .is_dirty = ctrl_isdirty_##vname, \
968 .clear_dirty = ctrl_cleardirty_##vname
971 #define VCREATE_FUNCS(vname) \
972 static int ctrl_get_##vname(struct pvr2_ctrl *cptr,int *vp) \
973 {*vp = cptr->hdw->vname##_val; return 0;} \
974 static int ctrl_set_##vname(struct pvr2_ctrl *cptr,int m,int v) \
975 {cptr->hdw->vname##_val = v; cptr->hdw->vname##_dirty = !0; return 0;} \
976 static int ctrl_isdirty_##vname(struct pvr2_ctrl *cptr) \
977 {return cptr->hdw->vname##_dirty != 0;} \
978 static void ctrl_cleardirty_##vname(struct pvr2_ctrl *cptr) \
979 {cptr->hdw->vname##_dirty = 0;}
1003 .desc =
"Brightness",
1004 .name =
"brightness",
1005 .default_value = 128,
1012 .default_value = 68,
1017 .desc =
"Saturation",
1018 .name =
"saturation",
1019 .default_value = 64,
1033 .default_value = 62000,
1065 .desc =
"Capture crop left margin",
1066 .name =
"crop_left",
1071 .get_min_value = ctrl_cropl_min_get,
1072 .get_max_value = ctrl_cropl_max_get,
1073 .get_def_value = ctrl_get_cropcapdl,
1075 .desc =
"Capture crop top margin",
1081 .get_min_value = ctrl_cropt_min_get,
1082 .get_max_value = ctrl_cropt_max_get,
1083 .get_def_value = ctrl_get_cropcapdt,
1085 .desc =
"Capture crop width",
1086 .name =
"crop_width",
1088 .default_value = 720,
1091 .get_max_value = ctrl_cropw_max_get,
1092 .get_def_value = ctrl_get_cropcapdw,
1094 .desc =
"Capture crop height",
1095 .name =
"crop_height",
1097 .default_value = 480,
1100 .get_max_value = ctrl_croph_max_get,
1101 .get_def_value = ctrl_get_cropcapdh,
1103 .desc =
"Capture capability pixel aspect numerator",
1104 .name =
"cropcap_pixel_numerator",
1106 .get_value = ctrl_get_cropcappan,
1108 .desc =
"Capture capability pixel aspect denominator",
1109 .name =
"cropcap_pixel_denominator",
1111 .get_value = ctrl_get_cropcappad,
1113 .desc =
"Capture capability bounds top",
1114 .name =
"cropcap_bounds_top",
1116 .get_value = ctrl_get_cropcapbt,
1118 .desc =
"Capture capability bounds left",
1119 .name =
"cropcap_bounds_left",
1121 .get_value = ctrl_get_cropcapbl,
1123 .desc =
"Capture capability bounds width",
1124 .name =
"cropcap_bounds_width",
1126 .get_value = ctrl_get_cropcapbw,
1128 .desc =
"Capture capability bounds height",
1129 .name =
"cropcap_bounds_height",
1131 .get_value = ctrl_get_cropcapbh,
1133 .desc =
"Video Source",
1137 .check_value = ctrl_check_input,
1139 DEFENUM(control_values_input),
1141 .desc =
"Audio Mode",
1142 .name =
"audio_mode",
1146 DEFENUM(control_values_audiomode),
1148 .desc =
"Horizontal capture resolution",
1149 .name =
"resolution_hor",
1151 .default_value = 720,
1155 .desc =
"Vertical capture resolution",
1156 .name =
"resolution_ver",
1158 .default_value = 480,
1163 .get_max_value = ctrl_vres_max_get,
1164 .get_min_value = ctrl_vres_min_get,
1168 .desc =
"Audio Sampling Frequency",
1171 DEFENUM(control_values_srate),
1173 .desc =
"Tuner Frequency (Hz)",
1174 .name =
"frequency",
1177 .set_value = ctrl_freq_set,
1178 .get_value = ctrl_freq_get,
1179 .is_dirty = ctrl_freq_is_dirty,
1180 .clear_dirty = ctrl_freq_clear_dirty,
1184 .get_max_value = ctrl_freq_max_get,
1185 .get_min_value = ctrl_freq_min_get,
1189 .set_value = ctrl_channel_set,
1190 .get_value = ctrl_channel_get,
1193 .desc =
"Channel Program Frequency",
1194 .name =
"freq_table_value",
1195 .set_value = ctrl_channelfreq_set,
1196 .get_value = ctrl_channelfreq_get,
1200 .get_max_value = ctrl_freq_max_get,
1201 .get_min_value = ctrl_freq_min_get,
1203 .desc =
"Channel Program ID",
1204 .name =
"freq_table_channel",
1205 .set_value = ctrl_channelprog_set,
1206 .get_value = ctrl_channelprog_get,
1209 .desc =
"Streaming Enabled",
1210 .name =
"streaming_enabled",
1211 .get_value = ctrl_streamingenabled_get,
1214 .desc =
"USB Speed",
1215 .name =
"usb_speed",
1216 .get_value = ctrl_hsm_get,
1219 .desc =
"Master State",
1220 .name =
"master_state",
1221 .get_value = ctrl_masterstate_get,
1224 .desc =
"Signal Present",
1225 .name =
"signal_present",
1226 .get_value = ctrl_signal_get,
1229 .desc =
"Audio Modes Present",
1230 .name =
"audio_modes_present",
1231 .get_value = ctrl_audio_modes_present_get,
1240 control_values_audiomode),
1242 .desc =
"Video Standards Available Mask",
1243 .name =
"video_standard_mask_available",
1246 .get_value = ctrl_stdavail_get,
1247 .set_value = ctrl_stdavail_set,
1248 .val_to_sym = ctrl_std_val_to_sym,
1249 .sym_to_val = ctrl_std_sym_to_val,
1252 .desc =
"Video Standards In Use Mask",
1253 .name =
"video_standard_mask_active",
1256 .get_value = ctrl_stdcur_get,
1257 .set_value = ctrl_stdcur_set,
1258 .is_dirty = ctrl_stdcur_is_dirty,
1259 .clear_dirty = ctrl_stdcur_clear_dirty,
1260 .val_to_sym = ctrl_std_val_to_sym,
1261 .sym_to_val = ctrl_std_sym_to_val,
1264 .desc =
"Video Standards Detected Mask",
1265 .name =
"video_standard_mask_detected",
1268 .get_value = ctrl_stddetect_get,
1269 .val_to_sym = ctrl_std_val_to_sym,
1270 .sym_to_val = ctrl_std_sym_to_val,
1275 #define CTRLDEF_COUNT ARRAY_SIZE(control_defs)
1322 static void pvr2_hdw_set_cur_freq(
struct pvr2_hdw *hdw,
unsigned long val)
1361 static int pvr2_locate_firmware(
struct pvr2_hdw *hdw,
1363 const char *fwtypename,
1364 unsigned int fwcount,
1365 const char *fwnames[])
1369 for (idx = 0; idx < fwcount; idx++) {
1380 if (ret == -
ENOENT)
continue;
1382 "request_firmware fatal error with code=%d",ret);
1387 " Device %s firmware"
1388 " seems to be missing.",
1391 "Did you install the pvrusb2 firmware files"
1392 " in their proper location?");
1395 "request_firmware unable to locate %s file %s",
1396 fwtypename,fwnames[0]);
1399 "request_firmware unable to locate"
1400 " one of the following %s files:",
1402 for (idx = 0; idx < fwcount; idx++) {
1404 "request_firmware: Failed to find %s",
1422 static int pvr2_upload_firmware1(
struct pvr2_hdw *hdw)
1427 unsigned int fwsize;
1431 if (!hdw->
hdw_desc->fx2_firmware.cnt) {
1434 "Connected device type defines"
1435 " no firmware to upload; ignoring firmware");
1443 ret = pvr2_locate_firmware(hdw,&fw_entry,
"fx2 controller",
1453 pipe = usb_sndctrlpipe(hdw->
usb_dev, 0);
1454 fwsize = fw_entry->
size;
1456 if ((fwsize != 0x2000) &&
1457 (!(hdw->
hdw_desc->flag_fx2_16kb && (fwsize == 0x4000)))) {
1458 if (hdw->
hdw_desc->flag_fx2_16kb) {
1460 "Wrong fx2 firmware size"
1461 " (expected 8192 or 16384, got %u)",
1465 "Wrong fx2 firmware size"
1466 " (expected 8192, got %u)",
1474 if (fw_ptr ==
NULL){
1486 for (address = 0; address < fwsize; address += 0x800) {
1487 memcpy(fw_ptr, fw_entry->
data + address, 0x800);
1489 0, fw_ptr, 0x800,
HZ);
1503 if (ret == fwsize) {
1523 unsigned int pipe, fw_len, fw_done, bcnt,
icnt;
1527 static const char *fw_files[] = {
1531 if (hdw->
hdw_desc->flag_skip_cx23416_firmware) {
1537 ret = pvr2_locate_firmware(hdw,&fw_entry,
"encoder",
1539 if (ret < 0)
return ret;
1573 ret |= pvr2_issue_simple_cmd(hdw,
FX2CMD_MEMSEL | (1 << 8) | (0 << 16));
1577 "firmware2 upload prep failed, ret=%d",ret);
1584 fw_len = fw_entry->
size;
1586 if (fw_len %
sizeof(
u32)) {
1588 "size of %s firmware"
1589 " must be a multiple of %zu bytes",
1590 fw_files[fwidx],
sizeof(
u32));
1597 if (fw_ptr ==
NULL){
1600 "failed to allocate memory for firmware2 upload");
1608 for (fw_done = 0; fw_done < fw_len;) {
1609 bcnt = fw_len - fw_done;
1611 memcpy(fw_ptr, fw_entry->
data + fw_done, bcnt);
1624 for (icnt = 0; icnt < bcnt/4 ; icnt++)
1628 &actual_length,
HZ);
1629 ret |= (actual_length != bcnt);
1635 fw_files[fwidx],fw_done,fw_len);
1642 "firmware2 upload transfer failure");
1650 ret |= pvr2_issue_simple_cmd(hdw,
FX2CMD_MEMSEL | (1 << 8) | (0 << 16));
1654 "firmware2 upload post-proc failure");
1658 if (hdw->
hdw_desc->signal_routing_scheme ==
1668 static const char *pvr2_get_state_name(
unsigned int st)
1671 return pvr2_state_names[
st];
1676 static int pvr2_decoder_enable(
struct pvr2_hdw *hdw,
int enablefl)
1683 (enablefl ?
"on" :
"off"));
1694 "WARNING: No decoder present");
1696 trace_stbit(
"flag_decoder_missed",
1709 static int pvr2_hdw_untrip_unlocked(
struct pvr2_hdw *hdw)
1714 "Clearing driver error statuss");
1723 fl = pvr2_hdw_untrip_unlocked(hdw);
1725 if (fl) pvr2_hdw_state_sched(hdw);
1742 pvr2_hdw_untrip_unlocked(hdw);
1746 "/*--TRACE_STREAM--*/ %s",
1747 enable_flag ?
"enable" :
"disable");
1749 pvr2_hdw_state_sched(hdw);
1751 if ((ret = pvr2_hdw_wait(hdw,0)) < 0)
return ret;
1755 if ((ret = pvr2_hdw_wait(hdw,st)) < 0)
return ret;
1769 trace_stbit(
"state_pipeline_config",
1771 pvr2_hdw_state_sched(hdw);
1775 return pvr2_hdw_wait(hdw,0);
1779 static int get_default_tuner_type(
struct pvr2_hdw *hdw)
1783 if ((unit_number >= 0) && (unit_number <
PVR_NUM)) {
1784 tp =
tuner[unit_number];
1786 if (tp < 0)
return -
EINVAL;
1797 if ((unit_number >= 0) && (unit_number <
PVR_NUM)) {
1798 tp = video_std[unit_number];
1805 static unsigned int get_default_error_tolerance(
struct pvr2_hdw *hdw)
1809 if ((unit_number >= 0) && (unit_number <
PVR_NUM)) {
1810 tp = tolerance[unit_number];
1816 static int pvr2_hdw_check_firmware(
struct pvr2_hdw *hdw)
1825 result = pvr2_send_request_ex(hdw,
HZ*1,!0,
1828 if (result < 0)
break;
1832 "Probe of device endpoint 1 result status %d",
1836 "Probe of device endpoint 1 succeeded");
1879 static void pvr2_hdw_setup_std(
struct pvr2_hdw *hdw)
1885 std1 = get_default_standard(hdw);
1886 std3 = std1 ? 0 : hdw->
hdw_desc->default_std_mask;
1890 "Supported video standard(s) reported available"
1891 " in hardware: %.*s",
1900 "Expanding supported video standards"
1901 " to include: %.*s",
1911 "Initial video standard forced to %.*s",
1920 "Initial video standard"
1921 " (determined by device type): %.*s",bcnt,buf);
1929 for (idx = 0; idx <
ARRAY_SIZE(std_eeprom_maps); idx++) {
1930 if (std_eeprom_maps[idx].
msk ?
1931 ((std_eeprom_maps[idx].
pat ^
1933 std_eeprom_maps[idx].
msk) :
1934 (std_eeprom_maps[
idx].
pat !=
1937 std_eeprom_maps[idx].
std);
1939 "Initial video standard guessed as %.*s",
1950 static unsigned int pvr2_copy_i2c_addr_list(
1951 unsigned short *
dst,
const unsigned char *
src,
1952 unsigned int dst_max)
1954 unsigned int cnt = 0;
1956 while (src[cnt] && (cnt + 1) < dst_max) {
1965 static void pvr2_hdw_cx25840_vbi_hack(
struct pvr2_hdw *hdw)
1984 " Executing cx25840 VBI hack",
1991 vbi, s_sliced_fmt, &
fmt.fmt.sliced);
1995 static int pvr2_hdw_load_subdev(
struct pvr2_hdw *hdw,
2001 unsigned int i2ccnt;
2002 const unsigned char *
p;
2007 fname = (mid <
ARRAY_SIZE(module_names)) ? module_names[mid] :
NULL;
2010 "Module ID %u for device %s has no name?"
2011 " The driver might have a configuration problem.",
2017 "Module ID %u (%s) for device %s being loaded...",
2023 if (!i2ccnt && ((p = (mid <
ARRAY_SIZE(module_i2c_addresses)) ?
2024 module_i2c_addresses[mid] :
NULL) != NULL)) {
2026 i2ccnt = pvr2_copy_i2c_addr_list(i2caddr, p,
2031 " Using default i2c address list",
2038 "Module ID %u (%s) for device %s:"
2039 " No i2c addresses."
2040 " The driver might have a configuration problem.",
2041 mid, fname, hdw->
hdw_desc->description);
2048 " Setting up with specified i2c address 0x%x",
2051 fname, i2caddr[0], NULL);
2055 " Setting up with address probe list",
2063 "Module ID %u (%s) for device %s failed to load."
2064 " Possible missing sub-device kernel module or"
2065 " initialization failure within module.",
2066 mid, fname, hdw->
hdw_desc->description);
2091 static void pvr2_hdw_load_modules(
struct pvr2_hdw *hdw)
2098 cm = &hdw->
hdw_desc->client_modules;
2099 for (idx = 0; idx < cm->
cnt; idx++) {
2100 request_module(cm->
lst[idx]);
2104 for (idx = 0; idx < ct->
cnt; idx++) {
2105 if (pvr2_hdw_load_subdev(hdw, &ct->
lst[idx]) < 0) okFl = 0;
2114 static void pvr2_hdw_setup_low(
struct pvr2_hdw *hdw)
2120 if (hdw->
hdw_desc->fx2_firmware.cnt) {
2123 (hdw->
usb_intf->cur_altsetting->desc.bNumEndpoints
2127 "USB endpoint config looks strange"
2128 "; possibly firmware needs to be"
2133 reloadFl = !pvr2_hdw_check_firmware(hdw);
2136 "Check for FX2 firmware failed"
2137 "; possibly firmware needs to be"
2142 if (pvr2_upload_firmware1(hdw) != 0) {
2144 "Failure uploading firmware1");
2155 if (!hdw->
hdw_desc->flag_no_powerup) {
2162 pvr2_issue_simple_cmd(hdw,
2172 pvr2_hdw_load_modules(hdw);
2179 if (cptr->
info->skip_init)
continue;
2180 if (!cptr->
info->set_value)
continue;
2181 cptr->
info->set_value(cptr,~0,cptr->
info->default_value);
2184 pvr2_hdw_cx25840_vbi_hack(hdw);
2198 if (hdw->
hdw_desc->flag_has_hauppauge_rom) {
2199 ret = pvr2_hdw_get_eeprom_addr(hdw);
2203 "Unable to determine location of eeprom,"
2229 pvr2_hdw_setup_std(hdw);
2231 if (!get_default_tuner_type(hdw)) {
2233 "pvr2_hdw_setup: Tuner type overridden to %d",
2240 if (hdw->
hdw_desc->signal_routing_scheme ==
2247 pvr2_hdw_commit_setup(hdw);
2252 "pvr2_hdw_setup: video stream is %p",hdw->
vid_stream);
2254 idx = get_default_error_tolerance(hdw);
2257 "pvr2_hdw_setup: video stream %p"
2258 " setting tolerance %u",
2269 pvr2_hdw_state_sched(hdw);
2276 static void pvr2_hdw_setup(
struct pvr2_hdw *hdw)
2280 pvr2_hdw_setup_low(hdw);
2282 "pvr2_hdw_setup(hdw=%p) done, ok=%d init_ok=%d",
2288 "Device initialization"
2289 " completed successfully.");
2295 "Device microcontroller firmware"
2296 " (re)loaded; it should now reset"
2302 "Device initialization was not successful.");
2306 "Giving up since device"
2307 " microcontroller firmware"
2308 " appears to be missing.");
2315 "***WARNING*** pvrusb2 driver initialization"
2316 " failed due to the failure of one or more"
2317 " sub-device kernel modules.");
2320 "You need to resolve the failing condition"
2321 " before this driver can function. There"
2322 " should be some earlier messages giving more"
2323 " information about the problem.");
2329 "Attempting pvrusb2 recovery by reloading"
2330 " primary firmware.");
2333 "If this works, device should disconnect"
2334 " and reconnect in a sane state.");
2336 pvr2_upload_firmware1(hdw);
2340 "***WARNING*** pvrusb2 device hardware"
2341 " appears to be jammed"
2342 " and I can't clear it.");
2345 "You might need to power cycle"
2346 " the pvrusb2 device"
2347 " in order to recover.");
2358 void (*callback_func)(
void *),
2359 void *callback_data)
2373 pvr2_hdw_setup(hdw);
2384 unsigned int idx,cnt1,cnt2,
m;
2388 struct usb_device *usb_dev;
2394 usb_dev = interface_to_usbdev(intf);
2398 if (hdw_desc == NULL) {
2400 " No device description pointer,"
2401 " unable to continue.");
2404 " to get it included in the driver\n");
2416 "WARNING: Support for this device (%s) is"
2419 "Important functionality might not be"
2420 " entirely working.");
2422 "Please consider contacting the driver author to"
2423 " help with further stabilization of the driver.");
2426 if (!hdw)
goto fail;
2435 pvr2_hdw_decoder_stabilization_timeout;
2483 for (idx = 0; idx < 32; idx++) {
2488 cptr->
info = control_defs+
idx;
2493 if (m)
for (idx = 0; idx < (
sizeof(
m) << 3); idx++) {
2494 if (!((1 << idx) & m))
continue;
2495 hdw->input_val =
idx;
2513 ciptr->
is_dirty = ctrl_cx2341x_is_dirty;
2514 if (!idx) ciptr->
clear_dirty = ctrl_cx2341x_clear_dirty;
2524 switch (qctrl.
type) {
2550 for (idx = 0; idx < 32; idx++) {
2551 if (!(valid_std_mask & (1 << idx)))
continue;
2606 "Error registering with v4l core, giving up");
2610 for (idx = 0; idx <
PVR_NUM; idx++) {
2611 if (unit_pointers[idx])
continue;
2613 unit_pointers[
idx] = hdw;
2626 if (cnt1 >=
sizeof(hdw->
name)) cnt1 =
sizeof(hdw->
name)-1;
2627 hdw->
name[cnt1] = 0;
2643 ifnum = hdw->
usb_intf->cur_altsetting->desc.bInterfaceNumber;
2675 static void pvr2_hdw_remove_usb_stuff(
struct pvr2_hdw *hdw)
2732 pvr2_hdw_remove_usb_stuff(hdw);
2758 pvr2_hdw_remove_usb_stuff(hdw);
2782 unsigned int ctl_id)
2791 i = cptr->
info->internal_id;
2792 if (i && (i == ctl_id))
return cptr;
2808 i = cptr->
info->v4l_id;
2809 if (i && (i == ctl_id))
return cptr;
2818 unsigned int ctl_id)
2828 i = cptr->
info->v4l_id;
2830 if (i <= ctl_id)
continue;
2831 if (cp2 && (cp2->
info->v4l_id < i))
continue;
2851 static void pvr2_subdev_set_control(
struct pvr2_hdw *hdw,
int id,
2852 const char *name,
int val)
2862 #define PVR2_SUBDEV_SET_CONTROL(hdw, id, lab) \
2863 if ((hdw)->lab##_dirty || (hdw)->force_dirty) { \
2864 pvr2_subdev_set_control(hdw, id, #lab, (hdw)->lab##_val); \
2872 video, querystd, &std);
2878 static void pvr2_subdev_update(
struct pvr2_hdw *hdw)
2887 struct tuner_setup
setup;
2892 setup.addr = ADDR_UNSET;
2894 setup.mode_mask = T_RADIO | T_ANALOG_TV;
2910 pvr2_hdw_cx25840_vbi_hack(hdw);
2926 if (hdw->input_dirty || hdw->audiomode_dirty || hdw->
force_dirty) {
2928 memset(&vt, 0,
sizeof(vt));
2931 vt.audmode = hdw->audiomode_val;
2941 memset(&freq, 0,
sizeof(freq));
2944 freq.frequency = (fv * 2) / 125;
2946 freq.frequency = fv / 62500;
2957 s_frequency, &freq);
2960 if (hdw->res_hor_dirty || hdw->res_ver_dirty || hdw->
force_dirty) {
2961 struct v4l2_mbus_framefmt
fmt;
2963 fmt.width = hdw->res_hor_val;
2964 fmt.height = hdw->res_ver_val;
2975 switch (hdw->srate_val) {
2988 audio, s_clock_freq, val);
2996 if (
id >=
ARRAY_SIZE(pvr2_module_update_functions))
continue;
2997 fp = pvr2_module_update_functions[
id];
3011 static int pvr2_hdw_commit_setup(
struct pvr2_hdw *hdw)
3018 unsigned int bcnt,
ccnt;
3022 if (!cptr->
info->is_dirty)
continue;
3023 if (!cptr->
info->is_dirty(cptr))
continue;
3027 bcnt =
scnprintf(buf,
sizeof(buf),
"\"%s\" <-- ",
3030 cptr->
info->get_value(cptr,&value);
3033 sizeof(buf)-bcnt,&ccnt);
3035 bcnt +=
scnprintf(buf+bcnt,
sizeof(buf)-bcnt,
" <%s>",
3036 get_ctrl_typename(cptr->
info->type));
3038 "/*--TRACE_COMMIT--*/ %.*s",
3049 pvr2_hdw_state_sched(hdw);
3060 static int pvr2_hdw_commit_execute(
struct pvr2_hdw *hdw)
3064 int disruptive_change;
3093 if (nvres != hdw->res_ver_val) {
3094 hdw->res_ver_val = nvres;
3095 hdw->res_ver_dirty = !0;
3103 memset(&c1, 0,
sizeof(c1));
3107 c1.value = gop_size;
3119 if (hdw->res_hor_dirty && hdw->cropw_val < hdw->res_hor_val) {
3120 hdw->cropw_val = hdw->res_hor_val;
3121 hdw->cropw_dirty = !0;
3122 }
else if (hdw->cropw_dirty) {
3123 hdw->res_hor_dirty = !0;
3124 hdw->res_hor_val =
min(720, hdw->cropw_val);
3126 if (hdw->res_ver_dirty && hdw->croph_val < hdw->res_ver_val) {
3127 hdw->croph_val = hdw->res_ver_val;
3128 hdw->croph_dirty = !0;
3129 }
else if (hdw->croph_dirty) {
3131 hdw->res_ver_dirty = !0;
3132 hdw->res_ver_val =
min(nvres, hdw->croph_val);
3143 hdw->res_ver_dirty ||
3144 hdw->res_hor_dirty ||
3157 if (hdw->srate_dirty) {
3165 memset(&c1,0,
sizeof(c1));
3169 c1.value = hdw->srate_val;
3178 if (hdw->
hdw_desc->signal_routing_scheme ==
3193 pvr2_subdev_update(hdw);
3199 if (!cptr->
info->clear_dirty)
continue;
3200 cptr->
info->clear_dirty(cptr);
3224 fl = pvr2_hdw_commit_setup(hdw);
3227 return pvr2_hdw_wait(hdw,0);
3236 fl = pvr2_hdw_state_eval(hdw);
3280 if (result < 0)
break;
3296 static int pvr2_hdw_check_cropcap(
struct pvr2_hdw *hdw)
3314 stat = pvr2_hdw_check_cropcap(hdw);
3347 printk(
KERN_INFO "pvrusb2: ================= START STATUS CARD #%d =================\n", nr);
3351 pvr2_hdw_state_log_state(hdw);
3352 printk(
KERN_INFO "pvrusb2: ================== END STATUS CARD #%d ==================\n", nr);
3358 #define EEPROM_SIZE 8192
3359 #define trace_eeprom(...) pvr2_trace(PVR2_TRACE_EEPROM,__VA_ARGS__)
3360 static u8 *pvr2_full_eeprom_fetch(
struct pvr2_hdw *hdw)
3374 "Failed to allocate memory"
3375 " required to read eeprom");
3379 trace_eeprom(
"Value for eeprom addr from controller was 0x%x",
3385 if (addr & 0x80) addr >>= 1;
3390 mode16 = (addr & 1);
3392 trace_eeprom(
"Examining %d byte eeprom at location 0x%x"
3393 " using %d bit addressing",eepromSize,addr,
3398 msg[0].
len = mode16 ? 2 : 1;
3410 if (pcnt + tcnt > EEPROM_SIZE) pcnt = EEPROM_SIZE-tcnt;
3413 iadd[0] = offs >> 8;
3419 msg[1].
buf = eeprom+tcnt;
3423 "eeprom fetch set offs err=%d",ret);
3440 if ((hdw->
fw_buffer == NULL) == !enable_flag)
break;
3444 "Cleaning up after CPU firmware fetch");
3458 hdw->
fw_size = (mode == 1) ? 0x4000 : 0x2000;
3460 "Preparing to suck out CPU firmware"
3475 "Grabbing CPU firmware");
3476 pipe = usb_rcvctrlpipe(hdw->
usb_dev, 0);
3477 for(address = 0; address < hdw->
fw_size;
3488 "Done grabbing CPU firmware");
3491 "Sucking down EEPROM contents");
3492 hdw->
fw_buffer = pvr2_full_eeprom_fetch(hdw);
3495 "EEPROM content suck failed.");
3500 "Done sucking down EEPROM contents");
3515 char *buf,
unsigned int cnt)
3529 "Read firmware data offs=%d EOF",
3540 "Read firmware data offs=%d cnt=%d",
3574 static void pvr2_ctl_write_complete(
struct urb *
urb)
3576 struct pvr2_hdw *hdw = urb->context;
3583 static void pvr2_ctl_read_complete(
struct urb *urb)
3585 struct pvr2_hdw *hdw = urb->context;
3592 static void pvr2_ctl_timeout(
unsigned long data)
3609 static int pvr2_send_request_ex(
struct pvr2_hdw *hdw,
3610 unsigned int timeout,
int probe_fl,
3611 void *write_data,
unsigned int write_len,
3612 void *read_data,
unsigned int read_len)
3619 "Attempted to execute control transfer"
3623 if (!hdw->
flag_ok && !probe_fl) {
3625 "Attempted to execute control transfer"
3626 " when device not ok");
3632 "Attempted to execute control transfer"
3633 " when USB is disconnected");
3639 if (!write_data) write_len = 0;
3640 if (!read_data) read_len = 0;
3644 "Attempted to execute %d byte"
3645 " control-write transfer (limit=%d)",
3652 "Attempted to execute %d byte"
3653 " control-read transfer (limit=%d)",
3657 if ((!write_len) && (!read_len)) {
3660 "Attempted to execute null control transfer?");
3682 timer.function = pvr2_ctl_timeout;
3687 for (idx = 0; idx < write_len; idx++) {
3689 ((
unsigned char *)write_data)[
idx];
3698 pvr2_ctl_write_complete,
3705 "Failed to submit write-control"
3706 " URB status=%d",status);
3722 pvr2_ctl_read_complete,
3729 "Failed to submit read-control"
3730 " URB status=%d",status);
3756 "Timed out control-write");
3772 "control-write URB failure,"
3783 "control-write URB short,"
3784 " expected=%d got=%d",
3802 "control-read URB failure,"
3813 "control-read URB short,"
3814 " expected=%d got=%d",
3821 for (idx = 0; idx < read_len; idx++) {
3822 ((
unsigned char *)read_data)[
idx] =
3830 if ((status < 0) && (!probe_fl)) {
3838 void *write_data,
unsigned int write_len,
3839 void *read_data,
unsigned int read_len)
3841 return pvr2_send_request_ex(hdw,
HZ*4,0,
3842 write_data,write_len,
3843 read_data,read_len);
3847 static int pvr2_issue_simple_cmd(
struct pvr2_hdw *hdw,
u32 cmdcode)
3850 unsigned int cnt = 1;
3851 unsigned int args = 0;
3854 args = (cmdcode >> 8) & 0xffu;
3855 args = (args > 2) ? 2 : args;
3858 hdw->
cmd_buffer[1] = (cmdcode >> 16) & 0xffu;
3860 hdw->
cmd_buffer[2] = (cmdcode >> 24) & 0xffu;
3865 unsigned int ccnt,bcnt;
3871 "Sending FX2 command 0x%x",cmdcode);
3873 for (idx = 0; idx <
ARRAY_SIZE(pvr2_fx2cmd_desc); idx++) {
3874 if (pvr2_fx2cmd_desc[idx].
id == cmdcode) {
3878 pvr2_fx2cmd_desc[idx].
desc);
3899 pvr2_trace(PVR2_TRACE_INIT,
"%.*s",bcnt,tbuf);
3956 "Device being rendered inoperable");
3961 trace_stbit(
"flag_ok",hdw->
flag_ok);
3962 pvr2_hdw_state_sched(hdw);
3969 pvr2_trace(PVR2_TRACE_INIT,
"Performing a device reset...");
3973 usb_unlock_device(hdw->
usb_dev);
3976 "Failed to lock USB device ret=%d",ret);
3978 if (init_pause_msec) {
3980 "Waiting %u msec for hardware to settle",
4000 "Unable to allocate memory to control CPU reset");
4004 pvr2_trace(PVR2_TRACE_INIT,
"cpureset_assert(%d)",val);
4006 da[0] = val ? 0x01 : 0x00;
4010 pipe = usb_sndctrlpipe(hdw->
usb_dev, 0);
4014 "cpureset_assert(%d) error=%d",val,ret);
4043 "Requesting decoder reset");
4047 pvr2_hdw_cx25840_vbi_hack(hdw);
4051 "Unable to reset decoder: nothing attached");
4056 static int pvr2_hdw_cmd_hcw_demod_reset(
struct pvr2_hdw *hdw,
int onoff)
4059 return pvr2_issue_simple_cmd(hdw,
4062 ((onoff ? 1 : 0) << 16));
4066 static int pvr2_hdw_cmd_onair_fe_power_ctrl(
struct pvr2_hdw *hdw,
int onoff)
4069 return pvr2_issue_simple_cmd(hdw,(onoff ?
4075 static int pvr2_hdw_cmd_onair_digital_path_ctrl(
struct pvr2_hdw *hdw,
4078 return pvr2_issue_simple_cmd(hdw,(onoff ?
4084 static void pvr2_hdw_cmd_modeswitch(
struct pvr2_hdw *hdw,
int digitalFl)
4095 switch (hdw->
hdw_desc->digital_control_scheme) {
4097 pvr2_hdw_cmd_hcw_demod_reset(hdw,digitalFl);
4098 if (cmode == PVR2_PATHWAY_ANALOG) {
4110 pvr2_hdw_cmd_onair_fe_power_ctrl(hdw,digitalFl);
4115 pvr2_hdw_untrip_unlocked(hdw);
4120 static void pvr2_led_ctrl_hauppauge(
struct pvr2_hdw *hdw,
int onoff)
4145 static void pvr2_led_ctrl(
struct pvr2_hdw *hdw,
int onoff)
4147 unsigned int scheme_id;
4150 if ((!onoff) == (!hdw->
led_on))
return;
4152 hdw->
led_on = onoff != 0;
4154 scheme_id = hdw->
hdw_desc->led_scheme;
4156 fp = led_methods[scheme_id];
4161 if (fp) (*fp)(hdw,
onoff);
4166 static int pvr2_hdw_cmd_usbstream(
struct pvr2_hdw *hdw,
int runFl)
4173 return pvr2_issue_simple_cmd(hdw,
4189 switch (hdw->
hdw_desc->digital_control_scheme) {
4191 return pvr2_issue_simple_cmd(hdw,
4196 ret = pvr2_issue_simple_cmd(hdw,
4200 if (ret)
return ret;
4201 return pvr2_hdw_cmd_onair_digital_path_ctrl(hdw,runFl);
4209 static int state_eval_pathway_ok(
struct pvr2_hdw *hdw)
4227 static int state_eval_encoder_ok(
struct pvr2_hdw *hdw)
4236 if (!hdw->
hdw_desc->flag_digital_requires_cx23416)
return 0;
4253 static int state_eval_encoder_config(
struct pvr2_hdw *hdw)
4284 trace_stbit(
"state_encoder_waitok",
4320 static int state_check_disable_encoder_run(
struct pvr2_hdw *hdw)
4333 case PVR2_PATHWAY_ANALOG:
4365 static int state_check_enable_encoder_run(
struct pvr2_hdw *hdw)
4378 case PVR2_PATHWAY_ANALOG:
4386 if ((hdw->
hdw_desc->digital_control_scheme ==
4411 static int state_eval_encoder_run(
struct pvr2_hdw *hdw)
4414 if (!state_check_disable_encoder_run(hdw))
return 0;
4421 if (!state_check_enable_encoder_run(hdw))
return 0;
4436 static void pvr2_hdw_quiescent_timeout(
unsigned long data)
4447 static void pvr2_hdw_decoder_stabilization_timeout(
unsigned long data)
4458 static void pvr2_hdw_encoder_wait_timeout(
unsigned long data)
4469 static void pvr2_hdw_encoder_run_timeout(
unsigned long data)
4482 static int state_eval_decoder_run(
struct pvr2_hdw *hdw)
4491 pvr2_decoder_enable(hdw,0);
4537 if (pvr2_decoder_enable(hdw,!0) < 0)
return 0;
4559 static int state_eval_usbstream_run(
struct pvr2_hdw *hdw)
4567 (hdw->
hdw_desc->flag_digital_requires_cx23416)) {
4576 pvr2_hdw_cmd_usbstream(hdw,0);
4586 (hdw->
hdw_desc->flag_digital_requires_cx23416)) {
4589 if (hdw->
hdw_desc->digital_control_scheme ==
4599 if (pvr2_hdw_cmd_usbstream(hdw,!0) < 0)
return 0;
4608 static int state_eval_pipeline_config(
struct pvr2_hdw *hdw)
4612 pvr2_hdw_commit_execute(hdw);
4620 static int state_update_pipeline_state(
struct pvr2_hdw *hdw)
4645 state_eval_pathway_ok,
4646 state_eval_pipeline_config,
4647 state_eval_encoder_ok,
4648 state_eval_encoder_config,
4649 state_eval_decoder_run,
4650 state_eval_encoder_run,
4651 state_eval_usbstream_run,
4656 static int pvr2_hdw_state_update(
struct pvr2_hdw *hdw)
4659 int state_updated = 0;
4677 state_update_pipeline_state(hdw);
4680 if ((*eval_funcs[i])(hdw)) {
4683 state_update_pipeline_state(hdw);
4686 }
while (check_flag && hdw->
flag_ok);
4689 return state_updated;
4693 static unsigned int print_input_mask(
unsigned int msk,
4694 char *buf,
unsigned int acnt)
4696 unsigned int idx,ccnt;
4697 unsigned int tcnt = 0;
4698 for (idx = 0; idx <
ARRAY_SIZE(control_values_input); idx++) {
4699 if (!((1 << idx) & msk))
continue;
4704 control_values_input[idx]);
4711 static const char *pvr2_pathway_state_name(
int id)
4714 case PVR2_PATHWAY_ANALOG:
return "analog";
4716 default:
return "unknown";
4721 static unsigned int pvr2_hdw_report_unlocked(
struct pvr2_hdw *hdw,
int which,
4722 char *buf,
unsigned int acnt)
4728 "driver:%s%s%s%s%s <mode=%s>",
4729 (hdw->
flag_ok ?
" <ok>" :
" <fail>"),
4740 "pipeline:%s%s%s%s",
4743 " <configok>" :
" <stale>"),
4749 "worker:%s%s%s%s%s%s%s",
4752 "<decode:run>" :
" <decode:start>") :
4754 "" :
" <decode:stop>")),
4756 " <decode:quiescent>" :
""),
4758 "" :
" <encode:init>"),
4762 " <encode:firstrun>") :
4765 " <encode:virgin>")),
4767 " <encode:configok>" :
4769 "" :
" <encode:waitok>")),
4771 " <usb:run>" :
" <usb:stop>"),
4773 " <pathway:ok>" :
""));
4780 unsigned int tcnt = 0;
4785 "Hardware supported inputs: ");
4793 "; allowed inputs: ");
4810 " URBs: queued=%u idle=%u ready=%u"
4811 " processed=%u failed=%u",
4812 stats.bytes_processed,
4813 stats.buffers_in_queue,
4814 stats.buffers_in_idle,
4815 stats.buffers_in_ready,
4816 stats.buffers_processed,
4817 stats.buffers_failed);
4821 return scnprintf(buf, acnt,
"ir scheme: id=%d %s",
id,
4823 "?" : ir_scheme_names[
id]));
4834 static unsigned int pvr2_hdw_report_clients(
struct pvr2_hdw *hdw,
4835 char *buf,
unsigned int acnt)
4838 unsigned int tcnt = 0;
4844 ccnt =
scnprintf(buf, acnt,
"Associated v4l2-subdev drivers and I2C clients:\n");
4849 if (
id <
ARRAY_SIZE(module_names)) p = module_names[
id];
4851 ccnt =
scnprintf(buf + tcnt, acnt - tcnt,
" %s:", p);
4854 ccnt =
scnprintf(buf + tcnt, acnt - tcnt,
4855 " (unknown id=%u):",
id);
4858 client = v4l2_get_subdevdata(sd);
4860 ccnt =
scnprintf(buf + tcnt, acnt - tcnt,
4861 " %s @ %02x\n", client->
name,
4865 ccnt =
scnprintf(buf + tcnt, acnt - tcnt,
4866 " no i2c client\n");
4875 char *buf,
unsigned int acnt)
4877 unsigned int bcnt,ccnt,
idx;
4880 for (idx = 0; ; idx++) {
4881 ccnt = pvr2_hdw_report_unlocked(hdw,idx,buf,acnt);
4883 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
4885 buf[0] =
'\n'; ccnt = 1;
4886 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
4888 ccnt = pvr2_hdw_report_clients(hdw, buf, acnt);
4889 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
4895 static void pvr2_hdw_state_log_state(
struct pvr2_hdw *hdw)
4898 unsigned int idx, ccnt;
4899 unsigned int lcnt, ucnt;
4901 for (idx = 0; ; idx++) {
4902 ccnt = pvr2_hdw_report_unlocked(hdw,idx,buf,
sizeof(buf));
4906 ccnt = pvr2_hdw_report_clients(hdw, buf,
sizeof(buf));
4908 while (ucnt < ccnt) {
4910 while ((lcnt + ucnt < ccnt) && (buf[lcnt + ucnt] !=
'\n')) {
4921 static int pvr2_hdw_state_eval(
struct pvr2_hdw *hdw)
4924 int state_updated = 0;
4925 int callback_flag = 0;
4929 "Drive state check START");
4931 pvr2_hdw_state_log_state(hdw);
4935 state_updated = pvr2_hdw_state_update(hdw);
4944 }
else if ((analog_mode ||
4945 hdw->
hdw_desc->flag_digital_requires_cx23416) &&
4960 "Device state change from %s to %s",
4962 pvr2_get_state_name(st));
4968 if (state_updated) {
4974 pvr2_hdw_state_log_state(hdw);
4977 "Drive state check DONE callback=%d",callback_flag);
4979 return callback_flag;
4984 static void pvr2_hdw_state_sched(
struct pvr2_hdw *hdw)
5017 if (ret)
return ret;
5018 nval = (cval & ~msk) | (val & msk);
5020 "GPIO direction changing 0x%x:0x%x"
5021 " from 0x%x to 0x%x",
5026 "GPIO direction changing to 0x%x",nval);
5038 if (ret)
return ret;
5039 nval = (cval & ~msk) | (val & msk);
5041 "GPIO output changing 0x%x:0x%x from 0x%x to 0x%x",
5046 "GPIO output changing to 0x%x",nval);
5055 memset(vtp, 0,
sizeof(*vtp));
5065 " type=%u strength=%u audio=0x%x cap=0x%x"
5089 static int pvr2_hdw_set_input(
struct pvr2_hdw *hdw,
int v)
5091 if (hdw->input_val != v) {
5093 hdw->input_dirty = !0;
5112 unsigned int change_mask,
5113 unsigned int change_val)
5116 unsigned int nv,
m,
idx;
5120 nv |= (change_val & change_mask);
5140 for (idx = 0; idx < (
sizeof(
m) << 3); idx++) {
5141 if (!((1 << idx) & m))
continue;
5142 pvr2_hdw_set_input(hdw,idx);
5152 static int pvr2_hdw_get_eeprom_addr(
struct pvr2_hdw *hdw)
5160 if (result < 0)
break;
5169 int setFl,
u64 *val_ptr)
5171 #ifdef CONFIG_VIDEO_ADV_DEBUG
5180 if (setFl) req.
val = *val_ptr;
5183 if (!setFl) *val_ptr = req.
val;