Skip to content

Commit 5b958ef

Browse files
6by9pelwell
authored andcommitted
media: imx219: Adjust PLL settings based on the number of MIPI lanes
Commit ceddfd4 ("media: i2c: imx219: Support four-lane operation") added support for device tree to allow configuration of the sensor to use 4 lanes with a link frequency of 363MHz, and amended the advertised pixel rate to 280.8MPix/s. However it didn't change any of the PLL settings, so actually it would have been running effectively overclocked in the MIPI block, and with the frame rate and exposure calculations being wrong. The pixel rate and link frequency advertised were taken from the "Clock Setting Example" section of the datasheet. However those are based on an external clock of 12MHz, and are unachievable with a clock of 24MHz (it seems PREPLLCLK_VT_DIV and PREPLLCK_OP_DIV can ONLY be set via the automatic configuration doumented in "9-1-2 EXCK_FREQ setting depend on INCK frequency). Dropping all support for the 363MHz link frequency would cause problems for existing users, so allow it from device tree, but log a warning that the requested value is not being truly applied. Fixes: ceddfd4 ("media: i2c: imx219: Support four-lane operation") Co-developed-by: Peyton Howe <peyton.howe@bellsouth.net> Signed-off-by: Peyton Howe <peyton.howe@bellsouth.net> Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
1 parent 545cb71 commit 5b958ef

File tree

1 file changed

+64
-19
lines changed

1 file changed

+64
-19
lines changed

drivers/media/i2c/imx219.c

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@
148148

149149
/* Pixel rate is fixed for all the modes */
150150
#define IMX219_PIXEL_RATE 182400000
151-
#define IMX219_PIXEL_RATE_4LANE 280800000
151+
#define IMX219_PIXEL_RATE_4LANE 281600000
152152

153153
#define IMX219_DEFAULT_LINK_FREQ 456000000
154-
#define IMX219_DEFAULT_LINK_FREQ_4LANE 363000000
154+
#define IMX219_DEFAULT_LINK_FREQ_4LANE_UNSUPPORTED 363000000
155+
#define IMX219_DEFAULT_LINK_FREQ_4LANE 364000000
155156

156157
/* IMX219 native and active pixel array size. */
157158
#define IMX219_NATIVE_WIDTH 3296U
@@ -224,15 +225,6 @@ static const struct cci_reg_sequence imx219_common_regs[] = {
224225
{ CCI_REG8(0x30eb), 0x05 },
225226
{ CCI_REG8(0x30eb), 0x09 },
226227

227-
/* PLL Clock Table */
228-
{ IMX219_REG_VTPXCK_DIV, 5 },
229-
{ IMX219_REG_VTSYCK_DIV, 1 },
230-
{ IMX219_REG_PREPLLCK_VT_DIV, 3 }, /* 0x03 = AUTO set */
231-
{ IMX219_REG_PREPLLCK_OP_DIV, 3 }, /* 0x03 = AUTO set */
232-
{ IMX219_REG_PLL_VT_MPY, 57 },
233-
{ IMX219_REG_OPSYCK_DIV, 1 },
234-
{ IMX219_REG_PLL_OP_MPY, 114 },
235-
236228
/* Undocumented registers */
237229
{ CCI_REG8(0x455e), 0x00 },
238230
{ CCI_REG8(0x471e), 0x4b },
@@ -316,6 +308,34 @@ static const struct cci_reg_sequence raw10_framefmt_regs[] = {
316308
{ IMX219_REG_OPPXCK_DIV, 10 },
317309
};
318310

311+
static const struct cci_reg_sequence imx219_2lane_regs[] = {
312+
/* PLL Clock Table */
313+
{ IMX219_REG_VTPXCK_DIV, 5 },
314+
{ IMX219_REG_VTSYCK_DIV, 1 },
315+
{ IMX219_REG_PREPLLCK_VT_DIV, 3 }, /* 0x03 = AUTO set */
316+
{ IMX219_REG_PREPLLCK_OP_DIV, 3 }, /* 0x03 = AUTO set */
317+
{ IMX219_REG_PLL_VT_MPY, 57 },
318+
{ IMX219_REG_OPSYCK_DIV, 1 },
319+
{ IMX219_REG_PLL_OP_MPY, 114 },
320+
321+
/* 2-Lane CSI Mode */
322+
{ IMX219_REG_CSI_LANE_MODE, IMX219_CSI_2_LANE_MODE },
323+
};
324+
325+
static const struct cci_reg_sequence imx219_4lane_regs[] = {
326+
/* PLL Clock Table */
327+
{ IMX219_REG_VTPXCK_DIV, 5 },
328+
{ IMX219_REG_VTSYCK_DIV, 1 },
329+
{ IMX219_REG_PREPLLCK_VT_DIV, 3 }, /* 0x03 = AUTO set */
330+
{ IMX219_REG_PREPLLCK_OP_DIV, 3 }, /* 0x03 = AUTO set */
331+
{ IMX219_REG_PLL_VT_MPY, 88 },
332+
{ IMX219_REG_OPSYCK_DIV, 1 },
333+
{ IMX219_REG_PLL_OP_MPY, 91 },
334+
335+
/* 4-Lane CSI Mode */
336+
{ IMX219_REG_CSI_LANE_MODE, IMX219_CSI_4_LANE_MODE },
337+
};
338+
319339
static const s64 imx219_link_freq_menu[] = {
320340
IMX219_DEFAULT_LINK_FREQ,
321341
};
@@ -941,9 +961,11 @@ static int imx219_get_selection(struct v4l2_subdev *sd,
941961

942962
static int imx219_configure_lanes(struct imx219 *imx219)
943963
{
944-
return cci_write(imx219->regmap, IMX219_REG_CSI_LANE_MODE,
945-
imx219->lanes == 2 ? IMX219_CSI_2_LANE_MODE :
946-
IMX219_CSI_4_LANE_MODE, NULL);
964+
/* Write the appropriate PLL settings for the number of MIPI lanes */
965+
return cci_multi_reg_write(imx219->regmap,
966+
imx219->lanes == 2 ? imx219_2lane_regs : imx219_4lane_regs,
967+
imx219->lanes == 2 ? ARRAY_SIZE(imx219_2lane_regs) :
968+
ARRAY_SIZE(imx219_4lane_regs), NULL);
947969
};
948970

949971
static int imx219_start_streaming(struct imx219 *imx219,
@@ -1334,6 +1356,7 @@ static int imx219_check_hwcfg(struct device *dev, struct imx219 *imx219)
13341356
.bus_type = V4L2_MBUS_CSI2_DPHY
13351357
};
13361358
int ret = -EINVAL;
1359+
bool link_frequency_valid = false;
13371360

13381361
endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
13391362
if (!endpoint) {
@@ -1360,11 +1383,33 @@ static int imx219_check_hwcfg(struct device *dev, struct imx219 *imx219)
13601383
goto error_out;
13611384
}
13621385

1363-
if (ep_cfg.nr_of_link_frequencies != 1 ||
1364-
(ep_cfg.link_frequencies[0] != ((imx219->lanes == 2) ?
1365-
IMX219_DEFAULT_LINK_FREQ : IMX219_DEFAULT_LINK_FREQ_4LANE))) {
1366-
dev_err(dev, "Link frequency not supported: %lld\n",
1367-
ep_cfg.link_frequencies[0]);
1386+
if (ep_cfg.nr_of_link_frequencies == 1) {
1387+
switch (imx219->lanes) {
1388+
case 2:
1389+
if (ep_cfg.link_frequencies[0] ==
1390+
IMX219_DEFAULT_LINK_FREQ)
1391+
link_frequency_valid = true;
1392+
break;
1393+
case 4:
1394+
if (ep_cfg.link_frequencies[0] ==
1395+
IMX219_DEFAULT_LINK_FREQ_4LANE)
1396+
link_frequency_valid = true;
1397+
else if (ep_cfg.link_frequencies[0] ==
1398+
IMX219_DEFAULT_LINK_FREQ_4LANE_UNSUPPORTED) {
1399+
dev_warn(dev, "Link frequency of %d not supported, but has been incorrectly advertised previously\n",
1400+
IMX219_DEFAULT_LINK_FREQ_4LANE_UNSUPPORTED);
1401+
dev_warn(dev, "Using link frequency of %d\n",
1402+
IMX219_DEFAULT_LINK_FREQ_4LANE);
1403+
link_frequency_valid = true;
1404+
}
1405+
break;
1406+
}
1407+
}
1408+
1409+
if (!link_frequency_valid) {
1410+
dev_err_probe(dev, -EINVAL,
1411+
"Link frequency not supported: %lld\n",
1412+
ep_cfg.link_frequencies[0]);
13681413
goto error_out;
13691414
}
13701415

0 commit comments

Comments
 (0)