unmaintained/xiaomi-wt88047-downstream: new device (Xiaomi Redmi 2) (MR 2085)

This device port is unmaintained: The mainline port (xiaomi-wt88047)
is preferred. This is only intended for testing, and was used to validate
the battery/charging driver as one example. Various patches are used
for the downstream kernel that expose helpful information for debugging.

[ci:skip-build]: already built successfully in CI
This commit is contained in:
Minecrell 2021-02-14 17:11:21 +01:00 committed by Dylan Van Assche
parent 08acabdb05
commit 3d50fe77da
No known key found for this signature in database
GPG key ID: 8642571587897EA1
14 changed files with 4202 additions and 0 deletions

View file

@ -0,0 +1,23 @@
# Unmaintained: Downstream port, only for testing. Use mainline port (xiaomi-wt88047)!
# Reference: <https://postmarketos.org/devicepkg>
pkgname=device-xiaomi-wt88047-downstream
pkgdesc="Xiaomi Redmi 2 (Downstream)"
pkgver=1
pkgrel=0
url="https://postmarketos.org"
license="MIT"
arch="armv7"
options="!check !archcheck"
depends="postmarketos-base linux-xiaomi-wt88047-downstream mkbootimg mesa-dri-gallium msm-fb-refresher"
makedepends="devicepkg-dev"
source="deviceinfo"
build() {
devicepkg_build $startdir $pkgname
}
package() {
devicepkg_package $startdir $pkgname
}
sha512sums="f03ad78b28c93066e3d5794c4853288f587f92774f1e370adc5211a6f084751ca63aa3f608693282411b018d227ceb0bfb0cda0d2199c6e624af1d9807c043a4 deviceinfo"

View file

@ -0,0 +1,34 @@
# Reference: <https://postmarketos.org/deviceinfo>
# Please use double quotes only. You can source this file in shell
# scripts.
deviceinfo_format_version="0"
deviceinfo_name="Xiaomi Redmi 2"
deviceinfo_manufacturer="Xiaomi"
deviceinfo_codename="xiaomi-wt88047-downstream"
deviceinfo_year="2015"
deviceinfo_dtb=""
deviceinfo_modules_initfs=""
deviceinfo_arch="armv7"
# Device related
deviceinfo_chassis="handset"
deviceinfo_keyboard="false"
deviceinfo_external_storage="true"
deviceinfo_screen_width="720"
deviceinfo_screen_height="1280"
# Bootloader related
deviceinfo_flash_method="fastboot"
deviceinfo_kernel_cmdline="console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom msm_rtb.filter=0x237 ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1 loop.max_part=7 phy-msm-usb.floated_charger_enable=1 buildvariant=userdebug"
deviceinfo_generate_bootimg="true"
deviceinfo_bootimg_qcdt="true"
deviceinfo_bootimg_mtk_mkimage="false"
deviceinfo_bootimg_dtb_second="false"
deviceinfo_flash_offset_base="0x80000000"
deviceinfo_flash_offset_kernel="0x00008000"
deviceinfo_flash_offset_ramdisk="0x02000000"
deviceinfo_flash_offset_second="0x00f00000"
deviceinfo_flash_offset_tags="0x01e00000"
deviceinfo_flash_pagesize="2048"
deviceinfo_flash_sparse="true"

View file

@ -0,0 +1,81 @@
# Unmaintained: Downstream port, only for testing. Use mainline port (xiaomi-wt88047)!
# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm/configs/lineageos_wt88047_defconfig
pkgname=linux-xiaomi-wt88047-downstream
pkgver=3.10.108
pkgrel=0
pkgdesc="Xiaomi Redmi 2 downstream kernel fork"
arch="armv7"
_carch="arm"
_flavor="xiaomi-wt88047-downstream"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="bash bc bison devicepkg-dev flex openssl-dev perl dtbtool gcc4"
# Compiler: GCC 4
if [ "${CC:0:5}" != "gcc4-" ]; then
CC="gcc4-$CC"
HOSTCC="gcc4-gcc"
CROSS_COMPILE="gcc4-$CROSS_COMPILE"
fi
# Source
_repository="android_kernel_wingtech_msm8916"
_commit="beb5692ed25808aebce7b57e318cf8bd33e645d8"
_smb_tag="v5.11.7-msm8916"
_config="config-$_flavor.$arch"
source="
$pkgname-$_commit.tar.gz::https://github.com/LineageOS/$_repository/archive/$_commit.tar.gz
$_config
bq2022a-batid-debug.patch
cpr-dump.patch
gpio-debug.patch
memshare-debug.patch
remove-gcc-wrapper.patch
smb1360-debug.patch
smb1360-dump-wt88047.patch
smb1360-dump-$_smb_tag.c::https://raw.githubusercontent.com/msm8916-mainline/linux/$_smb_tag/drivers/power/supply/smb1360-dump.c
smb1360-like-mainline.patch
smb1360-fix-safety-timer-wt88047.patch
wt88047-smb1360-like-mainline.patch
"
builddir="$srcdir/$_repository-$_commit"
_outdir="out"
prepare() {
# wt88047 has a modified copy of smb1360-charger-fg.c but the patch works for it :)
sed -i 's/smb1360-charger-fg.c/smb1360-charger-fg-wt88047.c/g' "$srcdir"/smb1360-*.patch
cp "$srcdir/smb1360-dump-$_smb_tag.c" drivers/power/smb1360-dump.c
default_prepare
. downstreamkernel_prepare
}
build() {
unset LDFLAGS
make O="$_outdir" ARCH="$_carch" CC="$CC" HOSTCC="$HOSTCC" \
KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
}
package() {
downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor" "$_outdir"
# Master DTB (deviceinfo_bootimg_qcdt)
dtbTool -p scripts/dtc/ -o "$pkgdir"/boot/dt.img "$_outdir/arch/$_carch/boot/"
}
sha512sums="0c4375a54f2cb324e2bc8f6fc1279d2970b92ee86c10e7c954811c22aac6d9f4a263a43fe9e98bfe78aa6ea425e049eec080964ee33015fe129cf2d8972eb4ac linux-xiaomi-wt88047-downstream-beb5692ed25808aebce7b57e318cf8bd33e645d8.tar.gz
de9f775b6ad1dd3750b79028d3bb99863afddae433016af56bff31f3e756f180c8ecd0c458d9153a24c8b16e63bbc3ee8f9bb21aa1aa31eeff928dfd58ea5fc0 config-xiaomi-wt88047-downstream.armv7
be82480d4f05852161f714a0c0cb48c16ed2be7ff9d1cb93bddf5858e5229315e9be548582bdd6f8129d8e1a2a8a7e243a402d2e53acb23242c0fce53299f1c6 bq2022a-batid-debug.patch
f040a1d7169b9ddb5baabb7de1838441e8608894dc6dc61ececb1acb4fe9851289934b37d74afb61addc01d7a1e4f1d2413f5e542c2a4aeb0c01f680797d37c6 cpr-dump.patch
e9f809b6659375cd7e854821f9925faa263d287c06e44071017cd4afb32f79c47e63760c9c95b4f0c15b79b6b1af4a36911861104a7b56dea2195baf9e4f4685 gpio-debug.patch
56083a8b290a7b1b1ffc9c8e3333db6d786a20d6e91ee400e895ecee8d31cccc75d809be13bcfe5cfb7d5b53a687b25281e8fd454cf420468ded3f77dcea9897 memshare-debug.patch
4a09fdcf99a4716a4ced11b7d74b7867423e5f6fa6c62674e57f496a10647c0b704fd5f91c46711e363337b54d3b7917b6c685230568eab44b6303bd285a2b61 remove-gcc-wrapper.patch
3507cd892cf7a07d924c457de746aae232230489ce1810bd8c97fb45817ddf952afd9605243aee63772a6572afa65f2914f307e183aa24fef1c33f98bec036bc smb1360-debug.patch
25405fa68442bc5ce5e2d8bf3a908ca4cf556633f66478523d1db2db76d11af255f9992412a110b5ffcf06692e26d82b6ad3886dacd5b67ea3944d468405b6b1 smb1360-dump-wt88047.patch
f61902474ab221a85a8910dcfbc48736e323a6bbc83896f778bb87d356464679c62ddf1c583e660a5c3c790dba420cce6cb9ca59b720234846dac7e80aa47368 smb1360-dump-v5.11.7-msm8916.c
2fe3899a925efae3f7845ae2a9c9a0198595b2311616dbc8bf754da69634cf730cf766d6378ea9d6096a1b9f165c7c7104e7e12a7020cf09c31b48d49117ba83 smb1360-like-mainline.patch
30f6466b5b1389c6b38838d7e7d6da0d4dd3dd94efa9e69d42c6551572121a716014f788de621a41a1d59c9d24768b4a321c9a2e02d2a640b0205412d81fd363 smb1360-fix-safety-timer-wt88047.patch
4a3021b331303b6e618dbc15f4de3c4bf7516d9c779204e88f1233243b535086434cb33c022ea25fd6cb3f0fe5f599074255b212a22dfda9d7a47b48794dd701 wt88047-smb1360-like-mainline.patch"

View file

@ -0,0 +1,12 @@
Enable debug prints for bq2022a-batid. This is used for battery detection
on xiaomi-wt88047. Similar code is used for mainline within the lk2nd bootloader.
diff --git a/drivers/power/bq2022a-batid.c b/drivers/power/bq2022a-batid.c
index c806eca2ce8..90d274482b4 100644
--- a/drivers/power/bq2022a-batid.c
+++ b/drivers/power/bq2022a-batid.c
@@ -1,3 +1,4 @@
+#define DEBUG
#define pr_fmt(fmt) "BQ2022A:%s: " fmt, __func__
#include <linux/init.h>

View file

@ -0,0 +1 @@
../../.shared-patches/linux/qcom/msm8916/cpr-dump.patch

View file

@ -0,0 +1 @@
../../.shared-patches/linux/qcom/msm8916/gpio-debug.patch

View file

@ -0,0 +1 @@
../../.shared-patches/linux/qcom/msm8916/memshare-debug.patch

View file

@ -0,0 +1 @@
../../.shared-patches/linux/qcom/msm8916/remove-gcc-wrapper.patch

View file

@ -0,0 +1 @@
../../.shared-patches/linux/qcom/msm8916/smb1360-debug.patch

View file

@ -0,0 +1,80 @@
Dump all known registers of the SMB1360 battery/charging chip.
The same output can be generated with the mainline driver which allows verifying
if all the registers are set correctly.
(Note: Separate patch needed for wt88047 because it uses a slightly custom
smb1360-charger-fg driver...)
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 3f93c7636c8..24e48c337e4 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -1,6 +1,7 @@
ccflags-$(CONFIG_POWER_SUPPLY_DEBUG) := -DDEBUG
power_supply-y := power_supply_core.o
+power_supply-y += smb1360-dump.o
power_supply-$(CONFIG_SYSFS) += power_supply_sysfs.o
power_supply-$(CONFIG_LEDS_TRIGGERS) += power_supply_leds.o
diff --git a/drivers/power/smb1360-charger-fg-wt88047.c b/drivers/power/smb1360-charger-fg-wt88047.c
index fa03089b8b7..73ccd8d059e 100644
--- a/drivers/power/smb1360-charger-fg-wt88047.c
+++ b/drivers/power/smb1360-charger-fg-wt88047.c
@@ -3452,6 +3452,38 @@ static int smb1360_jeita_init(struct smb1360_chip *chip)
return rc;
}
+extern void smb1360_dump(struct i2c_client *client);
+extern void smb1360_dump_fg_scratch(struct i2c_client *fg_client);
+extern void smb1360_dump_fg(struct i2c_client *client);
+
+static void smb1360_dump_all(struct smb1360_chip *chip)
+{
+ int ret;
+
+ mutex_lock(&chip->read_write_lock);
+ smb1360_dump(chip->client);
+ mutex_unlock(&chip->read_write_lock);
+
+ ret = smb1360_enable_fg_access(chip);
+ if (ret)
+ return;
+
+ mutex_lock(&chip->read_write_lock);
+ smb1360_dump_fg_scratch(chip->client);
+
+ /* Do cool hacks to access FG I2C address instead */
+ chip->fg_access_type = FG_ACCESS_CFG;
+ smb1360_select_fg_i2c_address(chip);
+
+ chip->client->addr = chip->fg_i2c_addr;
+ smb1360_dump_fg(chip->client);
+ chip->client->addr = chip->default_i2c_addr;
+ mutex_unlock(&chip->read_write_lock);
+
+ smb1360_disable_fg_access(chip);
+ smb1360_check_cycle_stretch(chip);
+}
+
static int smb1360_hw_init(struct smb1360_chip *chip)
{
int rc;
@@ -3460,6 +3492,9 @@ static int smb1360_hw_init(struct smb1360_chip *chip)
smb1360_check_feature_support(chip);
+ /* Dump initial registers */
+ smb1360_dump_all(chip);
+
rc = smb1360_enable_volatile_writes(chip);
if (rc < 0) {
dev_err(chip->dev, "Couldn't configure for volatile rc = %d\n",
@@ -3787,6 +3822,8 @@ static int smb1360_hw_init(struct smb1360_chip *chip)
return rc;
}
+ /* Dump final registers */
+ smb1360_dump_all(chip);
return rc;
}

View file

@ -0,0 +1,51 @@
From 7acfecc35efefab4df9444f46726bb29a8b50afa Mon Sep 17 00:00:00 2001
From: Zhenhua Huang <zhenhuah@codeaurora.org>
Date: Wed, 27 Aug 2014 12:52:39 +0800
Subject: [PATCH] power: smb1360: Fix issue for safety-timer setting
Safety-timer means maximum duration in minutes that a single charge
cycle may last.
Fix issue by correcting the safety timer enable bit.
Change-Id: I2f4592bbb98360d80dd9210ed50b3cac83e137ae
Signed-off-by: Zhenhua Huang <zhenhuah@codeaurora.org>
---
drivers/power/smb1360-charger-fg-wt88047.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/power/smb1360-charger-fg-wt88047.c b/drivers/power/smb1360-charger-fg-wt88047.c
index fa03089b8b7..94672901436 100644
--- a/drivers/power/smb1360-charger-fg-wt88047.c
+++ b/drivers/power/smb1360-charger-fg-wt88047.c
@@ -75,7 +75,7 @@
#define CHG_STAT_DISABLE_BIT BIT(0)
#define CFG_SFY_TIMER_CTRL_REG 0x0A
-#define SAFETY_TIME_EN_BIT BIT(4)
+#define SAFETY_TIME_DISABLE_BIT BIT(5)
#define SAFETY_TIME_MINUTES_SHIFT 2
#define SAFETY_TIME_MINUTES_MASK SMB1360_MASK(3, 2)
@@ -3580,7 +3580,7 @@ static int smb1360_hw_init(struct smb1360_chip *chip)
if (chip->safety_time == 0) {
/* safety timer disabled */
rc = smb1360_masked_write(chip, CFG_SFY_TIMER_CTRL_REG,
- SAFETY_TIME_EN_BIT, 0);
+ SAFETY_TIME_DISABLE_BIT, SAFETY_TIME_DISABLE_BIT);
if (rc < 0) {
dev_err(chip->dev,
"Couldn't disable safety timer rc = %d\n",
@@ -3595,8 +3595,8 @@ static int smb1360_hw_init(struct smb1360_chip *chip)
}
}
rc = smb1360_masked_write(chip, CFG_SFY_TIMER_CTRL_REG,
- SAFETY_TIME_EN_BIT | SAFETY_TIME_MINUTES_MASK,
- SAFETY_TIME_EN_BIT | reg);
+ SAFETY_TIME_DISABLE_BIT | SAFETY_TIME_MINUTES_MASK,
+ reg);
if (rc < 0) {
dev_err(chip->dev,
"Couldn't set safety timer rc = %d\n",
--
2.30.1

View file

@ -0,0 +1 @@
../../.shared-patches/linux/qcom/msm8916/smb1360-like-mainline.patch

View file

@ -0,0 +1,34 @@
Change SMB1360 configuration to match what we use for the mainline driver.
This makes it easier to compare the registers programmed by the downstream driver
with the mainline driver.
qcom,config-hard-thresholds enables an ugly hack that requires monitoring the
battery temperature from the kernel (instead of letting the hardware do its job).
The mainline kernel does not implement this, so disable it on downstream as well.
diff --git a/arch/arm/boot/dts/qcom/msm8916-wt88047.dts b/arch/arm/boot/dts/qcom/msm8916-wt88047.dts
index a72332b4e35..289a1c8202a 100644
--- a/arch/arm/boot/dts/qcom/msm8916-wt88047.dts
+++ b/arch/arm/boot/dts/qcom/msm8916-wt88047.dts
@@ -35,18 +35,19 @@
qcom,fg-batt-capacity-mah = <2200>;
qcom,fg-cc-soc-coeff = <0x8373>;
qcom,fg-delta-soc = <1>;
+ qcom,fg-soc-min = <15>;
qcom,fg-cutoff-voltage-mv = <3400>;
qcom,fg-iterm-ma = <150>;
qcom,fg-ibatt-standby-ma = <200>;
qcom,fg-cc-to-cv-mv = <4328>;
- qcom,fg-auto-recharge-soc = <99>;
+ qcom,fg-auto-recharge-soc = <95>;
qcom,warm-recharge-thresh-mv = <200>;
qcom,thermistor-c1-coeff = <0x85d2>;
qcom,float-voltage-mv = <4350>;
qcom,iterm-ma = <100>;
+ qcom,charging-timeout = <192>;
qcom,otg-batt-curr-limit = <950>;
qcom,thermal-mitigation = <1500 700 600 0>;
- qcom,config-hard-thresholds;
qcom,hot-bat-decidegc = <600>;
qcom,cold-bat-decidegc = <0>;
qcom,soft-jeita-supported;