@@ -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,34 @@ 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, Data[9:0]
1346
+ * 10: 8-bit bus, Data[7:0]
1347
+ * x1: 8-bit bus, Data[9:2]
1348
+ */
1349
+ uint8_t data_order = 0 ;
1350
+
1351
+ if (cfg -> bus_width == 8 && cfg -> data_shift == 0 ) {
1352
+ data_order = BIT (2 );
1353
+ } else if (cfg -> bus_width == 8 && cfg -> data_shift == 2 ) {
1354
+ data_order = BIT (1 );
1355
+ } else if (cfg -> bus_width == 10 && cfg -> data_shift == 0 ) {
1356
+ data_order = 0 ;
1357
+ } else {
1358
+ LOG_ERR ("Invalid DVP data order: bus width = %u, data shift = %u" ,
1359
+ cfg -> bus_width , cfg -> data_shift );
1360
+ return - EIO ;
1361
+ }
1362
+
1363
+ /* Set DVP data order */
1364
+ ret = video_modify_cci_reg (& cfg -> i2c , OV5640_REG8 (DATA_ORDER_REG ), BIT (2 ) | BIT (1 ),
1365
+ data_order );
1366
+ if (ret ) {
1367
+ LOG_ERR ("Unable to set DVP data order" );
1368
+ return - EIO ;
1369
+ }
1338
1370
} else {
1339
1371
/* Set virtual channel */
1340
1372
ret = video_modify_cci_reg (& cfg -> i2c , OV5640_REG8 (0x4814 ), 3U << 6 ,
@@ -1392,15 +1424,19 @@ static int ov5640_init(const struct device *dev)
1392
1424
#define OV5640_GET_POWERDOWN_GPIO (n )
1393
1425
#endif
1394
1426
1427
+ #define OV5640_EP_PROP_OR (n , prop , default ) \
1428
+ DT_PROP_OR(DT_CHILD(DT_INST_CHILD(n, port), endpoint), prop, default)
1429
+
1395
1430
#define OV5640_INIT (n ) \
1396
1431
static struct ov5640_data ov5640_data_##n; \
1397
1432
\
1398
1433
static const struct ov5640_config ov5640_cfg_##n = { \
1399
1434
.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), \
1435
+ .bus_type = OV5640_EP_PROP_OR(n, bus_type, VIDEO_BUS_TYPE_CSI2_DPHY), \
1436
+ .bus_width = OV5640_EP_PROP_OR(n, bus_width, 10), \
1437
+ .data_shift = OV5640_EP_PROP_OR(n, data_shift, 0), \
1438
+ OV5640_GET_RESET_GPIO(n) \
1439
+ OV5640_GET_POWERDOWN_GPIO(n) \
1404
1440
}; \
1405
1441
\
1406
1442
DEVICE_DT_INST_DEFINE(n, &ov5640_init, NULL, &ov5640_data_##n, &ov5640_cfg_##n, \
0 commit comments