tegra-video: Convert to media-centric pipe
Subsystems (4)
v2 cover tegra-video: Convert to media-centric pipe
A minimal set of changes required to convert video-centric pipe into media-centric. I know that moving to /media should be last commit, but it may be beneficial to keep this history in the /media subsystem, instead of leaving it in staging.
All changes were tested on:
LG Optimus Vu (P895) Tegra30 device:
- MT9M114 front sensor with complex topology and irregular pad mapping
- IMX111 rear sensor which has simple pixel array and a single pad
ASUS Transformer TF701T Tegra114 device:
- same MT9M114 front sensor
- OV5693 rear sensor which has simple pixel array and a single pad
Nvidia Tegra Note 7 (P1988) Tegra114 device:
- OV5693 rear sensor
They all work and produce images.
---
Changes in v2:
- added VIDEO_V4L2_SUBDEV_API selection
- fixed video device and tpg channels remaining if v4l2_device_register_subdev_nodes() fails
- restore vidioc_enum_input(), vidioc_g_input(), vidioc_s_input()
- dropping bitmap entirely was switched to using it to sync VI and CSI/VIP bridge formats
- tegra_channel_update_gangports() moved from tegra_channel_set_subdev_active_fmt() into tegra_channel_init()
- switch to defining v4l2_frmsize_stepwise as part of VI SoC instead of filling it via vi_fmt_align()
- restored and fixed tegra_get_format_by_fourcc() logic, it matched only first instance of pixelformat, though it may not be supported
- updated tegra_channel_enum_framesizes() to use v4l2_frmsize_stepwise from VI SoC
- upgraded __tegra_channel_try_format() to accept and fill tegra_video_format struct
- changed to tegra_channel_enum_format() dropped
- updated tegra_channel_link_validate() logic to use active format from tegra_vi_channel struct
- in tegra_v4l2_dev_notify() use parsing of media tree to get video device instead of blindly v4l2_get_subdev_hostdata() from subdev
- in tegra_channel_get_remote_csi_subdev() added tegra_csi_tpg_ops check
- updated tegra_csi_enum_bus_code() and tegra_vip_enum_bus_code() logic
---
Jonas Schwöbel (1):
media: tegra-video: vi: Match fourcc against channel format bitmap
Svyatoslav Ryhel (14):
staging: media: tegra-video: Move driver to media/platform/nvidia
media: tegra-video: vi: Drop controls consolidation into VI device
media: tegra-video: vi: Expose all sub-devices in the pipeline
media: tegra-video: vi: Drop subdevice passthrough and input ioctls
media: tegra-video: vi: Build bitmap of formats compatible with
CSI/VIP instead of source
media: tegra-video: Expose SoC stepwise frame size limits
media: tegra-video: vi: Report stepwise frame sizes instead of
querying subdev
media: tegra-video: vi: Configure capture format locally without
subdev calls
media: tegra-video: vi: Implement link_validate for video entity
media: tegra-video: video: Resolve video device via media graph on
notifications
media: tegra-video: Remove remote source subdev helper
media: tegra-video: csi: Scope pad and state ops to TPG mode
media: tegra-video: csi: Add pad and media operations for own CSI
channels
media: tegra-video: vip: Add pad and media operations for VIP
MAINTAINERS | 2 +-
drivers/media/platform/nvidia/Kconfig | 2 +
drivers/media/platform/nvidia/Makefile | 1 +
.../platform/nvidia}/tegra-video/Kconfig | 1 +
.../platform/nvidia}/tegra-video/Makefile | 0
.../platform/nvidia}/tegra-video/csi.c | 299 +++++++---
.../platform/nvidia}/tegra-video/csi.h | 0
.../platform/nvidia}/tegra-video/tegra20.c | 10 +
.../platform/nvidia}/tegra-video/tegra210.c | 10 +
.../platform/nvidia}/tegra-video/vi.c | 548 +++---------------
.../platform/nvidia}/tegra-video/vi.h | 4 +-
.../platform/nvidia}/tegra-video/video.c | 74 ++-
.../platform/nvidia}/tegra-video/video.h | 0
.../platform/nvidia}/tegra-video/vip.c | 94 ++-
.../platform/nvidia}/tegra-video/vip.h | 0
drivers/staging/media/Kconfig | 2 -
drivers/staging/media/Makefile | 1 -
drivers/staging/media/tegra-video/TODO | 5 -
18 files changed, 495 insertions(+), 558 deletions(-)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/Kconfig (94%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/Makefile (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/csi.c (75%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/csi.h (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/tegra20.c (99%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/tegra210.c (99%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/vi.c (74%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/vi.h (99%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/video.c (78%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/video.h (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/vip.c (72%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/vip.h (100%)
delete mode 100644 drivers/staging/media/tegra-video/TODOSignature · 1 line
2.53.0
PATCH v2 1/15 staging: media: tegra-video: Move driver to media/platform/nvidia
The Tegra Video Input drivers are mature and developed enough to be moved from staging into the media subsystem. TODO file removed. Path in MAINTAINERS updated. No other functional changes are introduced.
---
MAINTAINERS | 2 +-
drivers/media/platform/nvidia/Kconfig | 2 ++
drivers/media/platform/nvidia/Makefile | 1 +
.../media => media/platform/nvidia}/tegra-video/Kconfig | 0
.../media => media/platform/nvidia}/tegra-video/Makefile | 0
.../media => media/platform/nvidia}/tegra-video/csi.c | 0
.../media => media/platform/nvidia}/tegra-video/csi.h | 0
.../media => media/platform/nvidia}/tegra-video/tegra20.c | 0
.../media => media/platform/nvidia}/tegra-video/tegra210.c | 0
.../media => media/platform/nvidia}/tegra-video/vi.c | 0
.../media => media/platform/nvidia}/tegra-video/vi.h | 0
.../media => media/platform/nvidia}/tegra-video/video.c | 0
.../media => media/platform/nvidia}/tegra-video/video.h | 0
.../media => media/platform/nvidia}/tegra-video/vip.c | 0
.../media => media/platform/nvidia}/tegra-video/vip.h | 0
drivers/staging/media/Kconfig | 2 --
drivers/staging/media/Makefile | 1 -
drivers/staging/media/tegra-video/TODO | 5 -----
18 files changed, 4 insertions(+), 9 deletions(-)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/Kconfig (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/Makefile (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/csi.c (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/csi.h (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/tegra20.c (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/tegra210.c (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/vi.c (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/vi.h (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/video.c (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/video.h (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/vip.c (100%)
rename drivers/{staging/media => media/platform/nvidia}/tegra-video/vip.h (100%)
delete mode 100644 drivers/staging/media/tegra-video/TODOMAINTAINERS +1 -1
@@ -27916,7 +27916,7 @@ F: Documentation/devicetree/bindings/display/tegra/nvidia,tegra20-host1x.yaml F: Documentation/devicetree/bindings/display/tegra/nvidia,tegra20-vi.yaml F: Documentation/devicetree/bindings/display/tegra/nvidia,tegra20-vip.yaml F: Documentation/devicetree/bindings/display/tegra/nvidia,tegra210-csi.yaml -F: drivers/staging/media/tegra-video/ +F: drivers/media/platform/nvidia/tegra-video/ TEGRA XUSB PADCTL DRIVER M: JC Kuo <[email protected]>
drivers/media/platform/nvidia/Kconfig +2 -0
@@ -3,3 +3,5 @@ comment "NVidia media platform drivers" source "drivers/media/platform/nvidia/tegra-vde/Kconfig" + +source "drivers/media/platform/nvidia/tegra-video/Kconfig"
drivers/media/platform/nvidia/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-y += tegra-vde/ +obj-y += tegra-video/
drivers/media/platform/nvidia/tegra-video/Kconfig renamed from drivers/staging/media/tegra-video/Kconfig +0 -0
drivers/media/platform/nvidia/tegra-video/Makefile renamed from drivers/staging/media/tegra-video/Makefile +0 -0
drivers/media/platform/nvidia/tegra-video/csi.c renamed from drivers/staging/media/tegra-video/csi.c +0 -0
drivers/media/platform/nvidia/tegra-video/csi.h renamed from drivers/staging/media/tegra-video/csi.h +0 -0
drivers/media/platform/nvidia/tegra-video/tegra20.c renamed from drivers/staging/media/tegra-video/tegra20.c +0 -0
drivers/media/platform/nvidia/tegra-video/tegra210.c renamed from drivers/staging/media/tegra-video/tegra210.c +0 -0
drivers/media/platform/nvidia/tegra-video/vi.c renamed from drivers/staging/media/tegra-video/vi.c +0 -0
drivers/media/platform/nvidia/tegra-video/vi.h renamed from drivers/staging/media/tegra-video/vi.h +0 -0
drivers/media/platform/nvidia/tegra-video/video.c renamed from drivers/staging/media/tegra-video/video.c +0 -0
drivers/media/platform/nvidia/tegra-video/video.h renamed from drivers/staging/media/tegra-video/video.h +0 -0
drivers/media/platform/nvidia/tegra-video/vip.c renamed from drivers/staging/media/tegra-video/vip.c +0 -0
drivers/media/platform/nvidia/tegra-video/vip.h renamed from drivers/staging/media/tegra-video/vip.h +0 -0
drivers/staging/media/Kconfig +0 -2
@@ -34,8 +34,6 @@ source "drivers/staging/media/meson/vdec/Kconfig" source "drivers/staging/media/sunxi/Kconfig" -source "drivers/staging/media/tegra-video/Kconfig" - menuconfig STAGING_MEDIA_DEPRECATED bool "Media staging drivers (DEPRECATED)" default n
drivers/staging/media/Makefile +0 -1
@@ -3,7 +3,6 @@ obj-$(CONFIG_INTEL_ATOMISP) += atomisp/ obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx/ obj-$(CONFIG_VIDEO_MESON_VDEC) += meson/vdec/ obj-$(CONFIG_VIDEO_SUNXI) += sunxi/ -obj-$(CONFIG_VIDEO_TEGRA) += tegra-video/ obj-$(CONFIG_VIDEO_IPU3_IMGU) += ipu3/ obj-$(CONFIG_VIDEO_INTEL_IPU7) += ipu7/ obj-$(CONFIG_DVB_AV7110) += av7110/
drivers/staging/media/tegra-video/TODO deleted +0 -5
@@ -1,5 +0,0 @@ -TODO list -* Add support for Ganged mode. -* Add RAW10 packed video format support to Tegra210 video formats. -* Add support for suspend and resume. -* Make sure v4l2-compliance tests pass with all of the above implementations.
Signature · 1 line
2.53.0
PATCH v2 2/15 media: tegra-video: vi: Drop controls consolidation into VI device
In reply to Svyatoslav RyhelLike any video-centric video input pipeline, Tegra VI combines all controls from linked devices into a /dev/video*. This behavior is no longer desired, since it causes conflicts when controls are duplicated and does not allow including controls from auxiliary devices such as a VCM or flash LEDs. Remove consolidation of all devices in the pipe into the VI device.
--- .../media/platform/nvidia/tegra-video/vi.c | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-)
drivers/media/platform/nvidia/tegra-video/vi.c +2 -22
@@ -960,9 +960,6 @@ static int tegra_channel_setup_ctrl_handler(struct tegra_vi_channel *chan) return chan->ctrl_handler.error; }#else -struct v4l2_subdev *subdev; -struct v4l2_ctrl *hflip, *vflip; -/* custom control */ v4l2_ctrl_new_custom (&chan->ctrl_handler, &syncpt_timeout_ctrl,NULL );if (chan->ctrl_handler.error) {
@@ -973,27 +970,10 @@ static int tegra_channel_setup_ctrl_handler(struct tegra_vi_channel *chan) return chan->ctrl_handler.error; } - subdev =tegra_channel_get_remote_source_subdev (chan); -if (!subdev) -return -ENODEV ; - - ret =v4l2_ctrl_add_handler (&chan->ctrl_handler, subdev->ctrl_handler, -NULL , true); -if (ret <0 ) { -dev_err (chan->vi->dev, -"failed to add subdev %s ctrl handler: %d\n" , - subdev->name, ret); -v4l2_ctrl_handler_free (&chan->ctrl_handler); -return ret; - } - - hflip =v4l2_ctrl_find (subdev->ctrl_handler,V4L2_CID_HFLIP ); -if (chan->vi->soc->has_h_v_flip && !hflip) +if (chan->vi->soc->has_h_v_flip) {v4l2_ctrl_new_std (&chan->ctrl_handler, &vi_ctrl_ops,V4L2_CID_HFLIP ,0 ,1 ,1 ,0 ); - - vflip =v4l2_ctrl_find (subdev->ctrl_handler,V4L2_CID_VFLIP ); -if (chan->vi->soc->has_h_v_flip && !vflip)v4l2_ctrl_new_std (&chan->ctrl_handler, &vi_ctrl_ops,V4L2_CID_VFLIP ,0 ,1 ,1 ,0 ); + }#endif /* setup the controls */
Signature · 1 line
2.53.0
PATCH v2 3/15 media: tegra-video: vi: Expose all sub-devices in the pipeline
In reply to Svyatoslav RyhelAdd support for exposing /dev/v4l-subdev* nodes for the CSI and VIP bridge sub-devices to userspace by setting V4L2_SUBDEV_FL_HAS_DEVNODE flag. Call v4l2_device_register_subdev_nodes() in the async complete notifier callback to expose all devices in the pipeline, including auxiliary ones.
--- drivers/media/platform/nvidia/tegra-video/Kconfig | 1 + drivers/media/platform/nvidia/tegra-video/csi.c | 1 + drivers/media/platform/nvidia/tegra-video/vi.c | 14 ++++++++++++++ drivers/media/platform/nvidia/tegra-video/vip.c | 1 + 4 files changed, 17 insertions(+)
drivers/media/platform/nvidia/tegra-video/Kconfig +1 -0
@@ -5,6 +5,7 @@ config VIDEO_TEGRA depends on VIDEO_DEV select MEDIA_CONTROLLER select VIDEOBUF2_DMA_CONTIG + select VIDEO_V4L2_SUBDEV_API select V4L2_FWNODE help Choose this option if you have an NVIDIA Tegra SoC.
drivers/media/platform/nvidia/tegra-video/csi.c +1 -0
@@ -680,6 +680,7 @@ static int tegra_csi_channel_init(struct tegra_csi_channel *chan)v4l2_set_subdevdata (subdev, chan); subdev->fwnode =of_fwnode_handle (chan->of_node); subdev->entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ; + subdev->flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;/* initialize media entity pads */ ret = media_entity_pads_init(&subdev->entity, chan->numpads,
drivers/media/platform/nvidia/tegra-video/vi.c +14 -0
@@ -1392,6 +1392,12 @@ int tegra_v4l2_nodes_setup_tpg(struct tegra_video_device *vid) csi_chan =list_next_entry (csi_chan, list); } + ret =v4l2_device_register_subdev_nodes (&vid->v4l2_dev); +if (ret) { +dev_err (vi->dev,"failed to register subdev nodes\n" ); + goto cleanup; + } +return 0 ; cleanup:
@@ -1548,12 +1554,14 @@ static int tegra_vi_graph_notify_complete(struct v4l2_async_notifier *notifier)struct tegra_vi_graph_entity *entity;struct v4l2_async_connection *asd;struct v4l2_subdev *subdev; +struct tegra_video_device *vid;struct tegra_vi_channel *chan;struct tegra_vi *vi;int ret; chan = container_of(notifier, struct tegra_vi_channel, notifier); vi = chan->vi; + vid =dev_get_drvdata (vi->client.host);dev_dbg (vi->dev,"notify complete, all subdevs registered\n" );
@@ -1610,6 +1618,12 @@ static int tegra_vi_graph_notify_complete(struct v4l2_async_notifier *notifier) subdev =tegra_channel_get_remote_source_subdev (chan);v4l2_set_subdev_hostdata (subdev, chan); + ret =v4l2_device_register_subdev_nodes (&vid->v4l2_dev); +if (ret) { +dev_err (vi->dev,"failed to register subdev nodes\n" ); + goto unregister_video; + } +return 0 ; unregister_video:
drivers/media/platform/nvidia/tegra-video/vip.c +1 -0
@@ -165,6 +165,7 @@ static int tegra_vip_channel_init(struct tegra_vip *vip)v4l2_set_subdevdata (subdev, &vip->chan); subdev->fwnode =of_fwnode_handle (vip->chan.of_node); subdev->entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ; + subdev->flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; err =media_entity_pads_init (&subdev->entity,TEGRA_VIP_PADS_NUM , vip->chan.pads);if (err)
Signature · 1 line
2.53.0
PATCH v2 4/15 media: tegra-video: vi: Drop subdevice passthrough and input ioctls
In reply to Svyatoslav RyhelDrop V4L2 video device ioctl callbacks in tegra_channel_ioctl_ops that simply proxy stream parameters, frame intervals, selection, EDID, or DV timings to the remote source subdevice, as part of moving the driver to a media-controller pipeline model.
--- .../media/platform/nvidia/tegra-video/vi.c | 269 +----------------- 1 file changed, 1 insertion(+), 268 deletions(-)
drivers/media/platform/nvidia/tegra-video/vi.c +1 -268
@@ -308,26 +308,6 @@ static int tegra_channel_querycap(struct file *file, void *fh,return 0 ; } -static int tegra_channel_g_parm (struct file *file,void *fh, -struct v4l2_streamparm *a) -{ -struct tegra_vi_channel *chan =video_drvdata (file); -struct v4l2_subdev *subdev; - - subdev =tegra_channel_get_remote_source_subdev (chan); -return v4l2_g_parm_cap (&chan->video, subdev, a); -} - -static int tegra_channel_s_parm (struct file *file,void *fh, -struct v4l2_streamparm *a) -{ -struct tegra_vi_channel *chan =video_drvdata (file); -struct v4l2_subdev *subdev; - - subdev =tegra_channel_get_remote_source_subdev (chan); -return v4l2_s_parm_cap (&chan->video, subdev, a); -} -static int tegra_channel_enum_framesizes (struct file *file,void *fh,struct v4l2_frmsizeenum *sizes) {
@@ -358,38 +338,6 @@ static int tegra_channel_enum_framesizes(struct file *file, void *fh,return 0 ; } -static int tegra_channel_enum_frameintervals (struct file *file,void *fh, -struct v4l2_frmivalenum *ivals) -{ -int ret; -struct tegra_vi_channel *chan =video_drvdata (file); -struct v4l2_subdev *subdev; -const struct tegra_video_format *fmtinfo; -struct v4l2_subdev_frame_interval_enum fie = { - .index = ivals->index, - .width = ivals->width, - .height = ivals->height, - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - }; - - fmtinfo =tegra_get_format_by_fourcc (chan->vi, ivals->pixel_format); -if (!fmtinfo) -return -EINVAL ; - - fie.code = fmtinfo->code; - - subdev =tegra_channel_get_remote_source_subdev (chan); - ret =v4l2_subdev_call (subdev, pad, enum_frame_interval,NULL , &fie); -if (ret) -return ret; - - ivals->type =V4L2_FRMIVAL_TYPE_DISCRETE ; - ivals->discrete.numerator = fie.interval.numerator; - ivals->discrete.denominator = fie.interval.denominator; - -return 0 ; -} -static int tegra_channel_enum_format (struct file *file,void *fh,struct v4l2_fmtdesc *f) {
@@ -601,203 +549,6 @@ tegra_channel_subscribe_event(struct v4l2_fh *fh,return v4l2_ctrl_subscribe_event (fh, sub); } -static int tegra_channel_g_selection (struct file *file,void *priv, -struct v4l2_selection *sel) -{ -struct tegra_vi_channel *chan =video_drvdata (file); -struct v4l2_subdev *subdev; -struct v4l2_subdev_format fmt = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - }; -struct v4l2_subdev_selection sdsel = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - .target = sel->target, - }; -int ret; - - subdev =tegra_channel_get_remote_source_subdev (chan); -if (!v4l2_subdev_has_op (subdev, pad, get_selection)) -return -ENOTTY ; - -if (sel->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE ) -return -EINVAL ; -/* -* Try the get selection operation and fallback to get format if not -* implemented. -*/ - ret =v4l2_subdev_call (subdev, pad, get_selection,NULL ,NULL , &sdsel); -if (!ret) - sel->r = sdsel.r; -if (ret != -ENOIOCTLCMD ) -return ret; - - ret =v4l2_subdev_call (subdev, pad, get_fmt,NULL , &fmt); -if (ret <0 ) -return ret; - - sel->r.left =0 ; - sel->r.top =0 ; - sel->r.width = fmt.format.width; - sel->r.height = fmt.format.height; - -return 0 ; -} - -static int tegra_channel_s_selection (struct file *file,void *fh, -struct v4l2_selection *sel) -{ -struct tegra_vi_channel *chan =video_drvdata (file); -struct v4l2_subdev *subdev; -int ret; -struct v4l2_subdev_selection sdsel = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - .target = sel->target, - .flags = sel->flags, - .r = sel->r, - }; - - subdev =tegra_channel_get_remote_source_subdev (chan); -if (!v4l2_subdev_has_op (subdev, pad, set_selection)) -return -ENOTTY ; - -if (sel->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE ) -return -EINVAL ; - -if (vb2_is_busy (&chan->queue)) -return -EBUSY ; - - ret =v4l2_subdev_call (subdev, pad, set_selection,NULL ,NULL , &sdsel); -if (!ret) { - sel->r = sdsel.r; -/* -* Subdev active format resolution may have changed during -* set selection operation. So, update channel format to -* the sub-device active format. -*/ -return tegra_channel_set_subdev_active_fmt (chan); - } - -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) -{ -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, g_dv_timings)) -return -ENOTTY ; - -return v4l2_device_call_until_err (chan->video.v4l2_dev,0 , - pad, g_dv_timings,0 , 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, pad, 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 , - pad, s_dv_timings,0 , 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; - chan->vi->ops->vi_fmt_align (&chan->format, chan->fmtinfo->bpp); -tegra_channel_update_gangports (chan); - -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, pad, query_dv_timings)) -return -ENOTTY ; - -return v4l2_device_call_until_err (chan->video.v4l2_dev,0 , - pad, query_dv_timings,0 , 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_log_status (struct file *file,void *fh) {struct tegra_vi_channel *chan =video_drvdata (file);
@@ -810,17 +561,11 @@ static int tegra_channel_log_status(struct file *file, void *fh)static int tegra_channel_enum_input (struct file *file,void *fh,struct v4l2_input *inp) { -struct tegra_vi_channel *chan =video_drvdata (file); -struct v4l2_subdev *subdev; -if (inp->index)return -EINVAL ; inp->type =V4L2_INPUT_TYPE_CAMERA ; - subdev =tegra_channel_get_remote_source_subdev (chan); -strscpy (inp->name, subdev->name,sizeof (inp->name)); -if (v4l2_subdev_has_op (subdev, pad, dv_timings_cap)) - inp->capabilities =V4L2_IN_CAP_DV_TIMINGS ; +strscpy (inp->name,"Camera" ,sizeof (inp->name));return 0 ; }
@@ -844,10 +589,7 @@ static int tegra_channel_s_input(struct file *file, void *priv,static const struct v4l2_ioctl_ops tegra_channel_ioctl_ops = { .vidioc_querycap = tegra_channel_querycap, - .vidioc_g_parm = tegra_channel_g_parm, - .vidioc_s_parm = tegra_channel_s_parm, .vidioc_enum_framesizes = tegra_channel_enum_framesizes, - .vidioc_enum_frameintervals = tegra_channel_enum_frameintervals, .vidioc_enum_fmt_vid_cap = tegra_channel_enum_format, .vidioc_g_fmt_vid_cap = tegra_channel_get_format, .vidioc_s_fmt_vid_cap = tegra_channel_set_format,
@@ -866,15 +608,6 @@ static const struct v4l2_ioctl_ops tegra_channel_ioctl_ops = { .vidioc_streamoff = vb2_ioctl_streamoff, .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, - .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, - .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.53.0
PATCH v2 5/15 media: tegra-video: vi: Build bitmap of formats compatible with CSI/VIP instead of source
In reply to Svyatoslav RyhelTegra VI supports media bus formats that map to the same pixel format entry (mostly YUV formats). This is required for supporting both CSI and VIP. Since vidioc_enum_fmt_vid_cap() exposes pixel formats, it cannot expose the same format for multiple media bus codes. Enumerate pixel formats matching those supported by the attached CSI or VIP bridge.
Remove tegra_channel_set_subdev_active_fmt() so channel format enumeration no longer depends on subdevice media bus enumeration during graph completion.
--- .../media/platform/nvidia/tegra-video/vi.c | 39 +------------------ 1 file changed, 2 insertions(+), 37 deletions(-)
drivers/media/platform/nvidia/tegra-video/vi.c +2 -37
@@ -504,39 +504,6 @@ static int tegra_channel_set_format(struct file *file, void *fh,return 0 ; } -static int tegra_channel_set_subdev_active_fmt (struct tegra_vi_channel *chan) -{ -int ret, index; -struct v4l2_subdev *subdev; -struct v4l2_subdev_format fmt = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - }; - -/* -* Initialize channel format to the sub-device active format if there -* is corresponding match in the Tegra supported video formats. -*/ - subdev =tegra_channel_get_remote_source_subdev (chan); - ret =v4l2_subdev_call (subdev, pad, get_fmt,NULL , &fmt); -if (ret) -return ret; - - index =tegra_get_format_idx_by_code (chan->vi, fmt.format.code,0 ); -if (index <0 ) -return -EINVAL ; - - chan->fmtinfo = &chan->vi->soc->video_formats[index]; -v4l2_fill_pix_format (&chan->format, &fmt.format); - chan->format.pixelformat = chan->fmtinfo->fourcc; - chan->format.bytesperline = chan->format.width * chan->fmtinfo->bpp; - chan->format.sizeimage = chan->format.bytesperline * - chan->format.height; - chan->vi->ops->vi_fmt_align (&chan->format, chan->fmtinfo->bpp); -tegra_channel_update_gangports (chan); - -return 0 ; -} -static int tegra_channel_subscribe_event (struct v4l2_fh *fh,const struct v4l2_event_subscription *sub)
@@ -752,7 +719,7 @@ static int vi_fmts_bitmap_init(struct tegra_vi_channel *chan)* available media bus formats of sub-device and the pre-defined Tegra * supported video formats. */ - subdev =tegra_channel_get_remote_source_subdev (chan); + subdev =tegra_channel_get_remote_bridge_subdev (chan);while (1 ) { ret =v4l2_subdev_call (subdev, pad, enum_mbus_code,NULL , &code);
@@ -786,9 +753,6 @@ static int vi_fmts_bitmap_init(struct tegra_vi_channel *chan)bitmap_set (chan->fmts_bitmap, index,1 ); } -/* initialize channel format to the sub-device active format */ -tegra_channel_set_subdev_active_fmt (chan); -return 0 ; }
@@ -838,6 +802,7 @@ static int tegra_channel_init(struct tegra_vi_channel *chan) chan->format.bytesperline =TEGRA_DEF_WIDTH * chan->fmtinfo->bpp; chan->format.sizeimage = chan->format.bytesperline *TEGRA_DEF_HEIGHT ; vi->ops->vi_fmt_align (&chan->format, chan->fmtinfo->bpp); +tegra_channel_update_gangports (chan); ret = vi->ops->channel_host1x_syncpt_init (chan);if (ret)
Signature · 1 line
2.53.0
PATCH v2 6/15 media: tegra-video: Expose SoC stepwise frame size limits
In reply to Svyatoslav RyhelAdd a const struct v4l2_frmsize_stepwise *framesize field to struct tegra_vi_soc to define Tegra20 and Tegra210 frame size limits. This will be needed for CSI/VIP and VI frame-related operations.
--- drivers/media/platform/nvidia/tegra-video/tegra20.c | 10 ++++++++++ drivers/media/platform/nvidia/tegra-video/tegra210.c | 10 ++++++++++ drivers/media/platform/nvidia/tegra-video/vi.h | 2 ++ 3 files changed, 22 insertions(+)
drivers/media/platform/nvidia/tegra-video/tegra20.c +10 -0
@@ -809,6 +809,15 @@ static const struct tegra_vi_ops tegra20_vi_ops = { .vi_stop_streaming = tegra20_vi_stop_streaming, }; +static const struct v4l2_frmsize_stepwise tegra20_video_framesize = { + .min_width =TEGRA20_MIN_WIDTH , + .max_width =TEGRA20_MAX_WIDTH , + .step_width =2 , + .min_height =TEGRA20_MIN_HEIGHT , + .max_height =TEGRA20_MAX_HEIGHT , + .step_height =2 , +}; +#define TEGRA20_VIDEO_FMT (DATA_TYPE ,BIT_WIDTH ,MBUS_CODE ,BPP ,FOURCC ) \ { \ .img_dt = TEGRA_IMAGE_DT_##DATA_TYPE, \
@@ -850,6 +859,7 @@ const struct tegra_vi_soc tegra20_vi_soc = { .nformats = ARRAY_SIZE(tegra20_video_formats), .default_video_format = &tegra20_video_formats[0], .ops = &tegra20_vi_ops, + .framesize = &tegra20_video_framesize, .hw_revision = 1, .vi_max_channels = 2, /* TEGRA_VI_OUT_1 and TEGRA_VI_OUT_2 */ .vi_max_clk_hz = 450000000,
drivers/media/platform/nvidia/tegra-video/tegra210.c +10 -0
@@ -705,6 +705,15 @@ static void tegra210_vi_stop_streaming(struct vb2_queue *vq)video_device_pipeline_stop (&chan->video); } +static const struct v4l2_frmsize_stepwise tegra210_video_framesize = { + .min_width =TEGRA210_MIN_WIDTH , + .max_width =TEGRA210_MAX_WIDTH , + .step_width =2 , + .min_height =TEGRA210_MIN_HEIGHT , + .max_height =TEGRA210_MAX_HEIGHT , + .step_height =2 , +}; +/* * Tegra210 VI Pixel memory format enum. * These format enum value gets programmed into corresponding Tegra VI
@@ -815,6 +824,7 @@ const struct tegra_vi_soc tegra210_vi_soc = { .video_formats = tegra210_video_formats, .nformats = ARRAY_SIZE(tegra210_video_formats), .ops = &tegra210_vi_ops, + .framesize = &tegra210_video_framesize, .hw_revision = 3, .vi_max_channels = 6,#if IS_ENABLED (CONFIG_VIDEO_TEGRA_TPG )
drivers/media/platform/nvidia/tegra-video/vi.h +2 -0
@@ -71,6 +71,7 @@ struct tegra_vi_ops {* @nformats: total video formats * @default_video_format: default video format (pointer to a @video_formats item) * @ops: vi operations +* @framesize: frame size limitations * @hw_revision: VI hw_revision * @vi_max_channels: supported max streaming channels * @vi_max_clk_hz: VI clock max frequency
@@ -81,6 +82,7 @@ struct tegra_vi_soc {const unsigned int nformats;const struct tegra_video_format *default_video_format;const struct tegra_vi_ops *ops; +const struct v4l2_frmsize_stepwise *framesize;u32 hw_revision;unsigned int vi_max_channels;unsigned int vi_max_clk_hz;
Signature · 1 line
2.53.0
PATCH v2 7/15 media: tegra-video: vi: Match fourcc against channel format bitmap
In reply to Svyatoslav RyhelFrom: Jonas Schwöbel <[email protected]>
Update tegra_get_format_by_fourcc() to accept a struct tegra_vi_channel pointer and match fourcc values against the channel's TPG or subdevice format bitmap, updating callers in vi.c accordingly.
This is required because VI supports different media bus formats with the same pixel format, so only the first matching instance would be returned without checking whether the index is among the supported formats.
--- .../media/platform/nvidia/tegra-video/vi.c | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-)
drivers/media/platform/nvidia/tegra-video/vi.c +17 -10
@@ -88,16 +88,24 @@ static u32 tegra_get_format_fourcc_by_idx(struct tegra_vi *vi, }static const struct tegra_video_format * -tegra_get_format_by_fourcc (struct tegra_vi *vi,u32 fourcc) +tegra_get_format_by_fourcc (struct tegra_vi_channel *chan,u32 fourcc) { +unsigned long *fmts_bitmap = chan->tpg_fmts_bitmap; +struct tegra_vi *vi = chan->vi;unsigned int i; -for (i =0 ; i < vi->soc->nformats; ++i) { +if (!IS_ENABLED (CONFIG_VIDEO_TEGRA_TPG )) + fmts_bitmap = chan->fmts_bitmap; + +for (i =0 ; i < vi->soc->nformats; ++i)if (vi->soc->video_formats[i].fourcc == fourcc) -return &vi->soc->video_formats[i]; - } +if (test_bit (i, fmts_bitmap)) +break ; -return NULL ; +if (i >= vi->soc->nformats) +return NULL ; + +return &vi->soc->video_formats[i]; }/*
@@ -320,7 +328,7 @@ static int tegra_channel_enum_framesizes(struct file *file, void *fh, .which = V4L2_SUBDEV_FORMAT_ACTIVE, }; - fmtinfo =tegra_get_format_by_fourcc (chan->vi, sizes->pixel_format); + fmtinfo =tegra_get_format_by_fourcc (chan, sizes->pixel_format);if (!fmtinfo)return -EINVAL ;
@@ -403,12 +411,11 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,* Retrieve the format information and if requested format isn't * supported, keep the current format. */ - fmtinfo =tegra_get_format_by_fourcc (chan->vi, pix->pixelformat); + fmtinfo =tegra_get_format_by_fourcc (chan, pix->pixelformat);if (!fmtinfo) { pix->pixelformat = chan->format.pixelformat; pix->colorspace = chan->format.colorspace; - fmtinfo =tegra_get_format_by_fourcc (chan->vi, - pix->pixelformat); + fmtinfo =tegra_get_format_by_fourcc (chan, pix->pixelformat); } pix->field =V4L2_FIELD_NONE ;
@@ -485,7 +492,7 @@ static int tegra_channel_set_format(struct file *file, void *fh,if (ret)return ret; - fmtinfo =tegra_get_format_by_fourcc (chan->vi, pix->pixelformat); + fmtinfo =tegra_get_format_by_fourcc (chan, pix->pixelformat); fmt.pad =0 ;v4l2_fill_mbus_format (&fmt.format, pix, fmtinfo->code);
Signature · 1 line
2.53.0
PATCH v2 8/15 media: tegra-video: vi: Report stepwise frame sizes instead of querying subdev
In reply to Svyatoslav RyhelUpdate tegra_channel_enum_framesizes() to return frame sizes supported by VI instead of forwarding enum_frame_size to the remote source subdevice.
--- .../media/platform/nvidia/tegra-video/vi.c | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-)
drivers/media/platform/nvidia/tegra-video/vi.c +6 -16
@@ -319,29 +319,19 @@ static int tegra_channel_querycap(struct file *file, void *fh,static int tegra_channel_enum_framesizes (struct file *file,void *fh,struct v4l2_frmsizeenum *sizes) { -int ret;struct tegra_vi_channel *chan =video_drvdata (file); -struct v4l2_subdev *subdev;const struct tegra_video_format *fmtinfo; -struct v4l2_subdev_frame_size_enum fse = { - .index = sizes->index, - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - }; +struct tegra_vi *vi = chan->vi; + +if (sizes->index !=0 ) +return -EINVAL ; fmtinfo =tegra_get_format_by_fourcc (chan, sizes->pixel_format);if (!fmtinfo)return -EINVAL ; - fse.code = fmtinfo->code; - - subdev =tegra_channel_get_remote_source_subdev (chan); - ret =v4l2_subdev_call (subdev, pad, enum_frame_size,NULL , &fse); -if (ret) -return ret; - - sizes->type =V4L2_FRMSIZE_TYPE_DISCRETE ; - sizes->discrete.width = fse.max_width; - sizes->discrete.height = fse.max_height; + sizes->type =V4L2_FRMSIZE_TYPE_STEPWISE ; +memcpy (&sizes->stepwise, vi->soc->framesize,sizeof (sizes->stepwise));return 0 ; }
Signature · 1 line
2.53.0
PATCH v2 9/15 media: tegra-video: vi: Configure capture format locally without subdev calls
In reply to Svyatoslav RyhelSimplify __tegra_channel_try_format() and tegra_channel_set_format() to validate, align, and store the capture pixel format locally on the video channel instead of querying or setting formats on the remote subdevice and allocating temporary subdev state.
--- .../media/platform/nvidia/tegra-video/vi.c | 90 +++---------------- 1 file changed, 12 insertions(+), 78 deletions(-)
drivers/media/platform/nvidia/tegra-video/vi.c +12 -78
@@ -366,37 +366,11 @@ static int tegra_channel_get_format(struct file *file, void *fh, }static int __tegra_channel_try_format (struct tegra_vi_channel *chan, -struct v4l2_pix_format *pix) +struct v4l2_pix_format *pix, +const struct tegra_video_format **tfmtinfo) {const struct tegra_video_format *fmtinfo; -static struct lock_class_key key; -struct v4l2_subdev *subdev; -struct v4l2_subdev_format fmt = { - .which =V4L2_SUBDEV_FORMAT_TRY , - }; -struct v4l2_subdev_state *sd_state; -struct v4l2_subdev_frame_size_enum fse = { - .which =V4L2_SUBDEV_FORMAT_TRY , - }; -struct v4l2_subdev_selection sdsel = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - .target =V4L2_SEL_TGT_CROP_BOUNDS , - }; -struct v4l2_rect *try_crop; -int ret =0 ; - - subdev =tegra_channel_get_remote_source_subdev (chan); -if (!subdev) -return -ENODEV ; -/* -* FIXME: Drop this call, drivers are not supposed to use -* __v4l2_subdev_state_alloc(). -*/ - sd_state =__v4l2_subdev_state_alloc (subdev,"tegra:state->lock" , - &key); -if (IS_ERR (sd_state)) -return PTR_ERR (sd_state);/* * Retrieve the format information and if requested format isn't * supported, keep the current format.
@@ -408,42 +382,18 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan, fmtinfo =tegra_get_format_by_fourcc (chan, pix->pixelformat); } - pix->field =V4L2_FIELD_NONE ; - fmt.pad =0 ; -v4l2_fill_mbus_format (&fmt.format, pix, fmtinfo->code); +if (tfmtinfo) + *tfmtinfo = fmtinfo; -/* -* Attempt to obtain the format size from subdev. -* If not available, try to get crop boundary from subdev. -*/ - try_crop =v4l2_subdev_state_get_crop (sd_state,0 ); - fse.code = fmtinfo->code; - ret =v4l2_subdev_call (subdev, pad, enum_frame_size, sd_state, &fse); -if (ret) { -if (!v4l2_subdev_has_op (subdev, pad, get_selection) || -v4l2_subdev_call (subdev, pad, get_selection,NULL ,NULL , &sdsel)) { - try_crop->width =0 ; - try_crop->height =0 ; - }else { - try_crop->width = sdsel.r.width; - try_crop->height = sdsel.r.height; - } - }else { - try_crop->width = fse.max_width; - try_crop->height = fse.max_height; - } - - ret =v4l2_subdev_call (subdev, pad, set_fmt,NULL , sd_state, &fmt); -if (ret <0 ) - goto out_free; + pix->field =V4L2_FIELD_NONE ; + pix->colorspace = chan->format.colorspace; + pix->xfer_func =V4L2_XFER_FUNC_DEFAULT ; + pix->ycbcr_enc =V4L2_YCBCR_ENC_DEFAULT ; + pix->quantization =V4L2_QUANTIZATION_DEFAULT ; -v4l2_fill_pix_format (pix, &fmt.format); chan->vi->ops->vi_fmt_align (pix, fmtinfo->bpp); -out_free: -__v4l2_subdev_state_free (sd_state); - -return ret; +return 0 ; } static int tegra_channel_try_format(struct file *file, void *fh,
@@ -451,7 +401,7 @@ static int tegra_channel_try_format(struct file *file, void *fh, {struct tegra_vi_channel *chan =video_drvdata (file); -return __tegra_channel_try_format (chan, &format->fmt.pix); +return __tegra_channel_try_format (chan, &format->fmt.pix,NULL ); }static void tegra_channel_update_gangports (struct tegra_vi_channel *chan)
@@ -467,10 +417,6 @@ static int tegra_channel_set_format(struct file *file, void *fh, {struct tegra_vi_channel *chan =video_drvdata (file);const struct tegra_video_format *fmtinfo; -struct v4l2_subdev_format fmt = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - }; -struct v4l2_subdev *subdev;struct v4l2_pix_format *pix = &format->fmt.pix;int ret;
@@ -478,22 +424,10 @@ static int tegra_channel_set_format(struct file *file, void *fh,return -EBUSY ;/* get supported format by try_fmt */ - ret =__tegra_channel_try_format (chan, pix); + ret =__tegra_channel_try_format (chan, pix, &fmtinfo);if (ret)return ret; - fmtinfo =tegra_get_format_by_fourcc (chan, pix->pixelformat); - - fmt.pad =0 ; -v4l2_fill_mbus_format (&fmt.format, pix, fmtinfo->code); - subdev =tegra_channel_get_remote_source_subdev (chan); - ret =v4l2_subdev_call (subdev, pad, set_fmt,NULL ,NULL , &fmt); -if (ret <0 ) -return ret; - -v4l2_fill_pix_format (pix, &fmt.format); - chan->vi->ops->vi_fmt_align (pix, fmtinfo->bpp); - chan->format = *pix; chan->fmtinfo = fmtinfo;tegra_channel_update_gangports (chan);
Signature · 1 line
2.53.0
PATCH v2 10/15 media: tegra-video: vi: Implement link_validate for video entity
In reply to Svyatoslav RyhelAdd tegra_channel_link_validate() and attach it via tegra_channel_media_ops to chan->video.entity.ops to verify that the remote subdevice pad's active format (dimensions and media bus code) matches the channel's configured format during media pipeline validation.
--- .../media/platform/nvidia/tegra-video/vi.c | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/media/platform/nvidia/tegra-video/vi.c +41 -0
@@ -485,6 +485,46 @@ static int tegra_channel_s_input(struct file *file, void *priv,return 0 ; } +static int tegra_channel_link_validate (struct media_link *link) +{ +struct video_device *video = +media_entity_to_video_device (link->sink->entity); +struct v4l2_subdev *subdev = +media_entity_to_v4l2_subdev (link->source->entity); +struct tegra_vi_channel *chan =video_get_drvdata (video); +struct v4l2_subdev_format fmt = { + .which =V4L2_SUBDEV_FORMAT_ACTIVE , + .pad = link->source->index, + }; +int ret; + +if (!chan->fmtinfo) +return -EPIPE ; + + ret =v4l2_subdev_call (subdev, pad, get_fmt,NULL , &fmt); +if (ret) +return ret; + +if (fmt.format.height != chan->format.height || + fmt.format.width != chan->format.width || + fmt.format.code != chan->fmtinfo->code) { +dev_dbg (chan->vi->dev, +"link '%s':%u -> '%s':%u not valid: 0x%04x/%ux%u != 0x%04x/%ux%u\n" , + link->source->entity->name, link->source->index, + link->sink->entity->name, link->sink->index, + fmt.format.code, fmt.format.width, fmt.format.height, + chan->fmtinfo->code, chan->format.width, + chan->format.height); +return -EPIPE ; + } + +return 0 ; +} + +static const struct media_entity_operations tegra_channel_media_ops = { + .link_validate = tegra_channel_link_validate, +}; +static const struct v4l2_ioctl_ops tegra_channel_ioctl_ops = { .vidioc_querycap = tegra_channel_querycap, .vidioc_enum_framesizes = tegra_channel_enum_framesizes,
@@ -764,6 +804,7 @@ static int tegra_channel_init(struct tegra_vi_channel *chan) dev_name(vi->dev), "output", chan->portnos[0]); chan->video.vfl_type =VFL_TYPE_VIDEO ; chan->video.vfl_dir =VFL_DIR_RX ; + chan->video.entity.ops = &tegra_channel_media_ops; chan->video.ioctl_ops = &tegra_channel_ioctl_ops; chan->video.ctrl_handler = &chan->ctrl_handler; chan->video.lock = &chan->video_lock;
Signature · 1 line
2.53.0
PATCH v2 11/15 media: tegra-video: video: Resolve video device via media graph on notifications
In reply to Svyatoslav RyhelWalk downstream from the notifying subdevice along source pad links via find_pipeline_video_device() to locate the associated video_device and channel instead of relying on v4l2_get_subdev_hostdata(sd), and filter notifications to V4L2_EVENT_SOURCE_CHANGE before forwarding events and marking streaming vb2 queues in error.
--- .../media/platform/nvidia/tegra-video/video.c | 74 +++++++++++++++---- 1 file changed, 59 insertions(+), 15 deletions(-)
drivers/media/platform/nvidia/tegra-video/video.c +59 -15
@@ -7,38 +7,82 @@#include <linux/module.h> #include <linux/platform_device.h> +#include <media/media-entity.h> +#include <media/v4l2-dev.h> #include <media/v4l2-event.h> +#include <media/v4l2-subdev.h> #include "video.h" -static void tegra_v4l2_dev_release (struct v4l2_device *v4l2_dev) +/* Walk from the caller to the video device via active links */ +static struct video_device *find_pipeline_video_device (struct v4l2_subdev *sd) { -struct tegra_video_device *vid; +struct media_entity *entity = &sd->entity; +struct video_device *vdev =NULL ; - vid = container_of(v4l2_dev, struct tegra_video_device, v4l2_dev); +while (entity) { +struct media_pad *src_pad =NULL ; +struct media_pad *remote_pad; +unsigned int i; -/* cleanup channels here as all video device nodes are released */ -tegra_channels_cleanup (vid->vi); +if (is_media_entity_v4l2_video_device (entity)) { + vdev =media_entity_to_video_device (entity); +break ; + } -v4l2_device_unregister (v4l2_dev); -media_device_unregister (&vid->media_dev); -media_device_cleanup (&vid->media_dev); -kfree (vid); +for (i =0 ; i < entity->num_pads; i++) { +if (entity->pads[i].flags &MEDIA_PAD_FL_SOURCE ) { + src_pad = &entity->pads[i]; +break ; + } + } + +if (!src_pad) +break ; + + remote_pad =media_pad_remote_pad_first (src_pad); +if (!remote_pad) +break ; + + entity = remote_pad->entity; + } + +return vdev; }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; +struct video_device *video; -if (notification !=V4L2_DEVICE_NOTIFY_EVENT ) +if (notification !=V4L2_DEVICE_NOTIFY_EVENT || + ev->type !=V4L2_EVENT_SOURCE_CHANGE )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); + video =find_pipeline_video_device (sd); +if (video) { +struct tegra_vi_channel *chan =video_get_drvdata (video); + +v4l2_event_queue (video, ev); +if (vb2_is_streaming (&chan->queue)) +vb2_queue_error (&chan->queue); + } +} + +static void tegra_v4l2_dev_release (struct v4l2_device *v4l2_dev) +{ +struct tegra_video_device *vid; + + vid = container_of(v4l2_dev, struct tegra_video_device, v4l2_dev); + +/* cleanup channels here as all video device nodes are released */ +tegra_channels_cleanup (vid->vi); + +v4l2_device_unregister (v4l2_dev); +media_device_unregister (&vid->media_dev); +media_device_cleanup (&vid->media_dev); +kfree (vid); }static int host1x_video_probe (struct host1x_device *dev)
Signature · 1 line
2.53.0
PATCH v2 12/15 media: tegra-video: Remove remote source subdev helper
In reply to Svyatoslav RyhelLook up the remote source subdevice directly via media_entity_remote_source_pad_unique() in csi_get_pixel_rate(), tegra_csi_enable_stream(), and tegra_csi_disable_stream(), allowing tegra_channel_get_remote_source_subdev() and its subdev hostdata setup in VI to be removed.
--- .../media/platform/nvidia/tegra-video/csi.c | 31 ++++++++++++++----- .../media/platform/nvidia/tegra-video/vi.c | 30 ------------------ .../media/platform/nvidia/tegra-video/vi.h | 2 -- 3 files changed, 23 insertions(+), 40 deletions(-)
drivers/media/platform/nvidia/tegra-video/csi.c +23 -8
@@ -282,12 +282,18 @@ static int csi_init_state(struct v4l2_subdev *sd,static unsigned int csi_get_pixel_rate (struct tegra_csi_channel *csi_chan) { -struct tegra_vi_channel *chan; +struct v4l2_subdev *subdev = &csi_chan->subdev;struct v4l2_subdev *src_subdev;struct v4l2_ctrl *ctrl; +struct media_pad *pad; - chan =v4l2_get_subdev_hostdata (&csi_chan->subdev); - src_subdev =tegra_channel_get_remote_source_subdev (chan); + pad =media_entity_remote_source_pad_unique (&subdev->entity); +if (IS_ERR (pad) || !is_media_entity_v4l2_subdev (pad->entity)) { +dev_err (csi_chan->csi->dev,"failed to get source entity\n" ); +return 0 ; + } + + src_subdev =media_entity_to_v4l2_subdev (pad->entity); ctrl =v4l2_ctrl_find (src_subdev->ctrl_handler,V4L2_CID_PIXEL_RATE );if (ctrl)return v4l2_ctrl_g_ctrl_int64 (ctrl);
@@ -383,6 +389,8 @@ static int tegra_csi_enable_stream(struct v4l2_subdev *subdev)if (csi_chan->mipi) {struct v4l2_subdev *src_subdev; +struct media_pad *pad; +/* * TRM has incorrectly documented to wait for done status from * calibration logic after CSI interface power on.
@@ -392,9 +400,12 @@ static int tegra_csi_enable_stream(struct v4l2_subdev *subdev)* CSI subdev stream-on triggers start of MIPI pads calibration. * Wait for calibration to finish here after sensor subdev stream-on. */ - src_subdev =tegra_channel_get_remote_source_subdev (chan); - ret =v4l2_subdev_call (src_subdev, video, s_stream, true); + pad =media_entity_remote_source_pad_unique (&subdev->entity); +if (IS_ERR (pad) || !is_media_entity_v4l2_subdev (pad->entity)) + goto disable_csi_stream; + src_subdev =media_entity_to_v4l2_subdev (pad->entity); + ret =v4l2_subdev_call (src_subdev, video, s_stream, true);if (ret <0 && ret != -ENOIOCTLCMD ) goto disable_csi_stream;
@@ -425,7 +436,6 @@ static int tegra_csi_enable_stream(struct v4l2_subdev *subdev)static int tegra_csi_disable_stream (struct v4l2_subdev *subdev) { -struct tegra_vi_channel *chan =v4l2_get_subdev_hostdata (subdev);struct tegra_csi_channel *csi_chan =to_csi_chan (subdev);struct tegra_csi *csi = csi_chan->csi;int err;
@@ -436,11 +446,16 @@ static int tegra_csi_disable_stream(struct v4l2_subdev *subdev)*/ if (csi_chan->mipi) {struct v4l2_subdev *src_subdev; +struct media_pad *pad; + + pad =media_entity_remote_source_pad_unique (&subdev->entity); +if (IS_ERR (pad) || !is_media_entity_v4l2_subdev (pad->entity)) +dev_err (csi->dev,"failed to get source entity\n" ); - src_subdev =tegra_channel_get_remote_source_subdev (chan); + src_subdev =media_entity_to_v4l2_subdev (pad->entity); err =v4l2_subdev_call (src_subdev, video, s_stream, false);if (err <0 && err != -ENOIOCTLCMD ) -dev_err_probe (csi->dev, err,"source subdev stream off failed\n" ); +dev_err (csi->dev,"source subdev stream off failed: %d\n" , err); } csi->ops->csi_stop_streaming (csi_chan);
drivers/media/platform/nvidia/tegra-video/vi.c +0 -30
@@ -181,33 +181,6 @@ tegra_channel_get_remote_bridge_subdev(struct tegra_vi_channel *chan)return media_entity_to_v4l2_subdev (pad->entity); } -/* -* Walk up the chain until the initial source (e.g. image sensor) -*/ -struct v4l2_subdev * -tegra_channel_get_remote_source_subdev (struct tegra_vi_channel *chan) -{ -struct media_pad *pad; -struct v4l2_subdev *subdev; -struct media_entity *entity; - - subdev =tegra_channel_get_remote_bridge_subdev (chan); -if (!subdev) -return NULL ; - - pad = &subdev->entity.pads[0 ]; -while (!(pad->flags &MEDIA_PAD_FL_SOURCE )) { - pad =media_pad_remote_pad_first (pad); -if (!pad || !is_media_entity_v4l2_subdev (pad->entity)) -break ; - entity = pad->entity; - pad = &entity->pads[0 ]; - subdev =media_entity_to_v4l2_subdev (entity); - } - -return subdev; -} -static int tegra_channel_enable_stream (struct tegra_vi_channel *chan) {struct v4l2_subdev *subdev;
@@ -1285,9 +1258,6 @@ 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); - ret =v4l2_device_register_subdev_nodes (&vid->v4l2_dev);if (ret) {dev_err (vi->dev,"failed to register subdev nodes\n" );
drivers/media/platform/nvidia/tegra-video/vi.h +0 -2
@@ -303,8 +303,6 @@ extern const struct tegra_vi_soc tegra210_vi_soc;struct v4l2_subdev *tegra_channel_get_remote_csi_subdev (struct tegra_vi_channel *chan); -struct v4l2_subdev * -tegra_channel_get_remote_source_subdev (struct tegra_vi_channel *chan);int tegra_channel_set_stream (struct tegra_vi_channel *chan,bool on);void tegra_channel_release_buffers (struct tegra_vi_channel *chan,enum vb2_buffer_state state);
Signature · 1 line
2.53.0
PATCH v2 13/15 media: tegra-video: csi: Scope pad and state ops to TPG mode
In reply to Svyatoslav RyhelRename the CSI pad, state, and frame-interval callbacks to tegra_csi_tpg_*(), remove per-function CONFIG_VIDEO_TEGRA_TPG checks, and only attach pad ops, internal ops, and TPG blank-interval setup when CONFIG_VIDEO_TEGRA_TPG is enabled.
--- .../media/platform/nvidia/tegra-video/csi.c | 122 ++++++++---------- 1 file changed, 56 insertions(+), 66 deletions(-)
drivers/media/platform/nvidia/tegra-video/csi.c +56 -66
@@ -21,6 +21,10 @@#define MHZ 1000000 +/* +* Test pattern generator configuration +*/ +/* * CSI is a separate subdevice which has 6 source pads to generate * test pattern. CSI subdevice pad ops are used only for TPG and
@@ -52,13 +56,10 @@ static const struct v4l2_frmsize_discrete tegra_csi_tpg_sizes[] = {/* * V4L2 Subdevice Pad Operations */ -static int csi_enum_bus_code (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_mbus_code_enum *code) +static int tegra_csi_tpg_enum_bus_code (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_mbus_code_enum *code) { -if (!IS_ENABLED (CONFIG_VIDEO_TEGRA_TPG )) -return -ENOIOCTLCMD ; -if (code->index >=ARRAY_SIZE (tegra_csi_tpg_fmts))return -EINVAL ;
@@ -67,15 +68,12 @@ static int csi_enum_bus_code(struct v4l2_subdev *subdev,return 0 ; } -static int csi_get_format (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_format *fmt) +static int tegra_csi_tpg_get_format (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) {struct tegra_csi_channel *csi_chan =to_csi_chan (subdev); -if (!IS_ENABLED (CONFIG_VIDEO_TEGRA_TPG )) -return -ENOIOCTLCMD ; - fmt->format = csi_chan->format;return 0 ;
@@ -114,15 +112,12 @@ static void csi_chan_update_blank_intervals(struct tegra_csi_channel *csi_chan, } } -static int csi_enum_framesizes (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_frame_size_enum *fse) +static int tegra_csi_tpg_enum_framesizes (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_frame_size_enum *fse) {unsigned int i; -if (!IS_ENABLED (CONFIG_VIDEO_TEGRA_TPG )) -return -ENOIOCTLCMD ; -if (fse->index >=ARRAY_SIZE (tegra_csi_tpg_sizes))return -EINVAL ;
@@ -141,18 +136,15 @@ static int csi_enum_framesizes(struct v4l2_subdev *subdev,return 0 ; } -static int csi_enum_frameintervals (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_frame_interval_enum *fie) +static int tegra_csi_tpg_enum_frameintervals (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_frame_interval_enum *fie) {struct tegra_csi_channel *csi_chan =to_csi_chan (subdev);struct tegra_csi *csi = csi_chan->csi;const struct tpg_framerate *frmrate = csi->soc->tpg_frmrate_table;int index; -if (!IS_ENABLED (CONFIG_VIDEO_TEGRA_TPG )) -return -ENOIOCTLCMD ; -/* one framerate per format and resolution */ if (fie->index >0 )return -EINVAL ;
@@ -168,10 +160,10 @@ static int csi_enum_frameintervals(struct v4l2_subdev *subdev,return 0 ; } -static int csi_set_format (struct v4l2_subdev *subdev, -const struct v4l2_subdev_client_info *ci, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_format *fmt) +static int tegra_csi_tpg_set_format (struct v4l2_subdev *subdev, +const struct v4l2_subdev_client_info *ci, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) {struct tegra_csi_channel *csi_chan =to_csi_chan (subdev);struct v4l2_mbus_framefmt *format = &fmt->format;
@@ -181,9 +173,6 @@ static int csi_set_format(struct v4l2_subdev *subdev,struct v4l2_fract *interval;int index; -if (!IS_ENABLED (CONFIG_VIDEO_TEGRA_TPG )) -return -ENOIOCTLCMD ; - sizes = v4l2_find_nearest_size(tegra_csi_tpg_sizes, ARRAY_SIZE(tegra_csi_tpg_sizes), width, height,
@@ -225,13 +214,10 @@ static int csi_set_format(struct v4l2_subdev *subdev,/* * V4L2 Subdevice Video Operations */ -static int tegra_csi_get_frame_interval (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_frame_interval *vfi) +static int tegra_csi_tpg_get_frame_interval (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_frame_interval *vfi) { -if (!IS_ENABLED (CONFIG_VIDEO_TEGRA_TPG )) -return -ENOIOCTLCMD ; -if (vfi->pad >= subdev->entity.num_pads)return -EINVAL ;
@@ -240,13 +226,10 @@ static int tegra_csi_get_frame_interval(struct v4l2_subdev *subdev,return 0 ; } -static int tegra_csi_set_frame_interval (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_frame_interval *vfi) +static int tegra_csi_tpg_set_frame_interval (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_frame_interval *vfi) { -if (!IS_ENABLED (CONFIG_VIDEO_TEGRA_TPG )) -return -ENOIOCTLCMD ; -if (vfi->pad >= subdev->entity.num_pads)return -EINVAL ;
@@ -255,8 +238,8 @@ static int tegra_csi_set_frame_interval(struct v4l2_subdev *subdev,return 0 ; } -static int csi_init_state (struct v4l2_subdev *sd, -struct v4l2_subdev_state *state) +static int tegra_csi_tpg_init_state (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state) {struct tegra_csi_channel *csi_chan =to_csi_chan (sd);const struct tpg_framerate *frmrate;
@@ -491,23 +474,27 @@ static const struct v4l2_subdev_video_ops tegra_csi_video_ops = { .s_stream = tegra_csi_s_stream, }; -static const struct v4l2_subdev_pad_ops tegra_csi_pad_ops = { - .enum_mbus_code = csi_enum_bus_code, - .enum_frame_size = csi_enum_framesizes, - .enum_frame_interval = csi_enum_frameintervals, - .get_fmt = csi_get_format, - .set_fmt = csi_set_format, - .get_frame_interval = tegra_csi_get_frame_interval, - .set_frame_interval = tegra_csi_set_frame_interval, +static const struct v4l2_subdev_pad_ops tegra_csi_tpg_pad_ops = { + .enum_mbus_code = tegra_csi_tpg_enum_bus_code, + .enum_frame_size = tegra_csi_tpg_enum_framesizes, + .enum_frame_interval = tegra_csi_tpg_enum_frameintervals, + .get_fmt = tegra_csi_tpg_get_format, + .set_fmt = tegra_csi_tpg_set_format, + .get_frame_interval = tegra_csi_tpg_get_frame_interval, + .set_frame_interval = tegra_csi_tpg_set_frame_interval, +}; + +static const struct v4l2_subdev_ops tegra_csi_tpg_ops = { + .video = &tegra_csi_video_ops, + .pad = &tegra_csi_tpg_pad_ops, };static const struct v4l2_subdev_ops tegra_csi_ops = { - .video = &tegra_csi_video_ops, - .pad = &tegra_csi_pad_ops, + .video = &tegra_csi_video_ops, }; -static const struct v4l2_subdev_internal_ops tegra_csi_internal_ops = { - .init_state = csi_init_state, +static const struct v4l2_subdev_internal_ops tegra_csi_tpg_internal_ops = { + .init_state = tegra_csi_tpg_init_state, };struct v4l2_subdev *tegra_channel_get_remote_csi_subdev (struct tegra_vi_channel *chan)
@@ -523,7 +510,8 @@ struct v4l2_subdev *tegra_channel_get_remote_csi_subdev(struct tegra_vi_channelif (!subdev)return NULL ; -return subdev->ops == &tegra_csi_ops ? subdev :NULL ; +return (subdev->ops == &tegra_csi_ops || + subdev->ops == &tegra_csi_tpg_ops) ? subdev :NULL ; } static int tegra_csi_channel_alloc(struct tegra_csi *csi,
@@ -678,20 +666,23 @@ static int tegra_csi_channel_init(struct tegra_csi_channel *chan) chan->format.colorspace =V4L2_COLORSPACE_SRGB ; chan->format.width =TEGRA_DEF_WIDTH ; chan->format.height =TEGRA_DEF_HEIGHT ; -csi_chan_update_blank_intervals (chan, chan->format.code, - chan->format.width, - chan->format.height); +/* initialize V4L2 subdevice and media entity */ subdev = &chan->subdev; -v4l2_subdev_init (subdev, &tegra_csi_ops); - subdev->dev = csi->dev; -if (IS_ENABLED (CONFIG_VIDEO_TEGRA_TPG )) +if (IS_ENABLED (CONFIG_VIDEO_TEGRA_TPG )) { +v4l2_subdev_init (subdev, &tegra_csi_tpg_ops); +csi_chan_update_blank_intervals (chan, chan->format.code, + chan->format.width, + chan->format.height); + subdev->internal_ops = &tegra_csi_tpg_internal_ops;snprintf (subdev->name,sizeof (subdev->name),"%s-%d" ,"tpg" , chan->csi_port_nums[0 ]); -else + }else {snprintf (subdev->name,sizeof (subdev->name),"%s" ,kbasename (chan->of_node->full_name)); + } + subdev->dev = csi->dev;v4l2_set_subdevdata (subdev, chan); subdev->fwnode =of_fwnode_handle (chan->of_node); subdev->entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ;
@@ -707,7 +698,6 @@ static int tegra_csi_channel_init(struct tegra_csi_channel *chan)return ret; } - subdev->internal_ops = &tegra_csi_internal_ops; ret =v4l2_subdev_init_finalize (subdev);if (ret <0 ) { dev_err(csi->dev,
Signature · 1 line
2.53.0
PATCH v2 14/15 media: tegra-video: csi: Add pad and media operations for own CSI channels
In reply to Svyatoslav RyhelImplement pad format enumeration, format negotiation clamped to SoC limits via vi_fmt_align(), subdevice state initialization across sink and source pads, and v4l2_subdev_link_validate() for CSI bridge channels when TPG mode is disabled.
--- .../media/platform/nvidia/tegra-video/csi.c | 149 +++++++++++++++++- 1 file changed, 147 insertions(+), 2 deletions(-)
drivers/media/platform/nvidia/tegra-video/csi.c +147 -2
@@ -323,6 +323,133 @@ void tegra_csi_calc_settle_time(struct tegra_csi_channel *csi_chan, / (2 * pix_clk_mhz) - 5000) / 1000; } +/* +* Proper CSI configuration +*/ + +enum tegra_csi_bridge_pad { +TEGRA_CSI_PAD_SINK =0 , +TEGRA_CSI_PAD_SOURCE =1 , +TEGRA_CSI_NUM_PADS , +}; + +static const u32 tegra_csi_mbus_formats[] = { +/* RAW 8 */ +MEDIA_BUS_FMT_SGBRG8_1X8 , +MEDIA_BUS_FMT_SBGGR8_1X8 , +MEDIA_BUS_FMT_SRGGB8_1X8 , +MEDIA_BUS_FMT_SGRBG8_1X8 , +/* RAW 10 */ +MEDIA_BUS_FMT_SGBRG10_1X10 , +MEDIA_BUS_FMT_SBGGR10_1X10 , +MEDIA_BUS_FMT_SRGGB10_1X10 , +MEDIA_BUS_FMT_SGRBG10_1X10 , +/* RAW 12 */ +MEDIA_BUS_FMT_SGBRG12_1X12 , +MEDIA_BUS_FMT_SBGGR12_1X12 , +MEDIA_BUS_FMT_SRGGB12_1X12 , +MEDIA_BUS_FMT_SGRBG12_1X12 , +/* RGB888 */ +MEDIA_BUS_FMT_RGB888_1X24 , +MEDIA_BUS_FMT_RGB888_1X32_PADHI , +/* YUV422 */ +MEDIA_BUS_FMT_UYVY8_1X16 , +MEDIA_BUS_FMT_VYUY8_1X16 , +MEDIA_BUS_FMT_YUYV8_1X16 , +MEDIA_BUS_FMT_YVYU8_1X16 , +}; + +static u32 tegra_csi_get_format_code (u32 code) +{ +u32 i; + +for (i =0 ; i <ARRAY_SIZE (tegra_csi_mbus_formats); i++) +if (tegra_csi_mbus_formats[i] == code) +break ; + +if (i >=ARRAY_SIZE (tegra_csi_mbus_formats)) +return MEDIA_BUS_FMT_SRGGB10_1X10 ; + +return tegra_csi_mbus_formats[i]; +} + +/* +* V4L2 Subdevice Operations +*/ +static int tegra_csi_enum_bus_code (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *state, +struct v4l2_subdev_mbus_code_enum *code) +{ +const struct v4l2_mbus_framefmt *sink_fmt; + +if (code->pad ==TEGRA_CSI_PAD_SINK ) { +if (code->index >=ARRAY_SIZE (tegra_csi_mbus_formats)) +return -EINVAL ; + + code->code = tegra_csi_mbus_formats[code->index]; + }else { +if (code->index >0 ) +return -EINVAL ; + + sink_fmt =v4l2_subdev_state_get_format (state, +TEGRA_CSI_PAD_SINK ); + code->code = sink_fmt->code; + } + +return 0 ; +} + +static int tegra_csi_set_format (struct v4l2_subdev *subdev, +const struct v4l2_subdev_client_info *ci, +struct v4l2_subdev_state *state, +struct v4l2_subdev_format *format) +{ +struct tegra_vi_channel *chan =v4l2_get_subdev_hostdata (subdev); +struct v4l2_mbus_framefmt *mbus_fmt = &format->format; +struct v4l2_mbus_framefmt *sink_fmt, *src_fmt; +struct tegra_vi *vi = chan->vi; +const struct v4l2_frmsize_stepwise *stepwise = vi->soc->framesize; + +/* The format on the source pad always matches the sink pad */ +if (format->pad ==TEGRA_CSI_PAD_SOURCE ) +return v4l2_subdev_get_fmt (subdev, state, format); + + sink_fmt =v4l2_subdev_state_get_format (state,TEGRA_CSI_PAD_SINK ); + src_fmt =v4l2_subdev_state_get_format (state,TEGRA_CSI_PAD_SOURCE ); +if (!sink_fmt || !src_fmt) +return -EINVAL ; + + mbus_fmt->code =tegra_csi_get_format_code (mbus_fmt->code); + mbus_fmt->field =V4L2_FIELD_NONE ; + + mbus_fmt->width =clamp_t (u32, mbus_fmt->width, stepwise->min_width, + stepwise->max_width); + mbus_fmt->height =clamp_t (u32, mbus_fmt->height, stepwise->min_height, + stepwise->max_height); + + *sink_fmt = *mbus_fmt; + *src_fmt = *mbus_fmt; + +return 0 ; +} + +static int tegra_csi_init_state (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *state) +{ +struct tegra_csi_channel *chan =to_csi_chan (subdev); +struct v4l2_mbus_framefmt *fmt[TEGRA_CSI_NUM_PADS ]; + +for (int i =0 ; i < chan->numpads; i++) { + fmt[i] =v4l2_subdev_state_get_format (state, i); +if (!fmt[i]) +continue ; + + *fmt[i] = chan->format; + } + +return 0 ; +} +static int tegra_csi_enable_stream (struct v4l2_subdev *subdev) {struct tegra_vi_channel *chan =v4l2_get_subdev_hostdata (subdev);
@@ -484,6 +611,12 @@ static const struct v4l2_subdev_pad_ops tegra_csi_tpg_pad_ops = { .set_frame_interval = tegra_csi_tpg_set_frame_interval, }; +static const struct v4l2_subdev_pad_ops tegra_csi_pad_ops = { + .enum_mbus_code = tegra_csi_enum_bus_code, + .get_fmt = v4l2_subdev_get_fmt, + .set_fmt = tegra_csi_set_format, +}; +static const struct v4l2_subdev_ops tegra_csi_tpg_ops = { .video = &tegra_csi_video_ops, .pad = &tegra_csi_tpg_pad_ops,
@@ -491,12 +624,21 @@ static const struct v4l2_subdev_ops tegra_csi_tpg_ops = {static const struct v4l2_subdev_ops tegra_csi_ops = { .video = &tegra_csi_video_ops, + .pad = &tegra_csi_pad_ops, };static const struct v4l2_subdev_internal_ops tegra_csi_tpg_internal_ops = { .init_state = tegra_csi_tpg_init_state, }; +static const struct v4l2_subdev_internal_ops tegra_csi_internal_ops = { + .init_state = tegra_csi_init_state, +}; + +static const struct media_entity_operations tegra_csi_media_ops = { + .link_validate = v4l2_subdev_link_validate, +}; +struct v4l2_subdev *tegra_channel_get_remote_csi_subdev (struct tegra_vi_channel *chan) {struct media_pad *pad;
@@ -546,8 +688,8 @@ static int tegra_csi_channel_alloc(struct tegra_csi *csi, chan->of_node =of_node_get (node); chan->numpads = num_pads;if (num_pads &0x2 ) { - chan->pads[0 ].flags =MEDIA_PAD_FL_SINK ; - chan->pads[1 ].flags =MEDIA_PAD_FL_SOURCE ; + chan->pads[TEGRA_CSI_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; + chan->pads[TEGRA_CSI_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ; }else { chan->pads[0 ].flags =MEDIA_PAD_FL_SOURCE ; }
@@ -678,6 +820,8 @@ static int tegra_csi_channel_init(struct tegra_csi_channel *chan)snprintf (subdev->name,sizeof (subdev->name),"%s-%d" ,"tpg" , chan->csi_port_nums[0 ]); }else { +v4l2_subdev_init (subdev, &tegra_csi_ops); + subdev->internal_ops = &tegra_csi_internal_ops;snprintf (subdev->name,sizeof (subdev->name),"%s" ,kbasename (chan->of_node->full_name)); }
@@ -686,6 +830,7 @@ static int tegra_csi_channel_init(struct tegra_csi_channel *chan)v4l2_set_subdevdata (subdev, chan); subdev->fwnode =of_fwnode_handle (chan->of_node); subdev->entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ; + subdev->entity.ops = &tegra_csi_media_ops; subdev->flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;/* initialize media entity pads */
Signature · 1 line
2.53.0
PATCH v2 15/15 media: tegra-video: vip: Add pad and media operations for VIP
In reply to Svyatoslav RyhelImplement pad format enumeration, format negotiation clamped to SoC limits via vi_fmt_align(), and v4l2_subdev_link_validate() for VIP bridge channels.
--- .../media/platform/nvidia/tegra-video/vip.c | 93 ++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-)
drivers/media/platform/nvidia/tegra-video/vip.c +92 -1
@@ -21,6 +21,14 @@#include "vip.h" #include "video.h" +static const u32 tegra_vip_mbus_formats[] = { +/* YUV422 */ +MEDIA_BUS_FMT_UYVY8_2X8 , +MEDIA_BUS_FMT_VYUY8_2X8 , +MEDIA_BUS_FMT_YUYV8_2X8 , +MEDIA_BUS_FMT_YVYU8_2X8 , +}; +static inline struct tegra_vip *host1x_client_to_vip (struct host1x_client *client) { return container_of(client, struct tegra_vip, client);
@@ -36,6 +44,77 @@ static inline struct tegra_vip *vip_channel_to_vip(struct tegra_vip_channel *cha return container_of(chan, struct tegra_vip, chan); } +static u32 tegra_vip_get_format_code (u32 code) +{ +u32 i; + +for (i =0 ; i <ARRAY_SIZE (tegra_vip_mbus_formats); i++) +if (tegra_vip_mbus_formats[i] == code) +break ; + +if (i >=ARRAY_SIZE (tegra_vip_mbus_formats)) + i =0 ; + +return tegra_vip_mbus_formats[i]; +} + +static int tegra_vip_enum_bus_code (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *state, +struct v4l2_subdev_mbus_code_enum *code) +{ +const struct v4l2_mbus_framefmt *sink_fmt; + +if (code->pad ==TEGRA_VIP_PAD_SINK ) { +if (code->index >=ARRAY_SIZE (tegra_vip_mbus_formats)) +return -EINVAL ; + + code->code = tegra_vip_mbus_formats[code->index]; + }else { +if (code->index >0 ) +return -EINVAL ; + + sink_fmt =v4l2_subdev_state_get_format (state, +TEGRA_VIP_PAD_SINK ); + code->code = sink_fmt->code; + } + +return 0 ; +} + +static int tegra_vip_set_format (struct v4l2_subdev *subdev, +const struct v4l2_subdev_client_info *ci, +struct v4l2_subdev_state *state, +struct v4l2_subdev_format *format) +{ +struct tegra_vi_channel *chan =v4l2_get_subdev_hostdata (subdev); +struct v4l2_mbus_framefmt *mbus_fmt = &format->format; +struct v4l2_mbus_framefmt *sink_fmt, *src_fmt; +struct tegra_vi *vi = chan->vi; +const struct v4l2_frmsize_stepwise *stepwise = vi->soc->framesize; + +/* The format on the source pad always matches the sink pad */ +if (format->pad ==TEGRA_VIP_PAD_SOURCE ) +return v4l2_subdev_get_fmt (subdev, state, format); + + sink_fmt =v4l2_subdev_state_get_format (state,TEGRA_VIP_PAD_SINK ); + src_fmt =v4l2_subdev_state_get_format (state,TEGRA_VIP_PAD_SOURCE ); +if (!sink_fmt || !src_fmt) +return -EINVAL ; + + mbus_fmt->code =tegra_vip_get_format_code (mbus_fmt->code); + mbus_fmt->field =V4L2_FIELD_NONE ; + + mbus_fmt->width =clamp_t (u32, mbus_fmt->width, stepwise->min_width, + stepwise->max_width); + mbus_fmt->height =clamp_t (u32, mbus_fmt->height, stepwise->min_height, + stepwise->max_height); + + *sink_fmt = *mbus_fmt; + *src_fmt = *mbus_fmt; + +return 0 ; +} +/* Find the previous subdev in the pipeline (i.e. the one connected to our sink pad) */ static struct v4l2_subdev *tegra_vip_channel_get_prev_subdev (struct tegra_vip_channel *chan) {
@@ -104,8 +183,19 @@ static const struct v4l2_subdev_video_ops tegra_vip_video_ops = { .s_stream = tegra_vip_s_stream, }; +static const struct v4l2_subdev_pad_ops tegra_vip_pad_ops = { + .enum_mbus_code = tegra_vip_enum_bus_code, + .get_fmt = v4l2_subdev_get_fmt, + .set_fmt = tegra_vip_set_format, +}; +static const struct v4l2_subdev_ops tegra_vip_ops = { - .video = &tegra_vip_video_ops, + .video = &tegra_vip_video_ops, + .pad = &tegra_vip_pad_ops, +}; + +static const struct media_entity_operations tegra_vip_media_ops = { + .link_validate = v4l2_subdev_link_validate, };static int tegra_vip_channel_of_parse (struct tegra_vip *vip)
@@ -165,6 +255,7 @@ static int tegra_vip_channel_init(struct tegra_vip *vip)v4l2_set_subdevdata (subdev, &vip->chan); subdev->fwnode =of_fwnode_handle (vip->chan.of_node); subdev->entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ; + subdev->entity.ops = &tegra_vip_media_ops; subdev->flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; err =media_entity_pads_init (&subdev->entity,TEGRA_VIP_PADS_NUM , vip->chan.pads);
Signature · 1 line
2.53.0