aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/cx25821/cx25821-video2.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/cx25821/cx25821-video2.c')
-rw-r--r--drivers/staging/cx25821/cx25821-video2.c218
1 files changed, 109 insertions, 109 deletions
diff --git a/drivers/staging/cx25821/cx25821-video2.c b/drivers/staging/cx25821/cx25821-video2.c
index 98db1488dcf..10df4f981f3 100644
--- a/drivers/staging/cx25821/cx25821-video2.c
+++ b/drivers/staging/cx25821/cx25821-video2.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the Conexant CX25821 PCIe bridge 2 * Driver for the Conexant CX25821 PCIe bridge
3 * 3 *
4 * Copyright (C) 2009 Conexant Systems Inc. 4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com> 5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver 6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
7 * 7 *
@@ -41,37 +41,37 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
41 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]); 41 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
42 42
43 if (!list_empty(&q->queued)) { 43 if (!list_empty(&q->queued)) {
44 list_add_tail(&buf->vb.queue, &q->queued); 44 list_add_tail(&buf->vb.queue, &q->queued);
45 buf->vb.state = VIDEOBUF_QUEUED; 45 buf->vb.state = VIDEOBUF_QUEUED;
46 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); 46 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i);
47 47
48 } else if (list_empty(&q->active)) { 48 } else if (list_empty(&q->active)) {
49 list_add_tail(&buf->vb.queue, &q->active); 49 list_add_tail(&buf->vb.queue, &q->active);
50 cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH02]); 50 cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH02]);
51 buf->vb.state = VIDEOBUF_ACTIVE; 51 buf->vb.state = VIDEOBUF_ACTIVE;
52 buf->count = q->count++; 52 buf->count = q->count++;
53 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 53 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
54 dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", 54 dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
55 buf, buf->vb. i, buf->count, q->count); 55 buf, buf->vb. i, buf->count, q->count);
56 } else { 56 } else {
57 prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); 57 prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
58 if (prev->vb.width == buf->vb.width && 58 if (prev->vb.width == buf->vb.width &&
59 prev->vb.height == buf->vb.height && 59 prev->vb.height == buf->vb.height &&
60 prev->fmt == buf->fmt) { 60 prev->fmt == buf->fmt) {
61 list_add_tail(&buf->vb.queue, &q->active); 61 list_add_tail(&buf->vb.queue, &q->active);
62 buf->vb.state = VIDEOBUF_ACTIVE; 62 buf->vb.state = VIDEOBUF_ACTIVE;
63 buf->count = q->count++; 63 buf->count = q->count++;
64 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 64 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
65 65
66 /* 64 bit bits 63-32 */ 66 /* 64 bit bits 63-32 */
67 prev->risc.jmp[2] = cpu_to_le32(0); 67 prev->risc.jmp[2] = cpu_to_le32(0);
68 dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); 68 dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count);
69 69
70 } else { 70 } else {
71 list_add_tail(&buf->vb.queue, &q->queued); 71 list_add_tail(&buf->vb.queue, &q->queued);
72 buf->vb.state = VIDEOBUF_QUEUED; 72 buf->vb.state = VIDEOBUF_QUEUED;
73 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); 73 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i);
74 } 74 }
75 } 75 }
76 76
77 if (list_empty(&q->active)) 77 if (list_empty(&q->active))
@@ -101,17 +101,17 @@ static int video_open(struct file *file)
101 lock_kernel(); 101 lock_kernel();
102 list_for_each(list, &cx25821_devlist) 102 list_for_each(list, &cx25821_devlist)
103 { 103 {
104 h = list_entry(list, struct cx25821_dev, devlist); 104 h = list_entry(list, struct cx25821_dev, devlist);
105 105
106 if (h->video_dev[SRAM_CH02] && h->video_dev[SRAM_CH02]->minor == minor) { 106 if (h->video_dev[SRAM_CH02] && h->video_dev[SRAM_CH02]->minor == minor) {
107 dev = h; 107 dev = h;
108 type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 108 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
109 } 109 }
110 } 110 }
111 111
112 if (NULL == dev) { 112 if (NULL == dev) {
113 unlock_kernel(); 113 unlock_kernel();
114 return -ENODEV; 114 return -ENODEV;
115 } 115 }
116 116
117 printk("open minor=%d type=%s\n", minor, v4l2_type_names[type]); 117 printk("open minor=%d type=%s\n", minor, v4l2_type_names[type]);
@@ -119,8 +119,8 @@ static int video_open(struct file *file)
119 /* allocate + initialize per filehandle data */ 119 /* allocate + initialize per filehandle data */
120 fh = kzalloc(sizeof(*fh), GFP_KERNEL); 120 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
121 if (NULL == fh) { 121 if (NULL == fh) {
122 unlock_kernel(); 122 unlock_kernel();
123 return -ENOMEM; 123 return -ENOMEM;
124 } 124 }
125 file->private_data = fh; 125 file->private_data = fh;
126 fh->dev = dev; 126 fh->dev = dev;
@@ -128,9 +128,9 @@ static int video_open(struct file *file)
128 fh->width = 720; 128 fh->width = 720;
129 129
130 if(dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK) 130 if(dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
131 fh->height = 576; 131 fh->height = 576;
132 else 132 else
133 fh->height = 480; 133 fh->height = 480;
134 134
135 dev->channel_opened = SRAM_CH02; 135 dev->channel_opened = SRAM_CH02;
136 pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV; 136 pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
@@ -139,11 +139,11 @@ static int video_open(struct file *file)
139 v4l2_prio_open(&dev->prio,&fh->prio); 139 v4l2_prio_open(&dev->prio,&fh->prio);
140 140
141 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops, 141 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
142 &dev->pci->dev, &dev->slock, 142 &dev->pci->dev, &dev->slock,
143 V4L2_BUF_TYPE_VIDEO_CAPTURE, 143 V4L2_BUF_TYPE_VIDEO_CAPTURE,
144 V4L2_FIELD_INTERLACED, 144 V4L2_FIELD_INTERLACED,
145 sizeof(struct cx25821_buffer), 145 sizeof(struct cx25821_buffer),
146 fh); 146 fh);
147 147
148 dprintk(1, "post videobuf_queue_init()\n"); 148 dprintk(1, "post videobuf_queue_init()\n");
149 unlock_kernel(); 149 unlock_kernel();
@@ -157,15 +157,15 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
157 157
158 switch (fh->type) 158 switch (fh->type)
159 { 159 {
160 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 160 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
161 if (res_locked(fh->dev, RESOURCE_VIDEO2)) 161 if (res_locked(fh->dev, RESOURCE_VIDEO2))
162 return -EBUSY; 162 return -EBUSY;
163 163
164 return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); 164 return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK);
165 165
166 default: 166 default:
167 BUG(); 167 BUG();
168 return 0; 168 return 0;
169 } 169 }
170} 170}
171 171
@@ -175,36 +175,36 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
175 struct cx25821_buffer *buf; 175 struct cx25821_buffer *buf;
176 176
177 if (res_check(fh, RESOURCE_VIDEO2)) { 177 if (res_check(fh, RESOURCE_VIDEO2)) {
178 /* streaming capture */ 178 /* streaming capture */
179 if (list_empty(&fh->vidq.stream)) 179 if (list_empty(&fh->vidq.stream))
180 return POLLERR; 180 return POLLERR;
181 buf = list_entry(fh->vidq.stream.next, 181 buf = list_entry(fh->vidq.stream.next,
182 struct cx25821_buffer, vb.stream); 182 struct cx25821_buffer, vb.stream);
183 } else { 183 } else {
184 /* read() capture */ 184 /* read() capture */
185 buf = (struct cx25821_buffer *)fh->vidq.read_buf; 185 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
186 if (NULL == buf) 186 if (NULL == buf)
187 return POLLERR; 187 return POLLERR;
188 } 188 }
189 189
190 poll_wait(file, &buf->vb.done, wait); 190 poll_wait(file, &buf->vb.done, wait);
191 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) 191 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR)
192 { 192 {
193 if( buf->vb.state == VIDEOBUF_DONE ) 193 if( buf->vb.state == VIDEOBUF_DONE )
194 { 194 {
195 struct cx25821_dev *dev = fh->dev; 195 struct cx25821_dev *dev = fh->dev;
196 196
197 if( dev && dev->use_cif_resolution[SRAM_CH02] ) 197 if( dev && dev->use_cif_resolution[SRAM_CH02] )
198 { 198 {
199 u8 cam_id = *((char*)buf->vb.baddr+3); 199 u8 cam_id = *((char*)buf->vb.baddr+3);
200 memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2)); 200 memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2));
201 *((char*)buf->vb.baddr+3) = cam_id; 201 *((char*)buf->vb.baddr+3) = cam_id;
202 } 202 }
203 } 203 }
204 204
205 return POLLIN|POLLRDNORM; 205 return POLLIN|POLLRDNORM;
206 } 206 }
207 207
208 return 0; 208 return 0;
209} 209}
210 210
@@ -219,13 +219,13 @@ static int video_release(struct file *file)
219 219
220 /* stop video capture */ 220 /* stop video capture */
221 if (res_check(fh, RESOURCE_VIDEO2)) { 221 if (res_check(fh, RESOURCE_VIDEO2)) {
222 videobuf_queue_cancel(&fh->vidq); 222 videobuf_queue_cancel(&fh->vidq);
223 res_free(dev, fh, RESOURCE_VIDEO2); 223 res_free(dev, fh, RESOURCE_VIDEO2);
224 } 224 }
225 225
226 if (fh->vidq.read_buf) { 226 if (fh->vidq.read_buf) {
227 buffer_release(&fh->vidq, fh->vidq.read_buf); 227 buffer_release(&fh->vidq, fh->vidq.read_buf);
228 kfree(fh->vidq.read_buf); 228 kfree(fh->vidq.read_buf);
229 } 229 }
230 230
231 videobuf_mmap_free(&fh->vidq); 231 videobuf_mmap_free(&fh->vidq);
@@ -245,17 +245,17 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
245 245
246 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) 246 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
247 { 247 {
248 return -EINVAL; 248 return -EINVAL;
249 } 249 }
250 250
251 if (unlikely(i != fh->type)) 251 if (unlikely(i != fh->type))
252 { 252 {
253 return -EINVAL; 253 return -EINVAL;
254 } 254 }
255 255
256 if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO2)))) 256 if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO2))))
257 { 257 {
258 return -EBUSY; 258 return -EBUSY;
259 } 259 }
260 260
261 return videobuf_streamon(get_queue(fh)); 261 return videobuf_streamon(get_queue(fh));
@@ -268,14 +268,14 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
268 int err, res; 268 int err, res;
269 269
270 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 270 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
271 return -EINVAL; 271 return -EINVAL;
272 if (i != fh->type) 272 if (i != fh->type)
273 return -EINVAL; 273 return -EINVAL;
274 274
275 res = get_resource(fh, RESOURCE_VIDEO2); 275 res = get_resource(fh, RESOURCE_VIDEO2);
276 err = videobuf_streamoff(get_queue(fh)); 276 err = videobuf_streamoff(get_queue(fh));
277 if (err < 0) 277 if (err < 0)
278 return err; 278 return err;
279 res_free(dev, fh, res); 279 res_free(dev, fh, res);
280 return 0; 280 return 0;
281} 281}
@@ -286,21 +286,21 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
286{ 286{
287 struct cx25821_fh *fh = priv; 287 struct cx25821_fh *fh = priv;
288 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 288 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
289 int err; 289 int err;
290 int pix_format = 0; 290 int pix_format = 0;
291 291
292 if (fh) 292 if (fh)
293 { 293 {
294 err = v4l2_prio_check(&dev->prio, &fh->prio); 294 err = v4l2_prio_check(&dev->prio, &fh->prio);
295 if (0 != err) 295 if (0 != err)
296 return err; 296 return err;
297 } 297 }
298 298
299 dprintk(2, "%s()\n", __func__); 299 dprintk(2, "%s()\n", __func__);
300 err = vidioc_try_fmt_vid_cap(file, priv, f); 300 err = vidioc_try_fmt_vid_cap(file, priv, f);
301 301
302 if (0 != err) 302 if (0 != err)
303 return err; 303 return err;
304 304
305 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat); 305 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
306 fh->vidq.field = f->fmt.pix.field; 306 fh->vidq.field = f->fmt.pix.field;
@@ -308,33 +308,33 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
308 // check if width and height is valid based on set standard 308 // check if width and height is valid based on set standard
309 if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) 309 if (is_valid_width(f->fmt.pix.width, dev->tvnorm))
310 { 310 {
311 fh->width = f->fmt.pix.width; 311 fh->width = f->fmt.pix.width;
312 } 312 }
313 313
314 if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) 314 if (is_valid_height(f->fmt.pix.height, dev->tvnorm))
315 { 315 {
316 fh->height = f->fmt.pix.height; 316 fh->height = f->fmt.pix.height;
317 } 317 }
318 318
319 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) 319 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
320 pix_format = PIXEL_FRMT_411; 320 pix_format = PIXEL_FRMT_411;
321 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) 321 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
322 pix_format = PIXEL_FRMT_422; 322 pix_format = PIXEL_FRMT_422;
323 else 323 else
324 return -EINVAL; 324 return -EINVAL;
325
326 cx25821_set_pixel_format( dev, SRAM_CH02, pix_format );
325 327
326 cx25821_set_pixel_format( dev, SRAM_CH02, pix_format );
327
328 // check if cif resolution 328 // check if cif resolution
329 if (fh->width == 320 || fh->width == 352) 329 if (fh->width == 320 || fh->width == 352)
330 { 330 {
331 dev->use_cif_resolution[SRAM_CH02] = 1; 331 dev->use_cif_resolution[SRAM_CH02] = 1;
332 }else 332 }else
333 { 333 {
334 dev->use_cif_resolution[SRAM_CH02] = 0; 334 dev->use_cif_resolution[SRAM_CH02] = 0;
335 } 335 }
336 dev->cif_width[SRAM_CH02] = fh->width; 336 dev->cif_width[SRAM_CH02] = fh->width;
337 medusa_set_resolution( dev, fh->width, SRAM_CH02 ); 337 medusa_set_resolution( dev, fh->width, SRAM_CH02 );
338 338
339 339
340 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); 340 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field);
@@ -349,7 +349,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
349 struct cx25821_fh *fh = priv; 349 struct cx25821_fh *fh = priv;
350 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 350 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
351 351
352 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK); 352 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
353 353
354 p->sequence = dev->vidq[SRAM_CH02].count; 354 p->sequence = dev->vidq[SRAM_CH02].count;
355 355
@@ -361,15 +361,15 @@ static int vidioc_log_status (struct file *file, void *priv)
361 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 361 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
362 char name[32 + 2]; 362 char name[32 + 2];
363 363
364 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH02]; 364 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH02];
365 u32 tmp = 0; 365 u32 tmp = 0;
366 366
367 snprintf(name, sizeof(name), "%s/2", dev->name); 367 snprintf(name, sizeof(name), "%s/2", dev->name);
368 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n", 368 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
369 dev->name); 369 dev->name);
370 370
371 cx25821_call_all(dev, core, log_status); 371 cx25821_call_all(dev, core, log_status);
372 372
373 tmp = cx_read(sram_ch->dma_ctl); 373 tmp = cx_read(sram_ch->dma_ctl);
374 printk(KERN_INFO "Video input 2 is %s\n", (tmp & 0x11)?"streaming" : "stopped"); 374 printk(KERN_INFO "Video input 2 is %s\n", (tmp & 0x11)?"streaming" : "stopped");
375 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n", 375 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
@@ -381,10 +381,10 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
381 struct v4l2_control *ctl) 381 struct v4l2_control *ctl)
382{ 382{
383 struct cx25821_fh *fh = priv; 383 struct cx25821_fh *fh = priv;
384 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 384 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
385 int err; 385 int err;
386 386
387 if (fh) { 387 if (fh) {
388 err = v4l2_prio_check(&dev->prio, &fh->prio); 388 err = v4l2_prio_check(&dev->prio, &fh->prio);
389 if (0 != err) 389 if (0 != err)
390 return err; 390 return err;