@@ -1833,6 +1833,8 @@ struct ov5670 {
18331833
18341834 /* Streaming on/off */
18351835 bool streaming ;
1836+ /* True if the device has been identified */
1837+ bool identified ;
18361838};
18371839
18381840#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)
22732275 return 0 ;
22742276}
22752277
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+
22762304/* Prepare streaming by writing default values and customized values */
22772305static int ov5670_start_streaming (struct ov5670 * ov5670 )
22782306{
@@ -2281,6 +2309,10 @@ static int ov5670_start_streaming(struct ov5670 *ov5670)
22812309 int link_freq_index ;
22822310 int ret ;
22832311
2312+ ret = ov5670_identify_module (ov5670 );
2313+ if (ret )
2314+ return ret ;
2315+
22842316 /* Get out of from software reset */
22852317 ret = ov5670_write_reg (ov5670 , OV5670_REG_SOFTWARE_RST ,
22862318 OV5670_REG_VALUE_08BIT , OV5670_SOFTWARE_RST );
@@ -2400,27 +2432,6 @@ static int __maybe_unused ov5670_resume(struct device *dev)
24002432 return 0 ;
24012433}
24022434
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-
24242435static const struct v4l2_subdev_core_ops ov5670_core_ops = {
24252436 .log_status = v4l2_ctrl_subdev_log_status ,
24262437 .subscribe_event = v4l2_ctrl_subdev_subscribe_event ,
@@ -2462,6 +2473,7 @@ static int ov5670_probe(struct i2c_client *client)
24622473 struct ov5670 * ov5670 ;
24632474 const char * err_msg ;
24642475 u32 input_clk = 0 ;
2476+ bool full_power ;
24652477 int ret ;
24662478
24672479 device_property_read_u32 (& client -> dev , "clock-frequency" , & input_clk );
@@ -2478,11 +2490,14 @@ static int ov5670_probe(struct i2c_client *client)
24782490 /* Initialize subdev */
24792491 v4l2_i2c_subdev_init (& ov5670 -> sd , client , & ov5670_subdev_ops );
24802492
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+ }
24862501 }
24872502
24882503 mutex_init (& ov5670 -> mutex );
@@ -2519,11 +2534,9 @@ static int ov5670_probe(struct i2c_client *client)
25192534
25202535 ov5670 -> streaming = false;
25212536
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 );
25272540 pm_runtime_enable (& client -> dev );
25282541 pm_runtime_idle (& client -> dev );
25292542
@@ -2565,7 +2578,7 @@ static const struct dev_pm_ops ov5670_pm_ops = {
25652578
25662579#ifdef CONFIG_ACPI
25672580static const struct acpi_device_id ov5670_acpi_ids [] = {
2568- {"INT3479" },
2581+ { "INT3479" },
25692582 { /* sentinel */ }
25702583};
25712584
@@ -2580,6 +2593,7 @@ static struct i2c_driver ov5670_i2c_driver = {
25802593 },
25812594 .probe_new = ov5670_probe ,
25822595 .remove = ov5670_remove ,
2596+ .flags = I2C_DRV_ACPI_WAIVE_D0_PROBE ,
25832597};
25842598
25852599module_i2c_driver (ov5670_i2c_driver );
0 commit comments