Skip to content

Commit b341d9d

Browse files
ngphibangkartben
authored andcommitted
video: Merge video_stream_start/stop driver APIs
The video_stream_start/stop() APIs are counter-symetric and have the same function signature. Also, the implementation logic for those driver APIs is generally the same. Merge them to save memory and code lines. For the sake of simplicity, still keep the user APIs to preserve backward compatibility with downstream applications. Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
1 parent db6a4e0 commit b341d9d

17 files changed

+140
-231
lines changed

doc/releases/migration-guide-4.1.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ Video
471471
``pitch = width * video_pix_fmt_bpp(pixfmt)`` needs to be replaced by an equivalent
472472
``pitch = width * video_bits_per_pixel(pixfmt) / BITS_PER_BYTE``.
473473

474+
* The :c:func:`video_stream_start` and :c:func:`video_stream_stop` driver APIs are now merged
475+
into the new :c:func:`video_set_stream` driver API. The user APIs are however unchanged to
476+
keep backward compatibility with downstream applications.
477+
474478
Watchdog
475479
========
476480

doc/releases/release-notes-4.1.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ Removed APIs and options
7777
and only supported 8-bit depth to :c:func:`video_bits_per_pixel()` returning
7878
the *bit* count and supporting any color depth.
7979

80+
* The ``video_stream_start()`` and ``video_stream_stop()`` driver APIs have been
81+
replaced by ``video_set_stream()``.
82+
8083
* :kconfig:option:`CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO`
8184

8285
* The :kconfig:option:`CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE` option has been removed
@@ -161,6 +164,11 @@ New APIs and options
161164
* Image management :c:macro:`MGMT_EVT_OP_IMG_MGMT_DFU_CONFIRMED` now has image data field
162165
:c:struct:`img_mgmt_image_confirmed`.
163166

167+
* Video
168+
169+
* :c:func:`video_set_stream()` driver API has replaced :c:func:`video_stream_start()` and
170+
:c:func:`video_stream_stop()` driver APIs.
171+
164172
* Other
165173

166174
* :kconfig:option:`CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA`

drivers/video/gc2145.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,18 +1076,12 @@ static int gc2145_get_fmt(const struct device *dev, enum video_endpoint_id ep,
10761076
return 0;
10771077
}
10781078

1079-
static int gc2145_stream_start(const struct device *dev)
1079+
static int gc2145_set_stream(const struct device *dev, bool enable)
10801080
{
10811081
const struct gc2145_config *cfg = dev->config;
10821082

1083-
return gc2145_write_reg(&cfg->i2c, 0xf2, 0x0f);
1084-
}
1085-
1086-
static int gc2145_stream_stop(const struct device *dev)
1087-
{
1088-
const struct gc2145_config *cfg = dev->config;
1089-
1090-
return gc2145_write_reg(&cfg->i2c, 0xf2, 0x00);
1083+
return enable ? gc2145_write_reg(&cfg->i2c, 0xf2, 0x0f)
1084+
: gc2145_write_reg(&cfg->i2c, 0xf2, 0x00);
10911085
}
10921086

10931087
static int gc2145_get_caps(const struct device *dev, enum video_endpoint_id ep,
@@ -1113,8 +1107,7 @@ static DEVICE_API(video, gc2145_driver_api) = {
11131107
.set_format = gc2145_set_fmt,
11141108
.get_format = gc2145_get_fmt,
11151109
.get_caps = gc2145_get_caps,
1116-
.stream_start = gc2145_stream_start,
1117-
.stream_stop = gc2145_stream_stop,
1110+
.set_stream = gc2145_set_stream,
11181111
.set_ctrl = gc2145_set_ctrl,
11191112
};
11201113

drivers/video/mt9m114.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,10 @@ static int mt9m114_get_fmt(const struct device *dev, enum video_endpoint_id ep,
451451
return 0;
452452
}
453453

454-
static int mt9m114_stream_start(const struct device *dev)
454+
static int mt9m114_set_stream(const struct device *dev, bool enable)
455455
{
456-
return mt9m114_set_state(dev, MT9M114_SYS_STATE_START_STREAMING);
457-
}
458-
459-
static int mt9m114_stream_stop(const struct device *dev)
460-
{
461-
return mt9m114_set_state(dev, MT9M114_SYS_STATE_ENTER_SUSPEND);
456+
return enable ? mt9m114_set_state(dev, MT9M114_SYS_STATE_START_STREAMING)
457+
: mt9m114_set_state(dev, MT9M114_SYS_STATE_ENTER_SUSPEND);
462458
}
463459

464460
static int mt9m114_get_caps(const struct device *dev, enum video_endpoint_id ep,
@@ -499,8 +495,7 @@ static DEVICE_API(video, mt9m114_driver_api) = {
499495
.set_format = mt9m114_set_fmt,
500496
.get_format = mt9m114_get_fmt,
501497
.get_caps = mt9m114_get_caps,
502-
.stream_start = mt9m114_stream_start,
503-
.stream_stop = mt9m114_stream_stop,
498+
.set_stream = mt9m114_set_stream,
504499
.set_ctrl = mt9m114_set_ctrl,
505500
};
506501

drivers/video/ov2640.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -910,12 +910,7 @@ static int ov2640_get_fmt(const struct device *dev,
910910
return 0;
911911
}
912912

913-
static int ov2640_stream_start(const struct device *dev)
914-
{
915-
return 0;
916-
}
917-
918-
static int ov2640_stream_stop(const struct device *dev)
913+
static int ov2640_set_stream(const struct device *dev, bool enable)
919914
{
920915
return 0;
921916
}
@@ -975,8 +970,7 @@ static DEVICE_API(video, ov2640_driver_api) = {
975970
.set_format = ov2640_set_fmt,
976971
.get_format = ov2640_get_fmt,
977972
.get_caps = ov2640_get_caps,
978-
.stream_start = ov2640_stream_start,
979-
.stream_stop = ov2640_stream_stop,
973+
.set_stream = ov2640_set_stream,
980974
.set_ctrl = ov2640_set_ctrl,
981975
};
982976

drivers/video/ov5640.c

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -862,38 +862,21 @@ static int ov5640_get_caps(const struct device *dev, enum video_endpoint_id ep,
862862
return 0;
863863
}
864864

865-
static int ov5640_stream_start(const struct device *dev)
865+
static int ov5640_set_stream(const struct device *dev, bool enable)
866866
{
867867
const struct ov5640_config *cfg = dev->config;
868868

869869
if (!ov5640_is_dvp(dev)) {
870-
/* Power up MIPI PHY HS Tx & LP Rx in 2 data lanes mode */
871-
int ret = ov5640_write_reg(&cfg->i2c, IO_MIPI_CTRL00_REG, 0x45);
872-
873-
if (ret) {
874-
LOG_ERR("Unable to power up MIPI PHY");
875-
return ret;
876-
}
877-
}
878-
879-
return ov5640_write_reg(&cfg->i2c, SYS_CTRL0_REG, SYS_CTRL0_SW_PWUP);
880-
}
881-
882-
static int ov5640_stream_stop(const struct device *dev)
883-
{
884-
const struct ov5640_config *cfg = dev->config;
885-
886-
if (!ov5640_is_dvp(dev)) {
887-
/* Power down MIPI PHY HS Tx & LP Rx */
888-
int ret = ov5640_write_reg(&cfg->i2c, IO_MIPI_CTRL00_REG, 0x40);
889-
870+
/* Power up / down MIPI PHY HS Tx & LP Rx in 2 data lanes mode */
871+
int ret = ov5640_write_reg(&cfg->i2c, IO_MIPI_CTRL00_REG, enable ? 0x45 : 0x40);
890872
if (ret) {
891-
LOG_ERR("Unable to power down MIPI PHY");
873+
LOG_ERR("Unable to power up / down MIPI PHY");
892874
return ret;
893875
}
894876
}
895877

896-
return ov5640_write_reg(&cfg->i2c, SYS_CTRL0_REG, SYS_CTRL0_SW_PWDN);
878+
return ov5640_write_reg(&cfg->i2c, SYS_CTRL0_REG,
879+
enable ? SYS_CTRL0_SW_PWUP : SYS_CTRL0_SW_PWDN);
897880
}
898881

899882
#define TEST_PATTERN_ENABLE BIT(7)
@@ -1164,8 +1147,7 @@ static DEVICE_API(video, ov5640_driver_api) = {
11641147
.set_format = ov5640_set_fmt,
11651148
.get_format = ov5640_get_fmt,
11661149
.get_caps = ov5640_get_caps,
1167-
.stream_start = ov5640_stream_start,
1168-
.stream_stop = ov5640_stream_stop,
1150+
.set_stream = ov5640_set_stream,
11691151
.set_ctrl = ov5640_set_ctrl,
11701152
.get_ctrl = ov5640_get_ctrl,
11711153
.set_frmival = ov5640_set_frmival,

drivers/video/ov7670.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,7 @@ static int ov7670_init(const struct device *dev)
550550
return 0;
551551
}
552552

553-
static int ov7670_stream_start(const struct device *dev)
554-
{
555-
return 0;
556-
}
557-
558-
static int ov7670_stream_stop(const struct device *dev)
553+
static int ov7670_set_stream(const struct device *dev, bool enable)
559554
{
560555
return 0;
561556
}
@@ -580,8 +575,7 @@ static DEVICE_API(video, ov7670_api) = {
580575
.set_format = ov7670_set_fmt,
581576
.get_format = ov7670_get_fmt,
582577
.get_caps = ov7670_get_caps,
583-
.stream_start = ov7670_stream_start,
584-
.stream_stop = ov7670_stream_stop,
578+
.set_stream = ov7670_set_stream,
585579
.set_ctrl = ov7670_set_ctrl,
586580
};
587581

drivers/video/ov7725.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,7 @@ static int ov7725_get_fmt(const struct device *dev,
517517
return 0;
518518
}
519519

520-
static int ov7725_stream_start(const struct device *dev)
521-
{
522-
return 0;
523-
}
524-
525-
static int ov7725_stream_stop(const struct device *dev)
520+
static int ov7725_set_stream(const struct device *dev, bool enable)
526521
{
527522
return 0;
528523
}
@@ -552,8 +547,7 @@ static DEVICE_API(video, ov7725_driver_api) = {
552547
.set_format = ov7725_set_fmt,
553548
.get_format = ov7725_get_fmt,
554549
.get_caps = ov7725_get_caps,
555-
.stream_start = ov7725_stream_start,
556-
.stream_stop = ov7725_stream_stop,
550+
.set_stream = ov7725_set_stream,
557551
};
558552

559553
static int ov7725_init(const struct device *dev)

drivers/video/video_emul_imager.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,14 +423,9 @@ static int emul_imager_get_caps(const struct device *dev, enum video_endpoint_id
423423
return 0;
424424
}
425425

426-
static int emul_imager_stream_start(const struct device *dev)
426+
static int emul_imager_set_stream(const struct device *dev, bool enable)
427427
{
428-
return emul_imager_write_reg(dev, EMUL_IMAGER_REG_CTRL, 1);
429-
}
430-
431-
static int emul_imager_stream_stop(const struct device *dev)
432-
{
433-
return emul_imager_write_reg(dev, EMUL_IMAGER_REG_CTRL, 0);
428+
return emul_imager_write_reg(dev, EMUL_IMAGER_REG_CTRL, enable ? 1 : 0);
434429
}
435430

436431
static DEVICE_API(video, emul_imager_driver_api) = {
@@ -442,8 +437,7 @@ static DEVICE_API(video, emul_imager_driver_api) = {
442437
.set_format = emul_imager_set_fmt,
443438
.get_format = emul_imager_get_fmt,
444439
.get_caps = emul_imager_get_caps,
445-
.stream_start = emul_imager_stream_start,
446-
.stream_stop = emul_imager_stream_stop,
440+
.set_stream = emul_imager_set_stream,
447441
};
448442

449443
int emul_imager_init(const struct device *dev)

drivers/video/video_emul_rx.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,12 @@ static int emul_rx_get_caps(const struct device *dev, enum video_endpoint_id ep,
131131
return video_get_caps(cfg->source_dev, VIDEO_EP_OUT, caps);
132132
}
133133

134-
static int emul_rx_stream_start(const struct device *dev)
134+
static int emul_rx_set_stream(const struct device *dev, bool enable)
135135
{
136136
const struct emul_rx_config *cfg = dev->config;
137137

138-
/* A real hardware driver would first start its own peripheral */
139-
return video_stream_start(cfg->source_dev);
140-
}
141-
142-
static int emul_rx_stream_stop(const struct device *dev)
143-
{
144-
const struct emul_rx_config *cfg = dev->config;
145-
146-
return video_stream_stop(cfg->source_dev);
147-
/* A real hardware driver would then stop its own peripheral */
138+
/* A real hardware driver would first start / stop its own peripheral */
139+
return enable ? video_stream_start(cfg->source_dev) : video_stream_stop(cfg->source_dev);
148140
}
149141

150142
static void emul_rx_worker(struct k_work *work)
@@ -259,8 +251,7 @@ static DEVICE_API(video, emul_rx_driver_api) = {
259251
.set_format = emul_rx_set_fmt,
260252
.get_format = emul_rx_get_fmt,
261253
.get_caps = emul_rx_get_caps,
262-
.stream_start = emul_rx_stream_start,
263-
.stream_stop = emul_rx_stream_stop,
254+
.set_stream = emul_rx_set_stream,
264255
.enqueue = emul_rx_enqueue,
265256
.dequeue = emul_rx_dequeue,
266257
.flush = emul_rx_flush,

0 commit comments

Comments
 (0)