@@ -99,6 +99,8 @@ LOG_MODULE_REGISTER(video_ov5640, CONFIG_VIDEO_LOG_LEVEL);
9999#define SDE_CTRL10_REG 0x558a
100100#define SDE_CTRL11_REG 0x558b
101101
102+ #define DATA_ORDER_REG 0x4745
103+
102104#define DEFAULT_MIPI_CHANNEL 0
103105
104106#define PI 3.141592654
@@ -128,6 +130,8 @@ struct ov5640_config {
128130 struct gpio_dt_spec powerdown_gpio ;
129131#endif
130132 int bus_type ;
133+ int bus_width ;
134+ int data_shift ;
131135};
132136
133137struct ov5640_mipi_frmrate_config {
@@ -1335,6 +1339,33 @@ static int ov5640_init(const struct device *dev)
13351339 LOG_ERR ("Unable to initialize the sensor with DVP parameters" );
13361340 return - EIO ;
13371341 }
1342+
1343+ /*
1344+ * Select the DVP data order using bits [2:1] of DATA_ORDER_REG:
1345+ * 00 : 10-bit bus uses Data lines [9:0] or 8-bit bus uses Data lines [9:2]
1346+ * x1 : 8-bit bus uses Data lines [7:0]
1347+ * 10 : Not supported by this driver
1348+ */
1349+ uint8_t data_order = 0 ;
1350+
1351+ if ((cfg -> bus_width == 10 && cfg -> data_shift == 0 ) ||
1352+ (cfg -> bus_width == 8 && cfg -> data_shift == 2 )) {
1353+ data_order = 0 ;
1354+ } else if (cfg -> bus_width == 8 && cfg -> data_shift == 0 ) {
1355+ data_order = BIT (1 );
1356+ } else {
1357+ LOG_ERR ("Invalid DVP config: width=%u shift=%u" , cfg -> bus_width ,
1358+ cfg -> data_shift );
1359+ return - ENOTSUP ;
1360+ }
1361+
1362+ /* Set DVP data order */
1363+ ret = video_modify_cci_reg (& cfg -> i2c , OV5640_REG8 (DATA_ORDER_REG ), BIT (2 ) | BIT (1 ),
1364+ data_order );
1365+ if (ret ) {
1366+ LOG_ERR ("Unable to set DVP data order" );
1367+ return - EIO ;
1368+ }
13381369 } else {
13391370 /* Set virtual channel */
13401371 ret = video_modify_cci_reg (& cfg -> i2c , OV5640_REG8 (0x4814 ), 3U << 6 ,
@@ -1392,15 +1423,19 @@ static int ov5640_init(const struct device *dev)
13921423#define OV5640_GET_POWERDOWN_GPIO (n )
13931424#endif
13941425
1426+ #define OV5640_EP_PROP_OR (n , prop , default ) \
1427+ DT_PROP_OR(DT_CHILD(DT_INST_CHILD(n, port), endpoint), prop, default)
1428+
13951429#define OV5640_INIT (n ) \
13961430 static struct ov5640_data ov5640_data_##n; \
13971431 \
13981432 static const struct ov5640_config ov5640_cfg_##n = { \
13991433 .i2c = I2C_DT_SPEC_INST_GET(n), \
1400- OV5640_GET_RESET_GPIO(n) \
1401- OV5640_GET_POWERDOWN_GPIO(n) \
1402- .bus_type = DT_PROP_OR(DT_CHILD(DT_INST_CHILD(n, port), endpoint), bus_type, \
1403- VIDEO_BUS_TYPE_CSI2_DPHY), \
1434+ .bus_type = OV5640_EP_PROP_OR(n, bus_type, VIDEO_BUS_TYPE_CSI2_DPHY), \
1435+ .bus_width = OV5640_EP_PROP_OR(n, bus_width, 10), \
1436+ .data_shift = OV5640_EP_PROP_OR(n, data_shift, 0), \
1437+ OV5640_GET_RESET_GPIO(n) \
1438+ OV5640_GET_POWERDOWN_GPIO(n) \
14041439 }; \
14051440 \
14061441 DEVICE_DT_INST_DEFINE(n, &ov5640_init, NULL, &ov5640_data_##n, &ov5640_cfg_##n, \
0 commit comments