mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] media: mt9v032: Improvements from PHYTEC
@ 2026-10-09 10:28 Primoz Fiser
  2026-10-09 10:28 ` [PATCH 1/3] media: mt9v032: Support color format selection Primoz Fiser
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Primoz Fiser @ 2026-10-09 10:28 UTC (permalink / raw)
  To: Laurent Pinchart, Sakari Ailus, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, upstream

Add PHYTEC improvements for the Aptina mt9v032 sensor used on their
VM010 phyCAM modules.

Christian Hemp (1):
  media: mt9v032: Support color format selection

Jan Luebbe (1):
  media: mt9v032: Add control for row noise correction

Stefan Riedmüller (1):
  media: mt9v032: Add get_mbus_config subdev_pad_ops callback

 drivers/media/i2c/mt9v032.c | 95 +++++++++++++++++++++++++++++++------
 1 file changed, 80 insertions(+), 15 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] media: mt9v032: Support color format selection
  2026-10-09 10:28 [PATCH 0/3] media: mt9v032: Improvements from PHYTEC Primoz Fiser
@ 2026-10-09 10:28 ` Primoz Fiser
  2026-10-09 10:28 ` [PATCH 2/3] media: mt9v032: Add control for row noise correction Primoz Fiser
  2026-10-09 10:28 ` [PATCH 3/3] media: mt9v032: Add get_mbus_config subdev_pad_ops callback Primoz Fiser
  2 siblings, 0 replies; 4+ messages in thread
From: Primoz Fiser @ 2026-10-09 10:28 UTC (permalink / raw)
  To: Laurent Pinchart, Sakari Ailus, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, upstream

From: Christian Hemp <c.hemp@phytec.de>

The driver only ever exposed one fixed mbus code per sensor variant
(MEDIA_BUS_FMT_SGRBG10_1X10 for color, MEDIA_BUS_FMT_Y10_1X10 for
monochrome): enum_mbus_code() rejected any index > 0, and set_format()
ignored the requested code entirely.

Add per-variant format tables (8-bit and 10-bit Bayer/greyscale) and a
mt9v032_find_datafmt() helper, so userspace can actually select the
pixel format via the standard subdev pad ops instead of being limited
to the single hardcoded 10-bit default.

Signed-off-by: Christian Hemp <c.hemp@phytec.de>
Signed-off-by: Primoz Fiser <primoz.fiser@norik.com>
---
 drivers/media/i2c/mt9v032.c | 47 +++++++++++++++++++++++++++++--------
 1 file changed, 37 insertions(+), 10 deletions(-)

diff --git a/drivers/media/i2c/mt9v032.c b/drivers/media/i2c/mt9v032.c
index 29823378f0c7..5da10fe42552 100644
--- a/drivers/media/i2c/mt9v032.c
+++ b/drivers/media/i2c/mt9v032.c
@@ -187,6 +187,16 @@ struct mt9v032_platform_data {
 	s64 link_def_freq;
 };
 
+static const u32 mt9v032_color_fmts[] = {
+	MEDIA_BUS_FMT_SGRBG8_1X8,
+	MEDIA_BUS_FMT_SGRBG10_1X10,
+};
+
+static const u32 mt9v032_monochrome_fmts[] = {
+	MEDIA_BUS_FMT_Y8_1X8,
+	MEDIA_BUS_FMT_Y10_1X10,
+};
+
 struct mt9v032 {
 	struct device *dev;
 
@@ -215,6 +225,8 @@ struct mt9v032 {
 	struct mt9v032_platform_data pdata;
 	const struct mt9v032_model_info *model;
 	const struct mt9v032_model_version *version;
+	const u32 *fmts;
+	int num_fmts;
 
 	u32 sysclk;
 	u16 aec_agc;
@@ -434,16 +446,28 @@ static int mt9v032_s_stream(struct v4l2_subdev *subdev, int enable)
 	return regmap_update_bits(map, MT9V032_CHIP_CONTROL, mode, mode);
 }
 
+static u32 mt9v032_find_datafmt(struct mt9v032 *mt9v032, u32 code)
+{
+	const u32 *fmt = mt9v032->fmts;
+	int i;
+
+	for (i = 0; i < mt9v032->num_fmts; i++)
+		if (fmt[i] == code)
+			return fmt[i];
+
+	return fmt[mt9v032->num_fmts - 1];
+}
+
 static int mt9v032_enum_mbus_code(struct v4l2_subdev *subdev,
 				  struct v4l2_subdev_state *sd_state,
 				  struct v4l2_subdev_mbus_code_enum *code)
 {
 	struct mt9v032 *mt9v032 = to_mt9v032(subdev);
 
-	if (code->index > 0)
+	if (code->index >= mt9v032->num_fmts)
 		return -EINVAL;
 
-	code->code = mt9v032->format.code;
+	code->code = mt9v032->fmts[code->index];
 	return 0;
 }
 
@@ -535,6 +559,8 @@ static int mt9v032_set_format(struct v4l2_subdev *subdev,
 	__format->width = __crop->width / hratio;
 	__format->height = __crop->height / vratio;
 
+	__format->code = mt9v032_find_datafmt(mt9v032, format->format.code);
+
 	if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
 		mt9v032->hratio = hratio;
 		mt9v032->vratio = vratio;
@@ -946,10 +972,7 @@ static int mt9v032_open(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)
 
 	format = v4l2_subdev_state_get_format(fh->state, 0);
 
-	if (mt9v032->model->color)
-		format->code = MEDIA_BUS_FMT_SGRBG10_1X10;
-	else
-		format->code = MEDIA_BUS_FMT_Y10_1X10;
+	format->code = mt9v032_find_datafmt(mt9v032, 0);
 
 	format->width = MT9V032_WINDOW_WIDTH_DEF;
 	format->height = MT9V032_WINDOW_HEIGHT_DEF;
@@ -1157,10 +1180,14 @@ static int mt9v032_probe(struct i2c_client *client)
 	mt9v032->crop.width = MT9V032_WINDOW_WIDTH_DEF;
 	mt9v032->crop.height = MT9V032_WINDOW_HEIGHT_DEF;
 
-	if (mt9v032->model->color)
-		mt9v032->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
-	else
-		mt9v032->format.code = MEDIA_BUS_FMT_Y10_1X10;
+	if (mt9v032->model->color) {
+		mt9v032->fmts = mt9v032_color_fmts;
+		mt9v032->num_fmts = ARRAY_SIZE(mt9v032_color_fmts);
+	} else {
+		mt9v032->fmts = mt9v032_monochrome_fmts;
+		mt9v032->num_fmts = ARRAY_SIZE(mt9v032_monochrome_fmts);
+	}
+	mt9v032->format.code = mt9v032_find_datafmt(mt9v032, 0);
 
 	mt9v032->format.width = MT9V032_WINDOW_WIDTH_DEF;
 	mt9v032->format.height = MT9V032_WINDOW_HEIGHT_DEF;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] media: mt9v032: Add control for row noise correction
  2026-10-09 10:28 [PATCH 0/3] media: mt9v032: Improvements from PHYTEC Primoz Fiser
  2026-10-09 10:28 ` [PATCH 1/3] media: mt9v032: Support color format selection Primoz Fiser
@ 2026-10-09 10:28 ` Primoz Fiser
  2026-10-09 10:28 ` [PATCH 3/3] media: mt9v032: Add get_mbus_config subdev_pad_ops callback Primoz Fiser
  2 siblings, 0 replies; 4+ messages in thread
From: Primoz Fiser @ 2026-10-09 10:28 UTC (permalink / raw)
  To: Laurent Pinchart, Sakari Ailus, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, upstream

From: Jan Luebbe <jlu@pengutronix.de>

The sensor's row noise correction algorithm was previously always
disabled by unconditionally writing 0 to MT9V032_ROW_NOISE_CORR_CONTROL,
with no way for userspace to enable it.

Add a V4L2_CID_ROW_NOISE_CORRECTION boolean control so userspace can
toggle the model-specific enable value (MT9V032_ROW_NOISE_CORR_ENABLE /
MT9V034_ROW_NOISE_CORR_ENABLE) at runtime. Default to disabled to
preserve existing behaviour.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
Signed-off-by: Primoz Fiser <primoz.fiser@norik.com>
---
 drivers/media/i2c/mt9v032.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/drivers/media/i2c/mt9v032.c b/drivers/media/i2c/mt9v032.c
index 5da10fe42552..d8e34e128d77 100644
--- a/drivers/media/i2c/mt9v032.c
+++ b/drivers/media/i2c/mt9v032.c
@@ -167,6 +167,7 @@ struct mt9v032_model_data {
 	unsigned int pclk_reg;
 	unsigned int aec_max_shutter_reg;
 	const struct v4l2_ctrl_config * const aec_max_shutter_v4l2_ctrl;
+	unsigned int row_noise_enable;
 };
 
 struct mt9v032_model_info {
@@ -231,6 +232,7 @@ struct mt9v032 {
 	u32 sysclk;
 	u16 aec_agc;
 	u16 hblank;
+	bool row_noise_corr;
 	struct {
 		struct v4l2_ctrl *test_pattern;
 		struct v4l2_ctrl *test_pattern_color;
@@ -356,11 +358,6 @@ static int __mt9v032_set_power(struct mt9v032 *mt9v032, bool on)
 			return ret;
 	}
 
-	/* Disable the noise correction algorithm and restore the controls. */
-	ret = regmap_write(map, MT9V032_ROW_NOISE_CORR_CONTROL, 0);
-	if (ret < 0)
-		return ret;
-
 	return v4l2_ctrl_handler_setup(&mt9v032->ctrls);
 }
 
@@ -679,6 +676,10 @@ static int mt9v032_set_selection(struct v4l2_subdev *subdev,
  * Maximum shutter width used for AEC.
  */
 #define V4L2_CID_AEC_MAX_SHUTTER_WIDTH	(V4L2_CID_USER_BASE | 0x1007)
+/*
+ * Row Noise Correction enable.
+ */
+#define V4L2_CID_ROW_NOISE_CORRECTION	(V4L2_CID_USER_BASE | 0x1008)
 
 static int mt9v032_s_ctrl(struct v4l2_ctrl *ctrl)
 {
@@ -770,6 +771,11 @@ static int mt9v032_s_ctrl(struct v4l2_ctrl *ctrl)
 		return regmap_write(map,
 				    mt9v032->model->data->aec_max_shutter_reg,
 				    ctrl->val);
+	case V4L2_CID_ROW_NOISE_CORRECTION:
+		mt9v032->row_noise_corr = ctrl->val;
+		return regmap_write(map, MT9V032_ROW_NOISE_CORR_CONTROL,
+				    mt9v032->row_noise_corr ?
+				    mt9v032->model->data->row_noise_enable : 0);
 	}
 
 	return 0;
@@ -850,6 +856,16 @@ static const struct v4l2_ctrl_config mt9v032_aegc_controls[] = {
 		.step		= 1,
 		.def		= 2,
 		.flags		= 0,
+	}, {
+		.ops		= &mt9v032_ctrl_ops,
+		.id		= V4L2_CID_ROW_NOISE_CORRECTION,
+		.type		= V4L2_CTRL_TYPE_BOOLEAN,
+		.name		= "Row Noise Correction",
+		.min		= 0,
+		.max		= 1,
+		.step		= 1,
+		.def		= 0,
+		.flags		= 0,
 	}
 };
 
@@ -1246,6 +1262,7 @@ static const struct mt9v032_model_data mt9v032_model_data[] = {
 		.pclk_reg = MT9V032_PIXEL_CLOCK,
 		.aec_max_shutter_reg = MT9V032_AEC_MAX_SHUTTER_WIDTH,
 		.aec_max_shutter_v4l2_ctrl = &mt9v032_aec_max_shutter_width,
+		.row_noise_enable = MT9V032_ROW_NOISE_CORR_ENABLE,
 	}, {
 		/* MT9V024, MT9V034 */
 		.min_row_time = 690,
@@ -1257,6 +1274,7 @@ static const struct mt9v032_model_data mt9v032_model_data[] = {
 		.pclk_reg = MT9V034_PIXEL_CLOCK,
 		.aec_max_shutter_reg = MT9V034_AEC_MAX_SHUTTER_WIDTH,
 		.aec_max_shutter_v4l2_ctrl = &mt9v034_aec_max_shutter_width,
+		.row_noise_enable = MT9V034_ROW_NOISE_CORR_ENABLE,
 	},
 };
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] media: mt9v032: Add get_mbus_config subdev_pad_ops callback
  2026-10-09 10:28 [PATCH 0/3] media: mt9v032: Improvements from PHYTEC Primoz Fiser
  2026-10-09 10:28 ` [PATCH 1/3] media: mt9v032: Support color format selection Primoz Fiser
  2026-10-09 10:28 ` [PATCH 2/3] media: mt9v032: Add control for row noise correction Primoz Fiser
@ 2026-10-09 10:28 ` Primoz Fiser
  2 siblings, 0 replies; 4+ messages in thread
From: Primoz Fiser @ 2026-10-09 10:28 UTC (permalink / raw)
  To: Laurent Pinchart, Sakari Ailus, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, upstream

From: Stefan Riedmüller <s.riedmueller@phytec.de>

Some drivers like the i.MX6 IPU driver require the get_mbus_config
callback to be implemented, thus implement it.

Signed-off-by: Stefan Riedmüller <s.riedmueller@phytec.de>
Signed-off-by: Primoz Fiser <primoz.fiser@norik.com>
---
 drivers/media/i2c/mt9v032.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/media/i2c/mt9v032.c b/drivers/media/i2c/mt9v032.c
index d8e34e128d77..7cf0421355b5 100644
--- a/drivers/media/i2c/mt9v032.c
+++ b/drivers/media/i2c/mt9v032.c
@@ -1003,6 +1003,25 @@ static int mt9v032_close(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)
 	return mt9v032_set_power(subdev, 0);
 }
 
+static int mt9v032_get_mbus_config(struct v4l2_subdev *sd, unsigned int pad,
+				   struct v4l2_mbus_config *cfg)
+{
+	struct mt9v032 *mt9v032 = to_mt9v032(sd);
+
+	cfg->type = V4L2_MBUS_PARALLEL;
+
+	cfg->bus.parallel.flags = V4L2_MBUS_MASTER |
+				  V4L2_MBUS_HSYNC_ACTIVE_HIGH |
+				  V4L2_MBUS_VSYNC_ACTIVE_HIGH |
+				  V4L2_MBUS_DATA_ACTIVE_HIGH;
+
+	cfg->bus.parallel.flags |= mt9v032->pdata.clk_pol ?
+				   V4L2_MBUS_PCLK_SAMPLE_RISING :
+				   V4L2_MBUS_PCLK_SAMPLE_FALLING;
+
+	return 0;
+}
+
 static const struct v4l2_subdev_core_ops mt9v032_subdev_core_ops = {
 	.s_power	= mt9v032_set_power,
 };
@@ -1018,6 +1037,7 @@ static const struct v4l2_subdev_pad_ops mt9v032_subdev_pad_ops = {
 	.set_fmt = mt9v032_set_format,
 	.get_selection = mt9v032_get_selection,
 	.set_selection = mt9v032_set_selection,
+	.get_mbus_config = mt9v032_get_mbus_config,
 };
 
 static const struct v4l2_subdev_ops mt9v032_subdev_ops = {
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-09 10:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-09 10:28 [PATCH 0/3] media: mt9v032: Improvements from PHYTEC Primoz Fiser
2026-10-09 10:28 ` [PATCH 1/3] media: mt9v032: Support color format selection Primoz Fiser
2026-10-09 10:28 ` [PATCH 2/3] media: mt9v032: Add control for row noise correction Primoz Fiser
2026-10-09 10:28 ` [PATCH 3/3] media: mt9v032: Add get_mbus_config subdev_pad_ops callback Primoz Fiser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®