jmontleon / pixelbook-fedora

How to install Fedora on a Pixelbook with reasonable results
62 stars 12 forks source link

Add Jack detection #33

Closed EMLommers closed 2 years ago

EMLommers commented 2 years ago

To switch between the speaker and the headphone automatically with jack detection

The following method is just a workaround because it only works with one user. Ideally pulseaudio should take care of this. (Need more research on alsa ucm)

Install the acpid package

Put the following in /etc/acpi/events/plugheadphone

event=jack/headphone HEADPHONE plug
action=sudo -u YOUR_USER_NAME XDG_RUNTIME_DIR=/run/user/YOUR_USER_ID pactl set-card-profile 0 Headphone

and put the following in /etc/acpi/events/unplugheadphone

event=jack/headphone HEADPHONE unplug
action=sudo -u YOUR_USER_NAME XDG_RUNTIME_DIR=/run/user/YOUR_USER_ID pactl set-card-profile 0 Speaker

replace YOUR_USER_NAME and YOUR_USER_ID accordingly.

Enable and start acpid service

sudo systemctl enable --now acpid
jmontleon commented 2 years ago

Hey, thanks for this! I'm sure there are people that will be thrilled to have it, even as a workaround.

When I have a minute I'll add it to a package and/or the playbook. Even when that's done, this is probably another good issue to leave open until someone figures out the proper magic.

jmontleon commented 2 years ago

Did you do something to adjust the profiles? These commands just give me an error like so:

$ pactl set-card-profile 0 Speaker
Failure: No such entity

I was able to set the headphone/mic like so though:

while inotifywait -e modify /tmp/acpi.log; do
  HEADPHONE=$(tail -n 1 /tmp/acpi.log | grep -e 'HEADPHONE' -e 'MICROPHONE')
  if echo "$HEADPHONE" | grep 'unplug$' ; then
    pactl set-default-sink alsa_output.platform-kbl_r5514_5663_max.HiFi__hw_kblr55145663max_0__sink
    pactl set-default-source alsa_input.platform-kbl_r5514_5663_max.HiFi__hw_kblr55145663max_4__source
  else
    pactl set-default-sink alsa_output.platform-kbl_r5514_5663_max.HiFi__hw_kblr55145663max_2__sink
    pactl set-default-source alsa_input.platform-kbl_r5514_5663_max.HiFi__hw_kblr55145663max_1__source
  fi
done

(taking inspiration from your suggestion and https://github.com/jmontleon/pixelbook-fedora/blob/de2d49a5567d930fd846724679ab522e924720a5/scripts/pixelbook-disable-tablet-touchpad)

jmontleon commented 2 years ago

Don't know if you'd be interested in trying this and other changes: https://github.com/jmontleon/pixelbook-fedora/issues/34

EMLommers commented 2 years ago

I will run ansible and see the results... Audio works. I modified the ucm file and got working without acpid. checked the cras_ucm.h use-case.h and use-case.c ucm_local.h To convert the cras ucm to ucm2 and alsa-lib 1.2.6. is critical for the alsalib . Will upload when I am satisfied with result.

I am using X11,not kde or wayland. because I love working with plank!
The keyboard-backlight stopped working.

The automatic detect of Jack stopped suddenly misterously.... Using combination of JackControl and JackHWMute does not work correctly anymore. Sections where you have playback or capture, need to add Playback(or Capture) before MixerName. CaptureChannels / PlaybackChannels in combination with Capture/PlackbackPriority have to be added. JackDev, JackSwitch and JackType are depricated as of alsa 1.2.6
I think JackControl should be valued as "Headphone Jack" , do not know yet if variable JackCTL is needed JackHWMute without JackControl is not working.....

For now keep the ACPI workaround........ keep you posted By the way: currenty running kernel 5.17.9-300.fc36.x86_64

EMLommers commented 2 years ago

Something weird happened with alsa, maybe it is an update but the complete ucm is neglected. Seems Alsa is bit unstable or so.. Getting FW Errors and 'base clock too low' FAILED to set DMIC clock... alsaucm listcards , is empty, because it is checking ../alsa/ucm2/conf.virt.d/ alsaucm reload is pointing to ../alsa/ucm2/conf.d/....
and sometimes it is getting the ucm from ../alsa/ucm2/ somewhere there is an issue... ucm.conf or alsa-lib?

EMLommers commented 2 years ago

I am trying to get the original asound.state file from chromeos because some of the alsmixer widgets make no sense, like STO1... And STO2..., Widget for Left but no Right defined.. guess some should be renamed. When using Brunch framework, some firmware files are missing. Do you have original ChromeOS asound.state file?

EMLommers commented 2 years ago

Some changes should be made to alsa. conf.d,conf.virt.d and ucm.conf should be in upper directory, /usr/share/alsa . To make it logical and work correctly , pointing to correct directories. Also to keep future versions in mind like ucm3 or ucm4 etc.

EMLommers commented 2 years ago

I know it is not in your hands.... But I think you understand.

jmontleon commented 2 years ago

The .d directories are a recent addition, I think in alsa 1.2.6. Prior to that most the files in pixelbook-alsa-ucm were one directory up, and broke when the Fedora package was updated. I don't have any insight into the changes. If there are improvements that can be made to the pixelbook-alsa-ucm package to make things work better PRs are of course welcome.

I got help here at one point and that's really the most substantial change I've made to anything: https://github.com/alsa-project/alsa-ucm-conf/issues/108

It's possible if you can get in touch with alsa folks they could help you through getting it to work more fully, if they have time.

It's very possible this isn't the only thing that makes no sense outside of Chrome OS https://github.com/alsa-project/alsa-ucm-conf/issues/108#issuecomment-885852598

EMLommers commented 2 years ago

Alsa is a bit of a mess, in the end they will succeed of course. Google removed and added some 'ucm instructions' , for simplification and removed or shortened instructions. CRAS is maybe not so bad after all. As you have probably notices Google or ChromeOS gives itself instructions per directory or library, like '/ROOT-A/usr/share/alsa/ucm/.keep_media-sound_alsa-utils-0.9' Sometimes they invert the value of a mixer, alter names, add in ChromiumBrowser or CRAS additional widgets. I have checked the source and header files of CRAS and alsa. For example CRAS mentioned: MixerElem 'DAC' , it relates to ALSA (Depending on Device for playback or recording) in ucm2 it sould be named: PlaybackMixerElem 'DAC' and for Example MixerElem 'ADC' should be in UCM2 CaptureMixerElem 'ADC' Alsa is slowly following google in their approach.. Google removed 'JackType', JackSwitch, and they embedded in Cras auto lookup for hctl or gpio jacktype.

I have tried so many things to get Jack detect via alsa.. cannot detect.. The solution check acpi is the best and most stable solution for now. I am using bit more firmware files due to google's 'upstream'

9d71-GOOGLE-EVEMAX-0-tplg.bin iwlwifi-7265D-29.ucode
rt2870.bin dsp_lib_dsm_core_spt_release.bin
rt3070.bin google_touchpad.bin
rt5514_dsp_fw1.bin rt5514_dsp_fw2.bin rt5514_dsp_fw3.bin i915 - all files
intel - files in folder specified below
iwl-dbg-cfg.ini
wacom_firmware_EVE.hex

Intel directory copied all dsp* files Noticed in upstream linux-firmware dsp_fw_release.bin pointed to dsp_fw_kbl_v3402.bin, relink to dsp_fw_kbl_v3420.bin

Added additional kernel parameters as used by Google in Overlay-Eve options kvm-intel.vmentry_l1d_flush=always options i915 enable_dpcd_backlight=1 options i915 enable_dbc=1 options i915 enable_guc_loading=1 options i915 enable_guc_submission=0 options snd_intel_sndcfg

I would suggest to close this topic.. Jack is working, and I think no-one really cares if it is a workaround or not.. The way you handled the jack event works.. to 'do not fix is it is not broken'... it works...and we will see in the future!