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