Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] v4l2-dv-timings: add interlace support in detect cvt/gtf

Extend detect_cvt/gtf API to indicate the format type (interlaced
or progressive). In case of interlaced, the vertical front and back
porch and vsync values for both (odd,even) fields are considered to
derive image height. Populated vsync, vertical front, back porch
values in bt timing structure for even and odd fields and updated
the flags appropriately.

Also modified the functions calling the detect_cvt/gtf(). As of now
these functions are calling detect_cvt/gtf() with interlaced flag
set to false.

Cc: Martin Bugge <marbugge@cisco.com>
Cc: Mats Randgaard <matrandg@cisco.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Prashant Laddha <prladdha@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Prashant Laddha and committed by
Mauro Carvalho Chehab
061ddda6 8cf6874e

+58 -14
+2 -2
drivers/media/i2c/adv7604.c
··· 1331 1331 if (v4l2_detect_cvt(stdi->lcf + 1, hfreq, stdi->lcvs, 1332 1332 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) | 1333 1333 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0), 1334 - timings)) 1334 + false, timings)) 1335 1335 return 0; 1336 1336 if (v4l2_detect_gtf(stdi->lcf + 1, hfreq, stdi->lcvs, 1337 1337 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) | 1338 1338 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0), 1339 - state->aspect_ratio, timings)) 1339 + false, state->aspect_ratio, timings)) 1340 1340 return 0; 1341 1341 1342 1342 v4l2_dbg(2, debug, sd,
+2 -2
drivers/media/i2c/adv7842.c
··· 1445 1445 if (v4l2_detect_cvt(stdi->lcf + 1, hfreq, stdi->lcvs, 1446 1446 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) | 1447 1447 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0), 1448 - timings)) 1448 + false, timings)) 1449 1449 return 0; 1450 1450 if (v4l2_detect_gtf(stdi->lcf + 1, hfreq, stdi->lcvs, 1451 1451 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) | 1452 1452 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0), 1453 - state->aspect_ratio, timings)) 1453 + false, state->aspect_ratio, timings)) 1454 1454 return 0; 1455 1455 1456 1456 v4l2_dbg(2, debug, sd,
+3 -2
drivers/media/platform/vivid/vivid-vid-cap.c
··· 1628 1628 1629 1629 if (bt->standards == 0 || (bt->standards & V4L2_DV_BT_STD_CVT)) { 1630 1630 if (v4l2_detect_cvt(total_v_lines, h_freq, bt->vsync, 1631 - bt->polarities, timings)) 1631 + bt->polarities, false, timings)) 1632 1632 return true; 1633 1633 } 1634 1634 ··· 1639 1639 &aspect_ratio.numerator, 1640 1640 &aspect_ratio.denominator); 1641 1641 if (v4l2_detect_gtf(total_v_lines, h_freq, bt->vsync, 1642 - bt->polarities, aspect_ratio, timings)) 1642 + bt->polarities, false, 1643 + aspect_ratio, timings)) 1643 1644 return true; 1644 1645 } 1645 1646 return false;
+47 -6
drivers/media/v4l2-core/v4l2-dv-timings.c
··· 346 346 * @vsync - the height of the vertical sync in lines. 347 347 * @polarities - the horizontal and vertical polarities (same as struct 348 348 * v4l2_bt_timings polarities). 349 + * @interlaced - if this flag is true, it indicates interlaced format 349 350 * @fmt - the resulting timings. 350 351 * 351 352 * This function will attempt to detect if the given values correspond to a ··· 358 357 * detection function. 359 358 */ 360 359 bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync, 361 - u32 polarities, struct v4l2_dv_timings *fmt) 360 + u32 polarities, bool interlaced, struct v4l2_dv_timings *fmt) 362 361 { 363 362 int v_fp, v_bp, h_fp, h_bp, hsync; 364 363 int frame_width, image_height, image_width; ··· 393 392 if (v_bp < CVT_MIN_V_BPORCH) 394 393 v_bp = CVT_MIN_V_BPORCH; 395 394 } 396 - image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1; 395 + 396 + if (interlaced) 397 + image_height = (frame_height - 2 * v_fp - 2 * vsync - 2 * v_bp) & ~0x1; 398 + else 399 + image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1; 397 400 398 401 if (image_height < 0) 399 402 return false; ··· 470 465 fmt->bt.hsync = hsync; 471 466 fmt->bt.vsync = vsync; 472 467 fmt->bt.hbackporch = frame_width - image_width - h_fp - hsync; 473 - fmt->bt.vbackporch = frame_height - image_height - v_fp - vsync; 468 + 469 + if (!interlaced) { 470 + fmt->bt.vbackporch = frame_height - image_height - v_fp - vsync; 471 + fmt->bt.interlaced = V4L2_DV_PROGRESSIVE; 472 + } else { 473 + fmt->bt.vbackporch = (frame_height - image_height - 2 * v_fp - 474 + 2 * vsync) / 2; 475 + fmt->bt.il_vbackporch = frame_height - image_height - 2 * v_fp - 476 + 2 * vsync - fmt->bt.vbackporch; 477 + fmt->bt.il_vfrontporch = v_fp; 478 + fmt->bt.il_vsync = vsync; 479 + fmt->bt.flags |= V4L2_DV_FL_HALF_LINE; 480 + fmt->bt.interlaced = V4L2_DV_INTERLACED; 481 + } 482 + 474 483 fmt->bt.pixelclock = pix_clk; 475 484 fmt->bt.standards = V4L2_DV_BT_STD_CVT; 485 + 476 486 if (reduced_blanking) 477 487 fmt->bt.flags |= V4L2_DV_FL_REDUCED_BLANKING; 488 + 478 489 return true; 479 490 } 480 491 EXPORT_SYMBOL_GPL(v4l2_detect_cvt); ··· 529 508 * @vsync - the height of the vertical sync in lines. 530 509 * @polarities - the horizontal and vertical polarities (same as struct 531 510 * v4l2_bt_timings polarities). 511 + * @interlaced - if this flag is true, it indicates interlaced format 532 512 * @aspect - preferred aspect ratio. GTF has no method of determining the 533 513 * aspect ratio in order to derive the image width from the 534 514 * image height, so it has to be passed explicitly. Usually ··· 545 523 unsigned hfreq, 546 524 unsigned vsync, 547 525 u32 polarities, 526 + bool interlaced, 548 527 struct v4l2_fract aspect, 549 528 struct v4l2_dv_timings *fmt) 550 529 { ··· 570 547 571 548 /* Vertical */ 572 549 v_fp = GTF_V_FP; 573 - 574 550 v_bp = (GTF_MIN_VSYNC_BP * hfreq + 500000) / 1000000 - vsync; 575 - image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1; 551 + if (interlaced) 552 + image_height = (frame_height - 2 * v_fp - 2 * vsync - 2 * v_bp) & ~0x1; 553 + else 554 + image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1; 576 555 577 556 if (image_height < 0) 578 557 return false; ··· 628 603 fmt->bt.hsync = hsync; 629 604 fmt->bt.vsync = vsync; 630 605 fmt->bt.hbackporch = frame_width - image_width - h_fp - hsync; 631 - fmt->bt.vbackporch = frame_height - image_height - v_fp - vsync; 606 + 607 + if (!interlaced) { 608 + fmt->bt.vbackporch = frame_height - image_height - v_fp - vsync; 609 + fmt->bt.interlaced = V4L2_DV_PROGRESSIVE; 610 + } else { 611 + fmt->bt.vbackporch = (frame_height - image_height - 2 * v_fp - 612 + 2 * vsync) / 2; 613 + fmt->bt.il_vbackporch = frame_height - image_height - 2 * v_fp - 614 + 2 * vsync - fmt->bt.vbackporch; 615 + fmt->bt.il_vfrontporch = v_fp; 616 + fmt->bt.il_vsync = vsync; 617 + fmt->bt.flags |= V4L2_DV_FL_HALF_LINE; 618 + fmt->bt.interlaced = V4L2_DV_INTERLACED; 619 + } 620 + 632 621 fmt->bt.pixelclock = pix_clk; 633 622 fmt->bt.standards = V4L2_DV_BT_STD_GTF; 623 + 634 624 if (!default_gtf) 635 625 fmt->bt.flags |= V4L2_DV_FL_REDUCED_BLANKING; 626 + 636 627 return true; 637 628 } 638 629 EXPORT_SYMBOL_GPL(v4l2_detect_gtf);
+4 -2
include/media/v4l2-dv-timings.h
··· 117 117 * @vsync - the height of the vertical sync in lines. 118 118 * @polarities - the horizontal and vertical polarities (same as struct 119 119 * v4l2_bt_timings polarities). 120 + * @interlaced - if this flag is true, it indicates interlaced format 120 121 * @fmt - the resulting timings. 121 122 * 122 123 * This function will attempt to detect if the given values correspond to a ··· 125 124 * in with the found CVT timings. 126 125 */ 127 126 bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync, 128 - u32 polarities, struct v4l2_dv_timings *fmt); 127 + u32 polarities, bool interlaced, struct v4l2_dv_timings *fmt); 129 128 130 129 /** v4l2_detect_gtf - detect if the given timings follow the GTF standard 131 130 * @frame_height - the total height of the frame (including blanking) in lines. ··· 133 132 * @vsync - the height of the vertical sync in lines. 134 133 * @polarities - the horizontal and vertical polarities (same as struct 135 134 * v4l2_bt_timings polarities). 135 + * @interlaced - if this flag is true, it indicates interlaced format 136 136 * @aspect - preferred aspect ratio. GTF has no method of determining the 137 137 * aspect ratio in order to derive the image width from the 138 138 * image height, so it has to be passed explicitly. Usually ··· 146 144 * in with the found GTF timings. 147 145 */ 148 146 bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, unsigned vsync, 149 - u32 polarities, struct v4l2_fract aspect, 147 + u32 polarities, bool interlaced, struct v4l2_fract aspect, 150 148 struct v4l2_dv_timings *fmt); 151 149 152 150 /** v4l2_calc_aspect_ratio - calculate the aspect ratio based on bytes