@@ -493,6 +493,9 @@ struct ov5675 {
493493
494494 /* Streaming on/off */
495495 bool streaming ;
496+
497+ /* True if the device has been identified */
498+ bool identified ;
496499};
497500
498501static u64 to_pixel_rate (u32 f_index )
@@ -808,12 +811,41 @@ static void ov5675_update_pad_format(const struct ov5675_mode *mode,
808811 fmt -> field = V4L2_FIELD_NONE ;
809812}
810813
814+ static int ov5675_identify_module (struct ov5675 * ov5675 )
815+ {
816+ struct i2c_client * client = v4l2_get_subdevdata (& ov5675 -> sd );
817+ int ret ;
818+ u32 val ;
819+
820+ if (ov5675 -> identified )
821+ return 0 ;
822+
823+ ret = ov5675_read_reg (ov5675 , OV5675_REG_CHIP_ID ,
824+ OV5675_REG_VALUE_24BIT , & val );
825+ if (ret )
826+ return ret ;
827+
828+ if (val != OV5675_CHIP_ID ) {
829+ dev_err (& client -> dev , "chip id mismatch: %x!=%x" ,
830+ OV5675_CHIP_ID , val );
831+ return - ENXIO ;
832+ }
833+
834+ ov5675 -> identified = true;
835+
836+ return 0 ;
837+ }
838+
811839static int ov5675_start_streaming (struct ov5675 * ov5675 )
812840{
813841 struct i2c_client * client = v4l2_get_subdevdata (& ov5675 -> sd );
814842 const struct ov5675_reg_list * reg_list ;
815843 int link_freq_index , ret ;
816844
845+ ret = ov5675_identify_module (ov5675 );
846+ if (ret )
847+ return ret ;
848+
817849 link_freq_index = ov5675 -> cur_mode -> link_freq_index ;
818850 reg_list = & link_freq_configs [link_freq_index ].reg_list ;
819851 ret = ov5675_write_reg_list (ov5675 , reg_list );
@@ -1048,26 +1080,6 @@ static const struct v4l2_subdev_internal_ops ov5675_internal_ops = {
10481080 .open = ov5675_open ,
10491081};
10501082
1051- static int ov5675_identify_module (struct ov5675 * ov5675 )
1052- {
1053- struct i2c_client * client = v4l2_get_subdevdata (& ov5675 -> sd );
1054- int ret ;
1055- u32 val ;
1056-
1057- ret = ov5675_read_reg (ov5675 , OV5675_REG_CHIP_ID ,
1058- OV5675_REG_VALUE_24BIT , & val );
1059- if (ret )
1060- return ret ;
1061-
1062- if (val != OV5675_CHIP_ID ) {
1063- dev_err (& client -> dev , "chip id mismatch: %x!=%x" ,
1064- OV5675_CHIP_ID , val );
1065- return - ENXIO ;
1066- }
1067-
1068- return 0 ;
1069- }
1070-
10711083static int ov5675_check_hwcfg (struct device * dev )
10721084{
10731085 struct fwnode_handle * ep ;
@@ -1154,6 +1166,7 @@ static int ov5675_remove(struct i2c_client *client)
11541166static int ov5675_probe (struct i2c_client * client )
11551167{
11561168 struct ov5675 * ov5675 ;
1169+ bool full_power ;
11571170 int ret ;
11581171
11591172 ret = ov5675_check_hwcfg (& client -> dev );
@@ -1168,10 +1181,14 @@ static int ov5675_probe(struct i2c_client *client)
11681181 return - ENOMEM ;
11691182
11701183 v4l2_i2c_subdev_init (& ov5675 -> sd , client , & ov5675_subdev_ops );
1171- ret = ov5675_identify_module (ov5675 );
1172- if (ret ) {
1173- dev_err (& client -> dev , "failed to find sensor: %d" , ret );
1174- return ret ;
1184+
1185+ full_power = acpi_dev_state_d0 (& client -> dev );
1186+ if (full_power ) {
1187+ ret = ov5675_identify_module (ov5675 );
1188+ if (ret ) {
1189+ dev_err (& client -> dev , "failed to find sensor: %d" , ret );
1190+ return ret ;
1191+ }
11751192 }
11761193
11771194 mutex_init (& ov5675 -> mutex );
@@ -1204,7 +1221,10 @@ static int ov5675_probe(struct i2c_client *client)
12041221 * Device is already turned on by i2c-core with ACPI domain PM.
12051222 * Enable runtime PM and turn off the device.
12061223 */
1207- pm_runtime_set_active (& client -> dev );
1224+
1225+ /* Set the device's state to active if it's in D0 state. */
1226+ if (full_power )
1227+ pm_runtime_set_active (& client -> dev );
12081228 pm_runtime_enable (& client -> dev );
12091229 pm_runtime_idle (& client -> dev );
12101230
@@ -1241,6 +1261,7 @@ static struct i2c_driver ov5675_i2c_driver = {
12411261 },
12421262 .probe_new = ov5675_probe ,
12431263 .remove = ov5675_remove ,
1264+ .flags = I2C_DRV_ACPI_WAIVE_D0_PROBE ,
12441265};
12451266
12461267module_i2c_driver (ov5675_i2c_driver );
0 commit comments