Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bcm2835_v4l2 on RPi1 kernel oops #1447

Closed
kad opened this issue May 1, 2016 · 65 comments
Closed

bcm2835_v4l2 on RPi1 kernel oops #1447

kad opened this issue May 1, 2016 · 65 comments
Labels
Waiting for internal comment Waiting for comment from a member of the Raspberry Pi engineering team

Comments

@kad
Copy link

kad commented May 1, 2016

After upgrading to 4.4.8, started to see kernel OOPS while trying to load v4l driver. 4.4.7 was ok.
Is it something known ?

[   67.186322] Linux video capture interface: v2.00
[   67.303470] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[   67.311943] pgd = d556c000
[   67.314787] [00000000] *pgd=130fd831, *pte=00000000, *ppte=00000000
[   67.321446] Internal error: Oops: 17 [#1] ARM
[   67.325901] Modules linked in: bcm2835_v4l2(+) videobuf2_vmalloc videobuf2_memops videobuf2_v4l2 videobuf2_core v4l2_common videodev media cfg80211 joydev evdev i2c_bcm2708 spi_bcm2835 bcm2835_gpiomem bcm2835_wdt uio_pdrv_genirq uio sch_fq_codel bcm2835_rng rng_core ip_tables x_tables ipv6
[   67.352503] CPU: 0 PID: 656 Comm: modprobe Not tainted 4.4.8-2-ARCH #1
[   67.359151] Hardware name: BCM2708
[   67.362632] task: d5492820 ti: d31be000 task.ti: d31be000
[   67.368234] PC is at bm2835_mmal_init+0x78/0x738 [bcm2835_v4l2]
[   67.374268] LR is at 0x0
[   67.376870] pc : [<bf1d0078>]    lr : [<00000000>]    psr: a0000113
               sp : d31bfd90  ip : 00000000  fp : 2a9154dc
[   67.388543] r10: 00000001  r9 : bf1cc394  r8 : 00000000
[   67.393872] r7 : bf1d0000  r6 : 00000000  r5 : 00000000  r4 : d55ba800
[   67.400517] r3 : bf1cb644  r2 : 00000000  r1 : 00000000  r0 : d55ba800
[   67.407163] Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
[   67.414430] Control: 00c5387d  Table: 1556c008  DAC: 00000055
[   67.420285] Process modprobe (pid: 656, stack limit = 0xd31be188)
[   67.426494] Stack: (0xd31bfd90 to 0xd31c0000)
[   67.430944] fd80:                                     00000002 c04bac60 ff0a0005 00000000
[   67.439271] fda0: 00000020 00000001 d3244000 ffffffff 00000a20 00000798 00000000 00000000
[   67.447600] fdc0: d31c2b40 00000000 d56eab40 00000001 2a9154dc c04bd8a4 00000000 d31bfe08
[   67.455932] fde0: 00000000 bf1cc620 00000001 c0a94f10 c0a94f10 d31c2b40 bf1d0000 00000000
[   67.464264] fe00: d56eab40 00000001 2a9154dc c00094b8 00000001 00000000 00000001 d552b838
[   67.472590] fe20: 00000000 d5421064 c0984e4c bf1cc668 00000004 d571a018 c0ba3e64 00000000
[   67.480920] fe40: d7f3d764 d7c8cd00 00000000 bf1cc668 2a9154dc c01145f8 2a9154dc c00d6fd8
[   67.489246] fe60: bf1cc620 00000001 d31c22c0 bf1cc620 bf1cc668 00000001 2a9154dc c00cf9f4
[   67.497575] fe80: d31bff44 00000001 d31bff44 00000001 d56eab48 c007c2d8 bf1cc62c 00007fff
[   67.505901] fea0: bf1cc620 c0079afc c0079578 bf1cc718 00000000 d8eb3304 bf1cc7d4 bf1cc62c
[   67.514230] fec0: 00000000 c079e4d0 00400000 d56eaf00 006e0288 c0105140 00400000 00000000
[   67.522558] fee0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[   67.530884] ff00: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000e354
[   67.539213] ff20: 00000000 b4c6735c d8eb3354 0002bce8 d31be000 00000000 006e0288 c007c8c4
[   67.547540] ff40: 00001a03 d8ea5000 0000e354 d8eb2c9c d8eb2ad8 d8eaff24 00007814 00008944
[   67.555870] ff60: 00000000 00000000 00000000 000031dc 00000029 0000002a 0000001f 00000023
[   67.564199] ff80: 00000018 00000000 00005a03 006e0490 b4c59008 00040000 00000080 c000f0a4
[   67.572525] ffa0: d31be000 c000ef00 006e0490 b4c59008 b4c59008 0000e354 0002bce8 bf170000
[   67.580853] ffc0: 006e0490 b4c59008 00040000 00000080 0002bce8 00000000 00000000 006e0288
[   67.589186] ffe0: 0003e164 beca0930 00020bb4 b6e89140 60000010 b4c59008 17ffa861 17ffac61
[   67.597612] [<bf1d0078>] (bm2835_mmal_init [bcm2835_v4l2]) from [<c00094b8>] (do_one_initcall+0x80/0x1dc)
[   67.607402] [<c00094b8>] (do_one_initcall) from [<c00cf9f4>] (do_init_module+0x5c/0x1c0)
[   67.615678] [<c00cf9f4>] (do_init_module) from [<c007c2d8>] (load_module+0x1ad8/0x1fa0)
[   67.623848] [<c007c2d8>] (load_module) from [<c007c8c4>] (SyS_init_module+0x124/0x140)
[   67.631936] [<c007c8c4>] (SyS_init_module) from [<c000ef00>] (ret_fast_syscall+0x0/0x34)
[   67.640186] Code: 0a000188 e59d200c e59f3634 e082e186 (e792c186)
[   67.646904] ---[ end trace 5265da98745e43b3 ]---
@popcornmix
Copy link
Collaborator

Can you identify the exact update which caused this. See:
https://github.com/Hexxeh/rpi-firmware/commits/master

If you click on each commit the end of the url contains a git hash. Run
sudo rpi-update <hash>
to revert back to that version. Report the first version with this error.

@6by9
Copy link
Contributor

6by9 commented May 2, 2016

At a guess Hexxeh/rpi-firmware@6d158ad is going to be the first version with the issue - that was the first one to include querying the GPU for max sensor resolution which is done in bm2835_mmal_init.
9dc0b88f1d3b5e9400e4adaadd13a4ef5e7348fa is the one previous to that.

I can't see anything wrong with the handling there so can't currently give any advice. I had tested that fairly thoroughly on Pi2 and CM3, and there's no significant difference in that area for Pi1. Seeing as you're on 4.4.8 I assume you've used rpi-update and updated the firmware as well as kernel. There was a firmware change associated around that request as well.

@DeX77
Copy link
Contributor

DeX77 commented May 6, 2016

I can confirm modprobing bcm2835-v4l2 crashes kernel here.

Specs:

Hardware        : BCM2708
Revision        : 000e

Running Arch Linux ARM:

linux-raspberrypi 4.4.8-2
raspberrypi-firmware-tools 20160503-1
raspberrypi-firmware-bootloader-x 20160503-1
raspberrypi-firmware-bootloader 20160503-1
linux-firmware 20160315.deb1d83-1

@popcornmix
Copy link
Collaborator

Not seeing a kernel crash here. What does:

vcgencmd version
uname -a

report?

@DeX77
Copy link
Contributor

DeX77 commented May 7, 2016

/opt/vc/bin/vcgencmd version
May  3 2016 17:47:44 
Copyright (c) 2012 Broadcom
version b870a5bbf6c662327916ee582c22309c9f997b3d (clean) (release)
uname -a
Linux alarmpi 4.4.8-2-ARCH #1 Tue Apr 26 19:13:10 MDT 2016 armv6l GNU/Linux

@kad
Copy link
Author

kad commented May 7, 2016

Tried with fresh 4.4.9 kernel:

[  111.269707] media: Linux media interface: v0.10
[  111.370081] Linux video capture interface: v2.00
[  111.490692] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[  111.499124] pgd = d30d0000
[  111.501988] [00000000] *pgd=11050831, *pte=00000000, *ppte=00000000
[  111.508592] Internal error: Oops: 17 [#1] ARM
[  111.513040] Modules linked in: bcm2835_v4l2(+) videobuf2_vmalloc videobuf2_memops videobuf2_v4l2 videobuf2_core v4l2_common videodev media cfg80211 i2c_bcm2708 spi_bcm2835 bcm2835_gpiomem bcm2835_wdt uio_p
drv_genirq uio sch_fq_codel bcm2835_rng rng_core ip_tables x_tables ipv6
[  111.538374] CPU: 0 PID: 655 Comm: modprobe Not tainted 4.4.9-1-ARCH #1
[  111.545014] Hardware name: BCM2708
[  111.548486] task: d6b0dda0 ti: d3330000 task.ti: d3330000
[  111.554070] PC is at bm2835_mmal_init+0x78/0x738 [bcm2835_v4l2]
[  111.560098] LR is at 0x0
[  111.562689] pc : [<bf1c3078>]    lr : [<00000000>]    psr: a0000113
               sp : d3331d90  ip : 00000000  fp : 2cded15c
[  111.574345] r10: 00000001  r9 : bf1bf394  r8 : 00000000
[  111.579664] r7 : bf1c3000  r6 : 00000000  r5 : 00000000  r4 : d5479800
[  111.586299] r3 : bf1be644  r2 : 00000000  r1 : 00000000  r0 : d5479800
[  111.592939] Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
[  111.600195] Control: 00c5387d  Table: 130d0008  DAC: 00000055
[  111.608475] Process modprobe (pid: 655, stack limit = 0xd3330188)
[  111.617228] Stack: (0xd3331d90 to 0xd3332000)
[  111.624239] 1d80:                                     00000002 c04bb040 ff0a0005 00000000
[  111.637730] 1da0: 00000020 00000001 d3334000 ffffffff 00000a20 00000798 00000000 00000000
[  111.651265] 1dc0: d55e4640 00000000 d3212ec0 00000001 2cded15c c04bdc84 d541e018 d3331e08
[  111.664982] 1de0: d6a19480 bf1bf620 00000001 c0a94f30 c0a94f30 d55e4640 bf1c3000 00000000
[  111.678910] 1e00: d3212ec0 00000001 2cded15c c00094b8 f348c558 00000019 00000001 d3330000
[  111.693103] 1e20: d3330000 d7001e60 d3212ec8 024000c0 c00cf9b8 0000000c d3331e4c c0794be4
[  111.707440] 1e40: 024000c0 d7001e60 d3331e54 c0794c30 2cded15c c0114618 2cded15c c00d6fd8
[  111.721988] 1e60: bf1bf620 00000001 d55e45e0 bf1bf620 bf1bf668 00000001 2cded15c c00cf9f4
[  111.736774] 1e80: d3331f44 00000001 d3331f44 00000001 d3212ec8 c007c2c0 bf1bf62c 00007fff
[  111.751777] 1ea0: bf1bf620 c0079ae4 c0079560 bf1bf718 00000000 d90d9304 bf1bf7d4 bf1bf62c
[  111.767050] 1ec0: 00000000 c079e4d0 00400000 d32123c0 0192b280 c0105160 00400000 00000000
[  111.782634] 1ee0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[  111.798354] 1f00: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000e354
[  111.814304] 1f20: 00000000 b4c1335c d90d9354 0002bce8 d3330000 00000000 0192b280 c007c8ac
[  111.830396] 1f40: 00001a04 d90cb000 0000e354 d90d8c9c d90d8ad8 d90d5f24 00007814 00008944
[  111.846489] 1f60: 00000000 00000000 00000000 000031dc 00000029 0000002a 0000001f 00000023
[  111.862574] 1f80: 00000018 00000000 00005a04 0192b060 b4c05008 00040000 00000080 c000f0a4
[  111.878688] 1fa0: d3330000 c000ef00 0192b060 b4c05008 b4c05008 0000e354 0002bce8 c7037e00
[  111.894805] 1fc0: 0192b060 b4c05008 00040000 00000080 0002bce8 00000000 00000000 0192b280
[  111.910935] 1fe0: 0003e164 bed28930 00020bb4 b6e34670 60000010 b4c05008 8080827f 7f808283
[  111.927210] [<bf1c3078>] (bm2835_mmal_init [bcm2835_v4l2]) from [<c00094b8>] (do_one_initcall+0x80/0x1dc)
[  111.944797] [<c00094b8>] (do_one_initcall) from [<c00cf9f4>] (do_init_module+0x5c/0x1c0)
[  111.960780] [<c00cf9f4>] (do_init_module) from [<c007c2c0>] (load_module+0x1ad8/0x1fa0)
[  111.976609] [<c007c2c0>] (load_module) from [<c007c8ac>] (SyS_init_module+0x124/0x140)
[  111.992332] [<c007c8ac>] (SyS_init_module) from [<c000ef00>] (ret_fast_syscall+0x0/0x34)
[  112.008146] Code: 0a000188 e59d200c e59f3634 e082e186 (e792c186)
[  112.018482] ---[ end trace 8fb7666a31e04815 ]---
[  113.949638] cfg80211: Verifying active interfaces after reg change
[root@campi kad]# /opt/vc/bin/vcgencmd version
May  6 2016 13:57:24
Copyright (c) 2012 Broadcom
version 0cc642d53eab041e67c8c373d989fef5847448f8 (clean) (release)
[root@campi kad]# uname -a
Linux campi 4.4.9-1-ARCH #1 Fri May 6 12:52:21 MDT 2016 armv6l GNU/Linux
[root@campi kad]#

kernel build corresponds to commit 68bead2
reference: https://github.com/archlinuxarm/PKGBUILDs/blob/master/core/linux-raspberrypi/PKGBUILD

@popcornmix
Copy link
Collaborator

@kad were you running raspbian or arch?

@kad
Copy link
Author

kad commented May 7, 2016

Place where I can reproduce this crash is running Arch

@popcornmix
Copy link
Collaborator

I don't believe this affects raspbian. Arch builds a custom kernel, so the problem would be better reported there.

@kad
Copy link
Author

kad commented May 7, 2016

Issue reported in both places...
Arch uses kernel from this repository, and according to PKGBUILD, I don't see how userspace components or additional patches for aufs4 and BFQ would be able to interfere with V4L, thus reported upstream, meaning to this repo.

@popcornmix
Copy link
Collaborator

Arch builds a custom kernel based on the sources here, but with different patches and config options so we can't offer support for issues that affect Arch and not raspbian.

Reproduce the issue with raspbian, and we can help more.

@kad
Copy link
Author

kad commented May 8, 2016

Can you point to any raspbian (test) image that has 4.4.8+ kernel ? places where I have raspbian, all running 4.1.19.

@popcornmix
Copy link
Collaborator

Just use latest raspbian and run rpi-update.
Or wait about a week for an updated raspbian image.

@kad
Copy link
Author

kad commented May 8, 2016

Indeed, with binary kernel from https://github.com/Hexxeh/rpi-firmware I can't reproduce same crash.
There is no code difference between Arch kernel and rpi-firmware in that space, but kernel configs are different.

CC: @kmihelich

At same time, briefly looking at bcm2835-camera.c I can see couple of places where pointers followed without verification that they are not NULL :(

@kmihelich
Copy link

This to me looks very much like a bug report for a kernel, which is what this repository is for. Not for a distribution of Debian rebuilt for ARMv6.

A bug in your code is obviously present, given the logs above. If a bug in your kernel has surfaced due to a different configuration, you should investigate why your code is failing. If you aren't checking your pointers adequately and this somehow isn't a problem in your particular configuration and build environment, that does not mean it is not a problem with your code. Attempting to sweep this under the rug by saying, "you aren't using our configuration, therefore it's not our problem," is a rather unprofessional attitude to take to kernel development.

@pelwell
Copy link
Contributor

pelwell commented May 8, 2016

Bugs in, or the lack of, error handling are some of the most common sources of issues. Although we will investigate and fix any bugs we find, that may not help your users who are still faced with an error message, so check your house is in order.

@kmihelich
Copy link

We're talking about a null pointer dereference error message from the kernel. This message is not coming from userspace code.

@pelwell
Copy link
Contributor

pelwell commented May 8, 2016

Which, if it is in error path, is provoked by an error (hence the name). Since Raspbian doesn't exhibit the crash, the error is likely to be caused by either a different kernel configuration or different user space activity, which you may want to look into.

In other words, if the crash is caused by an error, fixing the crash won't fix the error.

@kmihelich
Copy link

And when the kernel stops dereferencing a null pointer, userspace can be looked into at that time to determine if the issue is still present.

@pelwell
Copy link
Contributor

pelwell commented May 8, 2016

Some people appreciate the heads-up...

@pelwell
Copy link
Contributor

pelwell commented May 8, 2016

Where can I download the precise bcm2835-v4l2 module that corresponds to this trace? I know the kernel commit, but since I want to disassemble it I want to avoid toolchain and build option differences.

@kmihelich
Copy link

http://mirror.archlinuxarm.org/armv6h/core/linux-raspberrypi-4.4.9-1-armv6h.pkg.tar.xz

Keep in mind that newer versions of GCC do a better job of exposing incorrect code that causes these types of issues. I've seen similar issues from in-house kernel code that was only ever built with old versions such as 4.9 and previous; never qualified against current stable versions.

That specific build was against GCC 5.3.0, and you can get a copy of the cross-compile toolchain here to test with:
https://archlinuxarm.org/builder/xtools/5.3.0-5/

Any future builds will be built with GCC 6.1.1, which has a corresponding cross toolchain in the immediate subdirectory.

@pelwell
Copy link
Contributor

pelwell commented May 8, 2016

I've downloaded the archive and extracted the module, but it doesn't match the trace - the .ko doesn't even contain the symbol bm2835_mmal_init.

@kmihelich
Copy link

The modules are gzip'd.

nm bcm2835-v4l2.ko | grep bm2835_mmal_init
00000000 t bm2835_mmal_init
00002ce0 T bm2835_mmal_init_controls

@pelwell
Copy link
Contributor

pelwell commented May 8, 2016

Interesting - the objdump in my toolchain is reporting the aliased name instead - init_module.

@pelwell
Copy link
Contributor

pelwell commented May 8, 2016

If it is indeed a matching component then it is a very strange crash. It looks as though the address of a local variable (resolutions), which has been stored on the stack (both the data and a pointer to it), is now zero (the pointer, not the data).

Line 1877 appears to be the faulting line. At that point, r2 is resolutions (loaded from sp+12 - 00000000), while ip holds the address of resolutions[camera][0] (also zero, because camera (r6) is zero).

@kad
Copy link
Author

kad commented May 8, 2016

FYI, here is config diff between kernel from Raspbian project and Archlinux:
https://gist.github.com/kad/bbc59804a9ce640124719979e531ad2a
Raspbian binary kernel able to boot and load module without problems (same device, same bootloaders, same userspace in both test cases, only difference is /lib/modules/* and /boot/kernel.img)

@kad
Copy link
Author

kad commented May 8, 2016

@pelwell in line 1532 there is potential issue where stack after resolutions[] would be overwritten, due to fact of writing to index that is bigger than MAX_BCM2835_CAMERAS (size of resoltions[]). it shouldn't be the case, as cam_info.num_cameras should be 0 or 1... but still.

@popcornmix
Copy link
Collaborator

So raspbian kernel works okay with arch image?
Does it still work if you rebuild it using arch tools, but raspbian .config? I wonder if gcc version or build flags may have an effect.

@kad
Copy link
Author

kad commented May 8, 2016

Binary kernel from https://github.com/Hexxeh/rpi-firmware works on top of Arch image.
Haven't tried to rebuild it, as so far don't have cross-compilation environment setup for those purposes.
So far was just happy user than actual developer for arch packages :)

popcornmix pushed a commit that referenced this issue Aug 13, 2017
- Supports raw YUV capture, preview, JPEG and H264.
- Uses videobuf2 for data transfer, using dma_buf.
- Uses 3.6.10 timestamping
- Camera power based on use
- Uses immutable input mode on video encoder

Signed-off-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Luke Diamand <luked@broadcom.com>

V4L2: Fixes from 6by9

V4L2: Fix EV values. Add manual shutter speed control

V4L2 EV values should be in units of 1/1000. Corrected.
Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
give manual shutter control. Requires manual exposure mode
to be selected first.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct JPEG Q-factor range

Should be 1-100, not 0-100

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue of driver jamming if STREAMON failed.

Fix issue where the driver was left in a partially enabled
state if STREAMON failed, and would then reject many IOCTLs
as it thought it was streaming.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix ISO controls.

Driver was passing the index to the GPU, and not the desired
ISO value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add flicker avoidance controls

Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
avoidance frequencies.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for frame rate control.

Add support for frame rate (or time per frame as V4L2
inverts it) control via s_parm.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Improve G_FBUF handling so we pass conformance

Return some sane numbers for get framebuffer so that
we pass conformance.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix information advertised through g_vidfmt

Width and height were being stored based on incorrect
values.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for inline H264 headers

Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
to control H264 inline headers.
Requires firmware fix to work correctly, otherwise format
has to be set to H264 before this parameter is set.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix JPEG timestamp issue

JPEG images were coming through from the GPU with timestamp
of 0. Detect this and give current system time instead
of some invalid value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue when switching down JPEG resolution.

JPEG buffer size calculation is based on input resolution.
Input resolution was being configured after output port
format. Caused failures if switching from one JPEG resolution
to a smaller one.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable MJPEG encoding

Requires GPU firmware update to support MJPEG encoder.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct flag settings for compressed formats

Set flags field correctly on enum_fmt_vid_cap for compressed
image formats.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: H264 profile & level ctrls, FPS control and auto exp pri

Several control handling updates.
H264 profile and level controls.
Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
select whether AE is allowed to override the framerate specified.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct BGR24 to RGB24 in format table

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add additional pixel formats. Correct colourspace

Adds the other flavours of YUYV, and NV12.
Corrects the overlay advertised colourspace.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Drop logging msg from info to debug

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Initial pass at scene modes.

Only supports exposure mode and metering modes.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add manual white balance control.

Adds support for V4L2_CID_RED_BALANCE and
V4L2_CID_BLUE_BALANCE. Only has an effect if
V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
V4L2_WHITE_BALANCE_MANUAL selected.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

config: Enable V4L / MMAL driver

V4L2: Increase the MMAL timeout to 3sec

MJPEG codec flush is now taking longer and results
in a kernel panic if the driver has stopped waiting for
the result when it finally completes.
Increase the timeout value from 1 to 3secs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for setting H264_I_PERIOD

Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
to set the frequency with which I frames are produced.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable GPU function for removing padding from images.

GPU can now support arbitrary strides, although may require
additional processing to achieve it. Enable this feature
so that the images delivered are the size requested.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for V4L2_PIX_FMT_BGR32

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Set the colourspace to avoid odd YUV-RGB conversions

Removes the amiguity from the conversion routines and stops
them dropping back to the SD vs HD choice of coeffs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Make video/still threshold a run-time param

Move the define for at what resolution the driver
switches from a video mode capture to a stills mode
capture to module parameters.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix incorrect pool sizing

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add option to disable enum_framesizes.

Gstreamer's handling of a driver that advertises
V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
resolutions is broken. See bug
https://bugzilla.gnome.org/show_bug.cgi?id=726521

Optional parameter of gst_v4l2src_is_broken added.
If non-zero, the driver claims not to support that
ioctl, and gstreamer should be happy again (it
guesses a set of defaults for itself).

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for more image formats

Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD

Request to extend the range from the fairly arbitrary
1000 frames (33 seconds at 30fps). Extend out to the
max range supported (int32 value).
Also allow 0, which is handled by the codec as only
send an I-frame on the first frame and never again.
There may be an exception if it detects a significant
scene change, but there's no easy way around that.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

bcm2835-camera: stop_streaming now has a void return

BCM2835-V4L2: Fix compliance test failures

VIDIOC_TRY_FMT and VIDIOC_S_FMT tests were faling due
to reporting V4L2_COLORSPACE_JPEG when the colour
format wasn't V4L2_PIX_FMT_JPEG.
Now reports V4L2_COLORSPACE_SMPTE170M for YUV formats.

bcm2835 camera planar/packed stride length

Added a field to the mmal_fmt struct used to compute the bytes per line
when using a particular format. This results in the correct stride being
calculated even when the format is planar.

Signed-off-by: Garrett Wilson <g@floft.net>

bcm2835: camera: check for scene not being found

static analysis by cppcheck detected some potential NULL pointer
dereference issues:

[drivers/media/platform/bcm2835/controls.c:854]: (error) Possible null
  pointer dereference: scene
  (and lines 858, 859 too)

it is possible that scene is not found because of an invalue ctrl->val
and is therefore NULL and hence causing a null pointer dereference.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

bcm2835: memcpy port data to m rather than rmsg

static analysis by cppcheck detected a memcpy to rmsg which is
not actually initialized at that point.  The memcpy should be copying
to variable m instead.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

BCM2835-V4L2: Return buffers to videobuf2 on shutdown

#817
Fixes the kernel warning from videobuf2 as buffers
are now returned as they are being flushed on
stop_streaming.

squash: Fixup bcm2835-camera for changes in kernel 4.4 api

v4l2: Fix up driver to upstream timestamp changes

bcm2835-camera: fix a bug in computation of frame timestamp

Fixes #1318

V4L2 driver updates (#1393)

* BCM2835-V4L2: Correct ISO control and add V4L2_CID_ISO_SENSITIVITY_AUTO

#1251

V4L2_CID_ISO_SENSITIVITY was not advertising ISO*1000 as it should.
V4L2_CID_ISO_SENSITIVITY_AUTO was not implemented, so was taking
V4L2_CID_ISO_SENSITIVITY as 0 for auto mode.
Still accepts 0 for auto, but also abides by the new parameter.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add a video_nr parameter.

Adds a kernel parameter "video_nr" to specify the preferred
/dev/videoX device node.
https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=136120&p=905545

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add support for multiple cameras

Ask GPU on load how many cameras have been detected, and
enumerate that number of devices.
Only applicable on the Compute Module as no other device
exposes multiple CSI2 interfaces.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add control of the overlay location and alpha.

Actually do something useful in vidioc_s_fmt_vid_overlay and
vidioc_try_fmt_vid_overlay, rather than effectively having
read-only fields.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: V4L2-Compliance failure fix

VIDIOC_TRY_FMT was failing due to bytesperline not
being set correctly by default.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Make all module parameters static

Clean up to correct variable scope

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

V4L2: Request maximum resolution from GPU

Get resolution information about the sensors from the GPU
and advertise it correctly.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-V4L2: Increase minimum resolution to 32x32

#1498 showed
up that 16x16 is failing to work on the GPU for some reason.

GPU bug being tracked on
raspberrypi/firmware#607
Workaround here by increasing minimum resolution via V4L2
to 32x32.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

[media]: bcm2835-camera: fix compilation error

There is an error when compiling rpi-4.6.y branch:
  CC [M]  drivers/media/platform/bcm2835/bcm2835-camera.o
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .queue_setup = queue_setup,
                 ^
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: note: (near initialization for 'bm2835_mmal_video_qops.queue_setup')

The const void *parg in setup_queue callback is not needed since commit:
df9ecb0.
This commit removes it.

Signed-off-by: Slawomir Stepien <sst@poczta.fm>

bcm2835-camera: Fix max/min error when looping over cameras/resolutions

See: #1447 (comment)

BCM2835-V4L2: Correct handling for BGR24 vs RGB24.

There was a bug in the GPU firmware that had reversed these
two formats.
Detect the old firmware, and reverse the formats if necessary.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-v4l2: Fix a conformance test failure

Format ioctls:
	test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
	warn: v4l2-test-formats.cpp(1195): S_PARM is supported but
		doesn't report V4L2_CAP_TIMEPERFRAME.
	fail: v4l2-test-formats.cpp(1118): node->has_frmintervals
		&& !cap->capability
popcornmix pushed a commit that referenced this issue Aug 13, 2017
#1447
port_parameter_get() failed to account for the header
(u32 id and u32 size) in the size before memcpying
the response into the response buffer, so overrunning
the provided buffer by 8 bytes.

Account for those bytes, and also a belt-and-braces
check to ensure we never copy more than *value_size
bytes into value.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Oct 29, 2017
- Supports raw YUV capture, preview, JPEG and H264.
- Uses videobuf2 for data transfer, using dma_buf.
- Uses 3.6.10 timestamping
- Camera power based on use
- Uses immutable input mode on video encoder

Signed-off-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Luke Diamand <luked@broadcom.com>

V4L2: Fixes from 6by9

V4L2: Fix EV values. Add manual shutter speed control

V4L2 EV values should be in units of 1/1000. Corrected.
Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
give manual shutter control. Requires manual exposure mode
to be selected first.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct JPEG Q-factor range

Should be 1-100, not 0-100

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue of driver jamming if STREAMON failed.

Fix issue where the driver was left in a partially enabled
state if STREAMON failed, and would then reject many IOCTLs
as it thought it was streaming.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix ISO controls.

Driver was passing the index to the GPU, and not the desired
ISO value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add flicker avoidance controls

Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
avoidance frequencies.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for frame rate control.

Add support for frame rate (or time per frame as V4L2
inverts it) control via s_parm.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Improve G_FBUF handling so we pass conformance

Return some sane numbers for get framebuffer so that
we pass conformance.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix information advertised through g_vidfmt

Width and height were being stored based on incorrect
values.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for inline H264 headers

Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
to control H264 inline headers.
Requires firmware fix to work correctly, otherwise format
has to be set to H264 before this parameter is set.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix JPEG timestamp issue

JPEG images were coming through from the GPU with timestamp
of 0. Detect this and give current system time instead
of some invalid value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue when switching down JPEG resolution.

JPEG buffer size calculation is based on input resolution.
Input resolution was being configured after output port
format. Caused failures if switching from one JPEG resolution
to a smaller one.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable MJPEG encoding

Requires GPU firmware update to support MJPEG encoder.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct flag settings for compressed formats

Set flags field correctly on enum_fmt_vid_cap for compressed
image formats.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: H264 profile & level ctrls, FPS control and auto exp pri

Several control handling updates.
H264 profile and level controls.
Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
select whether AE is allowed to override the framerate specified.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct BGR24 to RGB24 in format table

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add additional pixel formats. Correct colourspace

Adds the other flavours of YUYV, and NV12.
Corrects the overlay advertised colourspace.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Drop logging msg from info to debug

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Initial pass at scene modes.

Only supports exposure mode and metering modes.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add manual white balance control.

Adds support for V4L2_CID_RED_BALANCE and
V4L2_CID_BLUE_BALANCE. Only has an effect if
V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
V4L2_WHITE_BALANCE_MANUAL selected.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

config: Enable V4L / MMAL driver

V4L2: Increase the MMAL timeout to 3sec

MJPEG codec flush is now taking longer and results
in a kernel panic if the driver has stopped waiting for
the result when it finally completes.
Increase the timeout value from 1 to 3secs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for setting H264_I_PERIOD

Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
to set the frequency with which I frames are produced.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable GPU function for removing padding from images.

GPU can now support arbitrary strides, although may require
additional processing to achieve it. Enable this feature
so that the images delivered are the size requested.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for V4L2_PIX_FMT_BGR32

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Set the colourspace to avoid odd YUV-RGB conversions

Removes the amiguity from the conversion routines and stops
them dropping back to the SD vs HD choice of coeffs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Make video/still threshold a run-time param

Move the define for at what resolution the driver
switches from a video mode capture to a stills mode
capture to module parameters.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix incorrect pool sizing

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add option to disable enum_framesizes.

Gstreamer's handling of a driver that advertises
V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
resolutions is broken. See bug
https://bugzilla.gnome.org/show_bug.cgi?id=726521

Optional parameter of gst_v4l2src_is_broken added.
If non-zero, the driver claims not to support that
ioctl, and gstreamer should be happy again (it
guesses a set of defaults for itself).

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for more image formats

Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD

Request to extend the range from the fairly arbitrary
1000 frames (33 seconds at 30fps). Extend out to the
max range supported (int32 value).
Also allow 0, which is handled by the codec as only
send an I-frame on the first frame and never again.
There may be an exception if it detects a significant
scene change, but there's no easy way around that.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

bcm2835-camera: stop_streaming now has a void return

BCM2835-V4L2: Fix compliance test failures

VIDIOC_TRY_FMT and VIDIOC_S_FMT tests were faling due
to reporting V4L2_COLORSPACE_JPEG when the colour
format wasn't V4L2_PIX_FMT_JPEG.
Now reports V4L2_COLORSPACE_SMPTE170M for YUV formats.

bcm2835 camera planar/packed stride length

Added a field to the mmal_fmt struct used to compute the bytes per line
when using a particular format. This results in the correct stride being
calculated even when the format is planar.

Signed-off-by: Garrett Wilson <g@floft.net>

bcm2835: camera: check for scene not being found

static analysis by cppcheck detected some potential NULL pointer
dereference issues:

[drivers/media/platform/bcm2835/controls.c:854]: (error) Possible null
  pointer dereference: scene
  (and lines 858, 859 too)

it is possible that scene is not found because of an invalue ctrl->val
and is therefore NULL and hence causing a null pointer dereference.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

bcm2835: memcpy port data to m rather than rmsg

static analysis by cppcheck detected a memcpy to rmsg which is
not actually initialized at that point.  The memcpy should be copying
to variable m instead.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

BCM2835-V4L2: Return buffers to videobuf2 on shutdown

#817
Fixes the kernel warning from videobuf2 as buffers
are now returned as they are being flushed on
stop_streaming.

squash: Fixup bcm2835-camera for changes in kernel 4.4 api

v4l2: Fix up driver to upstream timestamp changes

bcm2835-camera: fix a bug in computation of frame timestamp

Fixes #1318

V4L2 driver updates (#1393)

* BCM2835-V4L2: Correct ISO control and add V4L2_CID_ISO_SENSITIVITY_AUTO

#1251

V4L2_CID_ISO_SENSITIVITY was not advertising ISO*1000 as it should.
V4L2_CID_ISO_SENSITIVITY_AUTO was not implemented, so was taking
V4L2_CID_ISO_SENSITIVITY as 0 for auto mode.
Still accepts 0 for auto, but also abides by the new parameter.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add a video_nr parameter.

Adds a kernel parameter "video_nr" to specify the preferred
/dev/videoX device node.
https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=136120&p=905545

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add support for multiple cameras

Ask GPU on load how many cameras have been detected, and
enumerate that number of devices.
Only applicable on the Compute Module as no other device
exposes multiple CSI2 interfaces.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add control of the overlay location and alpha.

Actually do something useful in vidioc_s_fmt_vid_overlay and
vidioc_try_fmt_vid_overlay, rather than effectively having
read-only fields.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: V4L2-Compliance failure fix

VIDIOC_TRY_FMT was failing due to bytesperline not
being set correctly by default.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Make all module parameters static

Clean up to correct variable scope

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

V4L2: Request maximum resolution from GPU

Get resolution information about the sensors from the GPU
and advertise it correctly.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-V4L2: Increase minimum resolution to 32x32

#1498 showed
up that 16x16 is failing to work on the GPU for some reason.

GPU bug being tracked on
raspberrypi/firmware#607
Workaround here by increasing minimum resolution via V4L2
to 32x32.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

[media]: bcm2835-camera: fix compilation error

There is an error when compiling rpi-4.6.y branch:
  CC [M]  drivers/media/platform/bcm2835/bcm2835-camera.o
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .queue_setup = queue_setup,
                 ^
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: note: (near initialization for 'bm2835_mmal_video_qops.queue_setup')

The const void *parg in setup_queue callback is not needed since commit:
df9ecb0.
This commit removes it.

Signed-off-by: Slawomir Stepien <sst@poczta.fm>

bcm2835-camera: Fix max/min error when looping over cameras/resolutions

See: #1447 (comment)

BCM2835-V4L2: Correct handling for BGR24 vs RGB24.

There was a bug in the GPU firmware that had reversed these
two formats.
Detect the old firmware, and reverse the formats if necessary.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-v4l2: Fix a conformance test failure

Format ioctls:
	test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
	warn: v4l2-test-formats.cpp(1195): S_PARM is supported but
		doesn't report V4L2_CAP_TIMEPERFRAME.
	fail: v4l2-test-formats.cpp(1118): node->has_frmintervals
		&& !cap->capability
popcornmix pushed a commit that referenced this issue Oct 29, 2017
#1447
port_parameter_get() failed to account for the header
(u32 id and u32 size) in the size before memcpying
the response into the response buffer, so overrunning
the provided buffer by 8 bytes.

Account for those bytes, and also a belt-and-braces
check to ensure we never copy more than *value_size
bytes into value.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
raspbian-autopush pushed a commit to raspbian-packages/linux-4.9 that referenced this issue Nov 2, 2017
commit e5a33f9
Author: Vincent Sanders <vincent.sanders@collabora.co.uk>
Date:   Wed Jan 30 12:45:18 2013 +0000

    bcm2835: add v4l2 camera device
    
    - Supports raw YUV capture, preview, JPEG and H264.
    - Uses videobuf2 for data transfer, using dma_buf.
    - Uses 3.6.10 timestamping
    - Camera power based on use
    - Uses immutable input mode on video encoder
    
    Signed-off-by: Daniel Stone <daniels@collabora.com>
    Signed-off-by: Luke Diamand <luked@broadcom.com>
    
    V4L2: Fixes from 6by9
    
    V4L2: Fix EV values. Add manual shutter speed control
    
    V4L2 EV values should be in units of 1/1000. Corrected.
    Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
    give manual shutter control. Requires manual exposure mode
    to be selected first.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Correct JPEG Q-factor range
    
    Should be 1-100, not 0-100
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix issue of driver jamming if STREAMON failed.
    
    Fix issue where the driver was left in a partially enabled
    state if STREAMON failed, and would then reject many IOCTLs
    as it thought it was streaming.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix ISO controls.
    
    Driver was passing the index to the GPU, and not the desired
    ISO value.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add flicker avoidance controls
    
    Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
    avoidance frequencies.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for frame rate control.
    
    Add support for frame rate (or time per frame as V4L2
    inverts it) control via s_parm.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Improve G_FBUF handling so we pass conformance
    
    Return some sane numbers for get framebuffer so that
    we pass conformance.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix information advertised through g_vidfmt
    
    Width and height were being stored based on incorrect
    values.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for inline H264 headers
    
    Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
    to control H264 inline headers.
    Requires firmware fix to work correctly, otherwise format
    has to be set to H264 before this parameter is set.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix JPEG timestamp issue
    
    JPEG images were coming through from the GPU with timestamp
    of 0. Detect this and give current system time instead
    of some invalid value.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix issue when switching down JPEG resolution.
    
    JPEG buffer size calculation is based on input resolution.
    Input resolution was being configured after output port
    format. Caused failures if switching from one JPEG resolution
    to a smaller one.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Enable MJPEG encoding
    
    Requires GPU firmware update to support MJPEG encoder.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Correct flag settings for compressed formats
    
    Set flags field correctly on enum_fmt_vid_cap for compressed
    image formats.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: H264 profile & level ctrls, FPS control and auto exp pri
    
    Several control handling updates.
    H264 profile and level controls.
    Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
    select whether AE is allowed to override the framerate specified.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Correct BGR24 to RGB24 in format table
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add additional pixel formats. Correct colourspace
    
    Adds the other flavours of YUYV, and NV12.
    Corrects the overlay advertised colourspace.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Drop logging msg from info to debug
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Initial pass at scene modes.
    
    Only supports exposure mode and metering modes.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add manual white balance control.
    
    Adds support for V4L2_CID_RED_BALANCE and
    V4L2_CID_BLUE_BALANCE. Only has an effect if
    V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
    V4L2_WHITE_BALANCE_MANUAL selected.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    config: Enable V4L / MMAL driver
    
    V4L2: Increase the MMAL timeout to 3sec
    
    MJPEG codec flush is now taking longer and results
    in a kernel panic if the driver has stopped waiting for
    the result when it finally completes.
    Increase the timeout value from 1 to 3secs.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for setting H264_I_PERIOD
    
    Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
    to set the frequency with which I frames are produced.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Enable GPU function for removing padding from images.
    
    GPU can now support arbitrary strides, although may require
    additional processing to achieve it. Enable this feature
    so that the images delivered are the size requested.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for V4L2_PIX_FMT_BGR32
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Set the colourspace to avoid odd YUV-RGB conversions
    
    Removes the amiguity from the conversion routines and stops
    them dropping back to the SD vs HD choice of coeffs.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Make video/still threshold a run-time param
    
    Move the define for at what resolution the driver
    switches from a video mode capture to a stills mode
    capture to module parameters.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix incorrect pool sizing
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add option to disable enum_framesizes.
    
    Gstreamer's handling of a driver that advertises
    V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
    resolutions is broken. See bug
    https://bugzilla.gnome.org/show_bug.cgi?id=726521
    
    Optional parameter of gst_v4l2src_is_broken added.
    If non-zero, the driver claims not to support that
    ioctl, and gstreamer should be happy again (it
    guesses a set of defaults for itself).
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for more image formats
    
    Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
    
    Request to extend the range from the fairly arbitrary
    1000 frames (33 seconds at 30fps). Extend out to the
    max range supported (int32 value).
    Also allow 0, which is handled by the codec as only
    send an I-frame on the first frame and never again.
    There may be an exception if it detects a significant
    scene change, but there's no easy way around that.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    bcm2835-camera: stop_streaming now has a void return
    
    BCM2835-V4L2: Fix compliance test failures
    
    VIDIOC_TRY_FMT and VIDIOC_S_FMT tests were faling due
    to reporting V4L2_COLORSPACE_JPEG when the colour
    format wasn't V4L2_PIX_FMT_JPEG.
    Now reports V4L2_COLORSPACE_SMPTE170M for YUV formats.
    
    bcm2835 camera planar/packed stride length
    
    Added a field to the mmal_fmt struct used to compute the bytes per line
    when using a particular format. This results in the correct stride being
    calculated even when the format is planar.
    
    Signed-off-by: Garrett Wilson <g@floft.net>
    
    bcm2835: camera: check for scene not being found
    
    static analysis by cppcheck detected some potential NULL pointer
    dereference issues:
    
    [drivers/media/platform/bcm2835/controls.c:854]: (error) Possible null
      pointer dereference: scene
      (and lines 858, 859 too)
    
    it is possible that scene is not found because of an invalue ctrl->val
    and is therefore NULL and hence causing a null pointer dereference.
    
    Signed-off-by: Colin Ian King <colin.king@canonical.com>
    
    bcm2835: memcpy port data to m rather than rmsg
    
    static analysis by cppcheck detected a memcpy to rmsg which is
    not actually initialized at that point.  The memcpy should be copying
    to variable m instead.
    
    Signed-off-by: Colin Ian King <colin.king@canonical.com>
    
    BCM2835-V4L2: Return buffers to videobuf2 on shutdown
    
    raspberrypi/linux#817
    Fixes the kernel warning from videobuf2 as buffers
    are now returned as they are being flushed on
    stop_streaming.
    
    squash: Fixup bcm2835-camera for changes in kernel 4.4 api
    
    v4l2: Fix up driver to upstream timestamp changes
    
    bcm2835-camera: fix a bug in computation of frame timestamp
    
    Fixes #1318
    
    V4L2 driver updates (#1393)
    
    * BCM2835-V4L2: Correct ISO control and add V4L2_CID_ISO_SENSITIVITY_AUTO
    
    raspberrypi/linux#1251
    
    V4L2_CID_ISO_SENSITIVITY was not advertising ISO*1000 as it should.
    V4L2_CID_ISO_SENSITIVITY_AUTO was not implemented, so was taking
    V4L2_CID_ISO_SENSITIVITY as 0 for auto mode.
    Still accepts 0 for auto, but also abides by the new parameter.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: Add a video_nr parameter.
    
    Adds a kernel parameter "video_nr" to specify the preferred
    /dev/videoX device node.
    https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=136120&p=905545
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: Add support for multiple cameras
    
    Ask GPU on load how many cameras have been detected, and
    enumerate that number of devices.
    Only applicable on the Compute Module as no other device
    exposes multiple CSI2 interfaces.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: Add control of the overlay location and alpha.
    
    Actually do something useful in vidioc_s_fmt_vid_overlay and
    vidioc_try_fmt_vid_overlay, rather than effectively having
    read-only fields.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: V4L2-Compliance failure fix
    
    VIDIOC_TRY_FMT was failing due to bytesperline not
    being set correctly by default.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: Make all module parameters static
    
    Clean up to correct variable scope
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    V4L2: Request maximum resolution from GPU
    
    Get resolution information about the sensors from the GPU
    and advertise it correctly.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    BCM2835-V4L2: Increase minimum resolution to 32x32
    
    raspberrypi/linux#1498 showed
    up that 16x16 is failing to work on the GPU for some reason.
    
    GPU bug being tracked on
    raspberrypi/firmware#607
    Workaround here by increasing minimum resolution via V4L2
    to 32x32.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    [media]: bcm2835-camera: fix compilation error
    
    There is an error when compiling rpi-4.6.y branch:
      CC [M]  drivers/media/platform/bcm2835/bcm2835-camera.o
    drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
      .queue_setup = queue_setup,
                     ^
    drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: note: (near initialization for 'bm2835_mmal_video_qops.queue_setup')
    
    The const void *parg in setup_queue callback is not needed since commit:
    df9ecb0.
    This commit removes it.
    
    Signed-off-by: Slawomir Stepien <sst@poczta.fm>
    
    bcm2835-camera: Fix max/min error when looping over cameras/resolutions
    
    See: raspberrypi/linux#1447 (comment)
    
    BCM2835-V4L2: Correct handling for BGR24 vs RGB24.
    
    There was a bug in the GPU firmware that had reversed these
    two formats.
    Detect the old firmware, and reverse the formats if necessary.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    BCM2835-v4l2: Fix a conformance test failure
    
    Format ioctls:
            test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
            warn: v4l2-test-formats.cpp(1195): S_PARM is supported but
                    doesn't report V4L2_CAP_TIMEPERFRAME.
            fail: v4l2-test-formats.cpp(1118): node->has_frmintervals
                    && !cap->capability


Gbp-Pq: Topic rpi
Gbp-Pq: Name rpi_1049_e5a33f9d545dd69ce73f18b874eb9f699a3cc66f.patch
raspbian-autopush pushed a commit to raspbian-packages/linux-4.9 that referenced this issue Nov 2, 2017
commit 8d2ad4f
Author: Dave Stevenson <dave.stevenson@raspberrypi.org>
Date:   Fri Mar 10 14:43:15 2017 +0000

    bcm2835-v4l2: Fix buffer overflow problem
    
    raspberrypi/linux#1447
    port_parameter_get() failed to account for the header
    (u32 id and u32 size) in the size before memcpying
    the response into the response buffer, so overrunning
    the provided buffer by 8 bytes.
    
    Account for those bytes, and also a belt-and-braces
    check to ensure we never copy more than *value_size
    bytes into value.
    
    Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>


Gbp-Pq: Topic rpi
Gbp-Pq: Name rpi_1197_8d2ad4f0d4a6f53f21ce8f35391f9d7504661b39.patch
pelwell pushed a commit to pelwell/linux that referenced this issue Nov 18, 2017
- Supports raw YUV capture, preview, JPEG and H264.
- Uses videobuf2 for data transfer, using dma_buf.
- Uses 3.6.10 timestamping
- Camera power based on use
- Uses immutable input mode on video encoder

Signed-off-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Luke Diamand <luked@broadcom.com>

V4L2: Fixes from 6by9

V4L2: Fix EV values. Add manual shutter speed control

V4L2 EV values should be in units of 1/1000. Corrected.
Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
give manual shutter control. Requires manual exposure mode
to be selected first.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct JPEG Q-factor range

Should be 1-100, not 0-100

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue of driver jamming if STREAMON failed.

Fix issue where the driver was left in a partially enabled
state if STREAMON failed, and would then reject many IOCTLs
as it thought it was streaming.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix ISO controls.

Driver was passing the index to the GPU, and not the desired
ISO value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add flicker avoidance controls

Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
avoidance frequencies.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for frame rate control.

Add support for frame rate (or time per frame as V4L2
inverts it) control via s_parm.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Improve G_FBUF handling so we pass conformance

Return some sane numbers for get framebuffer so that
we pass conformance.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix information advertised through g_vidfmt

Width and height were being stored based on incorrect
values.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for inline H264 headers

Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
to control H264 inline headers.
Requires firmware fix to work correctly, otherwise format
has to be set to H264 before this parameter is set.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix JPEG timestamp issue

JPEG images were coming through from the GPU with timestamp
of 0. Detect this and give current system time instead
of some invalid value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue when switching down JPEG resolution.

JPEG buffer size calculation is based on input resolution.
Input resolution was being configured after output port
format. Caused failures if switching from one JPEG resolution
to a smaller one.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable MJPEG encoding

Requires GPU firmware update to support MJPEG encoder.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct flag settings for compressed formats

Set flags field correctly on enum_fmt_vid_cap for compressed
image formats.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: H264 profile & level ctrls, FPS control and auto exp pri

Several control handling updates.
H264 profile and level controls.
Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
select whether AE is allowed to override the framerate specified.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct BGR24 to RGB24 in format table

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add additional pixel formats. Correct colourspace

Adds the other flavours of YUYV, and NV12.
Corrects the overlay advertised colourspace.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Drop logging msg from info to debug

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Initial pass at scene modes.

Only supports exposure mode and metering modes.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add manual white balance control.

Adds support for V4L2_CID_RED_BALANCE and
V4L2_CID_BLUE_BALANCE. Only has an effect if
V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
V4L2_WHITE_BALANCE_MANUAL selected.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

config: Enable V4L / MMAL driver

V4L2: Increase the MMAL timeout to 3sec

MJPEG codec flush is now taking longer and results
in a kernel panic if the driver has stopped waiting for
the result when it finally completes.
Increase the timeout value from 1 to 3secs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for setting H264_I_PERIOD

Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
to set the frequency with which I frames are produced.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable GPU function for removing padding from images.

GPU can now support arbitrary strides, although may require
additional processing to achieve it. Enable this feature
so that the images delivered are the size requested.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for V4L2_PIX_FMT_BGR32

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Set the colourspace to avoid odd YUV-RGB conversions

Removes the amiguity from the conversion routines and stops
them dropping back to the SD vs HD choice of coeffs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Make video/still threshold a run-time param

Move the define for at what resolution the driver
switches from a video mode capture to a stills mode
capture to module parameters.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix incorrect pool sizing

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add option to disable enum_framesizes.

Gstreamer's handling of a driver that advertises
V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
resolutions is broken. See bug
https://bugzilla.gnome.org/show_bug.cgi?id=726521

Optional parameter of gst_v4l2src_is_broken added.
If non-zero, the driver claims not to support that
ioctl, and gstreamer should be happy again (it
guesses a set of defaults for itself).

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for more image formats

Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD

Request to extend the range from the fairly arbitrary
1000 frames (33 seconds at 30fps). Extend out to the
max range supported (int32 value).
Also allow 0, which is handled by the codec as only
send an I-frame on the first frame and never again.
There may be an exception if it detects a significant
scene change, but there's no easy way around that.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

bcm2835-camera: stop_streaming now has a void return

BCM2835-V4L2: Fix compliance test failures

VIDIOC_TRY_FMT and VIDIOC_S_FMT tests were faling due
to reporting V4L2_COLORSPACE_JPEG when the colour
format wasn't V4L2_PIX_FMT_JPEG.
Now reports V4L2_COLORSPACE_SMPTE170M for YUV formats.

bcm2835 camera planar/packed stride length

Added a field to the mmal_fmt struct used to compute the bytes per line
when using a particular format. This results in the correct stride being
calculated even when the format is planar.

Signed-off-by: Garrett Wilson <g@floft.net>

bcm2835: camera: check for scene not being found

static analysis by cppcheck detected some potential NULL pointer
dereference issues:

[drivers/media/platform/bcm2835/controls.c:854]: (error) Possible null
  pointer dereference: scene
  (and lines 858, 859 too)

it is possible that scene is not found because of an invalue ctrl->val
and is therefore NULL and hence causing a null pointer dereference.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

bcm2835: memcpy port data to m rather than rmsg

static analysis by cppcheck detected a memcpy to rmsg which is
not actually initialized at that point.  The memcpy should be copying
to variable m instead.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

BCM2835-V4L2: Return buffers to videobuf2 on shutdown

raspberrypi#817
Fixes the kernel warning from videobuf2 as buffers
are now returned as they are being flushed on
stop_streaming.

squash: Fixup bcm2835-camera for changes in kernel 4.4 api

v4l2: Fix up driver to upstream timestamp changes

bcm2835-camera: fix a bug in computation of frame timestamp

Fixes raspberrypi#1318

V4L2 driver updates (raspberrypi#1393)

* BCM2835-V4L2: Correct ISO control and add V4L2_CID_ISO_SENSITIVITY_AUTO

raspberrypi#1251

V4L2_CID_ISO_SENSITIVITY was not advertising ISO*1000 as it should.
V4L2_CID_ISO_SENSITIVITY_AUTO was not implemented, so was taking
V4L2_CID_ISO_SENSITIVITY as 0 for auto mode.
Still accepts 0 for auto, but also abides by the new parameter.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add a video_nr parameter.

Adds a kernel parameter "video_nr" to specify the preferred
/dev/videoX device node.
https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=136120&p=905545

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add support for multiple cameras

Ask GPU on load how many cameras have been detected, and
enumerate that number of devices.
Only applicable on the Compute Module as no other device
exposes multiple CSI2 interfaces.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add control of the overlay location and alpha.

Actually do something useful in vidioc_s_fmt_vid_overlay and
vidioc_try_fmt_vid_overlay, rather than effectively having
read-only fields.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: V4L2-Compliance failure fix

VIDIOC_TRY_FMT was failing due to bytesperline not
being set correctly by default.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Make all module parameters static

Clean up to correct variable scope

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

V4L2: Request maximum resolution from GPU

Get resolution information about the sensors from the GPU
and advertise it correctly.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-V4L2: Increase minimum resolution to 32x32

raspberrypi#1498 showed
up that 16x16 is failing to work on the GPU for some reason.

GPU bug being tracked on
raspberrypi/firmware#607
Workaround here by increasing minimum resolution via V4L2
to 32x32.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

[media]: bcm2835-camera: fix compilation error

There is an error when compiling rpi-4.6.y branch:
  CC [M]  drivers/media/platform/bcm2835/bcm2835-camera.o
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .queue_setup = queue_setup,
                 ^
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: note: (near initialization for 'bm2835_mmal_video_qops.queue_setup')

The const void *parg in setup_queue callback is not needed since commit:
df9ecb0.
This commit removes it.

Signed-off-by: Slawomir Stepien <sst@poczta.fm>

bcm2835-camera: Fix max/min error when looping over cameras/resolutions

See: raspberrypi#1447 (comment)

BCM2835-V4L2: Correct handling for BGR24 vs RGB24.

There was a bug in the GPU firmware that had reversed these
two formats.
Detect the old firmware, and reverse the formats if necessary.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-v4l2: Fix a conformance test failure

Format ioctls:
	test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
	warn: v4l2-test-formats.cpp(1195): S_PARM is supported but
		doesn't report V4L2_CAP_TIMEPERFRAME.
	fail: v4l2-test-formats.cpp(1118): node->has_frmintervals
		&& !cap->capability
pelwell pushed a commit to pelwell/linux that referenced this issue Nov 19, 2017
- Supports raw YUV capture, preview, JPEG and H264.
- Uses videobuf2 for data transfer, using dma_buf.
- Uses 3.6.10 timestamping
- Camera power based on use
- Uses immutable input mode on video encoder

Signed-off-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Luke Diamand <luked@broadcom.com>

V4L2: Fixes from 6by9

V4L2: Fix EV values. Add manual shutter speed control

V4L2 EV values should be in units of 1/1000. Corrected.
Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
give manual shutter control. Requires manual exposure mode
to be selected first.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct JPEG Q-factor range

Should be 1-100, not 0-100

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue of driver jamming if STREAMON failed.

Fix issue where the driver was left in a partially enabled
state if STREAMON failed, and would then reject many IOCTLs
as it thought it was streaming.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix ISO controls.

Driver was passing the index to the GPU, and not the desired
ISO value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add flicker avoidance controls

Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
avoidance frequencies.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for frame rate control.

Add support for frame rate (or time per frame as V4L2
inverts it) control via s_parm.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Improve G_FBUF handling so we pass conformance

Return some sane numbers for get framebuffer so that
we pass conformance.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix information advertised through g_vidfmt

Width and height were being stored based on incorrect
values.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for inline H264 headers

Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
to control H264 inline headers.
Requires firmware fix to work correctly, otherwise format
has to be set to H264 before this parameter is set.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix JPEG timestamp issue

JPEG images were coming through from the GPU with timestamp
of 0. Detect this and give current system time instead
of some invalid value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue when switching down JPEG resolution.

JPEG buffer size calculation is based on input resolution.
Input resolution was being configured after output port
format. Caused failures if switching from one JPEG resolution
to a smaller one.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable MJPEG encoding

Requires GPU firmware update to support MJPEG encoder.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct flag settings for compressed formats

Set flags field correctly on enum_fmt_vid_cap for compressed
image formats.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: H264 profile & level ctrls, FPS control and auto exp pri

Several control handling updates.
H264 profile and level controls.
Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
select whether AE is allowed to override the framerate specified.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct BGR24 to RGB24 in format table

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add additional pixel formats. Correct colourspace

Adds the other flavours of YUYV, and NV12.
Corrects the overlay advertised colourspace.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Drop logging msg from info to debug

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Initial pass at scene modes.

Only supports exposure mode and metering modes.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add manual white balance control.

Adds support for V4L2_CID_RED_BALANCE and
V4L2_CID_BLUE_BALANCE. Only has an effect if
V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
V4L2_WHITE_BALANCE_MANUAL selected.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

config: Enable V4L / MMAL driver

V4L2: Increase the MMAL timeout to 3sec

MJPEG codec flush is now taking longer and results
in a kernel panic if the driver has stopped waiting for
the result when it finally completes.
Increase the timeout value from 1 to 3secs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for setting H264_I_PERIOD

Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
to set the frequency with which I frames are produced.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable GPU function for removing padding from images.

GPU can now support arbitrary strides, although may require
additional processing to achieve it. Enable this feature
so that the images delivered are the size requested.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for V4L2_PIX_FMT_BGR32

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Set the colourspace to avoid odd YUV-RGB conversions

Removes the amiguity from the conversion routines and stops
them dropping back to the SD vs HD choice of coeffs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Make video/still threshold a run-time param

Move the define for at what resolution the driver
switches from a video mode capture to a stills mode
capture to module parameters.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix incorrect pool sizing

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add option to disable enum_framesizes.

Gstreamer's handling of a driver that advertises
V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
resolutions is broken. See bug
https://bugzilla.gnome.org/show_bug.cgi?id=726521

Optional parameter of gst_v4l2src_is_broken added.
If non-zero, the driver claims not to support that
ioctl, and gstreamer should be happy again (it
guesses a set of defaults for itself).

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for more image formats

Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD

Request to extend the range from the fairly arbitrary
1000 frames (33 seconds at 30fps). Extend out to the
max range supported (int32 value).
Also allow 0, which is handled by the codec as only
send an I-frame on the first frame and never again.
There may be an exception if it detects a significant
scene change, but there's no easy way around that.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

bcm2835-camera: stop_streaming now has a void return

BCM2835-V4L2: Fix compliance test failures

VIDIOC_TRY_FMT and VIDIOC_S_FMT tests were faling due
to reporting V4L2_COLORSPACE_JPEG when the colour
format wasn't V4L2_PIX_FMT_JPEG.
Now reports V4L2_COLORSPACE_SMPTE170M for YUV formats.

bcm2835 camera planar/packed stride length

Added a field to the mmal_fmt struct used to compute the bytes per line
when using a particular format. This results in the correct stride being
calculated even when the format is planar.

Signed-off-by: Garrett Wilson <g@floft.net>

bcm2835: camera: check for scene not being found

static analysis by cppcheck detected some potential NULL pointer
dereference issues:

[drivers/media/platform/bcm2835/controls.c:854]: (error) Possible null
  pointer dereference: scene
  (and lines 858, 859 too)

it is possible that scene is not found because of an invalue ctrl->val
and is therefore NULL and hence causing a null pointer dereference.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

bcm2835: memcpy port data to m rather than rmsg

static analysis by cppcheck detected a memcpy to rmsg which is
not actually initialized at that point.  The memcpy should be copying
to variable m instead.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

BCM2835-V4L2: Return buffers to videobuf2 on shutdown

raspberrypi#817
Fixes the kernel warning from videobuf2 as buffers
are now returned as they are being flushed on
stop_streaming.

squash: Fixup bcm2835-camera for changes in kernel 4.4 api

v4l2: Fix up driver to upstream timestamp changes

bcm2835-camera: fix a bug in computation of frame timestamp

Fixes raspberrypi#1318

V4L2 driver updates (raspberrypi#1393)

* BCM2835-V4L2: Correct ISO control and add V4L2_CID_ISO_SENSITIVITY_AUTO

raspberrypi#1251

V4L2_CID_ISO_SENSITIVITY was not advertising ISO*1000 as it should.
V4L2_CID_ISO_SENSITIVITY_AUTO was not implemented, so was taking
V4L2_CID_ISO_SENSITIVITY as 0 for auto mode.
Still accepts 0 for auto, but also abides by the new parameter.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add a video_nr parameter.

Adds a kernel parameter "video_nr" to specify the preferred
/dev/videoX device node.
https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=136120&p=905545

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add support for multiple cameras

Ask GPU on load how many cameras have been detected, and
enumerate that number of devices.
Only applicable on the Compute Module as no other device
exposes multiple CSI2 interfaces.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add control of the overlay location and alpha.

Actually do something useful in vidioc_s_fmt_vid_overlay and
vidioc_try_fmt_vid_overlay, rather than effectively having
read-only fields.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: V4L2-Compliance failure fix

VIDIOC_TRY_FMT was failing due to bytesperline not
being set correctly by default.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Make all module parameters static

Clean up to correct variable scope

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

V4L2: Request maximum resolution from GPU

Get resolution information about the sensors from the GPU
and advertise it correctly.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-V4L2: Increase minimum resolution to 32x32

raspberrypi#1498 showed
up that 16x16 is failing to work on the GPU for some reason.

GPU bug being tracked on
raspberrypi/firmware#607
Workaround here by increasing minimum resolution via V4L2
to 32x32.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

[media]: bcm2835-camera: fix compilation error

There is an error when compiling rpi-4.6.y branch:
  CC [M]  drivers/media/platform/bcm2835/bcm2835-camera.o
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .queue_setup = queue_setup,
                 ^
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: note: (near initialization for 'bm2835_mmal_video_qops.queue_setup')

The const void *parg in setup_queue callback is not needed since commit:
df9ecb0.
This commit removes it.

Signed-off-by: Slawomir Stepien <sst@poczta.fm>

bcm2835-camera: Fix max/min error when looping over cameras/resolutions

See: raspberrypi#1447 (comment)

BCM2835-V4L2: Correct handling for BGR24 vs RGB24.

There was a bug in the GPU firmware that had reversed these
two formats.
Detect the old firmware, and reverse the formats if necessary.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-v4l2: Fix a conformance test failure

Format ioctls:
	test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
	warn: v4l2-test-formats.cpp(1195): S_PARM is supported but
		doesn't report V4L2_CAP_TIMEPERFRAME.
	fail: v4l2-test-formats.cpp(1118): node->has_frmintervals
		&& !cap->capability
pelwell pushed a commit to pelwell/linux that referenced this issue Nov 19, 2017
- Supports raw YUV capture, preview, JPEG and H264.
- Uses videobuf2 for data transfer, using dma_buf.
- Uses 3.6.10 timestamping
- Camera power based on use
- Uses immutable input mode on video encoder

Signed-off-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Luke Diamand <luked@broadcom.com>

V4L2: Fixes from 6by9

V4L2: Fix EV values. Add manual shutter speed control

V4L2 EV values should be in units of 1/1000. Corrected.
Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
give manual shutter control. Requires manual exposure mode
to be selected first.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct JPEG Q-factor range

Should be 1-100, not 0-100

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue of driver jamming if STREAMON failed.

Fix issue where the driver was left in a partially enabled
state if STREAMON failed, and would then reject many IOCTLs
as it thought it was streaming.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix ISO controls.

Driver was passing the index to the GPU, and not the desired
ISO value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add flicker avoidance controls

Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
avoidance frequencies.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for frame rate control.

Add support for frame rate (or time per frame as V4L2
inverts it) control via s_parm.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Improve G_FBUF handling so we pass conformance

Return some sane numbers for get framebuffer so that
we pass conformance.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix information advertised through g_vidfmt

Width and height were being stored based on incorrect
values.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for inline H264 headers

Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
to control H264 inline headers.
Requires firmware fix to work correctly, otherwise format
has to be set to H264 before this parameter is set.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix JPEG timestamp issue

JPEG images were coming through from the GPU with timestamp
of 0. Detect this and give current system time instead
of some invalid value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue when switching down JPEG resolution.

JPEG buffer size calculation is based on input resolution.
Input resolution was being configured after output port
format. Caused failures if switching from one JPEG resolution
to a smaller one.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable MJPEG encoding

Requires GPU firmware update to support MJPEG encoder.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct flag settings for compressed formats

Set flags field correctly on enum_fmt_vid_cap for compressed
image formats.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: H264 profile & level ctrls, FPS control and auto exp pri

Several control handling updates.
H264 profile and level controls.
Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
select whether AE is allowed to override the framerate specified.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct BGR24 to RGB24 in format table

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add additional pixel formats. Correct colourspace

Adds the other flavours of YUYV, and NV12.
Corrects the overlay advertised colourspace.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Drop logging msg from info to debug

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Initial pass at scene modes.

Only supports exposure mode and metering modes.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add manual white balance control.

Adds support for V4L2_CID_RED_BALANCE and
V4L2_CID_BLUE_BALANCE. Only has an effect if
V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
V4L2_WHITE_BALANCE_MANUAL selected.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

config: Enable V4L / MMAL driver

V4L2: Increase the MMAL timeout to 3sec

MJPEG codec flush is now taking longer and results
in a kernel panic if the driver has stopped waiting for
the result when it finally completes.
Increase the timeout value from 1 to 3secs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for setting H264_I_PERIOD

Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
to set the frequency with which I frames are produced.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable GPU function for removing padding from images.

GPU can now support arbitrary strides, although may require
additional processing to achieve it. Enable this feature
so that the images delivered are the size requested.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for V4L2_PIX_FMT_BGR32

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Set the colourspace to avoid odd YUV-RGB conversions

Removes the amiguity from the conversion routines and stops
them dropping back to the SD vs HD choice of coeffs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Make video/still threshold a run-time param

Move the define for at what resolution the driver
switches from a video mode capture to a stills mode
capture to module parameters.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix incorrect pool sizing

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add option to disable enum_framesizes.

Gstreamer's handling of a driver that advertises
V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
resolutions is broken. See bug
https://bugzilla.gnome.org/show_bug.cgi?id=726521

Optional parameter of gst_v4l2src_is_broken added.
If non-zero, the driver claims not to support that
ioctl, and gstreamer should be happy again (it
guesses a set of defaults for itself).

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for more image formats

Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD

Request to extend the range from the fairly arbitrary
1000 frames (33 seconds at 30fps). Extend out to the
max range supported (int32 value).
Also allow 0, which is handled by the codec as only
send an I-frame on the first frame and never again.
There may be an exception if it detects a significant
scene change, but there's no easy way around that.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

bcm2835-camera: stop_streaming now has a void return

BCM2835-V4L2: Fix compliance test failures

VIDIOC_TRY_FMT and VIDIOC_S_FMT tests were faling due
to reporting V4L2_COLORSPACE_JPEG when the colour
format wasn't V4L2_PIX_FMT_JPEG.
Now reports V4L2_COLORSPACE_SMPTE170M for YUV formats.

bcm2835 camera planar/packed stride length

Added a field to the mmal_fmt struct used to compute the bytes per line
when using a particular format. This results in the correct stride being
calculated even when the format is planar.

Signed-off-by: Garrett Wilson <g@floft.net>

bcm2835: camera: check for scene not being found

static analysis by cppcheck detected some potential NULL pointer
dereference issues:

[drivers/media/platform/bcm2835/controls.c:854]: (error) Possible null
  pointer dereference: scene
  (and lines 858, 859 too)

it is possible that scene is not found because of an invalue ctrl->val
and is therefore NULL and hence causing a null pointer dereference.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

bcm2835: memcpy port data to m rather than rmsg

static analysis by cppcheck detected a memcpy to rmsg which is
not actually initialized at that point.  The memcpy should be copying
to variable m instead.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

BCM2835-V4L2: Return buffers to videobuf2 on shutdown

raspberrypi#817
Fixes the kernel warning from videobuf2 as buffers
are now returned as they are being flushed on
stop_streaming.

squash: Fixup bcm2835-camera for changes in kernel 4.4 api

v4l2: Fix up driver to upstream timestamp changes

bcm2835-camera: fix a bug in computation of frame timestamp

Fixes raspberrypi#1318

V4L2 driver updates (raspberrypi#1393)

* BCM2835-V4L2: Correct ISO control and add V4L2_CID_ISO_SENSITIVITY_AUTO

raspberrypi#1251

V4L2_CID_ISO_SENSITIVITY was not advertising ISO*1000 as it should.
V4L2_CID_ISO_SENSITIVITY_AUTO was not implemented, so was taking
V4L2_CID_ISO_SENSITIVITY as 0 for auto mode.
Still accepts 0 for auto, but also abides by the new parameter.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add a video_nr parameter.

Adds a kernel parameter "video_nr" to specify the preferred
/dev/videoX device node.
https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=136120&p=905545

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add support for multiple cameras

Ask GPU on load how many cameras have been detected, and
enumerate that number of devices.
Only applicable on the Compute Module as no other device
exposes multiple CSI2 interfaces.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add control of the overlay location and alpha.

Actually do something useful in vidioc_s_fmt_vid_overlay and
vidioc_try_fmt_vid_overlay, rather than effectively having
read-only fields.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: V4L2-Compliance failure fix

VIDIOC_TRY_FMT was failing due to bytesperline not
being set correctly by default.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Make all module parameters static

Clean up to correct variable scope

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

V4L2: Request maximum resolution from GPU

Get resolution information about the sensors from the GPU
and advertise it correctly.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-V4L2: Increase minimum resolution to 32x32

raspberrypi#1498 showed
up that 16x16 is failing to work on the GPU for some reason.

GPU bug being tracked on
raspberrypi/firmware#607
Workaround here by increasing minimum resolution via V4L2
to 32x32.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

[media]: bcm2835-camera: fix compilation error

There is an error when compiling rpi-4.6.y branch:
  CC [M]  drivers/media/platform/bcm2835/bcm2835-camera.o
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .queue_setup = queue_setup,
                 ^
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: note: (near initialization for 'bm2835_mmal_video_qops.queue_setup')

The const void *parg in setup_queue callback is not needed since commit:
df9ecb0.
This commit removes it.

Signed-off-by: Slawomir Stepien <sst@poczta.fm>

bcm2835-camera: Fix max/min error when looping over cameras/resolutions

See: raspberrypi#1447 (comment)

BCM2835-V4L2: Correct handling for BGR24 vs RGB24.

There was a bug in the GPU firmware that had reversed these
two formats.
Detect the old firmware, and reverse the formats if necessary.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-v4l2: Fix a conformance test failure

Format ioctls:
	test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
	warn: v4l2-test-formats.cpp(1195): S_PARM is supported but
		doesn't report V4L2_CAP_TIMEPERFRAME.
	fail: v4l2-test-formats.cpp(1118): node->has_frmintervals
		&& !cap->capability
pelwell pushed a commit to pelwell/linux that referenced this issue Nov 19, 2017
- Supports raw YUV capture, preview, JPEG and H264.
- Uses videobuf2 for data transfer, using dma_buf.
- Uses 3.6.10 timestamping
- Camera power based on use
- Uses immutable input mode on video encoder

Signed-off-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Luke Diamand <luked@broadcom.com>

V4L2: Fixes from 6by9

V4L2: Fix EV values. Add manual shutter speed control

V4L2 EV values should be in units of 1/1000. Corrected.
Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
give manual shutter control. Requires manual exposure mode
to be selected first.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct JPEG Q-factor range

Should be 1-100, not 0-100

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue of driver jamming if STREAMON failed.

Fix issue where the driver was left in a partially enabled
state if STREAMON failed, and would then reject many IOCTLs
as it thought it was streaming.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix ISO controls.

Driver was passing the index to the GPU, and not the desired
ISO value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add flicker avoidance controls

Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
avoidance frequencies.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for frame rate control.

Add support for frame rate (or time per frame as V4L2
inverts it) control via s_parm.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Improve G_FBUF handling so we pass conformance

Return some sane numbers for get framebuffer so that
we pass conformance.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix information advertised through g_vidfmt

Width and height were being stored based on incorrect
values.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for inline H264 headers

Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
to control H264 inline headers.
Requires firmware fix to work correctly, otherwise format
has to be set to H264 before this parameter is set.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix JPEG timestamp issue

JPEG images were coming through from the GPU with timestamp
of 0. Detect this and give current system time instead
of some invalid value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue when switching down JPEG resolution.

JPEG buffer size calculation is based on input resolution.
Input resolution was being configured after output port
format. Caused failures if switching from one JPEG resolution
to a smaller one.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable MJPEG encoding

Requires GPU firmware update to support MJPEG encoder.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct flag settings for compressed formats

Set flags field correctly on enum_fmt_vid_cap for compressed
image formats.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: H264 profile & level ctrls, FPS control and auto exp pri

Several control handling updates.
H264 profile and level controls.
Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
select whether AE is allowed to override the framerate specified.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct BGR24 to RGB24 in format table

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add additional pixel formats. Correct colourspace

Adds the other flavours of YUYV, and NV12.
Corrects the overlay advertised colourspace.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Drop logging msg from info to debug

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Initial pass at scene modes.

Only supports exposure mode and metering modes.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add manual white balance control.

Adds support for V4L2_CID_RED_BALANCE and
V4L2_CID_BLUE_BALANCE. Only has an effect if
V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
V4L2_WHITE_BALANCE_MANUAL selected.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

config: Enable V4L / MMAL driver

V4L2: Increase the MMAL timeout to 3sec

MJPEG codec flush is now taking longer and results
in a kernel panic if the driver has stopped waiting for
the result when it finally completes.
Increase the timeout value from 1 to 3secs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for setting H264_I_PERIOD

Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
to set the frequency with which I frames are produced.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable GPU function for removing padding from images.

GPU can now support arbitrary strides, although may require
additional processing to achieve it. Enable this feature
so that the images delivered are the size requested.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for V4L2_PIX_FMT_BGR32

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Set the colourspace to avoid odd YUV-RGB conversions

Removes the amiguity from the conversion routines and stops
them dropping back to the SD vs HD choice of coeffs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Make video/still threshold a run-time param

Move the define for at what resolution the driver
switches from a video mode capture to a stills mode
capture to module parameters.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix incorrect pool sizing

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add option to disable enum_framesizes.

Gstreamer's handling of a driver that advertises
V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
resolutions is broken. See bug
https://bugzilla.gnome.org/show_bug.cgi?id=726521

Optional parameter of gst_v4l2src_is_broken added.
If non-zero, the driver claims not to support that
ioctl, and gstreamer should be happy again (it
guesses a set of defaults for itself).

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for more image formats

Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD

Request to extend the range from the fairly arbitrary
1000 frames (33 seconds at 30fps). Extend out to the
max range supported (int32 value).
Also allow 0, which is handled by the codec as only
send an I-frame on the first frame and never again.
There may be an exception if it detects a significant
scene change, but there's no easy way around that.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

bcm2835-camera: stop_streaming now has a void return

BCM2835-V4L2: Fix compliance test failures

VIDIOC_TRY_FMT and VIDIOC_S_FMT tests were faling due
to reporting V4L2_COLORSPACE_JPEG when the colour
format wasn't V4L2_PIX_FMT_JPEG.
Now reports V4L2_COLORSPACE_SMPTE170M for YUV formats.

bcm2835 camera planar/packed stride length

Added a field to the mmal_fmt struct used to compute the bytes per line
when using a particular format. This results in the correct stride being
calculated even when the format is planar.

Signed-off-by: Garrett Wilson <g@floft.net>

bcm2835: camera: check for scene not being found

static analysis by cppcheck detected some potential NULL pointer
dereference issues:

[drivers/media/platform/bcm2835/controls.c:854]: (error) Possible null
  pointer dereference: scene
  (and lines 858, 859 too)

it is possible that scene is not found because of an invalue ctrl->val
and is therefore NULL and hence causing a null pointer dereference.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

bcm2835: memcpy port data to m rather than rmsg

static analysis by cppcheck detected a memcpy to rmsg which is
not actually initialized at that point.  The memcpy should be copying
to variable m instead.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

BCM2835-V4L2: Return buffers to videobuf2 on shutdown

raspberrypi#817
Fixes the kernel warning from videobuf2 as buffers
are now returned as they are being flushed on
stop_streaming.

squash: Fixup bcm2835-camera for changes in kernel 4.4 api

v4l2: Fix up driver to upstream timestamp changes

bcm2835-camera: fix a bug in computation of frame timestamp

Fixes raspberrypi#1318

V4L2 driver updates (raspberrypi#1393)

* BCM2835-V4L2: Correct ISO control and add V4L2_CID_ISO_SENSITIVITY_AUTO

raspberrypi#1251

V4L2_CID_ISO_SENSITIVITY was not advertising ISO*1000 as it should.
V4L2_CID_ISO_SENSITIVITY_AUTO was not implemented, so was taking
V4L2_CID_ISO_SENSITIVITY as 0 for auto mode.
Still accepts 0 for auto, but also abides by the new parameter.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add a video_nr parameter.

Adds a kernel parameter "video_nr" to specify the preferred
/dev/videoX device node.
https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=136120&p=905545

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add support for multiple cameras

Ask GPU on load how many cameras have been detected, and
enumerate that number of devices.
Only applicable on the Compute Module as no other device
exposes multiple CSI2 interfaces.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add control of the overlay location and alpha.

Actually do something useful in vidioc_s_fmt_vid_overlay and
vidioc_try_fmt_vid_overlay, rather than effectively having
read-only fields.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: V4L2-Compliance failure fix

VIDIOC_TRY_FMT was failing due to bytesperline not
being set correctly by default.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Make all module parameters static

Clean up to correct variable scope

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

V4L2: Request maximum resolution from GPU

Get resolution information about the sensors from the GPU
and advertise it correctly.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-V4L2: Increase minimum resolution to 32x32

raspberrypi#1498 showed
up that 16x16 is failing to work on the GPU for some reason.

GPU bug being tracked on
raspberrypi/firmware#607
Workaround here by increasing minimum resolution via V4L2
to 32x32.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

[media]: bcm2835-camera: fix compilation error

There is an error when compiling rpi-4.6.y branch:
  CC [M]  drivers/media/platform/bcm2835/bcm2835-camera.o
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .queue_setup = queue_setup,
                 ^
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: note: (near initialization for 'bm2835_mmal_video_qops.queue_setup')

The const void *parg in setup_queue callback is not needed since commit:
df9ecb0.
This commit removes it.

Signed-off-by: Slawomir Stepien <sst@poczta.fm>

bcm2835-camera: Fix max/min error when looping over cameras/resolutions

See: raspberrypi#1447 (comment)

BCM2835-V4L2: Correct handling for BGR24 vs RGB24.

There was a bug in the GPU firmware that had reversed these
two formats.
Detect the old firmware, and reverse the formats if necessary.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-v4l2: Fix a conformance test failure

Format ioctls:
	test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
	warn: v4l2-test-formats.cpp(1195): S_PARM is supported but
		doesn't report V4L2_CAP_TIMEPERFRAME.
	fail: v4l2-test-formats.cpp(1118): node->has_frmintervals
		&& !cap->capability
pelwell pushed a commit to pelwell/linux that referenced this issue Nov 19, 2017
- Supports raw YUV capture, preview, JPEG and H264.
- Uses videobuf2 for data transfer, using dma_buf.
- Uses 3.6.10 timestamping
- Camera power based on use
- Uses immutable input mode on video encoder

Signed-off-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Luke Diamand <luked@broadcom.com>

V4L2: Fixes from 6by9

V4L2: Fix EV values. Add manual shutter speed control

V4L2 EV values should be in units of 1/1000. Corrected.
Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
give manual shutter control. Requires manual exposure mode
to be selected first.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct JPEG Q-factor range

Should be 1-100, not 0-100

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue of driver jamming if STREAMON failed.

Fix issue where the driver was left in a partially enabled
state if STREAMON failed, and would then reject many IOCTLs
as it thought it was streaming.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix ISO controls.

Driver was passing the index to the GPU, and not the desired
ISO value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add flicker avoidance controls

Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
avoidance frequencies.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for frame rate control.

Add support for frame rate (or time per frame as V4L2
inverts it) control via s_parm.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Improve G_FBUF handling so we pass conformance

Return some sane numbers for get framebuffer so that
we pass conformance.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix information advertised through g_vidfmt

Width and height were being stored based on incorrect
values.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for inline H264 headers

Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
to control H264 inline headers.
Requires firmware fix to work correctly, otherwise format
has to be set to H264 before this parameter is set.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix JPEG timestamp issue

JPEG images were coming through from the GPU with timestamp
of 0. Detect this and give current system time instead
of some invalid value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue when switching down JPEG resolution.

JPEG buffer size calculation is based on input resolution.
Input resolution was being configured after output port
format. Caused failures if switching from one JPEG resolution
to a smaller one.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable MJPEG encoding

Requires GPU firmware update to support MJPEG encoder.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct flag settings for compressed formats

Set flags field correctly on enum_fmt_vid_cap for compressed
image formats.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: H264 profile & level ctrls, FPS control and auto exp pri

Several control handling updates.
H264 profile and level controls.
Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
select whether AE is allowed to override the framerate specified.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct BGR24 to RGB24 in format table

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add additional pixel formats. Correct colourspace

Adds the other flavours of YUYV, and NV12.
Corrects the overlay advertised colourspace.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Drop logging msg from info to debug

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Initial pass at scene modes.

Only supports exposure mode and metering modes.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add manual white balance control.

Adds support for V4L2_CID_RED_BALANCE and
V4L2_CID_BLUE_BALANCE. Only has an effect if
V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
V4L2_WHITE_BALANCE_MANUAL selected.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

config: Enable V4L / MMAL driver

V4L2: Increase the MMAL timeout to 3sec

MJPEG codec flush is now taking longer and results
in a kernel panic if the driver has stopped waiting for
the result when it finally completes.
Increase the timeout value from 1 to 3secs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for setting H264_I_PERIOD

Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
to set the frequency with which I frames are produced.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable GPU function for removing padding from images.

GPU can now support arbitrary strides, although may require
additional processing to achieve it. Enable this feature
so that the images delivered are the size requested.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for V4L2_PIX_FMT_BGR32

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Set the colourspace to avoid odd YUV-RGB conversions

Removes the amiguity from the conversion routines and stops
them dropping back to the SD vs HD choice of coeffs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Make video/still threshold a run-time param

Move the define for at what resolution the driver
switches from a video mode capture to a stills mode
capture to module parameters.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix incorrect pool sizing

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add option to disable enum_framesizes.

Gstreamer's handling of a driver that advertises
V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
resolutions is broken. See bug
https://bugzilla.gnome.org/show_bug.cgi?id=726521

Optional parameter of gst_v4l2src_is_broken added.
If non-zero, the driver claims not to support that
ioctl, and gstreamer should be happy again (it
guesses a set of defaults for itself).

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for more image formats

Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD

Request to extend the range from the fairly arbitrary
1000 frames (33 seconds at 30fps). Extend out to the
max range supported (int32 value).
Also allow 0, which is handled by the codec as only
send an I-frame on the first frame and never again.
There may be an exception if it detects a significant
scene change, but there's no easy way around that.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

bcm2835-camera: stop_streaming now has a void return

BCM2835-V4L2: Fix compliance test failures

VIDIOC_TRY_FMT and VIDIOC_S_FMT tests were faling due
to reporting V4L2_COLORSPACE_JPEG when the colour
format wasn't V4L2_PIX_FMT_JPEG.
Now reports V4L2_COLORSPACE_SMPTE170M for YUV formats.

bcm2835 camera planar/packed stride length

Added a field to the mmal_fmt struct used to compute the bytes per line
when using a particular format. This results in the correct stride being
calculated even when the format is planar.

Signed-off-by: Garrett Wilson <g@floft.net>

bcm2835: camera: check for scene not being found

static analysis by cppcheck detected some potential NULL pointer
dereference issues:

[drivers/media/platform/bcm2835/controls.c:854]: (error) Possible null
  pointer dereference: scene
  (and lines 858, 859 too)

it is possible that scene is not found because of an invalue ctrl->val
and is therefore NULL and hence causing a null pointer dereference.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

bcm2835: memcpy port data to m rather than rmsg

static analysis by cppcheck detected a memcpy to rmsg which is
not actually initialized at that point.  The memcpy should be copying
to variable m instead.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

BCM2835-V4L2: Return buffers to videobuf2 on shutdown

raspberrypi#817
Fixes the kernel warning from videobuf2 as buffers
are now returned as they are being flushed on
stop_streaming.

squash: Fixup bcm2835-camera for changes in kernel 4.4 api

v4l2: Fix up driver to upstream timestamp changes

bcm2835-camera: fix a bug in computation of frame timestamp

Fixes raspberrypi#1318

V4L2 driver updates (raspberrypi#1393)

* BCM2835-V4L2: Correct ISO control and add V4L2_CID_ISO_SENSITIVITY_AUTO

raspberrypi#1251

V4L2_CID_ISO_SENSITIVITY was not advertising ISO*1000 as it should.
V4L2_CID_ISO_SENSITIVITY_AUTO was not implemented, so was taking
V4L2_CID_ISO_SENSITIVITY as 0 for auto mode.
Still accepts 0 for auto, but also abides by the new parameter.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add a video_nr parameter.

Adds a kernel parameter "video_nr" to specify the preferred
/dev/videoX device node.
https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=136120&p=905545

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add support for multiple cameras

Ask GPU on load how many cameras have been detected, and
enumerate that number of devices.
Only applicable on the Compute Module as no other device
exposes multiple CSI2 interfaces.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add control of the overlay location and alpha.

Actually do something useful in vidioc_s_fmt_vid_overlay and
vidioc_try_fmt_vid_overlay, rather than effectively having
read-only fields.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: V4L2-Compliance failure fix

VIDIOC_TRY_FMT was failing due to bytesperline not
being set correctly by default.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Make all module parameters static

Clean up to correct variable scope

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

V4L2: Request maximum resolution from GPU

Get resolution information about the sensors from the GPU
and advertise it correctly.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-V4L2: Increase minimum resolution to 32x32

raspberrypi#1498 showed
up that 16x16 is failing to work on the GPU for some reason.

GPU bug being tracked on
raspberrypi/firmware#607
Workaround here by increasing minimum resolution via V4L2
to 32x32.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

[media]: bcm2835-camera: fix compilation error

There is an error when compiling rpi-4.6.y branch:
  CC [M]  drivers/media/platform/bcm2835/bcm2835-camera.o
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .queue_setup = queue_setup,
                 ^
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: note: (near initialization for 'bm2835_mmal_video_qops.queue_setup')

The const void *parg in setup_queue callback is not needed since commit:
df9ecb0.
This commit removes it.

Signed-off-by: Slawomir Stepien <sst@poczta.fm>

bcm2835-camera: Fix max/min error when looping over cameras/resolutions

See: raspberrypi#1447 (comment)

BCM2835-V4L2: Correct handling for BGR24 vs RGB24.

There was a bug in the GPU firmware that had reversed these
two formats.
Detect the old firmware, and reverse the formats if necessary.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-v4l2: Fix a conformance test failure

Format ioctls:
	test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
	warn: v4l2-test-formats.cpp(1195): S_PARM is supported but
		doesn't report V4L2_CAP_TIMEPERFRAME.
	fail: v4l2-test-formats.cpp(1118): node->has_frmintervals
		&& !cap->capability
pelwell pushed a commit to pelwell/linux that referenced this issue Nov 19, 2017
- Supports raw YUV capture, preview, JPEG and H264.
- Uses videobuf2 for data transfer, using dma_buf.
- Uses 3.6.10 timestamping
- Camera power based on use
- Uses immutable input mode on video encoder

Signed-off-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Luke Diamand <luked@broadcom.com>

V4L2: Fixes from 6by9

V4L2: Fix EV values. Add manual shutter speed control

V4L2 EV values should be in units of 1/1000. Corrected.
Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
give manual shutter control. Requires manual exposure mode
to be selected first.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct JPEG Q-factor range

Should be 1-100, not 0-100

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue of driver jamming if STREAMON failed.

Fix issue where the driver was left in a partially enabled
state if STREAMON failed, and would then reject many IOCTLs
as it thought it was streaming.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix ISO controls.

Driver was passing the index to the GPU, and not the desired
ISO value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add flicker avoidance controls

Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
avoidance frequencies.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for frame rate control.

Add support for frame rate (or time per frame as V4L2
inverts it) control via s_parm.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Improve G_FBUF handling so we pass conformance

Return some sane numbers for get framebuffer so that
we pass conformance.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix information advertised through g_vidfmt

Width and height were being stored based on incorrect
values.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for inline H264 headers

Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
to control H264 inline headers.
Requires firmware fix to work correctly, otherwise format
has to be set to H264 before this parameter is set.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix JPEG timestamp issue

JPEG images were coming through from the GPU with timestamp
of 0. Detect this and give current system time instead
of some invalid value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue when switching down JPEG resolution.

JPEG buffer size calculation is based on input resolution.
Input resolution was being configured after output port
format. Caused failures if switching from one JPEG resolution
to a smaller one.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable MJPEG encoding

Requires GPU firmware update to support MJPEG encoder.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct flag settings for compressed formats

Set flags field correctly on enum_fmt_vid_cap for compressed
image formats.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: H264 profile & level ctrls, FPS control and auto exp pri

Several control handling updates.
H264 profile and level controls.
Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
select whether AE is allowed to override the framerate specified.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct BGR24 to RGB24 in format table

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add additional pixel formats. Correct colourspace

Adds the other flavours of YUYV, and NV12.
Corrects the overlay advertised colourspace.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Drop logging msg from info to debug

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Initial pass at scene modes.

Only supports exposure mode and metering modes.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add manual white balance control.

Adds support for V4L2_CID_RED_BALANCE and
V4L2_CID_BLUE_BALANCE. Only has an effect if
V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
V4L2_WHITE_BALANCE_MANUAL selected.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

config: Enable V4L / MMAL driver

V4L2: Increase the MMAL timeout to 3sec

MJPEG codec flush is now taking longer and results
in a kernel panic if the driver has stopped waiting for
the result when it finally completes.
Increase the timeout value from 1 to 3secs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for setting H264_I_PERIOD

Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
to set the frequency with which I frames are produced.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable GPU function for removing padding from images.

GPU can now support arbitrary strides, although may require
additional processing to achieve it. Enable this feature
so that the images delivered are the size requested.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for V4L2_PIX_FMT_BGR32

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Set the colourspace to avoid odd YUV-RGB conversions

Removes the amiguity from the conversion routines and stops
them dropping back to the SD vs HD choice of coeffs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Make video/still threshold a run-time param

Move the define for at what resolution the driver
switches from a video mode capture to a stills mode
capture to module parameters.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix incorrect pool sizing

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add option to disable enum_framesizes.

Gstreamer's handling of a driver that advertises
V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
resolutions is broken. See bug
https://bugzilla.gnome.org/show_bug.cgi?id=726521

Optional parameter of gst_v4l2src_is_broken added.
If non-zero, the driver claims not to support that
ioctl, and gstreamer should be happy again (it
guesses a set of defaults for itself).

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for more image formats

Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD

Request to extend the range from the fairly arbitrary
1000 frames (33 seconds at 30fps). Extend out to the
max range supported (int32 value).
Also allow 0, which is handled by the codec as only
send an I-frame on the first frame and never again.
There may be an exception if it detects a significant
scene change, but there's no easy way around that.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

bcm2835-camera: stop_streaming now has a void return

BCM2835-V4L2: Fix compliance test failures

VIDIOC_TRY_FMT and VIDIOC_S_FMT tests were faling due
to reporting V4L2_COLORSPACE_JPEG when the colour
format wasn't V4L2_PIX_FMT_JPEG.
Now reports V4L2_COLORSPACE_SMPTE170M for YUV formats.

bcm2835 camera planar/packed stride length

Added a field to the mmal_fmt struct used to compute the bytes per line
when using a particular format. This results in the correct stride being
calculated even when the format is planar.

Signed-off-by: Garrett Wilson <g@floft.net>

bcm2835: camera: check for scene not being found

static analysis by cppcheck detected some potential NULL pointer
dereference issues:

[drivers/media/platform/bcm2835/controls.c:854]: (error) Possible null
  pointer dereference: scene
  (and lines 858, 859 too)

it is possible that scene is not found because of an invalue ctrl->val
and is therefore NULL and hence causing a null pointer dereference.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

bcm2835: memcpy port data to m rather than rmsg

static analysis by cppcheck detected a memcpy to rmsg which is
not actually initialized at that point.  The memcpy should be copying
to variable m instead.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

BCM2835-V4L2: Return buffers to videobuf2 on shutdown

raspberrypi#817
Fixes the kernel warning from videobuf2 as buffers
are now returned as they are being flushed on
stop_streaming.

squash: Fixup bcm2835-camera for changes in kernel 4.4 api

v4l2: Fix up driver to upstream timestamp changes

bcm2835-camera: fix a bug in computation of frame timestamp

Fixes raspberrypi#1318

V4L2 driver updates (raspberrypi#1393)

* BCM2835-V4L2: Correct ISO control and add V4L2_CID_ISO_SENSITIVITY_AUTO

raspberrypi#1251

V4L2_CID_ISO_SENSITIVITY was not advertising ISO*1000 as it should.
V4L2_CID_ISO_SENSITIVITY_AUTO was not implemented, so was taking
V4L2_CID_ISO_SENSITIVITY as 0 for auto mode.
Still accepts 0 for auto, but also abides by the new parameter.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add a video_nr parameter.

Adds a kernel parameter "video_nr" to specify the preferred
/dev/videoX device node.
https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=136120&p=905545

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add support for multiple cameras

Ask GPU on load how many cameras have been detected, and
enumerate that number of devices.
Only applicable on the Compute Module as no other device
exposes multiple CSI2 interfaces.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add control of the overlay location and alpha.

Actually do something useful in vidioc_s_fmt_vid_overlay and
vidioc_try_fmt_vid_overlay, rather than effectively having
read-only fields.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: V4L2-Compliance failure fix

VIDIOC_TRY_FMT was failing due to bytesperline not
being set correctly by default.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Make all module parameters static

Clean up to correct variable scope

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

V4L2: Request maximum resolution from GPU

Get resolution information about the sensors from the GPU
and advertise it correctly.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-V4L2: Increase minimum resolution to 32x32

raspberrypi#1498 showed
up that 16x16 is failing to work on the GPU for some reason.

GPU bug being tracked on
raspberrypi/firmware#607
Workaround here by increasing minimum resolution via V4L2
to 32x32.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

[media]: bcm2835-camera: fix compilation error

There is an error when compiling rpi-4.6.y branch:
  CC [M]  drivers/media/platform/bcm2835/bcm2835-camera.o
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .queue_setup = queue_setup,
                 ^
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: note: (near initialization for 'bm2835_mmal_video_qops.queue_setup')

The const void *parg in setup_queue callback is not needed since commit:
df9ecb0.
This commit removes it.

Signed-off-by: Slawomir Stepien <sst@poczta.fm>

bcm2835-camera: Fix max/min error when looping over cameras/resolutions

See: raspberrypi#1447 (comment)

BCM2835-V4L2: Correct handling for BGR24 vs RGB24.

There was a bug in the GPU firmware that had reversed these
two formats.
Detect the old firmware, and reverse the formats if necessary.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-v4l2: Fix a conformance test failure

Format ioctls:
	test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
	warn: v4l2-test-formats.cpp(1195): S_PARM is supported but
		doesn't report V4L2_CAP_TIMEPERFRAME.
	fail: v4l2-test-formats.cpp(1118): node->has_frmintervals
		&& !cap->capability
ryncsn pushed a commit to ryncsn/linux-rasp that referenced this issue Nov 21, 2017
- Supports raw YUV capture, preview, JPEG and H264.
- Uses videobuf2 for data transfer, using dma_buf.
- Uses 3.6.10 timestamping
- Camera power based on use
- Uses immutable input mode on video encoder

Signed-off-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Luke Diamand <luked@broadcom.com>

V4L2: Fixes from 6by9

V4L2: Fix EV values. Add manual shutter speed control

V4L2 EV values should be in units of 1/1000. Corrected.
Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
give manual shutter control. Requires manual exposure mode
to be selected first.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct JPEG Q-factor range

Should be 1-100, not 0-100

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue of driver jamming if STREAMON failed.

Fix issue where the driver was left in a partially enabled
state if STREAMON failed, and would then reject many IOCTLs
as it thought it was streaming.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix ISO controls.

Driver was passing the index to the GPU, and not the desired
ISO value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add flicker avoidance controls

Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
avoidance frequencies.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for frame rate control.

Add support for frame rate (or time per frame as V4L2
inverts it) control via s_parm.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Improve G_FBUF handling so we pass conformance

Return some sane numbers for get framebuffer so that
we pass conformance.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix information advertised through g_vidfmt

Width and height were being stored based on incorrect
values.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for inline H264 headers

Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
to control H264 inline headers.
Requires firmware fix to work correctly, otherwise format
has to be set to H264 before this parameter is set.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix JPEG timestamp issue

JPEG images were coming through from the GPU with timestamp
of 0. Detect this and give current system time instead
of some invalid value.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix issue when switching down JPEG resolution.

JPEG buffer size calculation is based on input resolution.
Input resolution was being configured after output port
format. Caused failures if switching from one JPEG resolution
to a smaller one.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable MJPEG encoding

Requires GPU firmware update to support MJPEG encoder.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct flag settings for compressed formats

Set flags field correctly on enum_fmt_vid_cap for compressed
image formats.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: H264 profile & level ctrls, FPS control and auto exp pri

Several control handling updates.
H264 profile and level controls.
Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
select whether AE is allowed to override the framerate specified.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Correct BGR24 to RGB24 in format table

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add additional pixel formats. Correct colourspace

Adds the other flavours of YUYV, and NV12.
Corrects the overlay advertised colourspace.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Drop logging msg from info to debug

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Initial pass at scene modes.

Only supports exposure mode and metering modes.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add manual white balance control.

Adds support for V4L2_CID_RED_BALANCE and
V4L2_CID_BLUE_BALANCE. Only has an effect if
V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
V4L2_WHITE_BALANCE_MANUAL selected.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

config: Enable V4L / MMAL driver

V4L2: Increase the MMAL timeout to 3sec

MJPEG codec flush is now taking longer and results
in a kernel panic if the driver has stopped waiting for
the result when it finally completes.
Increase the timeout value from 1 to 3secs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for setting H264_I_PERIOD

Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
to set the frequency with which I frames are produced.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Enable GPU function for removing padding from images.

GPU can now support arbitrary strides, although may require
additional processing to achieve it. Enable this feature
so that the images delivered are the size requested.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for V4L2_PIX_FMT_BGR32

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Set the colourspace to avoid odd YUV-RGB conversions

Removes the amiguity from the conversion routines and stops
them dropping back to the SD vs HD choice of coeffs.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Make video/still threshold a run-time param

Move the define for at what resolution the driver
switches from a video mode capture to a stills mode
capture to module parameters.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Fix incorrect pool sizing

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add option to disable enum_framesizes.

Gstreamer's handling of a driver that advertises
V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
resolutions is broken. See bug
https://bugzilla.gnome.org/show_bug.cgi?id=726521

Optional parameter of gst_v4l2src_is_broken added.
If non-zero, the driver claims not to support that
ioctl, and gstreamer should be happy again (it
guesses a set of defaults for itself).

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Add support for more image formats

Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD

Request to extend the range from the fairly arbitrary
1000 frames (33 seconds at 30fps). Extend out to the
max range supported (int32 value).
Also allow 0, which is handled by the codec as only
send an I-frame on the first frame and never again.
There may be an exception if it detects a significant
scene change, but there's no easy way around that.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>

bcm2835-camera: stop_streaming now has a void return

BCM2835-V4L2: Fix compliance test failures

VIDIOC_TRY_FMT and VIDIOC_S_FMT tests were faling due
to reporting V4L2_COLORSPACE_JPEG when the colour
format wasn't V4L2_PIX_FMT_JPEG.
Now reports V4L2_COLORSPACE_SMPTE170M for YUV formats.

bcm2835 camera planar/packed stride length

Added a field to the mmal_fmt struct used to compute the bytes per line
when using a particular format. This results in the correct stride being
calculated even when the format is planar.

Signed-off-by: Garrett Wilson <g@floft.net>

bcm2835: camera: check for scene not being found

static analysis by cppcheck detected some potential NULL pointer
dereference issues:

[drivers/media/platform/bcm2835/controls.c:854]: (error) Possible null
  pointer dereference: scene
  (and lines 858, 859 too)

it is possible that scene is not found because of an invalue ctrl->val
and is therefore NULL and hence causing a null pointer dereference.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

bcm2835: memcpy port data to m rather than rmsg

static analysis by cppcheck detected a memcpy to rmsg which is
not actually initialized at that point.  The memcpy should be copying
to variable m instead.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

BCM2835-V4L2: Return buffers to videobuf2 on shutdown

raspberrypi#817
Fixes the kernel warning from videobuf2 as buffers
are now returned as they are being flushed on
stop_streaming.

squash: Fixup bcm2835-camera for changes in kernel 4.4 api

v4l2: Fix up driver to upstream timestamp changes

bcm2835-camera: fix a bug in computation of frame timestamp

Fixes raspberrypi#1318

V4L2 driver updates (raspberrypi#1393)

* BCM2835-V4L2: Correct ISO control and add V4L2_CID_ISO_SENSITIVITY_AUTO

raspberrypi#1251

V4L2_CID_ISO_SENSITIVITY was not advertising ISO*1000 as it should.
V4L2_CID_ISO_SENSITIVITY_AUTO was not implemented, so was taking
V4L2_CID_ISO_SENSITIVITY as 0 for auto mode.
Still accepts 0 for auto, but also abides by the new parameter.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add a video_nr parameter.

Adds a kernel parameter "video_nr" to specify the preferred
/dev/videoX device node.
https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=136120&p=905545

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add support for multiple cameras

Ask GPU on load how many cameras have been detected, and
enumerate that number of devices.
Only applicable on the Compute Module as no other device
exposes multiple CSI2 interfaces.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Add control of the overlay location and alpha.

Actually do something useful in vidioc_s_fmt_vid_overlay and
vidioc_try_fmt_vid_overlay, rather than effectively having
read-only fields.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: V4L2-Compliance failure fix

VIDIOC_TRY_FMT was failing due to bytesperline not
being set correctly by default.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

* BCM2835-V4L2: Make all module parameters static

Clean up to correct variable scope

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

V4L2: Request maximum resolution from GPU

Get resolution information about the sensors from the GPU
and advertise it correctly.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-V4L2: Increase minimum resolution to 32x32

raspberrypi#1498 showed
up that 16x16 is failing to work on the GPU for some reason.

GPU bug being tracked on
raspberrypi/firmware#607
Workaround here by increasing minimum resolution via V4L2
to 32x32.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

[media]: bcm2835-camera: fix compilation error

There is an error when compiling rpi-4.6.y branch:
  CC [M]  drivers/media/platform/bcm2835/bcm2835-camera.o
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .queue_setup = queue_setup,
                 ^
drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: note: (near initialization for 'bm2835_mmal_video_qops.queue_setup')

The const void *parg in setup_queue callback is not needed since commit:
df9ecb0.
This commit removes it.

Signed-off-by: Slawomir Stepien <sst@poczta.fm>

bcm2835-camera: Fix max/min error when looping over cameras/resolutions

See: raspberrypi#1447 (comment)

BCM2835-V4L2: Correct handling for BGR24 vs RGB24.

There was a bug in the GPU firmware that had reversed these
two formats.
Detect the old firmware, and reverse the formats if necessary.

Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>

BCM2835-v4l2: Fix a conformance test failure

Format ioctls:
	test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
	warn: v4l2-test-formats.cpp(1195): S_PARM is supported but
		doesn't report V4L2_CAP_TIMEPERFRAME.
	fail: v4l2-test-formats.cpp(1118): node->has_frmintervals
		&& !cap->capability
ryncsn pushed a commit to ryncsn/linux-rasp that referenced this issue Nov 21, 2017
raspberrypi#1447
port_parameter_get() failed to account for the header
(u32 id and u32 size) in the size before memcpying
the response into the response buffer, so overrunning
the provided buffer by 8 bytes.

Account for those bytes, and also a belt-and-braces
check to ensure we never copy more than *value_size
bytes into value.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
raspbian-autopush pushed a commit to raspbian-packages/linux-4.9 that referenced this issue Apr 7, 2018
commit f2d51ef
Author: Vincent Sanders <vincent.sanders@collabora.co.uk>
Date:   Wed Jan 30 12:45:18 2013 +0000

    bcm2835: add v4l2 camera device
    
    - Supports raw YUV capture, preview, JPEG and H264.
    - Uses videobuf2 for data transfer, using dma_buf.
    - Uses 3.6.10 timestamping
    - Camera power based on use
    - Uses immutable input mode on video encoder
    
    Signed-off-by: Daniel Stone <daniels@collabora.com>
    Signed-off-by: Luke Diamand <luked@broadcom.com>
    
    V4L2: Fixes from 6by9
    
    V4L2: Fix EV values. Add manual shutter speed control
    
    V4L2 EV values should be in units of 1/1000. Corrected.
    Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
    give manual shutter control. Requires manual exposure mode
    to be selected first.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Correct JPEG Q-factor range
    
    Should be 1-100, not 0-100
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix issue of driver jamming if STREAMON failed.
    
    Fix issue where the driver was left in a partially enabled
    state if STREAMON failed, and would then reject many IOCTLs
    as it thought it was streaming.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix ISO controls.
    
    Driver was passing the index to the GPU, and not the desired
    ISO value.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add flicker avoidance controls
    
    Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
    avoidance frequencies.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for frame rate control.
    
    Add support for frame rate (or time per frame as V4L2
    inverts it) control via s_parm.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Improve G_FBUF handling so we pass conformance
    
    Return some sane numbers for get framebuffer so that
    we pass conformance.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix information advertised through g_vidfmt
    
    Width and height were being stored based on incorrect
    values.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for inline H264 headers
    
    Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
    to control H264 inline headers.
    Requires firmware fix to work correctly, otherwise format
    has to be set to H264 before this parameter is set.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix JPEG timestamp issue
    
    JPEG images were coming through from the GPU with timestamp
    of 0. Detect this and give current system time instead
    of some invalid value.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix issue when switching down JPEG resolution.
    
    JPEG buffer size calculation is based on input resolution.
    Input resolution was being configured after output port
    format. Caused failures if switching from one JPEG resolution
    to a smaller one.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Enable MJPEG encoding
    
    Requires GPU firmware update to support MJPEG encoder.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Correct flag settings for compressed formats
    
    Set flags field correctly on enum_fmt_vid_cap for compressed
    image formats.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: H264 profile & level ctrls, FPS control and auto exp pri
    
    Several control handling updates.
    H264 profile and level controls.
    Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
    select whether AE is allowed to override the framerate specified.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Correct BGR24 to RGB24 in format table
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add additional pixel formats. Correct colourspace
    
    Adds the other flavours of YUYV, and NV12.
    Corrects the overlay advertised colourspace.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Drop logging msg from info to debug
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Initial pass at scene modes.
    
    Only supports exposure mode and metering modes.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add manual white balance control.
    
    Adds support for V4L2_CID_RED_BALANCE and
    V4L2_CID_BLUE_BALANCE. Only has an effect if
    V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
    V4L2_WHITE_BALANCE_MANUAL selected.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    config: Enable V4L / MMAL driver
    
    V4L2: Increase the MMAL timeout to 3sec
    
    MJPEG codec flush is now taking longer and results
    in a kernel panic if the driver has stopped waiting for
    the result when it finally completes.
    Increase the timeout value from 1 to 3secs.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for setting H264_I_PERIOD
    
    Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
    to set the frequency with which I frames are produced.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Enable GPU function for removing padding from images.
    
    GPU can now support arbitrary strides, although may require
    additional processing to achieve it. Enable this feature
    so that the images delivered are the size requested.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for V4L2_PIX_FMT_BGR32
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Set the colourspace to avoid odd YUV-RGB conversions
    
    Removes the amiguity from the conversion routines and stops
    them dropping back to the SD vs HD choice of coeffs.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Make video/still threshold a run-time param
    
    Move the define for at what resolution the driver
    switches from a video mode capture to a stills mode
    capture to module parameters.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix incorrect pool sizing
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add option to disable enum_framesizes.
    
    Gstreamer's handling of a driver that advertises
    V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
    resolutions is broken. See bug
    https://bugzilla.gnome.org/show_bug.cgi?id=726521
    
    Optional parameter of gst_v4l2src_is_broken added.
    If non-zero, the driver claims not to support that
    ioctl, and gstreamer should be happy again (it
    guesses a set of defaults for itself).
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for more image formats
    
    Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
    
    Request to extend the range from the fairly arbitrary
    1000 frames (33 seconds at 30fps). Extend out to the
    max range supported (int32 value).
    Also allow 0, which is handled by the codec as only
    send an I-frame on the first frame and never again.
    There may be an exception if it detects a significant
    scene change, but there's no easy way around that.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    bcm2835-camera: stop_streaming now has a void return
    
    BCM2835-V4L2: Fix compliance test failures
    
    VIDIOC_TRY_FMT and VIDIOC_S_FMT tests were faling due
    to reporting V4L2_COLORSPACE_JPEG when the colour
    format wasn't V4L2_PIX_FMT_JPEG.
    Now reports V4L2_COLORSPACE_SMPTE170M for YUV formats.
    
    bcm2835 camera planar/packed stride length
    
    Added a field to the mmal_fmt struct used to compute the bytes per line
    when using a particular format. This results in the correct stride being
    calculated even when the format is planar.
    
    Signed-off-by: Garrett Wilson <g@floft.net>
    
    bcm2835: camera: check for scene not being found
    
    static analysis by cppcheck detected some potential NULL pointer
    dereference issues:
    
    [drivers/media/platform/bcm2835/controls.c:854]: (error) Possible null
      pointer dereference: scene
      (and lines 858, 859 too)
    
    it is possible that scene is not found because of an invalue ctrl->val
    and is therefore NULL and hence causing a null pointer dereference.
    
    Signed-off-by: Colin Ian King <colin.king@canonical.com>
    
    bcm2835: memcpy port data to m rather than rmsg
    
    static analysis by cppcheck detected a memcpy to rmsg which is
    not actually initialized at that point.  The memcpy should be copying
    to variable m instead.
    
    Signed-off-by: Colin Ian King <colin.king@canonical.com>
    
    BCM2835-V4L2: Return buffers to videobuf2 on shutdown
    
    raspberrypi/linux#817
    Fixes the kernel warning from videobuf2 as buffers
    are now returned as they are being flushed on
    stop_streaming.
    
    squash: Fixup bcm2835-camera for changes in kernel 4.4 api
    
    v4l2: Fix up driver to upstream timestamp changes
    
    bcm2835-camera: fix a bug in computation of frame timestamp
    
    Fixes #1318
    
    V4L2 driver updates (#1393)
    
    * BCM2835-V4L2: Correct ISO control and add V4L2_CID_ISO_SENSITIVITY_AUTO
    
    raspberrypi/linux#1251
    
    V4L2_CID_ISO_SENSITIVITY was not advertising ISO*1000 as it should.
    V4L2_CID_ISO_SENSITIVITY_AUTO was not implemented, so was taking
    V4L2_CID_ISO_SENSITIVITY as 0 for auto mode.
    Still accepts 0 for auto, but also abides by the new parameter.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: Add a video_nr parameter.
    
    Adds a kernel parameter "video_nr" to specify the preferred
    /dev/videoX device node.
    https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=136120&p=905545
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: Add support for multiple cameras
    
    Ask GPU on load how many cameras have been detected, and
    enumerate that number of devices.
    Only applicable on the Compute Module as no other device
    exposes multiple CSI2 interfaces.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: Add control of the overlay location and alpha.
    
    Actually do something useful in vidioc_s_fmt_vid_overlay and
    vidioc_try_fmt_vid_overlay, rather than effectively having
    read-only fields.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: V4L2-Compliance failure fix
    
    VIDIOC_TRY_FMT was failing due to bytesperline not
    being set correctly by default.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: Make all module parameters static
    
    Clean up to correct variable scope
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    V4L2: Request maximum resolution from GPU
    
    Get resolution information about the sensors from the GPU
    and advertise it correctly.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    BCM2835-V4L2: Increase minimum resolution to 32x32
    
    raspberrypi/linux#1498 showed
    up that 16x16 is failing to work on the GPU for some reason.
    
    GPU bug being tracked on
    raspberrypi/firmware#607
    Workaround here by increasing minimum resolution via V4L2
    to 32x32.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    [media]: bcm2835-camera: fix compilation error
    
    There is an error when compiling rpi-4.6.y branch:
      CC [M]  drivers/media/platform/bcm2835/bcm2835-camera.o
    drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
      .queue_setup = queue_setup,
                     ^
    drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: note: (near initialization for 'bm2835_mmal_video_qops.queue_setup')
    
    The const void *parg in setup_queue callback is not needed since commit:
    df9ecb0.
    This commit removes it.
    
    Signed-off-by: Slawomir Stepien <sst@poczta.fm>
    
    bcm2835-camera: Fix max/min error when looping over cameras/resolutions
    
    See: raspberrypi/linux#1447 (comment)
    
    BCM2835-V4L2: Correct handling for BGR24 vs RGB24.
    
    There was a bug in the GPU firmware that had reversed these
    two formats.
    Detect the old firmware, and reverse the formats if necessary.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    BCM2835-v4l2: Fix a conformance test failure
    
    Format ioctls:
            test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
            warn: v4l2-test-formats.cpp(1195): S_PARM is supported but
                    doesn't report V4L2_CAP_TIMEPERFRAME.
            fail: v4l2-test-formats.cpp(1118): node->has_frmintervals
                    && !cap->capability


Gbp-Pq: Topic rpi
Gbp-Pq: Name rpi_1049_f2d51efbeac118fa3c386f34cab3d7f2be7d5261.patch
raspbian-autopush pushed a commit to raspbian-packages/linux-4.9 that referenced this issue Apr 7, 2018
commit 0798a36
Author: Dave Stevenson <dave.stevenson@raspberrypi.org>
Date:   Fri Mar 10 14:43:15 2017 +0000

    bcm2835-v4l2: Fix buffer overflow problem
    
    raspberrypi/linux#1447
    port_parameter_get() failed to account for the header
    (u32 id and u32 size) in the size before memcpying
    the response into the response buffer, so overrunning
    the provided buffer by 8 bytes.
    
    Account for those bytes, and also a belt-and-braces
    check to ensure we never copy more than *value_size
    bytes into value.
    
    Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>


Gbp-Pq: Topic rpi
Gbp-Pq: Name rpi_1196_0798a364c331378ce6b37d6d4c276040505a5417.patch
raspbian-autopush pushed a commit to raspbian-packages/linux-4.9 that referenced this issue Nov 11, 2018
commit f2d51ef
Author: Vincent Sanders <vincent.sanders@collabora.co.uk>
Date:   Wed Jan 30 12:45:18 2013 +0000

    bcm2835: add v4l2 camera device
    
    - Supports raw YUV capture, preview, JPEG and H264.
    - Uses videobuf2 for data transfer, using dma_buf.
    - Uses 3.6.10 timestamping
    - Camera power based on use
    - Uses immutable input mode on video encoder
    
    Signed-off-by: Daniel Stone <daniels@collabora.com>
    Signed-off-by: Luke Diamand <luked@broadcom.com>
    
    V4L2: Fixes from 6by9
    
    V4L2: Fix EV values. Add manual shutter speed control
    
    V4L2 EV values should be in units of 1/1000. Corrected.
    Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
    give manual shutter control. Requires manual exposure mode
    to be selected first.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Correct JPEG Q-factor range
    
    Should be 1-100, not 0-100
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix issue of driver jamming if STREAMON failed.
    
    Fix issue where the driver was left in a partially enabled
    state if STREAMON failed, and would then reject many IOCTLs
    as it thought it was streaming.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix ISO controls.
    
    Driver was passing the index to the GPU, and not the desired
    ISO value.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add flicker avoidance controls
    
    Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
    avoidance frequencies.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for frame rate control.
    
    Add support for frame rate (or time per frame as V4L2
    inverts it) control via s_parm.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Improve G_FBUF handling so we pass conformance
    
    Return some sane numbers for get framebuffer so that
    we pass conformance.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix information advertised through g_vidfmt
    
    Width and height were being stored based on incorrect
    values.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for inline H264 headers
    
    Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
    to control H264 inline headers.
    Requires firmware fix to work correctly, otherwise format
    has to be set to H264 before this parameter is set.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix JPEG timestamp issue
    
    JPEG images were coming through from the GPU with timestamp
    of 0. Detect this and give current system time instead
    of some invalid value.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix issue when switching down JPEG resolution.
    
    JPEG buffer size calculation is based on input resolution.
    Input resolution was being configured after output port
    format. Caused failures if switching from one JPEG resolution
    to a smaller one.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Enable MJPEG encoding
    
    Requires GPU firmware update to support MJPEG encoder.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Correct flag settings for compressed formats
    
    Set flags field correctly on enum_fmt_vid_cap for compressed
    image formats.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: H264 profile & level ctrls, FPS control and auto exp pri
    
    Several control handling updates.
    H264 profile and level controls.
    Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
    select whether AE is allowed to override the framerate specified.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Correct BGR24 to RGB24 in format table
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add additional pixel formats. Correct colourspace
    
    Adds the other flavours of YUYV, and NV12.
    Corrects the overlay advertised colourspace.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Drop logging msg from info to debug
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Initial pass at scene modes.
    
    Only supports exposure mode and metering modes.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add manual white balance control.
    
    Adds support for V4L2_CID_RED_BALANCE and
    V4L2_CID_BLUE_BALANCE. Only has an effect if
    V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
    V4L2_WHITE_BALANCE_MANUAL selected.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    config: Enable V4L / MMAL driver
    
    V4L2: Increase the MMAL timeout to 3sec
    
    MJPEG codec flush is now taking longer and results
    in a kernel panic if the driver has stopped waiting for
    the result when it finally completes.
    Increase the timeout value from 1 to 3secs.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for setting H264_I_PERIOD
    
    Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
    to set the frequency with which I frames are produced.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Enable GPU function for removing padding from images.
    
    GPU can now support arbitrary strides, although may require
    additional processing to achieve it. Enable this feature
    so that the images delivered are the size requested.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for V4L2_PIX_FMT_BGR32
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Set the colourspace to avoid odd YUV-RGB conversions
    
    Removes the amiguity from the conversion routines and stops
    them dropping back to the SD vs HD choice of coeffs.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Make video/still threshold a run-time param
    
    Move the define for at what resolution the driver
    switches from a video mode capture to a stills mode
    capture to module parameters.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Fix incorrect pool sizing
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add option to disable enum_framesizes.
    
    Gstreamer's handling of a driver that advertises
    V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
    resolutions is broken. See bug
    https://bugzilla.gnome.org/show_bug.cgi?id=726521
    
    Optional parameter of gst_v4l2src_is_broken added.
    If non-zero, the driver claims not to support that
    ioctl, and gstreamer should be happy again (it
    guesses a set of defaults for itself).
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Add support for more image formats
    
    Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
    
    Request to extend the range from the fairly arbitrary
    1000 frames (33 seconds at 30fps). Extend out to the
    max range supported (int32 value).
    Also allow 0, which is handled by the codec as only
    send an I-frame on the first frame and never again.
    There may be an exception if it detects a significant
    scene change, but there's no easy way around that.
    
    Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
    
    bcm2835-camera: stop_streaming now has a void return
    
    BCM2835-V4L2: Fix compliance test failures
    
    VIDIOC_TRY_FMT and VIDIOC_S_FMT tests were faling due
    to reporting V4L2_COLORSPACE_JPEG when the colour
    format wasn't V4L2_PIX_FMT_JPEG.
    Now reports V4L2_COLORSPACE_SMPTE170M for YUV formats.
    
    bcm2835 camera planar/packed stride length
    
    Added a field to the mmal_fmt struct used to compute the bytes per line
    when using a particular format. This results in the correct stride being
    calculated even when the format is planar.
    
    Signed-off-by: Garrett Wilson <g@floft.net>
    
    bcm2835: camera: check for scene not being found
    
    static analysis by cppcheck detected some potential NULL pointer
    dereference issues:
    
    [drivers/media/platform/bcm2835/controls.c:854]: (error) Possible null
      pointer dereference: scene
      (and lines 858, 859 too)
    
    it is possible that scene is not found because of an invalue ctrl->val
    and is therefore NULL and hence causing a null pointer dereference.
    
    Signed-off-by: Colin Ian King <colin.king@canonical.com>
    
    bcm2835: memcpy port data to m rather than rmsg
    
    static analysis by cppcheck detected a memcpy to rmsg which is
    not actually initialized at that point.  The memcpy should be copying
    to variable m instead.
    
    Signed-off-by: Colin Ian King <colin.king@canonical.com>
    
    BCM2835-V4L2: Return buffers to videobuf2 on shutdown
    
    raspberrypi/linux#817
    Fixes the kernel warning from videobuf2 as buffers
    are now returned as they are being flushed on
    stop_streaming.
    
    squash: Fixup bcm2835-camera for changes in kernel 4.4 api
    
    v4l2: Fix up driver to upstream timestamp changes
    
    bcm2835-camera: fix a bug in computation of frame timestamp
    
    Fixes #1318
    
    V4L2 driver updates (#1393)
    
    * BCM2835-V4L2: Correct ISO control and add V4L2_CID_ISO_SENSITIVITY_AUTO
    
    raspberrypi/linux#1251
    
    V4L2_CID_ISO_SENSITIVITY was not advertising ISO*1000 as it should.
    V4L2_CID_ISO_SENSITIVITY_AUTO was not implemented, so was taking
    V4L2_CID_ISO_SENSITIVITY as 0 for auto mode.
    Still accepts 0 for auto, but also abides by the new parameter.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: Add a video_nr parameter.
    
    Adds a kernel parameter "video_nr" to specify the preferred
    /dev/videoX device node.
    https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=136120&p=905545
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: Add support for multiple cameras
    
    Ask GPU on load how many cameras have been detected, and
    enumerate that number of devices.
    Only applicable on the Compute Module as no other device
    exposes multiple CSI2 interfaces.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: Add control of the overlay location and alpha.
    
    Actually do something useful in vidioc_s_fmt_vid_overlay and
    vidioc_try_fmt_vid_overlay, rather than effectively having
    read-only fields.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: V4L2-Compliance failure fix
    
    VIDIOC_TRY_FMT was failing due to bytesperline not
    being set correctly by default.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    * BCM2835-V4L2: Make all module parameters static
    
    Clean up to correct variable scope
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    V4L2: Request maximum resolution from GPU
    
    Get resolution information about the sensors from the GPU
    and advertise it correctly.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    BCM2835-V4L2: Increase minimum resolution to 32x32
    
    raspberrypi/linux#1498 showed
    up that 16x16 is failing to work on the GPU for some reason.
    
    GPU bug being tracked on
    raspberrypi/firmware#607
    Workaround here by increasing minimum resolution via V4L2
    to 32x32.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    [media]: bcm2835-camera: fix compilation error
    
    There is an error when compiling rpi-4.6.y branch:
      CC [M]  drivers/media/platform/bcm2835/bcm2835-camera.o
    drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
      .queue_setup = queue_setup,
                     ^
    drivers/media/platform/bcm2835/bcm2835-camera.c:639:17: note: (near initialization for 'bm2835_mmal_video_qops.queue_setup')
    
    The const void *parg in setup_queue callback is not needed since commit:
    df9ecb0.
    This commit removes it.
    
    Signed-off-by: Slawomir Stepien <sst@poczta.fm>
    
    bcm2835-camera: Fix max/min error when looping over cameras/resolutions
    
    See: raspberrypi/linux#1447 (comment)
    
    BCM2835-V4L2: Correct handling for BGR24 vs RGB24.
    
    There was a bug in the GPU firmware that had reversed these
    two formats.
    Detect the old firmware, and reverse the formats if necessary.
    
    Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
    
    BCM2835-v4l2: Fix a conformance test failure
    
    Format ioctls:
            test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
            warn: v4l2-test-formats.cpp(1195): S_PARM is supported but
                    doesn't report V4L2_CAP_TIMEPERFRAME.
            fail: v4l2-test-formats.cpp(1118): node->has_frmintervals
                    && !cap->capability


Gbp-Pq: Topic rpi
Gbp-Pq: Name rpi_1049_f2d51efbeac118fa3c386f34cab3d7f2be7d5261.patch
raspbian-autopush pushed a commit to raspbian-packages/linux-4.9 that referenced this issue Nov 11, 2018
commit 0798a36
Author: Dave Stevenson <dave.stevenson@raspberrypi.org>
Date:   Fri Mar 10 14:43:15 2017 +0000

    bcm2835-v4l2: Fix buffer overflow problem
    
    raspberrypi/linux#1447
    port_parameter_get() failed to account for the header
    (u32 id and u32 size) in the size before memcpying
    the response into the response buffer, so overrunning
    the provided buffer by 8 bytes.
    
    Account for those bytes, and also a belt-and-braces
    check to ensure we never copy more than *value_size
    bytes into value.
    
    Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>


Gbp-Pq: Topic rpi
Gbp-Pq: Name rpi_1196_0798a364c331378ce6b37d6d4c276040505a5417.patch
phhusson pushed a commit to phhusson/dkms-rpi-codec that referenced this issue Jun 26, 2020
raspberrypi/linux#1447
port_parameter_get() failed to account for the header
(u32 id and u32 size) in the size before memcpying
the response into the response buffer, so overrunning
the provided buffer by 8 bytes.

Account for those bytes, and also a belt-and-braces
check to ensure we never copy more than *value_size
bytes into value.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
Signed-off-by: Michael Zoran <mzoran@crowfest.net>
Tested-by: Michael Zoran <mzoran@crowfest.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
krazey pushed a commit to krazey/android_kernel_samsung_exynos9810 that referenced this issue Mar 29, 2022
raspberrypi/linux#1447
port_parameter_get() failed to account for the header
(u32 id and u32 size) in the size before memcpying
the response into the response buffer, so overrunning
the provided buffer by 8 bytes.

Account for those bytes, and also a belt-and-braces
check to ensure we never copy more than *value_size
bytes into value.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
Signed-off-by: Michael Zoran <mzoran@crowfest.net>
Tested-by: Michael Zoran <mzoran@crowfest.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Waiting for internal comment Waiting for comment from a member of the Raspberry Pi engineering team
Projects
None yet
Development

No branches or pull requests