Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1170803pxj; Fri, 21 May 2021 08:03:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9qGd29FGITvbIkPf2xrCXrYvd3TZxM2JZZMMV2ESi8rGwO/2xqfnCaQ9GkWIZQ4V6DJj/ X-Received: by 2002:aa7:db94:: with SMTP id u20mr11632205edt.381.1621609439246; Fri, 21 May 2021 08:03:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621609439; cv=none; d=google.com; s=arc-20160816; b=RKEltRFuFK6awwq2IjENnL9mRRDLMREpkCClSpsJegnhLVi0D3zduZaQDCwCOTlslU CpgGWK4NlMYJn1BaYynekMGOwYl+bDdveN2DR8h3gorBMYoRVekPguld31YpiyQygvi7 txLaBevQ679GA0IcKVIXQtYLHuOEJzpTCDJEL+VQyZo4iUtw7iL8m+i3oUlQk3QlaJV7 wVkSRAhmDqdnNKVrGNF6P2hZRgkO6A/8VRl/F7G+18CulxPmog/gAhtkGeMXBsX/4Kea LL/3MV8/3N9LcEB4XS47qkuyK3hTytn2ucQOwkd1SAPLkbnra+zC5ouwFPVnHWUMDcAi f9rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=xSuvjYqxzyBijangSRw9lFhtoZvKGPPFIa1fBTK45Ng=; b=LFBHRo2mMNB9W8BumDX/8K4WZ7Chyt3bCLfZLSM2bCO6w8hGU3oMA5ksVGXMUW36nM MbLJH0cFsXPjMJVV/hb1ISs40rbCKN3CqJxFlT+a6w81+fbZ/W4Cl+kTFYGJ6yrRGOF1 nd7kdpObyaDkdt5tavgOYVSgDJLRObudqq/O5Vfqan2oJ3fTaJRSHGUguwV6Or0Advjw G/qiPMN16dQHUuBY3slteO69jtwRNdNNLn2hCU3gOM6AqgY/hX05bdi2v8Lb2x3VLrOZ bHnclsgtFGW9wKM4rXeiNRgMob4DGw8HSZjoVi0/Y7Xuwj2wD8Z0I+7rq42iA+eqW+PF A7rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=aW61Kkql; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t1si5131722edq.541.2021.05.21.08.03.36; Fri, 21 May 2021 08:03:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=aW61Kkql; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232923AbhETPtp (ORCPT + 99 others); Thu, 20 May 2021 11:49:45 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:45080 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231966AbhETPtl (ORCPT ); Thu, 20 May 2021 11:49:41 -0400 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 63A03C06B5; Thu, 20 May 2021 15:48:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1621525699; bh=iDYmYWV64aAc5K1mNGxWkrk1Utm//trijiEmustKlxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=aW61KkqlRYTb+CBrVySjmaKeDtX26DVzsemD9F487xV+JxPTYcZQUicxWaelBmSJQ OKoq8FLOEG4n/D+hMiMT3+4jZ/hbZS7ZBUUscxP9kBmC0fNLmF+Q40e9JDBwW6ziLG qw8DYIJrHLkkStEjpRFx4TOswxYoH6vRZu4+GmeQT6tfdCQxgTIFJ/xNg+1K9mFjCs WuB5yzQO/3dFQxpAyf2OyLmmlmv7EVN1jnrDH9uVUvPf78hHNyhmJ7pIyvaEACCrN5 EzgwAh/lldOp/cd85/hAo5uVo8+aF4EAqjcNqil2/JNDwpqnDmxCZoMPl8JquBZcIU c0M6gwjeGcQyw== Received: from de02dwvm009.internal.synopsys.com (de02dwvm009.internal.synopsys.com [10.225.17.73]) by mailhost.synopsys.com (Postfix) with ESMTP id 2CEA5A0074; Thu, 20 May 2021 15:48:18 +0000 (UTC) X-SNPS-Relay: synopsys.com From: Nelson Costa To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Kishon Vijay Abraham I , Vinod Koul , Rob Herring , Jose Abreu , Nelson Costa Subject: [RFC v2 8/9] media: dwc: dw-hdmi-rx: Add support for Aspect Ratio Date: Thu, 20 May 2021 17:48:02 +0200 Message-Id: <4a2781f854f8bad68b542debe43c989424a21d80.1621524721.git.nelson.costa@synopsys.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds support to get aspect ratio for the current video being received and provide the info through v4l2 API query_dv_timings. Signed-off-by: Nelson Costa --- drivers/media/platform/dwc/dw-hdmi-rx.c | 54 +++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/dwc/dw-hdmi-rx.c b/drivers/media/platform/dwc/dw-hdmi-rx.c index b20eccc..a468a93 100644 --- a/drivers/media/platform/dwc/dw-hdmi-rx.c +++ b/drivers/media/platform/dwc/dw-hdmi-rx.c @@ -2250,13 +2250,31 @@ static u32 dw_hdmi_get_width(struct dw_hdmi_dev *dw_dev) return width; } +static int dw_hdmi_vic_to_cea861(u8 hdmi_vic) +{ + switch (hdmi_vic) { + case 1: + return 95; + case 2: + return 94; + case 3: + return 93; + case 4: + return 98; + default: + return 0; + } +} + static int dw_hdmi_query_dv_timings(struct v4l2_subdev *sd, struct v4l2_dv_timings *timings) { struct dw_hdmi_dev *dw_dev = to_dw_dev(sd); struct v4l2_bt_timings *bt = &timings->bt; + struct v4l2_dv_timings t = {0}; bool is_hdmi_vic; u32 htot, hofs; + u8 cea861_vic; u32 vtot; u8 vic; @@ -2351,8 +2369,40 @@ static int dw_hdmi_query_dv_timings(struct v4l2_subdev *sd, } } - dev_dbg(dw_dev->dev, "%s: width=%u, height=%u, mbuscode=%u\n", __func__, - bt->width, bt->height, dw_hdmi_get_mbus_code(dw_dev)); + if (is_hdmi_vic) + cea861_vic = dw_hdmi_vic_to_cea861(bt->hdmi_vic); + else + cea861_vic = vic; + + /* picture aspect ratio based on v4l2 dv timings array */ + if (v4l2_find_dv_timings_cea861_vic(&t, cea861_vic)) { + /* when the numerator/denominator are zero means that the + * picture aspect ratio is the same of the active measures ratio + */ + if (!t.bt.picture_aspect.numerator) { + unsigned long n, d; + + rational_best_approximation(t.bt.width, t.bt.height, + t.bt.width, t.bt.height, + &n, &d); + t.bt.picture_aspect.numerator = n; + t.bt.picture_aspect.denominator = d; + } + + bt->picture_aspect = t.bt.picture_aspect; + } else { + bt->picture_aspect.numerator = 0; + bt->picture_aspect.denominator = 0; + dev_dbg(dw_dev->dev, + "%s: cea861_vic=%d was not found in v4l2 dv timings", + __func__, cea861_vic); + } + + dev_dbg(dw_dev->dev, + "%s: width=%u, height=%u, mbuscode=%u, cea861_vic=%d, ar={%d,%d}\n", + __func__, bt->width, bt->height, dw_hdmi_get_mbus_code(dw_dev), + cea861_vic, bt->picture_aspect.numerator, + bt->picture_aspect.denominator); return 0; } -- 2.7.4