Received: by 10.223.176.5 with SMTP id f5csp389712wra; Fri, 9 Feb 2018 00:24:02 -0800 (PST) X-Google-Smtp-Source: AH8x225e52j0jO8cZyNFLYHq7d9RbIa80HnKnDX9fKz9A8klCMn8m0g4mV1d//Fnh+QcmkP0lWLm X-Received: by 10.98.170.15 with SMTP id e15mr1974699pff.207.1518164642641; Fri, 09 Feb 2018 00:24:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518164642; cv=none; d=google.com; s=arc-20160816; b=X+en9yT/YldqJPDWzdt06kdLVA9cs0tmiY9TBqvCQOOm3QFvXr8BQK/4PJN01mX5wQ fRh8jtsRBlNllOsmhj5eU7QEMGvftTNLZk7w/qPfRnC3Frz41RRX63+u/5j1aVPKTIxH PQXilbH8KdNQcEn+cL5kZseYuFnaEdPTz4m8xzhVw/NKsRv/9itm5jZjUED9q9/uwiZr s5E9gSYiA6IxayDIJ5PnyvK08QZud7UFc2Hv6rUilGZdd4eHSt5WIxsjnIZ6e/rKdARx 35ZuqBgZ+Np6bufNhjsGgk6fIvRkg5E39SVtaPoyqrzbROJ0KHSnxVLCZVed/KB3lVe0 B9Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=04a2eJgG2YzBlfhayiSQXGHuRd8Y24RQ1SliKvTJlOQ=; b=WdzKlhq2o8B2dBZFU/ylY8NOJuVwp7UjELdqnbm7byPqJfy9bQwsty6vq5FVeub208 6oxotarED9IN+i3klx5C3RCwOJgGeRy+f39Fqw5junRwZwHhItywSx4jPEzGccaDhDvi 0B4Y7yORQAlVqDec3sofECylBLXIRj35iKGhgal01vA+x+T4Eb0JKNzo2FlKbZAmiUBs Nt8uGDC5ul1C89H9dI1PaWglxT2os+8tRCLmbP45hFhFgNi3eY7PXyCh+CHmTl+Ispo7 0IJ5yGM+E0EUXbp1iygcsEd2dt3kaJ/AFJ1X5hxRW4GL5n7Aa9PPmNIPiOKEEt2U4B5z QhGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8-v6si1193418ple.359.2018.02.09.00.23.47; Fri, 09 Feb 2018 00:24:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751049AbeBIIIl (ORCPT + 99 others); Fri, 9 Feb 2018 03:08:41 -0500 Received: from lb1-smtp-cloud9.xs4all.net ([194.109.24.22]:51295 "EHLO lb1-smtp-cloud9.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750863AbeBIIIj (ORCPT ); Fri, 9 Feb 2018 03:08:39 -0500 Received: from [192.168.2.10] ([212.251.195.8]) by smtp-cloud9.xs4all.net with ESMTPA id k3jWeoAJ8oWCOk3jZe74kZ; Fri, 09 Feb 2018 09:08:38 +0100 Subject: Re: [PATCH v10 6/8] media: i2c: Add TDA1997x HDMI receiver driver To: Tim Harvey , linux-media@vger.kernel.org, alsa-devel@alsa-project.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, shawnguo@kernel.org, Steve Longerbeam , Philipp Zabel , Hans Verkuil , Mauro Carvalho Chehab References: <1518157956-14220-1-git-send-email-tharvey@gateworks.com> <1518157956-14220-7-git-send-email-tharvey@gateworks.com> From: Hans Verkuil Message-ID: Date: Fri, 9 Feb 2018 09:08:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <1518157956-14220-7-git-send-email-tharvey@gateworks.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfNZL8ue7NvMp4hbWcfem8Uwa7AG1XAowiWAaOMEO1aILg9i6pMcFG8dDq3ID8NHGbGsf5QcVgFXN6vA4V30xQ2gYVxweoC3OpJXswjIxnTLSkF/ci6f8 Ywz9I2cejtWFj4wtlrw2TZE308eBX6FM6Fn74O3UTzHWvWjDa0sgsMfSPfgkSHeqnRLTtfRxIpNfUMhok7fbhBmIXaaEshLQnT8KXTUsO88MTlC/sorhxjp+ Ks3VpE9MpDbaeA2y5z7+x/uMH0txooBF4hXBY9mwpuwB8OI0XBNniVsGUMzyPRkkwx/pcK9lVX61wsNgLgztHGT9K4BxMvV121KEjDKRiiva5JufVCC5Kfpj /az29n3Ga9V8akzK6uUrNCMkiqo7Es/NnBzMN5Zpd5EkpKtJuBfVXNKcDmjOAiA2rdgM+e2HcZ0KyxvXusSwqGofvNLsKZp7kJxdb0CpjFWDnRw3BRwke3OW 1KO2mbbVuVQUNn0S Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Tim, We're almost there. Two more comments: On 02/09/2018 07:32 AM, Tim Harvey wrote: > +static int > +tda1997x_detect_std(struct tda1997x_state *state, > + struct v4l2_dv_timings *timings) > +{ > + struct v4l2_subdev *sd = &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) cycles > + */ > + vper = io_read24(sd, REG_V_PER) & MASK_VPER; > + hper = io_read16(sd, REG_H_PER) & MASK_HPER; > + hsper = io_read16(sd, REG_HS_WIDTH) & MASK_HSWIDTH; > + if (!vper || !hper || !hsper) > + return -ENOLINK; See my comment for g_input_status below. This condition looks more like a ENOLCK. Or perhaps it should be: if (!vper && !hper && !hsper) return -ENOLINK; if (!vper || !hper || !hsper) return -ENOLCK; I would recommend that you test a bit with no signal and a bad signal (perhaps one that uses a pixelclock that is too high for this device?). > + v4l2_dbg(1, debug, sd, "Signal Timings: %u/%u/%u\n", vper, hper, hsper); > + > + for (i = 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 = &v4l2_dv_timings_presets[i].bt; > + width = V4L2_DV_BT_FRAME_WIDTH(bt); > + lines = V4L2_DV_BT_FRAME_HEIGHT(bt); > + _hper = (u32)bt->pixelclock / width; > + if (bt->interlaced) > + lines /= 2; > + /* vper +/- 0.7% */ > + vmin = ((27000000 / 1000) * 993) / _hper * lines; > + vmax = ((27000000 / 1000) * 1007) / _hper * lines; > + /* hper +/- 1.0% */ > + hmin = ((27000000 / 100) * 99) / _hper; > + hmax = ((27000000 / 100) * 101) / _hper; > + /* hsper +/- 2 (take care to avoid 32bit overflow) */ > + _hsper = 27000 * bt->hsync / ((u32)bt->pixelclock/1000); > + hsmin = _hsper - 2; > + hsmax = _hsper + 2; > + > + /* vmatch matches the framerate */ > + vmatch = ((vper <= vmax) && (vper >= vmin)) ? 1 : 0; > + /* hmatch matches the width */ > + hmatch = ((hper <= hmax) && (hper >= hmin)) ? 1 : 0; > + /* hsmatch matches the hswidth */ > + hsmatch = ((hsper <= hsmax) && (hsper >= hsmin)) ? 1 : 0; > + if (hmatch && vmatch && hsmatch) { > + *timings = v4l2_dv_timings_presets[i]; > + v4l2_print_dv_timings(sd->name, "Detected format: ", > + timings, false); > + return 0; > + } > + } > + > + v4l_err(state->client, "no resolution match for timings: %d/%d/%d\n", > + vper, hper, hsper); > + return -EINVAL; > +} -EINVAL isn't the correct error code here. I would go for -ERANGE. It's not perfect, but close enough. -EINVAL indicates that the user filled in wrong values, but that's not the case here. > +static int > +tda1997x_g_input_status(struct v4l2_subdev *sd, u32 *status) > +{ > + struct tda1997x_state *state = to_state(sd); > + u32 vper; > + u16 hper; > + u16 hsper; > + > + mutex_lock(&state->lock); > + v4l2_dbg(1, debug, sd, "inputs:%d/%d\n", > + state->input_detect[0], state->input_detect[1]); > + if (state->input_detect[0] || state->input_detect[1]) I'm confused. This device has two HDMI inputs? Does 'detecting input' equate to 'I see a signal and I am locked'? I gather from the irq function that sets these values that it is closer to 'I see a signal' and that 'I am locked' is something you would test by looking at the vper/hper/hsper. > + *status = 0; > + else { > + vper = io_read24(sd, REG_V_PER) & MASK_VPER; > + hper = io_read16(sd, REG_H_PER) & MASK_HPER; > + hsper = io_read16(sd, REG_HS_WIDTH) & MASK_HSWIDTH; > + v4l2_dbg(1, debug, sd, "timings:%d/%d/%d\n", vper, hper, hsper); > + if (!vper || !hper || !hsper) > + *status |= V4L2_IN_ST_NO_SYNC; > + else > + *status |= V4L2_IN_ST_NO_SIGNAL; So if we have valid vper, hper and hsper, then there is no signal? That doesn't make sense. I'd expect to see something like this: if (!input_detect[0] && !input_detect[1]) // no signal else if (!vper || !hper || !vsper) // no sync else // have signal and sync I'm not sure about the precise meaning of input_detect, so I might be wrong about that bit. Regards, Hans