Commit | Line | Data |
---|---|---|
e0d3bafd | 1 | /* |
cde4362f MCC |
2 | cx231xx-video.c - driver for Conexant Cx23100/101/102 |
3 | USB video capture devices | |
e0d3bafd SD |
4 | |
5 | Copyright (C) 2008 <srinivasa.deevi at conexant dot com> | |
84b5dbf3 MCC |
6 | Based on em28xx driver |
7 | Based on cx23885 driver | |
8 | Based on cx88 driver | |
e0d3bafd SD |
9 | |
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with this program; if not, write to the Free Software | |
22 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | */ | |
24 | ||
e0d3bafd SD |
25 | #include <linux/init.h> |
26 | #include <linux/list.h> | |
27 | #include <linux/module.h> | |
28 | #include <linux/kernel.h> | |
29 | #include <linux/bitmap.h> | |
30 | #include <linux/usb.h> | |
31 | #include <linux/i2c.h> | |
32 | #include <linux/version.h> | |
33 | #include <linux/mm.h> | |
34 | #include <linux/mutex.h> | |
35 | ||
36 | #include <media/v4l2-common.h> | |
37 | #include <media/v4l2-ioctl.h> | |
38 | #include <media/v4l2-chip-ident.h> | |
39 | #include <media/msp3400.h> | |
40 | #include <media/tuner.h> | |
41 | ||
42 | #include "dvb_frontend.h" | |
43 | ||
44 | #include "cx231xx.h" | |
45 | #include "cx231xx-vbi.h" | |
46 | ||
818fdf34 MCC |
47 | #define CX231XX_VERSION_CODE KERNEL_VERSION(0, 0, 1) |
48 | ||
e0d3bafd SD |
49 | #define DRIVER_AUTHOR "Srinivasa Deevi <srinivasa.deevi@conexant.com>" |
50 | #define DRIVER_DESC "Conexant cx231xx based USB video device driver" | |
51 | ||
e0d3bafd SD |
52 | #define cx231xx_videodbg(fmt, arg...) do {\ |
53 | if (video_debug) \ | |
54 | printk(KERN_INFO "%s %s :"fmt, \ | |
55 | dev->name, __func__ , ##arg); } while (0) | |
56 | ||
57 | static unsigned int isoc_debug; | |
58 | module_param(isoc_debug, int, 0644); | |
59 | MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]"); | |
60 | ||
61 | #define cx231xx_isocdbg(fmt, arg...) \ | |
62 | do {\ | |
63 | if (isoc_debug) { \ | |
64 | printk(KERN_INFO "%s %s :"fmt, \ | |
65 | dev->name, __func__ , ##arg); \ | |
66 | } \ | |
67 | } while (0) | |
68 | ||
69 | MODULE_AUTHOR(DRIVER_AUTHOR); | |
70 | MODULE_DESCRIPTION(DRIVER_DESC); | |
71 | MODULE_LICENSE("GPL"); | |
72 | ||
e0d3bafd SD |
73 | static unsigned int card[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET }; |
74 | static unsigned int video_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET }; | |
75 | static unsigned int vbi_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET }; | |
76 | static unsigned int radio_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET }; | |
77 | ||
84b5dbf3 | 78 | module_param_array(card, int, NULL, 0444); |
e0d3bafd SD |
79 | module_param_array(video_nr, int, NULL, 0444); |
80 | module_param_array(vbi_nr, int, NULL, 0444); | |
81 | module_param_array(radio_nr, int, NULL, 0444); | |
82 | ||
84b5dbf3 | 83 | MODULE_PARM_DESC(card, "card type"); |
e0d3bafd | 84 | MODULE_PARM_DESC(video_nr, "video device numbers"); |
84b5dbf3 | 85 | MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); |
e0d3bafd SD |
86 | MODULE_PARM_DESC(radio_nr, "radio device numbers"); |
87 | ||
88 | static unsigned int video_debug; | |
89 | module_param(video_debug, int, 0644); | |
90 | MODULE_PARM_DESC(video_debug, "enable debug messages [video]"); | |
91 | ||
e0d3bafd SD |
92 | /* supported video standards */ |
93 | static struct cx231xx_fmt format[] = { | |
94 | { | |
84b5dbf3 MCC |
95 | .name = "16bpp YUY2, 4:2:2, packed", |
96 | .fourcc = V4L2_PIX_FMT_YUYV, | |
97 | .depth = 16, | |
98 | .reg = 0, | |
99 | }, | |
e0d3bafd SD |
100 | }; |
101 | ||
e0d3bafd SD |
102 | /* supported controls */ |
103 | /* Common to all boards */ | |
104 | ||
105 | /* ------------------------------------------------------------------- */ | |
106 | ||
107 | static const struct v4l2_queryctrl no_ctl = { | |
84b5dbf3 | 108 | .name = "42", |
e0d3bafd SD |
109 | .flags = V4L2_CTRL_FLAG_DISABLED, |
110 | }; | |
111 | ||
112 | static struct cx231xx_ctrl cx231xx_ctls[] = { | |
113 | /* --- video --- */ | |
114 | { | |
cde4362f MCC |
115 | .v = { |
116 | .id = V4L2_CID_BRIGHTNESS, | |
117 | .name = "Brightness", | |
118 | .minimum = 0x00, | |
119 | .maximum = 0xff, | |
120 | .step = 1, | |
121 | .default_value = 0x7f, | |
122 | .type = V4L2_CTRL_TYPE_INTEGER, | |
123 | }, | |
124 | .off = 128, | |
125 | .reg = LUMA_CTRL, | |
126 | .mask = 0x00ff, | |
127 | .shift = 0, | |
128 | }, { | |
129 | .v = { | |
130 | .id = V4L2_CID_CONTRAST, | |
131 | .name = "Contrast", | |
132 | .minimum = 0, | |
133 | .maximum = 0xff, | |
134 | .step = 1, | |
135 | .default_value = 0x3f, | |
136 | .type = V4L2_CTRL_TYPE_INTEGER, | |
137 | }, | |
138 | .off = 0, | |
139 | .reg = LUMA_CTRL, | |
140 | .mask = 0xff00, | |
141 | .shift = 8, | |
142 | }, { | |
143 | .v = { | |
144 | .id = V4L2_CID_HUE, | |
145 | .name = "Hue", | |
146 | .minimum = 0, | |
147 | .maximum = 0xff, | |
148 | .step = 1, | |
149 | .default_value = 0x7f, | |
150 | .type = V4L2_CTRL_TYPE_INTEGER, | |
151 | }, | |
152 | .off = 128, | |
153 | .reg = CHROMA_CTRL, | |
154 | .mask = 0xff0000, | |
155 | .shift = 16, | |
156 | }, { | |
157 | /* strictly, this only describes only U saturation. | |
158 | * V saturation is handled specially through code. | |
159 | */ | |
160 | .v = { | |
161 | .id = V4L2_CID_SATURATION, | |
162 | .name = "Saturation", | |
163 | .minimum = 0, | |
164 | .maximum = 0xff, | |
165 | .step = 1, | |
166 | .default_value = 0x7f, | |
167 | .type = V4L2_CTRL_TYPE_INTEGER, | |
168 | }, | |
169 | .off = 0, | |
170 | .reg = CHROMA_CTRL, | |
171 | .mask = 0x00ff, | |
172 | .shift = 0, | |
173 | }, { | |
174 | /* --- audio --- */ | |
175 | .v = { | |
176 | .id = V4L2_CID_AUDIO_MUTE, | |
177 | .name = "Mute", | |
178 | .minimum = 0, | |
179 | .maximum = 1, | |
180 | .default_value = 1, | |
181 | .type = V4L2_CTRL_TYPE_BOOLEAN, | |
182 | }, | |
183 | .reg = PATH1_CTL1, | |
184 | .mask = (0x1f << 24), | |
185 | .shift = 24, | |
186 | }, { | |
187 | .v = { | |
188 | .id = V4L2_CID_AUDIO_VOLUME, | |
189 | .name = "Volume", | |
190 | .minimum = 0, | |
191 | .maximum = 0x3f, | |
192 | .step = 1, | |
193 | .default_value = 0x3f, | |
194 | .type = V4L2_CTRL_TYPE_INTEGER, | |
195 | }, | |
196 | .reg = PATH1_VOL_CTL, | |
197 | .mask = 0xff, | |
198 | .shift = 0, | |
199 | } | |
e0d3bafd SD |
200 | }; |
201 | static const int CX231XX_CTLS = ARRAY_SIZE(cx231xx_ctls); | |
202 | ||
203 | static const u32 cx231xx_user_ctrls[] = { | |
204 | V4L2_CID_USER_CLASS, | |
205 | V4L2_CID_BRIGHTNESS, | |
206 | V4L2_CID_CONTRAST, | |
207 | V4L2_CID_SATURATION, | |
208 | V4L2_CID_HUE, | |
209 | V4L2_CID_AUDIO_VOLUME, | |
210 | #if 0 | |
211 | V4L2_CID_AUDIO_BALANCE, | |
212 | #endif | |
213 | V4L2_CID_AUDIO_MUTE, | |
214 | 0 | |
215 | }; | |
216 | ||
217 | static const u32 *ctrl_classes[] = { | |
218 | cx231xx_user_ctrls, | |
219 | NULL | |
220 | }; | |
221 | ||
e0d3bafd SD |
222 | /* ------------------------------------------------------------------ |
223 | Video buffer and parser functions | |
224 | ------------------------------------------------------------------*/ | |
225 | ||
226 | /* | |
227 | * Announces that a buffer were filled and request the next | |
228 | */ | |
229 | static inline void buffer_filled(struct cx231xx *dev, | |
84b5dbf3 MCC |
230 | struct cx231xx_dmaqueue *dma_q, |
231 | struct cx231xx_buffer *buf) | |
e0d3bafd SD |
232 | { |
233 | /* Advice that buffer was filled */ | |
234 | cx231xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); | |
235 | buf->vb.state = VIDEOBUF_DONE; | |
236 | buf->vb.field_count++; | |
237 | do_gettimeofday(&buf->vb.ts); | |
238 | ||
239 | dev->video_mode.isoc_ctl.buf = NULL; | |
240 | ||
241 | list_del(&buf->vb.queue); | |
242 | wake_up(&buf->vb.done); | |
243 | } | |
244 | ||
84b5dbf3 | 245 | static inline void print_err_status(struct cx231xx *dev, int packet, int status) |
e0d3bafd SD |
246 | { |
247 | char *errmsg = "Unknown"; | |
248 | ||
249 | switch (status) { | |
250 | case -ENOENT: | |
251 | errmsg = "unlinked synchronuously"; | |
252 | break; | |
253 | case -ECONNRESET: | |
254 | errmsg = "unlinked asynchronuously"; | |
255 | break; | |
256 | case -ENOSR: | |
257 | errmsg = "Buffer error (overrun)"; | |
258 | break; | |
259 | case -EPIPE: | |
260 | errmsg = "Stalled (device not responding)"; | |
261 | break; | |
262 | case -EOVERFLOW: | |
263 | errmsg = "Babble (bad cable?)"; | |
264 | break; | |
265 | case -EPROTO: | |
266 | errmsg = "Bit-stuff error (bad cable?)"; | |
267 | break; | |
268 | case -EILSEQ: | |
269 | errmsg = "CRC/Timeout (could be anything)"; | |
270 | break; | |
271 | case -ETIME: | |
272 | errmsg = "Device does not respond"; | |
273 | break; | |
274 | } | |
275 | if (packet < 0) { | |
84b5dbf3 | 276 | cx231xx_isocdbg("URB status %d [%s].\n", status, errmsg); |
e0d3bafd SD |
277 | } else { |
278 | cx231xx_isocdbg("URB packet %d, status %d [%s].\n", | |
84b5dbf3 | 279 | packet, status, errmsg); |
e0d3bafd SD |
280 | } |
281 | } | |
282 | ||
283 | /* | |
284 | * video-buf generic routine to get the next available buffer | |
285 | */ | |
286 | static inline void get_next_buf(struct cx231xx_dmaqueue *dma_q, | |
84b5dbf3 | 287 | struct cx231xx_buffer **buf) |
e0d3bafd | 288 | { |
84b5dbf3 MCC |
289 | struct cx231xx_video_mode *vmode = |
290 | container_of(dma_q, struct cx231xx_video_mode, vidq); | |
291 | struct cx231xx *dev = container_of(vmode, struct cx231xx, video_mode); | |
e0d3bafd SD |
292 | |
293 | char *outp; | |
294 | ||
e0d3bafd SD |
295 | if (list_empty(&dma_q->active)) { |
296 | cx231xx_isocdbg("No active queue to serve\n"); | |
297 | dev->video_mode.isoc_ctl.buf = NULL; | |
298 | *buf = NULL; | |
299 | return; | |
300 | } | |
301 | ||
302 | /* Get the next buffer */ | |
303 | *buf = list_entry(dma_q->active.next, struct cx231xx_buffer, vb.queue); | |
304 | ||
305 | /* Cleans up buffer - Usefull for testing for frame/URB loss */ | |
306 | outp = videobuf_to_vmalloc(&(*buf)->vb); | |
307 | memset(outp, 0, (*buf)->vb.size); | |
308 | ||
309 | dev->video_mode.isoc_ctl.buf = *buf; | |
310 | ||
311 | return; | |
312 | } | |
313 | ||
314 | /* | |
315 | * Controls the isoc copy of each urb packet | |
316 | */ | |
317 | static inline int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb) | |
318 | { | |
84b5dbf3 MCC |
319 | struct cx231xx_buffer *buf; |
320 | struct cx231xx_dmaqueue *dma_q = urb->context; | |
e0d3bafd | 321 | unsigned char *outp = NULL; |
84b5dbf3 | 322 | int i, rc = 1; |
e0d3bafd | 323 | unsigned char *p_buffer; |
84b5dbf3 MCC |
324 | u32 bytes_parsed = 0, buffer_size = 0; |
325 | u8 sav_eav = 0; | |
e0d3bafd SD |
326 | |
327 | if (!dev) | |
328 | return 0; | |
329 | ||
330 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) | |
331 | return 0; | |
332 | ||
333 | if (urb->status < 0) { | |
334 | print_err_status(dev, -1, urb->status); | |
335 | if (urb->status == -ENOENT) | |
336 | return 0; | |
337 | } | |
338 | ||
339 | buf = dev->video_mode.isoc_ctl.buf; | |
340 | if (buf != NULL) | |
341 | outp = videobuf_to_vmalloc(&buf->vb); | |
342 | ||
343 | for (i = 0; i < urb->number_of_packets; i++) { | |
344 | int status = urb->iso_frame_desc[i].status; | |
345 | ||
346 | if (status < 0) { | |
347 | print_err_status(dev, i, status); | |
348 | if (urb->iso_frame_desc[i].status != -EPROTO) | |
349 | continue; | |
350 | } | |
351 | ||
84b5dbf3 | 352 | if (urb->iso_frame_desc[i].actual_length <= 0) { |
e0d3bafd SD |
353 | /* cx231xx_isocdbg("packet %d is empty",i); - spammy */ |
354 | continue; | |
355 | } | |
356 | if (urb->iso_frame_desc[i].actual_length > | |
84b5dbf3 | 357 | dev->video_mode.max_pkt_size) { |
e0d3bafd SD |
358 | cx231xx_isocdbg("packet bigger than packet size"); |
359 | continue; | |
360 | } | |
361 | ||
84b5dbf3 | 362 | /* get buffer pointer and length */ |
e0d3bafd | 363 | p_buffer = urb->transfer_buffer + urb->iso_frame_desc[i].offset; |
84b5dbf3 MCC |
364 | buffer_size = urb->iso_frame_desc[i].actual_length; |
365 | bytes_parsed = 0; | |
366 | ||
367 | if (dma_q->is_partial_line) { | |
b9255176 | 368 | /* Handle the case of a partial line */ |
84b5dbf3 MCC |
369 | sav_eav = dma_q->last_sav; |
370 | } else { | |
b9255176 SD |
371 | /* Check for a SAV/EAV overlapping |
372 | the buffer boundary */ | |
84b5dbf3 MCC |
373 | sav_eav = |
374 | cx231xx_find_boundary_SAV_EAV(p_buffer, | |
375 | dma_q->partial_buf, | |
376 | &bytes_parsed); | |
377 | } | |
e0d3bafd | 378 | |
84b5dbf3 | 379 | sav_eav &= 0xF0; |
cde4362f MCC |
380 | /* Get the first line if we have some portion of an SAV/EAV from |
381 | the last buffer or a partial line */ | |
84b5dbf3 | 382 | if (sav_eav) { |
cde4362f | 383 | bytes_parsed += cx231xx_get_video_line(dev, dma_q, |
b9255176 SD |
384 | sav_eav, /* SAV/EAV */ |
385 | p_buffer + bytes_parsed, /* p_buffer */ | |
386 | buffer_size - bytes_parsed);/* buf size */ | |
84b5dbf3 | 387 | } |
e0d3bafd | 388 | |
84b5dbf3 MCC |
389 | /* Now parse data that is completely in this buffer */ |
390 | /* dma_q->is_partial_line = 0; */ | |
e0d3bafd | 391 | |
84b5dbf3 MCC |
392 | while (bytes_parsed < buffer_size) { |
393 | u32 bytes_used = 0; | |
e0d3bafd | 394 | |
b9255176 SD |
395 | sav_eav = cx231xx_find_next_SAV_EAV( |
396 | p_buffer + bytes_parsed, /* p_buffer */ | |
397 | buffer_size - bytes_parsed, /* buf size */ | |
398 | &bytes_used);/* bytes used to get SAV/EAV */ | |
e0d3bafd | 399 | |
84b5dbf3 | 400 | bytes_parsed += bytes_used; |
e0d3bafd | 401 | |
84b5dbf3 MCC |
402 | sav_eav &= 0xF0; |
403 | if (sav_eav && (bytes_parsed < buffer_size)) { | |
cde4362f | 404 | bytes_parsed += cx231xx_get_video_line(dev, |
b9255176 SD |
405 | dma_q, sav_eav, /* SAV/EAV */ |
406 | p_buffer + bytes_parsed,/* p_buffer */ | |
407 | buffer_size - bytes_parsed);/*buf size*/ | |
84b5dbf3 MCC |
408 | } |
409 | } | |
e0d3bafd | 410 | |
cde4362f MCC |
411 | /* Save the last four bytes of the buffer so we can check the |
412 | buffer boundary condition next time */ | |
84b5dbf3 MCC |
413 | memcpy(dma_q->partial_buf, p_buffer + buffer_size - 4, 4); |
414 | bytes_parsed = 0; | |
e0d3bafd | 415 | |
84b5dbf3 MCC |
416 | } |
417 | return rc; | |
e0d3bafd SD |
418 | } |
419 | ||
cde4362f MCC |
420 | u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf, |
421 | u32 *p_bytes_used) | |
e0d3bafd | 422 | { |
84b5dbf3 MCC |
423 | u32 bytes_used; |
424 | u8 boundary_bytes[8]; | |
425 | u8 sav_eav = 0; | |
426 | ||
427 | *p_bytes_used = 0; | |
e0d3bafd | 428 | |
84b5dbf3 MCC |
429 | /* Create an array of the last 4 bytes of the last buffer and the first |
430 | 4 bytes of the current buffer. */ | |
e0d3bafd | 431 | |
84b5dbf3 MCC |
432 | memcpy(boundary_bytes, partial_buf, 4); |
433 | memcpy(boundary_bytes + 4, p_buffer, 4); | |
e0d3bafd | 434 | |
84b5dbf3 | 435 | /* Check for the SAV/EAV in the boundary buffer */ |
cde4362f MCC |
436 | sav_eav = cx231xx_find_next_SAV_EAV((u8 *)&boundary_bytes, 8, |
437 | &bytes_used); | |
e0d3bafd | 438 | |
84b5dbf3 MCC |
439 | if (sav_eav) { |
440 | /* found a boundary SAV/EAV. Updates the bytes used to reflect | |
441 | only those used in the new buffer */ | |
442 | *p_bytes_used = bytes_used - 4; | |
443 | } | |
e0d3bafd | 444 | |
84b5dbf3 | 445 | return sav_eav; |
e0d3bafd SD |
446 | } |
447 | ||
cde4362f | 448 | u8 cx231xx_find_next_SAV_EAV(u8 *p_buffer, u32 buffer_size, u32 *p_bytes_used) |
84b5dbf3 MCC |
449 | { |
450 | u32 i; | |
451 | u8 sav_eav = 0; | |
e0d3bafd | 452 | |
cde4362f MCC |
453 | /* |
454 | * Don't search if the buffer size is less than 4. It causes a page | |
455 | * fault since buffer_size - 4 evaluates to a large number in that | |
456 | * case. | |
457 | */ | |
84b5dbf3 MCC |
458 | if (buffer_size < 4) { |
459 | *p_bytes_used = buffer_size; | |
460 | return 0; | |
461 | } | |
e0d3bafd | 462 | |
84b5dbf3 | 463 | for (i = 0; i < (buffer_size - 3); i++) { |
e0d3bafd | 464 | |
84b5dbf3 MCC |
465 | if ((p_buffer[i] == 0xFF) && |
466 | (p_buffer[i + 1] == 0x00) && (p_buffer[i + 2] == 0x00)) { | |
e0d3bafd | 467 | |
84b5dbf3 MCC |
468 | *p_bytes_used = i + 4; |
469 | sav_eav = p_buffer[i + 3]; | |
470 | return sav_eav; | |
471 | } | |
472 | } | |
e0d3bafd | 473 | |
84b5dbf3 MCC |
474 | *p_bytes_used = buffer_size; |
475 | return 0; | |
476 | } | |
e0d3bafd | 477 | |
cde4362f MCC |
478 | u32 cx231xx_get_video_line(struct cx231xx *dev, |
479 | struct cx231xx_dmaqueue *dma_q, u8 sav_eav, | |
480 | u8 *p_buffer, u32 buffer_size) | |
84b5dbf3 MCC |
481 | { |
482 | u32 bytes_copied = 0; | |
483 | int current_field = -1; | |
484 | ||
485 | switch (sav_eav) { | |
486 | case SAV_ACTIVE_VIDEO_FIELD1: | |
cde4362f MCC |
487 | /* looking for skipped line which occurred in PAL 720x480 mode. |
488 | In this case, there will be no active data contained | |
489 | between the SAV and EAV */ | |
490 | if ((buffer_size > 3) && (p_buffer[0] == 0xFF) && | |
491 | (p_buffer[1] == 0x00) && (p_buffer[2] == 0x00) && | |
492 | ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1) || | |
493 | (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2) || | |
494 | (p_buffer[3] == EAV_VBLANK_FIELD1) || | |
495 | (p_buffer[3] == EAV_VBLANK_FIELD2))) | |
84b5dbf3 | 496 | return bytes_copied; |
84b5dbf3 MCC |
497 | current_field = 1; |
498 | break; | |
e0d3bafd | 499 | |
84b5dbf3 | 500 | case SAV_ACTIVE_VIDEO_FIELD2: |
cde4362f MCC |
501 | /* looking for skipped line which occurred in PAL 720x480 mode. |
502 | In this case, there will be no active data contained between | |
503 | the SAV and EAV */ | |
504 | if ((buffer_size > 3) && (p_buffer[0] == 0xFF) && | |
505 | (p_buffer[1] == 0x00) && (p_buffer[2] == 0x00) && | |
506 | ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1) || | |
507 | (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2) || | |
508 | (p_buffer[3] == EAV_VBLANK_FIELD1) || | |
509 | (p_buffer[3] == EAV_VBLANK_FIELD2))) | |
84b5dbf3 | 510 | return bytes_copied; |
84b5dbf3 MCC |
511 | current_field = 2; |
512 | break; | |
513 | } | |
e0d3bafd | 514 | |
84b5dbf3 | 515 | dma_q->last_sav = sav_eav; |
e0d3bafd | 516 | |
cde4362f MCC |
517 | bytes_copied = cx231xx_copy_video_line(dev, dma_q, p_buffer, |
518 | buffer_size, current_field); | |
84b5dbf3 MCC |
519 | |
520 | return bytes_copied; | |
e0d3bafd SD |
521 | } |
522 | ||
cde4362f MCC |
523 | u32 cx231xx_copy_video_line(struct cx231xx *dev, |
524 | struct cx231xx_dmaqueue *dma_q, u8 *p_line, | |
84b5dbf3 | 525 | u32 length, int field_number) |
e0d3bafd | 526 | { |
84b5dbf3 MCC |
527 | u32 bytes_to_copy; |
528 | struct cx231xx_buffer *buf; | |
529 | u32 _line_size = dev->width * 2; | |
e0d3bafd | 530 | |
cde4362f | 531 | if (dma_q->current_field != field_number) |
84b5dbf3 | 532 | cx231xx_reset_video_buffer(dev, dma_q); |
e0d3bafd | 533 | |
84b5dbf3 MCC |
534 | /* get the buffer pointer */ |
535 | buf = dev->video_mode.isoc_ctl.buf; | |
e0d3bafd | 536 | |
84b5dbf3 MCC |
537 | /* Remember the field number for next time */ |
538 | dma_q->current_field = field_number; | |
e0d3bafd | 539 | |
84b5dbf3 MCC |
540 | bytes_to_copy = dma_q->bytes_left_in_line; |
541 | if (bytes_to_copy > length) | |
542 | bytes_to_copy = length; | |
e0d3bafd | 543 | |
84b5dbf3 MCC |
544 | if (dma_q->lines_completed >= dma_q->lines_per_field) { |
545 | dma_q->bytes_left_in_line -= bytes_to_copy; | |
cde4362f MCC |
546 | dma_q->is_partial_line = (dma_q->bytes_left_in_line == 0) ? |
547 | 0 : 1; | |
84b5dbf3 MCC |
548 | return 0; |
549 | } | |
e0d3bafd | 550 | |
84b5dbf3 | 551 | dma_q->is_partial_line = 1; |
e0d3bafd | 552 | |
84b5dbf3 MCC |
553 | /* If we don't have a buffer, just return the number of bytes we would |
554 | have copied if we had a buffer. */ | |
555 | if (!buf) { | |
556 | dma_q->bytes_left_in_line -= bytes_to_copy; | |
cde4362f MCC |
557 | dma_q->is_partial_line = (dma_q->bytes_left_in_line == 0) |
558 | ? 0 : 1; | |
84b5dbf3 MCC |
559 | return bytes_to_copy; |
560 | } | |
e0d3bafd | 561 | |
84b5dbf3 MCC |
562 | /* copy the data to video buffer */ |
563 | cx231xx_do_copy(dev, dma_q, p_line, bytes_to_copy); | |
e0d3bafd | 564 | |
84b5dbf3 MCC |
565 | dma_q->pos += bytes_to_copy; |
566 | dma_q->bytes_left_in_line -= bytes_to_copy; | |
e0d3bafd | 567 | |
84b5dbf3 | 568 | if (dma_q->bytes_left_in_line == 0) { |
84b5dbf3 MCC |
569 | dma_q->bytes_left_in_line = _line_size; |
570 | dma_q->lines_completed++; | |
571 | dma_q->is_partial_line = 0; | |
e0d3bafd | 572 | |
84b5dbf3 | 573 | if (cx231xx_is_buffer_done(dev, dma_q) && buf) { |
84b5dbf3 | 574 | buffer_filled(dev, dma_q, buf); |
e0d3bafd | 575 | |
84b5dbf3 MCC |
576 | dma_q->pos = 0; |
577 | buf = NULL; | |
578 | dma_q->lines_completed = 0; | |
579 | } | |
580 | } | |
e0d3bafd | 581 | |
84b5dbf3 | 582 | return bytes_to_copy; |
e0d3bafd SD |
583 | } |
584 | ||
84b5dbf3 MCC |
585 | void cx231xx_reset_video_buffer(struct cx231xx *dev, |
586 | struct cx231xx_dmaqueue *dma_q) | |
e0d3bafd | 587 | { |
84b5dbf3 | 588 | struct cx231xx_buffer *buf; |
e0d3bafd | 589 | |
84b5dbf3 MCC |
590 | /* handle the switch from field 1 to field 2 */ |
591 | if (dma_q->current_field == 1) { | |
cde4362f | 592 | if (dma_q->lines_completed >= dma_q->lines_per_field) |
84b5dbf3 | 593 | dma_q->field1_done = 1; |
cde4362f | 594 | else |
84b5dbf3 | 595 | dma_q->field1_done = 0; |
84b5dbf3 | 596 | } |
e0d3bafd | 597 | |
84b5dbf3 | 598 | buf = dev->video_mode.isoc_ctl.buf; |
e0d3bafd | 599 | |
84b5dbf3 MCC |
600 | if (buf == NULL) { |
601 | u8 *outp = NULL; | |
602 | /* first try to get the buffer */ | |
603 | get_next_buf(dma_q, &buf); | |
e0d3bafd | 604 | |
84b5dbf3 MCC |
605 | if (buf) |
606 | outp = videobuf_to_vmalloc(&buf->vb); | |
e0d3bafd | 607 | |
84b5dbf3 MCC |
608 | dma_q->pos = 0; |
609 | dma_q->field1_done = 0; | |
610 | dma_q->current_field = -1; | |
611 | } | |
e0d3bafd | 612 | |
84b5dbf3 MCC |
613 | /* reset the counters */ |
614 | dma_q->bytes_left_in_line = dev->width << 1; | |
615 | dma_q->lines_completed = 0; | |
e0d3bafd SD |
616 | } |
617 | ||
618 | int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, | |
cde4362f | 619 | u8 *p_buffer, u32 bytes_to_copy) |
e0d3bafd | 620 | { |
84b5dbf3 MCC |
621 | u8 *p_out_buffer = NULL; |
622 | u32 current_line_bytes_copied = 0; | |
623 | struct cx231xx_buffer *buf; | |
624 | u32 _line_size = dev->width << 1; | |
625 | void *startwrite; | |
626 | int offset, lencopy; | |
e0d3bafd | 627 | |
84b5dbf3 | 628 | buf = dev->video_mode.isoc_ctl.buf; |
e0d3bafd | 629 | |
84b5dbf3 MCC |
630 | if (buf == NULL) |
631 | return -1; | |
e0d3bafd SD |
632 | |
633 | p_out_buffer = videobuf_to_vmalloc(&buf->vb); | |
634 | ||
84b5dbf3 | 635 | current_line_bytes_copied = _line_size - dma_q->bytes_left_in_line; |
e0d3bafd | 636 | |
84b5dbf3 MCC |
637 | /* Offset field 2 one line from the top of the buffer */ |
638 | offset = (dma_q->current_field == 1) ? 0 : _line_size; | |
e0d3bafd | 639 | |
84b5dbf3 MCC |
640 | /* Offset for field 2 */ |
641 | startwrite = p_out_buffer + offset; | |
e0d3bafd | 642 | |
84b5dbf3 MCC |
643 | /* lines already completed in the current field */ |
644 | startwrite += (dma_q->lines_completed * _line_size * 2); | |
e0d3bafd | 645 | |
84b5dbf3 MCC |
646 | /* bytes already completed in the current line */ |
647 | startwrite += current_line_bytes_copied; | |
e0d3bafd | 648 | |
cde4362f MCC |
649 | lencopy = dma_q->bytes_left_in_line > bytes_to_copy ? |
650 | bytes_to_copy : dma_q->bytes_left_in_line; | |
e0d3bafd | 651 | |
cde4362f | 652 | if ((u8 *)(startwrite + lencopy) > (u8 *)(p_out_buffer + buf->vb.size)) |
84b5dbf3 | 653 | return 0; |
e0d3bafd | 654 | |
84b5dbf3 MCC |
655 | /* The below copies the UYVY data straight into video buffer */ |
656 | cx231xx_swab((u16 *) p_buffer, (u16 *) startwrite, (u16) lencopy); | |
e0d3bafd | 657 | |
84b5dbf3 | 658 | return 0; |
e0d3bafd SD |
659 | } |
660 | ||
cde4362f | 661 | void cx231xx_swab(u16 *from, u16 *to, u16 len) |
e0d3bafd | 662 | { |
84b5dbf3 | 663 | u16 i; |
e0d3bafd | 664 | |
84b5dbf3 MCC |
665 | if (len <= 0) |
666 | return; | |
e0d3bafd | 667 | |
cde4362f | 668 | for (i = 0; i < len / 2; i++) |
84b5dbf3 | 669 | to[i] = (from[i] << 8) | (from[i] >> 8); |
e0d3bafd SD |
670 | } |
671 | ||
84b5dbf3 | 672 | u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q) |
e0d3bafd | 673 | { |
84b5dbf3 | 674 | u8 buffer_complete = 0; |
e0d3bafd | 675 | |
84b5dbf3 | 676 | /* Dual field stream */ |
cde4362f MCC |
677 | buffer_complete = ((dma_q->current_field == 2) && |
678 | (dma_q->lines_completed >= dma_q->lines_per_field) && | |
679 | dma_q->field1_done); | |
e0d3bafd | 680 | |
84b5dbf3 | 681 | return buffer_complete; |
e0d3bafd SD |
682 | } |
683 | ||
e0d3bafd SD |
684 | /* ------------------------------------------------------------------ |
685 | Videobuf operations | |
686 | ------------------------------------------------------------------*/ | |
687 | ||
688 | static int | |
689 | buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) | |
690 | { | |
691 | struct cx231xx_fh *fh = vq->priv_data; | |
84b5dbf3 | 692 | struct cx231xx *dev = fh->dev; |
e0d3bafd SD |
693 | struct v4l2_frequency f; |
694 | ||
cde4362f | 695 | *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7)>>3; |
e0d3bafd SD |
696 | if (0 == *count) |
697 | *count = CX231XX_DEF_BUF; | |
698 | ||
699 | if (*count < CX231XX_MIN_BUF) | |
700 | *count = CX231XX_MIN_BUF; | |
701 | ||
702 | /* Ask tuner to go to analog mode */ | |
703 | memset(&f, 0, sizeof(f)); | |
704 | f.frequency = dev->ctl_freq; | |
84b5dbf3 | 705 | f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
e0d3bafd SD |
706 | |
707 | cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, &f); | |
708 | ||
709 | return 0; | |
710 | } | |
711 | ||
712 | /* This is called *without* dev->slock held; please keep it that way */ | |
713 | static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf) | |
714 | { | |
84b5dbf3 MCC |
715 | struct cx231xx_fh *fh = vq->priv_data; |
716 | struct cx231xx *dev = fh->dev; | |
e0d3bafd | 717 | unsigned long flags = 0; |
cde4362f | 718 | |
e0d3bafd SD |
719 | if (in_interrupt()) |
720 | BUG(); | |
721 | ||
722 | /* We used to wait for the buffer to finish here, but this didn't work | |
723 | because, as we were keeping the state as VIDEOBUF_QUEUED, | |
724 | videobuf_queue_cancel marked it as finished for us. | |
725 | (Also, it could wedge forever if the hardware was misconfigured.) | |
726 | ||
727 | This should be safe; by the time we get here, the buffer isn't | |
728 | queued anymore. If we ever start marking the buffers as | |
729 | VIDEOBUF_ACTIVE, it won't be, though. | |
84b5dbf3 | 730 | */ |
e0d3bafd SD |
731 | spin_lock_irqsave(&dev->video_mode.slock, flags); |
732 | if (dev->video_mode.isoc_ctl.buf == buf) | |
733 | dev->video_mode.isoc_ctl.buf = NULL; | |
734 | spin_unlock_irqrestore(&dev->video_mode.slock, flags); | |
735 | ||
736 | videobuf_vmalloc_free(&buf->vb); | |
737 | buf->vb.state = VIDEOBUF_NEEDS_INIT; | |
738 | } | |
739 | ||
740 | static int | |
741 | buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, | |
84b5dbf3 | 742 | enum v4l2_field field) |
e0d3bafd | 743 | { |
84b5dbf3 MCC |
744 | struct cx231xx_fh *fh = vq->priv_data; |
745 | struct cx231xx_buffer *buf = | |
746 | container_of(vb, struct cx231xx_buffer, vb); | |
747 | struct cx231xx *dev = fh->dev; | |
748 | int rc = 0, urb_init = 0; | |
e0d3bafd SD |
749 | |
750 | /* The only currently supported format is 16 bits/pixel */ | |
cde4362f MCC |
751 | buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth |
752 | + 7) >> 3; | |
84b5dbf3 | 753 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
e0d3bafd SD |
754 | return -EINVAL; |
755 | ||
84b5dbf3 | 756 | buf->vb.width = dev->width; |
e0d3bafd | 757 | buf->vb.height = dev->height; |
84b5dbf3 | 758 | buf->vb.field = field; |
e0d3bafd SD |
759 | |
760 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { | |
761 | rc = videobuf_iolock(vq, &buf->vb, NULL); | |
762 | if (rc < 0) | |
763 | goto fail; | |
764 | } | |
765 | ||
766 | if (!dev->video_mode.isoc_ctl.num_bufs) | |
767 | urb_init = 1; | |
768 | ||
769 | if (urb_init) { | |
770 | rc = cx231xx_init_isoc(dev, CX231XX_NUM_PACKETS, | |
84b5dbf3 MCC |
771 | CX231XX_NUM_BUFS, |
772 | dev->video_mode.max_pkt_size, | |
773 | cx231xx_isoc_copy); | |
e0d3bafd SD |
774 | if (rc < 0) |
775 | goto fail; | |
776 | } | |
777 | ||
778 | buf->vb.state = VIDEOBUF_PREPARED; | |
779 | return 0; | |
780 | ||
cde4362f | 781 | fail: |
e0d3bafd SD |
782 | free_buffer(vq, buf); |
783 | return rc; | |
784 | } | |
785 | ||
84b5dbf3 | 786 | static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
e0d3bafd | 787 | { |
84b5dbf3 MCC |
788 | struct cx231xx_buffer *buf = |
789 | container_of(vb, struct cx231xx_buffer, vb); | |
790 | struct cx231xx_fh *fh = vq->priv_data; | |
791 | struct cx231xx *dev = fh->dev; | |
792 | struct cx231xx_dmaqueue *vidq = &dev->video_mode.vidq; | |
e0d3bafd SD |
793 | |
794 | buf->vb.state = VIDEOBUF_QUEUED; | |
795 | list_add_tail(&buf->vb.queue, &vidq->active); | |
796 | ||
797 | } | |
798 | ||
799 | static void buffer_release(struct videobuf_queue *vq, | |
84b5dbf3 | 800 | struct videobuf_buffer *vb) |
e0d3bafd | 801 | { |
84b5dbf3 MCC |
802 | struct cx231xx_buffer *buf = |
803 | container_of(vb, struct cx231xx_buffer, vb); | |
804 | struct cx231xx_fh *fh = vq->priv_data; | |
805 | struct cx231xx *dev = (struct cx231xx *)fh->dev; | |
e0d3bafd SD |
806 | |
807 | cx231xx_isocdbg("cx231xx: called buffer_release\n"); | |
808 | ||
809 | free_buffer(vq, buf); | |
810 | } | |
811 | ||
812 | static struct videobuf_queue_ops cx231xx_video_qops = { | |
84b5dbf3 MCC |
813 | .buf_setup = buffer_setup, |
814 | .buf_prepare = buffer_prepare, | |
815 | .buf_queue = buffer_queue, | |
816 | .buf_release = buffer_release, | |
e0d3bafd SD |
817 | }; |
818 | ||
819 | /********************* v4l2 interface **************************************/ | |
820 | ||
e0d3bafd SD |
821 | void video_mux(struct cx231xx *dev, int index) |
822 | { | |
823 | ||
824 | struct v4l2_routing route; | |
825 | ||
826 | route.input = INPUT(index)->vmux; | |
827 | route.output = 0; | |
828 | dev->video_input = index; | |
829 | dev->ctl_ainput = INPUT(index)->amux; | |
830 | ||
84b5dbf3 | 831 | cx231xx_set_video_input_mux(dev, index); |
e0d3bafd | 832 | |
84b5dbf3 MCC |
833 | cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_INT_S_VIDEO_ROUTING, |
834 | &route); | |
e0d3bafd | 835 | |
84b5dbf3 | 836 | cx231xx_set_audio_input(dev, dev->ctl_ainput); |
e0d3bafd | 837 | |
84b5dbf3 | 838 | cx231xx_info("video_mux : %d\n", index); |
e0d3bafd | 839 | |
84b5dbf3 MCC |
840 | /* do mode control overrides if required */ |
841 | cx231xx_do_mode_ctrl_overrides(dev); | |
e0d3bafd SD |
842 | } |
843 | ||
844 | /* Usage lock check functions */ | |
845 | static int res_get(struct cx231xx_fh *fh) | |
846 | { | |
84b5dbf3 MCC |
847 | struct cx231xx *dev = fh->dev; |
848 | int rc = 0; | |
e0d3bafd SD |
849 | |
850 | /* This instance already has stream_on */ | |
851 | if (fh->stream_on) | |
852 | return rc; | |
853 | ||
84b5dbf3 MCC |
854 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
855 | if (dev->stream_on) | |
856 | return -EBUSY; | |
857 | dev->stream_on = 1; | |
858 | } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { | |
859 | if (dev->vbi_stream_on) | |
860 | return -EBUSY; | |
861 | dev->vbi_stream_on = 1; | |
862 | } else | |
863 | return -EINVAL; | |
e0d3bafd | 864 | |
84b5dbf3 | 865 | fh->stream_on = 1; |
e0d3bafd SD |
866 | |
867 | return rc; | |
868 | } | |
869 | ||
870 | static int res_check(struct cx231xx_fh *fh) | |
871 | { | |
cde4362f | 872 | return fh->stream_on; |
e0d3bafd SD |
873 | } |
874 | ||
875 | static void res_free(struct cx231xx_fh *fh) | |
876 | { | |
84b5dbf3 | 877 | struct cx231xx *dev = fh->dev; |
e0d3bafd SD |
878 | |
879 | fh->stream_on = 0; | |
880 | ||
84b5dbf3 MCC |
881 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
882 | dev->stream_on = 0; | |
883 | if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) | |
884 | dev->vbi_stream_on = 0; | |
e0d3bafd SD |
885 | } |
886 | ||
887 | static int check_dev(struct cx231xx *dev) | |
888 | { | |
889 | if (dev->state & DEV_DISCONNECTED) { | |
890 | cx231xx_errdev("v4l2 ioctl: device not present\n"); | |
891 | return -ENODEV; | |
892 | } | |
893 | ||
894 | if (dev->state & DEV_MISCONFIGURED) { | |
895 | cx231xx_errdev("v4l2 ioctl: device is misconfigured; " | |
84b5dbf3 | 896 | "close and open it again\n"); |
e0d3bafd SD |
897 | return -EIO; |
898 | } | |
899 | return 0; | |
900 | } | |
901 | ||
902 | void get_scale(struct cx231xx *dev, | |
84b5dbf3 MCC |
903 | unsigned int width, unsigned int height, |
904 | unsigned int *hscale, unsigned int *vscale) | |
e0d3bafd | 905 | { |
84b5dbf3 MCC |
906 | unsigned int maxw = norm_maxw(dev); |
907 | unsigned int maxh = norm_maxh(dev); | |
e0d3bafd SD |
908 | |
909 | *hscale = (((unsigned long)maxw) << 12) / width - 4096L; | |
910 | if (*hscale >= 0x4000) | |
911 | *hscale = 0x3fff; | |
912 | ||
913 | *vscale = (((unsigned long)maxh) << 12) / height - 4096L; | |
914 | if (*vscale >= 0x4000) | |
915 | *vscale = 0x3fff; | |
916 | ||
84b5dbf3 MCC |
917 | dev->hscale = *hscale; |
918 | dev->vscale = *vscale; | |
e0d3bafd SD |
919 | |
920 | } | |
921 | ||
922 | /* ------------------------------------------------------------------ | |
923 | IOCTL vidioc handling | |
924 | ------------------------------------------------------------------*/ | |
925 | ||
926 | static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, | |
84b5dbf3 | 927 | struct v4l2_format *f) |
e0d3bafd | 928 | { |
84b5dbf3 MCC |
929 | struct cx231xx_fh *fh = priv; |
930 | struct cx231xx *dev = fh->dev; | |
e0d3bafd SD |
931 | |
932 | mutex_lock(&dev->lock); | |
933 | ||
934 | f->fmt.pix.width = dev->width; | |
935 | f->fmt.pix.height = dev->height; | |
936 | f->fmt.pix.pixelformat = dev->format->fourcc;; | |
937 | f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;; | |
84b5dbf3 | 938 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height; |
e0d3bafd SD |
939 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
940 | ||
941 | f->fmt.pix.field = V4L2_FIELD_INTERLACED; | |
942 | ||
943 | mutex_unlock(&dev->lock); | |
cde4362f | 944 | |
e0d3bafd SD |
945 | return 0; |
946 | } | |
947 | ||
948 | static struct cx231xx_fmt *format_by_fourcc(unsigned int fourcc) | |
949 | { | |
950 | unsigned int i; | |
951 | ||
952 | for (i = 0; i < ARRAY_SIZE(format); i++) | |
953 | if (format[i].fourcc == fourcc) | |
954 | return &format[i]; | |
955 | ||
956 | return NULL; | |
957 | } | |
958 | ||
959 | static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, | |
84b5dbf3 | 960 | struct v4l2_format *f) |
e0d3bafd | 961 | { |
84b5dbf3 MCC |
962 | struct cx231xx_fh *fh = priv; |
963 | struct cx231xx *dev = fh->dev; | |
964 | int width = f->fmt.pix.width; | |
965 | int height = f->fmt.pix.height; | |
966 | unsigned int maxw = norm_maxw(dev); | |
967 | unsigned int maxh = norm_maxh(dev); | |
968 | unsigned int hscale, vscale; | |
969 | struct cx231xx_fmt *fmt; | |
e0d3bafd SD |
970 | |
971 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); | |
972 | if (!fmt) { | |
973 | cx231xx_videodbg("Fourcc format (%08x) invalid.\n", | |
84b5dbf3 | 974 | f->fmt.pix.pixelformat); |
e0d3bafd SD |
975 | return -EINVAL; |
976 | } | |
977 | ||
978 | /* width must even because of the YUYV format | |
979 | height must be even because of interlacing */ | |
980 | height &= 0xfffe; | |
981 | width &= 0xfffe; | |
982 | ||
983 | if (unlikely(height < 32)) | |
984 | height = 32; | |
985 | if (unlikely(height > maxh)) | |
986 | height = maxh; | |
987 | if (unlikely(width < 48)) | |
988 | width = 48; | |
989 | if (unlikely(width > maxw)) | |
990 | width = maxw; | |
991 | ||
992 | get_scale(dev, width, height, &hscale, &vscale); | |
993 | ||
994 | width = (((unsigned long)maxw) << 12) / (hscale + 4096L); | |
995 | height = (((unsigned long)maxh) << 12) / (vscale + 4096L); | |
996 | ||
997 | f->fmt.pix.width = width; | |
998 | f->fmt.pix.height = height; | |
999 | f->fmt.pix.pixelformat = fmt->fourcc; | |
1000 | f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3; | |
1001 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height; | |
1002 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; | |
1003 | f->fmt.pix.field = V4L2_FIELD_INTERLACED; | |
1004 | ||
1005 | return 0; | |
1006 | } | |
1007 | ||
1008 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, | |
84b5dbf3 | 1009 | struct v4l2_format *f) |
e0d3bafd | 1010 | { |
84b5dbf3 MCC |
1011 | struct cx231xx_fh *fh = priv; |
1012 | struct cx231xx *dev = fh->dev; | |
1013 | int rc; | |
1014 | struct cx231xx_fmt *fmt; | |
e0d3bafd SD |
1015 | |
1016 | rc = check_dev(dev); | |
1017 | if (rc < 0) | |
1018 | return rc; | |
1019 | ||
e0d3bafd SD |
1020 | mutex_lock(&dev->lock); |
1021 | ||
84b5dbf3 | 1022 | vidioc_try_fmt_vid_cap(file, priv, f); |
e0d3bafd | 1023 | |
84b5dbf3 | 1024 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
e0d3bafd SD |
1025 | if (!fmt) { |
1026 | rc = -EINVAL; | |
1027 | goto out; | |
1028 | } | |
1029 | ||
1030 | if (videobuf_queue_is_busy(&fh->vb_vidq)) { | |
1031 | cx231xx_errdev("%s queue busy\n", __func__); | |
1032 | rc = -EBUSY; | |
1033 | goto out; | |
1034 | } | |
1035 | ||
1036 | if (dev->stream_on && !fh->stream_on) { | |
1037 | cx231xx_errdev("%s device in use by another fh\n", __func__); | |
1038 | rc = -EBUSY; | |
1039 | goto out; | |
1040 | } | |
1041 | ||
1042 | /* set new image size */ | |
1043 | dev->width = f->fmt.pix.width; | |
1044 | dev->height = f->fmt.pix.height; | |
84b5dbf3 | 1045 | dev->format = fmt; |
e0d3bafd SD |
1046 | get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); |
1047 | ||
84b5dbf3 | 1048 | cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_S_FMT, f); |
e0d3bafd | 1049 | |
84b5dbf3 | 1050 | /* Set the correct alternate setting for this resolution */ |
e0d3bafd SD |
1051 | cx231xx_resolution_set(dev); |
1052 | ||
cde4362f | 1053 | out: |
e0d3bafd SD |
1054 | mutex_unlock(&dev->lock); |
1055 | return rc; | |
1056 | } | |
1057 | ||
84b5dbf3 | 1058 | static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id * id) |
e0d3bafd | 1059 | { |
84b5dbf3 MCC |
1060 | struct cx231xx_fh *fh = priv; |
1061 | struct cx231xx *dev = fh->dev; | |
e0d3bafd SD |
1062 | |
1063 | *id = dev->norm; | |
1064 | return 0; | |
1065 | } | |
1066 | ||
1067 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm) | |
1068 | { | |
84b5dbf3 MCC |
1069 | struct cx231xx_fh *fh = priv; |
1070 | struct cx231xx *dev = fh->dev; | |
e0d3bafd | 1071 | struct v4l2_format f; |
84b5dbf3 | 1072 | int rc; |
e0d3bafd SD |
1073 | |
1074 | rc = check_dev(dev); | |
1075 | if (rc < 0) | |
1076 | return rc; | |
1077 | ||
84b5dbf3 | 1078 | cx231xx_info("vidioc_s_std : 0x%x\n", (unsigned int)*norm); |
e0d3bafd SD |
1079 | |
1080 | mutex_lock(&dev->lock); | |
1081 | dev->norm = *norm; | |
1082 | ||
e0d3bafd SD |
1083 | /* Adjusts width/height, if needed */ |
1084 | f.fmt.pix.width = dev->width; | |
1085 | f.fmt.pix.height = dev->height; | |
1086 | vidioc_try_fmt_vid_cap(file, priv, &f); | |
1087 | ||
1088 | /* set new image size */ | |
1089 | dev->width = f.fmt.pix.width; | |
1090 | dev->height = f.fmt.pix.height; | |
1091 | get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); | |
1092 | ||
1093 | cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_S_STD, &dev->norm); | |
1094 | ||
1095 | mutex_unlock(&dev->lock); | |
1096 | ||
84b5dbf3 | 1097 | cx231xx_resolution_set(dev); |
e0d3bafd | 1098 | |
84b5dbf3 MCC |
1099 | /* do mode control overrides */ |
1100 | cx231xx_do_mode_ctrl_overrides(dev); | |
e0d3bafd SD |
1101 | |
1102 | return 0; | |
1103 | } | |
1104 | ||
1105 | static const char *iname[] = { | |
1106 | [CX231XX_VMUX_COMPOSITE1] = "Composite1", | |
cde4362f | 1107 | [CX231XX_VMUX_SVIDEO] = "S-Video", |
e0d3bafd | 1108 | [CX231XX_VMUX_TELEVISION] = "Television", |
cde4362f MCC |
1109 | [CX231XX_VMUX_CABLE] = "Cable TV", |
1110 | [CX231XX_VMUX_DVB] = "DVB", | |
1111 | [CX231XX_VMUX_DEBUG] = "for debug only", | |
e0d3bafd SD |
1112 | }; |
1113 | ||
1114 | static int vidioc_enum_input(struct file *file, void *priv, | |
84b5dbf3 | 1115 | struct v4l2_input *i) |
e0d3bafd | 1116 | { |
84b5dbf3 MCC |
1117 | struct cx231xx_fh *fh = priv; |
1118 | struct cx231xx *dev = fh->dev; | |
1119 | unsigned int n; | |
e0d3bafd SD |
1120 | |
1121 | n = i->index; | |
1122 | if (n >= MAX_CX231XX_INPUT) | |
1123 | return -EINVAL; | |
1124 | if (0 == INPUT(n)->type) | |
1125 | return -EINVAL; | |
1126 | ||
1127 | i->index = n; | |
1128 | i->type = V4L2_INPUT_TYPE_CAMERA; | |
1129 | ||
1130 | strcpy(i->name, iname[INPUT(n)->type]); | |
1131 | ||
1132 | if ((CX231XX_VMUX_TELEVISION == INPUT(n)->type) || | |
84b5dbf3 | 1133 | (CX231XX_VMUX_CABLE == INPUT(n)->type)) |
e0d3bafd SD |
1134 | i->type = V4L2_INPUT_TYPE_TUNER; |
1135 | ||
1136 | i->std = dev->vdev->tvnorms; | |
1137 | ||
1138 | return 0; | |
1139 | } | |
1140 | ||
1141 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) | |
1142 | { | |
84b5dbf3 MCC |
1143 | struct cx231xx_fh *fh = priv; |
1144 | struct cx231xx *dev = fh->dev; | |
e0d3bafd SD |
1145 | |
1146 | *i = dev->video_input; | |
1147 | ||
1148 | return 0; | |
1149 | } | |
1150 | ||
1151 | static int vidioc_s_input(struct file *file, void *priv, unsigned int i) | |
1152 | { | |
84b5dbf3 MCC |
1153 | struct cx231xx_fh *fh = priv; |
1154 | struct cx231xx *dev = fh->dev; | |
1155 | int rc; | |
e0d3bafd SD |
1156 | |
1157 | rc = check_dev(dev); | |
1158 | if (rc < 0) | |
1159 | return rc; | |
1160 | ||
1161 | if (i >= MAX_CX231XX_INPUT) | |
1162 | return -EINVAL; | |
1163 | if (0 == INPUT(i)->type) | |
1164 | return -EINVAL; | |
1165 | ||
1166 | mutex_lock(&dev->lock); | |
1167 | ||
1168 | video_mux(dev, i); | |
1169 | ||
1170 | mutex_unlock(&dev->lock); | |
1171 | return 0; | |
1172 | } | |
1173 | ||
1174 | static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) | |
1175 | { | |
84b5dbf3 MCC |
1176 | struct cx231xx_fh *fh = priv; |
1177 | struct cx231xx *dev = fh->dev; | |
e0d3bafd SD |
1178 | |
1179 | switch (a->index) { | |
1180 | case CX231XX_AMUX_VIDEO: | |
1181 | strcpy(a->name, "Television"); | |
1182 | break; | |
1183 | case CX231XX_AMUX_LINE_IN: | |
1184 | strcpy(a->name, "Line In"); | |
1185 | break; | |
1186 | default: | |
1187 | return -EINVAL; | |
1188 | } | |
1189 | ||
1190 | a->index = dev->ctl_ainput; | |
1191 | a->capability = V4L2_AUDCAP_STEREO; | |
1192 | ||
1193 | return 0; | |
1194 | } | |
1195 | ||
1196 | static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a) | |
1197 | { | |
84b5dbf3 MCC |
1198 | struct cx231xx_fh *fh = priv; |
1199 | struct cx231xx *dev = fh->dev; | |
1200 | int status = 0; | |
e0d3bafd SD |
1201 | |
1202 | /* Doesn't allow manual routing */ | |
1203 | if (a->index != dev->ctl_ainput) | |
1204 | return -EINVAL; | |
1205 | ||
1206 | dev->ctl_ainput = INPUT(a->index)->amux; | |
84b5dbf3 | 1207 | status = cx231xx_set_audio_input(dev, dev->ctl_ainput); |
e0d3bafd SD |
1208 | |
1209 | return status; | |
1210 | } | |
1211 | ||
1212 | static int vidioc_queryctrl(struct file *file, void *priv, | |
84b5dbf3 | 1213 | struct v4l2_queryctrl *qc) |
e0d3bafd | 1214 | { |
84b5dbf3 MCC |
1215 | struct cx231xx_fh *fh = priv; |
1216 | struct cx231xx *dev = fh->dev; | |
1217 | int id = qc->id; | |
1218 | int i; | |
1219 | int rc; | |
e0d3bafd SD |
1220 | |
1221 | rc = check_dev(dev); | |
1222 | if (rc < 0) | |
1223 | return rc; | |
1224 | ||
84b5dbf3 | 1225 | qc->id = v4l2_ctrl_next(ctrl_classes, qc->id); |
e0d3bafd SD |
1226 | if (unlikely(qc->id == 0)) |
1227 | return -EINVAL; | |
1228 | ||
1229 | memset(qc, 0, sizeof(*qc)); | |
1230 | ||
1231 | qc->id = id; | |
1232 | ||
84b5dbf3 | 1233 | if (qc->id < V4L2_CID_BASE || qc->id >= V4L2_CID_LASTP1) |
e0d3bafd SD |
1234 | return -EINVAL; |
1235 | ||
1236 | for (i = 0; i < CX231XX_CTLS; i++) | |
1237 | if (cx231xx_ctls[i].v.id == qc->id) | |
1238 | break; | |
1239 | ||
1240 | if (i == CX231XX_CTLS) { | |
1241 | *qc = no_ctl; | |
1242 | return 0; | |
1243 | } | |
1244 | *qc = cx231xx_ctls[i].v; | |
1245 | ||
1246 | mutex_lock(&dev->lock); | |
84b5dbf3 | 1247 | cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_QUERYCTRL, qc); |
e0d3bafd SD |
1248 | mutex_unlock(&dev->lock); |
1249 | ||
1250 | if (qc->type) | |
1251 | return 0; | |
1252 | else | |
1253 | return -EINVAL; | |
1254 | } | |
1255 | ||
1256 | static int vidioc_g_ctrl(struct file *file, void *priv, | |
84b5dbf3 | 1257 | struct v4l2_control *ctrl) |
e0d3bafd | 1258 | { |
84b5dbf3 MCC |
1259 | struct cx231xx_fh *fh = priv; |
1260 | struct cx231xx *dev = fh->dev; | |
1261 | int rc; | |
e0d3bafd SD |
1262 | |
1263 | rc = check_dev(dev); | |
1264 | if (rc < 0) | |
1265 | return rc; | |
1266 | ||
1267 | mutex_lock(&dev->lock); | |
1268 | ||
1269 | cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_CTRL, ctrl); | |
1270 | ||
1271 | mutex_unlock(&dev->lock); | |
1272 | return rc; | |
1273 | } | |
1274 | ||
1275 | static int vidioc_s_ctrl(struct file *file, void *priv, | |
84b5dbf3 | 1276 | struct v4l2_control *ctrl) |
e0d3bafd | 1277 | { |
84b5dbf3 MCC |
1278 | struct cx231xx_fh *fh = priv; |
1279 | struct cx231xx *dev = fh->dev; | |
1280 | int rc; | |
e0d3bafd SD |
1281 | |
1282 | rc = check_dev(dev); | |
1283 | if (rc < 0) | |
1284 | return rc; | |
1285 | ||
1286 | mutex_lock(&dev->lock); | |
1287 | ||
1288 | cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_S_CTRL, ctrl); | |
1289 | ||
1290 | mutex_unlock(&dev->lock); | |
1291 | return rc; | |
1292 | } | |
1293 | ||
84b5dbf3 | 1294 | static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) |
e0d3bafd | 1295 | { |
84b5dbf3 MCC |
1296 | struct cx231xx_fh *fh = priv; |
1297 | struct cx231xx *dev = fh->dev; | |
1298 | int rc; | |
e0d3bafd SD |
1299 | |
1300 | rc = check_dev(dev); | |
1301 | if (rc < 0) | |
1302 | return rc; | |
1303 | ||
1304 | if (0 != t->index) | |
1305 | return -EINVAL; | |
1306 | ||
1307 | strcpy(t->name, "Tuner"); | |
1308 | ||
84b5dbf3 | 1309 | t->type = V4L2_TUNER_ANALOG_TV; |
e0d3bafd | 1310 | t->capability = V4L2_TUNER_CAP_NORM; |
84b5dbf3 MCC |
1311 | t->rangehigh = 0xffffffffUL; |
1312 | t->signal = 0xffff; /* LOCKED */ | |
e0d3bafd SD |
1313 | |
1314 | return 0; | |
1315 | } | |
1316 | ||
84b5dbf3 | 1317 | static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t) |
e0d3bafd | 1318 | { |
84b5dbf3 MCC |
1319 | struct cx231xx_fh *fh = priv; |
1320 | struct cx231xx *dev = fh->dev; | |
1321 | int rc; | |
e0d3bafd SD |
1322 | |
1323 | rc = check_dev(dev); | |
1324 | if (rc < 0) | |
1325 | return rc; | |
1326 | ||
1327 | if (0 != t->index) | |
1328 | return -EINVAL; | |
1329 | #if 0 | |
1330 | mutex_lock(&dev->lock); | |
1331 | ||
1332 | cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_TUNER, t); | |
1333 | ||
1334 | mutex_unlock(&dev->lock); | |
1335 | #endif | |
1336 | return 0; | |
1337 | } | |
1338 | ||
1339 | static int vidioc_g_frequency(struct file *file, void *priv, | |
84b5dbf3 | 1340 | struct v4l2_frequency *f) |
e0d3bafd | 1341 | { |
84b5dbf3 MCC |
1342 | struct cx231xx_fh *fh = priv; |
1343 | struct cx231xx *dev = fh->dev; | |
e0d3bafd | 1344 | |
84b5dbf3 | 1345 | mutex_lock(&dev->lock); |
e0d3bafd SD |
1346 | f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
1347 | f->frequency = dev->ctl_freq; | |
1348 | ||
84b5dbf3 | 1349 | cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_G_FREQUENCY, f); |
e0d3bafd | 1350 | |
84b5dbf3 | 1351 | mutex_unlock(&dev->lock); |
e0d3bafd SD |
1352 | |
1353 | return 0; | |
1354 | } | |
1355 | ||
1356 | static int vidioc_s_frequency(struct file *file, void *priv, | |
84b5dbf3 | 1357 | struct v4l2_frequency *f) |
e0d3bafd | 1358 | { |
84b5dbf3 MCC |
1359 | struct cx231xx_fh *fh = priv; |
1360 | struct cx231xx *dev = fh->dev; | |
1361 | int rc; | |
e0d3bafd SD |
1362 | |
1363 | rc = check_dev(dev); | |
1364 | if (rc < 0) | |
1365 | return rc; | |
1366 | ||
1367 | if (0 != f->tuner) | |
1368 | return -EINVAL; | |
1369 | ||
1370 | if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV)) | |
1371 | return -EINVAL; | |
1372 | if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO)) | |
1373 | return -EINVAL; | |
1374 | ||
84b5dbf3 MCC |
1375 | /* set pre channel change settings in DIF first */ |
1376 | rc = cx231xx_tuner_pre_channel_change(dev); | |
e0d3bafd SD |
1377 | |
1378 | mutex_lock(&dev->lock); | |
1379 | ||
1380 | dev->ctl_freq = f->frequency; | |
1381 | ||
84b5dbf3 | 1382 | if (dev->tuner_type == TUNER_XC5000) { |
cde4362f | 1383 | if (dev->cx231xx_set_analog_freq != NULL) |
84b5dbf3 | 1384 | dev->cx231xx_set_analog_freq(dev, f->frequency); |
e0d3bafd | 1385 | } else { |
cde4362f MCC |
1386 | cx231xx_i2c_call_clients(&dev->i2c_bus[1], |
1387 | VIDIOC_S_FREQUENCY, f); | |
e0d3bafd SD |
1388 | } |
1389 | ||
1390 | mutex_unlock(&dev->lock); | |
1391 | ||
84b5dbf3 MCC |
1392 | /* set post channel change settings in DIF first */ |
1393 | rc = cx231xx_tuner_post_channel_change(dev); | |
e0d3bafd | 1394 | |
84b5dbf3 | 1395 | cx231xx_info("Set New FREQUENCY to %d\n", f->frequency); |
e0d3bafd SD |
1396 | |
1397 | return rc; | |
1398 | } | |
1399 | ||
1400 | #ifdef CONFIG_VIDEO_ADV_DEBUG | |
1401 | ||
e0d3bafd | 1402 | /* |
b9255176 SD |
1403 | -R, --list-registers=type=<host/i2cdrv/i2caddr>, |
1404 | chip=<chip>[,min=<addr>,max=<addr>] | |
84b5dbf3 | 1405 | dump registers from <min> to <max> [VIDIOC_DBG_G_REGISTER] |
b9255176 SD |
1406 | -r, --set-register=type=<host/i2cdrv/i2caddr>, |
1407 | chip=<chip>,reg=<addr>,val=<val> | |
84b5dbf3 | 1408 | set the register [VIDIOC_DBG_S_REGISTER] |
e0d3bafd SD |
1409 | |
1410 | if type == host, then <chip> is the hosts chip ID (default 0) | |
1411 | if type == i2cdrv (default), then <chip> is the I2C driver name or ID | |
1412 | if type == i2caddr, then <chip> is the 7-bit I2C address | |
1413 | */ | |
1414 | ||
e0d3bafd SD |
1415 | static int vidioc_g_register(struct file *file, void *priv, |
1416 | struct v4l2_dbg_register *reg) | |
1417 | { | |
84b5dbf3 MCC |
1418 | struct cx231xx_fh *fh = priv; |
1419 | struct cx231xx *dev = fh->dev; | |
e0d3bafd | 1420 | int ret = 0; |
84b5dbf3 MCC |
1421 | u8 value[4] = { 0, 0, 0, 0 }; |
1422 | u32 data = 0; | |
1423 | ||
1424 | switch (reg->match.type) { | |
1425 | case V4L2_CHIP_MATCH_HOST: | |
1426 | switch (reg->match.addr) { | |
1427 | case 0: /* Cx231xx - internal registers */ | |
cde4362f MCC |
1428 | ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, |
1429 | (u16)reg->reg, value, 4); | |
1430 | reg->val = value[0] | value[1] << 8 | | |
1431 | value[2] << 16 | value[3] << 24; | |
84b5dbf3 MCC |
1432 | break; |
1433 | case 1: /* Colibri - read byte */ | |
cde4362f MCC |
1434 | ret = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, |
1435 | (u16)reg->reg, 2, &data, 1); | |
84b5dbf3 MCC |
1436 | reg->val = le32_to_cpu(data & 0xff); |
1437 | break; | |
1438 | case 14: /* Colibri - read dword */ | |
cde4362f MCC |
1439 | ret = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, |
1440 | (u16)reg->reg, 2, &data, 4); | |
84b5dbf3 MCC |
1441 | reg->val = le32_to_cpu(data); |
1442 | break; | |
1443 | case 2: /* Hammerhead - read byte */ | |
cde4362f MCC |
1444 | ret = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, |
1445 | (u16)reg->reg, 2, &data, 1); | |
84b5dbf3 MCC |
1446 | reg->val = le32_to_cpu(data & 0xff); |
1447 | break; | |
1448 | case 24: /* Hammerhead - read dword */ | |
cde4362f MCC |
1449 | ret = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, |
1450 | (u16)reg->reg, 2, &data, 4); | |
84b5dbf3 MCC |
1451 | reg->val = le32_to_cpu(data); |
1452 | break; | |
1453 | case 3: /* flatiron - read byte */ | |
cde4362f MCC |
1454 | ret = cx231xx_read_i2c_data(dev, |
1455 | Flatrion_DEVICE_ADDRESS, | |
1456 | (u16)reg->reg, 1, | |
1457 | &data, 1); | |
84b5dbf3 MCC |
1458 | reg->val = le32_to_cpu(data & 0xff); |
1459 | break; | |
1460 | case 34: /* flatiron - read dword */ | |
1461 | ret = | |
1462 | cx231xx_read_i2c_data(dev, Flatrion_DEVICE_ADDRESS, | |
cde4362f | 1463 | (u16)reg->reg, 1, &data, 4); |
84b5dbf3 MCC |
1464 | reg->val = le32_to_cpu(data); |
1465 | break; | |
1466 | } | |
1467 | return ret < 0 ? ret : 0; | |
e0d3bafd | 1468 | |
84b5dbf3 MCC |
1469 | case V4L2_CHIP_MATCH_I2C_DRIVER: |
1470 | cx231xx_i2c_call_clients(&dev->i2c_bus[0], | |
1471 | VIDIOC_DBG_G_REGISTER, reg); | |
1472 | return 0; | |
1473 | case V4L2_CHIP_MATCH_I2C_ADDR: | |
1474 | /* Not supported yet */ | |
1475 | return -EINVAL; | |
1476 | default: | |
1477 | if (!v4l2_chip_match_host(®->match)) | |
1478 | return -EINVAL; | |
1479 | } | |
e0d3bafd | 1480 | |
84b5dbf3 | 1481 | mutex_lock(&dev->lock); |
e0d3bafd | 1482 | cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_DBG_G_REGISTER, reg); |
84b5dbf3 | 1483 | mutex_unlock(&dev->lock); |
e0d3bafd SD |
1484 | |
1485 | return ret; | |
1486 | } | |
1487 | ||
1488 | static int vidioc_s_register(struct file *file, void *priv, | |
1489 | struct v4l2_dbg_register *reg) | |
1490 | { | |
84b5dbf3 MCC |
1491 | struct cx231xx_fh *fh = priv; |
1492 | struct cx231xx *dev = fh->dev; | |
1493 | int ret = 0; | |
e0d3bafd | 1494 | __le64 buf; |
84b5dbf3 MCC |
1495 | u32 value; |
1496 | u8 data[4] = { 0, 0, 0, 0 }; | |
e0d3bafd SD |
1497 | |
1498 | buf = cpu_to_le64(reg->val); | |
1499 | ||
84b5dbf3 MCC |
1500 | switch (reg->match.type) { |
1501 | case V4L2_CHIP_MATCH_HOST: | |
1502 | { | |
1503 | value = (u32) buf & 0xffffffff; | |
1504 | ||
1505 | switch (reg->match.addr) { | |
1506 | case 0: /* cx231xx internal registers */ | |
1507 | data[0] = (u8) value; | |
1508 | data[1] = (u8) (value >> 8); | |
1509 | data[2] = (u8) (value >> 16); | |
1510 | data[3] = (u8) (value >> 24); | |
cde4362f | 1511 | ret = cx231xx_write_ctrl_reg(dev, |
84b5dbf3 | 1512 | VRT_SET_REGISTER, |
cde4362f | 1513 | (u16)reg->reg, data, |
84b5dbf3 MCC |
1514 | 4); |
1515 | break; | |
1516 | case 1: /* Colibri - read byte */ | |
cde4362f MCC |
1517 | ret = cx231xx_write_i2c_data(dev, |
1518 | Colibri_DEVICE_ADDRESS, | |
1519 | (u16)reg->reg, 2, | |
1520 | value, 1); | |
84b5dbf3 MCC |
1521 | break; |
1522 | case 14: /* Colibri - read dword */ | |
cde4362f MCC |
1523 | ret = cx231xx_write_i2c_data(dev, |
1524 | Colibri_DEVICE_ADDRESS, | |
1525 | (u16)reg->reg, 2, | |
1526 | value, 4); | |
84b5dbf3 MCC |
1527 | break; |
1528 | case 2: /* Hammerhead - read byte */ | |
1529 | ret = | |
1530 | cx231xx_write_i2c_data(dev, | |
cde4362f MCC |
1531 | HAMMERHEAD_I2C_ADDRESS, |
1532 | (u16)reg->reg, 2, | |
1533 | value, 1); | |
84b5dbf3 MCC |
1534 | break; |
1535 | case 24: /* Hammerhead - read dword */ | |
1536 | ret = | |
1537 | cx231xx_write_i2c_data(dev, | |
cde4362f MCC |
1538 | HAMMERHEAD_I2C_ADDRESS, |
1539 | (u16)reg->reg, 2, | |
1540 | value, 4); | |
84b5dbf3 MCC |
1541 | break; |
1542 | case 3: /* flatiron - read byte */ | |
1543 | ret = | |
1544 | cx231xx_write_i2c_data(dev, | |
cde4362f MCC |
1545 | Flatrion_DEVICE_ADDRESS, |
1546 | (u16)reg->reg, 1, | |
1547 | value, 1); | |
84b5dbf3 MCC |
1548 | break; |
1549 | case 34: /* flatiron - read dword */ | |
1550 | ret = | |
1551 | cx231xx_write_i2c_data(dev, | |
cde4362f MCC |
1552 | Flatrion_DEVICE_ADDRESS, |
1553 | (u16)reg->reg, 1, | |
1554 | value, 4); | |
84b5dbf3 MCC |
1555 | break; |
1556 | } | |
1557 | } | |
1558 | return ret < 0 ? ret : 0; | |
1559 | ||
1560 | default: | |
1561 | break; | |
1562 | } | |
e0d3bafd SD |
1563 | |
1564 | mutex_lock(&dev->lock); | |
1565 | ||
1566 | cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_DBG_S_REGISTER, reg); | |
1567 | ||
84b5dbf3 | 1568 | mutex_unlock(&dev->lock); |
e0d3bafd | 1569 | |
84b5dbf3 | 1570 | return ret; |
e0d3bafd SD |
1571 | } |
1572 | #endif | |
1573 | ||
e0d3bafd | 1574 | static int vidioc_cropcap(struct file *file, void *priv, |
84b5dbf3 | 1575 | struct v4l2_cropcap *cc) |
e0d3bafd | 1576 | { |
84b5dbf3 MCC |
1577 | struct cx231xx_fh *fh = priv; |
1578 | struct cx231xx *dev = fh->dev; | |
e0d3bafd SD |
1579 | |
1580 | if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
1581 | return -EINVAL; | |
1582 | ||
1583 | cc->bounds.left = 0; | |
1584 | cc->bounds.top = 0; | |
1585 | cc->bounds.width = dev->width; | |
1586 | cc->bounds.height = dev->height; | |
1587 | cc->defrect = cc->bounds; | |
1588 | cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */ | |
1589 | cc->pixelaspect.denominator = 59; | |
1590 | ||
1591 | return 0; | |
1592 | } | |
1593 | ||
1594 | static int vidioc_streamon(struct file *file, void *priv, | |
84b5dbf3 | 1595 | enum v4l2_buf_type type) |
e0d3bafd | 1596 | { |
84b5dbf3 MCC |
1597 | struct cx231xx_fh *fh = priv; |
1598 | struct cx231xx *dev = fh->dev; | |
1599 | int rc; | |
e0d3bafd SD |
1600 | |
1601 | rc = check_dev(dev); | |
1602 | if (rc < 0) | |
1603 | return rc; | |
1604 | ||
84b5dbf3 | 1605 | mutex_lock(&dev->lock); |
e0d3bafd SD |
1606 | rc = res_get(fh); |
1607 | ||
1608 | if (likely(rc >= 0)) | |
1609 | rc = videobuf_streamon(&fh->vb_vidq); | |
1610 | ||
1611 | mutex_unlock(&dev->lock); | |
1612 | ||
1613 | return rc; | |
1614 | } | |
1615 | ||
1616 | static int vidioc_streamoff(struct file *file, void *priv, | |
84b5dbf3 | 1617 | enum v4l2_buf_type type) |
e0d3bafd | 1618 | { |
84b5dbf3 MCC |
1619 | struct cx231xx_fh *fh = priv; |
1620 | struct cx231xx *dev = fh->dev; | |
1621 | int rc; | |
e0d3bafd SD |
1622 | |
1623 | rc = check_dev(dev); | |
1624 | if (rc < 0) | |
1625 | return rc; | |
1626 | ||
84b5dbf3 MCC |
1627 | if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) || |
1628 | (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)) | |
e0d3bafd SD |
1629 | return -EINVAL; |
1630 | if (type != fh->type) | |
1631 | return -EINVAL; | |
1632 | ||
84b5dbf3 | 1633 | mutex_lock(&dev->lock); |
e0d3bafd SD |
1634 | |
1635 | videobuf_streamoff(&fh->vb_vidq); | |
1636 | res_free(fh); | |
1637 | ||
84b5dbf3 | 1638 | mutex_unlock(&dev->lock); |
e0d3bafd SD |
1639 | |
1640 | return 0; | |
1641 | } | |
1642 | ||
84b5dbf3 MCC |
1643 | static int vidioc_querycap(struct file *file, void *priv, |
1644 | struct v4l2_capability *cap) | |
e0d3bafd | 1645 | { |
84b5dbf3 MCC |
1646 | struct cx231xx_fh *fh = priv; |
1647 | struct cx231xx *dev = fh->dev; | |
e0d3bafd SD |
1648 | |
1649 | strlcpy(cap->driver, "cx231xx", sizeof(cap->driver)); | |
1650 | strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card)); | |
84b5dbf3 MCC |
1651 | strlcpy(cap->bus_info, dev_name(&dev->udev->dev), |
1652 | sizeof(cap->bus_info)); | |
e0d3bafd SD |
1653 | |
1654 | cap->version = CX231XX_VERSION_CODE; | |
1655 | ||
84b5dbf3 | 1656 | cap->capabilities = V4L2_CAP_VBI_CAPTURE | |
e0d3bafd | 1657 | #if 0 |
6e4f574b | 1658 | V4L2_CAP_SLICED_VBI_CAPTURE | |
e0d3bafd | 1659 | #endif |
6e4f574b SD |
1660 | V4L2_CAP_VIDEO_CAPTURE | |
1661 | V4L2_CAP_AUDIO | | |
1662 | V4L2_CAP_READWRITE | | |
1663 | V4L2_CAP_STREAMING; | |
e0d3bafd SD |
1664 | |
1665 | if (dev->tuner_type != TUNER_ABSENT) | |
1666 | cap->capabilities |= V4L2_CAP_TUNER; | |
1667 | ||
1668 | return 0; | |
1669 | } | |
1670 | ||
84b5dbf3 MCC |
1671 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
1672 | struct v4l2_fmtdesc *f) | |
e0d3bafd | 1673 | { |
84b5dbf3 | 1674 | if (unlikely(f->index >= ARRAY_SIZE(format))) |
e0d3bafd SD |
1675 | return -EINVAL; |
1676 | ||
1677 | strlcpy(f->description, format[f->index].name, sizeof(f->description)); | |
1678 | f->pixelformat = format[f->index].fourcc; | |
1679 | ||
1680 | return 0; | |
1681 | } | |
1682 | ||
1683 | /* Sliced VBI ioctls */ | |
1684 | static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv, | |
84b5dbf3 | 1685 | struct v4l2_format *f) |
e0d3bafd | 1686 | { |
84b5dbf3 MCC |
1687 | struct cx231xx_fh *fh = priv; |
1688 | struct cx231xx *dev = fh->dev; | |
1689 | int rc; | |
e0d3bafd SD |
1690 | |
1691 | rc = check_dev(dev); | |
1692 | if (rc < 0) | |
1693 | return rc; | |
1694 | ||
1695 | mutex_lock(&dev->lock); | |
1696 | ||
1697 | f->fmt.sliced.service_set = 0; | |
1698 | ||
1699 | cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_FMT, f); | |
1700 | ||
1701 | if (f->fmt.sliced.service_set == 0) | |
1702 | rc = -EINVAL; | |
1703 | ||
1704 | mutex_unlock(&dev->lock); | |
1705 | return rc; | |
1706 | } | |
1707 | ||
1708 | static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv, | |
84b5dbf3 | 1709 | struct v4l2_format *f) |
e0d3bafd | 1710 | { |
84b5dbf3 MCC |
1711 | struct cx231xx_fh *fh = priv; |
1712 | struct cx231xx *dev = fh->dev; | |
1713 | int rc; | |
e0d3bafd SD |
1714 | |
1715 | rc = check_dev(dev); | |
1716 | if (rc < 0) | |
1717 | return rc; | |
1718 | ||
1719 | mutex_lock(&dev->lock); | |
1720 | cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_FMT, f); | |
1721 | mutex_unlock(&dev->lock); | |
1722 | ||
1723 | if (f->fmt.sliced.service_set == 0) | |
1724 | return -EINVAL; | |
1725 | ||
1726 | return 0; | |
1727 | } | |
1728 | ||
e0d3bafd SD |
1729 | /* RAW VBI ioctls */ |
1730 | ||
1731 | static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv, | |
84b5dbf3 | 1732 | struct v4l2_format *f) |
e0d3bafd | 1733 | { |
84b5dbf3 MCC |
1734 | struct cx231xx_fh *fh = priv; |
1735 | struct cx231xx *dev = fh->dev; | |
e0d3bafd SD |
1736 | |
1737 | f->fmt.vbi.sampling_rate = (dev->norm & V4L2_STD_625_50) ? | |
84b5dbf3 | 1738 | 35468950 : 28636363; |
e0d3bafd SD |
1739 | f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH; |
1740 | f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; | |
1741 | f->fmt.vbi.offset = 64 * 4; | |
1742 | f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ? | |
84b5dbf3 | 1743 | PAL_VBI_START_LINE : NTSC_VBI_START_LINE; |
e0d3bafd | 1744 | f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ? |
84b5dbf3 | 1745 | PAL_VBI_LINES : NTSC_VBI_LINES; |
e0d3bafd | 1746 | f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ? |
84b5dbf3 | 1747 | PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263; |
e0d3bafd SD |
1748 | f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; |
1749 | ||
1750 | return 0; | |
1751 | ||
1752 | } | |
1753 | ||
1754 | static int vidioc_try_fmt_vbi_cap(struct file *file, void *priv, | |
84b5dbf3 | 1755 | struct v4l2_format *f) |
e0d3bafd | 1756 | { |
84b5dbf3 MCC |
1757 | struct cx231xx_fh *fh = priv; |
1758 | struct cx231xx *dev = fh->dev; | |
e0d3bafd | 1759 | |
84b5dbf3 | 1760 | if (dev->vbi_stream_on && !fh->stream_on) { |
e0d3bafd SD |
1761 | cx231xx_errdev("%s device in use by another fh\n", __func__); |
1762 | return -EBUSY; | |
1763 | } | |
1764 | ||
1765 | f->type = V4L2_BUF_TYPE_VBI_CAPTURE; | |
1766 | f->fmt.vbi.sampling_rate = (dev->norm & V4L2_STD_625_50) ? | |
84b5dbf3 | 1767 | 35468950 : 28636363; |
e0d3bafd SD |
1768 | f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH; |
1769 | f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; | |
1770 | f->fmt.vbi.offset = 244; | |
1771 | f->fmt.vbi.flags = 0; | |
1772 | f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ? | |
84b5dbf3 | 1773 | PAL_VBI_START_LINE : NTSC_VBI_START_LINE; |
e0d3bafd | 1774 | f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ? |
84b5dbf3 | 1775 | PAL_VBI_LINES : NTSC_VBI_LINES; |
e0d3bafd | 1776 | f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ? |
84b5dbf3 | 1777 | PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263; |
e0d3bafd SD |
1778 | f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; |
1779 | ||
1780 | return 0; | |
1781 | ||
1782 | } | |
1783 | ||
1784 | static int vidioc_reqbufs(struct file *file, void *priv, | |
1785 | struct v4l2_requestbuffers *rb) | |
1786 | { | |
84b5dbf3 MCC |
1787 | struct cx231xx_fh *fh = priv; |
1788 | struct cx231xx *dev = fh->dev; | |
1789 | int rc; | |
e0d3bafd SD |
1790 | |
1791 | rc = check_dev(dev); | |
1792 | if (rc < 0) | |
1793 | return rc; | |
1794 | ||
cde4362f | 1795 | return videobuf_reqbufs(&fh->vb_vidq, rb); |
e0d3bafd SD |
1796 | } |
1797 | ||
84b5dbf3 | 1798 | static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *b) |
e0d3bafd | 1799 | { |
84b5dbf3 MCC |
1800 | struct cx231xx_fh *fh = priv; |
1801 | struct cx231xx *dev = fh->dev; | |
1802 | int rc; | |
e0d3bafd SD |
1803 | |
1804 | rc = check_dev(dev); | |
1805 | if (rc < 0) | |
1806 | return rc; | |
1807 | ||
cde4362f | 1808 | return videobuf_querybuf(&fh->vb_vidq, b); |
e0d3bafd SD |
1809 | } |
1810 | ||
1811 | static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) | |
1812 | { | |
84b5dbf3 MCC |
1813 | struct cx231xx_fh *fh = priv; |
1814 | struct cx231xx *dev = fh->dev; | |
1815 | int rc; | |
e0d3bafd SD |
1816 | |
1817 | rc = check_dev(dev); | |
1818 | if (rc < 0) | |
1819 | return rc; | |
1820 | ||
cde4362f | 1821 | return videobuf_qbuf(&fh->vb_vidq, b); |
e0d3bafd SD |
1822 | } |
1823 | ||
1824 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) | |
1825 | { | |
84b5dbf3 MCC |
1826 | struct cx231xx_fh *fh = priv; |
1827 | struct cx231xx *dev = fh->dev; | |
1828 | int rc; | |
e0d3bafd SD |
1829 | |
1830 | rc = check_dev(dev); | |
1831 | if (rc < 0) | |
1832 | return rc; | |
1833 | ||
cde4362f | 1834 | return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK); |
e0d3bafd SD |
1835 | } |
1836 | ||
1837 | #ifdef CONFIG_VIDEO_V4L1_COMPAT | |
1838 | static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf) | |
1839 | { | |
84b5dbf3 | 1840 | struct cx231xx_fh *fh = priv; |
e0d3bafd SD |
1841 | |
1842 | return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8); | |
1843 | } | |
1844 | #endif | |
1845 | ||
e0d3bafd SD |
1846 | /* ----------------------------------------------------------- */ |
1847 | /* RADIO ESPECIFIC IOCTLS */ | |
1848 | /* ----------------------------------------------------------- */ | |
1849 | ||
84b5dbf3 | 1850 | static int radio_querycap(struct file *file, void *priv, |
e0d3bafd SD |
1851 | struct v4l2_capability *cap) |
1852 | { | |
1853 | struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; | |
1854 | ||
1855 | strlcpy(cap->driver, "cx231xx", sizeof(cap->driver)); | |
1856 | strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card)); | |
1857 | usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); | |
1858 | ||
1859 | cap->version = CX231XX_VERSION_CODE; | |
1860 | cap->capabilities = V4L2_CAP_TUNER; | |
1861 | return 0; | |
1862 | } | |
1863 | ||
84b5dbf3 | 1864 | static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) |
e0d3bafd SD |
1865 | { |
1866 | struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; | |
1867 | ||
1868 | if (unlikely(t->index > 0)) | |
1869 | return -EINVAL; | |
1870 | ||
1871 | strcpy(t->name, "Radio"); | |
1872 | t->type = V4L2_TUNER_RADIO; | |
1873 | ||
84b5dbf3 | 1874 | mutex_lock(&dev->lock); |
e0d3bafd | 1875 | cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_G_TUNER, t); |
84b5dbf3 | 1876 | mutex_unlock(&dev->lock); |
e0d3bafd SD |
1877 | |
1878 | return 0; | |
1879 | } | |
1880 | ||
84b5dbf3 | 1881 | static int radio_enum_input(struct file *file, void *priv, struct v4l2_input *i) |
e0d3bafd SD |
1882 | { |
1883 | if (i->index != 0) | |
1884 | return -EINVAL; | |
1885 | strcpy(i->name, "Radio"); | |
1886 | i->type = V4L2_INPUT_TYPE_TUNER; | |
1887 | ||
1888 | return 0; | |
1889 | } | |
1890 | ||
1891 | static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a) | |
1892 | { | |
1893 | if (unlikely(a->index)) | |
1894 | return -EINVAL; | |
1895 | ||
1896 | strcpy(a->name, "Radio"); | |
1897 | return 0; | |
1898 | } | |
1899 | ||
84b5dbf3 | 1900 | static int radio_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t) |
e0d3bafd SD |
1901 | { |
1902 | struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; | |
1903 | ||
1904 | if (0 != t->index) | |
1905 | return -EINVAL; | |
1906 | ||
84b5dbf3 | 1907 | mutex_lock(&dev->lock); |
e0d3bafd | 1908 | cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_TUNER, t); |
84b5dbf3 | 1909 | mutex_unlock(&dev->lock); |
e0d3bafd SD |
1910 | |
1911 | return 0; | |
1912 | } | |
1913 | ||
84b5dbf3 | 1914 | static int radio_s_audio(struct file *file, void *fh, struct v4l2_audio *a) |
e0d3bafd SD |
1915 | { |
1916 | return 0; | |
1917 | } | |
1918 | ||
1919 | static int radio_s_input(struct file *file, void *fh, unsigned int i) | |
1920 | { | |
1921 | return 0; | |
1922 | } | |
1923 | ||
1924 | static int radio_queryctrl(struct file *file, void *priv, | |
1925 | struct v4l2_queryctrl *c) | |
1926 | { | |
1927 | int i; | |
1928 | ||
84b5dbf3 | 1929 | if (c->id < V4L2_CID_BASE || c->id >= V4L2_CID_LASTP1) |
e0d3bafd SD |
1930 | return -EINVAL; |
1931 | if (c->id == V4L2_CID_AUDIO_MUTE) { | |
1932 | for (i = 0; i < CX231XX_CTLS; i++) | |
1933 | if (cx231xx_ctls[i].v.id == c->id) | |
1934 | break; | |
1935 | *c = cx231xx_ctls[i].v; | |
1936 | } else | |
1937 | *c = no_ctl; | |
1938 | return 0; | |
1939 | } | |
1940 | ||
1941 | /* | |
1942 | * cx231xx_v4l2_open() | |
1943 | * inits the device and starts isoc transfer | |
1944 | */ | |
1945 | static int cx231xx_v4l2_open(struct file *filp) | |
1946 | { | |
84b5dbf3 | 1947 | int minor = video_devdata(filp)->minor; |
e0d3bafd SD |
1948 | int errCode = 0, radio = 0; |
1949 | struct cx231xx *dev = NULL; | |
1950 | struct cx231xx_fh *fh; | |
1951 | enum v4l2_buf_type fh_type = 0; | |
1952 | ||
84b5dbf3 | 1953 | dev = cx231xx_get_device(minor, &fh_type, &radio); |
e0d3bafd SD |
1954 | if (NULL == dev) |
1955 | return -ENODEV; | |
1956 | ||
1957 | mutex_lock(&dev->lock); | |
1958 | ||
1959 | cx231xx_videodbg("open minor=%d type=%s users=%d\n", | |
84b5dbf3 | 1960 | minor, v4l2_type_names[fh_type], dev->users); |
e0d3bafd SD |
1961 | |
1962 | #if 0 | |
1963 | errCode = cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); | |
1964 | if (errCode < 0) { | |
84b5dbf3 MCC |
1965 | cx231xx_errdev |
1966 | ("Device locked on digital mode. Can't open analog\n"); | |
e0d3bafd SD |
1967 | mutex_unlock(&dev->lock); |
1968 | return -EBUSY; | |
1969 | } | |
1970 | #endif | |
1971 | ||
1972 | fh = kzalloc(sizeof(struct cx231xx_fh), GFP_KERNEL); | |
1973 | if (!fh) { | |
1974 | cx231xx_errdev("cx231xx-video.c: Out of memory?!\n"); | |
1975 | mutex_unlock(&dev->lock); | |
1976 | return -ENOMEM; | |
1977 | } | |
1978 | fh->dev = dev; | |
1979 | fh->radio = radio; | |
1980 | fh->type = fh_type; | |
1981 | filp->private_data = fh; | |
1982 | ||
1983 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { | |
1984 | dev->width = norm_maxw(dev); | |
1985 | dev->height = norm_maxh(dev); | |
1986 | dev->hscale = 0; | |
1987 | dev->vscale = 0; | |
1988 | ||
84b5dbf3 MCC |
1989 | /* Power up in Analog TV mode */ |
1990 | cx231xx_set_power_mode(dev, POLARIS_AVMODE_ANALOGT_TV); | |
e0d3bafd SD |
1991 | |
1992 | #if 0 | |
1993 | cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); | |
1994 | #endif | |
1995 | cx231xx_resolution_set(dev); | |
1996 | ||
84b5dbf3 MCC |
1997 | /* set video alternate setting */ |
1998 | cx231xx_set_video_alternate(dev); | |
e0d3bafd SD |
1999 | |
2000 | /* Needed, since GPIO might have disabled power of | |
2001 | some i2c device */ | |
2002 | cx231xx_config_i2c(dev); | |
2003 | ||
2004 | /* device needs to be initialized before isoc transfer */ | |
84b5dbf3 MCC |
2005 | dev->video_input = dev->video_input > 2 ? 2 : dev->video_input; |
2006 | video_mux(dev, dev->video_input); | |
e0d3bafd SD |
2007 | |
2008 | } | |
2009 | if (fh->radio) { | |
2010 | cx231xx_videodbg("video_open: setting radio device\n"); | |
2011 | ||
2012 | /* cx231xx_start_radio(dev); */ | |
2013 | ||
84b5dbf3 MCC |
2014 | cx231xx_i2c_call_clients(&dev->i2c_bus[1], AUDC_SET_RADIO, |
2015 | NULL); | |
e0d3bafd SD |
2016 | } |
2017 | ||
2018 | dev->users++; | |
2019 | ||
cde4362f MCC |
2020 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
2021 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_video_qops, | |
2022 | NULL, &dev->video_mode.slock, | |
2023 | fh->type, V4L2_FIELD_INTERLACED, | |
84b5dbf3 | 2024 | sizeof(struct cx231xx_buffer), fh); |
84b5dbf3 | 2025 | if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
cde4362f MCC |
2026 | /* Set the required alternate setting VBI interface works in |
2027 | Bulk mode only */ | |
84b5dbf3 | 2028 | cx231xx_set_alt_setting(dev, INDEX_VANC, 0); |
e0d3bafd | 2029 | |
cde4362f MCC |
2030 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_vbi_qops, |
2031 | NULL, &dev->vbi_mode.slock, | |
2032 | fh->type, V4L2_FIELD_SEQ_TB, | |
84b5dbf3 MCC |
2033 | sizeof(struct cx231xx_buffer), fh); |
2034 | } | |
e0d3bafd SD |
2035 | |
2036 | mutex_unlock(&dev->lock); | |
2037 | ||
2038 | return errCode; | |
2039 | } | |
2040 | ||
2041 | /* | |
2042 | * cx231xx_realease_resources() | |
2043 | * unregisters the v4l2,i2c and usb devices | |
2044 | * called when the device gets disconected or at module unload | |
2045 | */ | |
2046 | void cx231xx_release_analog_resources(struct cx231xx *dev) | |
2047 | { | |
2048 | ||
2049 | /*FIXME: I2C IR should be disconnected */ | |
2050 | ||
2051 | if (dev->radio_dev) { | |
2052 | if (-1 != dev->radio_dev->minor) | |
2053 | video_unregister_device(dev->radio_dev); | |
2054 | else | |
2055 | video_device_release(dev->radio_dev); | |
2056 | dev->radio_dev = NULL; | |
2057 | } | |
2058 | if (dev->vbi_dev) { | |
2059 | cx231xx_info("V4L2 device /dev/vbi%d deregistered\n", | |
84b5dbf3 | 2060 | dev->vbi_dev->num); |
e0d3bafd SD |
2061 | if (-1 != dev->vbi_dev->minor) |
2062 | video_unregister_device(dev->vbi_dev); | |
2063 | else | |
2064 | video_device_release(dev->vbi_dev); | |
2065 | dev->vbi_dev = NULL; | |
2066 | } | |
2067 | if (dev->vdev) { | |
2068 | cx231xx_info("V4L2 device /dev/video%d deregistered\n", | |
84b5dbf3 | 2069 | dev->vdev->num); |
e0d3bafd SD |
2070 | if (-1 != dev->vdev->minor) |
2071 | video_unregister_device(dev->vdev); | |
2072 | else | |
2073 | video_device_release(dev->vdev); | |
2074 | dev->vdev = NULL; | |
2075 | } | |
2076 | } | |
2077 | ||
2078 | /* | |
2079 | * cx231xx_v4l2_close() | |
2080 | * stops streaming and deallocates all resources allocated by the v4l2 | |
2081 | * calls and ioctls | |
2082 | */ | |
2083 | static int cx231xx_v4l2_close(struct file *filp) | |
2084 | { | |
84b5dbf3 MCC |
2085 | struct cx231xx_fh *fh = filp->private_data; |
2086 | struct cx231xx *dev = fh->dev; | |
e0d3bafd SD |
2087 | |
2088 | cx231xx_videodbg("users=%d\n", dev->users); | |
2089 | ||
84b5dbf3 | 2090 | mutex_lock(&dev->lock); |
e0d3bafd SD |
2091 | |
2092 | if (res_check(fh)) | |
2093 | res_free(fh); | |
2094 | ||
84b5dbf3 MCC |
2095 | if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
2096 | videobuf_stop(&fh->vb_vidq); | |
2097 | videobuf_mmap_free(&fh->vb_vidq); | |
2098 | ||
2099 | /* the device is already disconnect, | |
2100 | free the remaining resources */ | |
2101 | if (dev->state & DEV_DISCONNECTED) { | |
2102 | cx231xx_release_resources(dev); | |
2103 | mutex_unlock(&dev->lock); | |
2104 | kfree(dev); | |
2105 | return 0; | |
2106 | } | |
2107 | ||
2108 | /* do this before setting alternate! */ | |
2109 | cx231xx_uninit_vbi_isoc(dev); | |
2110 | ||
2111 | /* set alternate 0 */ | |
cde4362f | 2112 | if (!dev->vbi_or_sliced_cc_mode) |
84b5dbf3 | 2113 | cx231xx_set_alt_setting(dev, INDEX_VANC, 0); |
cde4362f | 2114 | else |
84b5dbf3 | 2115 | cx231xx_set_alt_setting(dev, INDEX_HANC, 0); |
84b5dbf3 MCC |
2116 | |
2117 | kfree(fh); | |
2118 | dev->users--; | |
2119 | wake_up_interruptible_nr(&dev->open, 1); | |
2120 | mutex_unlock(&dev->lock); | |
2121 | return 0; | |
e0d3bafd SD |
2122 | } |
2123 | ||
2124 | if (dev->users == 1) { | |
2125 | videobuf_stop(&fh->vb_vidq); | |
2126 | videobuf_mmap_free(&fh->vb_vidq); | |
2127 | ||
2128 | /* the device is already disconnect, | |
2129 | free the remaining resources */ | |
2130 | if (dev->state & DEV_DISCONNECTED) { | |
2131 | cx231xx_release_resources(dev); | |
2132 | mutex_unlock(&dev->lock); | |
2133 | kfree(dev); | |
2134 | return 0; | |
2135 | } | |
2136 | ||
84b5dbf3 MCC |
2137 | /* Save some power by putting tuner to sleep */ |
2138 | cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_STANDBY, | |
2139 | NULL); | |
e0d3bafd SD |
2140 | |
2141 | /* do this before setting alternate! */ | |
2142 | cx231xx_uninit_isoc(dev); | |
2143 | cx231xx_set_mode(dev, CX231XX_SUSPEND); | |
2144 | ||
2145 | /* set alternate 0 */ | |
2146 | cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0); | |
2147 | } | |
2148 | kfree(fh); | |
2149 | dev->users--; | |
2150 | wake_up_interruptible_nr(&dev->open, 1); | |
2151 | mutex_unlock(&dev->lock); | |
2152 | return 0; | |
2153 | } | |
2154 | ||
2155 | /* | |
2156 | * cx231xx_v4l2_read() | |
2157 | * will allocate buffers when called for the first time | |
2158 | */ | |
2159 | static ssize_t | |
cde4362f MCC |
2160 | cx231xx_v4l2_read(struct file *filp, char __user *buf, size_t count, |
2161 | loff_t *pos) | |
e0d3bafd SD |
2162 | { |
2163 | struct cx231xx_fh *fh = filp->private_data; | |
2164 | struct cx231xx *dev = fh->dev; | |
2165 | int rc; | |
2166 | ||
2167 | rc = check_dev(dev); | |
2168 | if (rc < 0) | |
2169 | return rc; | |
2170 | ||
84b5dbf3 MCC |
2171 | if ((fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) || |
2172 | (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)) { | |
e0d3bafd SD |
2173 | mutex_lock(&dev->lock); |
2174 | rc = res_get(fh); | |
2175 | mutex_unlock(&dev->lock); | |
2176 | ||
2177 | if (unlikely(rc < 0)) | |
2178 | return rc; | |
2179 | ||
2180 | return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0, | |
84b5dbf3 | 2181 | filp->f_flags & O_NONBLOCK); |
e0d3bafd SD |
2182 | } |
2183 | return 0; | |
2184 | } | |
2185 | ||
2186 | /* | |
2187 | * cx231xx_v4l2_poll() | |
2188 | * will allocate buffers when called for the first time | |
2189 | */ | |
2190 | static unsigned int cx231xx_v4l2_poll(struct file *filp, poll_table * wait) | |
2191 | { | |
2192 | struct cx231xx_fh *fh = filp->private_data; | |
2193 | struct cx231xx *dev = fh->dev; | |
2194 | int rc; | |
2195 | ||
2196 | rc = check_dev(dev); | |
2197 | if (rc < 0) | |
2198 | return rc; | |
2199 | ||
2200 | mutex_lock(&dev->lock); | |
2201 | rc = res_get(fh); | |
2202 | mutex_unlock(&dev->lock); | |
2203 | ||
2204 | if (unlikely(rc < 0)) | |
2205 | return POLLERR; | |
2206 | ||
84b5dbf3 MCC |
2207 | if ((V4L2_BUF_TYPE_VIDEO_CAPTURE == fh->type) || |
2208 | (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type)) | |
2209 | return videobuf_poll_stream(filp, &fh->vb_vidq, wait); | |
2210 | else | |
e0d3bafd SD |
2211 | return POLLERR; |
2212 | } | |
2213 | ||
2214 | /* | |
2215 | * cx231xx_v4l2_mmap() | |
2216 | */ | |
2217 | static int cx231xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma) | |
2218 | { | |
84b5dbf3 MCC |
2219 | struct cx231xx_fh *fh = filp->private_data; |
2220 | struct cx231xx *dev = fh->dev; | |
2221 | int rc; | |
e0d3bafd SD |
2222 | |
2223 | rc = check_dev(dev); | |
2224 | if (rc < 0) | |
2225 | return rc; | |
2226 | ||
84b5dbf3 | 2227 | mutex_lock(&dev->lock); |
e0d3bafd SD |
2228 | rc = res_get(fh); |
2229 | mutex_unlock(&dev->lock); | |
2230 | ||
2231 | if (unlikely(rc < 0)) | |
2232 | return rc; | |
2233 | ||
2234 | rc = videobuf_mmap_mapper(&fh->vb_vidq, vma); | |
2235 | ||
2236 | cx231xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n", | |
84b5dbf3 MCC |
2237 | (unsigned long)vma->vm_start, |
2238 | (unsigned long)vma->vm_end - | |
2239 | (unsigned long)vma->vm_start, rc); | |
e0d3bafd SD |
2240 | |
2241 | return rc; | |
2242 | } | |
2243 | ||
2244 | static const struct v4l2_file_operations cx231xx_v4l_fops = { | |
cde4362f MCC |
2245 | .owner = THIS_MODULE, |
2246 | .open = cx231xx_v4l2_open, | |
84b5dbf3 | 2247 | .release = cx231xx_v4l2_close, |
cde4362f MCC |
2248 | .read = cx231xx_v4l2_read, |
2249 | .poll = cx231xx_v4l2_poll, | |
2250 | .mmap = cx231xx_v4l2_mmap, | |
2251 | .ioctl = video_ioctl2, | |
e0d3bafd SD |
2252 | }; |
2253 | ||
2254 | static const struct v4l2_ioctl_ops video_ioctl_ops = { | |
cde4362f MCC |
2255 | .vidioc_querycap = vidioc_querycap, |
2256 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, | |
2257 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, | |
2258 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, | |
2259 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, | |
2260 | .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, | |
2261 | .vidioc_try_fmt_vbi_cap = vidioc_try_fmt_vbi_cap, | |
2262 | .vidioc_s_fmt_vbi_cap = vidioc_try_fmt_vbi_cap, | |
2263 | .vidioc_g_audio = vidioc_g_audio, | |
2264 | .vidioc_s_audio = vidioc_s_audio, | |
2265 | .vidioc_cropcap = vidioc_cropcap, | |
2266 | .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap, | |
e0d3bafd | 2267 | .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap, |
cde4362f MCC |
2268 | .vidioc_reqbufs = vidioc_reqbufs, |
2269 | .vidioc_querybuf = vidioc_querybuf, | |
2270 | .vidioc_qbuf = vidioc_qbuf, | |
2271 | .vidioc_dqbuf = vidioc_dqbuf, | |
2272 | .vidioc_s_std = vidioc_s_std, | |
2273 | .vidioc_g_std = vidioc_g_std, | |
2274 | .vidioc_enum_input = vidioc_enum_input, | |
2275 | .vidioc_g_input = vidioc_g_input, | |
2276 | .vidioc_s_input = vidioc_s_input, | |
2277 | .vidioc_queryctrl = vidioc_queryctrl, | |
2278 | .vidioc_g_ctrl = vidioc_g_ctrl, | |
2279 | .vidioc_s_ctrl = vidioc_s_ctrl, | |
2280 | .vidioc_streamon = vidioc_streamon, | |
2281 | .vidioc_streamoff = vidioc_streamoff, | |
2282 | .vidioc_g_tuner = vidioc_g_tuner, | |
2283 | .vidioc_s_tuner = vidioc_s_tuner, | |
2284 | .vidioc_g_frequency = vidioc_g_frequency, | |
2285 | .vidioc_s_frequency = vidioc_s_frequency, | |
e0d3bafd | 2286 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
cde4362f MCC |
2287 | .vidioc_g_register = vidioc_g_register, |
2288 | .vidioc_s_register = vidioc_s_register, | |
e0d3bafd SD |
2289 | #endif |
2290 | #ifdef CONFIG_VIDEO_V4L1_COMPAT | |
cde4362f | 2291 | .vidiocgmbuf = vidiocgmbuf, |
e0d3bafd SD |
2292 | #endif |
2293 | }; | |
2294 | ||
2295 | static struct video_device cx231xx_vbi_template; | |
2296 | ||
2297 | static const struct video_device cx231xx_video_template = { | |
cde4362f MCC |
2298 | .fops = &cx231xx_v4l_fops, |
2299 | .release = video_device_release, | |
2300 | .ioctl_ops = &video_ioctl_ops, | |
2301 | .minor = -1, | |
2302 | .tvnorms = V4L2_STD_ALL, | |
84b5dbf3 | 2303 | .current_norm = V4L2_STD_PAL, |
e0d3bafd SD |
2304 | }; |
2305 | ||
2306 | static const struct v4l2_file_operations radio_fops = { | |
cde4362f MCC |
2307 | .owner = THIS_MODULE, |
2308 | .open = cx231xx_v4l2_open, | |
84b5dbf3 | 2309 | .release = cx231xx_v4l2_close, |
cde4362f | 2310 | .ioctl = video_ioctl2, |
e0d3bafd SD |
2311 | }; |
2312 | ||
2313 | static const struct v4l2_ioctl_ops radio_ioctl_ops = { | |
cde4362f MCC |
2314 | .vidioc_querycap = radio_querycap, |
2315 | .vidioc_g_tuner = radio_g_tuner, | |
2316 | .vidioc_enum_input = radio_enum_input, | |
2317 | .vidioc_g_audio = radio_g_audio, | |
2318 | .vidioc_s_tuner = radio_s_tuner, | |
2319 | .vidioc_s_audio = radio_s_audio, | |
2320 | .vidioc_s_input = radio_s_input, | |
2321 | .vidioc_queryctrl = radio_queryctrl, | |
2322 | .vidioc_g_ctrl = vidioc_g_ctrl, | |
2323 | .vidioc_s_ctrl = vidioc_s_ctrl, | |
84b5dbf3 MCC |
2324 | .vidioc_g_frequency = vidioc_g_frequency, |
2325 | .vidioc_s_frequency = vidioc_s_frequency, | |
e0d3bafd | 2326 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
cde4362f MCC |
2327 | .vidioc_g_register = vidioc_g_register, |
2328 | .vidioc_s_register = vidioc_s_register, | |
e0d3bafd SD |
2329 | #endif |
2330 | }; | |
2331 | ||
2332 | static struct video_device cx231xx_radio_template = { | |
cde4362f MCC |
2333 | .name = "cx231xx-radio", |
2334 | .fops = &radio_fops, | |
84b5dbf3 | 2335 | .ioctl_ops = &radio_ioctl_ops, |
cde4362f | 2336 | .minor = -1, |
e0d3bafd SD |
2337 | }; |
2338 | ||
2339 | /******************************** usb interface ******************************/ | |
2340 | ||
b9255176 SD |
2341 | static struct video_device *cx231xx_vdev_init(struct cx231xx *dev, |
2342 | const struct video_device | |
2343 | *template, const char *type_name) | |
e0d3bafd SD |
2344 | { |
2345 | struct video_device *vfd; | |
2346 | ||
2347 | vfd = video_device_alloc(); | |
2348 | if (NULL == vfd) | |
2349 | return NULL; | |
cde4362f | 2350 | |
e0d3bafd | 2351 | *vfd = *template; |
84b5dbf3 | 2352 | vfd->minor = -1; |
e0d3bafd SD |
2353 | vfd->parent = &dev->udev->dev; |
2354 | vfd->release = video_device_release; | |
2355 | vfd->debug = video_debug; | |
2356 | ||
84b5dbf3 | 2357 | snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name); |
e0d3bafd SD |
2358 | |
2359 | return vfd; | |
2360 | } | |
2361 | ||
2362 | int cx231xx_register_analog_devices(struct cx231xx *dev) | |
2363 | { | |
2364 | int ret; | |
2365 | ||
84b5dbf3 | 2366 | cx231xx_info("%s()\n", __func__); |
e0d3bafd SD |
2367 | |
2368 | cx231xx_info("%s: v4l2 driver version %d.%d.%d\n", | |
84b5dbf3 MCC |
2369 | dev->name, |
2370 | (CX231XX_VERSION_CODE >> 16) & 0xff, | |
2371 | (CX231XX_VERSION_CODE >> 8) & 0xff, | |
2372 | CX231XX_VERSION_CODE & 0xff); | |
e0d3bafd SD |
2373 | |
2374 | /* set default norm */ | |
84b5dbf3 | 2375 | /*dev->norm = cx231xx_video_template.current_norm; */ |
e0d3bafd SD |
2376 | dev->width = norm_maxw(dev); |
2377 | dev->height = norm_maxh(dev); | |
2378 | dev->interlaced = 0; | |
2379 | dev->hscale = 0; | |
2380 | dev->vscale = 0; | |
2381 | ||
2382 | /* Analog specific initialization */ | |
2383 | dev->format = &format[0]; | |
2384 | /* video_mux(dev, dev->video_input); */ | |
2385 | ||
2386 | /* Audio defaults */ | |
2387 | dev->mute = 1; | |
2388 | dev->volume = 0x1f; | |
2389 | ||
2390 | /* enable vbi capturing */ | |
84b5dbf3 | 2391 | /* write code here... */ |
e0d3bafd SD |
2392 | |
2393 | /* allocate and fill video video_device struct */ | |
2394 | dev->vdev = cx231xx_vdev_init(dev, &cx231xx_video_template, "video"); | |
2395 | if (!dev->vdev) { | |
2396 | cx231xx_errdev("cannot allocate video_device.\n"); | |
2397 | return -ENODEV; | |
2398 | } | |
2399 | ||
2400 | /* register v4l2 video video_device */ | |
2401 | ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER, | |
84b5dbf3 | 2402 | video_nr[dev->devno]); |
e0d3bafd | 2403 | if (ret) { |
84b5dbf3 MCC |
2404 | cx231xx_errdev("unable to register video device (error=%i).\n", |
2405 | ret); | |
e0d3bafd SD |
2406 | return ret; |
2407 | } | |
2408 | ||
84b5dbf3 MCC |
2409 | cx231xx_info("%s/0: registered device video%d [v4l2]\n", |
2410 | dev->name, dev->vdev->num); | |
e0d3bafd | 2411 | |
84b5dbf3 MCC |
2412 | /* Initialize VBI template */ |
2413 | memcpy(&cx231xx_vbi_template, &cx231xx_video_template, | |
2414 | sizeof(cx231xx_vbi_template)); | |
2415 | strcpy(cx231xx_vbi_template.name, "cx231xx-vbi"); | |
e0d3bafd SD |
2416 | |
2417 | /* Allocate and fill vbi video_device struct */ | |
2418 | dev->vbi_dev = cx231xx_vdev_init(dev, &cx231xx_vbi_template, "vbi"); | |
2419 | ||
2420 | /* register v4l2 vbi video_device */ | |
2421 | ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, | |
84b5dbf3 | 2422 | vbi_nr[dev->devno]); |
e0d3bafd SD |
2423 | if (ret < 0) { |
2424 | cx231xx_errdev("unable to register vbi device\n"); | |
2425 | return ret; | |
2426 | } | |
2427 | ||
84b5dbf3 MCC |
2428 | cx231xx_info("%s/0: registered device vbi%d\n", |
2429 | dev->name, dev->vbi_dev->num); | |
e0d3bafd SD |
2430 | |
2431 | if (cx231xx_boards[dev->model].radio.type == CX231XX_RADIO) { | |
cde4362f MCC |
2432 | dev->radio_dev = cx231xx_vdev_init(dev, &cx231xx_radio_template, |
2433 | "radio"); | |
e0d3bafd SD |
2434 | if (!dev->radio_dev) { |
2435 | cx231xx_errdev("cannot allocate video_device.\n"); | |
2436 | return -ENODEV; | |
2437 | } | |
2438 | ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO, | |
2439 | radio_nr[dev->devno]); | |
2440 | if (ret < 0) { | |
2441 | cx231xx_errdev("can't register radio device\n"); | |
2442 | return ret; | |
2443 | } | |
2444 | cx231xx_info("Registered radio device as /dev/radio%d\n", | |
84b5dbf3 | 2445 | dev->radio_dev->num); |
e0d3bafd SD |
2446 | } |
2447 | ||
2448 | cx231xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n", | |
84b5dbf3 | 2449 | dev->vdev->num, dev->vbi_dev->num); |
e0d3bafd SD |
2450 | |
2451 | return 0; | |
2452 | } |