aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/cx25821/cx25821-video7.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/cx25821/cx25821-video7.c')
-rw-r--r--drivers/staging/cx25821/cx25821-video7.c214
1 files changed, 107 insertions, 107 deletions
diff --git a/drivers/staging/cx25821/cx25821-video7.c b/drivers/staging/cx25821/cx25821-video7.c
index 966e369a4ab..71da80992b6 100644
--- a/drivers/staging/cx25821/cx25821-video7.c
+++ b/drivers/staging/cx25821/cx25821-video7.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 *
@@ -37,39 +37,39 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
37 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); 37 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
38 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */ 38 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
39 39
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 if (!list_empty(&q->queued)) { 41 if (!list_empty(&q->queued)) {
42 list_add_tail(&buf->vb.queue, &q->queued); 42 list_add_tail(&buf->vb.queue, &q->queued);
43 buf->vb.state = VIDEOBUF_QUEUED; 43 buf->vb.state = VIDEOBUF_QUEUED;
44 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); 44 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i);
45 45
46 } else if (list_empty(&q->active)) { 46 } else if (list_empty(&q->active)) {
47 list_add_tail(&buf->vb.queue, &q->active); 47 list_add_tail(&buf->vb.queue, &q->active);
48 cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH07]); 48 cx25821_start_video_dma(dev, q, buf, &dev->sram_channels[SRAM_CH07]);
49 buf->vb.state = VIDEOBUF_ACTIVE; 49 buf->vb.state = VIDEOBUF_ACTIVE;
50 buf->count = q->count++; 50 buf->count = q->count++;
51 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 51 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
52 dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", 52 dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
53 buf, buf->vb. i, buf->count, q->count); 53 buf, buf->vb. i, buf->count, q->count);
54 } else { 54 } else {
55 prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue); 55 prev = list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
56 if (prev->vb.width == buf->vb.width && 56 if (prev->vb.width == buf->vb.width &&
57 prev->vb.height == buf->vb.height && 57 prev->vb.height == buf->vb.height &&
58 prev->fmt == buf->fmt) { 58 prev->fmt == buf->fmt) {
59 list_add_tail(&buf->vb.queue, &q->active); 59 list_add_tail(&buf->vb.queue, &q->active);
60 buf->vb.state = VIDEOBUF_ACTIVE; 60 buf->vb.state = VIDEOBUF_ACTIVE;
61 buf->count = q->count++; 61 buf->count = q->count++;
62 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 62 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
63 63
64 /* 64 bit bits 63-32 */ 64 /* 64 bit bits 63-32 */
65 prev->risc.jmp[2] = cpu_to_le32(0); 65 prev->risc.jmp[2] = cpu_to_le32(0);
66 dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count); 66 dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", buf, buf->vb.i, buf->count);
67 67
68 } else { 68 } else {
69 list_add_tail(&buf->vb.queue, &q->queued); 69 list_add_tail(&buf->vb.queue, &q->queued);
70 buf->vb.state = VIDEOBUF_QUEUED; 70 buf->vb.state = VIDEOBUF_QUEUED;
71 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i); 71 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, buf->vb.i);
72 } 72 }
73 } 73 }
74 74
75 if (list_empty(&q->active)) 75 if (list_empty(&q->active))
@@ -99,17 +99,17 @@ static int video_open(struct file *file)
99 lock_kernel(); 99 lock_kernel();
100 list_for_each(list, &cx25821_devlist) 100 list_for_each(list, &cx25821_devlist)
101 { 101 {
102 h = list_entry(list, struct cx25821_dev, devlist); 102 h = list_entry(list, struct cx25821_dev, devlist);
103 103
104 if (h->video_dev[SRAM_CH07] && h->video_dev[SRAM_CH07]->minor == minor) { 104 if (h->video_dev[SRAM_CH07] && h->video_dev[SRAM_CH07]->minor == minor) {
105 dev = h; 105 dev = h;
106 type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 106 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
107 } 107 }
108 } 108 }
109 109
110 if (NULL == dev) { 110 if (NULL == dev) {
111 unlock_kernel(); 111 unlock_kernel();
112 return -ENODEV; 112 return -ENODEV;
113 } 113 }
114 114
115 printk("open minor=%d type=%s\n", minor, v4l2_type_names[type]); 115 printk("open minor=%d type=%s\n", minor, v4l2_type_names[type]);
@@ -117,8 +117,8 @@ static int video_open(struct file *file)
117 /* allocate + initialize per filehandle data */ 117 /* allocate + initialize per filehandle data */
118 fh = kzalloc(sizeof(*fh), GFP_KERNEL); 118 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
119 if (NULL == fh) { 119 if (NULL == fh) {
120 unlock_kernel(); 120 unlock_kernel();
121 return -ENOMEM; 121 return -ENOMEM;
122 } 122 }
123 file->private_data = fh; 123 file->private_data = fh;
124 fh->dev = dev; 124 fh->dev = dev;
@@ -126,22 +126,22 @@ static int video_open(struct file *file)
126 fh->width = 720; 126 fh->width = 720;
127 127
128 if(dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK) 128 if(dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
129 fh->height = 576; 129 fh->height = 576;
130 else 130 else
131 fh->height = 480; 131 fh->height = 480;
132 132
133 dev->channel_opened = SRAM_CH07; 133 dev->channel_opened = SRAM_CH07;
134 pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV; 134 pix_format = (dev->pixel_formats[dev->channel_opened] == PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
135 fh->fmt = format_by_fourcc(pix_format); 135 fh->fmt = format_by_fourcc(pix_format);
136 136
137 v4l2_prio_open(&dev->prio,&fh->prio); 137 v4l2_prio_open(&dev->prio,&fh->prio);
138 138
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_VIDEO7)) 159 if (res_locked(fh->dev, RESOURCE_VIDEO7))
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,34 +173,34 @@ 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_VIDEO7)) { 175 if (res_check(fh, RESOURCE_VIDEO7)) {
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_CH07] ) 195 if( dev && dev->use_cif_resolution[SRAM_CH07] )
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;
@@ -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_VIDEO7)) { 219 if (res_check(fh, RESOURCE_VIDEO7)) {
220 videobuf_queue_cancel(&fh->vidq); 220 videobuf_queue_cancel(&fh->vidq);
221 res_free(dev, fh, RESOURCE_VIDEO7); 221 res_free(dev, fh, RESOURCE_VIDEO7);
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_VIDEO7)))) 254 if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO7))))
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_VIDEO7); 273 res = get_resource(fh, RESOURCE_VIDEO7);
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}
@@ -283,13 +283,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
283{ 283{
284 struct cx25821_fh *fh = priv; 284 struct cx25821_fh *fh = priv;
285 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 285 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
286 int err; 286 int err;
287 int pix_format = 0; 287 int pix_format = 0;
288 288
289 if (fh) 289 if (fh)
290 { 290 {
291 err = v4l2_prio_check(&dev->prio, &fh->prio); 291 err = v4l2_prio_check(&dev->prio, &fh->prio);
292 if (0 != err) 292 if (0 != err)
293 return err; 293 return err;
294 } 294 }
295 295
@@ -297,7 +297,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
297 err = vidioc_try_fmt_vid_cap(file, priv, f); 297 err = vidioc_try_fmt_vid_cap(file, priv, f);
298 298
299 if (0 != err) 299 if (0 != err)
300 return err; 300 return err;
301 301
302 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat); 302 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
303 fh->vidq.field = f->fmt.pix.field; 303 fh->vidq.field = f->fmt.pix.field;
@@ -305,33 +305,33 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_forma
305 // check if width and height is valid based on set standard 305 // check if width and height is valid based on set standard
306 if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) 306 if (is_valid_width(f->fmt.pix.width, dev->tvnorm))
307 { 307 {
308 fh->width = f->fmt.pix.width; 308 fh->width = f->fmt.pix.width;
309 } 309 }
310 310
311 if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) 311 if (is_valid_height(f->fmt.pix.height, dev->tvnorm))
312 { 312 {
313 fh->height = f->fmt.pix.height; 313 fh->height = f->fmt.pix.height;
314 } 314 }
315 315
316 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) 316 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
317 pix_format = PIXEL_FRMT_411; 317 pix_format = PIXEL_FRMT_411;
318 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) 318 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
319 pix_format = PIXEL_FRMT_422; 319 pix_format = PIXEL_FRMT_422;
320 else 320 else
321 return -EINVAL; 321 return -EINVAL;
322
323 cx25821_set_pixel_format( dev, SRAM_CH07, pix_format );
322 324
323 cx25821_set_pixel_format( dev, SRAM_CH07, pix_format );
324
325 // check if cif resolution 325 // check if cif resolution
326 if (fh->width == 320 || fh->width == 352) 326 if (fh->width == 320 || fh->width == 352)
327 { 327 {
328 dev->use_cif_resolution[SRAM_CH07] = 1; 328 dev->use_cif_resolution[SRAM_CH07] = 1;
329 }else 329 }else
330 { 330 {
331 dev->use_cif_resolution[SRAM_CH07] = 0; 331 dev->use_cif_resolution[SRAM_CH07] = 0;
332 } 332 }
333 dev->cif_width[SRAM_CH07] = fh->width; 333 dev->cif_width[SRAM_CH07] = fh->width;
334 medusa_set_resolution( dev, fh->width, SRAM_CH07 ); 334 medusa_set_resolution( dev, fh->width, SRAM_CH07 );
335 335
336 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field); 336 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, fh->height, fh->vidq.field);
337 cx25821_call_all(dev, video, s_fmt, f); 337 cx25821_call_all(dev, video, s_fmt, f);
@@ -345,7 +345,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
345 struct cx25821_fh *fh = priv; 345 struct cx25821_fh *fh = priv;
346 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 346 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
347 347
348 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK); 348 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
349 349
350 p->sequence = dev->vidq[SRAM_CH07].count; 350 p->sequence = dev->vidq[SRAM_CH07].count;
351 351
@@ -356,14 +356,14 @@ static int vidioc_log_status (struct file *file, void *priv)
356 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 356 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
357 char name[32 + 2]; 357 char name[32 + 2];
358 358
359 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH07]; 359 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH07];
360 u32 tmp = 0; 360 u32 tmp = 0;
361 361
362 snprintf(name, sizeof(name), "%s/2", dev->name); 362 snprintf(name, sizeof(name), "%s/2", dev->name);
363 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n", 363 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
364 dev->name); 364 dev->name);
365 cx25821_call_all(dev, core, log_status); 365 cx25821_call_all(dev, core, log_status);
366 366
367 tmp = cx_read(sram_ch->dma_ctl); 367 tmp = cx_read(sram_ch->dma_ctl);
368 printk(KERN_INFO "Video input 7 is %s\n", (tmp & 0x11)?"streaming" : "stopped"); 368 printk(KERN_INFO "Video input 7 is %s\n", (tmp & 0x11)?"streaming" : "stopped");
369 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n", 369 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
@@ -375,10 +375,10 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
375 struct v4l2_control *ctl) 375 struct v4l2_control *ctl)
376{ 376{
377 struct cx25821_fh *fh = priv; 377 struct cx25821_fh *fh = priv;
378 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 378 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
379 int err; 379 int err;
380 380
381 if (fh) { 381 if (fh) {
382 err = v4l2_prio_check(&dev->prio, &fh->prio); 382 err = v4l2_prio_check(&dev->prio, &fh->prio);
383 if (0 != err) 383 if (0 != err)
384 return err; 384 return err;