@@ -99,6 +99,8 @@ LOG_MODULE_REGISTER(video_ov5640, CONFIG_VIDEO_LOG_LEVEL);
99
99
#define SDE_CTRL10_REG 0x558a
100
100
#define SDE_CTRL11_REG 0x558b
101
101
102
+ #define DATA_ORDER_REG 0x4745
103
+
102
104
#define DEFAULT_MIPI_CHANNEL 0
103
105
104
106
#define PI 3.141592654
@@ -128,6 +130,8 @@ struct ov5640_config {
128
130
struct gpio_dt_spec powerdown_gpio ;
129
131
#endif
130
132
int bus_type ;
133
+ int bus_width ;
134
+ int data_shift ;
131
135
};
132
136
133
137
struct ov5640_mipi_frmrate_config {
@@ -1335,6 +1339,33 @@ static int ov5640_init(const struct device *dev)
1335
1339
LOG_ERR ("Unable to initialize the sensor with DVP parameters" );
1336
1340
return - EIO ;
1337
1341
}
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 - EIO ;
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
+ }
1338
1369
} else {
1339
1370
/* Set virtual channel */
1340
1371
ret = video_modify_cci_reg (& cfg -> i2c , OV5640_REG8 (0x4814 ), 3U << 6 ,
@@ -1392,15 +1423,19 @@ static int ov5640_init(const struct device *dev)
1392
1423
#define OV5640_GET_POWERDOWN_GPIO (n )
1393
1424
#endif
1394
1425
1426
+ #define OV5640_EP_PROP_OR (n , prop , default ) \
1427
+ DT_PROP_OR(DT_CHILD(DT_INST_CHILD(n, port), endpoint), prop, default)
1428
+
1395
1429
#define OV5640_INIT (n ) \
1396
1430
static struct ov5640_data ov5640_data_##n; \
1397
1431
\
1398
1432
static const struct ov5640_config ov5640_cfg_##n = { \
1399
1433
.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) \
1404
1439
}; \
1405
1440
\
1406
1441
DEVICE_DT_INST_DEFINE(n, &ov5640_init, NULL, &ov5640_data_##n, &ov5640_cfg_##n, \
0 commit comments