aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/cx25821/cx25821-video1.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/cx25821/cx25821-video1.c')
-rw-r--r--drivers/staging/cx25821/cx25821-video1.c214
1 files changed, 107 insertions, 107 deletions
diff --git a/drivers/staging/cx25821/cx25821-video1.c b/drivers/staging/cx25821/cx25821-video1.c
index 44db11940ff..c36f664f635 100644
--- a/drivers/staging/cx25821/cx25821-video1.c
+++ b/drivers/staging/cx25821/cx25821-video1.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_CH01]); 50 cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH01]);
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_CH01] && h->video_dev[SRAM_CH01]->minor == minor) { 106 if (h->video_dev[SRAM_CH01] && h->video_dev[SRAM_CH01]->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 125
126 file->private_data = fh; 126 file->private_data = fh;
@@ -129,9 +129,9 @@ static int video_open(struct file *file)
129 fh->width = 720; 129 fh->width = 720;
130 130
131 if(dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK) 131 if(dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
132 fh->height = 576; 132 fh->height = 576;
133 else 133 else
134 fh->height = 480; 134 fh->height = 480;
135 135
136 dev->channel_opened = SRAM_CH01; 136 dev->channel_opened = SRAM_CH01;
137 pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV; 137 pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
@@ -140,11 +140,11 @@ static int video_open(struct file *file)
140 v4l2_prio_open(&dev->prio,&fh->prio); 140 v4l2_prio_open(&dev->prio,&fh->prio);
141 141
142 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops, 142 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
143 &dev->pci->dev, &dev->slock, 143 &dev->pci->dev, &dev->slock,
144 V4L2_BUF_TYPE_VIDEO_CAPTURE, 144 V4L2_BUF_TYPE_VIDEO_CAPTURE,
145 V4L2_FIELD_INTERLACED, 145 V4L2_FIELD_INTERLACED,
146 sizeof(struct cx25821_buffer), 146 sizeof(struct cx25821_buffer),
147 fh); 147 fh);
148 148
149 dprintk(1, "post videobuf_queue_init()\n"); 149 dprintk(1, "post videobuf_queue_init()\n");
150 unlock_kernel(); 150 unlock_kernel();
@@ -158,15 +158,15 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
158 158
159 switch (fh->type) 159 switch (fh->type)
160 { 160 {
161 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 161 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
162 if (res_locked(fh->dev, RESOURCE_VIDEO1)) 162 if (res_locked(fh->dev, RESOURCE_VIDEO1))
163 return -EBUSY; 163 return -EBUSY;
164 164
165 return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); 165 return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK);
166 166
167 default: 167 default:
168 BUG(); 168 BUG();
169 return 0; 169 return 0;
170 } 170 }
171} 171}
172 172
@@ -176,36 +176,36 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
176 struct cx25821_buffer *buf; 176 struct cx25821_buffer *buf;
177 177
178 if (res_check(fh, RESOURCE_VIDEO1)) { 178 if (res_check(fh, RESOURCE_VIDEO1)) {
179 /* streaming capture */ 179 /* streaming capture */
180 if (list_empty(&fh->vidq.stream)) 180 if (list_empty(&fh->vidq.stream))
181 return POLLERR; 181 return POLLERR;
182 buf = list_entry(fh->vidq.stream.next, 182 buf = list_entry(fh->vidq.stream.next,
183 struct cx25821_buffer, vb.stream); 183 struct cx25821_buffer, vb.stream);
184 } else { 184 } else {
185 /* read() capture */ 185 /* read() capture */
186 buf = (struct cx25821_buffer *)fh->vidq.read_buf; 186 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
187 if (NULL == buf) 187 if (NULL == buf)
188 return POLLERR; 188 return POLLERR;
189 } 189 }
190 190
191 poll_wait(file, &buf->vb.done, wait); 191 poll_wait(file, &buf->vb.done, wait);
192 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) 192 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR)
193 { 193 {
194 if( buf->vb.state == VIDEOBUF_DONE ) 194 if( buf->vb.state == VIDEOBUF_DONE )
195 { 195 {
196 struct cx25821_dev *dev = fh->dev; 196 struct cx25821_dev *dev = fh->dev;
197 197
198 if( dev && dev->use_cif_resolution[SRAM_CH01] ) 198 if( dev && dev->use_cif_resolution[SRAM_CH01] )
199 { 199 {
200 u8 cam_id = *((char*)buf->vb.baddr+3); 200 u8 cam_id = *((char*)buf->vb.baddr+3);
201 memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2)); 201 memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2));
202 *((char*)buf->vb.baddr+3) = cam_id; 202 *((char*)buf->vb.baddr+3) = cam_id;
203 } 203 }
204 } 204 }
205 205
206 return POLLIN|POLLRDNORM; 206 return POLLIN|POLLRDNORM;
207 } 207 }
208 208
209 return 0; 209 return 0;
210} 210}
211 211
@@ -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_VIDEO1)) { 221 if (res_check(fh, RESOURCE_VIDEO1)) {
222 videobuf_queue_cancel(&fh->vidq); 222 videobuf_queue_cancel(&fh->vidq);
223 res_free(dev, fh, RESOURCE_VIDEO1); 223 res_free(dev, fh, RESOURCE_VIDEO1);
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_VIDEO1)))) 256 if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO1))))
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_VIDEO1); 275 res = get_resource(fh, RESOURCE_VIDEO1);
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_CH01, pix_format );
325 327
326 cx25821_set_pixel_format( dev, SRAM_CH01, 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_CH01] = 1; 331 dev->use_cif_resolution[SRAM_CH01] = 1;
332 }else 332 }else
333 { 333 {
334 dev->use_cif_resolution[SRAM_CH01] = 0; 334 dev->use_cif_resolution[SRAM_CH01] = 0;
335 } 335 }
336 dev->cif_width[SRAM_CH01] = fh->width; 336 dev->cif_width[SRAM_CH01] = fh->width;
337 medusa_set_resolution( dev, fh->width, SRAM_CH01 ); 337 medusa_set_resolution( dev, fh->width, SRAM_CH01 );
338 338
339 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); 339 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field);
340 cx25821_call_all(dev, video, s_fmt, f); 340 cx25821_call_all(dev, video, s_fmt, f);
@@ -348,7 +348,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
348 struct cx25821_fh *fh = priv; 348 struct cx25821_fh *fh = priv;
349 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 349 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
350 350
351 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK); 351 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
352 352
353 p->sequence = dev->vidq[SRAM_CH01].count; 353 p->sequence = dev->vidq[SRAM_CH01].count;
354 354
@@ -360,7 +360,7 @@ static int vidioc_log_status (struct file *file, void *priv)
360 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 360 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
361 char name[32 + 2]; 361 char name[32 + 2];
362 362
363 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH01]; 363 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH01];
364 u32 tmp = 0; 364 u32 tmp = 0;
365 365
366 snprintf(name, sizeof(name), "%s/2", dev->name); 366 snprintf(name, sizeof(name), "%s/2", dev->name);
@@ -378,10 +378,10 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
378 struct v4l2_control *ctl) 378 struct v4l2_control *ctl)
379{ 379{
380 struct cx25821_fh *fh = priv; 380 struct cx25821_fh *fh = priv;
381 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 381 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
382 int err; 382 int err;
383 383
384 if (fh) { 384 if (fh) {
385 err = v4l2_prio_check(&dev->prio, &fh->prio); 385 err = v4l2_prio_check(&dev->prio, &fh->prio);
386 if (0 != err) 386 if (0 != err)
387 return err; 387 return err;
@@ -397,7 +397,7 @@ static const struct v4l2_file_operations video_fops = {
397 .read = video_read, 397 .read = video_read,
398 .poll = video_poll, 398 .poll = video_poll,
399 .mmap = video_mmap, 399 .mmap = video_mmap,
400 .ioctl = video_ioctl2, 400 .ioctl = video_ioctl2,
401}; 401};
402 402
403static const struct v4l2_ioctl_ops video_ioctl_ops = { 403static const struct v4l2_ioctl_ops video_ioctl_ops = {