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: 12435697 X-Patchwork-Delegate: kieran@bingham.xyz 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=ham 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 3ECBEC43216 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 28494610CC for ; Fri, 13 Aug 2021 15:09:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241320AbhHMPJb (ORCPT ); Fri, 13 Aug 2021 11:09:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241270AbhHMPJ0 (ORCPT ); Fri, 13 Aug 2021 11:09:26 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBF96C061292 for ; Fri, 13 Aug 2021 08:08:59 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id h13so13785051wrp.1 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=fa5u4T/MYPaNmdoUnaTqK3kwwE3RzhCAlxx0iULaxf7rzuIbWfiwhWn2Uh8Nsv4CyU mpNuYxEdUcHItWV28O/BnsbKLlD0VoWEcLkjhZq7UscQ0qymQPUffcTVAw7NN44cRmbw HJe9LA7I7guqD8vt3ZZyJ6tVsbemgRVyXSjnrkNJeFgObxI6p7kEGbNPiDLuj1PqPCb0 wmjbtKNPaZBUxc36Q8HPh4itu2IpKP1/gd6+qivlnIXm47FA9yUPdk0i1JWKnj/+rbyS 3xBKPcGd+aBL7coNX/1vQLodgR1DTYlVtAN6RexAjSM6StqkFLp3qh81jBnumuykv0Yg igPA== X-Gm-Message-State: AOAM531Klh3MI/KHVWQ/w0upxsFjJviUKQCWdNMfStSDRaZH+H0jpQYK gkWJumsclU+e2AlAkrGhx2j1Cg== 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-renesas-soc@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: 12435699 X-Patchwork-Delegate: kieran@bingham.xyz 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=ham 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 6393AC19F35 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 4C638610A5 for ; Fri, 13 Aug 2021 15:09:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241367AbhHMPJc (ORCPT ); Fri, 13 Aug 2021 11:09:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241395AbhHMPJ1 (ORCPT ); Fri, 13 Aug 2021 11:09:27 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB1BEC06129F for ; Fri, 13 Aug 2021 08:09:00 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id v4so6630165wro.12 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=Ag3VDDobBat7cJSQK/WEr8eRnO8yjSYCYNskrxcLoxU2t7p5UlFehFlM0gvytBEGAm ANoYT2H6GhJ/L5hFREpXfzbPF3n6+igM7kzgPd8vK2Ch/shfGWM8FdYQtkrjU/05K+NF ALsMsdCELsvoBMiwlXefYbv2CgbKV1gw/NDWP5zt5/QH9IykyMYPXzxkFlxmeDjV1R6q LHdrXDSf022TiDRGrqq8TqibT6BsQtw66l6yCwwybz0S+heVCggeRqCvAi9j/ad6oLwU hVfzSure8qToVhaUDNtVGwIEe//zLqfIiMnTiXaWJdsc1gWjm8RONZxOp+cTU1Ujhjfd 3BAA== X-Gm-Message-State: AOAM533U8eS7R3tLdl31yrAvdQf98BXL/eKjlkYNSQ7yRw2p0EcoAFyx rB9OanG0j/ckfbg/HiTWp5lSzg== 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-renesas-soc@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: 12435701 X-Patchwork-Delegate: kieran@bingham.xyz 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=ham 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 B043DC4320A for ; Fri, 13 Aug 2021 15:09:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BAE5610F7 for ; Fri, 13 Aug 2021 15:09:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241478AbhHMPJm (ORCPT ); Fri, 13 Aug 2021 11:09:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241407AbhHMPJ2 (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 5F40FC061756 for ; Fri, 13 Aug 2021 08:09:01 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id h13so13785190wrp.1 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=Eos+07yTNEFkgZDa97W80JCvUf7AwVdO6CK9RJuP02gg78Cc2pDIOtY1EZfm10VqTE zGiChfIcuBEtranugagoX69Vm7YMReNRYlo14LW+3oNcW5tzL5IbuVAnGYzCFR75/iyC qCtXS0BNBuR9BscxudaT+8KsC0yuKELvIr+18lY61Z3JEC9M/CIzTdtzVVAAIDFf3Lih EgSJM/Z7N8fM5OYTthvRnBMu3uuuGVazkpy9KUabW3aJmS2r9daIx4u+kruY+bxi/qJs 0ubYn86zDPiJ75TsZftJCzLgXDttpZkE0VgTR+Ep6/g3uVg/s16wkVDlqgTPVhkxlYqI JJSQ== X-Gm-Message-State: AOAM533W/kE2VJRCenPYdgK6SBHIZrPalfa6sbjkXTHg6FIxVNqXrD31 0ozu3f6CtGsbpDymdCDRQqlgqw== 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-renesas-soc@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);