Note: This guide is based on this gist by rraks. I did not discover how to do this, all credit goes to them!
The speakers on some ASUS laptops, like the ASUS Vivobook 16 Flip, do not work out of the box on current versions of Linux. But, it is possible to fix them using some magic scripts.
This guide will show you the scripts needed to make the speakers work, and how to control their volume and integrate volume control with GNOME.
This guide has only been tested on Fedora 43 (as it's what I use). Your mileage may vary.
Also checkout my guide on how to get tablet mode working properly on the ASUS Vivobook 16 Flip here!
The ASUS Vivobook 16 Flip TP3607SA uses Texas Instruments TAS2781 amplifiers for its speakers. The kernel driver fails to initialize these amplifiers properly, so we need to manually configure them via I2C and create a volume control service.
Install required packages:
sudo dnf install i2c-tools alsa-utilsLoad the i2c-dev module:
sudo modprobe i2c-devThis script initializes the TAS2781 amplifiers and must run at boot.
sudo nano /usr/local/bin/tas2781-init.shPaste the following:
#!/bin/bash
export TERM=linux
# Some distros don't have i2c-dev module loaded by default, so we load it manually
modprobe i2c-dev
i2c_bus=0
echo "Using I2C bus: $i2c_bus"
i2c_addr=(0x38 0x3d)
count=0
for value in "${i2c_addr[@]}"; do
val=$((count % 2))
i2cset -f -y "$i2c_bus" "$value" 0x00 0x00
i2cset -f -y "$i2c_bus" "$value" 0x7f 0x00
i2cset -f -y "$i2c_bus" "$value" 0x01 0x01
i2cset -f -y "$i2c_bus" "$value" 0x0e 0xc4
i2cset -f -y "$i2c_bus" "$value" 0x0f 0x40
i2cset -f -y "$i2c_bus" "$value" 0x5c 0xd9
i2cset -f -y "$i2c_bus" "$value" 0x60 0x10
if [ $val -eq 0 ]; then
i2cset -f -y "$i2c_bus" "$value" 0x0a 0x1e
else
i2cset -f -y "$i2c_bus" "$value" 0x0a 0x2e
fi
i2cset -f -y "$i2c_bus" "$value" 0x0d 0x01
i2cset -f -y "$i2c_bus" "$value" 0x16 0x40
i2cset -f -y "$i2c_bus" "$value" 0x00 0x01
i2cset -f -y "$i2c_bus" "$value" 0x17 0xc8
i2cset -f -y "$i2c_bus" "$value" 0x00 0x04
i2cset -f -y "$i2c_bus" "$value" 0x30 0x00
i2cset -f -y "$i2c_bus" "$value" 0x31 0x00
i2cset -f -y "$i2c_bus" "$value" 0x32 0x00
i2cset -f -y "$i2c_bus" "$value" 0x33 0x01
i2cset -f -y "$i2c_bus" "$value" 0x00 0x08
i2cset -f -y "$i2c_bus" "$value" 0x18 0x00
i2cset -f -y "$i2c_bus" "$value" 0x19 0x00
i2cset -f -y "$i2c_bus" "$value" 0x1a 0x00
i2cset -f -y "$i2c_bus" "$value" 0x1b 0x00
i2cset -f -y "$i2c_bus" "$value" 0x28 0x40
i2cset -f -y "$i2c_bus" "$value" 0x29 0x00
i2cset -f -y "$i2c_bus" "$value" 0x2a 0x00
i2cset -f -y "$i2c_bus" "$value" 0x2b 0x00
i2cset -f -y "$i2c_bus" "$value" 0x00 0x0a
i2cset -f -y "$i2c_bus" "$value" 0x48 0x00
i2cset -f -y "$i2c_bus" "$value" 0x49 0x00
i2cset -f -y "$i2c_bus" "$value" 0x4a 0x00
i2cset -f -y "$i2c_bus" "$value" 0x4b 0x00
i2cset -f -y "$i2c_bus" "$value" 0x58 0x40
i2cset -f -y "$i2c_bus" "$value" 0x59 0x00
i2cset -f -y "$i2c_bus" "$value" 0x5a 0x00
i2cset -f -y "$i2c_bus" "$value" 0x5b 0x00
i2cset -f -y "$i2c_bus" "$value" 0x00 0x00
i2cset -f -y "$i2c_bus" "$value" 0x02 0x00
count=$((count + 1))
done**NOTE: your i2c_bus and i2c_addr may be different. ** This script is not mine and comes from here. There are more details there on how it works and how to find your i2c_bus.
Make it executable:
sudo chmod +x /usr/local/bin/tas2781-init.shTest it:
sudo /usr/local/bin/tas2781-init.sh
speaker-test -c2 -t wavYou should hear sound now (though be careful - it will be ahttps://gist.github.com/rraks/4edddb99b50b94fe6298adbf3c9f43ebt maximum volume).
This script controls the speaker volume by writing to the TAS2781's digital volume control registers.
sudo nano /usr/local/bin/tas2781-volume. shPaste the following:
#!/bin/bash
i2c_bus=0
i2c_addr=(0x38 0x3d)
# Volume 0-100
VOLUME=${1:-50}
# Convert to 4-byte value (signed 8.24 format)
# 0x00000000 = silent
# 0x40000000 = unity gain (default)
# 0x7F000000 = max gain (about +6dB louder)
# Adjust the max value (0x7F) to change maximum volume
SCALE=$((VOLUME * 0x7F / 100))
for value in "${i2c_addr[@]}"; do
# Switch to page 0x08
i2cset -f -y "$i2c_bus" "$value" 0x00 0x08
# Set registers 0x28-0x2b (4-byte volume control)
i2cset -f -y "$i2c_bus" "$value" 0x28 $(printf "0x%02x" $SCALE)
i2cset -f -y "$i2c_bus" "$value" 0x29 0x00
i2cset -f -y "$i2c_bus" "$value" 0x2a 0x00
i2cset -f -y "$i2c_bus" "$value" 0x2b 0x00
done
echo "Volume set to $VOLUME% (byte value: $(printf "0x%02x" $SCALE))"Make it executable:
sudo chmod +x /usr/local/bin/tas2781-volume.shTest volume control:
sudo /usr/local/bin/tas2781-volume.sh 0 # No sound
sudo /usr/local/bin/tas2781-volume.sh 1 # Very quiet
sudo /usr/local/bin/tas2781-volume.sh 10 # Fairly quiet
sudo /usr/local/bin/tas2781-volume. sh 50 # Medium
sudo /usr/local/bin/tas2781-volume.sh 100 # MaxThe volume curve in this script is completely arbritary and simply reflects my preferences. It is definitely not perfect. A non linear curve probably makes more sense. I might update it in the future.
To change the maximum volume, edit the line in the volume script:
SCALE=$((VOLUME * 0x7F / 100))-
For louder maximum volume: Change
0x7Fto0xFFSCALE=$((VOLUME * 0xFF / 100)) -
For quieter maximum volume: Change
0x7Fto a lower value like0x60SCALE=$((VOLUME * 0x60 / 100))
The value 0x40 represents unity gain (0dB), 0x7F is about +6dB, and 0xFF is maximum.
This script monitors GNOME/PipeWire volume changes and syncs them to the hardware.
sudo nano /usr/local/bin/tas2781-pipewire-sync.shPaste the following:
#!/bin/bash
i2c_bus=0
i2c_addr=(0x38 0x3d)
# Detect the actual user (not root)
REAL_USER=$(who | awk '{print $1}' | head -1)
REAL_UID=$(id -u $REAL_USER)
export XDG_RUNTIME_DIR="/run/user/$REAL_UID"
# Function to set hardware volume
set_hw_volume() {
local VOLUME=$1
local SCALE=$((VOLUME * 0x7F / 100))
for value in "${i2c_addr[@]}"; do
i2cset -f -y "$i2c_bus" "$value" 0x00 0x08
i2cset -f -y "$i2c_bus" "$value" 0x28 $(printf "0x%02x" $SCALE)
i2cset -f -y "$i2c_bus" "$value" 0x29 0x00
i2cset -f -y "$i2c_bus" "$value" 0x2a 0x00
i2cset -f -y "$i2c_bus" "$value" 0x2b 0x00
done
}
# Monitor PipeWire volume changes as the real user
su - $REAL_USER -c "export XDG_RUNTIME_DIR=/run/user/$REAL_UID; pactl subscribe" | \
grep --line-buffered "sink" | while read -r line; do
# Get current volume percentage from default sink (as the real user)
VOLUME=$(su - $REAL_USER -c "export XDG_RUNTIME_DIR=/run/user/$REAL_UID; pactl get-sink-volume @DEFAULT_SINK@" | grep -oP '\d+%' | head -1 | tr -d '%')
if [ -n "$VOLUME" ]; then
set_hw_volume "$VOLUME"
fi
doneMake it executable:
sudo chmod +x /usr/local/bin/tas2781-pipewire-sync.shNote: If you changed the max volume in Step 2, make sure to change the same line in this script:
local SCALE=$((VOLUME * 0x7F / 100))sudo nano /etc/systemd/system/tas2781-init.servicePaste:
[Unit]
Description=Initialize TAS2781 Amplifiers
After=sound.target
Before=pipewire.service tas2781-volume-sync.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/tas2781-init.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.targetsudo nano /etc/systemd/system/tas2781-volume-sync.servicePaste:
[Unit]
Description=TAS2781 Volume Sync with PipeWire
After=sound. target pipewire.service tas2781-init.service
[Service]
Type=simple
ExecStart=/usr/local/bin/tas2781-pipewire-sync.sh
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable tas2781-init.service
sudo systemctl enable tas2781-volume-sync.service
sudo systemctl start tas2781-init.service
sudo systemctl start tas2781-volume-sync.serviceCheck that both services are running:
sudo systemctl status tas2781-init.service
sudo systemctl status tas2781-volume-sync. service-
Reboot your laptop:
sudo reboot
-
After reboot, test the speakers:
speaker-test -c2 -t wav
-
Try changing volume using:
- GNOME volume slider (top-right menu)
- Keyboard volume keys
- Any application's volume control
The hardware volume should automatically follow!
Check the init service:
sudo systemctl status tas2781-init.service
sudo journalctl -u tas2781-init.serviceCheck the volume sync service:
sudo systemctl status tas2781-volume-sync.service
sudo journalctl -u tas2781-volume-sync.service -fEdit the SCALE calculation in both /usr/local/bin/tas2781-volume.sh and /usr/local/bin/tas2781-pipewire-sync.sh. Change 0x7F to a higher value (up to 0xFF) for louder, or lower value for quieter maximum volume.
All work good except on resume from standby mode. I edited this script to restart init service on resume. (for Ubuntu)
/lib/systemd/system-sleep/tas2781-init :
#!/bin/sh
if [ "$1" = "post" ]; then
systemctl restart tas2781-init.service
fi