• John Hsu's avatar
    ASoC: nau8825: cross talk suppression measurement function · b50455fa
    John Hsu authored
    The cross talk measurement function can reduce cross talk across the JKTIP
    HPL) and JKR1(HPR) outputs which measures the cross talk signal level to
    determine what is the cross talk reduction gain. This system works by
    sending a 23Hz -24dBV sine wave into the headset output DAC and through
    the PGA. The output of the PGA is then connected to an internal current
    sense which measures the attenuated 23Hz signal and passing the output to
    an ADC which converts the measurement to a binary code. With two separated
    measurement, one for JKR1(HPR) and the other JKTIP(HPL), measurement data
    can be separated read in IMM_RMS_L for HSR and HSL after each measurement.
    
    Thus, the measurement function has four states to complete whole sequence.
    (1)Prepare state : Prepare the resource for detection and transfer to HPR
    IMM stat to make JKR1(HPR) impedance measure.
    (2)HPR IMM state : Read out orignal signal level of JKR1(HPR) and transfer
    to HPL IMM state to make JKTIP(HPL) impedance measure.
    (3)HPL IMM state : Read out cross talk signal level of JKTIP(HPL) and
    transfer to IMM state to determine suppression sidetone gain.
    (4)IMM state : Computes cross talk suppression sidetone gain with orignal
    and cross talk signal level. Apply this gain and then restore codec con-
    figuration. Then transfer to Done state for ending.
    
    In order to get the cross talk suppression sidetone gain, we need the
    function to compute log10 value and the result is round off to 3 decimal.
    This function takes reference to dvb-math. The source code locates as the
    following. "Linux/drivers/media/dvb-core/dvb_math.c"
    Then, the orignal and cross talk signal vlues need to be characterized.
    The sidetone value can be converted to decibel with the equation below.
    sidetone = 20 * log (original signal level / crosstalk signal level)
    
    Besides, the state machine for cross talk process needs interruptions to
    trigger worked. We have the RMS intrruption enabled with the internal VCO
    clock when headset connected. In the interrupt handler, the driver will
    judge the headset is high impedance or not. If yes, the cross talk supp-
    ression shouldn't apply and do nothing but relieve the protection raised
    before. Otherwise, apply the cross talk suppression in the headset and
    start the process.
    
    Because the process spends a lot of time, there is an resource race issue
    easily between the application and interruption. They will control codec
    power and clock concurrently. In one situaiton, the jack is inserted when
    playback, and then the application changes to headset device. The applica-
    tion prepares the playback and interrupt handler raises work for cross
    talk process together. For this case, the solution is that driver delays
    soc jack report until cross talk process completes. The mechanism can
    avoid application to do playback preparation before cross talk detection
    is still working.
    In another situaiton, the system suspends when playback. After resume, the
    system restarts playback, and meanwhile jack detection restarts. The play-
    back preparation and cross talk process triggered by interruptions happens
    concurrently. For the case, the driver provides the semaphone to syn-
    chronize the playback and interrupt handler. In order to avoid the play-
    back interfered by cross talk process, the driver make the playback prepa-
    ration halted until cross talk process finish. After codec resume, the
    driver finds the codec dai is active, and then the driver raises the pro-
    tection for cross talk function to avoid the playback recovers before
    cross talk process finish.
    
    The driver also provides cancel method to forcely cancel the cross talk
    task and restores the configuration to original status. Before the codec
    remove, ejection, or suspend, the driver is obliged to cancel the cross
    talk detection process. It can reduce the risk of failure when quickly and
    continually doing jack insertion and ejection.
    Signed-off-by: default avatarJohn Hsu <KCHSU0@nuvoton.com>
    Signed-off-by: default avatarMark Brown <broonie@kernel.org>
    b50455fa
nau8825.h 16.5 KB