Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3628418pxb; Mon, 24 Jan 2022 13:54:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJydDX5tRSQS8+gpD3UK5LNBqAX7SRHEsHVDYL2ASHuOFKmmbO3PygHhKI2rONS5d8cLDCzD X-Received: by 2002:a63:8ac7:: with SMTP id y190mr10983537pgd.359.1643061255917; Mon, 24 Jan 2022 13:54:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643061255; cv=none; d=google.com; s=arc-20160816; b=gLXigLFH74LXnpj4XJV9xI7HathYWkOYhLIUrvcQxWo/FlaX8PtDm/283Wr0ukngvF WDfjt9V2MgDM2mPd2pkWoMDRN/ICvY3Q8mfTmTRFGvz+C6qZynRNXUdpOU+A2P6G6xc6 ZQEuwS51xck4axBtZuyS8Ha6PIrtrvkjVdYcgNmk5+JjbNpYzVoDy6pZh5ORnF16F8Nq vSHuLs6yNwy+DHLQi2wAtNufOwX+Q6O5CuNUY0c5WBs16WXLxvwJb9MiElmP16HMWom3 ytc+m6QyoR90yGGPwXVznsexDBlGs0H6Ml6VEkcVLDwomGRKtZ8mvrTG1GXUQANe8t0i Bg9Q== 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=TAqKPGdjPyb4OKxu1ZbRRhANtF7o/c68Pln2F+XoJdk=; b=LCV5i/3yXxF53BRIL/ZBKv6r5LbyeyVur4j0/U2llN1MgL2RWQdT1xpPFEIYsP0D0p F7Rhj/CCRFbweJSpEktcWV9hT3q9T43sqWpuaQfaxF7F8bfiVh5/uMCO+MFIQ1e5goN4 aHNTuZyGrwY5/FrUqt1txUsoJCJ6stkfJrOK5lsQKjnJC2uWC1d+zmVnDfq95fSFtRgp MzHS5jZ1Sp90kqnHti6w9iUYtUltUBbsxqy88h5sYJGQ5F+i+db2O1JWwbSPZTdqN5G2 /j+uFscWBH4ZDdrALN0FWSm3/NcquabIVBF3oxOmKX+i2+ZNopNYw5OnPNIaDx6b9EYk I4yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mDlZgF8Z; 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 w10si13854582plq.346.2022.01.24.13.54.03; Mon, 24 Jan 2022 13:54:15 -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=mDlZgF8Z; 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 S1456931AbiAXVk1 (ORCPT + 99 others); Mon, 24 Jan 2022 16:40:27 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:50862 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445095AbiAXVCL (ORCPT ); Mon, 24 Jan 2022 16:02:11 -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 C8146611DA; Mon, 24 Jan 2022 21:02:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB269C340E5; Mon, 24 Jan 2022 21:02:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058130; bh=IhACb9bxfxsVvsSEtnGRQo29vIfTysy249Res4IG6L4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mDlZgF8Z+G/ucHLdsJ58kTvecV5Ja775GozrP2TI+xgBXcejbd0QqL+S+bOo78A2r peiMDBtt71Gv10ujEiXdgWBdJorfoderRbt95AkzLolQzKgeuxzU/t+JsWdCNU764p gZPERttGdkX8d32X4mx30yqV1xr2O2O9o2zXmQEQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Suresh Udipi , Kazuyoshi Akiyama , Michael Rodin , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.16 0188/1039] media: rcar-csi2: Correct the selection of hsfreqrange Date: Mon, 24 Jan 2022 19:32:57 +0100 Message-Id: <20220124184131.625904622@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 [ Upstream commit cee44d4fbacbbdfe62697ec94e76c6e4f726c5df ] hsfreqrange should be chosen based on the calculated mbps which is closer to the default bit rate and within the range as per table[1]. But current calculation always selects first value which is greater than or equal to the calculated mbps which may lead to chosing a wrong range in some cases. For example for 360 mbps for H3/M3N Existing logic selects Calculated value 360Mbps : Default 400Mbps Range [368.125 -433.125 mbps] This hsfreqrange is out of range. The logic is changed to get the default value which is closest to the calculated value [1] Calculated value 360Mbps : Default 350Mbps Range [320.625 -380.625 mpbs] [1] specs r19uh0105ej0200-r-car-3rd-generation.pdf [Table 25.9] Please note that According to Renesas in Table 25.9 the range for 220 default value is corrected as below |Range (Mbps) | Default Bit rate (Mbps) | ----------------------------------------------- | 197.125-244.125 | 220 | ----------------------------------------------- Fixes: 769afd212b16 ("media: rcar-csi2: add Renesas R-Car MIPI CSI-2 receiver driver") Signed-off-by: Suresh Udipi Signed-off-by: Kazuyoshi Akiyama Signed-off-by: Michael Rodin Reviewed-by: Niklas Söderlund Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/platform/rcar-vin/rcar-csi2.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c index 11848d0c4a55c..436b7be969202 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -542,16 +542,23 @@ static int rcsi2_wait_phy_start(struct rcar_csi2 *priv, static int rcsi2_set_phypll(struct rcar_csi2 *priv, unsigned int mbps) { const struct rcsi2_mbps_reg *hsfreq; + const struct rcsi2_mbps_reg *hsfreq_prev = NULL; - for (hsfreq = priv->info->hsfreqrange; hsfreq->mbps != 0; hsfreq++) + for (hsfreq = priv->info->hsfreqrange; hsfreq->mbps != 0; hsfreq++) { if (hsfreq->mbps >= mbps) break; + hsfreq_prev = hsfreq; + } if (!hsfreq->mbps) { dev_err(priv->dev, "Unsupported PHY speed (%u Mbps)", mbps); return -ERANGE; } + if (hsfreq_prev && + ((mbps - hsfreq_prev->mbps) <= (hsfreq->mbps - mbps))) + hsfreq = hsfreq_prev; + rcsi2_write(priv, PHYPLL_REG, PHYPLL_HSFREQRANGE(hsfreq->reg)); return 0; -- 2.34.1