pvrusb2-hdw.c

来自「trident tm5600的linux驱动」· C语言 代码 · 共 2,389 行 · 第 1/5 页

C
2,389
字号
	return 0;}static int ctrl_get_cropcapbl(struct pvr2_ctrl *cptr, int *val){	struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;	int stat = pvr2_hdw_check_cropcap(cptr->hdw);	if (stat != 0) {		return stat;	}	*val = cap->bounds.left;	return 0;}static int ctrl_get_cropcapbt(struct pvr2_ctrl *cptr, int *val){	struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;	int stat = pvr2_hdw_check_cropcap(cptr->hdw);	if (stat != 0) {		return stat;	}	*val = cap->bounds.top;	return 0;}static int ctrl_get_cropcapbw(struct pvr2_ctrl *cptr, int *val){	struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;	int stat = pvr2_hdw_check_cropcap(cptr->hdw);	if (stat != 0) {		return stat;	}	*val = cap->bounds.width;	return 0;}static int ctrl_get_cropcapbh(struct pvr2_ctrl *cptr, int *val){	struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;	int stat = pvr2_hdw_check_cropcap(cptr->hdw);	if (stat != 0) {		return stat;	}	*val = cap->bounds.height;	return 0;}static int ctrl_get_cropcapdl(struct pvr2_ctrl *cptr, int *val){	struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;	int stat = pvr2_hdw_check_cropcap(cptr->hdw);	if (stat != 0) {		return stat;	}	*val = cap->defrect.left;	return 0;}static int ctrl_get_cropcapdt(struct pvr2_ctrl *cptr, int *val){	struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;	int stat = pvr2_hdw_check_cropcap(cptr->hdw);	if (stat != 0) {		return stat;	}	*val = cap->defrect.top;	return 0;}static int ctrl_get_cropcapdw(struct pvr2_ctrl *cptr, int *val){	struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;	int stat = pvr2_hdw_check_cropcap(cptr->hdw);	if (stat != 0) {		return stat;	}	*val = cap->defrect.width;	return 0;}static int ctrl_get_cropcapdh(struct pvr2_ctrl *cptr, int *val){	struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;	int stat = pvr2_hdw_check_cropcap(cptr->hdw);	if (stat != 0) {		return stat;	}	*val = cap->defrect.height;	return 0;}static int ctrl_get_cropcappan(struct pvr2_ctrl *cptr, int *val){	struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;	int stat = pvr2_hdw_check_cropcap(cptr->hdw);	if (stat != 0) {		return stat;	}	*val = cap->pixelaspect.numerator;	return 0;}static int ctrl_get_cropcappad(struct pvr2_ctrl *cptr, int *val){	struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;	int stat = pvr2_hdw_check_cropcap(cptr->hdw);	if (stat != 0) {		return stat;	}	*val = cap->pixelaspect.denominator;	return 0;}static int ctrl_vres_max_get(struct pvr2_ctrl *cptr,int *vp){	/* Actual maximum depends on the video standard in effect. */	if (cptr->hdw->std_mask_cur & V4L2_STD_525_60) {		*vp = 480;	} else {		*vp = 576;	}	return 0;}static int ctrl_vres_min_get(struct pvr2_ctrl *cptr,int *vp){	/* Actual minimum depends on device digitizer type. */	if (cptr->hdw->hdw_desc->flag_has_cx25840) {		*vp = 75;	} else {		*vp = 17;	}	return 0;}static int ctrl_get_input(struct pvr2_ctrl *cptr,int *vp){	*vp = cptr->hdw->input_val;	return 0;}static int ctrl_check_input(struct pvr2_ctrl *cptr,int v){	return ((1 << v) & cptr->hdw->input_allowed_mask) != 0;}static int ctrl_set_input(struct pvr2_ctrl *cptr,int m,int v){	return pvr2_hdw_set_input(cptr->hdw,v);}static int ctrl_isdirty_input(struct pvr2_ctrl *cptr){	return cptr->hdw->input_dirty != 0;}static void ctrl_cleardirty_input(struct pvr2_ctrl *cptr){	cptr->hdw->input_dirty = 0;}static int ctrl_freq_max_get(struct pvr2_ctrl *cptr, int *vp){	unsigned long fv;	struct pvr2_hdw *hdw = cptr->hdw;	if (hdw->tuner_signal_stale) {		pvr2_i2c_core_status_poll(hdw);	}	fv = hdw->tuner_signal_info.rangehigh;	if (!fv) {		/* Safety fallback */		*vp = TV_MAX_FREQ;		return 0;	}	if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {		fv = (fv * 125) / 2;	} else {		fv = fv * 62500;	}	*vp = fv;	return 0;}static int ctrl_freq_min_get(struct pvr2_ctrl *cptr, int *vp){	unsigned long fv;	struct pvr2_hdw *hdw = cptr->hdw;	if (hdw->tuner_signal_stale) {		pvr2_i2c_core_status_poll(hdw);	}	fv = hdw->tuner_signal_info.rangelow;	if (!fv) {		/* Safety fallback */		*vp = TV_MIN_FREQ;		return 0;	}	if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {		fv = (fv * 125) / 2;	} else {		fv = fv * 62500;	}	*vp = fv;	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;	cptr->hdw->enc_unsafe_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, 0, &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 pvr2_hdw *hdw = cptr->hdw;	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(&hdw->enc_ctl_state,				hdw->state_encoder_run, &cs,				VIDIOC_S_EXT_CTRLS);	if (ret == -EBUSY) {		/* Oops.  cx2341x is telling us it's not safe to change		   this control while we're capturing.  Make a note of this		   fact so that the pipeline will be stopped the next time		   controls are committed.  Then go on ahead and store this		   change anyway. */		ret = cx2341x_ext_ctrls(&hdw->enc_ctl_state,					0, &cs,					VIDIOC_S_EXT_CTRLS);		if (!ret) hdw->enc_unsafe_stale = !0;	}	if (ret) return ret;	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->state_pipeline_req;	return 0;}static int ctrl_masterstate_get(struct pvr2_ctrl *cptr,int *vp){	*vp = cptr->hdw->master_state;	return 0;}static int ctrl_hsm_get(struct pvr2_ctrl *cptr,int *vp){	int result = pvr2_hdw_is_hsm(cptr->hdw);	*vp = PVR2_CVAL_HSM_FULL;	if (result < 0) *vp = PVR2_CVAL_HSM_FAIL;	if (result) *vp = PVR2_CVAL_HSM_HIGH;	return 0;}static int ctrl_stdavail_get(struct pvr2_ctrl *cptr,int *vp){	*vp = cptr->hdw->std_mask_avail;	return 0;}static int ctrl_stdavail_set(struct pvr2_ctrl *cptr,int m,int v){	struct pvr2_hdw *hdw = cptr->hdw;	v4l2_std_id ns;	ns = hdw->std_mask_avail;	ns = (ns & ~m) | (v & m);	if (ns == hdw->std_mask_avail) return 0;	hdw->std_mask_avail = ns;	pvr2_hdw_internal_set_std_avail(hdw);	pvr2_hdw_internal_find_stdenum(hdw);	return 0;}static int ctrl_std_val_to_sym(struct pvr2_ctrl *cptr,int msk,int val,			       char *bufPtr,unsigned int bufSize,			       unsigned int *len){	*len = pvr2_std_id_to_str(bufPtr,bufSize,msk & val);	return 0;}static int ctrl_std_sym_to_val(struct pvr2_ctrl *cptr,			       const char *bufPtr,unsigned int bufSize,			       int *mskp,int *valp){	int ret;	v4l2_std_id id;	ret = pvr2_std_str_to_id(&id,bufPtr,bufSize);	if (ret < 0) return ret;	if (mskp) *mskp = id;	if (valp) *valp = id;	return 0;}static int ctrl_stdcur_get(struct pvr2_ctrl *cptr,int *vp){	*vp = cptr->hdw->std_mask_cur;	return 0;}static int ctrl_stdcur_set(struct pvr2_ctrl *cptr,int m,int v){	struct pvr2_hdw *hdw = cptr->hdw;	v4l2_std_id ns;	ns = hdw->std_mask_cur;	ns = (ns & ~m) | (v & m);	if (ns == hdw->std_mask_cur) return 0;	hdw->std_mask_cur = ns;	hdw->std_dirty = !0;	pvr2_hdw_internal_find_stdenum(hdw);	return 0;}static int ctrl_stdcur_is_dirty(struct pvr2_ctrl *cptr){	return cptr->hdw->std_dirty != 0;}static void ctrl_stdcur_clear_dirty(struct pvr2_ctrl *cptr){	cptr->hdw->std_dirty = 0;}static int ctrl_signal_get(struct pvr2_ctrl *cptr,int *vp){	struct pvr2_hdw *hdw = cptr->hdw;	pvr2_i2c_core_status_poll(hdw);	*vp = hdw->tuner_signal_info.signal;	return 0;}static int ctrl_audio_modes_present_get(struct pvr2_ctrl *cptr,int *vp){	int val = 0;	unsigned int subchan;	struct pvr2_hdw *hdw = cptr->hdw;	pvr2_i2c_core_status_poll(hdw);	subchan = hdw->tuner_signal_info.rxsubchans;	if (subchan & V4L2_TUNER_SUB_MONO) {		val |= (1 << V4L2_TUNER_MODE_MONO);	}	if (subchan & V4L2_TUNER_SUB_STEREO) {		val |= (1 << V4L2_TUNER_MODE_STEREO);	}	if (subchan & V4L2_TUNER_SUB_LANG1) {		val |= (1 << V4L2_TUNER_MODE_LANG1);	}	if (subchan & V4L2_TUNER_SUB_LANG2) {		val |= (1 << V4L2_TUNER_MODE_LANG2);	}	*vp = val;	return 0;}static int ctrl_stdenumcur_set(struct pvr2_ctrl *cptr,int m,int v){	struct pvr2_hdw *hdw = cptr->hdw;	if (v < 0) return -EINVAL;	if (v > hdw->std_enum_cnt) return -EINVAL;	hdw->std_enum_cur = v;	if (!v) return 0;	v--;	if (hdw->std_mask_cur == hdw->std_defs[v].id) return 0;	hdw->std_mask_cur = hdw->std_defs[v].id;	hdw->std_dirty = !0;	return 0;}static int ctrl_stdenumcur_get(struct pvr2_ctrl *cptr,int *vp){	*vp = cptr->hdw->std_enum_cur;	return 0;}static int ctrl_stdenumcur_is_dirty(struct pvr2_ctrl *cptr){	return cptr->hdw->std_dirty != 0;}static void ctrl_stdenumcur_clear_dirty(struct pvr2_ctrl *cptr){	cptr->hdw->std_dirty = 0;}#define DEFINT(vmin,vmax) \	.type = pvr2_ctl_int, \	.def.type_int.min_value = vmin, \	.def.type_int.max_value = vmax#define DEFENUM(tab) \	.type = pvr2_ctl_enum, \	.def.type_enum.count = ARRAY_SIZE(tab), \	.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, \	.def.type_bitmask.bit_names = tab#define DEFREF(vname) \	.set_value = ctrl_set_##vname, \	.get_value = ctrl_get_##vname, \	.is_dirty = ctrl_isdirty_##vname, \	.clear_dirty = ctrl_cleardirty_##vname#define VCREATE_FUNCS(vname) \static int ctrl_get_##vname(struct pvr2_ctrl *cptr,int *vp) \{*vp = cptr->hdw->vname##_val; return 0;} \static int ctrl_set_##vname(struct pvr2_ctrl *cptr,int m,int v) \{cptr->hdw->vname##_val = v; cptr->hdw->vname##_dirty = !0; return 0;} \static int ctrl_isdirty_##vname(struct pvr2_ctrl *cptr) \{return cptr->hdw->vname##_dirty != 0;} \

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?