From: Suresh Udipi <sudipi@jp.adit-jv.com>
To: <niklas.soderlund@ragnatech.se>
Cc: <akiyama@nds-osk.co.jp>, <efriedrich@de.adit-jv.com>,
<erosca@de.adit-jv.com>, <hverkuil-cisco@xs4all.nl>,
<jacopo+renesas@jmondi.org>, <laurent.pinchart@ideasonboard.com>,
<linux-kernel@vger.kernel.org>, <linux-media@vger.kernel.org>,
<linux-renesas-soc@vger.kernel.org>, <mrodin@de.adit-jv.com>,
<securitycheck@denso.co.jp>, <sudipi@jp.adit-jv.com>
Subject: [PATCH v2] [RFC] rcar-vin: rcar-csi2: Correct the selection of hsfreqrange
Date: Tue, 17 Mar 2020 16:08:25 +0900 [thread overview]
Message-ID: <1584428905-21560-1-git-send-email-sudipi@jp.adit-jv.com> (raw)
In-Reply-To: <20200316130247.GA2258968@oden.dyn.berto.se>
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.
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>
---
Changes in v2:
- Added the boundary check for the maximum bit rate.
- Simplified the logic by remmoving range check
as only the closest default value covers most
of the use cases.
- Aligning the commit message based on the above change
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 faa9fb2..6573625 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 },
@@ -431,16 +432,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
next prev parent reply other threads:[~2020-03-17 7:09 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-20 4:49 [PATCH] [RFC] media: rcar-csi2: Corrects the selection of hsfreqrange Suresh Udipi
2020-03-04 19:46 ` Niklas Söderlund
2020-03-16 13:02 ` Niklas Söderlund
2020-03-17 7:08 ` Suresh Udipi [this message]
2020-03-17 10:37 ` [PATCH v2] [RFC] rcar-vin: rcar-csi2: Correct " Niklas Söderlund
2020-03-18 9:00 ` Suresh Udipi
2020-03-18 10:19 ` Niklas Söderlund
2020-03-20 8:00 ` [PATCH v3] media: " Suresh Udipi
2020-03-23 4:48 ` [PATCH v4] " Suresh Udipi
2020-04-14 11:56 ` Niklas Söderlund
2020-04-30 6:03 ` [PATCH v5] " Suresh Udipi
2020-05-04 15:01 ` Michael Rodin
2020-05-12 21:30 ` Niklas Söderlund
2020-05-27 15:47 ` Michael Rodin
2020-05-27 16:16 ` [PATCH] rcar-vin: " Michael Rodin
2020-06-05 18:44 ` Michael Rodin
2020-06-08 3:25 ` [PATCH v6] media: " Suresh Udipi
2020-06-10 13:40 ` Niklas Söderlund
2020-06-12 3:10 ` Suresh Udipi
2020-06-12 17:28 ` Michael Rodin
2020-06-15 14:11 ` Niklas Söderlund
2020-06-17 4:57 ` [PATCH v7 1/2] " Suresh Udipi
2020-06-17 4:57 ` [PATCH v7 2/2] media: rcar-csi2: Add warning for PHY speed less than minimum Suresh Udipi
2020-06-17 13:37 ` [PATCH v7 1/2] media: rcar-csi2: Correct the selection of hsfreqrange Michael Rodin
2020-06-18 10:34 ` [PATCH v8 1/3] " Suresh Udipi
2020-06-18 10:34 ` [PATCH v8 2/3] media: rcar-csi2: Add warning for PHY speed less than minimum Suresh Udipi
2020-06-30 22:05 ` Niklas Söderlund
2020-06-18 10:34 ` [PATCH v8 3/3] media: rcar-csi2: Optimize the selection PHTW register Suresh Udipi
2020-06-30 22:08 ` Niklas Söderlund
2020-07-01 9:52 ` [PATCH v9 1/3] media: rcar-csi2: Correct the selection of hsfreqrange Suresh Udipi
2020-07-01 9:53 ` [PATCH v9 2/3] media: rcar-csi2: Add warning for PHY speed less than minimum Suresh Udipi
2020-07-01 9:53 ` [PATCH v9 3/3] media: rcar-csi2: Optimize the selection PHTW register Suresh Udipi
2020-06-30 22:03 ` [PATCH v8 1/3] media: rcar-csi2: Correct the selection of hsfreqrange Niklas Söderlund
2020-05-27 16:17 ` [PATCH] rcar-vin: rcar-csi2: Select the correct PHTW register Michael Rodin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1584428905-21560-1-git-send-email-sudipi@jp.adit-jv.com \
--to=sudipi@jp.adit-jv.com \
--cc=akiyama@nds-osk.co.jp \
--cc=efriedrich@de.adit-jv.com \
--cc=erosca@de.adit-jv.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=jacopo+renesas@jmondi.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=mrodin@de.adit-jv.com \
--cc=niklas.soderlund@ragnatech.se \
--cc=securitycheck@denso.co.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).