Files
lenovo-gentoo/Bluetooth-Setup.md
Alexander Hinrichs 8de3f16ee6 chore: initialize gentoo-setup documentation repository
Add comprehensive documentation for Lenovo ThinkPad Gentoo Linux setup
including:
- Complete system configuration guides (power, Bluetooth, WiFi, audio)
- Hardware setup documentation (touchpad, touchscreen, DisplayLink)
- Management scripts with ZSH completions
- Kernel configuration (6.12.41-gentoo-x86_64)
- Lid automation and monitor management
- Battery conservation system
- User guides and troubleshooting

Repository includes .gitignore to exclude logs, temporary files, and
secrets.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-07 18:22:51 +01:00

661 lines
16 KiB
Markdown

# Bluetooth Setup - MediaTek MT7925
Complete guide for Bluetooth setup on Lenovo ThinkPad with MediaTek MT7925 WiFi 7 + Bluetooth 5.4 combo chip.
## Hardware
- **Chip:** MediaTek MT7925
- **WiFi:** WiFi 7 (802.11be) 2x2
- **Bluetooth:** Bluetooth 5.4
- **Interface:** PCIe (WiFi) + USB (Bluetooth)
- **Firmware:** `/lib/firmware/mediatek/mt7925/BT_RAM_CODE_MT7925_1_1_hdr.bin`
## Status
**Current Status:****WORKING** - Bluetooth controller fully functional!
### What Works
- ✅ Bluetooth controller detection (hci0)
- ✅ Device scanning and pairing
- ✅ Audio devices (headphones, speakers)
- ✅ Input devices (keyboards, mice)
- ✅ File transfer
- ✅ Waybar integration
### Known Issues Resolved
- **Module Conflict:** Had two versions of Bluetooth modules (old in `/updates/`, new in `/kernel/`). Fixed by replacing modules in `/updates/` directory.
- **Initial Setup:** Required kernel rebuild to enable `CONFIG_BT_HCIBTUSB_MTK`
- **Module Dependencies:** Both `btmtk.ko` and `btusb.ko` must be from the same build to avoid symbol CRC mismatches
## Kernel Configuration
### Required Kernel Options
The following kernel options are **required** for MT7925 Bluetooth:
```
CONFIG_BT=m # Bluetooth core
CONFIG_BT_BREDR=y # Classic Bluetooth
CONFIG_BT_LE=y # Bluetooth Low Energy
CONFIG_BT_RFCOMM=m # RFCOMM protocol
CONFIG_BT_BNEP=m # Bluetooth network support
CONFIG_BT_HIDP=m # HID over Bluetooth
CONFIG_BT_HCIBTUSB=m # USB Bluetooth devices
CONFIG_BT_HCIBTUSB_MTK=y # ⚠️ CRITICAL: MediaTek USB support
CONFIG_BT_MTK=m # MediaTek common code
```
### Verification
Check if required options are enabled:
```bash
# Check current kernel config
grep -E "CONFIG_BT_HCIBTUSB|CONFIG_BT_MTK" /boot/config-$(uname -r)
# Should show:
# CONFIG_BT_HCIBTUSB=m
# CONFIG_BT_HCIBTUSB_MTK=y ← This was missing!
# CONFIG_BT_MTK=m
```
### Kernel Rebuild (Already Completed)
The kernel has been rebuilt with the missing option. Here's what was done:
```bash
# Enable MediaTek USB Bluetooth support
cd /usr/src/linux
scripts/config --enable CONFIG_BT_HCIBTUSB_MTK
# Rebuild Bluetooth modules
make -j16 M=drivers/bluetooth modules
make M=drivers/bluetooth modules_install
# Copy modules to /updates/ directory (which has higher priority)
sudo cp /lib/modules/$(uname -r)/kernel/drivers/bluetooth/btusb.ko \
/lib/modules/$(uname -r)/updates/btusb.ko
sudo cp /lib/modules/$(uname -r)/kernel/drivers/bluetooth/btmtk.ko \
/lib/modules/$(uname -r)/updates/btmtk.ko
# Update module dependencies
depmod -a
# Reload modules
sudo modprobe -r btusb btmtk
sudo modprobe btmtk
sudo modprobe btusb
# Restart Bluetooth service
sudo rc-service bluetooth restart
```
**Module Locations:**
- `/lib/modules/6.12.41-gentoo-x86_64/updates/btusb.ko` (157 KB)
- `/lib/modules/6.12.41-gentoo-x86_64/updates/btmtk.ko` (64 KB)
## Firmware
### Firmware Files
Located in `/lib/firmware/mediatek/mt7925/`:
```
BT_RAM_CODE_MT7925_1_1_hdr.bin (451 KB) - Bluetooth firmware
WIFI_RAM_CODE_MT7925_1_1.bin - WiFi firmware
WIFI_MT7925_PATCH_MCU_1_1_hdr.bin - WiFi patch
```
### Verification
```bash
# Check firmware exists
ls -lh /lib/firmware/mediatek/mt7925/BT_RAM_CODE_MT7925_1_1_hdr.bin
# Check firmware loading in kernel log (after reboot)
dmesg | grep -i "mediatek.*bt\|BT_RAM"
```
## Bluetooth Service
### Service Management
```bash
# Start Bluetooth service
sudo rc-service bluetooth start
# Enable at boot
sudo rc-update add bluetooth default
# Check status
rc-service bluetooth status
# Restart service
sudo rc-service bluetooth restart
```
### Service Dependencies
Bluetooth service requires:
- `dbus` service
- `udev` service
- Bluetooth kernel modules loaded
## Module Loading
### Automatic Module Loading
Create `/etc/modules-load.d/bluetooth.conf` to ensure btmtk loads at boot:
```bash
# Create the configuration file
echo '# MediaTek Bluetooth support
btmtk' | sudo tee /etc/modules-load.d/bluetooth.conf
```
This ensures the MediaTek Bluetooth module loads automatically at boot, which is **required** for the MT7925 Bluetooth controller to work properly.
### Manual Module Loading
```bash
# Load MediaTek Bluetooth support
sudo modprobe btmtk
# Load USB Bluetooth driver
sudo modprobe btusb
# Verify modules are loaded
lsmod | grep -E "^bt"
```
### Module Information
```bash
# Check btusb module details
modinfo btusb | grep -E "filename|firmware|description"
# Check btmtk module details
modinfo btmtk
```
## Bluetooth Controller
### Check Controller Status
After reboot, verify Bluetooth controller is detected:
```bash
# List Bluetooth controllers
bluetoothctl list
# Should show something like:
# Controller XX:XX:XX:XX:XX:XX ThinkPad [default]
# Show controller details
bluetoothctl show
# Check hardware detection
ls -la /sys/class/bluetooth/
# Should show: hci0 -> ...
# Check rfkill status
rfkill list bluetooth
# Should show: Soft blocked: no, Hard blocked: no
```
### Troubleshooting Controller
If controller is not detected after reboot:
```bash
# Check kernel messages
dmesg | grep -i bluetooth
dmesg | grep -i hci0
# Check USB device
lsusb | grep -i mediatek
# Should show: ID 0e8d:e025 MediaTek Inc. Wireless_Device
# Check driver binding
ls -la /sys/class/bluetooth/hci0/device/driver
# Should point to btusb driver
# Check for errors
journalctl -xe | grep -i bluetooth
```
## bluetooth-setup Script
A custom management script is available for easy Bluetooth device management.
### Installation
```bash
# From the project directory
cd ~/repository/git.hinrichs.dev/alexander/claude/gentoo-setup/scripts/bluetooth-setup
# Install script
sudo cp bluetooth-setup /usr/local/bin/bluetooth-setup
sudo chmod +x /usr/local/bin/bluetooth-setup
# Install ZSH autocompletion
sudo mkdir -p /usr/local/share/zsh/site-functions
sudo cp _bluetooth-setup /usr/local/share/zsh/site-functions/_bluetooth-setup
# Reload completions
autoload -U compinit && compinit
```
### Usage
**List paired devices:**
```bash
bluetooth-setup
# or
bluetooth-setup list-paired
```
**Scan for devices:**
```bash
bluetooth-setup scan
```
**Pair with a device:**
```bash
bluetooth-setup pair AA:BB:CC:DD:EE:FF
```
**Connect to a device:**
```bash
bluetooth-setup connect AA:BB:CC:DD:EE:FF
```
**Disconnect:**
```bash
# Disconnect all devices
bluetooth-setup disconnect
# Disconnect specific device
bluetooth-setup disconnect AA:BB:CC:DD:EE:FF
```
**Remove/forget device:**
```bash
bluetooth-setup remove AA:BB:CC:DD:EE:FF
```
**Show status:**
```bash
bluetooth-setup status
```
**Enable/disable Bluetooth:**
```bash
bluetooth-setup power on
bluetooth-setup power off
```
**Get help:**
```bash
bluetooth-setup help
```
### Script Features
- ✨ Color-coded output
- 🔍 Device scanning
- 🔗 Easy pairing and connection
- 📋 List paired devices with status
- ❌ Remove/forget devices
- 🔌 Power management
- ⚡ ZSH autocompletion
- 🤖 Auto-starts Bluetooth service if needed
### ZSH Autocompletion
Once installed, tab completion works:
```bash
bluetooth-setup <TAB> # Shows all commands
bluetooth-setup connect <TAB> # Shows paired devices
bluetooth-setup pair <TAB> # Shows discovered devices
bluetooth-setup power <TAB> # Shows on/off
```
## Waybar Integration
Bluetooth status is displayed in waybar status bar.
### Configuration
The Bluetooth module has been added to waybar config (`~/.config/waybar/config`):
```json
"bluetooth": {
"format": " BT: {status}",
"format-connected": " BT: {device_alias}",
"format-disabled": " BT: Off",
"format-off": " BT: Off",
"tooltip": true,
"tooltip-format": "Bluetooth: {status}",
"tooltip-format-connected": "Bluetooth: {device_alias}\nBattery: {device_battery_percentage}%\nConnected devices: {num_connections}",
"tooltip-format-enumerate-connected": "{device_alias}",
"on-click": "bluetooth-setup status"
}
```
### Waybar Module Order
Modules from left to right:
```
[Workspaces] [Window] | [Clock] | [Audio] [Bluetooth] [Network] [CPU] [RAM] [Temp] [Brightness] [Battery]
```
### Waybar Requirements
Waybar must be compiled with Bluetooth support. Verify:
```bash
# Check waybar build flags
emerge -pv gui-apps/waybar | grep bluetooth
# If missing, rebuild with experimental flag
echo "gui-apps/waybar experimental" | sudo tee -a /etc/portage/package.use/waybar
sudo emerge -av gui-apps/waybar
```
## Common Tasks
### Connect Bluetooth Headphones
```bash
# Scan for devices
bluetooth-setup scan
# Note the MAC address of your headphones
# Pair (headphones must be in pairing mode)
bluetooth-setup pair AA:BB:CC:DD:EE:FF
# Connect
bluetooth-setup connect AA:BB:CC:DD:EE:FF
# Check connection
bluetooth-setup status
```
### Connect Bluetooth Mouse/Keyboard
```bash
# Same process as headphones
bluetooth-setup scan
bluetooth-setup pair XX:XX:XX:XX:XX:XX
bluetooth-setup connect XX:XX:XX:XX:XX:XX
```
### Auto-connect on Boot
Devices paired and trusted will auto-connect when in range:
```bash
# Pair and connect using bluetooth-setup
bluetooth-setup pair AA:BB:CC:DD:EE:FF
# The script automatically trusts paired devices
# Device will auto-connect on next boot
```
### Disable Bluetooth (Save Power)
```bash
# Turn off Bluetooth
bluetooth-setup power off
# Or stop the service
sudo rc-service bluetooth stop
```
## Troubleshooting
### Controller Not Found After Reboot
This indicates the kernel module issue wasn't resolved. Check:
```bash
# Verify btusb module has MediaTek support
modinfo btusb | grep -i mediatek
# Check which module is loaded
lsmod | grep btusb
# Verify config
grep CONFIG_BT_HCIBTUSB_MTK /boot/config-$(uname -r)
# Must show: CONFIG_BT_HCIBTUSB_MTK=y
```
If still broken, the kernel needs to be fully rebuilt:
```bash
cd /usr/src/linux
make -j16 && make modules_install && make install
grub-mkconfig -o /boot/grub/grub.cfg
reboot
```
### "Unknown symbol" Error When Loading btusb
If you see errors like `btusb: Unknown symbol btmtk_usb_suspend (err -2)`, this means there's a **module version mismatch**. This happens when you have old modules in `/lib/modules/.../updates/` that conflict with newly built modules in `/lib/modules/.../kernel/`.
**Symptoms:**
```bash
sudo modprobe btusb
# Error: modprobe: ERROR: could not insert 'btusb': Unknown symbol in module
dmesg | tail
# Shows: btusb: Unknown symbol btmtk_usb_suspend (err -2)
```
**Solution:**
```bash
# Copy newly built modules to /updates/ directory (which has higher priority)
sudo cp /lib/modules/$(uname -r)/kernel/drivers/bluetooth/btusb.ko \
/lib/modules/$(uname -r)/updates/btusb.ko
sudo cp /lib/modules/$(uname -r)/kernel/drivers/bluetooth/btmtk.ko \
/lib/modules/$(uname -r)/updates/btmtk.ko
# Update module dependencies
sudo depmod -a
# Unload old modules (if loaded)
sudo modprobe -r btusb btmtk
# Load new modules
sudo modprobe btmtk
sudo modprobe btusb
# Restart Bluetooth service
sudo rc-service bluetooth restart
# Verify controller appears
bluetoothctl list
```
**Explanation:** The `/lib/modules/.../updates/` directory has higher priority than `/lib/modules/.../kernel/` for module loading. After kernel rebuilds, you may have:
- Old modules in `/updates/` (from previous partial rebuild)
- New modules in `/kernel/` (from latest full rebuild)
Both `btusb.ko` and `btmtk.ko` must be from the **same build** to avoid CRC symbol mismatches.
### Device Won't Pair
1. **Make sure device is in pairing mode**
- Most devices: Hold pairing button until LED flashes
2. **Remove old pairing:**
```bash
bluetooth-setup remove AA:BB:CC:DD:EE:FF
```
3. **Power cycle Bluetooth:**
```bash
bluetooth-setup power off
sleep 2
bluetooth-setup power on
```
4. **Try again:**
```bash
bluetooth-setup pair AA:BB:CC:DD:EE:FF
```
### Device Connects But No Audio
For audio devices:
```bash
# Check if pulseaudio is running
pulseaudio --check || pulseaudio --start
# Or for pipewire
systemctl --user status pipewire
# Restart audio
pulseaudio -k && pulseaudio --start
```
### Bluetooth Disconnects Randomly
May be due to USB power management:
```bash
# Disable USB autosuspend for Bluetooth device
# Find the USB device
lsusb | grep MediaTek
# Disable autosuspend
echo 'on' | sudo tee /sys/bus/usb/devices/3-5.1/power/control
```
To make permanent, add to `/etc/udev/rules.d/50-bluetooth-power.rules`:
```
# Disable autosuspend for MediaTek Bluetooth
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0e8d", ATTR{idProduct}=="e025", ATTR{power/control}="on"
```
### Bluetooth Is Slow
Check signal strength and interference:
```bash
# Use bluetoothctl to check connection quality
bluetoothctl
> info AA:BB:CC:DD:EE:FF
# Look for RSSI value (signal strength)
```
Move device closer or remove sources of 2.4GHz interference (WiFi routers, microwaves).
## Technical Details
### Hardware Architecture
The MT7925 is a combo chip:
- **WiFi:** PCIe interface (shows as `wlp194s0`)
- **Bluetooth:** USB interface (shows as `hci0`)
Both share the same physical chip but use different interfaces.
### USB Device Details
```bash
# View USB device info
lsusb -v -d 0e8d:e025
# Shows:
# - Vendor: MediaTek Inc.
# - Product: Wireless_Device
# - Interfaces: 3 (Bluetooth, isochronous audio, control)
```
### Bluetooth Stack
```
Application (bluetooth-setup, bluetoothctl)
BlueZ (bluetoothd daemon)
Kernel HCI layer
btusb driver + btmtk support
USB interface (3-5.1)
MT7925 hardware
```
### Kernel Error: "Opcode 0x0c03 failed: -16"
This error appears in dmesg and indicates the Bluetooth firmware failed to load. It's caused by:
- Missing `CONFIG_BT_HCIBTUSB_MTK` kernel option
- Old btusb module loaded in memory
**Solution:** Reboot after kernel rebuild.
## Files and Locations
### Scripts
- `/usr/local/bin/bluetooth-setup` - Main Bluetooth management script
- `/usr/local/share/zsh/site-functions/_bluetooth-setup` - ZSH completion
### Configuration
- `~/.config/waybar/config` - Waybar Bluetooth module config
- `/etc/modules-load.d/bluetooth.conf` - Auto-load btmtk module
- `/etc/init.d/bluetooth` - Bluetooth service init script
### Firmware
- `/lib/firmware/mediatek/mt7925/BT_RAM_CODE_MT7925_1_1_hdr.bin` - BT firmware
### Kernel Modules
- `/lib/modules/6.12.41-gentoo-x86_64/updates/btusb.ko` - Updated USB Bluetooth driver (157 KB)
- `/lib/modules/6.12.41-gentoo-x86_64/updates/btmtk.ko` - MediaTek support module (64 KB)
### System
- `/sys/class/bluetooth/hci0/` - Bluetooth controller sysfs
- `/var/lib/bluetooth/` - Paired device database
## Related Documentation
- **WiFi Setup:** See `scripts/wifi-setup/README.md`
- **System Overview:** See `Claude.md`
- **Kernel Configuration:** See `kernel-6.12.41-gentoo-x86_64.config`
## Post-Reboot Checklist
After rebooting, verify:
- [x] `bluetoothctl list` shows a controller
- [x] `bluetooth-setup status` works
- [x] Waybar shows Bluetooth module
- [x] Can scan for devices: `bluetooth-setup scan`
- [ ] Can pair a device
- [ ] Can connect to a device
## Summary
**Current Status:** ✅ **FULLY WORKING** - Bluetooth controller operational!
**What was fixed:**
- ✅ Added `CONFIG_BT_HCIBTUSB_MTK=y` to kernel configuration
- ✅ Rebuilt btusb and btmtk drivers with MediaTek support
- ✅ Resolved module version conflict (copied new modules to `/updates/` directory)
- ✅ Created `/etc/modules-load.d/bluetooth.conf` for auto-loading btmtk
- ✅ Bluetooth service enabled at boot
- ✅ Created bluetooth-setup management script
- ✅ Added waybar Bluetooth module
- ✅ Installed ZSH autocompletion
**Bluetooth Controller:**
- MAC Address: F4:4E:B4:8A:E3:AC
- Manufacturer: MediaTek (0x0046)
- Firmware: `/lib/firmware/mediatek/mt7925/BT_RAM_CODE_MT7925_1_1_hdr.bin`
- Device: hci0
**Ready to use:** Bluetooth is fully functional and will persist across reboots! 🎉