Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3584011pxb; Mon, 24 Jan 2022 12:49:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJy0iPR4PmrQj7liL64vX5oE1/4IElQ2ZZD81J3+y/m0MOyk4R1akRWFyuQxFnsz0KrhqXjl X-Received: by 2002:a63:7f12:: with SMTP id a18mr4104619pgd.453.1643057378890; Mon, 24 Jan 2022 12:49:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057378; cv=none; d=google.com; s=arc-20160816; b=Sdew9AxFMVCsJVWCvSZIRey4uSI9PwM35+eVdWzpBDE71DFhZ/MQs6rgWgp8zBH2oB ylvIYPgM9WFyQW7b+7WPN1Z4yEKhaQ6js7tnx9gWzXRvNAFL8A5iZGAH3NCmqxXKX8Lc PrZF03WZ2l33T+Ek4mDz25vTo3LUbX6kEW0UscCK/hO09HBWGQ7XVO6QSB9+ixrmJYxb FGvCrMEIIy2eRADiot4nobtpfWAgAaLrvhiuCAOBIj5moHMCsQ5vCVFSis5J7KVtpf3r d2cJgnX1w1O6hfRHZBk/bW5wiw2GGv81PoiHhejlPy+ouInv3p6TYHbqtbdiX+UVgDkQ prDA== 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=yqDD2cxCp6VmSKVM9lYGYKatdrc0SOZarn+hZ7lOWYM=; b=lCFP+byxrMvnwPsewJgzordi7aIk9qQXmBlANuTfL8RbZwhZo6VUBMyPARDF3QYEcg x/Y6B8MieZfj2Bpr9IJAhPGkRnS4ZHrTfk4Jctw8tj1C3tnVBjFVHzEAly5gTgO7SOgy oYMB7YZ+4MEd0MnlZqu1R8mXipkog+gNC3e1E56sRp7Sd6BK64xqZ5PJpjHKCbhSreV9 mpn4uvUC1aBog++eXykAWZxmoOD43cern010Fs2UOJGFLl7SwQoMxjUHP94DOBcT9HC9 VgcthHOl+qAjBGas6e6LufmAwsremOCkvA38Y/qQEezw94yk+RNO5iFCd3QB332YyA1o 4Hhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ihVZ/g2c"; 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 84si13948986pga.663.2022.01.24.12.49.27; Mon, 24 Jan 2022 12:49:38 -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="ihVZ/g2c"; 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 S1377267AbiAXUFO (ORCPT + 99 others); Mon, 24 Jan 2022 15:05:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356831AbiAXTr0 (ORCPT ); Mon, 24 Jan 2022 14:47:26 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 318A3C038AEC; Mon, 24 Jan 2022 11:23:19 -0800 (PST) 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 CCA15B8123F; Mon, 24 Jan 2022 19:23:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1643C340E5; Mon, 24 Jan 2022 19:23:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052197; bh=+5B2a8108S7AUZGD06016KZBTI+r/kEmX5RhV/EvtKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ihVZ/g2cXH+wcz1KNpmiL1gXE5TeK5iw0ulnZvCa6/TbIzBZBeie0FKzEHKojhKmv UjKG4tqyLp5M7U4C/XwwUVaCJK8hocU97RiAcTNoRtHDPedUeKvyX4FEpgw1Wje45Z M7Dust+j66aGsQTpgzb+jljEF2Up6aMIqMMwvi0U= 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 4.19 213/239] media: rcar-csi2: Optimize the selection PHTW register Date: Mon, 24 Jan 2022 19:44:11 +0100 Message-Id: <20220124183949.887495650@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183943.102762895@linuxfoundation.org> References: <20220124183943.102762895@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 @@ -843,10 +843,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);