@@ -872,38 +872,18 @@ static int arizona_micd_read(struct arizona_extcon_info *info)
872
872
return val ;
873
873
}
874
874
875
- static void arizona_micd_detect ( struct work_struct * work )
875
+ static int arizona_micdet_reading ( void * priv )
876
876
{
877
- struct arizona_extcon_info * info = container_of (work ,
878
- struct arizona_extcon_info ,
879
- micd_detect_work .work );
877
+ struct arizona_extcon_info * info = priv ;
880
878
struct arizona * arizona = info -> arizona ;
881
- unsigned int val = 0 , lvl ;
882
- int ret , i , key ;
883
-
884
- cancel_delayed_work_sync (& info -> micd_timeout_work );
885
-
886
- mutex_lock (& info -> lock );
887
-
888
- /* If the cable was removed while measuring ignore the result */
889
- ret = extcon_get_state (info -> edev , EXTCON_MECHANICAL );
890
- if (ret < 0 ) {
891
- dev_err (arizona -> dev , "Failed to check cable state: %d\n" ,
892
- ret );
893
- mutex_unlock (& info -> lock );
894
- return ;
895
- } else if (!ret ) {
896
- dev_dbg (arizona -> dev , "Ignoring MICDET for removed cable\n" );
897
- mutex_unlock (& info -> lock );
898
- return ;
899
- }
879
+ int ret , val ;
900
880
901
881
if (info -> detecting && arizona -> pdata .micd_software_compare )
902
882
ret = arizona_micd_adc_read (info );
903
883
else
904
884
ret = arizona_micd_read (info );
905
885
if (ret < 0 )
906
- goto handled ;
886
+ return ret ;
907
887
908
888
val = ret ;
909
889
@@ -913,11 +893,11 @@ static void arizona_micd_detect(struct work_struct *work)
913
893
info -> mic = false;
914
894
info -> detecting = false;
915
895
arizona_identify_headphone (info );
916
- goto handled ;
896
+ return 0 ;
917
897
}
918
898
919
899
/* If we got a high impedence we should have a headset, report it. */
920
- if (info -> detecting && ( val & ARIZONA_MICD_LVL_8 ) ) {
900
+ if (val & ARIZONA_MICD_LVL_8 ) {
921
901
info -> mic = true;
922
902
info -> detecting = false;
923
903
@@ -936,7 +916,7 @@ static void arizona_micd_detect(struct work_struct *work)
936
916
ret );
937
917
}
938
918
939
- goto handled ;
919
+ return 0 ;
940
920
}
941
921
942
922
/* If we detected a lower impedence during initial startup
@@ -945,7 +925,7 @@ static void arizona_micd_detect(struct work_struct *work)
945
925
* plain headphones. If both polarities report a low
946
926
* impedence then give up and report headphones.
947
927
*/
948
- if (info -> detecting && ( val & MICD_LVL_1_TO_7 ) ) {
928
+ if (val & MICD_LVL_1_TO_7 ) {
949
929
if (info -> jack_flips >= info -> micd_num_modes * 10 ) {
950
930
dev_dbg (arizona -> dev , "Detected HP/line\n" );
951
931
@@ -959,11 +939,43 @@ static void arizona_micd_detect(struct work_struct *work)
959
939
arizona_extcon_set_mode (info , info -> micd_mode );
960
940
961
941
info -> jack_flips ++ ;
942
+
943
+ if (arizona -> pdata .micd_software_compare )
944
+ regmap_update_bits (arizona -> regmap ,
945
+ ARIZONA_MIC_DETECT_1 ,
946
+ ARIZONA_MICD_ENA ,
947
+ ARIZONA_MICD_ENA );
948
+
949
+ queue_delayed_work (system_power_efficient_wq ,
950
+ & info -> micd_timeout_work ,
951
+ msecs_to_jiffies (arizona -> pdata .micd_timeout ));
962
952
}
963
953
964
- goto handled ;
954
+ return 0 ;
965
955
}
966
956
957
+ /*
958
+ * If we're still detecting and we detect a short then we've
959
+ * got a headphone.
960
+ */
961
+ dev_dbg (arizona -> dev , "Headphone detected\n" );
962
+ info -> detecting = false;
963
+
964
+ arizona_identify_headphone (info );
965
+
966
+ return 0 ;
967
+ }
968
+
969
+ static int arizona_button_reading (void * priv )
970
+ {
971
+ struct arizona_extcon_info * info = priv ;
972
+ struct arizona * arizona = info -> arizona ;
973
+ int val , key , lvl , i ;
974
+
975
+ val = arizona_micd_read (info );
976
+ if (val < 0 )
977
+ return val ;
978
+
967
979
/*
968
980
* If we're still detecting and we detect a short then we've
969
981
* got a headphone. Otherwise it's a button press.
@@ -986,11 +998,6 @@ static void arizona_micd_detect(struct work_struct *work)
986
998
} else {
987
999
dev_err (arizona -> dev , "Button out of range\n" );
988
1000
}
989
- } else if (info -> detecting ) {
990
- dev_dbg (arizona -> dev , "Headphone detected\n" );
991
- info -> detecting = false;
992
-
993
- arizona_identify_headphone (info );
994
1001
} else {
995
1002
dev_warn (arizona -> dev , "Button with no mic: %x\n" ,
996
1003
val );
@@ -1004,19 +1011,39 @@ static void arizona_micd_detect(struct work_struct *work)
1004
1011
arizona_extcon_pulse_micbias (info );
1005
1012
}
1006
1013
1007
- handled :
1008
- if (info -> detecting ) {
1009
- if (arizona -> pdata .micd_software_compare )
1010
- regmap_update_bits (arizona -> regmap ,
1011
- ARIZONA_MIC_DETECT_1 ,
1012
- ARIZONA_MICD_ENA ,
1013
- ARIZONA_MICD_ENA );
1014
+ return 0 ;
1015
+ }
1014
1016
1015
- queue_delayed_work (system_power_efficient_wq ,
1016
- & info -> micd_timeout_work ,
1017
- msecs_to_jiffies (arizona -> pdata .micd_timeout ));
1017
+ static void arizona_micd_detect (struct work_struct * work )
1018
+ {
1019
+ struct arizona_extcon_info * info = container_of (work ,
1020
+ struct arizona_extcon_info ,
1021
+ micd_detect_work .work );
1022
+ struct arizona * arizona = info -> arizona ;
1023
+ int ret ;
1024
+
1025
+ cancel_delayed_work_sync (& info -> micd_timeout_work );
1026
+
1027
+ mutex_lock (& info -> lock );
1028
+
1029
+ /* If the cable was removed while measuring ignore the result */
1030
+ ret = extcon_get_state (info -> edev , EXTCON_MECHANICAL );
1031
+ if (ret < 0 ) {
1032
+ dev_err (arizona -> dev , "Failed to check cable state: %d\n" ,
1033
+ ret );
1034
+ mutex_unlock (& info -> lock );
1035
+ return ;
1036
+ } else if (!ret ) {
1037
+ dev_dbg (arizona -> dev , "Ignoring MICDET for removed cable\n" );
1038
+ mutex_unlock (& info -> lock );
1039
+ return ;
1018
1040
}
1019
1041
1042
+ if (info -> detecting )
1043
+ arizona_micdet_reading (info );
1044
+ else
1045
+ arizona_button_reading (info );
1046
+
1020
1047
pm_runtime_mark_last_busy (info -> dev );
1021
1048
mutex_unlock (& info -> lock );
1022
1049
}
0 commit comments