Skip to content

Commit bada408

Browse files
KhanhNguyen-RVCthenguyenyf
authored andcommitted
drivers: video: ov5640: support DVP bus-width and data-shift from DTS
Add support in the OV5640 driver to configure the bus-width and data-shift properties from devicetree when operating in DVP (parallel) mode. This allows the number of parallel data lines and the bit shift to be set directly via DTS, ensuring correct configuration across different hardware designs. Signed-off-by: Khanh Nguyen <[email protected]>
1 parent eb8378f commit bada408

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

drivers/video/ov5640.c

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ LOG_MODULE_REGISTER(video_ov5640, CONFIG_VIDEO_LOG_LEVEL);
9595
#define SDE_CTRL10_REG 0x558a
9696
#define SDE_CTRL11_REG 0x558b
9797

98+
#define DATA_ORDER_REG 0x4745
99+
98100
#define DEFAULT_MIPI_CHANNEL 0
99101

100102
#define PI 3.141592654
@@ -124,6 +126,8 @@ struct ov5640_config {
124126
struct gpio_dt_spec powerdown_gpio;
125127
#endif
126128
int bus_type;
129+
int bus_width;
130+
int data_shift;
127131
};
128132

129133
struct ov5640_reg {
@@ -1394,6 +1398,33 @@ static int ov5640_init(const struct device *dev)
13941398
LOG_ERR("Unable to initialize the sensor with DVP parameters");
13951399
return -EIO;
13961400
}
1401+
1402+
/*
1403+
* Select the DVP data order using bits [2:1] of DATA_ORDER_REG:
1404+
* 00: 10-bit bus, Data[9:0]
1405+
* 10: 8-bit bus, Data[7:0]
1406+
* x1: 8-bit bus, Data[9:2]
1407+
*/
1408+
uint8_t data_order = 0;
1409+
1410+
if (cfg->bus_width == 8 && cfg->data_shift == 0) {
1411+
data_order = BIT(2);
1412+
} else if (cfg->bus_width == 8 && cfg->data_shift == 2) {
1413+
data_order = BIT(1);
1414+
} else if (cfg->bus_width == 10 && cfg->data_shift == 0) {
1415+
data_order = 0;
1416+
} else {
1417+
LOG_ERR("Invalid DVP data order: bus width = %u, data shift = %u",
1418+
cfg->bus_width, cfg->data_shift);
1419+
return -EIO;
1420+
}
1421+
1422+
/* Set DVP data order */
1423+
ret = ov5640_modify_reg(&cfg->i2c, DATA_ORDER_REG, BIT(2) | BIT(1), data_order);
1424+
if (ret) {
1425+
LOG_ERR("Unable to set DVP data order");
1426+
return -EIO;
1427+
}
13971428
} else {
13981429
/* Set virtual channel */
13991430
ret = ov5640_modify_reg(&cfg->i2c, 0x4814, 3U << 6,
@@ -1451,16 +1482,18 @@ static int ov5640_init(const struct device *dev)
14511482
#define OV5640_GET_POWERDOWN_GPIO(n)
14521483
#endif
14531484

1485+
#define OV5640_EP_PROP_OR(n, prop, default) \
1486+
DT_PROP_OR(DT_CHILD(DT_INST_CHILD(n, port), endpoint), prop, default)
1487+
14541488
#define OV5640_INIT(n) \
14551489
static struct ov5640_data ov5640_data_##n; \
14561490
\
14571491
static const struct ov5640_config ov5640_cfg_##n = { \
14581492
.i2c = I2C_DT_SPEC_INST_GET(n), \
1459-
OV5640_GET_RESET_GPIO(n) \
1460-
OV5640_GET_POWERDOWN_GPIO(n) \
1461-
.bus_type = DT_PROP_OR(DT_CHILD(DT_INST_CHILD(n, port), endpoint), bus_type, \
1462-
VIDEO_BUS_TYPE_CSI2_DPHY), \
1463-
}; \
1493+
.bus_type = OV5640_EP_PROP_OR(n, bus_type, VIDEO_BUS_TYPE_CSI2_DPHY), \
1494+
.bus_width = OV5640_EP_PROP_OR(n, bus_width, 10), \
1495+
.data_shift = OV5640_EP_PROP_OR(n, data_shift, 0), \
1496+
OV5640_GET_RESET_GPIO(n) OV5640_GET_POWERDOWN_GPIO(n)}; \
14641497
\
14651498
DEVICE_DT_INST_DEFINE(n, &ov5640_init, NULL, &ov5640_data_##n, &ov5640_cfg_##n, \
14661499
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &ov5640_driver_api); \

dts/bindings/video/ovti,ov5640.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,19 @@ properties:
2222
child-binding:
2323
child-binding:
2424
include: video-interfaces.yaml
25+
26+
properties:
27+
bus-width:
28+
enum: [8, 10]
29+
description: |
30+
Number of parallel data lines for pixel output. The OV5640
31+
supports only 8-bit or 10-bit configurations. This property
32+
is valid only for parallel buses.
33+
34+
data-shift:
35+
enum: [0, 2]
36+
description: |
37+
Bit shift applied to the parallel data lines. The OV5640
38+
supports only 0 (no shift) or 2-bit shift. For example:
39+
- "bus-width = <8>; data-shift = <0>;" lines 7:0 are used
40+
- "bus-width = <8>; data-shift = <2>;" lines 9:2 are used

0 commit comments

Comments
 (0)