# My Framework 13 AMD Edition
> currently a scratchpad :(
* AMD Ryzen 5 7640U with Linux (Pop!_OS)
* Expansion cards: 2 USB-C (in the rear position), 1 Type A, 1 HDMI
* Charger: Gigastone 100W charger -- 2C + 1A
My current boot parameter `/etc/kernelstub/configuration`:
* `rtc_cmos.use_acpi_alarm=1`: see [Preserve battery when in sleep](#Preserve-battery-when-in-sleep).
* `rootflags=subvol=@`: see [Filesystem setup (BTRFS)](#Filesystem-setup-BTRFS).
* `amdgpu.abmlevel=2`: see this thread, [Adaptive Backlight Management (ABM)](https://community.frame.work/t/adaptive-backlight-management-abm/41055). 3 and 4 are too aggressive to me.
* `iommu.strict=1`: for resolving `amdgpu` glitches.
## Installation
Official guides:
* Tutorial: https://guides.frame.work/Guide/Ubuntu+22.04+LTS+Installation+on+the+Framework+Laptop+13/109
* Final touch (included in the last step of the tutorial above): https://github.com/FrameworkComputer/linux-docs/blob/main/ubuntu-22.04-amd-fw13.md
* But I don't want to install OEM kernels, mainly due to GRUB, so drivers for some components (e.g., fingerprint sensor integration) most guides assume will be absent on my system
### Filesystem setup (BTRFS)
* The most informative guide I can find: https://mutschler.dev/linux/ubuntu-btrfs-20-04/ (but I skip all LUKS parts)
* https://wiki.manjaro.org/index.php/Btrfs#Familiar_with_btrfs-slang_.3F
## Useful resources
* ArchWiki, as always: https://wiki.archlinux.org/title/Framework_Laptop_13.
## Embedded controller (EC)
Tools (assuming no CrOS EC kernel module, see [this](https://github.com/FrameworkComputer/framework-system/issues/20)):
* ectool, unofficial utility to communicate with the embedded controller: https://gitlab.howett.net/DHowett/ectool.
Usage: `ectool --interface=lpc console`
* Framework provides an official one: https://github.com/FrameworkComputer/framework-system.
Usage: `framework_tool --driver portio --console recent`
## Power management
Mega thread: [[Guide] FW13 Ryzen Power Management](https://community.frame.work/t/guide-fw13-ryzen-power-management/42988).
Currently I use [`system76-power`](https://github.com/pop-os/system76-power) from master branch (just `cargo build` and then copy the result to replace `/usr/bin/system76-power` and restart the service for it), which is included by default in Pop OS, but seemingly missing several important parameters for saving power compared to PPD.
It is rumored that [auto-cpufreq](https://github.com/AdnanHodzic/auto-cpufreq) performs really well, but I don't have time to try.
BTW I found [this reply](https://community.frame.work/t/tracking-linux-battery-life-tuning/6665/407) and it seems to be effective:
```
# get its current value
$ cat /sys/module/pcie_aspm/parameters/policy
[default] performance powersave powersupersave
# set its value to "powersupersave"
$ echo powersupersave | sudo tee /sys/module/pcie_aspm/parameters/policy
powersupersave
```
## Misc issues
I did encounter some graphical glitches but very occasionly.
### Wireless networking
Setting regulation domain explicitly might help: https://www.linuxquestions.org/questions/slackware-14/network-manager-wifi-regional-settings-4175559295/
**But it does not work on my machine!** The region is default to US, and setting anything would lead to strange country "98".
### Touchpad is too sensitive
Say you want to change scrolling speed under X11 (10~50, default 15, larger is *slower*). Create a file at `/usr/share/X11/xorg.conf.d/30-touchpad.conf`:
```
Section "InputClass"
Identifier "Touchpad"
Driver "libinput"
MatchIsTouchpad "on"
Option "ScrollPixelDistance" "25"
EndSection
```
Takes effect on the next login.
#### For Firefox under X11
Set `MOZ_USE_XINPUT2=1` with some tweaks in `about:config`:
| Key | Value |
| ------------------------------ | ----- |
| apz.fling_friction | 0.005 |
| apz.gtk.pangesture.delta_mode | 2 |
| apz.gtk.touchpad_pinch.enabled | false |
### HW decoding in Firefox
It is disabled by default on AMD GPUs and can be enabled with `media.ffmpeg.vaapi.enabled` set to `true`. See [gfxinfo](https://sourcegraph.com/github.com/mozilla/gecko-dev@FIREFOX_ESR_115_3_X_RELBRANCH/-/blob/widget/gtk/GfxInfo.cpp?L974). The GPU only supports H264, VP9, AV1, which can be confirmed in <about:support>.
#### Monitoring the power consumption
I wonder if I can monitor these data to benchmark each solution: https://www.reddit.com/r/UsbCHardware/comments/rbwd1t/measuring_effective_power_received_on_a_usbc_port/
Framework's EC provides some information about active PD states (negotiated voltage and current) for each port.
EC log has an estimated drain time, but I cannot utilize it without polling. The output of `ectool` is longer, but I don't know why.
The handy `powerdraw` script: https://gist.github.com/guss77/c91e1d6583fad5b5c917eafc345cb81b
### Auto-adjustment of (screen) backlight is too crude
See https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/issues/575 for inspiration.
For now, I just disabled that option in GNOME and controlled it manually.
### Preserve battery when in sleep
There is some random wake up behavior observed: https://community.frame.work/t/resolved-systemd-suspend-then-hibernate-wakes-up-after-5-minutes/39392. Also, it is really annoying that closing the lid will wake up the OS from sleep.
Use [s2idle](https://gitlab.freedesktop.org/drm/amd/-/blob/master/scripts/amd_s2idle.py) script to detect problems. One common point it suggests is to add `rtc_cmos.use_acpi_alarm=1` into the boot parameter.
Note that it is not the lid open/close event itself that wakes up the system, but the extra IRQ interrupts whose effect is similar to a keystroke. So it happens even when the setting in the DM is disabled.
Disable lid wake up behavior through udev: https://community.frame.work/t/tracking-framework-amd-ryzen-7040-series-lid-wakeup-behavior-feedback/39128/45
TODO: SSD is fast nowadays, should really do hibernation when battery level matters (e.g., during travels).