@@ -95,6 +95,8 @@ LOG_MODULE_REGISTER(video_ov5640, CONFIG_VIDEO_LOG_LEVEL);
95
95
#define SDE_CTRL10_REG 0x558a
96
96
#define SDE_CTRL11_REG 0x558b
97
97
98
+ #define DATA_ORDER_REG 0x4745
99
+
98
100
#define DEFAULT_MIPI_CHANNEL 0
99
101
100
102
#define PI 3.141592654
@@ -124,6 +126,8 @@ struct ov5640_config {
124
126
struct gpio_dt_spec powerdown_gpio ;
125
127
#endif
126
128
int bus_type ;
129
+ int bus_width ;
130
+ int data_shift ;
127
131
};
128
132
129
133
struct ov5640_reg {
@@ -1394,6 +1398,33 @@ static int ov5640_init(const struct device *dev)
1394
1398
LOG_ERR ("Unable to initialize the sensor with DVP parameters" );
1395
1399
return - EIO ;
1396
1400
}
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
+ }
1397
1428
} else {
1398
1429
/* Set virtual channel */
1399
1430
ret = ov5640_modify_reg (& cfg -> i2c , 0x4814 , 3U << 6 ,
@@ -1451,16 +1482,18 @@ static int ov5640_init(const struct device *dev)
1451
1482
#define OV5640_GET_POWERDOWN_GPIO (n )
1452
1483
#endif
1453
1484
1485
+ #define OV5640_EP_PROP_OR (n , prop , default ) \
1486
+ DT_PROP_OR(DT_CHILD(DT_INST_CHILD(n, port), endpoint), prop, default)
1487
+
1454
1488
#define OV5640_INIT (n ) \
1455
1489
static struct ov5640_data ov5640_data_##n; \
1456
1490
\
1457
1491
static const struct ov5640_config ov5640_cfg_##n = { \
1458
1492
.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)}; \
1464
1497
\
1465
1498
DEVICE_DT_INST_DEFINE(n, &ov5640_init, NULL, &ov5640_data_##n, &ov5640_cfg_##n, \
1466
1499
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &ov5640_driver_api); \
0 commit comments