Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp852252pxb; Thu, 19 Aug 2021 12:56:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiYLlpSj3oo4Wu4ZQAej4Y3qs80f/DHIcwbqbapmiuxWCBkpb/XTCafpd71VVxijFUNpDw X-Received: by 2002:a17:907:f86:: with SMTP id kb6mr17802003ejc.138.1629402987848; Thu, 19 Aug 2021 12:56:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629402987; cv=none; d=google.com; s=arc-20160816; b=bfUSUF+yuG2i4jgUd2TuHtnc4s4zODa8mo1DL+K0x8iBeKLdoNpKAWyauc68ZkEbyE g6xZkw4Z3dME9ebJwlpUtSgVrriGhJOlU3RkikBzPYW0ToG8pWlh1zesVruydRnLjKbv 0Vvh38WruEKV0mNo2l1/drMAY0GEVRcfpQTeQ28+PSb1dnqApinT8vKc1GhIz91mZuHw xzBm9jpwGjamm8DUR8Zy1eMZxT00gHOabP9JpPi9mB18qm2ol2omUvG7xRlWrg1X3ffS 27cBCKqWv69K4Pfayq20x0mM3Nv2HWWKwWT7iyMQFc6o9tPYkxoIomBp9J7eDuPtbaPh pOHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=JLR3/Tzo397T8TPt0QvJ4Ukv/VXdUANi7HJVf1QYHrQ=; b=SedEJOWe2JSD3e7SScx+mFT+TtZmm9w6dZwYSfMOTfosh/VCkEe2cmOonCISO8qWcQ CGNlOSvd3yMHzrWTIpdEQL5VanGiGPsplN5KOWnDXjG19MzuaOFCgwxHSAEV0Ut82Tjc Mj7WzByjRld954QpEC60rL8KAzk9USHX3gFUDXdPQDS+LyDkbOJjQqdss022/stufWLy QBDAfBDpmPGwLN6OxnwYC0hMDyl7FwMxzpRCEZF12wAdwbH+JdNBBIkNVdYJm9qvB4Jw ZRBVorazYH0jMJ314keuSr2PwzWD5DU4zVZBSxfBW4A2kiDUVZ9fT1ednAtT0VsmyW5P PhQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gateworks-com.20150623.gappssmtp.com header.s=20150623 header.b=g8z6YrVZ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p23si4325221edw.135.2021.08.19.12.56.03; Thu, 19 Aug 2021 12:56:27 -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=@gateworks-com.20150623.gappssmtp.com header.s=20150623 header.b=g8z6YrVZ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229677AbhHSTxN (ORCPT + 99 others); Thu, 19 Aug 2021 15:53:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230506AbhHSTxN (ORCPT ); Thu, 19 Aug 2021 15:53:13 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1E4BC061756 for ; Thu, 19 Aug 2021 12:52:36 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id n5so5712240pjt.4 for ; Thu, 19 Aug 2021 12:52:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gateworks-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=JLR3/Tzo397T8TPt0QvJ4Ukv/VXdUANi7HJVf1QYHrQ=; b=g8z6YrVZArvT/HXJx3/mHjHi6M4D7D/EgtR2obzEHoCprIWkSn6MwqpjSlXWyFkcnK Pj/aVsb+DFjpq9wD/m4he9+J3kDkEWeyX3WbMYs43rPpfobFYVp+JBXvfvMNUQgjLOXN U7+73p71PTKRdOdnbrJmi7wZuRr+YwcBGghhPO9aFtfTyUOdH6/0x9DwVfArtwgIHqfR caL/G6Z/iSfy+l+pVuyqULhrytDDTGJ4QfW+a6IFp/A2K3irj417Z6nSxxKoxx/NQVLJ CBdL102e/tfzKQ0JZWMRBnjQsG2VjSr80z9JyMADJ9lGAKdzVjiFFAgYR2cQ4HMJriR1 e7EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=JLR3/Tzo397T8TPt0QvJ4Ukv/VXdUANi7HJVf1QYHrQ=; b=ZT6kR7teGr2FdDIDIlcu9XCuvyN0QyZXdFAslobcq6wkhzC+E1nA2f/mSqJcYlcmMw uS95EHF+GMRZatQYJOvVxTQfHt9XjeUQxZD96/66OG973Qh58IENA/d1pHURMR59hV1j PENEh9ZQCrw7v1p7qICisNUvlArYmLccbmXrAMjKbvbk1HzD5pQGXyFvwvyLLybhxMwq Zwkinz8aoEKhLhAGOGXjc96LyyzpB2QLW7rNKasTAt2yIjn5KAzmexopNXb7TLnZ6rmR l1geEZetlDgKj9DE3PoTs+OxNqhjrgiwiU9Z20qVlBJyE+NV5SY9iFSqOf2y7Aa/kObw U2iA== X-Gm-Message-State: AOAM531oeacpI2whTygrQI9qnTGhX8ZLt3P819sRit/vvAIl8+sh82qj 0gWRIJmD+ECPbkK/bRTvcUuoUfrNEA5BZPIQXSPd1Q== X-Received: by 2002:a17:902:a9c7:b029:12b:349:b318 with SMTP id b7-20020a170902a9c7b029012b0349b318mr13281658plr.13.1629402756032; Thu, 19 Aug 2021 12:52:36 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Tim Harvey Date: Thu, 19 Aug 2021 12:52:24 -0700 Message-ID: Subject: Re: [PATCH v2] TDA1997x: replace video detection routine To: =?UTF-8?Q?Krzysztof_Ha=C5=82asa?= Cc: Mauro Carvalho Chehab , linux-media , open list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 26, 2021 at 4:01 AM Krzysztof Ha=C5=82asa wro= te: > > The TDA1997x (HDMI receiver) driver currently uses a specific video > format detection scheme. The frame (or field in interlaced mode), line > and HSync pulse durations are compared to those of known, standard video > modes. If a match is found, the mode is assumed to be detected, > otherwise -ERANGE is returned (then possibly ignored). This means that: > - another mode with similar timings will be detected incorrectly > (e.g. 2x faster clock and lines twice as long) > - non-standard modes will not work. > > I propose to replace this scheme with a direct read of geometry > registers. This way all modes recognized by the chip will be supported. > > In interlaced modes, the code assumes the V sync signal has the same > duration for both fields. While this may be not necessarily true, > I can't see any way to get the "other" V sync width. This is most > probably harmless. > > I have checked the register values in interlaced mode, but currently > can't test such a setup (I only have remote access to a device working > in interlaced mode). Perhaps this will change in time. > > All tests have been performed on Gateworks' Ventana GW54xx board, with > a TDA19971 chip. > > Signed-off-by: Krzysztof Ha=C5=82asa > > --- > This version extracts H and V sync polarities of the incoming signal and > matches the parameters against the standard video modes. > > 1/1000 pixel clock tolerance had to be increased to 1/500 because the > 1/1.001 (NTSC-like) pixclk and frame rate reduction already caused > 1/1000 deviation, and there was no room for further difference. > > This patch requires just posted "[PATCH] TDA1997x: report -ENOLINK > after disconnecting HDMI source". > > diff --git a/drivers/media/i2c/tda1997x.c b/drivers/media/i2c/tda1997x.c > index 36a7b89afb08..a6afb387785d 100644 > --- a/drivers/media/i2c/tda1997x.c > +++ b/drivers/media/i2c/tda1997x.c > @@ -1092,67 +1092,82 @@ tda1997x_detect_std(struct tda1997x_state *state, > struct v4l2_dv_timings *timings) > { > struct v4l2_subdev *sd =3D &state->sd; > - u32 vper; > - u16 hper; > - u16 hsper; > - int i; > > /* > * Read the FMT registers > - * REG_V_PER: Period of a frame (or two fields) in MCLK(27MHz) = cycles > - * REG_H_PER: Period of a line in MCLK(27MHz) cycles > - * REG_HS_WIDTH: Period of horiz sync pulse in MCLK(27MHz) cycl= es > + * REG_V_PER: Period of a frame (or field) in MCLK (27MHz) cycl= es > + * REG_H_PER: Period of a line in MCLK (27MHz) cycles > + * REG_HS_WIDTH: Period of horiz sync pulse in MCLK (27MHz) cyc= les > */ > - vper =3D io_read24(sd, REG_V_PER) & MASK_VPER; > - hper =3D io_read16(sd, REG_H_PER) & MASK_HPER; > - hsper =3D io_read16(sd, REG_HS_WIDTH) & MASK_HSWIDTH; > - v4l2_dbg(1, debug, sd, "Signal Timings: %u/%u/%u\n", vper, hper, = hsper); > + u32 vper, vsync_pos; > + u16 hper, hsync_pos, hsper, interlaced; > + u16 htot, hact, hfront, hsync, hback; > + u16 vtot, vact, vfront1, vfront2, vsync, vback1, vback2; > > if (!state->input_detect[0] && !state->input_detect[1]) > return -ENOLINK; > > - for (i =3D 0; v4l2_dv_timings_presets[i].bt.width; i++) { > - const struct v4l2_bt_timings *bt; > - u32 lines, width, _hper, _hsper; > - u32 vmin, vmax, hmin, hmax, hsmin, hsmax; > - bool vmatch, hmatch, hsmatch; > - > - bt =3D &v4l2_dv_timings_presets[i].bt; > - width =3D V4L2_DV_BT_FRAME_WIDTH(bt); > - lines =3D V4L2_DV_BT_FRAME_HEIGHT(bt); > - _hper =3D (u32)bt->pixelclock / width; > - if (bt->interlaced) > - lines /=3D 2; > - /* vper +/- 0.7% */ > - vmin =3D ((27000000 / 1000) * 993) / _hper * lines; > - vmax =3D ((27000000 / 1000) * 1007) / _hper * lines; > - /* hper +/- 1.0% */ > - hmin =3D ((27000000 / 100) * 99) / _hper; > - hmax =3D ((27000000 / 100) * 101) / _hper; > - /* hsper +/- 2 (take care to avoid 32bit overflow) */ > - _hsper =3D 27000 * bt->hsync / ((u32)bt->pixelclock/1000)= ; > - hsmin =3D _hsper - 2; > - hsmax =3D _hsper + 2; > - > - /* vmatch matches the framerate */ > - vmatch =3D ((vper <=3D vmax) && (vper >=3D vmin)) ? 1 : 0= ; > - /* hmatch matches the width */ > - hmatch =3D ((hper <=3D hmax) && (hper >=3D hmin)) ? 1 : 0= ; > - /* hsmatch matches the hswidth */ > - hsmatch =3D ((hsper <=3D hsmax) && (hsper >=3D hsmin)) ? = 1 : 0; > - if (hmatch && vmatch && hsmatch) { > - v4l2_print_dv_timings(sd->name, "Detected format:= ", > - &v4l2_dv_timings_presets[i]= , > - false); > - if (timings) > - *timings =3D v4l2_dv_timings_presets[i]; > - return 0; > - } > - } > + vper =3D io_read24(sd, REG_V_PER); > + hper =3D io_read16(sd, REG_H_PER); > + hsper =3D io_read16(sd, REG_HS_WIDTH); > + vsync_pos =3D vper & MASK_VPER_SYNC_POS; > + hsync_pos =3D hper & MASK_HPER_SYNC_POS; > + interlaced =3D hsper & MASK_HSWIDTH_INTERLACED; > + vper &=3D MASK_VPER; > + hper &=3D MASK_HPER; > + hsper &=3D MASK_HSWIDTH; > + v4l2_dbg(1, debug, sd, "Signal Timings: %u/%u/%u\n", vper, hper, = hsper); > > - v4l_err(state->client, "no resolution match for timings: %d/%d/%d= \n", > - vper, hper, hsper); > - return -ERANGE; > + htot =3D io_read16(sd, REG_FMT_H_TOT); > + hact =3D io_read16(sd, REG_FMT_H_ACT); > + hfront =3D io_read16(sd, REG_FMT_H_FRONT); > + hsync =3D io_read16(sd, REG_FMT_H_SYNC); > + hback =3D io_read16(sd, REG_FMT_H_BACK); > + > + vtot =3D io_read16(sd, REG_FMT_V_TOT); > + vact =3D io_read16(sd, REG_FMT_V_ACT); > + vfront1 =3D io_read(sd, REG_FMT_V_FRONT_F1); > + vfront2 =3D io_read(sd, REG_FMT_V_FRONT_F2); > + vsync =3D io_read(sd, REG_FMT_V_SYNC); > + vback1 =3D io_read(sd, REG_FMT_V_BACK_F1); > + vback2 =3D io_read(sd, REG_FMT_V_BACK_F2); > + > + v4l2_dbg(1, debug, sd, "Geometry: H %u %u %u %u %u Sync%c V %u %= u %u %u %u %u %u Sync%c\n", > + htot, hact, hfront, hsync, hback, hsync_pos ? '+' : '-', > + vtot, vact, vfront1, vfront2, vsync, vback1, vback2, vsy= nc_pos ? '+' : '-'); > + > + if (!timings) > + return 0; > + > + timings->type =3D V4L2_DV_BT_656_1120; > + timings->bt.width =3D hact; > + timings->bt.hfrontporch =3D hfront; > + timings->bt.hsync =3D hsync; > + timings->bt.hbackporch =3D hback; > + timings->bt.height =3D vact; > + timings->bt.vfrontporch =3D vfront1; > + timings->bt.vsync =3D vsync; > + timings->bt.vbackporch =3D vback1; > + timings->bt.interlaced =3D interlaced ? V4L2_DV_INTERLACED : V4L2= _DV_PROGRESSIVE; > + timings->bt.polarities =3D vsync_pos ? V4L2_DV_VSYNC_POS_POL : 0; > + timings->bt.polarities |=3D hsync_pos ? V4L2_DV_HSYNC_POS_POL : 0= ; > + > + timings->bt.pixelclock =3D (u64)htot * vtot * 27000000; > + if (interlaced) { > + timings->bt.il_vfrontporch =3D vfront2; > + timings->bt.il_vsync =3D timings->bt.vsync; > + timings->bt.il_vbackporch =3D vback2; > + do_div(timings->bt.pixelclock, vper * 2 /* full frame */)= ; > + } else { > + timings->bt.il_vfrontporch =3D 0; > + timings->bt.il_vsync =3D 0; > + timings->bt.il_vbackporch =3D 0; > + do_div(timings->bt.pixelclock, vper); > + } > + v4l2_find_dv_timings_cap(timings, &tda1997x_dv_timings_cap, > + (u32)timings->bt.pixelclock / 500, NULL,= NULL); > + v4l2_print_dv_timings(sd->name, "Detected format: ", timings, fal= se); > + return 0; > } > > /* some sort of errata workaround for chip revision 0 (N1) */ > diff --git a/drivers/media/i2c/tda1997x_regs.h b/drivers/media/i2c/tda199= 7x_regs.h > index d9b3daada07d..115371ba33f0 100644 > --- a/drivers/media/i2c/tda1997x_regs.h > +++ b/drivers/media/i2c/tda1997x_regs.h > @@ -117,9 +117,12 @@ > #define REG_CURPAGE_00H 0xFF > > #define MASK_VPER 0x3fffff > +#define MASK_VPER_SYNC_POS 0x800000 > #define MASK_VHREF 0x3fff > #define MASK_HPER 0x0fff > +#define MASK_HPER_SYNC_POS 0x8000 > #define MASK_HSWIDTH 0x03ff > +#define MASK_HSWIDTH_INTERLACED 0x8000 > > /* HPD Detection */ > #define DETECT_UTIL BIT(7) /* utility of HDMI level */ Krzysztof, I can't get this to apply (to 5.13, linux/master, or linux-media/master). What are you based on and do you have a git repo I can get it from? Also, for quick testing do you recall how to invoke the 'log_debug' function from userspace? I think its a v4l2-ctl operation. Best regards, Tim