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