Xiaomi POCO F1 (xiaomi-beryllium)

Another great phone based on Qualcomm Snapdragon 845 (SDM845).
Get the schematics here.
== How to enter flash mode ==
You have to press + to enter the bootloader.
== Know your panel variant ==
There are two variants of the Xiaomi Poco F1 with different display panels and touchscreens.
1. EBBG Panel (and Focaltech touchscreen) - dsi_ebbg_fhd_ft8719_video_display
2. Tianma Panel (and Novatek touchscreen) - dsi_tianma_fhd_nt36672a_video_display
To know your panel variant, get into a terminal with root access (you can use TWRP recovery's terminal as it has root access or rooted android ROM)
1. Run su to make sure you have root access
2. Run cat /proc/cmdline. Output would be similar to:
rcupdate.rcu_expedited=1 console=tty0 earlycon=msm_geni_serial,0xA84000 androidboot.hardware=qcom androidboot.console=ttyMSM0 video=vfb:640x400,bpp=32,memsize=3072000 msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 service_locator.enable=1 swiotlb=2048 androidboot.configfs=true loop.max_part=7 androidboot.usbcontroller=a600000.dwc3 root=/dev/dm-0 dm="system none ro,0 1 android-verity /dev/sde48" androidboot.verifiedbootstate=orange androidboot.keymaster=1 androidboot.veritymode=enforcing androidboot.bootdevice=1d84000.ufshc androidboot.serialno=b79782d2 androidboot.baseband=sdm msm_drm.dsi_display0=dsi_tianma_fhd_nt36672a_video_display: androidboot.ramdump=disable androidboot.secureboot=1 androidboot.dp=0x0 androidboot.cpuid=0x205772eb androidboot.hwversion=4.19.0 androidboot.hwc=INDIA androidboot.cert=M1805E10A androidboot.hwlevel=MP
4. Note the value of msm_drm.dsi_display0. In the example above, it's dsi_tianma_fhd_nt36672a_video_display, i.e Tianma panel variant. For EBBG panel variant, it would be dsi_ebbg_fhd_ft8719_video_display
During pmbootstrap init, select the kernel variant by choosing either tianma or ebbg based on the output from above.
== Installation ==
In order to install postmarketOS the bootloader must be unlocked.
Unlocking is done by following the official process provided by Xiaomi (read the FAQ for detailed instructions).
It is possible to either use a pre-built image as explained in the installation article, or to use pmbootstrap to build your own image.
It's highly recommended to update your bootloader; see below for more details.
1. Run pmbootstrap init and select xiaomi as vendor and beryllium as device.
2. Select the Kernel variant based on the panel noted from the "Know your panel variant" section above.
3. Follow the onscreen instruction and configure as your needs.
4. Build the system
pmbootstrap install
add --fde if you need full disk encryption (FDE) 
and 
--filesystem f2fs for an emmc friendly filesystem.
5. Flash the kernel and rootfs:
pmbootstrap flasher flash_kernel
pmbootstrap flasher flash_rootfs --partition userdata
fastboot reboot
=== Installation to SD card ===
You can take advantage of Poco F1's SD card slot to install postmarketOS for testing.
Install to the SD card:
$ pmbootstrap install --sdcard=/dev/mmcblk0
To boot from SD, with the device in fastboot mode (with device off, press Power + Volume Down until it enters fastboot mode), type:
$ pmbootstrap flasher boot
Note: This uses pmbootstrap from your computer to boot postmarketOS from the SD card without disturbing your bootloader or your system.
=== Installation using a prebuilt image (fastboot) ===
Turn off your device, press volume down + power until the device enters bootloader/fastboot mode. Make sure you've installed android-tools or a similar package providing the "fastboot" program on your computer, with the appropriate drivers on Windows.
Download the both the -boot.img.xz and the main system's .img.xz (see above about picking the appropriate variant), then do the following (using the image filename at the time of writing as an example):
$ unxz -v 20230212-1217-postmarketOS-v22.12-plasma-mobile-3.9-xiaomi-beryllium-ebbg-boot.img.xz
$ fastboot flash boot 20230212-1217-postmarketOS-v22.12-plasma-mobile-3.9-xiaomi-beryllium-ebbg-boot.img
$ unxz -v 20230212-1217-postmarketOS-v22.12-plasma-mobile-3.9-xiaomi-beryllium-ebbg.img.xz
$ fastboot flash userdata 20230212-1217-postmarketOS-v22.12-plasma-mobile-3.9-xiaomi-beryllium-ebbg.img
$ fastboot reboot
Read the official pmbootstrap documentation for more info.
=== Updating the bootloader ===
This involves downloading MIUI and extracting bootloader images to flash. Refer to the LineageOS wiki for more info.
= Mainline status =
== Display ==
Works fine. MSM DRM based panel. 
The Tianma variant is already in mainline Linux. 
The EBBG panel variant is available in our kernel fork and works fine, but it is not upstreamed yet.
If you're running Phosh and have no camera notch in the top panel (clock invisible), create a file ~/.phoshdebug with this content:
GMOBILE_DT_COMPATIBLES=xiaomi,beryllium
export GMOBILE_DT_COMPATIBLES
(#3458)
Then restart Phosh: doas service tinydm restart
Brightness can be adjusted. The PMI8998 QCOM WLED driver from mainline is used for brightness adjustment.
== Touchscreen ==
For the Tianma variant, there are patches available for the NT36XXX touchscreen over here: https://lwn.net/ml/linux-kernel/20201028221302.66583-1-kholk11@gmail.com/
Its still not accepted. But works fine with some fixes and included in our fork. 
For the EBBG variant, Venji10 has written downstream based driver for focaltech touchscreen. Its not upstreamed yet. Included in our fork and works fine.
== 3D GPU Acceleration ==
Since our panels are MSM DRM based, 3D acceleration works perfectly fine using the freedreno driver from mainline.
But firefox still seem to have a problem with hardware acceleration/gpu support.
== WiFi ==
2.4Ghz WiFi connection works perfectly fine.
However, 5Ghz WiFi network has poor signal reception or goes offline after a few minutes. Requires fix (is there an issue open?).
If you have issues connecting to the wifi, double check dmesg. If the following lines are in dmesg:
[ 302.291007] wlan0: authenticate with c0:06:c3:b6:d0:f6
[ 302.291066] wlan0: bad VHT capabilities, disabling VHT
[ 302.291070] wlan0: 80 MHz not supported, disabling VHT
Then you must change the wifi width from 80 MHz to 20 MHz in your router's settings. The regulatory region gets selected as CN (China) which causes this issue.You can change the regulatory region by following the instructions here: Change regulatory region
Do not forget to add packages during pmbootstrap init, or you won't be able to change regulatory region after installation:
Sometimes, even if those lines are in dmesg it can still connect to the Wi-Fi (after a few more tries, disabling and enabling Wi-Fi until eventually it succeeds)
[20:23:45] Extra packages [none]: iw,wireless-regdb
== Bluetooth ==
The Bluetooth service crashes on boot and requires a restart in Phosh. (Still valid?)
sudo service bluetooth restart
Now you should be able to see the devices show up in Settings->Bluetooth and to pair from the UI.
If you want to switch off and on the bluetooth in Phosh, use Settings->Power->Bluetooth toggle and not the Settings->Bluetooth toggle as it doesn't seem to work properly. Requires fix eventually.
== Audio ==
Almost all audio devices work (Speakers, Earpiece, Headphones+Mic, Phone Bottom Mic, Bluetooth headphones+Mic).
Except for the Top mic. It doesn't work for some weird reason and on some devices headphone detection is not working (workaround: plug them in and reboot).
The userspace ALSA UCM confs are available in our repo.
Headphones+Mic & Phone Internal Mic are already in mainline dts. 
The TAS2559 driver requires a rewrite and needs to be upstreamed. Included in our fork.
PipeWire has some serious issues with Sound, you'll encounter the following issues:
*Calls not working
*No Microphone input
*Very low volume
*Distortion
*Softlocks (rare)
For reliable audio, especially calls, switch from Pipewire to Pulseaudio (dont mess with the configurations in pavucontrol before you do the switch!):
sudo apk add sxmo-utils-audio-pulseaudio
sudo apk del sxmo-utils-audio-pipewire
sudo apk del postmarket-os-base-ui-audio-pipewire
sudo apk del pipewire
You may need to forcibly remove wireplumber on existing installations of postmarketos edge:
sudo apk del --force-broken-world wireplumber
sudo apk del --force-broken-world pipewire
sudo apk upgrade -a
Check this issue..
== Battery ==
Caleb and Joel wrote the pmi8998-charger driver with basic functionalities such as charge percentage, temperature, USB plug in and out detection, therefore, basic charging works.
But this still requires quite some rework to make it generic and stable. It lacks on several issues, including no fast charging support and sometimes reporting charging when its not.
=== OTG ===
It would also be needed to enable USB OTG feature.
Caleb started an approach with an usb-c driver and a new charging driver, see here. Sam figured out that this already works quite promising after disabling 
usr/lib/NetworkManager/dispatcher.d/50-tethering.sh
usr/lib/NetworkManager/conf.d/50-tethering.conf
.
== GPS ==
GPS works as expected and can be used for navigation!
Carefully read Troubleshooting:GPS for more details on how to activate the GPS using ModemManager's CLI, enabling Geoclue and also on how to use gps without sim card.
== Camera ==
With latest 6.11 kernel and Phosh, camera works out of the box! 
For Sxmo, set a rule:
sudo touch /etc/udev/rules.d/90-camera.rules
containing:
KERNEL=="udmabuf",GROUP="video",MODE="0660"
give access to the device:
sudo chmod 777 /dev/udmabuf
sudo chmod 777 /dev/urandom # not sure about this
reboot and snapshot is working!
To get megapixels1.x working, we need this config file copied to /usr/share/megapixels/config/xiaomi,beryllium.ini
For megapixels2.x, we need this config file, copied to the directory mentioned above, or, when self compiled, to /usr/local/share/megapixels/config/xiaomi,beryllium.conf.
Make sure to manually lower the shutter and iso values in megapixels.
To dramatically increase image quality, install gmic (available on edge, not v24.12) and copy these postprocessing scripts to /usr/share/megapixels/postprocessor.d/. The postprocess_auto.sh is good for general color correction. Select it before hitting the shutter.
The Camera register configurations can be observed by enabling CAMSS debug in downstream android kernel and noting the logs for lines similar to CAM-CCI: cam_cci_data_queue: 741: cmd_size 24 addr 0x136 data 0x18
The Poco F1 Camera Configuration I have noted so far:
---------------------------------------------------------------------------------------
COMMON CONFIG
---------------------------------------------------------------------------------------
CAM_IOVDD_EN 		| gpio50 	| tlmm		| vreg_s4a_1p8		| 1.8V
CAM_LDO_EN		| gpio99	| tlmm		| No idea		| 1.35V
---------------------------------------------------------------------------------------
Front Cam 1 - Samsung S5K3T1 (20MP)
---------------------------------------------------------------------------------------
CAM_F1_RSTN 		| gpio104 	| tlmm		| -
FRONT_CAM1_AVDD_EN 	| gpio29 	| tlmm		| vreg_bob
FRONT_CAM1_DVDD_EN	| gpio9		| pmi8998	| vreg_s3a_1p35
---------------------------------------------------------------------------------------
Rear Cam 1 - Sony IMX363 (12MP), I2C Address (0x10)
---------------------------------------------------------------------------------------
CAM_R1_RSTN		| gpio80	| tlmm		| -
REAR_CAM1_AVDD_EN 	| gpio40 	| tlmm		| vreg_bob		| 2.8V
REAR_CAM1_DVDD_EN	| gpio11	| pmi8998	| vreg_s3a_1p35		| 1.35V
---------------------------------------------------------------------------------------
Front Cam 2 - OV7251 ??
---------------------------------------------------------------------------------------
CAM_F2_RSTN 		| gpio25 	| tlmm		-
FRONT_CAM2_AVDD_EN 	| gpio91 	| tlmm
FRONT_CAM2_DVDD_EN 	| gpio7 	| tlmm
---------------------------------------------------------------------------------------
Rear Cam 2 - Samsung S5K5E8 (5MP)
---------------------------------------------------------------------------------------
CAM_R2_RSTN		| gpio28	| tlmm		-
REAR_CAM2_AVDD_EN	| gpio79	| tlmm
REAR_CAM2_DVDD_EN	| gpio92	| tlmm
---------------------------------------------------------------------------------------
== Sensors ==
SDM845 devices use the SLPI for sensor connectivity 
initial support was added in .
The following packages are required on the user-side to enable sensors:
hexagonrcpd
libssc
iio-sensor-proxy
See also 
Setting polkit to access without root:
Copy this to /etc/polkit-1/rules.d/01-sensor-claim.rules 
== Proximity Sensor ==
As mentioned above, works after installing iio-sensor-proxy.
Test it with:
monitor-sensor --proximity
To get it working for calls in sxmo, you might need a custom script.
== LEDs ==
Torch and status led are accessable via kernel moduls, e.g.
enabling the status led next to the usb port:
echo 255 > /sys/class/leds/white:status/brightness
== NFC ==
There is no NFC hardware on this device.
== Fingerprint ==
Read this.
Get a working driver here
== Vibrator ==
Works.
== SDcard ==
The SDcard slot works and you can mount and use SDcards.
There might be SIM issues, see DualSIM section below.
== Mobile Data, Calls and SMS ==
Calls and SMS work fine, but as there is no convenient way to enter a SIM PIN, you should remove the PIN from your SIM card when inserted in some Android phone.
Mobile data can be more tricky. If mobile data does not work (an orange exclamation mark over the cellular icon might indicate this), make sure that you obey the following order:
* Disable "Mobile Network" and enable Wi-Fi (unclear: Is Internet access needed?).
* Turn on "Mobile Network" and "Mobile Data", enter your APN when asked and not appearing automatically.
== Dual SIM ==
Although there is no dual SIM support yet, Second SIM slot can be activated as primary sim slot; Which is necessary if we want to use the SD Card.
If you don't switch to the second SIM slot but have the SIM card in the second slot, you will not be able to unlock the SIM using its PIN code.
So if you can't unlock your SIM, check if the SIM is physically in the right slot that the modem thinks it should be.
Get the Application ID (AID) of the SIM:
$ sudo qmicli -d qrtr://0 --uim-get-card-status
Switch the SIM slot:
$ sudo qmicli -d qrtr://0 --uim-switch-slot=2
Provision the SIM slot:
$ sudo qmicli -d qrtr://0 --uim-change-provisioning-session="slot=1,activate=yes,session-type=primary-gw-provisioning,aid=[AID from previous step]"
In case you receive errors in the last step, reboot the phone and try the last step again.
== Mobile Data Problems ==
libqmi has support for QRTR+IPA based modems for quite some time, as seen in the repo: https://gitlab.freedesktop.org/mobile-broadband/libqmi/-/merge_requests?scope=all&search=qrtr&state=merged
ModemManager which uses libqmi to control the modem has added support for QRTR recently: https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/470
Inspite of all this, some Poco F1 users have mobile data connection issues on some mobile networks. During mobile data connection, it fails with the following errors
[2441]: <info> [024233428.438170] [modem0/bearer1] couldn't start network: QMI protocol error (14): 'CallFailed'
[2441]: <info> [024233428.438253] [modem0/bearer1] call end reason (3): generic-no-service
Once reported about it over here: https://gitlab.freedesktop.org/mobile-broadband/libqmi/-/merge_requests/235#note_893224. Still have to properly submit a bug report on this.
You can show an overview what the modem manager sees as follows:
sudo mmcli -m 0 # Warning: output includes personal data
sudo mmcli -m 0 | grep -v -e imei -e Numbers -e equipment # excludes some personal data
== Change Kernel parameters ==
1, sudo vim /etc/deviceinfo
2, Change cmdline parameters to desired state
3, sudo apk fix linux-postmarketos-qcom-sdm845
= Community Info =
== Maintainers ==
* Venji10
* User:Joel
== Users owning this device ==
== See also ==
* Initial merge request
* SDM845 Mainline kernel: https://gitlab.com/sdm845-mainline/linux
* Another old WIP mainline kernel by Venji10: https://github.com/Venji10/linux-beryllium
* Attempt at fixing PipeWire issues with Pocophone F1
* Xiaomi POCO F1 (xiaomi-beryllium)/sxmo
* Update firmware on Xiaomi Poco F1 (BitTorrent mganet-link and eMule mganet-link)
* MiFlash unlock tool 7.6.727.43 direct download link