]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/staging/cx25821/cx25821-audups11.c
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[net-next-2.6.git] / drivers / staging / cx25821 / cx25821-audups11.c
CommitLineData
02b20b0b
MCC
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
bb4c9a74 4 * Copyright (C) 2009 Conexant Systems Inc.
02b20b0b
MCC
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 *
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
5a0e3ad6
TH
24#include <linux/slab.h>
25
02b20b0b
MCC
26#include "cx25821-video.h"
27
02b20b0b
MCC
28static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
29{
1a9fc855
MCC
30 struct cx25821_buffer *buf =
31 container_of(vb, struct cx25821_buffer, vb);
32 struct cx25821_buffer *prev;
33 struct cx25821_fh *fh = vq->priv_data;
34 struct cx25821_dev *dev = fh->dev;
35 struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH11];
36
37 /* add jump to stopper */
38 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
39 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
40 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
41
42 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
43
44 if (!list_empty(&q->queued)) {
45 list_add_tail(&buf->vb.queue, &q->queued);
46 buf->vb.state = VIDEOBUF_QUEUED;
47 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
48 buf->vb.i);
49
50 } else if (list_empty(&q->active)) {
51 list_add_tail(&buf->vb.queue, &q->active);
52 cx25821_start_video_dma(dev, q, buf,
53 &dev->sram_channels[SRAM_CH11]);
54 buf->vb.state = VIDEOBUF_ACTIVE;
55 buf->count = q->count++;
56 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
57 dprintk(2,
58 "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
59 buf, buf->vb.i, buf->count, q->count);
bb4c9a74 60 } else {
1a9fc855
MCC
61 prev =
62 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
63 if (prev->vb.width == buf->vb.width
64 && prev->vb.height == buf->vb.height
65 && prev->fmt == buf->fmt) {
66 list_add_tail(&buf->vb.queue, &q->active);
67 buf->vb.state = VIDEOBUF_ACTIVE;
68 buf->count = q->count++;
69 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
70
71 /* 64 bit bits 63-32 */
72 prev->risc.jmp[2] = cpu_to_le32(0);
73 dprintk(2,
74 "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
75 buf, buf->vb.i, buf->count);
76
77 } else {
78 list_add_tail(&buf->vb.queue, &q->queued);
79 buf->vb.state = VIDEOBUF_QUEUED;
80 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
81 buf->vb.i);
82 }
bb4c9a74 83 }
02b20b0b 84
1a9fc855
MCC
85 if (list_empty(&q->active)) {
86 dprintk(2, "active queue empty!\n");
87 }
02b20b0b
MCC
88}
89
02b20b0b 90static struct videobuf_queue_ops cx25821_video_qops = {
1a9fc855
MCC
91 .buf_setup = buffer_setup,
92 .buf_prepare = buffer_prepare,
93 .buf_queue = buffer_queue,
94 .buf_release = buffer_release,
02b20b0b
MCC
95};
96
02b20b0b
MCC
97static int video_open(struct file *file)
98{
50462eb0 99 struct video_device *vdev = video_devdata(file);
63b0d5ad 100 struct cx25821_dev *dev = video_drvdata(file);
1a9fc855 101 struct cx25821_fh *fh;
63b0d5ad 102 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
02b20b0b 103
50462eb0
LP
104 printk("open dev=%s type=%s\n", video_device_node_name(vdev),
105 v4l2_type_names[type]);
02b20b0b 106
1a9fc855
MCC
107 /* allocate + initialize per filehandle data */
108 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
63b0d5ad 109 if (NULL == fh)
1a9fc855 110 return -ENOMEM;
63b0d5ad
LP
111
112 lock_kernel();
02b20b0b 113
1a9fc855
MCC
114 file->private_data = fh;
115 fh->dev = dev;
116 fh->type = type;
117 fh->width = 720;
02b20b0b 118
1a9fc855
MCC
119 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
120 fh->height = 576;
121 else
122 fh->height = 480;
bb4c9a74 123
1a9fc855
MCC
124 dev->channel_opened = 10;
125 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_YUYV);
02b20b0b 126
1a9fc855 127 v4l2_prio_open(&dev->prio, &fh->prio);
02b20b0b 128
1a9fc855
MCC
129 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
130 &dev->pci->dev, &dev->slock,
131 V4L2_BUF_TYPE_VIDEO_CAPTURE,
132 V4L2_FIELD_INTERLACED,
133 sizeof(struct cx25821_buffer), fh);
02b20b0b 134
1a9fc855
MCC
135 dprintk(1, "post videobuf_queue_init()\n");
136 unlock_kernel();
02b20b0b 137
1a9fc855 138 return 0;
02b20b0b
MCC
139}
140
1a9fc855
MCC
141static ssize_t video_read(struct file *file, char __user * data, size_t count,
142 loff_t * ppos)
02b20b0b 143{
1a9fc855 144 struct cx25821_fh *fh = file->private_data;
02b20b0b 145
1a9fc855 146 switch (fh->type) {
bb4c9a74 147 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1a9fc855
MCC
148 if (res_locked(fh->dev, RESOURCE_VIDEO11))
149 return -EBUSY;
02b20b0b 150
1a9fc855
MCC
151 return videobuf_read_one(&fh->vidq, data, count, ppos,
152 file->f_flags & O_NONBLOCK);
02b20b0b 153
bb4c9a74 154 default:
1a9fc855
MCC
155 BUG();
156 return 0;
157 }
02b20b0b
MCC
158}
159
1a9fc855
MCC
160static unsigned int video_poll(struct file *file,
161 struct poll_table_struct *wait)
02b20b0b 162{
1a9fc855
MCC
163 struct cx25821_fh *fh = file->private_data;
164 struct cx25821_buffer *buf;
165
166 if (res_check(fh, RESOURCE_VIDEO11)) {
167 /* streaming capture */
168 if (list_empty(&fh->vidq.stream))
169 return POLLERR;
170 buf = list_entry(fh->vidq.stream.next,
171 struct cx25821_buffer, vb.stream);
172 } else {
173 /* read() capture */
174 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
175 if (NULL == buf)
176 return POLLERR;
177 }
02b20b0b 178
1a9fc855
MCC
179 poll_wait(file, &buf->vb.done, wait);
180 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR)
181 return POLLIN | POLLRDNORM;
182 return 0;
183}
02b20b0b
MCC
184
185static int video_release(struct file *file)
186{
1a9fc855
MCC
187 struct cx25821_fh *fh = file->private_data;
188 struct cx25821_dev *dev = fh->dev;
02b20b0b 189
1a9fc855
MCC
190 //stop the risc engine and fifo
191 //cx_write(channel11->dma_ctl, 0);
02b20b0b 192
1a9fc855
MCC
193 /* stop video capture */
194 if (res_check(fh, RESOURCE_VIDEO11)) {
195 videobuf_queue_cancel(&fh->vidq);
196 res_free(dev, fh, RESOURCE_VIDEO11);
197 }
02b20b0b 198
1a9fc855
MCC
199 if (fh->vidq.read_buf) {
200 buffer_release(&fh->vidq, fh->vidq.read_buf);
201 kfree(fh->vidq.read_buf);
202 }
02b20b0b 203
1a9fc855 204 videobuf_mmap_free(&fh->vidq);
02b20b0b 205
1a9fc855 206 v4l2_prio_close(&dev->prio, &fh->prio);
02b20b0b 207
1a9fc855
MCC
208 file->private_data = NULL;
209 kfree(fh);
02b20b0b 210
1a9fc855 211 return 0;
02b20b0b
MCC
212}
213
02b20b0b
MCC
214static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
215{
1a9fc855
MCC
216 struct cx25821_fh *fh = priv;
217 struct cx25821_dev *dev = fh->dev;
02b20b0b 218
1a9fc855
MCC
219 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
220 return -EINVAL;
221 }
02b20b0b 222
1a9fc855
MCC
223 if (unlikely(i != fh->type)) {
224 return -EINVAL;
225 }
02b20b0b 226
1a9fc855
MCC
227 if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO11)))) {
228 return -EBUSY;
229 }
02b20b0b 230
1a9fc855 231 return videobuf_streamon(get_queue(fh));
02b20b0b
MCC
232}
233
234static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
235{
1a9fc855
MCC
236 struct cx25821_fh *fh = priv;
237 struct cx25821_dev *dev = fh->dev;
238 int err, res;
239
240 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
241 return -EINVAL;
242 if (i != fh->type)
243 return -EINVAL;
244
245 res = get_resource(fh, RESOURCE_VIDEO11);
246 err = videobuf_streamoff(get_queue(fh));
247 if (err < 0)
248 return err;
249 res_free(dev, fh, res);
250 return 0;
02b20b0b
MCC
251}
252
1a9fc855
MCC
253static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
254 struct v4l2_format *f)
02b20b0b 255{
1a9fc855
MCC
256 struct cx25821_fh *fh = priv;
257 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
258 int err;
259
260 if (fh) {
261 err = v4l2_prio_check(&dev->prio, &fh->prio);
262 if (0 != err)
263 return err;
264 }
265
266 dprintk(2, "%s()\n", __func__);
267 err = vidioc_try_fmt_vid_cap(file, priv, f);
02b20b0b 268
bb4c9a74 269 if (0 != err)
1a9fc855
MCC
270 return err;
271 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
272 fh->width = f->fmt.pix.width;
273 fh->height = f->fmt.pix.height;
274 fh->vidq.field = f->fmt.pix.field;
275 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
276 fh->height, fh->vidq.field);
277 cx25821_call_all(dev, video, s_fmt, f);
278 return 0;
02b20b0b
MCC
279}
280
1a9fc855
MCC
281static long video_ioctl_upstream11(struct file *file, unsigned int cmd,
282 unsigned long arg)
bb4c9a74 283{
1a9fc855
MCC
284 struct cx25821_fh *fh = file->private_data;
285 struct cx25821_dev *dev = fh->dev;
286 int command = 0;
287 struct upstream_user_struct *data_from_user;
288
289 data_from_user = (struct upstream_user_struct *)arg;
290
291 if (!data_from_user) {
292 printk
293 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
294 __func__);
295 return 0;
296 }
bb4c9a74 297
1a9fc855 298 command = data_from_user->command;
bb4c9a74 299
1a9fc855
MCC
300 if (command != UPSTREAM_START_AUDIO && command != UPSTREAM_STOP_AUDIO) {
301 return 0;
302 }
02b20b0b 303
1a9fc855
MCC
304 dev->input_filename = data_from_user->input_filename;
305 dev->input_audiofilename = data_from_user->input_filename;
306 dev->vid_stdname = data_from_user->vid_stdname;
307 dev->pixel_format = data_from_user->pixel_format;
308 dev->channel_select = data_from_user->channel_select;
309 dev->command = data_from_user->command;
bb4c9a74 310
1a9fc855 311 switch (command) {
bb4c9a74 312 case UPSTREAM_START_AUDIO:
1a9fc855
MCC
313 cx25821_start_upstream_audio(dev, data_from_user);
314 break;
bb4c9a74
MCC
315
316 case UPSTREAM_STOP_AUDIO:
1a9fc855
MCC
317 cx25821_stop_upstream_audio(dev);
318 break;
319 }
bb4c9a74 320
1a9fc855 321 return 0;
02b20b0b
MCC
322}
323
324static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
325{
1a9fc855
MCC
326 struct cx25821_fh *fh = priv;
327 return videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
02b20b0b
MCC
328}
329
1a9fc855 330static int vidioc_log_status(struct file *file, void *priv)
02b20b0b 331{
1a9fc855
MCC
332 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
333 char name[32 + 2];
02b20b0b 334
1a9fc855
MCC
335 snprintf(name, sizeof(name), "%s/2", dev->name);
336 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
02b20b0b 337 dev->name);
1a9fc855
MCC
338 cx25821_call_all(dev, core, log_status);
339 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
02b20b0b 340 dev->name);
1a9fc855 341 return 0;
02b20b0b
MCC
342}
343
344static int vidioc_s_ctrl(struct file *file, void *priv,
1a9fc855 345 struct v4l2_control *ctl)
02b20b0b 346{
1a9fc855 347 struct cx25821_fh *fh = priv;
c424d46f 348 struct cx25821_dev *dev;
1a9fc855
MCC
349 int err;
350
351 if (fh) {
c424d46f 352 dev = fh->dev;
1a9fc855
MCC
353 err = v4l2_prio_check(&dev->prio, &fh->prio);
354 if (0 != err)
355 return err;
356 }
357 return 0;
02b20b0b 358}
1a9fc855 359
02b20b0b
MCC
360// exported stuff
361static const struct v4l2_file_operations video_fops = {
1a9fc855
MCC
362 .owner = THIS_MODULE,
363 .open = video_open,
364 .release = video_release,
365 .read = video_read,
366 .poll = video_poll,
367 .mmap = video_mmap,
368 .ioctl = video_ioctl_upstream11,
02b20b0b
MCC
369};
370
371static const struct v4l2_ioctl_ops video_ioctl_ops = {
1a9fc855
MCC
372 .vidioc_querycap = vidioc_querycap,
373 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
374 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
375 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
376 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
377 .vidioc_reqbufs = vidioc_reqbufs,
378 .vidioc_querybuf = vidioc_querybuf,
379 .vidioc_qbuf = vidioc_qbuf,
380 .vidioc_dqbuf = vidioc_dqbuf,
02b20b0b 381#ifdef TUNER_FLAG
1a9fc855
MCC
382 .vidioc_s_std = vidioc_s_std,
383 .vidioc_querystd = vidioc_querystd,
02b20b0b 384#endif
1a9fc855
MCC
385 .vidioc_cropcap = vidioc_cropcap,
386 .vidioc_s_crop = vidioc_s_crop,
387 .vidioc_g_crop = vidioc_g_crop,
388 .vidioc_enum_input = vidioc_enum_input,
389 .vidioc_g_input = vidioc_g_input,
390 .vidioc_s_input = vidioc_s_input,
391 .vidioc_g_ctrl = vidioc_g_ctrl,
392 .vidioc_s_ctrl = vidioc_s_ctrl,
393 .vidioc_queryctrl = vidioc_queryctrl,
394 .vidioc_streamon = vidioc_streamon,
395 .vidioc_streamoff = vidioc_streamoff,
396 .vidioc_log_status = vidioc_log_status,
397 .vidioc_g_priority = vidioc_g_priority,
398 .vidioc_s_priority = vidioc_s_priority,
02b20b0b 399#ifdef CONFIG_VIDEO_V4L1_COMPAT
1a9fc855 400 .vidiocgmbuf = vidiocgmbuf,
02b20b0b
MCC
401#endif
402#ifdef TUNER_FLAG
1a9fc855
MCC
403 .vidioc_g_tuner = vidioc_g_tuner,
404 .vidioc_s_tuner = vidioc_s_tuner,
405 .vidioc_g_frequency = vidioc_g_frequency,
406 .vidioc_s_frequency = vidioc_s_frequency,
02b20b0b
MCC
407#endif
408#ifdef CONFIG_VIDEO_ADV_DEBUG
1a9fc855
MCC
409 .vidioc_g_register = vidioc_g_register,
410 .vidioc_s_register = vidioc_s_register,
02b20b0b
MCC
411#endif
412};
413
414struct video_device cx25821_video_template11 = {
1a9fc855
MCC
415 .name = "cx25821-audioupstream",
416 .fops = &video_fops,
1a9fc855
MCC
417 .ioctl_ops = &video_ioctl_ops,
418 .tvnorms = CX25821_NORMS,
419 .current_norm = V4L2_STD_NTSC_M,
02b20b0b 420};