Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3614939pxb; Mon, 24 Jan 2022 13:34:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvTVZNbdnqJhznJQhppxn28a8lh6SgxEU7TTudx+d7HTwtSE1nOmYos11WGMjGLU9lRL3i X-Received: by 2002:a17:902:a601:b0:148:adf2:9725 with SMTP id u1-20020a170902a60100b00148adf29725mr16089018plq.136.1643060056353; Mon, 24 Jan 2022 13:34:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643060056; cv=none; d=google.com; s=arc-20160816; b=iUue3CSfOWngMGgNfmeSm0gQumTAlJLdza7SbO/vEPQEK0DbauS40ctqnFeuB0MQK8 UEJ84mLJORekQvav94Fc845QpctEeD5+xJozrmn1xwoq9M+pr8mOe0AkKDWkhMKMMFJB CwO2uSf83BTrxGFPLrUb7gzwlr8vGIzmMqCXI6oLpnSTG2fYDDXFQIwaMIFGVHyG1eQt wxSNED04e0V6U+IP/Y1FNEbIFsJsFgldx9n2Ax/p8Oz43gHVUA4+xOC3bf/nMPdbzJVS XoMCKzpCHN1caXHDcgbh048PMLWiG3Kx8Z74JeykY1YCycyL20ROKfAtHSGxNwXdlkeU ICdg== 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=uPyN/hqgr/LBkvx2QRWDOTti9gFq/wlwHotfNDL0B50=; b=ZMvhOBeDSvo/vnZmJGttGE6IFUMxTts4sFtE7zdrItTmW9ATH615UZiuSoCjYW/Y+B IQJ0GICjetU/LFOLIp5wFuIs/XXgQ8ZVlLMMSB0P0mjCW9Jwr5pWcy6DZ8a6hxPj3gpX 95D9UcPFLGTiXIR7VrHZbYzuWJz+U6QFqZ6gfnfVJ43K7vyAirzqyyAh5xH0cczUAL6D M8xiYJLUb6NlSDLH1G3XnGJA3GDjhv9BaiM4g5HnJs9xUa+32U9si9DGwz/qKCmyNjrh CeT2zsmZUnTMC38k1/vKV8SSjSgdVQL9abzI4toqRXXC03hsfuIuH9zcnk3ALeRz4kF7 zJFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jBNSDaIF; 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 x1si13492301pgk.279.2022.01.24.13.33.54; Mon, 24 Jan 2022 13:34:16 -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=jBNSDaIF; 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 S1447607AbiAXVLE (ORCPT + 99 others); Mon, 24 Jan 2022 16:11:04 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:47042 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1390922AbiAXUqj (ORCPT ); Mon, 24 Jan 2022 15:46:39 -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 ams.source.kernel.org (Postfix) with ESMTPS id 7A722B8121C; Mon, 24 Jan 2022 20:46:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 818CEC340E5; Mon, 24 Jan 2022 20:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643057195; bh=4LlpM95g7CNgEA0hqrQZzMpteGnWJ4lfkbLqK14oIGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jBNSDaIFS3ZDeM5I7/pAVBBjtfU5powu4pwmVs900AGWmyioO+rkob53F99mmxWt/ g+dKH3vapBVztYOxF7ndAeEeXJfHZVw2ZKLspdMMLWqhwOVqWJqMwr3W9yvQU5x/5S KVhpIKGH2xNKN2BjqXlWgGjfCcs5KN57PIn5BRpQ= 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.15 733/846] media: rcar-csi2: Optimize the selection PHTW register Date: Mon, 24 Jan 2022 19:44:10 +0100 Message-Id: <20220124184126.285314729@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 @@ -989,10 +989,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);