From patchwork Wed Jul 1 09:52:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Suresh Udipi X-Patchwork-Id: 11635963 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4115E13B4 for ; Wed, 1 Jul 2020 09:53:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24B9B20747 for ; Wed, 1 Jul 2020 09:53:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=adit-jv.com header.i=@adit-jv.com header.b="gzV88vIe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729772AbgGAJxM (ORCPT ); Wed, 1 Jul 2020 05:53:12 -0400 Received: from ma-dnext02.denso.co.jp ([133.192.181.77]:33306 "EHLO adnmlgw02h.denso.co.jp" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729125AbgGAJxM (ORCPT ); Wed, 1 Jul 2020 05:53:12 -0400 Received: from grdma02h.denso.co.jp (unknown [133.192.24.24]) by adnmlgw02h.denso.co.jp (Postfix) with ESMTP id 0A75D2003C32; Wed, 1 Jul 2020 18:53:10 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adit-jv.com; s=jpadit-jvmail2020; t=1593597190; bh=7vMnJFc58ZUxgfOr5zdrARnb6OS0Vcw9IaskaHz/0Sc=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=gzV88vIeTaGB1+7N4bQZj18bmbwzwyUKP2ppcWUBfNwqy0r0cRpbNk9O60J//AOO1 B2i29zcTPn0VKDhcBkVFWbCfHBW0ERd7rQTpCXXCuXLdNrMv3MFZezfCEMj+LNRNGQ Zxx8WUX0kzMn6kUQyTwwal/x6ZmkkG8FeAicXs0OOXaTJLyh5DCm07EB0elcnXbtMg bSfIQNzpkWjkJfkcDpGaph7pCsjKM/vxjIB68Ygf8/FPnj6xyU927GrNSwfe5jyIz1 hM7NU27cLmuNZ1p3awx8hMLYK2jIVIJMG+alrnIrr4wnYJL0X4tICsydHfMQgubSyR a3mqZcJEL7Rdw== Received: by grdma02h.denso.co.jp (Postfix, from userid 0) id 079A3C04E01; Wed, 1 Jul 2020 18:53:10 +0900 (JST) Received: from smtp1.denso.co.jp [133.192.24.88] by grdma02h. with ESMTP id UAA29947; Wed, 1 Jul 2020 18:53:09 +0900 Received: from ky0exch01.adit-jv.com ([10.71.113.8]) by smtp01.denso.co.jp (MOS 4.4.7-GA) with ESMTP id GDD18802; Wed, 1 Jul 2020 18:53:08 +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; Wed, 1 Jul 2020 18:53:07 +0900 From: Suresh Udipi To: CC: , , , , , , , , , , Subject: [PATCH v9 1/3] media: rcar-csi2: Correct the selection of hsfreqrange Date: Wed, 1 Jul 2020 18:52:59 +0900 Message-ID: <1593597181-8296-1-git-send-email-sudipi@jp.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20200630220816.GL2365286@oden.dyn.berto.se> References: <20200630220816.GL2365286@oden.dyn.berto.se> MIME-Version: 1.0 X-Originating-IP: [10.71.112.120] Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@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 Reviewed-by: Niklas Söderlund --- 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 Changes in v9 - Added Reviewed-by. - Removed unncessary space in commit msg and commits 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 Wed Jul 1 09:53:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Suresh Udipi X-Patchwork-Id: 11635965 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9734313B4 for ; Wed, 1 Jul 2020 09:53:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7DA9C2073E for ; Wed, 1 Jul 2020 09:53:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=adit-jv.com header.i=@adit-jv.com header.b="EntwAUkX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729791AbgGAJxR (ORCPT ); Wed, 1 Jul 2020 05:53:17 -0400 Received: from ma-dnext02.denso.co.jp ([133.192.181.77]:33408 "EHLO adnmlgw02h.denso.co.jp" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726343AbgGAJxR (ORCPT ); Wed, 1 Jul 2020 05:53:17 -0400 Received: from grdma01h.denso.co.jp (unknown [133.192.24.24]) by adnmlgw02h.denso.co.jp (Postfix) with ESMTP id A1AF82003C30; Wed, 1 Jul 2020 18:53:14 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adit-jv.com; s=jpadit-jvmail2020; t=1593597194; bh=QpK+feyWmMCQlJ+m4C4aQ/rhiLGJd7a1sLleuAWZDT4=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=EntwAUkXrLsccTlGuLiiojVNtXlRpA6fKNFxBz1RSYFEaeolArF+Kq3r9478TMzRR 2KP1T+D4to3eNjS6Aesm+X9ZKoY2J3hilIb3kH8qc1VOmfKqH5X8xR+HvGVQuaU7uc AXfDc4WBJbNEFMd+p70ZmCQdps641ix2jFMTwLJwITotDoyBm2yYEEWe7cZkyr7rIa 7AyVIsTFrUBMHFNF73i+TQuu/f0AsttdBDGgvkzkTL1SAn2TBRjYpic5hz/4lW4Y1+ BYKNydlffm6zbhk3LoBVibA+lqQNnZ4rptPhUDyrGjtAor0zC5VuNFdTvWjRxr+v7K 6Es618WluUXVQ== Received: by grdma01h.denso.co.jp (Postfix, from userid 0) id 9E299C04E0E; Wed, 1 Jul 2020 18:53:14 +0900 (JST) Received: from smtp1.denso.co.jp [133.192.24.88] by grdma01h. with ESMTP id UAA12285; Wed, 1 Jul 2020 18:53:14 +0900 Received: from ky0exch01.adit-jv.com ([10.71.113.8]) by smtp01.denso.co.jp (MOS 4.4.7-GA) with ESMTP id GDD18852; Wed, 1 Jul 2020 18:53:14 +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; Wed, 1 Jul 2020 18:53:13 +0900 From: Suresh Udipi To: CC: , , , , , , , , , , Subject: [PATCH v9 2/3] media: rcar-csi2: Add warning for PHY speed less than minimum Date: Wed, 1 Jul 2020 18:53:00 +0900 Message-ID: <1593597181-8296-2-git-send-email-sudipi@jp.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1593597181-8296-1-git-send-email-sudipi@jp.adit-jv.com> References: <20200630220816.GL2365286@oden.dyn.berto.se> <1593597181-8296-1-git-send-email-sudipi@jp.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.71.112.120] Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Add a warning message when the selected PHY speed is less than supported minimum PHY speed given in the hsfreq table[1]. For raspberry pi camera capture on Kingfisher board with resolution 640x480, the calculated PHY speed is 48 mbps which is less than the minimum PHY speed 80 Mbps from the table[1]. But in this cases capture is successful. [1] specs r19uh0105ej0200-r-car-3rd-generation.pdf [Table 25.9] Signed-off-by: Suresh Udipi Signed-off-by: Michael Rodin Reviewed-by: Niklas Söderlund --- drivers/media/platform/rcar-vin/rcar-csi2.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c index f18dedc..1184527 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -433,6 +433,10 @@ 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; + if (mbps < priv->info->hsfreqrange->mbps) + dev_warn(priv->dev, "%u Mbps less than min PHY speed %u Mbps", + mbps, priv->info->hsfreqrange->mbps); + for (hsfreq = priv->info->hsfreqrange; hsfreq->mbps != 0; hsfreq++) { if (hsfreq->mbps >= mbps) break; From patchwork Wed Jul 1 09:53:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Suresh Udipi X-Patchwork-Id: 11635969 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A205912 for ; Wed, 1 Jul 2020 09:53:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F3AF20747 for ; Wed, 1 Jul 2020 09:53:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=adit-jv.com header.i=@adit-jv.com header.b="DDbJNvOS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729799AbgGAJxY (ORCPT ); Wed, 1 Jul 2020 05:53:24 -0400 Received: from ma-dnext01.denso.co.jp ([133.192.181.76]:33426 "EHLO adnmlgw01h.denso.co.jp" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726343AbgGAJxX (ORCPT ); Wed, 1 Jul 2020 05:53:23 -0400 Received: from grdma01h.denso.co.jp (unknown [133.192.24.24]) by adnmlgw01h.denso.co.jp (Postfix) with ESMTP id 822EA2001015; Wed, 1 Jul 2020 18:53:22 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adit-jv.com; s=jpadit-jvmail2020; t=1593597202; bh=AA4N0r3nVMyfY229fipU3bpRWZ7RgWTk3Fj6MV78fTw=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=DDbJNvOS4/iQn3Hej09I5Jk2rTWGLl/YzzYA91CW7pQCEDJVkObN5R9K/RJMDv8vJ Nk4ROCLAyB4bZ775VjNpPxJ4WImTmc2IwtshUf+KD7zwhbZzVTZ8wpjIMaxfpinl+H IfbEdfABMkvVWytqgJf/Bk5V8PJYFx/RjJnq7riDL2S7d1TKwRqNOrNEcWfJrgPlDH ElidiEYhFM+QN+on8ta06tR1weYV7kOksAjqOsyqeQ79DklPFnDcQniHxti6BONWqX pIXUraftczACfTk4jDu5AHCXpsOSblwWpzw+92yc9KKzJTeOSLCKVLPJt7USqyG6Az QiztAfqCBBfTw== Received: by grdma01h.denso.co.jp (Postfix, from userid 0) id 7F51CC04E0A; Wed, 1 Jul 2020 18:53:22 +0900 (JST) Received: from smtp1.denso.co.jp [133.192.24.88] by grdma01h. with ESMTP id UAA12619; Wed, 1 Jul 2020 18:53:22 +0900 Received: from ky0exch01.adit-jv.com ([10.71.113.8]) by smtp01.denso.co.jp (MOS 4.4.7-GA) with ESMTP id GDD18934; Wed, 1 Jul 2020 18:53:22 +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; Wed, 1 Jul 2020 18:53:21 +0900 From: Suresh Udipi To: CC: , , , , , , , , , , Subject: [PATCH v9 3/3] media: rcar-csi2: Optimize the selection PHTW register Date: Wed, 1 Jul 2020 18:53:01 +0900 Message-ID: <1593597181-8296-3-git-send-email-sudipi@jp.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1593597181-8296-1-git-send-email-sudipi@jp.adit-jv.com> References: <20200630220816.GL2365286@oden.dyn.berto.se> <1593597181-8296-1-git-send-email-sudipi@jp.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.71.112.120] Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@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 Reviewed-by: Niklas Söderlund --- 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 1184527..3efa1cb 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -917,10 +917,17 @@ 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);