Received: by 2002:a05:7208:b08c:b0:82:bbfa:f723 with SMTP id c12csp398486rbb; Fri, 26 Apr 2024 07:26:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWP67hLwA3SZ7hlhSIJG9RuPp7+JF5ig14zpaaVb1HlC37j0XttsVeegmfRg8AOBNyUmDyugv3Y+tjTg2SMpVtvtSKmaacYyffgl0oxiQ== X-Google-Smtp-Source: AGHT+IF3obPqxYtS79LDxrGXaqIISHlZ6fYAZdp6Uf+jEmyW6AbOduNJunJQWouXZyaqdqXbJ8S9 X-Received: by 2002:a50:aadd:0:b0:56c:1735:57a2 with SMTP id r29-20020a50aadd000000b0056c173557a2mr2754849edc.31.1714141575718; Fri, 26 Apr 2024 07:26:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714141575; cv=pass; d=google.com; s=arc-20160816; b=AKjNYPJcEbmr/YTLvt9Fcz7OJuy25E+vhHJpaXMLJFoY9br8P0VJCSZ0CqeU8a/Blq cRE5JtB9ymB5nDgnm6FaNKEJUbUh76Dpbs+GGlyZf4DGOK1EHcusMNF7Sf+tBzgxBXJD +Zbdl6ZIbABKlQkWepCzmOKWu3R+uVtKMio9BBH+8MfQ3fOMQT4Ai3wUuaHskTDWbnZv tjaflsgGMt1KGTJaEPBs21zPKpjZblsEwRibZL1vwfhqUAt+psGOPFklvyX9wAbDVw26 V2KBHPpxFG5AtUj1GuFDXHRBKkkLYhsPK84UvLGjFVUNTL+rR5WOwUr0lmM9FSpcbAKQ ZJqg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=s6M9zQV6YJq8q2X08RiFsEYZLRFiyA4keaohZ0IcraM=; fh=NcJMVFNaR8bzRgLN6H4coLXdbR1fdwxxAYxDB/lPPz0=; b=s5OCFFN5PtMf8rY7dUYwfg3T31WgWnvgEiyaKLrz79CmVw8p9dU3qdzO0KV8xBYwBu IFAKQ1JS3gGpJBqC05M6BEWaK9sl+2sNI/w5jKDw4Pdv4BtgsnI0Tj0RhX+uUp8uFXFs lM67+NDqqpptIV5266cSffuHrfkSvK3BEE+LvCPqeo5wqBTzxMKzixIorqsEweSPfj6w STI3GHlC+6wBHOTu1hhwnZfutryhCoWI3RslV6tZc37OLOP+uOOqcFbBIASnOcUL2jVW oO64CjCVZc5hgT3M2UBKFdZLdLdM8TrJEcMCLln+QXKam6+55ljH4xu3wPy/rt9Z5ZPk 652g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gpxsee.org); spf=pass (google.com: domain of linux-kernel+bounces-160149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160149-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f25-20020a50a6d9000000b005723fb30dcasi2069617edc.351.2024.04.26.07.26.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 07:26:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gpxsee.org); spf=pass (google.com: domain of linux-kernel+bounces-160149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160149-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 7A47C1F22C29 for ; Fri, 26 Apr 2024 14:26:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0590D1494B2; Fri, 26 Apr 2024 14:25:38 +0000 (UTC) Received: from mx.gpxsee.org (mx.gpxsee.org [37.205.14.76]) (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 C8681148844; Fri, 26 Apr 2024 14:25:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=37.205.14.76 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714141537; cv=none; b=J7qD66Z0WRAwpMuTg6UfmT3Iv3I4noDFDvyHKjgAGea9n12rcUpKcSTLxrqvAv65jYB/m+vWcg0C8egg2J2Xzp7Kbz6DelPuvABwTmP0V9dv4T/NfKc01XWEuK1RNp4heRZ+EOpMySJ2H9zwCYO5wKVyB+LxMV2Q70H6AJDH69Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714141537; c=relaxed/simple; bh=DU6s0vTQxydn1ZYnilNR1xt3FPg4W4iYH0LBzNC5xwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P0W4uuh37rTu6ohsWQibvqCWlEkXrHYmFrI2XcNznx7WdDsOd/e7rgzcfNyXG9iDym7ob05a8wF7MMBU0f86rJs+l8+denrHTUbcFz4Q03PvGIejCQBQY3IzloE9uCPMQqy8RtS5F0s1gfa1zeoupNTVQsHIoumTi+ce4s58J2M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gpxsee.org; spf=pass smtp.mailfrom=gpxsee.org; arc=none smtp.client-ip=37.205.14.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gpxsee.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gpxsee.org Received: from mgb4.. (unknown [62.77.71.229]) by mx.gpxsee.org (Postfix) with ESMTPSA id 71D4A4270C; Fri, 26 Apr 2024 16:16:26 +0200 (CEST) From: tumic@gpxsee.org To: Mauro Carvalho Chehab , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Martin=20T=C5=AFma?= Subject: [PATCH v5 3/4] media: mgb4: Fixed signal frame rate limit handling Date: Fri, 26 Apr 2024 16:16:18 +0200 Message-ID: <20240426141619.8866-4-tumic@gpxsee.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240426141619.8866-1-tumic@gpxsee.org> References: <20240426141619.8866-1-tumic@gpxsee.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Martin Tůma Change the default DV timings for the outputs to produce a better signal less "crippled" by the frame rate limiting. While the individual values are now different, the resulting signal still matches the same default display as before. Additionaly fix the corner case when the frame rate limit is set to zero causing a "divide by zero" kernel panic. Signed-off-by: Martin Tůma --- 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 +- 3 files changed, 12 insertions(+), 11 deletions(-) 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 d98b6e87d71f..998edcbd9723 100644 --- a/drivers/media/pci/mgb4/mgb4_vout.c +++ b/drivers/media/pci/mgb4/mgb4_vout.c @@ -665,12 +665,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); @@ -696,8 +696,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; -- 2.44.0