-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Improve NXP CSI and MIPI_CSI2Rx drivers #76475
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
Changes from all commits
31e9847
8507244
5af4c2b
ac2e131
36be625
95c31de
0732cf1
5a2ddea
e95d199
7528267
f4bb2da
9a61086
c957768
c9849af
aea820d
361c47f
d07370c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <zephyr/dt-bindings/video/video-interfaces.h> | ||
|
|
||
| /{ | ||
| chosen { | ||
| zephyr,camera = &nxp_csi; | ||
|
|
@@ -21,7 +23,9 @@ | |
|
|
||
| port { | ||
| ov5640_ep_out: endpoint { | ||
| remote-endpoint = <&mipi_csi2rx_ep_in>; | ||
|
||
| remote-endpoint-label = "mipi_csi2rx_ep_in"; | ||
| bus-type = <VIDEO_BUS_TYPE_CSI2_DPHY>; | ||
| data-lanes = <1 2>; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
@@ -30,14 +34,13 @@ | |
| &nxp_mipi_csi { | ||
| status = "okay"; | ||
|
|
||
| sensor = <&ov5640>; | ||
|
|
||
| ports { | ||
| port@1 { | ||
| reg = <1>; | ||
|
|
||
| mipi_csi2rx_ep_in: endpoint { | ||
| remote-endpoint = <&ov5640_ep_out>; | ||
| remote-endpoint-label = "ov5640_ep_out"; | ||
| data-lanes = <1 2>; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| /* | ||
| * Copyright (c) 2019, Linaro Limited | ||
| * Copyright 2024 NXP | ||
|
||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
@@ -17,6 +18,16 @@ | |
| #include <fsl_cache.h> | ||
| #endif | ||
|
|
||
| #if defined(CONFIG_VIDEO_MCUX_MIPI_CSI2RX) | ||
| #define DEVICE_DT_INST_GET_SOURCE_DEV(n) \ | ||
| DEVICE_DT_GET(DT_PARENT(DT_GPARENT(DT_NODELABEL(DT_STRING_TOKEN( \ | ||
| DT_CHILD(DT_INST_CHILD(n, port), endpoint), remote_endpoint_label))))) | ||
| #else | ||
| #define DEVICE_DT_INST_GET_SOURCE_DEV(n) \ | ||
| DEVICE_DT_GET(DT_GPARENT(DT_NODELABEL(DT_STRING_TOKEN( \ | ||
| DT_CHILD(DT_INST_CHILD(n, port), endpoint), remote_endpoint_label)))) | ||
| #endif | ||
|
|
||
| struct video_mcux_csi_config { | ||
| CSI_Type *base; | ||
| const struct device *source_dev; | ||
|
|
@@ -32,25 +43,6 @@ struct video_mcux_csi_data { | |
| struct k_poll_signal *signal; | ||
| }; | ||
|
|
||
| static inline unsigned int video_pix_fmt_bpp(uint32_t pixelformat) | ||
ngphibang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| switch (pixelformat) { | ||
| case VIDEO_PIX_FMT_BGGR8: | ||
| case VIDEO_PIX_FMT_GBRG8: | ||
| case VIDEO_PIX_FMT_GRBG8: | ||
| case VIDEO_PIX_FMT_RGGB8: | ||
| return 1; | ||
| case VIDEO_PIX_FMT_RGB565: | ||
| case VIDEO_PIX_FMT_YUYV: | ||
| return 2; | ||
| case VIDEO_PIX_FMT_XRGB32: | ||
| case VIDEO_PIX_FMT_XYUV32: | ||
| return 4; | ||
| default: | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| static void __frame_done_cb(CSI_Type *base, csi_handle_t *handle, status_t status, void *user_data) | ||
| { | ||
| struct video_mcux_csi_data *data = user_data; | ||
|
|
@@ -450,6 +442,42 @@ static int video_mcux_csi_set_signal(const struct device *dev, enum video_endpoi | |
| } | ||
| #endif | ||
|
|
||
| static int video_mcux_csi_set_frmival(const struct device *dev, enum video_endpoint_id ep, | ||
| struct video_frmival *frmival) | ||
| { | ||
| const struct video_mcux_csi_config *config = dev->config; | ||
|
|
||
| return video_set_frmival(config->source_dev, ep, frmival); | ||
| } | ||
|
|
||
| static int video_mcux_csi_get_frmival(const struct device *dev, enum video_endpoint_id ep, | ||
| struct video_frmival *frmival) | ||
| { | ||
| const struct video_mcux_csi_config *config = dev->config; | ||
|
|
||
| return video_get_frmival(config->source_dev, ep, frmival); | ||
| } | ||
|
|
||
| static int video_mcux_csi_enum_frmival(const struct device *dev, enum video_endpoint_id ep, | ||
| struct video_frmival_enum *fie) | ||
| { | ||
| const struct video_mcux_csi_config *config = dev->config; | ||
| const struct video_format *fie_fmt = fie->format; | ||
| int ret; | ||
|
|
||
| #if defined(CONFIG_VIDEO_MCUX_MIPI_CSI2RX) | ||
| struct video_format converted_fmt = *fie->format; | ||
|
|
||
| video_pix_fmt_convert(&converted_fmt, false); | ||
| fie->format = &converted_fmt; | ||
| #endif | ||
|
|
||
| ret = video_enum_frmival(config->source_dev, ep, fie); | ||
| fie->format = fie_fmt; | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| static const struct video_driver_api video_mcux_csi_driver_api = { | ||
| .set_format = video_mcux_csi_set_fmt, | ||
| .get_format = video_mcux_csi_get_fmt, | ||
|
|
@@ -461,6 +489,9 @@ static const struct video_driver_api video_mcux_csi_driver_api = { | |
| .set_ctrl = video_mcux_csi_set_ctrl, | ||
| .get_ctrl = video_mcux_csi_get_ctrl, | ||
| .get_caps = video_mcux_csi_get_caps, | ||
| .set_frmival = video_mcux_csi_set_frmival, | ||
| .get_frmival = video_mcux_csi_get_frmival, | ||
| .enum_frmival = video_mcux_csi_enum_frmival, | ||
| #ifdef CONFIG_POLL | ||
| .set_signal = video_mcux_csi_set_signal, | ||
| #endif | ||
|
|
@@ -471,7 +502,7 @@ PINCTRL_DT_INST_DEFINE(0); | |
|
|
||
| static const struct video_mcux_csi_config video_mcux_csi_config_0 = { | ||
| .base = (CSI_Type *)DT_INST_REG_ADDR(0), | ||
| .source_dev = DEVICE_DT_GET(DT_INST_PHANDLE(0, source)), | ||
| .source_dev = DEVICE_DT_INST_GET_SOURCE_DEV(0), | ||
| .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0), | ||
| }; | ||
|
|
||
|
|
@@ -490,11 +521,6 @@ static int video_mcux_csi_init_0(const struct device *dev) | |
| return video_mcux_csi_init(dev); | ||
| } | ||
|
|
||
| /* CONFIG_KERNEL_INIT_PRIORITY_DEVICE is used to make sure the | ||
| * CSI peripheral is initialized before the camera, which is | ||
| * necessary since the clock to the camera is provided by the | ||
| * CSI peripheral. | ||
| */ | ||
| DEVICE_DT_INST_DEFINE(0, &video_mcux_csi_init_0, NULL, &video_mcux_csi_data_0, | ||
| &video_mcux_csi_config_0, POST_KERNEL, CONFIG_VIDEO_MCUX_CSI_INIT_PRIORITY, | ||
| &video_mcux_csi_driver_api); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.