mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 01:49:46 +00:00
media: bcm2835-unicam: Driver for CCP2/CSI2 camera interface
Add a driver for the Unicam camera receiver block on BCM283x processors. Compared to the bcm2835-camera driver present in staging, this driver handles the Unicam block only (CSI-2 receiver), and doesn't depend on the VC4 firmware running on the VPU. The commit is made up of a series of changes cherry-picked from the rpi-5.4.y branch of https://github.com/raspberrypi/linux/ with additional enhancements, forward-ported to the mainline kernel. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reported-by: kbuild test robot <lkp@intel.com> media: bcm2835-unicam: Add support for get_mbus_config to set num lanes Use the get_mbus_config pad subdev call to allow a source to use fewer than the number of CSI2 lanes defined in device tree. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: Avoid gcc warning over {0} on endpoint Older gcc versions object to = { 0 } initialisation if the first elemtn in the structure is a substructure. Use = { } to avoid this compiler warning. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: Reinstate V4L2_CAP_READWRITE in the caps v4l2-compliance throws a failure if the device doesn't advertise V4L2_CAP_READWRITE but allows read or write operations. We do support read, so reinstate the flag. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: Ensure type is VIDEO_CAPTURE in [g|s]_selection [g|s]_selection pass in a buffer type that needs to be validated before passing on to the sensor subdev. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835: unicam: Set VPU min clock freq to 250Mhz. When streaming with Unicam, the VPU must have a clock frequency of at least 250Mhz. Otherwise, the input fifos could overrun, causing image corruption. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> media: bcm2835-unicam: Drop WARN on uing direct cache alias Pi 0&1 pass all ARM accesses through the VPU L2 cache, therefore the dma-ranges property sets the cache alias bits to other than the direct alias, hence this WARN was firing. It was overprotective coding, so assume that everything is OK with the dma-ranges, and remove the WARN. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: Always service interrupts From when bringing up the driver, there was a check in the isr to ignore interrupts (claiming them handled) should the driver not be streaming. The VPU now will not register a camera driver if it finds a CSI2 node enabled in device tree, therefore this flawed check is redundant. https://github.com/raspberrypi/linux/issues/3602 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835: unicam: Fix uninitialized warning Signed-off-by: Jacko Dirks <jdirks.linuxdev@gmail.com> media: bcm2835-unicam: Fixup review comments from Hans. Updates the driver based on the upstream review comments from Hans Verkuil at https://patchwork.linuxtv.org/patch/63531/ Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: Retain packing information on G_FMT The change to retrieve the pixel format always on g_fmt didn't check whether the native or unpacked version of the format had been requested, and always returned the packed one. Correct this so that the packing setting is retained whereever possible. Fixes "9d59e89 media: bcm2835-unicam: Re-fetch mbus code from subdev on a g_fmt call" Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: change minimum number of vb2_queue buffers to 1 Since the unicam driver was modified to write to a dummy buffer when no user-supplied buffer is available, it can now write to and return a buffer even when there's only a single one. Enable this by changing the min_buffers_needed in the vb2_queue; it will be useful for enabling still captures without allocating more memory than absolutely necessary. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> staging: vc04_services: ISP: Add a more complex ISP processing component Driver for the BCM2835 ISP hardware block. This driver uses the MMAL component to program the ISP hardware through the VC firmware. The ISP component can produce two video stream outputs, and Bayer image statistics. This can't be encompassed in a simple V4L2 M2M device, so create a new device that registers 4 video nodes. This patch squashes all the development patches from the earlier rpi-5.4.y branch into one Signed-off-by: Naushir Patuck <naush@raspberrypi.com> staging/bcm2835-isp: Add the unpacked (16bpp) raw formats Now that the firmware supports the unpacked (16bpp) variants of the MIPI raw formats, add the mappings. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> staging/bcm2835-isp: Log the number of excess supported formats When logging that the firmware has provided more supported formats than we had allocated storage for, log the number allocated and returned. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> staging: vc04_services: ISP: Add colour denoise control Add colour denoise control to the bcm2835 driver through a new v4l2 control: V4L2_CID_USER_BCM2835_ISP_CDN. Add the accompanying MMAL configuration structure definitions as well. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> bcm2835-isp: Allow formats with different colour spaces. Each supported format now includes a mask showing the allowed colour spaces, as well as a default colour space for when one was not specified. Additionally we translate the colour space to mmal format and pass it over to the VideoCore. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> media: i2c: add ov9281 driver. Change-Id: I7b77250bbc56d2f861450cf77271ad15f9b88ab1 Signed-off-by: Zefa Chen <zefa.chen@rock-chips.com> media: i2c: ov9281: fix mclk issue when probe multiple camera. Takes the ov9281 part only from the Rockchip's patch. Change-Id: I30e833baf2c1bb07d6d87ddb3b00759ab45a90e4 Signed-off-by: Zefa Chen <zefa.chen@rock-chips.com> media: i2c: ov9281: add enum_frame_interval function for iq tool 2.2 and hal3 Adds the ov9281 parts of the Rockchip patch adding enum_frame_interval to a large number of drivers. Change-Id: I03344cd6cf278dd7c18fce8e97479089ef185a5c Signed-off-by: Zefa Chen <zefa.chen@rock-chips.com> media: i2c: ov9281: Fixup for recent kernel releases, and remove custom code The Rockchip driver was based on a 4.4 kernel, and had several custom Rockchip parts. Update to 5.4 kernel APIs, with the relevant controls required by libcamera, and remove custom Rockchip parts. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: i2c: ov9281: Read chip ID via 2 reads Vision Components have made an OV9281 module which blocks reading back the majority of registers to comply with NDAs, and in doing so doesn't allow auto-increment register reading as used when reading the chip ID. Use two reads and manually combine the results. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: i2c: ov9281: Add support for 8 bit readout The sensor supports 8 bit mode as well as 10bit, so add the relevant code to allow selection of this. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: ov9281: Add 1280x720 and 640x480 modes Breaks out common register set and adds the different registers for 1280x720 (cropped) and 640x480 (skipped) modes Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> Fixed picture line bug in all ov9281 modes Signed-off-by: Mathias Anhalt <mathiasanhalt@web.de> Added hflip and vflip controls to ov9281 Signed-off-by: Mathias Anhalt <mathiasanhalt@web.de> media: i2c: ov9281: Remove override of subdev name From the original Rockchip driver, the subdev was renamed from the default to being "mov9281 <dev_name>" whereas the default would have been "ov9281 <dev_name>". Remove the override to drop back to the default rather than a vendor custom string. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: v4l2-subdev: add subdev-wide state struct Signed-off-by: Dom Cobley <popcornmix@gmail.com> media: i2c: ov9281: Add fwnode properties controls Add call to v4l2_ctrl_new_fwnode_properties to read and create the fwnode based controls. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: i2c: ov9281: Sensor should report RAW color space Tested on Raspberry Pi running libcamera. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> Partial revert "media: i2c: add ov9281 driver." This partially reverts commit84e98e3a4f. The commit had merged some changes to other drivers with adding the ov9281 driver. Only the ov9281 parts have been reverted. staging/bcm2835-isp: Fix compiler warning The result of dividing a u32 by a size_t is an unsigned int on arm32 and a long unsigned int on arm64. Use "%zu" (the size_t format) to remove the build warning for 64-bit builds. Signed-off-by: Phil Elwell <phil@raspberrypi.com> staging: vc04_services: isp: Set the YUV420/YVU420 format stride to 64 bytes The bcm2835 ISP requires the base address of all input/output planes to have 32 byte alignment. Using a Y stride of 32 bytes would not guarantee that the V plane would fulfil this, e.g. a height of 650 lines would mean the V plane buffer is not 32 byte aligned for YUV420 formats. Having a Y stride of 64 bytes would ensure both U and V planes have a 32 byte alignment, as the luma height will always be an even number of lines. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> vc04_services: isp: Report input node as wanting full range RAW color space RAW color spaces are more usually reported as having full range quantization. Tested using libcamera. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> drivers: bcm2835_isp: Allow multiple users for the ISP driver. Add a second (identical) set of device nodes to allow concurrent use of the ISP hardware by another user. This change effectively creates a second state structure (struct bcm2835_isp_dev) to maintain independent state for the second user. Node and media entity names are appened with the instance index appropriately. Further users can be added by changing the BCM2835_ISP_NUM_INSTANCES define. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> drivers: bcm2835_isp: Fix div by 0 bug. Fix a possible division by 0 bug when setting up the mmal port for the stats port. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> staging/bcm2835-isp: Fix cleanup after init fail bcm2835_isp_remove is called on an initialisation failure, but at that point the drvdata hasn't been set. This causes a crash when e.g. using the cutdown firmware (gpu_mem=16). Move platform_set_drvdata before the instance probing loop to avoid the problem. See: https://github.com/raspberrypi/linux/issues/4774 Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-v4l2-isp: Add missing lock initialization ISP device allocation is dynamic hence the locks too. struct mutex queue_lock is not initialized which result in bug. Fixing same by initializing it. [ 29.847138] INFO: trying to register non-static key. [ 29.847156] The code is fine but needs lockdep annotation, or maybe [ 29.847159] you didn't initialize this object before use? [ 29.847161] turning off the locking correctness validator. [ 29.847167] CPU: 1 PID: 343 Comm: v4l_id Tainted: G C 5.15.11-rt24-v8+ #8 [ 29.847187] Hardware name: Raspberry Pi 4 Model B Rev 1.4 (DT) [ 29.847194] Call trace: [ 29.847197] dump_backtrace+0x0/0x1b8 [ 29.847227] show_stack+0x20/0x30 [ 29.847240] dump_stack_lvl+0x8c/0xb8 [ 29.847254] dump_stack+0x18/0x34 [ 29.847263] register_lock_class+0x494/0x4a0 [ 29.847278] __lock_acquire+0x80/0x1680 [ 29.847289] lock_acquire+0x214/0x3a0 [ 29.847300] mutex_lock_nested+0x70/0xc8 [ 29.847312] _vb2_fop_release+0x3c/0xa8 [videobuf2_v4l2] [ 29.847346] vb2_fop_release+0x34/0x60 [videobuf2_v4l2] [ 29.847367] v4l2_release+0xc8/0x108 [videodev] [ 29.847453] __fput+0x8c/0x258 [ 29.847476] ____fput+0x18/0x28 [ 29.847487] task_work_run+0x98/0x180 [ 29.847502] do_notify_resume+0x228/0x3f8 [ 29.847515] el0_svc+0xec/0xf0 [ 29.847523] el0t_64_sync_handler+0x90/0xb8 [ 29.847531] el0t_64_sync+0x180/0x184 Signed-off-by: Padmanabha Srinivasaiah <treasure4paddy@gmail.com> staging: vc04_services: isp: Permit all sRGB colour spaces on ISP outputs ISP outputs actually support all colour spaces that are fundamentally sRGB underneath, regardless of whether an RGB or YUV output format is actually requested. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> drivers: staging: bcm2835-isp: Do not cleanup mmal vcsm buffer on stop_streaming On stop_streaming() the vcsm buffer handle gets released by the buffer cleanup code. This will subsequently cause and error if userland re-queues the same buffer on the next start_streaming() call. Remove this cleanup code and rely on the vb2_ops->buf_cleanup() call to do the cleanups instead. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> drivers: staging: bcm2835-isp: Clear LS table handle in the firmware When all nodes have stopped streaming, ensure the firmware has released its handle on the LS table dmabuf. This is done by passing a null handle in the LS params. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> drivers: staging: bcm2835-isp: Respect caller's stride value The stride value reported for output image buffers should be at least as large as any value that was passed in by the caller (subject to correct alignment for the pixel format). If the value is zero (meaning no value was passed), or is too small, the minimum acceptable value will be substituted. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> staging: vc04_services: bcm2835-isp: Drop include Makefile directive Drop the include directive. They can break the build, when one only wants to build a subdirectory. Replace with "../" for the includes in the bcm2835-isp instead. The fix is equivalent to the four patches between29d49a76c5("staging: vc04_services: bcm2835-audio: Drop include Makefile directive")...2529ca211402 ("staging: vc04_services: interface: Drop include Makefile directive") Fixes: c8f89c9551c1 ("staging: vc04_services: ISP: Add a more complex ISP processing component") Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> staging: vc04_services: bcm2835-v4l2-isp: Register with vchiq_bus_type Register the bcm2835-v4l2-isp driver with the vchiq_bus_type instead of using the platform driver/device. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> staging: vc04_services: bcm2835-v4l2-isp: Explicitly set DMA mask The platform model originally handled the DMA mask. Now that we are on the vchiq_bus we need to explicitly set this. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> drivers: media: bcm2835_isp: Cache LS table dmabuf Clients such as libcamera do not change the LS table dmabuf on every frame. In such cases instead of mapping/remapping the same dmabuf on every frame to send to the firmware, cache the dmabuf once and only update and remap if the dmabuf has been changed by the userland client. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> media: bcm2835-unicam: Correctly handle error propagation for stream on On a failure in start_streaming(), the error code would not propagate to the calling function on all conditions. This would cause the userland caller to not know of the failure. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> media: bcm2835-unicam: Return early from stop_streaming() if stopped clk_disable_unprepare() is called unconditionally in stop_streaming(). This is incorrect in the cases where start_streaming() fails, and unprepares all clocks as part of the failure cleanup. To avoid this, ensure that clk_disable_unprepare() is only called in stop_streaming() if the clocks are in a prepared state. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> media: bcm2835-unicam: Clear clock state when stopping streaming Commit65e08c4650failed to clear the clock state when the device stopped streaming. Fix this, as it might again cause the same problems when doing an unprepare. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> media: bcm2835-unicam: Fix bug in buffer swapping logic If multiple sets of interrupts occur simultaneously, it may be unsafe to swap buffers, as the hardware may already be re-using the current buffers. In such cases, avoid swapping buffers, and wait for the next opportunity at the Frame End interrupt to signal completion. Additionally, check the packet compare status when watching for frame end for buffers swaps, as this could also signify a frame end event. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> media: bcm2835-unicam: Forward input status from subdevice The vidioc_enum_input() v4l2 ioctl is capable of returning sensor/input status as well. This is used in current GStreamer HEAD for signal detection [1]. bcm2835-unicam does handle this syscall, but it didn't ask the subdevice driver about the input status. The input then appeared as always present. This commit adds the necessary query. There is a precedent for this - the R-Car VIN V4L2 driver does a similar call [2]. [1]:ce0be27caf/sys/v4l2/gstv4l2src.c (L553)[2]:7fb9d006d3/drivers/media/platform/rcar-vin/rcar-v4l2.c (L548)Signed-off-by: Jakub Vaněk <linuxtardis@gmail.com> media/bcm2835-unicam: Parse pad numbers correctly The driver was making big assumptions about the source device using pad 0 and 1, which doesn't follow for more complex devices where Unicam's source device may be a sink device for something else. Read the pad numbers through media controller, and reference them appropriately. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media/bcm2835-unicam: Add support for configuration via MC API Adds Media Controller API support for more complex pipelines. libcamera is about to switch to using this mechanism for configuring sensors. This can be enabled by either a module parameter, or device tree. Various functions have been moved to group video-centric and mc-centric functions together. Based on a similar conversion done to ti-vpe. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: Fixup for 5.18 and new get_mbus_config struct The number of active CSI2 data lanes has moved within the struct v4l2_mbus_config used by the get_mbus_config API call. Update the driver to match the changes in mainline. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> drivers: bcm2835_unicam: Add logging message when a frame is dropped. If a dummy buffer is still active on a frame start, it indicates that this frame will be dropped. The explicit logging helps users identify performance issues. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> drivers: bcm2835_unicam: Disable trigger mode operation On a Pi3 B/B+ platform the imx219 sensor frequently generates a single corrupt frame when the sensor first starts. This can either be a missing line, or invalid samples within the line. This only occurrs using the Unicam kernel driver. Disabling trigger mode elimiates this corruption. Since trigger mode is a legacy feature copied from the firmware driver and not expected to be needed, remove it. Tested on the Raspberry Pi cameras and shows no ill effects. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> media: bcm2835-unicam: Set ret on error path in unicam_async_complete() Clang warns: drivers/media/platform/bcm2835/bcm2835-unicam.c:3109:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] if (!source_pads) { ^~~~~~~~~~~~ drivers/media/platform/bcm2835/bcm2835-unicam.c:3152:9: note: uninitialized use occurs here return ret; ^~~ drivers/media/platform/bcm2835/bcm2835-unicam.c:3109:2: note: remove the 'if' if its condition is always false if (!source_pads) { ^~~~~~~~~~~~~~~~~~~ drivers/media/platform/bcm2835/bcm2835-unicam.c:3091:9: note: initialize the variable 'ret' to silence this warning int ret; ^ = 0 1 warning generated. When the if condition is true, ret will be used uninitialized, which could result in undesirable behavior. Set ret to -ENODEV on the error path, which is a standard error code for the ->complete() callback. Fixes:d056e86eb3("media/bcm2835-unicam: Parse pad numbers correctly") Signed-off-by: Nathan Chancellor <nathan@kernel.org> media: bcm2835-unicam: Handle a repeated frame start with no end In the case of 2 frame starts being received with no frame end between, the queued buffer held in next_frm was lost as the pointer was overwritten with the dummy buffer. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: Correctly handle FS + FE ISR condtion If we get a simultaneous FS + FE interrupt for the same frame, it cannot be marked as completed and returned to userland as the framebuffer will be refilled by Unicam on the next sensor frame. Additionally, the timestamp will be set to 0 as the FS interrupt handling code will not have run yet. To avoid these problems, the frame is considered dropped in the FE handler, and will be returned to userland on the subsequent sensor frame. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> media: bcm2835-unicam: Fix for possible dummy buffer overrun The Unicam hardware has been observed to cause a buffer overrun when using the dummy buffer as a circular buffer. The conditions that cause the overrun are not fully known, but it seems to occur when the memory bus is heavily loaded. To avoid the overrun, program the hardware with a buffer size of 0 when using the dummy buffer. This will cause overrun into the allocated dummy buffer, but avoid out of bounds writes. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> media: bcm2835-unicam: Fix up start/stop api change Signed-off-by: Dom Cobley <popcornmix@gmail.com> media: bcm2835-unicam: Use mipi-csi2.h header for data type values The MIPI CSI2 data type ID values are now defined in the mipi-csi2.h header, so use those defines instead of hard coding them in the driver. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: Add support for RAW16 formats With the RAW16 formats now having a defined CSI2 data type ID, they can be added to the driver. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: Start and stop media_pipeline with same node media_pipeline_start and media_pipeline_stop now validate that the pipeline is being started and stopped with the same pipe and pad handles. When running with embedded metadata (eg imx477 and imx708), the start typically happens from the metadata pad, whilst stop is always from the image pad. Always pass the image pad to media_pipeline_start to ensure that the calls are balanced. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> drivers: media: bcm2835_unicam: Improve frame sequence count handling Ensure that the frame sequence counter is incremented only if a previous frame start interrupt has occurred, or a frame start + frame end has occurred simultaneously. This corresponds the sequence number with the actual number of frames produced by the sensor, not the number of frame buffers dequeued back to userland. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> bcm2835-unicam: hacks to allow it to build media: bcm2835-unicam: Fix up async notifier usage Fixes "8a090fc3e549 bcm2835-unicam: hacks to allow it to build" media: bcm2835-unicam: Add option for a GPIO to reflect FS/FE timing The legacy stack had an option to have a GPIO track frame start and end events to give basic synchronisation to the incoming image stream. https://forums.raspberrypi.com/viewtopic.php?t=190314 Replicate this in the kernel Unicam driver. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: Add support for 12bit mono packed format Now that V4L2_PIX_FMT_Y12P is defined, allow passing raw 12bit mono packed data through the peripheral. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: Add support for 14bit mono sources Now that V4L2_PIX_FMT_Y14 and V4L2_PIX_FMT_Y14P are defined, allow passing 14bit mono data through the peripheral. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: Add support for unpacked 14bit Bayer formats Now that the 14bit non-packed Bayer formats are defined, add them into the supported formats lookup table. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> media: bcm2835-unicam: Reinstate old downstream driver as legacy Whilst the Unicam driver has now been upstreamed it only supports configuration via Media Controller (not driven from the /dev/videoN node), which makes life significantly harder for simple devices such as mono sensors, and HDMI or analogue video to CSI2 bridge chips (eg TC358743 and ADV7282M). Fix up the downstream driver so that it builds, reinstate the links from Kconfig and Makefile to it, and give it a new Kconfig name (VIDEO_BCM2835_UNICAM_LEGACY). Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
This commit is contained in:
committed by
Dom Cobley
parent
fd0986bd97
commit
a59c69b3bc
@@ -67,6 +67,7 @@ source "drivers/media/platform/amlogic/Kconfig"
|
||||
source "drivers/media/platform/amphion/Kconfig"
|
||||
source "drivers/media/platform/aspeed/Kconfig"
|
||||
source "drivers/media/platform/atmel/Kconfig"
|
||||
source "drivers/media/platform/bcm2835/Kconfig"
|
||||
source "drivers/media/platform/broadcom/Kconfig"
|
||||
source "drivers/media/platform/cadence/Kconfig"
|
||||
source "drivers/media/platform/chips-media/Kconfig"
|
||||
|
||||
@@ -10,6 +10,7 @@ obj-y += amlogic/
|
||||
obj-y += amphion/
|
||||
obj-y += aspeed/
|
||||
obj-y += atmel/
|
||||
obj-y += bcm2835/
|
||||
obj-y += broadcom/
|
||||
obj-y += cadence/
|
||||
obj-y += chips-media/
|
||||
|
||||
24
drivers/media/platform/bcm2835/Kconfig
Normal file
24
drivers/media/platform/bcm2835/Kconfig
Normal file
@@ -0,0 +1,24 @@
|
||||
# Broadcom VideoCore4 V4L2 camera support
|
||||
|
||||
config VIDEO_BCM2835_UNICAM_LEGACY
|
||||
tristate "Broadcom BCM283x/BCM271x Unicam video capture driver - no MC"
|
||||
depends on VIDEO_DEV
|
||||
depends on ARCH_BCM2835 || COMPILE_TEST
|
||||
select VIDEO_V4L2_SUBDEV_API
|
||||
select MEDIA_CONTROLLER
|
||||
select VIDEOBUF2_DMA_CONTIG
|
||||
select V4L2_FWNODE
|
||||
help
|
||||
Say Y here to enable support for the BCM283x/BCM271x CSI-2 receiver.
|
||||
This is a V4L2 driver that controls the CSI-2 receiver directly,
|
||||
independently from the VC4 firmware.
|
||||
This is the downstream version of this driver that still supports
|
||||
being driven from the video node for simple devices. The mainline
|
||||
driver only supports using Media Controller.
|
||||
This driver is mutually exclusive with the use of bcm2835-camera. The
|
||||
firmware will disable all access to the peripheral from within the
|
||||
firmware if it finds a DT node using it, and bcm2835-camera will
|
||||
therefore fail to probe.
|
||||
|
||||
To compile this driver as a module, choose M here. The module will be
|
||||
called bcm2835-unicam.
|
||||
4
drivers/media/platform/bcm2835/Makefile
Normal file
4
drivers/media/platform/bcm2835/Makefile
Normal file
@@ -0,0 +1,4 @@
|
||||
# Makefile for BCM2835 Unicam driver
|
||||
|
||||
bcm2835-unicam-legacy-y := bcm2835-unicam.o
|
||||
obj-$(CONFIG_VIDEO_BCM2835_UNICAM_LEGACY) += bcm2835-unicam-legacy.o
|
||||
3522
drivers/media/platform/bcm2835/bcm2835-unicam.c
Normal file
3522
drivers/media/platform/bcm2835/bcm2835-unicam.c
Normal file
File diff suppressed because it is too large
Load Diff
253
drivers/media/platform/bcm2835/vc4-regs-unicam.h
Normal file
253
drivers/media/platform/bcm2835/vc4-regs-unicam.h
Normal file
@@ -0,0 +1,253 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017-2020 Raspberry Pi Trading.
|
||||
* Dave Stevenson <dave.stevenson@raspberrypi.com>
|
||||
*/
|
||||
|
||||
#ifndef VC4_REGS_UNICAM_H
|
||||
#define VC4_REGS_UNICAM_H
|
||||
|
||||
/*
|
||||
* The following values are taken from files found within the code drop
|
||||
* made by Broadcom for the BCM21553 Graphics Driver, predominantly in
|
||||
* brcm_usrlib/dag/vmcsx/vcinclude/hardware_vc4.h.
|
||||
* They have been modified to be only the register offset.
|
||||
*/
|
||||
#define UNICAM_CTRL 0x000
|
||||
#define UNICAM_STA 0x004
|
||||
#define UNICAM_ANA 0x008
|
||||
#define UNICAM_PRI 0x00c
|
||||
#define UNICAM_CLK 0x010
|
||||
#define UNICAM_CLT 0x014
|
||||
#define UNICAM_DAT0 0x018
|
||||
#define UNICAM_DAT1 0x01c
|
||||
#define UNICAM_DAT2 0x020
|
||||
#define UNICAM_DAT3 0x024
|
||||
#define UNICAM_DLT 0x028
|
||||
#define UNICAM_CMP0 0x02c
|
||||
#define UNICAM_CMP1 0x030
|
||||
#define UNICAM_CAP0 0x034
|
||||
#define UNICAM_CAP1 0x038
|
||||
#define UNICAM_ICTL 0x100
|
||||
#define UNICAM_ISTA 0x104
|
||||
#define UNICAM_IDI0 0x108
|
||||
#define UNICAM_IPIPE 0x10c
|
||||
#define UNICAM_IBSA0 0x110
|
||||
#define UNICAM_IBEA0 0x114
|
||||
#define UNICAM_IBLS 0x118
|
||||
#define UNICAM_IBWP 0x11c
|
||||
#define UNICAM_IHWIN 0x120
|
||||
#define UNICAM_IHSTA 0x124
|
||||
#define UNICAM_IVWIN 0x128
|
||||
#define UNICAM_IVSTA 0x12c
|
||||
#define UNICAM_ICC 0x130
|
||||
#define UNICAM_ICS 0x134
|
||||
#define UNICAM_IDC 0x138
|
||||
#define UNICAM_IDPO 0x13c
|
||||
#define UNICAM_IDCA 0x140
|
||||
#define UNICAM_IDCD 0x144
|
||||
#define UNICAM_IDS 0x148
|
||||
#define UNICAM_DCS 0x200
|
||||
#define UNICAM_DBSA0 0x204
|
||||
#define UNICAM_DBEA0 0x208
|
||||
#define UNICAM_DBWP 0x20c
|
||||
#define UNICAM_DBCTL 0x300
|
||||
#define UNICAM_IBSA1 0x304
|
||||
#define UNICAM_IBEA1 0x308
|
||||
#define UNICAM_IDI1 0x30c
|
||||
#define UNICAM_DBSA1 0x310
|
||||
#define UNICAM_DBEA1 0x314
|
||||
#define UNICAM_MISC 0x400
|
||||
|
||||
/*
|
||||
* The following bitmasks are from the kernel released by Broadcom
|
||||
* for Android - https://android.googlesource.com/kernel/bcm/
|
||||
* The Rhea, Hawaii, and Java chips all contain the same VideoCore4
|
||||
* Unicam block as BCM2835, as defined in eg
|
||||
* arch/arm/mach-rhea/include/mach/rdb_A0/brcm_rdb_cam.h and similar.
|
||||
* Values reworked to use the kernel BIT and GENMASK macros.
|
||||
*
|
||||
* Some of the bit mnenomics have been amended to match the datasheet.
|
||||
*/
|
||||
/* UNICAM_CTRL Register */
|
||||
#define UNICAM_CPE BIT(0)
|
||||
#define UNICAM_MEM BIT(1)
|
||||
#define UNICAM_CPR BIT(2)
|
||||
#define UNICAM_CPM_MASK GENMASK(3, 3)
|
||||
#define UNICAM_CPM_CSI2 0
|
||||
#define UNICAM_CPM_CCP2 1
|
||||
#define UNICAM_SOE BIT(4)
|
||||
#define UNICAM_DCM_MASK GENMASK(5, 5)
|
||||
#define UNICAM_DCM_STROBE 0
|
||||
#define UNICAM_DCM_DATA 1
|
||||
#define UNICAM_SLS BIT(6)
|
||||
#define UNICAM_PFT_MASK GENMASK(11, 8)
|
||||
#define UNICAM_OET_MASK GENMASK(20, 12)
|
||||
|
||||
/* UNICAM_STA Register */
|
||||
#define UNICAM_SYN BIT(0)
|
||||
#define UNICAM_CS BIT(1)
|
||||
#define UNICAM_SBE BIT(2)
|
||||
#define UNICAM_PBE BIT(3)
|
||||
#define UNICAM_HOE BIT(4)
|
||||
#define UNICAM_PLE BIT(5)
|
||||
#define UNICAM_SSC BIT(6)
|
||||
#define UNICAM_CRCE BIT(7)
|
||||
#define UNICAM_OES BIT(8)
|
||||
#define UNICAM_IFO BIT(9)
|
||||
#define UNICAM_OFO BIT(10)
|
||||
#define UNICAM_BFO BIT(11)
|
||||
#define UNICAM_DL BIT(12)
|
||||
#define UNICAM_PS BIT(13)
|
||||
#define UNICAM_IS BIT(14)
|
||||
#define UNICAM_PI0 BIT(15)
|
||||
#define UNICAM_PI1 BIT(16)
|
||||
#define UNICAM_FSI_S BIT(17)
|
||||
#define UNICAM_FEI_S BIT(18)
|
||||
#define UNICAM_LCI_S BIT(19)
|
||||
#define UNICAM_BUF0_RDY BIT(20)
|
||||
#define UNICAM_BUF0_NO BIT(21)
|
||||
#define UNICAM_BUF1_RDY BIT(22)
|
||||
#define UNICAM_BUF1_NO BIT(23)
|
||||
#define UNICAM_DI BIT(24)
|
||||
|
||||
#define UNICAM_STA_MASK_ALL \
|
||||
(UNICAM_DL + \
|
||||
UNICAM_SBE + \
|
||||
UNICAM_PBE + \
|
||||
UNICAM_HOE + \
|
||||
UNICAM_PLE + \
|
||||
UNICAM_SSC + \
|
||||
UNICAM_CRCE + \
|
||||
UNICAM_IFO + \
|
||||
UNICAM_OFO + \
|
||||
UNICAM_PS + \
|
||||
UNICAM_PI0 + \
|
||||
UNICAM_PI1)
|
||||
|
||||
/* UNICAM_ANA Register */
|
||||
#define UNICAM_APD BIT(0)
|
||||
#define UNICAM_BPD BIT(1)
|
||||
#define UNICAM_AR BIT(2)
|
||||
#define UNICAM_DDL BIT(3)
|
||||
#define UNICAM_CTATADJ_MASK GENMASK(7, 4)
|
||||
#define UNICAM_PTATADJ_MASK GENMASK(11, 8)
|
||||
|
||||
/* UNICAM_PRI Register */
|
||||
#define UNICAM_PE BIT(0)
|
||||
#define UNICAM_PT_MASK GENMASK(2, 1)
|
||||
#define UNICAM_NP_MASK GENMASK(7, 4)
|
||||
#define UNICAM_PP_MASK GENMASK(11, 8)
|
||||
#define UNICAM_BS_MASK GENMASK(15, 12)
|
||||
#define UNICAM_BL_MASK GENMASK(17, 16)
|
||||
|
||||
/* UNICAM_CLK Register */
|
||||
#define UNICAM_CLE BIT(0)
|
||||
#define UNICAM_CLPD BIT(1)
|
||||
#define UNICAM_CLLPE BIT(2)
|
||||
#define UNICAM_CLHSE BIT(3)
|
||||
#define UNICAM_CLTRE BIT(4)
|
||||
#define UNICAM_CLAC_MASK GENMASK(8, 5)
|
||||
#define UNICAM_CLSTE BIT(29)
|
||||
|
||||
/* UNICAM_CLT Register */
|
||||
#define UNICAM_CLT1_MASK GENMASK(7, 0)
|
||||
#define UNICAM_CLT2_MASK GENMASK(15, 8)
|
||||
|
||||
/* UNICAM_DATn Registers */
|
||||
#define UNICAM_DLE BIT(0)
|
||||
#define UNICAM_DLPD BIT(1)
|
||||
#define UNICAM_DLLPE BIT(2)
|
||||
#define UNICAM_DLHSE BIT(3)
|
||||
#define UNICAM_DLTRE BIT(4)
|
||||
#define UNICAM_DLSM BIT(5)
|
||||
#define UNICAM_DLFO BIT(28)
|
||||
#define UNICAM_DLSTE BIT(29)
|
||||
|
||||
#define UNICAM_DAT_MASK_ALL (UNICAM_DLSTE + UNICAM_DLFO)
|
||||
|
||||
/* UNICAM_DLT Register */
|
||||
#define UNICAM_DLT1_MASK GENMASK(7, 0)
|
||||
#define UNICAM_DLT2_MASK GENMASK(15, 8)
|
||||
#define UNICAM_DLT3_MASK GENMASK(23, 16)
|
||||
|
||||
/* UNICAM_ICTL Register */
|
||||
#define UNICAM_FSIE BIT(0)
|
||||
#define UNICAM_FEIE BIT(1)
|
||||
#define UNICAM_IBOB BIT(2)
|
||||
#define UNICAM_FCM BIT(3)
|
||||
#define UNICAM_TFC BIT(4)
|
||||
#define UNICAM_LIP_MASK GENMASK(6, 5)
|
||||
#define UNICAM_LCIE_MASK GENMASK(28, 16)
|
||||
|
||||
/* UNICAM_IDI0/1 Register */
|
||||
#define UNICAM_ID0_MASK GENMASK(7, 0)
|
||||
#define UNICAM_ID1_MASK GENMASK(15, 8)
|
||||
#define UNICAM_ID2_MASK GENMASK(23, 16)
|
||||
#define UNICAM_ID3_MASK GENMASK(31, 24)
|
||||
|
||||
/* UNICAM_ISTA Register */
|
||||
#define UNICAM_FSI BIT(0)
|
||||
#define UNICAM_FEI BIT(1)
|
||||
#define UNICAM_LCI BIT(2)
|
||||
|
||||
#define UNICAM_ISTA_MASK_ALL (UNICAM_FSI + UNICAM_FEI + UNICAM_LCI)
|
||||
|
||||
/* UNICAM_IPIPE Register */
|
||||
#define UNICAM_PUM_MASK GENMASK(2, 0)
|
||||
/* Unpacking modes */
|
||||
#define UNICAM_PUM_NONE 0
|
||||
#define UNICAM_PUM_UNPACK6 1
|
||||
#define UNICAM_PUM_UNPACK7 2
|
||||
#define UNICAM_PUM_UNPACK8 3
|
||||
#define UNICAM_PUM_UNPACK10 4
|
||||
#define UNICAM_PUM_UNPACK12 5
|
||||
#define UNICAM_PUM_UNPACK14 6
|
||||
#define UNICAM_PUM_UNPACK16 7
|
||||
#define UNICAM_DDM_MASK GENMASK(6, 3)
|
||||
#define UNICAM_PPM_MASK GENMASK(9, 7)
|
||||
/* Packing modes */
|
||||
#define UNICAM_PPM_NONE 0
|
||||
#define UNICAM_PPM_PACK8 1
|
||||
#define UNICAM_PPM_PACK10 2
|
||||
#define UNICAM_PPM_PACK12 3
|
||||
#define UNICAM_PPM_PACK14 4
|
||||
#define UNICAM_PPM_PACK16 5
|
||||
#define UNICAM_DEM_MASK GENMASK(11, 10)
|
||||
#define UNICAM_DEBL_MASK GENMASK(14, 12)
|
||||
#define UNICAM_ICM_MASK GENMASK(16, 15)
|
||||
#define UNICAM_IDM_MASK GENMASK(17, 17)
|
||||
|
||||
/* UNICAM_ICC Register */
|
||||
#define UNICAM_ICFL_MASK GENMASK(4, 0)
|
||||
#define UNICAM_ICFH_MASK GENMASK(9, 5)
|
||||
#define UNICAM_ICST_MASK GENMASK(12, 10)
|
||||
#define UNICAM_ICLT_MASK GENMASK(15, 13)
|
||||
#define UNICAM_ICLL_MASK GENMASK(31, 16)
|
||||
|
||||
/* UNICAM_DCS Register */
|
||||
#define UNICAM_DIE BIT(0)
|
||||
#define UNICAM_DIM BIT(1)
|
||||
#define UNICAM_DBOB BIT(3)
|
||||
#define UNICAM_FDE BIT(4)
|
||||
#define UNICAM_LDP BIT(5)
|
||||
#define UNICAM_EDL_MASK GENMASK(15, 8)
|
||||
|
||||
/* UNICAM_DBCTL Register */
|
||||
#define UNICAM_DBEN BIT(0)
|
||||
#define UNICAM_BUF0_IE BIT(1)
|
||||
#define UNICAM_BUF1_IE BIT(2)
|
||||
|
||||
/* UNICAM_CMP[0,1] register */
|
||||
#define UNICAM_PCE BIT(31)
|
||||
#define UNICAM_GI BIT(9)
|
||||
#define UNICAM_CPH BIT(8)
|
||||
#define UNICAM_PCVC_MASK GENMASK(7, 6)
|
||||
#define UNICAM_PCDT_MASK GENMASK(5, 0)
|
||||
|
||||
/* UNICAM_MISC register */
|
||||
#define UNICAM_FL0 BIT(6)
|
||||
#define UNICAM_FL1 BIT(9)
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user