Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp956830ybm; Wed, 27 May 2020 12:08:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJnMoBhTyeZhrKSQ+d2c79fr+TsuU/g2g8yfq12DduS1tFw/1tIWJX9UEcBesDlRkiv1SU X-Received: by 2002:a50:c906:: with SMTP id o6mr21850790edh.95.1590606521845; Wed, 27 May 2020 12:08:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590606521; cv=none; d=google.com; s=arc-20160816; b=d2pvDM9x70ye/HbPV6PFKJgFlzl8z4do2R/xnR/kG8GWX3/+EzCQjnU2O5gvDUJbxd PEhF0SnZipwYxD65tqcLQ534T00iiCRqxplVV9JbtukDuMmrUzkWTBsyPLrmaumioU+9 4bix3FBhiyOos9FhyJYQp2iFTouDlHadxvvHQJ/oe/SU6zvlwPca1K48y+zXd2brAhB9 s7TQ5zMJATnplkQnBVXVHjAeiZSnwUG7hmCxRHvAR9NLz4WgrwKCY9W/3tstcRrOoO+R qNzx1cykn0fZru85pGi0P9kl/9WEL32GD5iMfv+3Y9dDqxeHfBrTQbhgtSCmtalwXwJc 3y3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=VEOq1ytGRJvTmyPmeJ1dTX/9AtObiL+26hVDNUWhHTg=; b=W8DVeMtnY77aAuCczzaw3Wy9WIfm0RjhXC80hzHvZ7yYkim6DrFJn8UlTRYm+vDJHX HsEFDhugomxDy3nn6cZNx0IdhkMnbnMlSMgZDogSvaFZDQs4KKvEXMRy0H2CAn8NJJUr YBQK4/4UkfONbveGGpSy3jBmPvwXiOh1587UbMEoZ+QIFcAbN3gKmU6BHVOHoR5uL6xk 26W7NwEADg7U0a8Jck92P5p+MYbGYK7kS09zuaglq+T8rP3MJKn17fMBO0vW8d/+Qk+O RNHImLsienNnQTBx/cyYU/yyegx44MouJnYvnbNOHfpoUtAog19J7YwtitwIxW7rLC7i lBKA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m24si2355325eji.423.2020.05.27.12.08.19; Wed, 27 May 2020 12:08:41 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730580AbgE0QRT (ORCPT + 98 others); Wed, 27 May 2020 12:17:19 -0400 Received: from smtp1.de.adit-jv.com ([93.241.18.167]:45215 "EHLO smtp1.de.adit-jv.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727801AbgE0QRR (ORCPT ); Wed, 27 May 2020 12:17:17 -0400 Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 42EEA3C057F; Wed, 27 May 2020 18:17:14 +0200 (CEST) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HflFoytKzyDw; Wed, 27 May 2020 18:17:08 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id B95253C0579; Wed, 27 May 2020 18:17:08 +0200 (CEST) Received: from vmlxhi-121.localdomain (10.72.94.22) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.487.0; Wed, 27 May 2020 18:17:08 +0200 From: Michael Rodin To: =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Mauro Carvalho Chehab , , , CC: Michael Rodin , , , , Suresh Udipi Subject: [PATCH] rcar-vin: rcar-csi2: Correct the selection of hsfreqrange Date: Wed, 27 May 2020 18:16:07 +0200 Message-ID: <1590596167-17403-1-git-send-email-mrodin@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20200512213045.GC2542285@oden.dyn.berto.se> References: <20200512213045.GC2542285@oden.dyn.berto.se> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.72.94.22] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suresh Udipi 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] There is one exectpion value 227Mbps, which may cause out of range. This needs to be further handled if required. Fixes: ADIT v4.14 commit 9e568b895ee0 ("media: rcar-csi2: add Renesas R-Car MIPI CSI-2 receiver driver") Signed-off-by: Suresh Udipi Signed-off-by: Michael Rodin --- drivers/media/platform/rcar-vin/rcar-csi2.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c index c473a56..73d9830 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -199,6 +199,7 @@ static const struct rcsi2_mbps_reg phtw_mbps_v3m_e3[] = { /* PHY Frequency Control */ #define PHYPLL_REG 0x68 #define PHYPLL_HSFREQRANGE(n) ((n) << 16) +#define PHYPLL_HSFREQRANGE_MAX 1500 static const struct rcsi2_mbps_reg hsfreqrange_h3_v3h_m3n[] = { { .mbps = 80, .reg = 0x00 }, @@ -446,16 +447,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++) - if (hsfreq->mbps >= mbps) - break; - - if (!hsfreq->mbps) { + if (mbps > PHYPLL_HSFREQRANGE_MAX) { dev_err(priv->dev, "Unsupported PHY speed (%u Mbps)", mbps); return -ERANGE; } + for (hsfreq = priv->info->hsfreqrange; hsfreq->mbps != 0; hsfreq++) { + if (hsfreq->mbps >= mbps) + break; + hsfreq_prev = hsfreq; + } + + 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.7.4