Commit 3560f6dc authored by 吴智聪(John Wu)'s avatar 吴智聪(John Wu)

clean up code and fix some typo in vpfe and tvp7000 code

parent a5555708
...@@ -96,8 +96,8 @@ static struct v4l2_fract sp_aspect = VPFE_PIXELASPECT_NTSC_SP; ...@@ -96,8 +96,8 @@ static struct v4l2_fract sp_aspect = VPFE_PIXELASPECT_NTSC_SP;
#define NTOSD_INPUTS 2 #define NTOSD_INPUTS 2
static struct v4l2_input ntosd_inputs[NTOSD_INPUTS] = { static struct v4l2_input ntosd_inputs[NTOSD_INPUTS] = {
{ 0, "COMPOSITE", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_ALL, 0 }, { 0, "COMPOSITE", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_ALL, 0},
{ 1, "COMPONENT", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_ALL, 0 }, { 1, "COMPONENT", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_ALL, 0},
}; };
static vpfe_obj vpfe_device = { /* the default format is NTSC */ static vpfe_obj vpfe_device = { /* the default format is NTSC */
...@@ -138,6 +138,7 @@ struct v4l2_capability vpfe_drvcap = { ...@@ -138,6 +138,7 @@ struct v4l2_capability vpfe_drvcap = {
.capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING .capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING
}; };
static irqreturn_t vpfe_isr(int irq, void *dev_id) static irqreturn_t vpfe_isr(int irq, void *dev_id)
{ {
vpfe_obj *vpfe = &vpfe_device; vpfe_obj *vpfe = &vpfe_device;
...@@ -149,42 +150,52 @@ static irqreturn_t vpfe_isr(int irq, void *dev_id) ...@@ -149,42 +150,52 @@ static irqreturn_t vpfe_isr(int irq, void *dev_id)
fid = ccdc_getfid(); fid = ccdc_getfid();
vpfe->field_id ^= 1; /* switch the software maintained field id */ vpfe->field_id ^= 1; /* switch the software maintained field id */
debug_print(KERN_INFO "field id = %x:%x.\n", fid, vpfe->field_id); debug_print(KERN_INFO "field id = %x:%x.\n", fid, vpfe->field_id);
if (fid == vpfe->field_id) { /* we are in-sync here, continue */ if (fid == vpfe->field_id)
if (fid == 0) { { /* we are in-sync here, continue */
if (fid == 0)
{
/* One frame is just being captured. If the next frame /* One frame is just being captured. If the next frame
is available, release the current frame and move on */ is available, release the current frame and move on */
if (vpfe->curFrm != vpfe->nextFrm) { if (vpfe->curFrm != vpfe->nextFrm)
{
vpfe->curFrm->state = STATE_DONE; vpfe->curFrm->state = STATE_DONE;
wake_up_interruptible(&vpfe->curFrm->done); wake_up_interruptible(&vpfe->curFrm->done);
vpfe->curFrm = vpfe->nextFrm; vpfe->curFrm = vpfe->nextFrm;
} }
/* based on whether the two fields are stored interleavely */ /* based on whether the two fields are stored interleavely */
/* or separately in memory, reconfigure the CCDC memory address */ /* or separately in memory, reconfigure the CCDC memory address */
if (vpfe->field == V4L2_FIELD_SEQ_TB) { if (vpfe->field == V4L2_FIELD_SEQ_TB)
{
u32 addr = vpfe->curFrm->boff + vpfe->field_offset; u32 addr = vpfe->curFrm->boff + vpfe->field_offset;
ccdc_setfbaddr((unsigned long)addr); ccdc_setfbaddr((unsigned long)addr);
} }
} else if (fid == 1) { }
else if (fid == 1)
{
/* if one field is just being captured */ /* if one field is just being captured */
/* configure the next frame */ /* configure the next frame */
/* get the next frame from the empty queue */ /* get the next frame from the empty queue */
/* if no frame is available, hold on to the current buffer */ /* if no frame is available, hold on to the current buffer */
if (!list_empty(&vpfe->dma_queue) if (!list_empty(&vpfe->dma_queue)
&& vpfe->curFrm == vpfe->nextFrm) { && vpfe->curFrm == vpfe->nextFrm)
{
vpfe->nextFrm = list_entry(vpfe->dma_queue.next, vpfe->nextFrm = list_entry(vpfe->dma_queue.next,
struct videobuf_buffer, queue); struct videobuf_buffer, queue);
list_del(&vpfe->nextFrm->queue); list_del(&vpfe->nextFrm->queue);
vpfe->nextFrm->state = STATE_ACTIVE; vpfe->nextFrm->state = STATE_ACTIVE;
ccdc_setfbaddr((unsigned long)vpfe->nextFrm->boff); ccdc_setfbaddr((unsigned long)vpfe->nextFrm->boff);
} }
if (vpfe->mode_changed) { if (vpfe->mode_changed)
{
ccdc_setwin(&vpfe->ccdc_params); ccdc_setwin(&vpfe->ccdc_params);
/* update the field offset */ /* update the field offset */
vpfe->field_offset = (vpfe->vwin.height - 2) * vpfe->vwin.width; vpfe->field_offset = (vpfe->vwin.height - 2) * vpfe->vwin.width;
vpfe->mode_changed = FALSE; vpfe->mode_changed = FALSE;
} }
} }
} else if (fid == 0) { }
else if (fid == 0)
{
/* recover from any hardware out-of-sync due to */ /* recover from any hardware out-of-sync due to */
/* possible switch of video source */ /* possible switch of video source */
/* for fid == 0, sync up the two fids */ /* for fid == 0, sync up the two fids */
...@@ -217,7 +228,8 @@ static int buffer_prepare(struct videobuf_queue *q, ...@@ -217,7 +228,8 @@ static int buffer_prepare(struct videobuf_queue *q,
{ {
vpfe_obj *vpfe = &vpfe_device; vpfe_obj *vpfe = &vpfe_device;
if (vb->state == STATE_NEEDS_INIT) { if (vb->state == STATE_NEEDS_INIT)
{
vb->width = vpfe->vwin.width; vb->width = vpfe->vwin.width;
vb->height = vpfe->vwin.height; vb->height = vpfe->vwin.height;
vb->size = VPFE_MAX_FBUF_SIZE; vb->size = VPFE_MAX_FBUF_SIZE;
...@@ -235,7 +247,8 @@ buffer_config(struct videobuf_queue *q, unsigned int count) ...@@ -235,7 +247,8 @@ buffer_config(struct videobuf_queue *q, unsigned int count)
vpfe_obj *vpfe = &vpfe_device; vpfe_obj *vpfe = &vpfe_device;
int i; int i;
for(i = 0; i < count; i++) { for (i = 0; i < count; i++)
{
q->bufs[i]->boff = virt_to_phys(vpfe->fbuffers[i]); q->bufs[i]->boff = virt_to_phys(vpfe->fbuffers[i]);
debug_print(KERN_INFO "buffer address: %x\n", q->bufs[i]->boff); debug_print(KERN_INFO "buffer address: %x\n", q->bufs[i]->boff);
} }
...@@ -248,13 +261,16 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) ...@@ -248,13 +261,16 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
int i; int i;
*size = VPFE_MAX_FBUF_SIZE; *size = VPFE_MAX_FBUF_SIZE;
for (i = VPFE_DEFNUM_FBUFS; i < *count; i++) { for (i = VPFE_DEFNUM_FBUFS; i < *count; i++)
{
u32 size = PAGE_SIZE << VPFE_MAX_FBUF_ORDER; u32 size = PAGE_SIZE << VPFE_MAX_FBUF_ORDER;
void *mem = (void *)__get_free_pages(GFP_KERNEL |GFP_DMA, void *mem = (void *)__get_free_pages(GFP_KERNEL |GFP_DMA,
VPFE_MAX_FBUF_ORDER); VPFE_MAX_FBUF_ORDER);
if (mem) { if (mem)
{
unsigned long adr = (unsigned long)mem; unsigned long adr = (unsigned long)mem;
while (size > 0) { while (size > 0)
{
/* make sure the frame buffers are never /* make sure the frame buffers are never
swapped out of memory */ swapped out of memory */
SetPageReserved(virt_to_page(adr)); SetPageReserved(virt_to_page(adr));
...@@ -262,7 +278,9 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) ...@@ -262,7 +278,9 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
size -= PAGE_SIZE; size -= PAGE_SIZE;
} }
vpfe->fbuffers[i] = mem; vpfe->fbuffers[i] = mem;
} else { }
else
{
break; break;
} }
} }
...@@ -283,9 +301,10 @@ static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) ...@@ -283,9 +301,10 @@ static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
{ {
/* free the buffer if it is not one of the 3 allocated at initializaiton time */ /* free the buffer if it is not one of the 3 allocated at initializaiton time */
if(vb->i < vpfe_device.numbuffers if (vb->i < vpfe_device.numbuffers
&& vb->i >= VPFE_DEFNUM_FBUFS && vb->i >= VPFE_DEFNUM_FBUFS
&& vpfe_device.fbuffers[vb->i]){ && vpfe_device.fbuffers[vb->i])
{
free_pages((unsigned long)vpfe_device.fbuffers[vb->i], free_pages((unsigned long)vpfe_device.fbuffers[vb->i],
VPFE_MAX_FBUF_ORDER); VPFE_MAX_FBUF_ORDER);
vpfe_device.fbuffers[vb->i] = NULL; vpfe_device.fbuffers[vb->i] = NULL;
...@@ -330,7 +349,8 @@ static int vpfe_select_capture_device(int id) ...@@ -330,7 +349,8 @@ static int vpfe_select_capture_device(int id)
down_interruptible(&vpfe_device.device_list_lock); down_interruptible(&vpfe_device.device_list_lock);
list_for_each_entry(device, &vpfe_device.capture_device_list, list_for_each_entry(device, &vpfe_device.capture_device_list,
device_list){ device_list){
if (device->id == id) { if (device->id == id)
{
err = vpfe_capture_device_active(device); err = vpfe_capture_device_active(device);
up(&vpfe_device.device_list_lock); up(&vpfe_device.device_list_lock);
return err; return err;
...@@ -348,18 +368,21 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -348,18 +368,21 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
vpfe_fh *fh = file->private_data; vpfe_fh *fh = file->private_data;
int ret = 0; int ret = 0;
switch (cmd) { switch (cmd)
{
case VIDIOC_S_CTRL: case VIDIOC_S_CTRL:
case VIDIOC_S_CROP: case VIDIOC_S_CROP:
case VIDIOC_S_FMT: case VIDIOC_S_FMT:
case VIDIOC_S_STD: case VIDIOC_S_STD:
ret = v4l2_prio_check(&vpfe->prio, &fh->prio); ret = v4l2_prio_check(&vpfe->prio, &fh->prio);
if (0 != ret) { if (0 != ret)
{
return ret; return ret;
} }
break; break;
} }
switch (cmd) { switch (cmd)
{
case VIDIOC_QUERYCAP: case VIDIOC_QUERYCAP:
{ {
struct v4l2_capability *cap = (struct v4l2_capability *)arg; struct v4l2_capability *cap = (struct v4l2_capability *)arg;
...@@ -373,16 +396,21 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -373,16 +396,21 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
u32 index = fmt->index; u32 index = fmt->index;
memset(fmt, 0, sizeof(*fmt)); memset(fmt, 0, sizeof(*fmt));
fmt->index = index; fmt->index = index;
if (index == 0) { if (index == 0)
{
/* only yuv4:2:2 format is supported at this point */ /* only yuv4:2:2 format is supported at this point */
fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
strcpy(fmt->description, "YCbCr4:2:2 Interleaved UYUV"); strcpy(fmt->description, "YCbCr4:2:2 Interleaved UYUV");
fmt->pixelformat = V4L2_PIX_FMT_UYVY; fmt->pixelformat = V4L2_PIX_FMT_UYVY;
} else if (index == 1) { }
else if (index == 1)
{
fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
strcpy(fmt->description, "YCbCr4:2:2 Interleaved YUYV"); strcpy(fmt->description, "YCbCr4:2:2 Interleaved YUYV");
fmt->pixelformat = V4L2_PIX_FMT_YUYV; fmt->pixelformat = V4L2_PIX_FMT_YUYV;
} else { }
else
{
ret = -EINVAL; ret = -EINVAL;
} }
break; break;
...@@ -390,9 +418,12 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -390,9 +418,12 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
case VIDIOC_G_FMT: case VIDIOC_G_FMT:
{ {
struct v4l2_format *fmt = (struct v4l2_format *)arg; struct v4l2_format *fmt = (struct v4l2_format *)arg;
if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
{
ret = -EINVAL; ret = -EINVAL;
} else { }
else
{
struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
down_interruptible(&vpfe->lock); down_interruptible(&vpfe->lock);
pixfmt->width = vpfe->vwin.width; pixfmt->width = vpfe->vwin.width;
...@@ -411,50 +442,65 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -411,50 +442,65 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
struct v4l2_format *fmt = (struct v4l2_format *)arg; struct v4l2_format *fmt = (struct v4l2_format *)arg;
struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
ccdc_params_ycbcr *params = &vpfe->ccdc_params; ccdc_params_ycbcr *params = &vpfe->ccdc_params;
if (vpfe->started) { /* make sure streaming is not started */ if (vpfe->started)
{ /* make sure streaming is not started */
ret = -EBUSY; ret = -EBUSY;
break; break;
} }
down_interruptible(&vpfe->lock); down_interruptible(&vpfe->lock);
if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
{
ret = -EINVAL; ret = -EINVAL;
up(&vpfe->lock); up(&vpfe->lock);
break; break;
} }
if ((pixfmt->width + vpfe->vwin.left <= vpfe->bounds.width) & if ((pixfmt->width + vpfe->vwin.left <= vpfe->bounds.width) &
(pixfmt->height + vpfe->vwin.top <= vpfe->bounds.height)) { (pixfmt->height + vpfe->vwin.top <= vpfe->bounds.height))
{
/* this is the case when no scaling is supported */ /* this is the case when no scaling is supported */
/* crop window is directed modified */ /* crop window is directed modified */
vpfe->vwin.height = pixfmt->height; vpfe->vwin.height = pixfmt->height;
vpfe->vwin.width = pixfmt->width; vpfe->vwin.width = pixfmt->width;
params->win.width = pixfmt->width; params->win.width = pixfmt->width;
params->win.height = pixfmt->height; params->win.height = pixfmt->height;
} else { }
else
{
ret = -EINVAL; ret = -EINVAL;
up(&vpfe->lock); up(&vpfe->lock);
break; break;
} }
/* setup the CCDC parameters accordingly */ /* setup the CCDC parameters accordingly */
if (pixfmt->pixelformat == V4L2_PIX_FMT_YUYV) { if (pixfmt->pixelformat == V4L2_PIX_FMT_YUYV)
{
params->pix_order = CCDC_PIXORDER_YCBYCR; params->pix_order = CCDC_PIXORDER_YCBYCR;
vpfe->pixelfmt = pixfmt->pixelformat; vpfe->pixelfmt = pixfmt->pixelformat;
} else if (pixfmt->pixelformat == V4L2_PIX_FMT_UYVY) { }
else if (pixfmt->pixelformat == V4L2_PIX_FMT_UYVY)
{
params->pix_order = CCDC_PIXORDER_CBYCRY; params->pix_order = CCDC_PIXORDER_CBYCRY;
vpfe->pixelfmt = pixfmt->pixelformat; vpfe->pixelfmt = pixfmt->pixelformat;
} else { }
else
{
ret = -EINVAL; /* not supported format */ ret = -EINVAL; /* not supported format */
up(&vpfe->lock); up(&vpfe->lock);
break; break;
} }
if (pixfmt->field == V4L2_FIELD_NONE || if (pixfmt->field == V4L2_FIELD_NONE ||
pixfmt->field == V4L2_FIELD_INTERLACED) { pixfmt->field == V4L2_FIELD_INTERLACED)
{
params->buf_type = CCDC_BUFTYPE_FLD_INTERLEAVED; params->buf_type = CCDC_BUFTYPE_FLD_INTERLEAVED;
vpfe->field = pixfmt->field; vpfe->field = pixfmt->field;
} else if (pixfmt->field == V4L2_FIELD_SEQ_TB) { }
else if (pixfmt->field == V4L2_FIELD_SEQ_TB)
{
params->buf_type = CCDC_BUFTYPE_FLD_SEPARATED; params->buf_type = CCDC_BUFTYPE_FLD_SEPARATED;
vpfe->field = pixfmt->field; vpfe->field = pixfmt->field;
} else { }
else
{
ret = -EINVAL; ret = -EINVAL;
} }
...@@ -466,14 +512,18 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -466,14 +512,18 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
case VIDIOC_TRY_FMT: case VIDIOC_TRY_FMT:
{ {
struct v4l2_format *fmt = (struct v4l2_format *)arg; struct v4l2_format *fmt = (struct v4l2_format *)arg;
if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
{
ret = -EINVAL; ret = -EINVAL;
} else { }
else
{
struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
if (pixfmt->width > vpfe->bounds.width || if (pixfmt->width > vpfe->bounds.width ||
pixfmt->height > vpfe->bounds.height || pixfmt->height > vpfe->bounds.height ||
(pixfmt->pixelformat != V4L2_PIX_FMT_UYVY && (pixfmt->pixelformat != V4L2_PIX_FMT_UYVY &&
pixfmt->pixelformat != V4L2_PIX_FMT_YUYV)) { pixfmt->pixelformat != V4L2_PIX_FMT_YUYV))
{
ret = -EINVAL; ret = -EINVAL;
} }
} }
...@@ -490,26 +540,32 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -490,26 +540,32 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
v4l2_std_id id = *(v4l2_std_id *) arg; v4l2_std_id id = *(v4l2_std_id *) arg;
int sqp = 0; int sqp = 0;
if (vpfe->started) { /* make sure streaming is not started */ if (vpfe->started)
{ /* make sure streaming is not started */
ret = -EBUSY; ret = -EBUSY;
break; break;
} }
down_interruptible(&vpfe->lock); down_interruptible(&vpfe->lock);
if (id & V4L2_STD_625_50) { if (id & V4L2_STD_625_50)
{
vpfe->std = id; vpfe->std = id;
vpfe->bounds = vpfe->vwin = pal_bounds; vpfe->bounds = vpfe->vwin = pal_bounds;
vpfe->pixelaspect = pal_aspect; vpfe->pixelaspect = pal_aspect;
vpfe->ccdc_params.win = pal_bounds; vpfe->ccdc_params.win = pal_bounds;
vpfe->ccdc_params.frm_fmt = CCDC_FRMFMT_INTERLACED; vpfe->ccdc_params.frm_fmt = CCDC_FRMFMT_INTERLACED;
vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT; vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT;
} else if (id & V4L2_STD_525_60) { }
else if (id & V4L2_STD_525_60)
{
vpfe->std = id; vpfe->std = id;
vpfe->bounds = vpfe->vwin = ntsc_bounds; vpfe->bounds = vpfe->vwin = ntsc_bounds;
vpfe->pixelaspect = ntsc_aspect; vpfe->pixelaspect = ntsc_aspect;
vpfe->ccdc_params.win = ntsc_bounds; vpfe->ccdc_params.win = ntsc_bounds;
vpfe->ccdc_params.frm_fmt = CCDC_FRMFMT_INTERLACED; vpfe->ccdc_params.frm_fmt = CCDC_FRMFMT_INTERLACED;
vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT; vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT;
} else if (id & VPFE_STD_625_50_SQP) { }
else if (id & VPFE_STD_625_50_SQP)
{
vpfe->std = id; vpfe->std = id;
vpfe->bounds = vpfe->vwin = palsp_bounds; vpfe->bounds = vpfe->vwin = palsp_bounds;
vpfe->pixelaspect = sp_aspect; vpfe->pixelaspect = sp_aspect;
...@@ -517,7 +573,9 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -517,7 +573,9 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT; vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT;
sqp = 1; sqp = 1;
id >>= 32; id >>= 32;
} else if (id & VPFE_STD_525_60_SQP) { }
else if (id & VPFE_STD_525_60_SQP)
{
vpfe->std = id; vpfe->std = id;
sqp = 1; sqp = 1;
vpfe->std = id; vpfe->std = id;
...@@ -527,28 +585,36 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -527,28 +585,36 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
vpfe->ccdc_params.win = ntscsp_bounds; vpfe->ccdc_params.win = ntscsp_bounds;
vpfe->ccdc_params.frm_fmt = CCDC_FRMFMT_INTERLACED; vpfe->ccdc_params.frm_fmt = CCDC_FRMFMT_INTERLACED;
vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT; vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT;
} else if (id & VPFE_STD_AUTO) { }
else if (id & VPFE_STD_AUTO)
{
vpfe->bounds = vpfe->vwin = pal_bounds; vpfe->bounds = vpfe->vwin = pal_bounds;
vpfe->pixelaspect = pal_aspect; vpfe->pixelaspect = pal_aspect;
vpfe->ccdc_params.win = pal_bounds; vpfe->ccdc_params.win = pal_bounds;
vpfe->ccdc_params.frm_fmt = CCDC_FRMFMT_INTERLACED; vpfe->ccdc_params.frm_fmt = CCDC_FRMFMT_INTERLACED;
vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT; vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT;
vpfe->std = id; vpfe->std = id;
} else if (id & VPFE_STD_AUTO_SQP) { }
else if (id & VPFE_STD_AUTO_SQP)
{
vpfe->std = id; vpfe->std = id;
vpfe->bounds = vpfe->vwin = palsp_bounds; vpfe->bounds = vpfe->vwin = palsp_bounds;
vpfe->pixelaspect = sp_aspect; vpfe->pixelaspect = sp_aspect;
vpfe->ccdc_params.frm_fmt = CCDC_FRMFMT_INTERLACED; vpfe->ccdc_params.frm_fmt = CCDC_FRMFMT_INTERLACED;
vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT; vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT;
sqp = 1; sqp = 1;
} else if (id & V4L2_STD_HD_480P) { }
else if (id & V4L2_STD_HD_480P)
{
vpfe->std = id; vpfe->std = id;
vpfe->bounds = vpfe->vwin = hd_480p_bounds; vpfe->bounds = vpfe->vwin = hd_480p_bounds;
vpfe->pixelaspect = sp_aspect; vpfe->pixelaspect = sp_aspect;
vpfe->ccdc_params.win = hd_480p_bounds; vpfe->ccdc_params.win = hd_480p_bounds;
vpfe->ccdc_params.frm_fmt = CCDC_FRMFMT_PROGRESSIVE; vpfe->ccdc_params.frm_fmt = CCDC_FRMFMT_PROGRESSIVE;
vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_16BIT; vpfe->ccdc_params.pix_fmt = CCDC_PIXFMT_YCBCR_16BIT;
} else { }
else
{
ret = -EINVAL; ret = -EINVAL;
} }
...@@ -566,46 +632,59 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -566,46 +632,59 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
u32 index = std->index; u32 index = std->index;
memset(std, 0, sizeof(*std)); memset(std, 0, sizeof(*std));
std->index = index; std->index = index;
if (index == 0) { if (index == 0)
{
std->id = V4L2_STD_525_60; std->id = V4L2_STD_525_60;
strcpy(std->name, "SD-525line-30fps"); strcpy(std->name, "SD-525line-30fps");
std->framelines = 525; std->framelines = 525;
std->frameperiod.numerator = 1001; std->frameperiod.numerator = 1001;
std->frameperiod.denominator = 30000; std->frameperiod.denominator = 30000;
} else if (index == 1) { }
else if (index == 1)
{
std->id = V4L2_STD_625_50; std->id = V4L2_STD_625_50;
strcpy(std->name, "SD-625line-25fps"); strcpy(std->name, "SD-625line-25fps");
std->framelines = 625; std->framelines = 625;
std->frameperiod.numerator = 1; std->frameperiod.numerator = 1;
std->frameperiod.denominator = 25; std->frameperiod.denominator = 25;
} else if (index == 2) { }
else if (index == 2)
{
std->id = VPFE_STD_625_50_SQP; std->id = VPFE_STD_625_50_SQP;
strcpy(std->name, strcpy(std->name,
"SD-625line-25fps square pixel"); "SD-625line-25fps square pixel");
std->framelines = 625; std->framelines = 625;
std->frameperiod.numerator = 1; std->frameperiod.numerator = 1;
std->frameperiod.denominator = 25; std->frameperiod.denominator = 25;
} else if (index == 3) { }
else if (index == 3)
{
std->id = VPFE_STD_525_60_SQP; std->id = VPFE_STD_525_60_SQP;
strcpy(std->name, strcpy(std->name,
"SD-525line-25fps square pixel"); "SD-525line-25fps square pixel");
std->framelines = 525; std->framelines = 525;
std->frameperiod.numerator = 1001; std->frameperiod.numerator = 1001;
std->frameperiod.denominator = 30000; std->frameperiod.denominator = 30000;
} else if (index == 4) { }
else if (index == 4)
{
std->id = VPFE_STD_AUTO; std->id = VPFE_STD_AUTO;
strcpy(std->name, "automatic detect"); strcpy(std->name, "automatic detect");
std->framelines = 625; std->framelines = 625;
std->frameperiod.numerator = 1; std->frameperiod.numerator = 1;
std->frameperiod.denominator = 1; std->frameperiod.denominator = 1;
} else if (index == 5) { }
else if (index == 5)
{
std->id = VPFE_STD_AUTO_SQP; std->id = VPFE_STD_AUTO_SQP;
strcpy(std->name, strcpy(std->name,
"automatic detect square pixel"); "automatic detect square pixel");
std->framelines = 625; std->framelines = 625;
std->frameperiod.numerator = 1; std->frameperiod.numerator = 1;
std->frameperiod.denominator = 1; std->frameperiod.denominator = 1;
} else { }
else
{
ret = -EINVAL; ret = -EINVAL;
} }
break; break;
...@@ -614,7 +693,7 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -614,7 +693,7 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
{ {
struct v4l2_input *input = (struct v4l2_input *)arg; struct v4l2_input *input = (struct v4l2_input *)arg;
if( input->index < 0 || input->index >= NTOSD_INPUTS) if ( input->index < 0 || input->index >= NTOSD_INPUTS)
ret = -EINVAL; ret = -EINVAL;
memcpy(input, &ntosd_inputs[input->index], sizeof(struct v4l2_input)); memcpy(input, &ntosd_inputs[input->index], sizeof(struct v4l2_input));
...@@ -656,17 +735,23 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -656,17 +735,23 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
case VIDIOC_G_PARM: case VIDIOC_G_PARM:
{ {
struct v4l2_streamparm *parm = (struct v4l2_streamparm *)arg; struct v4l2_streamparm *parm = (struct v4l2_streamparm *)arg;
if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
{
/* only capture is supported */ /* only capture is supported */
ret = -EINVAL; ret = -EINVAL;
} else { }
else
{
struct v4l2_captureparm *capparm = &parm->parm.capture; struct v4l2_captureparm *capparm = &parm->parm.capture;
memset(capparm, 0, sizeof(struct v4l2_captureparm)); memset(capparm, 0, sizeof(struct v4l2_captureparm));
down_interruptible(&vpfe->lock); down_interruptible(&vpfe->lock);
if (vpfe->std & V4L2_STD_625_50) { if (vpfe->std & V4L2_STD_625_50)
{
capparm->timeperframe.numerator = 1; capparm->timeperframe.numerator = 1;
capparm->timeperframe.denominator = 25; /* PAL 25fps */ capparm->timeperframe.denominator = 25; /* PAL 25fps */
} else { }
else
{
capparm->timeperframe.numerator = 1001; capparm->timeperframe.numerator = 1001;
capparm->timeperframe.denominator = 30000; /*NTSC 29.97fps */ capparm->timeperframe.denominator = 30000; /*NTSC 29.97fps */
} }
...@@ -699,9 +784,12 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -699,9 +784,12 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
case VIDIOC_G_CROP: case VIDIOC_G_CROP:
{ {
struct v4l2_crop *crop = arg; struct v4l2_crop *crop = arg;
if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
{
ret = -EINVAL; ret = -EINVAL;
} else { }
else
{
crop->c = vpfe->vwin; crop->c = vpfe->vwin;
} }
break; break;
...@@ -710,7 +798,8 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -710,7 +798,8 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
{ {
struct v4l2_crop *crop = arg; struct v4l2_crop *crop = arg;
ccdc_params_ycbcr *params = &vpfe->ccdc_params; ccdc_params_ycbcr *params = &vpfe->ccdc_params;
if (vpfe->started) { /* make sure streaming is not started */ if (vpfe->started)
{ /* make sure streaming is not started */
ret = -EBUSY; ret = -EBUSY;
break; break;
} }
...@@ -720,13 +809,16 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -720,13 +809,16 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
/* make sure parameters are valid */ /* make sure parameters are valid */
if (crop->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && if (crop->type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
(crop->c.left + crop->c.width <= vpfe->bounds.left + vpfe->bounds.width) && (crop->c.left + crop->c.width <= vpfe->bounds.left + vpfe->bounds.width) &&
(crop->c.top + crop->c.height <= vpfe->bounds.top + vpfe->bounds.height)) { (crop->c.top + crop->c.height <= vpfe->bounds.top + vpfe->bounds.height))
{
down_interruptible(&vpfe->lock); down_interruptible(&vpfe->lock);
vpfe->vwin = crop->c; vpfe->vwin = crop->c;
params->win = vpfe->vwin; params->win = vpfe->vwin;
up(&vpfe->lock); up(&vpfe->lock);
} else { }
else
{
ret = -EINVAL; ret = -EINVAL;
} }
break; break;
...@@ -755,7 +847,8 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -755,7 +847,8 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
} }
case VIDIOC_REQBUFS: case VIDIOC_REQBUFS:
if (vpfe->io_usrs != 0) { if (vpfe->io_usrs != 0)
{
ret = -EBUSY; ret = -EBUSY;
break; break;
} }
...@@ -788,11 +881,13 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -788,11 +881,13 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
ret = videobuf_dqbuf(&vpfe->bufqueue, arg, 0); ret = videobuf_dqbuf(&vpfe->bufqueue, arg, 0);
break; break;
case VIDIOC_STREAMON: case VIDIOC_STREAMON:
if (!fh->io_allowed) { if (!fh->io_allowed)
{
ret = -EACCES; ret = -EACCES;
break; break;
} }
if (vpfe->started){ if (vpfe->started)
{
ret = -EBUSY; ret = -EBUSY;
break; break;
} }
...@@ -803,7 +898,8 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -803,7 +898,8 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
/* get the current and next frame buffers */ /* get the current and next frame buffers */
/* we expect at least one buffer is in driver at this point */ /* we expect at least one buffer is in driver at this point */
/* if not, error is returned */ /* if not, error is returned */
if (list_empty(&vpfe->dma_queue)) { if (list_empty(&vpfe->dma_queue))
{
ret = -EIO; ret = -EIO;
break; break;
} }
...@@ -835,11 +931,13 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -835,11 +931,13 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
break; break;
case VIDIOC_STREAMOFF: case VIDIOC_STREAMOFF:
{ {
if (!fh->io_allowed) { if (!fh->io_allowed)
{
ret = -EACCES; ret = -EACCES;
break; break;
} }
if(!vpfe->started){ if (!vpfe->started)
{
ret = -EINVAL; ret = -EINVAL;
break; break;
} }
...@@ -855,7 +953,8 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -855,7 +953,8 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
{ {
/* this can be used directly and bypass the V4L2 APIs */ /* this can be used directly and bypass the V4L2 APIs */
ccdc_params_ycbcr *params = &vpfe->ccdc_params; ccdc_params_ycbcr *params = &vpfe->ccdc_params;
if(vpfe->started){ if (vpfe->started)
{
/* only allowed if streaming is not started */ /* only allowed if streaming is not started */
ret = -EBUSY; ret = -EBUSY;
break; break;
...@@ -865,14 +964,20 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -865,14 +964,20 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
have consistant settings */ have consistant settings */
*params = (*(ccdc_params_ycbcr *) arg); *params = (*(ccdc_params_ycbcr *) arg);
vpfe->vwin = params->win; vpfe->vwin = params->win;
if (params->buf_type == CCDC_BUFTYPE_FLD_INTERLEAVED) { if (params->buf_type == CCDC_BUFTYPE_FLD_INTERLEAVED)
{
vpfe->field = V4L2_FIELD_INTERLACED; vpfe->field = V4L2_FIELD_INTERLACED;
} else if (params->buf_type == CCDC_BUFTYPE_FLD_SEPARATED) { }
else if (params->buf_type == CCDC_BUFTYPE_FLD_SEPARATED)
{
vpfe->field = V4L2_FIELD_SEQ_TB; vpfe->field = V4L2_FIELD_SEQ_TB;
} }
if (params->pix_order == CCDC_PIXORDER_YCBYCR) { if (params->pix_order == CCDC_PIXORDER_YCBYCR)
{
vpfe->pixelfmt = V4L2_PIX_FMT_YUYV; vpfe->pixelfmt = V4L2_PIX_FMT_YUYV;
} else if (params->pix_order == CCDC_PIXORDER_CBYCRY) { }
else if (params->pix_order == CCDC_PIXORDER_CBYCRY)
{
vpfe->pixelfmt = V4L2_PIX_FMT_UYVY; vpfe->pixelfmt = V4L2_PIX_FMT_UYVY;
} }
up(&vpfe->lock); up(&vpfe->lock);
...@@ -885,7 +990,8 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -885,7 +990,8 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
driver does not check the consistancy */ driver does not check the consistancy */
struct vpfe_capture_params *params = (struct vpfe_capture_param *) arg; struct vpfe_capture_params *params = (struct vpfe_capture_param *) arg;
v4l2_std_id std = 0; v4l2_std_id std = 0;
if(vpfe->started){ if (vpfe->started)
{
/* only allowed if streaming is not started */ /* only allowed if streaming is not started */
ret = -EBUSY; ret = -EBUSY;
break; break;
...@@ -893,20 +999,28 @@ static int vpfe_doioctl(struct inode *inode, struct file *file, ...@@ -893,20 +999,28 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
down_interruptible(&vpfe->lock); down_interruptible(&vpfe->lock);
std = params->mode; std = params->mode;
if (params->squarepixel) { /* square pixel mode */ if (params->squarepixel)
{ /* square pixel mode */
std <<= 32; std <<= 32;
} }
if (std & V4L2_STD_625_50) { if (std & V4L2_STD_625_50)
{
vpfe->bounds = pal_bounds; vpfe->bounds = pal_bounds;
vpfe->pixelaspect = pal_aspect; vpfe->pixelaspect = pal_aspect;
} else if (std & V4L2_STD_525_60) { }
else if (std & V4L2_STD_525_60)
{
vpfe->bounds = ntsc_bounds; vpfe->bounds = ntsc_bounds;
vpfe->pixelaspect = ntsc_aspect; vpfe->pixelaspect = ntsc_aspect;
} else if (std & VPFE_STD_625_50_SQP) { }
else if (std & VPFE_STD_625_50_SQP)
{
vpfe->bounds = palsp_bounds; vpfe->bounds = palsp_bounds;
vpfe->pixelaspect = sp_aspect; vpfe->pixelaspect = sp_aspect;
} else if (std & VPFE_STD_525_60_SQP) { }
else if (std & VPFE_STD_525_60_SQP)
{
vpfe->bounds = ntscsp_bounds; vpfe->bounds = ntscsp_bounds;
vpfe->pixelaspect = sp_aspect; vpfe->pixelaspect = sp_aspect;
} }
...@@ -928,7 +1042,8 @@ static int vpfe_ioctl(struct inode *inode, struct file *file, ...@@ -928,7 +1042,8 @@ static int vpfe_ioctl(struct inode *inode, struct file *file,
{ {
int ret; int ret;
ret = video_usercopy(inode, file, cmd, arg, vpfe_doioctl); ret = video_usercopy(inode, file, cmd, arg, vpfe_doioctl);
if( cmd == VIDIOC_S_FMT || cmd == VIDIOC_TRY_FMT ){ if ( cmd == VIDIOC_S_FMT || cmd == VIDIOC_TRY_FMT )
{
ret = video_usercopy(inode, file, VIDIOC_G_FMT, ret = video_usercopy(inode, file, VIDIOC_G_FMT,
arg, vpfe_doioctl); arg, vpfe_doioctl);
} }
...@@ -949,14 +1064,18 @@ static int vpfe_open(struct inode *inode, struct file *filep) ...@@ -949,14 +1064,18 @@ static int vpfe_open(struct inode *inode, struct file *filep)
debug_print(KERN_INFO "vpfe: open minor=%d\n", minor); debug_print(KERN_INFO "vpfe: open minor=%d\n", minor);
/* check to make sure the minor numbers match */ /* check to make sure the minor numbers match */
if (vpfe_device.video_dev && vpfe_device.video_dev->minor == minor) { if (vpfe_device.video_dev && vpfe_device.video_dev->minor == minor)
{
vpfe = &vpfe_device; vpfe = &vpfe_device;
} else { /* device not found here */ }
else
{ /* device not found here */
return -ENODEV; return -ENODEV;
} }
/* allocate per filehandle data */ /* allocate per filehandle data */
if ((fh = kmalloc(sizeof(*fh), GFP_KERNEL)) == NULL) { if ((fh = kmalloc(sizeof(*fh), GFP_KERNEL)) == NULL)
{
return -ENOMEM; return -ENOMEM;
} }
filep->private_data = fh; filep->private_data = fh;
...@@ -979,7 +1098,8 @@ static int vpfe_release(struct inode *inode, struct file *filep) ...@@ -979,7 +1098,8 @@ static int vpfe_release(struct inode *inode, struct file *filep)
vpfe_obj *vpfe = fh->dev; vpfe_obj *vpfe = fh->dev;
down_interruptible(&vpfe->lock); down_interruptible(&vpfe->lock);
if (fh->io_allowed) { if (fh->io_allowed)
{
vpfe->io_usrs = 0; vpfe->io_usrs = 0;
ccdc_enable(FALSE); ccdc_enable(FALSE);
vpfe->started = FALSE; vpfe->started = FALSE;
...@@ -1022,7 +1142,8 @@ static int __init vpfe_probe(struct device *device) ...@@ -1022,7 +1142,8 @@ static int __init vpfe_probe(struct device *device)
vpfe_obj *vpfe = &vpfe_device; vpfe_obj *vpfe = &vpfe_device;
/* alloc video device */ /* alloc video device */
if ((vfd = video_device_alloc()) == NULL) { if ((vfd = video_device_alloc()) == NULL)
{
return -ENOMEM; return -ENOMEM;
} }
*vfd = vpfe_video_template; *vfd = vpfe_video_template;
...@@ -1048,7 +1169,8 @@ static int __init vpfe_probe(struct device *device) ...@@ -1048,7 +1169,8 @@ static int __init vpfe_probe(struct device *device)
debug_print(KERN_INFO "trying to register vpfe device.\n"); debug_print(KERN_INFO "trying to register vpfe device.\n");
debug_print(KERN_INFO "vpfe=%x,vpfe->video_dev=%x\n", (int)vpfe, debug_print(KERN_INFO "vpfe=%x,vpfe->video_dev=%x\n", (int)vpfe,
(int)&vpfe->video_dev); (int)&vpfe->video_dev);
if (video_register_device(vpfe->video_dev, VFL_TYPE_GRABBER, -1) < 0) { if (video_register_device(vpfe->video_dev, VFL_TYPE_GRABBER, -1) < 0)
{
video_device_release(vpfe->video_dev); video_device_release(vpfe->video_dev);
vpfe->video_dev = NULL; vpfe->video_dev = NULL;
return -1; return -1;
...@@ -1100,7 +1222,8 @@ int vpfe_capture_device_unregister(struct vpfe_capture_device *device) ...@@ -1100,7 +1222,8 @@ int vpfe_capture_device_unregister(struct vpfe_capture_device *device)
down_interruptible(&vpfe_device.lock); down_interruptible(&vpfe_device.lock);
/* if the device to be unregistered is active, /* if the device to be unregistered is active,
deactivate it! */ deactivate it! */
if (IS_ACTIVE(device)) { if (IS_ACTIVE(device))
{
DEVICE_DEACTIVATE(device); DEVICE_DEACTIVATE(device);
SET_ACTIVE_DEVICE(NULL); SET_ACTIVE_DEVICE(NULL);
} }
...@@ -1170,12 +1293,15 @@ static int vpfe_init(void) ...@@ -1170,12 +1293,15 @@ static int vpfe_init(void)
int result = 0; int result = 0;
void *mem; void *mem;
/* allocate memory at initialization time to guarentee availability */ /* allocate memory at initialization time to guarentee availability */
for (i = 0; i < VPFE_DEFNUM_FBUFS; i++) { for (i = 0; i < VPFE_DEFNUM_FBUFS; i++)
{
mem = (void *)__get_free_pages(GFP_KERNEL | GFP_DMA, VPFE_MAX_FBUF_ORDER); mem = (void *)__get_free_pages(GFP_KERNEL | GFP_DMA, VPFE_MAX_FBUF_ORDER);
if (mem) { if (mem)
{
unsigned long adr = (unsigned long)mem; unsigned long adr = (unsigned long)mem;
u32 size = PAGE_SIZE << VPFE_MAX_FBUF_ORDER; u32 size = PAGE_SIZE << VPFE_MAX_FBUF_ORDER;
while (size > 0) { while (size > 0)
{
/* make sure the frame buffers /* make sure the frame buffers
are never swapped out of memory */ are never swapped out of memory */
SetPageReserved(virt_to_page(adr)); SetPageReserved(virt_to_page(adr));
...@@ -1184,8 +1310,11 @@ static int vpfe_init(void) ...@@ -1184,8 +1310,11 @@ static int vpfe_init(void)
} }
vpfe_device.fbuffers[i] = (u8 *) mem; vpfe_device.fbuffers[i] = (u8 *) mem;
debug_print(KERN_INFO "memory address %d\t%x\n", i, mem); debug_print(KERN_INFO "memory address %d\t%x\n", i, mem);
} else { }
while (--i >= 0) { else
{
while (--i >= 0)
{
free_pages((unsigned long)vpfe_device.fbuffers[i], free_pages((unsigned long)vpfe_device.fbuffers[i],
VPFE_MAX_FBUF_ORDER); VPFE_MAX_FBUF_ORDER);
} }
...@@ -1193,11 +1322,13 @@ static int vpfe_init(void) ...@@ -1193,11 +1322,13 @@ static int vpfe_init(void)
return -ENOMEM; return -ENOMEM;
} }
} }
if (driver_register(&vpfe_driver) != 0) { if (driver_register(&vpfe_driver) != 0)
{
debug_print(KERN_INFO "driver registration failed\n"); debug_print(KERN_INFO "driver registration failed\n");
return -1; return -1;
} }
if (platform_device_register(&_vpfe_device) != 0) { if (platform_device_register(&_vpfe_device) != 0)
{
driver_unregister(&vpfe_driver); driver_unregister(&vpfe_driver);
debug_print(KERN_INFO "device registration failed\n"); debug_print(KERN_INFO "device registration failed\n");
return -1; return -1;
...@@ -1207,7 +1338,8 @@ static int vpfe_init(void) ...@@ -1207,7 +1338,8 @@ static int vpfe_init(void)
/* setup interrupt handling */ /* setup interrupt handling */
result = request_irq(IRQ_VDINT0, vpfe_isr, IRQF_DISABLED, result = request_irq(IRQ_VDINT0, vpfe_isr, IRQF_DISABLED,
"dm644xv4l2", (void *)&vpfe_device); "dm644xv4l2", (void *)&vpfe_device);
if (result < 0) { if (result < 0)
{
printk(KERN_ERR "DaVinci v4l2 capture driver: cannot initialize IRQ\n"); printk(KERN_ERR "DaVinci v4l2 capture driver: cannot initialize IRQ\n");
return result; return result;
} }
...@@ -1227,7 +1359,8 @@ static void vpfe_cleanup(void) ...@@ -1227,7 +1359,8 @@ static void vpfe_cleanup(void)
/* disable interrupt */ /* disable interrupt */
free_irq(IRQ_VDINT0, &vpfe_device); free_irq(IRQ_VDINT0, &vpfe_device);
while (--i >= 0) { while (--i >= 0)
{
free_pages((unsigned long)vpfe_device.fbuffers[i], free_pages((unsigned long)vpfe_device.fbuffers[i],
VPFE_MAX_FBUF_ORDER); VPFE_MAX_FBUF_ORDER);
} }
......
...@@ -521,7 +521,7 @@ static int tvp7000_detect_client(struct i2c_adapter *adapter, ...@@ -521,7 +521,7 @@ static int tvp7000_detect_client(struct i2c_adapter *adapter,
static inline int tvp7000_read_reg(u8 reg); static inline int tvp7000_read_reg(u8 reg);
static inline int tvp7000_write_reg(u8 reg, u8 value); static inline int tvp7000_write_reg(u8 reg, u8 value);
static int tvp7000_setup_video_stardard(const struct tvp7000_video_std *std); static int tvp7000_setup_video_standard(const struct tvp7000_video_std *std);
static int tvp7000_device_init(struct vpfe_capture_params *params); static int tvp7000_device_init(struct vpfe_capture_params *params);
static int tvp7000_device_cmd(u32 cmd, void *arg); static int tvp7000_device_cmd(u32 cmd, void *arg);
...@@ -576,7 +576,8 @@ static int tvp7000_detect_client(struct i2c_adapter *adapter, ...@@ -576,7 +576,8 @@ static int tvp7000_detect_client(struct i2c_adapter *adapter,
FN_IN; FN_IN;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA |
I2C_FUNC_SMBUS_WRITE_BYTE)) { I2C_FUNC_SMBUS_WRITE_BYTE))
{
DPRINTK("Functionality check failed for %s\n", DPRINTK("Functionality check failed for %s\n",
client_name); client_name);
return err; return err;
...@@ -584,7 +585,8 @@ static int tvp7000_detect_client(struct i2c_adapter *adapter, ...@@ -584,7 +585,8 @@ static int tvp7000_detect_client(struct i2c_adapter *adapter,
tvp7000_client = kmalloc(sizeof(struct i2c_client), tvp7000_client = kmalloc(sizeof(struct i2c_client),
GFP_KERNEL); GFP_KERNEL);
if (tvp7000_client == NULL) { if (tvp7000_client == NULL)
{
err = -ENOMEM; err = -ENOMEM;
DPRINTK("Couldn't allocate memory for %s\n", DPRINTK("Couldn't allocate memory for %s\n",
client_name); client_name);
...@@ -599,7 +601,8 @@ static int tvp7000_detect_client(struct i2c_adapter *adapter, ...@@ -599,7 +601,8 @@ static int tvp7000_detect_client(struct i2c_adapter *adapter,
strlcpy(tvp7000_client->name, client_name, I2C_NAME_SIZE); strlcpy(tvp7000_client->name, client_name, I2C_NAME_SIZE);
err = i2c_attach_client(tvp7000_client); err = i2c_attach_client(tvp7000_client);
if (err) { if (err)
{
DPRINTK("Couldn't attach %s\n", client_name); DPRINTK("Couldn't attach %s\n", client_name);
kfree(tvp7000_client); kfree(tvp7000_client);
return err; return err;
...@@ -622,7 +625,8 @@ static int tvp7000_detach_client(struct i2c_client *client) ...@@ -622,7 +625,8 @@ static int tvp7000_detach_client(struct i2c_client *client)
FN_IN; FN_IN;
err = i2c_detach_client(client); err = i2c_detach_client(client);
if (err) { if (err)
{
DPRINTK("Client deregistration failed, \ DPRINTK("Client deregistration failed, \
client not detached.\n"); client not detached.\n");
return err; return err;
...@@ -651,8 +655,7 @@ static void tvp7000_device_power_on(bool on) ...@@ -651,8 +655,7 @@ static void tvp7000_device_power_on(bool on)
udelay(5); udelay(5);
} }
static int tvp7000_setup_video_stardard( static int tvp7000_setup_video_standard(const struct tvp7000_video_std *std)
const struct tvp7000_video_std *std)
{ {
int err = 0; int err = 0;
int val; int val;
...@@ -660,17 +663,13 @@ static int tvp7000_setup_video_stardard( ...@@ -660,17 +663,13 @@ static int tvp7000_setup_video_stardard(
if (std == NULL) if (std == NULL)
return -EINVAL; return -EINVAL;
err |= tvp7000_write_reg(TVP7000_PLL_DIVIDE_MSB, err |= tvp7000_write_reg(TVP7000_PLL_DIVIDE_MSB, std->plldiv_msb);
std->plldiv_msb); err |= tvp7000_write_reg(TVP7000_PLL_DIVIDE_LSB, std->plldiv_lsb);
err |= tvp7000_write_reg(TVP7000_PLL_DIVIDE_LSB, err |= tvp7000_write_reg(TVP7000_PLL_CTRL, std->pll_ctrl);
std->plldiv_lsb);
err |= tvp7000_write_reg(TVP7000_PLL_CTRL,
std->pll_ctrl);
val = tvp7000_read_reg(TVP7000_PHASE_SELECT); val = tvp7000_read_reg(TVP7000_PHASE_SELECT);
val &= ~0x01; val &= ~0x01;
err |= tvp7000_write_reg(TVP7000_PHASE_SELECT, err |= tvp7000_write_reg(TVP7000_PHASE_SELECT, (std->phase_select_bit0 & 0x01) | val);
(std->phase_select_bit0 & 0x01) | val);
return err; return err;
} }
...@@ -678,7 +677,7 @@ static int tvp7000_setup_video_stardard( ...@@ -678,7 +677,7 @@ static int tvp7000_setup_video_stardard(
static int tvp7000_selmux(void) static int tvp7000_selmux(void)
{ {
if(tvp7000_write_reg(TVP7000_INPUT_MUX_1, 0)) // set channel 1 if (tvp7000_write_reg(TVP7000_INPUT_MUX_1, 0)) // set channel 1
return -1; return -1;
return 0; return 0;
} }
...@@ -687,7 +686,7 @@ static int input_signal_exist(void) ...@@ -687,7 +686,7 @@ static int input_signal_exist(void)
{ {
int val; int val;
val = tvp7000_read_reg(TVP7000_SYNC_DETECT_STATUS); val = tvp7000_read_reg(TVP7000_SYNC_DETECT_STATUS);
if((val & 0x80) && (val & 0x10)) if ((val & 0x80) && (val & 0x10))
{ {
return 0; return 0;
} }
...@@ -698,7 +697,8 @@ static int tvp7000_device_cmd(u32 cmd, void *arg) ...@@ -698,7 +697,8 @@ static int tvp7000_device_cmd(u32 cmd, void *arg)
{ {
int ret = 0; int ret = 0;
switch (cmd) { switch (cmd)
{
case 0: case 0:
case VIDIOC_INT_RESET: case VIDIOC_INT_RESET:
tvp7000_device_init(NULL); tvp7000_device_init(NULL);
...@@ -716,7 +716,7 @@ static int tvp7000_device_cmd(u32 cmd, void *arg) ...@@ -716,7 +716,7 @@ static int tvp7000_device_cmd(u32 cmd, void *arg)
int input = *(int *)arg; int input = *(int *)arg;
if (input == VPFE_AMUX_COMPONENT) if (input == VPFE_AMUX_COMPONENT)
{ {
if(tvp7000_device_init(NULL)) if (tvp7000_device_init(NULL))
ret = -EBUSY; ret = -EBUSY;
} }
else else
...@@ -730,7 +730,7 @@ static int tvp7000_device_cmd(u32 cmd, void *arg) ...@@ -730,7 +730,7 @@ static int tvp7000_device_cmd(u32 cmd, void *arg)
if (params->amuxmode == VPFE_AMUX_COMPONENT) if (params->amuxmode == VPFE_AMUX_COMPONENT)
{ {
ret = tvp7000_setup_video_stardard(STD(VIDEO480P60HZ)); ret = tvp7000_setup_video_standard(STD(VIDEO480P60HZ));
} }
else else
ret = -1; ret = -1;
...@@ -753,7 +753,7 @@ static int tvp7000_device_init(struct vpfe_capture_params *params) ...@@ -753,7 +753,7 @@ static int tvp7000_device_init(struct vpfe_capture_params *params)
/* initialize TVP7000 as its default values */ /* initialize TVP7000 as its default values */
tvp7000_write_inittab(tvp7000_init_default, NUM_OF_REGS(tvp7000_init_default)); tvp7000_write_inittab(tvp7000_init_default, NUM_OF_REGS(tvp7000_init_default));
tvp7000_write_inittab(tvp7000_init_component, NUM_OF_REGS(tvp7000_init_component)); tvp7000_write_inittab(tvp7000_init_component, NUM_OF_REGS(tvp7000_init_component));
if(tvp7000_selmux()) if (tvp7000_selmux())
return -1; return -1;
return 0; return 0;
} }
...@@ -804,14 +804,16 @@ static __init int tvp7000_init(void) ...@@ -804,14 +804,16 @@ static __init int tvp7000_init(void)
break; break;
} }
} }
if (err) { if (err)
{
DPRINTK("I2C driver %s add failed\n", DPRINTK("I2C driver %s add failed\n",
tvp7000_driver.driver.name); tvp7000_driver.driver.name);
return err; return err;
} }
err = vpfe_capture_device_register(&tvp7000_capture_device); err = vpfe_capture_device_register(&tvp7000_capture_device);
if (err) { if (err)
{
DPRINTK("VPFE Capture Device %s register failed\n", DPRINTK("VPFE Capture Device %s register failed\n",
tvp7000_capture_device.name); tvp7000_capture_device.name);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment