Commit graph

235 commits

Author SHA1 Message Date
sudarsan N
48bbbfe976 drivers: video: fix NULL dereference in mipid02_get_fmt
Category: Null pointer dereference (CWE-476)

Corrects the logic that validates the result of mipid04_get_format_desc().
Previously, the check was inverted, which could lead to a NULL pointer
dereference when accessing desc->pixelformat.

Fixes Coverity CID: 525183

Signed-off-by: sudarsan N <sudarsansamy2002@gmail.com>
2025-06-20 11:50:49 +01:00
Phi Bang Nguyen
10deca2ef6 drivers: video: Fix skipped CIDs when enumerating controls
When enumerating controls with VIDEO_CTRL_FLAG_NEXT_CTRL, if child devices
have controls with IDs lower or equal to the ones in the parent devices,
those controls will be accidentally skipped.

Fix this by resetting the query's ID and tracking of the queried device in
the query when moving to the next device in the pipeline.

Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-06-19 22:37:54 -07:00
Kate Wang
e2d97c7ca6 drivers: video: ov7670: update the camera init sequence
The previous initialization sequence fails to configure the module
properly. Update the sequence using the code provided by vendor.
The update is verified using the FRDM-MCXN947 SmartDMA camera case
under samples/drivers/video/capture.

Signed-off-by: Kate Wang <yumeng.wang@nxp.com>
2025-06-19 14:04:45 +02:00
Benjamin Cabé
e3a7a32334 drivers: video: mt9m114: add missing const qualifiers
Ensure that the various configuration tables are marked as const to save
on RAM usage.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-18 17:46:35 -04:00
Benjamin Cabé
b35ba2d40e drivers: video: adopt SHELL_HELP
Adopt SHELL_HELP macro for video_shell

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-13 10:17:08 -07:00
sudarsan N
cda6858d99 drivers: video: fix null deref in video_get_csi_link_freq()
Add null and bounds checks before accessing int_menu[ctrl.val].

CID: 525179
Fixes: #91244

Signed-off-by: sudarsan N <sudarsansamy2002@gmail.com>
2025-06-13 10:10:13 +02:00
Josuah Demangeon
a3728d71e9 drivers: video: common: avoid dead code in functions with retry
Avoid k_sleep() never being called when video_write_reg_retry() and
video_read_reg_retry() have a number of retry set to zero (default).
The default number of retries being controlled by
CONFIG_VIDEO_I2C_RETRY_NUM.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-06-13 07:36:37 +02:00
Alain Volmat
fea5c421b4 drivers: video: dcmipp: add functions for external ISP functions usage
Add weak functions and their call within the dcmipp driver so that
externally provided ISP control functions can be called by the
driver at right timing in order to perform the control of the
ISP part of the DCMIPP.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-06 10:10:58 +02:00
Alain Volmat
cd8dccf211 drivers: video: introduction of the stm32 DCMIPP driver
The STM32 Digital Camera Memory Interface Pixel Processor (DCMIPP)
is a multi-pipeline camera interface allowing to capture
and process frames from parallel or CSI interfaces depending on its
version.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-06 10:10:58 +02:00
Alain Volmat
3db7b40238 video: introduction of driver for Omnivision OV9655
This commit add support for the Omnivision OV9655 sensor,
a 1.3MPix Color SXGA (1280x1024 sensor).
Current driver only allow output of 320x240 and 160x120
resolution either in RGB565 or YUYV.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-04 15:50:24 -04:00
Alain Volmat
9c62fb8810 video: stm32: dcmi: correct typo dmci -> dcmi
DMA callback is wrongly named as dmci in the source code,
correct the name to be dcmi_dma_callback.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-04 15:50:24 -04:00
Alain Volmat
64149e4df6 video: stm32_dcmi: addition of STM32L4 DMA support
The STM32 DMA LL api differ between the STM32F7 and the STM32L4
in order to get the CHANNEL instance information.  For that
reason, enclose within preproc statements STM32F7 specific code
and add STM32L4 code related to the DMA configuration for the
DCMI peripheral.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-04 15:50:24 -04:00
Alain Volmat
b03ec6dd29 video: stm32: dcmi: fix video interface properties read
This commit fixes an error introduced by commit c0dae0c9ac
("video: stm32: dcmi: perform config based on endpoint properties")
in which incorrect instance was being access leading to usage of
the default value for pixel clock / hsync / vsync polarities and bus
width.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-04 15:50:24 -04:00
Alain Volmat
2c2b2268af video: imx335: only include gpio code if needed
Rely on DT_ANY_INST_HAS_PROP_STATUS_OKAY to only build the
gpio handling code for reset pin if this is being used by
one or more instance of the device.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-02 22:35:45 -04:00
Alain Volmat
fc6d5c4871 video: imx335: increase T4 delay post reset
Increase the T4 delay after releasing the reset of the
sensor in order to avoid getting I2C communication issues
at initialization time.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-02 22:35:45 -04:00
Alain Volmat
4e63863b46 video: ov5640: only include gpio code if needed
Rely on DT_ANY_INST_HAS_PROP_STATUS_OKAY to only build the
gpio handling code for reset and powerdown pins if this is
being used by one or more instance of the device.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-02 22:35:45 -04:00
Alain Volmat
9f81f4f7ec video: ov5640: allow usage without reset or powerdown gpios
reset and powerdown pins are optionals.

gpio_is_ready_dt should not be called in case of reset or
powerdown are not present.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-02 22:35:45 -04:00
Josuah Demangeon
a3465f8f4d drivers: video: sw_generator: convert to use the devicetree
Make the video software generator a devicetree node, which allows enabling
several instances, and select it as chosen { zephyr,camera = &... }; node.
It can be enabled via a `video-sw-generator` snippet.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-06-02 05:48:21 +02:00
Alain Volmat
5fa26d9aea video: gc2145: use VGA resolution as default
Since QVGA resolution is currently not working in CSI, use VGA
as default resolution to avoid failing during the init of the
driver.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-02 05:48:12 +02:00
Alain Volmat
79e218aaf4 video: gc2145: add CSI mode of the GC2145 sensor
Add possibility to use the gc2145 sensor in CSI mode by
adding the bus-type property in the device-tree.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-02 05:48:12 +02:00
Alain Volmat
979d8ff0fe video: gc2145: avoid default DVP enabling
Do not enable by default the DVP streaming to avoid conflict
with the introduction of the MIPI mode of the GC2145.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-02 05:48:12 +02:00
Alain Volmat
eeab052505 video: st_mipid02: addition of ST MIPID02 CSI bridge
Addition of the support for the CSI to DVP bridge ST MIPID02.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-02 05:48:03 +02:00
Alain Volmat
b0432a8f48 video: add LINK_FREQ ctrl and a helper to retrieve it
Add a ctrl VIDEO_CID_LINK_FREQ to indicate to a sink
the frequency at which a device streams data over
CSI2. Since not all source device currently provide the
LINK_FREQ control, add a helper function to retrieve
it, with a fall-back by doing an approximate via the
PIXEL_RATE control.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-02 05:48:03 +02:00
Alain Volmat
b5d8aee7d7 video: common: addition of INTEGER_MENU control type
Add a new INTEGER_MENU type allowing to store signed 64bits
integer into a menu.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-06-02 05:48:03 +02:00
Alain Volmat
087a08c5fb video: sw_generator: remove frmival values check
Now that api core functions check that denominator / numerator are not
null, it is no more necessary to perform this check within drivers.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-05-28 05:54:15 +02:00
Alain Volmat
5623772ff3 video: remove valid pointer check in api entry points
Now that video api functions have __ASSERT_NO_MSG calls, drivers
do not need to check the entry point functions pointers.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-05-28 05:54:15 +02:00
Alain Volmat
08df2fd92e video: common: add __ASSERT_NO_MSG in video api function entry
Protect video API functions via __ASSERT_NO_MSG call to ensure that
required pointers are valid when entering functions.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-05-28 05:54:15 +02:00
Phi Bang Nguyen
e462ef3c07 drivers: video: ov7670: Set default format to RGB565 QVGA
The default format for ov7670 is currently VGA YUYV and it counts on the
smartdma to reset the format to RGB565 QVGA when get_format() is called.

Recently, set_format() is decoupled from get_format() so this assumption
is nolonger correct.

Set the default format to RGB565 QVGA instead.

Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
2025-05-23 15:39:31 +02:00
Alain Volmat
1d6c2c7926 drivers: video: introduction of imx335 sensor driver
Add support for the Sony IMX335 CSI sensor.
This sensor supports resolution of 2592x1944 in RGGB bayer format
either 10 or 12 bits and using 2 or 4 CSI lanes.
For the time being only 10 bits on 2 CSI lanes is supported via
this commit.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-05-22 20:56:38 +02:00
Josuah Demangeon
638cb67191 drivers: video: sw_generator: sort header alphabetically
Sort alphabetically the header added in the previous few commits
as well as the original implementation.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-05-21 19:56:30 +02:00
Josuah Demangeon
4f344584ce drivers: video: sw_generator: fix div by zero on very low framerate
When the FPS value stored in data->frame_rate is zero, a division by zero
occurs. Fix it by clamping the frame rate between min and max values.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-05-21 19:56:30 +02:00
Josuah Demangeon
5687dc80c7 drivers: video: sw_generator: make k_work_sync a local variable
The documentation of k_work_cancel_delayable_sync() states that the input
k_work_sync parameter needs to be valid until the function call returns,
so there is no need to preserve the state across successive calls.
Now that there is a single work-related field in the struct, rename it
to simply "work".

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-05-21 19:56:30 +02:00
Josuah Demangeon
04912d461b drivers: video: sw_generator: introduce the RGB24 test pattern
This complements the 32-bit RGB (XRGB32) test pattern with an equivalent
24-bit RGB (RGB24) implementation.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-05-21 19:56:30 +02:00
Josuah Demangeon
d1e71ae901 drivers: video: sw_generator: add support for bayer and YUV formats
This refactors the pattern generator functions to also offer bayer formats
as input. 4 variant of bayer formats are proposed. The pixel packing is
also now split from the color selection: only a single RGB and single YUV
array used by all the pattern generators.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-05-21 19:56:30 +02:00
Josuah Demangeon
70b4b93985 drivers: video: sw_generator: modify video_sw_generator_fill_colorbar()
Add a check for the array size to avoid overwriting unrelated memory when
the buffer is too small for the full format. It first check if there is
enough buffer for one line, and fill it programmatically. Then, it will
try to duplicate that line over the entire buffer, in the limit of the
room available.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-05-21 19:56:30 +02:00
Josuah Demangeon
82d2f94f12 drivers: video: sw_generator: fix video_sw_generator_enum_frmival()
Return an error on fie.index >= 1 as there is only one framerate entry
per pixelformat, this prevents an endless loop.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-05-21 19:56:30 +02:00
Josuah Demangeon
ba5d3bad8b drivers: video: sw_generator: use video_format_caps_index()
Use the video_format_caps_index() function to check if a format matches
any entry of the format caps.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-05-21 19:56:30 +02:00
Josuah Demangeon
c15f24de60 drivers: video: sw_generator: refactor: flatten arrays
Help with maintainance and possibly readability by using a more regular
layout for various tables of numbers. This adds a comma on the last
element to help with formatters like clang-format.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-05-21 19:56:30 +02:00
Josuah Demangeon
d8d04ba66b drivers: video: sw_generator: preserve full prefix for internal functions
In order to help debugging through GDB and other error messages and debug
tools, convert the __xxx prefix to video_sw_generator_xxx full prefix.
To help keep function names short, use slightly shorter sufixes.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-05-21 19:56:30 +02:00
Alberto Escolar Piedras
ed4ed05501 drivers/video/video_ctrls: Fix code compliance issues
Fix issues detected by checkpatch

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-05-21 12:35:28 +02:00
Josuah Demangeon
c8ff2b89d9 drivers: video: common: introduce CCI utilities
Add a library for the Camera Common Interface, part of the MIPI CSI
protocol standard defining methods to configure a camera device over I2C,
such as which size for the register address/data.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-05-21 08:01:12 +02:00
Josuah Demangeon
c67b915482 drivers: video: shell: introduce the video shell
Introduce the video shell and implement some video shell commands.
Make use of the various querying API to implement tab-completion, and
validiate the data, as well as convert string names into integers.
Commands provided: frmival, format, ctrl, start, stop, capture

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-05-20 18:27:43 +02:00
Phi Bang Nguyen
075ee09bd1 drivers: video: mcux_smartdma: Don't set_format() in get_format()
Do not set_format() when doing get_format(). This design seems initially
to simplify the sample (just get_format() and everything works out of the
box) but it makes thing incomprehensive and error prone.

Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
2025-05-20 18:27:35 +02:00
Phi Bang Nguyen
d0eedc5192 drivers: video: mcux_csi: Don't set_format() in get_format()
Do not set_format() when doing get_format(). This design seems initially
to simplify the sample (just get_format() and everything works out of the
box) but it makes thing incomprehensive and error prone.

Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
2025-05-20 18:27:35 +02:00
Phi Bang Nguyen
0c1e2c9e6d drivers: video: Move format pitch setting to bridge drivers
The format pitch (bytesperline) field is typically set by the bridge
drivers, i.e. DMA, ISP drivers who actually handle the memory as they
know exactly the memory layout constraints.

Application just set the pixel format and resolution and must always
read back this field to see what the driver actually sets (to allocate
buffers for example).

Also, drop format pitch setting in sensor drivers as this is not needed.

Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
2025-05-20 18:27:35 +02:00
Phi Bang Nguyen
0b090fafa3 drivers: video: stm32-dcmi: Drop video_stm32_dcmi_is_fmt_valid
Drop video_stm32_dcmi_is_fmt_valid() as it is not needed. In this
function, (i) checking against a format based on another utility
function video_bits_per_pixel() is not robust, this check is done in
the sensor driver, (ii) checking against the heap size is not
appropriate because this should be done when allocating buffers, not
in get/set format.

Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
2025-05-20 18:27:35 +02:00
Phi Bang Nguyen
fcadb792be drivers: video: Compute bits per pixel according to format
Compute bits per pixel according to the pixel format instead of
hardcoding it.

Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
2025-05-20 18:27:35 +02:00
Trung Hieu Le
da12135525 drivers: video: ov5640: Fix constrast value sign
Fix sign's register for constrast value.

Signed-off-by: Trung Hieu Le <trunghieu.le@nxp.com>
Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
2025-05-20 18:27:35 +02:00
Trung Hieu Le
a3c31a5ca1 drivers: video: ov5640: Fix brightness control register
Fix the sign register for brightness control

Signed-off-by: Trung Hieu Le <trunghieu.le@nxp.com>
Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
2025-05-20 18:27:35 +02:00
Trung Hieu Le
cc5f5506da drivers: video: ov5640: Fix HUE register write
SDE_CTRL8_REG's value must be modified using modify_register.

Signed-off-by: Trung Hieu Le <trunghieu.le@nxp.com>
Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
2025-05-20 18:27:35 +02:00