From: Hans de Goede <hansg@kernel.org>
To: Sakari Ailus <sakari.ailus@linux.intel.com>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Hans de Goede <hansg@kernel.org>,
Mathis Foerst <mathis.foerst@mt.com>,
linux-media@vger.kernel.org
Subject: [PATCH v3 03/15] media: mt9m114: Use aptina-PLL helper to get PLL values
Date: Sun, 29 Jun 2025 22:56:13 +0200 [thread overview]
Message-ID: <20250629205626.68341-4-hansg@kernel.org> (raw)
In-Reply-To: <20250629205626.68341-1-hansg@kernel.org>
Before this change the driver used hardcoded PLL m, n and p values to
achieve a 48MHz pixclock when used with an external clock with a frequency
of 24 MHz.
Use aptina_pll_calculate() to allow the driver to work with different
external clock frequencies. The m, n, and p values will be unchanged
with a 24 MHz extclk and this has also been tested with a 19.2 MHz
clock where m gets increased from 32 to 40.
Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Hans de Goede <hansg@kernel.org>
---
Changes in v3:
- Document that using 768Mhz for out_clock_max does not work
Changes in v2:
- Add select VIDEO_APTINA_PLL to Kconfig
- Use correct aptina_pll_limits
---
drivers/media/i2c/Kconfig | 1 +
drivers/media/i2c/mt9m114.c | 55 +++++++++++++++++++++++++++----------
2 files changed, 41 insertions(+), 15 deletions(-)
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 0b58197471ae..75674bc40107 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -295,6 +295,7 @@ config VIDEO_MT9M111
config VIDEO_MT9M114
tristate "onsemi MT9M114 sensor support"
select V4L2_CCI_I2C
+ select VIDEO_APTINA_PLL
help
This is a Video4Linux2 sensor-level driver for the onsemi MT9M114
camera.
diff --git a/drivers/media/i2c/mt9m114.c b/drivers/media/i2c/mt9m114.c
index 5a7c45ce2169..9e703012cb0e 100644
--- a/drivers/media/i2c/mt9m114.c
+++ b/drivers/media/i2c/mt9m114.c
@@ -31,6 +31,8 @@
#include <media/v4l2-mediabus.h>
#include <media/v4l2-subdev.h>
+#include "aptina-pll.h"
+
/* Sysctl registers */
#define MT9M114_CHIP_ID CCI_REG16(0x0000)
#define MT9M114_COMMAND_REGISTER CCI_REG16(0x0080)
@@ -263,9 +265,9 @@
#define MT9M114_CAM_SYSCTL_PLL_ENABLE_VALUE BIT(0)
#define MT9M114_CAM_SYSCTL_PLL_DISABLE_VALUE 0x00
#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_M_N CCI_REG16(0xc980)
-#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_VALUE(m, n) (((n) << 8) | (m))
+#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_VALUE(m, n) ((((n) - 1) << 8) | (m))
#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_P CCI_REG16(0xc982)
-#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE(p) ((p) << 8)
+#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE(p) (((p) - 1) << 8)
#define MT9M114_CAM_PORT_OUTPUT_CONTROL CCI_REG16(0xc984)
#define MT9M114_CAM_PORT_PORT_SELECT_PARALLEL (0 << 0)
#define MT9M114_CAM_PORT_PORT_SELECT_MIPI (1 << 0)
@@ -326,7 +328,7 @@
* minimum values that have been seen in register lists are 303 and 38, use
* them.
*
- * Set the default to achieve 1280x960 at 30fps.
+ * Set the default to achieve 1280x960 at 30fps with a 48 MHz pixclock.
*/
#define MT9M114_MIN_HBLANK 303
#define MT9M114_MIN_VBLANK 38
@@ -336,6 +338,8 @@
#define MT9M114_DEF_FRAME_RATE 30
#define MT9M114_MAX_FRAME_RATE 120
+#define MT9M114_DEF_PIXCLOCK 48000000
+
#define MT9M114_PIXEL_ARRAY_WIDTH 1296U
#define MT9M114_PIXEL_ARRAY_HEIGHT 976U
@@ -380,11 +384,7 @@ struct mt9m114 {
struct v4l2_fwnode_endpoint bus_cfg;
bool bypass_pll;
- struct {
- unsigned int m;
- unsigned int n;
- unsigned int p;
- } pll;
+ struct aptina_pll pll;
unsigned int pixrate;
bool streaming;
@@ -757,7 +757,7 @@ static int mt9m114_initialize(struct mt9m114 *sensor)
sensor->pll.n),
&ret);
cci_write(sensor->regmap, MT9M114_CAM_SYSCTL_PLL_DIVIDER_P,
- MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE(sensor->pll.p),
+ MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE(sensor->pll.p1),
&ret);
}
@@ -2262,12 +2262,30 @@ static int mt9m114_verify_link_frequency(struct mt9m114 *sensor,
static int mt9m114_clk_init(struct mt9m114 *sensor)
{
+ static const struct aptina_pll_limits limits = {
+ .ext_clock_min = 6000000,
+ .ext_clock_max = 54000000,
+ /* int_clock_* limits are not documented taken from mt9p031.c */
+ .int_clock_min = 2000000,
+ .int_clock_max = 13500000,
+ /*
+ * out_clock_min is not documented, taken from mt9p031.c.
+ * out_clock_max is documented as 768MHz, but this leads to
+ * a non working setup. Use 400MHz instead which results in
+ * the same PLL settings as used by the vendor's drivers.
+ */
+ .out_clock_min = 180000000,
+ .out_clock_max = 400000000,
+ .pix_clock_max = 48000000,
+ .n_min = 1,
+ .n_max = 64,
+ .m_min = 16,
+ .m_max = 192,
+ .p1_min = 1,
+ .p1_max = 64,
+ };
unsigned int pixrate;
-
- /* Hardcode the PLL multiplier and dividers to default settings. */
- sensor->pll.m = 32;
- sensor->pll.n = 1;
- sensor->pll.p = 7;
+ int ret;
/*
* Calculate the pixel rate and link frequency. The CSI-2 bus is clocked
@@ -2287,8 +2305,15 @@ static int mt9m114_clk_init(struct mt9m114 *sensor)
}
/* Check if the PLL configuration fits the configured link frequency. */
+ sensor->pll.ext_clock = sensor->clk_freq;
+ sensor->pll.pix_clock = MT9M114_DEF_PIXCLOCK;
+
+ ret = aptina_pll_calculate(&sensor->client->dev, &limits, &sensor->pll);
+ if (ret)
+ return ret;
+
pixrate = sensor->clk_freq * sensor->pll.m
- / ((sensor->pll.n + 1) * (sensor->pll.p + 1));
+ / (sensor->pll.n * sensor->pll.p1);
if (mt9m114_verify_link_frequency(sensor, pixrate) == 0) {
sensor->pixrate = pixrate;
sensor->bypass_pll = false;
--
2.49.0
next prev parent reply other threads:[~2025-06-29 20:56 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-29 20:56 [PATCH v3 00/15] media: mt9m114: Changes to make it work with atomisp devices Hans de Goede
2025-06-29 20:56 ` [PATCH v3 01/15] media: aptina-pll: Debug log p1 min and max values Hans de Goede
2025-06-29 20:56 ` [PATCH v3 02/15] media: mt9m114: Add support for clock-frequency property Hans de Goede
2025-06-29 20:56 ` Hans de Goede [this message]
2025-06-29 20:56 ` [PATCH v3 04/15] media: mt9m114: Lower minimum vblank value Hans de Goede
2025-06-29 20:56 ` [PATCH v3 05/15] media: mt9m114: Fix default hblank and vblank values Hans de Goede
2025-06-29 20:56 ` [PATCH v3 06/15] media: mt9m114: Tweak default hblank and vblank for more accurate fps Hans de Goede
2025-06-29 20:56 ` [PATCH v3 07/15] media: mt9m114: Avoid a reset low spike during probe() Hans de Goede
2025-06-29 20:56 ` [PATCH v3 08/15] media: mt9m114: Put sensor in reset on power down Hans de Goede
2025-06-29 20:56 ` [PATCH v3 09/15] media: mt9m114: Add and use mt9m114_ifp_get_border() helper function Hans de Goede
2025-07-02 0:17 ` Laurent Pinchart
2025-06-29 20:56 ` [PATCH v3 10/15] media: mt9m114: Adjust IFP selections and src format when src pixelfmt changes to/from RAW10 Hans de Goede
2025-07-02 0:32 ` Laurent Pinchart
2025-12-23 13:33 ` Hans de Goede
2025-06-29 20:56 ` [PATCH v3 11/15] media: mt9m114: Update src pad sel and format when sink pad format changes Hans de Goede
2025-07-02 0:36 ` Laurent Pinchart
2025-06-29 20:56 ` [PATCH v3 12/15] media: mt9m114: Don't allow changing the IFP crop/compose selections when bypassing the scaler Hans de Goede
2025-07-02 0:42 ` Laurent Pinchart
2025-06-29 20:56 ` [PATCH v3 13/15] media: mt9m114: Drop start-, stop-streaming sequence from initialize Hans de Goede
2025-07-02 1:08 ` Laurent Pinchart
2025-12-23 13:37 ` Hans de Goede
2025-12-23 16:50 ` Laurent Pinchart
2025-12-23 16:57 ` Hans de Goede
2025-06-29 20:56 ` [PATCH v3 14/15] media: mt9m114: Return -EPROBE_DEFER if no endpoint is found Hans de Goede
2025-07-02 0:53 ` Laurent Pinchart
2025-12-24 12:12 ` Hans de Goede
2025-12-27 14:54 ` Laurent Pinchart
2025-06-29 20:56 ` [PATCH v3 15/15] media: mt9m114: Add ACPI enumeration support Hans de Goede
[not found] ` <6861b00f.050a0220.379e4a.5185@mx.google.com>
2025-06-30 7:34 ` [v3,00/15] media: mt9m114: Changes to make it work with atomisp devices Hans de Goede
2025-06-30 22:28 ` [PATCH v3 00/15] " Laurent Pinchart
2025-07-01 13:21 ` Hans de Goede
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=20250629205626.68341-4-hansg@kernel.org \
--to=hansg@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=mathis.foerst@mt.com \
--cc=sakari.ailus@linux.intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox