Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3660510pxb; Mon, 24 Jan 2022 14:42:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrnNWHV9YSMHGm/Q+5Di9MYnfTHk/byLkfusHzZV9BdSGro+mzVByKNd8t1oSE9IOipQug X-Received: by 2002:a17:90b:1806:: with SMTP id lw6mr489209pjb.82.1643064168247; Mon, 24 Jan 2022 14:42:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643064168; cv=none; d=google.com; s=arc-20160816; b=x2ZxU4kVMeR2PCj4EK2QpmB5Ovx0lVtyA/SoGDh+v57K0JThmfRoFe/wMt3O0PlEw7 BUzXUWNVBIYJ8/zgQ2mNhss8/ztKJl9r6C56KnT7QUNaHTX+UCAmgHLM+A6O2ACbAJFJ TsuRQPw/13vehagTTSv+1C9tut2LWp14pwaO0SZmCrba3OKlg02uheRi14xfjAGmQ4gt xjs6H7timHij8ceODFwa59l3oSMk+b/v0fvO91jlAKiN299LnILdlnCwGuVzMPFWIuQK JjHcXtOrSqdLSlSUazPnX+sBgtWYLNWpQbi4Shi9jpsZauy+i4Py53kScDzM+TBKs/Ti vSeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aPqzSFmBUFucL4OEFhb/r31ZKlNfbYW9f9XqLKtkn6E=; b=obso4rPKwAjpZbznDEW/huQXKh45tP2Tc/TayjWlyb9tBARMJx7vISIPXFRBch9W93 PocCPR2i/qMQIIoFHJnHDIfo+Puv+XSqXZNNeQSXB88ntcf9XySuyduGP1vC3sy/+y5M 7mtTjbuVwg3T8X2jF4qhtGheDiA0foQofV4URWInperUXjj+WqZqvvS25FyYFPu8fIKX j9Dt/UCn3v0pSpQdu/WubeKuc4MMfSmcfys+kvLP84QaItVvBKnPOUN7eyK+bwFAlPSr 04TUXfoyUpgvLp5vRkWJARiplexQa71WcvzbHqy+bUWOzPJ1Cyd5D65uEmpVGl6a/pIF nSKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="oIOWU7J/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c8si18231142pgq.661.2022.01.24.14.42.36; Mon, 24 Jan 2022 14:42:48 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b="oIOWU7J/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1835549AbiAXWgt (ORCPT + 99 others); Mon, 24 Jan 2022 17:36:49 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:58600 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1456858AbiAXVkR (ORCPT ); Mon, 24 Jan 2022 16:40:17 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 96E346151D; Mon, 24 Jan 2022 21:40:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DD59C340E4; Mon, 24 Jan 2022 21:40:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060416; bh=bp019RBoTTCh7yRBmXJPnGFc3pky8+XP4OrNPBx1/AM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oIOWU7J/EPdgH3JIiAAO0hDK8h0C06VTAVvQnXw7Y5mu7g/EBBCMl+OJEIR4/w6wJ /qnkrkBjLiw6B8DI8916L+hYleQnMr+kto03++fSilQ5Q4ua4BR9Kn/w9f3EWyWVzV BEXEg9N8ImAapw4PS6xptQ7OiIXmtMbH1IYAIC04= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Suresh Udipi , Michael Rodin , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Hans Verkuil , Mauro Carvalho Chehab Subject: [PATCH 5.16 0907/1039] media: rcar-csi2: Optimize the selection PHTW register Date: Mon, 24 Jan 2022 19:44:56 +0100 Message-Id: <20220124184155.785926208@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suresh Udipi commit 549cc89cd09a85aaa16dc07ef3db811d5cf9bcb1 upstream. PHTW register is selected based on default bit rate from Table[1]. for the bit rates less than or equal to 250. Currently first value of default bit rate which is greater than or equal to the caculated mbps is selected. This selection can be further improved by selecting the default bit rate which is nearest to the calculated value. [1] specs r19uh0105ej0200-r-car-3rd-generation.pdf [Table 25.12] Fixes: 769afd212b16 ("media: rcar-csi2: add Renesas R-Car MIPI CSI-2 receiver driver") Signed-off-by: Suresh Udipi Signed-off-by: Michael Rodin Reviewed-by: Niklas Söderlund Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/platform/rcar-vin/rcar-csi2.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -1104,10 +1104,17 @@ static int rcsi2_phtw_write_mbps(struct const struct rcsi2_mbps_reg *values, u16 code) { const struct rcsi2_mbps_reg *value; + const struct rcsi2_mbps_reg *prev_value = NULL; - for (value = values; value->mbps; value++) + for (value = values; value->mbps; value++) { if (value->mbps >= mbps) break; + prev_value = value; + } + + if (prev_value && + ((mbps - prev_value->mbps) <= (value->mbps - mbps))) + value = prev_value; if (!value->mbps) { dev_err(priv->dev, "Unsupported PHY speed (%u Mbps)", mbps);