thesofproject / linux

Linux kernel source tree
Other
89 stars 129 forks source link

[BUG] Huawei Matebook 14s headphone / speaker problem (CX8070 codec) #3350

Open cihatertem opened 2 years ago

cihatertem commented 2 years ago

I tried different distros Ubuntu 21.10/Fedora and now Arch linux. I have an issue with speaker, headphone settings. First of all the laptop has 4 speakers and 4 dijital mics. Well these are problems: 1) Gnome volume slider does not effect on volume. Each clicks give same beep until below %5 and volume goes down. 2) If I plug a headphone, no sound at headphone and sound still comes from speakers. And after unplugged the headphone, speakers go mutted! 3) To unmut the speakers I have to go alsamixer and select sound card 'sof-hda-dsp' (codec Chip: Conexant CX8070 ) and then I have to unmut headphone 4) I can set speaker's volume from alsamixer's headphone slider. Speaker slider has no effect, Master slider only effect depends on headphone slider point.

Environment 1) Branch name and commit hash of the 2 repositories: sof (firmware/topology) and linux (kernel driver).

I tried several model=NAME options but there is no result. Here they are, installed alsa packages with sof-bin: alsa-card-profiles, alsa-firmware, alsa-lib, alsa-plugins, alsa-topology-conf, alsa-ucm-conf, alsa-utils, pulseaudio-alsa, zita-alsa-pcmi, sof-firmware, sof-tools

If you need more log, outputs, please lead me :)

aplay -l 
**** List of PLAYBACK Hardware Devices ****
card 0: sofhdadsp [sof-hda-dsp], device 0: HDA Analog (*) []
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: sofhdadsp [sof-hda-dsp], device 1: HDA Digital (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: sofhdadsp [sof-hda-dsp], device 3: HDMI1 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: sofhdadsp [sof-hda-dsp], device 4: HDMI2 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: sofhdadsp [sof-hda-dsp], device 5: HDMI3 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
pacmd list-sinks
4 sink(s) available.
    index: 0
    name: <alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_5__sink>
    driver: <module-alsa-card.c>
    flags: HARDWARE DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
    state: SUSPENDED
    suspend cause: IDLE
    priority: 9037
    volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
            balance 0.00
    base volume: 65536 / 100% / 0.00 dB
    volume steps: 65537
    muted: no
    current latency: 0.00 ms
    max request: 0 KiB
    max rewind: 0 KiB
    monitor source: 0
    sample spec: s24-32le 2ch 48000Hz
    channel map: front-left,front-right
                 Stereo
    used by: 0
    linked by: 0
    configured latency: 0.00 ms; range is 0.50 .. 170.67 ms
    card: 0 <alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic>
    module: 6
    properties:
        alsa.resolution_bits = "32"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = ""
        alsa.id = "HDMI3 (*)"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "5"
        alsa.card = "0"
        alsa.card_name = "sof-hda-dsp"
        alsa.long_card_name = "HUAWEI-HKD_WXX-M1010-HKD_WXX_PCB"
        alsa.driver_name = "snd_soc_skl_hda_dsp"
        device.bus_path = "pci-0000:00:1f.3-platform-skl_hda_dsp_generic"
        sysfs.path = "/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0"
        device.bus = "pci"
        device.vendor.id = "8086"
        device.vendor.name = "Intel Corporation"
        device.product.id = "a0c8"
        device.product.name = "Tiger Lake-LP Smart Sound Technology Audio Controller"
        device.string = "_ucm0001.hw:sofhdadsp,5"
        device.buffering.buffer_size = "65536"
        device.buffering.fragment_size = "16384"
        device.access_mode = "mmap+timer"
        device.profile.name = "HiFi: hw:sofhdadsp,5: sink"
        device.profile.description = "HDMI / DisplayPort 3 Output"
        alsa.mixer_device = "_ucm0001.hw:sofhdadsp"
        device.description = "Tiger Lake-LP Smart Sound Technology Audio Controller HDMI / DisplayPort 3 Output"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    ports:
        [Out] HDMI3: HDMI / DisplayPort 3 Output (priority 700, latency offset 0 usec, available: no)
            properties:

    active port: <[Out] HDMI3>
    index: 1
    name: <alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_4__sink>
    driver: <module-alsa-card.c>
    flags: HARDWARE DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
    state: SUSPENDED
    suspend cause: IDLE
    priority: 9036
    volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
            balance 0.00
    base volume: 65536 / 100% / 0.00 dB
    volume steps: 65537
    muted: no
    current latency: 0.00 ms
    max request: 0 KiB
    max rewind: 0 KiB
    monitor source: 1
    sample spec: s24-32le 2ch 48000Hz
    channel map: front-left,front-right
                 Stereo
    used by: 0
    linked by: 0
    configured latency: 0.00 ms; range is 0.50 .. 170.67 ms
    card: 0 <alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic>
    module: 6
    properties:
        alsa.resolution_bits = "32"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = ""
        alsa.id = "HDMI2 (*)"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "4"
        alsa.card = "0"
        alsa.card_name = "sof-hda-dsp"
        alsa.long_card_name = "HUAWEI-HKD_WXX-M1010-HKD_WXX_PCB"
        alsa.driver_name = "snd_soc_skl_hda_dsp"
        device.bus_path = "pci-0000:00:1f.3-platform-skl_hda_dsp_generic"
        sysfs.path = "/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0"
        device.bus = "pci"
        device.vendor.id = "8086"
        device.vendor.name = "Intel Corporation"
        device.product.id = "a0c8"
        device.product.name = "Tiger Lake-LP Smart Sound Technology Audio Controller"
        device.string = "_ucm0001.hw:sofhdadsp,4"
        device.buffering.buffer_size = "65536"
        device.buffering.fragment_size = "16384"
        device.access_mode = "mmap+timer"
        device.profile.name = "HiFi: hw:sofhdadsp,4: sink"
        device.profile.description = "HDMI / DisplayPort 2 Output"
        alsa.mixer_device = "_ucm0001.hw:sofhdadsp"
        device.description = "Tiger Lake-LP Smart Sound Technology Audio Controller HDMI / DisplayPort 2 Output"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    ports:
        [Out] HDMI2: HDMI / DisplayPort 2 Output (priority 600, latency offset 0 usec, available: no)
            properties:

    active port: <[Out] HDMI2>
    index: 2
    name: <alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_3__sink>
    driver: <module-alsa-card.c>
    flags: HARDWARE DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
    state: SUSPENDED
    suspend cause: IDLE
    priority: 9035
    volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
            balance 0.00
    base volume: 65536 / 100% / 0.00 dB
    volume steps: 65537
    muted: no
    current latency: 0.00 ms
    max request: 0 KiB
    max rewind: 0 KiB
    monitor source: 2
    sample spec: s24-32le 2ch 48000Hz
    channel map: front-left,front-right
                 Stereo
    used by: 0
    linked by: 0
    configured latency: 0.00 ms; range is 0.50 .. 170.67 ms
    card: 0 <alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic>
    module: 6
    properties:
        alsa.resolution_bits = "32"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = ""
        alsa.id = "HDMI1 (*)"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "3"
        alsa.card = "0"
        alsa.card_name = "sof-hda-dsp"
        alsa.long_card_name = "HUAWEI-HKD_WXX-M1010-HKD_WXX_PCB"
        alsa.driver_name = "snd_soc_skl_hda_dsp"
        device.bus_path = "pci-0000:00:1f.3-platform-skl_hda_dsp_generic"
        sysfs.path = "/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0"
        device.bus = "pci"
        device.vendor.id = "8086"
        device.vendor.name = "Intel Corporation"
        device.product.id = "a0c8"
        device.product.name = "Tiger Lake-LP Smart Sound Technology Audio Controller"
        device.string = "_ucm0001.hw:sofhdadsp,3"
        device.buffering.buffer_size = "65536"
        device.buffering.fragment_size = "16384"
        device.access_mode = "mmap+timer"
        device.profile.name = "HiFi: hw:sofhdadsp,3: sink"
        device.profile.description = "HDMI / DisplayPort 1 Output"
        alsa.mixer_device = "_ucm0001.hw:sofhdadsp"
        device.description = "Tiger Lake-LP Smart Sound Technology Audio Controller HDMI / DisplayPort 1 Output"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    ports:
        [Out] HDMI1: HDMI / DisplayPort 1 Output (priority 500, latency offset 0 usec, available: no)
            properties:

    active port: <[Out] HDMI1>
  * index: 3
    name: <alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink>
    driver: <module-alsa-card.c>
    flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
    state: IDLE
    suspend cause: (none)
    priority: 9032
    volume: front-left: 31032 /  47% / -19.48 dB,   front-right: 31032 /  47% / -19.48 dB
            balance 0.00
    base volume: 65536 / 100% / 0.00 dB
    volume steps: 65537
    muted: no
    current latency: 40.32 ms
    max request: 15 KiB
    max rewind: 15 KiB
    monitor source: 3
    sample spec: s24-32le 2ch 48000Hz
    channel map: front-left,front-right
                 Stereo
    used by: 0
    linked by: 2
    configured latency: 40.00 ms; range is 0.50 .. 170.67 ms
    card: 0 <alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic>
    module: 6
    properties:
        alsa.resolution_bits = "32"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = ""
        alsa.id = "HDA Analog (*)"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "0"
        alsa.card = "0"
        alsa.card_name = "sof-hda-dsp"
        alsa.long_card_name = "HUAWEI-HKD_WXX-M1010-HKD_WXX_PCB"
        alsa.driver_name = "snd_soc_skl_hda_dsp"
        device.bus_path = "pci-0000:00:1f.3-platform-skl_hda_dsp_generic"
        sysfs.path = "/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0"
        device.bus = "pci"
        device.vendor.id = "8086"
        device.vendor.name = "Intel Corporation"
        device.product.id = "a0c8"
        device.product.name = "Tiger Lake-LP Smart Sound Technology Audio Controller"
        device.string = "_ucm0001.hw:sofhdadsp"
        device.buffering.buffer_size = "65536"
        device.buffering.fragment_size = "16384"
        device.access_mode = "mmap+timer"
        device.profile.name = "HiFi: hw:sofhdadsp: sink"
        device.profile.description = "Speaker + Headphones"
        alsa.mixer_device = "_ucm0001.hw:sofhdadsp"
        device.description = "Tiger Lake-LP Smart Sound Technology Audio Controller Speaker + Headphones"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    ports:
        [Out] Speaker: Speaker (priority 100, latency offset 0 usec, available: unknown)
            properties:

        [Out] Headphones: Headphones (priority 200, latency offset 0 usec, available: no)
            properties:

    active port: <[Out] Speaker>
sudo lshw -c multimedia
  *-usb:1                   
       description: Video
       product: USB Camera
       vendor: 3730304231385631354A4A
       physical id: 6
       bus info: usb@3:6
       version: 0.0e
       serial: 200901010001
       capabilities: usb-2.01
       configuration: driver=uvcvideo maxpower=500mA speed=480Mbit/s
  *-multimedia
       description: Multimedia audio controller
       product: Tiger Lake-LP Smart Sound Technology Audio Controller
       vendor: Intel Corporation
       physical id: 1f.3
       bus info: pci@0000:00:1f.3
       version: 20
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi bus_master cap_list
       configuration: driver=sof-audio-pci-intel-tgl latency=32
       resources: iomemory:600-5ff iomemory:600-5ff irq:168 memory:601d170000-601d173fff memory:601d000000-601d0fffff
arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: sofhdadsp [sof-hda-dsp], device 0: HDA Analog (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: sofhdadsp [sof-hda-dsp], device 1: HDA Digital (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: sofhdadsp [sof-hda-dsp], device 6: DMIC (*) []
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: sofhdadsp [sof-hda-dsp], device 7: DMIC16kHz (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
amixer 
Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 65536
  Mono:
  Front Left: Playback 31032 [47%] [on]
  Front Right: Playback 31032 [47%] [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch cswitch-joined
  Capture channels: Front Left - Front Right - Rear Left - Rear Right
  Limits: Capture 0 - 65536
  Front Left: Capture 65536 [100%] [off]
  Front Right: Capture 65536 [100%] [off]
  Rear Left: Capture 65536 [100%] [off]
  Rear Right: Capture 65536 [100%] [off]
UrsulPolar commented 1 year ago

Hello! Though I'm not a programmer, or an expert in anything that has to do with codecs or C coding, I've written the following, having as a starting point a code written by someone else, and adjusted to have the system change the output to the headphones / speakers on jack connect for our lovely MateBooks... I also need to mention @anticodeninja and @DmitriiMukhin for the hints with regards to the proper verbs to be used. I stuck with SET_EAPD_BTLENABLE (0x70c) and SET_CONNECT_SEL (0x701) for the HP/SPKR nodes.

I refactored the code quite a bit and seems to be an usable solution. It properly resumes from suspend


/*
* File: huawei_matebook14s_codec_fix.cpp
* Author: ursul_polar
*
* Created on Apr 09, 2023, 9:19 PM
*/
#include <iostream>
#include <fcntl.h>
#include <unistd.h>
#include <syslog.h>
#include <sys/ioctl.h>
#include <memory>
#include <signal.h>

// Class to handle file descriptor class FileDescriptor { public: explicit FileDescriptor(const char* path, int flags) { fd = open(path, flags); if (fd < 0) { syslog(LOG_ERR, "Failed to open file %s", path); throw std::runtime_error("Failed to open file"); } }

    ~FileDescriptor() {
        close(fd_);
    }

    operator int() const {
        return fd_;
    }

private:
    int fd_;

};

typedef uint32_t u32;

// Headphones connection enum enum HDAConnectionState { HEADPHONES_CONNECTED = 8, HEADPHONES_DISCONNECTED = 0 };

define HDA_VERB(nid, verb, param) ((nid) << 24 | (verb) << 8 | (param))

define HDA_IOCTL_VERB_WRITE _IOWR('H', 0x11, struct hda_verb_ioctl)

define SPEAKER_VERBS_COUNT 3

const u32 speaker_verbs[SPEAKER_VERBS_COUNT] = { HDA_VERB(0x16, 0x701, 0x0001), HDA_VERB(0x17, 0x70C, 0x0002), HDA_VERB(0x1, 0x715, 0x2) };

define HEADPHONES_VERBS_COUNT 5

const u32 headphones_verbs[HEADPHONES_VERBS_COUNT] = { HDA_VERB(0x16, 0x701, 0x0000), HDA_VERB(0x17, 0x70C, 0x0000), HDA_VERB(0x1, 0x717, 0x2), HDA_VERB(0x1, 0x716, 0x2), HDA_VERB(0x1, 0x715, 0x0) };

// Define HDA verb ioctl struct struct hda_verb_ioctl { u32 verb; u32 res; };

// Define path to HDA device file

define HW_PATH_FD "/dev/snd/hwC0D0"

// Open HDA device file and return file descriptor wrapped in a unique_ptr std::unique_ptr open_hda_device_file() { try { auto fd = std::make_unique(HW_PATH_FD, O_RDWR | O_NOCTTY); return fd; } catch (const std::runtime_error& e) { syslog(LOG_ERR, "Failed to open HDA device file."); exit(EXIT_FAILURE); } }

// Get the connection state of the headphones int get_headphones_connection_state() { auto fd = open_hda_device_file(); hda_verb_ioctl state_check = { .verb = HDA_VERB(0x16, 0x0f09, 0x0) }; if (ioctl(*fd, HDA_IOCTL_VERB_WRITE, &state_check) < 0) { syslog(LOG_ERR, "Failed to send verb ioctl to HDA device file."); exit(EXIT_FAILURE); } return (state_check.res >> 31) & 1; }

// Set the connection state of the speakers void set_speaker_connection_state(bool connected) { auto fd = open_hda_device_file(); const u32 verbs = connected ? speaker_verbs : headphones_verbs; const int verb_count = connected ? SPEAKER_VERBS_COUNT : HEADPHONES_VERBS_COUNT; for (int i = 0; i < verb_count; i++) { hda_verb_ioctl verb = { .verb = verbs[i] }; if (ioctl(fd, HDA_IOCTL_VERB_WRITE, &verb) < 0) { syslog(LOG_ERR, "Failed to send verb ioctl to HDA device file."); exit(EXIT_FAILURE); } syslog(LOG_INFO, "Written data to hda verb 0x%.8x", verb); } }

bool should_exit = false;

void signal_handler(int signum) { if (signum == SIGCONT) { syslog(LOG_INFO, "Received SIGCONT signal, exiting loop"); should_exit = true; } }

int main() { // Register signal handler for SIGCONT struct sigaction sig_action; sig_action.sa_handler = &signal_handler; sigemptyset(&sig_action.sa_mask); sig_action.sa_flags = 0; if (sigaction(SIGCONT, &sig_action, nullptr) < 0) { syslog(LOG_ERR, "Failed to register signal handler for SIGCONT"); exit(EXIT_FAILURE); }else{ syslog(LOG_INFO, "Successfully registered signal handler"); }

// Set initial connection state
int state = 8;

while(!should_exit){
    int current_state = get_headphones_connection_state();

    if(state != current_state){
        // Set speakers to connected or disconnected based on current state of headphones
        set_speaker_connection_state(current_state == HEADPHONES_DISCONNECTED);
        state = current_state;
    }

    sleep(1);
}

return 0;

}


I've compiled the code with `gcc` while having ` gcc-c++` installed. The executable was moved in `/usr/local/bin`.
```text
$ gcc  huawei_matebook14s_codec_fix.cpp -lstdc++ -o huawei-codec-fix
# mv huawei-codec-fix /usr/local/bin/

To have it used by a service a file was created in /etc/systemd/system/huawei-codec-fix.service.

# cat  << EOF > /etc/systemd/system/huawei-codec-fix.service
[Unit]
Description=huawei-codec-fix
Before=sleep.target
StopWhenUnneeded=yes

[Service]
Type=idle
ExecStart=/usr/local/bin/huawei-sound-fix
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target suspend.target hibernate.target hybrid-sleep.target sleep.target
EOF

On Fedora 37, in order to have the service file detected by systemd and the permission for systemd to run the executable that we just created we need to make use of restorecon.

# /usr/sbin/restorecon -rv /etc/systemd/system/huawei-codec-fix.service
# /usr/sbin/restorecon -rv /usr/local/bin/huawei-codec-fix

After this we can proceed with loading, enabling and starting the service.

# systemctl daemon-reload
# systemctl enable huawei-codec-fix.service
# systemctl start huawei-codec-fix.service

It writes to logs if it's unable to get control of the device or if a change occurs. You can see the state of the service with:

# systemctl status huawei-codec-fix.service

or the insignificant logs with:

# journalctl -xeu huawei-codec-fix

It's obvious that you can choose another name for the file/service.

I know it's not a proper fix, but hope it helps.

Jan 22 09:34:32 MateBook14s systemd[1]: Started huawei-codec-fix.service - huawei-codec-fix.
░░ Subject: A start job for unit huawei-codec-fix.service has finished successfully
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit huawei-codec-fix.service has finished successfully.
░░
░░ The job identifier is 12631.
Jan 22 09:34:32 MateBook14s huawei-codec-fix[40371]: Daemon started.
Jan 22 09:34:33 MateBook14s huawei-codec-fix[40371]: Enabled headphone output
Jan 22 09:41:46 MateBook14s huawei-codec-fix[40371]: Enabled speaker output
Jan 22 09:43:46 MateBook14s huawei-codec-fix[40371]: Enabled headphone output
Jan 22 09:44:06 MateBook14s huawei-codec-fix[40371]: Enabled speaker output
Jan 22 09:44:20 MateBook14s huawei-codec-fix[40371]: Enabled headphone output
Jan 22 10:06:26 MateBook14s systemd[1]: Stopping huawei-codec-fix.service - huawei-codec-fix...
░░ Subject: A stop job for unit huawei-codec-fix.service has begun execution
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A stop job for unit huawei-codec-fix.service has begun execution.
░░
░░ The job identifier is 12877.
Jan 22 10:06:26 MateBook14s systemd[1]: huawei-codec-fix.service: Deactivated successfully.
░░ Subject: Unit succeeded
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ The unit huawei-codec-fix.service has successfully entered the 'dead' state.
Jan 22 10:06:26 MateBook14s huawei-codec-fix[40371]: Daemon stopped.
Jan 22 10:06:26 MateBook14s systemd[1]: Stopped huawei-codec-fix.service - huawei-codec-fix.
░░ Subject: A stop job for unit huawei-codec-fix.service has finished
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A stop job for unit huawei-codec-fix.service has finished.
░░
░░ The job identifier is 12877 and the job result is done.

Evidently, if anyone notices something that is not proper in the code or has the option to improve it, feel free to do so.

spacer2010 commented 1 year ago

That works for me, first time I get sound after 1 year

Thank you very much ❤️

Wolfgang Endres

On Sat, 21 Jan 2023, 17:56 doom-fr, @.***> wrote:

a workaround ... -> https://askubuntu.com/questions/1451232/no-sound-on-huawei-14s-with-ubuntu-22-10/1451233#1451233

— Reply to this email directly, view it on GitHub https://github.com/thesofproject/linux/issues/3350#issuecomment-1399288147, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHICGODYD7TQ7RTRU43WLXTWTQIK7ANCNFSM5KTOKH7Q . You are receiving this because you were mentioned.Message ID: @.***>

xalexalex commented 1 year ago

I tested the recently proposed solutions:

@doom-fr as far as I can tell that module option should be deprecated in favor of options snd-intel-dspcfg dsp_driver=1

And at least on my machine, all the possible values for that option (0,1,2,3) fix something but break something else. Namely, with dsp_driver=0 (auto) and with dsp_driver=3 (SOF), I get working digital mics but then what does not work is simultaneous audio (dmix). This means that if I have a running mpv process, all concurrent attempts to run some audio result in a JACK error and no further audio is played (e.g. notifications). This can be fixed by using pulseaudio, but then somehow my battery consumption spikes up by 2-3x (!)

With dsp_driver=1 I get working simultaneous audio (dmix) but then the digital microphones are not recognized and don't work.

With dsp_driver=2 (SST) both things do not work.

doom-fr commented 1 year ago

@UrsulPolar : "internal mics are unaffected" means they work or not ??

UrsulPolar commented 1 year ago

@UrsulPolar : "internal mics are unaffected" means they work or not ??

@doom-fr They work. As a note, I have no modporbe module option set.

~~LE: I've made some changes. After suspend it seems the pins get reseted and audio output was crackling. I added the rest of the verbs commands in the code to be invoked when the switch is made. Even so, after suspend you either need to insert a jack to trigger the switch or to restart the service. I have no clue where to go with this from here.~~

maniadevice commented 1 year ago

@UrsulPolar thank you for your efforts. Maybe someone in this thread has a better idea about next steps to include the fix after improving it? Maybe @plbossart or @lgirdwood. Apologies if I've tagged y'all incorrectly.

RobertPietraru commented 1 year ago

Guys, so if you are just trying to get your speakers to work, as I was, here's a simple solution: image

I just cut a headphone jack and plugged in the end. Not an ideal solution, but if you don't want to wear headphones, it's good enough. Plus it's portable :)

UrsulPolar commented 1 year ago

If anyone wants to pitch in https://consumer.huawei.com/en/community/details/Huawei-HKD-WXX-14s-no-sound-and-fingerprint-in-any-Linux-OS/topicId_186462/postId_966341/

florian-sabonchi commented 1 year ago

Hello i found a solution to solve

The solution is generally to add/edit a configuration file to your system.

sudo sh -c "echo 'options snd-hda-intel model=alc255-acer,dell-headset-multi' >> /etc/modprobe.d/sound.conf"

Reset alsa:

sudo alsactl restore

Sound should now work properly on your Matebook

The command appends the line "options snd-hda-intel model=alc255-acer,dell-headset-multi" to the end of the file. This specific configuration option sets the model of the Intel HDA (High Definition Audio) sound chip. It specifies that the model is "alc255-acer,dell-headset-multi,"

GeorgeKarles commented 1 year ago

@UrsulPolar I tried it right now and when i run alsactl restore i get the following message

alsa-lib main.c:1541:(snd_use_case_mgr_open) error: failed to import hw:0 use case configuration -2 alsa-lib main.c:1541:(snd_use_case_mgr_open) error: failed to import hw:0 use case configuration -2 Found hardware: "sof-essx8336" "Intel Kabylake HDMI" "HDA:8086280b,80860101,00100000 cfg-dmics:2" "" "" Hardware is initialized using a generic method alsactl: set_control:1475: Cannot write control '2:0:0:ALC Capture Target Volume:0' : Invalid argument

any idea what i can do?

cihatertem commented 1 year ago

Hello i found a solution to solve

The solution is generally to add/edit a configuration file to your system.

sudo sh -c "echo 'options snd-hda-intel model=alc255-acer,dell-headset-multi' >> /etc/modprobe.d/sound.conf"

Reset alsa:

sudo alsactl restore

Sound should now work properly on your Matebook

The command appends the line "options snd-hda-intel model=alc255-acer,dell-headset-multi" to the end of the file. This specific configuration option sets the model of the Intel HDA (High Definition Audio) sound chip. It specifies that the model is "alc255-acer,dell-headset-multi,"

Your solution didn't work on my Ubuntu 22.04(5.19 hwe kernel and pipewire 0.3.48) system.

florian-sabonchi commented 1 year ago

Hello i found a solution to solve The solution is generally to add/edit a configuration file to your system. sudo sh -c "echo 'options snd-hda-intel model=alc255-acer,dell-headset-multi' >> /etc/modprobe.d/sound.conf" Reset alsa: sudo alsactl restore Sound should now work properly on your Matebook The command appends the line "options snd-hda-intel model=alc255-acer,dell-headset-multi" to the end of the file. This specific configuration option sets the model of the Intel HDA (High Definition Audio) sound chip. It specifies that the model is "alc255-acer,dell-headset-multi,"

Your solution didn't work on my Ubuntu 22.04(5.19 hwe kernel and pipewire 0.3.48) system.

Do you received some error messages? Tested with alsa

cihatertem commented 1 year ago

Hello i found a solution to solve The solution is generally to add/edit a configuration file to your system. sudo sh -c "echo 'options snd-hda-intel model=alc255-acer,dell-headset-multi' >> /etc/modprobe.d/sound.conf" Reset alsa: sudo alsactl restore Sound should now work properly on your Matebook The command appends the line "options snd-hda-intel model=alc255-acer,dell-headset-multi" to the end of the file. This specific configuration option sets the model of the Intel HDA (High Definition Audio) sound chip. It specifies that the model is "alc255-acer,dell-headset-multi,"

Your solution didn't work on my Ubuntu 22.04(5.19 hwe kernel and pipewire 0.3.48) system.

Do you received some error messages? Tested with alsa

No error message, but I dont use pure alsa. I am on pipewire.

foofly commented 1 year ago

Hello i found a solution to solve The solution is generally to add/edit a configuration file to your system. sudo sh -c "echo 'options snd-hda-intel model=alc255-acer,dell-headset-multi' >> /etc/modprobe.d/sound.conf" Reset alsa: sudo alsactl restore Sound should now work properly on your Matebook The command appends the line "options snd-hda-intel model=alc255-acer,dell-headset-multi" to the end of the file. This specific configuration option sets the model of the Intel HDA (High Definition Audio) sound chip. It specifies that the model is "alc255-acer,dell-headset-multi,"

Your solution didn't work on my Ubuntu 22.04(5.19 hwe kernel and pipewire 0.3.48) system.

Do you received some error messages? Tested with alsa

No error message, but I dont use pure alsa. I am on pipewire.

Attempted on POP OS (22.04, kernal 6.2.6). Had no effect unfortunately.

phanky5 commented 1 year ago

alsactl init

I can get it to work by running alsactl init on Huawei Matebook 14s with Fedora 38.

To run alsactl init automatically on startup I created this file:

nano ~/.config/autostart/sound.desktop

Then put the following contents into the file and save:

[Desktop Entry] Type=Application Name=Alsa Exec=alsactl init Comment=Bring up sound

Afterward, just restart and it should work. I haven't tested what happens when you connect headphones via jack. I only have USB or Bluetooth headphones.

izheynes commented 1 year ago

alsactl init

I can get it to work by running alsactl init on Huawei Matebook 14s with Fedora 38.

To run alsactl init automatically on startup I created this file:

nano ~/.config/autostart/sound.desktop

Then put the following contents into the file and save:

[Desktop Entry] Type=Application Name=Alsa Exec=alsactl init Comment=Bring up sound

Afterward, just restart and it should work. I haven't tested what happens when you connect headphones via jack. I only have USB or Bluetooth headphones.

It works and that's impressive I haven't had sound for a almost a year now. The thing now is that the audio has poor quality and is has very low volume. Also when I run alsactl restore it shows

alsactl: set_control:1475: Cannot write control '2:0:0:ALC Capture Target Volume:0' : Invalid argument

Any I idea to solve it?

phanky5 commented 1 year ago

@Israellh2001 sound quality is probably a problem with your kernel version. I had tested some older Debian and Ubuntu releases before. Some had sound but low volume and quality as you describe. I am running kernel 6.3.11-200.fc38.x86_64. I don't have any issues with volume or quality.

I don't get any error when running alsactl restore.

spacer2010 commented 1 year ago

Can get sound running the command but after don't have microphone for Skype or others

Sent from Outlook for Androidhttps://aka.ms/AAb9ysg


From: phanky5 @.> Sent: Sunday, July 9, 2023 7:41:01 AM To: thesofproject/linux @.> Cc: spacer2010 @.>; Mention @.> Subject: Re: [thesofproject/linux] [BUG] Huawei Matebook 14s headphone / speaker problem (CX8070 codec) (Issue #3350)

@Israellh2001https://github.com/Israellh2001 sound quality is probably a problem with your kernel version. I had tested some older Debian and Ubuntu releases before. Some had sound but low volume and quality as you describe. I am running kernel 6.3.11-200.fc38.x86_64. I don't have any issues with volume or quality.

— Reply to this email directly, view it on GitHubhttps://github.com/thesofproject/linux/issues/3350#issuecomment-1627612894, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHICGOE32E2FR44QXDETZBTXPI763ANCNFSM5KTOKH7Q. You are receiving this because you were mentioned.Message ID: @.***>

Smoren commented 1 year ago

Hi, everyone!

Disclaimer: I saw the HDA spec for the first time in my life just a few evenings ago so there is a chance that I might understand something incorrectly, but I still hope that my experience might be helpful.

After spending a few evenings with QEMU, HDA spec, CX20671 Datasheet (it is another SoC, but it's better than nothing) and hda-verb I was able to find the commands which can fix both cases (a speaker and headphones) on Ubuntu 22.04 (5.15.0-52-generic).

To enable a speaker and disable headphones:

sudo hda-verb /dev/snd/hwC0D0 0x16 0x701 0x0001 // move output to speaker dac
sudo hda-verb /dev/snd/hwC0D0 0x17 0x70C 0x0002 // enable speaker
sudo hda-verb /dev/snd/hwC0D0 0x1 0x715 0x2     // disable headphones

To disable a speaker and enable headphones:

sudo hda-verb /dev/snd/hwC0D0 0x16 0x701 0x0000 // move output to headphones dac
sudo hda-verb /dev/snd/hwC0D0 0x17 0x70C 0x0000 // disable speaker
sudo hda-verb /dev/snd/hwC0D0 0x1 0x717 0x2     // pin output mode
sudo hda-verb /dev/snd/hwC0D0 0x1 0x716 0x2     // pin enable
sudo hda-verb /dev/snd/hwC0D0 0x1 0x715 0x0     // clear pin value

Looks like there is some weird hardware design, because from my prospective, the interesting widgets are:

  • 0x01 - Audio Function Group
  • 0x10 - Headphones DAC (really both devices connected here)
  • 0x11 - Speaker DAC
  • 0x16 - Headphones Jack
  • 0x17 - Internal Speaker

And:

  • widgets 0x16 and 0x17 simply should be connected to different DACs 0x10 and 0x11, but Internal Speaker 0x17 ignores the connection select command and use the value from Headphones Jack 0x16.
  • Headphone Jack 0x16 is controlled with some weird stuff so it should be enabled with GPIO commands for Audio Group 0x01.
  • Internal Speaker 0x17 is coupled with Headphone Jack 0x16 so it should be explicitly disabled with EAPD/BTL Enable command.

I hope, somebody can put this knowledge in order and make a patch to kernel 😊

Thanks for this solution! I implemented a daemon that monitors headphones connection/disconnection and switchs output mode using your idea.

foofly commented 1 year ago

@Smoren thank you! This solved my issue completely!

Kubuntu 23.04 x86_64 6.2.0-26-generic Matebook 14

tikhcloud commented 1 year ago

Hi, everyone!

Disclaimer: I saw the HDA spec for the first time in my life just a few evenings ago so there is a chance that I might understand something incorrectly, but I still hope that my experience might be helpful.

After spending a few evenings with QEMU, HDA spec, CX20671 Datasheet (it is another SoC, but it's better than nothing) and hda-verb I was able to find the commands which can fix both cases (a speaker and headphones) on Ubuntu 22.04 (5.15.0-52-generic).

To enable a speaker and disable headphones:

sudo hda-verb /dev/snd/hwC0D0 0x16 0x701 0x0001 // move output to speaker dac
sudo hda-verb /dev/snd/hwC0D0 0x17 0x70C 0x0002 // enable speaker
sudo hda-verb /dev/snd/hwC0D0 0x1 0x715 0x2     // disable headphones

To disable a speaker and enable headphones:

sudo hda-verb /dev/snd/hwC0D0 0x16 0x701 0x0000 // move output to headphones dac
sudo hda-verb /dev/snd/hwC0D0 0x17 0x70C 0x0000 // disable speaker
sudo hda-verb /dev/snd/hwC0D0 0x1 0x717 0x2     // pin output mode
sudo hda-verb /dev/snd/hwC0D0 0x1 0x716 0x2     // pin enable
sudo hda-verb /dev/snd/hwC0D0 0x1 0x715 0x0     // clear pin value

Looks like there is some weird hardware design, because from my prospective, the interesting widgets are:

* 0x01 - Audio Function Group

* 0x10 - Headphones DAC (really both devices connected here)

* 0x11 - Speaker DAC

* 0x16 - Headphones Jack

* 0x17 - Internal Speaker

And:

* widgets 0x16 and 0x17 simply should be connected to different DACs 0x10 and 0x11, but Internal Speaker 0x17 ignores the connection select command and use the value from Headphones Jack 0x16.

* Headphone Jack 0x16 is controlled with some weird stuff so it should be enabled with GPIO commands for Audio Group 0x01.

* Internal Speaker 0x17 is coupled with Headphone Jack 0x16 so it should be explicitly disabled with EAPD/BTL Enable command.

I hope, somebody can put this knowledge in order and make a patch to kernel 😊

Solution doesn't work :( Ubuntu 22.04.2 LTS x86_64, 6.2.0-26-generic, Matebook 14s 2023 HKFG-XX

Headphones plugged or unplugged doesn't matter, nothing changes. As usual, sound comes from speakers when headphones plugged in :

sudo hda-verb /dev/snd/hwC0D0 0x16 0x701 0x0001 // move output to speaker dac
sudo hda-verb /dev/snd/hwC0D0 0x17 0x70C 0x0002 // enable speaker
sudo hda-verb /dev/snd/hwC0D0 0x1 0x715 0x2     // disable headphones

Both speakers and headphones working at the same time:

sudo hda-verb /dev/snd/hwC0D0 0x16 0x701 0x0000 // move output to headphones dac
sudo hda-verb /dev/snd/hwC0D0 0x17 0x70C 0x0000 // disable speaker
sudo hda-verb /dev/snd/hwC0D0 0x1 0x717 0x2     // pin output mode
sudo hda-verb /dev/snd/hwC0D0 0x1 0x716 0x2     // pin enable
sudo hda-verb /dev/snd/hwC0D0 0x1 0x715 0x0     // clear pin value

Also, only 2 speakers out of 4 works..

thule1291 commented 1 year ago

Guys, so if you are just trying to get your speakers to work, as I was, here's a simple solution: image

I just cut a headphone jack and plugged in the end. Not an ideal solution, but if you don't want to wear headphones, it's good enough. Plus it's portable :)

THIS is the best Solution so far! I thought it was a joke at first but no, absolutely perfect! (Huawei MateBook X Pro 2021, 13.90", Intel Core i7-1165G7, 16 GB, 1000 GB, CH)

merelm-academy commented 10 months ago

Hi guys, I have a matebook 14 2020 with speakers and microphones array not working. I don't want to give you too much hope but I read on forums that in the future version 6.7 of the linux kernel there could be a generic fix to the audio problem of Huawei matebooks. I'm not sure that could be a definitive solution to our problem with these pc but could be a starting point. https://github.com/codepayne/linux-sound-huawei/issues/15 May the force be with you...

cihatertem commented 10 months ago

Hi guys, I have a matebook 14 2020 with speakers and microphones array not working. I don't want to give you too much hope but I read on forums that in the future version 6.7 of the linux kernel there could be a generic fix to the audio problem of Huawei matebooks. I'm not sure that could be a definitive solution to our problem with these pc but could be a starting point. codepayne/linux-sound-huawei#15 May the force be with you...

Nice improved for Huawei laptops with "AMD CPUs that connect using the ACP3x module to a ES8336 CODEC.". But 14s uses intel and the codec is CX8070. :/

merelm-academy commented 10 months ago

My pc and other AMD's laptop use "snd_hda_intel" driver that are the same for intel CPUs. Is it possible that they are working on your issue that is similar to mine?

cihatertem commented 10 months ago

My pc and other AMD's laptop use "snd_hda_intel" driver that are the same for intel CPUs. Is it possible that they are working on your issue that is similar to mine?

I am not sure but codes are different. And a user commented above and mark the this topic issue as codec problem. Nevermind, we'll see soon :)

eniskastrati commented 9 months ago

Currently having the issue with my new matebook14 amd ryzen 7 5400U 16GB RAM. Anyone a solution that I can try?

cihatertem commented 8 months ago

2 years and no official progress :), we could make happy birthday party for the bug!

Cypukat85 commented 8 months ago

2 years and no official progress :), we could make happy birthday party for the bug!

This is a client-only problem because the vendor does not add Linux support as a specification. Next time I will choose a more suitable model and manufacturer.

maniadevice commented 8 months ago

Does anyone know what's the best way to contact them about this issue? If not, I can look around and type up an email for them, and then paste the template here. So everyone here can send one out to them.

vpkopylov commented 8 months ago

I have the same issue with my Huawei MateBook 16s, although the chip name is different: Conexant SN6140. A simple workaround that works for me is executing (from a startup script) amixer -c 0 sset Headphone on 100 (this command unmutes Headphone ). It doesn't solve the problem with not working headphones plugged in jack (doesn't matter if you use bluetooth headphones), but at least speaker works.

developersu commented 8 months ago

Same on Honor MagicView 14 (HGE-W76). Same issues with same Conexant cx8070

maniadevice commented 8 months ago

FWIW, just sent out an email here https://consumer.huawei.com/uk/support/contact-us/email-us/ and posted the link to this github issue. I don't know if they are going to care about one person. But maybe more of us can put some pressure?

NikitaMarakushev commented 8 months ago

I had the same problem with huawei matebook d14, until i tried current lastest fedora 39 with kernel 6.5 I consider, that using some of rolling-release distros, such as fedora, manjaro, void e. t. c can probably fix that problem

vpkopylov commented 8 months ago

I had the same problem with huawei matebook d14, until i tried current lastest fedora 39 with kernel 6.5 I consider, that using some of rolling-release distros, such as fedora, manjaro, void e. t. c can probably fix that problem

I am on Arch Linux and the system is up to date. Still have this problem with Matebook 16s (if a workaround is not applied)

foofly commented 7 months ago

I've posted this before, but I've had success with this: https://github.com/Smoren/huawei-ubuntu-sound-fix

Tested on Kbuntu, Solus and Endevour OS (all running plasma as that's my preference)

spacer2010 commented 7 months ago

I tried it on my Matebook S14 on Debian Bookworm

IIT WORKS

After nearly 2 years that the first time i can hear my sound without introduce commands

On Friday 12 January 2024 03:44:36 PM (+01:00), Bill Kav wrote:

I've posted this before, but I've had success with this: https://github.com/Smoren/huawei-ubuntu-sound-fix

Tested on Kbuntu, Solus and Endevour OS (all running plasma as that's my preference)

— Reply to this email directly, view it on GitHub https://github.com/thesofproject/linux/issues/3350#issuecomment-1889399224 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AHICGOGFYTEHC7KGFKAUDFTYOFD5JAVCNFSM5KTOKH72U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBYHEZTSOJSGI2A . You are receiving this because you were mentioned.

-- Wolfgang Endres +34 643705733 +66 933260183

eniskastrati commented 7 months ago

I just dual booted Debian 12.4 Bookworm and again getting the dummy output.! Have you also done any other changes on your site @spacer2010 ?

spacer2010 commented 7 months ago

I only install this fix https://github.com/Smoren/huawei-ubuntu-sound-fix After install all is working well have normal sound , my matbook now recognise if I use headphones or not and speaker work.

Wolfgang Endres

On Fri, 12 Jan 2024, 18:21 Enis K, @.***> wrote:

I just dual booted Debian 12.4 Bookworm and again getting the dummy output.! Have you also done any changes on your site @spacer2010 https://github.com/spacer2010 ?

— Reply to this email directly, view it on GitHub https://github.com/thesofproject/linux/issues/3350#issuecomment-1889681158, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHICGOCEB7X76K3LH5HJT3DYOFWJ5AVCNFSM5KTOKH72U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBYHE3DQMJRGU4A . You are receiving this because you were mentioned.Message ID: @.***>

spacer2010 commented 7 months ago

"Dummy output" maybe you didn't install the sof packet

Wolfgang Endres

On Fri, 12 Jan 2024, 18:21 Enis K, @.***> wrote:

I just dual booted Debian 12.4 Bookworm and again getting the dummy output.! Have you also done any changes on your site @spacer2010 https://github.com/spacer2010 ?

— Reply to this email directly, view it on GitHub https://github.com/thesofproject/linux/issues/3350#issuecomment-1889681158, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHICGOCEB7X76K3LH5HJT3DYOFWJ5AVCNFSM5KTOKH72U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBYHE3DQMJRGU4A . You are receiving this because you were mentioned.Message ID: @.***>

vpkopylov commented 7 months ago

I can confirm that this workaround https://github.com/Smoren/huawei-ubuntu-sound-fix also works on Arch Linux and Matebook 16s out of box! Thanks @foofly Even though README claims support only for Ubuntu and Fedora, the installation script contains pacman commands as well. And this is the best workaround so far, because both the speakers and the headphones work properly, and auto switching between them also works.

catmeowjiao commented 7 months ago

I have a matebook 14s and I'm trying to use the headset's microphone but it doesn't work, how do I fix it?

foofly commented 7 months ago

@catmeowjiao depending on your distro, the link I posted above may be your best bet.

catmeowjiao commented 5 months ago

FWIW, just sent out an email here https://consumer.huawei.com/uk/support/contact-us/email-us/ and posted the link to this github issue. I don't know if they are going to care about one person. But maybe more of us can put some pressure?

They should only respond to problems with Deepin, a Linux distribution in China.

Fisherworks commented 3 months ago

I can confirm that this workaround https://github.com/Smoren/huawei-ubuntu-sound-fix also works on Arch Linux and Matebook 16s out of box! Thanks @foofly Even though README claims support only for Ubuntu and Fedora, the installation script contains pacman commands as well. And this is the best workaround so far, because both the speakers and the headphones work properly, and auto switching between them also works.

Confirm this working too, on Matebook 14 with kernel 6.9.3 on Arch Linux.