1.启动后,断电重启和直接reboot启动,两种情况的log显示的fuelgauge的读取信息不一致。具体log如下:
断电启动:
[ 83.180240] [0: kworker/u16:8: 3335] s2mu106-fuelgauge 7-003b: s2mu106_get_vbat: vbat (3944)
[ 83.234555] [0: kworker/u16:8: 3335] s2mu106-fuelgauge 7-003b: s2mu106_get_avgvbat: avgvbat (3944)
[ 83.236894] [0: kworker/u16:8: 3335] s2mu106-fuelgauge 7-003b: s2mu106_get_current: current (-2)mA
[ 83.240522] [0: kworker/u16:8: 3335] s2mu106-fuelgauge 7-003b: s2mu106_get_avgcurrent: avg current (-2)mA
[ 83.249447] [0: kworker/u16:8: 3335] s2mu106_get_temperature: temperature (264)
[ 83.282385] [0: kworker/u16:8: 3335] s2mu106-fuelgauge 7-003b: s2mu106_get_avgcurrent: avg current (-2)mA
[ 83.360249] [0: kworker/u16:8: 3335] s2mu00x-battery s2mu00x-battery: get_battery_info:Vnow(3944mV),Inow(-2mA),Imax(500mA),Ichg()
reboot启动:
[ 114.068570] [0: kworker/u16:9: 3328] s2mu106-fuelgauge 7-003b: s2mu106_get_vbat: vbat (3841)
[ 114.122895] [0: kworker/u16:9: 3328] s2mu106-fuelgauge 7-003b: s2mu106_get_avgvbat: avgvbat (3841)
[ 114.124740] [0: kworker/u16:9: 3328] s2mu106-fuelgauge 7-003b: s2mu106_get_current: current (0)mA
[ 114.127765] [0: kworker/u16:9: 3328] s2mu106-fuelgauge 7-003b: s2mu106_get_avgcurrent: avg current (0)mA
[ 114.137483] [0: kworker/u16:9: 3328] s2mu106_get_temperature: temperature (263)
[ 114.171159] [0: kworker/u16:9: 3328] s2mu106-fuelgauge 7-003b: s2mu106_get_avgcurrent: avg current (0)mA
[ 114.248306] [0: kworker/u16:9: 3328] s2mu00x-battery s2mu00x-battery: get_battery_info:Vnow(3841mV),Inow(0mA),Imax(500mA),Ichg(4)
分析:
由于每次reboot开机以后显示的log和关机前次开机一样,但是断电重启以后log信息改变,所以怀疑是fuelgauge没有校准。
方法:搜索robustar2中BootLoader中106的驱动,移植校准代码。
2.移植驱动之后编译开机显示电压为0V,无法开机。
initializing platform
bootloader partition start block(512 Byte): 14244720
s2mu106_charger_set_mode: S2MU106_CHG_CTRL0 = 0x00
s2mu106_charger_reg_init, 0xec(7f)
s2mu106_charger_reg_init, 0xe5(f8)
s2mu106_charger_set_charging_current: S2MU106_CHG_CTRL7 = 0x00
s2mu106_check_por: 0x1F = 0x00
s2mu106_check_por: 0x1E = 0x00
s2mu106_get_vbat: vbat (0), src(0x00)
s2mu106_muic_get_vbus: 0x4E = 0xff
dead_battery_recovery: Start DBR! delay = 500ms, VBUS = 1
Watchdog mask_wdt_reset register mask!
Watchdog cluster 0 stop done, WTCON = 8000
s2mu106_charger_set_mode: S2MU106_CHG_CTRL0 = 0x00
s2mu106_charger_set_input_current: S2MU106_CHG_CTRL1 = 0x00
s2mu106_charger_set_charging_current: S2MU106_CHG_CTRL7 = 0x00
s2mu106_get_vbat: vbat (0), src(0x00)
s2mu106_muic_get_vbus: 0x4E = 0xff
s2mu106_charger_get_mode: S2MU106_CHG_CTRL0 = 0xff
dead_battery_recovery: vbat is low!(0mV), Keep charging(vbus = 1)
s2mu106_get_vbat: vbat (0), src(0x00)
s2mu106_muic_get_vbus: 0x4E = 0xff
s2mu106_charger_get_mode: S2MU106_CHG_CTRL0 = 0xff
dead_battery_recovery: vbat is low!(0mV), Keep charging(vbus = 1)
问题分析:
1.由打印log中dead_battery_recovery: Start DBR! delay = 500ms, VBUS = 1这一句可以定位到fg_s2mu106.c中,通过分析可以知道函数中vbat数据读取错误,对比了华秦的robustar2发现有两处有关106的代码没有完全一直到avl中,分别是fastboot和boot目录下的文件,移植完成后编译重启,但是仍然无法得到正确的VBat。
2.想到由于硬件avl中charger的i2c接口和robustar2不同,怀疑是i2c接口不对导致的错误,检测代码发现接口确实不对。对照硬件电路和9609芯片手册改正i2c接口配置(此处使用gpio模拟串口,所以应该看9609中gpio章节)。
修改代码:
1.#ifndef __IF_PMIC_S2MU106_H__
#define __IF_PMIC_S2MU106_H__
#define GPP0BASE (0x139b0000)
#define GPP0CON *(volatile unsigned int *)(GPP0BASE + 0x0)
#define GPP0DAT *(volatile unsigned int *)(GPP0BASE + 0x4)
#define GPP0PUD *(volatile unsigned int *)(GPP0BASE + 0x8)
/* SDA: GPP0_2, SCL: GPP0_3 */
#define GPIO_DAT_S2MU106 GPP0DAT
#define GPIO_DAT_SHIFT (6) //此处由2修改成6,因为使用的是GPP0[6]
#define GPIO_PUD_S2MU106 GPP0PUD &= ~(0xff << (GPIO_DAT_SHIFT*4))
2.#ifndef __FG_S2MU106_H__
#define __FG_S2MU106_H__
#define GPP1BASE (0x139b0000)
#define GPP1CON *(volatile unsigned int *)(GPP0BASE + 0x0020)
#define GPP1DAT *(volatile unsigned int *)(GPP0BASE + 0x0024)
#define GPP1PUD *(volatile unsigned int *)(GPP0BASE + 0x0028)
/* SDA: GPP0_0, SCL: GPP0_1 */
#define GPIO_DAT_FG_S2MU106 GPP1DAT
#define GPIO_DAT_FG_SHIFT (0)
#define GPIO_PUD_FG_S2MU106 GPP1PUD &= ~(0xff << (GPIO_DAT_FG_SHIFT*4))
#define IIC_S2MU106_FG_ESCL_Hi GPP1DAT |= (0x1 << (GPIO_DAT_FG_SHIFT+1))
#define IIC_S2MU106_FG_ESCL_Lo GPP1DAT &= ~(0x1 << (GPIO_DAT_FG_SHIFT+1))
#define IIC_S2MU106_FG_ESDA_Hi GPP1DAT |= (0x1 << GPIO_DAT_FG_SHIFT)
#define IIC_S2MU106_FG_ESDA_Lo GPP1DAT &= ~(0x1 << GPIO_DAT_FG_SHIFT)
#define IIC_S2MU106_FG_ESCL_INP GPP1CON &= ~(0xf << ((GPIO_DAT_FG_SHIFT+1)*4))
#define IIC_S2MU106_FG_ESCL_OUTP GPP1CON = (GPP1CON & ~(0xf << ((GPIO_DAT_FG_SHIFT+1)*4)))| (0x1 << ((GPIO_DAT_FG_SHIFT+1)*4))
#define IIC_S2MU106_FG_ESDA_INP GPP1CON &= ~(0xf << (GPIO_DAT_FG_SHIFT*4))
#define IIC_S2MU106_FG_ESDA_OUTP GPP1CON = (GPP1CON & ~(0xf << (GPIO_DAT_FG_SHIFT*4))) | (0x1 << (GPIO_DAT_FG_SHIFT*4))