jack-injection.rst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. ============================
  2. ALSA Jack Software Injection
  3. ============================
  4. Simple Introduction On Jack Injection
  5. =====================================
  6. Here jack injection means users could inject plugin or plugout events
  7. to the audio jacks through debugfs interface, it is helpful to
  8. validate ALSA userspace changes. For example, we change the audio
  9. profile switching code in the pulseaudio, and we want to verify if the
  10. change works as expected and if the change introduce the regression,
  11. in this case, we could inject plugin or plugout events to an audio
  12. jack or to some audio jacks, we don't need to physically access the
  13. machine and plug/unplug physical devices to the audio jack.
  14. In this design, an audio jack doesn't equal to a physical audio jack.
  15. Sometimes a physical audio jack contains multi functions, and the
  16. ALSA driver creates multi ``jack_kctl`` for a ``snd_jack``, here the
  17. ``snd_jack`` represents a physical audio jack and the ``jack_kctl``
  18. represents a function, for example a physical jack has two functions:
  19. headphone and mic_in, the ALSA ASoC driver will build 2 ``jack_kctl``
  20. for this jack. The jack injection is implemented based on the
  21. ``jack_kctl`` instead of ``snd_jack``.
  22. To inject events to audio jacks, we need to enable the jack injection
  23. via ``sw_inject_enable`` first, once it is enabled, this jack will not
  24. change the state by hardware events anymore, we could inject plugin or
  25. plugout events via ``jackin_inject`` and check the jack state via
  26. ``status``, after we finish our test, we need to disable the jack
  27. injection via ``sw_inject_enable`` too, once it is disabled, the jack
  28. state will be restored according to the last reported hardware events
  29. and will change by future hardware events.
  30. The Layout of Jack Injection Interface
  31. ======================================
  32. If users enable the SND_JACK_INJECTION_DEBUG in the kernel, the audio
  33. jack injection interface will be created as below:
  34. ::
  35. $debugfs_mount_dir/sound
  36. |-- card0
  37. |-- |-- HDMI_DP_pcm_10_Jack
  38. |-- |-- |-- jackin_inject
  39. |-- |-- |-- kctl_id
  40. |-- |-- |-- mask_bits
  41. |-- |-- |-- status
  42. |-- |-- |-- sw_inject_enable
  43. |-- |-- |-- type
  44. ...
  45. |-- |-- HDMI_DP_pcm_9_Jack
  46. |-- |-- jackin_inject
  47. |-- |-- kctl_id
  48. |-- |-- mask_bits
  49. |-- |-- status
  50. |-- |-- sw_inject_enable
  51. |-- |-- type
  52. |-- card1
  53. |-- HDMI_DP_pcm_5_Jack
  54. |-- |-- jackin_inject
  55. |-- |-- kctl_id
  56. |-- |-- mask_bits
  57. |-- |-- status
  58. |-- |-- sw_inject_enable
  59. |-- |-- type
  60. ...
  61. |-- Headphone_Jack
  62. |-- |-- jackin_inject
  63. |-- |-- kctl_id
  64. |-- |-- mask_bits
  65. |-- |-- status
  66. |-- |-- sw_inject_enable
  67. |-- |-- type
  68. |-- Headset_Mic_Jack
  69. |-- jackin_inject
  70. |-- kctl_id
  71. |-- mask_bits
  72. |-- status
  73. |-- sw_inject_enable
  74. |-- type
  75. The Explanation Of The Nodes
  76. ======================================
  77. kctl_id
  78. read-only, get jack_kctl->kctl's id
  79. ::
  80. sound/card1/Headphone_Jack# cat kctl_id
  81. Headphone Jack
  82. mask_bits
  83. read-only, get jack_kctl's supported events mask_bits
  84. ::
  85. sound/card1/Headphone_Jack# cat mask_bits
  86. 0x0001 HEADPHONE(0x0001)
  87. status
  88. read-only, get jack_kctl's current status
  89. - headphone unplugged:
  90. ::
  91. sound/card1/Headphone_Jack# cat status
  92. Unplugged
  93. - headphone plugged:
  94. ::
  95. sound/card1/Headphone_Jack# cat status
  96. Plugged
  97. type
  98. read-only, get snd_jack's supported events from type (all supported events on the physical audio jack)
  99. ::
  100. sound/card1/Headphone_Jack# cat type
  101. 0x7803 HEADPHONE(0x0001) MICROPHONE(0x0002) BTN_3(0x0800) BTN_2(0x1000) BTN_1(0x2000) BTN_0(0x4000)
  102. sw_inject_enable
  103. read-write, enable or disable injection
  104. - injection disabled:
  105. ::
  106. sound/card1/Headphone_Jack# cat sw_inject_enable
  107. Jack: Headphone Jack Inject Enabled: 0
  108. - injection enabled:
  109. ::
  110. sound/card1/Headphone_Jack# cat sw_inject_enable
  111. Jack: Headphone Jack Inject Enabled: 1
  112. - to enable jack injection:
  113. ::
  114. sound/card1/Headphone_Jack# echo 1 > sw_inject_enable
  115. - to disable jack injection:
  116. ::
  117. sound/card1/Headphone_Jack# echo 0 > sw_inject_enable
  118. jackin_inject
  119. write-only, inject plugin or plugout
  120. - to inject plugin:
  121. ::
  122. sound/card1/Headphone_Jack# echo 1 > jackin_inject
  123. - to inject plugout:
  124. ::
  125. sound/card1/Headphone_Jack# echo 0 > jackin_inject