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

video: drivers misc fixes #87366

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boards/shields/dvp_fpc24_mt9m114/dvp_fpc24_mt9m114.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

&dvp_fpc24_i2c {
mt9m114: mt9m114@48 {
compatible = "aptina,mt9m114";
compatible = "onnn,mt9m114";
reg = <0x48>;

port {
Expand Down
2 changes: 1 addition & 1 deletion doc/releases/release-notes-2.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ Drivers and Sensors

* Video

* Added MCUX CSI and Aptina MT9M114 drivers
* Added MCUX CSI and Onsemi MT9M114 drivers
* Added software video pattern generator driver

* Watchdog
Expand Down
7 changes: 7 additions & 0 deletions drivers/video/Kconfig.emul_rx
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ config VIDEO_EMUL_RX
default y
help
Enable driver for the MIPI RX emulated DMA engine.

config VIDEO_EMUL_RX_INIT_PRIORITY
int "Emul Rx init priority"
default 61
depends on VIDEO_EMUL_RX
help
Initialization priority for the EMUL Rx device.
7 changes: 7 additions & 0 deletions drivers/video/Kconfig.mcux_mipi_csi2rx
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ config VIDEO_MCUX_MIPI_CSI2RX
default y
depends on DT_HAS_NXP_MIPI_CSI2RX_ENABLED
select VIDEO_MCUX_CSI

config VIDEO_MCUX_MIPI_CSI2RX_INIT_PRIORITY
int "NXP MCUX CSI-2 Rx init priority"
default 61
depends on VIDEO_MCUX_MIPI_CSI2RX
help
Initialization priority for the MIPI CSI-2 Rx device.
4 changes: 2 additions & 2 deletions drivers/video/Kconfig.mt9m114
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# SPDX-License-Identifier: Apache-2.0

config VIDEO_MT9M114
bool "MT9M114 Aptina CMOS digital image sensor"
bool "MT9M114 Onsemi CMOS digital image sensor"
select I2C
depends on DT_HAS_APTINA_MT9M114_ENABLED
depends on DT_HAS_ONNN_MT9M114_ENABLED
default y
help
Enable driver for MT9M114 CMOS digital image sensor device.
52 changes: 23 additions & 29 deletions drivers/video/mt9m114.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#define DT_DRV_COMPAT aptina_mt9m114
#define DT_DRV_COMPAT onnn_mt9m114

#include <zephyr/kernel.h>
#include <zephyr/device.h>
Expand Down Expand Up @@ -165,7 +165,7 @@ static struct mt9m114_reg mt9m114_1280_720[] = {
{MT9M114_CAM_STAT_AE_INITIAL_WINDOW_YEND, 2, 0x008F}, /* 143 */
{/* NULL terminated */}};

static struct mt9m114_resolution_config resolutionConfigs[] = {
static struct mt9m114_resolution_config resolution_configs[] = {
{.width = 480, .height = 272, .params = mt9m114_480_272},
{.width = 640, .height = 480, .params = mt9m114_640_480},
{.width = 1280, .height = 720, .params = mt9m114_1280_720},
Expand Down Expand Up @@ -424,10 +424,10 @@ static int mt9m114_set_fmt(const struct device *dev, enum video_endpoint_id ep,
}

/* Set output resolution */
for (i = 0; i < ARRAY_SIZE(resolutionConfigs); i++) {
if (fmt->width == resolutionConfigs[i].width &&
fmt->height == resolutionConfigs[i].height) {
ret = mt9m114_write_all(dev, resolutionConfigs[i].params);
for (i = 0; i < ARRAY_SIZE(resolution_configs); i++) {
if (fmt->width == resolution_configs[i].width &&
fmt->height == resolution_configs[i].height) {
ret = mt9m114_write_all(dev, resolution_configs[i].params);
if (ret) {
LOG_ERR("Unable to set resolution");
return ret;
Expand Down Expand Up @@ -501,10 +501,16 @@ static DEVICE_API(video, mt9m114_driver_api) = {

static int mt9m114_init(const struct device *dev)
{
const struct mt9m114_config *cfg = dev->config;
struct video_format fmt;
uint16_t val;
int ret;

if (!device_is_ready(cfg->i2c.bus)) {
LOG_ERR("Bus device is not ready");
return -ENODEV;
}

/* no power control, wait for camera ready */
k_sleep(K_MSEC(100));

Expand Down Expand Up @@ -547,26 +553,14 @@ static int mt9m114_init(const struct device *dev)
return 0;
}

#if 1 /* Unique Instance */

static const struct mt9m114_config mt9m114_cfg_0 = {
.i2c = I2C_DT_SPEC_INST_GET(0),
};

static struct mt9m114_data mt9m114_data_0;

static int mt9m114_init_0(const struct device *dev)
{
const struct mt9m114_config *cfg = dev->config;

if (!device_is_ready(cfg->i2c.bus)) {
LOG_ERR("Bus device is not ready");
return -ENODEV;
}

return mt9m114_init(dev);
}

DEVICE_DT_INST_DEFINE(0, &mt9m114_init_0, NULL, &mt9m114_data_0, &mt9m114_cfg_0, POST_KERNEL,
CONFIG_VIDEO_INIT_PRIORITY, &mt9m114_driver_api);
#endif
#define MT9M114_INIT(n) \
static struct mt9m114_data mt9m114_data_##n; \
\
static const struct mt9m114_config mt9m114_cfg_##n = { \
.i2c = I2C_DT_SPEC_INST_GET(n), \
}; \
\
DEVICE_DT_INST_DEFINE(n, &mt9m114_init, NULL, &mt9m114_data_##n, &mt9m114_cfg_##n, \
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &mt9m114_driver_api);

DT_INST_FOREACH_STATUS_OKAY(MT9M114_INIT)
67 changes: 46 additions & 21 deletions drivers/video/ov5640.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ struct ov5640_mode_config {

struct ov5640_data {
struct video_format fmt;
uint64_t cur_pixrate;
uint32_t cur_pixrate;
uint16_t cur_frmrate;
const struct ov5640_mode_config *cur_mode;
bool auto_gain;
};

static const struct ov5640_reg init_params_common[] = {
Expand Down Expand Up @@ -933,9 +934,13 @@ static int ov5640_set_ctrl_hue(const struct device *dev, int value)
sign = 0x02;
}

struct ov5640_reg hue_params[] = {{SDE_CTRL8_REG, sign},
{SDE_CTRL1_REG, abs(cos_coef)},
{SDE_CTRL2_REG, abs(sin_coef)}};
struct ov5640_reg hue_params[] = {{SDE_CTRL1_REG, abs(cos_coef) & 0xFF},
{SDE_CTRL2_REG, abs(sin_coef) & 0xFF}};

ret = ov5640_modify_reg(&cfg->i2c, SDE_CTRL8_REG, 0x7F, sign);
if (ret) {
return ret;
}

return ov5640_write_multi_regs(&cfg->i2c, hue_params, ARRAY_SIZE(hue_params));
}
Expand Down Expand Up @@ -966,22 +971,26 @@ static int ov5640_set_ctrl_brightness(const struct device *dev, int value)
return -EINVAL;
}

struct ov5640_reg brightness_params[] = {{SDE_CTRL8_REG, value >= 0 ? 0x01 : 0x09},
{SDE_CTRL7_REG, abs(value) & 0xff}};
int ret = ov5640_modify_reg(&cfg->i2c, SDE_CTRL0_REG, BIT(2), BIT(2));

if (ret) {
return ret;
}

return ov5640_write_multi_regs(&cfg->i2c, brightness_params, ARRAY_SIZE(brightness_params));
ret = ov5640_modify_reg(&cfg->i2c, SDE_CTRL8_REG, BIT(3), value >= 0 ? 0 : BIT(3));
if (ret) {
return ret;
}

return ov5640_write_reg(&cfg->i2c, SDE_CTRL7_REG, (abs(value) << 4) & 0xf0);
}

static int ov5640_set_ctrl_contrast(const struct device *dev, int value)
{
const struct ov5640_config *cfg = dev->config;
const struct ov5640_data *data = dev->data;

if (!IN_RANGE(value, 0, UINT8_MAX)) {
if (!IN_RANGE(value, -UINT8_MAX, UINT8_MAX)) {
return -EINVAL;
}

Expand All @@ -991,31 +1000,45 @@ static int ov5640_set_ctrl_contrast(const struct device *dev, int value)
return ret;
}

ret = ov5640_modify_reg(&cfg->i2c, SDE_CTRL6_REG, BIT(2), value >= 0 ? 0 : BIT(2));
if (ret) {
return ret;
}

return ov5640_write_reg(&cfg->i2c, SDE_CTRL6_REG, value & 0xff);
}

static int ov5640_set_ctrl_gain(const struct device *dev, int value)
{
const struct ov5640_config *cfg = dev->config;
struct ov5640_data *data = dev->data;

if (data->auto_gain) {
return -ENOTSUP;
}

if (!IN_RANGE(value, 0, UINT16_MAX)) {
if (!IN_RANGE(value, 0, 1023)) {
return -EINVAL;
}

if (value) {
int ret = ov5640_modify_reg(&cfg->i2c, AEC_PK_MANUAL, BIT(1), BIT(0));
int ret = ov5640_modify_reg(&cfg->i2c, AEC_PK_REAL_GAIN, 0x03, (value >> 8) & 0x03);

if (ret) {
return ret;
}
if (ret) {
return ret;
}

struct ov5640_reg gain_params[] = {{AEC_PK_REAL_GAIN, value >> 8},
{AEC_PK_REAL_GAIN + 1, value & 0xff}};
ret = ov5640_write_reg(&cfg->i2c, AEC_PK_REAL_GAIN + 1, value & 0xff);
return ret;
}

return ov5640_write_multi_regs(&cfg->i2c, gain_params, ARRAY_SIZE(gain_params));
} else {
return ov5640_write_reg(&cfg->i2c, AEC_PK_MANUAL, 0);
}
static int ov5640_set_ctrl_autogain(const struct device *dev, bool value)
{
const struct ov5640_config *cfg = dev->config;
struct ov5640_data *data = dev->data;

data->auto_gain = value;

return ov5640_modify_reg(&cfg->i2c, AEC_PK_MANUAL, BIT(1), data->auto_gain ? 0 : BIT(1));
}

static int ov5640_set_ctrl_hflip(const struct device *dev, int value)
Expand Down Expand Up @@ -1073,6 +1096,8 @@ static int ov5640_set_ctrl(const struct device *dev, unsigned int cid, void *val
return ov5640_set_ctrl_brightness(dev, (int)(value));
case VIDEO_CID_CONTRAST:
return ov5640_set_ctrl_contrast(dev, (int)value);
case VIDEO_CID_AUTOGAIN:
return ov5640_set_ctrl_autogain(dev, (bool)(value));
case VIDEO_CID_GAIN:
return ov5640_set_ctrl_gain(dev, (int)(value));
case VIDEO_CID_HFLIP:
Expand All @@ -1092,7 +1117,7 @@ static inline int ov5640_get_ctrl(const struct device *dev, unsigned int cid, vo

switch (cid) {
case VIDEO_CID_PIXEL_RATE:
*((uint64_t *)value) = drv_data->cur_pixrate;
*((uint32_t *)value) = drv_data->cur_pixrate;

return 0;
default:
Expand Down
2 changes: 1 addition & 1 deletion drivers/video/video_emul_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,6 @@ int emul_rx_init(const struct device *dev)
}; \
\
DEVICE_DT_INST_DEFINE(n, &emul_rx_init, NULL, &emul_rx_data_##n, &emul_rx_cfg_##n, \
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &emul_rx_driver_api);
POST_KERNEL, CONFIG_VIDEO_EMUL_RX_INIT_PRIORITY, &emul_rx_driver_api);

DT_INST_FOREACH_STATUS_OKAY(EMUL_RX_DEFINE)
27 changes: 13 additions & 14 deletions drivers/video/video_mcux_mipi_csi2rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct mipi_csi2rx_data {
};

struct mipi_csi2rx_tHsSettleEscClk_config {
uint64_t pixel_rate;
uint32_t pixel_rate;
uint8_t tHsSettle_EscClk;
};

Expand All @@ -51,7 +51,7 @@ static int mipi_csi2rx_update_settings(const struct device *dev, enum video_endp
const struct mipi_csi2rx_config *config = dev->config;
struct mipi_csi2rx_data *drv_data = dev->data;
uint8_t bpp;
uint64_t sensor_pixel_rate;
uint32_t sensor_pixel_rate;
uint32_t root_clk_rate, ui_clk_rate, sensor_byte_clk, best_match;
int ret, ind = 0;
struct video_format fmt;
Expand Down Expand Up @@ -95,9 +95,8 @@ static int mipi_csi2rx_update_settings(const struct device *dev, enum video_endp
}

if (sensor_pixel_rate > ui_clk_rate) {
ret = clock_control_set_rate(
drv_data->clock_dev, drv_data->clock_ui,
(clock_control_subsys_rate_t)(uint32_t)sensor_pixel_rate);
ret = clock_control_set_rate(drv_data->clock_dev, drv_data->clock_ui,
(clock_control_subsys_rate_t)sensor_pixel_rate);
if (ret) {
return ret;
}
Expand Down Expand Up @@ -216,21 +215,20 @@ static int mipi_csi2rx_get_frmival(const struct device *dev, enum video_endpoint
return video_get_frmival(config->sensor_dev, ep, frmival);
}

static uint64_t mipi_csi2rx_cal_frame_size(const struct video_format *fmt)
static uint32_t mipi_csi2rx_cal_frame_size(const struct video_format *fmt)
{
return fmt->height * fmt->width * video_bits_per_pixel(fmt->pixelformat);
}

static uint64_t mipi_csi2rx_estimate_pixel_rate(const struct video_frmival *cur_fmival,
static uint32_t mipi_csi2rx_estimate_pixel_rate(const struct video_frmival *cur_fmival,
const struct video_frmival *fie_frmival,
const struct video_format *cur_format,
const struct video_format *fie_format,
uint64_t cur_pixel_rate, uint8_t laneNum)
uint32_t cur_pixel_rate, uint8_t laneNum)
{
return mipi_csi2rx_cal_frame_size(cur_format) * fie_frmival->denominator *
cur_fmival->numerator * cur_pixel_rate /
(mipi_csi2rx_cal_frame_size(fie_format) * fie_frmival->numerator *
cur_fmival->denominator);
return (mipi_csi2rx_cal_frame_size(cur_format) / mipi_csi2rx_cal_frame_size(fie_format) *
fie_frmival->denominator / fie_frmival->numerator * cur_fmival->numerator /
cur_fmival->denominator * cur_pixel_rate);
}

static int mipi_csi2rx_enum_frmival(const struct device *dev, enum video_endpoint_id ep,
Expand All @@ -239,7 +237,7 @@ static int mipi_csi2rx_enum_frmival(const struct device *dev, enum video_endpoin
const struct mipi_csi2rx_config *config = dev->config;
struct mipi_csi2rx_data *drv_data = dev->data;
int ret;
uint64_t cur_pixel_rate, est_pixel_rate;
uint32_t cur_pixel_rate, est_pixel_rate;
struct video_frmival cur_frmival;
struct video_format cur_fmt;

Expand Down Expand Up @@ -351,7 +349,8 @@ static int mipi_csi2rx_init(const struct device *dev)
}; \
\
DEVICE_DT_INST_DEFINE(n, &mipi_csi2rx_init, NULL, &mipi_csi2rx_data_##n, \
&mipi_csi2rx_config_##n, POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, \
&mipi_csi2rx_config_##n, POST_KERNEL, \
CONFIG_VIDEO_MCUX_MIPI_CSI2RX_INIT_PRIORITY, \
&mipi_csi2rx_driver_api);

DT_INST_FOREACH_STATUS_OKAY(MIPI_CSI2RX_INIT)
1 change: 0 additions & 1 deletion dts/bindings/vendor-prefixes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ ap Angst+Pfister
apa Apa Electronic Co., Ltd
apm Applied Micro Circuits Corporation (APM)
apple Apple Inc.
aptina Aptina Imaging
arasan Arasan Chip Systems
arc Synopsys, Inc. (formerly ARC International PLC)
archermind ArcherMind Technology (Nanjing) Co., Ltd.
Expand Down
2 changes: 1 addition & 1 deletion dts/bindings/video/aptina,mt9m114.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

description: MT9M114 CMOS video sensor

compatible: "aptina,mt9m114"
compatible: "onnn,mt9m114"

include: i2c-device.yaml

Expand Down
3 changes: 3 additions & 0 deletions include/zephyr/drivers/video-controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ extern "C" {
/** Amount of time an image sensor is exposed to light, affecting the brightness */
#define VIDEO_CID_EXPOSURE (VIDEO_CID_BASE + 17)

/** Enable/Disable the autogain */
#define VIDEO_CID_AUTOGAIN (VIDEO_CID_BASE + 18)

/** Amount of amplification performed to each pixel electrical signal, affecting the brightness */
#define VIDEO_CID_GAIN (VIDEO_CID_BASE + 19)

Expand Down
2 changes: 1 addition & 1 deletion tests/drivers/build_all/video/app.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
clock-frequency = <100000>;

test_i2c_mt9m114: mt9m114@0 {
compatible = "aptina,mt9m114";
compatible = "onnn,mt9m114";
reg = <0>;
};

Expand Down
Loading