linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] media: atmel: atmel-isc-base: fixes for GREY/mt9v022 support
@ 2019-11-25  8:32 Eugen.Hristev
  2019-11-25  8:32 ` [PATCH 1/5] media: atmel: atmel-isc-base: allow 8 bit direct dump Eugen.Hristev
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Eugen.Hristev @ 2019-11-25  8:32 UTC (permalink / raw)
  To: linux-media, linux-kernel, linux-arm-kernel, hverkuil; +Cc: Eugen.Hristev

From: Eugen Hristev <eugen.hristev@microchip.com>


Hello,

This series fixes various issues inside the atmel-isc driver and comes with
support for Y10 sensors like mt9v022 Micron mono sensor.

This series applies on top of my patch :
[PATCH v2] media: atmel: atmel-isc-base: expose white balance as v4l2 controls


Eugen Hristev (5):
  media: atmel: atmel-isc-base: allow 8 bit direct dump
  media: atmel: atmel-isc-base: add support for Y10 format
  media: atmel: atmel-isc-base: properly initialize pad_cfg
  media: atmel: atmel-isc-base: fix enum calls default format
  media: atmel: atmel-isc-base: initialize the try_crop for the pads in
    try_fmt

 drivers/media/platform/atmel/atmel-isc-base.c | 93 +++++++++++++++++++++------
 1 file changed, 74 insertions(+), 19 deletions(-)

-- 
2.7.4


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

* [PATCH 1/5] media: atmel: atmel-isc-base: allow 8 bit direct dump
  2019-11-25  8:32 [PATCH 0/5] media: atmel: atmel-isc-base: fixes for GREY/mt9v022 support Eugen.Hristev
@ 2019-11-25  8:32 ` Eugen.Hristev
  2019-11-25  8:32 ` [PATCH 2/5] media: atmel: atmel-isc-base: add support for Y10 format Eugen.Hristev
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eugen.Hristev @ 2019-11-25  8:32 UTC (permalink / raw)
  To: linux-media, linux-kernel, linux-arm-kernel, hverkuil; +Cc: Eugen.Hristev

From: Eugen Hristev <eugen.hristev@microchip.com>

In case the format that the sensor sends is 8 bit only (like GREY for example)
we need to be able to bypass ISC pipeline and directly dump 8 bits.
That's why the hardcoded value of 16 bpp is not correct in all cases.
This change allows the output format to decide what is the correct bpp (bits per
pixel) such that the result is in the proper format.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
---
 drivers/media/platform/atmel/atmel-isc-base.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
index 604374a..0cfb524 100644
--- a/drivers/media/platform/atmel/atmel-isc-base.c
+++ b/drivers/media/platform/atmel/atmel-isc-base.c
@@ -1049,18 +1049,10 @@ static int isc_try_validate_formats(struct isc_device *isc)
 /*
  * Configures the RLP and DMA modules, depending on the output format
  * configured for the ISC.
- * If direct_dump == true, just dump raw data 8 bits.
+ * If direct_dump == true, just dump raw data 8/16 bits depending on format.
  */
 static int isc_try_configure_rlp_dma(struct isc_device *isc, bool direct_dump)
 {
-	if (direct_dump) {
-		isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DAT8;
-		isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED8;
-		isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED;
-		isc->try_config.bpp = 16;
-		return 0;
-	}
-
 	switch (isc->try_config.fourcc) {
 	case V4L2_PIX_FMT_SBGGR8:
 	case V4L2_PIX_FMT_SGBRG8:
@@ -1141,6 +1133,14 @@ static int isc_try_configure_rlp_dma(struct isc_device *isc, bool direct_dump)
 	default:
 		return -EINVAL;
 	}
+
+	if (direct_dump) {
+		isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DAT8;
+		isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED8;
+		isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED;
+		return 0;
+	}
+
 	return 0;
 }
 
-- 
2.7.4


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

* [PATCH 2/5] media: atmel: atmel-isc-base: add support for Y10 format
  2019-11-25  8:32 [PATCH 0/5] media: atmel: atmel-isc-base: fixes for GREY/mt9v022 support Eugen.Hristev
  2019-11-25  8:32 ` [PATCH 1/5] media: atmel: atmel-isc-base: allow 8 bit direct dump Eugen.Hristev
@ 2019-11-25  8:32 ` Eugen.Hristev
  2019-11-25  8:32 ` [PATCH 3/5] media: atmel: atmel-isc-base: properly initialize pad_cfg Eugen.Hristev
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eugen.Hristev @ 2019-11-25  8:32 UTC (permalink / raw)
  To: linux-media, linux-kernel, linux-arm-kernel, hverkuil; +Cc: Eugen.Hristev

From: Eugen Hristev <eugen.hristev@microchip.com>

The ISC can receive input from sensors using Y10 format directly
(10 bits greyscale). In this case, the ISC must dump the data directly,
either as GREY (8bit) or Y10 (10bit).
Y16 is not supported because we cannot align the MSB 10 bits to the MSB inside
the 16bit container.
For this format, the ISC internal pipeline cannot work (only works with BAYER),
so we must dump the data directly as 8bit/10bit.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
---
 drivers/media/platform/atmel/atmel-isc-base.c | 35 ++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
index 0cfb524..a948294 100644
--- a/drivers/media/platform/atmel/atmel-isc-base.c
+++ b/drivers/media/platform/atmel/atmel-isc-base.c
@@ -73,6 +73,9 @@ const struct isc_format controller_formats[] = {
 	{
 		.fourcc		= V4L2_PIX_FMT_GREY,
 	},
+	{
+		.fourcc		= V4L2_PIX_FMT_Y10,
+	},
 };
 
 /* This is a list of formats that the ISC can receive as *input* */
@@ -164,6 +167,12 @@ struct isc_format formats_list[] = {
 		.mbus_code	= MEDIA_BUS_FMT_RGB565_2X8_LE,
 		.pfe_cfg0_bps	= ISC_PFE_CFG0_BPS_EIGHT,
 	},
+	{
+		.fourcc		= V4L2_PIX_FMT_Y10,
+		.mbus_code	= MEDIA_BUS_FMT_Y10_1X10,
+		.pfe_cfg0_bps	= ISC_PFG_CFG0_BPS_TEN,
+	},
+
 };
 
 /* Gamma table with gamma 1/2.2 */
@@ -211,6 +220,10 @@ const u32 isc_gamma_table[GAMMA_MAX + 1][GAMMA_ENTRIES] = {
 #define ISC_IS_FORMAT_RAW(mbus_code) \
 	(((mbus_code) & 0xf000) == 0x3000)
 
+#define ISC_IS_FORMAT_GREY(mbus_code) \
+	(((mbus_code) == MEDIA_BUS_FMT_Y10_1X10) | \
+	(((mbus_code) == MEDIA_BUS_FMT_Y8_1X8)))
+
 #define ISC_CTRL_ISC_TO_V4L2(x) ((x) == ISC_WB_O_ZERO_VAL ? 0 : (x))
 #define ISC_CTRL_V4L2_TO_ISC(x) ((x) ? (x) : ISC_WB_O_ZERO_VAL)
 
@@ -1026,6 +1039,7 @@ static int isc_try_validate_formats(struct isc_device *isc)
 		rgb = true;
 		break;
 	case V4L2_PIX_FMT_GREY:
+	case V4L2_PIX_FMT_Y10:
 		ret = 0;
 		grey = true;
 		break;
@@ -1033,16 +1047,19 @@ static int isc_try_validate_formats(struct isc_device *isc)
 	/* any other different formats are not supported */
 		ret = -EINVAL;
 	}
-
-	/* we cannot output RAW/Grey if we do not receive RAW */
-	if ((bayer || grey) &&
-	    !ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code))
-		return -EINVAL;
-
 	v4l2_dbg(1, debug, &isc->v4l2_dev,
 		 "Format validation, requested rgb=%u, yuv=%u, grey=%u, bayer=%u\n",
 		 rgb, yuv, grey, bayer);
 
+	/* we cannot output RAW if we do not receive RAW */
+	if ((bayer) && !ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code))
+		return -EINVAL;
+
+	/* we cannot output GREY if we do not receive RAW/GREY */
+	if (grey && !ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code) &&
+	    !ISC_IS_FORMAT_GREY(isc->try_config.sd_format->mbus_code))
+		return -EINVAL;
+
 	return ret;
 }
 
@@ -1130,6 +1147,12 @@ static int isc_try_configure_rlp_dma(struct isc_device *isc, bool direct_dump)
 		isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED;
 		isc->try_config.bpp = 8;
 		break;
+	case V4L2_PIX_FMT_Y10:
+		isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DATY10;
+		isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED16;
+		isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED;
+		isc->try_config.bpp = 16;
+		break;
 	default:
 		return -EINVAL;
 	}
-- 
2.7.4


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

* [PATCH 3/5] media: atmel: atmel-isc-base: properly initialize pad_cfg
  2019-11-25  8:32 [PATCH 0/5] media: atmel: atmel-isc-base: fixes for GREY/mt9v022 support Eugen.Hristev
  2019-11-25  8:32 ` [PATCH 1/5] media: atmel: atmel-isc-base: allow 8 bit direct dump Eugen.Hristev
  2019-11-25  8:32 ` [PATCH 2/5] media: atmel: atmel-isc-base: add support for Y10 format Eugen.Hristev
@ 2019-11-25  8:32 ` Eugen.Hristev
  2019-11-25  8:32 ` [PATCH 4/5] media: atmel: atmel-isc-base: fix enum calls default format Eugen.Hristev
  2019-11-25  8:32 ` [PATCH 5/5] media: atmel: atmel-isc-base: initialize the try_crop for the pads in try_fmt Eugen.Hristev
  4 siblings, 0 replies; 6+ messages in thread
From: Eugen.Hristev @ 2019-11-25  8:32 UTC (permalink / raw)
  To: linux-media, linux-kernel, linux-arm-kernel, hverkuil; +Cc: Eugen.Hristev

From: Eugen Hristev <eugen.hristev@microchip.com>

In try_fmt, properly initialize the pad_cfg variable to zeros.
This can be used by various calls from the subdev, so it's better
to have it initialized.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
---
 drivers/media/platform/atmel/atmel-isc-base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
index a948294..7c73bcd 100644
--- a/drivers/media/platform/atmel/atmel-isc-base.c
+++ b/drivers/media/platform/atmel/atmel-isc-base.c
@@ -1239,7 +1239,7 @@ static int isc_try_fmt(struct isc_device *isc, struct v4l2_format *f,
 	int i;
 	struct isc_format *sd_fmt = NULL, *direct_fmt = NULL;
 	struct v4l2_pix_format *pixfmt = &f->fmt.pix;
-	struct v4l2_subdev_pad_config pad_cfg;
+	struct v4l2_subdev_pad_config pad_cfg = {0};
 	struct v4l2_subdev_format format = {
 		.which = V4L2_SUBDEV_FORMAT_TRY,
 	};
-- 
2.7.4


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

* [PATCH 4/5] media: atmel: atmel-isc-base: fix enum calls default format
  2019-11-25  8:32 [PATCH 0/5] media: atmel: atmel-isc-base: fixes for GREY/mt9v022 support Eugen.Hristev
                   ` (2 preceding siblings ...)
  2019-11-25  8:32 ` [PATCH 3/5] media: atmel: atmel-isc-base: properly initialize pad_cfg Eugen.Hristev
@ 2019-11-25  8:32 ` Eugen.Hristev
  2019-11-25  8:32 ` [PATCH 5/5] media: atmel: atmel-isc-base: initialize the try_crop for the pads in try_fmt Eugen.Hristev
  4 siblings, 0 replies; 6+ messages in thread
From: Eugen.Hristev @ 2019-11-25  8:32 UTC (permalink / raw)
  To: linux-media, linux-kernel, linux-arm-kernel, hverkuil; +Cc: Eugen.Hristev

From: Eugen Hristev <eugen.hristev@microchip.com>

With some sensors, the mbus code must match the one that sensor supports.
In this case we should initialize the mbus_code of the fse/fie before
calling the subdev, and not after.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
---
 drivers/media/platform/atmel/atmel-isc-base.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
index 7c73bcd..1bb1dd5 100644
--- a/drivers/media/platform/atmel/atmel-isc-base.c
+++ b/drivers/media/platform/atmel/atmel-isc-base.c
@@ -1461,6 +1461,7 @@ static int isc_enum_framesizes(struct file *file, void *fh,
 {
 	struct isc_device *isc = video_drvdata(file);
 	struct v4l2_subdev_frame_size_enum fse = {
+		.code = isc->config.sd_format->mbus_code,
 		.index = fsize->index,
 		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
 	};
@@ -1483,8 +1484,6 @@ static int isc_enum_framesizes(struct file *file, void *fh,
 	if (ret)
 		return ret;
 
-	fse.code = isc->config.sd_format->mbus_code;
-
 	fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
 	fsize->discrete.width = fse.max_width;
 	fsize->discrete.height = fse.max_height;
@@ -1497,6 +1496,7 @@ static int isc_enum_frameintervals(struct file *file, void *fh,
 {
 	struct isc_device *isc = video_drvdata(file);
 	struct v4l2_subdev_frame_interval_enum fie = {
+		.code = isc->config.sd_format->mbus_code,
 		.index = fival->index,
 		.width = fival->width,
 		.height = fival->height,
@@ -1521,7 +1521,6 @@ static int isc_enum_frameintervals(struct file *file, void *fh,
 	if (ret)
 		return ret;
 
-	fie.code = isc->config.sd_format->mbus_code;
 	fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
 	fival->discrete = fie.interval;
 
-- 
2.7.4


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

* [PATCH 5/5] media: atmel: atmel-isc-base: initialize the try_crop for the pads in try_fmt
  2019-11-25  8:32 [PATCH 0/5] media: atmel: atmel-isc-base: fixes for GREY/mt9v022 support Eugen.Hristev
                   ` (3 preceding siblings ...)
  2019-11-25  8:32 ` [PATCH 4/5] media: atmel: atmel-isc-base: fix enum calls default format Eugen.Hristev
@ 2019-11-25  8:32 ` Eugen.Hristev
  4 siblings, 0 replies; 6+ messages in thread
From: Eugen.Hristev @ 2019-11-25  8:32 UTC (permalink / raw)
  To: linux-media, linux-kernel, linux-arm-kernel, hverkuil; +Cc: Eugen.Hristev

From: Eugen Hristev <eugen.hristev@microchip.com>

When requesting format from sensor, some sensors call the subdev_get_try_crop
which for ISC was not properly initialized, and this causes errors in
determining proper image resolutions.
To accommodate for this, when trying a format (in try_fmt), first attempt to
obtain the framesize for this format from sensor.
In case this fails, use the maximum ISC width/height as try_crop, otherwise
provide the first size height/width from the sensor.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
---
 drivers/media/platform/atmel/atmel-isc-base.c | 33 +++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
index 1bb1dd5..511f0c5 100644
--- a/drivers/media/platform/atmel/atmel-isc-base.c
+++ b/drivers/media/platform/atmel/atmel-isc-base.c
@@ -1233,6 +1233,36 @@ static int isc_try_configure_pipeline(struct isc_device *isc)
 	return 0;
 }
 
+static void isc_try_fse(struct isc_device *isc,
+			struct v4l2_subdev_pad_config *pad_cfg)
+{
+	int ret;
+	struct v4l2_subdev_frame_size_enum fse = {0};
+	/*
+	 * If we do not know yet which format the subdev is using, we cannot
+	 * do anything.
+	 */
+	if (!isc->try_config.sd_format)
+		return;
+
+	fse.code = isc->try_config.sd_format->mbus_code;
+	fse.which = V4L2_SUBDEV_FORMAT_TRY;
+
+	ret = v4l2_subdev_call(isc->current_subdev->sd, pad, enum_frame_size,
+			       pad_cfg, &fse);
+	/*
+	 * Attempt to obtain format size from subdev. If not available,
+	 * just use the maximum ISC can receive.
+	 */
+	if (ret) {
+		pad_cfg->try_crop.width = ISC_MAX_SUPPORT_WIDTH;
+		pad_cfg->try_crop.height = ISC_MAX_SUPPORT_HEIGHT;
+	} else {
+		pad_cfg->try_crop.width = fse.max_width;
+		pad_cfg->try_crop.height = fse.max_height;
+	}
+}
+
 static int isc_try_fmt(struct isc_device *isc, struct v4l2_format *f,
 			u32 *code)
 {
@@ -1336,6 +1366,9 @@ static int isc_try_fmt(struct isc_device *isc, struct v4l2_format *f,
 	if (ret)
 		goto isc_try_fmt_err;
 
+	/* Obtain frame sizes if possible to have crop requirements ready */
+	isc_try_fse(isc, &pad_cfg);
+
 	v4l2_fill_mbus_format(&format.format, pixfmt, mbus_code);
 	ret = v4l2_subdev_call(isc->current_subdev->sd, pad, set_fmt,
 			       &pad_cfg, &format);
-- 
2.7.4


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

end of thread, other threads:[~2019-11-25  8:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-25  8:32 [PATCH 0/5] media: atmel: atmel-isc-base: fixes for GREY/mt9v022 support Eugen.Hristev
2019-11-25  8:32 ` [PATCH 1/5] media: atmel: atmel-isc-base: allow 8 bit direct dump Eugen.Hristev
2019-11-25  8:32 ` [PATCH 2/5] media: atmel: atmel-isc-base: add support for Y10 format Eugen.Hristev
2019-11-25  8:32 ` [PATCH 3/5] media: atmel: atmel-isc-base: properly initialize pad_cfg Eugen.Hristev
2019-11-25  8:32 ` [PATCH 4/5] media: atmel: atmel-isc-base: fix enum calls default format Eugen.Hristev
2019-11-25  8:32 ` [PATCH 5/5] media: atmel: atmel-isc-base: initialize the try_crop for the pads in try_fmt Eugen.Hristev

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).