• Arnaud Ferraris's avatar
    ASoC: sun8i-codec: Implement jack and accessory detection · 21fa98f4
    Arnaud Ferraris authored
    Add support for the jack detection functionality in the A64 variant,
    which uses a pair of IRQs; and microphone accessory (button) detection,
    which uses an ADC with an IRQ trigger.
    
    IRQs will only be triggered if the JACKDETEN, HMICBIASEN, and MICADCEN
    bits are set appropriately in the analog codec component
    (sun50i-codec-analog), but there is no direct software dependency
    between the two components.
    
    Setup ADC so that it samples with period of 16ms, disable smoothing
    and enable MDATA threshold (should be below idle voltage/HMIC_DATA
    value). Also enable HMIC_N, which makes sure we get HMIC_N samples
    after HMIC_DATA crosses the threshold.
    
    This allows us to perform steady state detection of HMIC_DATA, by
    comparing current and previous ADC samples, to detect end of the
    transient when the user de-presses the button. Otherwise ADC could
    sample anywhere within the transient, and the driver may mis-issue
    key-press events for other buttons attached to the resistor ladder.
    
    [Ondrej: Almost complete rewrite of the patch, change to use set_jack
    API. Better de-bounce, fix mic button handling, better interrupt
    processing.]
    Signed-off-by: default avatarArnaud Ferraris <arnaud.ferraris@collabora.com>
    [Samuel: Decouple from analog codec, fixes]
    Co-developed-by: default avatarSamuel Holland <samuel@sholland.org>
    Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
    Co-developed-by: default avatarOndrej Jirman <megi@xff.cz>
    Signed-off-by: default avatarOndrej Jirman <megi@xff.cz>
    Link: https://msgid.link/r/20240302140042.1990256-5-megi@xff.czSigned-off-by: default avatarMark Brown <broonie@kernel.org>
    21fa98f4
sun8i-codec.c 53.6 KB