media: atmel: atmel-isc: implement media controller
Subsystems (5)
v9 cover media: atmel: atmel-isc: implement media controller
This series is the v9 series that attempts to support media controller in the atmel ISC and XISC drivers.
The CSI2DC driver was accepted thus removed from the patch series, together with other patches.
Important note: this series applies on top of current media_staging tree, as it relies on previous patches in the series which were accepted.
Thanks to everyone who reviewed my work !
Eugen
Changes in v9:
-> kernel robot reported isc_link_validate is not static, changed to static.
Changes in v8:
-> scaler: modified crop bounds to have the exact source size
Changes in v7:
-> scaler: modified crop bounds to have maximum isc size -> format propagation: did small changes as per Jacopo review
Changes in v6:
-> worked a bit on scaler, added try crop and other changes as per Jacopo review -> worked on isc-base enum_fmt , reworked as per Jacopo review
Changes in v5:
-> removed patch that removed the 'stop' variable as it was still required -> added two new trivial patches
-> reworked some parts of the scaler and format propagation after discussions with Jacopo
Changes in v4:
-> as reviewed by Hans, added new patch to remove the 'stop' variable and reworked one patch that was using it
-> as reviewed by Jacopo, reworked some parts of the media controller implementation
Changes in v3:
- change in bindings, small fixes in csi2dc driver and conversion to mc for the isc-base.
- removed some MAINTAINERS patches and used patterns in MAINTAINERS
Changes in v2:
- integrated many changes suggested by Jacopo in the review of the v1 series.
- add a few new patches
Eugen Hristev (13):
media: atmel: atmel-isc-base: use streaming status when queueing
buffers
media: atmel: atmel-isc-base: replace is_streaming call in
s_fmt_vid_cap
media: atmel: atmel-isc: remove redundant comments
media: atmel: atmel-isc: implement media controller
media: atmel: atmel-sama5d2-isc: fix wrong mask in YUYV format check
media: atmel: atmel-isc-base: use mutex to lock awb workqueue from
streaming
media: atmel: atmel-isc: compact the controller formats list
media: atmel: atmel-isc: change format propagation to subdev into only
verification
media: atmel: atmel-sama7g5-isc: remove stray line
dt-bindings: media: microchip,xisc: add bus-width of 14
ARM: dts: at91: sama7g5: add nodes for video capture
ARM: configs: at91: sama7: add xisc and csi2dc
ARM: multi_v7_defconfig: add atmel video pipeline modules
.../bindings/media/microchip,xisc.yaml | 2 +- arch/arm/boot/dts/sama7g5.dtsi | 49 ++ arch/arm/configs/multi_v7_defconfig | 3 + arch/arm/configs/sama7_defconfig | 2 + drivers/media/platform/atmel/Makefile | 2 +- drivers/media/platform/atmel/atmel-isc-base.c | 518 ++++++++++-------- .../media/platform/atmel/atmel-isc-scaler.c | 267 +++++++++ drivers/media/platform/atmel/atmel-isc.h | 58 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 87 +-- .../media/platform/atmel/atmel-sama7g5-isc.c | 93 ++-- 10 files changed, 754 insertions(+), 327 deletions(-) create mode 100644 drivers/media/platform/atmel/atmel-isc-scaler.c
Signature · 1 line
2.25.1
PATCH v9 1/13 media: atmel: atmel-isc-base: use streaming status when queueing buffers
During experiments with libcamera, it looks like vb2_is_streaming returns true before our start streaming is called.
Order of operations is streamon -> queue -> start_streaming
ISC would have started the DMA immediately when a buffer is being added to the vbqueue if the queue is streaming.
It is more safe to start the DMA after the start streaming of the driver is called.
Thus, even if vb2queue is streaming, add the buffer to the dma queue of the driver instead of actually starting the DMA process, if the start streaming has not been called yet.
Tho achieve this, we have to use vb2_start_streaming_called instead of vb2_is_streaming.
--- drivers/media/platform/atmel/atmel-isc-base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/atmel/atmel-isc-base.c +1 -1
@@ -442,7 +442,7 @@ static void isc_buffer_queue(struct vb2_buffer *vb)spin_lock_irqsave (&isc->dma_queue_lock, flags);if (!isc->cur_frm &&list_empty (&isc->dma_queue) && -vb2_is_streaming (vb->vb2_queue)) { +vb2_start_streaming_called (vb->vb2_queue)) { isc->cur_frm = buf;isc_start_dma (isc); }else
Signature · 1 line
2.25.1
PATCH v9 2/13 media: atmel: atmel-isc-base: replace is_streaming call in s_fmt_vid_cap
In reply to Eugen HristevIn s_fmt_vid_cap, we should check if vb2_is_busy and return EBUSY, not check if it's streaming to return the busy state.
--- drivers/media/platform/atmel/atmel-isc-base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/atmel/atmel-isc-base.c +1 -1
@@ -1029,7 +1029,7 @@ static int isc_s_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file); -if (vb2_is_streaming (&isc->vb2_vidq)) +if (vb2_is_busy (&isc->vb2_vidq))return -EBUSY ;return isc_set_fmt (isc, f);
Signature · 1 line
2.25.1
PATCH v9 3/13 media: atmel: atmel-isc: remove redundant comments
In reply to Eugen HristevRemove duplicate comments which are already in place before the struct definition.
--- drivers/media/platform/atmel/atmel-isc.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/atmel/atmel-isc.h +3 -3
@@ -272,7 +272,7 @@ struct isc_device {struct video_device video_dev;struct vb2_queue vb2_vidq; -spinlock_t dma_queue_lock;/* serialize access to dma queue */ +spinlock_t dma_queue_lock;struct list_head dma_queue;struct isc_buffer *cur_frm;unsigned int sequence;
@@ -289,8 +289,8 @@ struct isc_device {struct isc_ctrls ctrls;struct work_struct awb_work; -struct mutex lock;/* serialize access to file operations */ -spinlock_t awb_lock;/* serialize access to DMA buffers from awb work queue */ +struct mutex lock; +spinlock_t awb_lock;struct regmap_field *pipeline[ISC_PIPE_LINE_NODE_NUM ];
Signature · 1 line
2.25.1
PATCH v9 4/13 media: atmel: atmel-isc: implement media controller
In reply to Eugen HristevImplement the support for media-controller.
This means that the capabilities of the driver have changed and now it also advertises the IO_MC .
The driver will register its media device, and add the video entity to this media device. The subdevices are registered to the same media device. The ISC will have a base entity which is auto-detected as atmel_isc_base. It will also register a subdevice that allows cropping of the incoming frame to the maximum frame size supported by the ISC.
The ISC will create a link between the subdevice that is asynchronously registered and the atmel_isc_scaler entity.
Then, the atmel_isc_scaler and atmel_isc_base are connected through another link.
---
Changes in v8:
- use source format size as bounds always
Changes in v7:
- use maximum isc frame size as bounds always
Changes in v6:
- reworked a bit as suggested by Jacopo
- add try crops
Changes in v5:
- reworked s_fmt to pass the same format from sink to source
- simplified enum_mbus_code
- separated tgt and bounds to report correctly in g_sel
Changes in v4:
As suggested by Jacopo:
- renamed atmel_isc_mc to atmel_isc_scaler.c
- moved init_mc/clean_mc to isc_base file
Changes in v2:
- implement try formats
drivers/media/platform/atmel/Makefile | 2 +- drivers/media/platform/atmel/atmel-isc-base.c | 75 ++++- .../media/platform/atmel/atmel-isc-scaler.c | 262 ++++++++++++++++++ drivers/media/platform/atmel/atmel-isc.h | 37 +++ .../media/platform/atmel/atmel-sama5d2-isc.c | 14 +- .../media/platform/atmel/atmel-sama7g5-isc.c | 12 +- 6 files changed, 394 insertions(+), 8 deletions(-) create mode 100644 drivers/media/platform/atmel/atmel-isc-scaler.c
drivers/media/platform/atmel/Makefile +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only atmel-isc-objs = atmel-sama5d2-isc.o atmel-xisc-objs = atmel-sama7g5-isc.o -atmel-isc-common-objs = atmel-isc-base.o atmel-isc-clk.o +atmel-isc-common-objs = atmel-isc-base.o atmel-isc-clk.o atmel-isc-scaler.o obj-$(CONFIG_VIDEO_ATMEL_ISI) += atmel-isi.o obj-$(CONFIG_VIDEO_ATMEL_ISC_BASE) += atmel-isc-common.o
drivers/media/platform/atmel/atmel-isc-base.c +71 -4
125 lines not on this page · raw message
drivers/media/platform/atmel/atmel-isc-scaler.c new file +262 -0
262 lines not on this page · raw message
drivers/media/platform/atmel/atmel-isc.h +37 -0
@@ -183,6 +183,17 @@ struct isc_reg_offsets {u32 his_entry; }; +enum isc_mc_pads { +ISC_PAD_SINK =0 , +ISC_PADS_NUM =1 , +}; + +enum isc_scaler_pads { +ISC_SCALER_PAD_SINK =0 , +ISC_SCALER_PAD_SOURCE =1 , +ISC_SCALER_PADS_NUM =2 , +}; +/* * struct isc_device - ISC device driver data/config struct * @regmap: Register map
@@ -258,6 +269,12 @@ struct isc_reg_offsets {* be used as an input to the controller * @controller_formats_size: size of controller_formats array * @formats_list_size: size of formats_list array +* @pads: media controller pads for isc video entity +* @mdev: media device that is registered by the isc +* @remote_pad: remote pad on the connected subdevice +* @scaler_sd: subdevice for the scaler that isc registers +* @scaler_pads: media controller pads for the scaler subdevice +* @scaler_format: current format for the scaler subdevice */ struct isc_device {struct regmap *regmap;
@@ -346,6 +363,19 @@ struct isc_device {struct isc_format *formats_list;u32 controller_formats_size;u32 formats_list_size; + +struct { +struct media_pad pads[ISC_PADS_NUM ]; +struct media_device mdev; + +u32 remote_pad; + }; + +struct { +struct v4l2_subdev scaler_sd; +struct media_pad scaler_pads[ISC_SCALER_PADS_NUM ]; +struct v4l2_mbus_framefmt scaler_format[ISC_SCALER_PADS_NUM ]; + }; };extern const struct regmap_config isc_regmap_config;
@@ -357,4 +387,11 @@ int isc_clk_init(struct isc_device *isc);void isc_subdev_cleanup (struct isc_device *isc);void isc_clk_cleanup (struct isc_device *isc); +int isc_scaler_link (struct isc_device *isc); +int isc_scaler_init (struct isc_device *isc); +int isc_mc_init (struct isc_device *isc,u32 ver); +void isc_mc_cleanup (struct isc_device *isc); + +struct isc_format *isc_find_format_by_code (struct isc_device *isc, +unsigned int code,int *index);#endif
drivers/media/platform/atmel/atmel-sama5d2-isc.c +12 -2
@@ -553,6 +553,12 @@ static int atmel_isc_probe(struct platform_device *pdev)break ; } +regmap_read (isc->regmap,ISC_VERSION + isc->offsets.version, &ver); + + ret =isc_mc_init (isc, ver); +if (ret <0 ) + goto isc_probe_mc_init_err; +pm_runtime_set_active (dev);pm_runtime_enable (dev);pm_request_idle (dev);
@@ -562,7 +568,7 @@ static int atmel_isc_probe(struct platform_device *pdev) ret =clk_prepare_enable (isc->ispck);if (ret) {dev_err (dev,"failed to enable ispck: %d\n" , ret); - goto cleanup_subdev; + goto isc_probe_mc_init_err; }/* ispck should be greater or equal to hclock */
@@ -572,7 +578,6 @@ static int atmel_isc_probe(struct platform_device *pdev) goto unprepare_clk; } -regmap_read (isc->regmap,ISC_VERSION + isc->offsets.version, &ver);dev_info (dev,"Microchip ISC version %x\n" , ver);return 0 ;
@@ -580,6 +585,9 @@ static int atmel_isc_probe(struct platform_device *pdev) unprepare_clk:clk_disable_unprepare (isc->ispck); +isc_probe_mc_init_err: +isc_mc_cleanup (isc); + cleanup_subdev:isc_subdev_cleanup (isc);
@@ -600,6 +608,8 @@ static int atmel_isc_remove(struct platform_device *pdev)pm_runtime_disable (&pdev->dev); +isc_mc_cleanup (isc); +isc_subdev_cleanup (isc);v4l2_device_unregister (&isc->v4l2_dev);
drivers/media/platform/atmel/atmel-sama7g5-isc.c +11 -1
@@ -547,15 +547,23 @@ static int microchip_xisc_probe(struct platform_device *pdev)break ; } +regmap_read (isc->regmap,ISC_VERSION + isc->offsets.version, &ver); + + ret =isc_mc_init (isc, ver); +if (ret <0 ) + goto isc_probe_mc_init_err; +pm_runtime_set_active (dev);pm_runtime_enable (dev);pm_request_idle (dev); -regmap_read (isc->regmap,ISC_VERSION + isc->offsets.version, &ver);dev_info (dev,"Microchip XISC version %x\n" , ver);return 0 ; +isc_probe_mc_init_err: +isc_mc_cleanup (isc); + cleanup_subdev:isc_subdev_cleanup (isc);
@@ -576,6 +584,8 @@ static int microchip_xisc_remove(struct platform_device *pdev)pm_runtime_disable (&pdev->dev); +isc_mc_cleanup (isc); +isc_subdev_cleanup (isc);v4l2_device_unregister (&isc->v4l2_dev);
Signature · 1 line
2.25.1
PATCH v9 5/13 media: atmel: atmel-sama5d2-isc: fix wrong mask in YUYV format check
In reply to Eugen HristevWhile this does not happen in production, this check should be done versus the mask, as checking with the YCYC value may not include some bits that may be set.
Is it correct and safe to check the whole mask.
--- drivers/media/platform/atmel/atmel-sama5d2-isc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/atmel/atmel-sama5d2-isc.c +1 -1
@@ -291,7 +291,7 @@ static void isc_sama5d2_config_rlp(struct isc_device *isc)* Thus, if the YCYC mode is selected, replace it with the * sama5d2-compliant mode which is YYCC . */ -if ((rlp_mode &ISC_RLP_CFG_MODE_YCYC ) ==ISC_RLP_CFG_MODE_YCYC ) { +if ((rlp_mode &ISC_RLP_CFG_MODE_MASK ) ==ISC_RLP_CFG_MODE_YCYC ) { rlp_mode &= ~ISC_RLP_CFG_MODE_MASK ; rlp_mode |=ISC_RLP_CFG_MODE_YYCC ; }
Signature · 1 line
2.25.1
PATCH v9 6/13 media: atmel: atmel-isc-base: use mutex to lock awb workqueue from streaming
In reply to Eugen HristevThe AWB workqueue runs in a kernel thread and needs to be synchronized w.r.t. the streaming status.
It is possible that streaming is stopped while the AWB workq is running. In this case it is likely that the check for vb2_start_streaming_called is done at one point in time, but the AWB computations are done later, including a call to isc_update_profile, which requires streaming to be started. Thus , isc_update_profile will fail if during this operation sequence the streaming was stopped.
To solve this issue, a mutex is added, that will serialize the awb work and streaming stopping, with the mention that either streaming is stopped completely including termination of the last frame is done, and after that the AWB work can check stream status and stop; either first AWB work is completed and after that the streaming can stop correctly.
The awb spin lock cannot be used since this spinlock is taken in the same context and using it in the stop streaming will result in a recursion BUG.
--- drivers/media/platform/atmel/atmel-isc-base.c | 29 ++++++++++++++++--- drivers/media/platform/atmel/atmel-isc.h | 2 ++ 2 files changed, 27 insertions(+), 4 deletions(-)
drivers/media/platform/atmel/atmel-isc-base.c +25 -4
@@ -401,6 +401,7 @@ static void isc_stop_streaming(struct vb2_queue *vq)struct isc_buffer *buf;int ret; +mutex_lock (&isc->awb_mutex);v4l2_ctrl_activate (isc->do_wb_ctrl, false); isc->stop = true;
@@ -410,6 +411,8 @@ static void isc_stop_streaming(struct vb2_queue *vq)v4l2_err (&isc->v4l2_dev,"Timeout waiting for end of the capture\n" ); +mutex_unlock (&isc->awb_mutex); +/* Disable DMA interrupt */ regmap_write (isc->regmap,ISC_INTDIS ,ISC_INT_DDONE );
@@ -1397,10 +1400,6 @@ static void isc_awb_work(struct work_struct *w)u32 min, max;int ret; -/* streaming is not active anymore */ -if (isc->stop) -return ; -if (ctrls->hist_stat !=HIST_ENABLED )return ;
@@ -1455,7 +1454,24 @@ static void isc_awb_work(struct work_struct *w) }regmap_write (regmap,ISC_HIS_CFG + isc->offsets.his, hist_id | baysel |ISC_HIS_CFG_RAR ); + +/* +* We have to make sure the streaming has not stopped meanwhile. +* ISC requires a frame to clock the internal profile update. +* To avoid issues, lock the sequence with a mutex +*/ +mutex_lock (&isc->awb_mutex); + +/* streaming is not active anymore */ +if (isc->stop) { +mutex_unlock (&isc->awb_mutex); +return ; + }; +isc_update_profile (isc); + +mutex_unlock (&isc->awb_mutex); +/* if awb has been disabled, we don't need to start another histogram */ if (ctrls->awb)regmap_write (regmap,ISC_CTRLEN ,ISC_CTRL_HISREQ );
@@ -1548,6 +1564,7 @@ static int isc_s_awb_ctrl(struct v4l2_ctrl *ctrl)*/ v4l2_ctrl_activate (isc->do_wb_ctrl, false); } +mutex_unlock (&isc->awb_mutex);/* if we have autowhitebalance on, start histogram procedure */ if (ctrls->awb == ISC_WB_AUTO &&
@@ -1740,6 +1757,7 @@ static void isc_async_unbind(struct v4l2_async_notifier *notifier, {struct isc_device *isc =container_of (notifier->v4l2_dev, struct isc_device, v4l2_dev); +mutex_destroy (&isc->awb_mutex);cancel_work_sync (&isc->awb_work);video_unregister_device (&isc->video_dev);v4l2_ctrl_handler_free (&isc->ctrls.handler);
@@ -1850,6 +1868,8 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier) isc->current_subdev =container_of (notifier, struct isc_subdev_entity, notifier);mutex_init (&isc->lock); +mutex_init (&isc->awb_mutex); +init_completion (&isc->comp);/* Initialize videobuf2 queue */
@@ -1930,6 +1950,7 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)video_unregister_device (vdev); isc_async_complete_err: +mutex_destroy (&isc->awb_mutex);mutex_destroy (&isc->lock);return ret; }
drivers/media/platform/atmel/atmel-isc.h +2 -0
@@ -229,6 +229,7 @@ enum isc_scaler_pads {* * @lock: lock for serializing userspace file operations * with ISC operations +* @awb_mutex: serialize access to streaming status from awb work queue * @awb_lock: lock for serializing awb work queue operations * with DMA/buffer operations *
@@ -307,6 +308,7 @@ struct isc_device {struct work_struct awb_work;struct mutex lock; +struct mutex awb_mutex;spinlock_t awb_lock;struct regmap_field *pipeline[ISC_PIPE_LINE_NODE_NUM ];
Signature · 1 line
2.25.1
Re: [PATCH v9 06/13] media: atmel: atmel-isc-base: use mutex to lock awb workqueue from streaming
Hi Eugen,
Quoted 7 lines · Eugen Hristev
The AWB workqueue runs in a kernel thread and needs to be synchronized w.r.t. the streaming status.
It is possible that streaming is stopped while the AWB workq is running. In this case it is likely that the check forvb2_start_streaming_calledis done at one point in time, but the AWB computations are done later, including a call toisc_update_profile, which requires streaming to be started. Thus ,isc_update_profilewill fail if during this operation sequence the
Quoted 8 lines
streaming was stopped.
To solve this issue, a mutex is added, that will serialize the awb work and streaming stopping, with the mention that either streaming is stopped completely including termination of the last frame is done, and after that the AWB work can check stream status and stop; either first AWB work is completed and after that the streaming can stop correctly.
The awb spin lock cannot be used since this spinlock is taken in the same context and using it in the stop streaming will result in a recursion BUG.
Please keep the line length in a commit log to no more than 75.
Quoted 9 lines
Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>--- drivers/media/platform/atmel/atmel-isc-base.c | 29 ++++++++++++++++--- drivers/media/platform/atmel/atmel-isc.h | 2 ++ 2 files changed, 27 insertions(+), 4 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-0
<snip>
drivers/media/platform/atmel/atmel-isc-base.c static int isc_s_awb_ctrl(struct v4l2_ctrl *ctrl) · line 1567
Quoted 5 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -1548,6 +1564,7 @@ static int isc_s_awb_ctrl(struct v4l2_ctrl *ctrl)*/ v4l2_ctrl_activate (isc->do_wb_ctrl, false); } +mutex_unlock (&isc->awb_mutex);
Huh? What is this unlock doing here? Am I missing something?
Regards,
Hans
Quoted 48 lines
drivers/media/platform/atmel/atmel-isc-base.c +4
-0/* if we have autowhitebalance on, start histogram procedure */ if (ctrls->awb == ISC_WB_AUTO &&@@ -1740,6 +1757,7 @@ static void isc_async_unbind(struct v4l2_async_notifier *notifier, {struct isc_device *isc =container_of (notifier->v4l2_dev, struct isc_device, v4l2_dev); +mutex_destroy (&isc->awb_mutex);cancel_work_sync (&isc->awb_work);video_unregister_device (&isc->video_dev);v4l2_ctrl_handler_free (&isc->ctrls.handler);@@ -1850,6 +1868,8 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier) isc->current_subdev =container_of (notifier, struct isc_subdev_entity, notifier);mutex_init (&isc->lock); +mutex_init (&isc->awb_mutex); +init_completion (&isc->comp);/* Initialize videobuf2 queue */ @@ -1930,6 +1950,7 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)video_unregister_device (vdev); isc_async_complete_err: +mutex_destroy (&isc->awb_mutex);mutex_destroy (&isc->lock);return ret; }drivers/media/platform/atmel/atmel-isc.h +2
-0@@ -229,6 +229,7 @@ enum isc_scaler_pads {* * @lock: lock for serializing userspace file operations * with ISC operations +* @awb_mutex: serialize access to streaming status from awb work queue * @awb_lock: lock for serializing awb work queue operations * with DMA/buffer operations * @@ -307,6 +308,7 @@ struct isc_device {struct work_struct awb_work;struct mutex lock; +struct mutex awb_mutex;spinlock_t awb_lock;struct regmap_field *pipeline[ISC_PIPE_LINE_NODE_NUM ];
Re: [PATCH v9 06/13] media: atmel: atmel-isc-base: use mutex to lock awb workqueue from streaming
Quoted 33 lines · Hans Verkuil
Hi Eugen,
Quoted 7 lines · Eugen Hristev
The AWB workqueue runs in a kernel thread and needs to be synchronized w.r.t. the streaming status.
It is possible that streaming is stopped while the AWB workq is running. In this case it is likely that the check forvb2_start_streaming_calledis done at one point in time, but the AWB computations are done later, including a call toisc_update_profile, which requires streaming to be started. Thus ,isc_update_profilewill fail if during this operation sequence theQuoted 8 lines
streaming was stopped.
To solve this issue, a mutex is added, that will serialize the awb work and streaming stopping, with the mention that either streaming is stopped completely including termination of the last frame is done, and after that the AWB work can check stream status and stop; either first AWB work is completed and after that the streaming can stop correctly.
The awb spin lock cannot be used since this spinlock is taken in the same context and using it in the stop streaming will result in a recursion BUG.Please keep the line length in a commit log to no more than 75.
Quoted 9 lines
Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>--- drivers/media/platform/atmel/atmel-isc-base.c | 29 ++++++++++++++++--- drivers/media/platform/atmel/atmel-isc.h | 2 ++ 2 files changed, 27 insertions(+), 4 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-0<snip>
Quoted 7 lines
drivers/media/platform/atmel/atmel-isc-base.c static int isc_s_awb_ctrl(struct v4l2_ctrl *ctrl) · line 1567
Quoted 5 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -1548,6 +1564,7 @@ static int isc_s_awb_ctrl(struct v4l2_ctrl *ctrl)*/ v4l2_ctrl_activate (isc->do_wb_ctrl, false); } +mutex_unlock (&isc->awb_mutex);Huh? What is this unlock doing here? Am I missing something?
Hello Hans,
Sorry. It looks like the corresponding mutex_lock was lost when I rebased the series over the patch to use 'is_streaming' instead of 'stop' variable.
In version 3, the mutex_lock was there :
https://www.spinics.net/lists/linux-media/msg204059.html
Somehow a race problem did not occur in this specific critical area in my tests.
I will resend this patch as a v10 , or the whole series if you have other comments on the other patches? How would you prefer ?
Thanks,
Eugen
Quoted 54 lines
Regards,
Hans
Quoted 48 lines
drivers/media/platform/atmel/atmel-isc-base.c +4
-0/* if we have autowhitebalance on, start histogram procedure */ if (ctrls->awb == ISC_WB_AUTO &&@@ -1740,6 +1757,7 @@ static void isc_async_unbind(struct v4l2_async_notifier *notifier, {struct isc_device *isc =container_of (notifier->v4l2_dev, struct isc_device, v4l2_dev); +mutex_destroy (&isc->awb_mutex);cancel_work_sync (&isc->awb_work);video_unregister_device (&isc->video_dev);v4l2_ctrl_handler_free (&isc->ctrls.handler);@@ -1850,6 +1868,8 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier) isc->current_subdev =container_of (notifier, struct isc_subdev_entity, notifier);mutex_init (&isc->lock); +mutex_init (&isc->awb_mutex); +init_completion (&isc->comp);/* Initialize videobuf2 queue */ @@ -1930,6 +1950,7 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)video_unregister_device (vdev); isc_async_complete_err: +mutex_destroy (&isc->awb_mutex);mutex_destroy (&isc->lock);return ret; }drivers/media/platform/atmel/atmel-isc.h +2
-0@@ -229,6 +229,7 @@ enum isc_scaler_pads {* * @lock: lock for serializing userspace file operations * with ISC operations +* @awb_mutex: serialize access to streaming status from awb work queue * @awb_lock: lock for serializing awb work queue operations * with DMA/buffer operations * @@ -307,6 +308,7 @@ struct isc_device {struct work_struct awb_work;struct mutex lock; +struct mutex awb_mutex;spinlock_t awb_lock;struct regmap_field *pipeline[ISC_PIPE_LINE_NODE_NUM ];
Re: [PATCH v9 06/13] media: atmel: atmel-isc-base: use mutex to lock awb workqueue from streaming
Quoted 49 lines · On 29/04/2022 10:08, [email protected] wrote:
Quoted 33 lines · Hans Verkuil
Hi Eugen,
Quoted 7 lines · Eugen Hristev
The AWB workqueue runs in a kernel thread and needs to be synchronized w.r.t. the streaming status.
It is possible that streaming is stopped while the AWB workq is running. In this case it is likely that the check forvb2_start_streaming_calledis done at one point in time, but the AWB computations are done later, including a call toisc_update_profile, which requires streaming to be started. Thus ,isc_update_profilewill fail if during this operation sequence theQuoted 8 lines
streaming was stopped.
To solve this issue, a mutex is added, that will serialize the awb work and streaming stopping, with the mention that either streaming is stopped completely including termination of the last frame is done, and after that the AWB work can check stream status and stop; either first AWB work is completed and after that the streaming can stop correctly.
The awb spin lock cannot be used since this spinlock is taken in the same context and using it in the stop streaming will result in a recursion BUG.Please keep the line length in a commit log to no more than 75.
Quoted 9 lines
Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>--- drivers/media/platform/atmel/atmel-isc-base.c | 29 ++++++++++++++++--- drivers/media/platform/atmel/atmel-isc.h | 2 ++ 2 files changed, 27 insertions(+), 4 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-0<snip>
Quoted 7 lines
drivers/media/platform/atmel/atmel-isc-base.c static int isc_s_awb_ctrl(struct v4l2_ctrl *ctrl) · line 1567
Quoted 5 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -1548,6 +1564,7 @@ static int isc_s_awb_ctrl(struct v4l2_ctrl *ctrl)*/ v4l2_ctrl_activate (isc->do_wb_ctrl, false); } +mutex_unlock (&isc->awb_mutex);Huh? What is this unlock doing here? Am I missing something?
Hello Hans,
Sorry. It looks like the corresponding
mutex_lockwas lost when I rebased the series over the patch to use 'is_streaming' instead of 'stop' variable.
In version 3, themutex_lockwas there :
Quoted 7 lines
https://www.spinics.net/lists/linux-media/msg204059.html
Somehow a race problem did not occur in this specific critical area in my tests.
I will resend this patch as a v10 , or the whole series if you have other comments on the other patches? How would you prefer ?
I have more comments (just finished the full review), so a v10 is definitely needed.
Regards,
Hans
Quoted 59 lines
Thanks,
EugenQuoted 54 lines
Regards,
Hans
Quoted 48 lines
drivers/media/platform/atmel/atmel-isc-base.c +4
-0/* if we have autowhitebalance on, start histogram procedure */ if (ctrls->awb == ISC_WB_AUTO &&@@ -1740,6 +1757,7 @@ static void isc_async_unbind(struct v4l2_async_notifier *notifier, {struct isc_device *isc =container_of (notifier->v4l2_dev, struct isc_device, v4l2_dev); +mutex_destroy (&isc->awb_mutex);cancel_work_sync (&isc->awb_work);video_unregister_device (&isc->video_dev);v4l2_ctrl_handler_free (&isc->ctrls.handler);@@ -1850,6 +1868,8 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier) isc->current_subdev =container_of (notifier, struct isc_subdev_entity, notifier);mutex_init (&isc->lock); +mutex_init (&isc->awb_mutex); +init_completion (&isc->comp);/* Initialize videobuf2 queue */ @@ -1930,6 +1950,7 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)video_unregister_device (vdev); isc_async_complete_err: +mutex_destroy (&isc->awb_mutex);mutex_destroy (&isc->lock);return ret; }drivers/media/platform/atmel/atmel-isc.h +2
-0@@ -229,6 +229,7 @@ enum isc_scaler_pads {* * @lock: lock for serializing userspace file operations * with ISC operations +* @awb_mutex: serialize access to streaming status from awb work queue * @awb_lock: lock for serializing awb work queue operations * with DMA/buffer operations * @@ -307,6 +308,7 @@ struct isc_device {struct work_struct awb_work;struct mutex lock; +struct mutex awb_mutex;spinlock_t awb_lock;struct regmap_field *pipeline[ISC_PIPE_LINE_NODE_NUM ];
PATCH v9 7/13 media: atmel: atmel-isc: compact the controller formats list
In reply to Eugen HristevCompact the list array to be more readable.
No other changes, only cosmetic.
--- .../media/platform/atmel/atmel-sama5d2-isc.c | 51 ++++++---------- .../media/platform/atmel/atmel-sama7g5-isc.c | 60 +++++++------------ 2 files changed, 37 insertions(+), 74 deletions(-)
drivers/media/platform/atmel/atmel-sama5d2-isc.c +17 -34
@@ -60,56 +60,39 @@static const struct isc_format sama5d2_controller_formats[] = { { .fourcc =V4L2_PIX_FMT_ARGB444 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_ARGB555 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_RGB565 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_ABGR32 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_XBGR32 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_YUV420 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_YUYV , - }, - { + }, { .fourcc =V4L2_PIX_FMT_YUV422P , - }, - { + }, { .fourcc =V4L2_PIX_FMT_GREY , - }, - { + }, { .fourcc =V4L2_PIX_FMT_Y10 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_SBGGR8 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_SGBRG8 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_SGRBG8 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_SRGGB8 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_SBGGR10 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_SGBRG10 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_SGRBG10 , - }, - { + }, { .fourcc =V4L2_PIX_FMT_SRGGB10 , }, };
drivers/media/platform/atmel/atmel-sama7g5-isc.c +20 -40
85 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v9 8/13 media: atmel: atmel-isc: change format propagation to subdev into only verification
In reply to Eugen HristevAs a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at start_streaming() time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification at start_streaming time, such that the ISC will return an error if the subdevice is not properly configured. To achieve this, media_pipeline_start
is called and a link_validate callback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with an mbus_code, the enumfmt handler should only return the formats that are supported for this mbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.
---
Changes in v9:
- isc_link_validate now static
Changes in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by Jacopo
Changes in v6:
- reworked a bit enum_fmt as suggested by Jacopo
Changes in v5:
- removed user_formats dynamic list as it is now pointless
- greatly simplified the enum_fmt function
- removed some init code that was useless now
Changes in v4:
- moved validation code into link_validate and used media_pipeline_start
- merged this patch with the enum_fmt patch which was previously in v3 of the series
Changes in v3:
- clamp to maximum resolution once the frame size from the subdev is found
drivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)
drivers/media/platform/atmel/atmel-isc-base.c +184 -228
@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)
@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe); +if (ret) + goto err_pipeline_start; +/* Enable stream on the sub device */ ret =v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,1 );if (ret && ret != -ENOIOCTLCMD ) {
@@ -385,6 +384,9 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,0 ); err_start_stream: +media_pipeline_stop (&isc->video_dev.entity); + +err_pipeline_start:spin_lock_irqsave (&isc->dma_queue_lock, flags);list_for_each_entry (buf, &isc->dma_queue, list)vb2_buffer_done (&buf->vb.vb2_buf,VB2_BUF_STATE_QUEUED );
@@ -423,6 +425,9 @@ static void isc_stop_streaming(struct vb2_queue *vq)if (ret && ret != -ENOIOCTLCMD )v4l2_err (&isc->v4l2_dev,"stream off failed in subdev\n" ); +/* Stop media pipeline */ +media_pipeline_stop (&isc->video_dev.entity); +/* Release all active buffers */ spin_lock_irqsave (&isc->dma_queue_lock, flags);if (unlikely (isc->cur_frm)) {
@@ -453,22 +458,6 @@ static void isc_buffer_queue(struct vb2_buffer *vb)spin_unlock_irqrestore (&isc->dma_queue_lock, flags); } -static struct isc_format *find_format_by_fourcc (struct isc_device *isc, -unsigned int fourcc) -{ -unsigned int num_formats = isc->num_user_formats; -struct isc_format *fmt; -unsigned int i; - -for (i =0 ; i < num_formats; i++) { - fmt = isc->user_formats[i]; -if (fmt->fourcc == fourcc) -return fmt; - } - -return NULL ; -} -static const struct vb2_ops isc_vb2_ops = { .queue_setup = isc_queue_setup, .wait_prepare = vb2_ops_wait_prepare,
@@ -497,23 +486,57 @@ static int isc_enum_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file);u32 index = f->index; -u32 i, supported_index; +u32 i, supported_index =0 ; +struct isc_format *fmt; + +/* +* If we are not asked a specific mbus_code, we have to report all +* the formats that we can output. +*/ +if (!f->mbus_code) { +if (index >= isc->controller_formats_size) +return -EINVAL ; -if (index < isc->controller_formats_size) { f->pixelformat = isc->controller_formats[index].fourcc; + +return 0 ; + } + +/* +* If a specific mbus_code is requested, check if we support +* this mbus_code as input for the ISC. +* If it's supported, then we report the corresponding pixelformat +* as first possible option for the ISC. +* E.g. mbus MEDIA_BUS_FMT_YUYV8_2X8 and report +* 'YUYV' (YUYV 4:2:2) +*/ + fmt =isc_find_format_by_code (isc, f->mbus_code, &i); +if (!fmt) +return -EINVAL ; + +if (!index) { + f->pixelformat = fmt->fourcc; +return 0 ; } - index -= isc->controller_formats_size; + supported_index++; - supported_index =0 ; +/* If the index is not raw, we don't have anymore formats to report */ +if (!ISC_IS_FORMAT_RAW (f->mbus_code)) +return -EINVAL ; -for (i =0 ; i < isc->formats_list_size; i++) { -if (!ISC_IS_FORMAT_RAW (isc->formats_list[i].mbus_code) || - !isc->formats_list[i].sd_support) +/* +* We are asked for a specific mbus code, which is raw. +* We have to search through the formats we can convert to. +* We have to skip the raw formats, we cannot convert to raw. +* E.g. 'AR12' (16-bit ARGB 4-4-4-4), 'AR15' (16-bit ARGB 1-5-5-5), etc. +*/ +for (i =0 ; i < isc->controller_formats_size; i++) { +if (isc->controller_formats[i].raw)continue ; -if (supported_index == index) { - f->pixelformat = isc->formats_list[i].fourcc; +if (index == supported_index) { + f->pixelformat = isc->controller_formats[i].fourcc;return 0 ; } supported_index++;
@@ -584,20 +607,30 @@ static int isc_try_validate_formats(struct isc_device *isc)break ;default :/* any other different formats are not supported */ +v4l2_err (&isc->v4l2_dev,"Requested unsupported format.\n" ); ret = -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)) +if (bayer && + !ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output RAW if we do not receive RAW.\n" );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)) + !ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output GREY if we do not receive RAW/GREY.\n" );return -EINVAL ; + } + +if ((rgb || bayer || yuv) && +ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot convert GREY to another format.\n" ); +return -EINVAL ; + }return ret; }
@@ -825,7 +858,7 @@ static void isc_try_fse(struct isc_device *isc,* If we do not know yet which format the subdev is using, we cannot * do anything. */ -if (!isc->try_config.sd_format) +if (!isc->config.sd_format)return ; fse.code = isc->try_config.sd_format->mbus_code;
@@ -846,180 +879,140 @@ static void isc_try_fse(struct isc_device *isc, } } -static int isc_try_fmt (struct isc_device *isc,struct v4l2_format *f, -u32 *code) +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_state pad_state = { - .pads = &pad_cfg - }; -struct v4l2_subdev_format format = { - .which =V4L2_SUBDEV_FORMAT_TRY , - }; -u32 mbus_code; -int ret; -bool rlp_dma_direct_dump = false; +unsigned int i;if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE )return -EINVAL ; -/* Step 1: find a RAW format that is supported */ -for (i =0 ; i < isc->num_user_formats; i++) { -if (ISC_IS_FORMAT_RAW (isc->user_formats[i]->mbus_code)) { - sd_fmt = isc->user_formats[i]; + isc->try_config.fourcc = isc->controller_formats[0 ].fourcc; + +/* find if the format requested is supported */ +for (i =0 ; i < isc->controller_formats_size; i++) +if (isc->controller_formats[i].fourcc == pixfmt->pixelformat) { + isc->try_config.fourcc = pixfmt->pixelformat;break ; } - } -/* Step 2: We can continue with this RAW format, or we can look -* for better: maybe sensor supports directly what we need. -*/ - direct_fmt =find_format_by_fourcc (isc, pixfmt->pixelformat); - -/* Step 3: We have both. We decide given the module parameter which -* one to use. -*/ -if (direct_fmt && sd_fmt && sensor_preferred) - sd_fmt = direct_fmt; - -/* Step 4: we do not have RAW but we have a direct format. Use it. */ -if (direct_fmt && !sd_fmt) - sd_fmt = direct_fmt; - -/* Step 5: if we are using a direct format, we need to package -* everything as 8 bit data and just dump it -*/ -if (sd_fmt == direct_fmt) - rlp_dma_direct_dump = true; - -/* Step 6: We have no format. This can happen if the userspace -* requests some weird/invalid format. -* In this case, default to whatever we have -*/ -if (!sd_fmt && !direct_fmt) { - sd_fmt = isc->user_formats[isc->num_user_formats -1 ]; -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Sensor not supporting %.4s, using %.4s\n" , - (char *)&pixfmt->pixelformat, (char *)&sd_fmt->fourcc); - } - -if (!sd_fmt) { - ret = -EINVAL ; - goto isc_try_fmt_err; - } - -/* Step 7: Print out what we decided for debugging */ -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Preferring to have sensor using format %.4s\n" , - (char *)&sd_fmt->fourcc); -/* Step 8: at this moment we decided which format the subdev will use */ - isc->try_config.sd_format = sd_fmt; +isc_try_configure_rlp_dma (isc, false);/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - -/* -* The mbus format is the one the subdev outputs. -* The pixels will be transferred in this format Sensor -> ISC -*/ - mbus_code = sd_fmt->mbus_code; - -/* -* Validate formats. If the required format is not OK, default to raw. -*/ - - isc->try_config.fourcc = pixfmt->pixelformat; - -if (isc_try_validate_formats (isc)) { - pixfmt->pixelformat = isc->try_config.fourcc = sd_fmt->fourcc; -/* Re-try to validate the new format */ - ret =isc_try_validate_formats (isc); -if (ret) - goto isc_try_fmt_err; - } - - ret =isc_try_configure_rlp_dma (isc, rlp_dma_direct_dump); -if (ret) - goto isc_try_fmt_err; - - ret =isc_try_configure_pipeline (isc); -if (ret) - goto isc_try_fmt_err; - -/* Obtain frame sizes if possible to have crop requirements ready */ -isc_try_fse (isc, &pad_state); - -v4l2_fill_mbus_format (&format.format, pixfmt, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, set_fmt, - &pad_state, &format); -if (ret <0 ) - goto isc_try_fmt_subdev_err; - -v4l2_fill_pix_format (pixfmt, &format.format); +v4l_bound_align_image (&pixfmt->width,16 , isc->max_width,0 , + &pixfmt->height,16 , isc->max_height,0 ,0 ); +/* If we did not find the requested format, we will fallback here */ + pixfmt->pixelformat = isc->try_config.fourcc; + pixfmt->colorspace =V4L2_COLORSPACE_SRGB ; + pixfmt->field =V4L2_FIELD_NONE ; -/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - pixfmt->field =V4L2_FIELD_NONE ; pixfmt->bytesperline = (pixfmt->width * isc->try_config.bpp_v4l2) >>3 ; pixfmt->sizeimage = ((pixfmt->width * isc->try_config.bpp) >>3 ) * pixfmt->height; -if (code) - *code = mbus_code; + isc->try_fmt = *f;return 0 ; +} -isc_try_fmt_err: -v4l2_err (&isc->v4l2_dev,"Could not find any possible format for a working pipeline\n" ); -isc_try_fmt_subdev_err: -memset (&isc->try_config,0 ,sizeof (isc->try_config)); +static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +{ +isc_try_fmt (isc, f); -return ret; +/* make the try configuration active */ + isc->config = isc->try_config; + isc->fmt = isc->try_fmt; + +v4l2_dbg (1 , debug, &isc->v4l2_dev,"ISC set_fmt to %.4s @%dx%d\n" , + (char *)&f->fmt.pix.pixelformat, + f->fmt.pix.width, f->fmt.pix.height); + +return 0 ; } -static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +static int isc_validate (struct isc_device *isc) { +int ret; +int i; +struct isc_format *sd_fmt =NULL ; +struct v4l2_pix_format *pixfmt = &isc->fmt.fmt.pix;struct v4l2_subdev_format format = { .which =V4L2_SUBDEV_FORMAT_ACTIVE , + .pad = isc->remote_pad, + }; +struct v4l2_subdev_pad_config pad_cfg = {}; +struct v4l2_subdev_state pad_state = { + .pads = &pad_cfg, }; -u32 mbus_code =0 ; -int ret; - ret =isc_try_fmt (isc, f, &mbus_code); +/* Get current format from subdev */ + ret =v4l2_subdev_call (isc->current_subdev->sd, pad, get_fmt,NULL , + &format);if (ret)return ret; -v4l2_fill_mbus_format (&format.format, &f->fmt.pix, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, - set_fmt,NULL , &format); -if (ret <0 ) -return ret; +/* Identify the subdev's format configuration */ +for (i =0 ; i < isc->formats_list_size; i++) +if (isc->formats_list[i].mbus_code == format.format.code) { + sd_fmt = &isc->formats_list[i]; +break ; + } + +/* Check if the format is not supported */ +if (!sd_fmt) { +v4l2_err (&isc->v4l2_dev, +"Current subdevice is streaming a media bus code that is not supported 0x%x\n" , + format.format.code); +return -EPIPE ; + } + +/* At this moment we know which format the subdev will use */ + isc->try_config.sd_format = sd_fmt; + +/* If the sensor is not RAW, we can only do a direct dump */ +if (!ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) +isc_try_configure_rlp_dma (isc, true);/* Limit to Atmel ISC hardware capabilities */ -if (f->fmt.pix.width > isc->max_width) - f->fmt.pix.width = isc->max_width; -if (f->fmt.pix.height > isc->max_height) - f->fmt.pix.height = isc->max_height; +v4l_bound_align_image (&format.format.width,16 , isc->max_width,0 , + &format.format.height,16 , isc->max_height,0 ,0 ); - isc->fmt = *f; +/* Check if the frame size is the same. Otherwise we may overflow */ +if (pixfmt->height != format.format.height || + pixfmt->width != format.format.width) { +v4l2_err (&isc->v4l2_dev, +"ISC not configured with the proper frame size: %dx%d\n" , + format.format.width, format.format.height); +return -EPIPE ; + } +v4l2_dbg (1 , debug, &isc->v4l2_dev, +"Identified subdev using format %.4s with %dx%d %d bpp\n" , + (char *)&sd_fmt->fourcc, pixfmt->width, pixfmt->height, + isc->try_config.bpp); + +/* Reset and restart AWB if the subdevice changed the format */ if (isc->try_config.sd_format && isc->config.sd_format && isc->try_config.sd_format != isc->config.sd_format) { isc->ctrls.hist_stat =HIST_INIT ;isc_reset_awb_ctrls (isc);isc_update_v4l2_ctrls (isc); } -/* make the try configuration active */ + +/* Validate formats */ + ret =isc_try_validate_formats (isc); +if (ret) +return ret; + +/* Obtain frame sizes if possible to have crop requirements ready */ +isc_try_fse (isc, &pad_state); + +/* Configure ISC pipeline for the config */ + ret =isc_try_configure_pipeline (isc); +if (ret) +return ret; + isc->config = isc->try_config;v4l2_dbg (1 , debug, &isc->v4l2_dev,"New ISC configuration in place\n" );
@@ -1043,7 +1036,7 @@ static int isc_try_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file); -return isc_try_fmt (isc, f,NULL ); +return isc_try_fmt (isc, f); } static int isc_enum_input(struct file *file, void *priv,
@@ -1098,10 +1091,6 @@ static int isc_enum_framesizes(struct file *file, void *fh,if (fsize->index)return -EINVAL ; -for (i =0 ; i < isc->num_user_formats; i++) -if (isc->user_formats[i]->fourcc == fsize->pixel_format) - ret =0 ; -for (i =0 ; i < isc->controller_formats_size; i++)if (isc->controller_formats[i].fourcc == fsize->pixel_format) ret =0 ;
@@ -1782,52 +1771,6 @@ struct isc_format *isc_find_format_by_code(struct isc_device *isc, }EXPORT_SYMBOL_GPL (isc_find_format_by_code); -static int isc_formats_init (struct isc_device *isc) -{ -struct isc_format *fmt; -struct v4l2_subdev *subdev = isc->current_subdev->sd; -unsigned int num_fmts, i, j; -u32 list_size = isc->formats_list_size; -struct v4l2_subdev_mbus_code_enum mbus_code = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - }; - - num_fmts =0 ; -while (!v4l2_subdev_call (subdev, pad, enum_mbus_code, -NULL , &mbus_code)) { - mbus_code.index++; - - fmt =isc_find_format_by_code (isc, mbus_code.code, &i); -if (!fmt) { -v4l2_warn (&isc->v4l2_dev,"Mbus code %x not supported\n" , - mbus_code.code); -continue ; - } - - fmt->sd_support = true; - num_fmts++; - } - -if (!num_fmts) -return -ENXIO ; - - isc->num_user_formats = num_fmts; - isc->user_formats =devm_kcalloc (isc->dev, - num_fmts,sizeof (*isc->user_formats), -GFP_KERNEL ); -if (!isc->user_formats) -return -ENOMEM ; - - fmt = &isc->formats_list[0 ]; -for (i =0 , j =0 ; i < list_size; i++) { -if (fmt->sd_support) - isc->user_formats[j++] = fmt; - fmt++; - } - -return 0 ; -} -static int isc_set_default_fmt (struct isc_device *isc) {struct v4l2_format f = {
@@ -1836,12 +1779,12 @@ static int isc_set_default_fmt(struct isc_device *isc) .width = VGA_WIDTH, .height = VGA_HEIGHT, .field = V4L2_FIELD_NONE, - .pixelformat = isc->user_formats[0]->fourcc, + .pixelformat = isc->controller_formats[0].fourcc, }, };int ret; - ret =isc_try_fmt (isc, &f,NULL ); + ret =isc_try_fmt (isc, &f);if (ret)return ret;
@@ -1896,13 +1839,6 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)spin_lock_init (&isc->dma_queue_lock);spin_lock_init (&isc->awb_lock); - ret =isc_formats_init (isc); -if (ret <0 ) { -v4l2_err (&isc->v4l2_dev, -"Init format failed: %d\n" , ret); - goto isc_async_complete_err; - } - ret =isc_set_default_fmt (isc);if (ret) {v4l2_err (&isc->v4l2_dev,"Could not set default format\n" );
@@ -2016,6 +1952,24 @@ int isc_pipeline_init(struct isc_device *isc) }EXPORT_SYMBOL_GPL (isc_pipeline_init); +static int isc_link_validate (struct media_link *link) +{ +struct video_device *vdev = +media_entity_to_video_device (link->sink->entity); +struct isc_device *isc =video_get_drvdata (vdev); +int ret; + + ret =v4l2_subdev_link_validate (link); +if (ret) +return ret; + +return isc_validate (isc); +} + +static const struct media_entity_operations isc_entity_operations = { + .link_validate = isc_link_validate, +}; +int isc_mc_init (struct isc_device *isc,u32 ver) {const struct of_device_id *match;
@@ -2023,6 +1977,8 @@ int isc_mc_init(struct isc_device *isc, u32 ver) isc->video_dev.entity.function =MEDIA_ENT_F_IO_V4L ; isc->video_dev.entity.flags =MEDIA_ENT_FL_DEFAULT ; + isc->video_dev.entity.ops = &isc_entity_operations; + isc->pads[ISC_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; ret = media_entity_pads_init(&isc->video_dev.entity, ISC_PADS_NUM,
drivers/media/platform/atmel/atmel-isc-scaler.c +5 -0
@@ -173,6 +173,10 @@ static const struct v4l2_subdev_pad_ops isc_scaler_pad_ops = { .init_cfg = isc_scaler_init_cfg, }; +static const struct media_entity_operations isc_scaler_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; +static const struct v4l2_subdev_ops xisc_scaler_subdev_ops = { .pad = &isc_scaler_pad_ops, };
@@ -190,6 +194,7 @@ int isc_scaler_init(struct isc_device *isc) isc->scaler_sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; isc->scaler_sd.entity.function =MEDIA_ENT_F_PROC_VIDEO_SCALER ; + isc->scaler_sd.entity.ops = &isc_scaler_entity_ops; isc->scaler_pads[ISC_SCALER_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; isc->scaler_pads[ISC_SCALER_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ;
drivers/media/platform/atmel/atmel-isc.h +7 -6
@@ -63,15 +63,16 @@ struct isc_subdev_entity {* @cfa_baycfg: If this format is RAW BAYER, indicate the type of bayer. this is either BGBG, RGRG, etc. * @pfe_cfg0_bps: Number of hardware data lines connected to the ISC +* @raw: If the format is raw bayer. */ struct isc_format {u32 fourcc;u32 mbus_code;u32 cfa_baycfg; - -bool sd_support;u32 pfe_cfg0_bps; + +bool raw; };/* Pipeline bitmap */
@@ -216,8 +217,7 @@ enum isc_scaler_pads {* @comp: completion reference that signals frame completion * * @fmt: current v42l format -* @user_formats: list of formats that are supported and agreed with sd -* @num_user_formats: how many formats are in user_formats +* @try_fmt: current v4l2 try format * * @config: current ISC format configuration * @try_config: the current ISC try format , not yet activated
@@ -272,6 +272,7 @@ enum isc_scaler_pads {* @formats_list_size: size of formats_list array * @pads: media controller pads for isc video entity * @mdev: media device that is registered by the isc +* @mpipe: media device pipeline used by the isc * @remote_pad: remote pad on the connected subdevice * @scaler_sd: subdevice for the scaler that isc registers * @scaler_pads: media controller pads for the scaler subdevice
@@ -298,8 +299,7 @@ struct isc_device {struct completion comp;struct v4l2_format fmt; -struct isc_format **user_formats; -unsigned int num_user_formats; +struct v4l2_format try_fmt;struct fmt_config config;struct fmt_config try_config;
@@ -369,6 +369,7 @@ struct isc_device {struct {struct media_pad pads[ISC_PADS_NUM ];struct media_device mdev; +struct media_pipeline mpipe;u32 remote_pad; };
drivers/media/platform/atmel/atmel-sama5d2-isc.c +20 -0
@@ -80,20 +80,40 @@ static const struct isc_format sama5d2_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y10, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };
drivers/media/platform/atmel/atmel-sama7g5-isc.c +20 -0
@@ -89,20 +89,40 @@ static const struct isc_format sama7g5_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y16, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };
Signature · 1 line
2.25.1
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)
drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);
The pipeline validation is done in start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick off start_streaming.
Drivers like vsp1, omap3isp and the samsung drivers all do this in streamon().
I think that is the correct time to do this.
Laurent, Jacopo, do you agree with that?
I notice that quite a few other drivers do this in start_streaming as well, but I think it just weird that a QBUF can return EPIPE while STREAMON might succeed.
Perhaps we need an optional vb2 validate() callback that is called by vb2_core_streamon() to validate the pipeline before streaming. That makes it easier to implement these checks rather than having to implement your own streamon ioctl.
Regards,
Hans
Quoted 742 lines
drivers/media/platform/atmel/atmel-isc-base.c +183
-223+if (ret) + goto err_pipeline_start; +/* Enable stream on the sub device */ ret =v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,1 );if (ret && ret != -ENOIOCTLCMD ) {@@ -385,6 +384,9 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,0 ); err_start_stream: +media_pipeline_stop (&isc->video_dev.entity); + +err_pipeline_start:spin_lock_irqsave (&isc->dma_queue_lock, flags);list_for_each_entry (buf, &isc->dma_queue, list)vb2_buffer_done (&buf->vb.vb2_buf,VB2_BUF_STATE_QUEUED );@@ -423,6 +425,9 @@ static void isc_stop_streaming(struct vb2_queue *vq)if (ret && ret != -ENOIOCTLCMD )v4l2_err (&isc->v4l2_dev,"stream off failed in subdev\n" ); +/* Stop media pipeline */ +media_pipeline_stop (&isc->video_dev.entity); +/* Release all active buffers */ spin_lock_irqsave (&isc->dma_queue_lock, flags);if (unlikely (isc->cur_frm)) {@@ -453,22 +458,6 @@ static void isc_buffer_queue(struct vb2_buffer *vb)spin_unlock_irqrestore (&isc->dma_queue_lock, flags); } -static struct isc_format *find_format_by_fourcc (struct isc_device *isc, -unsigned int fourcc) -{ -unsigned int num_formats = isc->num_user_formats; -struct isc_format *fmt; -unsigned int i; - -for (i =0 ; i < num_formats; i++) { - fmt = isc->user_formats[i]; -if (fmt->fourcc == fourcc) -return fmt; - } - -return NULL ; -} -static const struct vb2_ops isc_vb2_ops = { .queue_setup = isc_queue_setup, .wait_prepare = vb2_ops_wait_prepare,@@ -497,23 +486,57 @@ static int isc_enum_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file);u32 index = f->index; -u32 i, supported_index; +u32 i, supported_index =0 ; +struct isc_format *fmt; + +/* +* If we are not asked a specific mbus_code, we have to report all +* the formats that we can output. +*/ +if (!f->mbus_code) { +if (index >= isc->controller_formats_size) +return -EINVAL ; -if (index < isc->controller_formats_size) { f->pixelformat = isc->controller_formats[index].fourcc; + +return 0 ; + } + +/* +* If a specific mbus_code is requested, check if we support +* this mbus_code as input for the ISC. +* If it's supported, then we report the corresponding pixelformat +* as first possible option for the ISC. +* E.g. mbus MEDIA_BUS_FMT_YUYV8_2X8 and report +* 'YUYV' (YUYV 4:2:2) +*/ + fmt =isc_find_format_by_code (isc, f->mbus_code, &i); +if (!fmt) +return -EINVAL ; + +if (!index) { + f->pixelformat = fmt->fourcc; +return 0 ; } - index -= isc->controller_formats_size; + supported_index++; - supported_index =0 ; +/* If the index is not raw, we don't have anymore formats to report */ +if (!ISC_IS_FORMAT_RAW (f->mbus_code)) +return -EINVAL ; -for (i =0 ; i < isc->formats_list_size; i++) { -if (!ISC_IS_FORMAT_RAW (isc->formats_list[i].mbus_code) || - !isc->formats_list[i].sd_support) +/* +* We are asked for a specific mbus code, which is raw. +* We have to search through the formats we can convert to. +* We have to skip the raw formats, we cannot convert to raw. +* E.g. 'AR12' (16-bit ARGB 4-4-4-4), 'AR15' (16-bit ARGB 1-5-5-5), etc. +*/ +for (i =0 ; i < isc->controller_formats_size; i++) { +if (isc->controller_formats[i].raw)continue ; -if (supported_index == index) { - f->pixelformat = isc->formats_list[i].fourcc; +if (index == supported_index) { + f->pixelformat = isc->controller_formats[i].fourcc;return 0 ; } supported_index++;@@ -584,20 +607,30 @@ static int isc_try_validate_formats(struct isc_device *isc)break ;default :/* any other different formats are not supported */ +v4l2_err (&isc->v4l2_dev,"Requested unsupported format.\n" ); ret = -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)) +if (bayer && + !ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output RAW if we do not receive RAW.\n" );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)) + !ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output GREY if we do not receive RAW/GREY.\n" );return -EINVAL ; + } + +if ((rgb || bayer || yuv) && +ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot convert GREY to another format.\n" ); +return -EINVAL ; + }return ret; }@@ -825,7 +858,7 @@ static void isc_try_fse(struct isc_device *isc,* If we do not know yet which format the subdev is using, we cannot * do anything. */ -if (!isc->try_config.sd_format) +if (!isc->config.sd_format)return ; fse.code = isc->try_config.sd_format->mbus_code;@@ -846,180 +879,140 @@ static void isc_try_fse(struct isc_device *isc, } } -static int isc_try_fmt (struct isc_device *isc,struct v4l2_format *f, -u32 *code) +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_state pad_state = { - .pads = &pad_cfg - }; -struct v4l2_subdev_format format = { - .which =V4L2_SUBDEV_FORMAT_TRY , - }; -u32 mbus_code; -int ret; -bool rlp_dma_direct_dump = false; +unsigned int i;if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE )return -EINVAL ; -/* Step 1: find a RAW format that is supported */ -for (i =0 ; i < isc->num_user_formats; i++) { -if (ISC_IS_FORMAT_RAW (isc->user_formats[i]->mbus_code)) { - sd_fmt = isc->user_formats[i]; + isc->try_config.fourcc = isc->controller_formats[0 ].fourcc; + +/* find if the format requested is supported */ +for (i =0 ; i < isc->controller_formats_size; i++) +if (isc->controller_formats[i].fourcc == pixfmt->pixelformat) { + isc->try_config.fourcc = pixfmt->pixelformat;break ; } - } -/* Step 2: We can continue with this RAW format, or we can look -* for better: maybe sensor supports directly what we need. -*/ - direct_fmt =find_format_by_fourcc (isc, pixfmt->pixelformat); - -/* Step 3: We have both. We decide given the module parameter which -* one to use. -*/ -if (direct_fmt && sd_fmt && sensor_preferred) - sd_fmt = direct_fmt; - -/* Step 4: we do not have RAW but we have a direct format. Use it. */ -if (direct_fmt && !sd_fmt) - sd_fmt = direct_fmt; - -/* Step 5: if we are using a direct format, we need to package -* everything as 8 bit data and just dump it -*/ -if (sd_fmt == direct_fmt) - rlp_dma_direct_dump = true; - -/* Step 6: We have no format. This can happen if the userspace -* requests some weird/invalid format. -* In this case, default to whatever we have -*/ -if (!sd_fmt && !direct_fmt) { - sd_fmt = isc->user_formats[isc->num_user_formats -1 ]; -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Sensor not supporting %.4s, using %.4s\n" , - (char *)&pixfmt->pixelformat, (char *)&sd_fmt->fourcc); - } - -if (!sd_fmt) { - ret = -EINVAL ; - goto isc_try_fmt_err; - } - -/* Step 7: Print out what we decided for debugging */ -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Preferring to have sensor using format %.4s\n" , - (char *)&sd_fmt->fourcc); -/* Step 8: at this moment we decided which format the subdev will use */ - isc->try_config.sd_format = sd_fmt; +isc_try_configure_rlp_dma (isc, false);/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - -/* -* The mbus format is the one the subdev outputs. -* The pixels will be transferred in this format Sensor -> ISC -*/ - mbus_code = sd_fmt->mbus_code; - -/* -* Validate formats. If the required format is not OK, default to raw. -*/ - - isc->try_config.fourcc = pixfmt->pixelformat; - -if (isc_try_validate_formats (isc)) { - pixfmt->pixelformat = isc->try_config.fourcc = sd_fmt->fourcc; -/* Re-try to validate the new format */ - ret =isc_try_validate_formats (isc); -if (ret) - goto isc_try_fmt_err; - } - - ret =isc_try_configure_rlp_dma (isc, rlp_dma_direct_dump); -if (ret) - goto isc_try_fmt_err; - - ret =isc_try_configure_pipeline (isc); -if (ret) - goto isc_try_fmt_err; - -/* Obtain frame sizes if possible to have crop requirements ready */ -isc_try_fse (isc, &pad_state); - -v4l2_fill_mbus_format (&format.format, pixfmt, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, set_fmt, - &pad_state, &format); -if (ret <0 ) - goto isc_try_fmt_subdev_err; - -v4l2_fill_pix_format (pixfmt, &format.format); +v4l_bound_align_image (&pixfmt->width,16 , isc->max_width,0 , + &pixfmt->height,16 , isc->max_height,0 ,0 ); +/* If we did not find the requested format, we will fallback here */ + pixfmt->pixelformat = isc->try_config.fourcc; + pixfmt->colorspace =V4L2_COLORSPACE_SRGB ; + pixfmt->field =V4L2_FIELD_NONE ; -/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - pixfmt->field =V4L2_FIELD_NONE ; pixfmt->bytesperline = (pixfmt->width * isc->try_config.bpp_v4l2) >>3 ; pixfmt->sizeimage = ((pixfmt->width * isc->try_config.bpp) >>3 ) * pixfmt->height; -if (code) - *code = mbus_code; + isc->try_fmt = *f;return 0 ; +} -isc_try_fmt_err: -v4l2_err (&isc->v4l2_dev,"Could not find any possible format for a working pipeline\n" ); -isc_try_fmt_subdev_err: -memset (&isc->try_config,0 ,sizeof (isc->try_config)); +static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +{ +isc_try_fmt (isc, f); -return ret; +/* make the try configuration active */ + isc->config = isc->try_config; + isc->fmt = isc->try_fmt; + +v4l2_dbg (1 , debug, &isc->v4l2_dev,"ISC set_fmt to %.4s @%dx%d\n" , + (char *)&f->fmt.pix.pixelformat, + f->fmt.pix.width, f->fmt.pix.height); + +return 0 ; } -static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +static int isc_validate (struct isc_device *isc) { +int ret; +int i; +struct isc_format *sd_fmt =NULL ; +struct v4l2_pix_format *pixfmt = &isc->fmt.fmt.pix;struct v4l2_subdev_format format = { .which =V4L2_SUBDEV_FORMAT_ACTIVE , + .pad = isc->remote_pad, + }; +struct v4l2_subdev_pad_config pad_cfg = {}; +struct v4l2_subdev_state pad_state = { + .pads = &pad_cfg, }; -u32 mbus_code =0 ; -int ret; - ret =isc_try_fmt (isc, f, &mbus_code); +/* Get current format from subdev */ + ret =v4l2_subdev_call (isc->current_subdev->sd, pad, get_fmt,NULL , + &format);if (ret)return ret; -v4l2_fill_mbus_format (&format.format, &f->fmt.pix, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, - set_fmt,NULL , &format); -if (ret <0 ) -return ret; +/* Identify the subdev's format configuration */ +for (i =0 ; i < isc->formats_list_size; i++) +if (isc->formats_list[i].mbus_code == format.format.code) { + sd_fmt = &isc->formats_list[i]; +break ; + } + +/* Check if the format is not supported */ +if (!sd_fmt) { +v4l2_err (&isc->v4l2_dev, +"Current subdevice is streaming a media bus code that is not supported 0x%x\n" , + format.format.code); +return -EPIPE ; + } + +/* At this moment we know which format the subdev will use */ + isc->try_config.sd_format = sd_fmt; + +/* If the sensor is not RAW, we can only do a direct dump */ +if (!ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) +isc_try_configure_rlp_dma (isc, true);/* Limit to Atmel ISC hardware capabilities */ -if (f->fmt.pix.width > isc->max_width) - f->fmt.pix.width = isc->max_width; -if (f->fmt.pix.height > isc->max_height) - f->fmt.pix.height = isc->max_height; +v4l_bound_align_image (&format.format.width,16 , isc->max_width,0 , + &format.format.height,16 , isc->max_height,0 ,0 ); - isc->fmt = *f; +/* Check if the frame size is the same. Otherwise we may overflow */ +if (pixfmt->height != format.format.height || + pixfmt->width != format.format.width) { +v4l2_err (&isc->v4l2_dev, +"ISC not configured with the proper frame size: %dx%d\n" , + format.format.width, format.format.height); +return -EPIPE ; + } +v4l2_dbg (1 , debug, &isc->v4l2_dev, +"Identified subdev using format %.4s with %dx%d %d bpp\n" , + (char *)&sd_fmt->fourcc, pixfmt->width, pixfmt->height, + isc->try_config.bpp); + +/* Reset and restart AWB if the subdevice changed the format */ if (isc->try_config.sd_format && isc->config.sd_format && isc->try_config.sd_format != isc->config.sd_format) { isc->ctrls.hist_stat =HIST_INIT ;isc_reset_awb_ctrls (isc);isc_update_v4l2_ctrls (isc); } -/* make the try configuration active */ + +/* Validate formats */ + ret =isc_try_validate_formats (isc); +if (ret) +return ret; + +/* Obtain frame sizes if possible to have crop requirements ready */ +isc_try_fse (isc, &pad_state); + +/* Configure ISC pipeline for the config */ + ret =isc_try_configure_pipeline (isc); +if (ret) +return ret; + isc->config = isc->try_config;v4l2_dbg (1 , debug, &isc->v4l2_dev,"New ISC configuration in place\n" );@@ -1043,7 +1036,7 @@ static int isc_try_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file); -return isc_try_fmt (isc, f,NULL ); +return isc_try_fmt (isc, f); } static int isc_enum_input(struct file *file, void *priv,@@ -1098,10 +1091,6 @@ static int isc_enum_framesizes(struct file *file, void *fh,if (fsize->index)return -EINVAL ; -for (i =0 ; i < isc->num_user_formats; i++) -if (isc->user_formats[i]->fourcc == fsize->pixel_format) - ret =0 ; -for (i =0 ; i < isc->controller_formats_size; i++)if (isc->controller_formats[i].fourcc == fsize->pixel_format) ret =0 ;@@ -1782,52 +1771,6 @@ struct isc_format *isc_find_format_by_code(struct isc_device *isc, }EXPORT_SYMBOL_GPL (isc_find_format_by_code); -static int isc_formats_init (struct isc_device *isc) -{ -struct isc_format *fmt; -struct v4l2_subdev *subdev = isc->current_subdev->sd; -unsigned int num_fmts, i, j; -u32 list_size = isc->formats_list_size; -struct v4l2_subdev_mbus_code_enum mbus_code = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - }; - - num_fmts =0 ; -while (!v4l2_subdev_call (subdev, pad, enum_mbus_code, -NULL , &mbus_code)) { - mbus_code.index++; - - fmt =isc_find_format_by_code (isc, mbus_code.code, &i); -if (!fmt) { -v4l2_warn (&isc->v4l2_dev,"Mbus code %x not supported\n" , - mbus_code.code); -continue ; - } - - fmt->sd_support = true; - num_fmts++; - } - -if (!num_fmts) -return -ENXIO ; - - isc->num_user_formats = num_fmts; - isc->user_formats =devm_kcalloc (isc->dev, - num_fmts,sizeof (*isc->user_formats), -GFP_KERNEL ); -if (!isc->user_formats) -return -ENOMEM ; - - fmt = &isc->formats_list[0 ]; -for (i =0 , j =0 ; i < list_size; i++) { -if (fmt->sd_support) - isc->user_formats[j++] = fmt; - fmt++; - } - -return 0 ; -} -static int isc_set_default_fmt (struct isc_device *isc) {struct v4l2_format f = {@@ -1836,12 +1779,12 @@ static int isc_set_default_fmt(struct isc_device *isc) .width = VGA_WIDTH, .height = VGA_HEIGHT, .field = V4L2_FIELD_NONE, - .pixelformat = isc->user_formats[0]->fourcc, + .pixelformat = isc->controller_formats[0].fourcc, }, };int ret; - ret =isc_try_fmt (isc, &f,NULL ); + ret =isc_try_fmt (isc, &f);if (ret)return ret;@@ -1896,13 +1839,6 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)spin_lock_init (&isc->dma_queue_lock);spin_lock_init (&isc->awb_lock); - ret =isc_formats_init (isc); -if (ret <0 ) { -v4l2_err (&isc->v4l2_dev, -"Init format failed: %d\n" , ret); - goto isc_async_complete_err; - } - ret =isc_set_default_fmt (isc);if (ret) {v4l2_err (&isc->v4l2_dev,"Could not set default format\n" );@@ -2016,6 +1952,24 @@ int isc_pipeline_init(struct isc_device *isc) }EXPORT_SYMBOL_GPL (isc_pipeline_init); +static int isc_link_validate (struct media_link *link) +{ +struct video_device *vdev = +media_entity_to_video_device (link->sink->entity); +struct isc_device *isc =video_get_drvdata (vdev); +int ret; + + ret =v4l2_subdev_link_validate (link); +if (ret) +return ret; + +return isc_validate (isc); +} + +static const struct media_entity_operations isc_entity_operations = { + .link_validate = isc_link_validate, +}; +int isc_mc_init (struct isc_device *isc,u32 ver) {const struct of_device_id *match;@@ -2023,6 +1977,8 @@ int isc_mc_init(struct isc_device *isc, u32 ver) isc->video_dev.entity.function =MEDIA_ENT_F_IO_V4L ; isc->video_dev.entity.flags =MEDIA_ENT_FL_DEFAULT ; + isc->video_dev.entity.ops = &isc_entity_operations; + isc->pads[ISC_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; ret = media_entity_pads_init(&isc->video_dev.entity, ISC_PADS_NUM,drivers/media/platform/atmel/atmel-isc-scaler.c +5
-0@@ -173,6 +173,10 @@ static const struct v4l2_subdev_pad_ops isc_scaler_pad_ops = { .init_cfg = isc_scaler_init_cfg, }; +static const struct media_entity_operations isc_scaler_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; +static const struct v4l2_subdev_ops xisc_scaler_subdev_ops = { .pad = &isc_scaler_pad_ops, };@@ -190,6 +194,7 @@ int isc_scaler_init(struct isc_device *isc) isc->scaler_sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; isc->scaler_sd.entity.function =MEDIA_ENT_F_PROC_VIDEO_SCALER ; + isc->scaler_sd.entity.ops = &isc_scaler_entity_ops; isc->scaler_pads[ISC_SCALER_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; isc->scaler_pads[ISC_SCALER_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ;drivers/media/platform/atmel/atmel-isc.h +7
-6@@ -63,15 +63,16 @@ struct isc_subdev_entity {* @cfa_baycfg: If this format is RAW BAYER, indicate the type of bayer. this is either BGBG, RGRG, etc. * @pfe_cfg0_bps: Number of hardware data lines connected to the ISC +* @raw: If the format is raw bayer. */ struct isc_format {u32 fourcc;u32 mbus_code;u32 cfa_baycfg; - -bool sd_support;u32 pfe_cfg0_bps; + +bool raw; };/* Pipeline bitmap */ @@ -216,8 +217,7 @@ enum isc_scaler_pads {* @comp: completion reference that signals frame completion * * @fmt: current v42l format -* @user_formats: list of formats that are supported and agreed with sd -* @num_user_formats: how many formats are in user_formats +* @try_fmt: current v4l2 try format * * @config: current ISC format configuration * @try_config: the current ISC try format , not yet activated @@ -272,6 +272,7 @@ enum isc_scaler_pads {* @formats_list_size: size of formats_list array * @pads: media controller pads for isc video entity * @mdev: media device that is registered by the isc +* @mpipe: media device pipeline used by the isc * @remote_pad: remote pad on the connected subdevice * @scaler_sd: subdevice for the scaler that isc registers * @scaler_pads: media controller pads for the scaler subdevice @@ -298,8 +299,7 @@ struct isc_device {struct completion comp;struct v4l2_format fmt; -struct isc_format **user_formats; -unsigned int num_user_formats; +struct v4l2_format try_fmt;struct fmt_config config;struct fmt_config try_config;@@ -369,6 +369,7 @@ struct isc_device {struct {struct media_pad pads[ISC_PADS_NUM ];struct media_device mdev; +struct media_pipeline mpipe;u32 remote_pad; };drivers/media/platform/atmel/atmel-sama5d2-isc.c +20
-0@@ -80,20 +80,40 @@ static const struct isc_format sama5d2_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y10, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };drivers/media/platform/atmel/atmel-sama7g5-isc.c +20
-0@@ -89,20 +89,40 @@ static const struct isc_format sama7g5_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y16, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Quoted 83 lines · Hans Verkuil
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.
Quoted 3 lines
Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in streamon(). The problem that I faced at that time was that streamoff was never called, so I could not call media_pipeline_stop(). Then Jacopo told me to move it to start_streaming (see change log for v4) , and I did not face any more problems.
Eugen
Quoted 759 lines
Laurent, Jacopo, do you agree with that?
I notice that quite a few other drivers do this in
start_streamingas well, but I think it just weird that a QBUF can return EPIPE while STREAMON might succeed.Perhaps we need an optional vb2
validate()callback that is called byvb2_core_streamon()to validate the pipeline before streaming. That makes it easier to implement these checks rather than having to implement your own streamon ioctl.Regards,
Hans
Quoted 742 lines
drivers/media/platform/atmel/atmel-isc-base.c +183
-223+if (ret) + goto err_pipeline_start; +/* Enable stream on the sub device */ ret =v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,1 );if (ret && ret != -ENOIOCTLCMD ) {@@ -385,6 +384,9 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,0 ); err_start_stream: +media_pipeline_stop (&isc->video_dev.entity); + +err_pipeline_start:spin_lock_irqsave (&isc->dma_queue_lock, flags);list_for_each_entry (buf, &isc->dma_queue, list)vb2_buffer_done (&buf->vb.vb2_buf,VB2_BUF_STATE_QUEUED );@@ -423,6 +425,9 @@ static void isc_stop_streaming(struct vb2_queue *vq)if (ret && ret != -ENOIOCTLCMD )v4l2_err (&isc->v4l2_dev,"stream off failed in subdev\n" ); +/* Stop media pipeline */ +media_pipeline_stop (&isc->video_dev.entity); +/* Release all active buffers */ spin_lock_irqsave (&isc->dma_queue_lock, flags);if (unlikely (isc->cur_frm)) {@@ -453,22 +458,6 @@ static void isc_buffer_queue(struct vb2_buffer *vb)spin_unlock_irqrestore (&isc->dma_queue_lock, flags); } -static struct isc_format *find_format_by_fourcc (struct isc_device *isc, -unsigned int fourcc) -{ -unsigned int num_formats = isc->num_user_formats; -struct isc_format *fmt; -unsigned int i; - -for (i =0 ; i < num_formats; i++) { - fmt = isc->user_formats[i]; -if (fmt->fourcc == fourcc) -return fmt; - } - -return NULL ; -} -static const struct vb2_ops isc_vb2_ops = { .queue_setup = isc_queue_setup, .wait_prepare = vb2_ops_wait_prepare,@@ -497,23 +486,57 @@ static int isc_enum_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file);u32 index = f->index; -u32 i, supported_index; +u32 i, supported_index =0 ; +struct isc_format *fmt; + +/* +* If we are not asked a specific mbus_code, we have to report all +* the formats that we can output. +*/ +if (!f->mbus_code) { +if (index >= isc->controller_formats_size) +return -EINVAL ; -if (index < isc->controller_formats_size) { f->pixelformat = isc->controller_formats[index].fourcc; + +return 0 ; + } + +/* +* If a specific mbus_code is requested, check if we support +* this mbus_code as input for the ISC. +* If it's supported, then we report the corresponding pixelformat +* as first possible option for the ISC. +* E.g. mbus MEDIA_BUS_FMT_YUYV8_2X8 and report +* 'YUYV' (YUYV 4:2:2) +*/ + fmt =isc_find_format_by_code (isc, f->mbus_code, &i); +if (!fmt) +return -EINVAL ; + +if (!index) { + f->pixelformat = fmt->fourcc; +return 0 ; } - index -= isc->controller_formats_size; + supported_index++; - supported_index =0 ; +/* If the index is not raw, we don't have anymore formats to report */ +if (!ISC_IS_FORMAT_RAW (f->mbus_code)) +return -EINVAL ; -for (i =0 ; i < isc->formats_list_size; i++) { -if (!ISC_IS_FORMAT_RAW (isc->formats_list[i].mbus_code) || - !isc->formats_list[i].sd_support) +/* +* We are asked for a specific mbus code, which is raw. +* We have to search through the formats we can convert to. +* We have to skip the raw formats, we cannot convert to raw. +* E.g. 'AR12' (16-bit ARGB 4-4-4-4), 'AR15' (16-bit ARGB 1-5-5-5), etc. +*/ +for (i =0 ; i < isc->controller_formats_size; i++) { +if (isc->controller_formats[i].raw)continue ; -if (supported_index == index) { - f->pixelformat = isc->formats_list[i].fourcc; +if (index == supported_index) { + f->pixelformat = isc->controller_formats[i].fourcc;return 0 ; } supported_index++;@@ -584,20 +607,30 @@ static int isc_try_validate_formats(struct isc_device *isc)break ;default :/* any other different formats are not supported */ +v4l2_err (&isc->v4l2_dev,"Requested unsupported format.\n" ); ret = -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)) +if (bayer && + !ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output RAW if we do not receive RAW.\n" );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)) + !ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output GREY if we do not receive RAW/GREY.\n" );return -EINVAL ; + } + +if ((rgb || bayer || yuv) && +ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot convert GREY to another format.\n" ); +return -EINVAL ; + }return ret; }@@ -825,7 +858,7 @@ static void isc_try_fse(struct isc_device *isc,* If we do not know yet which format the subdev is using, we cannot * do anything. */ -if (!isc->try_config.sd_format) +if (!isc->config.sd_format)return ; fse.code = isc->try_config.sd_format->mbus_code;@@ -846,180 +879,140 @@ static void isc_try_fse(struct isc_device *isc, } } -static int isc_try_fmt (struct isc_device *isc,struct v4l2_format *f, -u32 *code) +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_state pad_state = { - .pads = &pad_cfg - }; -struct v4l2_subdev_format format = { - .which =V4L2_SUBDEV_FORMAT_TRY , - }; -u32 mbus_code; -int ret; -bool rlp_dma_direct_dump = false; +unsigned int i;if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE )return -EINVAL ; -/* Step 1: find a RAW format that is supported */ -for (i =0 ; i < isc->num_user_formats; i++) { -if (ISC_IS_FORMAT_RAW (isc->user_formats[i]->mbus_code)) { - sd_fmt = isc->user_formats[i]; + isc->try_config.fourcc = isc->controller_formats[0 ].fourcc; + +/* find if the format requested is supported */ +for (i =0 ; i < isc->controller_formats_size; i++) +if (isc->controller_formats[i].fourcc == pixfmt->pixelformat) { + isc->try_config.fourcc = pixfmt->pixelformat;break ; } - } -/* Step 2: We can continue with this RAW format, or we can look -* for better: maybe sensor supports directly what we need. -*/ - direct_fmt =find_format_by_fourcc (isc, pixfmt->pixelformat); - -/* Step 3: We have both. We decide given the module parameter which -* one to use. -*/ -if (direct_fmt && sd_fmt && sensor_preferred) - sd_fmt = direct_fmt; - -/* Step 4: we do not have RAW but we have a direct format. Use it. */ -if (direct_fmt && !sd_fmt) - sd_fmt = direct_fmt; - -/* Step 5: if we are using a direct format, we need to package -* everything as 8 bit data and just dump it -*/ -if (sd_fmt == direct_fmt) - rlp_dma_direct_dump = true; - -/* Step 6: We have no format. This can happen if the userspace -* requests some weird/invalid format. -* In this case, default to whatever we have -*/ -if (!sd_fmt && !direct_fmt) { - sd_fmt = isc->user_formats[isc->num_user_formats -1 ]; -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Sensor not supporting %.4s, using %.4s\n" , - (char *)&pixfmt->pixelformat, (char *)&sd_fmt->fourcc); - } - -if (!sd_fmt) { - ret = -EINVAL ; - goto isc_try_fmt_err; - } - -/* Step 7: Print out what we decided for debugging */ -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Preferring to have sensor using format %.4s\n" , - (char *)&sd_fmt->fourcc); -/* Step 8: at this moment we decided which format the subdev will use */ - isc->try_config.sd_format = sd_fmt; +isc_try_configure_rlp_dma (isc, false);/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - -/* -* The mbus format is the one the subdev outputs. -* The pixels will be transferred in this format Sensor -> ISC -*/ - mbus_code = sd_fmt->mbus_code; - -/* -* Validate formats. If the required format is not OK, default to raw. -*/ - - isc->try_config.fourcc = pixfmt->pixelformat; - -if (isc_try_validate_formats (isc)) { - pixfmt->pixelformat = isc->try_config.fourcc = sd_fmt->fourcc; -/* Re-try to validate the new format */ - ret =isc_try_validate_formats (isc); -if (ret) - goto isc_try_fmt_err; - } - - ret =isc_try_configure_rlp_dma (isc, rlp_dma_direct_dump); -if (ret) - goto isc_try_fmt_err; - - ret =isc_try_configure_pipeline (isc); -if (ret) - goto isc_try_fmt_err; - -/* Obtain frame sizes if possible to have crop requirements ready */ -isc_try_fse (isc, &pad_state); - -v4l2_fill_mbus_format (&format.format, pixfmt, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, set_fmt, - &pad_state, &format); -if (ret <0 ) - goto isc_try_fmt_subdev_err; - -v4l2_fill_pix_format (pixfmt, &format.format); +v4l_bound_align_image (&pixfmt->width,16 , isc->max_width,0 , + &pixfmt->height,16 , isc->max_height,0 ,0 ); +/* If we did not find the requested format, we will fallback here */ + pixfmt->pixelformat = isc->try_config.fourcc; + pixfmt->colorspace =V4L2_COLORSPACE_SRGB ; + pixfmt->field =V4L2_FIELD_NONE ; -/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - pixfmt->field =V4L2_FIELD_NONE ; pixfmt->bytesperline = (pixfmt->width * isc->try_config.bpp_v4l2) >>3 ; pixfmt->sizeimage = ((pixfmt->width * isc->try_config.bpp) >>3 ) * pixfmt->height; -if (code) - *code = mbus_code; + isc->try_fmt = *f;return 0 ; +} -isc_try_fmt_err: -v4l2_err (&isc->v4l2_dev,"Could not find any possible format for a working pipeline\n" ); -isc_try_fmt_subdev_err: -memset (&isc->try_config,0 ,sizeof (isc->try_config)); +static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +{ +isc_try_fmt (isc, f); -return ret; +/* make the try configuration active */ + isc->config = isc->try_config; + isc->fmt = isc->try_fmt; + +v4l2_dbg (1 , debug, &isc->v4l2_dev,"ISC set_fmt to %.4s @%dx%d\n" , + (char *)&f->fmt.pix.pixelformat, + f->fmt.pix.width, f->fmt.pix.height); + +return 0 ; } -static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +static int isc_validate (struct isc_device *isc) { +int ret; +int i; +struct isc_format *sd_fmt =NULL ; +struct v4l2_pix_format *pixfmt = &isc->fmt.fmt.pix;struct v4l2_subdev_format format = { .which =V4L2_SUBDEV_FORMAT_ACTIVE , + .pad = isc->remote_pad, + }; +struct v4l2_subdev_pad_config pad_cfg = {}; +struct v4l2_subdev_state pad_state = { + .pads = &pad_cfg, }; -u32 mbus_code =0 ; -int ret; - ret =isc_try_fmt (isc, f, &mbus_code); +/* Get current format from subdev */ + ret =v4l2_subdev_call (isc->current_subdev->sd, pad, get_fmt,NULL , + &format);if (ret)return ret; -v4l2_fill_mbus_format (&format.format, &f->fmt.pix, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, - set_fmt,NULL , &format); -if (ret <0 ) -return ret; +/* Identify the subdev's format configuration */ +for (i =0 ; i < isc->formats_list_size; i++) +if (isc->formats_list[i].mbus_code == format.format.code) { + sd_fmt = &isc->formats_list[i]; +break ; + } + +/* Check if the format is not supported */ +if (!sd_fmt) { +v4l2_err (&isc->v4l2_dev, +"Current subdevice is streaming a media bus code that is not supported 0x%x\n" , + format.format.code); +return -EPIPE ; + } + +/* At this moment we know which format the subdev will use */ + isc->try_config.sd_format = sd_fmt; + +/* If the sensor is not RAW, we can only do a direct dump */ +if (!ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) +isc_try_configure_rlp_dma (isc, true);/* Limit to Atmel ISC hardware capabilities */ -if (f->fmt.pix.width > isc->max_width) - f->fmt.pix.width = isc->max_width; -if (f->fmt.pix.height > isc->max_height) - f->fmt.pix.height = isc->max_height; +v4l_bound_align_image (&format.format.width,16 , isc->max_width,0 , + &format.format.height,16 , isc->max_height,0 ,0 ); - isc->fmt = *f; +/* Check if the frame size is the same. Otherwise we may overflow */ +if (pixfmt->height != format.format.height || + pixfmt->width != format.format.width) { +v4l2_err (&isc->v4l2_dev, +"ISC not configured with the proper frame size: %dx%d\n" , + format.format.width, format.format.height); +return -EPIPE ; + } +v4l2_dbg (1 , debug, &isc->v4l2_dev, +"Identified subdev using format %.4s with %dx%d %d bpp\n" , + (char *)&sd_fmt->fourcc, pixfmt->width, pixfmt->height, + isc->try_config.bpp); + +/* Reset and restart AWB if the subdevice changed the format */ if (isc->try_config.sd_format && isc->config.sd_format && isc->try_config.sd_format != isc->config.sd_format) { isc->ctrls.hist_stat =HIST_INIT ;isc_reset_awb_ctrls (isc);isc_update_v4l2_ctrls (isc); } -/* make the try configuration active */ + +/* Validate formats */ + ret =isc_try_validate_formats (isc); +if (ret) +return ret; + +/* Obtain frame sizes if possible to have crop requirements ready */ +isc_try_fse (isc, &pad_state); + +/* Configure ISC pipeline for the config */ + ret =isc_try_configure_pipeline (isc); +if (ret) +return ret; + isc->config = isc->try_config;v4l2_dbg (1 , debug, &isc->v4l2_dev,"New ISC configuration in place\n" );@@ -1043,7 +1036,7 @@ static int isc_try_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file); -return isc_try_fmt (isc, f,NULL ); +return isc_try_fmt (isc, f); } static int isc_enum_input(struct file *file, void *priv,@@ -1098,10 +1091,6 @@ static int isc_enum_framesizes(struct file *file, void *fh,if (fsize->index)return -EINVAL ; -for (i =0 ; i < isc->num_user_formats; i++) -if (isc->user_formats[i]->fourcc == fsize->pixel_format) - ret =0 ; -for (i =0 ; i < isc->controller_formats_size; i++)if (isc->controller_formats[i].fourcc == fsize->pixel_format) ret =0 ;@@ -1782,52 +1771,6 @@ struct isc_format *isc_find_format_by_code(struct isc_device *isc, }EXPORT_SYMBOL_GPL (isc_find_format_by_code); -static int isc_formats_init (struct isc_device *isc) -{ -struct isc_format *fmt; -struct v4l2_subdev *subdev = isc->current_subdev->sd; -unsigned int num_fmts, i, j; -u32 list_size = isc->formats_list_size; -struct v4l2_subdev_mbus_code_enum mbus_code = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - }; - - num_fmts =0 ; -while (!v4l2_subdev_call (subdev, pad, enum_mbus_code, -NULL , &mbus_code)) { - mbus_code.index++; - - fmt =isc_find_format_by_code (isc, mbus_code.code, &i); -if (!fmt) { -v4l2_warn (&isc->v4l2_dev,"Mbus code %x not supported\n" , - mbus_code.code); -continue ; - } - - fmt->sd_support = true; - num_fmts++; - } - -if (!num_fmts) -return -ENXIO ; - - isc->num_user_formats = num_fmts; - isc->user_formats =devm_kcalloc (isc->dev, - num_fmts,sizeof (*isc->user_formats), -GFP_KERNEL ); -if (!isc->user_formats) -return -ENOMEM ; - - fmt = &isc->formats_list[0 ]; -for (i =0 , j =0 ; i < list_size; i++) { -if (fmt->sd_support) - isc->user_formats[j++] = fmt; - fmt++; - } - -return 0 ; -} -static int isc_set_default_fmt (struct isc_device *isc) {struct v4l2_format f = {@@ -1836,12 +1779,12 @@ static int isc_set_default_fmt(struct isc_device *isc) .width = VGA_WIDTH, .height = VGA_HEIGHT, .field = V4L2_FIELD_NONE, - .pixelformat = isc->user_formats[0]->fourcc, + .pixelformat = isc->controller_formats[0].fourcc, }, };int ret; - ret =isc_try_fmt (isc, &f,NULL ); + ret =isc_try_fmt (isc, &f);if (ret)return ret;@@ -1896,13 +1839,6 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)spin_lock_init (&isc->dma_queue_lock);spin_lock_init (&isc->awb_lock); - ret =isc_formats_init (isc); -if (ret <0 ) { -v4l2_err (&isc->v4l2_dev, -"Init format failed: %d\n" , ret); - goto isc_async_complete_err; - } - ret =isc_set_default_fmt (isc);if (ret) {v4l2_err (&isc->v4l2_dev,"Could not set default format\n" );@@ -2016,6 +1952,24 @@ int isc_pipeline_init(struct isc_device *isc) }EXPORT_SYMBOL_GPL (isc_pipeline_init); +static int isc_link_validate (struct media_link *link) +{ +struct video_device *vdev = +media_entity_to_video_device (link->sink->entity); +struct isc_device *isc =video_get_drvdata (vdev); +int ret; + + ret =v4l2_subdev_link_validate (link); +if (ret) +return ret; + +return isc_validate (isc); +} + +static const struct media_entity_operations isc_entity_operations = { + .link_validate = isc_link_validate, +}; +int isc_mc_init (struct isc_device *isc,u32 ver) {const struct of_device_id *match;@@ -2023,6 +1977,8 @@ int isc_mc_init(struct isc_device *isc, u32 ver) isc->video_dev.entity.function =MEDIA_ENT_F_IO_V4L ; isc->video_dev.entity.flags =MEDIA_ENT_FL_DEFAULT ; + isc->video_dev.entity.ops = &isc_entity_operations; + isc->pads[ISC_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; ret = media_entity_pads_init(&isc->video_dev.entity, ISC_PADS_NUM,drivers/media/platform/atmel/atmel-isc-scaler.c +5
-0@@ -173,6 +173,10 @@ static const struct v4l2_subdev_pad_ops isc_scaler_pad_ops = { .init_cfg = isc_scaler_init_cfg, }; +static const struct media_entity_operations isc_scaler_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; +static const struct v4l2_subdev_ops xisc_scaler_subdev_ops = { .pad = &isc_scaler_pad_ops, };@@ -190,6 +194,7 @@ int isc_scaler_init(struct isc_device *isc) isc->scaler_sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; isc->scaler_sd.entity.function =MEDIA_ENT_F_PROC_VIDEO_SCALER ; + isc->scaler_sd.entity.ops = &isc_scaler_entity_ops; isc->scaler_pads[ISC_SCALER_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; isc->scaler_pads[ISC_SCALER_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ;drivers/media/platform/atmel/atmel-isc.h +7
-6@@ -63,15 +63,16 @@ struct isc_subdev_entity {* @cfa_baycfg: If this format is RAW BAYER, indicate the type of bayer. this is either BGBG, RGRG, etc. * @pfe_cfg0_bps: Number of hardware data lines connected to the ISC +* @raw: If the format is raw bayer. */ struct isc_format {u32 fourcc;u32 mbus_code;u32 cfa_baycfg; - -bool sd_support;u32 pfe_cfg0_bps; + +bool raw; };/* Pipeline bitmap */ @@ -216,8 +217,7 @@ enum isc_scaler_pads {* @comp: completion reference that signals frame completion * * @fmt: current v42l format -* @user_formats: list of formats that are supported and agreed with sd -* @num_user_formats: how many formats are in user_formats +* @try_fmt: current v4l2 try format * * @config: current ISC format configuration * @try_config: the current ISC try format , not yet activated @@ -272,6 +272,7 @@ enum isc_scaler_pads {* @formats_list_size: size of formats_list array * @pads: media controller pads for isc video entity * @mdev: media device that is registered by the isc +* @mpipe: media device pipeline used by the isc * @remote_pad: remote pad on the connected subdevice * @scaler_sd: subdevice for the scaler that isc registers * @scaler_pads: media controller pads for the scaler subdevice @@ -298,8 +299,7 @@ struct isc_device {struct completion comp;struct v4l2_format fmt; -struct isc_format **user_formats; -unsigned int num_user_formats; +struct v4l2_format try_fmt;struct fmt_config config;struct fmt_config try_config;@@ -369,6 +369,7 @@ struct isc_device {struct {struct media_pad pads[ISC_PADS_NUM ];struct media_device mdev; +struct media_pipeline mpipe;u32 remote_pad; };drivers/media/platform/atmel/atmel-sama5d2-isc.c +20
-0@@ -80,20 +80,40 @@ static const struct isc_format sama5d2_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y10, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };drivers/media/platform/atmel/atmel-sama7g5-isc.c +20
-0@@ -89,20 +89,40 @@ static const struct isc_format sama7g5_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y16, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.
It's a mess. Looking at some drivers I see that omap3isp calls media_pipeline_stop in streamoff (so will have the same problem as you described if VIDIOC_STREAMOFF isn't called), exynos4-is does the same, but it also checks the streaming state in the release() fop callback, so that would fix this problem. And vimc does this in stop_streaming.
I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
I'd like to know what others think.
Regards,
Hans
Quoted 763 lines
Eugen
Quoted 759 lines
Laurent, Jacopo, do you agree with that?
I notice that quite a few other drivers do this in
start_streamingas well, but I think it just weird that a QBUF can return EPIPE while STREAMON might succeed.Perhaps we need an optional vb2
validate()callback that is called byvb2_core_streamon()to validate the pipeline before streaming. That makes it easier to implement these checks rather than having to implement your own streamon ioctl.Regards,
Hans
Quoted 742 lines
drivers/media/platform/atmel/atmel-isc-base.c +183
-223+if (ret) + goto err_pipeline_start; +/* Enable stream on the sub device */ ret =v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,1 );if (ret && ret != -ENOIOCTLCMD ) {@@ -385,6 +384,9 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,0 ); err_start_stream: +media_pipeline_stop (&isc->video_dev.entity); + +err_pipeline_start:spin_lock_irqsave (&isc->dma_queue_lock, flags);list_for_each_entry (buf, &isc->dma_queue, list)vb2_buffer_done (&buf->vb.vb2_buf,VB2_BUF_STATE_QUEUED );@@ -423,6 +425,9 @@ static void isc_stop_streaming(struct vb2_queue *vq)if (ret && ret != -ENOIOCTLCMD )v4l2_err (&isc->v4l2_dev,"stream off failed in subdev\n" ); +/* Stop media pipeline */ +media_pipeline_stop (&isc->video_dev.entity); +/* Release all active buffers */ spin_lock_irqsave (&isc->dma_queue_lock, flags);if (unlikely (isc->cur_frm)) {@@ -453,22 +458,6 @@ static void isc_buffer_queue(struct vb2_buffer *vb)spin_unlock_irqrestore (&isc->dma_queue_lock, flags); } -static struct isc_format *find_format_by_fourcc (struct isc_device *isc, -unsigned int fourcc) -{ -unsigned int num_formats = isc->num_user_formats; -struct isc_format *fmt; -unsigned int i; - -for (i =0 ; i < num_formats; i++) { - fmt = isc->user_formats[i]; -if (fmt->fourcc == fourcc) -return fmt; - } - -return NULL ; -} -static const struct vb2_ops isc_vb2_ops = { .queue_setup = isc_queue_setup, .wait_prepare = vb2_ops_wait_prepare,@@ -497,23 +486,57 @@ static int isc_enum_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file);u32 index = f->index; -u32 i, supported_index; +u32 i, supported_index =0 ; +struct isc_format *fmt; + +/* +* If we are not asked a specific mbus_code, we have to report all +* the formats that we can output. +*/ +if (!f->mbus_code) { +if (index >= isc->controller_formats_size) +return -EINVAL ; -if (index < isc->controller_formats_size) { f->pixelformat = isc->controller_formats[index].fourcc; + +return 0 ; + } + +/* +* If a specific mbus_code is requested, check if we support +* this mbus_code as input for the ISC. +* If it's supported, then we report the corresponding pixelformat +* as first possible option for the ISC. +* E.g. mbus MEDIA_BUS_FMT_YUYV8_2X8 and report +* 'YUYV' (YUYV 4:2:2) +*/ + fmt =isc_find_format_by_code (isc, f->mbus_code, &i); +if (!fmt) +return -EINVAL ; + +if (!index) { + f->pixelformat = fmt->fourcc; +return 0 ; } - index -= isc->controller_formats_size; + supported_index++; - supported_index =0 ; +/* If the index is not raw, we don't have anymore formats to report */ +if (!ISC_IS_FORMAT_RAW (f->mbus_code)) +return -EINVAL ; -for (i =0 ; i < isc->formats_list_size; i++) { -if (!ISC_IS_FORMAT_RAW (isc->formats_list[i].mbus_code) || - !isc->formats_list[i].sd_support) +/* +* We are asked for a specific mbus code, which is raw. +* We have to search through the formats we can convert to. +* We have to skip the raw formats, we cannot convert to raw. +* E.g. 'AR12' (16-bit ARGB 4-4-4-4), 'AR15' (16-bit ARGB 1-5-5-5), etc. +*/ +for (i =0 ; i < isc->controller_formats_size; i++) { +if (isc->controller_formats[i].raw)continue ; -if (supported_index == index) { - f->pixelformat = isc->formats_list[i].fourcc; +if (index == supported_index) { + f->pixelformat = isc->controller_formats[i].fourcc;return 0 ; } supported_index++;@@ -584,20 +607,30 @@ static int isc_try_validate_formats(struct isc_device *isc)break ;default :/* any other different formats are not supported */ +v4l2_err (&isc->v4l2_dev,"Requested unsupported format.\n" ); ret = -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)) +if (bayer && + !ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output RAW if we do not receive RAW.\n" );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)) + !ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output GREY if we do not receive RAW/GREY.\n" );return -EINVAL ; + } + +if ((rgb || bayer || yuv) && +ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot convert GREY to another format.\n" ); +return -EINVAL ; + }return ret; }@@ -825,7 +858,7 @@ static void isc_try_fse(struct isc_device *isc,* If we do not know yet which format the subdev is using, we cannot * do anything. */ -if (!isc->try_config.sd_format) +if (!isc->config.sd_format)return ; fse.code = isc->try_config.sd_format->mbus_code;@@ -846,180 +879,140 @@ static void isc_try_fse(struct isc_device *isc, } } -static int isc_try_fmt (struct isc_device *isc,struct v4l2_format *f, -u32 *code) +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_state pad_state = { - .pads = &pad_cfg - }; -struct v4l2_subdev_format format = { - .which =V4L2_SUBDEV_FORMAT_TRY , - }; -u32 mbus_code; -int ret; -bool rlp_dma_direct_dump = false; +unsigned int i;if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE )return -EINVAL ; -/* Step 1: find a RAW format that is supported */ -for (i =0 ; i < isc->num_user_formats; i++) { -if (ISC_IS_FORMAT_RAW (isc->user_formats[i]->mbus_code)) { - sd_fmt = isc->user_formats[i]; + isc->try_config.fourcc = isc->controller_formats[0 ].fourcc; + +/* find if the format requested is supported */ +for (i =0 ; i < isc->controller_formats_size; i++) +if (isc->controller_formats[i].fourcc == pixfmt->pixelformat) { + isc->try_config.fourcc = pixfmt->pixelformat;break ; } - } -/* Step 2: We can continue with this RAW format, or we can look -* for better: maybe sensor supports directly what we need. -*/ - direct_fmt =find_format_by_fourcc (isc, pixfmt->pixelformat); - -/* Step 3: We have both. We decide given the module parameter which -* one to use. -*/ -if (direct_fmt && sd_fmt && sensor_preferred) - sd_fmt = direct_fmt; - -/* Step 4: we do not have RAW but we have a direct format. Use it. */ -if (direct_fmt && !sd_fmt) - sd_fmt = direct_fmt; - -/* Step 5: if we are using a direct format, we need to package -* everything as 8 bit data and just dump it -*/ -if (sd_fmt == direct_fmt) - rlp_dma_direct_dump = true; - -/* Step 6: We have no format. This can happen if the userspace -* requests some weird/invalid format. -* In this case, default to whatever we have -*/ -if (!sd_fmt && !direct_fmt) { - sd_fmt = isc->user_formats[isc->num_user_formats -1 ]; -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Sensor not supporting %.4s, using %.4s\n" , - (char *)&pixfmt->pixelformat, (char *)&sd_fmt->fourcc); - } - -if (!sd_fmt) { - ret = -EINVAL ; - goto isc_try_fmt_err; - } - -/* Step 7: Print out what we decided for debugging */ -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Preferring to have sensor using format %.4s\n" , - (char *)&sd_fmt->fourcc); -/* Step 8: at this moment we decided which format the subdev will use */ - isc->try_config.sd_format = sd_fmt; +isc_try_configure_rlp_dma (isc, false);/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - -/* -* The mbus format is the one the subdev outputs. -* The pixels will be transferred in this format Sensor -> ISC -*/ - mbus_code = sd_fmt->mbus_code; - -/* -* Validate formats. If the required format is not OK, default to raw. -*/ - - isc->try_config.fourcc = pixfmt->pixelformat; - -if (isc_try_validate_formats (isc)) { - pixfmt->pixelformat = isc->try_config.fourcc = sd_fmt->fourcc; -/* Re-try to validate the new format */ - ret =isc_try_validate_formats (isc); -if (ret) - goto isc_try_fmt_err; - } - - ret =isc_try_configure_rlp_dma (isc, rlp_dma_direct_dump); -if (ret) - goto isc_try_fmt_err; - - ret =isc_try_configure_pipeline (isc); -if (ret) - goto isc_try_fmt_err; - -/* Obtain frame sizes if possible to have crop requirements ready */ -isc_try_fse (isc, &pad_state); - -v4l2_fill_mbus_format (&format.format, pixfmt, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, set_fmt, - &pad_state, &format); -if (ret <0 ) - goto isc_try_fmt_subdev_err; - -v4l2_fill_pix_format (pixfmt, &format.format); +v4l_bound_align_image (&pixfmt->width,16 , isc->max_width,0 , + &pixfmt->height,16 , isc->max_height,0 ,0 ); +/* If we did not find the requested format, we will fallback here */ + pixfmt->pixelformat = isc->try_config.fourcc; + pixfmt->colorspace =V4L2_COLORSPACE_SRGB ; + pixfmt->field =V4L2_FIELD_NONE ; -/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - pixfmt->field =V4L2_FIELD_NONE ; pixfmt->bytesperline = (pixfmt->width * isc->try_config.bpp_v4l2) >>3 ; pixfmt->sizeimage = ((pixfmt->width * isc->try_config.bpp) >>3 ) * pixfmt->height; -if (code) - *code = mbus_code; + isc->try_fmt = *f;return 0 ; +} -isc_try_fmt_err: -v4l2_err (&isc->v4l2_dev,"Could not find any possible format for a working pipeline\n" ); -isc_try_fmt_subdev_err: -memset (&isc->try_config,0 ,sizeof (isc->try_config)); +static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +{ +isc_try_fmt (isc, f); -return ret; +/* make the try configuration active */ + isc->config = isc->try_config; + isc->fmt = isc->try_fmt; + +v4l2_dbg (1 , debug, &isc->v4l2_dev,"ISC set_fmt to %.4s @%dx%d\n" , + (char *)&f->fmt.pix.pixelformat, + f->fmt.pix.width, f->fmt.pix.height); + +return 0 ; } -static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +static int isc_validate (struct isc_device *isc) { +int ret; +int i; +struct isc_format *sd_fmt =NULL ; +struct v4l2_pix_format *pixfmt = &isc->fmt.fmt.pix;struct v4l2_subdev_format format = { .which =V4L2_SUBDEV_FORMAT_ACTIVE , + .pad = isc->remote_pad, + }; +struct v4l2_subdev_pad_config pad_cfg = {}; +struct v4l2_subdev_state pad_state = { + .pads = &pad_cfg, }; -u32 mbus_code =0 ; -int ret; - ret =isc_try_fmt (isc, f, &mbus_code); +/* Get current format from subdev */ + ret =v4l2_subdev_call (isc->current_subdev->sd, pad, get_fmt,NULL , + &format);if (ret)return ret; -v4l2_fill_mbus_format (&format.format, &f->fmt.pix, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, - set_fmt,NULL , &format); -if (ret <0 ) -return ret; +/* Identify the subdev's format configuration */ +for (i =0 ; i < isc->formats_list_size; i++) +if (isc->formats_list[i].mbus_code == format.format.code) { + sd_fmt = &isc->formats_list[i]; +break ; + } + +/* Check if the format is not supported */ +if (!sd_fmt) { +v4l2_err (&isc->v4l2_dev, +"Current subdevice is streaming a media bus code that is not supported 0x%x\n" , + format.format.code); +return -EPIPE ; + } + +/* At this moment we know which format the subdev will use */ + isc->try_config.sd_format = sd_fmt; + +/* If the sensor is not RAW, we can only do a direct dump */ +if (!ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) +isc_try_configure_rlp_dma (isc, true);/* Limit to Atmel ISC hardware capabilities */ -if (f->fmt.pix.width > isc->max_width) - f->fmt.pix.width = isc->max_width; -if (f->fmt.pix.height > isc->max_height) - f->fmt.pix.height = isc->max_height; +v4l_bound_align_image (&format.format.width,16 , isc->max_width,0 , + &format.format.height,16 , isc->max_height,0 ,0 ); - isc->fmt = *f; +/* Check if the frame size is the same. Otherwise we may overflow */ +if (pixfmt->height != format.format.height || + pixfmt->width != format.format.width) { +v4l2_err (&isc->v4l2_dev, +"ISC not configured with the proper frame size: %dx%d\n" , + format.format.width, format.format.height); +return -EPIPE ; + } +v4l2_dbg (1 , debug, &isc->v4l2_dev, +"Identified subdev using format %.4s with %dx%d %d bpp\n" , + (char *)&sd_fmt->fourcc, pixfmt->width, pixfmt->height, + isc->try_config.bpp); + +/* Reset and restart AWB if the subdevice changed the format */ if (isc->try_config.sd_format && isc->config.sd_format && isc->try_config.sd_format != isc->config.sd_format) { isc->ctrls.hist_stat =HIST_INIT ;isc_reset_awb_ctrls (isc);isc_update_v4l2_ctrls (isc); } -/* make the try configuration active */ + +/* Validate formats */ + ret =isc_try_validate_formats (isc); +if (ret) +return ret; + +/* Obtain frame sizes if possible to have crop requirements ready */ +isc_try_fse (isc, &pad_state); + +/* Configure ISC pipeline for the config */ + ret =isc_try_configure_pipeline (isc); +if (ret) +return ret; + isc->config = isc->try_config;v4l2_dbg (1 , debug, &isc->v4l2_dev,"New ISC configuration in place\n" );@@ -1043,7 +1036,7 @@ static int isc_try_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file); -return isc_try_fmt (isc, f,NULL ); +return isc_try_fmt (isc, f); } static int isc_enum_input(struct file *file, void *priv,@@ -1098,10 +1091,6 @@ static int isc_enum_framesizes(struct file *file, void *fh,if (fsize->index)return -EINVAL ; -for (i =0 ; i < isc->num_user_formats; i++) -if (isc->user_formats[i]->fourcc == fsize->pixel_format) - ret =0 ; -for (i =0 ; i < isc->controller_formats_size; i++)if (isc->controller_formats[i].fourcc == fsize->pixel_format) ret =0 ;@@ -1782,52 +1771,6 @@ struct isc_format *isc_find_format_by_code(struct isc_device *isc, }EXPORT_SYMBOL_GPL (isc_find_format_by_code); -static int isc_formats_init (struct isc_device *isc) -{ -struct isc_format *fmt; -struct v4l2_subdev *subdev = isc->current_subdev->sd; -unsigned int num_fmts, i, j; -u32 list_size = isc->formats_list_size; -struct v4l2_subdev_mbus_code_enum mbus_code = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - }; - - num_fmts =0 ; -while (!v4l2_subdev_call (subdev, pad, enum_mbus_code, -NULL , &mbus_code)) { - mbus_code.index++; - - fmt =isc_find_format_by_code (isc, mbus_code.code, &i); -if (!fmt) { -v4l2_warn (&isc->v4l2_dev,"Mbus code %x not supported\n" , - mbus_code.code); -continue ; - } - - fmt->sd_support = true; - num_fmts++; - } - -if (!num_fmts) -return -ENXIO ; - - isc->num_user_formats = num_fmts; - isc->user_formats =devm_kcalloc (isc->dev, - num_fmts,sizeof (*isc->user_formats), -GFP_KERNEL ); -if (!isc->user_formats) -return -ENOMEM ; - - fmt = &isc->formats_list[0 ]; -for (i =0 , j =0 ; i < list_size; i++) { -if (fmt->sd_support) - isc->user_formats[j++] = fmt; - fmt++; - } - -return 0 ; -} -static int isc_set_default_fmt (struct isc_device *isc) {struct v4l2_format f = {@@ -1836,12 +1779,12 @@ static int isc_set_default_fmt(struct isc_device *isc) .width = VGA_WIDTH, .height = VGA_HEIGHT, .field = V4L2_FIELD_NONE, - .pixelformat = isc->user_formats[0]->fourcc, + .pixelformat = isc->controller_formats[0].fourcc, }, };int ret; - ret =isc_try_fmt (isc, &f,NULL ); + ret =isc_try_fmt (isc, &f);if (ret)return ret;@@ -1896,13 +1839,6 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)spin_lock_init (&isc->dma_queue_lock);spin_lock_init (&isc->awb_lock); - ret =isc_formats_init (isc); -if (ret <0 ) { -v4l2_err (&isc->v4l2_dev, -"Init format failed: %d\n" , ret); - goto isc_async_complete_err; - } - ret =isc_set_default_fmt (isc);if (ret) {v4l2_err (&isc->v4l2_dev,"Could not set default format\n" );@@ -2016,6 +1952,24 @@ int isc_pipeline_init(struct isc_device *isc) }EXPORT_SYMBOL_GPL (isc_pipeline_init); +static int isc_link_validate (struct media_link *link) +{ +struct video_device *vdev = +media_entity_to_video_device (link->sink->entity); +struct isc_device *isc =video_get_drvdata (vdev); +int ret; + + ret =v4l2_subdev_link_validate (link); +if (ret) +return ret; + +return isc_validate (isc); +} + +static const struct media_entity_operations isc_entity_operations = { + .link_validate = isc_link_validate, +}; +int isc_mc_init (struct isc_device *isc,u32 ver) {const struct of_device_id *match;@@ -2023,6 +1977,8 @@ int isc_mc_init(struct isc_device *isc, u32 ver) isc->video_dev.entity.function =MEDIA_ENT_F_IO_V4L ; isc->video_dev.entity.flags =MEDIA_ENT_FL_DEFAULT ; + isc->video_dev.entity.ops = &isc_entity_operations; + isc->pads[ISC_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; ret = media_entity_pads_init(&isc->video_dev.entity, ISC_PADS_NUM,drivers/media/platform/atmel/atmel-isc-scaler.c +5
-0@@ -173,6 +173,10 @@ static const struct v4l2_subdev_pad_ops isc_scaler_pad_ops = { .init_cfg = isc_scaler_init_cfg, }; +static const struct media_entity_operations isc_scaler_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; +static const struct v4l2_subdev_ops xisc_scaler_subdev_ops = { .pad = &isc_scaler_pad_ops, };@@ -190,6 +194,7 @@ int isc_scaler_init(struct isc_device *isc) isc->scaler_sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; isc->scaler_sd.entity.function =MEDIA_ENT_F_PROC_VIDEO_SCALER ; + isc->scaler_sd.entity.ops = &isc_scaler_entity_ops; isc->scaler_pads[ISC_SCALER_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; isc->scaler_pads[ISC_SCALER_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ;drivers/media/platform/atmel/atmel-isc.h +7
-6@@ -63,15 +63,16 @@ struct isc_subdev_entity {* @cfa_baycfg: If this format is RAW BAYER, indicate the type of bayer. this is either BGBG, RGRG, etc. * @pfe_cfg0_bps: Number of hardware data lines connected to the ISC +* @raw: If the format is raw bayer. */ struct isc_format {u32 fourcc;u32 mbus_code;u32 cfa_baycfg; - -bool sd_support;u32 pfe_cfg0_bps; + +bool raw; };/* Pipeline bitmap */ @@ -216,8 +217,7 @@ enum isc_scaler_pads {* @comp: completion reference that signals frame completion * * @fmt: current v42l format -* @user_formats: list of formats that are supported and agreed with sd -* @num_user_formats: how many formats are in user_formats +* @try_fmt: current v4l2 try format * * @config: current ISC format configuration * @try_config: the current ISC try format , not yet activated @@ -272,6 +272,7 @@ enum isc_scaler_pads {* @formats_list_size: size of formats_list array * @pads: media controller pads for isc video entity * @mdev: media device that is registered by the isc +* @mpipe: media device pipeline used by the isc * @remote_pad: remote pad on the connected subdevice * @scaler_sd: subdevice for the scaler that isc registers * @scaler_pads: media controller pads for the scaler subdevice @@ -298,8 +299,7 @@ struct isc_device {struct completion comp;struct v4l2_format fmt; -struct isc_format **user_formats; -unsigned int num_user_formats; +struct v4l2_format try_fmt;struct fmt_config config;struct fmt_config try_config;@@ -369,6 +369,7 @@ struct isc_device {struct {struct media_pad pads[ISC_PADS_NUM ];struct media_device mdev; +struct media_pipeline mpipe;u32 remote_pad; };drivers/media/platform/atmel/atmel-sama5d2-isc.c +20
-0@@ -80,20 +80,40 @@ static const struct isc_format sama5d2_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y10, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };drivers/media/platform/atmel/atmel-sama7g5-isc.c +20
-0@@ -89,20 +89,40 @@ static const struct isc_format sama7g5_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y16, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Hello
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.
Yes indeed, seems I suggested to use media_pipeline_handler in a comment on your v3
"at s_stream time your top driver calls media_pipeline_start()"
sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see media_pipeline_start being called at all in v3 of the patch
Quoted 9 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Are you suggesting to have vb2 to call media_pipeline_start() or is it more complex than this ?
Quoted 771 lines
I'd like to know what others think.
Regards,
Hans
Quoted 763 lines
Eugen
Quoted 759 lines
Laurent, Jacopo, do you agree with that?
I notice that quite a few other drivers do this in
start_streamingas well, but I think it just weird that a QBUF can return EPIPE while STREAMON might succeed.Perhaps we need an optional vb2
validate()callback that is called byvb2_core_streamon()to validate the pipeline before streaming. That makes it easier to implement these checks rather than having to implement your own streamon ioctl.Regards,
Hans
Quoted 742 lines
drivers/media/platform/atmel/atmel-isc-base.c +183
-223+if (ret) + goto err_pipeline_start; +/* Enable stream on the sub device */ ret =v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,1 );if (ret && ret != -ENOIOCTLCMD ) {@@ -385,6 +384,9 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,0 ); err_start_stream: +media_pipeline_stop (&isc->video_dev.entity); + +err_pipeline_start:spin_lock_irqsave (&isc->dma_queue_lock, flags);list_for_each_entry (buf, &isc->dma_queue, list)vb2_buffer_done (&buf->vb.vb2_buf,VB2_BUF_STATE_QUEUED );@@ -423,6 +425,9 @@ static void isc_stop_streaming(struct vb2_queue *vq)if (ret && ret != -ENOIOCTLCMD )v4l2_err (&isc->v4l2_dev,"stream off failed in subdev\n" ); +/* Stop media pipeline */ +media_pipeline_stop (&isc->video_dev.entity); +/* Release all active buffers */ spin_lock_irqsave (&isc->dma_queue_lock, flags);if (unlikely (isc->cur_frm)) {@@ -453,22 +458,6 @@ static void isc_buffer_queue(struct vb2_buffer *vb)spin_unlock_irqrestore (&isc->dma_queue_lock, flags); } -static struct isc_format *find_format_by_fourcc (struct isc_device *isc, -unsigned int fourcc) -{ -unsigned int num_formats = isc->num_user_formats; -struct isc_format *fmt; -unsigned int i; - -for (i =0 ; i < num_formats; i++) { - fmt = isc->user_formats[i]; -if (fmt->fourcc == fourcc) -return fmt; - } - -return NULL ; -} -static const struct vb2_ops isc_vb2_ops = { .queue_setup = isc_queue_setup, .wait_prepare = vb2_ops_wait_prepare,@@ -497,23 +486,57 @@ static int isc_enum_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file);u32 index = f->index; -u32 i, supported_index; +u32 i, supported_index =0 ; +struct isc_format *fmt; + +/* +* If we are not asked a specific mbus_code, we have to report all +* the formats that we can output. +*/ +if (!f->mbus_code) { +if (index >= isc->controller_formats_size) +return -EINVAL ; -if (index < isc->controller_formats_size) { f->pixelformat = isc->controller_formats[index].fourcc; + +return 0 ; + } + +/* +* If a specific mbus_code is requested, check if we support +* this mbus_code as input for the ISC. +* If it's supported, then we report the corresponding pixelformat +* as first possible option for the ISC. +* E.g. mbus MEDIA_BUS_FMT_YUYV8_2X8 and report +* 'YUYV' (YUYV 4:2:2) +*/ + fmt =isc_find_format_by_code (isc, f->mbus_code, &i); +if (!fmt) +return -EINVAL ; + +if (!index) { + f->pixelformat = fmt->fourcc; +return 0 ; } - index -= isc->controller_formats_size; + supported_index++; - supported_index =0 ; +/* If the index is not raw, we don't have anymore formats to report */ +if (!ISC_IS_FORMAT_RAW (f->mbus_code)) +return -EINVAL ; -for (i =0 ; i < isc->formats_list_size; i++) { -if (!ISC_IS_FORMAT_RAW (isc->formats_list[i].mbus_code) || - !isc->formats_list[i].sd_support) +/* +* We are asked for a specific mbus code, which is raw. +* We have to search through the formats we can convert to. +* We have to skip the raw formats, we cannot convert to raw. +* E.g. 'AR12' (16-bit ARGB 4-4-4-4), 'AR15' (16-bit ARGB 1-5-5-5), etc. +*/ +for (i =0 ; i < isc->controller_formats_size; i++) { +if (isc->controller_formats[i].raw)continue ; -if (supported_index == index) { - f->pixelformat = isc->formats_list[i].fourcc; +if (index == supported_index) { + f->pixelformat = isc->controller_formats[i].fourcc;return 0 ; } supported_index++;@@ -584,20 +607,30 @@ static int isc_try_validate_formats(struct isc_device *isc)break ;default :/* any other different formats are not supported */ +v4l2_err (&isc->v4l2_dev,"Requested unsupported format.\n" ); ret = -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)) +if (bayer && + !ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output RAW if we do not receive RAW.\n" );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)) + !ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output GREY if we do not receive RAW/GREY.\n" );return -EINVAL ; + } + +if ((rgb || bayer || yuv) && +ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot convert GREY to another format.\n" ); +return -EINVAL ; + }return ret; }@@ -825,7 +858,7 @@ static void isc_try_fse(struct isc_device *isc,* If we do not know yet which format the subdev is using, we cannot * do anything. */ -if (!isc->try_config.sd_format) +if (!isc->config.sd_format)return ; fse.code = isc->try_config.sd_format->mbus_code;@@ -846,180 +879,140 @@ static void isc_try_fse(struct isc_device *isc, } } -static int isc_try_fmt (struct isc_device *isc,struct v4l2_format *f, -u32 *code) +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_state pad_state = { - .pads = &pad_cfg - }; -struct v4l2_subdev_format format = { - .which =V4L2_SUBDEV_FORMAT_TRY , - }; -u32 mbus_code; -int ret; -bool rlp_dma_direct_dump = false; +unsigned int i;if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE )return -EINVAL ; -/* Step 1: find a RAW format that is supported */ -for (i =0 ; i < isc->num_user_formats; i++) { -if (ISC_IS_FORMAT_RAW (isc->user_formats[i]->mbus_code)) { - sd_fmt = isc->user_formats[i]; + isc->try_config.fourcc = isc->controller_formats[0 ].fourcc; + +/* find if the format requested is supported */ +for (i =0 ; i < isc->controller_formats_size; i++) +if (isc->controller_formats[i].fourcc == pixfmt->pixelformat) { + isc->try_config.fourcc = pixfmt->pixelformat;break ; } - } -/* Step 2: We can continue with this RAW format, or we can look -* for better: maybe sensor supports directly what we need. -*/ - direct_fmt =find_format_by_fourcc (isc, pixfmt->pixelformat); - -/* Step 3: We have both. We decide given the module parameter which -* one to use. -*/ -if (direct_fmt && sd_fmt && sensor_preferred) - sd_fmt = direct_fmt; - -/* Step 4: we do not have RAW but we have a direct format. Use it. */ -if (direct_fmt && !sd_fmt) - sd_fmt = direct_fmt; - -/* Step 5: if we are using a direct format, we need to package -* everything as 8 bit data and just dump it -*/ -if (sd_fmt == direct_fmt) - rlp_dma_direct_dump = true; - -/* Step 6: We have no format. This can happen if the userspace -* requests some weird/invalid format. -* In this case, default to whatever we have -*/ -if (!sd_fmt && !direct_fmt) { - sd_fmt = isc->user_formats[isc->num_user_formats -1 ]; -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Sensor not supporting %.4s, using %.4s\n" , - (char *)&pixfmt->pixelformat, (char *)&sd_fmt->fourcc); - } - -if (!sd_fmt) { - ret = -EINVAL ; - goto isc_try_fmt_err; - } - -/* Step 7: Print out what we decided for debugging */ -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Preferring to have sensor using format %.4s\n" , - (char *)&sd_fmt->fourcc); -/* Step 8: at this moment we decided which format the subdev will use */ - isc->try_config.sd_format = sd_fmt; +isc_try_configure_rlp_dma (isc, false);/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - -/* -* The mbus format is the one the subdev outputs. -* The pixels will be transferred in this format Sensor -> ISC -*/ - mbus_code = sd_fmt->mbus_code; - -/* -* Validate formats. If the required format is not OK, default to raw. -*/ - - isc->try_config.fourcc = pixfmt->pixelformat; - -if (isc_try_validate_formats (isc)) { - pixfmt->pixelformat = isc->try_config.fourcc = sd_fmt->fourcc; -/* Re-try to validate the new format */ - ret =isc_try_validate_formats (isc); -if (ret) - goto isc_try_fmt_err; - } - - ret =isc_try_configure_rlp_dma (isc, rlp_dma_direct_dump); -if (ret) - goto isc_try_fmt_err; - - ret =isc_try_configure_pipeline (isc); -if (ret) - goto isc_try_fmt_err; - -/* Obtain frame sizes if possible to have crop requirements ready */ -isc_try_fse (isc, &pad_state); - -v4l2_fill_mbus_format (&format.format, pixfmt, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, set_fmt, - &pad_state, &format); -if (ret <0 ) - goto isc_try_fmt_subdev_err; - -v4l2_fill_pix_format (pixfmt, &format.format); +v4l_bound_align_image (&pixfmt->width,16 , isc->max_width,0 , + &pixfmt->height,16 , isc->max_height,0 ,0 ); +/* If we did not find the requested format, we will fallback here */ + pixfmt->pixelformat = isc->try_config.fourcc; + pixfmt->colorspace =V4L2_COLORSPACE_SRGB ; + pixfmt->field =V4L2_FIELD_NONE ; -/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - pixfmt->field =V4L2_FIELD_NONE ; pixfmt->bytesperline = (pixfmt->width * isc->try_config.bpp_v4l2) >>3 ; pixfmt->sizeimage = ((pixfmt->width * isc->try_config.bpp) >>3 ) * pixfmt->height; -if (code) - *code = mbus_code; + isc->try_fmt = *f;return 0 ; +} -isc_try_fmt_err: -v4l2_err (&isc->v4l2_dev,"Could not find any possible format for a working pipeline\n" ); -isc_try_fmt_subdev_err: -memset (&isc->try_config,0 ,sizeof (isc->try_config)); +static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +{ +isc_try_fmt (isc, f); -return ret; +/* make the try configuration active */ + isc->config = isc->try_config; + isc->fmt = isc->try_fmt; + +v4l2_dbg (1 , debug, &isc->v4l2_dev,"ISC set_fmt to %.4s @%dx%d\n" , + (char *)&f->fmt.pix.pixelformat, + f->fmt.pix.width, f->fmt.pix.height); + +return 0 ; } -static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +static int isc_validate (struct isc_device *isc) { +int ret; +int i; +struct isc_format *sd_fmt =NULL ; +struct v4l2_pix_format *pixfmt = &isc->fmt.fmt.pix;struct v4l2_subdev_format format = { .which =V4L2_SUBDEV_FORMAT_ACTIVE , + .pad = isc->remote_pad, + }; +struct v4l2_subdev_pad_config pad_cfg = {}; +struct v4l2_subdev_state pad_state = { + .pads = &pad_cfg, }; -u32 mbus_code =0 ; -int ret; - ret =isc_try_fmt (isc, f, &mbus_code); +/* Get current format from subdev */ + ret =v4l2_subdev_call (isc->current_subdev->sd, pad, get_fmt,NULL , + &format);if (ret)return ret; -v4l2_fill_mbus_format (&format.format, &f->fmt.pix, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, - set_fmt,NULL , &format); -if (ret <0 ) -return ret; +/* Identify the subdev's format configuration */ +for (i =0 ; i < isc->formats_list_size; i++) +if (isc->formats_list[i].mbus_code == format.format.code) { + sd_fmt = &isc->formats_list[i]; +break ; + } + +/* Check if the format is not supported */ +if (!sd_fmt) { +v4l2_err (&isc->v4l2_dev, +"Current subdevice is streaming a media bus code that is not supported 0x%x\n" , + format.format.code); +return -EPIPE ; + } + +/* At this moment we know which format the subdev will use */ + isc->try_config.sd_format = sd_fmt; + +/* If the sensor is not RAW, we can only do a direct dump */ +if (!ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) +isc_try_configure_rlp_dma (isc, true);/* Limit to Atmel ISC hardware capabilities */ -if (f->fmt.pix.width > isc->max_width) - f->fmt.pix.width = isc->max_width; -if (f->fmt.pix.height > isc->max_height) - f->fmt.pix.height = isc->max_height; +v4l_bound_align_image (&format.format.width,16 , isc->max_width,0 , + &format.format.height,16 , isc->max_height,0 ,0 ); - isc->fmt = *f; +/* Check if the frame size is the same. Otherwise we may overflow */ +if (pixfmt->height != format.format.height || + pixfmt->width != format.format.width) { +v4l2_err (&isc->v4l2_dev, +"ISC not configured with the proper frame size: %dx%d\n" , + format.format.width, format.format.height); +return -EPIPE ; + } +v4l2_dbg (1 , debug, &isc->v4l2_dev, +"Identified subdev using format %.4s with %dx%d %d bpp\n" , + (char *)&sd_fmt->fourcc, pixfmt->width, pixfmt->height, + isc->try_config.bpp); + +/* Reset and restart AWB if the subdevice changed the format */ if (isc->try_config.sd_format && isc->config.sd_format && isc->try_config.sd_format != isc->config.sd_format) { isc->ctrls.hist_stat =HIST_INIT ;isc_reset_awb_ctrls (isc);isc_update_v4l2_ctrls (isc); } -/* make the try configuration active */ + +/* Validate formats */ + ret =isc_try_validate_formats (isc); +if (ret) +return ret; + +/* Obtain frame sizes if possible to have crop requirements ready */ +isc_try_fse (isc, &pad_state); + +/* Configure ISC pipeline for the config */ + ret =isc_try_configure_pipeline (isc); +if (ret) +return ret; + isc->config = isc->try_config;v4l2_dbg (1 , debug, &isc->v4l2_dev,"New ISC configuration in place\n" );@@ -1043,7 +1036,7 @@ static int isc_try_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file); -return isc_try_fmt (isc, f,NULL ); +return isc_try_fmt (isc, f); } static int isc_enum_input(struct file *file, void *priv,@@ -1098,10 +1091,6 @@ static int isc_enum_framesizes(struct file *file, void *fh,if (fsize->index)return -EINVAL ; -for (i =0 ; i < isc->num_user_formats; i++) -if (isc->user_formats[i]->fourcc == fsize->pixel_format) - ret =0 ; -for (i =0 ; i < isc->controller_formats_size; i++)if (isc->controller_formats[i].fourcc == fsize->pixel_format) ret =0 ;@@ -1782,52 +1771,6 @@ struct isc_format *isc_find_format_by_code(struct isc_device *isc, }EXPORT_SYMBOL_GPL (isc_find_format_by_code); -static int isc_formats_init (struct isc_device *isc) -{ -struct isc_format *fmt; -struct v4l2_subdev *subdev = isc->current_subdev->sd; -unsigned int num_fmts, i, j; -u32 list_size = isc->formats_list_size; -struct v4l2_subdev_mbus_code_enum mbus_code = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - }; - - num_fmts =0 ; -while (!v4l2_subdev_call (subdev, pad, enum_mbus_code, -NULL , &mbus_code)) { - mbus_code.index++; - - fmt =isc_find_format_by_code (isc, mbus_code.code, &i); -if (!fmt) { -v4l2_warn (&isc->v4l2_dev,"Mbus code %x not supported\n" , - mbus_code.code); -continue ; - } - - fmt->sd_support = true; - num_fmts++; - } - -if (!num_fmts) -return -ENXIO ; - - isc->num_user_formats = num_fmts; - isc->user_formats =devm_kcalloc (isc->dev, - num_fmts,sizeof (*isc->user_formats), -GFP_KERNEL ); -if (!isc->user_formats) -return -ENOMEM ; - - fmt = &isc->formats_list[0 ]; -for (i =0 , j =0 ; i < list_size; i++) { -if (fmt->sd_support) - isc->user_formats[j++] = fmt; - fmt++; - } - -return 0 ; -} -static int isc_set_default_fmt (struct isc_device *isc) {struct v4l2_format f = {@@ -1836,12 +1779,12 @@ static int isc_set_default_fmt(struct isc_device *isc) .width = VGA_WIDTH, .height = VGA_HEIGHT, .field = V4L2_FIELD_NONE, - .pixelformat = isc->user_formats[0]->fourcc, + .pixelformat = isc->controller_formats[0].fourcc, }, };int ret; - ret =isc_try_fmt (isc, &f,NULL ); + ret =isc_try_fmt (isc, &f);if (ret)return ret;@@ -1896,13 +1839,6 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)spin_lock_init (&isc->dma_queue_lock);spin_lock_init (&isc->awb_lock); - ret =isc_formats_init (isc); -if (ret <0 ) { -v4l2_err (&isc->v4l2_dev, -"Init format failed: %d\n" , ret); - goto isc_async_complete_err; - } - ret =isc_set_default_fmt (isc);if (ret) {v4l2_err (&isc->v4l2_dev,"Could not set default format\n" );@@ -2016,6 +1952,24 @@ int isc_pipeline_init(struct isc_device *isc) }EXPORT_SYMBOL_GPL (isc_pipeline_init); +static int isc_link_validate (struct media_link *link) +{ +struct video_device *vdev = +media_entity_to_video_device (link->sink->entity); +struct isc_device *isc =video_get_drvdata (vdev); +int ret; + + ret =v4l2_subdev_link_validate (link); +if (ret) +return ret; + +return isc_validate (isc); +} + +static const struct media_entity_operations isc_entity_operations = { + .link_validate = isc_link_validate, +}; +int isc_mc_init (struct isc_device *isc,u32 ver) {const struct of_device_id *match;@@ -2023,6 +1977,8 @@ int isc_mc_init(struct isc_device *isc, u32 ver) isc->video_dev.entity.function =MEDIA_ENT_F_IO_V4L ; isc->video_dev.entity.flags =MEDIA_ENT_FL_DEFAULT ; + isc->video_dev.entity.ops = &isc_entity_operations; + isc->pads[ISC_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; ret = media_entity_pads_init(&isc->video_dev.entity, ISC_PADS_NUM,drivers/media/platform/atmel/atmel-isc-scaler.c +5
-0@@ -173,6 +173,10 @@ static const struct v4l2_subdev_pad_ops isc_scaler_pad_ops = { .init_cfg = isc_scaler_init_cfg, }; +static const struct media_entity_operations isc_scaler_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; +static const struct v4l2_subdev_ops xisc_scaler_subdev_ops = { .pad = &isc_scaler_pad_ops, };@@ -190,6 +194,7 @@ int isc_scaler_init(struct isc_device *isc) isc->scaler_sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; isc->scaler_sd.entity.function =MEDIA_ENT_F_PROC_VIDEO_SCALER ; + isc->scaler_sd.entity.ops = &isc_scaler_entity_ops; isc->scaler_pads[ISC_SCALER_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; isc->scaler_pads[ISC_SCALER_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ;drivers/media/platform/atmel/atmel-isc.h +7
-6@@ -63,15 +63,16 @@ struct isc_subdev_entity {* @cfa_baycfg: If this format is RAW BAYER, indicate the type of bayer. this is either BGBG, RGRG, etc. * @pfe_cfg0_bps: Number of hardware data lines connected to the ISC +* @raw: If the format is raw bayer. */ struct isc_format {u32 fourcc;u32 mbus_code;u32 cfa_baycfg; - -bool sd_support;u32 pfe_cfg0_bps; + +bool raw; };/* Pipeline bitmap */ @@ -216,8 +217,7 @@ enum isc_scaler_pads {* @comp: completion reference that signals frame completion * * @fmt: current v42l format -* @user_formats: list of formats that are supported and agreed with sd -* @num_user_formats: how many formats are in user_formats +* @try_fmt: current v4l2 try format * * @config: current ISC format configuration * @try_config: the current ISC try format , not yet activated @@ -272,6 +272,7 @@ enum isc_scaler_pads {* @formats_list_size: size of formats_list array * @pads: media controller pads for isc video entity * @mdev: media device that is registered by the isc +* @mpipe: media device pipeline used by the isc * @remote_pad: remote pad on the connected subdevice * @scaler_sd: subdevice for the scaler that isc registers * @scaler_pads: media controller pads for the scaler subdevice @@ -298,8 +299,7 @@ struct isc_device {struct completion comp;struct v4l2_format fmt; -struct isc_format **user_formats; -unsigned int num_user_formats; +struct v4l2_format try_fmt;struct fmt_config config;struct fmt_config try_config;@@ -369,6 +369,7 @@ struct isc_device {struct {struct media_pad pads[ISC_PADS_NUM ];struct media_device mdev; +struct media_pipeline mpipe;u32 remote_pad; };drivers/media/platform/atmel/atmel-sama5d2-isc.c +20
-0@@ -80,20 +80,40 @@ static const struct isc_format sama5d2_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y10, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };drivers/media/platform/atmel/atmel-sama7g5-isc.c +20
-0@@ -89,20 +89,40 @@ static const struct isc_format sama7g5_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y16, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Quoted 117 lines · Jacopo Mondi
Hello
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.Yes indeed, seems I suggested to use
media_pipeline_handlerin a comment on your v3"at
s_streamtime your top driver callsmedia_pipeline_start()"sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see
media_pipeline_startbeing called at all in v3 of the patchQuoted 7 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.
Quoted 5 lines
Quoted 2 lines
I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Are you suggesting to have vb2 to call
media_pipeline_start()or is it more complex than this ?
No, I don't think vb2 should do that. But it needs two new ops: pipeline_start/stop (or some other name) that are called at VIDIOC_STREAMON time and when the streaming stops (due to STREAMOFF or by closing the fh). The driver can then take appropriate action, which will typically be calling media_pipeline_start/stop, but other checks may also be needed at that time.
Regards,
Hans
Quoted 772 lines
Quoted 772 lines
I'd like to know what others think.
Regards,
Hans
Quoted 763 lines
Eugen
Quoted 759 lines
Laurent, Jacopo, do you agree with that?
I notice that quite a few other drivers do this in
start_streamingas well, but I think it just weird that a QBUF can return EPIPE while STREAMON might succeed.Perhaps we need an optional vb2
validate()callback that is called byvb2_core_streamon()to validate the pipeline before streaming. That makes it easier to implement these checks rather than having to implement your own streamon ioctl.Regards,
Hans
Quoted 742 lines
drivers/media/platform/atmel/atmel-isc-base.c +183
-223+if (ret) + goto err_pipeline_start; +/* Enable stream on the sub device */ ret =v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,1 );if (ret && ret != -ENOIOCTLCMD ) {@@ -385,6 +384,9 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,0 ); err_start_stream: +media_pipeline_stop (&isc->video_dev.entity); + +err_pipeline_start:spin_lock_irqsave (&isc->dma_queue_lock, flags);list_for_each_entry (buf, &isc->dma_queue, list)vb2_buffer_done (&buf->vb.vb2_buf,VB2_BUF_STATE_QUEUED );@@ -423,6 +425,9 @@ static void isc_stop_streaming(struct vb2_queue *vq)if (ret && ret != -ENOIOCTLCMD )v4l2_err (&isc->v4l2_dev,"stream off failed in subdev\n" ); +/* Stop media pipeline */ +media_pipeline_stop (&isc->video_dev.entity); +/* Release all active buffers */ spin_lock_irqsave (&isc->dma_queue_lock, flags);if (unlikely (isc->cur_frm)) {@@ -453,22 +458,6 @@ static void isc_buffer_queue(struct vb2_buffer *vb)spin_unlock_irqrestore (&isc->dma_queue_lock, flags); } -static struct isc_format *find_format_by_fourcc (struct isc_device *isc, -unsigned int fourcc) -{ -unsigned int num_formats = isc->num_user_formats; -struct isc_format *fmt; -unsigned int i; - -for (i =0 ; i < num_formats; i++) { - fmt = isc->user_formats[i]; -if (fmt->fourcc == fourcc) -return fmt; - } - -return NULL ; -} -static const struct vb2_ops isc_vb2_ops = { .queue_setup = isc_queue_setup, .wait_prepare = vb2_ops_wait_prepare,@@ -497,23 +486,57 @@ static int isc_enum_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file);u32 index = f->index; -u32 i, supported_index; +u32 i, supported_index =0 ; +struct isc_format *fmt; + +/* +* If we are not asked a specific mbus_code, we have to report all +* the formats that we can output. +*/ +if (!f->mbus_code) { +if (index >= isc->controller_formats_size) +return -EINVAL ; -if (index < isc->controller_formats_size) { f->pixelformat = isc->controller_formats[index].fourcc; + +return 0 ; + } + +/* +* If a specific mbus_code is requested, check if we support +* this mbus_code as input for the ISC. +* If it's supported, then we report the corresponding pixelformat +* as first possible option for the ISC. +* E.g. mbus MEDIA_BUS_FMT_YUYV8_2X8 and report +* 'YUYV' (YUYV 4:2:2) +*/ + fmt =isc_find_format_by_code (isc, f->mbus_code, &i); +if (!fmt) +return -EINVAL ; + +if (!index) { + f->pixelformat = fmt->fourcc; +return 0 ; } - index -= isc->controller_formats_size; + supported_index++; - supported_index =0 ; +/* If the index is not raw, we don't have anymore formats to report */ +if (!ISC_IS_FORMAT_RAW (f->mbus_code)) +return -EINVAL ; -for (i =0 ; i < isc->formats_list_size; i++) { -if (!ISC_IS_FORMAT_RAW (isc->formats_list[i].mbus_code) || - !isc->formats_list[i].sd_support) +/* +* We are asked for a specific mbus code, which is raw. +* We have to search through the formats we can convert to. +* We have to skip the raw formats, we cannot convert to raw. +* E.g. 'AR12' (16-bit ARGB 4-4-4-4), 'AR15' (16-bit ARGB 1-5-5-5), etc. +*/ +for (i =0 ; i < isc->controller_formats_size; i++) { +if (isc->controller_formats[i].raw)continue ; -if (supported_index == index) { - f->pixelformat = isc->formats_list[i].fourcc; +if (index == supported_index) { + f->pixelformat = isc->controller_formats[i].fourcc;return 0 ; } supported_index++;@@ -584,20 +607,30 @@ static int isc_try_validate_formats(struct isc_device *isc)break ;default :/* any other different formats are not supported */ +v4l2_err (&isc->v4l2_dev,"Requested unsupported format.\n" ); ret = -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)) +if (bayer && + !ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output RAW if we do not receive RAW.\n" );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)) + !ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output GREY if we do not receive RAW/GREY.\n" );return -EINVAL ; + } + +if ((rgb || bayer || yuv) && +ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot convert GREY to another format.\n" ); +return -EINVAL ; + }return ret; }@@ -825,7 +858,7 @@ static void isc_try_fse(struct isc_device *isc,* If we do not know yet which format the subdev is using, we cannot * do anything. */ -if (!isc->try_config.sd_format) +if (!isc->config.sd_format)return ; fse.code = isc->try_config.sd_format->mbus_code;@@ -846,180 +879,140 @@ static void isc_try_fse(struct isc_device *isc, } } -static int isc_try_fmt (struct isc_device *isc,struct v4l2_format *f, -u32 *code) +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_state pad_state = { - .pads = &pad_cfg - }; -struct v4l2_subdev_format format = { - .which =V4L2_SUBDEV_FORMAT_TRY , - }; -u32 mbus_code; -int ret; -bool rlp_dma_direct_dump = false; +unsigned int i;if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE )return -EINVAL ; -/* Step 1: find a RAW format that is supported */ -for (i =0 ; i < isc->num_user_formats; i++) { -if (ISC_IS_FORMAT_RAW (isc->user_formats[i]->mbus_code)) { - sd_fmt = isc->user_formats[i]; + isc->try_config.fourcc = isc->controller_formats[0 ].fourcc; + +/* find if the format requested is supported */ +for (i =0 ; i < isc->controller_formats_size; i++) +if (isc->controller_formats[i].fourcc == pixfmt->pixelformat) { + isc->try_config.fourcc = pixfmt->pixelformat;break ; } - } -/* Step 2: We can continue with this RAW format, or we can look -* for better: maybe sensor supports directly what we need. -*/ - direct_fmt =find_format_by_fourcc (isc, pixfmt->pixelformat); - -/* Step 3: We have both. We decide given the module parameter which -* one to use. -*/ -if (direct_fmt && sd_fmt && sensor_preferred) - sd_fmt = direct_fmt; - -/* Step 4: we do not have RAW but we have a direct format. Use it. */ -if (direct_fmt && !sd_fmt) - sd_fmt = direct_fmt; - -/* Step 5: if we are using a direct format, we need to package -* everything as 8 bit data and just dump it -*/ -if (sd_fmt == direct_fmt) - rlp_dma_direct_dump = true; - -/* Step 6: We have no format. This can happen if the userspace -* requests some weird/invalid format. -* In this case, default to whatever we have -*/ -if (!sd_fmt && !direct_fmt) { - sd_fmt = isc->user_formats[isc->num_user_formats -1 ]; -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Sensor not supporting %.4s, using %.4s\n" , - (char *)&pixfmt->pixelformat, (char *)&sd_fmt->fourcc); - } - -if (!sd_fmt) { - ret = -EINVAL ; - goto isc_try_fmt_err; - } - -/* Step 7: Print out what we decided for debugging */ -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Preferring to have sensor using format %.4s\n" , - (char *)&sd_fmt->fourcc); -/* Step 8: at this moment we decided which format the subdev will use */ - isc->try_config.sd_format = sd_fmt; +isc_try_configure_rlp_dma (isc, false);/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - -/* -* The mbus format is the one the subdev outputs. -* The pixels will be transferred in this format Sensor -> ISC -*/ - mbus_code = sd_fmt->mbus_code; - -/* -* Validate formats. If the required format is not OK, default to raw. -*/ - - isc->try_config.fourcc = pixfmt->pixelformat; - -if (isc_try_validate_formats (isc)) { - pixfmt->pixelformat = isc->try_config.fourcc = sd_fmt->fourcc; -/* Re-try to validate the new format */ - ret =isc_try_validate_formats (isc); -if (ret) - goto isc_try_fmt_err; - } - - ret =isc_try_configure_rlp_dma (isc, rlp_dma_direct_dump); -if (ret) - goto isc_try_fmt_err; - - ret =isc_try_configure_pipeline (isc); -if (ret) - goto isc_try_fmt_err; - -/* Obtain frame sizes if possible to have crop requirements ready */ -isc_try_fse (isc, &pad_state); - -v4l2_fill_mbus_format (&format.format, pixfmt, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, set_fmt, - &pad_state, &format); -if (ret <0 ) - goto isc_try_fmt_subdev_err; - -v4l2_fill_pix_format (pixfmt, &format.format); +v4l_bound_align_image (&pixfmt->width,16 , isc->max_width,0 , + &pixfmt->height,16 , isc->max_height,0 ,0 ); +/* If we did not find the requested format, we will fallback here */ + pixfmt->pixelformat = isc->try_config.fourcc; + pixfmt->colorspace =V4L2_COLORSPACE_SRGB ; + pixfmt->field =V4L2_FIELD_NONE ; -/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - pixfmt->field =V4L2_FIELD_NONE ; pixfmt->bytesperline = (pixfmt->width * isc->try_config.bpp_v4l2) >>3 ; pixfmt->sizeimage = ((pixfmt->width * isc->try_config.bpp) >>3 ) * pixfmt->height; -if (code) - *code = mbus_code; + isc->try_fmt = *f;return 0 ; +} -isc_try_fmt_err: -v4l2_err (&isc->v4l2_dev,"Could not find any possible format for a working pipeline\n" ); -isc_try_fmt_subdev_err: -memset (&isc->try_config,0 ,sizeof (isc->try_config)); +static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +{ +isc_try_fmt (isc, f); -return ret; +/* make the try configuration active */ + isc->config = isc->try_config; + isc->fmt = isc->try_fmt; + +v4l2_dbg (1 , debug, &isc->v4l2_dev,"ISC set_fmt to %.4s @%dx%d\n" , + (char *)&f->fmt.pix.pixelformat, + f->fmt.pix.width, f->fmt.pix.height); + +return 0 ; } -static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +static int isc_validate (struct isc_device *isc) { +int ret; +int i; +struct isc_format *sd_fmt =NULL ; +struct v4l2_pix_format *pixfmt = &isc->fmt.fmt.pix;struct v4l2_subdev_format format = { .which =V4L2_SUBDEV_FORMAT_ACTIVE , + .pad = isc->remote_pad, + }; +struct v4l2_subdev_pad_config pad_cfg = {}; +struct v4l2_subdev_state pad_state = { + .pads = &pad_cfg, }; -u32 mbus_code =0 ; -int ret; - ret =isc_try_fmt (isc, f, &mbus_code); +/* Get current format from subdev */ + ret =v4l2_subdev_call (isc->current_subdev->sd, pad, get_fmt,NULL , + &format);if (ret)return ret; -v4l2_fill_mbus_format (&format.format, &f->fmt.pix, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, - set_fmt,NULL , &format); -if (ret <0 ) -return ret; +/* Identify the subdev's format configuration */ +for (i =0 ; i < isc->formats_list_size; i++) +if (isc->formats_list[i].mbus_code == format.format.code) { + sd_fmt = &isc->formats_list[i]; +break ; + } + +/* Check if the format is not supported */ +if (!sd_fmt) { +v4l2_err (&isc->v4l2_dev, +"Current subdevice is streaming a media bus code that is not supported 0x%x\n" , + format.format.code); +return -EPIPE ; + } + +/* At this moment we know which format the subdev will use */ + isc->try_config.sd_format = sd_fmt; + +/* If the sensor is not RAW, we can only do a direct dump */ +if (!ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) +isc_try_configure_rlp_dma (isc, true);/* Limit to Atmel ISC hardware capabilities */ -if (f->fmt.pix.width > isc->max_width) - f->fmt.pix.width = isc->max_width; -if (f->fmt.pix.height > isc->max_height) - f->fmt.pix.height = isc->max_height; +v4l_bound_align_image (&format.format.width,16 , isc->max_width,0 , + &format.format.height,16 , isc->max_height,0 ,0 ); - isc->fmt = *f; +/* Check if the frame size is the same. Otherwise we may overflow */ +if (pixfmt->height != format.format.height || + pixfmt->width != format.format.width) { +v4l2_err (&isc->v4l2_dev, +"ISC not configured with the proper frame size: %dx%d\n" , + format.format.width, format.format.height); +return -EPIPE ; + } +v4l2_dbg (1 , debug, &isc->v4l2_dev, +"Identified subdev using format %.4s with %dx%d %d bpp\n" , + (char *)&sd_fmt->fourcc, pixfmt->width, pixfmt->height, + isc->try_config.bpp); + +/* Reset and restart AWB if the subdevice changed the format */ if (isc->try_config.sd_format && isc->config.sd_format && isc->try_config.sd_format != isc->config.sd_format) { isc->ctrls.hist_stat =HIST_INIT ;isc_reset_awb_ctrls (isc);isc_update_v4l2_ctrls (isc); } -/* make the try configuration active */ + +/* Validate formats */ + ret =isc_try_validate_formats (isc); +if (ret) +return ret; + +/* Obtain frame sizes if possible to have crop requirements ready */ +isc_try_fse (isc, &pad_state); + +/* Configure ISC pipeline for the config */ + ret =isc_try_configure_pipeline (isc); +if (ret) +return ret; + isc->config = isc->try_config;v4l2_dbg (1 , debug, &isc->v4l2_dev,"New ISC configuration in place\n" );@@ -1043,7 +1036,7 @@ static int isc_try_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file); -return isc_try_fmt (isc, f,NULL ); +return isc_try_fmt (isc, f); } static int isc_enum_input(struct file *file, void *priv,@@ -1098,10 +1091,6 @@ static int isc_enum_framesizes(struct file *file, void *fh,if (fsize->index)return -EINVAL ; -for (i =0 ; i < isc->num_user_formats; i++) -if (isc->user_formats[i]->fourcc == fsize->pixel_format) - ret =0 ; -for (i =0 ; i < isc->controller_formats_size; i++)if (isc->controller_formats[i].fourcc == fsize->pixel_format) ret =0 ;@@ -1782,52 +1771,6 @@ struct isc_format *isc_find_format_by_code(struct isc_device *isc, }EXPORT_SYMBOL_GPL (isc_find_format_by_code); -static int isc_formats_init (struct isc_device *isc) -{ -struct isc_format *fmt; -struct v4l2_subdev *subdev = isc->current_subdev->sd; -unsigned int num_fmts, i, j; -u32 list_size = isc->formats_list_size; -struct v4l2_subdev_mbus_code_enum mbus_code = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - }; - - num_fmts =0 ; -while (!v4l2_subdev_call (subdev, pad, enum_mbus_code, -NULL , &mbus_code)) { - mbus_code.index++; - - fmt =isc_find_format_by_code (isc, mbus_code.code, &i); -if (!fmt) { -v4l2_warn (&isc->v4l2_dev,"Mbus code %x not supported\n" , - mbus_code.code); -continue ; - } - - fmt->sd_support = true; - num_fmts++; - } - -if (!num_fmts) -return -ENXIO ; - - isc->num_user_formats = num_fmts; - isc->user_formats =devm_kcalloc (isc->dev, - num_fmts,sizeof (*isc->user_formats), -GFP_KERNEL ); -if (!isc->user_formats) -return -ENOMEM ; - - fmt = &isc->formats_list[0 ]; -for (i =0 , j =0 ; i < list_size; i++) { -if (fmt->sd_support) - isc->user_formats[j++] = fmt; - fmt++; - } - -return 0 ; -} -static int isc_set_default_fmt (struct isc_device *isc) {struct v4l2_format f = {@@ -1836,12 +1779,12 @@ static int isc_set_default_fmt(struct isc_device *isc) .width = VGA_WIDTH, .height = VGA_HEIGHT, .field = V4L2_FIELD_NONE, - .pixelformat = isc->user_formats[0]->fourcc, + .pixelformat = isc->controller_formats[0].fourcc, }, };int ret; - ret =isc_try_fmt (isc, &f,NULL ); + ret =isc_try_fmt (isc, &f);if (ret)return ret;@@ -1896,13 +1839,6 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)spin_lock_init (&isc->dma_queue_lock);spin_lock_init (&isc->awb_lock); - ret =isc_formats_init (isc); -if (ret <0 ) { -v4l2_err (&isc->v4l2_dev, -"Init format failed: %d\n" , ret); - goto isc_async_complete_err; - } - ret =isc_set_default_fmt (isc);if (ret) {v4l2_err (&isc->v4l2_dev,"Could not set default format\n" );@@ -2016,6 +1952,24 @@ int isc_pipeline_init(struct isc_device *isc) }EXPORT_SYMBOL_GPL (isc_pipeline_init); +static int isc_link_validate (struct media_link *link) +{ +struct video_device *vdev = +media_entity_to_video_device (link->sink->entity); +struct isc_device *isc =video_get_drvdata (vdev); +int ret; + + ret =v4l2_subdev_link_validate (link); +if (ret) +return ret; + +return isc_validate (isc); +} + +static const struct media_entity_operations isc_entity_operations = { + .link_validate = isc_link_validate, +}; +int isc_mc_init (struct isc_device *isc,u32 ver) {const struct of_device_id *match;@@ -2023,6 +1977,8 @@ int isc_mc_init(struct isc_device *isc, u32 ver) isc->video_dev.entity.function =MEDIA_ENT_F_IO_V4L ; isc->video_dev.entity.flags =MEDIA_ENT_FL_DEFAULT ; + isc->video_dev.entity.ops = &isc_entity_operations; + isc->pads[ISC_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; ret = media_entity_pads_init(&isc->video_dev.entity, ISC_PADS_NUM,drivers/media/platform/atmel/atmel-isc-scaler.c +5
-0@@ -173,6 +173,10 @@ static const struct v4l2_subdev_pad_ops isc_scaler_pad_ops = { .init_cfg = isc_scaler_init_cfg, }; +static const struct media_entity_operations isc_scaler_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; +static const struct v4l2_subdev_ops xisc_scaler_subdev_ops = { .pad = &isc_scaler_pad_ops, };@@ -190,6 +194,7 @@ int isc_scaler_init(struct isc_device *isc) isc->scaler_sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; isc->scaler_sd.entity.function =MEDIA_ENT_F_PROC_VIDEO_SCALER ; + isc->scaler_sd.entity.ops = &isc_scaler_entity_ops; isc->scaler_pads[ISC_SCALER_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; isc->scaler_pads[ISC_SCALER_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ;drivers/media/platform/atmel/atmel-isc.h +7
-6@@ -63,15 +63,16 @@ struct isc_subdev_entity {* @cfa_baycfg: If this format is RAW BAYER, indicate the type of bayer. this is either BGBG, RGRG, etc. * @pfe_cfg0_bps: Number of hardware data lines connected to the ISC +* @raw: If the format is raw bayer. */ struct isc_format {u32 fourcc;u32 mbus_code;u32 cfa_baycfg; - -bool sd_support;u32 pfe_cfg0_bps; + +bool raw; };/* Pipeline bitmap */ @@ -216,8 +217,7 @@ enum isc_scaler_pads {* @comp: completion reference that signals frame completion * * @fmt: current v42l format -* @user_formats: list of formats that are supported and agreed with sd -* @num_user_formats: how many formats are in user_formats +* @try_fmt: current v4l2 try format * * @config: current ISC format configuration * @try_config: the current ISC try format , not yet activated @@ -272,6 +272,7 @@ enum isc_scaler_pads {* @formats_list_size: size of formats_list array * @pads: media controller pads for isc video entity * @mdev: media device that is registered by the isc +* @mpipe: media device pipeline used by the isc * @remote_pad: remote pad on the connected subdevice * @scaler_sd: subdevice for the scaler that isc registers * @scaler_pads: media controller pads for the scaler subdevice @@ -298,8 +299,7 @@ struct isc_device {struct completion comp;struct v4l2_format fmt; -struct isc_format **user_formats; -unsigned int num_user_formats; +struct v4l2_format try_fmt;struct fmt_config config;struct fmt_config try_config;@@ -369,6 +369,7 @@ struct isc_device {struct {struct media_pad pads[ISC_PADS_NUM ];struct media_device mdev; +struct media_pipeline mpipe;u32 remote_pad; };drivers/media/platform/atmel/atmel-sama5d2-isc.c +20
-0@@ -80,20 +80,40 @@ static const struct isc_format sama5d2_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y10, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };drivers/media/platform/atmel/atmel-sama7g5-isc.c +20
-0@@ -89,20 +89,40 @@ static const struct isc_format sama7g5_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y16, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Quoted 103 lines · Hans Verkuil
Quoted 102 lines · Jacopo Mondi
Hello
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.Yes indeed, seems I suggested to use
media_pipeline_handlerin a comment on your v3
Quoted 7 lines
Quoted 7 lines
"at
s_streamtime your top driver callsmedia_pipeline_start()"sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see
media_pipeline_startbeing called at all in v3 of the patch
No need to be sorry. Your suggestion was good and some other drivers do it, and it works well. We use this in production at the moment. So thank you for that.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Quoted 8 lines
Quoted 2 lines
Are you suggesting to have vb2 to call
media_pipeline_start()or is it more complex than this ?No, I don't think vb2 should do that. But it needs two new ops: pipeline_start/stop (or some other name) that are called at
VIDIOC_STREAMONtime and when the streaming stops (due to STREAMOFF or by closing the fh). The driver can then take appropriate action, which will typically be calling media_pipeline_start/stop, but other checks may also be needed at that time.
I can try to implement this and test with my driver, and come up with a proposal, if that is fine with you.
Eugen
Quoted 778 lines
Regards,
Hans
Quoted 772 lines
Quoted 772 lines
I'd like to know what others think.
Regards,
Hans
Quoted 763 lines
Eugen
Quoted 759 lines
Laurent, Jacopo, do you agree with that?
I notice that quite a few other drivers do this in
start_streamingas well, but I think it just weird that a QBUF can return EPIPE while STREAMON might succeed.Perhaps we need an optional vb2
validate()callback that is called byvb2_core_streamon()to validate the pipeline before streaming. That makes it easier to implement these checks rather than having to implement your own streamon ioctl.Regards,
Hans
Quoted 742 lines
drivers/media/platform/atmel/atmel-isc-base.c +183
-223+if (ret) + goto err_pipeline_start; +/* Enable stream on the sub device */ ret =v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,1 );if (ret && ret != -ENOIOCTLCMD ) {@@ -385,6 +384,9 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,0 ); err_start_stream: +media_pipeline_stop (&isc->video_dev.entity); + +err_pipeline_start:spin_lock_irqsave (&isc->dma_queue_lock, flags);list_for_each_entry (buf, &isc->dma_queue, list)vb2_buffer_done (&buf->vb.vb2_buf,VB2_BUF_STATE_QUEUED );@@ -423,6 +425,9 @@ static void isc_stop_streaming(struct vb2_queue *vq)if (ret && ret != -ENOIOCTLCMD )v4l2_err (&isc->v4l2_dev,"stream off failed in subdev\n" ); +/* Stop media pipeline */ +media_pipeline_stop (&isc->video_dev.entity); +/* Release all active buffers */ spin_lock_irqsave (&isc->dma_queue_lock, flags);if (unlikely (isc->cur_frm)) {@@ -453,22 +458,6 @@ static void isc_buffer_queue(struct vb2_buffer *vb)spin_unlock_irqrestore (&isc->dma_queue_lock, flags); } -static struct isc_format *find_format_by_fourcc (struct isc_device *isc, -unsigned int fourcc) -{ -unsigned int num_formats = isc->num_user_formats; -struct isc_format *fmt; -unsigned int i; - -for (i =0 ; i < num_formats; i++) { - fmt = isc->user_formats[i]; -if (fmt->fourcc == fourcc) -return fmt; - } - -return NULL ; -} -static const struct vb2_ops isc_vb2_ops = { .queue_setup = isc_queue_setup, .wait_prepare = vb2_ops_wait_prepare,@@ -497,23 +486,57 @@ static int isc_enum_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file);u32 index = f->index; -u32 i, supported_index; +u32 i, supported_index =0 ; +struct isc_format *fmt; + +/* +* If we are not asked a specific mbus_code, we have to report all +* the formats that we can output. +*/ +if (!f->mbus_code) { +if (index >= isc->controller_formats_size) +return -EINVAL ; -if (index < isc->controller_formats_size) { f->pixelformat = isc->controller_formats[index].fourcc; + +return 0 ; + } + +/* +* If a specific mbus_code is requested, check if we support +* this mbus_code as input for the ISC. +* If it's supported, then we report the corresponding pixelformat +* as first possible option for the ISC. +* E.g. mbus MEDIA_BUS_FMT_YUYV8_2X8 and report +* 'YUYV' (YUYV 4:2:2) +*/ + fmt =isc_find_format_by_code (isc, f->mbus_code, &i); +if (!fmt) +return -EINVAL ; + +if (!index) { + f->pixelformat = fmt->fourcc; +return 0 ; } - index -= isc->controller_formats_size; + supported_index++; - supported_index =0 ; +/* If the index is not raw, we don't have anymore formats to report */ +if (!ISC_IS_FORMAT_RAW (f->mbus_code)) +return -EINVAL ; -for (i =0 ; i < isc->formats_list_size; i++) { -if (!ISC_IS_FORMAT_RAW (isc->formats_list[i].mbus_code) || - !isc->formats_list[i].sd_support) +/* +* We are asked for a specific mbus code, which is raw. +* We have to search through the formats we can convert to. +* We have to skip the raw formats, we cannot convert to raw. +* E.g. 'AR12' (16-bit ARGB 4-4-4-4), 'AR15' (16-bit ARGB 1-5-5-5), etc. +*/ +for (i =0 ; i < isc->controller_formats_size; i++) { +if (isc->controller_formats[i].raw)continue ; -if (supported_index == index) { - f->pixelformat = isc->formats_list[i].fourcc; +if (index == supported_index) { + f->pixelformat = isc->controller_formats[i].fourcc;return 0 ; } supported_index++;@@ -584,20 +607,30 @@ static int isc_try_validate_formats(struct isc_device *isc)break ;default :/* any other different formats are not supported */ +v4l2_err (&isc->v4l2_dev,"Requested unsupported format.\n" ); ret = -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)) +if (bayer && + !ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output RAW if we do not receive RAW.\n" );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)) + !ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output GREY if we do not receive RAW/GREY.\n" );return -EINVAL ; + } + +if ((rgb || bayer || yuv) && +ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot convert GREY to another format.\n" ); +return -EINVAL ; + }return ret; }@@ -825,7 +858,7 @@ static void isc_try_fse(struct isc_device *isc,* If we do not know yet which format the subdev is using, we cannot * do anything. */ -if (!isc->try_config.sd_format) +if (!isc->config.sd_format)return ; fse.code = isc->try_config.sd_format->mbus_code;@@ -846,180 +879,140 @@ static void isc_try_fse(struct isc_device *isc, } } -static int isc_try_fmt (struct isc_device *isc,struct v4l2_format *f, -u32 *code) +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_state pad_state = { - .pads = &pad_cfg - }; -struct v4l2_subdev_format format = { - .which =V4L2_SUBDEV_FORMAT_TRY , - }; -u32 mbus_code; -int ret; -bool rlp_dma_direct_dump = false; +unsigned int i;if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE )return -EINVAL ; -/* Step 1: find a RAW format that is supported */ -for (i =0 ; i < isc->num_user_formats; i++) { -if (ISC_IS_FORMAT_RAW (isc->user_formats[i]->mbus_code)) { - sd_fmt = isc->user_formats[i]; + isc->try_config.fourcc = isc->controller_formats[0 ].fourcc; + +/* find if the format requested is supported */ +for (i =0 ; i < isc->controller_formats_size; i++) +if (isc->controller_formats[i].fourcc == pixfmt->pixelformat) { + isc->try_config.fourcc = pixfmt->pixelformat;break ; } - } -/* Step 2: We can continue with this RAW format, or we can look -* for better: maybe sensor supports directly what we need. -*/ - direct_fmt =find_format_by_fourcc (isc, pixfmt->pixelformat); - -/* Step 3: We have both. We decide given the module parameter which -* one to use. -*/ -if (direct_fmt && sd_fmt && sensor_preferred) - sd_fmt = direct_fmt; - -/* Step 4: we do not have RAW but we have a direct format. Use it. */ -if (direct_fmt && !sd_fmt) - sd_fmt = direct_fmt; - -/* Step 5: if we are using a direct format, we need to package -* everything as 8 bit data and just dump it -*/ -if (sd_fmt == direct_fmt) - rlp_dma_direct_dump = true; - -/* Step 6: We have no format. This can happen if the userspace -* requests some weird/invalid format. -* In this case, default to whatever we have -*/ -if (!sd_fmt && !direct_fmt) { - sd_fmt = isc->user_formats[isc->num_user_formats -1 ]; -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Sensor not supporting %.4s, using %.4s\n" , - (char *)&pixfmt->pixelformat, (char *)&sd_fmt->fourcc); - } - -if (!sd_fmt) { - ret = -EINVAL ; - goto isc_try_fmt_err; - } - -/* Step 7: Print out what we decided for debugging */ -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Preferring to have sensor using format %.4s\n" , - (char *)&sd_fmt->fourcc); -/* Step 8: at this moment we decided which format the subdev will use */ - isc->try_config.sd_format = sd_fmt; +isc_try_configure_rlp_dma (isc, false);/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - -/* -* The mbus format is the one the subdev outputs. -* The pixels will be transferred in this format Sensor -> ISC -*/ - mbus_code = sd_fmt->mbus_code; - -/* -* Validate formats. If the required format is not OK, default to raw. -*/ - - isc->try_config.fourcc = pixfmt->pixelformat; - -if (isc_try_validate_formats (isc)) { - pixfmt->pixelformat = isc->try_config.fourcc = sd_fmt->fourcc; -/* Re-try to validate the new format */ - ret =isc_try_validate_formats (isc); -if (ret) - goto isc_try_fmt_err; - } - - ret =isc_try_configure_rlp_dma (isc, rlp_dma_direct_dump); -if (ret) - goto isc_try_fmt_err; - - ret =isc_try_configure_pipeline (isc); -if (ret) - goto isc_try_fmt_err; - -/* Obtain frame sizes if possible to have crop requirements ready */ -isc_try_fse (isc, &pad_state); - -v4l2_fill_mbus_format (&format.format, pixfmt, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, set_fmt, - &pad_state, &format); -if (ret <0 ) - goto isc_try_fmt_subdev_err; - -v4l2_fill_pix_format (pixfmt, &format.format); +v4l_bound_align_image (&pixfmt->width,16 , isc->max_width,0 , + &pixfmt->height,16 , isc->max_height,0 ,0 ); +/* If we did not find the requested format, we will fallback here */ + pixfmt->pixelformat = isc->try_config.fourcc; + pixfmt->colorspace =V4L2_COLORSPACE_SRGB ; + pixfmt->field =V4L2_FIELD_NONE ; -/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - pixfmt->field =V4L2_FIELD_NONE ; pixfmt->bytesperline = (pixfmt->width * isc->try_config.bpp_v4l2) >>3 ; pixfmt->sizeimage = ((pixfmt->width * isc->try_config.bpp) >>3 ) * pixfmt->height; -if (code) - *code = mbus_code; + isc->try_fmt = *f;return 0 ; +} -isc_try_fmt_err: -v4l2_err (&isc->v4l2_dev,"Could not find any possible format for a working pipeline\n" ); -isc_try_fmt_subdev_err: -memset (&isc->try_config,0 ,sizeof (isc->try_config)); +static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +{ +isc_try_fmt (isc, f); -return ret; +/* make the try configuration active */ + isc->config = isc->try_config; + isc->fmt = isc->try_fmt; + +v4l2_dbg (1 , debug, &isc->v4l2_dev,"ISC set_fmt to %.4s @%dx%d\n" , + (char *)&f->fmt.pix.pixelformat, + f->fmt.pix.width, f->fmt.pix.height); + +return 0 ; } -static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +static int isc_validate (struct isc_device *isc) { +int ret; +int i; +struct isc_format *sd_fmt =NULL ; +struct v4l2_pix_format *pixfmt = &isc->fmt.fmt.pix;struct v4l2_subdev_format format = { .which =V4L2_SUBDEV_FORMAT_ACTIVE , + .pad = isc->remote_pad, + }; +struct v4l2_subdev_pad_config pad_cfg = {}; +struct v4l2_subdev_state pad_state = { + .pads = &pad_cfg, }; -u32 mbus_code =0 ; -int ret; - ret =isc_try_fmt (isc, f, &mbus_code); +/* Get current format from subdev */ + ret =v4l2_subdev_call (isc->current_subdev->sd, pad, get_fmt,NULL , + &format);if (ret)return ret; -v4l2_fill_mbus_format (&format.format, &f->fmt.pix, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, - set_fmt,NULL , &format); -if (ret <0 ) -return ret; +/* Identify the subdev's format configuration */ +for (i =0 ; i < isc->formats_list_size; i++) +if (isc->formats_list[i].mbus_code == format.format.code) { + sd_fmt = &isc->formats_list[i]; +break ; + } + +/* Check if the format is not supported */ +if (!sd_fmt) { +v4l2_err (&isc->v4l2_dev, +"Current subdevice is streaming a media bus code that is not supported 0x%x\n" , + format.format.code); +return -EPIPE ; + } + +/* At this moment we know which format the subdev will use */ + isc->try_config.sd_format = sd_fmt; + +/* If the sensor is not RAW, we can only do a direct dump */ +if (!ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) +isc_try_configure_rlp_dma (isc, true);/* Limit to Atmel ISC hardware capabilities */ -if (f->fmt.pix.width > isc->max_width) - f->fmt.pix.width = isc->max_width; -if (f->fmt.pix.height > isc->max_height) - f->fmt.pix.height = isc->max_height; +v4l_bound_align_image (&format.format.width,16 , isc->max_width,0 , + &format.format.height,16 , isc->max_height,0 ,0 ); - isc->fmt = *f; +/* Check if the frame size is the same. Otherwise we may overflow */ +if (pixfmt->height != format.format.height || + pixfmt->width != format.format.width) { +v4l2_err (&isc->v4l2_dev, +"ISC not configured with the proper frame size: %dx%d\n" , + format.format.width, format.format.height); +return -EPIPE ; + } +v4l2_dbg (1 , debug, &isc->v4l2_dev, +"Identified subdev using format %.4s with %dx%d %d bpp\n" , + (char *)&sd_fmt->fourcc, pixfmt->width, pixfmt->height, + isc->try_config.bpp); + +/* Reset and restart AWB if the subdevice changed the format */ if (isc->try_config.sd_format && isc->config.sd_format && isc->try_config.sd_format != isc->config.sd_format) { isc->ctrls.hist_stat =HIST_INIT ;isc_reset_awb_ctrls (isc);isc_update_v4l2_ctrls (isc); } -/* make the try configuration active */ + +/* Validate formats */ + ret =isc_try_validate_formats (isc); +if (ret) +return ret; + +/* Obtain frame sizes if possible to have crop requirements ready */ +isc_try_fse (isc, &pad_state); + +/* Configure ISC pipeline for the config */ + ret =isc_try_configure_pipeline (isc); +if (ret) +return ret; + isc->config = isc->try_config;v4l2_dbg (1 , debug, &isc->v4l2_dev,"New ISC configuration in place\n" );@@ -1043,7 +1036,7 @@ static int isc_try_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file); -return isc_try_fmt (isc, f,NULL ); +return isc_try_fmt (isc, f); } static int isc_enum_input(struct file *file, void *priv,@@ -1098,10 +1091,6 @@ static int isc_enum_framesizes(struct file *file, void *fh,if (fsize->index)return -EINVAL ; -for (i =0 ; i < isc->num_user_formats; i++) -if (isc->user_formats[i]->fourcc == fsize->pixel_format) - ret =0 ; -for (i =0 ; i < isc->controller_formats_size; i++)if (isc->controller_formats[i].fourcc == fsize->pixel_format) ret =0 ;@@ -1782,52 +1771,6 @@ struct isc_format *isc_find_format_by_code(struct isc_device *isc, }EXPORT_SYMBOL_GPL (isc_find_format_by_code); -static int isc_formats_init (struct isc_device *isc) -{ -struct isc_format *fmt; -struct v4l2_subdev *subdev = isc->current_subdev->sd; -unsigned int num_fmts, i, j; -u32 list_size = isc->formats_list_size; -struct v4l2_subdev_mbus_code_enum mbus_code = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - }; - - num_fmts =0 ; -while (!v4l2_subdev_call (subdev, pad, enum_mbus_code, -NULL , &mbus_code)) { - mbus_code.index++; - - fmt =isc_find_format_by_code (isc, mbus_code.code, &i); -if (!fmt) { -v4l2_warn (&isc->v4l2_dev,"Mbus code %x not supported\n" , - mbus_code.code); -continue ; - } - - fmt->sd_support = true; - num_fmts++; - } - -if (!num_fmts) -return -ENXIO ; - - isc->num_user_formats = num_fmts; - isc->user_formats =devm_kcalloc (isc->dev, - num_fmts,sizeof (*isc->user_formats), -GFP_KERNEL ); -if (!isc->user_formats) -return -ENOMEM ; - - fmt = &isc->formats_list[0 ]; -for (i =0 , j =0 ; i < list_size; i++) { -if (fmt->sd_support) - isc->user_formats[j++] = fmt; - fmt++; - } - -return 0 ; -} -static int isc_set_default_fmt (struct isc_device *isc) {struct v4l2_format f = {@@ -1836,12 +1779,12 @@ static int isc_set_default_fmt(struct isc_device *isc) .width = VGA_WIDTH, .height = VGA_HEIGHT, .field = V4L2_FIELD_NONE, - .pixelformat = isc->user_formats[0]->fourcc, + .pixelformat = isc->controller_formats[0].fourcc, }, };int ret; - ret =isc_try_fmt (isc, &f,NULL ); + ret =isc_try_fmt (isc, &f);if (ret)return ret;@@ -1896,13 +1839,6 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)spin_lock_init (&isc->dma_queue_lock);spin_lock_init (&isc->awb_lock); - ret =isc_formats_init (isc); -if (ret <0 ) { -v4l2_err (&isc->v4l2_dev, -"Init format failed: %d\n" , ret); - goto isc_async_complete_err; - } - ret =isc_set_default_fmt (isc);if (ret) {v4l2_err (&isc->v4l2_dev,"Could not set default format\n" );@@ -2016,6 +1952,24 @@ int isc_pipeline_init(struct isc_device *isc) }EXPORT_SYMBOL_GPL (isc_pipeline_init); +static int isc_link_validate (struct media_link *link) +{ +struct video_device *vdev = +media_entity_to_video_device (link->sink->entity); +struct isc_device *isc =video_get_drvdata (vdev); +int ret; + + ret =v4l2_subdev_link_validate (link); +if (ret) +return ret; + +return isc_validate (isc); +} + +static const struct media_entity_operations isc_entity_operations = { + .link_validate = isc_link_validate, +}; +int isc_mc_init (struct isc_device *isc,u32 ver) {const struct of_device_id *match;@@ -2023,6 +1977,8 @@ int isc_mc_init(struct isc_device *isc, u32 ver) isc->video_dev.entity.function =MEDIA_ENT_F_IO_V4L ; isc->video_dev.entity.flags =MEDIA_ENT_FL_DEFAULT ; + isc->video_dev.entity.ops = &isc_entity_operations; + isc->pads[ISC_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; ret = media_entity_pads_init(&isc->video_dev.entity, ISC_PADS_NUM,drivers/media/platform/atmel/atmel-isc-scaler.c +5
-0@@ -173,6 +173,10 @@ static const struct v4l2_subdev_pad_ops isc_scaler_pad_ops = { .init_cfg = isc_scaler_init_cfg, }; +static const struct media_entity_operations isc_scaler_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; +static const struct v4l2_subdev_ops xisc_scaler_subdev_ops = { .pad = &isc_scaler_pad_ops, };@@ -190,6 +194,7 @@ int isc_scaler_init(struct isc_device *isc) isc->scaler_sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; isc->scaler_sd.entity.function =MEDIA_ENT_F_PROC_VIDEO_SCALER ; + isc->scaler_sd.entity.ops = &isc_scaler_entity_ops; isc->scaler_pads[ISC_SCALER_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; isc->scaler_pads[ISC_SCALER_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ;drivers/media/platform/atmel/atmel-isc.h +7
-6@@ -63,15 +63,16 @@ struct isc_subdev_entity {* @cfa_baycfg: If this format is RAW BAYER, indicate the type of bayer. this is either BGBG, RGRG, etc. * @pfe_cfg0_bps: Number of hardware data lines connected to the ISC +* @raw: If the format is raw bayer. */ struct isc_format {u32 fourcc;u32 mbus_code;u32 cfa_baycfg; - -bool sd_support;u32 pfe_cfg0_bps; + +bool raw; };/* Pipeline bitmap */ @@ -216,8 +217,7 @@ enum isc_scaler_pads {* @comp: completion reference that signals frame completion * * @fmt: current v42l format -* @user_formats: list of formats that are supported and agreed with sd -* @num_user_formats: how many formats are in user_formats +* @try_fmt: current v4l2 try format * * @config: current ISC format configuration * @try_config: the current ISC try format , not yet activated @@ -272,6 +272,7 @@ enum isc_scaler_pads {* @formats_list_size: size of formats_list array * @pads: media controller pads for isc video entity * @mdev: media device that is registered by the isc +* @mpipe: media device pipeline used by the isc * @remote_pad: remote pad on the connected subdevice * @scaler_sd: subdevice for the scaler that isc registers * @scaler_pads: media controller pads for the scaler subdevice @@ -298,8 +299,7 @@ struct isc_device {struct completion comp;struct v4l2_format fmt; -struct isc_format **user_formats; -unsigned int num_user_formats; +struct v4l2_format try_fmt;struct fmt_config config;struct fmt_config try_config;@@ -369,6 +369,7 @@ struct isc_device {struct {struct media_pad pads[ISC_PADS_NUM ];struct media_device mdev; +struct media_pipeline mpipe;u32 remote_pad; };drivers/media/platform/atmel/atmel-sama5d2-isc.c +20
-0@@ -80,20 +80,40 @@ static const struct isc_format sama5d2_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y10, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };drivers/media/platform/atmel/atmel-sama7g5-isc.c +20
-0@@ -89,20 +89,40 @@ static const struct isc_format sama7g5_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y16, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
In reply to Jacopo MondiQuoted 114 lines · Jacopo Mondi
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.Yes indeed, seems I suggested to use
media_pipeline_handlerin a comment on your v3"at
s_streamtime your top driver callsmedia_pipeline_start()"sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see
media_pipeline_startbeing called at all in v3 of the patchQuoted 6 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.
Quoted 5 lines
Quoted 2 lines
I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Are you suggesting to have vb2 to call
media_pipeline_start()or is it more complex than this ?
I think Hans meant adding a .validate() operation to vb2.
vb2 is already quite complex, I don't think adding more features is a good idea. I'd rather have vb2 focus on buffer management only (.start_streaming() and .stop_streaming() shouldn't have been in there in my opinion), and handle validation in the .streamon() handler. I'd expect most drivers that deal with media pipelines to do more work in .streamon() anyway.
Quoted 755 lines
Quoted 755 lines
I'd like to know what others think.
Quoted 753 lines
Quoted 753 lines
Laurent, Jacopo, do you agree with that?
I notice that quite a few other drivers do this in
start_streamingas well, but I think it just weird that a QBUF can return EPIPE while STREAMON might succeed.Perhaps we need an optional vb2
validate()callback that is called byvb2_core_streamon()to validate the pipeline before streaming. That makes it easier to implement these checks rather than having to implement your own streamon ioctl.Quoted 742 lines
drivers/media/platform/atmel/atmel-isc-base.c +183
-223+if (ret) + goto err_pipeline_start; +/* Enable stream on the sub device */ ret =v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,1 );if (ret && ret != -ENOIOCTLCMD ) {@@ -385,6 +384,9 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)v4l2_subdev_call (isc->current_subdev->sd, video, s_stream,0 ); err_start_stream: +media_pipeline_stop (&isc->video_dev.entity); + +err_pipeline_start:spin_lock_irqsave (&isc->dma_queue_lock, flags);list_for_each_entry (buf, &isc->dma_queue, list)vb2_buffer_done (&buf->vb.vb2_buf,VB2_BUF_STATE_QUEUED );@@ -423,6 +425,9 @@ static void isc_stop_streaming(struct vb2_queue *vq)if (ret && ret != -ENOIOCTLCMD )v4l2_err (&isc->v4l2_dev,"stream off failed in subdev\n" ); +/* Stop media pipeline */ +media_pipeline_stop (&isc->video_dev.entity); +/* Release all active buffers */ spin_lock_irqsave (&isc->dma_queue_lock, flags);if (unlikely (isc->cur_frm)) {@@ -453,22 +458,6 @@ static void isc_buffer_queue(struct vb2_buffer *vb)spin_unlock_irqrestore (&isc->dma_queue_lock, flags); } -static struct isc_format *find_format_by_fourcc (struct isc_device *isc, -unsigned int fourcc) -{ -unsigned int num_formats = isc->num_user_formats; -struct isc_format *fmt; -unsigned int i; - -for (i =0 ; i < num_formats; i++) { - fmt = isc->user_formats[i]; -if (fmt->fourcc == fourcc) -return fmt; - } - -return NULL ; -} -static const struct vb2_ops isc_vb2_ops = { .queue_setup = isc_queue_setup, .wait_prepare = vb2_ops_wait_prepare,@@ -497,23 +486,57 @@ static int isc_enum_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file);u32 index = f->index; -u32 i, supported_index; +u32 i, supported_index =0 ; +struct isc_format *fmt; + +/* +* If we are not asked a specific mbus_code, we have to report all +* the formats that we can output. +*/ +if (!f->mbus_code) { +if (index >= isc->controller_formats_size) +return -EINVAL ; -if (index < isc->controller_formats_size) { f->pixelformat = isc->controller_formats[index].fourcc; + +return 0 ; + } + +/* +* If a specific mbus_code is requested, check if we support +* this mbus_code as input for the ISC. +* If it's supported, then we report the corresponding pixelformat +* as first possible option for the ISC. +* E.g. mbus MEDIA_BUS_FMT_YUYV8_2X8 and report +* 'YUYV' (YUYV 4:2:2) +*/ + fmt =isc_find_format_by_code (isc, f->mbus_code, &i); +if (!fmt) +return -EINVAL ; + +if (!index) { + f->pixelformat = fmt->fourcc; +return 0 ; } - index -= isc->controller_formats_size; + supported_index++; - supported_index =0 ; +/* If the index is not raw, we don't have anymore formats to report */ +if (!ISC_IS_FORMAT_RAW (f->mbus_code)) +return -EINVAL ; -for (i =0 ; i < isc->formats_list_size; i++) { -if (!ISC_IS_FORMAT_RAW (isc->formats_list[i].mbus_code) || - !isc->formats_list[i].sd_support) +/* +* We are asked for a specific mbus code, which is raw. +* We have to search through the formats we can convert to. +* We have to skip the raw formats, we cannot convert to raw. +* E.g. 'AR12' (16-bit ARGB 4-4-4-4), 'AR15' (16-bit ARGB 1-5-5-5), etc. +*/ +for (i =0 ; i < isc->controller_formats_size; i++) { +if (isc->controller_formats[i].raw)continue ; -if (supported_index == index) { - f->pixelformat = isc->formats_list[i].fourcc; +if (index == supported_index) { + f->pixelformat = isc->controller_formats[i].fourcc;return 0 ; } supported_index++;@@ -584,20 +607,30 @@ static int isc_try_validate_formats(struct isc_device *isc)break ;default :/* any other different formats are not supported */ +v4l2_err (&isc->v4l2_dev,"Requested unsupported format.\n" ); ret = -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)) +if (bayer && + !ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output RAW if we do not receive RAW.\n" );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)) + !ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot output GREY if we do not receive RAW/GREY.\n" );return -EINVAL ; + } + +if ((rgb || bayer || yuv) && +ISC_IS_FORMAT_GREY (isc->try_config.sd_format->mbus_code)) { +v4l2_err (&isc->v4l2_dev,"Cannot convert GREY to another format.\n" ); +return -EINVAL ; + }return ret; }@@ -825,7 +858,7 @@ static void isc_try_fse(struct isc_device *isc,* If we do not know yet which format the subdev is using, we cannot * do anything. */ -if (!isc->try_config.sd_format) +if (!isc->config.sd_format)return ; fse.code = isc->try_config.sd_format->mbus_code;@@ -846,180 +879,140 @@ static void isc_try_fse(struct isc_device *isc, } } -static int isc_try_fmt (struct isc_device *isc,struct v4l2_format *f, -u32 *code) +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_state pad_state = { - .pads = &pad_cfg - }; -struct v4l2_subdev_format format = { - .which =V4L2_SUBDEV_FORMAT_TRY , - }; -u32 mbus_code; -int ret; -bool rlp_dma_direct_dump = false; +unsigned int i;if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE )return -EINVAL ; -/* Step 1: find a RAW format that is supported */ -for (i =0 ; i < isc->num_user_formats; i++) { -if (ISC_IS_FORMAT_RAW (isc->user_formats[i]->mbus_code)) { - sd_fmt = isc->user_formats[i]; + isc->try_config.fourcc = isc->controller_formats[0 ].fourcc; + +/* find if the format requested is supported */ +for (i =0 ; i < isc->controller_formats_size; i++) +if (isc->controller_formats[i].fourcc == pixfmt->pixelformat) { + isc->try_config.fourcc = pixfmt->pixelformat;break ; } - } -/* Step 2: We can continue with this RAW format, or we can look -* for better: maybe sensor supports directly what we need. -*/ - direct_fmt =find_format_by_fourcc (isc, pixfmt->pixelformat); - -/* Step 3: We have both. We decide given the module parameter which -* one to use. -*/ -if (direct_fmt && sd_fmt && sensor_preferred) - sd_fmt = direct_fmt; - -/* Step 4: we do not have RAW but we have a direct format. Use it. */ -if (direct_fmt && !sd_fmt) - sd_fmt = direct_fmt; - -/* Step 5: if we are using a direct format, we need to package -* everything as 8 bit data and just dump it -*/ -if (sd_fmt == direct_fmt) - rlp_dma_direct_dump = true; - -/* Step 6: We have no format. This can happen if the userspace -* requests some weird/invalid format. -* In this case, default to whatever we have -*/ -if (!sd_fmt && !direct_fmt) { - sd_fmt = isc->user_formats[isc->num_user_formats -1 ]; -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Sensor not supporting %.4s, using %.4s\n" , - (char *)&pixfmt->pixelformat, (char *)&sd_fmt->fourcc); - } - -if (!sd_fmt) { - ret = -EINVAL ; - goto isc_try_fmt_err; - } - -/* Step 7: Print out what we decided for debugging */ -v4l2_dbg (1 , debug, &isc->v4l2_dev, -"Preferring to have sensor using format %.4s\n" , - (char *)&sd_fmt->fourcc); -/* Step 8: at this moment we decided which format the subdev will use */ - isc->try_config.sd_format = sd_fmt; +isc_try_configure_rlp_dma (isc, false);/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - -/* -* The mbus format is the one the subdev outputs. -* The pixels will be transferred in this format Sensor -> ISC -*/ - mbus_code = sd_fmt->mbus_code; - -/* -* Validate formats. If the required format is not OK, default to raw. -*/ - - isc->try_config.fourcc = pixfmt->pixelformat; - -if (isc_try_validate_formats (isc)) { - pixfmt->pixelformat = isc->try_config.fourcc = sd_fmt->fourcc; -/* Re-try to validate the new format */ - ret =isc_try_validate_formats (isc); -if (ret) - goto isc_try_fmt_err; - } - - ret =isc_try_configure_rlp_dma (isc, rlp_dma_direct_dump); -if (ret) - goto isc_try_fmt_err; - - ret =isc_try_configure_pipeline (isc); -if (ret) - goto isc_try_fmt_err; - -/* Obtain frame sizes if possible to have crop requirements ready */ -isc_try_fse (isc, &pad_state); - -v4l2_fill_mbus_format (&format.format, pixfmt, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, set_fmt, - &pad_state, &format); -if (ret <0 ) - goto isc_try_fmt_subdev_err; - -v4l2_fill_pix_format (pixfmt, &format.format); +v4l_bound_align_image (&pixfmt->width,16 , isc->max_width,0 , + &pixfmt->height,16 , isc->max_height,0 ,0 ); +/* If we did not find the requested format, we will fallback here */ + pixfmt->pixelformat = isc->try_config.fourcc; + pixfmt->colorspace =V4L2_COLORSPACE_SRGB ; + pixfmt->field =V4L2_FIELD_NONE ; -/* Limit to Atmel ISC hardware capabilities */ -if (pixfmt->width > isc->max_width) - pixfmt->width = isc->max_width; -if (pixfmt->height > isc->max_height) - pixfmt->height = isc->max_height; - pixfmt->field =V4L2_FIELD_NONE ; pixfmt->bytesperline = (pixfmt->width * isc->try_config.bpp_v4l2) >>3 ; pixfmt->sizeimage = ((pixfmt->width * isc->try_config.bpp) >>3 ) * pixfmt->height; -if (code) - *code = mbus_code; + isc->try_fmt = *f;return 0 ; +} -isc_try_fmt_err: -v4l2_err (&isc->v4l2_dev,"Could not find any possible format for a working pipeline\n" ); -isc_try_fmt_subdev_err: -memset (&isc->try_config,0 ,sizeof (isc->try_config)); +static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +{ +isc_try_fmt (isc, f); -return ret; +/* make the try configuration active */ + isc->config = isc->try_config; + isc->fmt = isc->try_fmt; + +v4l2_dbg (1 , debug, &isc->v4l2_dev,"ISC set_fmt to %.4s @%dx%d\n" , + (char *)&f->fmt.pix.pixelformat, + f->fmt.pix.width, f->fmt.pix.height); + +return 0 ; } -static int isc_set_fmt (struct isc_device *isc,struct v4l2_format *f) +static int isc_validate (struct isc_device *isc) { +int ret; +int i; +struct isc_format *sd_fmt =NULL ; +struct v4l2_pix_format *pixfmt = &isc->fmt.fmt.pix;struct v4l2_subdev_format format = { .which =V4L2_SUBDEV_FORMAT_ACTIVE , + .pad = isc->remote_pad, + }; +struct v4l2_subdev_pad_config pad_cfg = {}; +struct v4l2_subdev_state pad_state = { + .pads = &pad_cfg, }; -u32 mbus_code =0 ; -int ret; - ret =isc_try_fmt (isc, f, &mbus_code); +/* Get current format from subdev */ + ret =v4l2_subdev_call (isc->current_subdev->sd, pad, get_fmt,NULL , + &format);if (ret)return ret; -v4l2_fill_mbus_format (&format.format, &f->fmt.pix, mbus_code); - ret =v4l2_subdev_call (isc->current_subdev->sd, pad, - set_fmt,NULL , &format); -if (ret <0 ) -return ret; +/* Identify the subdev's format configuration */ +for (i =0 ; i < isc->formats_list_size; i++) +if (isc->formats_list[i].mbus_code == format.format.code) { + sd_fmt = &isc->formats_list[i]; +break ; + } + +/* Check if the format is not supported */ +if (!sd_fmt) { +v4l2_err (&isc->v4l2_dev, +"Current subdevice is streaming a media bus code that is not supported 0x%x\n" , + format.format.code); +return -EPIPE ; + } + +/* At this moment we know which format the subdev will use */ + isc->try_config.sd_format = sd_fmt; + +/* If the sensor is not RAW, we can only do a direct dump */ +if (!ISC_IS_FORMAT_RAW (isc->try_config.sd_format->mbus_code)) +isc_try_configure_rlp_dma (isc, true);/* Limit to Atmel ISC hardware capabilities */ -if (f->fmt.pix.width > isc->max_width) - f->fmt.pix.width = isc->max_width; -if (f->fmt.pix.height > isc->max_height) - f->fmt.pix.height = isc->max_height; +v4l_bound_align_image (&format.format.width,16 , isc->max_width,0 , + &format.format.height,16 , isc->max_height,0 ,0 ); - isc->fmt = *f; +/* Check if the frame size is the same. Otherwise we may overflow */ +if (pixfmt->height != format.format.height || + pixfmt->width != format.format.width) { +v4l2_err (&isc->v4l2_dev, +"ISC not configured with the proper frame size: %dx%d\n" , + format.format.width, format.format.height); +return -EPIPE ; + } +v4l2_dbg (1 , debug, &isc->v4l2_dev, +"Identified subdev using format %.4s with %dx%d %d bpp\n" , + (char *)&sd_fmt->fourcc, pixfmt->width, pixfmt->height, + isc->try_config.bpp); + +/* Reset and restart AWB if the subdevice changed the format */ if (isc->try_config.sd_format && isc->config.sd_format && isc->try_config.sd_format != isc->config.sd_format) { isc->ctrls.hist_stat =HIST_INIT ;isc_reset_awb_ctrls (isc);isc_update_v4l2_ctrls (isc); } -/* make the try configuration active */ + +/* Validate formats */ + ret =isc_try_validate_formats (isc); +if (ret) +return ret; + +/* Obtain frame sizes if possible to have crop requirements ready */ +isc_try_fse (isc, &pad_state); + +/* Configure ISC pipeline for the config */ + ret =isc_try_configure_pipeline (isc); +if (ret) +return ret; + isc->config = isc->try_config;v4l2_dbg (1 , debug, &isc->v4l2_dev,"New ISC configuration in place\n" );@@ -1043,7 +1036,7 @@ static int isc_try_fmt_vid_cap(struct file *file, void *priv, {struct isc_device *isc =video_drvdata (file); -return isc_try_fmt (isc, f,NULL ); +return isc_try_fmt (isc, f); } static int isc_enum_input(struct file *file, void *priv,@@ -1098,10 +1091,6 @@ static int isc_enum_framesizes(struct file *file, void *fh,if (fsize->index)return -EINVAL ; -for (i =0 ; i < isc->num_user_formats; i++) -if (isc->user_formats[i]->fourcc == fsize->pixel_format) - ret =0 ; -for (i =0 ; i < isc->controller_formats_size; i++)if (isc->controller_formats[i].fourcc == fsize->pixel_format) ret =0 ;@@ -1782,52 +1771,6 @@ struct isc_format *isc_find_format_by_code(struct isc_device *isc, }EXPORT_SYMBOL_GPL (isc_find_format_by_code); -static int isc_formats_init (struct isc_device *isc) -{ -struct isc_format *fmt; -struct v4l2_subdev *subdev = isc->current_subdev->sd; -unsigned int num_fmts, i, j; -u32 list_size = isc->formats_list_size; -struct v4l2_subdev_mbus_code_enum mbus_code = { - .which =V4L2_SUBDEV_FORMAT_ACTIVE , - }; - - num_fmts =0 ; -while (!v4l2_subdev_call (subdev, pad, enum_mbus_code, -NULL , &mbus_code)) { - mbus_code.index++; - - fmt =isc_find_format_by_code (isc, mbus_code.code, &i); -if (!fmt) { -v4l2_warn (&isc->v4l2_dev,"Mbus code %x not supported\n" , - mbus_code.code); -continue ; - } - - fmt->sd_support = true; - num_fmts++; - } - -if (!num_fmts) -return -ENXIO ; - - isc->num_user_formats = num_fmts; - isc->user_formats =devm_kcalloc (isc->dev, - num_fmts,sizeof (*isc->user_formats), -GFP_KERNEL ); -if (!isc->user_formats) -return -ENOMEM ; - - fmt = &isc->formats_list[0 ]; -for (i =0 , j =0 ; i < list_size; i++) { -if (fmt->sd_support) - isc->user_formats[j++] = fmt; - fmt++; - } - -return 0 ; -} -static int isc_set_default_fmt (struct isc_device *isc) {struct v4l2_format f = {@@ -1836,12 +1779,12 @@ static int isc_set_default_fmt(struct isc_device *isc) .width = VGA_WIDTH, .height = VGA_HEIGHT, .field = V4L2_FIELD_NONE, - .pixelformat = isc->user_formats[0]->fourcc, + .pixelformat = isc->controller_formats[0].fourcc, }, };int ret; - ret =isc_try_fmt (isc, &f,NULL ); + ret =isc_try_fmt (isc, &f);if (ret)return ret;@@ -1896,13 +1839,6 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)spin_lock_init (&isc->dma_queue_lock);spin_lock_init (&isc->awb_lock); - ret =isc_formats_init (isc); -if (ret <0 ) { -v4l2_err (&isc->v4l2_dev, -"Init format failed: %d\n" , ret); - goto isc_async_complete_err; - } - ret =isc_set_default_fmt (isc);if (ret) {v4l2_err (&isc->v4l2_dev,"Could not set default format\n" );@@ -2016,6 +1952,24 @@ int isc_pipeline_init(struct isc_device *isc) }EXPORT_SYMBOL_GPL (isc_pipeline_init); +static int isc_link_validate (struct media_link *link) +{ +struct video_device *vdev = +media_entity_to_video_device (link->sink->entity); +struct isc_device *isc =video_get_drvdata (vdev); +int ret; + + ret =v4l2_subdev_link_validate (link); +if (ret) +return ret; + +return isc_validate (isc); +} + +static const struct media_entity_operations isc_entity_operations = { + .link_validate = isc_link_validate, +}; +int isc_mc_init (struct isc_device *isc,u32 ver) {const struct of_device_id *match;@@ -2023,6 +1977,8 @@ int isc_mc_init(struct isc_device *isc, u32 ver) isc->video_dev.entity.function =MEDIA_ENT_F_IO_V4L ; isc->video_dev.entity.flags =MEDIA_ENT_FL_DEFAULT ; + isc->video_dev.entity.ops = &isc_entity_operations; + isc->pads[ISC_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; ret = media_entity_pads_init(&isc->video_dev.entity, ISC_PADS_NUM,drivers/media/platform/atmel/atmel-isc-scaler.c +5
-0@@ -173,6 +173,10 @@ static const struct v4l2_subdev_pad_ops isc_scaler_pad_ops = { .init_cfg = isc_scaler_init_cfg, }; +static const struct media_entity_operations isc_scaler_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; +static const struct v4l2_subdev_ops xisc_scaler_subdev_ops = { .pad = &isc_scaler_pad_ops, };@@ -190,6 +194,7 @@ int isc_scaler_init(struct isc_device *isc) isc->scaler_sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; isc->scaler_sd.entity.function =MEDIA_ENT_F_PROC_VIDEO_SCALER ; + isc->scaler_sd.entity.ops = &isc_scaler_entity_ops; isc->scaler_pads[ISC_SCALER_PAD_SINK ].flags =MEDIA_PAD_FL_SINK ; isc->scaler_pads[ISC_SCALER_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ;drivers/media/platform/atmel/atmel-isc.h +7
-6@@ -63,15 +63,16 @@ struct isc_subdev_entity {* @cfa_baycfg: If this format is RAW BAYER, indicate the type of bayer. this is either BGBG, RGRG, etc. * @pfe_cfg0_bps: Number of hardware data lines connected to the ISC +* @raw: If the format is raw bayer. */ struct isc_format {u32 fourcc;u32 mbus_code;u32 cfa_baycfg; - -bool sd_support;u32 pfe_cfg0_bps; + +bool raw; };/* Pipeline bitmap */ @@ -216,8 +217,7 @@ enum isc_scaler_pads {* @comp: completion reference that signals frame completion * * @fmt: current v42l format -* @user_formats: list of formats that are supported and agreed with sd -* @num_user_formats: how many formats are in user_formats +* @try_fmt: current v4l2 try format * * @config: current ISC format configuration * @try_config: the current ISC try format , not yet activated @@ -272,6 +272,7 @@ enum isc_scaler_pads {* @formats_list_size: size of formats_list array * @pads: media controller pads for isc video entity * @mdev: media device that is registered by the isc +* @mpipe: media device pipeline used by the isc * @remote_pad: remote pad on the connected subdevice * @scaler_sd: subdevice for the scaler that isc registers * @scaler_pads: media controller pads for the scaler subdevice @@ -298,8 +299,7 @@ struct isc_device {struct completion comp;struct v4l2_format fmt; -struct isc_format **user_formats; -unsigned int num_user_formats; +struct v4l2_format try_fmt;struct fmt_config config;struct fmt_config try_config;@@ -369,6 +369,7 @@ struct isc_device {struct {struct media_pad pads[ISC_PADS_NUM ];struct media_device mdev; +struct media_pipeline mpipe;u32 remote_pad; };drivers/media/platform/atmel/atmel-sama5d2-isc.c +20
-0@@ -80,20 +80,40 @@ static const struct isc_format sama5d2_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y10, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };drivers/media/platform/atmel/atmel-sama7g5-isc.c +20
-0@@ -89,20 +89,40 @@ static const struct isc_format sama7g5_controller_formats[] = { .fourcc = V4L2_PIX_FMT_Y16, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, + .raw = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG12, + .raw = true, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB12, + .raw = true, }, };
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Quoted 121 lines · Laurent Pinchart
Quoted 114 lines · Jacopo Mondi
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.Yes indeed, seems I suggested to use
media_pipeline_handlerin a comment on your v3"at
s_streamtime your top driver callsmedia_pipeline_start()"sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see
media_pipeline_startbeing called at all in v3 of the patchQuoted 6 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.Quoted 5 lines
Quoted 2 lines
I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Are you suggesting to have vb2 to call
media_pipeline_start()or is it more complex than this ?
Quoted 8 lines
I think Hans meant adding a .validate() operation to vb2.
vb2 is already quite complex, I don't think adding more features is a good idea. I'd rather have vb2 focus on buffer management only (.start_streaming() and .stop_streaming() shouldn't have been in there in my opinion), and handle validation in the .streamon() handler. I'd expect most drivers that deal with media pipelines to do more work in .streamon() anyway.
I disagree with that :-)
It's vb2 that keeps track of the streaming state and when what actions need to be taken. Drivers really shouldn't need to care about the ioctls themselves, and just implement the relevant vb2 callbacks. Relying on drivers to handle any of the streaming ioctls is asking for problems, as this shows: most drivers implement this wrong today.
The vb2 framework knows when e.g. the pipeline needs to be started or stopped, and can do this at the best time, without drivers needing to keep track of when streamon/off/release is called. Keep that logic in vb2.
Regards,
Hans
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Quoted 139 lines · Hans Verkuil
Quoted 121 lines · Laurent Pinchart
Quoted 114 lines · Jacopo Mondi
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.Yes indeed, seems I suggested to use
media_pipeline_handlerin a comment on your v3"at
s_streamtime your top driver callsmedia_pipeline_start()"sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see
media_pipeline_startbeing called at all in v3 of the patchQuoted 6 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.Quoted 5 lines
Quoted 2 lines
I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Are you suggesting to have vb2 to call
media_pipeline_start()or is it more complex than this ?Quoted 8 lines
I think Hans meant adding a .validate() operation to vb2.
vb2 is already quite complex, I don't think adding more features is a good idea. I'd rather have vb2 focus on buffer management only (.start_streaming() and .stop_streaming() shouldn't have been in there in my opinion), and handle validation in the .streamon() handler. I'd expect most drivers that deal with media pipelines to do more work in .streamon() anyway.
I disagree with that :-)
It's vb2 that keeps track of the streaming state and when what actions need to be taken. Drivers really shouldn't need to care about the ioctls themselves, and just implement the relevant vb2 callbacks. Relying on drivers to handle any of the streaming ioctls is asking for problems, as this shows: most drivers implement this wrong today.
Quoted 4 lines
The vb2 framework knows when e.g. the pipeline needs to be started or stopped, and can do this at the best time, without drivers needing to keep track of when streamon/off/release is called. Keep that logic in vb2.
Pipeline management and buffer management are two different issues. Don't forget about devices that have multiple video nodes, part of the same pipeline (possibly a combination of output and capture nodes, or all of the same type). Forcing drivers to go through vb2 operations to handle the pipeline will be messy, will result in more bloat in vb2, and make the result more bug-prone and harder to maintain.
If pipeline management is too complex, let's simplify it, new helpers can make sense, but not through vb2.
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Quoted 152 lines · Laurent Pinchart
Quoted 139 lines · Hans Verkuil
Quoted 121 lines · Laurent Pinchart
Quoted 114 lines · Jacopo Mondi
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.Yes indeed, seems I suggested to use
media_pipeline_handlerin a comment on your v3"at
s_streamtime your top driver callsmedia_pipeline_start()"sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see
media_pipeline_startbeing called at all in v3 of the patchQuoted 6 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.Quoted 5 lines
Quoted 2 lines
I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Are you suggesting to have vb2 to call
media_pipeline_start()or is it more complex than this ?Quoted 8 lines
I think Hans meant adding a .validate() operation to vb2.
vb2 is already quite complex, I don't think adding more features is a good idea. I'd rather have vb2 focus on buffer management only (.start_streaming() and .stop_streaming() shouldn't have been in there in my opinion), and handle validation in the .streamon() handler. I'd expect most drivers that deal with media pipelines to do more work in .streamon() anyway.
I disagree with that :-)
It's vb2 that keeps track of the streaming state and when what actions need to be taken. Drivers really shouldn't need to care about the ioctls themselves, and just implement the relevant vb2 callbacks. Relying on drivers to handle any of the streaming ioctls is asking for problems, as this shows: most drivers implement this wrong today.
Quoted 4 lines
The vb2 framework knows when e.g. the pipeline needs to be started or stopped, and can do this at the best time, without drivers needing to keep track of when streamon/off/release is called. Keep that logic in vb2.
Pipeline management and buffer management are two different issues. Don't forget about devices that have multiple video nodes, part of the same pipeline (possibly a combination of output and capture nodes, or all of the same type). Forcing drivers to go through vb2 operations to handle the pipeline will be messy, will result in more bloat in vb2, and make the result more bug-prone and harder to maintain.
Quoted 3 lines
If pipeline management is too complex, let's simplify it, new helpers can make sense, but not through vb2.
But it is vb2 that knows when streaming starts and stops. The driver just needs to be informed (e.g. prepare_streaming and unprepare_streaming ops).
vb2 deals with buffer management and it keeps track of the streaming state and makes the streaming state transitions. That *is* an integral part of vb2. What is missing at the moment are callbacks done at streamon time and when the streaming stops (streamoff, or close() when is_streaming is true).
If you want to implement stream validation in a driver, then there are a lot of things you need to do:
- override streamon, make sure you call vb2_queue_is_busy(), validate the pipeline, then call vb2_streamon, if that fails, remember to stop the pipeline.
- override streamoff, make sure you call vb2_queue_is_busy(), stop the pipeline and call vb2_streamoff.
- in the release() function when the fh is closed, you have to check vb2_is_streaming(), check that you are the owner of the queue, and if true, stop the pipeline.
By moving this to vb2 ops all you need to implement are the prepare and unprepare ops.
Esp. the release() implementation is tricky. I'm pretty sure that drivers/media/platform/samsung/exynos4-is/fimc-lite.c is wrong, since it should only call media_pipeline_stop() for the owner of the queue. Instead it calls it for the last user of the queue.
I see that fimc_lite_streamoff() is wrong too: you can safely call VIDIOC_STREAMOFF twice: the second streamoff just returns 0 without doing anything. Instead media_pipeline_stop is called without testing if the queue is streaming.
And yes, this is in part because V4L2 has quite some history and certainly API choice were made in the past that we wouldn't make today. But vb2 shields you from that, and behaves much more like a proper state machine.
I know you prefer to give a lot more control to driver developers, but in my experience very few developers can do things like this right. And it is really hard as a reviewer to check if all the corner cases are handled correctly in a driver. If vb2 is used, then I know things are called at the right time, and that makes my life as reviewer so much easier.
There may still be a few drivers that really need to do this manually, and that's OK, but a driver like the atmel-isc doesn't need that at all.
Regards,
Hans
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Quoted 153 lines · Hans Verkuil
Quoted 152 lines · Laurent Pinchart
Quoted 139 lines · Hans Verkuil
Quoted 121 lines · Laurent Pinchart
Quoted 114 lines · Jacopo Mondi
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.Yes indeed, seems I suggested to use
media_pipeline_handlerin a comment on your v3"at
s_streamtime your top driver callsmedia_pipeline_start()"sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see
media_pipeline_startbeing called at all in v3 of the patchQuoted 6 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.Quoted 5 lines
Quoted 2 lines
I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Are you suggesting to have vb2 to call
media_pipeline_start()or is it more complex than this ?Quoted 8 lines
I think Hans meant adding a .validate() operation to vb2.
vb2 is already quite complex, I don't think adding more features is a good idea. I'd rather have vb2 focus on buffer management only (.start_streaming() and .stop_streaming() shouldn't have been in there in my opinion), and handle validation in the .streamon() handler. I'd expect most drivers that deal with media pipelines to do more work in .streamon() anyway.
I disagree with that :-)
It's vb2 that keeps track of the streaming state and when what actions need to be taken. Drivers really shouldn't need to care about the ioctls themselves, and just implement the relevant vb2 callbacks. Relying on drivers to handle any of the streaming ioctls is asking for problems, as this shows: most drivers implement this wrong today.
Quoted 4 lines
The vb2 framework knows when e.g. the pipeline needs to be started or stopped, and can do this at the best time, without drivers needing to keep track of when streamon/off/release is called. Keep that logic in vb2.
Pipeline management and buffer management are two different issues. Don't forget about devices that have multiple video nodes, part of the same pipeline (possibly a combination of output and capture nodes, or all of the same type). Forcing drivers to go through vb2 operations to handle the pipeline will be messy, will result in more bloat in vb2, and make the result more bug-prone and harder to maintain.
Quoted 5 lines
Quoted 3 lines
If pipeline management is too complex, let's simplify it, new helpers can make sense, but not through vb2.
But it is vb2 that knows when streaming starts and stops.
That's right, but pipeline start (which includes validation and resource reservation) needs to be performed synchronously with VIDIOC_STREAMON. The streaming state managed by vb2 is not relevant, media_pipeline_start() must not be delayed the same way .start_streaming() is.
Quoted 15 lines
The driver just
needs to be informed (e.g.prepare_streamingandunprepare_streamingops).vb2 deals with buffer management and it keeps track of the streaming state and makes the streaming state transitions. That *is* an integral part of vb2. What is missing at the moment are callbacks done at streamon time and when the streaming stops (streamoff, or
close()whenis_streamingis true).If you want to implement stream validation in a driver, then there are a lot of things you need to do:
- override streamon, make sure you call
vb2_queue_is_busy(), validate the pipeline, then callvb2_streamon, if that fails, remember to stop the pipeline.
Quoted 6 lines
- override streamoff, make sure you call
vb2_queue_is_busy(), stop the pipeline and callvb2_streamoff.- in the
release()function when the fh is closed, you have to checkvb2_is_streaming(), check that you are the owner of the queue, and if true, stop the pipeline.
I'm not opposed to helper functions to implement that, they can bundle vb2 calls and pipeline management.
Quoted 17 lines
By moving this to vb2 ops all you need to implement are the prepare and unprepare ops.
Esp. the
release()implementation is tricky. I'm pretty sure thatdrivers/media/platform/samsung/exynos4-is/fimc-lite.cis wrong, since it should only callmedia_pipeline_stop()for the owner of the queue. Instead it calls it for the last user of the queue.I see that
fimc_lite_streamoff()is wrong too: you can safely callVIDIOC_STREAMOFFtwice: the second streamoff just returns 0 without doing anything. Insteadmedia_pipeline_stopis called without testing if the queue is streaming.And yes, this is in part because V4L2 has quite some history and certainly API choice were made in the past that we wouldn't make today. But vb2 shields you from that, and behaves much more like a proper state machine.
Quoted 5 lines
I know you prefer to give a lot more control to driver developers, but in my experience very few developers can do things like this right. And it is really hard as a reviewer to check if all the corner cases are handled correctly in a driver. If vb2 is used, then I know things are called at the right time, and that makes my life as reviewer so much easier.
It's not just about giving more control to drivers, it's about organizing the software layers in a way that keeps them maintainable, with layered abstractions and not midlayers.
We are extensively reworking the media pipeline management as part of the stream series, and there will be more work on top of that that will make even more fundamental changes. I would like to at least postpone any work on vb2 until then, to be able to evaluate the impact.
Quoted 2 lines
There may still be a few drivers that really need to do this manually, and that's OK, but a driver like the atmel-isc doesn't need that at all.
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Quoted 158 lines · Laurent Pinchart
Quoted 157 lines · Hans Verkuil
Quoted 155 lines · Laurent Pinchart
Quoted 139 lines · Hans Verkuil
Quoted 121 lines · Laurent Pinchart
Quoted 114 lines · Jacopo Mondi
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.Yes indeed, seems I suggested to use
media_pipeline_handlerin a comment on your v3"at
s_streamtime your top driver callsmedia_pipeline_start()"sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see
media_pipeline_startbeing called at all in v3 of the patchQuoted 6 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.Quoted 5 lines
Quoted 2 lines
I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Are you suggesting to have vb2 to call
media_pipeline_start()or is it more complex than this ?Quoted 8 lines
I think Hans meant adding a .validate() operation to vb2.
vb2 is already quite complex, I don't think adding more features is a good idea. I'd rather have vb2 focus on buffer management only (.start_streaming() and .stop_streaming() shouldn't have been in there in my opinion), and handle validation in the .streamon() handler. I'd expect most drivers that deal with media pipelines to do more work in .streamon() anyway.
I disagree with that :-)
It's vb2 that keeps track of the streaming state and when what actions need to be taken. Drivers really shouldn't need to care about the ioctls themselves, and just implement the relevant vb2 callbacks. Relying on drivers to handle any of the streaming ioctls is asking for problems, as this shows: most drivers implement this wrong today.
Quoted 4 lines
The vb2 framework knows when e.g. the pipeline needs to be started or stopped, and can do this at the best time, without drivers needing to keep track of when streamon/off/release is called. Keep that logic in vb2.
Pipeline management and buffer management are two different issues. Don't forget about devices that have multiple video nodes, part of the same pipeline (possibly a combination of output and capture nodes, or all of the same type). Forcing drivers to go through vb2 operations to handle the pipeline will be messy, will result in more bloat in vb2, and make the result more bug-prone and harder to maintain.
If pipeline management is too complex, let's simplify it, new helpers can make sense, but not through vb2.
Quoted 7 lines
Quoted 1 line
But it is vb2 that knows when streaming starts and stops.
That's right, but pipeline start (which includes validation and resource reservation) needs to be performed synchronously with
VIDIOC_STREAMON. The streaming state managed by vb2 is not relevant,media_pipeline_start()must not be delayed the same way .start_streaming() is.
It will be the first thing that vb2_streamon calls. This has nothing to do with start_streaming: that's called when sufficient number of buffers are queued up to be able to start the DMA. This proposed prepare_streaming op will be called when VIDIOC_STREAMON is called.
Quoted 49 lines
Quoted 16 lines
The driver just
needs to be informed (e.g.prepare_streamingandunprepare_streamingops).vb2 deals with buffer management and it keeps track of the streaming state and makes the streaming state transitions. That *is* an integral part of vb2. What is missing at the moment are callbacks done at streamon time and when the streaming stops (streamoff, or
close()whenis_streamingis true).If you want to implement stream validation in a driver, then there are a lot of things you need to do:
- override streamon, make sure you call
vb2_queue_is_busy(), validate the pipeline, then callvb2_streamon, if that fails, remember to stop the pipeline.Quoted 6 lines
- override streamoff, make sure you call
vb2_queue_is_busy(), stop the pipeline and callvb2_streamoff.- in the
release()function when the fh is closed, you have to checkvb2_is_streaming(), check that you are the owner of the queue, and if true, stop the pipeline.I'm not opposed to helper functions to implement that, they can bundle vb2 calls and pipeline management.
Quoted 17 lines
By moving this to vb2 ops all you need to implement are the prepare and unprepare ops.
Esp. the
release()implementation is tricky. I'm pretty sure thatdrivers/media/platform/samsung/exynos4-is/fimc-lite.cis wrong, since it should only callmedia_pipeline_stop()for the owner of the queue. Instead it calls it for the last user of the queue.I see that
fimc_lite_streamoff()is wrong too: you can safely callVIDIOC_STREAMOFFtwice: the second streamoff just returns 0 without doing anything. Insteadmedia_pipeline_stopis called without testing if the queue is streaming.And yes, this is in part because V4L2 has quite some history and certainly API choice were made in the past that we wouldn't make today. But vb2 shields you from that, and behaves much more like a proper state machine.
Quoted 5 lines
I know you prefer to give a lot more control to driver developers, but in my experience very few developers can do things like this right. And it is really hard as a reviewer to check if all the corner cases are handled correctly in a driver. If vb2 is used, then I know things are called at the right time, and that makes my life as reviewer so much easier.
Quoted 8 lines
It's not just about giving more control to drivers, it's about organizing the software layers in a way that keeps them maintainable, with layered abstractions and not midlayers.
We are extensively reworking the media pipeline management as part of the stream series, and there will be more work on top of that that will make even more fundamental changes. I would like to at least postpone any work on vb2 until then, to be able to evaluate the impact.
I'll make an RFC patch for vb2 so you have a better idea of what it does.
Regards,
Hans
Quoted 4 lines
Quoted 3 lines
There may still be a few drivers that really need to do this manually, and that's OK, but a driver like the atmel-isc doesn't need that at all.
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Quoted 166 lines · Hans Verkuil
Quoted 157 lines · Laurent Pinchart
Quoted 156 lines · Hans Verkuil
Quoted 154 lines · Laurent Pinchart
Quoted 139 lines · Hans Verkuil
Quoted 121 lines · Laurent Pinchart
Quoted 114 lines · Jacopo Mondi
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.Yes indeed, seems I suggested to use
media_pipeline_handlerin a comment on your v3"at
s_streamtime your top driver callsmedia_pipeline_start()"sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see
media_pipeline_startbeing called at all in v3 of the patchQuoted 6 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.Quoted 5 lines
Quoted 2 lines
I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Are you suggesting to have vb2 to call
media_pipeline_start()or is it more complex than this ?Quoted 8 lines
I think Hans meant adding a .validate() operation to vb2.
vb2 is already quite complex, I don't think adding more features is a good idea. I'd rather have vb2 focus on buffer management only (.start_streaming() and .stop_streaming() shouldn't have been in there in my opinion), and handle validation in the .streamon() handler. I'd expect most drivers that deal with media pipelines to do more work in .streamon() anyway.
I disagree with that :-)
It's vb2 that keeps track of the streaming state and when what actions need to be taken. Drivers really shouldn't need to care about the ioctls themselves, and just implement the relevant vb2 callbacks. Relying on drivers to handle any of the streaming ioctls is asking for problems, as this shows: most drivers implement this wrong today.
Quoted 4 lines
The vb2 framework knows when e.g. the pipeline needs to be started or stopped, and can do this at the best time, without drivers needing to keep track of when streamon/off/release is called. Keep that logic in vb2.
Pipeline management and buffer management are two different issues. Don't forget about devices that have multiple video nodes, part of the same pipeline (possibly a combination of output and capture nodes, or all of the same type). Forcing drivers to go through vb2 operations to handle the pipeline will be messy, will result in more bloat in vb2, and make the result more bug-prone and harder to maintain.
If pipeline management is too complex, let's simplify it, new helpers can make sense, but not through vb2.
Quoted 7 lines
Quoted 1 line
But it is vb2 that knows when streaming starts and stops.
That's right, but pipeline start (which includes validation and resource reservation) needs to be performed synchronously with
VIDIOC_STREAMON. The streaming state managed by vb2 is not relevant,media_pipeline_start()must not be delayed the same way .start_streaming() is.
Quoted 4 lines
It will be the first thing that
vb2_streamoncalls. This has nothing to do withstart_streaming: that's called when sufficient number of buffers are queued up to be able to start the DMA. This proposedprepare_streamingop will be called whenVIDIOC_STREAMONis called.
Then it doesn't need vb2's knowledge of the stream state :-)
Quoted 52 lines
Quoted 52 lines
Quoted 15 lines
The driver just
needs to be informed (e.g.prepare_streamingandunprepare_streamingops).vb2 deals with buffer management and it keeps track of the streaming state and makes the streaming state transitions. That *is* an integral part of vb2. What is missing at the moment are callbacks done at streamon time and when the streaming stops (streamoff, or
close()whenis_streamingis true).If you want to implement stream validation in a driver, then there are a lot of things you need to do:
- override streamon, make sure you call
vb2_queue_is_busy(), validate the pipeline, then callvb2_streamon, if that fails, remember to stop the pipeline.Quoted 6 lines
- override streamoff, make sure you call
vb2_queue_is_busy(), stop the pipeline and callvb2_streamoff.- in the
release()function when the fh is closed, you have to checkvb2_is_streaming(), check that you are the owner of the queue, and if true, stop the pipeline.I'm not opposed to helper functions to implement that, they can bundle vb2 calls and pipeline management.
Quoted 17 lines
By moving this to vb2 ops all you need to implement are the prepare and unprepare ops.
Esp. the
release()implementation is tricky. I'm pretty sure thatdrivers/media/platform/samsung/exynos4-is/fimc-lite.cis wrong, since it should only callmedia_pipeline_stop()for the owner of the queue. Instead it calls it for the last user of the queue.I see that
fimc_lite_streamoff()is wrong too: you can safely callVIDIOC_STREAMOFFtwice: the second streamoff just returns 0 without doing anything. Insteadmedia_pipeline_stopis called without testing if the queue is streaming.And yes, this is in part because V4L2 has quite some history and certainly API choice were made in the past that we wouldn't make today. But vb2 shields you from that, and behaves much more like a proper state machine.
Quoted 5 lines
I know you prefer to give a lot more control to driver developers, but in my experience very few developers can do things like this right. And it is really hard as a reviewer to check if all the corner cases are handled correctly in a driver. If vb2 is used, then I know things are called at the right time, and that makes my life as reviewer so much easier.
It's not just about giving more control to drivers, it's about organizing the software layers in a way that keeps them maintainable, with layered abstractions and not midlayers.
Quoted 6 lines
Quoted 4 lines
We are extensively reworking the media pipeline management as part of the stream series, and there will be more work on top of that that will make even more fundamental changes. I would like to at least postpone any work on vb2 until then, to be able to evaluate the impact.
I'll make an RFC patch for vb2 so you have a better idea of what it does.
As long as we don't merge it before I get the chance to send the media pipeline management rework, I'm all for RFCs :-)
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
There may still be a few drivers that really need to do this manually, and that's OK, but a driver like the atmel-isc doesn't need that at all.
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Hi
Quoted 231 lines · Laurent Pinchart
Quoted 166 lines · Hans Verkuil
Quoted 157 lines · Laurent Pinchart
Quoted 156 lines · Hans Verkuil
Quoted 154 lines · Laurent Pinchart
Quoted 139 lines · Hans Verkuil
Quoted 121 lines · Laurent Pinchart
Quoted 114 lines · Jacopo Mondi
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 72 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the subdevice, it should rather check at
start_streaming()time if the subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification atstart_streamingtime, such that the ISC will return an error if the subdevice is not properly configured. To achieve this,media_pipeline_start
is called and alink_validatecallback is created to check the formats. With this being done, the module parameter 'sensor_preferred' makes no sense anymore. The ISC should not decide which format the sensor is using. The ISC should only cope with the situation and inform userspace if the streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the enumfmt callback. If enumfmt is called with anmbus_code, the enumfmt handler should only return the formats that are supported for thismbus_code. Otherwise, the enumfmt will report all the formats that the ISC could output. With this rework, the dynamic list of user formats is removed. It makes no more sense to identify at complete time which formats the sensor could emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at link validate time, decide whether it can use the format that is configured on the sink or not.Signed-off-by Eugen Hristev <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>---
Changes in v9:
-isc_link_validatenow staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by JacopoChanges in v6:
- reworked a bitenum_fmtas suggested by JacopoChanges in v5:
- removeduser_formatsdynamic list as it is now pointless
- greatly simplified theenum_fmtfunction
- removed some init code that was useless nowChanges in v4:
- moved validation code intolink_validateand usedmedia_pipeline_start
- merged this patch with theenum_fmtpatch which was previously in v3 of the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is founddrivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++---------- .../media/platform/atmel/atmel-isc-scaler.c | 5 + drivers/media/platform/atmel/atmel-isc.h | 13 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 20 + .../media/platform/atmel/atmel-sama7g5-isc.c | 20 + 5 files changed, 236 insertions(+), 234 deletions(-)drivers/media/platform/atmel/atmel-isc-base.c +0
-5@@ -36,11 +36,6 @@ static unsigned int debug;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"debug level (0-2)" ); -static unsigned int sensor_preferred =1 ; -module_param (sensor_preferred, uint,0644 ); -MODULE_PARM_DESC (sensor_preferred, -"Sensor is preferred to output the specified format (1-on 0-off), default 1" ); -#define ISC_IS_FORMAT_RAW (mbus_code) \ (((mbus_code) & 0xf000) == 0x3000)drivers/media/platform/atmel/atmel-isc-base.c static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) · line 335
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc-base.c +1
-0@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)unsigned long flags;int ret; + ret =media_pipeline_start (&isc->video_dev.entity, &isc->mpipe);The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.Yes indeed, seems I suggested to use
media_pipeline_handlerin a comment on your v3"at
s_streamtime your top driver callsmedia_pipeline_start()"sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see
media_pipeline_startbeing called at all in v3 of the patchQuoted 6 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.Quoted 5 lines
Quoted 2 lines
I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Are you suggesting to have vb2 to call
media_pipeline_start()or is it more complex than this ?Quoted 8 lines
I think Hans meant adding a .validate() operation to vb2.
vb2 is already quite complex, I don't think adding more features is a good idea. I'd rather have vb2 focus on buffer management only (.start_streaming() and .stop_streaming() shouldn't have been in there in my opinion), and handle validation in the .streamon() handler. I'd expect most drivers that deal with media pipelines to do more work in .streamon() anyway.
I disagree with that :-)
It's vb2 that keeps track of the streaming state and when what actions need to be taken. Drivers really shouldn't need to care about the ioctls themselves, and just implement the relevant vb2 callbacks. Relying on drivers to handle any of the streaming ioctls is asking for problems, as this shows: most drivers implement this wrong today.
Quoted 4 lines
The vb2 framework knows when e.g. the pipeline needs to be started or stopped, and can do this at the best time, without drivers needing to keep track of when streamon/off/release is called. Keep that logic in vb2.
Pipeline management and buffer management are two different issues. Don't forget about devices that have multiple video nodes, part of the same pipeline (possibly a combination of output and capture nodes, or all of the same type). Forcing drivers to go through vb2 operations to handle the pipeline will be messy, will result in more bloat in vb2, and make the result more bug-prone and harder to maintain.
If pipeline management is too complex, let's simplify it, new helpers can make sense, but not through vb2.
Quoted 7 lines
Quoted 1 line
But it is vb2 that knows when streaming starts and stops.
That's right, but pipeline start (which includes validation and resource reservation) needs to be performed synchronously with
VIDIOC_STREAMON. The streaming state managed by vb2 is not relevant,media_pipeline_start()must not be delayed the same way .start_streaming() is.Quoted 4 lines
It will be the first thing that
vb2_streamoncalls. This has nothing to do withstart_streaming: that's called when sufficient number of buffers are queued up to be able to start the DMA. This proposedprepare_streamingop will be called whenVIDIOC_STREAMONis called.Then it doesn't need vb2's knowledge of the stream state :-)
Quoted 57 lines
Quoted 56 lines
Quoted 15 lines
The driver just
needs to be informed (e.g.prepare_streamingandunprepare_streamingops).vb2 deals with buffer management and it keeps track of the streaming state and makes the streaming state transitions. That *is* an integral part of vb2. What is missing at the moment are callbacks done at streamon time and when the streaming stops (streamoff, or
close()whenis_streamingis true).If you want to implement stream validation in a driver, then there are a lot of things you need to do:
- override streamon, make sure you call
vb2_queue_is_busy(), validate the pipeline, then callvb2_streamon, if that fails, remember to stop the pipeline.Quoted 6 lines
- override streamoff, make sure you call
vb2_queue_is_busy(), stop the pipeline and callvb2_streamoff.- in the
release()function when the fh is closed, you have to checkvb2_is_streaming(), check that you are the owner of the queue, and if true, stop the pipeline.I'm not opposed to helper functions to implement that, they can bundle vb2 calls and pipeline management.
Quoted 17 lines
By moving this to vb2 ops all you need to implement are the prepare and unprepare ops.
Esp. the
release()implementation is tricky. I'm pretty sure thatdrivers/media/platform/samsung/exynos4-is/fimc-lite.cis wrong, since it should only callmedia_pipeline_stop()for the owner of the queue. Instead it calls it for the last user of the queue.I see that
fimc_lite_streamoff()is wrong too: you can safely callVIDIOC_STREAMOFFtwice: the second streamoff just returns 0 without doing anything. Insteadmedia_pipeline_stopis called without testing if the queue is streaming.And yes, this is in part because V4L2 has quite some history and certainly API choice were made in the past that we wouldn't make today. But vb2 shields you from that, and behaves much more like a proper state machine.
Quoted 5 lines
I know you prefer to give a lot more control to driver developers, but in my experience very few developers can do things like this right. And it is really hard as a reviewer to check if all the corner cases are handled correctly in a driver. If vb2 is used, then I know things are called at the right time, and that makes my life as reviewer so much easier.
It's not just about giving more control to drivers, it's about organizing the software layers in a way that keeps them maintainable, with layered abstractions and not midlayers.
We are extensively reworking the media pipeline management as part of the stream series, and there will be more work on top of that that will make even more fundamental changes. I would like to at least postpone any work on vb2 until then, to be able to evaluate the impact.
Quoted 5 lines
Quoted 1 line
I'll make an RFC patch for vb2 so you have a better idea of what it does.
As long as we don't merge it before I get the chance to send the media pipeline management rework, I'm all for RFCs :-)
To unblock Eugen is it fine if he moves media_pipeline_start() at streamon() time for now ? It will require overriding v4l2_ioctl.vidioc_streamon which might be a bit of additional work (but probably easier to replace once a proper solution lands)
Otherwise, should the series go in as it is now ?
Thanks
j
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
There may still be a few drivers that really need to do this manually, and that's OK, but a driver like the atmel-isc doesn't need that at all.
--
Regards,Laurent Pinchart
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Quoted 234 lines · Jacopo Mondi
Quoted 233 lines · Laurent Pinchart
Quoted 166 lines · Hans Verkuil
Quoted 157 lines · Laurent Pinchart
Quoted 156 lines · Hans Verkuil
Quoted 154 lines · Laurent Pinchart
Quoted 139 lines · Hans Verkuil
Quoted 121 lines · Laurent Pinchart
Quoted 114 lines · Jacopo Mondi
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 76 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the
subdevice, it should rather check at start_streaming() time if the subdev is properly
configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification
at start_streaming time, such that the ISC will return an error if the subdevice
is not properly configured. To achieve this, media_pipeline_start
is called and a link_validate callback is created to check the formats.
With this being done, the module parameter 'sensor_preferred' makes no sense
anymore. The ISC should not decide which format the sensor is using. The
ISC should only cope with the situation and inform userspace if the streaming
is possible in the current configuration.
The redesign of the format propagation has also risen the question of the
enumfmt callback. If enumfmt is called with an mbus_code, the enumfmt handler
should only return the formats that are supported for this mbus_code.
Otherwise, the enumfmt will report all the formats that the ISC could output.
With this rework, the dynamic list of user formats is removed. It makes no
more sense to identify at complete time which formats the sensor could emit,
and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at
link validate time, decide whether it can use the format that is configured
on the sink or not.Signed-off-by: Eugen Hristev <[email protected]>
Reviewed-by: Jacopo Mondi <[email protected]>
---
Changes in v9:
- isc_link_validate now staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by
JacopoChanges in v6:
- reworked a bit enum_fmt as suggested by JacopoChanges in v5:
- removed user_formats dynamic list as it is now pointless
- greatly simplified the enum_fmt function
- removed some init code that was useless nowChanges in v4:
- moved validation code into link_validate and used media_pipeline_start
- merged this patch with the enum_fmt patch which was previously in v3 of
the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is found
drivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++----------
.../media/platform/atmel/atmel-isc-scaler.c | 5 +
drivers/media/platform/atmel/atmel-isc.h | 13 +-
.../media/platform/atmel/atmel-sama5d2-isc.c | 20 +
.../media/platform/atmel/atmel-sama7g5-isc.c | 20 +
5 files changed, 236 insertions(+), 234 deletions(-)diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
index ee1dda6707a0..fe2c0af58060 100644
--- a/drivers/media/platform/atmel/atmel-isc-base.c
+++ b/drivers/media/platform/atmel/atmel-isc-base.c
@@ -36,11 +36,6 @@ static unsigned int debug;
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "debug level (0-2)");-static unsigned int sensor_preferred = 1;
-module_param(sensor_preferred, uint, 0644);
-MODULE_PARM_DESC(sensor_preferred,
- "Sensor is preferred to output the specified format (1-on 0-off), default 1");
-
#define ISC_IS_FORMAT_RAW(mbus_code) \
(((mbus_code) & 0xf000) == 0x3000)@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
unsigned long flags;
int ret;+ ret = media_pipeline_start(&isc->video_dev.entity, &isc->mpipe);
The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.Yes indeed, seems I suggested to use
media_pipeline_handlerin a comment on your v3"at
s_streamtime your top driver callsmedia_pipeline_start()"sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see
media_pipeline_startbeing called at all in v3 of the patchQuoted 6 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.Quoted 5 lines
Quoted 2 lines
I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Are you suggesting to have vb2 to call
media_pipeline_start()or is it more complex than this ?Quoted 8 lines
I think Hans meant adding a .validate() operation to vb2.
vb2 is already quite complex, I don't think adding more features is a good idea. I'd rather have vb2 focus on buffer management only (.start_streaming() and .stop_streaming() shouldn't have been in there in my opinion), and handle validation in the .streamon() handler. I'd expect most drivers that deal with media pipelines to do more work in .streamon() anyway.
I disagree with that :-)
It's vb2 that keeps track of the streaming state and when what actions need to be taken. Drivers really shouldn't need to care about the ioctls themselves, and just implement the relevant vb2 callbacks. Relying on drivers to handle any of the streaming ioctls is asking for problems, as this shows: most drivers implement this wrong today.
Quoted 4 lines
The vb2 framework knows when e.g. the pipeline needs to be started or stopped, and can do this at the best time, without drivers needing to keep track of when streamon/off/release is called. Keep that logic in vb2.
Pipeline management and buffer management are two different issues. Don't forget about devices that have multiple video nodes, part of the same pipeline (possibly a combination of output and capture nodes, or all of the same type). Forcing drivers to go through vb2 operations to handle the pipeline will be messy, will result in more bloat in vb2, and make the result more bug-prone and harder to maintain.
If pipeline management is too complex, let's simplify it, new helpers can make sense, but not through vb2.
Quoted 7 lines
Quoted 1 line
But it is vb2 that knows when streaming starts and stops.
That's right, but pipeline start (which includes validation and resource reservation) needs to be performed synchronously with
VIDIOC_STREAMON. The streaming state managed by vb2 is not relevant,media_pipeline_start()must not be delayed the same way .start_streaming() is.Quoted 4 lines
It will be the first thing that
vb2_streamoncalls. This has nothing to do withstart_streaming: that's called when sufficient number of buffers are queued up to be able to start the DMA. This proposedprepare_streamingop will be called whenVIDIOC_STREAMONis called.Then it doesn't need vb2's knowledge of the stream state :-)
Quoted 58 lines
Quoted 48 lines
Quoted 15 lines
The driver just
needs to be informed (e.g.prepare_streamingandunprepare_streamingops).vb2 deals with buffer management and it keeps track of the streaming state and makes the streaming state transitions. That *is* an integral part of vb2. What is missing at the moment are callbacks done at streamon time and when the streaming stops (streamoff, or
close()whenis_streamingis true).If you want to implement stream validation in a driver, then there are a lot of things you need to do:
- override streamon, make sure you call
vb2_queue_is_busy(), validate the pipeline, then callvb2_streamon, if that fails, remember to stop the pipeline.Quoted 6 lines
- override streamoff, make sure you call
vb2_queue_is_busy(), stop the pipeline and callvb2_streamoff.- in the
release()function when the fh is closed, you have to checkvb2_is_streaming(), check that you are the owner of the queue, and if true, stop the pipeline.I'm not opposed to helper functions to implement that, they can bundle vb2 calls and pipeline management.
Quoted 17 lines
By moving this to vb2 ops all you need to implement are the prepare and unprepare ops.
Esp. the
release()implementation is tricky. I'm pretty sure thatdrivers/media/platform/samsung/exynos4-is/fimc-lite.cis wrong, since it should only callmedia_pipeline_stop()for the owner of the queue. Instead it calls it for the last user of the queue.I see that
fimc_lite_streamoff()is wrong too: you can safely callVIDIOC_STREAMOFFtwice: the second streamoff just returns 0 without doing anything. Insteadmedia_pipeline_stopis called without testing if the queue is streaming.And yes, this is in part because V4L2 has quite some history and certainly API choice were made in the past that we wouldn't make today. But vb2 shields you from that, and behaves much more like a proper state machine.
Quoted 5 lines
I know you prefer to give a lot more control to driver developers, but in my experience very few developers can do things like this right. And it is really hard as a reviewer to check if all the corner cases are handled correctly in a driver. If vb2 is used, then I know things are called at the right time, and that makes my life as reviewer so much easier.
Quoted 8 lines
It's not just about giving more control to drivers, it's about organizing the software layers in a way that keeps them maintainable, with layered abstractions and not midlayers.
We are extensively reworking the media pipeline management as part of the stream series, and there will be more work on top of that that will make even more fundamental changes. I would like to at least postpone any work on vb2 until then, to be able to evaluate the impact.
I'll make an RFC patch for vb2 so you have a better idea of what it does.
Quoted 8 lines
Quoted 3 lines
As long as we don't merge it before I get the chance to send the media pipeline management rework, I'm all for RFCs :-)
To unblock Eugen is it fine if he moves
media_pipeline_start()atstreamon()time for now ? It will require overriding v4l2_ioctl.vidioc_streamon which might be a bit of additional work (but probably easier to replace once a proper solution lands)
Fine with me.
Quoted 4 lines
Otherwise, should the series go in as it is now ?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
There may still be a few drivers that really need to do this manually, and that's OK, but a driver like the atmel-isc doesn't need that at all.
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
In reply to Jacopo MondiQuoted 240 lines · Jacopo Mondi
Hi
Quoted 231 lines · Laurent Pinchart
Quoted 166 lines · Hans Verkuil
Quoted 157 lines · Laurent Pinchart
Quoted 156 lines · Hans Verkuil
Quoted 154 lines · Laurent Pinchart
Quoted 139 lines · Hans Verkuil
Quoted 121 lines · Laurent Pinchart
Quoted 114 lines · Jacopo Mondi
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
Quoted 76 lines · Eugen Hristev
As a top MC video driver, the atmel-isc should not propagate the format to the
subdevice, it should rather check at start_streaming() time if the subdev is properly
configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification
at start_streaming time, such that the ISC will return an error if the subdevice
is not properly configured. To achieve this, media_pipeline_start
is called and a link_validate callback is created to check the formats.
With this being done, the module parameter 'sensor_preferred' makes no sense
anymore. The ISC should not decide which format the sensor is using. The
ISC should only cope with the situation and inform userspace if the streaming
is possible in the current configuration.
The redesign of the format propagation has also risen the question of the
enumfmt callback. If enumfmt is called with an mbus_code, the enumfmt handler
should only return the formats that are supported for this mbus_code.
Otherwise, the enumfmt will report all the formats that the ISC could output.
With this rework, the dynamic list of user formats is removed. It makes no
more sense to identify at complete time which formats the sensor could emit,
and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at
link validate time, decide whether it can use the format that is configured
on the sink or not.Signed-off-by: Eugen Hristev <[email protected]>
Reviewed-by: Jacopo Mondi <[email protected]>
---
Changes in v9:
- isc_link_validate now staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by
JacopoChanges in v6:
- reworked a bit enum_fmt as suggested by JacopoChanges in v5:
- removed user_formats dynamic list as it is now pointless
- greatly simplified the enum_fmt function
- removed some init code that was useless nowChanges in v4:
- moved validation code into link_validate and used media_pipeline_start
- merged this patch with the enum_fmt patch which was previously in v3 of
the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is found
drivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++----------
.../media/platform/atmel/atmel-isc-scaler.c | 5 +
drivers/media/platform/atmel/atmel-isc.h | 13 +-
.../media/platform/atmel/atmel-sama5d2-isc.c | 20 +
.../media/platform/atmel/atmel-sama7g5-isc.c | 20 +
5 files changed, 236 insertions(+), 234 deletions(-)diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
index ee1dda6707a0..fe2c0af58060 100644
--- a/drivers/media/platform/atmel/atmel-isc-base.c
+++ b/drivers/media/platform/atmel/atmel-isc-base.c
@@ -36,11 +36,6 @@ static unsigned int debug;
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "debug level (0-2)");-static unsigned int sensor_preferred = 1;
-module_param(sensor_preferred, uint, 0644);
-MODULE_PARM_DESC(sensor_preferred,
- "Sensor is preferred to output the specified format (1-on 0-off), default 1");
-
#define ISC_IS_FORMAT_RAW(mbus_code) \
(((mbus_code) & 0xf000) == 0x3000)@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
unsigned long flags;
int ret;+ ret = media_pipeline_start(&isc->video_dev.entity, &isc->mpipe);
The pipeline validation is done in
start_streaming, but I don't think that is the best place: if STREAMON is called before buffers are queued, then an invalid pipeline isn't discovered until enough buffers are queued to kick offstart_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in
streamon().Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.Yes indeed, seems I suggested to use
media_pipeline_handlerin a comment on your v3"at
s_streamtime your top driver callsmedia_pipeline_start()"sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see
media_pipeline_startbeing called at all in v3 of the patchQuoted 6 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.Quoted 5 lines
Quoted 2 lines
I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Are you suggesting to have vb2 to call
media_pipeline_start()or is it more complex than this ?Quoted 8 lines
I think Hans meant adding a .validate() operation to vb2.
vb2 is already quite complex, I don't think adding more features is a good idea. I'd rather have vb2 focus on buffer management only (.start_streaming() and .stop_streaming() shouldn't have been in there in my opinion), and handle validation in the .streamon() handler. I'd expect most drivers that deal with media pipelines to do more work in .streamon() anyway.
I disagree with that :-)
It's vb2 that keeps track of the streaming state and when what actions need to be taken. Drivers really shouldn't need to care about the ioctls themselves, and just implement the relevant vb2 callbacks. Relying on drivers to handle any of the streaming ioctls is asking for problems, as this shows: most drivers implement this wrong today.
Quoted 4 lines
The vb2 framework knows when e.g. the pipeline needs to be started or stopped, and can do this at the best time, without drivers needing to keep track of when streamon/off/release is called. Keep that logic in vb2.
Pipeline management and buffer management are two different issues. Don't forget about devices that have multiple video nodes, part of the same pipeline (possibly a combination of output and capture nodes, or all of the same type). Forcing drivers to go through vb2 operations to handle the pipeline will be messy, will result in more bloat in vb2, and make the result more bug-prone and harder to maintain.
If pipeline management is too complex, let's simplify it, new helpers can make sense, but not through vb2.
Quoted 7 lines
Quoted 1 line
But it is vb2 that knows when streaming starts and stops.
That's right, but pipeline start (which includes validation and resource reservation) needs to be performed synchronously with
VIDIOC_STREAMON. The streaming state managed by vb2 is not relevant,media_pipeline_start()must not be delayed the same way .start_streaming() is.Quoted 4 lines
It will be the first thing that
vb2_streamoncalls. This has nothing to do withstart_streaming: that's called when sufficient number of buffers are queued up to be able to start the DMA. This proposedprepare_streamingop will be called whenVIDIOC_STREAMONis called.Then it doesn't need vb2's knowledge of the stream state :-)
Quoted 57 lines
Quoted 56 lines
Quoted 15 lines
The driver just
needs to be informed (e.g.prepare_streamingandunprepare_streamingops).vb2 deals with buffer management and it keeps track of the streaming state and makes the streaming state transitions. That *is* an integral part of vb2. What is missing at the moment are callbacks done at streamon time and when the streaming stops (streamoff, or
close()whenis_streamingis true).If you want to implement stream validation in a driver, then there are a lot of things you need to do:
- override streamon, make sure you call
vb2_queue_is_busy(), validate the pipeline, then callvb2_streamon, if that fails, remember to stop the pipeline.Quoted 6 lines
- override streamoff, make sure you call
vb2_queue_is_busy(), stop the pipeline and callvb2_streamoff.- in the
release()function when the fh is closed, you have to checkvb2_is_streaming(), check that you are the owner of the queue, and if true, stop the pipeline.I'm not opposed to helper functions to implement that, they can bundle vb2 calls and pipeline management.
Quoted 17 lines
By moving this to vb2 ops all you need to implement are the prepare and unprepare ops.
Esp. the
release()implementation is tricky. I'm pretty sure thatdrivers/media/platform/samsung/exynos4-is/fimc-lite.cis wrong, since it should only callmedia_pipeline_stop()for the owner of the queue. Instead it calls it for the last user of the queue.I see that
fimc_lite_streamoff()is wrong too: you can safely callVIDIOC_STREAMOFFtwice: the second streamoff just returns 0 without doing anything. Insteadmedia_pipeline_stopis called without testing if the queue is streaming.And yes, this is in part because V4L2 has quite some history and certainly API choice were made in the past that we wouldn't make today. But vb2 shields you from that, and behaves much more like a proper state machine.
Quoted 5 lines
I know you prefer to give a lot more control to driver developers, but in my experience very few developers can do things like this right. And it is really hard as a reviewer to check if all the corner cases are handled correctly in a driver. If vb2 is used, then I know things are called at the right time, and that makes my life as reviewer so much easier.
It's not just about giving more control to drivers, it's about organizing the software layers in a way that keeps them maintainable, with layered abstractions and not midlayers.
We are extensively reworking the media pipeline management as part of the stream series, and there will be more work on top of that that will make even more fundamental changes. I would like to at least postpone any work on vb2 until then, to be able to evaluate the impact.
Quoted 5 lines
Quoted 1 line
I'll make an RFC patch for vb2 so you have a better idea of what it does.
As long as we don't merge it before I get the chance to send the media pipeline management rework, I'm all for RFCs :-)
Quoted 6 lines
To unblock Eugen is it fine if he moves
media_pipeline_start()atstreamon()time for now ? It will require overriding v4l2_ioctl.vidioc_streamon which might be a bit of additional work (but probably easier to replace once a proper solution lands)Otherwise, should the series go in as it is now ?
I had a comment about patch 6, so I want a new series anyway. All the patches with just fixes (everything but 4 and 8) can go in once I have them.
I think - all things considered - it is currently best to start and stop the pipeline in start/stop_streaming: that at least avoids all the complications with streamon/off/close() that is really hard to get right without (IMHO) my proposed vb2 changes.
With that I will accept the series.
Regards,
Hans
Quoted 11 lines
Thanks
jQuoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
There may still be a few drivers that really need to do this manually, and that's OK, but a driver like the atmel-isc doesn't need that at all.
--
Regards,Laurent Pinchart
Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Quoted 252 lines · Hans Verkuil
Quoted 240 lines · Jacopo Mondi
Hi
Quoted 231 lines · Laurent Pinchart
Quoted 166 lines · Hans Verkuil
Quoted 157 lines · Laurent Pinchart
Quoted 156 lines · Hans Verkuil
Quoted 154 lines · Laurent Pinchart
Quoted 139 lines · Hans Verkuil
Quoted 121 lines · Laurent Pinchart
Quoted 114 lines · Jacopo Mondi
Quoted 87 lines · Hans Verkuil
Quoted 86 lines · On 29/04/2022 10:28, [email protected] wrote:
Quoted 85 lines · Hans Verkuil
On 10/03/2022 10:51, Eugen Hristev wrote:
As a top MC video driver, the atmel-isc should not propagate the format to the
subdevice, it should rather check at start_streaming() time if the subdev is properly
configured with a compatible format.
Removed the whole format finding logic, and reworked the format verification
at start_streaming time, such that the ISC will return an error if the subdevice
is not properly configured. To achieve this, media_pipeline_start
is called and a link_validate callback is created to check the formats.
With this being done, the module parameter 'sensor_preferred' makes no sense
anymore. The ISC should not decide which format the sensor is using. The
ISC should only cope with the situation and inform userspace if the streaming
is possible in the current configuration.
The redesign of the format propagation has also risen the question of the
enumfmt callback. If enumfmt is called with an mbus_code, the enumfmt handler
should only return the formats that are supported for this mbus_code.
Otherwise, the enumfmt will report all the formats that the ISC could output.
With this rework, the dynamic list of user formats is removed. It makes no
more sense to identify at complete time which formats the sensor could emit,
and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at
link validate time, decide whether it can use the format that is configured
on the sink or not.Signed-off-by: Eugen Hristev <[email protected]>
Reviewed-by: Jacopo Mondi <[email protected]>
---
Changes in v9:
- isc_link_validate now staticChanges in v7:
- minor typos as suggested by Jacopo
- small changes, reduce some indentation, modified an index, as suggested by
JacopoChanges in v6:
- reworked a bit enum_fmt as suggested by JacopoChanges in v5:
- removed user_formats dynamic list as it is now pointless
- greatly simplified the enum_fmt function
- removed some init code that was useless nowChanges in v4:
- moved validation code into link_validate and used media_pipeline_start
- merged this patch with the enum_fmt patch which was previously in v3 of
the seriesChanges in v3:
- clamp to maximum resolution once the frame size from the subdev is found
drivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++----------
.../media/platform/atmel/atmel-isc-scaler.c | 5 +
drivers/media/platform/atmel/atmel-isc.h | 13 +-
.../media/platform/atmel/atmel-sama5d2-isc.c | 20 +
.../media/platform/atmel/atmel-sama7g5-isc.c | 20 +
5 files changed, 236 insertions(+), 234 deletions(-)diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
index ee1dda6707a0..fe2c0af58060 100644
--- a/drivers/media/platform/atmel/atmel-isc-base.c
+++ b/drivers/media/platform/atmel/atmel-isc-base.c
@@ -36,11 +36,6 @@ static unsigned int debug;
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "debug level (0-2)");-static unsigned int sensor_preferred = 1;
-module_param(sensor_preferred, uint, 0644);
-MODULE_PARM_DESC(sensor_preferred,
- "Sensor is preferred to output the specified format (1-on 0-off), default 1");
-
#define ISC_IS_FORMAT_RAW(mbus_code) \
(((mbus_code) & 0xf000) == 0x3000)@@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
unsigned long flags;
int ret;+ ret = media_pipeline_start(&isc->video_dev.entity, &isc->mpipe);
The pipeline validation is done in start_streaming, but I don't think that
is the best place: if STREAMON is called before buffers are queued, then
an invalid pipeline isn't discovered until enough buffers are queued to
kick off start_streaming.Drivers like vsp1, omap3isp and the samsung drivers all do this in streamon().
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I think that is the correct time to do this.
Hello Hans,
Initially (v2, v3) I had this in
streamon(). The problem that I faced at that time was that streamoff was never called, so I could not callmedia_pipeline_stop(). Then Jacopo told me to move it tostart_streaming(see change log for v4) , and I did not face any more problems.Yes indeed, seems I suggested to use
media_pipeline_handlerin a comment on your v3"at
s_streamtime your top driver callsmedia_pipeline_start()"sorry about that, I should have looked around a bit more carefully and notice most drivers do so at vb2 streamon
However I don't see
media_pipeline_startbeing called at all in v3 of the patchQuoted 6 lines
It's a mess. Looking at some drivers I see that omap3isp calls
media_pipeline_stopin streamoff (so will have the same problem as you described ifVIDIOC_STREAMOFFisn't called), exynos4-is does the same, but it also checks the streaming state in therelease()fop callback, so that would fix this problem. And vimc does this instop_streaming.Quoted 5 lines
Quoted 2 lines
I'm in favor of fixing this in vb2, that framework knows exactly when this needs to be called.
Are you suggesting to have vb2 to call
media_pipeline_start()or is it more complex than this ?Quoted 8 lines
I think Hans meant adding a .validate() operation to vb2.
vb2 is already quite complex, I don't think adding more features is a good idea. I'd rather have vb2 focus on buffer management only (.start_streaming() and .stop_streaming() shouldn't have been in there in my opinion), and handle validation in the .streamon() handler. I'd expect most drivers that deal with media pipelines to do more work in .streamon() anyway.
I disagree with that :-)
It's vb2 that keeps track of the streaming state and when what actions need to be taken. Drivers really shouldn't need to care about the ioctls themselves, and just implement the relevant vb2 callbacks. Relying on drivers to handle any of the streaming ioctls is asking for problems, as this shows: most drivers implement this wrong today.
Quoted 4 lines
The vb2 framework knows when e.g. the pipeline needs to be started or stopped, and can do this at the best time, without drivers needing to keep track of when streamon/off/release is called. Keep that logic in vb2.
Pipeline management and buffer management are two different issues. Don't forget about devices that have multiple video nodes, part of the same pipeline (possibly a combination of output and capture nodes, or all of the same type). Forcing drivers to go through vb2 operations to handle the pipeline will be messy, will result in more bloat in vb2, and make the result more bug-prone and harder to maintain.
If pipeline management is too complex, let's simplify it, new helpers can make sense, but not through vb2.
Quoted 7 lines
Quoted 1 line
But it is vb2 that knows when streaming starts and stops.
That's right, but pipeline start (which includes validation and resource reservation) needs to be performed synchronously with
VIDIOC_STREAMON. The streaming state managed by vb2 is not relevant,media_pipeline_start()must not be delayed the same way .start_streaming() is.Quoted 4 lines
It will be the first thing that
vb2_streamoncalls. This has nothing to do withstart_streaming: that's called when sufficient number of buffers are queued up to be able to start the DMA. This proposedprepare_streamingop will be called whenVIDIOC_STREAMONis called.Then it doesn't need vb2's knowledge of the stream state :-)
Quoted 57 lines
Quoted 56 lines
Quoted 15 lines
The driver just
needs to be informed (e.g.prepare_streamingandunprepare_streamingops).vb2 deals with buffer management and it keeps track of the streaming state and makes the streaming state transitions. That *is* an integral part of vb2. What is missing at the moment are callbacks done at streamon time and when the streaming stops (streamoff, or
close()whenis_streamingis true).If you want to implement stream validation in a driver, then there are a lot of things you need to do:
- override streamon, make sure you call
vb2_queue_is_busy(), validate the pipeline, then callvb2_streamon, if that fails, remember to stop the pipeline.Quoted 6 lines
- override streamoff, make sure you call
vb2_queue_is_busy(), stop the pipeline and callvb2_streamoff.- in the
release()function when the fh is closed, you have to checkvb2_is_streaming(), check that you are the owner of the queue, and if true, stop the pipeline.I'm not opposed to helper functions to implement that, they can bundle vb2 calls and pipeline management.
Quoted 17 lines
By moving this to vb2 ops all you need to implement are the prepare and unprepare ops.
Esp. the
release()implementation is tricky. I'm pretty sure thatdrivers/media/platform/samsung/exynos4-is/fimc-lite.cis wrong, since it should only callmedia_pipeline_stop()for the owner of the queue. Instead it calls it for the last user of the queue.I see that
fimc_lite_streamoff()is wrong too: you can safely callVIDIOC_STREAMOFFtwice: the second streamoff just returns 0 without doing anything. Insteadmedia_pipeline_stopis called without testing if the queue is streaming.And yes, this is in part because V4L2 has quite some history and certainly API choice were made in the past that we wouldn't make today. But vb2 shields you from that, and behaves much more like a proper state machine.
Quoted 5 lines
I know you prefer to give a lot more control to driver developers, but in my experience very few developers can do things like this right. And it is really hard as a reviewer to check if all the corner cases are handled correctly in a driver. If vb2 is used, then I know things are called at the right time, and that makes my life as reviewer so much easier.
It's not just about giving more control to drivers, it's about organizing the software layers in a way that keeps them maintainable, with layered abstractions and not midlayers.
We are extensively reworking the media pipeline management as part of the stream series, and there will be more work on top of that that will make even more fundamental changes. I would like to at least postpone any work on vb2 until then, to be able to evaluate the impact.
Quoted 5 lines
Quoted 1 line
I'll make an RFC patch for vb2 so you have a better idea of what it does.
As long as we don't merge it before I get the chance to send the media pipeline management rework, I'm all for RFCs :-)
Quoted 6 lines
To unblock Eugen is it fine if he moves
media_pipeline_start()atstreamon()time for now ? It will require overriding v4l2_ioctl.vidioc_streamon which might be a bit of additional work (but probably easier to replace once a proper solution lands)Otherwise, should the series go in as it is now ?
I had a comment about patch 6, so I want a new series anyway. All the patches with just fixes (everything but 4 and 8) can go in once I have them.
Quoted 6 lines
I think - all things considered - it is currently best to start and stop the pipeline in start/stop_streaming: that at least avoids all the complications with streamon/off/close() that is really hard to get right without (IMHO) my proposed vb2 changes.
With that I will accept the series.
Hi,
I will be a few days off, but next week I will address the changes and come up with v10. I have to test it a little to make sure everything is fine.
Thanks !
Eugen
Quoted 17 lines
Regards,
Hans
Quoted 11 lines
Thanks
jQuoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
There may still be a few drivers that really need to do this manually, and that's OK, but a driver like the atmel-isc doesn't need that at all.
--
Regards,Laurent Pinchart
PATCH v9 9/13 media: atmel: atmel-sama7g5-isc: remove stray line
In reply to Eugen HristevRemove stray line from formats struct.
--- drivers/media/platform/atmel/atmel-sama7g5-isc.c | 1 - 1 file changed, 1 deletion(-)
drivers/media/platform/atmel/atmel-sama7g5-isc.c +0 -1
@@ -225,7 +225,6 @@ static struct isc_format sama7g5_formats_list[] = { .mbus_code = MEDIA_BUS_FMT_Y10_1X10, .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, }, - };static void isc_sama7g5_config_csc (struct isc_device *isc)
Signature · 1 line
2.25.1
PATCH v9 10/13 dt-bindings: media: microchip,xisc: add bus-width of 14
In reply to Eugen HristevThe Microchip XISC supports a bus width of 14 bits. Add it to the supported bus widths.
--- Documentation/devicetree/bindings/media/microchip,xisc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/devicetree/bindings/media/microchip,xisc.yaml +1 -1
@@ -67,7 +67,7 @@ properties: remote-endpoint: true bus-width: - enum: [8, 9, 10, 11, 12] + enum: [8, 9, 10, 11, 12, 14] default: 12 hsync-active:
Signature · 1 line
2.25.1
PATCH v9 11/13 ARM: dts: at91: sama7g5: add nodes for video capture
In reply to Eugen HristevAdd node for the XISC (eXtended Image Sensor Controller) and CSI2DC (csi2 demux controller).
These nodes represent the top level of the video capture hardware pipeline and are directly connected in hardware.
--- arch/arm/boot/dts/sama7g5.dtsi | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
arch/arm/boot/dts/sama7g5.dtsi +49 -0
@@ -266,6 +266,55 @@ sdmmc2: mmc@e120c000 { status = "disabled"; }; + csi2dc: csi2dc@e1404000 { + compatible = "microchip,sama7g5-csi2dc"; + reg = <0xe1404000 0x500>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 34>, <&xisc>; + clock-names = "pclk", "scck"; + assigned-clocks = <&xisc>; + assigned-clock-rates = <266000000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + csi2dc_in: endpoint { + }; + }; + + port@1 { + reg = <1>; + csi2dc_out: endpoint { + bus-width = <14>; + hsync-active = <1>; + vsync-active = <1>; + remote-endpoint = <&xisc_in>; + }; + }; + }; + }; + + xisc: xisc@e1408000 { + compatible = "microchip,sama7g5-isc"; + reg = <0xe1408000 0x2000>; + interrupts = <GIC_SPI 56 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 56>; + clock-names = "hclock"; + #clock-cells = <0>; + clock-output-names = "isc-mck"; + + port { + xisc_in: endpoint { + bus-type = <5>; /* Parallel */ + bus-width = <14>; + hsync-active = <1>; + vsync-active = <1>; + remote-endpoint = <&csi2dc_out>; + }; + }; + }; + pwm: pwm@e1604000 { compatible = "microchip,sama7g5-pwm", "atmel,sama5d2-pwm"; reg = <0xe1604000 0x4000>;
Signature · 1 line
2.25.1
PATCH v9 12/13 ARM: configs: at91: sama7: add xisc and csi2dc
In reply to Eugen HristevEnable XISC and CSI2DC drivers.
--- arch/arm/configs/sama7_defconfig | 2 ++ 1 file changed, 2 insertions(+)
arch/arm/configs/sama7_defconfig +2 -0
@@ -127,6 +127,8 @@ CONFIG_MEDIA_SUPPORT_FILTER=y CONFIG_MEDIA_CAMERA_SUPPORT=y CONFIG_MEDIA_PLATFORM_SUPPORT=y CONFIG_V4L_PLATFORM_DRIVERS=y +CONFIG_VIDEO_ATMEL_XISC=y +CONFIG_VIDEO_MICROCHIP_CSI2DC=y CONFIG_VIDEO_IMX219=m CONFIG_VIDEO_IMX274=m CONFIG_VIDEO_OV5647=m
Signature · 1 line
2.25.1
PATCH v9 13/13 ARM: multi_v7_defconfig: add atmel video pipeline modules
In reply to Eugen HristevAdd drivers for the atmel video capture pipeline: atmel isc, xisc and microchip csi2dc.
--- arch/arm/configs/multi_v7_defconfig | 3 +++ 1 file changed, 3 insertions(+)
arch/arm/configs/multi_v7_defconfig +3 -0
@@ -639,7 +639,10 @@ CONFIG_VIDEO_S5P_MIPI_CSIS=m CONFIG_VIDEO_EXYNOS_FIMC_LITE=m CONFIG_VIDEO_EXYNOS4_FIMC_IS=m CONFIG_VIDEO_RCAR_VIN=m +CONFIG_VIDEO_ATMEL_ISC=m +CONFIG_VIDEO_ATMEL_XISC=m CONFIG_VIDEO_ATMEL_ISI=m +CONFIG_VIDEO_MICROCHIP_CSI2DC=m CONFIG_V4L_MEM2MEM_DRIVERS=y CONFIG_VIDEO_SAMSUNG_S5P_JPEG=m CONFIG_VIDEO_SAMSUNG_S5P_MFC=m
Signature · 1 line
2.25.1
Hi Eugen,
Quoted 50 lines · Eugen Hristev
This series is the v9 series that attempts to support media controller in the atmel ISC and XISC drivers.
The CSI2DC driver was accepted thus removed from the patch series, together with other patches.Important note: this series applies on top of current
media_stagingtree, as it relies on previous patches in the series which were accepted.Thanks to everyone who reviewed my work !
Eugen
Changes in v9:
-> kernel robot reportedisc_link_validateis not static, changed to static.Changes in v8:
-> scaler: modified crop bounds to have the exact source sizeChanges in v7:
-> scaler: modified crop bounds to have maximum isc size -> format propagation: did small changes as per Jacopo reviewChanges in v6:
-> worked a bit on scaler, added try crop and other changes as per Jacopo review -> worked on isc-baseenum_fmt, reworked as per Jacopo reviewChanges in v5:
-> removed patch that removed the 'stop' variable as it was still required -> added two new trivial patches
-> reworked some parts of the scaler and format propagation after discussions with JacopoChanges in v4:
-> as reviewed by Hans, added new patch to remove the 'stop' variable and reworked one patch that was using it
-> as reviewed by Jacopo, reworked some parts of the media controller implementationChanges in v3:
- change in bindings, small fixes in csi2dc driver and conversion to mc for the isc-base.
- removed someMAINTAINERSpatches and used patterns inMAINTAINERSChanges in v2:
- integrated many changes suggested by Jacopo in the review of the v1 series.
- add a few new patches
Quoted 15 lines
Eugen Hristev (13):
media: atmel: atmel-isc-base: use streaming status when queueing
buffers
media: atmel: atmel-isc-base: replaceis_streamingcall in
s_fmt_vid_cap
media: atmel: atmel-isc: remove redundant comments
media: atmel: atmel-isc: implement media controller
media: atmel: atmel-sama5d2-isc: fix wrong mask in YUYV format check
media: atmel: atmel-isc-base: use mutex to lock awb workqueue from
streaming
media: atmel: atmel-isc: compact the controller formats list
media: atmel: atmel-isc: change format propagation to subdev into only
verification
media: atmel: atmel-sama7g5-isc: remove stray line
dt-bindings: media: microchip,xisc: add bus-width of 14
I'm a bit unhappy with the order of these patches. Mostly these are fixes, except for patches 4 and 8, which are the meat of this series and actually switching on the MC support.
Can those be moved to the end? That also makes it easier to merge the earlier patches if some more work is needed for the MC part.
I'm also not sure whether patches 4 and 8 shouldn't be a single patch, since patch 4 leaves the driver in an inconsistent state since it is missing the link validation code that patch 8 adds. Unless I missed something?
Regards,
Hans
Quoted 17 lines
ARM: dts: at91: sama7g5: add nodes for video capture
ARM: configs: at91: sama7: add xisc and csi2dc
ARM:multi_v7_defconfig: add atmel video pipeline modules.../bindings/media/microchip,xisc.yaml | 2 +- arch/arm/boot/dts/sama7g5.dtsi | 49 ++ arch/arm/configs/multi_v7_defconfig | 3 + arch/arm/configs/sama7_defconfig | 2 + drivers/media/platform/atmel/Makefile | 2 +- drivers/media/platform/atmel/atmel-isc-base.c | 518 ++++++++++-------- .../media/platform/atmel/atmel-isc-scaler.c | 267 +++++++++ drivers/media/platform/atmel/atmel-isc.h | 58 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 87 +-- .../media/platform/atmel/atmel-sama7g5-isc.c | 93 ++-- 10 files changed, 754 insertions(+), 327 deletions(-) create mode 100644 drivers/media/platform/atmel/atmel-isc-scaler.c
Quoted 73 lines · Hans Verkuil
Hi Eugen,
Quoted 50 lines · Eugen Hristev
This series is the v9 series that attempts to support media controller in the atmel ISC and XISC drivers.
The CSI2DC driver was accepted thus removed from the patch series, together with other patches.Important note: this series applies on top of current
media_stagingtree, as it relies on previous patches in the series which were accepted.Thanks to everyone who reviewed my work !
Eugen
Changes in v9:
-> kernel robot reportedisc_link_validateis not static, changed to static.Changes in v8:
-> scaler: modified crop bounds to have the exact source sizeChanges in v7:
-> scaler: modified crop bounds to have maximum isc size -> format propagation: did small changes as per Jacopo reviewChanges in v6:
-> worked a bit on scaler, added try crop and other changes as per Jacopo review -> worked on isc-baseenum_fmt, reworked as per Jacopo reviewChanges in v5:
-> removed patch that removed the 'stop' variable as it was still required -> added two new trivial patches
-> reworked some parts of the scaler and format propagation after discussions with JacopoChanges in v4:
-> as reviewed by Hans, added new patch to remove the 'stop' variable and reworked one patch that was using it
-> as reviewed by Jacopo, reworked some parts of the media controller implementationChanges in v3:
- change in bindings, small fixes in csi2dc driver and conversion to mc for the isc-base.
- removed someMAINTAINERSpatches and used patterns inMAINTAINERSChanges in v2:
- integrated many changes suggested by Jacopo in the review of the v1 series.
- add a few new patchesQuoted 15 lines
Eugen Hristev (13):
media: atmel: atmel-isc-base: use streaming status when queueing
buffers
media: atmel: atmel-isc-base: replaceis_streamingcall in
s_fmt_vid_cap
media: atmel: atmel-isc: remove redundant comments
media: atmel: atmel-isc: implement media controller
media: atmel: atmel-sama5d2-isc: fix wrong mask in YUYV format check
media: atmel: atmel-isc-base: use mutex to lock awb workqueue from
streaming
media: atmel: atmel-isc: compact the controller formats list
media: atmel: atmel-isc: change format propagation to subdev into only
verification
media: atmel: atmel-sama7g5-isc: remove stray line
dt-bindings: media: microchip,xisc: add bus-width of 14I'm a bit unhappy with the order of these patches. Mostly these are fixes, except for patches 4 and 8, which are the meat of this series and actually switching on the MC support.
Quoted 7 lines
Can those be moved to the end? That also makes it easier to merge the earlier patches if some more work is needed for the MC part.
I'm also not sure whether patches 4 and 8 shouldn't be a single patch, since patch 4 leaves the driver in an inconsistent state since it is missing the link validation code that patch 8 adds. Unless I missed something?
Hello Hans,
The difference that patch 8 is making is that the 'old way' of configuring the ISC is no longer possible.
Patch 4 makes the ISC 'mc-ready' with all entities, links, but the old way still works (meaning that the top driver will call s_fmt down to the subdev ).
After patch 8, the driver no longer has this support at all, and validates links at start_streaming, and no longer sets anything to the subdev, just validates the config that the subdev already has. So one reason that I had things in two patches was that patch 8 makes this big change that also makes userspace behave differently and has to configure all the subdevs and media pipeline.
If you feel patch 4 and patch 8 should be squashed, I can do it, definitely.
Let me know how to proceed ?
Thanks,
Eugen
Quoted 23 lines
Regards,
Hans
Quoted 17 lines
ARM: dts: at91: sama7g5: add nodes for video capture
ARM: configs: at91: sama7: add xisc and csi2dc
ARM:multi_v7_defconfig: add atmel video pipeline modules.../bindings/media/microchip,xisc.yaml | 2 +- arch/arm/boot/dts/sama7g5.dtsi | 49 ++ arch/arm/configs/multi_v7_defconfig | 3 + arch/arm/configs/sama7_defconfig | 2 + drivers/media/platform/atmel/Makefile | 2 +- drivers/media/platform/atmel/atmel-isc-base.c | 518 ++++++++++-------- .../media/platform/atmel/atmel-isc-scaler.c | 267 +++++++++ drivers/media/platform/atmel/atmel-isc.h | 58 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 87 +-- .../media/platform/atmel/atmel-sama7g5-isc.c | 93 ++-- 10 files changed, 754 insertions(+), 327 deletions(-)create mode 100644
drivers/media/platform/atmel/atmel-isc-scaler.c
Quoted 97 lines · On 29/04/2022 10:20, [email protected] wrote:
Quoted 73 lines · Hans Verkuil
Hi Eugen,
Quoted 50 lines · Eugen Hristev
This series is the v9 series that attempts to support media controller in the atmel ISC and XISC drivers.
The CSI2DC driver was accepted thus removed from the patch series, together with other patches.Important note: this series applies on top of current
media_stagingtree, as it relies on previous patches in the series which were accepted.Thanks to everyone who reviewed my work !
Eugen
Changes in v9:
-> kernel robot reportedisc_link_validateis not static, changed to static.Changes in v8:
-> scaler: modified crop bounds to have the exact source sizeChanges in v7:
-> scaler: modified crop bounds to have maximum isc size -> format propagation: did small changes as per Jacopo reviewChanges in v6:
-> worked a bit on scaler, added try crop and other changes as per Jacopo review -> worked on isc-baseenum_fmt, reworked as per Jacopo reviewChanges in v5:
-> removed patch that removed the 'stop' variable as it was still required -> added two new trivial patches
-> reworked some parts of the scaler and format propagation after discussions with JacopoChanges in v4:
-> as reviewed by Hans, added new patch to remove the 'stop' variable and reworked one patch that was using it
-> as reviewed by Jacopo, reworked some parts of the media controller implementationChanges in v3:
- change in bindings, small fixes in csi2dc driver and conversion to mc for the isc-base.
- removed someMAINTAINERSpatches and used patterns inMAINTAINERSChanges in v2:
- integrated many changes suggested by Jacopo in the review of the v1 series.
- add a few new patchesQuoted 15 lines
Eugen Hristev (13):
media: atmel: atmel-isc-base: use streaming status when queueing
buffers
media: atmel: atmel-isc-base: replaceis_streamingcall in
s_fmt_vid_cap
media: atmel: atmel-isc: remove redundant comments
media: atmel: atmel-isc: implement media controller
media: atmel: atmel-sama5d2-isc: fix wrong mask in YUYV format check
media: atmel: atmel-isc-base: use mutex to lock awb workqueue from
streaming
media: atmel: atmel-isc: compact the controller formats list
media: atmel: atmel-isc: change format propagation to subdev into only
verification
media: atmel: atmel-sama7g5-isc: remove stray line
dt-bindings: media: microchip,xisc: add bus-width of 14I'm a bit unhappy with the order of these patches. Mostly these are fixes, except for patches 4 and 8, which are the meat of this series and actually switching on the MC support.
Quoted 7 lines
Can those be moved to the end? That also makes it easier to merge the earlier patches if some more work is needed for the MC part.
I'm also not sure whether patches 4 and 8 shouldn't be a single patch, since patch 4 leaves the driver in an inconsistent state since it is missing the link validation code that patch 8 adds. Unless I missed something?
Hello Hans,
The difference that patch 8 is making is that the 'old way' of configuring the ISC is no longer possible.
Patch 4 makes the ISC 'mc-ready' with all entities, links, but the old way still works (meaning that the top driver will call
s_fmtdown to the subdev ).
After patch 8, the driver no longer has this support at all, and validates links atstart_streaming, and no longer sets anything to the subdev, just validates the config that the subdev already has. So one reason that I had things in two patches was that patch 8 makes this big change that also makes userspace behave differently and has to configure all the subdevs and media pipeline.
Quoted 3 lines
If you feel patch 4 and patch 8 should be squashed, I can do it, definitely.
Let me know how to proceed ?
Ah, that was your intention. The problem in patch 4 is that you set V4L2_CAP_IO_MC, which indicates to applications that they have to use the MC and configure the pipeline correctly. Moving that to patch 8 should resolve that, I think.
Regards,
Hans
Quoted 28 lines
Thanks,
EugenQuoted 23 lines
Regards,
Hans
Quoted 17 lines
ARM: dts: at91: sama7g5: add nodes for video capture
ARM: configs: at91: sama7: add xisc and csi2dc
ARM:multi_v7_defconfig: add atmel video pipeline modules.../bindings/media/microchip,xisc.yaml | 2 +- arch/arm/boot/dts/sama7g5.dtsi | 49 ++ arch/arm/configs/multi_v7_defconfig | 3 + arch/arm/configs/sama7_defconfig | 2 + drivers/media/platform/atmel/Makefile | 2 +- drivers/media/platform/atmel/atmel-isc-base.c | 518 ++++++++++-------- .../media/platform/atmel/atmel-isc-scaler.c | 267 +++++++++ drivers/media/platform/atmel/atmel-isc.h | 58 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 87 +-- .../media/platform/atmel/atmel-sama7g5-isc.c | 93 ++-- 10 files changed, 754 insertions(+), 327 deletions(-)create mode 100644
drivers/media/platform/atmel/atmel-isc-scaler.c
Quoted 98 lines · Hans Verkuil
Quoted 97 lines · On 29/04/2022 10:20, [email protected] wrote:
Quoted 73 lines · Hans Verkuil
Hi Eugen,
Quoted 50 lines · Eugen Hristev
This series is the v9 series that attempts to support media controller in the atmel ISC and XISC drivers.
The CSI2DC driver was accepted thus removed from the patch series, together with other patches.Important note: this series applies on top of current
media_stagingtree, as it relies on previous patches in the series which were accepted.Thanks to everyone who reviewed my work !
Eugen
Changes in v9:
-> kernel robot reportedisc_link_validateis not static, changed to static.Changes in v8:
-> scaler: modified crop bounds to have the exact source sizeChanges in v7:
-> scaler: modified crop bounds to have maximum isc size -> format propagation: did small changes as per Jacopo reviewChanges in v6:
-> worked a bit on scaler, added try crop and other changes as per Jacopo review -> worked on isc-baseenum_fmt, reworked as per Jacopo reviewChanges in v5:
-> removed patch that removed the 'stop' variable as it was still required -> added two new trivial patches
-> reworked some parts of the scaler and format propagation after discussions with JacopoChanges in v4:
-> as reviewed by Hans, added new patch to remove the 'stop' variable and reworked one patch that was using it
-> as reviewed by Jacopo, reworked some parts of the media controller implementationChanges in v3:
- change in bindings, small fixes in csi2dc driver and conversion to mc for the isc-base.
- removed someMAINTAINERSpatches and used patterns inMAINTAINERSChanges in v2:
- integrated many changes suggested by Jacopo in the review of the v1 series.
- add a few new patchesQuoted 15 lines
Eugen Hristev (13):
media: atmel: atmel-isc-base: use streaming status when queueing
buffers
media: atmel: atmel-isc-base: replaceis_streamingcall in
s_fmt_vid_cap
media: atmel: atmel-isc: remove redundant comments
media: atmel: atmel-isc: implement media controller
media: atmel: atmel-sama5d2-isc: fix wrong mask in YUYV format check
media: atmel: atmel-isc-base: use mutex to lock awb workqueue from
streaming
media: atmel: atmel-isc: compact the controller formats list
media: atmel: atmel-isc: change format propagation to subdev into only
verification
media: atmel: atmel-sama7g5-isc: remove stray line
dt-bindings: media: microchip,xisc: add bus-width of 14I'm a bit unhappy with the order of these patches. Mostly these are fixes, except for patches 4 and 8, which are the meat of this series and actually switching on the MC support.
Quoted 7 lines
Can those be moved to the end? That also makes it easier to merge the earlier patches if some more work is needed for the MC part.
I'm also not sure whether patches 4 and 8 shouldn't be a single patch, since patch 4 leaves the driver in an inconsistent state since it is missing the link validation code that patch 8 adds. Unless I missed something?
Hello Hans,
The difference that patch 8 is making is that the 'old way' of configuring the ISC is no longer possible.
Patch 4 makes the ISC 'mc-ready' with all entities, links, but the old way still works (meaning that the top driver will call
s_fmtdown to the subdev ).
After patch 8, the driver no longer has this support at all, and validates links atstart_streaming, and no longer sets anything to the subdev, just validates the config that the subdev already has. So one reason that I had things in two patches was that patch 8 makes this big change that also makes userspace behave differently and has to configure all the subdevs and media pipeline.
Quoted 8 lines
Quoted 3 lines
If you feel patch 4 and patch 8 should be squashed, I can do it, definitely.
Let me know how to proceed ?
Ah, that was your intention. The problem in patch 4 is that you set
V4L2_CAP_IO_MC, which indicates to applications that they have to use the MC and configure the pipeline correctly. Moving that to patch 8 should resolve that, I think.
Okay , got it.
Do you wish to apply some of the patches ? like maybe 1,2,3, 5, 7, 9, 10 ? I can then make the series smaller for the next iteration. Otherwise I will resend everything, no problem.
Eugen
Quoted 34 lines
Regards,
Hans
Quoted 28 lines
Thanks,
EugenQuoted 23 lines
Regards,
Hans
Quoted 17 lines
ARM: dts: at91: sama7g5: add nodes for video capture
ARM: configs: at91: sama7: add xisc and csi2dc
ARM:multi_v7_defconfig: add atmel video pipeline modules.../bindings/media/microchip,xisc.yaml | 2 +- arch/arm/boot/dts/sama7g5.dtsi | 49 ++ arch/arm/configs/multi_v7_defconfig | 3 + arch/arm/configs/sama7_defconfig | 2 + drivers/media/platform/atmel/Makefile | 2 +- drivers/media/platform/atmel/atmel-isc-base.c | 518 ++++++++++-------- .../media/platform/atmel/atmel-isc-scaler.c | 267 +++++++++ drivers/media/platform/atmel/atmel-isc.h | 58 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 87 +-- .../media/platform/atmel/atmel-sama7g5-isc.c | 93 ++-- 10 files changed, 754 insertions(+), 327 deletions(-)create mode 100644
drivers/media/platform/atmel/atmel-isc-scaler.c
Quoted 108 lines · On 29/04/2022 10:39, [email protected] wrote:
Quoted 98 lines · Hans Verkuil
Quoted 97 lines · On 29/04/2022 10:20, [email protected] wrote:
Quoted 73 lines · Hans Verkuil
Hi Eugen,
Quoted 50 lines · Eugen Hristev
This series is the v9 series that attempts to support media controller in the atmel ISC and XISC drivers.
The CSI2DC driver was accepted thus removed from the patch series, together with other patches.Important note: this series applies on top of current
media_stagingtree, as it relies on previous patches in the series which were accepted.Thanks to everyone who reviewed my work !
Eugen
Changes in v9:
-> kernel robot reportedisc_link_validateis not static, changed to static.Changes in v8:
-> scaler: modified crop bounds to have the exact source sizeChanges in v7:
-> scaler: modified crop bounds to have maximum isc size -> format propagation: did small changes as per Jacopo reviewChanges in v6:
-> worked a bit on scaler, added try crop and other changes as per Jacopo review -> worked on isc-baseenum_fmt, reworked as per Jacopo reviewChanges in v5:
-> removed patch that removed the 'stop' variable as it was still required -> added two new trivial patches
-> reworked some parts of the scaler and format propagation after discussions with JacopoChanges in v4:
-> as reviewed by Hans, added new patch to remove the 'stop' variable and reworked one patch that was using it
-> as reviewed by Jacopo, reworked some parts of the media controller implementationChanges in v3:
- change in bindings, small fixes in csi2dc driver and conversion to mc for the isc-base.
- removed someMAINTAINERSpatches and used patterns inMAINTAINERSChanges in v2:
- integrated many changes suggested by Jacopo in the review of the v1 series.
- add a few new patchesQuoted 15 lines
Eugen Hristev (13):
media: atmel: atmel-isc-base: use streaming status when queueing
buffers
media: atmel: atmel-isc-base: replaceis_streamingcall in
s_fmt_vid_cap
media: atmel: atmel-isc: remove redundant comments
media: atmel: atmel-isc: implement media controller
media: atmel: atmel-sama5d2-isc: fix wrong mask in YUYV format check
media: atmel: atmel-isc-base: use mutex to lock awb workqueue from
streaming
media: atmel: atmel-isc: compact the controller formats list
media: atmel: atmel-isc: change format propagation to subdev into only
verification
media: atmel: atmel-sama7g5-isc: remove stray line
dt-bindings: media: microchip,xisc: add bus-width of 14I'm a bit unhappy with the order of these patches. Mostly these are fixes, except for patches 4 and 8, which are the meat of this series and actually switching on the MC support.
Quoted 7 lines
Can those be moved to the end? That also makes it easier to merge the earlier patches if some more work is needed for the MC part.
I'm also not sure whether patches 4 and 8 shouldn't be a single patch, since patch 4 leaves the driver in an inconsistent state since it is missing the link validation code that patch 8 adds. Unless I missed something?
Hello Hans,
The difference that patch 8 is making is that the 'old way' of configuring the ISC is no longer possible.
Patch 4 makes the ISC 'mc-ready' with all entities, links, but the old way still works (meaning that the top driver will call
s_fmtdown to the subdev ).
After patch 8, the driver no longer has this support at all, and validates links atstart_streaming, and no longer sets anything to the subdev, just validates the config that the subdev already has. So one reason that I had things in two patches was that patch 8 makes this big change that also makes userspace behave differently and has to configure all the subdevs and media pipeline.Quoted 8 lines
Quoted 3 lines
If you feel patch 4 and patch 8 should be squashed, I can do it, definitely.
Let me know how to proceed ?
Ah, that was your intention. The problem in patch 4 is that you set
V4L2_CAP_IO_MC, which indicates to applications that they have to use the MC and configure the pipeline correctly. Moving that to patch 8 should resolve that, I think.
Quoted 5 lines
Okay , got it.
Do you wish to apply some of the patches ? like maybe 1,2,3, 5, 7, 9, 10 ? I can then make the series smaller for the next iteration. Otherwise I will resend everything, no problem.
Hmm, since patch 6 needs to be fixed anyway, I prefer a new series that includes just the fixes. And later a v10 with just the MC patches.
Regards,
Hans
Quoted 38 lines
Eugen
Quoted 34 lines
Regards,
Hans
Quoted 28 lines
Thanks,
EugenQuoted 23 lines
Regards,
Hans
Quoted 17 lines
ARM: dts: at91: sama7g5: add nodes for video capture
ARM: configs: at91: sama7: add xisc and csi2dc
ARM:multi_v7_defconfig: add atmel video pipeline modules.../bindings/media/microchip,xisc.yaml | 2 +- arch/arm/boot/dts/sama7g5.dtsi | 49 ++ arch/arm/configs/multi_v7_defconfig | 3 + arch/arm/configs/sama7_defconfig | 2 + drivers/media/platform/atmel/Makefile | 2 +- drivers/media/platform/atmel/atmel-isc-base.c | 518 ++++++++++-------- .../media/platform/atmel/atmel-isc-scaler.c | 267 +++++++++ drivers/media/platform/atmel/atmel-isc.h | 58 +- .../media/platform/atmel/atmel-sama5d2-isc.c | 87 +-- .../media/platform/atmel/atmel-sama7g5-isc.c | 93 ++-- 10 files changed, 754 insertions(+), 327 deletions(-)create mode 100644
drivers/media/platform/atmel/atmel-isc-scaler.c