为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

OV9650摄像头驱动

2017-10-08 10页 doc 38KB 58阅读

用户头像

is_589748

暂无简介

举报
OV9650摄像头驱动OV9650摄像头驱动 OV9650.c include ltlinux/module.hgt include ltlinux/delay.hgt include ltlinux/errno.hgt include ltlinux/fs.hgt include ltlinux/kernel.hgt include ltlinux/slab.hgt include ltlinux/mm.hgt include ltlinux/ioport.hgt include ltlinux/init.hgt include ltlinux...
OV9650摄像头驱动
OV9650摄像头驱动 OV9650.c include ltlinux/module.hgt include ltlinux/delay.hgt include ltlinux/errno.hgt include ltlinux/fs.hgt include ltlinux/kernel.hgt include ltlinux/slab.hgt include ltlinux/mm.hgt include ltlinux/ioport.hgt include ltlinux/init.hgt include ltlinux/sched.hgt include ltlinux/clk.hgt include ltlinux/random.hgt include ltlinux/version.hgt include ltlinux/videodev2.hgt include ltlinux/dma-mapping.hgt ifdef CONFIG_VIDEO_V4L1_COMPAT include ltlinux/videodev.hgt endif include ltlinux/interrupt.hgt include ltmedia/v4l2-common.hgt include ltlinux/highmem.hgt include ltlinux/miscdevice.hgt include ltlinux/gpio.hgt include ltasm/io.hgt include ltasm/memory.hgt include ltmach/regs-gpio.hgt include ltmach/regs-gpioj.hgt include ltmach/regs-clock.hgt include ltmach/map.hgt include quotov9650.hquot / debug print macro. / / hardware amp driver name version etc. / define CARD_NAME quotcameraquot static unsigned has_ov9650 unsigned long camif_base_addr / camera devices / 1static struct tx2440_camif_dev camera / image buffer for previewing. / struct tx2440_camif_buffer img_buff .state CAMIF_BUFF_INVALID .img_size 0 .order 0 .virt_base unsigned longNULL .phy_base unsigned longNULL .state CAMIF_BUFF_INVALID .img_size 0 .order 0 .virt_base unsigned longNULL .phy_base unsigned longNULL .state CAMIF_BUFF_INVALID .img_size 0 .order 0 .virt_base unsigned longNULL .phy_base unsigned longNULL .state CAMIF_BUFF_INVALID .img_size 0 .order 0 .virt_base unsigned longNULL .phy_base unsigned longNULL / software reset camera interface. / static void __inline__ soft_reset_camifvoid u32 cigctrl cigctrl 1ltlt311ltlt29 iowrite32cigctrl S3C244X_CIGCTRL mdelay10 2 cigctrl 1ltlt29 iowrite32cigctrl S3C244X_CIGCTRL mdelay10 / software reset camera interface. / static void __inline__ hw_reset_camifvoid u32 cigctrl cigctrl 1ltlt301ltlt29 iowrite32cigctrl S3C244X_CIGCTRL mdelay10 cigctrl 1ltlt29 iowrite32cigctrl S3C244X_CIGCTRL mdelay10 / switch camif from codec path to preview path. / static void __inline__ camif_c2pstruct tx2440_camif_dev pdev / 1. stop codec. / u32 cicoscctrl cicoscctrl ioread32S3C244X_CICOSCCTRL cicoscctrl amp 1ltlt15 // stop preview scaler. iowrite32cicoscctrl S3C244X_CICOSCCTRL / 2. soft-reset camif. / soft_reset_camif / 3. clear all overflow. / u32 ciwdofst ciwdofst ioread32S3C244X_CIWDOFST ciwdofst 1ltlt301ltlt151ltlt141ltlt131ltlt12 iowrite32ciwdofst S3C244X_CIWDOFST ciwdofst amp 1ltlt301ltlt151ltlt141ltlt131ltlt12 iowrite32ciwdofst S3C244X_CIWDOFST 3 / calculate main burst size and remained burst size. / static void __inline__ calc_burst_sizeu32 pixperwordu32 hSize u32 mainBurstSize u32 remainedBurstSize u32 tmp tmp hSize/pixperword16 switchtmp case 0: mainBurstSize 16 remainedBurstSize 16 break case 4: mainBurstSize 16 remainedBurstSize 4 break case 8: mainBurstSize16 remainedBurstSize 8 break default: tmphSize/pixperword8 switchtmp case 0: mainBurstSize 8 remainedBurstSize 8 break case 4: mainBurstSize 8 remainedBurstSize 4 default: mainBurstSize 4 tmp hSize/pixperword4 remainedBurstSize tmptmp:4 break break 4 / calculate prescaler ratio and shift. / static void __inline__ calc_prescaler_ratio_shiftu32 SrcSize u32 DstSize u32 ratio u32 shift ifSrcSizegt32DstSize ratio32 shift5 else ifSrcSizegt16DstSize ratio16 shift4 else ifSrcSizegt8DstSize ratio8 shift3 else ifSrcSizegt4DstSize ratio4 shift2 else ifSrcSizegt2DstSize ratio2 shift1 else ratio1 shift0 / update CISRCFMT only. / static void __inline__ update_source_fmt_regsstruct tx2440_camif_dev pdev u32 cisrcfmt cisrcfmt 1ltlt31 // ITU-R BT.601 YCbCr 8-bit mode 0ltlt30 // CBCr value offset cntrol for YCbCr 5 pdev-gtsrcHsizeltlt16 // source image width 2ltlt14 // input order is CbYCrY pdev-gtsrcVsizeltlt0 // source image height iowrite32cisrcfmt S3C244X_CISRCFMT / update registers: PREVIEW path: CIPRCLRSA1 CIPRCLRSA4 CIPRTRGFMT CIPRCTRL CIPRSCCTRL CIPRTAREA CODEC path: CICOYSA1 CICOYSA4 CICOCBSA1 CICOCBSA4 CICOCRSA1 CICOCRSA4 CICOTRGFMT CICOCTRL CICOTAREA / static void __inline__ update_target_fmt_regsstruct tx2440_camif_dev pdev u32 ciprtrgfmt u32 ciprctrl u32 ciprscctrl u32 mainBurstSize remainedBurstSize / CIPRCLRSA1 CIPRCLRSA4. / iowrite32img_buff0.phy_base S3C244X_CIPRCLRSA1 iowrite32img_buff1.phy_base S3C244X_CIPRCLRSA2 iowrite32img_buff2.phy_base S3C244X_CIPRCLRSA3 iowrite32img_buff3.phy_base S3C244X_CIPRCLRSA4 / CIPRTRGFMT. / ciprtrgfmt pdev-gtpreTargetHsizeltlt16 // horizontal pixel number of target image 0ltlt14 // dont mirror or rotation. pdev-gtpreTargetVsizeltlt0 // vertical pixel number of target image iowrite32ciprtrgfmt S3C244X_CIPRTRGFMT / CIPRCTRL. / calc_burst_size2 pdev-gtpreTargetHsize ampmainBurstSize ampremainedBurstSize 6 ciprctrl mainBurstSizeltlt19remainedBurstSizeltlt14 iowrite32ciprctrl S3C244X_CIPRCTRL / CIPRSCCTRL. / ciprscctrl ioread32S3C244X_CIPRSCCTRL ciprscctrl amp 1ltlt15 // clear all other info except preview scaler start. ciprscctrl 0ltlt30 // 16-bits RGB iowrite32ciprscctrl S3C244X_CIPRSCCTRL // 16-bit RGB / CIPRTAREA. / iowrite32pdev-gtpreTargetHsize pdev-gtpreTargetVsize S3C244X_CIPRTAREA / update CIWDOFST only. / static void __inline__ update_target_wnd_regsstruct tx2440_camif_dev pdev u32 ciwdofst u32 winHorOfst winVerOfst winHorOfst pdev-gtsrcHsize - pdev-gtwndHsizegtgt1 winVerOfst pdev-gtsrcVsize - pdev-gtwndVsizegtgt1 winHorOfst amp 0xFFFFFFF8 winVerOfst amp 0xFFFFFFF8 if winHorOfst 0ampampwinVerOfst 0 ciwdofst 0 // disable windows offset. else ciwdofst 1ltlt31 // window offset enable 1ltlt30 // clear the overflow ind flag of input CODEC FIFO Y winHorOfstltlt16 // windows horizontal offset 1ltlt15 // clear the overflow ind flag of input CODEC FIFO Cb 1ltlt14 // clear the overflow ind flag of input CODEC FIFO Cr 1ltlt13 // clear the overflow ind flag of input PREVIEW FIFO Cb 1ltlt12 // clear the overflow ind flag of input PREVIEW FIFO Cr winVerOfstltlt0 // window vertical offset iowrite32ciwdofst S3C244X_CIWDOFST / update registers: 7 PREVIEW path: CIPRSCPRERATIO CIPRSCPREDST CIPRSCCTRL CODEC path: CICOSCPRERATIO CICOSCPREDST CICOSCCTRL / static void __inline__ update_target_zoom_regsstruct tx2440_camif_dev pdev u32 preHratio preVratio u32 Hshift Vshift u32 shfactor u32 preDstWidth preDstHeight u32 Hscale Vscale u32 mainHratio mainVratio u32 ciprscpreratio u32 ciprscpredst u32 ciprscctrl / CIPRSCPRERATIO. / calc_prescaler_ratio_shiftpdev-gtwndHsize pdev-gtpreTargetHsize amppreHratio ampHshift calc_prescaler_ratio_shiftpdev-gtwndVsize pdev-gtpreTargetVsize amppreVratio ampVshift shfactor 10 - Hshift Vshift ciprscpreratio shfactorltlt28 // shift factor for preview pre-scaler preHratioltlt16 // horizontal ratio of preview pre-scaler preVratioltlt0 // vertical ratio of preview pre-scaler iowrite32ciprscpreratio S3C244X_CIPRSCPRERATIO / CIPRSCPREDST. / preDstWidth pdev-gtwndHsize / preHratio preDstHeight pdev-gtwndVsize / preVratio ciprscpredst preDstWidthltlt16 // destination width for preview pre-scaler preDstHeightltlt0 // destination height for preview pre-scaler iowrite32ciprscpredst S3C244X_CIPRSCPREDST / CIPRSCCTRL. / Hscale pdev-gtwndHsize gt pdev-gtpreTargetHsize0:1 Vscale pdev-gtwndVsize gt pdev-gtpreTargetVsize0:1 8 mainHratio pdev-gtwndHsizeltlt8/pdev-gtpreTargetHsizeltltHshift mainVratio pdev-gtwndVsizeltlt8/pdev-gtpreTargetVsizeltltVshift ciprscctrl ioread32S3C244X_CIPRSCCTRL ciprscctrl amp 1ltlt301ltlt15 // keep preview image format RGB565 or RGB24 and preview scaler start state. ciprscctrl 1ltlt31 // this bit should be always 1. Hscaleltlt29 // horizontal scale up/down. Vscaleltlt28 // vertical scale up/down. mainHratioltlt16 // horizontal scale ratio for preview main-scaler mainVratioltlt0 // vertical scale ratio for preview main-scaler iowrite32ciprscctrl S3C244X_CIPRSCCTRL / update camif registers called only when camif ready or ISR. / static void __inline__ update_camif_regsstruct tx2440_camif_dev pdev if in_irq while1 // wait until VSYNC is L barrier if ioread32S3C244X_CICOSTATUSamp1ltlt28 0 break / WARNING: dont change the statement sort below / update_source_fmt_regspdev update_target_wnd_regspdev update_target_fmt_regspdev update_target_zoom_regspdev / start image capture. param stream means capture pictures streamly or capture only one picture. / static int start_capturestruct tx2440_camif_dev pdev int stream int ret u32 ciwdofst u32 ciprscctrl u32 ciimgcpt 9 ciwdofst ioread32S3C244X_CIWDOFST ciwdofst 1ltlt30 // Clear the overflow indication flag of input CODEC FIFO Y 1ltlt15 // Clear the overflow indication flag of input CODEC FIFO Cb 1ltlt14 // Clear the overflow indication flag of input CODEC FIFO Cr 1ltlt13 // Clear the overflow indication flag of input PREVIEW FIFO Cb 1ltlt12 // Clear the overflow indication flag of input PREVIEW FIFO Cr iowrite32ciwdofst S3C244X_CIWDOFST ciprscctrl ioread32S3C244X_CIPRSCCTRL ciprscctrl 1ltlt15 // preview scaler start iowrite32ciprscctrl S3C244X_CIPRSCCTRL pdev-gtstate CAMIF_STATE_PREVIEWING ciimgcpt 1ltlt31 // camera interface global capture enable 1ltlt29 // capture enable for preview scaler. iowrite32ciimgcpt S3C244X_CIIMGCPT ret 0 if stream 0 pdev-gtcmdcode CAMIF_CMD_STOP ret wait_event_interruptiblepdev-gtcmdqueue pdev-gtcmdcode CAMIF_CMD_NONE return ret / stop image capture always called in ISR. P-path regs: CIPRSCCTRL CIPRCTRL C-path regs: CICOSCCTRL. CICOCTRL Global regs: CIIMGCPT / static void stop_capturestruct tx2440_camif_dev pdev u32 ciprscctrl u32 ciprctrl 10 u32 cicoscctrl u32 cicoctrl switchpdev-gtstate case CAMIF_STATE_PREVIEWING: / CIPRCTRL. / ciprctrl ioread32S3C244X_CIPRCTRL ciprctrl 1ltlt2 // enable last IRQ at the end of frame capture. iowrite32ciprctrl S3C244X_CIPRCTRL / CIPRSCCTRL. / ciprscctrl ioread32S3C244X_CIPRSCCTRL ciprscctrl amp 1ltlt15 // clear preview scaler start bit. iowrite32ciprscctrl S3C244X_CIPRSCCTRL / CIIMGCPT. / iowrite320 S3C244X_CIIMGCPT pdev-gtstate CAMIF_STATE_READY break case CAMIF_STATE_CODECING: / CICOCTRL. / cicoctrl ioread32S3C244X_CICOCTRL cicoctrl 1ltlt2 // enable last IRQ at the end of frame capture. iowrite32cicoctrl S3C244X_CICOCTRL / CICOSCCTRL. / cicoscctrl ioread32S3C244X_CICOSCCTRL cicoscctrl amp 1ltlt15 // clear codec scaler start bit. iowrite32cicoscctrl S3C244X_CICOSCCTRL / CIIMGCPT. / iowrite320 S3C244X_CIIMGCPT pdev-gtstate CAMIF_STATE_READY break / update camera interface with the new config. / 11static void update_camif_config struct tx2440_camif_fh fh u32 cmdcode struct tx2440_camif_dev pdev pdev fh-gtdev switch pdev-gtstate case CAMIF_STATE_READY: update_camif_regsfh-gtdev // config the regs directly. break case CAMIF_STATE_PREVIEWING: / camif is previewing image. / disable_irqIRQ_S3C2440_CAM_P // disable cam-preview irq. / source image format. / if cmdcode amp CAMIF_CMD_SFMT // ignore it nothing to do now. / target image format. / if cmdcode amp CAMIF_CMD_TFMT / change target image format only. / pdev-gtcmdcode CAMIF_CMD_TFMT / target image window offset. / if cmdcode amp CAMIF_CMD_WND pdev-gtcmdcode CAMIF_CMD_WND / target image zoomi amp zoomout. / if cmdcode amp CAMIF_CMD_ZOOM pdev-gtcmdcode CAMIF_CMD_ZOOM / stop previewing. / 12 if cmdcode amp CAMIF_CMD_STOP pdev-gtcmdcode CAMIF_CMD_STOP enable_irqIRQ_S3C2440_CAM_P // enable cam-preview irq. wait_eventpdev-gtcmdqueue pdev-gtcmdcodeCAMIF_CMD_NONE // wait until the ISR completes command. break case CAMIF_STATE_CODECING: / camif is previewing image. / disable_irqIRQ_S3C2440_CAM_C // disable cam-codec irq. / source image format. / if cmdcode amp CAMIF_CMD_SFMT // ignore it nothing to do now. / target image format. / if cmdcode amp CAMIF_CMD_TFMT / change target image format only. / pdev-gtcmdcode CAMIF_CMD_TFMT / target image window offset. / if cmdcode amp CAMIF_CMD_WND pdev-gtcmdcode CAMIF_CMD_WND / target image zoomi amp zoomout. / if cmdcode amp CAMIF_CMD_ZOOM pdev-gtcmdcode CAMIF_CMD_ZOOM / stop previewing. / if cmdcode amp CAMIF_CMD_STOP 13 pdev-gtcmdcode CAMIF_CMD_STOP enable_irqIRQ_S3C2440_CAM_C // enable cam-codec irq. wait_eventpdev-gtcmdqueue pdev-gtcmdcodeCAMIF_CMD_NONE // wait until the ISR completes command. break default: break / config camif when master-open camera./ static void init_camif_configstruct tx2440_camif_fh fh struct tx2440_camif_dev pdev pdev fh-gtdev pdev-gtinput 0 // FIXME the default input image format see inputs for detail. / the source image size input from external camera. / pdev-gtsrcHsize 1280 // FIXME the OV9650s horizontal output pixels. pdev-gtsrcVsize 1024 // FIXME the OV9650s verical output pixels. / the windowed image size. / pdev-gtwndHsize 1280 pdev-gtwndVsize 1024 / codec-path targetoutput image size. / pdev-gtcoTargetHsize pdev-gtwndHsize pdev-gtcoTargetVsize pdev-gtwndVsize / preview-path targetpreview image size. / pdev-gtpreTargetHsize 640 pdev-gtpreTargetVsize 480 update_camif_configfh CAMIF_CMD_STOP static void __inline__ invalid_image_buffervoid img_buff0.state CAMIF_BUFF_INVALID img_buff1.state CAMIF_BUFF_INVALID 14 img_buff2.state CAMIF_BUFF_INVALID img_buff3.state CAMIF_BUFF_INVALID / init image buffer only when the camif is first open. / static int __inline__ init_image_buffervoid int size1 size2 unsigned long size unsigned int order / size1 is the max image size of codec path. / size1 MAX_C_WIDTH MAX_C_HEIGHT 16 / 8 / size2 is the max image size of preview path. / size2 MAX_P_WIDTH MAX_P_HEIGHT 16 / 8 size size1 gt size2size1:size2 order get_ordersize img_buff0.order order img_buff0.virt_base __get_free_pagesGFP_KERNELGFP_DMA img_buff0.order if img_buff0.virt_base unsigned longNULL goto error0 img_buff0.phy_base img_buff0.virt_base - PAGE_OFFSET PHYS_OFFSET // the DMA address. img_buff1.order order img_buff1.virt_base __get_free_pagesGFP_KERNELGFP_DMA img_buff1.order if img_buff1.virt_base unsigned longNULL goto error1 img_buff1.phy_base img_buff1.virt_base - PAGE_OFFSET PHYS_OFFSET // the DMA address. img_buff2.order order img_buff2.virt_base __get_free_pagesGFP_KERNELGFP_DMA img_buff2.order if img_buff2.virt_base unsigned longNULL goto error2 15 img_buff2.phy_base img_buff2.virt_base - PAGE_OFFSET PHYS_OFFSET // the DMA address. img_buff3.order order img_buff3.virt_base __get_free_pagesGFP_KERNELGFP_DMA img_buff3.order if img_buff3.virt_base unsigned longNULL goto error3 img_buff3..
/
本文档为【OV9650摄像头驱动】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索