二、Driver - Battery Charging

本文介绍了MTK平台充电管理的两种方式及其驱动代码位置,对比了mdelay()与msleep()的不同应用场景,并讲解了如何配置关机充电、电池充电报警、读取设置PMIC寄存器等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



1.充电方式

a.PMIC直接充电:驱动代码位于:

mediatek\platform\mt6592\kernel\drivers\power\charging_hw_pmic.c

b.switch charge方式充电(switch charger是功率转换型的芯片)。驱动代码位于:

mediatek\platform\mt6592\kernel\drivers\power\charging_hw_xxxx.c

比如:fan5405 对应的文件就是charging_hw_fan5405.c

bq24158对应的文件就是charging_hw_bq24158.c

具体配置位于:

MTK_FAN5405_SUPPORT=no

MTK_FASTBOOT_SUPPORT=no

2.driver中mdelay() 与msleep()的区别使用:

在Linux Driver开发中,经常要用到延迟函数:msleep,mdelay/udelay.

虽然msleep和mdelay都有延迟的作用,但他们是有区别的.

1.)对于模块本身

mdelay是忙等待函数,在延迟过程中无法运行其他任务.这个延迟的时间是准确的.是需要等待多少时间就会真正等待多少时间.

msleep是休眠函数,它不涉及忙等待.你如果是msleep(10),那实际上延迟的时间,大部分时候是要多于10ms的,是个不定的时间值.

他们的差异,平时我也讲的出来,可是真正用起来的时候,就忘记了.曾在两个driver的i2c的code中,需要用到delay函数,而我用了msleep函数,一直I2C速度超慢.而我又不知道哪里出了问题,我潜意识中,认为我只delay了1ms,可是,实际上是十几毫秒.

2.)对于系统:

mdelay() 会占用cpu资源,导致其他功能此时也无法使用cpu资源。

msleep() 则不会占住cpu资源,其他模块此时也可以使用cpu资源。

delay函数是忙则等待,占用CPU时间;而sleep函数使调用的进程进行休眠。

3.)udelay() mdelay() ndelay() 区别:

udelay(); mdelay(); ndelay();实现的原理本质上都是忙等待,ndelay和mdelay都是通过udelay衍生出来的。

我们使用这些函数的实现往往会碰到编译器的警告implicit declaration of function 'udelay',这往往是由于头文件的使用不当造成的。

在include/asm-***/delay.h中定义了udelay(),而在include/linux/delay.h中定义了mdelay和ndelay.

udelay一般适用于一个比较小的delay,如果你填的数大于2000,系统会认为你这个是一个错误的delay函数,因此如果需要2ms以上的delay需要使用mdelay函数。

4.)msleep,ssleep区别:

休眠单位不同

5.)秒的单位

ms是毫秒=0.001秒

us是微秒=0.000001秒

ns是纳秒=0.000000001秒

3.如何配置关机充电(KPOC)中的 长按开机时间

file path:alps/mediatek/platform/mt6589/kernel/drivers/power/pmic_mt6320.c

modify #define LONG_PWRKEY_PRESS_TIME 2000*1000000

4.电池充电报警克制化

手机充电出现异常的报警主要有:

1. 充电电压超过正常允许的电压范围

2. 电池温度超过允许的电池温度

3. 长时间的超过1A的大电流充电

4. 电池电压超过允许的电池电压范围

5. 总的充电时间超过24hr.

配置文件:alps\mediatek\custom\{project}\kernel\battery\battery\cust_battery.h

与上述5个报警相对应的宏:

#define BATTERY_NOTIFY_CASE_0001

#define BATTERY_NOTIFY_CASE_0002

#define BATTERY_NOTIFY_CASE_0003

#define BATTERY_NOTIFY_CASE_0004

#define BATTERY_NOTIFY_CASE_0005

5.如何读取及设置PMIC registers

1)进入工程模式,读取和设置

拨号界面 ----------输入*#*# 3646633#*#* 进入工程模式 power ------ pmu ------ pmu register

或则 hardware testing ----- power ------ pmu ------ pmu register ,所有读写都是16进制

2)程序运行时,如何通过ADB cmd 获取及设置pmic registers?

adb shell cd /sys/devices/platform/mt-pmic

6.关于功耗问题:

1)第三方apk引起的,先予以排除;

2)wake up by RTC:kernel_log中查找wake up by RTC,分析唤醒源;

3)wake up by CCIF_MD:

4)wake up by EINT

7.高温高压后如何恢复充电

参考[FAQ10404]

在充电的过程中,如果出现高温或者高压的情况下, 系统会停止充电, 当温度或者充电器的电压值恢复正常后,如何恢复充电。

1 Introduction 1.1 General This compliance plan enables test and certification of USB Portable Devices, Charge rs and Charging Ports, Micro - ACAs, Standard - ACAs and ACA - Docks to USB 2.0 specification and to Battery Charging specification revision 1.2. Charging Ports include Dedicated Charging Ports and Charging Downstream Ports as defined in the Battery Charging Sp ecification revision 1.2. A USB Charger is a device with a Dedicated Charging Port, such as a wall adapter or car power adapter. Herein, USB Chargers are referred to as Dedicated Charging Ports as functionally they are identical. Previously a USB Portable Device with a battery and charging capability simply took power from a USB port without any control. With BC 1.2, a Portable Device can get more power and the battery can be charged faster. It is important to verify that a Portable Device complies with the BC 1.2 specification while communicating with a Charging Downstream Port and identifying a Dedicated Charger, and ensuring that it continues to operate as a functional USB device . Many existing dedicated chargers have offered a USB compliant physical conn ection but lacked a USB compliance program. This led to many chargers having characteristics incompatible with USB specifications. As well, even though PC host ports go through an extensive certification process, future PCs that claim a USB compliant Charg ing Port in their feature list will be required to pass compliance checks described in this document. These checks are in addition to those required for a USB compliant Standard Downstream Port.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值