Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * device driver for philips saa7134 based TV cards |
| 4 | * video4linux video interface |
| 5 | * |
| 6 | * (c) 2001-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] |
| 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 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/list.h> |
| 25 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/kernel.h> |
| 27 | #include <linux/slab.h> |
Heikki Orsila | 9040b32 | 2007-04-27 12:31:18 -0300 | [diff] [blame] | 28 | #include <linux/sort.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #include "saa7134-reg.h" |
| 31 | #include "saa7134.h" |
Michael Krufky | 5e453dc | 2006-01-09 15:32:31 -0200 | [diff] [blame] | 32 | #include <media/v4l2-common.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Mauro Carvalho Chehab | cd41e28 | 2006-04-09 15:43:41 -0300 | [diff] [blame] | 34 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Mauro Carvalho Chehab | 7943663 | 2005-11-08 21:37:49 -0800 | [diff] [blame] | 35 | /* Include V4L1 specific functions. Should be removed soon */ |
| 36 | #include <linux/videodev.h> |
Mauro Carvalho Chehab | cd41e28 | 2006-04-09 15:43:41 -0300 | [diff] [blame] | 37 | #endif |
Mauro Carvalho Chehab | 7943663 | 2005-11-08 21:37:49 -0800 | [diff] [blame] | 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | /* ------------------------------------------------------------------ */ |
| 40 | |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 41 | unsigned int video_debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | static unsigned int gbuffers = 8; |
Maxim Levitsky | 11f7078 | 2007-09-27 20:44:39 -0300 | [diff] [blame] | 43 | static unsigned int noninterlaced = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | static unsigned int gbufsize = 720*576*4; |
| 45 | static unsigned int gbufsize_max = 720*576*4; |
Hartmut Hackmann | 17b10a7 | 2006-10-02 19:55:07 -0300 | [diff] [blame] | 46 | static char secam[] = "--"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | module_param(video_debug, int, 0644); |
| 48 | MODULE_PARM_DESC(video_debug,"enable debug messages [video]"); |
| 49 | module_param(gbuffers, int, 0444); |
| 50 | MODULE_PARM_DESC(gbuffers,"number of capture buffers, range 2-32"); |
| 51 | module_param(noninterlaced, int, 0644); |
Hartmut Hackmann | d5fdd13 | 2006-07-15 09:45:34 -0300 | [diff] [blame] | 52 | MODULE_PARM_DESC(noninterlaced,"capture non interlaced video"); |
Hartmut Hackmann | 17b10a7 | 2006-10-02 19:55:07 -0300 | [diff] [blame] | 53 | module_param_string(secam, secam, sizeof(secam), 0644); |
| 54 | MODULE_PARM_DESC(secam, "force SECAM variant, either DK,L or Lc"); |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 57 | #define dprintk(fmt, arg...) if (video_debug&0x04) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | printk(KERN_DEBUG "%s/video: " fmt, dev->name , ## arg) |
| 59 | |
| 60 | /* ------------------------------------------------------------------ */ |
Robert W. Boone | 2f8d4f5 | 2005-11-08 21:37:10 -0800 | [diff] [blame] | 61 | /* Defines for Video Output Port Register at address 0x191 */ |
| 62 | |
| 63 | /* Bit 0: VIP code T bit polarity */ |
| 64 | |
| 65 | #define VP_T_CODE_P_NON_INVERTED 0x00 |
| 66 | #define VP_T_CODE_P_INVERTED 0x01 |
| 67 | |
| 68 | /* ------------------------------------------------------------------ */ |
| 69 | /* Defines for Video Output Port Register at address 0x195 */ |
| 70 | |
| 71 | /* Bit 2: Video output clock delay control */ |
| 72 | |
| 73 | #define VP_CLK_CTRL2_NOT_DELAYED 0x00 |
| 74 | #define VP_CLK_CTRL2_DELAYED 0x04 |
| 75 | |
| 76 | /* Bit 1: Video output clock invert control */ |
| 77 | |
| 78 | #define VP_CLK_CTRL1_NON_INVERTED 0x00 |
| 79 | #define VP_CLK_CTRL1_INVERTED 0x02 |
| 80 | |
| 81 | /* ------------------------------------------------------------------ */ |
| 82 | /* Defines for Video Output Port Register at address 0x196 */ |
| 83 | |
| 84 | /* Bits 2 to 0: VSYNC pin video vertical sync type */ |
| 85 | |
| 86 | #define VP_VS_TYPE_MASK 0x07 |
| 87 | |
| 88 | #define VP_VS_TYPE_OFF 0x00 |
| 89 | #define VP_VS_TYPE_V123 0x01 |
| 90 | #define VP_VS_TYPE_V_ITU 0x02 |
| 91 | #define VP_VS_TYPE_VGATE_L 0x03 |
| 92 | #define VP_VS_TYPE_RESERVED1 0x04 |
| 93 | #define VP_VS_TYPE_RESERVED2 0x05 |
| 94 | #define VP_VS_TYPE_F_ITU 0x06 |
| 95 | #define VP_VS_TYPE_SC_FID 0x07 |
| 96 | |
| 97 | /* ------------------------------------------------------------------ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /* data structs for video */ |
| 99 | |
| 100 | static int video_out[][9] = { |
| 101 | [CCIR656] = { 0x00, 0xb1, 0x00, 0xa1, 0x00, 0x04, 0x06, 0x00, 0x00 }, |
| 102 | }; |
| 103 | |
| 104 | static struct saa7134_format formats[] = { |
| 105 | { |
| 106 | .name = "8 bpp gray", |
| 107 | .fourcc = V4L2_PIX_FMT_GREY, |
| 108 | .depth = 8, |
| 109 | .pm = 0x06, |
| 110 | },{ |
| 111 | .name = "15 bpp RGB, le", |
| 112 | .fourcc = V4L2_PIX_FMT_RGB555, |
| 113 | .depth = 16, |
| 114 | .pm = 0x13 | 0x80, |
| 115 | },{ |
| 116 | .name = "15 bpp RGB, be", |
| 117 | .fourcc = V4L2_PIX_FMT_RGB555X, |
| 118 | .depth = 16, |
| 119 | .pm = 0x13 | 0x80, |
| 120 | .bswap = 1, |
| 121 | },{ |
| 122 | .name = "16 bpp RGB, le", |
| 123 | .fourcc = V4L2_PIX_FMT_RGB565, |
| 124 | .depth = 16, |
| 125 | .pm = 0x10 | 0x80, |
| 126 | },{ |
| 127 | .name = "16 bpp RGB, be", |
| 128 | .fourcc = V4L2_PIX_FMT_RGB565X, |
| 129 | .depth = 16, |
| 130 | .pm = 0x10 | 0x80, |
| 131 | .bswap = 1, |
| 132 | },{ |
| 133 | .name = "24 bpp RGB, le", |
| 134 | .fourcc = V4L2_PIX_FMT_BGR24, |
| 135 | .depth = 24, |
| 136 | .pm = 0x11, |
| 137 | },{ |
| 138 | .name = "24 bpp RGB, be", |
| 139 | .fourcc = V4L2_PIX_FMT_RGB24, |
| 140 | .depth = 24, |
| 141 | .pm = 0x11, |
| 142 | .bswap = 1, |
| 143 | },{ |
| 144 | .name = "32 bpp RGB, le", |
| 145 | .fourcc = V4L2_PIX_FMT_BGR32, |
| 146 | .depth = 32, |
| 147 | .pm = 0x12, |
| 148 | },{ |
| 149 | .name = "32 bpp RGB, be", |
| 150 | .fourcc = V4L2_PIX_FMT_RGB32, |
| 151 | .depth = 32, |
| 152 | .pm = 0x12, |
| 153 | .bswap = 1, |
| 154 | .wswap = 1, |
| 155 | },{ |
| 156 | .name = "4:2:2 packed, YUYV", |
| 157 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 158 | .depth = 16, |
| 159 | .pm = 0x00, |
| 160 | .bswap = 1, |
| 161 | .yuv = 1, |
| 162 | },{ |
| 163 | .name = "4:2:2 packed, UYVY", |
| 164 | .fourcc = V4L2_PIX_FMT_UYVY, |
| 165 | .depth = 16, |
| 166 | .pm = 0x00, |
| 167 | .yuv = 1, |
| 168 | },{ |
| 169 | .name = "4:2:2 planar, Y-Cb-Cr", |
| 170 | .fourcc = V4L2_PIX_FMT_YUV422P, |
| 171 | .depth = 16, |
| 172 | .pm = 0x09, |
| 173 | .yuv = 1, |
| 174 | .planar = 1, |
| 175 | .hshift = 1, |
| 176 | .vshift = 0, |
| 177 | },{ |
| 178 | .name = "4:2:0 planar, Y-Cb-Cr", |
| 179 | .fourcc = V4L2_PIX_FMT_YUV420, |
| 180 | .depth = 12, |
| 181 | .pm = 0x0a, |
| 182 | .yuv = 1, |
| 183 | .planar = 1, |
| 184 | .hshift = 1, |
| 185 | .vshift = 1, |
| 186 | },{ |
| 187 | .name = "4:2:0 planar, Y-Cb-Cr", |
| 188 | .fourcc = V4L2_PIX_FMT_YVU420, |
| 189 | .depth = 12, |
| 190 | .pm = 0x0a, |
| 191 | .yuv = 1, |
| 192 | .planar = 1, |
| 193 | .uvswap = 1, |
| 194 | .hshift = 1, |
| 195 | .vshift = 1, |
| 196 | } |
| 197 | }; |
| 198 | #define FORMATS ARRAY_SIZE(formats) |
| 199 | |
| 200 | #define NORM_625_50 \ |
| 201 | .h_start = 0, \ |
| 202 | .h_stop = 719, \ |
| 203 | .video_v_start = 24, \ |
| 204 | .video_v_stop = 311, \ |
Michael Schimek | f246a81 | 2005-06-23 22:04:47 -0700 | [diff] [blame] | 205 | .vbi_v_start_0 = 7, \ |
| 206 | .vbi_v_stop_0 = 22, \ |
| 207 | .vbi_v_start_1 = 319, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | .src_timing = 4 |
| 209 | |
| 210 | #define NORM_525_60 \ |
| 211 | .h_start = 0, \ |
| 212 | .h_stop = 703, \ |
Michael Schimek | f246a81 | 2005-06-23 22:04:47 -0700 | [diff] [blame] | 213 | .video_v_start = 23, \ |
| 214 | .video_v_stop = 262, \ |
| 215 | .vbi_v_start_0 = 10, \ |
| 216 | .vbi_v_stop_0 = 21, \ |
| 217 | .vbi_v_start_1 = 273, \ |
| 218 | .src_timing = 7 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | static struct saa7134_tvnorm tvnorms[] = { |
| 221 | { |
| 222 | .name = "PAL", /* autodetect */ |
| 223 | .id = V4L2_STD_PAL, |
| 224 | NORM_625_50, |
| 225 | |
| 226 | .sync_control = 0x18, |
| 227 | .luma_control = 0x40, |
| 228 | .chroma_ctrl1 = 0x81, |
| 229 | .chroma_gain = 0x2a, |
| 230 | .chroma_ctrl2 = 0x06, |
| 231 | .vgate_misc = 0x1c, |
| 232 | |
| 233 | },{ |
| 234 | .name = "PAL-BG", |
| 235 | .id = V4L2_STD_PAL_BG, |
| 236 | NORM_625_50, |
| 237 | |
| 238 | .sync_control = 0x18, |
| 239 | .luma_control = 0x40, |
| 240 | .chroma_ctrl1 = 0x81, |
| 241 | .chroma_gain = 0x2a, |
| 242 | .chroma_ctrl2 = 0x06, |
| 243 | .vgate_misc = 0x1c, |
| 244 | |
| 245 | },{ |
| 246 | .name = "PAL-I", |
| 247 | .id = V4L2_STD_PAL_I, |
| 248 | NORM_625_50, |
| 249 | |
| 250 | .sync_control = 0x18, |
| 251 | .luma_control = 0x40, |
| 252 | .chroma_ctrl1 = 0x81, |
| 253 | .chroma_gain = 0x2a, |
| 254 | .chroma_ctrl2 = 0x06, |
| 255 | .vgate_misc = 0x1c, |
| 256 | |
| 257 | },{ |
| 258 | .name = "PAL-DK", |
| 259 | .id = V4L2_STD_PAL_DK, |
| 260 | NORM_625_50, |
| 261 | |
| 262 | .sync_control = 0x18, |
| 263 | .luma_control = 0x40, |
| 264 | .chroma_ctrl1 = 0x81, |
| 265 | .chroma_gain = 0x2a, |
| 266 | .chroma_ctrl2 = 0x06, |
| 267 | .vgate_misc = 0x1c, |
| 268 | |
| 269 | },{ |
| 270 | .name = "NTSC", |
| 271 | .id = V4L2_STD_NTSC, |
| 272 | NORM_525_60, |
| 273 | |
| 274 | .sync_control = 0x59, |
| 275 | .luma_control = 0x40, |
| 276 | .chroma_ctrl1 = 0x89, |
| 277 | .chroma_gain = 0x2a, |
| 278 | .chroma_ctrl2 = 0x0e, |
| 279 | .vgate_misc = 0x18, |
| 280 | |
| 281 | },{ |
| 282 | .name = "SECAM", |
| 283 | .id = V4L2_STD_SECAM, |
| 284 | NORM_625_50, |
| 285 | |
Hartmut Hackmann | 17b10a7 | 2006-10-02 19:55:07 -0300 | [diff] [blame] | 286 | .sync_control = 0x18, |
| 287 | .luma_control = 0x1b, |
| 288 | .chroma_ctrl1 = 0xd1, |
| 289 | .chroma_gain = 0x80, |
| 290 | .chroma_ctrl2 = 0x00, |
| 291 | .vgate_misc = 0x1c, |
| 292 | |
| 293 | },{ |
| 294 | .name = "SECAM-DK", |
| 295 | .id = V4L2_STD_SECAM_DK, |
| 296 | NORM_625_50, |
| 297 | |
| 298 | .sync_control = 0x18, |
| 299 | .luma_control = 0x1b, |
| 300 | .chroma_ctrl1 = 0xd1, |
| 301 | .chroma_gain = 0x80, |
| 302 | .chroma_ctrl2 = 0x00, |
| 303 | .vgate_misc = 0x1c, |
| 304 | |
| 305 | },{ |
| 306 | .name = "SECAM-L", |
| 307 | .id = V4L2_STD_SECAM_L, |
| 308 | NORM_625_50, |
| 309 | |
| 310 | .sync_control = 0x18, |
| 311 | .luma_control = 0x1b, |
| 312 | .chroma_ctrl1 = 0xd1, |
| 313 | .chroma_gain = 0x80, |
| 314 | .chroma_ctrl2 = 0x00, |
| 315 | .vgate_misc = 0x1c, |
| 316 | |
| 317 | },{ |
| 318 | .name = "SECAM-Lc", |
| 319 | .id = V4L2_STD_SECAM_LC, |
| 320 | NORM_625_50, |
| 321 | |
| 322 | .sync_control = 0x18, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | .luma_control = 0x1b, |
| 324 | .chroma_ctrl1 = 0xd1, |
| 325 | .chroma_gain = 0x80, |
| 326 | .chroma_ctrl2 = 0x00, |
| 327 | .vgate_misc = 0x1c, |
| 328 | |
| 329 | },{ |
| 330 | .name = "PAL-M", |
| 331 | .id = V4L2_STD_PAL_M, |
| 332 | NORM_525_60, |
| 333 | |
| 334 | .sync_control = 0x59, |
| 335 | .luma_control = 0x40, |
| 336 | .chroma_ctrl1 = 0xb9, |
| 337 | .chroma_gain = 0x2a, |
| 338 | .chroma_ctrl2 = 0x0e, |
| 339 | .vgate_misc = 0x18, |
| 340 | |
| 341 | },{ |
| 342 | .name = "PAL-Nc", |
| 343 | .id = V4L2_STD_PAL_Nc, |
| 344 | NORM_625_50, |
| 345 | |
| 346 | .sync_control = 0x18, |
| 347 | .luma_control = 0x40, |
| 348 | .chroma_ctrl1 = 0xa1, |
| 349 | .chroma_gain = 0x2a, |
| 350 | .chroma_ctrl2 = 0x06, |
| 351 | .vgate_misc = 0x1c, |
| 352 | |
| 353 | },{ |
| 354 | .name = "PAL-60", |
| 355 | .id = V4L2_STD_PAL_60, |
| 356 | |
| 357 | .h_start = 0, |
| 358 | .h_stop = 719, |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 359 | .video_v_start = 23, |
| 360 | .video_v_stop = 262, |
| 361 | .vbi_v_start_0 = 10, |
| 362 | .vbi_v_stop_0 = 21, |
| 363 | .vbi_v_start_1 = 273, |
| 364 | .src_timing = 7, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
| 366 | .sync_control = 0x18, |
| 367 | .luma_control = 0x40, |
| 368 | .chroma_ctrl1 = 0x81, |
| 369 | .chroma_gain = 0x2a, |
| 370 | .chroma_ctrl2 = 0x06, |
| 371 | .vgate_misc = 0x1c, |
| 372 | } |
| 373 | }; |
| 374 | #define TVNORMS ARRAY_SIZE(tvnorms) |
| 375 | |
| 376 | #define V4L2_CID_PRIVATE_INVERT (V4L2_CID_PRIVATE_BASE + 0) |
| 377 | #define V4L2_CID_PRIVATE_Y_ODD (V4L2_CID_PRIVATE_BASE + 1) |
| 378 | #define V4L2_CID_PRIVATE_Y_EVEN (V4L2_CID_PRIVATE_BASE + 2) |
| 379 | #define V4L2_CID_PRIVATE_AUTOMUTE (V4L2_CID_PRIVATE_BASE + 3) |
| 380 | #define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 4) |
| 381 | |
| 382 | static const struct v4l2_queryctrl no_ctrl = { |
| 383 | .name = "42", |
| 384 | .flags = V4L2_CTRL_FLAG_DISABLED, |
| 385 | }; |
| 386 | static const struct v4l2_queryctrl video_ctrls[] = { |
| 387 | /* --- video --- */ |
| 388 | { |
| 389 | .id = V4L2_CID_BRIGHTNESS, |
| 390 | .name = "Brightness", |
| 391 | .minimum = 0, |
| 392 | .maximum = 255, |
| 393 | .step = 1, |
| 394 | .default_value = 128, |
| 395 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 396 | },{ |
| 397 | .id = V4L2_CID_CONTRAST, |
| 398 | .name = "Contrast", |
| 399 | .minimum = 0, |
| 400 | .maximum = 127, |
| 401 | .step = 1, |
| 402 | .default_value = 68, |
| 403 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 404 | },{ |
| 405 | .id = V4L2_CID_SATURATION, |
| 406 | .name = "Saturation", |
| 407 | .minimum = 0, |
| 408 | .maximum = 127, |
| 409 | .step = 1, |
| 410 | .default_value = 64, |
| 411 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 412 | },{ |
| 413 | .id = V4L2_CID_HUE, |
| 414 | .name = "Hue", |
| 415 | .minimum = -128, |
| 416 | .maximum = 127, |
| 417 | .step = 1, |
| 418 | .default_value = 0, |
| 419 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 420 | },{ |
Michael Schimek | f246a81 | 2005-06-23 22:04:47 -0700 | [diff] [blame] | 421 | .id = V4L2_CID_HFLIP, |
| 422 | .name = "Mirror", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | .minimum = 0, |
| 424 | .maximum = 1, |
| 425 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 426 | }, |
| 427 | /* --- audio --- */ |
| 428 | { |
| 429 | .id = V4L2_CID_AUDIO_MUTE, |
| 430 | .name = "Mute", |
| 431 | .minimum = 0, |
| 432 | .maximum = 1, |
| 433 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 434 | },{ |
| 435 | .id = V4L2_CID_AUDIO_VOLUME, |
| 436 | .name = "Volume", |
| 437 | .minimum = -15, |
| 438 | .maximum = 15, |
| 439 | .step = 1, |
| 440 | .default_value = 0, |
| 441 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 442 | }, |
| 443 | /* --- private --- */ |
| 444 | { |
| 445 | .id = V4L2_CID_PRIVATE_INVERT, |
| 446 | .name = "Invert", |
| 447 | .minimum = 0, |
| 448 | .maximum = 1, |
| 449 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 450 | },{ |
| 451 | .id = V4L2_CID_PRIVATE_Y_ODD, |
| 452 | .name = "y offset odd field", |
| 453 | .minimum = 0, |
| 454 | .maximum = 128, |
| 455 | .default_value = 0, |
| 456 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 457 | },{ |
| 458 | .id = V4L2_CID_PRIVATE_Y_EVEN, |
| 459 | .name = "y offset even field", |
| 460 | .minimum = 0, |
| 461 | .maximum = 128, |
| 462 | .default_value = 0, |
| 463 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 464 | },{ |
| 465 | .id = V4L2_CID_PRIVATE_AUTOMUTE, |
| 466 | .name = "automute", |
| 467 | .minimum = 0, |
| 468 | .maximum = 1, |
| 469 | .default_value = 1, |
| 470 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 471 | } |
| 472 | }; |
| 473 | static const unsigned int CTRLS = ARRAY_SIZE(video_ctrls); |
| 474 | |
| 475 | static const struct v4l2_queryctrl* ctrl_by_id(unsigned int id) |
| 476 | { |
| 477 | unsigned int i; |
| 478 | |
| 479 | for (i = 0; i < CTRLS; i++) |
| 480 | if (video_ctrls[i].id == id) |
| 481 | return video_ctrls+i; |
| 482 | return NULL; |
| 483 | } |
| 484 | |
| 485 | static struct saa7134_format* format_by_fourcc(unsigned int fourcc) |
| 486 | { |
| 487 | unsigned int i; |
| 488 | |
| 489 | for (i = 0; i < FORMATS; i++) |
| 490 | if (formats[i].fourcc == fourcc) |
| 491 | return formats+i; |
| 492 | return NULL; |
| 493 | } |
| 494 | |
| 495 | /* ----------------------------------------------------------------------- */ |
| 496 | /* resource management */ |
| 497 | |
| 498 | static int res_get(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bit) |
| 499 | { |
| 500 | if (fh->resources & bit) |
| 501 | /* have it already allocated */ |
| 502 | return 1; |
| 503 | |
| 504 | /* is it free? */ |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 505 | mutex_lock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | if (dev->resources & bit) { |
| 507 | /* no, someone else uses it */ |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 508 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | return 0; |
| 510 | } |
| 511 | /* it's free, grab it */ |
| 512 | fh->resources |= bit; |
| 513 | dev->resources |= bit; |
| 514 | dprintk("res: get %d\n",bit); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 515 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | return 1; |
| 517 | } |
| 518 | |
Heikki Orsila | 9040b32 | 2007-04-27 12:31:18 -0300 | [diff] [blame] | 519 | static int res_check(struct saa7134_fh *fh, unsigned int bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | { |
| 521 | return (fh->resources & bit); |
| 522 | } |
| 523 | |
Heikki Orsila | 9040b32 | 2007-04-27 12:31:18 -0300 | [diff] [blame] | 524 | static int res_locked(struct saa7134_dev *dev, unsigned int bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | { |
| 526 | return (dev->resources & bit); |
| 527 | } |
| 528 | |
| 529 | static |
| 530 | void res_free(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bits) |
| 531 | { |
Eric Sesterhenn | ae24601 | 2006-03-13 13:17:11 -0300 | [diff] [blame] | 532 | BUG_ON((fh->resources & bits) != bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 534 | mutex_lock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | fh->resources &= ~bits; |
| 536 | dev->resources &= ~bits; |
| 537 | dprintk("res: put %d\n",bits); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 538 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /* ------------------------------------------------------------------ */ |
| 542 | |
Adrian Bunk | b02044d | 2007-10-24 13:23:14 -0300 | [diff] [blame] | 543 | static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | dprintk("set tv norm = %s\n",norm->name); |
| 546 | dev->tvnorm = norm; |
| 547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | /* setup cropping */ |
| 549 | dev->crop_bounds.left = norm->h_start; |
| 550 | dev->crop_defrect.left = norm->h_start; |
| 551 | dev->crop_bounds.width = norm->h_stop - norm->h_start +1; |
| 552 | dev->crop_defrect.width = norm->h_stop - norm->h_start +1; |
| 553 | |
Michael Schimek | f246a81 | 2005-06-23 22:04:47 -0700 | [diff] [blame] | 554 | dev->crop_bounds.top = (norm->vbi_v_stop_0+1)*2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | dev->crop_defrect.top = norm->video_v_start*2; |
| 556 | dev->crop_bounds.height = ((norm->id & V4L2_STD_525_60) ? 524 : 624) |
| 557 | - dev->crop_bounds.top; |
| 558 | dev->crop_defrect.height = (norm->video_v_stop - norm->video_v_start +1)*2; |
| 559 | |
| 560 | dev->crop_current = dev->crop_defrect; |
| 561 | |
Maxim Levitsky | c458473 | 2007-10-12 00:57:15 -0300 | [diff] [blame] | 562 | saa7134_set_tvnorm_hw(dev); |
Maxim Levitsky | cb71201 | 2007-09-27 20:34:25 -0300 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | static void video_mux(struct saa7134_dev *dev, int input) |
| 566 | { |
| 567 | dprintk("video input = %d [%s]\n", input, card_in(dev, input).name); |
| 568 | dev->ctl_input = input; |
| 569 | set_tvnorm(dev, dev->tvnorm); |
| 570 | saa7134_tvaudio_setinput(dev, &card_in(dev, input)); |
| 571 | } |
| 572 | |
Maxim Levitsky | c458473 | 2007-10-12 00:57:15 -0300 | [diff] [blame] | 573 | |
| 574 | static void saa7134_set_decoder(struct saa7134_dev *dev) |
Maxim Levitsky | cb71201 | 2007-09-27 20:34:25 -0300 | [diff] [blame] | 575 | { |
| 576 | int luma_control, sync_control, mux; |
| 577 | |
| 578 | struct saa7134_tvnorm *norm = dev->tvnorm; |
| 579 | mux = card_in(dev, dev->ctl_input).vmux; |
| 580 | |
| 581 | luma_control = norm->luma_control; |
| 582 | sync_control = norm->sync_control; |
| 583 | |
| 584 | if (mux > 5) |
| 585 | luma_control |= 0x80; /* svideo */ |
| 586 | if (noninterlaced || dev->nosignal) |
| 587 | sync_control |= 0x20; |
| 588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | /* setup video decoder */ |
| 590 | saa_writeb(SAA7134_INCR_DELAY, 0x08); |
| 591 | saa_writeb(SAA7134_ANALOG_IN_CTRL1, 0xc0 | mux); |
| 592 | saa_writeb(SAA7134_ANALOG_IN_CTRL2, 0x00); |
| 593 | |
| 594 | saa_writeb(SAA7134_ANALOG_IN_CTRL3, 0x90); |
| 595 | saa_writeb(SAA7134_ANALOG_IN_CTRL4, 0x90); |
| 596 | saa_writeb(SAA7134_HSYNC_START, 0xeb); |
| 597 | saa_writeb(SAA7134_HSYNC_STOP, 0xe0); |
| 598 | saa_writeb(SAA7134_SOURCE_TIMING1, norm->src_timing); |
| 599 | |
| 600 | saa_writeb(SAA7134_SYNC_CTRL, sync_control); |
| 601 | saa_writeb(SAA7134_LUMA_CTRL, luma_control); |
| 602 | saa_writeb(SAA7134_DEC_LUMA_BRIGHT, dev->ctl_bright); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
Maxim Levitsky | f5a1ac6 | 2007-09-27 20:34:20 -0300 | [diff] [blame] | 604 | saa_writeb(SAA7134_DEC_LUMA_CONTRAST, |
| 605 | dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast); |
| 606 | |
| 607 | saa_writeb(SAA7134_DEC_CHROMA_SATURATION, |
| 608 | dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation); |
| 609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | saa_writeb(SAA7134_DEC_CHROMA_HUE, dev->ctl_hue); |
| 611 | saa_writeb(SAA7134_CHROMA_CTRL1, norm->chroma_ctrl1); |
| 612 | saa_writeb(SAA7134_CHROMA_GAIN, norm->chroma_gain); |
| 613 | |
| 614 | saa_writeb(SAA7134_CHROMA_CTRL2, norm->chroma_ctrl2); |
| 615 | saa_writeb(SAA7134_MODE_DELAY_CTRL, 0x00); |
| 616 | |
| 617 | saa_writeb(SAA7134_ANALOG_ADC, 0x01); |
| 618 | saa_writeb(SAA7134_VGATE_START, 0x11); |
| 619 | saa_writeb(SAA7134_VGATE_STOP, 0xfe); |
| 620 | saa_writeb(SAA7134_MISC_VGATE_MSB, norm->vgate_misc); |
| 621 | saa_writeb(SAA7134_RAW_DATA_GAIN, 0x40); |
| 622 | saa_writeb(SAA7134_RAW_DATA_OFFSET, 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Maxim Levitsky | c458473 | 2007-10-12 00:57:15 -0300 | [diff] [blame] | 625 | void saa7134_set_tvnorm_hw(struct saa7134_dev *dev) |
| 626 | { |
| 627 | saa7134_set_decoder(dev); |
| 628 | |
| 629 | if (card_in(dev, dev->ctl_input).tv) { |
| 630 | if ((card(dev).tuner_type == TUNER_PHILIPS_TDA8290) |
| 631 | && ((card(dev).tuner_config == 1) |
| 632 | || (card(dev).tuner_config == 2))) |
| 633 | saa7134_set_gpio(dev, 22, 5); |
| 634 | saa7134_i2c_call_clients(dev, VIDIOC_S_STD, &dev->tvnorm->id); |
| 635 | } |
| 636 | } |
| 637 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale) |
| 639 | { |
| 640 | static const struct { |
| 641 | int xpsc; |
| 642 | int xacl; |
| 643 | int xc2_1; |
| 644 | int xdcg; |
| 645 | int vpfy; |
| 646 | } vals[] = { |
| 647 | /* XPSC XACL XC2_1 XDCG VPFY */ |
| 648 | { 1, 0, 0, 0, 0 }, |
| 649 | { 2, 2, 1, 2, 2 }, |
| 650 | { 3, 4, 1, 3, 2 }, |
| 651 | { 4, 8, 1, 4, 2 }, |
| 652 | { 5, 8, 1, 4, 2 }, |
| 653 | { 6, 8, 1, 4, 3 }, |
| 654 | { 7, 8, 1, 4, 3 }, |
| 655 | { 8, 15, 0, 4, 3 }, |
| 656 | { 9, 15, 0, 4, 3 }, |
| 657 | { 10, 16, 1, 5, 3 }, |
| 658 | }; |
| 659 | static const int count = ARRAY_SIZE(vals); |
| 660 | int i; |
| 661 | |
| 662 | for (i = 0; i < count; i++) |
| 663 | if (vals[i].xpsc == prescale) |
| 664 | break; |
| 665 | if (i == count) |
| 666 | return; |
| 667 | |
| 668 | saa_writeb(SAA7134_H_PRESCALE(task), vals[i].xpsc); |
| 669 | saa_writeb(SAA7134_ACC_LENGTH(task), vals[i].xacl); |
| 670 | saa_writeb(SAA7134_LEVEL_CTRL(task), |
| 671 | (vals[i].xc2_1 << 3) | (vals[i].xdcg)); |
| 672 | saa_andorb(SAA7134_FIR_PREFILTER_CTRL(task), 0x0f, |
| 673 | (vals[i].vpfy << 2) | vals[i].vpfy); |
| 674 | } |
| 675 | |
| 676 | static void set_v_scale(struct saa7134_dev *dev, int task, int yscale) |
| 677 | { |
| 678 | int val,mirror; |
| 679 | |
| 680 | saa_writeb(SAA7134_V_SCALE_RATIO1(task), yscale & 0xff); |
| 681 | saa_writeb(SAA7134_V_SCALE_RATIO2(task), yscale >> 8); |
| 682 | |
| 683 | mirror = (dev->ctl_mirror) ? 0x02 : 0x00; |
| 684 | if (yscale < 2048) { |
| 685 | /* LPI */ |
| 686 | dprintk("yscale LPI yscale=%d\n",yscale); |
| 687 | saa_writeb(SAA7134_V_FILTER(task), 0x00 | mirror); |
| 688 | saa_writeb(SAA7134_LUMA_CONTRAST(task), 0x40); |
| 689 | saa_writeb(SAA7134_CHROMA_SATURATION(task), 0x40); |
| 690 | } else { |
| 691 | /* ACM */ |
| 692 | val = 0x40 * 1024 / yscale; |
| 693 | dprintk("yscale ACM yscale=%d val=0x%x\n",yscale,val); |
| 694 | saa_writeb(SAA7134_V_FILTER(task), 0x01 | mirror); |
| 695 | saa_writeb(SAA7134_LUMA_CONTRAST(task), val); |
| 696 | saa_writeb(SAA7134_CHROMA_SATURATION(task), val); |
| 697 | } |
| 698 | saa_writeb(SAA7134_LUMA_BRIGHT(task), 0x80); |
| 699 | } |
| 700 | |
| 701 | static void set_size(struct saa7134_dev *dev, int task, |
| 702 | int width, int height, int interlace) |
| 703 | { |
| 704 | int prescale,xscale,yscale,y_even,y_odd; |
| 705 | int h_start, h_stop, v_start, v_stop; |
| 706 | int div = interlace ? 2 : 1; |
| 707 | |
| 708 | /* setup video scaler */ |
| 709 | h_start = dev->crop_current.left; |
| 710 | v_start = dev->crop_current.top/2; |
| 711 | h_stop = (dev->crop_current.left + dev->crop_current.width -1); |
| 712 | v_stop = (dev->crop_current.top + dev->crop_current.height -1)/2; |
| 713 | |
| 714 | saa_writeb(SAA7134_VIDEO_H_START1(task), h_start & 0xff); |
| 715 | saa_writeb(SAA7134_VIDEO_H_START2(task), h_start >> 8); |
| 716 | saa_writeb(SAA7134_VIDEO_H_STOP1(task), h_stop & 0xff); |
| 717 | saa_writeb(SAA7134_VIDEO_H_STOP2(task), h_stop >> 8); |
| 718 | saa_writeb(SAA7134_VIDEO_V_START1(task), v_start & 0xff); |
| 719 | saa_writeb(SAA7134_VIDEO_V_START2(task), v_start >> 8); |
| 720 | saa_writeb(SAA7134_VIDEO_V_STOP1(task), v_stop & 0xff); |
| 721 | saa_writeb(SAA7134_VIDEO_V_STOP2(task), v_stop >> 8); |
| 722 | |
| 723 | prescale = dev->crop_current.width / width; |
| 724 | if (0 == prescale) |
| 725 | prescale = 1; |
| 726 | xscale = 1024 * dev->crop_current.width / prescale / width; |
| 727 | yscale = 512 * div * dev->crop_current.height / height; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 728 | dprintk("prescale=%d xscale=%d yscale=%d\n",prescale,xscale,yscale); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | set_h_prescale(dev,task,prescale); |
| 730 | saa_writeb(SAA7134_H_SCALE_INC1(task), xscale & 0xff); |
| 731 | saa_writeb(SAA7134_H_SCALE_INC2(task), xscale >> 8); |
| 732 | set_v_scale(dev,task,yscale); |
| 733 | |
| 734 | saa_writeb(SAA7134_VIDEO_PIXELS1(task), width & 0xff); |
| 735 | saa_writeb(SAA7134_VIDEO_PIXELS2(task), width >> 8); |
| 736 | saa_writeb(SAA7134_VIDEO_LINES1(task), height/div & 0xff); |
| 737 | saa_writeb(SAA7134_VIDEO_LINES2(task), height/div >> 8); |
| 738 | |
| 739 | /* deinterlace y offsets */ |
| 740 | y_odd = dev->ctl_y_odd; |
| 741 | y_even = dev->ctl_y_even; |
| 742 | saa_writeb(SAA7134_V_PHASE_OFFSET0(task), y_odd); |
| 743 | saa_writeb(SAA7134_V_PHASE_OFFSET1(task), y_even); |
| 744 | saa_writeb(SAA7134_V_PHASE_OFFSET2(task), y_odd); |
| 745 | saa_writeb(SAA7134_V_PHASE_OFFSET3(task), y_even); |
| 746 | } |
| 747 | |
| 748 | /* ------------------------------------------------------------------ */ |
| 749 | |
| 750 | struct cliplist { |
| 751 | __u16 position; |
| 752 | __u8 enable; |
| 753 | __u8 disable; |
| 754 | }; |
| 755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | static void set_cliplist(struct saa7134_dev *dev, int reg, |
| 757 | struct cliplist *cl, int entries, char *name) |
| 758 | { |
| 759 | __u8 winbits = 0; |
| 760 | int i; |
| 761 | |
| 762 | for (i = 0; i < entries; i++) { |
| 763 | winbits |= cl[i].enable; |
| 764 | winbits &= ~cl[i].disable; |
| 765 | if (i < 15 && cl[i].position == cl[i+1].position) |
| 766 | continue; |
| 767 | saa_writeb(reg + 0, winbits); |
| 768 | saa_writeb(reg + 2, cl[i].position & 0xff); |
| 769 | saa_writeb(reg + 3, cl[i].position >> 8); |
| 770 | dprintk("clip: %s winbits=%02x pos=%d\n", |
| 771 | name,winbits,cl[i].position); |
| 772 | reg += 8; |
| 773 | } |
| 774 | for (; reg < 0x400; reg += 8) { |
| 775 | saa_writeb(reg+ 0, 0); |
| 776 | saa_writeb(reg + 1, 0); |
| 777 | saa_writeb(reg + 2, 0); |
| 778 | saa_writeb(reg + 3, 0); |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | static int clip_range(int val) |
| 783 | { |
| 784 | if (val < 0) |
| 785 | val = 0; |
| 786 | return val; |
| 787 | } |
| 788 | |
Heikki Orsila | 9040b32 | 2007-04-27 12:31:18 -0300 | [diff] [blame] | 789 | /* Sort into smallest position first order */ |
| 790 | static int cliplist_cmp(const void *a, const void *b) |
| 791 | { |
| 792 | const struct cliplist *cla = a; |
| 793 | const struct cliplist *clb = b; |
| 794 | if (cla->position < clb->position) |
| 795 | return -1; |
| 796 | if (cla->position > clb->position) |
| 797 | return 1; |
| 798 | return 0; |
| 799 | } |
| 800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | static int setup_clipping(struct saa7134_dev *dev, struct v4l2_clip *clips, |
| 802 | int nclips, int interlace) |
| 803 | { |
| 804 | struct cliplist col[16], row[16]; |
Heikki Orsila | 9040b32 | 2007-04-27 12:31:18 -0300 | [diff] [blame] | 805 | int cols = 0, rows = 0, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | int div = interlace ? 2 : 1; |
| 807 | |
Heikki Orsila | 9040b32 | 2007-04-27 12:31:18 -0300 | [diff] [blame] | 808 | memset(col, 0, sizeof(col)); |
| 809 | memset(row, 0, sizeof(row)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | for (i = 0; i < nclips && i < 8; i++) { |
| 811 | col[cols].position = clip_range(clips[i].c.left); |
| 812 | col[cols].enable = (1 << i); |
| 813 | cols++; |
| 814 | col[cols].position = clip_range(clips[i].c.left+clips[i].c.width); |
| 815 | col[cols].disable = (1 << i); |
| 816 | cols++; |
| 817 | row[rows].position = clip_range(clips[i].c.top / div); |
| 818 | row[rows].enable = (1 << i); |
| 819 | rows++; |
| 820 | row[rows].position = clip_range((clips[i].c.top + clips[i].c.height) |
| 821 | / div); |
| 822 | row[rows].disable = (1 << i); |
| 823 | rows++; |
| 824 | } |
Heikki Orsila | 9040b32 | 2007-04-27 12:31:18 -0300 | [diff] [blame] | 825 | sort(col, cols, sizeof col[0], cliplist_cmp, NULL); |
| 826 | sort(row, rows, sizeof row[0], cliplist_cmp, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | set_cliplist(dev,0x380,col,cols,"cols"); |
| 828 | set_cliplist(dev,0x384,row,rows,"rows"); |
| 829 | return 0; |
| 830 | } |
| 831 | |
| 832 | static int verify_preview(struct saa7134_dev *dev, struct v4l2_window *win) |
| 833 | { |
| 834 | enum v4l2_field field; |
| 835 | int maxw, maxh; |
| 836 | |
| 837 | if (NULL == dev->ovbuf.base) |
| 838 | return -EINVAL; |
| 839 | if (NULL == dev->ovfmt) |
| 840 | return -EINVAL; |
| 841 | if (win->w.width < 48 || win->w.height < 32) |
| 842 | return -EINVAL; |
| 843 | if (win->clipcount > 2048) |
| 844 | return -EINVAL; |
| 845 | |
| 846 | field = win->field; |
| 847 | maxw = dev->crop_current.width; |
| 848 | maxh = dev->crop_current.height; |
| 849 | |
| 850 | if (V4L2_FIELD_ANY == field) { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 851 | field = (win->w.height > maxh/2) |
| 852 | ? V4L2_FIELD_INTERLACED |
| 853 | : V4L2_FIELD_TOP; |
| 854 | } |
| 855 | switch (field) { |
| 856 | case V4L2_FIELD_TOP: |
| 857 | case V4L2_FIELD_BOTTOM: |
| 858 | maxh = maxh / 2; |
| 859 | break; |
| 860 | case V4L2_FIELD_INTERLACED: |
| 861 | break; |
| 862 | default: |
| 863 | return -EINVAL; |
| 864 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | win->field = field; |
| 867 | if (win->w.width > maxw) |
| 868 | win->w.width = maxw; |
| 869 | if (win->w.height > maxh) |
| 870 | win->w.height = maxh; |
| 871 | return 0; |
| 872 | } |
| 873 | |
| 874 | static int start_preview(struct saa7134_dev *dev, struct saa7134_fh *fh) |
| 875 | { |
| 876 | unsigned long base,control,bpl; |
| 877 | int err; |
| 878 | |
| 879 | err = verify_preview(dev,&fh->win); |
| 880 | if (0 != err) |
| 881 | return err; |
| 882 | |
| 883 | dev->ovfield = fh->win.field; |
| 884 | dprintk("start_preview %dx%d+%d+%d %s field=%s\n", |
| 885 | fh->win.w.width,fh->win.w.height, |
| 886 | fh->win.w.left,fh->win.w.top, |
| 887 | dev->ovfmt->name,v4l2_field_names[dev->ovfield]); |
| 888 | |
| 889 | /* setup window + clipping */ |
| 890 | set_size(dev,TASK_B,fh->win.w.width,fh->win.w.height, |
| 891 | V4L2_FIELD_HAS_BOTH(dev->ovfield)); |
| 892 | setup_clipping(dev,fh->clips,fh->nclips, |
| 893 | V4L2_FIELD_HAS_BOTH(dev->ovfield)); |
| 894 | if (dev->ovfmt->yuv) |
| 895 | saa_andorb(SAA7134_DATA_PATH(TASK_B), 0x3f, 0x03); |
| 896 | else |
| 897 | saa_andorb(SAA7134_DATA_PATH(TASK_B), 0x3f, 0x01); |
| 898 | saa_writeb(SAA7134_OFMT_VIDEO_B, dev->ovfmt->pm | 0x20); |
| 899 | |
| 900 | /* dma: setup channel 1 (= Video Task B) */ |
| 901 | base = (unsigned long)dev->ovbuf.base; |
| 902 | base += dev->ovbuf.fmt.bytesperline * fh->win.w.top; |
| 903 | base += dev->ovfmt->depth/8 * fh->win.w.left; |
| 904 | bpl = dev->ovbuf.fmt.bytesperline; |
| 905 | control = SAA7134_RS_CONTROL_BURST_16; |
| 906 | if (dev->ovfmt->bswap) |
| 907 | control |= SAA7134_RS_CONTROL_BSWAP; |
| 908 | if (dev->ovfmt->wswap) |
| 909 | control |= SAA7134_RS_CONTROL_WSWAP; |
| 910 | if (V4L2_FIELD_HAS_BOTH(dev->ovfield)) { |
| 911 | saa_writel(SAA7134_RS_BA1(1),base); |
| 912 | saa_writel(SAA7134_RS_BA2(1),base+bpl); |
| 913 | saa_writel(SAA7134_RS_PITCH(1),bpl*2); |
| 914 | saa_writel(SAA7134_RS_CONTROL(1),control); |
| 915 | } else { |
| 916 | saa_writel(SAA7134_RS_BA1(1),base); |
| 917 | saa_writel(SAA7134_RS_BA2(1),base); |
| 918 | saa_writel(SAA7134_RS_PITCH(1),bpl); |
| 919 | saa_writel(SAA7134_RS_CONTROL(1),control); |
| 920 | } |
| 921 | |
| 922 | /* start dma */ |
| 923 | dev->ovenable = 1; |
| 924 | saa7134_set_dmabits(dev); |
| 925 | |
| 926 | return 0; |
| 927 | } |
| 928 | |
| 929 | static int stop_preview(struct saa7134_dev *dev, struct saa7134_fh *fh) |
| 930 | { |
| 931 | dev->ovenable = 0; |
| 932 | saa7134_set_dmabits(dev); |
| 933 | return 0; |
| 934 | } |
| 935 | |
| 936 | /* ------------------------------------------------------------------ */ |
| 937 | |
| 938 | static int buffer_activate(struct saa7134_dev *dev, |
| 939 | struct saa7134_buf *buf, |
| 940 | struct saa7134_buf *next) |
| 941 | { |
| 942 | unsigned long base,control,bpl; |
| 943 | unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */ |
| 944 | |
| 945 | dprintk("buffer_activate buf=%p\n",buf); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 946 | buf->vb.state = VIDEOBUF_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | buf->top_seen = 0; |
| 948 | |
| 949 | set_size(dev,TASK_A,buf->vb.width,buf->vb.height, |
| 950 | V4L2_FIELD_HAS_BOTH(buf->vb.field)); |
| 951 | if (buf->fmt->yuv) |
| 952 | saa_andorb(SAA7134_DATA_PATH(TASK_A), 0x3f, 0x03); |
| 953 | else |
| 954 | saa_andorb(SAA7134_DATA_PATH(TASK_A), 0x3f, 0x01); |
| 955 | saa_writeb(SAA7134_OFMT_VIDEO_A, buf->fmt->pm); |
| 956 | |
| 957 | /* DMA: setup channel 0 (= Video Task A0) */ |
| 958 | base = saa7134_buffer_base(buf); |
| 959 | if (buf->fmt->planar) |
| 960 | bpl = buf->vb.width; |
| 961 | else |
| 962 | bpl = (buf->vb.width * buf->fmt->depth) / 8; |
| 963 | control = SAA7134_RS_CONTROL_BURST_16 | |
| 964 | SAA7134_RS_CONTROL_ME | |
| 965 | (buf->pt->dma >> 12); |
| 966 | if (buf->fmt->bswap) |
| 967 | control |= SAA7134_RS_CONTROL_BSWAP; |
| 968 | if (buf->fmt->wswap) |
| 969 | control |= SAA7134_RS_CONTROL_WSWAP; |
| 970 | if (V4L2_FIELD_HAS_BOTH(buf->vb.field)) { |
| 971 | /* interlaced */ |
| 972 | saa_writel(SAA7134_RS_BA1(0),base); |
| 973 | saa_writel(SAA7134_RS_BA2(0),base+bpl); |
| 974 | saa_writel(SAA7134_RS_PITCH(0),bpl*2); |
| 975 | } else { |
| 976 | /* non-interlaced */ |
| 977 | saa_writel(SAA7134_RS_BA1(0),base); |
| 978 | saa_writel(SAA7134_RS_BA2(0),base); |
| 979 | saa_writel(SAA7134_RS_PITCH(0),bpl); |
| 980 | } |
| 981 | saa_writel(SAA7134_RS_CONTROL(0),control); |
| 982 | |
| 983 | if (buf->fmt->planar) { |
| 984 | /* DMA: setup channel 4+5 (= planar task A) */ |
| 985 | bpl_uv = bpl >> buf->fmt->hshift; |
| 986 | lines_uv = buf->vb.height >> buf->fmt->vshift; |
| 987 | base2 = base + bpl * buf->vb.height; |
| 988 | base3 = base2 + bpl_uv * lines_uv; |
| 989 | if (buf->fmt->uvswap) |
| 990 | tmp = base2, base2 = base3, base3 = tmp; |
| 991 | dprintk("uv: bpl=%ld lines=%ld base2/3=%ld/%ld\n", |
| 992 | bpl_uv,lines_uv,base2,base3); |
| 993 | if (V4L2_FIELD_HAS_BOTH(buf->vb.field)) { |
| 994 | /* interlaced */ |
| 995 | saa_writel(SAA7134_RS_BA1(4),base2); |
| 996 | saa_writel(SAA7134_RS_BA2(4),base2+bpl_uv); |
| 997 | saa_writel(SAA7134_RS_PITCH(4),bpl_uv*2); |
| 998 | saa_writel(SAA7134_RS_BA1(5),base3); |
| 999 | saa_writel(SAA7134_RS_BA2(5),base3+bpl_uv); |
| 1000 | saa_writel(SAA7134_RS_PITCH(5),bpl_uv*2); |
| 1001 | } else { |
| 1002 | /* non-interlaced */ |
| 1003 | saa_writel(SAA7134_RS_BA1(4),base2); |
| 1004 | saa_writel(SAA7134_RS_BA2(4),base2); |
| 1005 | saa_writel(SAA7134_RS_PITCH(4),bpl_uv); |
| 1006 | saa_writel(SAA7134_RS_BA1(5),base3); |
| 1007 | saa_writel(SAA7134_RS_BA2(5),base3); |
| 1008 | saa_writel(SAA7134_RS_PITCH(5),bpl_uv); |
| 1009 | } |
| 1010 | saa_writel(SAA7134_RS_CONTROL(4),control); |
| 1011 | saa_writel(SAA7134_RS_CONTROL(5),control); |
| 1012 | } |
| 1013 | |
| 1014 | /* start DMA */ |
| 1015 | saa7134_set_dmabits(dev); |
| 1016 | mod_timer(&dev->video_q.timeout, jiffies+BUFFER_TIMEOUT); |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
| 1020 | static int buffer_prepare(struct videobuf_queue *q, |
| 1021 | struct videobuf_buffer *vb, |
| 1022 | enum v4l2_field field) |
| 1023 | { |
| 1024 | struct saa7134_fh *fh = q->priv_data; |
| 1025 | struct saa7134_dev *dev = fh->dev; |
| 1026 | struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb); |
| 1027 | unsigned int size; |
| 1028 | int err; |
| 1029 | |
| 1030 | /* sanity checks */ |
| 1031 | if (NULL == fh->fmt) |
| 1032 | return -EINVAL; |
| 1033 | if (fh->width < 48 || |
| 1034 | fh->height < 32 || |
| 1035 | fh->width/4 > dev->crop_current.width || |
| 1036 | fh->height/4 > dev->crop_current.height || |
| 1037 | fh->width > dev->crop_bounds.width || |
| 1038 | fh->height > dev->crop_bounds.height) |
| 1039 | return -EINVAL; |
| 1040 | size = (fh->width * fh->height * fh->fmt->depth) >> 3; |
| 1041 | if (0 != buf->vb.baddr && buf->vb.bsize < size) |
| 1042 | return -EINVAL; |
| 1043 | |
| 1044 | dprintk("buffer_prepare [%d,size=%dx%d,bytes=%d,fields=%s,%s]\n", |
| 1045 | vb->i,fh->width,fh->height,size,v4l2_field_names[field], |
| 1046 | fh->fmt->name); |
| 1047 | if (buf->vb.width != fh->width || |
| 1048 | buf->vb.height != fh->height || |
| 1049 | buf->vb.size != size || |
| 1050 | buf->vb.field != field || |
| 1051 | buf->fmt != fh->fmt) { |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 1052 | saa7134_dma_free(q,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 1055 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 1056 | struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); |
| 1057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | buf->vb.width = fh->width; |
| 1059 | buf->vb.height = fh->height; |
| 1060 | buf->vb.size = size; |
| 1061 | buf->vb.field = field; |
| 1062 | buf->fmt = fh->fmt; |
| 1063 | buf->pt = &fh->pt_cap; |
| 1064 | |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 1065 | err = videobuf_iolock(q,&buf->vb,&dev->ovbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | if (err) |
| 1067 | goto oops; |
| 1068 | err = saa7134_pgtable_build(dev->pci,buf->pt, |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 1069 | dma->sglist, |
| 1070 | dma->sglen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | saa7134_buffer_startpage(buf)); |
| 1072 | if (err) |
| 1073 | goto oops; |
| 1074 | } |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 1075 | buf->vb.state = VIDEOBUF_PREPARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | buf->activate = buffer_activate; |
| 1077 | return 0; |
| 1078 | |
| 1079 | oops: |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 1080 | saa7134_dma_free(q,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | return err; |
| 1082 | } |
| 1083 | |
| 1084 | static int |
| 1085 | buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) |
| 1086 | { |
| 1087 | struct saa7134_fh *fh = q->priv_data; |
| 1088 | |
| 1089 | *size = fh->fmt->depth * fh->width * fh->height >> 3; |
| 1090 | if (0 == *count) |
| 1091 | *count = gbuffers; |
| 1092 | *count = saa7134_buffer_count(*size,*count); |
| 1093 | return 0; |
| 1094 | } |
| 1095 | |
| 1096 | static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) |
| 1097 | { |
| 1098 | struct saa7134_fh *fh = q->priv_data; |
| 1099 | struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb); |
| 1100 | |
| 1101 | saa7134_buffer_queue(fh->dev,&fh->dev->video_q,buf); |
| 1102 | } |
| 1103 | |
| 1104 | static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) |
| 1105 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb); |
| 1107 | |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 1108 | saa7134_dma_free(q,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | static struct videobuf_queue_ops video_qops = { |
| 1112 | .buf_setup = buffer_setup, |
| 1113 | .buf_prepare = buffer_prepare, |
| 1114 | .buf_queue = buffer_queue, |
| 1115 | .buf_release = buffer_release, |
| 1116 | }; |
| 1117 | |
| 1118 | /* ------------------------------------------------------------------ */ |
| 1119 | |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 1120 | int saa7134_g_ctrl(struct file *file, void *priv, struct v4l2_control *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | { |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1122 | struct saa7134_fh *fh = priv; |
| 1123 | struct saa7134_dev *dev = fh->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | const struct v4l2_queryctrl* ctrl; |
| 1125 | |
| 1126 | ctrl = ctrl_by_id(c->id); |
| 1127 | if (NULL == ctrl) |
| 1128 | return -EINVAL; |
| 1129 | switch (c->id) { |
| 1130 | case V4L2_CID_BRIGHTNESS: |
| 1131 | c->value = dev->ctl_bright; |
| 1132 | break; |
| 1133 | case V4L2_CID_HUE: |
| 1134 | c->value = dev->ctl_hue; |
| 1135 | break; |
| 1136 | case V4L2_CID_CONTRAST: |
| 1137 | c->value = dev->ctl_contrast; |
| 1138 | break; |
| 1139 | case V4L2_CID_SATURATION: |
| 1140 | c->value = dev->ctl_saturation; |
| 1141 | break; |
| 1142 | case V4L2_CID_AUDIO_MUTE: |
| 1143 | c->value = dev->ctl_mute; |
| 1144 | break; |
| 1145 | case V4L2_CID_AUDIO_VOLUME: |
| 1146 | c->value = dev->ctl_volume; |
| 1147 | break; |
| 1148 | case V4L2_CID_PRIVATE_INVERT: |
| 1149 | c->value = dev->ctl_invert; |
| 1150 | break; |
Michael Schimek | f246a81 | 2005-06-23 22:04:47 -0700 | [diff] [blame] | 1151 | case V4L2_CID_HFLIP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | c->value = dev->ctl_mirror; |
| 1153 | break; |
| 1154 | case V4L2_CID_PRIVATE_Y_EVEN: |
| 1155 | c->value = dev->ctl_y_even; |
| 1156 | break; |
| 1157 | case V4L2_CID_PRIVATE_Y_ODD: |
| 1158 | c->value = dev->ctl_y_odd; |
| 1159 | break; |
| 1160 | case V4L2_CID_PRIVATE_AUTOMUTE: |
| 1161 | c->value = dev->ctl_automute; |
| 1162 | break; |
| 1163 | default: |
| 1164 | return -EINVAL; |
| 1165 | } |
| 1166 | return 0; |
| 1167 | } |
Mauro Carvalho Chehab | f6e90a6 | 2007-12-11 15:01:57 -0300 | [diff] [blame] | 1168 | EXPORT_SYMBOL_GPL(saa7134_g_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 1170 | int saa7134_s_ctrl(struct file *file, void *f, struct v4l2_control *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | { |
| 1172 | const struct v4l2_queryctrl* ctrl; |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1173 | struct saa7134_fh *fh = f; |
| 1174 | struct saa7134_dev *dev = fh->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | unsigned long flags; |
| 1176 | int restart_overlay = 0; |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1177 | int err = -EINVAL; |
| 1178 | |
| 1179 | err = v4l2_prio_check(&dev->prio, &fh->prio); |
| 1180 | if (0 != err) |
| 1181 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1183 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | ctrl = ctrl_by_id(c->id); |
| 1186 | if (NULL == ctrl) |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1187 | goto error; |
| 1188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | dprintk("set_control name=%s val=%d\n",ctrl->name,c->value); |
| 1190 | switch (ctrl->type) { |
| 1191 | case V4L2_CTRL_TYPE_BOOLEAN: |
| 1192 | case V4L2_CTRL_TYPE_MENU: |
| 1193 | case V4L2_CTRL_TYPE_INTEGER: |
| 1194 | if (c->value < ctrl->minimum) |
| 1195 | c->value = ctrl->minimum; |
| 1196 | if (c->value > ctrl->maximum) |
| 1197 | c->value = ctrl->maximum; |
| 1198 | break; |
| 1199 | default: |
| 1200 | /* nothing */; |
| 1201 | }; |
| 1202 | switch (c->id) { |
| 1203 | case V4L2_CID_BRIGHTNESS: |
| 1204 | dev->ctl_bright = c->value; |
| 1205 | saa_writeb(SAA7134_DEC_LUMA_BRIGHT, dev->ctl_bright); |
| 1206 | break; |
| 1207 | case V4L2_CID_HUE: |
| 1208 | dev->ctl_hue = c->value; |
| 1209 | saa_writeb(SAA7134_DEC_CHROMA_HUE, dev->ctl_hue); |
| 1210 | break; |
| 1211 | case V4L2_CID_CONTRAST: |
| 1212 | dev->ctl_contrast = c->value; |
| 1213 | saa_writeb(SAA7134_DEC_LUMA_CONTRAST, |
| 1214 | dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast); |
| 1215 | break; |
| 1216 | case V4L2_CID_SATURATION: |
| 1217 | dev->ctl_saturation = c->value; |
| 1218 | saa_writeb(SAA7134_DEC_CHROMA_SATURATION, |
| 1219 | dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation); |
| 1220 | break; |
| 1221 | case V4L2_CID_AUDIO_MUTE: |
| 1222 | dev->ctl_mute = c->value; |
| 1223 | saa7134_tvaudio_setmute(dev); |
| 1224 | break; |
| 1225 | case V4L2_CID_AUDIO_VOLUME: |
| 1226 | dev->ctl_volume = c->value; |
| 1227 | saa7134_tvaudio_setvolume(dev,dev->ctl_volume); |
| 1228 | break; |
| 1229 | case V4L2_CID_PRIVATE_INVERT: |
| 1230 | dev->ctl_invert = c->value; |
| 1231 | saa_writeb(SAA7134_DEC_LUMA_CONTRAST, |
| 1232 | dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast); |
| 1233 | saa_writeb(SAA7134_DEC_CHROMA_SATURATION, |
| 1234 | dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation); |
| 1235 | break; |
Michael Schimek | f246a81 | 2005-06-23 22:04:47 -0700 | [diff] [blame] | 1236 | case V4L2_CID_HFLIP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | dev->ctl_mirror = c->value; |
| 1238 | restart_overlay = 1; |
| 1239 | break; |
| 1240 | case V4L2_CID_PRIVATE_Y_EVEN: |
| 1241 | dev->ctl_y_even = c->value; |
| 1242 | restart_overlay = 1; |
| 1243 | break; |
| 1244 | case V4L2_CID_PRIVATE_Y_ODD: |
| 1245 | dev->ctl_y_odd = c->value; |
| 1246 | restart_overlay = 1; |
| 1247 | break; |
| 1248 | case V4L2_CID_PRIVATE_AUTOMUTE: |
Mauro Carvalho Chehab | 7f17112 | 2007-10-18 19:56:47 -0300 | [diff] [blame] | 1249 | { |
| 1250 | struct v4l2_priv_tun_config tda9887_cfg; |
| 1251 | |
| 1252 | tda9887_cfg.tuner = TUNER_TDA9887; |
| 1253 | tda9887_cfg.priv = &dev->tda9887_conf; |
| 1254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | dev->ctl_automute = c->value; |
| 1256 | if (dev->tda9887_conf) { |
| 1257 | if (dev->ctl_automute) |
| 1258 | dev->tda9887_conf |= TDA9887_AUTOMUTE; |
| 1259 | else |
| 1260 | dev->tda9887_conf &= ~TDA9887_AUTOMUTE; |
Mauro Carvalho Chehab | 7f17112 | 2007-10-18 19:56:47 -0300 | [diff] [blame] | 1261 | |
| 1262 | saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, |
| 1263 | &tda9887_cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | } |
| 1265 | break; |
Mauro Carvalho Chehab | 7f17112 | 2007-10-18 19:56:47 -0300 | [diff] [blame] | 1266 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | default: |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1268 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | } |
| 1270 | if (restart_overlay && fh && res_check(fh, RESOURCE_OVERLAY)) { |
| 1271 | spin_lock_irqsave(&dev->slock,flags); |
| 1272 | stop_preview(dev,fh); |
| 1273 | start_preview(dev,fh); |
| 1274 | spin_unlock_irqrestore(&dev->slock,flags); |
| 1275 | } |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1276 | err = 0; |
| 1277 | |
| 1278 | error: |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1279 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1280 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | } |
Mauro Carvalho Chehab | f6e90a6 | 2007-12-11 15:01:57 -0300 | [diff] [blame] | 1282 | EXPORT_SYMBOL_GPL(saa7134_s_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | |
| 1284 | /* ------------------------------------------------------------------ */ |
| 1285 | |
| 1286 | static struct videobuf_queue* saa7134_queue(struct saa7134_fh *fh) |
| 1287 | { |
| 1288 | struct videobuf_queue* q = NULL; |
| 1289 | |
| 1290 | switch (fh->type) { |
| 1291 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 1292 | q = &fh->cap; |
| 1293 | break; |
| 1294 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 1295 | q = &fh->vbi; |
| 1296 | break; |
| 1297 | default: |
| 1298 | BUG(); |
| 1299 | } |
| 1300 | return q; |
| 1301 | } |
| 1302 | |
| 1303 | static int saa7134_resource(struct saa7134_fh *fh) |
| 1304 | { |
Heikki Orsila | 9040b32 | 2007-04-27 12:31:18 -0300 | [diff] [blame] | 1305 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1306 | return RESOURCE_VIDEO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | |
Heikki Orsila | 9040b32 | 2007-04-27 12:31:18 -0300 | [diff] [blame] | 1308 | if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 1309 | return RESOURCE_VBI; |
| 1310 | |
| 1311 | BUG(); |
| 1312 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | static int video_open(struct inode *inode, struct file *file) |
| 1316 | { |
| 1317 | int minor = iminor(inode); |
Trent Piepho | 6d28e98 | 2007-10-10 05:37:42 -0300 | [diff] [blame] | 1318 | struct saa7134_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | struct saa7134_fh *fh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1321 | int radio = 0; |
Trent Piepho | 6d28e98 | 2007-10-10 05:37:42 -0300 | [diff] [blame] | 1322 | list_for_each_entry(dev, &saa7134_devlist, devlist) { |
| 1323 | if (dev->video_dev && (dev->video_dev->minor == minor)) |
| 1324 | goto found; |
| 1325 | if (dev->radio_dev && (dev->radio_dev->minor == minor)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | radio = 1; |
Trent Piepho | 6d28e98 | 2007-10-10 05:37:42 -0300 | [diff] [blame] | 1327 | goto found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | } |
Trent Piepho | 6d28e98 | 2007-10-10 05:37:42 -0300 | [diff] [blame] | 1329 | if (dev->vbi_dev && (dev->vbi_dev->minor == minor)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | type = V4L2_BUF_TYPE_VBI_CAPTURE; |
Trent Piepho | 6d28e98 | 2007-10-10 05:37:42 -0300 | [diff] [blame] | 1331 | goto found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | } |
| 1333 | } |
Trent Piepho | 6d28e98 | 2007-10-10 05:37:42 -0300 | [diff] [blame] | 1334 | return -ENODEV; |
| 1335 | found: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | |
| 1337 | dprintk("open minor=%d radio=%d type=%s\n",minor,radio, |
| 1338 | v4l2_type_names[type]); |
| 1339 | |
| 1340 | /* allocate + initialize per filehandle data */ |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 1341 | fh = kzalloc(sizeof(*fh),GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | if (NULL == fh) |
| 1343 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | file->private_data = fh; |
| 1345 | fh->dev = dev; |
| 1346 | fh->radio = radio; |
| 1347 | fh->type = type; |
| 1348 | fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); |
| 1349 | fh->width = 720; |
| 1350 | fh->height = 576; |
| 1351 | v4l2_prio_open(&dev->prio,&fh->prio); |
| 1352 | |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 1353 | videobuf_queue_pci_init(&fh->cap, &video_qops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | dev->pci, &dev->slock, |
| 1355 | V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 1356 | V4L2_FIELD_INTERLACED, |
| 1357 | sizeof(struct saa7134_buf), |
| 1358 | fh); |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 1359 | videobuf_queue_pci_init(&fh->vbi, &saa7134_vbi_qops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | dev->pci, &dev->slock, |
| 1361 | V4L2_BUF_TYPE_VBI_CAPTURE, |
| 1362 | V4L2_FIELD_SEQ_TB, |
| 1363 | sizeof(struct saa7134_buf), |
| 1364 | fh); |
| 1365 | saa7134_pgtable_alloc(dev->pci,&fh->pt_cap); |
| 1366 | saa7134_pgtable_alloc(dev->pci,&fh->pt_vbi); |
| 1367 | |
| 1368 | if (fh->radio) { |
| 1369 | /* switch to radio mode */ |
| 1370 | saa7134_tvaudio_setinput(dev,&card(dev).radio); |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 1371 | saa7134_i2c_call_clients(dev,AUDC_SET_RADIO, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | } else { |
| 1373 | /* switch to video/vbi mode */ |
| 1374 | video_mux(dev,dev->ctl_input); |
| 1375 | } |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 1376 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | static ssize_t |
| 1380 | video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) |
| 1381 | { |
| 1382 | struct saa7134_fh *fh = file->private_data; |
| 1383 | |
| 1384 | switch (fh->type) { |
| 1385 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 1386 | if (res_locked(fh->dev,RESOURCE_VIDEO)) |
| 1387 | return -EBUSY; |
| 1388 | return videobuf_read_one(saa7134_queue(fh), |
| 1389 | data, count, ppos, |
| 1390 | file->f_flags & O_NONBLOCK); |
| 1391 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 1392 | if (!res_get(fh->dev,fh,RESOURCE_VBI)) |
| 1393 | return -EBUSY; |
| 1394 | return videobuf_read_stream(saa7134_queue(fh), |
| 1395 | data, count, ppos, 1, |
| 1396 | file->f_flags & O_NONBLOCK); |
| 1397 | break; |
| 1398 | default: |
| 1399 | BUG(); |
| 1400 | return 0; |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | static unsigned int |
| 1405 | video_poll(struct file *file, struct poll_table_struct *wait) |
| 1406 | { |
| 1407 | struct saa7134_fh *fh = file->private_data; |
| 1408 | struct videobuf_buffer *buf = NULL; |
| 1409 | |
| 1410 | if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) |
| 1411 | return videobuf_poll_stream(file, &fh->vbi, wait); |
| 1412 | |
| 1413 | if (res_check(fh,RESOURCE_VIDEO)) { |
| 1414 | if (!list_empty(&fh->cap.stream)) |
| 1415 | buf = list_entry(fh->cap.stream.next, struct videobuf_buffer, stream); |
| 1416 | } else { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1417 | mutex_lock(&fh->cap.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | if (UNSET == fh->cap.read_off) { |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 1419 | /* need to capture a new frame */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | if (res_locked(fh->dev,RESOURCE_VIDEO)) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1421 | mutex_unlock(&fh->cap.lock); |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 1422 | return POLLERR; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1423 | } |
| 1424 | if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,fh->cap.field)) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1425 | mutex_unlock(&fh->cap.lock); |
Mauro Carvalho Chehab | f2421ca | 2005-11-08 21:37:45 -0800 | [diff] [blame] | 1426 | return POLLERR; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1427 | } |
| 1428 | fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf); |
| 1429 | fh->cap.read_off = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | } |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1431 | mutex_unlock(&fh->cap.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | buf = fh->cap.read_buf; |
| 1433 | } |
| 1434 | |
| 1435 | if (!buf) |
| 1436 | return POLLERR; |
| 1437 | |
| 1438 | poll_wait(file, &buf->done, wait); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 1439 | if (buf->state == VIDEOBUF_DONE || |
| 1440 | buf->state == VIDEOBUF_ERROR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | return POLLIN|POLLRDNORM; |
| 1442 | return 0; |
| 1443 | } |
| 1444 | |
| 1445 | static int video_release(struct inode *inode, struct file *file) |
| 1446 | { |
| 1447 | struct saa7134_fh *fh = file->private_data; |
| 1448 | struct saa7134_dev *dev = fh->dev; |
| 1449 | unsigned long flags; |
| 1450 | |
| 1451 | /* turn off overlay */ |
| 1452 | if (res_check(fh, RESOURCE_OVERLAY)) { |
| 1453 | spin_lock_irqsave(&dev->slock,flags); |
| 1454 | stop_preview(dev,fh); |
| 1455 | spin_unlock_irqrestore(&dev->slock,flags); |
| 1456 | res_free(dev,fh,RESOURCE_OVERLAY); |
| 1457 | } |
| 1458 | |
| 1459 | /* stop video capture */ |
| 1460 | if (res_check(fh, RESOURCE_VIDEO)) { |
| 1461 | videobuf_streamoff(&fh->cap); |
| 1462 | res_free(dev,fh,RESOURCE_VIDEO); |
| 1463 | } |
| 1464 | if (fh->cap.read_buf) { |
| 1465 | buffer_release(&fh->cap,fh->cap.read_buf); |
| 1466 | kfree(fh->cap.read_buf); |
| 1467 | } |
| 1468 | |
| 1469 | /* stop vbi capture */ |
| 1470 | if (res_check(fh, RESOURCE_VBI)) { |
Brandon Philips | 053fcb6 | 2007-11-13 20:11:26 -0300 | [diff] [blame] | 1471 | videobuf_stop(&fh->vbi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | res_free(dev,fh,RESOURCE_VBI); |
| 1473 | } |
| 1474 | |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 1475 | /* ts-capture will not work in planar mode, so turn it off Hac: 04.05*/ |
| 1476 | saa_andorb(SAA7134_OFMT_VIDEO_A, 0x1f, 0); |
| 1477 | saa_andorb(SAA7134_OFMT_VIDEO_B, 0x1f, 0); |
| 1478 | saa_andorb(SAA7134_OFMT_DATA_A, 0x1f, 0); |
| 1479 | saa_andorb(SAA7134_OFMT_DATA_B, 0x1f, 0); |
| 1480 | |
Mauro Carvalho Chehab | 2f18071 | 2005-09-09 13:03:46 -0700 | [diff] [blame] | 1481 | saa7134_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL); |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 1482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | /* free stuff */ |
| 1484 | videobuf_mmap_free(&fh->cap); |
| 1485 | videobuf_mmap_free(&fh->vbi); |
| 1486 | saa7134_pgtable_free(dev->pci,&fh->pt_cap); |
| 1487 | saa7134_pgtable_free(dev->pci,&fh->pt_vbi); |
| 1488 | |
| 1489 | v4l2_prio_close(&dev->prio,&fh->prio); |
| 1490 | file->private_data = NULL; |
| 1491 | kfree(fh); |
| 1492 | return 0; |
| 1493 | } |
| 1494 | |
Heikki Orsila | 9040b32 | 2007-04-27 12:31:18 -0300 | [diff] [blame] | 1495 | static int video_mmap(struct file *file, struct vm_area_struct * vma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | { |
| 1497 | struct saa7134_fh *fh = file->private_data; |
| 1498 | |
| 1499 | return videobuf_mmap_mapper(saa7134_queue(fh), vma); |
| 1500 | } |
| 1501 | |
| 1502 | /* ------------------------------------------------------------------ */ |
| 1503 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1504 | static int saa7134_try_get_set_fmt_vbi(struct file *file, void *priv, |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1505 | struct v4l2_format *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | { |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1507 | struct saa7134_fh *fh = priv; |
| 1508 | struct saa7134_dev *dev = fh->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | struct saa7134_tvnorm *norm = dev->tvnorm; |
| 1510 | |
| 1511 | f->fmt.vbi.sampling_rate = 6750000 * 4; |
| 1512 | f->fmt.vbi.samples_per_line = 2048 /* VBI_LINE_LENGTH */; |
| 1513 | f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; |
| 1514 | f->fmt.vbi.offset = 64 * 4; |
Michael Schimek | f246a81 | 2005-06-23 22:04:47 -0700 | [diff] [blame] | 1515 | f->fmt.vbi.start[0] = norm->vbi_v_start_0; |
| 1516 | f->fmt.vbi.count[0] = norm->vbi_v_stop_0 - norm->vbi_v_start_0 +1; |
| 1517 | f->fmt.vbi.start[1] = norm->vbi_v_start_1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; |
| 1519 | f->fmt.vbi.flags = 0; /* VBI_UNSYNC VBI_INTERLACED */ |
| 1520 | |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1521 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1524 | static int saa7134_g_fmt_cap(struct file *file, void *priv, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1525 | struct v4l2_format *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | { |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1527 | struct saa7134_fh *fh = priv; |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1528 | |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1529 | f->fmt.pix.width = fh->width; |
| 1530 | f->fmt.pix.height = fh->height; |
| 1531 | f->fmt.pix.field = fh->cap.field; |
| 1532 | f->fmt.pix.pixelformat = fh->fmt->fourcc; |
| 1533 | f->fmt.pix.bytesperline = |
| 1534 | (f->fmt.pix.width * fh->fmt->depth) >> 3; |
| 1535 | f->fmt.pix.sizeimage = |
| 1536 | f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 1537 | return 0; |
| 1538 | } |
| 1539 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1540 | static int saa7134_g_fmt_overlay(struct file *file, void *priv, |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1541 | struct v4l2_format *f) |
| 1542 | { |
| 1543 | struct saa7134_fh *fh = priv; |
| 1544 | |
| 1545 | if (saa7134_no_overlay > 0) { |
| 1546 | printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | return -EINVAL; |
| 1548 | } |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1549 | f->fmt.win = fh->win; |
| 1550 | |
| 1551 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1554 | static int saa7134_try_fmt_cap(struct file *file, void *priv, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1555 | struct v4l2_format *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | { |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1557 | struct saa7134_fh *fh = priv; |
| 1558 | struct saa7134_dev *dev = fh->dev; |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1559 | struct saa7134_format *fmt; |
| 1560 | enum v4l2_field field; |
| 1561 | unsigned int maxw, maxh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1563 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
| 1564 | if (NULL == fmt) |
| 1565 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1567 | field = f->fmt.pix.field; |
| 1568 | maxw = min(dev->crop_current.width*4, dev->crop_bounds.width); |
| 1569 | maxh = min(dev->crop_current.height*4, dev->crop_bounds.height); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1571 | if (V4L2_FIELD_ANY == field) { |
| 1572 | field = (f->fmt.pix.height > maxh/2) |
| 1573 | ? V4L2_FIELD_INTERLACED |
| 1574 | : V4L2_FIELD_BOTTOM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | } |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1576 | switch (field) { |
| 1577 | case V4L2_FIELD_TOP: |
| 1578 | case V4L2_FIELD_BOTTOM: |
| 1579 | maxh = maxh / 2; |
| 1580 | break; |
| 1581 | case V4L2_FIELD_INTERLACED: |
| 1582 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | default: |
| 1584 | return -EINVAL; |
| 1585 | } |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1586 | |
| 1587 | f->fmt.pix.field = field; |
| 1588 | if (f->fmt.pix.width < 48) |
| 1589 | f->fmt.pix.width = 48; |
| 1590 | if (f->fmt.pix.height < 32) |
| 1591 | f->fmt.pix.height = 32; |
| 1592 | if (f->fmt.pix.width > maxw) |
| 1593 | f->fmt.pix.width = maxw; |
| 1594 | if (f->fmt.pix.height > maxh) |
| 1595 | f->fmt.pix.height = maxh; |
| 1596 | f->fmt.pix.width &= ~0x03; |
| 1597 | f->fmt.pix.bytesperline = |
| 1598 | (f->fmt.pix.width * fmt->depth) >> 3; |
| 1599 | f->fmt.pix.sizeimage = |
| 1600 | f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 1601 | |
| 1602 | return 0; |
| 1603 | } |
| 1604 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1605 | static int saa7134_try_fmt_overlay(struct file *file, void *priv, |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1606 | struct v4l2_format *f) |
| 1607 | { |
| 1608 | struct saa7134_fh *fh = priv; |
| 1609 | struct saa7134_dev *dev = fh->dev; |
| 1610 | |
| 1611 | if (saa7134_no_overlay > 0) { |
| 1612 | printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); |
| 1613 | return -EINVAL; |
| 1614 | } |
| 1615 | |
| 1616 | return verify_preview(dev, &f->fmt.win); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1619 | static int saa7134_s_fmt_cap(struct file *file, void *priv, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1620 | struct v4l2_format *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | { |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1622 | struct saa7134_fh *fh = priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | int err; |
| 1624 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1625 | err = saa7134_try_fmt_cap(file, priv, f); |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1626 | if (0 != err) |
| 1627 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1629 | fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
| 1630 | fh->width = f->fmt.pix.width; |
| 1631 | fh->height = f->fmt.pix.height; |
| 1632 | fh->cap.field = f->fmt.pix.field; |
| 1633 | return 0; |
| 1634 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1636 | static int saa7134_s_fmt_overlay(struct file *file, void *priv, |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1637 | struct v4l2_format *f) |
| 1638 | { |
| 1639 | struct saa7134_fh *fh = priv; |
| 1640 | struct saa7134_dev *dev = fh->dev; |
| 1641 | int err; |
| 1642 | unsigned int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1644 | if (saa7134_no_overlay > 0) { |
| 1645 | printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | return -EINVAL; |
| 1647 | } |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1648 | err = verify_preview(dev, &f->fmt.win); |
| 1649 | if (0 != err) |
| 1650 | return err; |
| 1651 | |
| 1652 | mutex_lock(&dev->lock); |
| 1653 | |
| 1654 | fh->win = f->fmt.win; |
| 1655 | fh->nclips = f->fmt.win.clipcount; |
| 1656 | |
| 1657 | if (fh->nclips > 8) |
| 1658 | fh->nclips = 8; |
| 1659 | |
| 1660 | if (copy_from_user(fh->clips, f->fmt.win.clips, |
| 1661 | sizeof(struct v4l2_clip)*fh->nclips)) { |
| 1662 | mutex_unlock(&dev->lock); |
| 1663 | return -EFAULT; |
| 1664 | } |
| 1665 | |
| 1666 | if (res_check(fh, RESOURCE_OVERLAY)) { |
| 1667 | spin_lock_irqsave(&dev->slock, flags); |
| 1668 | stop_preview(dev, fh); |
| 1669 | start_preview(dev, fh); |
| 1670 | spin_unlock_irqrestore(&dev->slock, flags); |
| 1671 | } |
| 1672 | |
| 1673 | mutex_unlock(&dev->lock); |
| 1674 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 1677 | int saa7134_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *c) |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1678 | { |
| 1679 | const struct v4l2_queryctrl *ctrl; |
| 1680 | |
| 1681 | if ((c->id < V4L2_CID_BASE || |
| 1682 | c->id >= V4L2_CID_LASTP1) && |
| 1683 | (c->id < V4L2_CID_PRIVATE_BASE || |
| 1684 | c->id >= V4L2_CID_PRIVATE_LASTP1)) |
| 1685 | return -EINVAL; |
| 1686 | ctrl = ctrl_by_id(c->id); |
| 1687 | *c = (NULL != ctrl) ? *ctrl : no_ctrl; |
| 1688 | return 0; |
| 1689 | } |
Mauro Carvalho Chehab | f6e90a6 | 2007-12-11 15:01:57 -0300 | [diff] [blame] | 1690 | EXPORT_SYMBOL_GPL(saa7134_queryctrl); |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1691 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1692 | static int saa7134_enum_input(struct file *file, void *priv, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1693 | struct v4l2_input *i) |
| 1694 | { |
| 1695 | struct saa7134_fh *fh = priv; |
| 1696 | struct saa7134_dev *dev = fh->dev; |
| 1697 | unsigned int n; |
| 1698 | |
| 1699 | n = i->index; |
| 1700 | if (n >= SAA7134_INPUT_MAX) |
| 1701 | return -EINVAL; |
| 1702 | if (NULL == card_in(dev, i->index).name) |
| 1703 | return -EINVAL; |
| 1704 | memset(i, 0, sizeof(*i)); |
| 1705 | i->index = n; |
| 1706 | i->type = V4L2_INPUT_TYPE_CAMERA; |
| 1707 | strcpy(i->name, card_in(dev, n).name); |
| 1708 | if (card_in(dev, n).tv) |
| 1709 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 1710 | i->audioset = 1; |
| 1711 | if (n == dev->ctl_input) { |
| 1712 | int v1 = saa_readb(SAA7134_STATUS_VIDEO1); |
| 1713 | int v2 = saa_readb(SAA7134_STATUS_VIDEO2); |
| 1714 | |
| 1715 | if (0 != (v1 & 0x40)) |
| 1716 | i->status |= V4L2_IN_ST_NO_H_LOCK; |
| 1717 | if (0 != (v2 & 0x40)) |
| 1718 | i->status |= V4L2_IN_ST_NO_SYNC; |
| 1719 | if (0 != (v2 & 0x0e)) |
| 1720 | i->status |= V4L2_IN_ST_MACROVISION; |
| 1721 | } |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1722 | i->std = SAA7134_NORMS; |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1723 | return 0; |
| 1724 | } |
| 1725 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1726 | static int saa7134_g_input(struct file *file, void *priv, unsigned int *i) |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 1727 | { |
| 1728 | struct saa7134_fh *fh = priv; |
| 1729 | struct saa7134_dev *dev = fh->dev; |
| 1730 | |
| 1731 | *i = dev->ctl_input; |
| 1732 | return 0; |
| 1733 | } |
| 1734 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1735 | static int saa7134_s_input(struct file *file, void *priv, unsigned int i) |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 1736 | { |
| 1737 | struct saa7134_fh *fh = priv; |
| 1738 | struct saa7134_dev *dev = fh->dev; |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1739 | int err; |
| 1740 | |
| 1741 | err = v4l2_prio_check(&dev->prio, &fh->prio); |
| 1742 | if (0 != err) |
| 1743 | return err; |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 1744 | |
| 1745 | if (i < 0 || i >= SAA7134_INPUT_MAX) |
| 1746 | return -EINVAL; |
| 1747 | if (NULL == card_in(dev, i).name) |
| 1748 | return -EINVAL; |
| 1749 | mutex_lock(&dev->lock); |
| 1750 | video_mux(dev, i); |
| 1751 | mutex_unlock(&dev->lock); |
| 1752 | return 0; |
| 1753 | } |
| 1754 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1755 | static int saa7134_querycap(struct file *file, void *priv, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1756 | struct v4l2_capability *cap) |
| 1757 | { |
| 1758 | struct saa7134_fh *fh = priv; |
| 1759 | struct saa7134_dev *dev = fh->dev; |
| 1760 | |
| 1761 | unsigned int tuner_type = dev->tuner_type; |
| 1762 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1763 | strcpy(cap->driver, "saa7134"); |
| 1764 | strlcpy(cap->card, saa7134_boards[dev->board].name, |
| 1765 | sizeof(cap->card)); |
| 1766 | sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci)); |
| 1767 | cap->version = SAA7134_VERSION_CODE; |
| 1768 | cap->capabilities = |
| 1769 | V4L2_CAP_VIDEO_CAPTURE | |
| 1770 | V4L2_CAP_VBI_CAPTURE | |
| 1771 | V4L2_CAP_READWRITE | |
| 1772 | V4L2_CAP_STREAMING | |
| 1773 | V4L2_CAP_TUNER; |
| 1774 | if (saa7134_no_overlay <= 0) |
| 1775 | cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY; |
| 1776 | |
| 1777 | if ((tuner_type == TUNER_ABSENT) || (tuner_type == UNSET)) |
| 1778 | cap->capabilities &= ~V4L2_CAP_TUNER; |
| 1779 | return 0; |
| 1780 | } |
| 1781 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1782 | static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id) |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1783 | { |
| 1784 | struct saa7134_fh *fh = priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | struct saa7134_dev *dev = fh->dev; |
| 1786 | unsigned long flags; |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1787 | unsigned int i; |
| 1788 | v4l2_std_id fixup; |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1789 | int err; |
| 1790 | |
| 1791 | err = v4l2_prio_check(&dev->prio, &fh->prio); |
| 1792 | if (0 != err) |
| 1793 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1795 | for (i = 0; i < TVNORMS; i++) |
| 1796 | if (*id == tvnorms[i].id) |
| 1797 | break; |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1798 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1799 | if (i == TVNORMS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | for (i = 0; i < TVNORMS; i++) |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1801 | if (*id & tvnorms[i].id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | break; |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1803 | if (i == TVNORMS) |
| 1804 | return -EINVAL; |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1805 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1806 | if ((*id & V4L2_STD_SECAM) && (secam[0] != '-')) { |
| 1807 | if (secam[0] == 'L' || secam[0] == 'l') { |
| 1808 | if (secam[1] == 'C' || secam[1] == 'c') |
| 1809 | fixup = V4L2_STD_SECAM_LC; |
| 1810 | else |
| 1811 | fixup = V4L2_STD_SECAM_L; |
| 1812 | } else { |
| 1813 | if (secam[0] == 'D' || secam[0] == 'd') |
| 1814 | fixup = V4L2_STD_SECAM_DK; |
| 1815 | else |
| 1816 | fixup = V4L2_STD_SECAM; |
Hartmut Hackmann | 17b10a7 | 2006-10-02 19:55:07 -0300 | [diff] [blame] | 1817 | } |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1818 | for (i = 0; i < TVNORMS; i++) |
| 1819 | if (fixup == tvnorms[i].id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | } |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1822 | |
| 1823 | *id = tvnorms[i].id; |
| 1824 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1825 | mutex_lock(&dev->lock); |
| 1826 | if (res_check(fh, RESOURCE_OVERLAY)) { |
| 1827 | spin_lock_irqsave(&dev->slock, flags); |
| 1828 | stop_preview(dev, fh); |
| 1829 | spin_unlock_irqrestore(&dev->slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1831 | set_tvnorm(dev, &tvnorms[i]); |
| 1832 | |
| 1833 | spin_lock_irqsave(&dev->slock, flags); |
| 1834 | start_preview(dev, fh); |
| 1835 | spin_unlock_irqrestore(&dev->slock, flags); |
| 1836 | } else |
| 1837 | set_tvnorm(dev, &tvnorms[i]); |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1838 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1839 | saa7134_tvaudio_do_scan(dev); |
| 1840 | mutex_unlock(&dev->lock); |
| 1841 | return 0; |
| 1842 | } |
| 1843 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1844 | static int saa7134_cropcap(struct file *file, void *priv, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1845 | struct v4l2_cropcap *cap) |
| 1846 | { |
| 1847 | struct saa7134_fh *fh = priv; |
| 1848 | struct saa7134_dev *dev = fh->dev; |
| 1849 | |
| 1850 | if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && |
| 1851 | cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) |
| 1852 | return -EINVAL; |
| 1853 | cap->bounds = dev->crop_bounds; |
| 1854 | cap->defrect = dev->crop_defrect; |
| 1855 | cap->pixelaspect.numerator = 1; |
| 1856 | cap->pixelaspect.denominator = 1; |
| 1857 | if (dev->tvnorm->id & V4L2_STD_525_60) { |
| 1858 | cap->pixelaspect.numerator = 11; |
| 1859 | cap->pixelaspect.denominator = 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | } |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1861 | if (dev->tvnorm->id & V4L2_STD_625_50) { |
| 1862 | cap->pixelaspect.numerator = 54; |
| 1863 | cap->pixelaspect.denominator = 59; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | } |
| 1865 | return 0; |
| 1866 | } |
| 1867 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1868 | static int saa7134_g_crop(struct file *file, void *f, struct v4l2_crop *crop) |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 1869 | { |
| 1870 | struct saa7134_fh *fh = f; |
| 1871 | struct saa7134_dev *dev = fh->dev; |
| 1872 | |
| 1873 | if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && |
| 1874 | crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) |
| 1875 | return -EINVAL; |
| 1876 | crop->c = dev->crop_current; |
| 1877 | return 0; |
| 1878 | } |
| 1879 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1880 | static int saa7134_s_crop(struct file *file, void *f, struct v4l2_crop *crop) |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 1881 | { |
| 1882 | struct saa7134_fh *fh = f; |
| 1883 | struct saa7134_dev *dev = fh->dev; |
| 1884 | struct v4l2_rect *b = &dev->crop_bounds; |
| 1885 | |
| 1886 | if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && |
| 1887 | crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) |
| 1888 | return -EINVAL; |
| 1889 | if (crop->c.height < 0) |
| 1890 | return -EINVAL; |
| 1891 | if (crop->c.width < 0) |
| 1892 | return -EINVAL; |
| 1893 | |
| 1894 | if (res_locked(fh->dev, RESOURCE_OVERLAY)) |
| 1895 | return -EBUSY; |
| 1896 | if (res_locked(fh->dev, RESOURCE_VIDEO)) |
| 1897 | return -EBUSY; |
| 1898 | |
| 1899 | if (crop->c.top < b->top) |
| 1900 | crop->c.top = b->top; |
| 1901 | if (crop->c.top > b->top + b->height) |
| 1902 | crop->c.top = b->top + b->height; |
| 1903 | if (crop->c.height > b->top - crop->c.top + b->height) |
| 1904 | crop->c.height = b->top - crop->c.top + b->height; |
| 1905 | |
| 1906 | if (crop->c.left < b->left) |
| 1907 | crop->c.left = b->left; |
| 1908 | if (crop->c.left > b->left + b->width) |
| 1909 | crop->c.left = b->left + b->width; |
| 1910 | if (crop->c.width > b->left - crop->c.left + b->width) |
| 1911 | crop->c.width = b->left - crop->c.left + b->width; |
| 1912 | |
| 1913 | dev->crop_current = crop->c; |
| 1914 | return 0; |
| 1915 | } |
| 1916 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1917 | static int saa7134_g_tuner(struct file *file, void *priv, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1918 | struct v4l2_tuner *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | { |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1920 | struct saa7134_fh *fh = priv; |
| 1921 | struct saa7134_dev *dev = fh->dev; |
| 1922 | int n; |
| 1923 | |
| 1924 | if (0 != t->index) |
| 1925 | return -EINVAL; |
| 1926 | memset(t, 0, sizeof(*t)); |
| 1927 | for (n = 0; n < SAA7134_INPUT_MAX; n++) |
| 1928 | if (card_in(dev, n).tv) |
| 1929 | break; |
| 1930 | if (NULL != card_in(dev, n).name) { |
| 1931 | strcpy(t->name, "Television"); |
| 1932 | t->type = V4L2_TUNER_ANALOG_TV; |
| 1933 | t->capability = V4L2_TUNER_CAP_NORM | |
| 1934 | V4L2_TUNER_CAP_STEREO | |
| 1935 | V4L2_TUNER_CAP_LANG1 | |
| 1936 | V4L2_TUNER_CAP_LANG2; |
| 1937 | t->rangehigh = 0xffffffffUL; |
| 1938 | t->rxsubchans = saa7134_tvaudio_getstereo(dev); |
| 1939 | t->audmode = saa7134_tvaudio_rx2mode(t->rxsubchans); |
| 1940 | } |
| 1941 | if (0 != (saa_readb(SAA7134_STATUS_VIDEO1) & 0x03)) |
| 1942 | t->signal = 0xffff; |
| 1943 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1946 | static int saa7134_s_tuner(struct file *file, void *priv, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1947 | struct v4l2_tuner *t) |
| 1948 | { |
| 1949 | struct saa7134_fh *fh = priv; |
| 1950 | struct saa7134_dev *dev = fh->dev; |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1951 | int rx, mode, err; |
| 1952 | |
| 1953 | err = v4l2_prio_check(&dev->prio, &fh->prio); |
| 1954 | if (0 != err) |
| 1955 | return err; |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1956 | |
| 1957 | mode = dev->thread.mode; |
| 1958 | if (UNSET == mode) { |
| 1959 | rx = saa7134_tvaudio_getstereo(dev); |
| 1960 | mode = saa7134_tvaudio_rx2mode(t->rxsubchans); |
| 1961 | } |
| 1962 | if (mode != t->audmode) |
| 1963 | dev->thread.mode = t->audmode; |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1964 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1965 | return 0; |
| 1966 | } |
| 1967 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1968 | static int saa7134_g_frequency(struct file *file, void *priv, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1969 | struct v4l2_frequency *f) |
| 1970 | { |
| 1971 | struct saa7134_fh *fh = priv; |
| 1972 | struct saa7134_dev *dev = fh->dev; |
| 1973 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1974 | f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
| 1975 | f->frequency = dev->ctl_freq; |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1976 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1977 | return 0; |
| 1978 | } |
| 1979 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 1980 | static int saa7134_s_frequency(struct file *file, void *priv, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1981 | struct v4l2_frequency *f) |
| 1982 | { |
| 1983 | struct saa7134_fh *fh = priv; |
| 1984 | struct saa7134_dev *dev = fh->dev; |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 1985 | int err; |
| 1986 | |
| 1987 | err = v4l2_prio_check(&dev->prio, &fh->prio); |
| 1988 | if (0 != err) |
| 1989 | return err; |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 1990 | |
| 1991 | if (0 != f->tuner) |
| 1992 | return -EINVAL; |
| 1993 | if (0 == fh->radio && V4L2_TUNER_ANALOG_TV != f->type) |
| 1994 | return -EINVAL; |
| 1995 | if (1 == fh->radio && V4L2_TUNER_RADIO != f->type) |
| 1996 | return -EINVAL; |
| 1997 | mutex_lock(&dev->lock); |
| 1998 | dev->ctl_freq = f->frequency; |
| 1999 | |
| 2000 | saa7134_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f); |
| 2001 | |
| 2002 | saa7134_tvaudio_do_scan(dev); |
| 2003 | mutex_unlock(&dev->lock); |
| 2004 | return 0; |
| 2005 | } |
| 2006 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2007 | static int saa7134_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2008 | { |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2009 | strcpy(a->name, "audio"); |
| 2010 | return 0; |
| 2011 | } |
| 2012 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2013 | static int saa7134_s_audio(struct file *file, void *priv, struct v4l2_audio *a) |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2014 | { |
| 2015 | return 0; |
| 2016 | } |
| 2017 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2018 | static int saa7134_g_priority(struct file *file, void *f, enum v4l2_priority *p) |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2019 | { |
| 2020 | struct saa7134_fh *fh = f; |
| 2021 | struct saa7134_dev *dev = fh->dev; |
| 2022 | |
| 2023 | *p = v4l2_prio_max(&dev->prio); |
| 2024 | return 0; |
| 2025 | } |
| 2026 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2027 | static int saa7134_s_priority(struct file *file, void *f, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2028 | enum v4l2_priority prio) |
| 2029 | { |
| 2030 | struct saa7134_fh *fh = f; |
| 2031 | struct saa7134_dev *dev = fh->dev; |
| 2032 | |
| 2033 | return v4l2_prio_change(&dev->prio, &fh->prio, prio); |
| 2034 | } |
| 2035 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2036 | static int saa7134_enum_fmt_cap(struct file *file, void *priv, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2037 | struct v4l2_fmtdesc *f) |
| 2038 | { |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 2039 | if (f->index >= FORMATS) |
| 2040 | return -EINVAL; |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2041 | |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 2042 | strlcpy(f->description, formats[f->index].name, |
| 2043 | sizeof(f->description)); |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2044 | |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 2045 | f->pixelformat = formats[f->index].fourcc; |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2046 | |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 2047 | return 0; |
| 2048 | } |
| 2049 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2050 | static int saa7134_enum_fmt_overlay(struct file *file, void *priv, |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 2051 | struct v4l2_fmtdesc *f) |
| 2052 | { |
| 2053 | if (saa7134_no_overlay > 0) { |
| 2054 | printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2055 | return -EINVAL; |
| 2056 | } |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 2057 | |
| 2058 | if ((f->index >= FORMATS) || formats[f->index].planar) |
| 2059 | return -EINVAL; |
| 2060 | |
| 2061 | strlcpy(f->description, formats[f->index].name, |
| 2062 | sizeof(f->description)); |
| 2063 | |
| 2064 | f->pixelformat = formats[f->index].fourcc; |
| 2065 | |
| 2066 | return 0; |
| 2067 | } |
| 2068 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2069 | static int saa7134_enum_fmt_vbi(struct file *file, void *priv, |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 2070 | struct v4l2_fmtdesc *f) |
| 2071 | { |
| 2072 | if (0 != f->index) |
| 2073 | return -EINVAL; |
| 2074 | |
| 2075 | f->pixelformat = V4L2_PIX_FMT_GREY; |
| 2076 | strcpy(f->description, "vbi data"); |
| 2077 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2078 | return 0; |
| 2079 | } |
| 2080 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2081 | static int saa7134_g_fbuf(struct file *file, void *f, |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 2082 | struct v4l2_framebuffer *fb) |
| 2083 | { |
| 2084 | struct saa7134_fh *fh = f; |
| 2085 | struct saa7134_dev *dev = fh->dev; |
| 2086 | |
| 2087 | *fb = dev->ovbuf; |
| 2088 | fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING; |
| 2089 | |
| 2090 | return 0; |
| 2091 | } |
| 2092 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2093 | static int saa7134_s_fbuf(struct file *file, void *f, |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 2094 | struct v4l2_framebuffer *fb) |
| 2095 | { |
| 2096 | struct saa7134_fh *fh = f; |
| 2097 | struct saa7134_dev *dev = fh->dev; |
| 2098 | struct saa7134_format *fmt; |
| 2099 | |
| 2100 | if (!capable(CAP_SYS_ADMIN) && |
| 2101 | !capable(CAP_SYS_RAWIO)) |
| 2102 | return -EPERM; |
| 2103 | |
| 2104 | /* check args */ |
| 2105 | fmt = format_by_fourcc(fb->fmt.pixelformat); |
| 2106 | if (NULL == fmt) |
| 2107 | return -EINVAL; |
| 2108 | |
| 2109 | /* ok, accept it */ |
| 2110 | dev->ovbuf = *fb; |
| 2111 | dev->ovfmt = fmt; |
| 2112 | if (0 == dev->ovbuf.fmt.bytesperline) |
| 2113 | dev->ovbuf.fmt.bytesperline = |
| 2114 | dev->ovbuf.fmt.width*fmt->depth/8; |
| 2115 | return 0; |
| 2116 | } |
| 2117 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2118 | static int saa7134_overlay(struct file *file, void *f, unsigned int on) |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 2119 | { |
| 2120 | struct saa7134_fh *fh = f; |
| 2121 | struct saa7134_dev *dev = fh->dev; |
| 2122 | unsigned long flags; |
| 2123 | |
| 2124 | if (on) { |
| 2125 | if (saa7134_no_overlay > 0) { |
| 2126 | dprintk("no_overlay\n"); |
| 2127 | return -EINVAL; |
| 2128 | } |
| 2129 | |
| 2130 | if (!res_get(dev, fh, RESOURCE_OVERLAY)) |
| 2131 | return -EBUSY; |
| 2132 | spin_lock_irqsave(&dev->slock, flags); |
| 2133 | start_preview(dev, fh); |
| 2134 | spin_unlock_irqrestore(&dev->slock, flags); |
| 2135 | } |
| 2136 | if (!on) { |
| 2137 | if (!res_check(fh, RESOURCE_OVERLAY)) |
| 2138 | return -EINVAL; |
| 2139 | spin_lock_irqsave(&dev->slock, flags); |
| 2140 | stop_preview(dev, fh); |
| 2141 | spin_unlock_irqrestore(&dev->slock, flags); |
| 2142 | res_free(dev, fh, RESOURCE_OVERLAY); |
| 2143 | } |
| 2144 | return 0; |
| 2145 | } |
| 2146 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2147 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 2148 | static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf) |
| 2149 | { |
| 2150 | struct saa7134_fh *fh = file->private_data; |
| 2151 | return videobuf_cgmbuf(saa7134_queue(fh), mbuf, 8); |
| 2152 | } |
| 2153 | #endif |
| 2154 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2155 | static int saa7134_reqbufs(struct file *file, void *priv, |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 2156 | struct v4l2_requestbuffers *p) |
| 2157 | { |
| 2158 | struct saa7134_fh *fh = priv; |
| 2159 | return videobuf_reqbufs(saa7134_queue(fh), p); |
| 2160 | } |
| 2161 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2162 | static int saa7134_querybuf(struct file *file, void *priv, |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 2163 | struct v4l2_buffer *b) |
| 2164 | { |
| 2165 | struct saa7134_fh *fh = priv; |
| 2166 | return videobuf_querybuf(saa7134_queue(fh), b); |
| 2167 | } |
| 2168 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2169 | static int saa7134_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 2170 | { |
| 2171 | struct saa7134_fh *fh = priv; |
| 2172 | return videobuf_qbuf(saa7134_queue(fh), b); |
| 2173 | } |
| 2174 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2175 | static int saa7134_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 2176 | { |
| 2177 | struct saa7134_fh *fh = priv; |
| 2178 | return videobuf_dqbuf(saa7134_queue(fh), b, |
| 2179 | file->f_flags & O_NONBLOCK); |
| 2180 | } |
| 2181 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2182 | static int saa7134_streamon(struct file *file, void *priv, |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 2183 | enum v4l2_buf_type type) |
| 2184 | { |
| 2185 | struct saa7134_fh *fh = priv; |
| 2186 | struct saa7134_dev *dev = fh->dev; |
| 2187 | int res = saa7134_resource(fh); |
| 2188 | |
| 2189 | if (!res_get(dev, fh, res)) |
| 2190 | return -EBUSY; |
| 2191 | |
| 2192 | return videobuf_streamon(saa7134_queue(fh)); |
| 2193 | } |
| 2194 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2195 | static int saa7134_streamoff(struct file *file, void *priv, |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 2196 | enum v4l2_buf_type type) |
| 2197 | { |
| 2198 | int err; |
| 2199 | struct saa7134_fh *fh = priv; |
| 2200 | struct saa7134_dev *dev = fh->dev; |
| 2201 | int res = saa7134_resource(fh); |
| 2202 | |
| 2203 | err = videobuf_streamoff(saa7134_queue(fh)); |
| 2204 | if (err < 0) |
| 2205 | return err; |
| 2206 | res_free(dev, fh, res); |
| 2207 | return 0; |
| 2208 | } |
| 2209 | |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2210 | static int saa7134_g_parm(struct file *file, void *fh, |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 2211 | struct v4l2_streamparm *parm) |
| 2212 | { |
Mauro Carvalho Chehab | 90bdc14 | 2007-12-07 17:23:38 -0300 | [diff] [blame] | 2213 | return 0; |
| 2214 | } |
| 2215 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2216 | static int radio_querycap(struct file *file, void *priv, |
| 2217 | struct v4l2_capability *cap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | { |
| 2219 | struct saa7134_fh *fh = file->private_data; |
| 2220 | struct saa7134_dev *dev = fh->dev; |
| 2221 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2222 | strcpy(cap->driver, "saa7134"); |
| 2223 | strlcpy(cap->card, saa7134_boards[dev->board].name, sizeof(cap->card)); |
| 2224 | sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci)); |
| 2225 | cap->version = SAA7134_VERSION_CODE; |
| 2226 | cap->capabilities = V4L2_CAP_TUNER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | return 0; |
| 2228 | } |
| 2229 | |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2230 | static int radio_g_tuner(struct file *file, void *priv, |
| 2231 | struct v4l2_tuner *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | { |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2233 | struct saa7134_fh *fh = file->private_data; |
| 2234 | struct saa7134_dev *dev = fh->dev; |
| 2235 | |
| 2236 | if (0 != t->index) |
| 2237 | return -EINVAL; |
| 2238 | |
| 2239 | memset(t, 0, sizeof(*t)); |
| 2240 | strcpy(t->name, "Radio"); |
| 2241 | t->type = V4L2_TUNER_RADIO; |
| 2242 | |
| 2243 | saa7134_i2c_call_clients(dev, VIDIOC_G_TUNER, t); |
| 2244 | if (dev->input->amux == TV) { |
| 2245 | t->signal = 0xf800 - ((saa_readb(0x581) & 0x1f) << 11); |
| 2246 | t->rxsubchans = (saa_readb(0x529) & 0x08) ? |
| 2247 | V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO; |
| 2248 | } |
| 2249 | return 0; |
| 2250 | } |
| 2251 | static int radio_s_tuner(struct file *file, void *priv, |
| 2252 | struct v4l2_tuner *t) |
| 2253 | { |
| 2254 | struct saa7134_fh *fh = file->private_data; |
| 2255 | struct saa7134_dev *dev = fh->dev; |
| 2256 | |
| 2257 | if (0 != t->index) |
| 2258 | return -EINVAL; |
| 2259 | |
| 2260 | saa7134_i2c_call_clients(dev, VIDIOC_S_TUNER, t); |
| 2261 | return 0; |
| 2262 | } |
| 2263 | |
| 2264 | static int radio_enum_input(struct file *file, void *priv, |
| 2265 | struct v4l2_input *i) |
| 2266 | { |
| 2267 | if (i->index != 0) |
| 2268 | return -EINVAL; |
| 2269 | |
| 2270 | strcpy(i->name, "Radio"); |
| 2271 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 2272 | |
| 2273 | return 0; |
| 2274 | } |
| 2275 | |
| 2276 | static int radio_g_input(struct file *filp, void *priv, unsigned int *i) |
| 2277 | { |
| 2278 | *i = 0; |
| 2279 | return 0; |
| 2280 | } |
| 2281 | |
| 2282 | static int radio_g_audio(struct file *file, void *priv, |
| 2283 | struct v4l2_audio *a) |
| 2284 | { |
| 2285 | memset(a, 0, sizeof(*a)); |
| 2286 | strcpy(a->name, "Radio"); |
| 2287 | return 0; |
| 2288 | } |
| 2289 | |
| 2290 | static int radio_s_audio(struct file *file, void *priv, |
| 2291 | struct v4l2_audio *a) |
| 2292 | { |
| 2293 | return 0; |
| 2294 | } |
| 2295 | |
| 2296 | static int radio_s_input(struct file *filp, void *priv, unsigned int i) |
| 2297 | { |
| 2298 | return 0; |
| 2299 | } |
| 2300 | |
| 2301 | static int radio_s_std(struct file *file, void *fh, v4l2_std_id *norm) |
| 2302 | { |
| 2303 | return 0; |
| 2304 | } |
| 2305 | |
| 2306 | static int radio_queryctrl(struct file *file, void *priv, |
| 2307 | struct v4l2_queryctrl *c) |
| 2308 | { |
| 2309 | const struct v4l2_queryctrl *ctrl; |
| 2310 | |
| 2311 | if (c->id < V4L2_CID_BASE || |
| 2312 | c->id >= V4L2_CID_LASTP1) |
| 2313 | return -EINVAL; |
| 2314 | if (c->id == V4L2_CID_AUDIO_MUTE) { |
| 2315 | ctrl = ctrl_by_id(c->id); |
| 2316 | *c = *ctrl; |
| 2317 | } else |
| 2318 | *c = no_ctrl; |
| 2319 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 2322 | static const struct file_operations video_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | { |
| 2324 | .owner = THIS_MODULE, |
| 2325 | .open = video_open, |
| 2326 | .release = video_release, |
| 2327 | .read = video_read, |
| 2328 | .poll = video_poll, |
| 2329 | .mmap = video_mmap, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2330 | .ioctl = video_ioctl2, |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 2331 | .compat_ioctl = v4l_compat_ioctl32, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | .llseek = no_llseek, |
| 2333 | }; |
| 2334 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 2335 | static const struct file_operations radio_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | { |
| 2337 | .owner = THIS_MODULE, |
| 2338 | .open = video_open, |
| 2339 | .release = video_release, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2340 | .ioctl = video_ioctl2, |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 2341 | .compat_ioctl = v4l_compat_ioctl32, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | .llseek = no_llseek, |
| 2343 | }; |
| 2344 | |
| 2345 | /* ----------------------------------------------------------- */ |
| 2346 | /* exported stuff */ |
| 2347 | |
| 2348 | struct video_device saa7134_video_template = |
| 2349 | { |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2350 | .name = "saa7134-video", |
| 2351 | .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER | |
| 2352 | VID_TYPE_CLIPPING|VID_TYPE_SCALES, |
| 2353 | .fops = &video_fops, |
| 2354 | .minor = -1, |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2355 | .vidioc_querycap = saa7134_querycap, |
| 2356 | .vidioc_enum_fmt_cap = saa7134_enum_fmt_cap, |
| 2357 | .vidioc_g_fmt_cap = saa7134_g_fmt_cap, |
| 2358 | .vidioc_try_fmt_cap = saa7134_try_fmt_cap, |
| 2359 | .vidioc_s_fmt_cap = saa7134_s_fmt_cap, |
| 2360 | .vidioc_enum_fmt_overlay = saa7134_enum_fmt_overlay, |
| 2361 | .vidioc_g_fmt_overlay = saa7134_g_fmt_overlay, |
| 2362 | .vidioc_try_fmt_overlay = saa7134_try_fmt_overlay, |
| 2363 | .vidioc_s_fmt_overlay = saa7134_s_fmt_overlay, |
| 2364 | .vidioc_enum_fmt_vbi = saa7134_enum_fmt_vbi, |
| 2365 | .vidioc_g_fmt_vbi = saa7134_try_get_set_fmt_vbi, |
| 2366 | .vidioc_try_fmt_vbi = saa7134_try_get_set_fmt_vbi, |
| 2367 | .vidioc_s_fmt_vbi = saa7134_try_get_set_fmt_vbi, |
| 2368 | .vidioc_g_audio = saa7134_g_audio, |
| 2369 | .vidioc_s_audio = saa7134_s_audio, |
| 2370 | .vidioc_cropcap = saa7134_cropcap, |
| 2371 | .vidioc_reqbufs = saa7134_reqbufs, |
| 2372 | .vidioc_querybuf = saa7134_querybuf, |
| 2373 | .vidioc_qbuf = saa7134_qbuf, |
| 2374 | .vidioc_dqbuf = saa7134_dqbuf, |
| 2375 | .vidioc_s_std = saa7134_s_std, |
| 2376 | .vidioc_enum_input = saa7134_enum_input, |
| 2377 | .vidioc_g_input = saa7134_g_input, |
| 2378 | .vidioc_s_input = saa7134_s_input, |
| 2379 | .vidioc_queryctrl = saa7134_queryctrl, |
| 2380 | .vidioc_g_ctrl = saa7134_g_ctrl, |
| 2381 | .vidioc_s_ctrl = saa7134_s_ctrl, |
| 2382 | .vidioc_streamon = saa7134_streamon, |
| 2383 | .vidioc_streamoff = saa7134_streamoff, |
| 2384 | .vidioc_g_tuner = saa7134_g_tuner, |
| 2385 | .vidioc_s_tuner = saa7134_s_tuner, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2386 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 2387 | .vidiocgmbuf = vidiocgmbuf, |
| 2388 | #endif |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2389 | .vidioc_g_crop = saa7134_g_crop, |
| 2390 | .vidioc_s_crop = saa7134_s_crop, |
| 2391 | .vidioc_g_fbuf = saa7134_g_fbuf, |
| 2392 | .vidioc_s_fbuf = saa7134_s_fbuf, |
| 2393 | .vidioc_overlay = saa7134_overlay, |
| 2394 | .vidioc_g_priority = saa7134_g_priority, |
| 2395 | .vidioc_s_priority = saa7134_s_priority, |
| 2396 | .vidioc_g_parm = saa7134_g_parm, |
| 2397 | .vidioc_g_frequency = saa7134_g_frequency, |
| 2398 | .vidioc_s_frequency = saa7134_s_frequency, |
Mauro Carvalho Chehab | 8c85454 | 2007-12-07 17:34:48 -0300 | [diff] [blame] | 2399 | .tvnorms = SAA7134_NORMS, |
| 2400 | .current_norm = V4L2_STD_PAL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | }; |
| 2402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | struct video_device saa7134_radio_template = |
| 2404 | { |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2405 | .name = "saa7134-radio", |
| 2406 | .type = VID_TYPE_TUNER, |
| 2407 | .fops = &radio_fops, |
| 2408 | .minor = -1, |
Douglas Schilling Landgraf | 8f61ae2 | 2007-12-07 17:09:53 -0300 | [diff] [blame] | 2409 | .vidioc_querycap = radio_querycap, |
| 2410 | .vidioc_g_tuner = radio_g_tuner, |
| 2411 | .vidioc_enum_input = radio_enum_input, |
| 2412 | .vidioc_g_audio = radio_g_audio, |
| 2413 | .vidioc_s_tuner = radio_s_tuner, |
| 2414 | .vidioc_s_audio = radio_s_audio, |
| 2415 | .vidioc_s_input = radio_s_input, |
| 2416 | .vidioc_s_std = radio_s_std, |
| 2417 | .vidioc_queryctrl = radio_queryctrl, |
| 2418 | .vidioc_g_input = radio_g_input, |
Mauro Carvalho Chehab | bfb12e3 | 2007-12-11 11:51:53 -0300 | [diff] [blame] | 2419 | .vidioc_g_ctrl = saa7134_g_ctrl, |
| 2420 | .vidioc_s_ctrl = saa7134_s_ctrl, |
| 2421 | .vidioc_g_frequency = saa7134_g_frequency, |
| 2422 | .vidioc_s_frequency = saa7134_s_frequency, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | }; |
| 2424 | |
| 2425 | int saa7134_video_init1(struct saa7134_dev *dev) |
| 2426 | { |
| 2427 | /* sanitycheck insmod options */ |
| 2428 | if (gbuffers < 2 || gbuffers > VIDEO_MAX_FRAME) |
| 2429 | gbuffers = 2; |
| 2430 | if (gbufsize < 0 || gbufsize > gbufsize_max) |
| 2431 | gbufsize = gbufsize_max; |
| 2432 | gbufsize = (gbufsize + PAGE_SIZE - 1) & PAGE_MASK; |
| 2433 | |
| 2434 | /* put some sensible defaults into the data structures ... */ |
| 2435 | dev->ctl_bright = ctrl_by_id(V4L2_CID_BRIGHTNESS)->default_value; |
| 2436 | dev->ctl_contrast = ctrl_by_id(V4L2_CID_CONTRAST)->default_value; |
| 2437 | dev->ctl_hue = ctrl_by_id(V4L2_CID_HUE)->default_value; |
| 2438 | dev->ctl_saturation = ctrl_by_id(V4L2_CID_SATURATION)->default_value; |
| 2439 | dev->ctl_volume = ctrl_by_id(V4L2_CID_AUDIO_VOLUME)->default_value; |
| 2440 | dev->ctl_mute = 1; // ctrl_by_id(V4L2_CID_AUDIO_MUTE)->default_value; |
| 2441 | dev->ctl_invert = ctrl_by_id(V4L2_CID_PRIVATE_INVERT)->default_value; |
| 2442 | dev->ctl_automute = ctrl_by_id(V4L2_CID_PRIVATE_AUTOMUTE)->default_value; |
| 2443 | |
| 2444 | if (dev->tda9887_conf && dev->ctl_automute) |
| 2445 | dev->tda9887_conf |= TDA9887_AUTOMUTE; |
| 2446 | dev->automute = 0; |
| 2447 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 2448 | INIT_LIST_HEAD(&dev->video_q.queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | init_timer(&dev->video_q.timeout); |
| 2450 | dev->video_q.timeout.function = saa7134_buffer_timeout; |
| 2451 | dev->video_q.timeout.data = (unsigned long)(&dev->video_q); |
| 2452 | dev->video_q.dev = dev; |
| 2453 | |
Maxim Levitsky | cb71201 | 2007-09-27 20:34:25 -0300 | [diff] [blame] | 2454 | if (saa7134_boards[dev->board].video_out) |
| 2455 | saa7134_videoport_init(dev); |
| 2456 | |
| 2457 | return 0; |
| 2458 | } |
| 2459 | |
| 2460 | int saa7134_videoport_init(struct saa7134_dev *dev) |
| 2461 | { |
| 2462 | /* enable video output */ |
| 2463 | int vo = saa7134_boards[dev->board].video_out; |
| 2464 | int video_reg; |
| 2465 | unsigned int vid_port_opts = saa7134_boards[dev->board].vid_port_opts; |
| 2466 | saa_writeb(SAA7134_VIDEO_PORT_CTRL0, video_out[vo][0]); |
| 2467 | video_reg = video_out[vo][1]; |
| 2468 | if (vid_port_opts & SET_T_CODE_POLARITY_NON_INVERTED) |
| 2469 | video_reg &= ~VP_T_CODE_P_INVERTED; |
| 2470 | saa_writeb(SAA7134_VIDEO_PORT_CTRL1, video_reg); |
| 2471 | saa_writeb(SAA7134_VIDEO_PORT_CTRL2, video_out[vo][2]); |
| 2472 | saa_writeb(SAA7134_VIDEO_PORT_CTRL3, video_out[vo][3]); |
| 2473 | saa_writeb(SAA7134_VIDEO_PORT_CTRL4, video_out[vo][4]); |
| 2474 | video_reg = video_out[vo][5]; |
| 2475 | if (vid_port_opts & SET_CLOCK_NOT_DELAYED) |
| 2476 | video_reg &= ~VP_CLK_CTRL2_DELAYED; |
| 2477 | if (vid_port_opts & SET_CLOCK_INVERTED) |
| 2478 | video_reg |= VP_CLK_CTRL1_INVERTED; |
| 2479 | saa_writeb(SAA7134_VIDEO_PORT_CTRL5, video_reg); |
| 2480 | video_reg = video_out[vo][6]; |
| 2481 | if (vid_port_opts & SET_VSYNC_OFF) { |
| 2482 | video_reg &= ~VP_VS_TYPE_MASK; |
| 2483 | video_reg |= VP_VS_TYPE_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | } |
Maxim Levitsky | cb71201 | 2007-09-27 20:34:25 -0300 | [diff] [blame] | 2485 | saa_writeb(SAA7134_VIDEO_PORT_CTRL6, video_reg); |
| 2486 | saa_writeb(SAA7134_VIDEO_PORT_CTRL7, video_out[vo][7]); |
| 2487 | saa_writeb(SAA7134_VIDEO_PORT_CTRL8, video_out[vo][8]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | |
| 2489 | return 0; |
| 2490 | } |
| 2491 | |
| 2492 | int saa7134_video_init2(struct saa7134_dev *dev) |
| 2493 | { |
| 2494 | /* init video hw */ |
| 2495 | set_tvnorm(dev,&tvnorms[0]); |
| 2496 | video_mux(dev,0); |
| 2497 | saa7134_tvaudio_setmute(dev); |
| 2498 | saa7134_tvaudio_setvolume(dev,dev->ctl_volume); |
| 2499 | return 0; |
| 2500 | } |
| 2501 | |
Maxim Levitsky | 11f7078 | 2007-09-27 20:44:39 -0300 | [diff] [blame] | 2502 | void saa7134_irq_video_signalchange(struct saa7134_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | { |
| 2504 | static const char *st[] = { |
| 2505 | "(no signal)", "NTSC", "PAL", "SECAM" }; |
| 2506 | u32 st1,st2; |
| 2507 | |
| 2508 | st1 = saa_readb(SAA7134_STATUS_VIDEO1); |
| 2509 | st2 = saa_readb(SAA7134_STATUS_VIDEO2); |
| 2510 | dprintk("DCSDT: pll: %s, sync: %s, norm: %s\n", |
| 2511 | (st1 & 0x40) ? "not locked" : "locked", |
| 2512 | (st2 & 0x40) ? "no" : "yes", |
| 2513 | st[st1 & 0x03]); |
Maxim Levitsky | 11f7078 | 2007-09-27 20:44:39 -0300 | [diff] [blame] | 2514 | dev->nosignal = (st1 & 0x40) || (st2 & 0x40) || !(st2 & 0x1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | |
| 2516 | if (dev->nosignal) { |
| 2517 | /* no video signal -> mute audio */ |
| 2518 | if (dev->ctl_automute) |
| 2519 | dev->automute = 1; |
| 2520 | saa7134_tvaudio_setmute(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | } else { |
| 2522 | /* wake up tvaudio audio carrier scan thread */ |
| 2523 | saa7134_tvaudio_do_scan(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | } |
Maxim Levitsky | 11f7078 | 2007-09-27 20:44:39 -0300 | [diff] [blame] | 2525 | |
| 2526 | if ((st2 & 0x80) && !noninterlaced && !dev->nosignal) |
| 2527 | saa_clearb(SAA7134_SYNC_CTRL, 0x20); |
| 2528 | else |
| 2529 | saa_setb(SAA7134_SYNC_CTRL, 0x20); |
| 2530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | if (dev->mops && dev->mops->signal_change) |
| 2532 | dev->mops->signal_change(dev); |
| 2533 | } |
| 2534 | |
Maxim Levitsky | 11f7078 | 2007-09-27 20:44:39 -0300 | [diff] [blame] | 2535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | void saa7134_irq_video_done(struct saa7134_dev *dev, unsigned long status) |
| 2537 | { |
| 2538 | enum v4l2_field field; |
| 2539 | |
| 2540 | spin_lock(&dev->slock); |
| 2541 | if (dev->video_q.curr) { |
| 2542 | dev->video_fieldcount++; |
| 2543 | field = dev->video_q.curr->vb.field; |
| 2544 | if (V4L2_FIELD_HAS_BOTH(field)) { |
| 2545 | /* make sure we have seen both fields */ |
| 2546 | if ((status & 0x10) == 0x00) { |
| 2547 | dev->video_q.curr->top_seen = 1; |
| 2548 | goto done; |
| 2549 | } |
| 2550 | if (!dev->video_q.curr->top_seen) |
| 2551 | goto done; |
| 2552 | } else if (field == V4L2_FIELD_TOP) { |
| 2553 | if ((status & 0x10) != 0x10) |
| 2554 | goto done; |
| 2555 | } else if (field == V4L2_FIELD_BOTTOM) { |
| 2556 | if ((status & 0x10) != 0x00) |
| 2557 | goto done; |
| 2558 | } |
| 2559 | dev->video_q.curr->vb.field_count = dev->video_fieldcount; |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 2560 | saa7134_buffer_finish(dev,&dev->video_q,VIDEOBUF_DONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | } |
| 2562 | saa7134_buffer_next(dev,&dev->video_q); |
| 2563 | |
| 2564 | done: |
| 2565 | spin_unlock(&dev->slock); |
| 2566 | } |
| 2567 | |
| 2568 | /* ----------------------------------------------------------- */ |
| 2569 | /* |
| 2570 | * Local variables: |
| 2571 | * c-basic-offset: 8 |
| 2572 | * End: |
| 2573 | */ |