Qualcomm Snapdragon 410/412 (MSM8916)

MSM8916/APQ8016 (or Snapdragon 410) is Qualcomm SoC released in 2014, with great mainline Linux support originally added for the Dragonboard 410c. There is a slightly higher clocked variant (CPU cores up to 1.4 GHz) available as Snapdragon 412.
== Devices ==
=== MSM8916 (Snapdragon 410) ===
=== APQ8016 (Snapdragon 410, WiFi-only) ===
The WiFi-only variant gt58wifi of samsung-gt58 is APQ8016.
The WiFi-only variant gt510wifi of samsung-gt510 is APQ8016.
=== MSM8916v2 (Snapdragon 412) ===
== Installation ==
All MSM8916 devices in postmarketOS use lk2nd as secondary bootloader. It does not replace the stock bootloader. Instead, it is flashed in place of an Android boot image, so that the stock bootloader will first load lk2nd instead of a regular Linux kernel. The advantage of this approach is that there is a consistent installation procedure for all MSM8916 devices (once lk2nd was installed), and various device-specific quirks can be handled within lk2nd.
=== Installing lk2nd ===
The instructions for installing lk2nd vary from device to device, so please check your device wiki page for instructions. Once you have lk2nd installed and working, you can proceed with the common installation procedure documented below.
=== Installation from pre-built image ===
Download a pre-built image as explained in the Installation article.
Unpack the compressed rootfs image (unxz *-<device>-*.img.xz) and with phone in "lk2nd mode" flash it to userdata partition. Do not forget to erase system partition to prevent accidental booting from it. For example:
 $ unxz --keep 20210202-0502-postmarketOS-edge-plasma-mobile-3.2-samsung-a5lte-mainline-modem.img.xz
 $ fastboot flash userdata 20210202-0502-postmarketOS-edge-plasma-mobile-3.2-samsung-a5lte-mainline-modem.img
 $ fastboot erase system
 $ fastboot reboot
You can safely ignore the small *-<device>-*-boot.img.xz file.
Enjoy postmarketOS!
(If the image has a pin on it try 0000, 1111, 1234 or 147147)
=== Installation using pmbootstrap ===
Follow the Installation/Using pmbootstrap article to build your own fully customized image, with many more UIs to choose from and other options. Below are MSM8916 specific notes.
During pmbootstrap init you may get prompted to select a provider for soc-qcom-msm8916-rproc: If you don't want to use the modem on your device (e.g. if your device is a tablet with APQ8016), you may want to pick no-modem.
Large phone UIs like Plasma Mobile or Phosh are too big for the system partition, so either install to the SD card:
$ pmbootstrap install --sdcard=/dev/mmcblk...
Or put your phone into lk2nd mode and flash to the userdata partition. Ignore the hint in the pmbootstrap output that pmbootstrap flasher flash_kernel should be used, this is not necessary. lk2nd will boot the kernel image from the installed rootfs.
$ pmbootstrap install
$ pmbootstrap flasher flash_rootfs --partition userdata
$ fastboot erase system
$ fastboot reboot
Enjoy postmarketOS!
=== Switching rproc mode ===
On msm8916 devices it's possible to choose if you want the remote processors (such as wifi and modem) to be enabled or not. You can change the mode by installing one of those packages by running sudo apk add soc-... on your device. (You may need to uninstall other rproc mode package first.)
* 
* 
* 
Disabling the remote processors frees up a bit of RAM that they would otherwise use (~80 MB of ram for modem) so you may want to disable the modem if you install the system on an APQ8016 device where the modem core is currently unused.
== Battery ==
Unfortunately, the battery/charging drivers are device-specific and hard to validate without expert knowledge. The level of battery/charging support can be seen in the "Battery" status row on the device page:
* Broken/Empty: Not supported, can not even check remaining battery capacity.
* Partial: Can check remaining battery capacity, but not charging status. Charging may or may not work, and may or may not be dangerous on long-time use.
* Working: Both battery/charging drivers are working. Charging works but is unlikely to be validated for safety.
== Audio ==
===Pipewire===
Seem to be broken
=== PulseAudio ===
Audio should work out of the box with PulseAudio. In your favorite PulseAudio mixer (e.g. pulsemixer on the command line) you can select the output port to use (e.g. Speaker, Earpiece, ...).
Note: If you use pulsemixer you can switch between output/input configuration with F1/F2, or loop with Tab/Shift+Tab. To select a particular output/input device press Enter and choose Set port.
=== ALSA ===
Everything is muted by default and must be enabled through alsaucm. Unfortunately, the tool is not very user-friendly.
 $ alsaucm -i -c hw:0
 set _verb HiFi
 set _enadev <device>
where <device> is one of Speaker, Earpiece, Headphones, Mic1, Mic2 or Headset.
alsaucm does not track which devices are already enabled, therefore it is possible to produce combinations that won't work properly (e.g. Headphones+Earpiece). To switch between devices, the old device first needs to be re-enabled and then disabled:
 $ alsaucm -i -c hw:0
 set _verb HiFi
 set _enadev OLD
 set _disdev OLD
 set _enadev NEW
== Modem ==
If you install via pmbootstrap, pick "all" as rproc provider and make sure to agree to the usage of non-free firmware (required for the modem). Prebuilt images should have the modem working out of the box.
Note that this changes the way audio is routed on the device:
* Without modem, audio is routed directly to the audio hardware, and works without the need for non-free firmware.
* With modem running, audio must be routed through the audio DSP, which requires non-free firmware.
Therefore you should choose the kernel depending whether or not you would like to run the modem. Note: for WiFi-only (APQ) variants no-modem does not imply no gnss.
For usage instructions, see Modem.
=== GNSS (GPS) ===
On Qualcomm devices GNSS is usually part of the modem. ModemManager and libqmi (with qmicli) can configure and use the modem Location service (as long as the modem device is present). Applications like Pure Maps can use ModemManager interface directly, however you may need to enable the gps module: 
 $ mmcli -m any --location-enable-gps-nmea
Alternatively you can run gpsd to read NMEA output from qmicli. An example of that would be the following (you still need ModemManager to run as it will keep the connection with the modem open):
First command will enable the location service on the modem and give you CID to attach to in the second command.
 $ sudo qmicli -pd /dev/modem --loc-start --client-no-release-cid
 $ sudo qmicli -pd /dev/modem --loc-follow-nmea --client-cid=2 | gpsd -bnN /dev/stdin
There is a several year old merge request to the gpsd that adds the support for GNSS via Qualcomm modem (PDS service).
 Hardware variants / alternative use cases
SOC	sim-card?	software 	gps available? 	gps fix? 	comment
MSM	no 	mmcli 1.22 	no 	no 	not supported mmcli <= v1.22 (TBD v1.24?)
MSM	no 	qmicli 1.34 	partial? (nmea-types)	no or WIP?	-pd qrtr://0 ?? command order / structure undocumented (if any)
MSM	no 	gpsd 3.25 	no 	no 	no PDS driver
MSM	no 	gpsd-pds ~3.22	yes 	yes 	downstream PDS driver (Linaro)
APQ	N/A 	mmcli 1.22 	no 	no 	(rproc-all) error: couldn't find modem
APQ	N/A 	qmicli 1.34 	partial? (nmea-types) 	no or WIP?	-pd qrtr://0 ?? command order / structure undocumented (if any)
APQ	N/A 	gpsd-pds ~3.22	yes 	yes 	downstream PDS driver (Linaro)
Notes:
GPS operation through mmcli without a sim-card is not yet supported; for APQ, there is no /dev/modem. 
Here, "gpsd-pds" is shorthand for "unpackaged patched downstream known-good pds-driver-patched gpsd".
== GPU ==
Snapdragon 410 uses Adreno 306 GPU and it's supported by the Freedreno driver in Mesa. While many applications work as-is, the driver isn't perfect and some applications may crash it. In some cases the GPU crash can lead to full system restart. If you see such behavior, you can try following workarounds:
* OpenGL ES 3.0 seems to cause system crashes in some cases (e.g. in SuperTuxKart). You may try to override the GLES version with an environment variable. For example: MESA_GLES_VERSION_OVERRIDE=2.0 supertuxkart
* If no other workaround works, you may have to use fully software rendering. Use like: LIBGL_ALWAYS_SOFTWARE=true supertuxkart.
You can find a full list of environment variables in the Mesa documentation.
=== Firefox ===
In particular, Firefox can struggle with hardware acceleration, making it completely unusable. To disable hardware acceleration:
* Run Firefox from the command line, disabling software rendering: LIBGL_ALWAYS_SOFTWARE=true firefox-esr (or firefox if you use the non-ESR version)
* Go into the settings, search for "hardware acceleration"
* Uncheck "Use hardware acceleration when available"
Alternatively:
* Go to about:config, click through the warning
* Search for layers.acceleration.disabled and set it to true
This issue is tracked as and .
== Troubleshooting == 
*;Screen doesn't work in Linux but works in lk2nd.: Your device may have a display panel that wasn't enabled yet as msm8916 team only enables known working display panels. You can check the config files in linux-panel-drivers repository to see if the panel that is listed on lk2nd screen is enabled there. Contact msm8916 maintainers via Matrix. You can also build the panel driver yourself, consult the MSM8916 Mainlining guide for that.
*;CPU runs at most at 998 MHz but it should be capable of running at 1200 MHz.: While the specifications of MSM8916 have 1200 MHz as max clock speed, currently the max MHz the CPU will operate with pmOS is 998 MHz. There are WIP changes available to make it work (https://github.com/TravMurav/linux/tree/cpr). Display the frequency range with cpufreq-info -l (units are kHz).
*;Device is slow to turn display on after it was left for a while. Calls don't wake it up as well.: Suspend is not yet fully implemented, please see the "Suspend" section below.
*;I've put a SIM into the device, but it's not detected.: Check, if your sim works with original OS and can register on a 4G network. Check if increasing sim_wait_time in /etc/conf.d/msm-modem-uim-selection fixes the issue.
== Suspend ==
Suspend is not yet fully implemented. For example, incoming calls do not wake up the phone . It's recommended to disable suspend.
=== Kernel config ===
To make sure you have suspend disabled in kernel config:
$ grep CONFIG_SUSPEND /boot/config 
# CONFIG_SUSPEND is not set
$ zcat /proc/config.gz | grep -i config_suspend #booted device
=== Phosh ===
In Phosh, it can be disabled in Tweaks -> Power.
Or you can execute this in a terminal:
$ gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type 'nothing'
$ gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
For SSH sessions:
$ DISPLAY=:0 gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type 'nothing'
$ DISPLAY=:0 gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
=== Plasma Mobile ===
For Plasma Mobile, disabling suspend in the settings currently doesn't work. Use command kcmshell5 powerdevilprofilesconfig in the terminal to call another settings page that works.
== Mainlining ==
* MSM8916 is a great platform to get started with mainlining! It has a dedicated MSM8916 Mainlining guide that explains how to get started.
== See also ==
* lk2nd
* Qualcomm Snapdragon 615/616 (MSM8939)
* Qualcomm Snapdragon 210 (MSM8909)
*