aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/cx25821/cx25821-video4.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/cx25821/cx25821-video4.c')
-rw-r--r--drivers/staging/cx25821/cx25821-video4.c210
1 files changed, 105 insertions, 105 deletions
diff --git a/drivers/staging/cx25821/cx25821-video4.c b/drivers/staging/cx25821/cx25821-video4.c
index 03da3642cc3..c1799d98135 100644
--- a/drivers/staging/cx25821/cx25821-video4.c
+++ b/drivers/staging/cx25821/cx25821-video4.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_CH04]); 49 cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH04]);
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_CH04] && h->video_dev[SRAM_CH04]->minor == minor) { 105 if (h->video_dev[SRAM_CH04] && h->video_dev[SRAM_CH04]->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_CH04; 134 dev->channel_opened = SRAM_CH04;
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;
@@ -137,11 +137,11 @@ static int video_open(struct file *file)
137 137
138 v4l2_prio_open(&dev->prio,&fh->prio); 138 v4l2_prio_open(&dev->prio,&fh->prio);
139 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops, 139 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
140 &dev->pci->dev, &dev->slock, 140 &dev->pci->dev, &dev->slock,
141 V4L2_BUF_TYPE_VIDEO_CAPTURE, 141 V4L2_BUF_TYPE_VIDEO_CAPTURE,
142 V4L2_FIELD_INTERLACED, 142 V4L2_FIELD_INTERLACED,
143 sizeof(struct cx25821_buffer), 143 sizeof(struct cx25821_buffer),
144 fh); 144 fh);
145 145
146 dprintk(1, "post videobuf_queue_init()\n"); 146 dprintk(1, "post videobuf_queue_init()\n");
147 unlock_kernel(); 147 unlock_kernel();
@@ -155,15 +155,15 @@ static ssize_t video_read(struct file *file, char __user *data, size_t count, lo
155 155
156 switch (fh->type) 156 switch (fh->type)
157 { 157 {
158 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 158 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
159 if (res_locked(fh->dev, RESOURCE_VIDEO4)) 159 if (res_locked(fh->dev, RESOURCE_VIDEO4))
160 return -EBUSY; 160 return -EBUSY;
161 161
162 return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK); 162 return videobuf_read_one(&fh->vidq, data, count, ppos, file->f_flags & O_NONBLOCK);
163 163
164 default: 164 default:
165 BUG(); 165 BUG();
166 return 0; 166 return 0;
167 } 167 }
168} 168}
169 169
@@ -173,36 +173,36 @@ static unsigned int video_poll(struct file *file, struct poll_table_struct *wait
173 struct cx25821_buffer *buf; 173 struct cx25821_buffer *buf;
174 174
175 if (res_check(fh, RESOURCE_VIDEO4)) { 175 if (res_check(fh, RESOURCE_VIDEO4)) {
176 /* streaming capture */ 176 /* streaming capture */
177 if (list_empty(&fh->vidq.stream)) 177 if (list_empty(&fh->vidq.stream))
178 return POLLERR; 178 return POLLERR;
179 buf = list_entry(fh->vidq.stream.next, 179 buf = list_entry(fh->vidq.stream.next,
180 struct cx25821_buffer, vb.stream); 180 struct cx25821_buffer, vb.stream);
181 } else { 181 } else {
182 /* read() capture */ 182 /* read() capture */
183 buf = (struct cx25821_buffer *)fh->vidq.read_buf; 183 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
184 if (NULL == buf) 184 if (NULL == buf)
185 return POLLERR; 185 return POLLERR;
186 } 186 }
187 187
188 poll_wait(file, &buf->vb.done, wait); 188 poll_wait(file, &buf->vb.done, wait);
189 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) 189 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR)
190 { 190 {
191 if( buf->vb.state == VIDEOBUF_DONE ) 191 if( buf->vb.state == VIDEOBUF_DONE )
192 { 192 {
193 struct cx25821_dev *dev = fh->dev; 193 struct cx25821_dev *dev = fh->dev;
194 194
195 if( dev && dev->use_cif_resolution[SRAM_CH04] ) 195 if( dev && dev->use_cif_resolution[SRAM_CH04] )
196 { 196 {
197 u8 cam_id = *((char*)buf->vb.baddr+3); 197 u8 cam_id = *((char*)buf->vb.baddr+3);
198 memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2)); 198 memcpy((char*)buf->vb.baddr, (char*)buf->vb.baddr + (fh->width * 2), (fh->width * 2));
199 *((char*)buf->vb.baddr+3) = cam_id; 199 *((char*)buf->vb.baddr+3) = cam_id;
200 } 200 }
201 } 201 }
202 202
203 return POLLIN|POLLRDNORM; 203 return POLLIN|POLLRDNORM;
204 } 204 }
205 205
206 return 0; 206 return 0;
207} 207}
208 208
@@ -217,13 +217,13 @@ static int video_release(struct file *file)
217 217
218 /* stop video capture */ 218 /* stop video capture */
219 if (res_check(fh, RESOURCE_VIDEO4)) { 219 if (res_check(fh, RESOURCE_VIDEO4)) {
220 videobuf_queue_cancel(&fh->vidq); 220 videobuf_queue_cancel(&fh->vidq);
221 res_free(dev, fh, RESOURCE_VIDEO4); 221 res_free(dev, fh, RESOURCE_VIDEO4);
222 } 222 }
223 223
224 if (fh->vidq.read_buf) { 224 if (fh->vidq.read_buf) {
225 buffer_release(&fh->vidq, fh->vidq.read_buf); 225 buffer_release(&fh->vidq, fh->vidq.read_buf);
226 kfree(fh->vidq.read_buf); 226 kfree(fh->vidq.read_buf);
227 } 227 }
228 228
229 videobuf_mmap_free(&fh->vidq); 229 videobuf_mmap_free(&fh->vidq);
@@ -243,17 +243,17 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
243 243
244 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) 244 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
245 { 245 {
246 return -EINVAL; 246 return -EINVAL;
247 } 247 }
248 248
249 if (unlikely(i != fh->type)) 249 if (unlikely(i != fh->type))
250 { 250 {
251 return -EINVAL; 251 return -EINVAL;
252 } 252 }
253 253
254 if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO4)))) 254 if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO4))))
255 { 255 {
256 return -EBUSY; 256 return -EBUSY;
257 } 257 }
258 258
259 return videobuf_streamon(get_queue(fh)); 259 return videobuf_streamon(get_queue(fh));
@@ -266,14 +266,14 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
266 int err, res; 266 int err, res;
267 267
268 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 268 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
269 return -EINVAL; 269 return -EINVAL;
270 if (i != fh->type) 270 if (i != fh->type)
271 return -EINVAL; 271 return -EINVAL;
272 272
273 res = get_resource(fh, RESOURCE_VIDEO4); 273 res = get_resource(fh, RESOURCE_VIDEO4);
274 err = videobuf_streamoff(get_queue(fh)); 274 err = videobuf_streamoff(get_queue(fh));
275 if (err < 0) 275 if (err < 0)
276 return err; 276 return err;
277 res_free(dev, fh, res); 277 res_free(dev, fh, res);
278 return 0; 278 return 0;
279} 279}
@@ -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 // check priority 290 // check priority
291 if (fh) 291 if (fh)
292 { 292 {
293 err = v4l2_prio_check(&dev->prio, &fh->prio); 293 err = v4l2_prio_check(&dev->prio, &fh->prio);
294 if (0 != err) 294 if (0 != err)
295 return err; 295 return err;
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_CH04, pix_format );
323 325
324 cx25821_set_pixel_format( dev, SRAM_CH04, 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_CH04] = 1; 329 dev->use_cif_resolution[SRAM_CH04] = 1;
330 }else 330 }else
331 { 331 {
332 dev->use_cif_resolution[SRAM_CH04] = 0; 332 dev->use_cif_resolution[SRAM_CH04] = 0;
333 } 333 }
334 dev->cif_width[SRAM_CH04] = fh->width; 334 dev->cif_width[SRAM_CH04] = fh->width;
335 medusa_set_resolution( dev, fh->width, SRAM_CH04); 335 medusa_set_resolution( dev, fh->width, SRAM_CH04);
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_CH04].count; 351 p->sequence = dev->vidq[SRAM_CH04].count;
352 352
@@ -358,7 +358,7 @@ static int vidioc_log_status (struct file *file, void *priv)
358 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 358 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
359 char name[32 + 2]; 359 char name[32 + 2];
360 360
361 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH04]; 361 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH04];
362 u32 tmp = 0; 362 u32 tmp = 0;
363 363
364 snprintf(name, sizeof(name), "%s/2", dev->name); 364 snprintf(name, sizeof(name), "%s/2", dev->name);
@@ -377,10 +377,10 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
377 struct v4l2_control *ctl) 377 struct v4l2_control *ctl)
378{ 378{
379 struct cx25821_fh *fh = priv; 379 struct cx25821_fh *fh = priv;
380 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 380 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
381 int err; 381 int err;
382 382
383 if (fh) { 383 if (fh) {
384 err = v4l2_prio_check(&dev->prio, &fh->prio); 384 err = v4l2_prio_check(&dev->prio, &fh->prio);
385 if (0 != err) 385 if (0 != err)
386 return err; 386 return err;