@@ -998,45 +998,29 @@ static int i2c_hid_core_resume(struct i2c_hid *ihid)
998
998
return hid_driver_reset_resume (hid );
999
999
}
1000
1000
1001
- /**
1002
- * __do_i2c_hid_core_initial_power_up() - First time power up of the i2c-hid device.
1003
- * @ihid: The ihid object created during probe.
1004
- *
1005
- * This function is called at probe time.
1006
- *
1007
- * The initial power on is where we do some basic validation that the device
1008
- * exists, where we fetch the HID descriptor, and where we create the actual
1009
- * HID devices.
1010
- *
1011
- * Return: 0 or error code.
1001
+ /*
1002
+ * Check that the device exists and parse the HID descriptor.
1012
1003
*/
1013
- static int __do_i2c_hid_core_initial_power_up (struct i2c_hid * ihid )
1004
+ static int __i2c_hid_core_probe (struct i2c_hid * ihid )
1014
1005
{
1015
1006
struct i2c_client * client = ihid -> client ;
1016
1007
struct hid_device * hid = ihid -> hid ;
1017
1008
int ret ;
1018
1009
1019
- ret = i2c_hid_core_power_up (ihid );
1020
- if (ret )
1021
- return ret ;
1022
-
1023
1010
/* Make sure there is something at this address */
1024
1011
ret = i2c_smbus_read_byte (client );
1025
1012
if (ret < 0 ) {
1026
1013
i2c_hid_dbg (ihid , "nothing at this address: %d\n" , ret );
1027
- ret = - ENXIO ;
1028
- goto err ;
1014
+ return - ENXIO ;
1029
1015
}
1030
1016
1031
1017
ret = i2c_hid_fetch_hid_descriptor (ihid );
1032
1018
if (ret < 0 ) {
1033
1019
dev_err (& client -> dev ,
1034
1020
"Failed to fetch the HID Descriptor\n" );
1035
- goto err ;
1021
+ return ret ;
1036
1022
}
1037
1023
1038
- enable_irq (client -> irq );
1039
-
1040
1024
hid -> version = le16_to_cpu (ihid -> hdesc .bcdVersion );
1041
1025
hid -> vendor = le16_to_cpu (ihid -> hdesc .wVendorID );
1042
1026
hid -> product = le16_to_cpu (ihid -> hdesc .wProductID );
@@ -1050,17 +1034,49 @@ static int __do_i2c_hid_core_initial_power_up(struct i2c_hid *ihid)
1050
1034
1051
1035
ihid -> quirks = i2c_hid_lookup_quirk (hid -> vendor , hid -> product );
1052
1036
1037
+ return 0 ;
1038
+ }
1039
+
1040
+ static int i2c_hid_core_register_hid (struct i2c_hid * ihid )
1041
+ {
1042
+ struct i2c_client * client = ihid -> client ;
1043
+ struct hid_device * hid = ihid -> hid ;
1044
+ int ret ;
1045
+
1046
+ enable_irq (client -> irq );
1047
+
1053
1048
ret = hid_add_device (hid );
1054
1049
if (ret ) {
1055
1050
if (ret != - ENODEV )
1056
1051
hid_err (client , "can't add hid device: %d\n" , ret );
1057
- goto err ;
1052
+ disable_irq (client -> irq );
1053
+ return ret ;
1058
1054
}
1059
1055
1060
1056
return 0 ;
1057
+ }
1058
+
1059
+ static int i2c_hid_core_probe_panel_follower (struct i2c_hid * ihid )
1060
+ {
1061
+ int ret ;
1062
+
1063
+ ret = i2c_hid_core_power_up (ihid );
1064
+ if (ret )
1065
+ return ret ;
1061
1066
1062
- err :
1067
+ ret = __i2c_hid_core_probe (ihid );
1068
+ if (ret )
1069
+ goto err_power_down ;
1070
+
1071
+ ret = i2c_hid_core_register_hid (ihid );
1072
+ if (ret )
1073
+ goto err_power_down ;
1074
+
1075
+ return 0 ;
1076
+
1077
+ err_power_down :
1063
1078
i2c_hid_core_power_down (ihid );
1079
+
1064
1080
return ret ;
1065
1081
}
1066
1082
@@ -1077,7 +1093,7 @@ static void ihid_core_panel_prepare_work(struct work_struct *work)
1077
1093
* steps.
1078
1094
*/
1079
1095
if (!hid -> version )
1080
- ret = __do_i2c_hid_core_initial_power_up (ihid );
1096
+ ret = i2c_hid_core_probe_panel_follower (ihid );
1081
1097
else
1082
1098
ret = i2c_hid_core_resume (ihid );
1083
1099
@@ -1136,7 +1152,6 @@ static int i2c_hid_core_register_panel_follower(struct i2c_hid *ihid)
1136
1152
struct device * dev = & ihid -> client -> dev ;
1137
1153
int ret ;
1138
1154
1139
- ihid -> is_panel_follower = true;
1140
1155
ihid -> panel_follower .funcs = & i2c_hid_core_panel_follower_funcs ;
1141
1156
1142
1157
/*
@@ -1156,30 +1171,6 @@ static int i2c_hid_core_register_panel_follower(struct i2c_hid *ihid)
1156
1171
return 0 ;
1157
1172
}
1158
1173
1159
- static int i2c_hid_core_initial_power_up (struct i2c_hid * ihid )
1160
- {
1161
- /*
1162
- * If we're a panel follower, we'll register and do our initial power
1163
- * up when the panel turns on; otherwise we do it right away.
1164
- */
1165
- if (drm_is_panel_follower (& ihid -> client -> dev ))
1166
- return i2c_hid_core_register_panel_follower (ihid );
1167
- else
1168
- return __do_i2c_hid_core_initial_power_up (ihid );
1169
- }
1170
-
1171
- static void i2c_hid_core_final_power_down (struct i2c_hid * ihid )
1172
- {
1173
- /*
1174
- * If we're a follower, the act of unfollowing will cause us to be
1175
- * powered down. Otherwise we need to manually do it.
1176
- */
1177
- if (ihid -> is_panel_follower )
1178
- drm_panel_remove_follower (& ihid -> panel_follower );
1179
- else
1180
- i2c_hid_core_suspend (ihid , true);
1181
- }
1182
-
1183
1174
int i2c_hid_core_probe (struct i2c_client * client , struct i2chid_ops * ops ,
1184
1175
u16 hid_descriptor_address , u32 quirks )
1185
1176
{
@@ -1211,6 +1202,7 @@ int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops,
1211
1202
ihid -> ops = ops ;
1212
1203
ihid -> client = client ;
1213
1204
ihid -> wHIDDescRegister = cpu_to_le16 (hid_descriptor_address );
1205
+ ihid -> is_panel_follower = drm_is_panel_follower (& client -> dev );
1214
1206
1215
1207
init_waitqueue_head (& ihid -> wait );
1216
1208
mutex_init (& ihid -> reset_lock );
@@ -1224,14 +1216,10 @@ int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops,
1224
1216
return ret ;
1225
1217
device_enable_async_suspend (& client -> dev );
1226
1218
1227
- ret = i2c_hid_init_irq (client );
1228
- if (ret < 0 )
1229
- goto err_buffers_allocated ;
1230
-
1231
1219
hid = hid_allocate_device ();
1232
1220
if (IS_ERR (hid )) {
1233
1221
ret = PTR_ERR (hid );
1234
- goto err_irq ;
1222
+ goto err_free_buffers ;
1235
1223
}
1236
1224
1237
1225
ihid -> hid = hid ;
@@ -1242,19 +1230,42 @@ int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops,
1242
1230
hid -> bus = BUS_I2C ;
1243
1231
hid -> initial_quirks = quirks ;
1244
1232
1245
- ret = i2c_hid_core_initial_power_up (ihid );
1233
+ /* Power on and probe unless device is a panel follower. */
1234
+ if (!ihid -> is_panel_follower ) {
1235
+ ret = i2c_hid_core_power_up (ihid );
1236
+ if (ret < 0 )
1237
+ goto err_destroy_device ;
1238
+
1239
+ ret = __i2c_hid_core_probe (ihid );
1240
+ if (ret < 0 )
1241
+ goto err_power_down ;
1242
+ }
1243
+
1244
+ ret = i2c_hid_init_irq (client );
1245
+ if (ret < 0 )
1246
+ goto err_power_down ;
1247
+
1248
+ /*
1249
+ * If we're a panel follower, we'll register when the panel turns on;
1250
+ * otherwise we do it right away.
1251
+ */
1252
+ if (ihid -> is_panel_follower )
1253
+ ret = i2c_hid_core_register_panel_follower (ihid );
1254
+ else
1255
+ ret = i2c_hid_core_register_hid (ihid );
1246
1256
if (ret )
1247
- goto err_mem_free ;
1257
+ goto err_free_irq ;
1248
1258
1249
1259
return 0 ;
1250
1260
1251
- err_mem_free :
1252
- hid_destroy_device (hid );
1253
-
1254
- err_irq :
1261
+ err_free_irq :
1255
1262
free_irq (client -> irq , ihid );
1256
-
1257
- err_buffers_allocated :
1263
+ err_power_down :
1264
+ if (!ihid -> is_panel_follower )
1265
+ i2c_hid_core_power_down (ihid );
1266
+ err_destroy_device :
1267
+ hid_destroy_device (hid );
1268
+ err_free_buffers :
1258
1269
i2c_hid_free_buffers (ihid );
1259
1270
1260
1271
return ret ;
@@ -1266,7 +1277,14 @@ void i2c_hid_core_remove(struct i2c_client *client)
1266
1277
struct i2c_hid * ihid = i2c_get_clientdata (client );
1267
1278
struct hid_device * hid ;
1268
1279
1269
- i2c_hid_core_final_power_down (ihid );
1280
+ /*
1281
+ * If we're a follower, the act of unfollowing will cause us to be
1282
+ * powered down. Otherwise we need to manually do it.
1283
+ */
1284
+ if (ihid -> is_panel_follower )
1285
+ drm_panel_remove_follower (& ihid -> panel_follower );
1286
+ else
1287
+ i2c_hid_core_suspend (ihid , true);
1270
1288
1271
1289
hid = ihid -> hid ;
1272
1290
hid_destroy_device (hid );
0 commit comments