/***************************************************************************
* can't able to update the design capacity in bq27441-G1
* 声明:
* 本文主要是记录分析bq27441-G1芯片无法修改一些参数的原因,主要是因为
* bq27x00_powersupply_init中绑定了bq27x00_battery_poll作为定时任务,之后
* 直接调用bq27x00_update获取电池信息,这个时候bq27x00_battery_poll还没有
* 执行,所以第一次bq27x00_update获取的是默认的bq27441-G1信息,而在此之后
* bq27x00_update中会对有些信息进行选择更新,所以造成了design capacity不
* 准确。
*
* 2016-2-22 深圳 南山平山村 曾剑锋
**************************************************************************/ /**
* 参考文章:
* Application of bq27441-g1 with 3.X Linux kernel
* http://e2e.ti.com/support/power_management/battery_management/f/180/p/471744/1701660
*/ static int __init bq27x00_powersupply_init(struct bq27x00_device_info *di)
{
int ret; di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
if (di->chip == BQ274XX) {
set_properties_array(di, bq274xx_battery_props,
ARRAY_SIZE(bq274xx_battery_props));
} else if (di->chip == BQ276XX) {
set_properties_array(di, bq276xx_battery_props,
ARRAY_SIZE(bq276xx_battery_props));
} else if (di->chip == BQ27520) {
set_properties_array(di, bq27520_battery_props,
ARRAY_SIZE(bq27520_battery_props));
} else if (di->chip == BQ2753X) {
set_properties_array(di, bq2753x_battery_props,
ARRAY_SIZE(bq2753x_battery_props));
} else {
set_properties_array(di, bq27x00_battery_props,
ARRAY_SIZE(bq27x00_battery_props));
}
di->bat.get_property = bq27x00_battery_get_property;
di->bat.external_power_changed = bq27x00_external_power_changed; INIT_DELAYED_WORK(&di->work, bq27x00_battery_poll); ------------------+
mutex_init(&di->lock); |
|
ret = power_supply_register(di->dev, &di->bat); |
if (ret) { |
dev_err(di->dev, "failed to register battery: %d\n", ret); |
return ret; |
} |
|
dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION); |
|
bq27x00_update(di); ------------------*------+
| |
return ; | |
} | |
| |
static void bq27x00_battery_poll(struct work_struct *work) <------------+ |
{ |
struct bq27x00_device_info *di = |
container_of(work, struct bq27x00_device_info, work.work); |
|
if (((di->chip == BQ274XX) || (di->chip == BQ276XX)) && |
!rom_mode_gauge_dm_initialized(di)) { |
rom_mode_gauge_dm_init(di); -------------------+ |
} | |
| |
bq27x00_update(di); -------------------*-------+
| |
if (poll_interval > ) { | |
/* The timer does not have to be accurate. */ | |
set_timer_slack(&di->work.timer, poll_interval * HZ / ); | |
schedule_delayed_work(&di->work, poll_interval * HZ); | |
} | |
} | |
| |
#define INITCOMP_TIMEOUT_MS 10000 | |
static void rom_mode_gauge_dm_init(struct bq27x00_device_info *di) <----+ |
{ |
int i; |
int timeout = INITCOMP_TIMEOUT_MS; |
u8 subclass, offset; |
u32 blk_number; |
u32 blk_number_prev = ; |
u8 buf[]; |
bool buf_valid = false; |
struct dm_reg *dm_reg; |
|
dev_dbg(di->dev, "%s:\n", __func__); |
|
while (!rom_mode_gauge_init_completed(di) && timeout > ) { |
msleep(); |
timeout -= ; |
} |
|
if (timeout <= ) { |
dev_err(di->dev, "%s: INITCOMP not set after %d seconds\n", |
__func__, INITCOMP_TIMEOUT_MS/); |
return; |
} |
|
if (!di->dm_regs || !di->dm_regs_count) { |
dev_err(di->dev, "%s: Data not available for DM initialization\n", |
__func__); |
return; |
} |
|
enter_cfg_update_mode(di); |
for (i = ; i < di->dm_regs_count; i++) { |
dm_reg = &di->dm_regs[i]; |
subclass = dm_reg->subclass; |
offset = dm_reg->offset; |
|
/* |
* Create a composite block number to see if the subsequent |
* register also belongs to the same 32 btye block in the DM |
*/ |
blk_number = subclass << ; |
blk_number |= offset >> ; |
|
if (blk_number == blk_number_prev) { |
copy_to_dm_buf_big_endian(di, buf, offset, |
dm_reg->len, dm_reg->data); |
} else { |
|
if (buf_valid) |
update_dm_block(di, blk_number_prev >> , |
(blk_number_prev << ) & 0xFF , buf); |
else |
buf_valid = true; |
|
read_dm_block(di, dm_reg->subclass, dm_reg->offset, |
buf); |
copy_to_dm_buf_big_endian(di, buf, offset, |
dm_reg->len, dm_reg->data); |
} |
blk_number_prev = blk_number; |
} |
|
/* Last buffer to be written */ |
if (buf_valid) |
update_dm_block(di, subclass, offset, buf); |
|
exit_cfg_update_mode(di); |
} |
|
static void bq27x00_update(struct bq27x00_device_info *di) <----------------+
{
struct bq27x00_reg_cache cache = {, };
bool is_bq27200 = (di->chip == BQ27200);
bool is_bq27500 = (di->chip == BQ27500);
bool is_bq274xx = (di->chip == BQ274XX);
bool is_bq276xx = (di->chip == BQ276XX); cache.flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, !is_bq27500);
if (cache.flags >= ) {
if (is_bq27200 && (cache.flags & BQ27200_FLAG_CI)) {
dev_info(di->dev, "battery is not calibrated! ignoring capacity values\n");
cache.capacity = -ENODATA;
cache.energy = -ENODATA;
cache.time_to_empty = -ENODATA;
cache.time_to_empty_avg = -ENODATA;
cache.time_to_full = -ENODATA;
cache.charge_full = -ENODATA;
cache.health = -ENODATA;
} else {
cache.capacity = bq27x00_battery_read_soc(di);
if (!(is_bq274xx || is_bq276xx)) {
cache.energy = bq27x00_battery_read_energy(di);
cache.time_to_empty =
bq27x00_battery_read_time(di,
BQ27XXX_REG_TTE);
cache.time_to_empty_avg =
bq27x00_battery_read_time(di,
BQ27XXX_REG_TTECP);
cache.time_to_full =
bq27x00_battery_read_time(di,
BQ27XXX_REG_TTF);
}
cache.charge_full = bq27x00_battery_read_fcc(di);
cache.health = bq27x00_battery_read_health(di);
}
cache.temperature = bq27x00_battery_read_temperature(di);
if (!is_bq274xx)
cache.cycle_count = bq27x00_battery_read_cyct(di);
cache.power_avg =
bq27x00_battery_read_pwr_avg(di, BQ27XXX_POWER_AVG); /* We only have to read charge design full once */
if (di->charge_design_full <= ) // pay attention at here
di->charge_design_full = bq27x00_battery_read_dcap(di); printk("---------------------------------------\n");
printk("cache.capacity : %d\n", cache.capacity);
printk("cache.energy : %d\n", cache.energy);
printk("cache.time_to_empty : %d\n", cache.time_to_empty);
printk("cache.charge_full : %d\n", cache.charge_full);
printk("cache.health : %d\n", cache.health);
printk("cache.tmperature : %d\n", cache.temperature);
printk("cache.power_avg : %d\n", cache.power_avg);
printk("di->charge_design_full : %d\n", di->charge_design_full);
printk("---------------------------------------\n");
} if (memcmp(&di->cache, &cache, sizeof(cache)) != ) {
di->cache = cache;
power_supply_changed(&di->bat);
} di->last_update = jiffies;
}

can't able to update the design capacity in bq27441-G1的更多相关文章

  1. The The Garbage-First (G1) collector since Oracle JDK 7 update 4 and later releases

    Refer to http://www.oracle.com/technetwork/tutorials/tutorials-1876574.html for detail. 一些内容复制到这儿 Th ...

  2. bq27441-G1 工作机制

    /*************************************************************************** * bq27441-G1 工作机制 * 声明: ...

  3. usb.ids

    # # List of USB ID's # # Maintained by Vojtech Pavlik <vojtech@suse.cz> # If you have any new ...

  4. TI单节电量计基本介绍及常见问题解答

    电量计(gas gauge /fuel gauge)是用来计量显示电池电量,通常包括mAh剩余容量(RM),满充容量(FCC),百分比容量(SOC),电压,电流,温度等,部分电量计还包含放空,充满时间 ...

  5. LSI Storcli 工具使用

    查看RAID卡ID 命令功能 查看LSI SAS3108RAID卡的ID. 命令格式 storcli64 show 使用实例 # 查看LSI SAS3108RAID卡的ID. [root@localh ...

  6. Java Hotspot G1 GC的一些关键技术

    G1 GC,全称Garbage-First Garbage Collector,通过-XX:+UseG1GC参数来启用,作为体验版随着JDK 6u14版本面世,在JDK 7u4版本发行时被正式推出,相 ...

  7. I.MX6 bq27441 driver hacking

    /************************************************************************* * I.MX6 bq27441 driver ha ...

  8. Win32_Battery class

    wmi的Win32_Battery类实现 其中EstimatedChargeRemaining属性返回剩余电量的百分比,EstimatedRunTime属性返回剩余时间(分钟) 其他属性参考http: ...

  9. SQL 基础学习(1):下载DB Browser for SQLite. 下载graphviz(为了使用Rails ERD的前提)出现❌,已debug.

    SQL is a standard language for storing, manipulating and retrieving data in databases. 关系型数据库:RDBMS( ...

随机推荐

  1. 快速编译Delphi XE3 项目工程组

    Embarcadero 做了个好事.工程组可以直接使用 MSBuild 进行编译,让发布更简单.在Bin目录中 rsvars.bat 用于设置编译的环境变量,结合使用就可以顺利进行编译. call r ...

  2. 【学习总结】整理一下int, NSInteger 等概念

    基本需要知道的 : unsigned : 没符号的 signed  : 有符号的 int : 整型 看看OC的定义 : #if __LP64__ || (TARGET_OS_EMBEDDED & ...

  3. 【BZOJ 2005】[Noi2010]能量采集

    Description 栋栋有一块长方形的地,他在地上种了一种能量植物,这种植物可以采集太阳光的能量.在这些植物采集能量后,栋栋再使用一个能量汇集机器把这些植物采集到的能量汇集到一起. 栋栋的植物种得 ...

  4. csharp excel interop programming

    string fileName = "c:\\a.xlsx"; var application = new Application(); application.Visible = ...

  5. linux驱动系列之arm汇编

    在arm平台学习linux时,会遇到arm汇编指令,arm汇编指令与8086汇编指令很多地方都不同,在此记下来以免后面忘了,同时在学习了汇编指令之后分析一些汇编指令编写的代码. 一.相对跳转指令b.b ...

  6. jQuery中的join方法

    和JS 中的JOIN 方法一样,将一数组按照JOIN的参数连接起来.比如: var arr = [ "a", "b", "c", " ...

  7. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  8. jquery下拉列表选中项改变时获取新选项的属性值

    $("#textSel").change(funtion(){ var selVal=$(this).val(); var selText=$("#textSel opt ...

  9. 团体程序设计天梯赛-练习集L2-010. 排座位

    L2-010. 排座位 时间限制 150 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 布置宴席最微妙的事情,就是给前来参宴的各位宾客安排座位. ...

  10. 团体程序设计天梯赛-练习集L1-002. 打印沙漏

    L1-002. 打印沙漏 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给 ...