⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 camera_mt9v111.c

📁 pxa270下的摄像头mtd91111的驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (write) {		MT9V111_IFP_READ16(0x5B, &val);		val = (val & ~1) | (~(vc->value) & 1);		MT9V111_IFP_WRITE16(0x5B, val);		dbg("new auto_flicker_cancellation value %d, reg %x\n",vc->value, val);		if (!mt9v111_flicker_cancellation_en) {			MT9V111_IFP_READ16(0x8, &val);			if (vc->value) {				val |= (1 << 11);				dbg("flicker cancellation enabled\n");			} else {				val &= ~(1 << 11);				dbg("flicker cancellation disabled\n");			}			MT9V111_IFP_WRITE16(0x8, val);		}		mt9v111_auto_flicker_cancellation_en = vc->value;	} else {		vc->value = mt9v111_auto_flicker_cancellation_en;	}	return 0;}static intmt9v111_flicker_cancellation(struct v4l2_control *vc, int write){	u16 val;	/* input value description:	0 - disable flicker cancellation, unless not in auto mode	1 - 50Hz	2 - 60Hz	*/	if (write) {		MT9V111_IFP_READ16(0x5B, &val);		val = (val & ~(1 << 1)) | (vc->value & (1 << 1));		MT9V111_IFP_WRITE16(0x5B, val);		dbg("new flicker_cancellation value %d, reg %x\n",vc->value, val);		if (!mt9v111_auto_flicker_cancellation_en) {			MT9V111_IFP_READ16(0x8, &val);			if (vc->value) {				val |= (1 << 11);				dbg("flicker cancellation enabled\n");			} else {				val &= ~(1 << 11);				dbg("flicker cancellation disabled\n");			}			MT9V111_IFP_WRITE16(0x8, val);		}		mt9v111_flicker_cancellation_en = vc->value;	} else {		vc->value = mt9v111_flicker_cancellation_en;	}	return 0;}static intfind_vctrl(int id){	int i;	if (id < V4L2_CID_BASE || id > V4L2_CID_LAST_PRIV)		return -EDOM;	for (i = NUM_CONTROLS - 1; i >= 0; i--)		if (control[i].qc.id == id)			break;	if (i < 0)		i = -EINVAL;	return i;}static intmt9v111_set_control(struct v4l2_control *vc){	int i = find_vctrl(vc->id);	if (i < 0)		return -EINVAL;	return control[i].handler(vc, 1);}static intmt9v111_get_control(struct v4l2_control *vc){	int i = find_vctrl(vc->id);	if (i < 0)		return -EINVAL;	return control[i].handler(vc, 0);}static intmt9v111_querymenu(struct v4l2_querymenu *qm){	/* No menu controls have been defined */	return -EINVAL;}static intmt9v111_query_control(struct v4l2_queryctrl *qc){	int i;	i = find_vctrl(qc->id);	if (i == -EINVAL) {		qc->flags = V4L2_CTRL_FLAG_DISABLED;		return 0;	}	if (i < 0)		return -EINVAL;	/*  V4L2 filled in category and group, preserve them */	control[i].qc.category = qc->category;	memcpy(control[i].qc.group, qc->group, sizeof (qc->group));	*qc = control[i].qc;	return 0;}static intmt9v111_find_size(struct v4l2_pix_format *fmt){	int isize;	if (fmt->width > mx2ads_image_size[VGA].width)		fmt->width = mx2ads_image_size[VGA].width;	if (fmt->height > mx2ads_image_size[VGA].height)		fmt->height = mx2ads_image_size[VGA].height;	for (isize = QQVGA; isize < VGA; isize++) {		if ((mx2ads_image_size[isize].height >= fmt->height) &&		    (mx2ads_image_size[isize].width >= fmt->width)) {			fmt->width = mx2ads_image_size[isize].width;			fmt->height = mx2ads_image_size[isize].height;			return isize;		}	}	return VGA;}intmt9v111_find_format(struct v4l2_pix_format *fmt){	switch (fmt->pixelformat) {	case V4L2_PIX_FMT_YUYV:		return YUV;	case V4L2_PIX_FMT_RGB565:	case V4L2_PIX_FMT_BGR24:	/* will have to convert to BGR24 */		return RGB565;	}	return -1;}/*resize*/static inline voidmt9v111_decimation_ctrl(unsigned int out_width, unsigned int out_height){	unsigned short a5_val, a6_val, a7_val, a8_val, a9_val, aa_val;	if (out_width > 640)		out_width = 640;	if (out_height > 480)		out_height = 480;	a5_val = 0;		/*horisontal control */	a6_val = 640;		/*take full window */	a7_val = out_width;	a8_val = 0;		/*vertical control */	a9_val = 480;		/*take full window */	aa_val = out_height;/*change & freeze*/	MT9V111_IFP_WRITE16(0xA5, 0x8000 | a5_val);	/*horisontal control */	MT9V111_IFP_WRITE16(0xA6, 0x8000 | a6_val);	/*take full window */	MT9V111_IFP_WRITE16(0xA7, 0x8000 | a7_val);	MT9V111_IFP_WRITE16(0xA8, 0x8000 | a8_val);	/*vertical control */	MT9V111_IFP_WRITE16(0xA9, 0x8000 | a9_val);	/*take full window */	MT9V111_IFP_WRITE16(0xAA, 0x8000 | aa_val);/*unfreeze & synchronize the changes*/	MT9V111_IFP_WRITE16(0xA5, a5_val & ~0x8000);}static intmt9v111_set_format(struct v4l2_pix_format *fmt){	enum pixel_format pixfmt;	uint16_t reg_val;	if ((pixfmt = mt9v111_find_format(fmt)) < 0)		return -EINVAL;	/*	 * turn camera into the selected mode	 */	MT9V111_IFP_READ16(0x8, &reg_val);	switch (pixfmt) {	case YUV:		reg_val &= ~(1<<12);		break;	case RGB565:		reg_val |= (1<<12);		break;	default:		return -EINVAL;	}	MT9V111_IFP_WRITE16(0x8, reg_val);	this->imgfmt = mt9v111_find_size(fmt);	mt9v111_decimation_ctrl(fmt->width, fmt->height);	return 0;}/*  * Open - open device */static intmt9v111_open(void){	uint16_t reg_val;        /*         * Make standby low (disable standby)         */	CSI_REG_READ(EXP_IO, reg_val);	reg_val &= ~EXP_IO_CSI_CTL0;	CSI_REG_WRITE(EXP_IO, reg_val);	udelay(20);	return 0;}/*  * Close - close the device */static intmt9v111_close(void){	uint16_t reg_val;        /*         * Make standby high (enable standby)         */	CSI_REG_READ(EXP_IO, reg_val);	reg_val |= EXP_IO_CSI_CTL0;	CSI_REG_WRITE(EXP_IO, reg_val);	udelay(20);	return 0;}/* * Free all resources */static voidmt9v111_cleanup(void){	mt9v111_close();	this->camif->sbus->cleanup();}/* * Check - whether Micron compatible camera present */static intmt9v111_detect(void){	uint16_t reg_val;	struct camera_serial_bus *sbus;	int ret;	this = &camera_mt9v111;	sbus = this->camif->sbus;	sbus->set_devid(CAMERA_MT9V111_DEV_ID);	CSI_REG_READ(EXP_IO, reg_val);	/*	 * Make standby low (disable standby)	 */	reg_val &= ~EXP_IO_CSI_CTL0;	CSI_REG_WRITE(EXP_IO, reg_val);	udelay(20);	/*	 * Make reset low (reset sensor)	 */	reg_val &= ~EXP_IO_CSI_CTL1;	CSI_REG_WRITE(EXP_IO, reg_val);	udelay(200);	/*	 * Make reset high	 */	reg_val |= EXP_IO_CSI_CTL1;	CSI_REG_WRITE(EXP_IO, reg_val);	udelay(200);	if ((ret = sbus->init()) < 0) {		mt9v111_cleanup();		return ret;	}	MT9V111_IC_READ16(MT9V111_IC_VERSION, &reg_val);	if (reg_val != MT9V111_CORE_VERSION) {		mt9v111_cleanup();		return -ENODEV;	}	return 0;}struct camera camera_mt9v111 = {	.imgfmt = QVGA,	.pixfmt = RGB565,	.detect = mt9v111_detect,	.init = mt9v111_init,	.cleanup = mt9v111_cleanup,	.open = mt9v111_open,	.close = mt9v111_close,	.set_format = mt9v111_set_format,	.set_frame_period = mt9v111_set_fp,	.get_frame_period = mt9v111_get_fp,	.query_control = mt9v111_query_control,	.get_control = mt9v111_get_control,	.set_control = mt9v111_set_control,	.query_menu = mt9v111_querymenu,};

⌨️ 快捷键说明

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