Commit 1a72f1f3 authored by 吴智聪(John Wu)'s avatar 吴智聪(John Wu)

Merge branch 'neuros' of...

Merge branch 'neuros' of ssh://git@git.neuros.com.cn/git/git-pub/osd20/linux-davinci-2.6 into neuros
parents 2e95231c ea459896
......@@ -52,36 +52,36 @@ MODULE_LICENSE("GPL");
#define IS_ACTIVE(x) \
((x) && ACTIVE_DEVICE() && ((x)->id == ACTIVE_DEVICE()->id))
#define DEVICE_DEACTIVATE(x) do { \
if ((x) && (x)->capture_device_deactive && \
(x)->capture_device_deactive()) \
debug_print(KERN_ERR\
"capture device %s deactivate failed\n", \
(x)->name); \
if ((x) && (x)->capture_device_deactive && \
(x)->capture_device_deactive()) \
debug_print(KERN_ERR \
"capture device %s deactivate failed\n", \
(x)->name); \
} while (0)
#define DEVICE_ACTIVATE(x) do { \
if ((x) && (x)->capture_device_active && \
(x)->capture_device_active()) \
debug_print(KERN_ERR \
"capture device %s activate failed\n", \
(x)->name); \
if ((x) && (x)->capture_device_active && \
(x)->capture_device_active()) \
debug_print(KERN_ERR \
"capture device %s activate failed\n", \
(x)->name); \
} while (0)
#define DEVICE_INIT(x, params) do { \
if ((x) && (x)->capture_device_init && \
(x)->capture_device_init(params)) \
debug_print(KERN_ERR \
"capture device %s init failed\n", \
(x)->name); \
if ((x) && (x)->capture_device_init && \
(x)->capture_device_init(params)) \
debug_print(KERN_ERR \
"capture device %s init failed\n", \
(x)->name); \
} while (0)
#define DEVICE_CLEANUP(x) do { \
if ((x) && (x)->capture_device_cleanup && \
(x)->capture_device_cleanup()) \
debug_print(KERN_ERR \
"capture device %s cleanup failed\n", \
(x)->name); \
if ((x) && (x)->capture_device_cleanup && \
(x)->capture_device_cleanup()) \
debug_print(KERN_ERR \
"capture device %s cleanup failed\n", \
(x)->name); \
} while (0)
#define DEVICE_CMD(dev, cmd, arg) \
((dev) && (dev)->capture_device_cmd && \
(dev)->capture_device_cmd(cmd, arg));
((dev) && (dev)->capture_device_cmd) ? \
(dev)->capture_device_cmd(cmd, arg) : -EINVAL
static struct v4l2_rect ntsc_bounds = VPFE_WIN_NTSC;
static struct v4l2_rect pal_bounds = VPFE_WIN_PAL;
......@@ -91,6 +91,12 @@ static struct v4l2_rect ntscsp_bounds = VPFE_WIN_NTSC_SP;
static struct v4l2_rect palsp_bounds = VPFE_WIN_PAL_SP;
static struct v4l2_fract sp_aspect = VPFE_PIXELASPECT_NTSC_SP;
#define NTOSD_INPUTS 2
static struct v4l2_input ntosd_inputs[NTOSD_INPUTS] = {
{ 0, "COMPOSITE", 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 */
.usrs = 0,
.io_usrs = 0,
......@@ -154,7 +160,7 @@ static irqreturn_t vpfe_isr(int irq, void *dev_id)
vpfe->curFrm->boff + vpfe->field_offset;
ccdc_setfbaddr((unsigned long)addr);
}
} else if (fid == 1) {
} else if (fid == 1) {
/* if one field is just being captured */
/* configure the next frame */
/* get the next frame from the empty queue */
......@@ -196,7 +202,6 @@ static int buffer_prepare(struct videobuf_queue *q,
{
vpfe_obj *vpfe = &vpfe_device;
if (vb->state == STATE_NEEDS_INIT) {
vb->width = vpfe->vwin.width;
vb->height = vpfe->vwin.height;
......@@ -208,11 +213,13 @@ static int buffer_prepare(struct videobuf_queue *q,
return 0;
}
static void
buffer_config(struct videobuf_queue *q, unsigned int count)
{
vpfe_obj *vpfe = &vpfe_device;
int i;
for(i = 0; i < count; i++) {
q->bufs[i]->boff = virt_to_phys(vpfe->fbuffers[i]);
debug_print(KERN_INFO "buffer address: %x\n", q->bufs[i]->boff);
......@@ -226,7 +233,6 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
int i;
*size = VPFE_MAX_FBUF_SIZE;
for (i = VPFE_DEFNUM_FBUFS; i < *count; i++) {
u32 size = PAGE_SIZE << VPFE_MAX_FBUF_ORDER;
void *mem = (void *)__get_free_pages(GFP_KERNEL |GFP_DMA,
......@@ -253,6 +259,7 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
{
vpfe_obj *vpfe = &vpfe_device;
/* add the buffer to the DMA queue */
list_add_tail(&vb->queue, &vpfe->dma_queue);
vb->state = STATE_QUEUED;
......@@ -262,15 +269,14 @@ 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 */
if(vb->i < vpfe_device.numbuffers
&& vb->i >= VPFE_DEFNUM_FBUFS
&& vpfe_device.fbuffers[vb->i]){
&& vb->i >= VPFE_DEFNUM_FBUFS
&& vpfe_device.fbuffers[vb->i]){
free_pages((unsigned long)vpfe_device.fbuffers[vb->i],
VPFE_MAX_FBUF_ORDER);
vpfe_device.fbuffers[vb->i] = NULL;
}
}
static struct videobuf_queue_ops video_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
......@@ -305,9 +311,10 @@ static int vpfe_select_capture_device(int id)
{
int err = 0;
struct vpfe_capture_device *device;
down_interruptible(&vpfe_device.device_list_lock);
list_for_each_entry(device, &vpfe_device.capture_device_list,
device_list){
device_list){
if (device->id == id) {
err = vpfe_capture_device_active(device);
up(&vpfe_device.device_list_lock);
......@@ -342,7 +349,7 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
case VIDIOC_QUERYCAP:
{
struct v4l2_capability *cap =
(struct v4l2_capability *)arg;
(struct v4l2_capability *)arg;
memset(cap, 0, sizeof(*cap));
*cap = vpfe_drvcap;
break;
......@@ -383,7 +390,7 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
pixfmt->pixelformat = vpfe->pixelfmt;
pixfmt->bytesperline = pixfmt->width * 2;
pixfmt->sizeimage =
pixfmt->bytesperline * pixfmt->height;
pixfmt->bytesperline * pixfmt->height;
pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
up(&vpfe->lock);
}
......@@ -525,8 +532,8 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
vpfe->capture_params.squarepixel = sqp;
ret |= DEVICE_CMD(ACTIVE_DEVICE(),
VPFE_CMD_CONFIG_CAPTURE,
&vpfe->capture_params);
VPFE_CMD_CONFIG_CAPTURE,
&vpfe->capture_params);
up(&vpfe->lock);
break;
......@@ -583,44 +590,42 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
}
case VIDIOC_ENUMINPUT:
{
u32 index=0;
struct v4l2_input *input = (struct v4l2_input *)arg;
if (input->index > 1) /* only two inputs are available */
if( input->index < 0 || input->index >= NTOSD_INPUTS)
ret = -EINVAL;
index = input->index;
memset(input, 0, sizeof(*input));
input->index = index;
input->type = V4L2_INPUT_TYPE_CAMERA;
input->std = V4L2_STD_ALL;
if(input->index == 0){
sprintf(input->name, "COMPOSITE");
}else if(input->index == 1) {
sprintf(input->name, "S-VIDEO");
}
memcpy(input, &ntosd_inputs[input->index], sizeof(struct v4l2_input));
break;
}
case VIDIOC_G_INPUT:
{
int *index = (int *)arg;
*index = vpfe->capture_params.amuxmode;
break;
}
case VIDIOC_S_INPUT:
{
int *index = (int *)arg;
if (*index > 1 || *index < 0) {
ret = -EINVAL;
}
if (*index == VPFE_AMUX_COMPOSITE)
vpfe_select_capture_device(VPFE_CAPTURE_ID_TVP5150);
else if (*index == VPFE_AMUX_COMPONENT)
vpfe_select_capture_device(VPFE_CAPTURE_ID_TVP7000);
else
return -EINVAL;
vpfe->capture_params.amuxmode = *index;
ret |= DEVICE_CMD(ACTIVE_DEVICE(),
VIDIOC_S_INPUT, index);
ret = DEVICE_CMD(ACTIVE_DEVICE(), VIDIOC_S_INPUT, index);
break;
}
case VIDIOC_CROPCAP:
{
struct v4l2_cropcap *cropcap =
(struct v4l2_cropcap *)arg;
(struct v4l2_cropcap *)arg;
cropcap->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
down_interruptible(&vpfe->lock);
cropcap->bounds = cropcap->defrect = vpfe->vwin;
......@@ -637,7 +642,7 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
ret = -EINVAL;
} else {
struct v4l2_captureparm *capparm =
&parm->parm.capture;
&parm->parm.capture;
memset(capparm, 0,
sizeof(struct v4l2_captureparm));
down_interruptible(&vpfe->lock);
......@@ -657,7 +662,7 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
down_interruptible(&vpfe->lock);
ret |= DEVICE_CMD(ACTIVE_DEVICE(),
VIDIOC_G_CTRL, arg);
VIDIOC_G_CTRL, arg);
up(&vpfe->lock);
break;
......@@ -665,7 +670,7 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
down_interruptible(&vpfe->lock);
ret |= DEVICE_CMD(ACTIVE_DEVICE(),
VIDIOC_S_CTRL, arg);
VIDIOC_S_CTRL, arg);
up(&vpfe->lock);
break;
......@@ -673,7 +678,7 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
down_interruptible(&vpfe->lock);
ret |= DEVICE_CMD(ACTIVE_DEVICE(),
VIDIOC_QUERYCTRL, arg);
VIDIOC_QUERYCTRL, arg);
up(&vpfe->lock);
break;
......@@ -720,7 +725,7 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
down_interruptible(&vpfe->lock);
ret |= DEVICE_CMD(ACTIVE_DEVICE(),
VIDIOC_QUERYSTD, id);
VIDIOC_QUERYSTD, id);
up(&vpfe->lock);
break;
......@@ -794,16 +799,16 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
debug_print(KERN_INFO "cur frame %x.\n",
vpfe->dma_queue.next);
vpfe->nextFrm = vpfe->curFrm =
list_entry(vpfe->dma_queue.next,
struct videobuf_buffer, queue);
list_entry(vpfe->dma_queue.next,
struct videobuf_buffer, queue);
/* remove the buffer from the queue */
list_del(&vpfe->curFrm->queue);
vpfe->curFrm->state = STATE_ACTIVE;
/* sense the current video input standard */
ret |= DEVICE_CMD(ACTIVE_DEVICE(),
VPFE_CMD_CONFIG_CAPTURE,
&vpfe->capture_params);
VPFE_CMD_CONFIG_CAPTURE,
&vpfe->capture_params);
/* configure the ccdc and resizer as needed */
/* start capture by enabling CCDC and resizer */
ccdc_config_ycbcr(&vpfe->ccdc_params);
......@@ -814,7 +819,7 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
vpfe->started = TRUE;
vpfe->mode_changed = FALSE;
vpfe->field_offset =
(vpfe->vwin.height - 2) * vpfe->vwin.width;
(vpfe->vwin.height - 2) * vpfe->vwin.width;
ccdc_enable(TRUE);
up(&vpfe->lock);
debug_print(KERN_INFO "started video streaming.\n");
......@@ -854,7 +859,7 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
if (params->buf_type == CCDC_BUFTYPE_FLD_INTERLEAVED) {
vpfe->field = V4L2_FIELD_INTERLACED;
} else if (params->buf_type ==
CCDC_BUFTYPE_FLD_SEPARATED) {
CCDC_BUFTYPE_FLD_SEPARATED) {
vpfe->field = V4L2_FIELD_SEQ_TB;
}
if (params->pix_order == CCDC_PIXORDER_YCBYCR) {
......@@ -900,18 +905,12 @@ static int vpfe_doioctl(struct inode *inode, struct file *file,
}
vpfe->std = std;
ret |= DEVICE_CMD(ACTIVE_DEVICE(),
VPFE_CMD_CONFIG_CAPTURE,
params);
VPFE_CMD_CONFIG_CAPTURE,
params);
vpfe->capture_params = *params;
up(&vpfe->lock);
break;
}
case VPFE_CMD_CAPTURE_ACTIVE:
{
int device_id = *((int *)arg);
ret = vpfe_select_capture_device(device_id);
break;
}
default:
ret = -ENOIOCTLCMD;
break;
......@@ -926,7 +925,7 @@ static int vpfe_ioctl(struct inode *inode, struct file *file,
ret = video_usercopy(inode, file, cmd, arg, vpfe_doioctl);
if( cmd == VIDIOC_S_FMT || cmd == VIDIOC_TRY_FMT ){
ret = video_usercopy(inode, file, VIDIOC_G_FMT,
arg, vpfe_doioctl);
arg, vpfe_doioctl);
}
return ret;
}
......@@ -962,6 +961,32 @@ static int vpfe_open(struct inode *inode, struct file *filep)
v4l2_prio_open(&vpfe->prio, &fh->prio);
vpfe->usrs++;
/* active the tvp5150 */
vpfe_select_capture_device(VPFE_CAPTURE_ID_TVP5150);
/* detect if there is valid signal input */
{
v4l2_std_id *id;
*id = 0;
down_interruptible(&vpfe->lock);
DEVICE_CMD(ACTIVE_DEVICE(), VIDIOC_QUERYSTD, id);
up(&vpfe->lock);
if (*id != V4L2_STD_UNKNOWN)
vpfe->capture_params.amuxmode = VPFE_AMUX_COMPOSITE;
else
{
/* no valid input for tvp5150 then try tvp7000
* activate the tvp7000, and detect if there is valid input
* Todo after tvp7000 driver available.
*/
debug_print(KERN_INFO "no valid signal input\n");
/* the device can be opened even without valid input
* so if no valid input, use a default one
*/
vpfe->capture_params.amuxmode = VPFE_AMUX_COMPOSITE;
}
}
return 0;
}
......@@ -1070,11 +1095,11 @@ int vpfe_capture_device_register(struct vpfe_capture_device *device)
/* call capture device specific init routine */
down_interruptible(&vpfe_device.lock);
DEVICE_INIT(device, &vpfe_device.capture_params);
DEVICE_INIT(device, &vpfe_device.capture_params);
up(&vpfe_device.lock);
debug_print(KERN_INFO "VPFE Capture device %s registered, id = %d.\n",
device->name, device->id);
device->name, device->id);
return 0;
}
EXPORT_SYMBOL(vpfe_capture_device_register);
......@@ -1098,22 +1123,22 @@ int vpfe_capture_device_unregister(struct vpfe_capture_device *device)
}
/* call device specific routine to do the clean up. */
DEVICE_CLEANUP(device);
up(&vpfe_device.lock);
up(&vpfe_device.lock);
debug_print(KERN_INFO "VPFE Capture device %s unregistered, id = %d\n",
device->name, device->id);
device->name, device->id);
return 0;
}
EXPORT_SYMBOL(vpfe_capture_device_unregister);
static int capture_device_all_unrigister(void)
static int capture_device_all_unregister(void)
{
int ret = 0;
struct vpfe_capture_device *device;
down_interruptible(&vpfe_device.lock);
list_for_each_entry(device, &vpfe_device.capture_device_list,
device_list){
device_list){
ret |= vpfe_capture_device_unregister(device);
}
up(&vpfe_device.lock);
......@@ -1153,7 +1178,7 @@ static struct platform_device _vpfe_device = {
.id = 1,
.dev = {
.release = vpfe_platform_release,
}
}
};
static int vpfe_init(void)
......@@ -1201,7 +1226,7 @@ static int vpfe_init(void)
ccdc_reset();
/* setup interrupt handling */
result = request_irq(IRQ_VDINT0, vpfe_isr, IRQF_DISABLED,
"dm644xv4l2", (void *)&vpfe_device);
"dm644xv4l2", (void *)&vpfe_device);
if (result < 0) {
printk(KERN_ERR "DaVinci v4l2 capture driver: cannot initialize IRQ\n");
return result;
......@@ -1217,7 +1242,7 @@ static void vpfe_cleanup(void)
platform_device_unregister(&_vpfe_device);
driver_unregister(&vpfe_driver);
capture_device_all_unrigister();
capture_device_all_unregister();
/* disable interrupt */
free_irq(IRQ_VDINT0, &vpfe_device);
......
......@@ -834,28 +834,25 @@ static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
static int tvp5150_get_std(struct i2c_client *c, v4l2_std_id *id)
{
int fmt = tvp5150_read(c, TVP5150_VIDEO_STD);
int fmt = tvp5150_read(c, TVP5150_STATUS_REG_5);
fmt &= 0x0F;
switch (fmt) {
case 0x00:
*id = V4L2_STD_ALL;
break;
case 0x02:
case 0x01:
*id = V4L2_STD_NTSC;
break;
case 0x04:
case 0x03:
*id = V4L2_STD_PAL;
break;
case 0x06:
case 0x05:
*id = V4L2_STD_PAL_M;
break;
case 0x08:
case 0x07:
*id = V4L2_STD_PAL_N | V4L2_STD_PAL_Nc;
break;
case 0x0A:
case 0x09:
*id = V4L2_STD_NTSC_443;
break;
case 0x0C:
case 0x0b:
*id = V4L2_STD_SECAM;
break;
default:
......
......@@ -41,8 +41,7 @@
#define VPFE_CMD_CAPTURE_ACTIVE _IOW('V', BASE_VIDIOC_PRIVATE + 4, long int)
#define VPFE_AMUX_COMPOSITE 0
#define VPFE_AMUX_SVIDEO 1
#define VPFE_AMUX_COMPONENT 2
#define VPFE_AMUX_COMPONENT 1
/* settings for commonly used video formats */
#define VPFE_WIN_NTSC {0,0,720,480}
......@@ -54,9 +53,8 @@
#define VPFE_WIN_QVGA {0,0,320,240}
#define VPFE_WIN_SIF {0,0,352,240}
#define VPFE_CAPTURE_ID_TVP5146 0
#define VPFE_CAPTURE_ID_TVP5150 1
#define VPFE_CAPTURE_ID_TVP7000 2
#define VPFE_CAPTURE_ID_TVP5150 0
#define VPFE_CAPTURE_ID_TVP7000 1
#ifdef __KERNEL__
......
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