From patchwork Fri Mar 20 14:31:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Laddha X-Patchwork-Id: 6057341 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 711EA9F399 for ; Fri, 20 Mar 2015 14:40:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8EAD020520 for ; Fri, 20 Mar 2015 14:40:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8E895203A0 for ; Fri, 20 Mar 2015 14:40:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751479AbbCTOkN (ORCPT ); Fri, 20 Mar 2015 10:40:13 -0400 Received: from aer-iport-2.cisco.com ([173.38.203.52]:7320 "EHLO aer-iport-2.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751444AbbCTOkL (ORCPT ); Fri, 20 Mar 2015 10:40:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=2990; q=dns/txt; s=iport; t=1426862411; x=1428072011; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=btJOuz03Xwg5dI+JNN8AA2O9Vc6ZXxShPMO4Hhcz+5c=; b=JWiPUJt2++dB4txYhR10X1jInpvXP77pDBDKKw4k3rkTaMyFKv/pfk/B QVpz6M699Zg6jacGOaf7Ko5pawU6YSpE08UK+ziFEMAHs/X0hEeidWXAs eXbOO8m4KqqrVAv8uMy0D2qhfozHAB1e00NTad/2OXm7UtKxJsY/Eogax 8=; X-IronPort-AV: E=Sophos;i="5.11,437,1422921600"; d="scan'208";a="394075180" Received: from aer-iport-nat.cisco.com (HELO aer-core-2.cisco.com) ([173.38.203.22]) by aer-iport-2.cisco.com with ESMTP; 20 Mar 2015 14:40:10 +0000 Received: from pla-VB.cisco.com ([10.65.67.170]) by aer-core-2.cisco.com (8.14.5/8.14.5) with ESMTP id t2KEe7kL022084; Fri, 20 Mar 2015 14:40:09 GMT From: Prashant Laddha To: Linux Media Mailing List Cc: Hans Verkuil , Prashant Laddha Subject: [PATCH 2/2] vivid: add support to set CVT, GTF timings Date: Fri, 20 Mar 2015 20:01:32 +0530 Message-Id: <1426861892-26656-2-git-send-email-prladdha@cisco.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426861892-26656-1-git-send-email-prladdha@cisco.com> References: <1426861892-26656-1-git-send-email-prladdha@cisco.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY, USER_IN_DEF_DKIM_WL autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In addition to v4l2_find_dv_timings_cap(), where timings are serached against the list of preset timings, the incoming timing from v4l2-ctl is checked against CVT and GTF standards. If it confirms to be CVT or GTF, it is treated as valid timing and vivid format is updated with new timings. Cc: Hans Verkuil Signed-off-by: Prashant Laddha --- drivers/media/platform/vivid/vivid-vid-cap.c | 61 +++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/vivid/vivid-vid-cap.c b/drivers/media/platform/vivid/vivid-vid-cap.c index 867a29a..b4ec9b0 100644 --- a/drivers/media/platform/vivid/vivid-vid-cap.c +++ b/drivers/media/platform/vivid/vivid-vid-cap.c @@ -1552,6 +1552,63 @@ int vivid_vid_cap_s_std(struct file *file, void *priv, v4l2_std_id id) return 0; } +static void find_aspect_ratio(u32 width, u32 height, + u32 *num, u32 *denom) +{ + if (!(height % 3) && ((height * 4 / 3) == width)) { + *num = 4; + *denom = 3; + } else if (!(height % 9) && ((height * 16 / 9) == width)) { + *num = 16; + *denom = 9; + } else if (!(height % 10) && ((height * 16 / 10) == width)) { + *num = 16; + *denom = 10; + } else if (!(height % 4) && ((height * 5 / 4) == width)) { + *num = 5; + *denom = 4; + } else if (!(height % 9) && ((height * 15 / 9) == width)) { + *num = 15; + *denom = 9; + } else { /* default to 16:9 */ + *num = 16; + *denom = 9; + } +} + +static bool valid_cvt_gtf_timings(struct v4l2_dv_timings *timings) +{ + struct v4l2_bt_timings *bt = &timings->bt; + u32 total_h_pixel; + u32 total_v_lines; + u32 h_freq; + + if (!v4l2_valid_dv_timings(timings, &vivid_dv_timings_cap, + NULL, NULL)) + return false; + + total_h_pixel = V4L2_DV_BT_FRAME_WIDTH(bt); + total_v_lines = V4L2_DV_BT_FRAME_HEIGHT(bt); + + h_freq = (u32)bt->pixelclock / total_h_pixel; + + if (bt->standards == V4L2_DV_BT_STD_CVT) + return v4l2_detect_cvt(total_v_lines, h_freq, bt->vsync, + bt->polarities, timings); + + if (bt->standards == V4L2_DV_BT_STD_GTF) { + struct v4l2_fract aspect_ratio; + + find_aspect_ratio(bt->width, bt->height, + &aspect_ratio.numerator, + &aspect_ratio.denominator); + return v4l2_detect_gtf(total_v_lines, h_freq, bt->vsync, + bt->polarities, aspect_ratio, timings); + } + + return false; +} + int vivid_vid_cap_s_dv_timings(struct file *file, void *_fh, struct v4l2_dv_timings *timings) { @@ -1561,8 +1618,10 @@ int vivid_vid_cap_s_dv_timings(struct file *file, void *_fh, return -ENODATA; if (vb2_is_busy(&dev->vb_vid_cap_q)) return -EBUSY; + if (!v4l2_find_dv_timings_cap(timings, &vivid_dv_timings_cap, - 0, NULL, NULL)) + 0, NULL, NULL) + && !valid_cvt_gtf_timings(timings)) return -EINVAL; if (v4l2_match_dv_timings(timings, &dev->dv_timings_cap, 0)) return 0;