media: tegra-video: Add support for capturing from HDMI-to-CSI bridge
Subsystems (4)
Sowjanya Komatineni
maintainercover media: tegra-video: Add support for capturing from HDMI-to-CSI bridge
This series includes below changes to allow capturing from HDMI-to-CSI bridges.
- Add DV timing, EDID and log status V4L2 IOCTLs
- Subscribe V4L2_EVENT_SOURCE_CHANGE
- Implement V4L2 device notify callback to report queue error on source change during active streaming.
- Add support for NV16 V4L2 Pixel format.
This series also include below fixes
- Allow format change for subdevs that don't have crop support.
- Correct V4L2 Pixel format for RGB888_1X24
- Enable VI pixel transform for YUV and RGB formats.
Sowjanya Komatineni (9):
media: tegra-video: Use zero crop settings if subdev has no
get_selection
media: tegra-video: Enable VI pixel transform for YUV and RGB formats
media: tegra-video: Fix V4L2 pixel format for RGB888_1X24
media: tegra-video: Add support for V4L2_PIX_FMT_NV16
media: tegra-video: Add DV timing support
media: tegra-video: Add support for EDID ioctl ops
media: tegra-video: Add support for VIDIOC_LOG_STATUS ioctl
media: tegra-video: Add support for V4L2_EVENT_SOURCE_CHANGE
media: tegra-video: Implement V4L2 device notify callback
drivers/staging/media/tegra-video/tegra210.c | 30 ++++- drivers/staging/media/tegra-video/vi.c | 171 ++++++++++++++++++++++++++- drivers/staging/media/tegra-video/video.c | 18 +++ 3 files changed, 211 insertions(+), 8 deletions(-)
Signature · 1 line
2.7.4
Sowjanya Komatineni
maintainerPATCH 1/9 media: tegra-video: Use zero crop settings if subdev has no get_selection
Currently try format implementation doesn't check if subdevice has get_selection ops implemented and returns -EINVAL on error from direct v4l2_subdev_call of get_selection.
Selection API's are not mandatory for all V4L2 subdevices.
This patch fixes it by adding v4l2_subdev_has_ops check prior to calling get_selection ops and continues with try or set format with zero crop settings for subdevices that don't have get_selection and returns -EINVAL only for subdevices that has get_selection ops.
--- drivers/staging/media/tegra-video/vi.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/staging/media/tegra-video/vi.c +12 -5
@@ -533,11 +533,18 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan, fse.code = fmtinfo->code; ret =v4l2_subdev_call (subdev, pad, enum_frame_size, pad_cfg, &fse);if (ret) { - ret =v4l2_subdev_call (subdev, pad, get_selection,NULL , &sdsel); -if (ret) -return -EINVAL ; - pad_cfg->try_crop.width = sdsel.r.width; - pad_cfg->try_crop.height = sdsel.r.height; +if (!v4l2_subdev_has_op (subdev, pad, get_selection)) { + pad_cfg->try_crop.width =0 ; + pad_cfg->try_crop.height =0 ; + }else { + ret =v4l2_subdev_call (subdev, pad, get_selection, +NULL , &sdsel); +if (ret) +return -EINVAL ; + + pad_cfg->try_crop.width = sdsel.r.width; + pad_cfg->try_crop.height = sdsel.r.height; + } }else { pad_cfg->try_crop.width = fse.max_width; pad_cfg->try_crop.height = fse.max_height;
Signature · 1 line
2.7.4
Sowjanya Komatineni
maintainerPATCH 2/9 media: tegra-video: Enable VI pixel transform for YUV and RGB formats
In reply to Sowjanya KomatineniVI Pixel transforms converts source pixel data to selected destination pixel formats in memory and aligns properly.
YUV and RGB formats need this pixel transform to be enabled.
RAW formats use T_R16_I destination pixel format in memory and does not need pixel transform as they support direct write to memory.
So, this patch enables pixel transform for YUV and RGB and keeps it bypass for RAW formats.
--- drivers/staging/media/tegra-video/tegra210.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/staging/media/tegra-video/tegra210.c +14 -1
@@ -178,10 +178,23 @@ static int tegra_channel_capture_setup(struct tegra_vi_channel *chan)u32 format = chan->fmtinfo->img_fmt;u32 data_type = chan->fmtinfo->img_dt;u32 word_count = (width * chan->fmtinfo->bit_width) /8 ; +u32 bypass_pixel_transform =BIT (BYPASS_PXL_TRANSFORM_OFFSET ); + +/* +* VI Pixel transformation unit converts source pixels data format +* into selected destination pixel format and aligns properly while +* interfacing with memory packer. +* This pixel transformation should be enabled for YUV and RGB +* formats and should be bypassed for RAW formats as RAW formats +* only support direct to memory. +*/ +if (chan->pg_mode || data_type ==TEGRA_IMAGE_DT_YUV422_8 || + data_type ==TEGRA_IMAGE_DT_RGB888 ) + bypass_pixel_transform =0 ;vi_csi_write (chan,TEGRA_VI_CSI_ERROR_STATUS ,0xffffffff );vi_csi_write (chan,TEGRA_VI_CSI_IMAGE_DEF , - ((chan->pg_mode ?0 :1 ) <<BYPASS_PXL_TRANSFORM_OFFSET ) | + bypass_pixel_transform | (format <<IMAGE_DEF_FORMAT_OFFSET ) |IMAGE_DEF_DEST_MEM );vi_csi_write (chan,TEGRA_VI_CSI_IMAGE_DT , data_type);
Signature · 1 line
2.7.4
Sowjanya Komatineni
maintainerPATCH 3/9 media: tegra-video: Fix V4L2 pixel format for RGB888_1X24
In reply to Sowjanya KomatineniV4L2 pixel format is incorrect for RGB888_1X24.
This patch fixes it.
--- drivers/staging/media/tegra-video/tegra210.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/tegra-video/tegra210.c +1 -1
@@ -619,7 +619,7 @@ static const struct tegra_video_format tegra210_video_formats[] = {TEGRA210_VIDEO_FMT (RAW12 ,12 ,SGBRG12_1X12 ,2 ,T_R16_I ,SGBRG12 ),TEGRA210_VIDEO_FMT (RAW12 ,12 ,SBGGR12_1X12 ,2 ,T_R16_I ,SBGGR12 ),/* RGB888 */ -TEGRA210_VIDEO_FMT (RGB888 ,24 ,RGB888_1X24 ,4 ,T_A8R8G8B8 ,RGB24 ), +TEGRA210_VIDEO_FMT (RGB888 ,24 ,RGB888_1X24 ,4 ,T_A8R8G8B8 ,XRGB32 ),TEGRA210_VIDEO_FMT (RGB888 ,24 ,RGB888_1X32_PADHI ,4 ,T_A8B8G8R8 , XBGR32),/* YUV422 */
Signature · 1 line
2.7.4
Sowjanya Komatineni
maintainerPATCH 4/9 media: tegra-video: Add support for V4L2_PIX_FMT_NV16
In reply to Sowjanya KomatineniNV16 are two-plane versions of YUV422 format.
VI/CSI surface0 registers corresponds to first Y plane and surface1 registers corresponds to seconds UV plane.
This patch updates image size for NV16 format to include both planes and programs VI/CSI surface1 registers for UV plane capture.
--- drivers/staging/media/tegra-video/tegra210.c | 13 +++++++++++++ drivers/staging/media/tegra-video/vi.c | 2 ++ 2 files changed, 15 insertions(+)
drivers/staging/media/tegra-video/tegra210.c +13 -0
@@ -287,6 +287,7 @@ static int tegra_channel_capture_frame(struct tegra_vi_channel *chan, {u32 thresh, value, frame_start, mw_ack_done;int bytes_per_line = chan->format.bytesperline; +u32 sizeimage = chan->format.sizeimage;int err;/* program buffer address by using surface 0 */
@@ -296,6 +297,18 @@ static int tegra_channel_capture_frame(struct tegra_vi_channel *chan,vi_csi_write (chan,TEGRA_VI_CSI_SURFACE0_STRIDE , bytes_per_line);/* +* Program surface 1 for UV plane with offset sizeimage from Y plane. +*/ +if (chan->fmtinfo->fourcc ==V4L2_PIX_FMT_NV16 ) { +vi_csi_write (chan,TEGRA_VI_CSI_SURFACE1_OFFSET_MSB , + ((u64 )buf->addr + sizeimage /2 ) >>32 ); +vi_csi_write (chan,TEGRA_VI_CSI_SURFACE1_OFFSET_LSB , + buf->addr + sizeimage /2 ); +vi_csi_write (chan,TEGRA_VI_CSI_SURFACE1_STRIDE , + bytes_per_line); + } + +/* * Tegra VI block interacts with host1x syncpt for synchronizing * programmed condition of capture state and hardware operation. * Frame start and Memory write acknowledge syncpts has their own
drivers/staging/media/tegra-video/vi.c +2 -0
@@ -484,6 +484,8 @@ static void tegra_channel_fmt_align(struct tegra_vi_channel *chan, pix->bytesperline =clamp (bpl, min_bpl, max_bpl); pix->sizeimage = pix->bytesperline * pix->height; +if (pix->pixelformat ==V4L2_PIX_FMT_NV16 ) + pix->sizeimage *=2 ; } static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
Signature · 1 line
2.7.4
Sowjanya Komatineni
maintainerPATCH 5/9 media: tegra-video: Add DV timing support
In reply to Sowjanya KomatineniThis patch adds below v4l2 DV timing ioctls to support HDMI-to-CSI bridges.
--- drivers/staging/media/tegra-video/vi.c | 97 ++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+)
drivers/staging/media/tegra-video/vi.c +97 -0
@@ -18,6 +18,7 @@#include <linux/pm_runtime.h> #include <linux/slab.h> +#include <media/v4l2-dv-timings.h> #include <media/v4l2-event.h> #include <media/v4l2-fh.h> #include <media/v4l2-fwnode.h>
@@ -720,6 +721,97 @@ static int tegra_channel_s_selection(struct file *file, void *fh,return ret; } +static int tegra_channel_g_dv_timings (struct file *file,void *fh, +struct v4l2_dv_timings *timings) +{ +struct tegra_vi_channel *chan =video_drvdata (file); +struct v4l2_subdev *subdev; + + subdev =tegra_channel_get_remote_source_subdev (chan); +if (!v4l2_subdev_has_op (subdev, video, g_dv_timings)) +return -ENOTTY ; + +return v4l2_device_call_until_err (chan->video.v4l2_dev,0 , + video, g_dv_timings, timings); +} + +static int tegra_channel_s_dv_timings (struct file *file,void *fh, +struct v4l2_dv_timings *timings) +{ +struct tegra_vi_channel *chan =video_drvdata (file); +struct v4l2_subdev *subdev; +struct v4l2_bt_timings *bt = &timings->bt; +struct v4l2_dv_timings curr_timings; +int ret; + + subdev =tegra_channel_get_remote_source_subdev (chan); +if (!v4l2_subdev_has_op (subdev, video, s_dv_timings)) +return -ENOTTY ; + + ret =tegra_channel_g_dv_timings (file, fh, &curr_timings); +if (ret) +return ret; + +if (v4l2_match_dv_timings (timings, &curr_timings,0 , false)) +return 0 ; + +if (vb2_is_busy (&chan->queue)) +return -EBUSY ; + + ret =v4l2_device_call_until_err (chan->video.v4l2_dev,0 , + video, s_dv_timings, timings); +if (ret) +return ret; + + chan->format.width = bt->width; + chan->format.height = bt->height; + chan->format.bytesperline = bt->width * chan->fmtinfo->bpp; + chan->format.sizeimage = chan->format.bytesperline * bt->height; +tegra_channel_fmt_align (chan, &chan->format, chan->fmtinfo->bpp); + +return 0 ; +} + +static int tegra_channel_query_dv_timings (struct file *file,void *fh, +struct v4l2_dv_timings *timings) +{ +struct tegra_vi_channel *chan =video_drvdata (file); +struct v4l2_subdev *subdev; + + subdev =tegra_channel_get_remote_source_subdev (chan); +if (!v4l2_subdev_has_op (subdev, video, query_dv_timings)) +return -ENOTTY ; + +return v4l2_device_call_until_err (chan->video.v4l2_dev,0 , + video, query_dv_timings, timings); +} + +static int tegra_channel_enum_dv_timings (struct file *file,void *fh, +struct v4l2_enum_dv_timings *timings) +{ +struct tegra_vi_channel *chan =video_drvdata (file); +struct v4l2_subdev *subdev; + + subdev =tegra_channel_get_remote_source_subdev (chan); +if (!v4l2_subdev_has_op (subdev, pad, enum_dv_timings)) +return -ENOTTY ; + +return v4l2_subdev_call (subdev, pad, enum_dv_timings, timings); +} + +static int tegra_channel_dv_timings_cap (struct file *file,void *fh, +struct v4l2_dv_timings_cap *cap) +{ +struct tegra_vi_channel *chan =video_drvdata (file); +struct v4l2_subdev *subdev; + + subdev =tegra_channel_get_remote_source_subdev (chan); +if (!v4l2_subdev_has_op (subdev, pad, dv_timings_cap)) +return -ENOTTY ; + +return v4l2_subdev_call (subdev, pad, dv_timings_cap, cap); +} +static int tegra_channel_enum_input (struct file *file,void *fh,struct v4l2_input *inp) {
@@ -779,6 +871,11 @@ static const struct v4l2_ioctl_ops tegra_channel_ioctl_ops = { .vidioc_unsubscribe_event = v4l2_event_unsubscribe, .vidioc_g_selection = tegra_channel_g_selection, .vidioc_s_selection = tegra_channel_s_selection, + .vidioc_g_dv_timings = tegra_channel_g_dv_timings, + .vidioc_s_dv_timings = tegra_channel_s_dv_timings, + .vidioc_query_dv_timings = tegra_channel_query_dv_timings, + .vidioc_enum_dv_timings = tegra_channel_enum_dv_timings, + .vidioc_dv_timings_cap = tegra_channel_dv_timings_cap, };/*
Signature · 1 line
2.7.4
Sowjanya Komatineni
maintainerPATCH 6/9 media: tegra-video: Add support for EDID ioctl ops
In reply to Sowjanya KomatineniThis patch adds support for EDID get and set v4l2 ioctl ops to use with HDMI to CSI bridges.
--- drivers/staging/media/tegra-video/vi.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/staging/media/tegra-video/vi.c +28 -0
@@ -721,6 +721,32 @@ static int tegra_channel_s_selection(struct file *file, void *fh,return ret; } +static int tegra_channel_g_edid (struct file *file,void *fh, +struct v4l2_edid *edid) +{ +struct tegra_vi_channel *chan =video_drvdata (file); +struct v4l2_subdev *subdev; + + subdev =tegra_channel_get_remote_source_subdev (chan); +if (!v4l2_subdev_has_op (subdev, pad, get_edid)) +return -ENOTTY ; + +return v4l2_subdev_call (subdev, pad, get_edid, edid); +} + +static int tegra_channel_s_edid (struct file *file,void *fh, +struct v4l2_edid *edid) +{ +struct tegra_vi_channel *chan =video_drvdata (file); +struct v4l2_subdev *subdev; + + subdev =tegra_channel_get_remote_source_subdev (chan); +if (!v4l2_subdev_has_op (subdev, pad, set_edid)) +return -ENOTTY ; + +return v4l2_subdev_call (subdev, pad, set_edid, edid); +} +static int tegra_channel_g_dv_timings (struct file *file,void *fh,struct v4l2_dv_timings *timings) {
@@ -871,6 +897,8 @@ static const struct v4l2_ioctl_ops tegra_channel_ioctl_ops = { .vidioc_unsubscribe_event = v4l2_event_unsubscribe, .vidioc_g_selection = tegra_channel_g_selection, .vidioc_s_selection = tegra_channel_s_selection, + .vidioc_g_edid = tegra_channel_g_edid, + .vidioc_s_edid = tegra_channel_s_edid, .vidioc_g_dv_timings = tegra_channel_g_dv_timings, .vidioc_s_dv_timings = tegra_channel_s_dv_timings, .vidioc_query_dv_timings = tegra_channel_query_dv_timings,
Signature · 1 line
2.7.4
Sowjanya Komatineni
maintainerPATCH 7/9 media: tegra-video: Add support for VIDIOC_LOG_STATUS ioctl
In reply to Sowjanya KomatineniThis patch adds support for log_status ioctl.
--- drivers/staging/media/tegra-video/vi.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/staging/media/tegra-video/vi.c +10 -0
@@ -838,6 +838,15 @@ static int tegra_channel_dv_timings_cap(struct file *file, void *fh,return v4l2_subdev_call (subdev, pad, dv_timings_cap, cap); } +static int tegra_channel_log_status (struct file *file,void *fh) +{ +struct tegra_vi_channel *chan =video_drvdata (file); + +v4l2_device_call_all (chan->video.v4l2_dev,0 , core, log_status); + +return 0 ; +} +static int tegra_channel_enum_input (struct file *file,void *fh,struct v4l2_input *inp) {
@@ -904,6 +913,7 @@ static const struct v4l2_ioctl_ops tegra_channel_ioctl_ops = { .vidioc_query_dv_timings = tegra_channel_query_dv_timings, .vidioc_enum_dv_timings = tegra_channel_enum_dv_timings, .vidioc_dv_timings_cap = tegra_channel_dv_timings_cap, + .vidioc_log_status = tegra_channel_log_status, };/*
Signature · 1 line
2.7.4
Sowjanya Komatineni
maintainerPATCH 8/9 media: tegra-video: Add support for V4L2_EVENT_SOURCE_CHANGE
In reply to Sowjanya KomatineniCurrent implementation uses v4l2_ctrl_subscribe_event() and this does not handle V4L2_EVENT_SOURCE_CHANGE.
So, update driver to handle V4L2_EVENT_SOURCE_CHANGE.
--- drivers/staging/media/tegra-video/vi.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/staging/media/tegra-video/vi.c +13 -1
@@ -642,6 +642,18 @@ static int tegra_channel_set_subdev_active_fmt(struct tegra_vi_channel *chan)return 0 ; } +static int +tegra_channel_subscribe_event (struct v4l2_fh *fh, +const struct v4l2_event_subscription *sub) +{ +switch (sub->type) { +case V4L2_EVENT_SOURCE_CHANGE : +return v4l2_event_subscribe (fh, sub,4 ,NULL ); + } + +return v4l2_ctrl_subscribe_event (fh, sub); +} +static int tegra_channel_g_selection (struct file *file,void *priv,struct v4l2_selection *sel) {
@@ -902,7 +914,7 @@ static const struct v4l2_ioctl_ops tegra_channel_ioctl_ops = { .vidioc_expbuf = vb2_ioctl_expbuf, .vidioc_streamon = vb2_ioctl_streamon, .vidioc_streamoff = vb2_ioctl_streamoff, - .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, + .vidioc_subscribe_event = tegra_channel_subscribe_event, .vidioc_unsubscribe_event = v4l2_event_unsubscribe, .vidioc_g_selection = tegra_channel_g_selection, .vidioc_s_selection = tegra_channel_s_selection,
Signature · 1 line
2.7.4
Sowjanya Komatineni
maintainerPATCH 9/9 media: tegra-video: Implement V4L2 device notify callback
In reply to Sowjanya KomatineniImplement V4L2 device notify callback to handleV4L2_EVENT_SOURCE_CHANGE event from subdevices.
HDMI-to-CSI bridge drivers trigger V4L2_EVENT_SOURCE_CHANGE when source DV timing changes are detected or when HDMI hotplug happens.
Runtime source parameter changes during active streaming is not allowed and Tegra video driver calls vb2_queue_error to signal a fatal error if a notification of this event happens during an active streaming.
--- drivers/staging/media/tegra-video/vi.c | 3 +++ drivers/staging/media/tegra-video/video.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+)
drivers/staging/media/tegra-video/vi.c +3 -0
@@ -1634,6 +1634,9 @@ static int tegra_vi_graph_notify_complete(struct v4l2_async_notifier *notifier)v4l2_set_subdev_hostdata (subdev, chan); + subdev =tegra_channel_get_remote_source_subdev (chan); +v4l2_set_subdev_hostdata (subdev, chan); +return 0 ; unregister_video:
drivers/staging/media/tegra-video/video.c +18 -0
@@ -7,6 +7,8 @@#include <linux/module.h> #include <linux/platform_device.h> +#include <media/v4l2-event.h> +#include "video.h" static void tegra_v4l2_dev_release (struct v4l2_device *v4l2_dev)
@@ -24,6 +26,21 @@ static void tegra_v4l2_dev_release(struct v4l2_device *v4l2_dev)kfree (vid); } +static void tegra_v4l2_dev_notify (struct v4l2_subdev *sd, +unsigned int notification,void *arg) +{ +struct tegra_vi_channel *chan; +const struct v4l2_event *ev = arg; + +if (notification !=V4L2_DEVICE_NOTIFY_EVENT ) +return ; + + chan =v4l2_get_subdev_hostdata (sd); +v4l2_event_queue (&chan->video, arg); +if (ev->type ==V4L2_EVENT_SOURCE_CHANGE &&vb2_is_streaming (&chan->queue)) +vb2_queue_error (&chan->queue); +} +static int host1x_video_probe (struct host1x_device *dev) {struct tegra_video_device *vid;
@@ -49,6 +66,7 @@ static int host1x_video_probe(struct host1x_device *dev) vid->v4l2_dev.mdev = &vid->media_dev; vid->v4l2_dev.release = tegra_v4l2_dev_release; + vid->v4l2_dev.notify = tegra_v4l2_dev_notify; ret =v4l2_device_register (&dev->dev, &vid->v4l2_dev);if (ret <0 ) { dev_err(&dev->dev,
Signature · 1 line
2.7.4