Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp4839846rwe; Tue, 30 Aug 2022 18:53:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR4v7VwGc0CUwwU7LsTuc8u20MZkKLW5V/I/4VXgVDU52jbedNjuee+SrDP6mjX+o8O+dsM+ X-Received: by 2002:aa7:88c8:0:b0:536:926:700f with SMTP id k8-20020aa788c8000000b005360926700fmr24439462pff.72.1661910803171; Tue, 30 Aug 2022 18:53:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661910803; cv=none; d=google.com; s=arc-20160816; b=NswCixy4H5a4y3v83ywGXcVhQytFxK1LG+0Jo5ysG0RfZP6bmZi9K7KwfLk9XKECiy IVHaMKMfbAycJ19nmrZnVIQO0klu+BLiG4rDefn8XAOIieWkH7LqJJ5dxS9Arh8jBvzh 9NWqamLz6744ZV1i4pZy9OlQmcoF+VSxH8H1sX4XMVi1Bn0GWJJ71oPjQd/Y03DoXVK2 CG+KlFzkrmh6qtax5kbZRjQ//LsBRBc8R+8rFxZ6jxRxjYSLqP8EwmTlS7rwjZMNVEl1 slsufNjQNtnfcdfpJvgNb+pVHY/9+6GRKPY3XgDKclEWUd5WHGD2aowEuP05VPDXUwG3 1sWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:dkim-signature; bh=drG6RMH0zFREgohP7fUu6e8MBztAwMPOm+LE74724sA=; b=YkLkB83/5hjC8VEL+HfQDp1florVCXXG5eotVtf8lxTQEXL6rraSJHuo1Yv6CtGmrL 0pwMT0ySW7Sw7E4fQbunXmgz8aCqtTei0OYsAkpifwkNE/cWy35pNwwTBpwa1A6L09+g 3OxUR7g6NYwxuRUqn9uMSpP5gk1xwrXHkw8dkcVnKqa0Wz13pyNg3e+DiC/bDXME4Xp0 KKVouT/mbT4RegfRTsws5G2KtzXL+H9GnJgZ/VBtPSugt1g3XQfb3L39VNi13RfqHWeW qv6sfO8hVhc49hgbgpV4+yPFiTaB1+wYMSxJ/s+QiP2uMHAj4AqtazUNqENiCytLK+oK uCuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EFsFMp+c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kk14-20020a17090b4a0e00b001fde61b869esi589603pjb.149.2022.08.30.18.53.11; Tue, 30 Aug 2022 18:53:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EFsFMp+c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231514AbiHaBpD (ORCPT + 99 others); Tue, 30 Aug 2022 21:45:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbiHaBpA (ORCPT ); Tue, 30 Aug 2022 21:45:00 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E606112A9A for ; Tue, 30 Aug 2022 18:44:57 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id j14so7604683lfu.4 for ; Tue, 30 Aug 2022 18:44:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:from:to:cc; bh=drG6RMH0zFREgohP7fUu6e8MBztAwMPOm+LE74724sA=; b=EFsFMp+canY/hKJink3xfIjzSIs5nK0ATMHsiNLvxO07lOyOzwsvad8rVyDd2wmSeg cWCjphxF3TSGFFDKqyBmATL/jehCiz7Ylb6ULQwm/mKEET2IUotRhOyHBInnuwebAx/W o98i4bzpAYKvvI2sU//Sa2wKHsHNlK0Ik4KVSfjlV5E7mJwynZVYZggwdjMG3KRyfVMo xPbIu9xAaQjWAcnqbsVBfJmmxCjJL8AJzz30l+qNOOOt1j+HNC9Xoq1+ko3At8FQwbwc GgYRNngTbp8HBenXcqfoYJexOO63aFwrEEDYhvuQd/DuP/2j454qxLb21o5XEYcIYyWs Dtmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:x-gm-message-state:from:to:cc; bh=drG6RMH0zFREgohP7fUu6e8MBztAwMPOm+LE74724sA=; b=XlWirZRUr14+Gfc8x89EEUEyTzd0UftJpahrvJMR8tIzN2Z9WwPBGu8X7nIyYSKzcH X6mxN6+Jd2XMUNycl19jbw3MRLtuaLLSjA6WKWYOwJo/n4KqdXidAvOULkBJNtbRKfIs IWrJgReQcSTUoOWYvBHqK8nOsal+iWVlAwzMxUoqAdusmabJOfSfwOrzES8lMoMtIUmh wGkxcMz9rGB48jGNpHoOMPQjzYbvoqabcwNAbDmBegrT9Fgsg6GvgTDeWmCM0fRoavnd aKuDwt9bbe0Oj59YE6GVCL1egSNERqTuSKwfO8uf649KjKUIamJlwsxf0BPDjwHaS5+G /yAw== X-Gm-Message-State: ACgBeo2V0xWBfPj0GVpJXh7ilDu+o2jdCUewdR/XTMFhlleX1kQIAIPX 08SNdrF+K5gp0ByRzEBRjrs= X-Received: by 2002:ac2:4901:0:b0:494:88dc:7efc with SMTP id n1-20020ac24901000000b0049488dc7efcmr411746lfi.408.1661910295748; Tue, 30 Aug 2022 18:44:55 -0700 (PDT) Received: from ?IPV6:2a02:a31a:a240:1700:d40b:b088:5bfe:3b81? ([2a02:a31a:a240:1700:d40b:b088:5bfe:3b81]) by smtp.googlemail.com with ESMTPSA id g1-20020a0565123b8100b004948f583e6bsm42248lfv.138.2022.08.30.18.44.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Aug 2022 18:44:55 -0700 (PDT) From: Mateusz Kwiatkowski X-Google-Original-From: Mateusz Kwiatkowski Message-ID: <242d272b-5b79-986c-9aaf-64e62f6b37ff@gmail.com> Date: Wed, 31 Aug 2022 03:44:52 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH v2 10/41] drm/modes: Add a function to generate analog display modes Content-Language: pl To: Maxime Ripard , Maxime Ripard , Ben Skeggs , David Airlie , Chen-Yu Tsai , Thomas Zimmermann , Jani Nikula , Lyude Paul , Philipp Zabel , Maarten Lankhorst , Rodrigo Vivi , Tvrtko Ursulin , Jernej Skrabec , Samuel Holland , Karol Herbst , =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= , Emma Anholt , Daniel Vetter , Joonas Lahtinen Cc: Hans de Goede , linux-arm-kernel@lists.infradead.org, Phil Elwell , intel-gfx@lists.freedesktop.org, Dave Stevenson , dri-devel@lists.freedesktop.org, Dom Cobley , linux-kernel@vger.kernel.org, nouveau@lists.freedesktop.org, linux-sunxi@lists.linux.dev, Geert Uytterhoeven References: <20220728-rpi-analog-tv-properties-v2-0-459522d653a7@cerno.tech> <20220728-rpi-analog-tv-properties-v2-10-459522d653a7@cerno.tech> In-Reply-To: <20220728-rpi-analog-tv-properties-v2-10-459522d653a7@cerno.tech> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Maxime, Wow. That's an enormous amount of effort put into this patch. But I'm tempted to say that this is actually overengineered quite a bit :D Considering that there's no way to access all these calculations from user space, and I can't imagine anybody using anything else than those standard 480i/576i (and maybe 240p/288p) modes at 13.5 MHz any time soon... I'm not sure if we actually need all this. But anyway, I'm not the maintainer of this subsystem, so I'm not the one to decide. > +enum drm_mode_analog { > +    DRM_MODE_ANALOG_NTSC, > +    DRM_MODE_ANALOG_PAL, > +}; Using "NTSC" and "PAL" to describe the 50Hz and 60Hz analog TV modes is common, but strictly speaking a misnomer. Those are color encoding systems, and your patchset fully supports lesser used, but standard encodings for those (e.g. PAL-M for 60Hz and SECAM for 50Hz). I'd propose switching to some more neutral naming scheme. Some ideas: - DRM_MODE_ANALOG_60_HZ / DRM_MODE_ANALOG_50_HZ (after standard refresh rate) - DRM_MODE_ANALOG_525_LINES / DRM_MODE_ANALOG_625_LINES (after standard line   count) - DRM_MODE_ANALOG_JM / DRM_MODE_ANALOG_BDGHIKLN (after corresponding ITU System   Letter Designations) > +#define NTSC_HFP_DURATION_TYP_NS    1500 > +#define NTSC_HFP_DURATION_MIN_NS    1270 > +#define NTSC_HFP_DURATION_MAX_NS    2220 You've defined those min/typ/max ranges, but you're not using the "typ" field for anything other than hslen. The actual "typical" value is thus always the midpoint, which isn't necessarily the best choice. In particular, for the standard 720px wide modes at 13.5 MHz, hsync_start ends up being 735 for 480i and 734 for 576i, instead of 736 and 732 requested by BT.601. That's all obviously within tolerances, but the image ends up noticeably off-center (at least on modern TVs), especially in the 576i case. > +    htotal = params->line_duration_ns * pixel_clock_hz / NSEC_PER_SEC; You're multiplying an unsigned int and an unsigned long - both types are only required to be 32 bit, so this is likely to overflow. You need to use a cast to unsigned long long, and then call do_div() for 64-bit division. This actually overflowed on me on my Pi running ARM32 kernel, resulting in negative horizontal porch lengths, and drm_helper_probe_add_cmdline_mode() taking over the mode generation (badly), and a horrible mess on screen. > +    vfp = vfp_min + (porches_rem / 2); > +    vbp = porches - vfp; Relative position of the vertical sync within the VBI effectively moves the image up and down. Adding that (porches_rem / 2) moves the image up off center by that many pixels. I'd keep the VFP always at minimum to keep the image centered. Best regards, Mateusz Kwiatkowski