Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp621688pxy; Wed, 28 Apr 2021 10:38:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjUCjtkgky6EVTzXrjN+wC/GMG7oLh39gq+xBLbd62M4QWpro50mtybzATVxtmzCpt/mHn X-Received: by 2002:aa7:d413:: with SMTP id z19mr13044125edq.37.1619631509433; Wed, 28 Apr 2021 10:38:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619631509; cv=none; d=google.com; s=arc-20160816; b=jmJ0+pbfoTqE2UB6JA3sGLDIzIc8hBZi4MDMtrzxBXmhkq2XehRqdFAl3yZyFJ/QAS FEx8DsUj6re4pWMzOKnPy9QetYNvb6/X0WJEWqnOMl+FlsCxm73ORIRw5JZslX6GFHn+ mOhSvD0DfJie1uxbJooksEdQBWw/JNAyBXu/w3E94gMdRQJsVFkCnuQx1d1mWF4o4J8J b00LQSZIUCawbilSEq5CyB8fY/lrUoJlXpoeQksA1Hg+xqZWBcbxmZo268BxGrc5Ur+x yCJ8PBVSi1v7q7xepPKydat53W5+5o/wpaZQXuyTycLqJl8Gv/7Sihk6/WQsu+unY2lc Ul9g== 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=i7vam7226CEykwRDzxZ5bMNq5N265L8tNsSXq8cv+OQ=; b=D2CuhuZ1EpM7xoYBNCC8EX7/lFYn9pCeIXjz8JOsdTSgNQm2rRLo7Pd718csrCWT96 Jq5d0vkuxXBCIiw2hXTU+sNJMj6W2/XRv01/c3n8oYeq9oBh9d6qBJ9WXcW5sgvxWgEq be+UN96xOQXJjaWO7JG/FoJ6pgOsBtekRGND/M2Woinjgg8CD/Twa9rkUNzOsRL8Kd50 67FADc4o0B9kRD1zeI5GkG/gSF7923Z1MFMf7GFnVCLR0CHygU4U1F+UjsYEixBM4MMR nZEz397wgwP17KgJRVPWxaOwDUZrSDYTPkfU731u45CDH+DGTdUwCp/Ox78IZg8tULjF mp3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=PW7xuBIs; 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 a18si570332ejy.632.2021.04.28.10.38.04; Wed, 28 Apr 2021 10:38:29 -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=PW7xuBIs; 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 S239837AbhD1P0D (ORCPT + 99 others); Wed, 28 Apr 2021 11:26:03 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:56546 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230527AbhD1P0D (ORCPT ); Wed, 28 Apr 2021 11:26:03 -0400 Received: from mailhost.synopsys.com (mdc-mailhost2.synopsys.com [10.225.0.210]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 4063B405C3; Wed, 28 Apr 2021 15:25:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1619623518; bh=EIYG6JjhDPjkluDzN5n/M9ZenHvTzZ4e//kR0u2y2CE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=PW7xuBIsmUZGwjkrAHFwXmBBQImaC1i1oKPSZqRxECT1C9V1ui7wqUcjte6P+RRJA cQ0gcXVXgXfk3cXIdl/u/Fiy9brA1LelY9sHCqlGqo0icx7bTi+4cZjUtbhoi3b3Pc YP+orlIsqAse2NUzZU/jzN11wUX1IUDUJL8BoWCHH7rENV//bV42VEMHMRnwRmPank I2EVbHYS964OuNb9CY3u8/g+pnFcsOl/f2dH6x2OVaAf23A+XqJT9wAjZF/vV9XThu 5znUqY/qduvUen5HxHxgaI45dqBAFUosq0PTQ2ppNCuFq+NdfQWbmnmOref5V3miBA BnQU8g7FYKQ7w== Received: from de02dwvm009.internal.synopsys.com (de02dwvm009.internal.synopsys.com [10.225.17.73]) by mailhost.synopsys.com (Postfix) with ESMTP id AFFC3A0099; Wed, 28 Apr 2021 15:25:16 +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 7/8] media: dwc: dw-hdmi-rx: Add support for Aspect Ratio Date: Wed, 28 Apr 2021 17:25:10 +0200 Message-Id: <0acdcfbe29d2cbb2974377d79391e55f5b489851.1618937288.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 07ac62f..78d9ef3 100644 --- a/drivers/media/platform/dwc/dw-hdmi-rx.c +++ b/drivers/media/platform/dwc/dw-hdmi-rx.c @@ -2252,13 +2252,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; @@ -2353,8 +2371,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