Android Bottom -up headphone Plug and audio channel switching instance
Because headphones are used as separate headsets, the events are reported separately. The detection of headphone jacks on the Android system layer is based on /sys/class/switch/h2w/state values (in 4.4.4_r2 For example in Wiredaccessorymanager.java).
A switch class -based h2w switch is implemented in the kernel as long as it is "true or false" . the Android system will be able to monitor the plug and unplug information.
Insert headphones when playing music, use Tinymix (refer to:Android audio underlying debug - based on Tinyalsa ) command to find the value of playback Path from SPK to hp_no_mic, it can be noted that the headset Plug and unplug software is detected properly.
# Tinymix
Mixer name: ' Rk_rk616_tiny '
Number of Controls:7
CTL Type num Name value
0 ENUM 1 Playback Path hp_no_mic
1 ENUM 1 Capture mic Path mic OFF
2 ENUM 1 Voice call Path OFF
3 ENUM 1 Voip Path OFF
4 INT 2 Speaker Playback Volume 24 24
5 INT 2 Headphone Playback Volume 24 24
6 ENUM 1 Modem Input Enable on
#
But the horn was still ringing, stating that it had not been closed. Check the schematic "control pin on the power amplifier" on which GPIO is followed.
According to the manual, as long as the gpio2_d7 can output low level can achieve the speaker off , using a multimeter measured in the headset after inserting the pin is still high, view code changes recorded in the previous version of the colleague is directly in the Rk_ HEADSET.C Headphone plug-in program changes to pull it down, this can be achieved but feel inappropriate,Android Upper should also have audio channel switch, according to the upper level to control the better. This can also be forced to open the speaker when inserting the headset, the "use of which audio communication decision" to the user.
This should be implemented in the kernel, because the Alsa has switched normally, it means that the upper layer has already called the corresponding interface. From the drive to analyze.
Device resources: You can see that the Speak and handphone GPIO are given the Rk30_pin2_pd7 .
static struct Rk616_platform_data Rk616_pdata = {
. Power_init = Rk616_power_on_init,
. Power_deinit = Rk616_power_deinit,
. scl_rate = Rk616_scl_rate,
. Lcd0_func = input,//port lcd0 as input
. Lcd1_func = input,//port lcd1 as input
. LVDS_CH_NR = 1,//the number of used LVDS channel
. HDMI_IRQ = Rk30_pin2_pd6,
. Spk_ctl_gpio = Rk30_pin2_pd7 ,
. Hp_ctl_gpio = Rk30_pin2_pd7 ,
};
Functions for controlling audio output channels in device drivers:
static int rk616_playback_path_put (struct Snd_kcontrol *kcontrol,
struct Snd_ctl_elem_value *ucontrol)
{
......
Case Hp_path:
Case Hp_no_mic:
Case RING_HP:
Case Ring_hp_no_mic:
Rk616_set_gpio (rk616_codec_set_spk, gpio_low);
if (Pre_path = = OFF)
RK616_CODEC_POWER_UP (Rk616_codec_playback);
Snd_soc_update_bits (codec, Rk616_spkl_ctl,
Rk616_vol_mask, Hpout_volume); , volume (bit 0-4)
Snd_soc_update_bits (codec, Rk616_spkr_ctl,
Rk616_vol_mask, Hpout_volume);
Rk616_set_gpio (rk616_codec_set_hp, gpio_high);
Break
......
}
Visible in the output to the headphone channel, disable SPEAKER and enable HP are set gpio_high, and finally rk30_pin2_ The PD7 is still high , and SPEAKERis not disabled. The schematic does not have a separate headphone to enable the pin. The issue is resolved by setting Hp_ctl_gpio to invalid_gpioin the resource.
Bonus: Principle headphones There has always been audio output, no matter the insertion is not plugged into the headset, the headset is inserted only when the SPEAKER is forbidden.
Strayed Astray:
1. Mistakenly think to go to see the Android Upper code in each kind of search for a long time, it is a waste, if you use tinymix to view the audio channel switch is normal, the kernel is no problem, the problem is also in the kernel and hardware.
Summary: The vast Android system does not allow you to understand each piece is very detailed, but if it will be a good division of the hierarchy, the problem will be well solved. The focus of the record is not on the specific model version and so on, but in the analysis of such problems encountered in the thinking.
Android bottom-up headphone Plug and audio channel switching instance