Re: [PATCH] rcar-vin: rcar-csi2: Correct the selection of hsfreqrange

From: Michael Rodin
Date: Fri Jun 05 2020 - 14:45:18 EST


Hello Niklas and Suresh,

Renesas confirmed that there is a typo in the Hardware Manual (Table 25.9):
The correct range for 220 Mbps is 197.125-244.125 and not 197.125 - 224.125
so the both patches are correct, we can do configuration based only on
the "default" bit rates. I would say that now we can correct the commit
message with respect to the exception value and use these patches. I would
additionally add a warning for bitrates below 80 Mbps. They seem to work
(for example Raspberry Pi camera), however they are not officially supported
so the user needs to be warned.

On Wed, May 27, 2020 at 06:16:07PM +0200, Michael Rodin wrote:
> From: Suresh Udipi <sudipi@xxxxxxxxxxxxxx>
>
> 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]
>
> There is one exectpion value 227Mbps, which may cause out of
> range. This needs to be further handled if required.
>
> Fixes: ADIT v4.14 commit 9e568b895ee0 ("media: rcar-csi2: add Renesas R-Car MIPI CSI-2 receiver driver")
>
> Signed-off-by: Suresh Udipi <sudipi@xxxxxxxxxxxxxx>
> Signed-off-by: Michael Rodin <mrodin@xxxxxxxxxxxxxx>
> ---
> drivers/media/platform/rcar-vin/rcar-csi2.c | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> index c473a56..73d9830 100644
> --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> @@ -199,6 +199,7 @@ static const struct rcsi2_mbps_reg phtw_mbps_v3m_e3[] = {
> /* PHY Frequency Control */
> #define PHYPLL_REG 0x68
> #define PHYPLL_HSFREQRANGE(n) ((n) << 16)
> +#define PHYPLL_HSFREQRANGE_MAX 1500
>
> static const struct rcsi2_mbps_reg hsfreqrange_h3_v3h_m3n[] = {
> { .mbps = 80, .reg = 0x00 },
> @@ -446,16 +447,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++)
> - if (hsfreq->mbps >= mbps)
> - break;
> -
> - if (!hsfreq->mbps) {
> + if (mbps > PHYPLL_HSFREQRANGE_MAX) {
> dev_err(priv->dev, "Unsupported PHY speed (%u Mbps)", mbps);
> return -ERANGE;
> }
>
> + for (hsfreq = priv->info->hsfreqrange; hsfreq->mbps != 0; hsfreq++) {
> + if (hsfreq->mbps >= mbps)
> + break;
> + hsfreq_prev = hsfreq;
> + }
> +
> + if (hsfreq_prev &&
> + ((mbps - hsfreq_prev->mbps) <= (hsfreq->mbps - mbps)))
> + hsfreq = hsfreq_prev;
> +
> rcsi2_write(priv, PHYPLL_REG, PHYPLL_HSFREQRANGE(hsfreq->reg));
>
> return 0;
> --
> 2.7.4
>

--
Best Regards,
Michael