From patchwork Thu Jun 18 10:34:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suresh Udipi X-Patchwork-Id: 209375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26D0FC433E0 for ; Thu, 18 Jun 2020 10:34:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 047132186A for ; Thu, 18 Jun 2020 10:34:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=adit-jv.com header.i=@adit-jv.com header.b="fGJzlRa4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728420AbgFRKep (ORCPT ); Thu, 18 Jun 2020 06:34:45 -0400 Received: from ma-dnext02.denso.co.jp ([133.192.181.77]:54001 "EHLO ma-dnext02.denso.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726991AbgFRKem (ORCPT ); Thu, 18 Jun 2020 06:34:42 -0400 Received: from grdma02h.denso.co.jp (unknown [133.192.24.24]) by ma-dnext02.denso.co.jp (Postfix) with ESMTP id 82CCB31C2D9; Thu, 18 Jun 2020 19:34:40 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=adit-jv.com; s=jpadit-jvmail2011; t=1592476480; bh=PqArx+iwOLW7rJ0MHUy1IoCPSk3aDJmD1/nPO2+Xj8M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fGJzlRa4iqJoXYVzYfKjljgtGEQ0sEpwXV2q8nLrmu6yzDeltyhbKSb56AVaVBDax A438xG1kkval0qtXC2leG5JzAvmd2nEByS0oTukMntZm+qVBXDSFoGp2aKTcghj8LL phZxoLDF6g1fowkpFTrjI3gyMGOmWYABLyX6g1eg8eITi1cCSHyDqoU1yGTVyYtoHX umrLKHZnNjhnvFSGbIG3Q1+C40X9mTpTmZ1KALJTzUaZUPN+Mvh4SfMm+LNU7BceS5 10MpdIJnk4KPI4OCar10EW1OsxJgppwAJmX9/X3ActPuUb/TiIDqAYtsc99o6CooIq zEkBnXndre5SA== Received: by grdma02h.denso.co.jp (Postfix, from userid 0) id 79E7DC04E0D; Thu, 18 Jun 2020 19:34:40 +0900 (JST) Received: from smtp0.denso.co.jp [133.192.24.87] by grdma02h. with ESMTP id VAA00351; Thu, 18 Jun 2020 19:34:40 +0900 Received: from ky0exch01.adit-jv.com ([10.71.113.8]) by smtp00.denso.co.jp (MOS 4.4.7-GA) with ESMTP id GBQ29315; Thu, 18 Jun 2020 19:34:39 +0900 Received: from jp-u0004.adit-jv.com (10.71.112.120) by ky0exch01.adit-jv.com (10.71.113.8) with Microsoft SMTP Server (TLS) id 14.3.487.0; Thu, 18 Jun 2020 19:34:39 +0900 From: Suresh Udipi To: CC: , , , , , , , , , , Subject: [PATCH v8 1/3] media: rcar-csi2: Correct the selection of hsfreqrange Date: Thu, 18 Jun 2020 19:34:30 +0900 Message-ID: <1592476472-26235-1-git-send-email-sudipi@jp.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20200617133705.GA88066@vmlxhi-121.adit-jv.com> References: <20200617133705.GA88066@vmlxhi-121.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.71.112.120] Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 --- Changes in v2: - Added the boundary check for the maximum bit rate. - Simplified the logic by remmoving range check as only the closest default value covers most of the use cases. - Aligning the commit message based on the above change Changes in v3: - Added max member from struct rcsi2_mbps_reg. mbps varialbe cannot be removed from rcsi2_mbps_reg, since this structure is reused for phtw_mbps_h3_v3h_m3n/phtw_mbps_v3m_e3 where mbps is used. - Update the walk of the array in rcsi2_set_phypll() so that it finds the first entry where the calculated bit rate is less than the max. - Support lower bit rates less than 80Mbps like 48Mbps (Raspberry pi camera 640x480 connected to Kingfisher) can also be supported by selecting the lowest default bit rate 80Mbps as done before this fix - Alignement of the commit message based on above changes. Changes in v4: - Remove unncessary braces. Changes in v5: - Removed mbps variable in rcsi2_mbps_reg and aligned all tables accordingly Changes in v6 - Renesas correct the range of default value 220Mbps. Now if we select the nearest value to the default value all the values are in range. So reverting back to original patch - Added warning for values less than Minimum 80Mbps Changes in v7 - Create a seperate commit for the warning message less than minimum 80Mbps - Reorder the statements to increase readability Changes in v8 - Extended the logic of selection of nearest mbps to PHTW registers value less than 250Mbps. A new commit is added 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 151e6a9..f18dedc 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -431,16 +431,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; From patchwork Thu Jun 18 10:34:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suresh Udipi X-Patchwork-Id: 209374 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F1F8C433E1 for ; Thu, 18 Jun 2020 10:35:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E2A32065F for ; Thu, 18 Jun 2020 10:35:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=adit-jv.com header.i=@adit-jv.com header.b="xrDC8ULP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728877AbgFRKfL (ORCPT ); Thu, 18 Jun 2020 06:35:11 -0400 Received: from ma-dnext03.denso.co.jp ([133.192.181.78]:44693 "EHLO ma-dnext03.denso.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728769AbgFRKfH (ORCPT ); Thu, 18 Jun 2020 06:35:07 -0400 Received: from grdma01h.denso.co.jp (unknown [133.192.24.24]) by ma-dnext03.denso.co.jp (Postfix) with ESMTP id 7533F5D0473; Thu, 18 Jun 2020 19:35:01 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=adit-jv.com; s=jpadit-jvmail2011; t=1592476501; bh=K0tPOIUp2y9bg5a2AL1dvczXgteN9sm026xR1Mrju64=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=xrDC8ULPYfHPn3ma4NzxmDfVEw0MXzCxCfrAhJZ1AgU0t3rALzNcSlW22WYw1m/HY qc3ywq+q3UcqZRLI3dhBP30oCzXcq5CDX/YByP9GqU3zNH86e7Aij6zwIpxlnWk9EX xFsUzZbvTPc48+gvRzy1WtiGf1HmT+CCYFa4p7iLrQsJohFZvxy+nAdoGouGSz8g54 xqf2fSgJ/RQJzFaeqyv5LgEkZTlBRfS0ErK1l62V/Nzc834LgvER2LtiE8wpWyHsiZ STJAnzoQcxC6VNZA9fLSZYDR8EVso7FiDOoZzgbgu4Kpz6HVr2NHPkF/tyqtCvnkZi 9XSBse7Z5ESMA== Received: by grdma01h.denso.co.jp (Postfix, from userid 0) id 7274CC0BDAB; Thu, 18 Jun 2020 19:35:01 +0900 (JST) Received: from smtp1.denso.co.jp [133.192.24.88] by grdma01h. with ESMTP id VAA11611; Thu, 18 Jun 2020 19:35:01 +0900 Received: from ky0exch01.adit-jv.com ([10.71.113.8]) by smtp01.denso.co.jp (MOS 4.4.7-GA) with ESMTP id GAZ77809; Thu, 18 Jun 2020 19:35:00 +0900 Received: from jp-u0004.adit-jv.com (10.71.112.120) by ky0exch01.adit-jv.com (10.71.113.8) with Microsoft SMTP Server (TLS) id 14.3.487.0; Thu, 18 Jun 2020 19:35:00 +0900 From: Suresh Udipi To: CC: , , , , , , , , , , Subject: [PATCH v8 3/3] media: rcar-csi2: Optimize the selection PHTW register Date: Thu, 18 Jun 2020 19:34:32 +0900 Message-ID: <1592476472-26235-3-git-send-email-sudipi@jp.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1592476472-26235-1-git-send-email-sudipi@jp.adit-jv.com> References: <20200617133705.GA88066@vmlxhi-121.adit-jv.com> <1592476472-26235-1-git-send-email-sudipi@jp.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.71.112.120] Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 --- drivers/media/platform/rcar-vin/rcar-csi2.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c index 1184527..d7bf59f 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -917,10 +917,18 @@ static int rcsi2_phtw_write_mbps(struct rcar_csi2 *priv, unsigned int mbps, 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);