162306a36Sopenharmony_ci=================== 262306a36Sopenharmony_ciASoC jack detection 362306a36Sopenharmony_ci=================== 462306a36Sopenharmony_ci 562306a36Sopenharmony_ciALSA has a standard API for representing physical jacks to user space, 662306a36Sopenharmony_cithe kernel side of which can be seen in include/sound/jack.h. ASoC 762306a36Sopenharmony_ciprovides a version of this API adding two additional features: 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci - It allows more than one jack detection method to work together on one 1062306a36Sopenharmony_ci user visible jack. In embedded systems it is common for multiple 1162306a36Sopenharmony_ci to be present on a single jack but handled by separate bits of 1262306a36Sopenharmony_ci hardware. 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci - Integration with DAPM, allowing DAPM endpoints to be updated 1562306a36Sopenharmony_ci automatically based on the detected jack status (eg, turning off the 1662306a36Sopenharmony_ci headphone outputs if no headphones are present). 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ciThis is done by splitting the jacks up into three things working 1962306a36Sopenharmony_citogether: the jack itself represented by a struct snd_soc_jack, sets of 2062306a36Sopenharmony_cisnd_soc_jack_pins representing DAPM endpoints to update and blocks of 2162306a36Sopenharmony_cicode providing jack reporting mechanisms. 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ciFor example, a system may have a stereo headset jack with two reporting 2462306a36Sopenharmony_cimechanisms, one for the headphone and one for the microphone. Some 2562306a36Sopenharmony_cisystems won't be able to use their speaker output while a headphone is 2662306a36Sopenharmony_ciconnected and so will want to make sure to update both speaker and 2762306a36Sopenharmony_ciheadphone when the headphone jack status changes. 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ciThe jack - struct snd_soc_jack 3062306a36Sopenharmony_ci============================== 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ciThis represents a physical jack on the system and is what is visible to 3362306a36Sopenharmony_ciuser space. The jack itself is completely passive, it is set up by the 3462306a36Sopenharmony_cimachine driver and updated by jack detection methods. 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ciJacks are created by the machine driver calling snd_soc_jack_new(). 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_cisnd_soc_jack_pin 3962306a36Sopenharmony_ci================ 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ciThese represent a DAPM pin to update depending on some of the status 4262306a36Sopenharmony_cibits supported by the jack. Each snd_soc_jack has zero or more of these 4362306a36Sopenharmony_ciwhich are updated automatically. They are created by the machine driver 4462306a36Sopenharmony_ciand associated with the jack using snd_soc_jack_add_pins(). The status 4562306a36Sopenharmony_ciof the endpoint may configured to be the opposite of the jack status if 4662306a36Sopenharmony_cirequired (eg, enabling a built in microphone if a microphone is not 4762306a36Sopenharmony_ciconnected via a jack). 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ciJack detection methods 5062306a36Sopenharmony_ci====================== 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ciActual jack detection is done by code which is able to monitor some 5362306a36Sopenharmony_ciinput to the system and update a jack by calling snd_soc_jack_report(), 5462306a36Sopenharmony_cispecifying a subset of bits to update. The jack detection code should 5562306a36Sopenharmony_cibe set up by the machine driver, taking configuration for the jack to 5662306a36Sopenharmony_ciupdate and the set of things to report when the jack is connected. 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ciOften this is done based on the status of a GPIO - a handler for this is 5962306a36Sopenharmony_ciprovided by the snd_soc_jack_add_gpio() function. Other methods are 6062306a36Sopenharmony_cialso available, for example integrated into CODECs. One example of 6162306a36Sopenharmony_ciCODEC integrated jack detection can be see in the WM8350 driver. 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ciEach jack may have multiple reporting mechanisms, though it will need at 6462306a36Sopenharmony_cileast one to be useful. 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ciMachine drivers 6762306a36Sopenharmony_ci=============== 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ciThese are all hooked together by the machine driver depending on the 7062306a36Sopenharmony_cisystem hardware. The machine driver will set up the snd_soc_jack and 7162306a36Sopenharmony_cithe list of pins to update then set up one or more jack detection 7262306a36Sopenharmony_cimechanisms to update that jack based on their current status. 73