[0/1] media: camss: fix VFE bpl_alignment for sdm845 and sm8250

Message ID 20230518215235.1668871-1-andrey.konovalov@linaro.org
Headers
Series media: camss: fix VFE bpl_alignment for sdm845 and sm8250 |

Message

Andrey Konovalov May 18, 2023, 9:52 p.m. UTC
  I tried to capture an image from SGRBG10_1X10/3280x2464 camera sensor on db845c
board (sdm845), and from SRGGB10_1X10/3280x2464 camera sensor on RB5 (qrb5165 /
sm8250). The captured frames contained incorrect image.

These formats are 4100 bytes per line. 4100 aligned by 8 is 4104. 4100 aligned
by 16 is 4112.

After looking at the frame data captured with the current bpl_alignment value
of 8 bytes, it becomes clear that the lines are not 4104 bytes long, but are
actually 4112 bytes long. That is the current bpl_alignment value is set
incorrectly.

With bpl_alignment set to 8 bytes (the value currently used by the camss
driver):
* on db845c capturing may stall after a few frames are captured OK
* the captured frames are corrupted:
  As the actual stride is 8 bytes more than expected, the 2nd line
  has 8 bytes from the 1st line tail in the beginning, and the actual
  data in the 2nd line are offset by these 8 bytes; the 3d line data
  are offset by 16 bytes etc. When the offset reaches the line length,
  one line starts with 0 offset again, the next line gets 8-byte offset
  etc. This results in "chainsaw shift" of lines in the captured image
  and messed up colours. Also a small part from the end of the actual frame
  (8 bytes times frame height) is not captured as it doesn't fit into the
  allocated buffer.
* "arm-smmu: Unhandled context fault" messages in dmesg output

Changing bpl_alignment to 16 bytes fixed all these issues:
* no capture stalls on db845c
* correct image in the captured frames
* "arm-smmu: Unhandled context fault" messages are gone

I've also used the patch
https://lore.kernel.org/lkml/20230503075340.45755-1-y.oudjana@protonmail.com/
as without it the camss driver is broken in media_tree - yavta fails with
error 22 (invalid argument).

Here is an example console log from db845c with bpl_alignment=8 (stride 4104):
-----8<-----
$ yavta -B capture-mplane --capture=5 -n 5 -I -f SGRBG10P -s 3280x2464 --file=ov8856-SGRBG10-3280x2464-#.bin /dev/video6
Device /dev/video6 opened.
Device `Qualcomm Camera Subsystem' on `platform:acb3000.camss' (driver 'qcom-camss') supports video, capture, with mplanes.
Video format set: SGRBG10P (41416770) 3280x2464 field none, 1 planes:
 * Stride 4104, buffer size 10112256
Video format: SGRBG10P (41416770) 3280x2464 field none, 1 planes:
 * Stride 4104, buffer size 10112256
5 buffers requested.
length: 1 offset: 4098861152 timestamp type/source: mono/EoF
Buffer 0/0 mapped at address 0xffffa305b000. 
<snip>
length: 1 offset: 4098861152 timestamp type/source: mono/EoF
Buffer 4/0 mapped at address 0xffffa09c7000.
0 (0) [-] none 0 10112256 B 818.593063 818.594398 8.942 fps ts mono/EoF
1 (1) [-] none 1 10112256 B 818.661186 818.662596 14.679 fps ts mono/EoF
2 (2) [-] none 2 10112256 B 818.727812 818.729342 15.009 fps ts mono/EoF
3 (3) [-] none 3 10112256 B 818.781710 818.794871 18.554 fps ts mono/EoF
<stalls after 4 of 5 frames captured>
^C
$
-----8<-----

The corresponding part of dmesg output:
-----8<-----
[  658.608956] arm-smmu 15000000.iommu: Unhandled context fault: fsr=0x402, iova=0xff9a5000, fsynr=0x3c0013, cbfrsynra=0x810, cb=14
[  658.676875] arm-smmu 15000000.iommu: Unhandled context fault: fsr=0x402, iova=0xfd9a5000, fsynr=0x3c0013, cbfrsynra=0x810, cb=14
[  658.743863] arm-smmu 15000000.iommu: Unhandled context fault: fsr=0x402, iova=0xfc9a5000, fsynr=0x3c0013, cbfrsynra=0x810, cb=14
[  658.810016] arm-smmu 15000000.iommu: Unhandled context fault: fsr=0x402, iova=0xfb9a5000, fsynr=0x3c0013, cbfrsynra=0x810, cb=14
### several seconds after Ctrl-C is pressed at the console:
[  670.950533] qcom-camss acb3000.camss: VFE idle timeout - resetting
-----8<-----

Andrey Konovalov (1):
  media: camss: set VFE bpl_alignment to 16 for sdm845 and sm8250

 drivers/media/platform/qcom/camss/camss-vfe.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
  

Comments

Bryan O'Donoghue May 22, 2023, 12:47 p.m. UTC | #1
On 18/05/2023 22:52, Andrey Konovalov wrote:
> I tried to capture an image from SGRBG10_1X10/3280x2464 camera sensor on db845c
> board (sdm845), and from SRGGB10_1X10/3280x2464 camera sensor on RB5 (qrb5165 /
> sm8250). The captured frames contained incorrect image.

I hadn't booted on an RB3 for ~3 months. I've confirmed this fix on rb3 
and on rb5.

Nice, work !

@Hans, @Laurent, @Michael any chance you could pull in these two commits?

https://git.codelinaro.org/bryan.odonoghue/kernel/-/tree/linux-next-qcom-camss

https://git.codelinaro.org/bryan.odonoghue/kernel/-/commit/c694ba97bccfc3e0c32504c1a71df3e8c04cfdeb

https://git.codelinaro.org/bryan.odonoghue/kernel/-/commit/54140e166c2ad5e2a21949f78e16d0c2093bd55d

---
bod