@@ -140,6 +140,8 @@ struct imx319 {
140
140
141
141
/* Streaming on/off */
142
142
bool streaming ;
143
+ /* True if the device has been identified */
144
+ bool identified ;
143
145
};
144
146
145
147
static const struct imx319_reg imx319_global_regs [] = {
@@ -2084,13 +2086,42 @@ imx319_set_pad_format(struct v4l2_subdev *sd,
2084
2086
return 0 ;
2085
2087
}
2086
2088
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
+
2087
2114
/* Start streaming */
2088
2115
static int imx319_start_streaming (struct imx319 * imx319 )
2089
2116
{
2090
2117
struct i2c_client * client = v4l2_get_subdevdata (& imx319 -> sd );
2091
2118
const struct imx319_reg_list * reg_list ;
2092
2119
int ret ;
2093
2120
2121
+ ret = imx319_identify_module (imx319 );
2122
+ if (ret )
2123
+ return ret ;
2124
+
2094
2125
/* Global Setting */
2095
2126
reg_list = & imx319_global_setting ;
2096
2127
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)
2206
2237
return ret ;
2207
2238
}
2208
2239
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
-
2229
2240
static const struct v4l2_subdev_core_ops imx319_subdev_core_ops = {
2230
2241
.subscribe_event = v4l2_ctrl_subdev_subscribe_event ,
2231
2242
.unsubscribe_event = v4l2_event_subdev_unsubscribe ,
@@ -2420,6 +2431,7 @@ static struct imx319_hwcfg *imx319_get_hwcfg(struct device *dev)
2420
2431
static int imx319_probe (struct i2c_client * client )
2421
2432
{
2422
2433
struct imx319 * imx319 ;
2434
+ bool full_power ;
2423
2435
int ret ;
2424
2436
u32 i ;
2425
2437
@@ -2432,11 +2444,14 @@ static int imx319_probe(struct i2c_client *client)
2432
2444
/* Initialize subdev */
2433
2445
v4l2_i2c_subdev_init (& imx319 -> sd , client , & imx319_subdev_ops );
2434
2446
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
+ }
2440
2455
}
2441
2456
2442
2457
imx319 -> hwcfg = imx319_get_hwcfg (& client -> dev );
@@ -2488,11 +2503,9 @@ static int imx319_probe(struct i2c_client *client)
2488
2503
if (ret < 0 )
2489
2504
goto error_media_entity ;
2490
2505
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 );
2496
2509
pm_runtime_enable (& client -> dev );
2497
2510
pm_runtime_idle (& client -> dev );
2498
2511
@@ -2545,6 +2558,7 @@ static struct i2c_driver imx319_i2c_driver = {
2545
2558
},
2546
2559
.probe_new = imx319_probe ,
2547
2560
.remove = imx319_remove ,
2561
+ .flags = I2C_DRV_ACPI_WAIVE_D0_PROBE ,
2548
2562
};
2549
2563
module_i2c_driver (imx319_i2c_driver );
2550
2564
0 commit comments