From patchwork Fri Aug 13 15:07:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 496815 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=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 B59F7C4320E for ; Fri, 13 Aug 2021 15:09:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9AE5661102 for ; Fri, 13 Aug 2021 15:09:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241366AbhHMPJb (ORCPT ); Fri, 13 Aug 2021 11:09:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241372AbhHMPJ0 (ORCPT ); Fri, 13 Aug 2021 11:09:26 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D53DEC06129D for ; Fri, 13 Aug 2021 08:08:59 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id x10so7441629wrt.8 for ; Fri, 13 Aug 2021 08:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MiAu4Z8LjA1jtagE+o9XE0peuWMmYw2d2UPpNQceGYc=; b=WRJfD/axNkbzHc9ld30D07yJhZJ15RrKg+KTlUlBVnaJVm2YY6INSzzoEJELkl9gK0 aGPwC2USk/z8fxeC7giIeFVwHF1Isd1WL/I0s1crNqQKxvLhw97+g/00Q1Do1EgpHtoy 4hIRQ8XfZWGkVTiStaVDOoj9LFO5ergZOfjI1T590JCLwxff8LpHjtH4XHAuWyDD7H++ zIPkJM3wWg3i3G7Wqrjh+IXTNdXl0RuiuZN7sktBYAbJanwfn5AiDcDDJJJU2eB3d6eU 62loY/tZs09qqg6VBvZ4QBniTtpU6J/b9Bt5jcIZpZW6VQOYC9fmrbd23/USVV45Nw0E 4//A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MiAu4Z8LjA1jtagE+o9XE0peuWMmYw2d2UPpNQceGYc=; b=X/cDUnR09lW1a4SRJXaOHptE0+aLAFD/FwSc2G3pw8qWdYyV5DM9FpK4xOPpPKZ0z4 Ha39k0l228eo4MRN2tHRbUABU47tVhShaJdFBzHr536E4HmQvH0Jpb5vETazUR2A7fva arD62HihHJd5bJK1yBofqcKOrfgcTrL4nHDBTb3o+TX51yZze5IZk4Dh0yGeN1LZMADo Emd/Ve5T/U6wYlA0Ya69P3vAycgXeYcoD/YEefCgMkChsOb12vrRus3whJjNcwjm2pkA V3r5BU7jyKlNrtCtt8nMRwFNgzOydqFqUb2V4tsNfq/tbT6qy68YvTGJDxf1E73K0XYW U8GA== X-Gm-Message-State: AOAM530y+ds0Piz4yqLBfxOn2RyzBAeC8NEiMcPjWQOfuIaJrQNOxoy1 2j6VsonSxexB7bAVP8FIsfA77w== X-Google-Smtp-Source: ABdhPJww6+pIROS9DTmsoIAwxtvURwjRSmy+0UbYqqK5noP6fvneTtzPZmdA+CaS/72OCFTUiWzW4w== X-Received: by 2002:adf:e107:: with SMTP id t7mr3726923wrz.165.1628867338451; Fri, 13 Aug 2021 08:08:58 -0700 (PDT) Received: from bismarck.berto.se (p54ac5892.dip0.t-ipconnect.de. [84.172.88.146]) by smtp.googlemail.com with ESMTPSA id h4sm1799575wrm.42.2021.08.13.08.08.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Aug 2021 08:08:57 -0700 (PDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Hans Verkuil , linux-media@vger.kernel.org Cc: Suresh Udipi , linux-renesas-soc@vger.kernel.org, =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH 1/3] media: rcar-csi2: Correct the selection of hsfreqrange Date: Fri, 13 Aug 2021 17:07:54 +0200 Message-Id: <20210813150756.131826-2-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150756.131826-1-niklas.soderlund+renesas@ragnatech.se> References: <20210813150756.131826-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@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] 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 --- 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 711b52ba42b54afd..d042967335edbd6a 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -543,16 +543,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 Fri Aug 13 15:07:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 496814 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=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 7DBBBC3F6A3 for ; Fri, 13 Aug 2021 15:09:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E7E361102 for ; Fri, 13 Aug 2021 15:09:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241421AbhHMPJc (ORCPT ); Fri, 13 Aug 2021 11:09:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241397AbhHMPJ1 (ORCPT ); Fri, 13 Aug 2021 11:09:27 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2038C06129E for ; Fri, 13 Aug 2021 08:09:00 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id k29so13726510wrd.7 for ; Fri, 13 Aug 2021 08:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aBRuit42IxEUIwCkR+zV1zkqANFvSAk/TjoZTt2MMGw=; b=iwNgaFK9cWzQLs5cUEnsoG7FFlx4b+NNX6tmMVvoD3qn72yi12KCmRwEZDKP5X+l99 dQd/raH6BcQ2tl4BLAnz1H0Nk29AzEkxxE9GgWb6S7+v0sYBKOMYKsd3sFXx1W93hdw8 lfzXI0+bJXPAu47JSY1w3z/e+hcNgTyDexgLfY+TxssKGw3igoHOPyRx2pqbcA3oC42E Tmh/PsMwog6XQZbl7hoLz/aXpG1I4D7hNba0AnOdwkWlS91pd7i5cHHTJ2+2sEqUDOaQ wDh/LpYZBK9K0p1EuN+wKgrjZqoA6QEs60quPBuEwUV/zPrffXHOOg62Yxr6SSqFr5Ng Gddw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aBRuit42IxEUIwCkR+zV1zkqANFvSAk/TjoZTt2MMGw=; b=lPTTgSuG3meaTMwnMMVAZZmRJuLojseHmDytWU7AMwEYJlaDO876juVmpIOuQXk200 +ZkY/vcrC/yuJ3+6+HEnwzIt61r51AogmcwuXxWcONQ45gaIQw8mPyoKiAE5mgcBHErN 0UaG9KlAosFIXFhV5l7A1uTrVI1T0xYVClJS6hoeTylVNU4u5e6nht8kUC7NzaejjKvm xSGMPsbFyalkci2SSh1sTOGXwp+DVK6wIsTDn1SHEqz+0vL/ZGJqFzCWWW4bkm1Hhhwq FL0iQC53K3Y2xL0P74Ek54RENtWmBedWO28F4ref96jdlOlAuggtrvspgOXY9QCBQ8g/ 03jg== X-Gm-Message-State: AOAM53233CSgu7H6hJFfP/m3qvgKw+WF8R09qvWxXJ0wwKk2lSJgM7SF UEWuXrxsbt/FrGsjEbKamDJO2A== X-Google-Smtp-Source: ABdhPJzdcgGAcabk9eunY75UKqtfzAFql7s3y8K9es1bXfigDeuxEcLw+Khc5167gR7xbzLBJ9z+4Q== X-Received: by 2002:a5d:58da:: with SMTP id o26mr3866594wrf.140.1628867339233; Fri, 13 Aug 2021 08:08:59 -0700 (PDT) Received: from bismarck.berto.se (p54ac5892.dip0.t-ipconnect.de. [84.172.88.146]) by smtp.googlemail.com with ESMTPSA id h4sm1799575wrm.42.2021.08.13.08.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Aug 2021 08:08:58 -0700 (PDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Hans Verkuil , linux-media@vger.kernel.org Cc: Suresh Udipi , linux-renesas-soc@vger.kernel.org, =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH 2/3] media: rcar-csi2: Add warning for PHY speed less than minimum Date: Fri, 13 Aug 2021 17:07:55 +0200 Message-Id: <20210813150756.131826-3-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150756.131826-1-niklas.soderlund+renesas@ragnatech.se> References: <20210813150756.131826-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Suresh Udipi 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 d042967335edbd6a..5b531e0bb5a08f9c 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -545,6 +545,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 Fri Aug 13 15:07:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 497256 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=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 0219DC432BE for ; Fri, 13 Aug 2021 15:09:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E05BC610F7 for ; Fri, 13 Aug 2021 15:09:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241479AbhHMPJm (ORCPT ); Fri, 13 Aug 2021 11:09:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241406AbhHMPJ2 (ORCPT ); Fri, 13 Aug 2021 11:09:28 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 601CDC0617AE for ; Fri, 13 Aug 2021 08:09:01 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id l18so13746481wrv.5 for ; Fri, 13 Aug 2021 08:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W8ZDF8z+b7ZAjV4vNrnorD1PEm8hr1QtFpmDxBnDqKg=; b=VX9JcxnfMM2tnvlJOsz34xq7pwp9ssD8+/TH0LQZnJ2sSRZSNW/mjdLEFOhULrMNmQ HXtTgwsl+kf4RGD2CLTPzCMdm5dyNZjgNM8L/SPFlY/AL4UwUWTBH7oRfj/RlV+JMSHH OPgdbnv30EcUrdxlul3W8poZj0O+hfyiv6rWtCDAbXPaX1F705jZ5luOPOaf+VHWosFX YEy13fZWjp2a4QCLdvz5zukoAQ1Kq5XzlNCoCxFwMXt9S3DAP/54wZIUnNcvxrN5TbjX hpzb4SGZUbzJkUem/s+vtSfmD0flu/FHQ8Fg6OvrBsgy+GoTR8bfZTv2pNj90Z/7ZCtW 6e1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W8ZDF8z+b7ZAjV4vNrnorD1PEm8hr1QtFpmDxBnDqKg=; b=m8yqI6jnVMTKFdi6/3vcj5KRLa1KTSAvel9LZIdbAIQ5tvIcWlclIyUB5DjI70tYvM F/hsn9HqHk9LxTbwDZx+lrLEr0b0HBfLxTLP/o7AT74D/lGR/7imrDphlgNXmPsemabD mWOFZdRAy4b9cGjceBJ76oRGymGzHp8dsXtDH5u6LYcF6GFI8yIpi/lH5KNVDe6hFd5d G/Yai3WFDT2/8h4QTcPnoynBHGarq8ls86pxWsMtuj86ts7plEYHc3UgpBIuBkfQHphX ncuq/8wdcyy6yphAwk3ojTHdGGAtGRrXF9GyUyNyx56U0AeRXHd8fg9Vs7Q0pCr0StPY 5c/g== X-Gm-Message-State: AOAM531+AIvQDy0YlqZ/+1iIomx33G/g2wDq6tCGfTQYP7oxf9SO+ZwE WG8Fz4YKdkBO9i0cIs+Oz14Tlw== X-Google-Smtp-Source: ABdhPJyGjTiuYAtrjcvhLSl8gbO6XVV1t3LdztqT9zh+jTuH+0J/ydhnwERR+YQFPworBdi9fqMXPQ== X-Received: by 2002:a5d:638b:: with SMTP id p11mr3697049wru.257.1628867340063; Fri, 13 Aug 2021 08:09:00 -0700 (PDT) Received: from bismarck.berto.se (p54ac5892.dip0.t-ipconnect.de. [84.172.88.146]) by smtp.googlemail.com with ESMTPSA id h4sm1799575wrm.42.2021.08.13.08.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Aug 2021 08:08:59 -0700 (PDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Hans Verkuil , linux-media@vger.kernel.org Cc: Suresh Udipi , linux-renesas-soc@vger.kernel.org, =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH 3/3] media: rcar-csi2: Optimize the selection PHTW register Date: Fri, 13 Aug 2021 17:07:56 +0200 Message-Id: <20210813150756.131826-4-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150756.131826-1-niklas.soderlund+renesas@ragnatech.se> References: <20210813150756.131826-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Suresh Udipi 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 5b531e0bb5a08f9c..4a27ea8ce96dceaf 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -1099,10 +1099,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);