Bug 208005

Summary: Headphones are not being detected on ASUS Zephyrus M/S GU502/DU502
Product: Drivers Reporter: iancmx
Component: Sound(ALSA)Assignee: Jaroslav Kysela (perex)
Status: RESOLVED IMPLEMENTED    
Severity: blocking CC: akusmirek, berlier.v, bigkrp, carloscg, contact, fernandonietop9, jamesfromnz+kernel, jiloxe4653, kakorha, luke, maksym.fedan, rockynhs, sounak.mukherjee2000, tiwai, um-li, us2cool, whane1977
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 5.4.43-1 Subsystem:
Regression: No Bisected commit-id:
Attachments: no option to select headphones when plugged in, seems like headphones are undetected
Test fix patch
Test patch to enable headset, and toggle outputs on jacksense
Test patch to enable headset, and toggle outputs on jacksense
Final patch to enable headset on GX502/SubSystem 0x10431881

Description iancmx 2020-06-01 06:51:41 UTC
Created attachment 289441 [details]
no option to select headphones when plugged in, seems like headphones are undetected

Linux is unable to detect headset on the Asus Zephyrus M GU502. When headphones are plugged in, the audio settings remains as Speakers (Built-in Audio Analag Stereo). Audio works perfectly on internal speakers but is unable to output to headphones. Under pavucontrol, there is no option to choose headphones even when headphones is plugged in. 

Other people experiencing the same problem:
https://forums.linuxmint.com/viewtopic.php?t=306891
https://askubuntu.com/questions/1179834/asus-m-gu502-unable-to-detect-headsets-in-ubuntu-18-04
https://forum.manjaro.org/t/headphones-not-detected-kde/145544


The sound card is ALC294 Analog
Comment 1 iancmx 2020-06-01 06:54:04 UTC
I forgot to mention that the audio jack on the Zephyrus M is a audio mic combo jack
Comment 4 Takashi Iwai 2020-06-16 13:44:27 UTC
You can try the different quirk for your device, e.g. add the following line

  SND_PCI_QUIRK(0x1043, 0x1881, "ASUS GU502", ALC294_FIXUP_ASUS_HPE),

in alc269_fixup_tbl[] in sound/pci/hda/patch_realtek.c
This will apply the same quirk as ASUS B9450FA that includes the headset support.

In anyway, please upload alsa-info.sh to Bugzilla, too.
Comment 6 iancmx 2020-06-17 00:12:12 UTC
(In reply to Takashi Iwai from comment #4)
> You can try the different quirk for your device, e.g. add the following line
> 
>   SND_PCI_QUIRK(0x1043, 0x1881, "ASUS GU502", ALC294_FIXUP_ASUS_HPE),
> 
> in alc269_fixup_tbl[] in sound/pci/hda/patch_realtek.c
> This will apply the same quirk as ASUS B9450FA that includes the headset
> support.
> 
> In anyway, please upload alsa-info.sh to Bugzilla, too.

where is the patch_realtek.c located? i did cd /sound and folder does not exist
Comment 7 Takashi Iwai 2020-06-17 07:33:25 UTC
It's in sound/pci/hda/patch_realtek.c in Linux kernel tree.  After patching, compile the kernel, install and retest.
Comment 8 Takashi Iwai 2020-06-17 07:37:42 UTC
Created attachment 289713 [details]
Test fix patch
Comment 9 iancmx 2020-06-28 04:05:09 UTC
I've installed and tested the fix patch. Now plugging in a headset would detect the external headset microphone. However, the sound output is still not showing a headset and only showing speaker as an option.
Comment 10 iancmx 2020-06-28 04:12:13 UTC
After some experiments, using hdajackrestask and mapping 0x19 to microphone, I am able to get the headeset microphone to work. Before remapping it and using the kernel, it was still unable to work.

Headset audio still does not work tho.
Comment 11 iancmx 2020-06-28 04:16:05 UTC
Just to follow up, I also remapped 0x21 to headphones, which enabled headphone detection, but theres still no audio coming from the headphone. Remapping 0x21 to headphones and 0x19 to microphone are both required to get the headset microphone to work and headphone jack DETECTION  (still no audio).
Comment 12 iancmx 2020-07-02 00:44:58 UTC
Disregard my previous 3 messages, i felt like ive explained what Ive done extremely poorly. After installing your patch, when I plug my headset in, linux detected the headset mic but it was not working properly. Headphones were still not being detected. I remapped pin 0x21 to headphones on HDAjackretask, and this cause headphone to be DETECTED (still no audio) and the mimcrophone from the headset to function perfectly. If you need any logs please let me know.
Comment 13 iancmx 2020-07-02 00:46:44 UTC
My current pincfg:
[codec]
0x10ec0294 0x10431881 0

[pincfg]
0x12 0x90a60120
0x13 0x40000000
0x14 0x411111f0
0x15 0x411111f0
0x16 0x411111f0
0x17 0x90170110
0x18 0x411111f0
0x19 0x01a1103c
0x1a 0x411111f0
0x1b 0x411111f0
0x1d 0x40600001
0x1e 0x411111f0
0x1f 0x411111f0
0x21 0x0321403f
Comment 14 iancmx 2020-07-02 00:47:59 UTC
the pin cfg i posted above was after applying your patch and remapping 0x21 to headphones on hdajackretask
Comment 15 iancmx 2020-07-05 04:19:19 UTC
Even though I have that pincfg, the default for 0x21 isn't changing to what the pincfg has:

Node 0x21 [Pin Complex] wcaps 0x40058d: Stereo Amp-Out
  Control: name="Headphone Playback Switch", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x00 0x00]
  Pincap 0x0001001c: OUT HP EAPD Detect
  EAPD 0x2: EAPD
  Pin Default 0x411111f0: [N/A] Speaker at Ext Rear
    Conn = 1/8, Color = Black
    DefAssociation = 0xf, Sequence = 0x0
    Misc = NO_PRESENCE
  Pin-ctls: 0xc0: OUT HP
  Unsolicited: tag=01, enabled=1
  Power states:  D0 D1 D2 D3 EPSS
  Power: setting=D0, actual=D0
  Connection: 2
Comment 16 lestairon 2020-07-22 10:38:12 UTC
(In reply to iancmx from comment #6)
> (In reply to Takashi Iwai from comment #4)
> > You can try the different quirk for your device, e.g. add the following
> line
> > 
> >   SND_PCI_QUIRK(0x1043, 0x1881, "ASUS GU502", ALC294_FIXUP_ASUS_HPE),
> > 
> > in alc269_fixup_tbl[] in sound/pci/hda/patch_realtek.c
> > This will apply the same quirk as ASUS B9450FA that includes the headset
> > support.
> > 
> > In anyway, please upload alsa-info.sh to Bugzilla, too.
> 
> where is the patch_realtek.c located? i did cd /sound and folder does not
> exist

Already installed the kernel and didn't work for me. It is the same machine listed on that patch
Comment 17 iancmx 2020-07-27 07:13:15 UTC
The patch indeed does not work. I have experimented with different hdadjackretask settings buts still unable to get it to work
Comment 18 iancmx 2020-08-08 06:41:01 UTC
Anyone has any tips on solving this bug is greatly appreciated. There are many other people facing the same issue with this laptop, and I would like to find a fix as sooon as possible.
Comment 19 jamesfromnz+kernel 2020-08-16 11:28:55 UTC
The Asus Rog Zephyrus S GX502GW has the same problem. The headphone/mic jack does not work in Linux but does in Windows. Again this problem is listed in many forms and I have found no fix. When headphones are plugged in sound continues via laptop speakers and nothing from headphones. The sound card for Asus GX502GW is Realtek ALC294. Thank you for any help with this matter.


System:
  Kernel: 5.4.0-42-generic x86_64 bits: 64 compiler: gcc v: 9.3.0 
  Desktop: Cinnamon 4.6.7 Distro: Linux Mint 20 Ulyana 
  base: Ubuntu 20.04 focal 
Machine:
  Type: Laptop System: ASUSTeK product: Zephyrus S GX502GW_GX502GW v: 1.0 
  serial: <filter> 
  Mobo: ASUSTeK model: GX502GW v: 1.0 serial: <filter> 
  UEFI: American Megatrends v: GX502GW.310 date: 04/24/2020 
Audio:
  Device-1: Intel Cannon Lake PCH cAVS vendor: ASUSTeK driver: snd_hda_intel 
  v: kernel bus ID: 00:1f.3 
  Device-2: NVIDIA TU106 High Definition Audio vendor: ASUSTeK 
  driver: snd_hda_intel v: kernel bus ID: 01:00.1 
  Sound Server: ALSA v: k5.4.0-42-generic
Comment 20 bobby 2020-08-19 14:43:03 UTC
I'm also on the GU502GU variant, no sound from headphone jack in Linux Mint or PopOS 20. Have been seeking a fix for some time. Thanks
Comment 21 iancmx 2020-08-19 20:47:32 UTC
For those who are getting the same issue, i recommend also posting on https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1877640 since there dont seem to be much responses in this forum. The more postts regarding this issue, greater the chance someone knowledgable may be able to fix it.
Comment 22 UndeadKernel 2020-08-21 18:32:06 UTC
Audio from the speakers in the Zephyrus S17 (GX701LWS) is not working. However, headphone audio is working as expected. This is what I see with dmesg:


    [    2.650348] snd_hda_codec_realtek hdaudioC0D0: autoconfig for ALC294: line_outs=1 (0x17/0x0/0x0/0x0/0x0) type:speaker
    [    2.650349] snd_hda_codec_realtek hdaudioC0D0:    speaker_outs=0 (0x0/0x0/0x0/0x0/0x0)
    [    2.650350] snd_hda_codec_realtek hdaudioC0D0:    hp_outs=1 (0x21/0x0/0x0/0x0/0x0)
    [    2.650350] snd_hda_codec_realtek hdaudioC0D0:    mono: mono_out=0x0
    [    2.650351] snd_hda_codec_realtek hdaudioC0D0:    inputs:
    [    2.650351] snd_hda_codec_realtek hdaudioC0D0:      Headset Mic=0x19
    [    2.650352] snd_hda_codec_realtek hdaudioC0D0:      Internal Mic=0x12


I would like to have the speakers working as well as the headphones.
Maybe I could share some configuration with you that could help in debugging this problem? This is the  output of alsa-info.sh:
https://pastebin.com/wyNSfSvv
Comment 23 iancmx 2020-08-30 01:57:38 UTC
Did you make any modifications to to your pin assignments? I'm not expert in this field but i would to see if theres any difference between the way your pin assignments is set up compared to the zephyrus ms. Can you screenshot your pin assignments in hda_jackretask?
Comment 24 Luke Jones 2020-09-01 04:56:34 UTC
I've been looking at this recently and though I've got the pins seemingly mapped, - I can't get sound through the headphones
- I *can* get input through headphone mic
- I can't get input from external mic jack
- Both ports detect what it plugged in correctly

What I've tried so far is 

[ALC294_FIXUP_ASUS_GX502_HPE] = {
	.type = HDA_FIXUP_VERBS,
	.v.verbs = (const struct hda_verb[]) {
		/* Set EAPD high */
		{ 0x20, AC_VERB_SET_COEF_INDEX, 0x0f },
		{ 0x20, AC_VERB_SET_PROC_COEF, 0x7774 },
		{ }
	},
	.chained = true,
	.chain_id = ALC294_FIXUP_ASUS_GX502_PINS
},
[ALC294_FIXUP_ASUS_GX502_PINS] = {
	.type = HDA_FIXUP_PINS,
	.v.pins = (const struct hda_pintbl[]) {
		{ 0x19, 0x03a11020 }, /* front HP mic */
		{ 0x1a, 0x00a11030 }, /* rear external mic */
		{ 0x21, 0x03211020 }, /* HP out */
		{ }
	},
	.chained = true,
	.chain_id = ALC294_FIXUP_ASUS_GX502_DUAL_SPK
},
[ALC294_FIXUP_ASUS_GX502_DUAL_SPK] = {
	.type = HDA_FIXUP_FUNC,
	.v.func = alc285_fixup_speaker2_to_dac1,
},

here though, the only thing guaranteed to work is the pin assignment - the verb and func are not required.

After this I started digging around a little more (slow progress with no knowledge of this stuff) which led me to looking at some code blocks in the related code which had comments stating that there was a reroute of the nodes happening. That led me to look at the nodes for the GX502:

Node 0x02 [Audio Output] wcaps 0x41d: Stereo Amp-Out
  Control: name="Headphone Playback Volume", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Device: name="ALC294 Analog", type="Audio", device=0
  Amp-Out caps: ofs=0x57, nsteps=0x57, stepsize=0x02, mute=0
  Amp-Out vals:  [0x4c 0x4c]
  Converter: stream=0, channel=0
  PCM:
    rates [0x560]: 44100 48000 96000 192000
    bits [0xe]: 16 20 24
    formats [0x1]: PCM
  Power states:  D0 D1 D2 D3 EPSS
  Power: setting=D0, actual=D0
Node 0x03 [Audio Output] wcaps 0x41d: Stereo Amp-Out
  Control: name="Speaker Playback Volume", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Amp-Out caps: ofs=0x57, nsteps=0x57, stepsize=0x02, mute=0
  Amp-Out vals:  [0x00 0x00]
  Converter: stream=0, channel=0
  PCM:
    rates [0x60]: 44100 48000
    bits [0xe]: 16 20 24
    formats [0x1]: PCM
  Power states:  D0 D1 D2 D3 EPSS
  Power: setting=D0, actual=D0

I have no idea how to determine what the routing is (it's also hard to google this). But it seems sort of possible that the headphone out requires a different route and it may be defaulting to node 0x03 instead of 0x02?

I guess something like:
/* force NID 0x17 (Bass Speaker) to DAC1 to share it with the main speaker */
static void alc285_fixup_speaker2_to_dac1(struct hda_codec *codec,
					  const struct hda_fixup *fix, int action)
{
	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
		static const hda_nid_t conn[] = { 0x02 };
		snd_hda_override_conn_list(codec, 0x17, ARRAY_SIZE(conn), conn);
	}
}

But for 0x21 instead of 0x17?

@Takashi, I am very prepared to put some time in to this as the issue affects a very large group of ASUS gaming laptop models.
Comment 25 Luke Jones 2020-09-01 07:37:53 UTC
I tried a function like:

/* force NID 0x17 (Bass Speaker) to DAC1 to share it with the main speaker */
static void alc294_fixup_speaker2_to_dac1(struct hda_codec *codec,
					  const struct hda_fixup *fix, int action)
{
	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
		static const hda_nid_t conn[] = { 0x03 };
		snd_hda_override_conn_list(codec, 0x21, ARRAY_SIZE(conn), conn);
	}
}

But this made zero change (tried with 0x02 and 0x03 nodes).
Comment 26 Luke Jones 2020-09-01 10:35:56 UTC
Related alsa-info is at http://alsa-project.org/db/?f=8ccec661a4234d3790f46a1ce6dfe3270cc51d64

I just realised the alsa info is using the last kernel hack I tried...

Quirks tried in addition to the pins I set in a previous reply:

ALC294_FIXUP_ASUS_SPK
ALC294_FIXUP_SPK2_TO_DAC1
ALC294_FIXUP_ASUS_DUAL_SPK
ALC294_FIXUP_ASUS_HPE

Also tried the following:

[ALC294_FIXUP_ASUS_GX502_HPE] = {
	.type = HDA_FIXUP_VERBS,
	.v.verbs = (const struct hda_verb[]) {
		/* Set EAPD high */
		{ 0x20, AC_VERB_SET_COEF_INDEX, 0x40 },
		{ 0x20, AC_VERB_SET_PROC_COEF, 0x8800 },
		{ 0x20, AC_VERB_SET_COEF_INDEX, 0x0f },
		{ 0x20, AC_VERB_SET_PROC_COEF, 0x7774 },
		{ }
	},
	.chained = true,
	.chain_id = ALC294_FIXUP_ASUS_GX502_PINS
},
[ALC294_FIXUP_ASUS_GX502_PINS] = {
	.type = HDA_FIXUP_PINS,
	.v.pins = (const struct hda_pintbl[]) {
		{ 0x19, 0x03a11020 }, /* front HP mic */
		{ 0x1a, 0x00a11030 }, /* rear external mic */
		{ 0x21, 0x03211020 }, /* HP out */
		{ }
	},
	.chained = true,
	.chain_id = ALC294_FIXUP_ASUS_GX502_DUAL_SPK
},
[ALC294_FIXUP_ASUS_GX502_DUAL_SPK] = {
	.type = HDA_FIXUP_FUNC,
	.v.func = alc294_fixup_speaker2_to_dac1,
},

static void alc294_fixup_speaker2_to_dac1(struct hda_codec *codec,
					  const struct hda_fixup *fix, int action)
{
	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
		static const hda_nid_t conn[] = { 0x02 };
		snd_hda_override_conn_list(codec, 0x21, ARRAY_SIZE(conn), conn);
	}
}


The pins *do* work, and detect the attached peripherals, states change in hdajacksensetest.
- External mic, detected, no input
- Headset mic, detected, input is good
- Headset speakers, no output
This is true for everything I've tried above.
I also noticed that Amp-Out vals change and are saved per 0x02 and 0x03, with 0x02 being the Headphone out.

I feel I've gone as far as I can without gaining additional knowledge. Googling many of the terms, parts of outputs etc isn't helping much.
Comment 27 Luke Jones 2020-09-05 11:47:46 UTC
I've now done a fair amount of work and discovered what works and what doesn't, along with getting a lot of data dumps. I will first try to sumarise what I *think* might be happening..

- The windows driver can enable and disable jack sensing on nid 0x21
- It appears to use 0x15 for actual heaphone output?
- The driver seems to have some defaults, but then a lot is changed via verbs I think

I wasn't able to decypher or discover the *exact* pincfg for all related pin complex. Maybe someone can help me here? Overall the setup seems a bit of a mess and possibly relies on the Windows driver to do some things I'm not sure about. For example the 0x20 0x10 0x8a20 verb toggles internal/headphones in Linux, but this is always on in Windows so I'm unsure how it manages output.

-----------------------------
What is different to default
-----------------------------
From Windows dump:
Wid=15  Codec=411111F0  Drv=01211420  Loc=00000000
Wid=19  Codec=411111F0  Drv=01A11050  Loc=00080000
Wid=1A  Codec=411111F0  Drv=01A11830  Loc=00020200 ? What is Loc?
Using the above directly in Linux works but: no HP out due to no jacksense

Verbs of 0x20:
NID  IDX  VAL
0x20 0x06 0x6215
0x20 0x07 0x0200
0x20 0x09 0x0021
0x20 0x0C 0x802B
0x20 0x10 0x8A20 // On in all Windows dumps
                 // 0x22 changes, from 0x19 0x1a 0x1b 0x12* to
                 // 0x19* 0x1a 0x1b 0x12
0x20 0x35 0x096A
0x20 0x36 0x5757
0x20 0x3B 0x60D9
0x20 0x43 0x3D90
0x20 0x49 0x0249
0x20 0x62 0xA007
0x20 0x6E 0x0C25

The problematic verb which toggles output from HP to internal:
0x20 0x10 0x8a20

These seem to disable Headset mic?
0x0F  0x7778
0x45  0xC089

The following changes depending on action
NID 0x20
No Headphones        | Headphones         | Jack-detect off, no headphones
Index 0x0F  0x7770   | Index 0x0F  0x7778 |  Index 0x0F  0x7774
Index 0x45  0x4089   | Index 0x45  0xC089 |  Index 0x45  0xD089
Index 0x46  0x0004   | Index 0x46  0x02F4 |  Index 0x46  0x0224 ?
Index 0x6B  0x4278   | Index 0x6B  0x0278 | ?

NID 0x58
Index 0x03  0x80A0   | Index 0x03  0x0DA3 
Index 0x01  0x0000   | Index 0x01  0x2000
Index 0x15  0x0000   | Index 0x15  0x0802
Index 0x16  0x0000   | Index 0x16  0xFB71 | Index 0x16  0xFB63 ??
Index 0x17  0x0000   | Index 0x17  0xFC34 | Index 0x17  0xFC26 ??
Index 0x18  0x0000   | Index 0x18  0x1F1F
Index 0x19  0x0000   | Index 0x19  0x0011 | Index 0x19  0x0013 ??
Index 0x1A  0x0000   | Index 0x1A  0xFEA6 | Index 0x1A  0xFEA9 ??
Index 0x1B  0x0000   | Index 0x1B  0x4000


So what works?

Setting the PINCFG as follows
0x19 0x01211050
0x1a 0x01a11030
0x21 0x03211020 // Needs 0x15 for actual output

Unmute 0x15, this is the amp for headphones
---
hda-verb /dev/snd/hwC0D0 0x15 SET_PIN_WIDGET_CONTROL 0xc0
hda-verb /dev/snd/hwC0D0 0x15 SET_AMP 0xb000

switches to headphone
---
hda-verb /dev/snd/hwC0D0 0x20 0x500 0x10
hda-verb /dev/snd/hwC0D0 0x20 0x400 0x8a20

switches to internal
---
hda-verb /dev/snd/hwC0D0 0x20 0x500 0x10
hda-verb /dev/snd/hwC0D0 0x20 0x400 0x0a20

Which can be translated to the firmware patch:
/lib/firmware/alc294-sound-patch.fw

[codec]
0x10ec0294 0x10431881 0
[pincfg]
0x19 0x03a11050
0x1a 0x01a11830
0x21 0x03211020
[verb]
0x15 0x707 0xc0
0x15 0x300 0xb000

Which can be loaded via:
/etc/modprobe.d/alsa-base.conf
options snd-hda-intel patch=alc294-sound-patch.fw


I'm working on a patch to try add the above with a jack-sense toggle for the 0x20 0x10 0x8a20 verb.

I've not gotten the rear-left mic jack to have input as yet. Jack sense does work on it.

I will post the dumps I have later.
Comment 28 Luke Jones 2020-09-05 11:49:43 UTC
Created attachment 292351 [details]
Test patch to enable headset, and toggle outputs on jacksense
Comment 29 iancmx 2020-09-05 20:33:36 UTC
@Luke Jones Just compiled the kernel to tested audio and headphones now work PERFECTLY. headset mic works too! However, the other mic jack doesnt seem to have input. it detects that the mic is connected tho. Thanks so much for your work on fixing this.
Comment 30 Luke Jones 2020-09-06 00:33:23 UTC
@ iancmx@hotmail.com, I found a small thing I missed to enable the digital in thingy on NID 0x0a, but I can't really test as I don't have an AUX type mic. The mic in your headset has a different pinout to what that jack expects.
Comment 31 Luke Jones 2020-09-06 00:36:03 UTC
Created attachment 292365 [details]
Test patch to enable headset, and toggle outputs on jacksense

Updated patch to enable the digital converter on 0x0a
Comment 32 Luke Jones 2020-09-06 03:58:47 UTC
I purchased a to do checks with. But, it seems either the jack or hardware isn't right, or the mic is faulty. I tested the rear mic jack in both Windows and using what I *thought* would work in Linux - no input.

If anyone can confirm in Windows that their hardware works, then test in Linux it would be much appreciated. Otherwise I will submit the patch as is since you can using a headset splitter with the front jack.
Comment 33 Luke Jones 2020-09-06 08:33:33 UTC
Created attachment 292369 [details]
Final patch to enable headset on GX502/SubSystem 0x10431881

This is the final patch I have submitted to the lkml and alsa lists for review. If the rear mic jack is found to work then great, but if not then we can submit a follow-up patch. The existing patch can at least get us on the road to getting the fixes in-kernel.
Comment 34 jamesfromnz+kernel 2020-09-06 10:26:57 UTC
can you point me in the right direction for how to apply this patch. I've been googling "compiled the kernel" as iancmx@hotmail.com has done. lots of reading so far but if you can spare a moment to point me in right direction.
Comment 35 lestairon 2020-09-07 17:57:48 UTC
(In reply to Luke Jones from comment #33)
> Created attachment 292369 [details]
> Final patch to enable headset on GX502/SubSystem 0x10431881
> 
> This is the final patch I have submitted to the lkml and alsa lists for
> review. If the rear mic jack is found to work then great, but if not then we
> can submit a follow-up patch. The existing patch can at least get us on the
> road to getting the fixes in-kernel.

Thank you very much! It works like a charm

And for everyone that want's to apply the patch. I don't know if it's the best way to do it but what i did is.

- Download the manjaro kernel from https://gitlab.manjaro.org/packages/core (I tried with 5.9)
- I created a new file with .patch extension then pasted Luke's attachment.
- Edited the PKGBUILD file and added the file previously created to the sources list.
- Executed the command updpkgsums to update the checksum and have no problems later.
- Executed the command makepkg -s. This command compiles the kernel, so it takes a lot of time to finish. Depends on your cpu, it can take hours.
- When finished, then run sudo pacman -U linux-compiled-kernel.pkg.tar.xz linux-compiled-kernel-headers.pkg.tar.xz

You have to replace linux-compiled-kernel with the one you have inside your folder, mine was linux59-5.9rc4.d0830.gf4d51df-1-x86_64.pkg.tar.xz and linux59-headers-5.9rc4.d0830.gf4d51df-1-x86_64.pkg.tar.xz

Keep in mind that you need to install the headers. Once It's done installing, reboot and you should be using the new kernels
Comment 36 Luke Jones 2020-09-07 20:18:51 UTC
@lestarion can you please run:

cat /proc/asound/card0/codec#0 |grep 'Subsystem Id'
and
cat /sys/class/dmi/id/product_name

I'm collecting information from various sources.
Comment 37 lestairon 2020-09-07 23:49:51 UTC
(In reply to Luke Jones from comment #36)
> @lestarion can you please run:
> 
> cat /proc/asound/card0/codec#0 |grep 'Subsystem Id'
> and
> cat /sys/class/dmi/id/product_name
> 
> I'm collecting information from various sources.

❯ cat /proc/asound/card0/codec#0 |grep 'Subsystem Id'
Subsystem Id: 0x10431881

❯ cat /sys/class/dmi/id/product_name
Zephyrus M GU502GW_GU502GW
Comment 38 Luke Jones 2020-09-08 23:50:50 UTC
Thanks @lestarion

There is another similar model which has some strangeness in the naming, but works well:

Subsystem Id: 0x104318d1
Zephyrus G GU502DU_GA502DU

I was curious to know if you had this model, which for all intents and purposes is actually a GA502DU.

Given the similarity with your model to mine, you may be interested in this patch also - https://www.spinics.net/lists/linux-input/msg68977.html
Comment 39 Luke Jones 2020-09-09 00:03:29 UTC
In case others land here in search of information on sound for a GU502, if your model is a GU502LV, I have various dumps for it and am working with a person who has the model to solve it. Any progress I make will be posted here.

This one is:
Subsystem Id: 0x10431E51
Unsure of exact product ID, likely to be GU502LV_GU502LV

You could possibly edit the patch to change the line:
SND_PCI_QUIRK(0x1043, 0x1881, "ASUS Zephyrus S/M", ALC294_FIXUP_ASUS_GX502_PINS),

to

SND_PCI_QUIRK(0x1043, 0x1E51, "ASUS Zephyrus S/M", ALC294_FIXUP_ASUS_GX502_PINS),

and test then post feedback here.
Comment 40 Luke Jones 2020-09-17 03:11:32 UTC
Also in the case of people landing here, I have put every drop of data I've gotten from a series of ASUS gaming laptops in this repo - https://gitlab.com/asus-linux/reverse-engineering

This includes such things as the DSDT, wireshark caps from windows, a keyboard LED mapping, and sound info dumps from Windows (and Linux, plus anything found).

Please feel free to contribute.
Comment 41 Luke Jones 2020-10-14 20:27:26 UTC
The patch for Subsystem Id: 0x10431881 is now in mainstream.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c3cdf189276c2a63da62ee250615bd55e3fb680d

If someone can test the other GU502 then we may be able to do another patch and close this issue. You only need to add the quirk as follows

// GU502LV_GU502LV
SND_PCI_QUIRK(0x1043, 0x1E51, "ASUS Zephyrus S/M", ALC294_FIXUP_ASUS_GX502_PINS),

// Zephyrus G GU502DU_GA502DU
SND_PCI_QUIRK(0x1043, 0x18D1, "ASUS Zephyrus G", ALC294_FIXUP_ASUS_GX502_PINS),
Comment 42 Vasileios 2020-10-16 21:50:49 UTC
I have the same issue with the Asus W500G5T laptop as described here:

https://bugzilla.kernel.org/show_bug.cgi?id=209585
Comment 43 nick 2020-11-09 14:47:09 UTC
I have a GU502 varient and applied the change from comment 39 in Kubuntu 20.10:

$ cat /sys/class/dmi/id/product_name
ROG Zephyrus M15 GU502LU_GU502LU

$ grep Subsystem /proc/asound/card0/codec#0
Subsystem Id: 0x10431e51

$ grep 'Zephyrus S' sound/pci/hda/patch_realtek.c 
        SND_PCI_QUIRK(0x1043, 0x1E51, "ASUS Zephyrus S/M", ALC294_FIXUP_ASUS_GX502_PINS),

$ uname -r
5.8.14-custom

Detection now works, but audio out is still not working. Here are my observations after making this change:

Boot without headphones connected:
- speakers work
- internal mic works
- detection works when headphones plugged/unplugged
- no audio out from headphones, however at max volume I can hear some crackling and garbled sounds
- inline mic works through headphone jack (input is detected, but I didn't verify a recording)
- rear mic jack detected when cable plugged in but I don't currently have a mic to test input

Boot with headphones connected:
- no output devices, not even the speakers are present, only the mic shows up in kde sound settings, 
- the inline mic does work
- when the headphones are removed it switches to the internal mic, which works
- rear mic jack detection works
- logging out or rebooting without the headphones connected restores the output devices

I've tested both ports in Windows with no issue.
Comment 44 Noah Li 2020-12-06 17:22:33 UTC
I run Arch in a GU502LW and applied the changes in comment #41:
> You only need to add the quirk as follows
> 
> // GU502LV_GU502LV
> SND_PCI_QUIRK(0x1043, 0x1E51, "ASUS Zephyrus S/M",
> ALC294_FIXUP_ASUS_GX502_PINS),
> 
> // Zephyrus G GU502DU_GA502DU
> SND_PCI_QUIRK(0x1043, 0x18D1, "ASUS Zephyrus G",
> ALC294_FIXUP_ASUS_GX502_PINS),
------------------------------------------------------------

System info:

$ cat /sys/class/dmi/id/product_name
ROG Zephyrus M15 GU502LW_GU502LW

$ grep Subsystem /proc/asound/card0/codec#0
Subsystem Id: 0x10431e51

$ uname -r
5.9.12-arch1-1
------------------------------------------------------------

I don't have a headset that comes with a mic, so I only tested the sound output.

The behavior is largely the same as described in comment #43. Speakers work. Headphones can be detected but there is no output; instead there is faint crackling noise.  The only difference is that, if I boot with a headphone connected, the output device is still correctly displayed, and if I disconnect the headphone the speakers can work properly.

Also I've tested both with and without a headphone splitter, and results remain the same.
Comment 45 bigkrp 2021-01-04 11:30:53 UTC
Same problem with Headphones. Are not displayed and do not work.

$ cat /sys/class/dmi/id/product_name
ROG Zephyrus M15 GU502LV_GU502LV

$ grep Subsystem /proc/asound/card0/codec#0
Subsystem Id: 0x10431e51

$ uname -r
5.9.16-200.fc33.x86_64
Comment 46 Valentin Berlier 2021-01-11 01:03:28 UTC
I'm facing exactly the same problems with my Zephyrus M15. The headphones are not being detected when plugged into the audio mic combo jack.

    ➜ cat /sys/class/dmi/id/product_name
    ROG Zephyrus M15 GU502LW_GU532LW

    ➜ grep Subsystem "/proc/asound/card0/codec#0"
    Subsystem Id: 0x10431e51

    ➜ uname -r
    5.9.16-200.fc33.x86_64
Comment 47 Luke Jones 2021-01-11 03:15:19 UTC
It's very difficult to debug these issues without access to the hardware, so I've attempted to distill everything I've learned so far in to a blog post on our website - https://asus-linux.org/blog/sound-2021-01-11/

It will hopefully get folks started. Then once a firmware patch is found that works it should be relatively simple to make a kernel patch.
Comment 48 Takashi Iwai 2021-01-11 08:47:09 UTC
The blog is really a nice read, thanks.  It's the things I would have done, too :)

Do I understand correctly that the speaker and the headphone outputs are mutual exclusive on your machine (with COEF 0x10 bit 31)?
Comment 49 Takashi Iwai 2021-01-11 09:12:49 UTC
Forget my last comment, now I remember that it's the hardware design indeed.

For further debugging of M15, the outputs of alsa-info.sh at both boots with and without the headphone plugged are needed to compare.  Also, the test with and without the headphone plugged; so there are 4 cases to test.

My wild guess is that BIOS doesn't set up the pin configs right when booting with the headphone plugged by some reason.  Let's see.
Comment 50 bigkrp 2021-03-01 09:43:19 UTC
Any updates? I still have problem with audio jack on latest fedora
Comment 51 kakorha 2021-04-10 22:56:56 UTC
Had the same issue after dual-booting Manjaro.

  $ cat /sys/class/dmi/id/product_name
    ROG Zephyrus M15 GU502LW_GU502LW

  $ grep Subsystem /proc/asound/card0/codec\#0
    Subsystem Id: 0x10431e51

  $ uname -r
    5.10.26-1-MANJARO

For those on this subsystem id, can you give the following firmware patch a try (derived from the steps in Luke's blog post with some extra elbow grease!):

[codec]
0x10ec0294 0x10431e51 0

[pincfg]
0x19 0x01a11050
0x1a 0x01a11830
0x21 0x012110f0

[verb]
0x15 0x707 0xc0
0x15 0x300 0xb000
0x1b 0x707 0x24


Notably the main difference that was elusive to find out was needing to adjust the VREF for pin 0x1b to get the headphone audio to start working.

Jack sensing seems to work out of the box when I plug and unplug both TRS and TRRS plugs. TRS keeps the internal microphone selected, while TRRS switches to the headset microphone. The dedicated microphone jack is still a no-go, but I use a usb microphone, and the headset microphone seems to work, so its not worth it for me to investigate it more.
Comment 52 Sounak 2021-07-03 19:33:11 UTC
(In reply to Luke Jones from comment #33)
> Created attachment 292369 [details]
> Final patch to enable headset on GX502/SubSystem 0x10431881
> 
> This is the final patch I have submitted to the lkml and alsa lists for
> review. If the rear mic jack is found to work then great, but if not then we
> can submit a follow-up patch. The existing patch can at least get us on the
> road to getting the fixes in-kernel.

Does this work for GU502 too?
Comment 53 Luke Jones 2021-07-04 21:30:16 UTC
(In reply to Sounak from comment #52)
> (In reply to Luke Jones from comment #33)
> > Created attachment 292369 [details]
> > Final patch to enable headset on GX502/SubSystem 0x10431881
> > 
> > This is the final patch I have submitted to the lkml and alsa lists for
> > review. If the rear mic jack is found to work then great, but if not then
> we
> > can submit a follow-up patch. The existing patch can at least get us on the
> > road to getting the fixes in-kernel.
> 
> Does this work for GU502 too?

There was a patch added and merged for 5.13+ kernel - https://github.com/torvalds/linux/commit/c1b55029493879f5bd585ff79f326e71f0bc05e3
Comment 54 Luke Jones 2021-07-04 21:30:56 UTC
I think this issue can be marked as solved.