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