media: rcar-vin: Remove emulated SEQ_{TB,BT}
v3 cover media: rcar-vin: Remove emulated SEQ_{TB,BT}
Hello,
When the driver was converted from soc_camera emulated support for V4L2_FIELD_SEQ_TB and V4L2_FIELD_SEQ_BT where added. This was done by capturing twice to the same VB2 buffer, but at different offsets.
This trend out to be a bad idea and the wrong place to try and emulate this kind of thing. Further more it is fragile when it comes to things like suspend/resume and scaling. Just how fragile it was have been made more apparent when more features where added to the driver for things the hardware really can do.
If user-space really want to capture things in a SEQ_{TB,BT} fashion this emulation of capturing twice to the same buffer with a different offset can be emulated their instead of the kernel, where it always should have been.
This series removes this emulation in patch 1/5 and then proceeds to remove a lot of cruft code needed to support it. The primary cleanups in patch 2/5 - 4/5 revolve around simplifying the VIN internal state tracking from 5 to 2 states needed to support the emulation.
Finally patch 5/5 removes a hack in the R-Car CSI-2 driver which was added to support this emulation, and is no longer needed.
I have tested this on Gen2, Gen3 and Gen4 without hitting any regressions or other issues, other then of course SEQ_{TB,BT} are no longer enumerated as output formats.
For changelog see individual patches.
Niklas Söderlund (5):
media: rcar-vin: Remove emulated SEQ_{TB,BT}
media: rcar-vin: Remove superfluous suspended state
media: rcar-vin: Remove superfluous starting state
media: rcar-vin: Simplify the shutdown process
media: rcar-csi2: Remove hack to detect NTSC content
drivers/media/platform/renesas/rcar-csi2.c | 8 +- .../platform/renesas/rcar-vin/rcar-core.c | 6 +- .../platform/renesas/rcar-vin/rcar-dma.c | 132 ++++-------------- .../platform/renesas/rcar-vin/rcar-v4l2.c | 7 - .../platform/renesas/rcar-vin/rcar-vin.h | 40 +----- 5 files changed, 33 insertions(+), 160 deletions(-)
Signature · 1 line
2.48.1
PATCH v3 1/5 media: rcar-vin: Remove emulated SEQ_{TB,BT}
When the driver was converted from soc_camera software support for V4L2_FIELD_SEQ_TB and V4L2_FIELD_SEQ_BT were added. This was done by capturing twice to the same VB2 buffer, but at different offsets.
This turned out to be a bad idea and it never really worked properly in all situations. As the hardware can't support this mode natively remove trying to emulate it in software. It's still possible to capture TOP or BOTTOM fields separately or both ALTERNATING. If user-space wants the same fields in the same buffer the same hack to capture twice to the same buffer can be done.
Removing this error prone emulated support pave ways in future work to simplify the internal buffer handling and making it less fragile, while enabling adding support for other features the hardware actually supports.
---
* Changes since v2
- Fix commit message.
* Changes since v1
- Remove 'prev' variable in rvin_fill_hw_slot() which is no longer used, but set.
--- .../platform/renesas/rcar-vin/rcar-dma.c | 58 +++---------------- .../platform/renesas/rcar-vin/rcar-v4l2.c | 7 --- .../platform/renesas/rcar-vin/rcar-vin.h | 18 ------ 3 files changed, 7 insertions(+), 76 deletions(-)
drivers/media/platform/renesas/rcar-vin/rcar-dma.c +7 -51
@@ -642,8 +642,6 @@ void rvin_scaler_gen3(struct rvin_dev *vin)case V4L2_FIELD_INTERLACED_TB :case V4L2_FIELD_INTERLACED_BT :case V4L2_FIELD_INTERLACED : -case V4L2_FIELD_SEQ_TB : -case V4L2_FIELD_SEQ_BT : clip_size |= vin->compose.height /2 ;break ;default :
@@ -727,8 +725,6 @@ static int rvin_setup(struct rvin_dev *vin)case V4L2_FIELD_INTERLACED_BT : vnmc =VNMC_IM_FULL |VNMC_FOC ;break ; -case V4L2_FIELD_SEQ_TB : -case V4L2_FIELD_SEQ_BT :case V4L2_FIELD_NONE :case V4L2_FIELD_ALTERNATE : vnmc =VNMC_IM_ODD_EVEN ;
@@ -1021,33 +1017,14 @@ static void rvin_fill_hw_slot(struct rvin_dev *vin, int slot)struct rvin_buffer *buf;struct vb2_v4l2_buffer *vbuf;dma_addr_t phys_addr; -int prev;/* A already populated slot shall never be overwritten. */ if (WARN_ON (vin->buf_hw[slot].buffer))return ; - prev = (slot ==0 ?HW_BUFFER_NUM : slot) -1 ; - -if (vin->buf_hw[prev].type ==HALF_TOP ) { - vbuf = vin->buf_hw[prev].buffer; - vin->buf_hw[slot].buffer = vbuf; - vin->buf_hw[slot].type =HALF_BOTTOM ; -switch (vin->format.pixelformat) { -case V4L2_PIX_FMT_NV12 : -case V4L2_PIX_FMT_NV16 : - phys_addr = vin->buf_hw[prev].phys + - vin->format.sizeimage /4 ; -break ; -default : - phys_addr = vin->buf_hw[prev].phys + - vin->format.sizeimage /2 ; -break ; - } - }else if ((vin->state !=STOPPED && vin->state !=RUNNING ) || -list_empty (&vin->buf_list)) { +if ((vin->state !=STOPPED && vin->state !=RUNNING ) || +list_empty (&vin->buf_list)) { vin->buf_hw[slot].buffer =NULL ; - vin->buf_hw[slot].type =FULL ; phys_addr = vin->scratch_phys; }else {/* Keep track of buffer we give to HW */
@@ -1056,16 +1033,12 @@ static void rvin_fill_hw_slot(struct rvin_dev *vin, int slot)list_del_init (to_buf_list (vbuf)); vin->buf_hw[slot].buffer = vbuf; - vin->buf_hw[slot].type = -V4L2_FIELD_IS_SEQUENTIAL (vin->format.field) ? -HALF_TOP :FULL ; -/* Setup DMA */ phys_addr =vb2_dma_contig_plane_dma_addr (&vbuf->vb2_buf,0 ); } -vin_dbg (vin,"Filling HW slot: %d type: %d buffer: %p\n" , - slot, vin->buf_hw[slot].type, vin->buf_hw[slot].buffer); +vin_dbg (vin,"Filling HW slot: %d buffer: %p\n" , + slot, vin->buf_hw[slot].buffer); vin->buf_hw[slot].phys = phys_addr;rvin_set_slot_addr (vin, slot, phys_addr);
@@ -1073,15 +1046,12 @@ static void rvin_fill_hw_slot(struct rvin_dev *vin, int slot)static int rvin_capture_start (struct rvin_dev *vin) { -int slot, ret; +int ret; -for (slot =0 ; slot <HW_BUFFER_NUM ; slot++) { +for (unsigned int slot =0 ; slot <HW_BUFFER_NUM ; slot++) { vin->buf_hw[slot].buffer =NULL ; - vin->buf_hw[slot].type =FULL ; - } - -for (slot =0 ; slot <HW_BUFFER_NUM ; slot++)rvin_fill_hw_slot (vin, slot); + } ret =rvin_setup (vin);if (ret)
@@ -1162,16 +1132,6 @@ static irqreturn_t rvin_irq(int irq, void *data)/* Capture frame */ if (vin->buf_hw[slot].buffer) { -/* -* Nothing to do but refill the hardware slot if -* capture only filled first half of vb2 buffer. -*/ -if (vin->buf_hw[slot].type ==HALF_TOP ) { - vin->buf_hw[slot].buffer =NULL ; -rvin_fill_hw_slot (vin, slot); - goto done; - } - vin->buf_hw[slot].buffer->field =rvin_get_active_field (vin, vnms); vin->buf_hw[slot].buffer->sequence = vin->sequence;
@@ -1322,8 +1282,6 @@ static int rvin_mc_validate_format(struct rvin_dev *vin, struct v4l2_subdev *sd,case V4L2_FIELD_INTERLACED_TB :case V4L2_FIELD_INTERLACED_BT :case V4L2_FIELD_INTERLACED : -case V4L2_FIELD_SEQ_TB : -case V4L2_FIELD_SEQ_BT :/* Supported natively */ break ;case V4L2_FIELD_ALTERNATE :
@@ -1336,8 +1294,6 @@ static int rvin_mc_validate_format(struct rvin_dev *vin, struct v4l2_subdev *sd,case V4L2_FIELD_INTERLACED_TB :case V4L2_FIELD_INTERLACED_BT :case V4L2_FIELD_INTERLACED : -case V4L2_FIELD_SEQ_TB : -case V4L2_FIELD_SEQ_BT :/* Use VIN hardware to combine the two fields */ fmt.format.height *=2 ;break ;
drivers/media/platform/renesas/rcar-vin/rcar-v4l2.c +0 -7
@@ -161,9 +161,6 @@ static u32 rvin_format_bytesperline(struct rvin_dev *vin,break ; } -if (V4L2_FIELD_IS_SEQUENTIAL (pix->field)) - align =0x80 ; -return ALIGN (pix->width, align) * fmt->bpp; }
@@ -194,8 +191,6 @@ static void rvin_format_align(struct rvin_dev *vin, struct v4l2_pix_format *pix)case V4L2_FIELD_INTERLACED_BT :case V4L2_FIELD_INTERLACED :case V4L2_FIELD_ALTERNATE : -case V4L2_FIELD_SEQ_TB : -case V4L2_FIELD_SEQ_BT :break ;default : pix->field =RVIN_DEFAULT_FIELD ;
@@ -504,8 +499,6 @@ static int rvin_remote_rectangle(struct rvin_dev *vin, struct v4l2_rect *rect)case V4L2_FIELD_INTERLACED_TB :case V4L2_FIELD_INTERLACED_BT :case V4L2_FIELD_INTERLACED : -case V4L2_FIELD_SEQ_TB : -case V4L2_FIELD_SEQ_BT : rect->height *=2 ;break ; }
drivers/media/platform/renesas/rcar-vin/rcar-vin.h +0 -18
@@ -77,23 +77,6 @@ enum rvin_dma_state { SUSPENDED, }; -/** -* enum rvin_buffer_type -* -* Describes how a buffer is given to the hardware. To be able -* to capture SEQ_TB/BT it's needed to capture to the same vb2 -* buffer twice so the type of buffer needs to be kept. -* -* @FULL: One capture fills the whole vb2 buffer -* @HALF_TOP: One capture fills the top half of the vb2 buffer -* @HALF_BOTTOM: One capture fills the bottom half of the vb2 buffer -*/ -enum rvin_buffer_type { -FULL , -HALF_TOP , -HALF_BOTTOM , -}; -/** * struct rvin_video_format - Data format stored in memory * @fourcc: Pixelformat
@@ -237,7 +220,6 @@ struct rvin_dev {spinlock_t qlock;struct {struct vb2_v4l2_buffer *buffer; -enum rvin_buffer_type type;dma_addr_t phys; } buf_hw[HW_BUFFER_NUM ];struct list_head buf_list;
Signature · 1 line
2.48.1
PATCH v3 2/5 media: rcar-vin: Remove superfluous suspended state
In reply to Niklas SöderlundThe VIN state of suspended is superfluous. The logic was that when the device were suspended and in a RUNNING state the state was set to SUSPENDED. And when resuming it checked if the state is SUSPENDED and if so started the device and changed it to RUNNING.
This can be avoided by simply checking if the device is in a RUNNING state at both suspend and resume callbacks. Remove the unneeded complexity.
---
* Changes since v2
- Update commit message.
--- drivers/media/platform/renesas/rcar-vin/rcar-core.c | 4 +--- drivers/media/platform/renesas/rcar-vin/rcar-vin.h | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-)
drivers/media/platform/renesas/rcar-vin/rcar-core.c +1 -3
@@ -1085,8 +1085,6 @@ static int __maybe_unused rvin_suspend(struct device *dev)rvin_stop_streaming (vin); - vin->state =SUSPENDED ; -return 0 ; }
@@ -1094,7 +1092,7 @@ static int __maybe_unused rvin_resume(struct device *dev) {struct rvin_dev *vin =dev_get_drvdata (dev); -if (vin->state !=SUSPENDED ) +if (vin->state !=RUNNING )return 0 ;/*
drivers/media/platform/renesas/rcar-vin/rcar-vin.h +0 -2
@@ -67,14 +67,12 @@ enum rvin_isp_id {* @STARTING: Capture starting up * @RUNNING: Operation in progress have buffers * @STOPPING: Stopping operation -* @SUSPENDED: Capture is suspended */ enum rvin_dma_state {STOPPED =0 ,STARTING ,RUNNING ,STOPPING , -SUSPENDED , };/**
Signature · 1 line
2.48.1
PATCH v3 3/5 media: rcar-vin: Remove superfluous starting state
In reply to Niklas SöderlundThe STARTING state is superfluous and can be replaced with a check of the sequence counter. The design idea is that the first buffer returned from the driver have to come from the first hardware buffer slot. Failing this the first 3 buffers queued to the device can be returned out-of-order.
But it's much clearer to check the sequence counter to only return the first buffer if it comes from hardware slot 0 then it is to carry around an extra state just for this. Remove the unneeded state and replace it with a simpler check.
--- drivers/media/platform/renesas/rcar-vin/rcar-dma.c | 5 ++--- drivers/media/platform/renesas/rcar-vin/rcar-vin.h | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-)
drivers/media/platform/renesas/rcar-vin/rcar-dma.c +2 -3
@@ -1064,7 +1064,7 @@ static int rvin_capture_start(struct rvin_dev *vin)/* Continuous Frame Capture Mode */ rvin_write (vin,VNFC_C_FRAME ,VNFC_REG ); - vin->state =STARTING ; + vin->state =RUNNING ;return 0 ; }
@@ -1120,14 +1120,13 @@ static irqreturn_t rvin_irq(int irq, void *data)* To hand buffers back in a known order to userspace start * to capture first from slot 0. */ -if (vin->state ==STARTING ) { +if (!vin->sequence) {if (slot !=0 ) {vin_dbg (vin,"Starting sync slot: %d\n" , slot); goto done; }vin_dbg (vin,"Capture start synced!\n" ); - vin->state =RUNNING ; }/* Capture frame */
drivers/media/platform/renesas/rcar-vin/rcar-vin.h +0 -2
@@ -64,13 +64,11 @@ enum rvin_isp_id {/** * enum rvin_dma_state - DMA states * @STOPPED: No operation in progress -* @STARTING: Capture starting up * @RUNNING: Operation in progress have buffers * @STOPPING: Stopping operation */ enum rvin_dma_state {STOPPED =0 , -STARTING ,RUNNING ,STOPPING , };
Signature · 1 line
2.48.1
PATCH v3 4/5 media: rcar-vin: Simplify the shutdown process
In reply to Niklas SöderlundWhen shutting down capture extra care was needed to try and complete a buffer that was involved in the emulated support for SEQ_{TB,BT}. This was needed as a buffer might be queued once to the driver, but two times to the hardware using different offsets.
As support for SEQ_{TB,BT} is now removed this shutdown process can be greatly simplified. And in addition the state keeping of the VIN device can be reduced to a single boolean value instead of keeping track of this SEQ_{TB,BT} stopping dance.
--- .../platform/renesas/rcar-vin/rcar-core.c | 4 +- .../platform/renesas/rcar-vin/rcar-dma.c | 75 ++++++------------- .../platform/renesas/rcar-vin/rcar-vin.h | 18 +---- 3 files changed, 26 insertions(+), 71 deletions(-)
drivers/media/platform/renesas/rcar-vin/rcar-core.c +2 -2
@@ -1080,7 +1080,7 @@ static int __maybe_unused rvin_suspend(struct device *dev) {struct rvin_dev *vin =dev_get_drvdata (dev); -if (vin->state !=RUNNING ) +if (!vin->running)return 0 ;rvin_stop_streaming (vin);
@@ -1092,7 +1092,7 @@ static int __maybe_unused rvin_resume(struct device *dev) {struct rvin_dev *vin =dev_get_drvdata (dev); -if (vin->state !=RUNNING ) +if (!vin->running)return 0 ;/*
drivers/media/platform/renesas/rcar-vin/rcar-dma.c +21 -54
143 lines not on this page · raw message
drivers/media/platform/renesas/rcar-vin/rcar-vin.h +3 -15
@@ -61,18 +61,6 @@ enum rvin_isp_id { (((unsigned int )RVIN_CSI_MAX ) > ((unsigned int )RVIN_ISP_MAX ) ? \ (unsigned int )RVIN_CSI_MAX : (unsigned int )RVIN_ISP_MAX ) -/** -* enum rvin_dma_state - DMA states -* @STOPPED: No operation in progress -* @RUNNING: Operation in progress have buffers -* @STOPPING: Stopping operation - */ -enum rvin_dma_state { -STOPPED =0 , -RUNNING , -STOPPING , -}; -/** * struct rvin_video_format - Data format stored in memory * @fourcc: Pixelformat
@@ -173,11 +161,11 @@ struct rvin_info {* @scratch: cpu address for scratch buffer * @scratch_phys: physical address of the scratch buffer * -* @qlock: protects @buf_hw, @buf_list, @sequence and @state +* @qlock: Protects @buf_hw, @buf_list, @sequence and @running * @buf_hw: Keeps track of buffers given to HW slot * @buf_list: list of queued buffers * @sequence: V4L2 buffers sequence number -* @state: keeps track of operation state +* @running: Keeps track of if the VIN is running * * @is_csi: flag to mark the VIN as using a CSI-2 subdevice * @chsel: Cached value of the current CSI-2 channel selection
@@ -220,7 +208,7 @@ struct rvin_dev { } buf_hw[HW_BUFFER_NUM ];struct list_head buf_list;unsigned int sequence; -enum rvin_dma_state state; +bool running;bool is_csi;unsigned int chsel;
Signature · 1 line
2.48.1
PATCH v3 5/5 media: rcar-csi2: Remove hack to detect NTSC content
In reply to Niklas SöderlundIn an effort to emulate support for SEQ_{TB,BT} in the R-Car VIN driver on data captured from a CVBS input a hack was added to detect NTSC vs PAL. This is ugly and as support for emulated SEQ_{TB,BT} have been removed from the VIN driver remove the ugly hack.
--- drivers/media/platform/renesas/rcar-csi2.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/media/platform/renesas/rcar-csi2.c +1 -7
@@ -1045,16 +1045,10 @@ static int rcsi2_start_receiver_gen3(struct rcar_csi2 *priv, vcdt2 |= vcdt_part << ((i %2 ) *16 ); } -if (fmt->field ==V4L2_FIELD_ALTERNATE ) { +if (fmt->field ==V4L2_FIELD_ALTERNATE ) fld =FLD_DET_SEL (1 ) |FLD_FLD_EN4 |FLD_FLD_EN3 |FLD_FLD_EN2 |FLD_FLD_EN ; -if (fmt->height ==240 ) - fld |=FLD_FLD_NUM (0 ); -else - fld |=FLD_FLD_NUM (1 ); - } -/* * Get the number of active data lanes inspecting the remote mbus * configuration.
Signature · 1 line
2.48.1