* [PATCH 1/3] media: rcar-csi2: Correct the selection of hsfreqrange
2021-08-13 15:07 [PATCH 0/3] rcar-csi2: Improve link frequency selection Niklas Söderlund
@ 2021-08-13 15:07 ` Niklas Söderlund
2021-08-13 15:07 ` [PATCH 2/3] media: rcar-csi2: Add warning for PHY speed less than minimum Niklas Söderlund
2021-08-13 15:07 ` [PATCH 3/3] media: rcar-csi2: Optimize the selection PHTW register Niklas Söderlund
2 siblings, 0 replies; 4+ messages in thread
From: Niklas Söderlund @ 2021-08-13 15:07 UTC (permalink / raw)
To: Hans Verkuil, linux-media
Cc: Suresh Udipi, linux-renesas-soc, Niklas Söderlund
From: Suresh Udipi <sudipi@jp.adit-jv.com>
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 <sudipi@jp.adit-jv.com>
Signed-off-by: Kazuyoshi Akiyama <akiyama@nds-osk.co.jp>
Signed-off-by: Michael Rodin <mrodin@de.adit-jv.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
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;
--
2.32.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] media: rcar-csi2: Add warning for PHY speed less than minimum
2021-08-13 15:07 [PATCH 0/3] rcar-csi2: Improve link frequency selection Niklas Söderlund
2021-08-13 15:07 ` [PATCH 1/3] media: rcar-csi2: Correct the selection of hsfreqrange Niklas Söderlund
@ 2021-08-13 15:07 ` Niklas Söderlund
2021-08-13 15:07 ` [PATCH 3/3] media: rcar-csi2: Optimize the selection PHTW register Niklas Söderlund
2 siblings, 0 replies; 4+ messages in thread
From: Niklas Söderlund @ 2021-08-13 15:07 UTC (permalink / raw)
To: Hans Verkuil, linux-media
Cc: Suresh Udipi, linux-renesas-soc, Niklas Söderlund
From: Suresh Udipi <sudipi@jp.adit-jv.com>
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 <sudipi@jp.adit-jv.com>
Signed-off-by: Michael Rodin <mrodin@de.adit-jv.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
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;
--
2.32.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] media: rcar-csi2: Optimize the selection PHTW register
2021-08-13 15:07 [PATCH 0/3] rcar-csi2: Improve link frequency selection Niklas Söderlund
2021-08-13 15:07 ` [PATCH 1/3] media: rcar-csi2: Correct the selection of hsfreqrange Niklas Söderlund
2021-08-13 15:07 ` [PATCH 2/3] media: rcar-csi2: Add warning for PHY speed less than minimum Niklas Söderlund
@ 2021-08-13 15:07 ` Niklas Söderlund
2 siblings, 0 replies; 4+ messages in thread
From: Niklas Söderlund @ 2021-08-13 15:07 UTC (permalink / raw)
To: Hans Verkuil, linux-media
Cc: Suresh Udipi, linux-renesas-soc, Niklas Söderlund
From: Suresh Udipi <sudipi@jp.adit-jv.com>
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 <sudipi@jp.adit-jv.com>
Signed-off-by: Michael Rodin <mrodin@de.adit-jv.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
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);
--
2.32.0
^ permalink raw reply related [flat|nested] 4+ messages in thread