From: Maxime Ripard <maxime.ripard@bootlin.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
linux-media@vger.kernel.org,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
Mylene Josserand <mylene.josserand@bootlin.com>,
Hans Verkuil <hans.verkuil@cisco.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Hugues Fruchet <hugues.fruchet@st.com>,
Maxime Ripard <maxime.ripard@bootlin.com>
Subject: [PATCH v2 09/12] media: ov5640: Compute the clock rate at runtime
Date: Mon, 16 Apr 2018 14:36:58 +0200 [thread overview]
Message-ID: <20180416123701.15901-10-maxime.ripard@bootlin.com> (raw)
In-Reply-To: <20180416123701.15901-1-maxime.ripard@bootlin.com>
The clock rate, while hardcoded until now, is actually a function of the
resolution, framerate and bytes per pixel. Now that we have an algorithm to
adjust our clock rate, we can select it dynamically when we change the
mode.
This changes a bit the clock rate being used, with the following effect:
+------+------+------+------+-----+-----------------+----------------+-----------+
| Hact | Vact | Htot | Vtot | FPS | Hardcoded clock | Computed clock | Deviation |
+------+------+------+------+-----+-----------------+----------------+-----------+
| 640 | 480 | 1896 | 1080 | 15 | 56000000 | 61430400 | 8.84 % |
| 640 | 480 | 1896 | 1080 | 30 | 112000000 | 122860800 | 8.84 % |
| 1024 | 768 | 1896 | 1080 | 15 | 56000000 | 61430400 | 8.84 % |
| 1024 | 768 | 1896 | 1080 | 30 | 112000000 | 122860800 | 8.84 % |
| 320 | 240 | 1896 | 984 | 15 | 56000000 | 55969920 | 0.05 % |
| 320 | 240 | 1896 | 984 | 30 | 112000000 | 111939840 | 0.05 % |
| 176 | 144 | 1896 | 984 | 15 | 56000000 | 55969920 | 0.05 % |
| 176 | 144 | 1896 | 984 | 30 | 112000000 | 111939840 | 0.05 % |
| 720 | 480 | 1896 | 984 | 15 | 56000000 | 55969920 | 0.05 % |
| 720 | 480 | 1896 | 984 | 30 | 112000000 | 111939840 | 0.05 % |
| 720 | 576 | 1896 | 984 | 15 | 56000000 | 55969920 | 0.05 % |
| 720 | 576 | 1896 | 984 | 30 | 112000000 | 111939840 | 0.05 % |
| 1280 | 720 | 1892 | 740 | 15 | 42000000 | 42002400 | 0.01 % |
| 1280 | 720 | 1892 | 740 | 30 | 84000000 | 84004800 | 0.01 % |
| 1920 | 1080 | 2500 | 1120 | 15 | 84000000 | 84000000 | 0.00 % |
| 1920 | 1080 | 2500 | 1120 | 30 | 168000000 | 168000000 | 0.00 % |
| 2592 | 1944 | 2844 | 1944 | 15 | 84000000 | 165862080 | 49.36 % |
+------+------+------+------+-----+-----------------+----------------+-----------+
Only the 640x480, 1024x768 and 2592x1944 modes are significantly affected
by the new formula.
In this case, 640x480 and 1024x768 are actually fixed by this driver.
Indeed, the sensor was sending data at, for example, 27.33fps instead of
30fps. This is -9%, which is roughly what we're seeing in the array.
Testing these modes with the new clock setup actually fix that error, and
data are now sent at around 30fps.
2592x1944, on the other hand, is probably due to the fact that this mode
can only be used using MIPI-CSI2, in a two lane mode. This would have to be
tested though.
Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
---
drivers/media/i2c/ov5640.c | 41 ++++++++++++++++----------------------
1 file changed, 17 insertions(+), 24 deletions(-)
diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index 8db4fc0f031c..62938e9dabc5 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -174,7 +174,6 @@ struct ov5640_mode_info {
u32 htot;
u32 vact;
u32 vtot;
- u32 clock;
const struct reg_value *reg_data;
u32 reg_data_size;
};
@@ -696,7 +695,6 @@ static const struct reg_value ov5640_setting_15fps_QSXGA_2592_1944[] = {
/* power-on sensor init reg table */
static const struct ov5640_mode_info ov5640_mode_init_data = {
0, SUBSAMPLING, 640, 1896, 480, 984,
- 112000000,
ov5640_init_setting_30fps_VGA,
ARRAY_SIZE(ov5640_init_setting_30fps_VGA),
};
@@ -706,91 +704,74 @@ ov5640_mode_data[OV5640_NUM_FRAMERATES][OV5640_NUM_MODES] = {
{
{OV5640_MODE_QCIF_176_144, SUBSAMPLING,
176, 1896, 144, 984,
- 56000000,
ov5640_setting_15fps_QCIF_176_144,
ARRAY_SIZE(ov5640_setting_15fps_QCIF_176_144)},
{OV5640_MODE_QVGA_320_240, SUBSAMPLING,
320, 1896, 240, 984,
- 56000000,
ov5640_setting_15fps_QVGA_320_240,
ARRAY_SIZE(ov5640_setting_15fps_QVGA_320_240)},
{OV5640_MODE_VGA_640_480, SUBSAMPLING,
640, 1896, 480, 1080,
- 56000000,
ov5640_setting_15fps_VGA_640_480,
ARRAY_SIZE(ov5640_setting_15fps_VGA_640_480)},
{OV5640_MODE_NTSC_720_480, SUBSAMPLING,
720, 1896, 480, 984,
- 56000000,
ov5640_setting_15fps_NTSC_720_480,
ARRAY_SIZE(ov5640_setting_15fps_NTSC_720_480)},
{OV5640_MODE_PAL_720_576, SUBSAMPLING,
720, 1896, 576, 984,
- 56000000,
ov5640_setting_15fps_PAL_720_576,
ARRAY_SIZE(ov5640_setting_15fps_PAL_720_576)},
{OV5640_MODE_XGA_1024_768, SUBSAMPLING,
1024, 1896, 768, 1080,
- 56000000,
ov5640_setting_15fps_XGA_1024_768,
ARRAY_SIZE(ov5640_setting_15fps_XGA_1024_768)},
{OV5640_MODE_720P_1280_720, SUBSAMPLING,
1280, 1892, 720, 740,
- 42000000,
ov5640_setting_15fps_720P_1280_720,
ARRAY_SIZE(ov5640_setting_15fps_720P_1280_720)},
{OV5640_MODE_1080P_1920_1080, SCALING,
1920, 2500, 1080, 1120,
- 84000000,
ov5640_setting_15fps_1080P_1920_1080,
ARRAY_SIZE(ov5640_setting_15fps_1080P_1920_1080)},
{OV5640_MODE_QSXGA_2592_1944, SCALING,
2592, 2844, 1944, 1968,
- 168000000,
ov5640_setting_15fps_QSXGA_2592_1944,
ARRAY_SIZE(ov5640_setting_15fps_QSXGA_2592_1944)},
}, {
{OV5640_MODE_QCIF_176_144, SUBSAMPLING,
176, 1896, 144, 984,
- 112000000,
ov5640_setting_30fps_QCIF_176_144,
ARRAY_SIZE(ov5640_setting_30fps_QCIF_176_144)},
{OV5640_MODE_QVGA_320_240, SUBSAMPLING,
320, 1896, 240, 984,
- 112000000,
ov5640_setting_30fps_QVGA_320_240,
ARRAY_SIZE(ov5640_setting_30fps_QVGA_320_240)},
{OV5640_MODE_VGA_640_480, SUBSAMPLING,
640, 1896, 480, 1080,
- 112000000,
ov5640_setting_30fps_VGA_640_480,
ARRAY_SIZE(ov5640_setting_30fps_VGA_640_480)},
{OV5640_MODE_NTSC_720_480, SUBSAMPLING,
720, 1896, 480, 984,
- 112000000,
ov5640_setting_30fps_NTSC_720_480,
ARRAY_SIZE(ov5640_setting_30fps_NTSC_720_480)},
{OV5640_MODE_PAL_720_576, SUBSAMPLING,
720, 1896, 576, 984,
- 112000000,
ov5640_setting_30fps_PAL_720_576,
ARRAY_SIZE(ov5640_setting_30fps_PAL_720_576)},
{OV5640_MODE_XGA_1024_768, SUBSAMPLING,
1024, 1896, 768, 1080,
- 112000000,
ov5640_setting_30fps_XGA_1024_768,
ARRAY_SIZE(ov5640_setting_30fps_XGA_1024_768)},
{OV5640_MODE_720P_1280_720, SUBSAMPLING,
1280, 1892, 720, 740,
- 84000000,
ov5640_setting_30fps_720P_1280_720,
ARRAY_SIZE(ov5640_setting_30fps_720P_1280_720)},
{OV5640_MODE_1080P_1920_1080, SCALING,
1920, 2500, 1080, 1120,
- 168000000,
ov5640_setting_30fps_1080P_1920_1080,
ARRAY_SIZE(ov5640_setting_30fps_1080P_1920_1080)},
- {OV5640_MODE_QSXGA_2592_1944, -1, 0, 0, 0, 0, 0, NULL, 0},
+ {OV5640_MODE_QSXGA_2592_1944, -1, 0, 0, 0, 0, NULL, 0},
},
};
@@ -1814,6 +1795,8 @@ static int ov5640_set_mode(struct ov5640_dev *sensor,
{
const struct ov5640_mode_info *mode = sensor->current_mode;
enum ov5640_downsize_mode dn_mode, orig_dn_mode;
+ unsigned long rate;
+ unsigned char bpp;
s32 exposure;
int ret;
@@ -1830,10 +1813,20 @@ static int ov5640_set_mode(struct ov5640_dev *sensor,
if (ret)
return ret;
- if (sensor->ep.bus_type == V4L2_MBUS_CSI2)
- ret = ov5640_set_mipi_pclk(sensor, mode->clock);
- else
- ret = ov5640_set_dvp_pclk(sensor, mode->clock);
+ /*
+ * All the formats we support have 2 bytes per pixel, except for JPEG
+ * which is 1 byte per pixel.
+ */
+ bpp = sensor->fmt.code == MEDIA_BUS_FMT_JPEG_1X8 ? 1 : 2;
+ rate = mode->vtot * mode->htot * bpp;
+ rate *= ov5640_framerates[sensor->current_fr];
+
+ if (sensor->ep.bus_type == V4L2_MBUS_CSI2) {
+ rate = rate / sensor->ep.bus.mipi_csi2.num_data_lanes;
+ ret = ov5640_set_mipi_pclk(sensor, rate);
+ } else {
+ ret = ov5640_set_dvp_pclk(sensor, rate);
+ }
if (ret < 0)
return 0;
--
2.17.0
next prev parent reply other threads:[~2018-04-16 12:37 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-16 12:36 [PATCH v2 00/12] media: ov5640: Misc cleanup and improvements Maxime Ripard
2018-04-16 12:36 ` [PATCH v2 01/12] media: ov5640: Add auto-focus feature Maxime Ripard
2018-04-19 10:36 ` Laurent Pinchart
2018-04-20 19:10 ` Maxime Ripard
2018-04-16 12:36 ` [PATCH v2 02/12] media: ov5640: Add light frequency control Maxime Ripard
2018-04-19 9:44 ` Laurent Pinchart
2018-04-20 19:04 ` Maxime Ripard
2018-04-24 11:55 ` Sakari Ailus
2018-04-16 12:36 ` [PATCH v2 03/12] media: ov5640: Don't force the auto exposure state at start time Maxime Ripard
2018-04-16 12:36 ` [PATCH v2 04/12] media: ov5640: Init properly the SCLK dividers Maxime Ripard
2018-04-16 12:36 ` [PATCH v2 05/12] media: ov5640: Change horizontal and vertical resolutions name Maxime Ripard
2018-04-16 12:36 ` [PATCH v2 06/12] media: ov5640: Add horizontal and vertical totals Maxime Ripard
2018-04-16 12:36 ` [PATCH v2 07/12] media: ov5640: Program the visible resolution Maxime Ripard
2018-04-16 12:36 ` [PATCH v2 08/12] media: ov5640: Adjust the clock based on the expected rate Maxime Ripard
2018-04-24 7:21 ` Sakari Ailus
2018-04-24 19:36 ` Maxime Ripard
2018-05-02 21:44 ` Sakari Ailus
2018-04-16 12:36 ` Maxime Ripard [this message]
2018-04-16 12:36 ` [PATCH v2 10/12] media: ov5640: Enhance FPS handling Maxime Ripard
2018-04-16 12:37 ` [PATCH v2 11/12] media: ov5640: Add 60 fps support Maxime Ripard
2018-05-15 13:33 ` Hugues FRUCHET
2018-05-17 8:52 ` Maxime Ripard
2018-05-17 13:29 ` Hugues FRUCHET
2018-05-18 9:05 ` Maxime Ripard
2018-04-16 12:37 ` [PATCH v2 12/12] media: ov5640: Remove duplicate auto-exposure setup Maxime Ripard
2018-04-16 23:22 ` [PATCH v2 00/12] media: ov5640: Misc cleanup and improvements Samuel Bobrowicz
2018-04-17 16:01 ` Maxime Ripard
2018-04-18 23:39 ` Samuel Bobrowicz
2018-04-19 12:32 ` Maxime Ripard
2018-04-24 22:11 ` Sam Bobrowicz
2018-04-25 19:53 ` Maxime Ripard
2018-04-27 9:27 ` Laurent Pinchart
2018-05-02 18:11 ` Sam Bobrowicz
2018-05-03 15:16 ` Maxime Ripard
2018-05-04 10:01 ` Loic Poulain
2018-05-04 21:13 ` Sam Bobrowicz
2018-05-07 8:10 ` Maxime Ripard
2018-05-04 7:26 ` Loic Poulain
2018-05-04 21:26 ` Sam Bobrowicz
2018-05-08 1:00 ` Sam Bobrowicz
2018-05-17 8:50 ` Maxime Ripard
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=20180416123701.15901-10-maxime.ripard@bootlin.com \
--to=maxime.ripard@bootlin.com \
--cc=hans.verkuil@cisco.com \
--cc=hugues.fruchet@st.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=mylene.josserand@bootlin.com \
--cc=sakari.ailus@linux.intel.com \
--cc=thomas.petazzoni@bootlin.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.