This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: rcar-csi2: Correct the selection of hsfreqrange
Author:  Suresh Udipi <[email protected]>
Date:    Fri Aug 13 17:07:54 2021 +0200

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 <[email protected]>
Signed-off-by: Kazuyoshi Akiyama <[email protected]>
Signed-off-by: Michael Rodin <[email protected]>
Reviewed-by: Niklas Söderlund <[email protected]>
Signed-off-by: Hans Verkuil <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>

 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 11848d0c4a55..436b7be96920 100644
--- a/drivers/media/platform/rcar-vin/rcar-csi2.c
+++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
@@ -542,16 +542,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;

_______________________________________________
linuxtv-commits mailing list
[email protected]
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

Reply via email to