G720 Yocto headphone detect

Now EVK board HP detect is ok .

But Custom Board NG . Custom board detect pin is reverse (compare to EVK board).

at android aosp system . it is ok when I modify headset-eint-level-pol to 4.but I found mediatek,eint-detect-mode is setted to 4 .but it is ng .how to config it

	accdet: accdet {
		compatible = "mediatek,mt6359-accdet";
		#sound-dai-cells = <0>;
		mediatek,mic-vol = <8>;
		mediatek,mic-mode = <2>;
		mediatek,pwm-deb-setting = <0x500 0x500 1 0x1f0
					    0x800 0x800 0x20 0x44
					    0x4 0x1
					    0x5 0x3 0x3 0x5 0xe>;
		mediatek,eint-use-ap = <0>;
		mediatek,eint-detect-mode = <4>;
		mediatek,eint-num = <0>;
		mediatek,eint-trig-mode = <1>;
		mediatek,eint-use-ext-res = <0>;
		mediatek,eint-comp-vth = <2>;
		mediatek,use-eint-jack-detect;
		mediatek,key-mode = <0>;
		mediatek,three-key-thr = <0 80 220 400>;
	};

Fixing Reversed Polarity on a Custom Board

To fix the reversed polarity on your custom board, update the device tree by changing:

mediatek,eint-trig-mode = <1>;  /* Active High */

to:

mediatek,eint-trig-mode = <2>;  /* Active Low */

Updated Device Tree Configuration

accdet: accdet {
    compatible = "mediatek,mt6359-accdet";
    #sound-dai-cells = <0>;

    mediatek,mic-vol = <8>;
    mediatek,mic-mode = <2>;

    mediatek,pwm-deb-setting = <0x500 0x500 1 0x1f0
                                0x800 0x800 0x20 0x44
                                0x4 0x1
                                0x5 0x3 0x3 0x5 0xe>;

    mediatek,eint-use-ap = <0>;
    mediatek,eint-detect-mode = <4>;
    mediatek,eint-num = <0>;

    /* Modified from 1 (Active High) to 2 (Active Low) */
    mediatek,eint-trig-mode = <2>;

    mediatek,eint-use-ext-res = <0>;
    mediatek,eint-comp-vth = <2>;

    mediatek,use-eint-jack-detect;

    mediatek,key-mode = <0>;
    mediatek,three-key-thr = <0 80 220 400>;
};

Important Hardware Considerations

PMIC vs. AP EINT (mediatek,eint-use-ap)

  • With

    mediatek,eint-use-ap = <0>;
    

    headset detection is handled directly by the PMIC (MT6359).

  • The polarity change via:

    mediatek,eint-trig-mode = <2>;
    

    takes effect immediately in PMIC hardware.


            accdet: accdet {
                    compatible = "mediatek,mt6359-accdet";
                    #sound-dai-cells = <0>;
                    mediatek,mic-vol = <8>;
                    mediatek,mic-mode = <2>;
                    mediatek,pwm-deb-setting = <0x500 0x500 1 0x1f0
                                                0x800 0x800 0x20 0x44
                                                0x4 0x1
                                                0x5 0x3 0x3 0x5 0xe>;
                    mediatek,eint-use-ap = <0>;
                    mediatek,eint-detect-mode = <4>;
                    mediatek,eint-num = <0>;
                    mediatek,eint-trig-mode = <2>;
                    mediatek,eint-use-ext-res = <0>;
                    mediatek,eint-comp-vth = <2>;
                    mediatek,key-mode = <0>;
                    mediatek,three-key-thr = <0 80 220 400>;
            };
with  mediatek,eint-use-ap = <0>; &mediatek,eint-trig-mode = <2>; but still is NG 

Please choose the scenario below that matches your custom board’s hardware design.

Scenario A: Using PMIC EINT (mediatek,eint-use-ap = <0>)

If the headset detection pin is connected to the PMIC (MT6359) accdet/EINT pin, the PMIC driver usually reads mediatek,eint-pol for polarity inversion.

Update your device tree node to include mediatek,eint-pol:

accdet: accdet {
    compatible = "mediatek,mt6359-accdet";
    /* ... keep other settings ... */
    mediatek,eint-use-ap = <0>;
    mediatek,eint-detect-mode = <4>;
    mediatek,eint-num = <0>;
    
    /* 1: Active High, 2: Active Low */
    mediatek,eint-trig-mode = <2>; 
    
    /* Polarity inversion: If it was 0, change to 1 (or vice-versa) to invert detection */
    mediatek,eint-pol = <1>; 
    
    mediatek,use-eint-jack-detect;
};

Scenario B: Using AP EINT (mediatek,eint-use-ap = <1>)

If your headset detection pin is wired directly to an AP GPIO, you must configure the driver to use the AP EINT.

In this mode, the polarity is governed by the interrupt flags defined in the AP GPIO/interrupt node, or through mediatek,headset-eint-level-pol.

accdet: accdet {
    compatible = "mediatek,mt6359-accdet";
    /* ... keep other settings ... */
    mediatek,eint-use-ap = <1>;          /* Enable AP-side EINT */
    mediatek,eint-detect-mode = <4>;
    
    /* Level/Polarity configuration for AP EINT */
    /* 0: Active Low, 1: Active High (Try inverting this value) */
    mediatek,headset-eint-level-pol = <0>; 
    
    mediatek,use-eint-jack-detect;
};

Note: If AP EINT is enabled, ensure that your device tree also correctly defines the pinctrl properties, interrupt-parent, and interrupts properties for the AP GPIO being used as the interrupt source.


:clipboard: Verification Checklist

  1. Verify Hardware Schematic: Double-check whether the headset detection pin (usually HP_DET or JACK_DET) is physically connected to the MT6359 PMIC pin or to an AP GPIO pin.
  2. Examine Kernel Boot Logs (dmesg):
    Plug and unplug the headset, then capture the kernel log to verify if the driver registers the event or prints any polarity/EINT warnings:
    dmesg | grep -E -i "accdet|pmic|eint"
    
  3. Verify Sysfs Status (if available):
    Check the state of the switch in Android sysfs to see if it responds to insertion:
    cat /sys/class/switch/h2w/state
    

modify :mediatek,eint-pol = <1>; mediatek,eint-trig-mode = <2>; it is still NG.

HP_Det is the same pin with evk board. the fellowing info is plugIn /out :

root@genio-720-evk:~# dmesg | grep -E -i “accdet|pmic|eint”
[ 0.324890] mt8189-pinctrl 10005000.pinctrl: mtk_eint_do_init eint total 210 pins.
[ 0.324923] mt8189-pinctrl 10005000.pinctrl: mtk_eint_do_init eint in new mode, assign the matrix number to 210.
[ 0.928235] pmic-codec-accdet mt6359-accdet: accdet caps=105
[ 3.946761] input: mtk-pmic-keys as /devices/platform/soc/1cc04000.pwrap/1cc04000.pwrap:pmic/mtk-pmic-keys/input/input2
root@genio-720-evk:~# dmesg | grep -E -i “accdet|pmic|eint”
[ 0.324890] mt8189-pinctrl 10005000.pinctrl: mtk_eint_do_init eint total 210 pins.
[ 0.324923] mt8189-pinctrl 10005000.pinctrl: mtk_eint_do_init eint in new mode, assign the matrix number to 210.
[ 0.928235] pmic-codec-accdet mt6359-accdet: accdet caps=105
[ 3.946761] input: mtk-pmic-keys as /devices/platform/soc/1cc04000.pwrap/1cc04000.pwrap:pmic/mtk-pmic-keys/input/input2

Based on the dmesg output you provided, the logs for plug-in and plug-out are completely identical, and no new kernel messages were generated during the physical action. This indicates that the operating system/driver is not receiving or registering any interrupt event at all when you plug or unplug the headset.

Since your custom board has a reversed detection mechanism compared to the EVK board, modifying the polarity in the device tree alone will not work if the hardware state transitions are not triggering the EINT (External Interrupt) engine in the first place.

Please follow below troubleshooting guidelines:


1. Check /proc/interrupts to Verify Hardware Interrupts

Before investigating the driver logic, you must confirm if the hardware interrupt is physically reaching the CPU.

  1. Run the following command with the headset unplugged:

    cat /proc/interrupts | grep -iE "accdet|pmic|eint"
    
  2. Plug the headset in, and run the command again.

  3. Analyze the results:

    • Look at the counter column for the accdet/PMIC EINT interrupt line.
    • If the count does not increase, the physical voltage transition on the pin is failing to trigger the PMIC interrupt engine.
    • If the count increases but nothing happens, the interrupt is firing, but the driver is rejecting it (likely due to debounce settings or state machine mismatch).

2. Measure and Compare Hardware Voltages (Crucial)

The MT6359 PMIC uses internal analog comparators (mediatek,eint-comp-vth) to sense state changes. If your custom board uses different pull-up/pull-down resistors or a reversed jack switch, the voltage levels during plug-in/out might not cross the PMIC’s internal comparator thresholds.

Please use a multimeter to measure the voltage on the HP_DET pin:

State EVK Board Voltage Custom Board Voltage
Headset Unplugged e.g., 1.8V Measure this
Headset Plugged In e.g., 0V Measure this
  • If your Custom Board voltages do not drop/rise cleanly to the threshold levels, the PMIC will never fire an interrupt.

  • Comparator Threshold Configuration:

    In your DTS node:

    mediatek,eint-comp-vth = <2>;
    

    This value determines the internal reference voltage threshold. If your custom board’s voltage swing is different, you may need to adjust this value or modify your hardware resistor divider to match the EVK voltage levels.


3. Verify Alternative DTS Polarity Properties

MediaTek’s PMIC driver implementations vary significantly across kernel versions (e.g., 4.19, 5.10, 5.15, 6.1). Depending on your specific driver codebase, the driver might ignore mediatek,eint-pol and instead look for other properties.

Search your kernel driver source code (usually located in drivers/misc/mediatek/accdet/ or sound/soc/codecs/mt6359-accdet.c) for the properties it parses, or try adding these common alternative properties to your DTS:

accdet: accdet {
    ...
    /* Try enabling high-level active or low-level active explicitly */
    mediatek,hp-eint-high = <1>; // Try 1 or 0

    /* Some drivers use this property even when eint-use-ap = <0> */
    mediatek,headset-eint-level-pol = <4>; // Try 4 (High-active) or 3 (Low-active)

    /* Check if the trigger mode needs to match the inactive-to-active edge */
    mediatek,eint-trig-mode = <2>; // 1: falling, 2: rising, 3: high level, 4: low level
    ...
};

4. Enable Kernel Dynamic Debugging

To see exactly what the mt6359-accdet driver is doing when the state changes, enable dynamic debugging for the accdet driver:

# Enable all debug logs for the accdet driver
echo "file mt6359-accdet.c +p" > /sys/kernel/debug/dynamic_debug/control

# If the file is named differently in your kernel, you can target the module:
echo "module mt6359_accdet +p" > /sys/kernel/debug/dynamic_debug/control

Once enabled, plug and unplug the headset again. You should see detailed prints in dmesg regarding the internal state machine transitions, comparator readings, and debounce timers, which will pinpoint exactly why the driver is rejecting the event.

cat /proc/interrupts | grep -iE “accdet|pmic|eint”

root@genio-520-evk:~# cat /proc/interrupts | grep -iE “accdet|pmic|eint”
33: 0 0 0 0 0 0 0 0 mtk-eint 6 Edge 11240000.mmc cd
221: 3 0 0 0 0 0 0 0 mtk-eint 194 Level mt6358-irq
245: 0 0 0 0 0 0 0 0 GICv3 528 Level mt-pmic-pwrap
255: 0 0 0 0 0 0 0 0 mt6358-irq 48 Edge mtk-pmic-keys
256: 0 0 0 0 0 0 0 0 mt6358-irq 49 Edge mtk-pmic-keys
257: 0 0 0 0 0 0 0 0 mt6358-irq 50 Edge mtk-pmic-keys
258: 0 0 0 0 0 0 0 0 mt6358-irq 51 Edge mtk-pmic-keys
259: 0 0 0 0 0 0 0 0 mt6358-irq 133 Edge ACCDET_IRQ
260: 0 0 0 0 0 0 0 0 mt6358-irq 134 Edge ACCDET_EINT0
root@genio-520-evk:~# cat /proc/interrupts | grep -iE “accdet|pmic|eint”
33: 0 0 0 0 0 0 0 0 mtk-eint 6 Edge 11240000.mmc cd
221: 3 0 0 0 0 0 0 0 mtk-eint 194 Level mt6358-irq
245: 0 0 0 0 0 0 0 0 GICv3 528 Level mt-pmic-pwrap
255: 0 0 0 0 0 0 0 0 mt6358-irq 48 Edge mtk-pmic-keys
256: 0 0 0 0 0 0 0 0 mt6358-irq 49 Edge mtk-pmic-keys
257: 0 0 0 0 0 0 0 0 mt6358-irq 50 Edge mtk-pmic-keys
258: 0 0 0 0 0 0 0 0 mt6358-irq 51 Edge mtk-pmic-keys
259: 0 0 0 0 0 0 0 0 mt6358-irq 133 Edge ACCDET_IRQ
260: 0 0 0 0 0 0 0 0 mt6358-irq 134 Edge ACCDET_EINT0

plug in /out

Headset Unplugged 2.21V

Headset Plugged In 2.45V

Due to AU_HPL AU_HPR signal .when Headset Unplugged ,Voltage is not zero.

Changed with mediatek,eint-comp-vth = <1>; I see the following but don’t know what it means

root@genio-720-evk:/# cat proc/interrupts |grep -iE “accdet|pmic|eint”
33: 0 0 0 0 0 0 0 0 mtk-eint 6 Edge 11240000.mmc cd
221: 2 0 0 0 0 0 0 0 mtk-eint 194 Level mt6358-irq
245: 0 0 0 0 0 0 0 0 GICv3 528 Level mt-pmic-pwrap
255: 0 0 0 0 0 0 0 0 mt6358-irq 48 Edge mtk-pmic-keys
256: 0 0 0 0 0 0 0 0 mt6358-irq 49 Edge mtk-pmic-keys
257: 0 0 0 0 0 0 0 0 mt6358-irq 50 Edge mtk-pmic-keys
258: 0 0 0 0 0 0 0 0 mt6358-irq 51 Edge mtk-pmic-keys
259: 0 0 0 0 0 0 0 0 mt6358-irq 133 Edge ACCDET_IRQ
260: 0 0 0 0 0 0 0 0 mt6358-irq 134 Edge ACCDET_EINT0
root@genio-720-evk:/# cat proc/interrupts |grep -iE “accdet|pmic|eint”
33: 0 0 0 0 0 0 0 0 mtk-eint 6 Edge 11240000.mmc cd
221: 3 0 0 0 0 0 0 0 mtk-eint 194 Level mt6358-irq
245: 0 0 0 0 0 0 0 0 GICv3 528 Level mt-pmic-pwrap
255: 0 0 0 0 0 0 0 0 mt6358-irq 48 Edge mtk-pmic-keys
256: 0 0 0 0 0 0 0 0 mt6358-irq 49 Edge mtk-pmic-keys
257: 0 0 0 0 0 0 0 0 mt6358-irq 50 Edge mtk-pmic-keys
258: 0 0 0 0 0 0 0 0 mt6358-irq 51 Edge mtk-pmic-keys
259: 0 0 0 0 0 0 0 0 mt6358-irq 133 Edge ACCDET_IRQ
260: 0 1 0 0 0 0 0 0 mt6358-irq 134 Edge ACCDET_EINT0

Now config:

            accdet: accdet {
                    compatible = "mediatek,mt6359-accdet";
                    #sound-dai-cells = <0>;
                    mediatek,mic-vol = <8>;
                    mediatek,mic-mode = <2>;
                    mediatek,pwm-deb-setting = <0x500 0x500 1 0x1f0
                                                0x800 0x800 0x20 0x44
                                                0x4 0x1
                                                0x5 0x3 0x3 0x5 0xe>;
                    mediatek,eint-use-ap = <0>;
                    mediatek,eint-detect-mode = <4>;
                    mediatek,eint-num = <0>;
                    mediatek,eint-trig-mode = <2>;
                    mediatek,eint-use-ext-res = <0>;
                    mediatek,eint-comp-vth = <1>;
                    mediatek,use-eint-jack-detect;
                    mediatek,key-mode = <0>;
                    mediatek,eint-pol = <1>;
                    mediatek,three-key-thr = <0 80 220 400>;
            };

For the same board: when Burn with the Android firmware, the pin reads high level when the pplugged in and 0 V when unplugged. However, after Burn in the Yocto firmware, the pin measures 2.45 V with plug in and 2.21 V when plugout. Could this be caused by missing or incorrect configurations somewhere?

Just to confirm—headphone detection works on Android, and the issue only happens after flashing Yocto. Is that correct?

Yes ! HP works very well on Android with the same board(plugin 2.4V plugout 0V. play music can hear sound from headphone). but yocto is not .

the following is android config

	accdet: accdet {
		compatible = "mediatek,mt6359-accdet";
		accdet-name = "mt63xx-accdet";
		accdet-mic-vol = <8>;
		accdet-plugout-debounce = <1>;
		accdet-mic-mode = <2>;
		eint_use_ext_res = <0>;
		headset-mode-setting = <0x500 0x500 1 0x1f0
					0x800 0x800 0x20 0x44
					0x4 0x1
					0x5 0x3 0x3 0x5 0xe>;
		headset-use-ap-eint = <0>;
		headset-eint-num = <0>;
		headset-eint-trig-mode = <1>;
		headset-eint-level-pol = <4>;
		headset-key-mode = <0>;
		headset-three-key-threshold = <0 80 220 400>;
		headset-three-key-threshold-CDD = <0 121 192 600>;
		headset-four-key-threshold = <0 58 121 192 400>;
		io-channels = <&pmic_auxadc AUXADC_ACCDET>;
		io-channel-names = "pmic_accdet";
		nvmem = <&pmic_efuse>;
		nvmem-names = "mt63xx-accdet-efuse";
		status = "okay";
	};

Do you have any advice? Thanks

Hi @wr.zeng

The property related to the trigger mode is mediatek,eint-level-pol, not mediatek,eint-detect-mode.

Please try adding this change to the accdet node in the dts file.

	accdet: accdet {
		compatible = "mediatek,mt6359-accdet";
		#sound-dai-cells = <0>;
		mediatek,mic-vol = <8>;
		mediatek,mic-mode = <2>;
		mediatek,pwm-deb-setting = <0x500 0x500 1 0x1f0
					    0x800 0x800 0x20 0x44
					    0x4 0x1
					    0x5 0x3 0x3 0x5 0xe>;
		mediatek,eint-use-ap = <0>;
		mediatek,eint-detect-mode = <4>;
		mediatek,eint-num = <0>;
		mediatek,eint-trig-mode = <1>;
		mediatek,eint-use-ext-res = <0>;
		mediatek,eint-comp-vth = <2>;
		mediatek,use-eint-jack-detect;
		mediatek,key-mode = <0>;
		mediatek,three-key-thr = <0 80 220 400>;
		mediatek,eint-level-pol = <4>;
	};

it is ok .thanks!