@@ -1833,6 +1833,8 @@ struct ov5670 {
1833
1833
1834
1834
/* Streaming on/off */
1835
1835
bool streaming ;
1836
+ /* True if the device has been identified */
1837
+ bool identified ;
1836
1838
};
1837
1839
1838
1840
#define to_ov5670 (_sd ) container_of(_sd, struct ov5670, sd)
@@ -2273,6 +2275,32 @@ static int ov5670_get_skip_frames(struct v4l2_subdev *sd, u32 *frames)
2273
2275
return 0 ;
2274
2276
}
2275
2277
2278
+ /* Verify chip ID */
2279
+ static int ov5670_identify_module (struct ov5670 * ov5670 )
2280
+ {
2281
+ struct i2c_client * client = v4l2_get_subdevdata (& ov5670 -> sd );
2282
+ int ret ;
2283
+ u32 val ;
2284
+
2285
+ if (ov5670 -> identified )
2286
+ return 0 ;
2287
+
2288
+ ret = ov5670_read_reg (ov5670 , OV5670_REG_CHIP_ID ,
2289
+ OV5670_REG_VALUE_24BIT , & val );
2290
+ if (ret )
2291
+ return ret ;
2292
+
2293
+ if (val != OV5670_CHIP_ID ) {
2294
+ dev_err (& client -> dev , "chip id mismatch: %x!=%x\n" ,
2295
+ OV5670_CHIP_ID , val );
2296
+ return - ENXIO ;
2297
+ }
2298
+
2299
+ ov5670 -> identified = true;
2300
+
2301
+ return 0 ;
2302
+ }
2303
+
2276
2304
/* Prepare streaming by writing default values and customized values */
2277
2305
static int ov5670_start_streaming (struct ov5670 * ov5670 )
2278
2306
{
@@ -2281,6 +2309,10 @@ static int ov5670_start_streaming(struct ov5670 *ov5670)
2281
2309
int link_freq_index ;
2282
2310
int ret ;
2283
2311
2312
+ ret = ov5670_identify_module (ov5670 );
2313
+ if (ret )
2314
+ return ret ;
2315
+
2284
2316
/* Get out of from software reset */
2285
2317
ret = ov5670_write_reg (ov5670 , OV5670_REG_SOFTWARE_RST ,
2286
2318
OV5670_REG_VALUE_08BIT , OV5670_SOFTWARE_RST );
@@ -2400,27 +2432,6 @@ static int __maybe_unused ov5670_resume(struct device *dev)
2400
2432
return 0 ;
2401
2433
}
2402
2434
2403
- /* Verify chip ID */
2404
- static int ov5670_identify_module (struct ov5670 * ov5670 )
2405
- {
2406
- struct i2c_client * client = v4l2_get_subdevdata (& ov5670 -> sd );
2407
- int ret ;
2408
- u32 val ;
2409
-
2410
- ret = ov5670_read_reg (ov5670 , OV5670_REG_CHIP_ID ,
2411
- OV5670_REG_VALUE_24BIT , & val );
2412
- if (ret )
2413
- return ret ;
2414
-
2415
- if (val != OV5670_CHIP_ID ) {
2416
- dev_err (& client -> dev , "chip id mismatch: %x!=%x\n" ,
2417
- OV5670_CHIP_ID , val );
2418
- return - ENXIO ;
2419
- }
2420
-
2421
- return 0 ;
2422
- }
2423
-
2424
2435
static const struct v4l2_subdev_core_ops ov5670_core_ops = {
2425
2436
.log_status = v4l2_ctrl_subdev_log_status ,
2426
2437
.subscribe_event = v4l2_ctrl_subdev_subscribe_event ,
@@ -2462,6 +2473,7 @@ static int ov5670_probe(struct i2c_client *client)
2462
2473
struct ov5670 * ov5670 ;
2463
2474
const char * err_msg ;
2464
2475
u32 input_clk = 0 ;
2476
+ bool full_power ;
2465
2477
int ret ;
2466
2478
2467
2479
device_property_read_u32 (& client -> dev , "clock-frequency" , & input_clk );
@@ -2478,11 +2490,14 @@ static int ov5670_probe(struct i2c_client *client)
2478
2490
/* Initialize subdev */
2479
2491
v4l2_i2c_subdev_init (& ov5670 -> sd , client , & ov5670_subdev_ops );
2480
2492
2481
- /* Check module identity */
2482
- ret = ov5670_identify_module (ov5670 );
2483
- if (ret ) {
2484
- err_msg = "ov5670_identify_module() error" ;
2485
- goto error_print ;
2493
+ full_power = acpi_dev_state_d0 (& client -> dev );
2494
+ if (full_power ) {
2495
+ /* Check module identity */
2496
+ ret = ov5670_identify_module (ov5670 );
2497
+ if (ret ) {
2498
+ err_msg = "ov5670_identify_module() error" ;
2499
+ goto error_print ;
2500
+ }
2486
2501
}
2487
2502
2488
2503
mutex_init (& ov5670 -> mutex );
@@ -2519,11 +2534,9 @@ static int ov5670_probe(struct i2c_client *client)
2519
2534
2520
2535
ov5670 -> streaming = false;
2521
2536
2522
- /*
2523
- * Device is already turned on by i2c-core with ACPI domain PM.
2524
- * Enable runtime PM and turn off the device.
2525
- */
2526
- pm_runtime_set_active (& client -> dev );
2537
+ /* Set the device's state to active if it's in D0 state. */
2538
+ if (full_power )
2539
+ pm_runtime_set_active (& client -> dev );
2527
2540
pm_runtime_enable (& client -> dev );
2528
2541
pm_runtime_idle (& client -> dev );
2529
2542
@@ -2565,7 +2578,7 @@ static const struct dev_pm_ops ov5670_pm_ops = {
2565
2578
2566
2579
#ifdef CONFIG_ACPI
2567
2580
static const struct acpi_device_id ov5670_acpi_ids [] = {
2568
- {"INT3479" },
2581
+ { "INT3479" },
2569
2582
{ /* sentinel */ }
2570
2583
};
2571
2584
@@ -2580,6 +2593,7 @@ static struct i2c_driver ov5670_i2c_driver = {
2580
2593
},
2581
2594
.probe_new = ov5670_probe ,
2582
2595
.remove = ov5670_remove ,
2596
+ .flags = I2C_DRV_ACPI_WAIVE_D0_PROBE ,
2583
2597
};
2584
2598
2585
2599
module_i2c_driver (ov5670_i2c_driver );
0 commit comments