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