@@ -140,6 +140,8 @@ struct imx319 {
140140
141141 /* Streaming on/off */
142142 bool streaming ;
143+ /* True if the device has been identified */
144+ bool identified ;
143145};
144146
145147static const struct imx319_reg imx319_global_regs [] = {
@@ -2084,13 +2086,42 @@ imx319_set_pad_format(struct v4l2_subdev *sd,
20842086 return 0 ;
20852087}
20862088
2089+ /* Verify chip ID */
2090+ static int imx319_identify_module (struct imx319 * imx319 )
2091+ {
2092+ struct i2c_client * client = v4l2_get_subdevdata (& imx319 -> sd );
2093+ int ret ;
2094+ u32 val ;
2095+
2096+ if (imx319 -> identified )
2097+ return 0 ;
2098+
2099+ ret = imx319_read_reg (imx319 , IMX319_REG_CHIP_ID , 2 , & val );
2100+ if (ret )
2101+ return ret ;
2102+
2103+ if (val != IMX319_CHIP_ID ) {
2104+ dev_err (& client -> dev , "chip id mismatch: %x!=%x" ,
2105+ IMX319_CHIP_ID , val );
2106+ return - EIO ;
2107+ }
2108+
2109+ imx319 -> identified = true;
2110+
2111+ return 0 ;
2112+ }
2113+
20872114/* Start streaming */
20882115static int imx319_start_streaming (struct imx319 * imx319 )
20892116{
20902117 struct i2c_client * client = v4l2_get_subdevdata (& imx319 -> sd );
20912118 const struct imx319_reg_list * reg_list ;
20922119 int ret ;
20932120
2121+ ret = imx319_identify_module (imx319 );
2122+ if (ret )
2123+ return ret ;
2124+
20942125 /* Global Setting */
20952126 reg_list = & imx319_global_setting ;
20962127 ret = imx319_write_regs (imx319 , reg_list -> regs , reg_list -> num_of_regs );
@@ -2206,26 +2237,6 @@ static int __maybe_unused imx319_resume(struct device *dev)
22062237 return ret ;
22072238}
22082239
2209- /* Verify chip ID */
2210- static int imx319_identify_module (struct imx319 * imx319 )
2211- {
2212- struct i2c_client * client = v4l2_get_subdevdata (& imx319 -> sd );
2213- int ret ;
2214- u32 val ;
2215-
2216- ret = imx319_read_reg (imx319 , IMX319_REG_CHIP_ID , 2 , & val );
2217- if (ret )
2218- return ret ;
2219-
2220- if (val != IMX319_CHIP_ID ) {
2221- dev_err (& client -> dev , "chip id mismatch: %x!=%x" ,
2222- IMX319_CHIP_ID , val );
2223- return - EIO ;
2224- }
2225-
2226- return 0 ;
2227- }
2228-
22292240static const struct v4l2_subdev_core_ops imx319_subdev_core_ops = {
22302241 .subscribe_event = v4l2_ctrl_subdev_subscribe_event ,
22312242 .unsubscribe_event = v4l2_event_subdev_unsubscribe ,
@@ -2420,6 +2431,7 @@ static struct imx319_hwcfg *imx319_get_hwcfg(struct device *dev)
24202431static int imx319_probe (struct i2c_client * client )
24212432{
24222433 struct imx319 * imx319 ;
2434+ bool full_power ;
24232435 int ret ;
24242436 u32 i ;
24252437
@@ -2432,11 +2444,14 @@ static int imx319_probe(struct i2c_client *client)
24322444 /* Initialize subdev */
24332445 v4l2_i2c_subdev_init (& imx319 -> sd , client , & imx319_subdev_ops );
24342446
2435- /* Check module identity */
2436- ret = imx319_identify_module (imx319 );
2437- if (ret ) {
2438- dev_err (& client -> dev , "failed to find sensor: %d" , ret );
2439- goto error_probe ;
2447+ full_power = acpi_dev_state_d0 (& client -> dev );
2448+ if (full_power ) {
2449+ /* Check module identity */
2450+ ret = imx319_identify_module (imx319 );
2451+ if (ret ) {
2452+ dev_err (& client -> dev , "failed to find sensor: %d" , ret );
2453+ goto error_probe ;
2454+ }
24402455 }
24412456
24422457 imx319 -> hwcfg = imx319_get_hwcfg (& client -> dev );
@@ -2488,11 +2503,9 @@ static int imx319_probe(struct i2c_client *client)
24882503 if (ret < 0 )
24892504 goto error_media_entity ;
24902505
2491- /*
2492- * Device is already turned on by i2c-core with ACPI domain PM.
2493- * Enable runtime PM and turn off the device.
2494- */
2495- pm_runtime_set_active (& client -> dev );
2506+ /* Set the device's state to active if it's in D0 state. */
2507+ if (full_power )
2508+ pm_runtime_set_active (& client -> dev );
24962509 pm_runtime_enable (& client -> dev );
24972510 pm_runtime_idle (& client -> dev );
24982511
@@ -2545,6 +2558,7 @@ static struct i2c_driver imx319_i2c_driver = {
25452558 },
25462559 .probe_new = imx319_probe ,
25472560 .remove = imx319_remove ,
2561+ .flags = I2C_DRV_ACPI_WAIVE_D0_PROBE ,
25482562};
25492563module_i2c_driver (imx319_i2c_driver );
25502564
0 commit comments