Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1254447lqe; Mon, 8 Apr 2024 03:48:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVku9ab6MG/arb8FQ1tP4VNVnDBQNNTGPORqBRdmwcMzeb/vxE+ZacyrMwbHTUP4jgvSft9Ppoz174O6Rt2HAhZz1c1980qdOSrd4FfIQ== X-Google-Smtp-Source: AGHT+IE6ZDHEWuwl+DhEYe5yHkiapzoeLgQK7YYoplYbfwZLAVt1qBApo8+cDpCdkRk858gn1mUz X-Received: by 2002:a05:6a20:9154:b0:1a7:23ae:4421 with SMTP id x20-20020a056a20915400b001a723ae4421mr12085727pzc.24.1712573281554; Mon, 08 Apr 2024 03:48:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712573281; cv=pass; d=google.com; s=arc-20160816; b=GnLwmCKdDNSwab88qzAwXz6sbgc7xBQRZYJ3cGfucKuTLgw51/vVR4pOHYl+aR6bUN 8FRzU6RFzsWof59aoD09YGrR5t3hJoDK5Hiq/To3eJWaF264O0e1Mhas3rw8+w2KhTDR btX/sKc159hwqC3XzmaJzi6ujljFgkmOlbtfa4ktZOwOaBB3QgElq1ruoLWoHDSZkhIh LbukxGGwUeVpksJp+ecq2dkAwH0QGuMp4mR7USMIqMbOFRc8V4LFYQkYnP7YyPKSBV3D IvvNVdmLCGLd+9p0QIHIuio9RKdrPbNbxJicTn4iC8deKEbRfxwVV+A3BtqhkrPhX/VZ wdDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id; bh=iPmBQhxpSZDYK6sjGHF5JcYHZoeWy+BKOqv9JI7gpec=; fh=ejZKMPXw/wpgIkBgg4R8fhS2jsJTspCs9srLwjcCwrU=; b=ni3n2j6UiuJhqH/Ix12NTmRCBrqr+6X7S1izmMJdCoz/N9SakkHH6wzb6jknEbwJ+I XXvDC6T86aUDWEC8rl16WbP4ryt12ToHcl73hELg9tyz3ziD1A3mYoZsI40pX4n8+ygg WN0fNeSUQ3Xl4NIse3x0d6dfoRBC1J3CZtYiKrZqJCAesepSgzmVswn00wY+zNye1Fx5 uQPf1YnvT11w05eIBoTuMMqEPYR79h83q7oh0BfCbrMtsk8cUv3Tru8DcVgCMhpR64mD g/VGqffUBe1x5ykd+8+MHKx7abrBm70dPO93SnC0b4qHxvew8Cu4jjySnUEXkCNo6n2U 9o2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-135233-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135233-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id a1-20020a636601000000b005e49cd906d6si6106151pgc.97.2024.04.08.03.48.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 03:48:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135233-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-135233-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135233-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 28744B2239D for ; Mon, 8 Apr 2024 10:48:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B05F64CE6; Mon, 8 Apr 2024 10:47:38 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1DB75F87E; Mon, 8 Apr 2024 10:47:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712573257; cv=none; b=DfehXF5v49xRJE4oooCwisMK9nmUUrOl9SvhXrgqstJLD+NfDYeR8Oc0W/9VqMMZRspjaJjPnGz2LxCLSf7h1FZIDj6v3kvd9o4102tEUNgecW/t9S89EbQIXX2IPTlxH8wN6h7+931xe0rwe8CgocOoZOZv2w1c7Yu2/tfrU7Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712573257; c=relaxed/simple; bh=Diq1SBCC+HFcKqwY87I5Y+2gDEwo7cWuc887OJgTYRM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=JdvhCG+/ALkypZ7MBG07UFQ+0I14zXoespA/1OirvFmGzawIuUJsNyhoj1jS3eD0jaTjAcXiOh9wnnIBj4W8n82LxPXI5lD4Bo8mh79bhgN/j4yBTISXgZT/PLgA7foiQx9yVLJufx7o2PaWSq1BS4rMYsn9hUH77dLTJAK7s2M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F474C43390; Mon, 8 Apr 2024 10:47:36 +0000 (UTC) Message-ID: <8a0cf515-e450-41b8-950c-4356f2fb9879@xs4all.nl> Date: Mon, 8 Apr 2024 12:47:34 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 3/3] media: mgb4: Fixed signal frame rate limit handling Content-Language: en-US, nl To: tumic@gpxsee.org, Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?Q?Martin_T=C5=AFma?= References: <20240322151005.3499-1-tumic@gpxsee.org> <20240322151005.3499-4-tumic@gpxsee.org> From: Hans Verkuil Autocrypt: addr=hverkuil@xs4all.nl; keydata= xsFNBFQ84W0BEAC7EF1iL4s3tY8cRTVkJT/297h0Hz0ypA+ByVM4CdU9sN6ua/YoFlr9k0K4 BFUlg7JzJoUuRbKxkYb8mmqOe722j7N3HO8+ofnio5cAP5W0WwDpM0kM84BeHU0aPSTsWiGR yw55SOK2JBSq7hueotWLfJLobMWhQii0Zd83hGT9SIt9uHaHjgwmtTH7MSTIiaY6N14nw2Ud C6Uykc1va0Wqqc2ov5ihgk/2k2SKa02ookQI3e79laOrbZl5BOXNKR9LguuOZdX4XYR3Zi6/ BsJ7pVCK9xkiVf8svlEl94IHb+sa1KrlgGv3fn5xgzDw8Z222TfFceDL/2EzUyTdWc4GaPMC E/c1B4UOle6ZHg02+I8tZicjzj5+yffv1lB5A1btG+AmoZrgf0X2O1B96fqgHx8w9PIpVERN YsmkfxvhfP3MO3oHh8UY1OLKdlKamMneCLk2up1Zlli347KMjHAVjBAiy8qOguKF9k7HOjif JCLYTkggrRiEiE1xg4tblBNj8WGyKH+u/hwwwBqCd/Px2HvhAsJQ7DwuuB3vBAp845BJYUU3 06kRihFqbO0vEt4QmcQDcbWINeZ2zX5TK7QQ91ldHdqJn6MhXulPKcM8tCkdD8YNXXKyKqNl UVqXnarz8m2JCbHgjEk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Ora gYmkrmv0duG1FStpY+IIQn1TOkuXrciTVfZY1cZD0aVxwlxXBnUNZZNslldvXFtndxR0SFat sflovhDxKyhFwXOP0Rv8H378/+14TaykknRBIKEc0+lcr+EMOSUR5eg4aURb8Gc3Uc7fgQ6q UssTXzHPyj1hAyDpfu8DzAwlh4kKFTodxSsKAjI45SLjadSc94/5Gy8645Y1KgBzBPTH7Q== In-Reply-To: <20240322151005.3499-4-tumic@gpxsee.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 22/03/2024 16:10, tumic@gpxsee.org wrote: > From: Martin Tůma > > Properly document the function of the mgb4 output frame_rate sysfs parameter > and fix the corner case when the frame rate is set to zero causing a "divide > by zero" kernel panic. This is mixing a fix and a documentation improvement into one patch. This should be split. Also, shouldn't the fix be either part of the previous patch or come before that patch? > > Signed-off-by: Martin Tůma > --- > Documentation/admin-guide/media/mgb4.rst | 8 ++++++-- > drivers/media/pci/mgb4/mgb4_sysfs_out.c | 9 +++++---- > drivers/media/pci/mgb4/mgb4_vout.c | 12 ++++++------ > drivers/media/pci/mgb4/mgb4_vout.h | 2 +- > 4 files changed, 18 insertions(+), 13 deletions(-) > > diff --git a/Documentation/admin-guide/media/mgb4.rst b/Documentation/admin-guide/media/mgb4.rst > index 2977f74d7e26..6fff886003e2 100644 > --- a/Documentation/admin-guide/media/mgb4.rst > +++ b/Documentation/admin-guide/media/mgb4.rst > @@ -228,8 +228,12 @@ Common FPDL3/GMSL output parameters > open.* > > **frame_rate** (RW): > - Output video frame rate in frames per second. The default frame rate is > - 60Hz. > + Output video signal frame rate limit in frames per second. Due to > + the limited output pixel clock steps, the card can not always generate > + a frame rate perfectly matching the value required by the connected display. > + Using this parameter one can limit the frame rate by "crippling" the signal > + so that the lines are not equal but the signal appears like having the exact > + frame rate to the connected display. The default frame rate limit is 60Hz. It's not clear what is meant with 'crippling'. Normally when dealing with video framerates the driver will pick the closest video timing to the requested framerate. It is understood that you can't always get the exact framerate, so drivers can make adjustments. Regards, Hans > > **hsync_polarity** (RW): > HSYNC signal polarity. > diff --git a/drivers/media/pci/mgb4/mgb4_sysfs_out.c b/drivers/media/pci/mgb4/mgb4_sysfs_out.c > index f67ff2a48329..573aa61c69d4 100644 > --- a/drivers/media/pci/mgb4/mgb4_sysfs_out.c > +++ b/drivers/media/pci/mgb4/mgb4_sysfs_out.c > @@ -229,9 +229,9 @@ static ssize_t frame_rate_show(struct device *dev, > struct video_device *vdev = to_video_device(dev); > struct mgb4_vout_dev *voutdev = video_get_drvdata(vdev); > u32 period = mgb4_read_reg(&voutdev->mgbdev->video, > - voutdev->config->regs.frame_period); > + voutdev->config->regs.frame_limit); > > - return sprintf(buf, "%u\n", MGB4_HW_FREQ / period); > + return sprintf(buf, "%u\n", period ? MGB4_HW_FREQ / period : 0); > } > > /* > @@ -245,14 +245,15 @@ static ssize_t frame_rate_store(struct device *dev, > struct video_device *vdev = to_video_device(dev); > struct mgb4_vout_dev *voutdev = video_get_drvdata(vdev); > unsigned long val; > - int ret; > + int limit, ret; > > ret = kstrtoul(buf, 10, &val); > if (ret) > return ret; > > + limit = val ? MGB4_HW_FREQ / val : 0; > mgb4_write_reg(&voutdev->mgbdev->video, > - voutdev->config->regs.frame_period, MGB4_HW_FREQ / val); > + voutdev->config->regs.frame_limit, limit); > > return count; > } > diff --git a/drivers/media/pci/mgb4/mgb4_vout.c b/drivers/media/pci/mgb4/mgb4_vout.c > index a6b55669f0a8..cd001ceaae63 100644 > --- a/drivers/media/pci/mgb4/mgb4_vout.c > +++ b/drivers/media/pci/mgb4/mgb4_vout.c > @@ -680,12 +680,12 @@ static void fpga_init(struct mgb4_vout_dev *voutdev) > mgb4_write_reg(video, regs->config, 0x00000011); > mgb4_write_reg(video, regs->resolution, > (DEFAULT_WIDTH << 16) | DEFAULT_HEIGHT); > - mgb4_write_reg(video, regs->hsync, 0x00102020); > - mgb4_write_reg(video, regs->vsync, 0x40020202); > - mgb4_write_reg(video, regs->frame_period, DEFAULT_PERIOD); > + mgb4_write_reg(video, regs->hsync, 0x00283232); > + mgb4_write_reg(video, regs->vsync, 0x40141F1E); > + mgb4_write_reg(video, regs->frame_limit, DEFAULT_PERIOD); > mgb4_write_reg(video, regs->padding, 0x00000000); > > - voutdev->freq = mgb4_cmt_set_vout_freq(voutdev, 70000 >> 1) << 1; > + voutdev->freq = mgb4_cmt_set_vout_freq(voutdev, 61150 >> 1) << 1; > > mgb4_write_reg(video, regs->config, > (voutdev->config->id + MGB4_VIN_DEVICES) << 2 | 1 << 4); > @@ -711,8 +711,8 @@ static void debugfs_init(struct mgb4_vout_dev *voutdev) > voutdev->regs[3].offset = voutdev->config->regs.hsync; > voutdev->regs[4].name = "VIDEO_PARAMS_2"; > voutdev->regs[4].offset = voutdev->config->regs.vsync; > - voutdev->regs[5].name = "FRAME_PERIOD"; > - voutdev->regs[5].offset = voutdev->config->regs.frame_period; > + voutdev->regs[5].name = "FRAME_LIMIT"; > + voutdev->regs[5].offset = voutdev->config->regs.frame_limit; > voutdev->regs[6].name = "PADDING_PIXELS"; > voutdev->regs[6].offset = voutdev->config->regs.padding; > if (has_timeperframe(video)) { > diff --git a/drivers/media/pci/mgb4/mgb4_vout.h b/drivers/media/pci/mgb4/mgb4_vout.h > index ab9b58b1deb7..adc8fe1e7ae6 100644 > --- a/drivers/media/pci/mgb4/mgb4_vout.h > +++ b/drivers/media/pci/mgb4/mgb4_vout.h > @@ -19,7 +19,7 @@ struct mgb4_vout_regs { > u32 config; > u32 status; > u32 resolution; > - u32 frame_period; > + u32 frame_limit; > u32 hsync; > u32 vsync; > u32 padding;