167 lines · plain
1============================2ALSA Jack Software Injection3============================4 5Simple Introduction On Jack Injection6=====================================7 8Here jack injection means users could inject plugin or plugout events9to the audio jacks through debugfs interface, it is helpful to10validate ALSA userspace changes. For example, we change the audio11profile switching code in the pulseaudio, and we want to verify if the12change works as expected and if the change introduce the regression,13in this case, we could inject plugin or plugout events to an audio14jack or to some audio jacks, we don't need to physically access the15machine and plug/unplug physical devices to the audio jack.16 17In this design, an audio jack doesn't equal to a physical audio jack.18Sometimes a physical audio jack contains multi functions, and the19ALSA driver creates multi ``jack_kctl`` for a ``snd_jack``, here the20``snd_jack`` represents a physical audio jack and the ``jack_kctl``21represents a function, for example a physical jack has two functions:22headphone and mic_in, the ALSA ASoC driver will build 2 ``jack_kctl``23for this jack. The jack injection is implemented based on the24``jack_kctl`` instead of ``snd_jack``.25 26To inject events to audio jacks, we need to enable the jack injection27via ``sw_inject_enable`` first, once it is enabled, this jack will not28change the state by hardware events anymore, we could inject plugin or29plugout events via ``jackin_inject`` and check the jack state via30``status``, after we finish our test, we need to disable the jack31injection via ``sw_inject_enable`` too, once it is disabled, the jack32state will be restored according to the last reported hardware events33and will change by future hardware events.34 35The Layout of Jack Injection Interface36======================================37 38If users enable the SND_JACK_INJECTION_DEBUG in the kernel, the audio39jack injection interface will be created as below:40::41 42 $debugfs_mount_dir/sound43 |-- card044 |-- |-- HDMI_DP_pcm_10_Jack45 |-- |-- |-- jackin_inject46 |-- |-- |-- kctl_id47 |-- |-- |-- mask_bits48 |-- |-- |-- status49 |-- |-- |-- sw_inject_enable50 |-- |-- |-- type51 ...52 |-- |-- HDMI_DP_pcm_9_Jack53 |-- |-- jackin_inject54 |-- |-- kctl_id55 |-- |-- mask_bits56 |-- |-- status57 |-- |-- sw_inject_enable58 |-- |-- type59 |-- card160 |-- HDMI_DP_pcm_5_Jack61 |-- |-- jackin_inject62 |-- |-- kctl_id63 |-- |-- mask_bits64 |-- |-- status65 |-- |-- sw_inject_enable66 |-- |-- type67 ...68 |-- Headphone_Jack69 |-- |-- jackin_inject70 |-- |-- kctl_id71 |-- |-- mask_bits72 |-- |-- status73 |-- |-- sw_inject_enable74 |-- |-- type75 |-- Headset_Mic_Jack76 |-- jackin_inject77 |-- kctl_id78 |-- mask_bits79 |-- status80 |-- sw_inject_enable81 |-- type82 83The Explanation Of The Nodes84======================================85 86kctl_id87 read-only, get jack_kctl->kctl's id88 ::89 90 sound/card1/Headphone_Jack# cat kctl_id91 Headphone Jack92 93mask_bits94 read-only, get jack_kctl's supported events mask_bits95 ::96 97 sound/card1/Headphone_Jack# cat mask_bits98 0x0001 HEADPHONE(0x0001)99 100status101 read-only, get jack_kctl's current status102 103- headphone unplugged:104 105 ::106 107 sound/card1/Headphone_Jack# cat status108 Unplugged109 110- headphone plugged:111 112 ::113 114 sound/card1/Headphone_Jack# cat status115 Plugged116 117type118 read-only, get snd_jack's supported events from type (all supported events on the physical audio jack)119 ::120 121 sound/card1/Headphone_Jack# cat type122 0x7803 HEADPHONE(0x0001) MICROPHONE(0x0002) BTN_3(0x0800) BTN_2(0x1000) BTN_1(0x2000) BTN_0(0x4000)123 124sw_inject_enable125 read-write, enable or disable injection126 127- injection disabled:128 129 ::130 131 sound/card1/Headphone_Jack# cat sw_inject_enable132 Jack: Headphone Jack Inject Enabled: 0133 134- injection enabled:135 136 ::137 138 sound/card1/Headphone_Jack# cat sw_inject_enable139 Jack: Headphone Jack Inject Enabled: 1140 141- to enable jack injection:142 143 ::144 145 sound/card1/Headphone_Jack# echo 1 > sw_inject_enable146 147- to disable jack injection:148 149 ::150 151 sound/card1/Headphone_Jack# echo 0 > sw_inject_enable152 153jackin_inject154 write-only, inject plugin or plugout155 156- to inject plugin:157 158 ::159 160 sound/card1/Headphone_Jack# echo 1 > jackin_inject161 162- to inject plugout:163 164 ::165 166 sound/card1/Headphone_Jack# echo 0 > jackin_inject167