From 8e4bff4cab0ddac6060645b0715210484d02ff40 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Wed, 30 Aug 2017 08:25:59 +0000 Subject: Initial file dump from open source release --- include/linux/battery/charger/bq24157_charger.h | 48 ++ include/linux/battery/charger/rt5033_charger.h | 96 +++ include/linux/battery/charger/rt9455_charger.h | 287 +++++++++ include/linux/battery/charger/sm5414_charger.h | 299 ++++++++++ include/linux/battery/charger/sm5701_charger.h | 167 ++++++ include/linux/battery/charger/smb328_charger.h | 72 +++ include/linux/battery/charger/smb358_charger.h | 79 +++ .../battery/charger/sprd27x3_charger4samsung.h | 124 ++++ include/linux/battery/fuelgauge/d2199_fuelgauge.h | 605 +++++++++++++++++++ include/linux/battery/fuelgauge/dummy_fuelgauge.h | 312 ++++++++++ include/linux/battery/fuelgauge/rt5033_fuelgauge.h | 173 ++++++ .../battery/fuelgauge/rt5033_fuelgauge_impl.h | 96 +++ .../battery/fuelgauge/sprd27x3_fuelgauge4samsung.h | 18 + .../linux/battery/fuelgauge/stc3115_fuelgauge.h | 285 +++++++++ include/linux/battery/sec_adc.h | 38 ++ include/linux/battery/sec_battery.h | 305 ++++++++++ include/linux/battery/sec_charger.h | 180 ++++++ include/linux/battery/sec_charging_common.h | 653 +++++++++++++++++++++ include/linux/battery/sec_fuelgauge.h | 143 +++++ 19 files changed, 3980 insertions(+) create mode 100644 include/linux/battery/charger/bq24157_charger.h create mode 100644 include/linux/battery/charger/rt5033_charger.h create mode 100644 include/linux/battery/charger/rt9455_charger.h create mode 100644 include/linux/battery/charger/sm5414_charger.h create mode 100644 include/linux/battery/charger/sm5701_charger.h create mode 100644 include/linux/battery/charger/smb328_charger.h create mode 100755 include/linux/battery/charger/smb358_charger.h create mode 100755 include/linux/battery/charger/sprd27x3_charger4samsung.h create mode 100644 include/linux/battery/fuelgauge/d2199_fuelgauge.h create mode 100644 include/linux/battery/fuelgauge/dummy_fuelgauge.h create mode 100644 include/linux/battery/fuelgauge/rt5033_fuelgauge.h create mode 100644 include/linux/battery/fuelgauge/rt5033_fuelgauge_impl.h create mode 100755 include/linux/battery/fuelgauge/sprd27x3_fuelgauge4samsung.h create mode 100644 include/linux/battery/fuelgauge/stc3115_fuelgauge.h create mode 100644 include/linux/battery/sec_adc.h create mode 100644 include/linux/battery/sec_battery.h create mode 100755 include/linux/battery/sec_charger.h create mode 100755 include/linux/battery/sec_charging_common.h create mode 100644 include/linux/battery/sec_fuelgauge.h (limited to 'include/linux/battery') diff --git a/include/linux/battery/charger/bq24157_charger.h b/include/linux/battery/charger/bq24157_charger.h new file mode 100644 index 00000000..f6eb589d --- /dev/null +++ b/include/linux/battery/charger/bq24157_charger.h @@ -0,0 +1,48 @@ +/* + * bq24157_charger.h + * Samsung BQ24157 Charger Header + * + * Copyright (C) 2012 Samsung Electronics, Inc. + * + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __BQ24157_CHARGER_H +#define __BQ24157_CHARGER_H __FILE__ + +/* Slave address should be shifted to the right 1bit. + * R/W bit should NOT be included. + */ +#define SEC_CHARGER_I2C_SLAVEADDR 0x6a + +/* BQ24157 Registers. */ +#define BQ24157_STATUS 0x00 +#define BQ24157_CONTROL 0x01 +#define BQ24157_VOLTAGE 0x02 +#define BQ24157_VENDOR 0x03 +#define BQ24157_CURRENT 0x04 +#define BQ24157_SPECIAL 0x05 +#define BQ24157_SAFETY 0x06 + +#define FLOAT_VOLTAGE_MASK 0xfc +#define FAST_CHARGING_CURRENT_MASK 0x70 +#define TERMINATION_CURRENT_MASK 0x07 +#define INPUT_CURRENT_MASK 0xC0 + +struct sec_chg_info { + bool dummy; +}; + +#endif /* __BQ24157_CHARGER_H */ + + + diff --git a/include/linux/battery/charger/rt5033_charger.h b/include/linux/battery/charger/rt5033_charger.h new file mode 100644 index 00000000..ce19b0d7 --- /dev/null +++ b/include/linux/battery/charger/rt5033_charger.h @@ -0,0 +1,96 @@ +/* + * drivers/battery/rt5033_charger.h + * + * Header of Richtek RT5033 Fuelgauge Driver + * + * Copyright (C) 2013 Richtek Technology Corp. + * Patrick Chang + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef RT5033_CHARGER_H +#define RT5033_CHARGER_H +#include +#include + +#define RT5033_CHG_STAT_CTRL 0x00 +#define RT5033_CHG_CTRL1 0x01 +#define RT5033_CHG_CTRL2 0x02 +#define RT5033_CHG_CTRL3 0x04 +#define RT5033_CHG_CTRL4 0x05 +#define RT5033_CHG_CTRL5 0x06 +#define RT5033_EOC_CTRL 0x07 +#define RT5033_CHG_RESET 0x08 +#define RT5033_UUG 0x19 + + +#define RT5033_CHGENB_MASK (1 << 0) +#define RT5033_OPAMODE_MASK (1 << 0) +#define RT5033_COF_EN_MASK (1 << 6) +#define RT5033_TIMEREN_MASK (1 << 0) +#define RT5033_SEL_SWFREQ_MASK (1 << 2) +#define RT5033_EOC_RESET_MASK (1<<4) +#define RT5033_TEEN_MASK (1 << 3) +#define RT5033_AICR_LIMIT_MASK (0x7 << 5) +#define RT5033_AICR_LIMIT_SHIFT 5 +#define RT5033_MIVR_MASK (0x7 << 5) +#define RT5033_MIVR_SHIFT 5 +#define RT5033_HZ_MASK (1 << 1) +#define RT5033_VOREG_MASK (0x3f << 2) +#define RT5033_VOREG_SHIFT 2 +#define RT5033_IEOC_MASK 0x07 +#define RT5033_IEOC_SHIFT 0 +#define RT5033_ICHRG_MASK 0xf0 +#define RT5033_ICHRG_SHIFT 4 + +#define RT5033_CHG_IRQ1 0x60 +#define RT5033_CHG_IRQ2 0x61 +#define RT5033_CHG_IRQ3 0x62 + +#define RT5033_CHG_IRQ_CTRL1 0x63 +#define RT5033_CHG_IRQ_CTRL2 0x64 +#define RT5033_CHG_IRQ_CTRL3 0x65 + +/* RT5033_CHG_STAT */ +#define RT5033_EXT_PMOS_CTRL 0x1 +#define RT5033_EXT_PMOS_CTRL_SHIFT 7 +#define RT5033SW_HW_CTRL 0x1 +#define RT5033SW_HW_CTRL_SHIFT 2 +#define RT5033_OTG_SS_DISABLE 0x1 +#define RT5033_OTG_SS_DISABLE_SHIFT 1 + +/* RT5033_CHR_CTRL1 */ +#define RT5033_IAICR 0x101 +#define RT5033_IAICR_SHIFT 5 +#define RT5033_HIGHER_OCP 0x1 +#define RT5033_HIGHER_OCP_SHIFT 4 +#define RT5033_TERMINATION_EN 0x0 +#define RT5033_TERMINATION_EN_SHIFT 3 +#define RT5033_SEL_SWFREQ 0x1 +#define RT5033_SEL_SWFREQ_SHIFT 2 +#define RT5033_HIGH_IMPEDANCE 0 +#define RT5033_HIGH_IMPEDANCE_SHIFT 1 +#define RT5033_OPA_MODE 2 +#define RT5033_OPA_MODE_SHIFT 0 + +/* RT5033_CHG_CTRL2 */ +#define RT5033_REG_VOLTAGE 0x011100 +#define RT5033_REG_VOLTAGE_SHIFT 2 +#define RT5033_TDEG_EOC 0x0 +#define RT5033_TDEG_EOC_SHIFT 0 + +/* RT5033_CHG_CTRL3 */ +#define RT5033_PPC_TE 0x0 +#define RT5033_PPC_TE_SHIFT 7 +#define RT5033_CHG_EN 0x1 +#define RT5033_CHG_EN_SHIFT 6 + + + +extern sec_battery_platform_data_t sec_battery_pdata; + + +#endif /*RT5033_CHARGER_H*/ diff --git a/include/linux/battery/charger/rt9455_charger.h b/include/linux/battery/charger/rt9455_charger.h new file mode 100644 index 00000000..c862fa99 --- /dev/null +++ b/include/linux/battery/charger/rt9455_charger.h @@ -0,0 +1,287 @@ +/* + * include/linux/battery/charger/rt9455_charger.h + * Include header file for Richtek RT9455 Switch Mode Charger IC + * + * Copyright (C) 2013 Richtek Electronics + * cy_huang + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __LINUX_BATTERY_CHARGER_RT9455_H + +#define SEC_CHARGER_I2C_SLAVEADDR (0x22) + +#define RT9455_DEVICE_NAME "RT9455" + +#define RT9455_RST_MASK 0x80 +#define RT9455_RST_SHIFT 7 + +#define RT9455_OPAMODE_MASK 0x01 +#define RT9455_OPAMODE_SHIFT 0 +enum { + OPA_CHARGER_MODE, + OPA_BOOST_MODE, +}; + +enum { + IAICR_EXTERNAL, + IAICR_INTERNAL, +}; + +enum { + OCP_2P5A, + OCP_3P5A, +}; + +enum { + SEL_FREQ_3MHz, + SEL_FREQ_1P5MHz, +}; + +#define RT9455_AICR_LIMIT_MASK 0xC0 +#define RT9455_AICR_LIMIT_SHIFT 6 +enum { + IAICR_LIMIT_100MA, + IAICR_LIMIT_500MA, + IAICR_LIMIT_1A, + IAICR_LIMIT_NO, + IAICR_LIMIT_MAX, +}; + +#define RT9455_VOREG_MASK 0xFC +#define RT9455_VOREG_SHIFT 2 + +enum { + OTGPL_ACTIVE_LOW, + OTGPL_ACTIVE_HIGH, +}; + +#define RT9455_IEOC_MASK 0x3 +#define RT9455_IEOC_SHIFT 0 +enum { + IEOC_10P, + IEOC_30P, + IEOC_20P, + IEOC_RESV, +}; + +enum { + IPREC_20MA, + IPREC_40MA, + IPREC_60MA, +}; + +enum { + VDPM_4V, + VDPM_4P25V, + VDPM_4P5V, + VDPM_DISABLE, +}; + +enum { + VPREC_2V, + VPREC_2P2V, + VPREC_2P4V, + VPREC_2P6V, + VPREC_2P8V, + VPREC_3V, +}; + + +#define RT9455_ICHRG_MASK 0x70 +#define RT9455_ICHRG_SHIFT 4 +enum { + ICHRG_20MV, + ICHRG_26MV, + ICHRG_32MV, + ICHRG_38MV, + ICHRG_44MV, + ICHRG_50MV, + ICHRG_56MV, + ICHRG_62MV, + ICHRG_MAX, +}; + +#define RT9455_CHGEN_MASK 0x10 +#define RT9455_CHGEN_SHIFT 4 + +#define RT9455_TEEN_MASK 0x80 +#define RT9455_TEEN_SHIFT 3 + +enum { + RT9455_REG_CTRL1, + RT9455_REG_CTRL2, + RT9455_REG_CTRL3, + RT9455_REG_DEVICE_ID, + RT9455_REG_CTRL4, + RT9455_REG_CTRL5, + RT9455_REG_CTRL6, + RT9455_REG_CTRL7, + RT9455_REG_IRQ1, + RT9455_REG_IRQ2, + RT9455_REG_IRQ3, + RT9455_REG_MASK1, + RT9455_REG_MASK2, + RT9455_REG_MASK3, + RT9455_REG_MAX, +}; + +// VBOOST EVENT BIT +#define RT9455_EVENT_BSTVINOVI 0x80 +#define RT9455_EVENT_BSTOLI 0x40 +#define RT9455_EVENT_BSTLOWVI 0x20 +#define RT9455_EVENT_BST32SI 0x08 + +// CHARGER EVENT BIT +#define RT9455_EVENT_CHRVPI 0x80 +#define RT9455_EVENT_CHBATOVI 0x20 +#define RT9455_EVENT_CHTERMI 0x10 +#define RT9455_EVENT_CHRCHGI 0x08 +#define RT9455_EVNET_CH32MI 0x04 +#define RT9455_EVENT_CHTREGI 0x02 +#define RT9455_EVENT_CHDPMI 0x01 + +// GENERAL EVENT BIT +#define RT9455_EVENT_TSDI 0x80 +#define RT9455_EVENT_VINOVPI 0x40 +#define RT9455_EVENT_BATAB 0x01 + +// RESET EVENT BIT +#define RT9455_EVENT_BEFORE_RST 0x80 +#define RT9455_EVENT_AFTER_RST 0x40 + +// If not set, no irq event will be masked +struct rt9455_irq_mask { + union { + struct { + unsigned char BATABM:1; + unsigned char Resv:5; + unsigned char VINOVPIM:1; + unsigned char TSDM:1; + }bitfield; + unsigned char val; + }mask1; + union { + struct { + unsigned char CHDPMIM:1; + unsigned char CHTREGIM:1; + unsigned char CH32MIM:1; + unsigned char CHRCHGIM:1; + unsigned char CHTERMIM:1; + unsigned char CHBATOVIM:1; + unsigned char Resv:1; + unsigned char CHRVPIM:1; + }bitfield; + unsigned char val; + }mask2; + union { + struct { + unsigned char Resv1:3; + unsigned char BST32SIM:1; + unsigned char Resv2:1; + unsigned char BSTLOWVIM:1; + unsigned char BSTOLIM:1; + unsigned char BSTVIMOVIM:1; + }bitfield; + unsigned char val; + }mask3; +}; + +struct rt9455_init_ctrlval { + union { + struct { + unsigned char OPA_MODE:1; + unsigned char HZ_BIT:1; + unsigned char IAICR_INT:1; + unsigned char TE:1; + unsigned char HIGH_OCP:1; + unsigned char SEL_SWFREQ:1; + unsigned char IAICR:2; + }bitfield; + unsigned char val; + }ctrl2; + union { + struct { + unsigned char OTG_EN:1; + unsigned char OTG_PL:1; + unsigned char VOREG:6; + }bitfield; + unsigned char val; + }ctrl3; + union { + struct { + unsigned char IEOC:2; + unsigned char IPREC:2; + unsigned char VDPM:2; + unsigned char Resv:1; + unsigned char TMR_EN:1; + }bitfield; + unsigned char val; + }ctrl5; + union { + struct { + unsigned char VPREC:3; + unsigned char Resv1:1; + unsigned char ICHRG:3; + unsigned char Resv2:1; + }bitfield; + unsigned char val; + }ctrl6; + union { + struct { + unsigned char VMREG:4; + unsigned char CHG_EN:1; + unsigned char Resv1:1; + unsigned char BATD_EN:1; + unsigned char Resv2:1; + }bitfield; + unsigned char val; + }ctrl7; +}; + +struct rt9455_callbacks { + void (*boost_callback)(int); + void (*charger_callback)(int); + void (*general_callback)(int); + void (*reset_callback)(int); +}; + +struct rt9455_chip_init_data { + struct rt9455_irq_mask irq_mask; + struct rt9455_init_ctrlval init_ctrlval; + struct rt9455_callbacks *callbacks; +}; + +#if 0 +struct rt9455_chip { + struct i2c_client *i2c; + struct device *dev; + struct workqueue_struct *wq; + struct rt9455_callbacks *cb; + int intr_gpio; + int irq; + int suspend; + int otg_ext_enable; + struct work_struct work; + struct mutex io_lock; +}; +#endif + +//external function for the customer +#if 0 +int rt9455_ext_force_otamode(int onoff); +int rt9455_ext_charger_current(int value); +int rt9455_ext_charger_switch(int onoff); +#endif + +#ifdef CONFIG_CHARGER_RT9455_DBG +#define RT_DBG(format, args...) \ + pr_info("%s:%s() line-%d: " format, RT9455_DEVICE_NAME, __FUNCTION__, __LINE__, ##args) +#else +#define RT_DBG(format, args...) +#endif /* CONFIG_CHARGER_RT9455_DBG */ + +#endif /* __LINUX_BATTERY_CHARGER_RT9455_H */ diff --git a/include/linux/battery/charger/sm5414_charger.h b/include/linux/battery/charger/sm5414_charger.h new file mode 100644 index 00000000..1bee317b --- /dev/null +++ b/include/linux/battery/charger/sm5414_charger.h @@ -0,0 +1,299 @@ +/* + * SM5414_charger.h + * SiliconMitus SM5414 Charger Header + * + * Copyright (C) 2013 SiliconMitus + * + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __SM5414_CHARGER_H +#define __SM5414_CHARGER_H __FILE__ + +/* Slave address should be shifted to the right 1bit. + * R/W bit should NOT be included. + */ +#define SEC_CHARGER_I2C_SLAVEADDR (0x92>>1) + +#define CALL_EVENT_SIOP 50 +#define HIGH_TEMP_SIOP 30 +#define CALL_EVENT_CURRENT 450 +#define HIGH_TEMP_CURRENT 350 + +/* SM5414 Registers. */ + +#define SM5414_INT1 0x00 +#define SM5414_INT2 0x01 +#define SM5414_INT3 0x02 +#define SM5414_INTMASK1 0x03 +#define SM5414_INTMASK2 0x04 +#define SM5414_INTMASK3 0x05 +#define SM5414_STATUS 0x06 +#define SM5414_CTRL 0x07 +#define SM5414_VBUSCTRL 0x08 +#define SM5414_CHGCTRL1 0x09 +#define SM5414_CHGCTRL2 0x0A +#define SM5414_CHGCTRL3 0x0B +#define SM5414_CHGCTRL4 0x0C +#define SM5414_CHGCTRL5 0x0D + +#define SM5414_INT1_THEMREG 0x01 +#define SM5414_INT1_THEMSHDN 0x02 +#define SM5414_INT1_BATOVP 0x04 +#define SM5414_INT1_VBUSLIMIT 0x08 +#define SM5414_INT1_AICL 0x10 +#define SM5414_INT1_VBUSINOK 0x20 +#define SM5414_INT1_VBUSUVLO 0x40 +#define SM5414_INT1_VBUSOVP 0x80 + +#define SM5414_INT2_TOPOFF 0x01 +#define SM5414_INT2_DONE 0x02 +#define SM5414_INT2_CHGRSTF 0x04 +#define SM5414_INT2_PRETMROFF 0x08 +#define SM5414_INT2_OTGFAIL 0x10 +#define SM5414_INT2_WEAKBAT 0x20 +#define SM5414_INT2_NOBAT 0x40 +#define SM5414_INT2_FASTTMROFF 0x80 + +#define SM5414_INT3_DISLIMIT 0x01 +#define SM5414_INT3_VSYSOLP 0x02 +#define SM5414_INT3_VSYSNG 0x04 +#define SM5414_INT3_VSYSOK 0x08 +#define SM5414_CHGCTRL1_AUTOSTOP (1 << 3) + +/* FAST Charge current */ +#define FASTCHG_100mA 0 +#define FASTCHG_150mA 1 +#define FASTCHG_200mA 2 +#define FASTCHG_250mA 3 +#define FASTCHG_300mA 4 +#define FASTCHG_350mA 5 +#define FASTCHG_400mA 6 +#define FASTCHG_450mA 7 +#define FASTCHG_500mA 8 +#define FASTCHG_550mA 9 +#define FASTCHG_600mA 10 +#define FASTCHG_650mA 11 +#define FASTCHG_700mA 12 +#define FASTCHG_750mA 13 +#define FASTCHG_800mA 14 +#define FASTCHG_850mA 15 +#define FASTCHG_900mA 16 +#define FASTCHG_950mA 17 +#define FASTCHG_1000mA 18 +#define FASTCHG_1050mA 19 +#define FASTCHG_1100mA 20 +#define FASTCHG_1150mA 21 +#define FASTCHG_1200mA 22 +#define FASTCHG_1250mA 23 +#define FASTCHG_1300mA 24 +#define FASTCHG_1350mA 25 +#define FASTCHG_1400mA 26 +#define FASTCHG_1450mA 27 +#define FASTCHG_1500mA 28 +#define FASTCHG_1550mA 29 +#define FASTCHG_1600mA 30 +#define FASTCHG_1650mA 31 +#define FASTCHG_1700mA 32 +#define FASTCHG_1750mA 33 +#define FASTCHG_1800mA 34 +#define FASTCHG_1850mA 35 +#define FASTCHG_1900mA 36 +#define FASTCHG_1950mA 37 +#define FASTCHG_2000mA 38 +#define FASTCHG_2050mA 39 +#define FASTCHG_2100mA 40 +#define FASTCHG_2150mA 41 +#define FASTCHG_2200mA 42 +#define FASTCHG_2250mA 43 +#define FASTCHG_2300mA 44 +#define FASTCHG_2350mA 45 +#define FASTCHG_2400mA 46 +#define FASTCHG_2450mA 47 +#define FASTCHG_2500mA 48 + +/* Input current Limit */ +#define VBUSLIMIT_100mA 0 +#define VBUSLIMIT_150mA 1 +#define VBUSLIMIT_200mA 2 +#define VBUSLIMIT_250mA 3 +#define VBUSLIMIT_300mA 4 +#define VBUSLIMIT_350mA 5 +#define VBUSLIMIT_400mA 6 +#define VBUSLIMIT_450mA 7 +#define VBUSLIMIT_500mA 8 +#define VBUSLIMIT_550mA 9 +#define VBUSLIMIT_600mA 10 +#define VBUSLIMIT_650mA 11 +#define VBUSLIMIT_700mA 12 +#define VBUSLIMIT_750mA 13 +#define VBUSLIMIT_800mA 14 +#define VBUSLIMIT_850mA 15 +#define VBUSLIMIT_900mA 16 +#define VBUSLIMIT_950mA 17 +#define VBUSLIMIT_1000mA 18 +#define VBUSLIMIT_1050mA 19 +#define VBUSLIMIT_1100mA 20 +#define VBUSLIMIT_1150mA 21 +#define VBUSLIMIT_1200mA 22 +#define VBUSLIMIT_1250mA 23 +#define VBUSLIMIT_1300mA 24 +#define VBUSLIMIT_1350mA 25 +#define VBUSLIMIT_1400mA 26 +#define VBUSLIMIT_1450mA 27 +#define VBUSLIMIT_1500mA 28 +#define VBUSLIMIT_1550mA 29 +#define VBUSLIMIT_1600mA 30 +#define VBUSLIMIT_1650mA 31 +#define VBUSLIMIT_1700mA 32 +#define VBUSLIMIT_1750mA 33 +#define VBUSLIMIT_1800mA 34 +#define VBUSLIMIT_1850mA 35 +#define VBUSLIMIT_1900mA 36 +#define VBUSLIMIT_1950mA 37 +#define VBUSLIMIT_2000mA 38 +#define VBUSLIMIT_2050mA 39 +#define VBUSLIMIT_2100mA 40 +#define VBUSLIMIT_2150mA 41 +#define VBUSLIMIT_2200mA 42 +#define VBUSLIMIT_2250mA 43 +#define VBUSLIMIT_2300mA 44 +#define VBUSLIMIT_2350mA 45 +#define VBUSLIMIT_2400mA 46 +#define VBUSLIMIT_2450mA 47 +#define VBUSLIMIT_2500mA 48 + +/* AICL TH */ +#define AICL_THRESHOLD_4_3_V 0 +#define AICL_THRESHOLD_4_4_V 1 +#define AICL_THRESHOLD_4_5_V 2 +#define AICL_THRESHOLD_4_6_V 3 +#define AICL_THRESHOLD_4_7_V 4 +#define AICL_THRESHOLD_4_8_V 5 +#define AICL_THRESHOLD_4_9_V 6 +#define AICL_THRESHOLD_MASK 0x0F + +/* AUTOSTOP */ +#define AUTOSTOP_EN (1<<3) + +/* AICLEN */ +#define AICL_EN (1<<2) + +/* PRECHG */ +#define PRECHG_150mA 0 +#define PRECHG_250mA 1 +#define PRECHG_350mA 2 +#define PRECHG_450mA 3 +#define PRECHG_MASK 0xFC + +/* Battery Regulation Voltage */ +#define BATREG_4_1_0_0_V 0 +#define BATREG_4_1_2_5_V 1 +#define BATREG_4_1_5_0_V 2 +#define BATREG_4_1_7_5_V 3 +#define BATREG_4_2_0_0_V 4 +#define BATREG_4_2_2_5_V 5 +#define BATREG_4_2_5_0_V 6 +#define BATREG_4_2_7_5_V 7 +#define BATREG_4_3_0_0_V 8 +#define BATREG_4_3_2_5_V 9 +#define BATREG_4_3_5_0_V 10 +#define BATREG_4_3_7_5_V 11 +#define BATREG_4_4_0_0_V 12 +#define BATREG_4_4_2_5_V 13 +#define BATREG_4_4_5_0_V 14 +#define BATREG_4_4_7_5_V 15 +#define BATREG_MASK 0x0F + +/* Weak Battery Voltage */ +#define WEAKBAT_3_0_0_V 0 +#define WEAKBAT_3_0_5_V 1 +#define WEAKBAT_3_1_0_V 2 +#define WEAKBAT_3_1_5_V 3 +#define WEAKBAT_3_2_0_V 4 +#define WEAKBAT_3_2_5_V 5 +#define WEAKBAT_3_3_0_V 6 +#define WEAKBAT_3_3_5_V 7 +#define WEAKBAT_3_4_0_V 8 +#define WEAKBAT_3_4_5_V 9 +#define WEAKBAT_3_5_0_V 10 +#define WEAKBAT_3_5_5_V 11 +#define WEAKBAT_3_6_0_V 12 +#define WEAKBAT_3_6_5_V 13 +#define WEAKBAT_3_7_0_V 14 +#define WEAKBAT_3_7_5_V 15 +#define WEAKBAT_MASK 0xF0 + +/* top-off charge current */ +#define TOPOFF_100mA 0 +#define TOPOFF_150mA 1 +#define TOPOFF_200mA 2 +#define TOPOFF_250mA 3 +#define TOPOFF_300mA 4 +#define TOPOFF_350mA 5 +#define TOPOFF_400mA 6 +#define TOPOFF_450mA 7 +#define TOPOFF_500mA 8 +#define TOPOFF_550mA 9 +#define TOPOFF_600mA 10 +#define TOPOFF_650mA 11 +#define TOPOFF_MASK 0x07 + +/* discharge current */ +#define DISCHARGELIMIT_DISABLED 0 +#define DISCHARGELIMIT_2_0_A 1 +#define DISCHARGELIMIT_2_5_A 2 +#define DISCHARGELIMIT_3_0_A 3 +#define DISCHARGELIMIT_3_5_A 4 +#define DISCHARGELIMIT_4_0_A 5 +#define DISCHARGELIMIT_4_5_A 6 +#define DISCHARGELIMIT_5_0_A 7 +#define DISCHARGELIMIT_MASK 0xF8 + +/* OTG voltage */ +#define VOTG_5_0_V 0 +#define VOTG_5_1_V 1 +#define VOTG_5_2_V 2 +#define VOTG_MASK 0x0F + +/* Fast timer */ +#define FASTTIMER_3_5_HOUR 0 +#define FASTTIMER_4_5_HOUR 1 +#define FASTTIMER_5_5_HOUR 2 +#define FASTTIMER_DISABLED 3 +#define FASTTIMER_MASK 0xF3 + +/* Topoff timer */ +#define TOPOFFTIMER_10MIN 0 +#define TOPOFFTIMER_20MIN 1 +#define TOPOFFTIMER_30MIN 2 +#define TOPOFFTIMER_45MIN 3 +#define TOPOFFTIMER_MASK 0xFC + +/* Enable charger */ +#define CHARGE_EN 0x02 + +void SM5414_i2c_int_read(struct i2c_client *client); + +#define BATREG_MASK 0x0F + +struct sec_chg_info { + bool dummy; + u8 int_1_s; + u8 int_2_s; + u8 int_3_s; + u8 int_1_h; + u8 int_2_h; + u8 int_3_h; +}; + +#endif /* __SM5414_CHARGER_H */ diff --git a/include/linux/battery/charger/sm5701_charger.h b/include/linux/battery/charger/sm5701_charger.h new file mode 100644 index 00000000..9956cddf --- /dev/null +++ b/include/linux/battery/charger/sm5701_charger.h @@ -0,0 +1,167 @@ +/* + * SM5701_charger.h + * SiliconMitus SM5701 Charger Header + * + * Copyright (C) 2014 SiliconMitus + * + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __SM5701_CHARGER_H +#define __SM5701_CHARGER_H __FILE__ +#include +#include + +/* SM5701 Registers. */ +#define SM5701_INT1 0x00 +#define SM5701_INT2 0x01 +#define SM5701_INT3 0x02 +#define SM5701_INTMASK1 0x03 +#define SM5701_INTMASK2 0x04 +#define SM5701_INTMASK3 0x05 +#define SM5701_STATUS1 0x06 +#define SM5701_STATUS2 0x07 +#define SM5701_STATUS3 0x08 +#define SM5701_CNTL 0x09 +#define SM5701_VBUSCNTL 0x0A +#define SM5701_CHGCNTL1 0x0B +#define SM5701_CHGCNTL2 0x0C +#define SM5701_CHGCNTL3 0x0D +#define SM5701_CHGCNTL4 0x0E + +#define SM5701_FLEDCNTL1 0x0F +#define SM5701_FLEDCNTL2 0x10 +#define SM5701_FLEDCNTL3 0x11 +#define SM5701_FLEDCNTL4 0x12 +#define SM5701_FLEDCNTL5 0x13 +#define SM5701_FLEDCNTL6 0x14 +#define SM5701_DEVICE_ID 0x15 + +#define BATREG_MASK 0x00 + +//INT1 +#define SM5701_INT1_AICL 0x01 +#define SM5701_INT1_BATOVP 0x02 +#define SM5701_INT1_VBUSOK 0x04 +#define SM5701_INT1_VBUSUVLO 0x08 +#define SM5701_INT1_VBUSOVP 0x10 +#define SM5701_INT1_VBUSLIMIT 0x20 +#define SM5701_INT1_CHGRSTF 0x40 +#define SM5701_INT1_NOBAT 0x80 +//INT2 +#define SM5701_INT2_TOPOFF 0x01 +#define SM5701_INT2_DONE 0x02 +#define SM5701_INT2_FASTTMROFF 0x04 +#define SM5701_INT2_CHGON 0x08 +//INT3 +#define SM5701_INT3_THEMSHDN 0x01 +#define SM5701_INT3_THEMREG 0x02 +#define SM5701_INT3_FLEDSHORT 0x04 +#define SM5701_INT3_FLEDOPEN 0x08 +#define SM5701_INT3_BOOSTPOK_NG 0x10 +#define SM5701_INT3_BOOSTPOK 0x20 +#define SM5701_INT3_AMSTMROFF 0x40 +#define SM5701_INT3_LOWBATT 0x80 +//INTMSK1 +#define SM5701_INTMSK1_AICLM 0x01 +#define SM5701_INTMSK1_BATOVPM 0x02 +#define SM5701_INTMSK1_VBUSOKM 0x04 +#define SM5701_INTMSK1_VBUSUVLOM 0x08 +#define SM5701_INTMSK1_VBUSOVPM 0x10 +#define SM5701_INTMSK1_VBUSLIMITM 0x20 +#define SM5701_INTMSK1_CHGRSTFM 0x40 +#define SM5701_INTMSK1_NOBATM 0x80 +//INTMSK2 +#define SM5701_INTMSK2_TOPOFFM 0x01 +#define SM5701_INTMSK2_DONEM 0x02 +#define SM5701_INTMSK2_FASTTMROFFM 0x04 +#define SM5701_INTMSK2_CHGONM 0x08 +//INTMSK3 +#define SM5701_INTMSK3_THEMSHDNM 0x01 +#define SM5701_INTMSK3_THEMREGM 0x02 +#define SM5701_INTMSK3_FLEDSHORTM 0x04 +#define SM5701_INTMSK3_FLEDOPENM 0x08 +#define SM5701_INTMSK3_BOOSTPOK_NGM 0x10 +#define SM5701_INTMSK3_BOOSTPOKM 0x20 +#define SM5701_INTMSK3_AMSTMROFFM 0x40 +#define SM5701_INTMSK3_LOWBATTM 0x80 +//STATUS1 +#define SM5701_STATUS1_AICL 0x01 +#define SM5701_STATUS1_BATOVP 0x02 +#define SM5701_STATUS1_VBUSOK 0x04 +#define SM5701_STATUS1_VBUSUVLO 0x08 +#define SM5701_STATUS1_VBUSOVP 0x10 +#define SM5701_STATUS1_VBUSLIMIT 0x20 +#define SM5701_STATUS1_CHGRSTF 0x40 +#define SM5701_STATUS1_NOBAT 0x80 +//STATUS2 +#define SM5701_STATUS2_TOPOFF 0x01 +#define SM5701_STATUS2_DONE 0x02 +#define SM5701_STATUS2_FASTTMROFF 0x04 +#define SM5701_STATUS2_CHGON 0x08 +//STATUS3 +#define SM5701_STATUS3_THEMSHDN 0x01 +#define SM5701_STATUS3_THEMREG 0x02 +#define SM5701_STATUS3_FLEDSHORT 0x04 +#define SM5701_STATUS3_FLEDOPEN 0x08 +#define SM5701_STATUS3_BOOSTPOK_NG 0x10 +#define SM5701_STATUS3_BOOSTPOK 0x20 +#define SM5701_STATUS3_ABSTMROFF 0x40 +#define SM5701_STATUS3_LOWBATT 0x80 +//CNTL +#define SM5701_CNTL_OPERATIONMODE 0x07 +#define SM5701_CNTL_RESET 0x08 +#define SM5701_CNTL_OVPSEL 0x30 +#define SM5701_CNTL_FREQSEL 0xc0 +#define SM5701_RESET 0x1 +//VBUSCNTL +#define SM5701_VBUSCNTL_VBUSLIMIT 0x07 +#define SM5701_VBUSCNTL_AICLTH 0x38 +#define SM5701_VBUSCNTL_AICLEN 0x40 + +//CHGCNTL1 +#define SM5701_CHGCNTL1_TOPOFF 0x0F +#define SM5701_CHGCNTL1_AUTOSTOP 0x10 +#define SM5701_CHGCNTL1_HSSLPCTRL 0x60 + +//CHGCNTL2 +#define SM5701_CHGCNTL2_FASTCHG 0x3F + +//CHGCNTL3 +#define SM5701_CHGCNTL3_BATREG 0x1F + +//CHGCNTL4 +#define SM5701_CHGCNTL4_TOPOFFTIMER 0x03 +#define SM5701_CHGCNTL4_FASTTIMER 0x0B + +#define SM5701_STATUS1_NOBAT_SHIFT 7 + +/* Enable charger Operation Mode */ +#define OP_MODE_CHG_ON 0x02 + +/* Disable charger Operation Mode */ +#define OP_MODE_CHG_OFF 0x01 + +#define FREQ_15 (0x00 << 6) +#define FREQ_12 (0x01 << 6) +#define FREQ_18 (0x02 << 6) +#define FREQ_24 (0x03 << 6) + +enum { + POWER_SUPPLY_VBUS_UNKNOWN = 0, + POWER_SUPPLY_VBUS_UVLO, + POWER_SUPPLY_VBUS_WEAK, + POWER_SUPPLY_VBUS_OVLO, + POWER_SUPPLY_VBUS_GOOD, +}; + +#endif /* __SM5701_CHARGER_H */ diff --git a/include/linux/battery/charger/smb328_charger.h b/include/linux/battery/charger/smb328_charger.h new file mode 100644 index 00000000..13da7b1c --- /dev/null +++ b/include/linux/battery/charger/smb328_charger.h @@ -0,0 +1,72 @@ +/* + * smb328_charger.h + * Samsung SMB328 Charger Header + * + * Copyright (C) 2012 Samsung Electronics, Inc. + * + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __SMB328_CHARGER_H +#define __SMB328_CHARGER_H __FILE__ + +#if defined(CONFIG_MACH_DELOSLTE_KOR_SKT) || defined(CONFIG_MACH_DELOSLTE_KOR_KT) || \ + defined(CONFIG_MACH_DELOSLTE_KOR_LGT) +#define SIOP_CHARGING_CURRENT_LIMIT_FEATURE +#endif + +/* Slave address should be shifted to the right 1bit. + * R/W bit should NOT be included. + */ + +#define SEC_CHARGER_I2C_SLAVEADDR (0x69 >> 1) + +#define CMD_A_ALLOW_WRITE BIT(7) +#define CMD_CHARGE_EN BIT(4) +#define CFG_AICL_ENABLE BIT(2) +#define CFG_OTG_ENABLE BIT(5) +#define CFG_AUTOMATIC_INPUT_CURRENT_LIMIT BIT(4) +#define CFG_AICL_VOLTAGE 0x03 +#define CFG_FLOAT_VOLTAGE_MASK 0x7E +#define CFG_FLOAT_VOLTAGE_SHIFT 1 +#define CFG_CHARGE_CURRENT_MASK 0xE0 +#define CFG_CHARGE_CURRENT_SHIFT 5 +#define CFG_INPUT_CURRENT_MASK 0xE0 +#define CFG_INPUT_CURRENT_SHIFT 5 +#define CFG_TERMINATION_CURRENT_MASK 0x07 +#define CFG_TERMINATION_CURRENT_SHIFT 0 +#define CFG_STAT_ASSETION_TERM_MASK 0xE0 +#define CFG_STAT_ASSETION_TERM_SHIFT 5 + +/* Register define */ +#define SMB328_CHARGE_CURRENT 0X00 +#define SMB328_INPUT_CURRENTLIMIT 0X01 +#define SMB328_FLOAT_VOLTAGE 0X02 +#define SMB328_FUNCTION_CONTROL_A 0X03 +#define SMB328_FUNCTION_CONTROL_B 0X04 +#define SMB328_FUNCTION_CONTROL_C 0X05 +#define SMB328_OTG_POWER_AND_LDO 0x06 +#define SMB328_VARIOUS_FUNCTIONS 0x07 +#define SMB328_OTHER_CONFIGURATION_SELECTION 0x08 +#define SMB328_INTERRUPT_SIGNAL_SELECTION 0x09 + +#define SMB328_COMMAND 0x31 +#define SMB328_INTERRUPT_STATUS_A 0x32 +#define SMB328_BATTERY_CHARGING_STATUS_A 0x33 +#define SMB328_INTERRUPT_STATUS_B 0x34 +#define SMB328_BATTERY_CHARGING_STATUS_B 0x35 +#define SMB328_BATTERY_CHARGING_STATUS_C 0x36 +#define SMB328_INTERRUPT_STATUS_C 0x37 +#define SMB328_BATTERY_CHARGING_STATUS_D 0x38 +#define SMB328_AUTOMATIC_INPUT_CURRENT_STATUS 0x39 + +#endif /* __SMB328_CHARGER_H */ diff --git a/include/linux/battery/charger/smb358_charger.h b/include/linux/battery/charger/smb358_charger.h new file mode 100755 index 00000000..26f9e620 --- /dev/null +++ b/include/linux/battery/charger/smb358_charger.h @@ -0,0 +1,79 @@ +/* + * smb358_charger.h + * Samsung SMB358 Charger Header + * + * Copyright (C) 2012 Samsung Electronics, Inc. + * + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __SMB358_CHARGER_H +#define __SMB358_CHARGER_H __FILE__ + +/* Slave address should be shifted to the right 1bit. + * R/W bit should NOT be included. + */ +#define SEC_CHARGER_I2C_SLAVEADDR 0x6A + +/* Register define */ +#define SMB358_CHARGE_CURRENT 0x00 +#define SMB358_INPUT_CURRENTLIMIT 0x01 +#define SMB358_VARIOUS_FUNCTIONS 0x02 +#define SMB358_FLOAT_VOLTAGE 0x03 +#define SMB358_CHARGE_CONTROL 0x04 +#define SMB358_STAT_TIMERS_CONTROL 0x05 +#define SMB358_PIN_ENABLE_CONTROL 0x06 +#define SMB358_THERM_CONTROL_A 0x07 +#define SMB358_SYSOK_USB30_SELECTION 0x08 +#define SMB358_OTHER_CONTROL_A 0x09 +#define SMB358_OTG_TLIM_THERM_CONTROL 0x0A +#define SMB358_LIMIT_CELL_TEMPERATURE_MONITOR 0x0B +#define SMB358_FAULT_INTERRUPT 0x0C +#define SMB358_STATUS_INTERRUPT 0x0D +#define SMB358_I2C_BUS_SLAVE_ADDR 0x0E + +#define SMB358_COMMAND_A 0x30 +#define SMB358_COMMAND_B 0x31 +#define SMB358_COMMAND_C 0x33 +#define SMB358_ADC_STATUS 0x34 +#define SMB358_INTERRUPT_STATUS_A 0x35 +#define SMB358_INTERRUPT_STATUS_B 0x36 +#define SMB358_INTERRUPT_STATUS_C 0x37 +#define SMB358_INTERRUPT_STATUS_D 0x38 +#define SMB358_INTERRUPT_STATUS_E 0x39 +#define SMB358_INTERRUPT_STATUS_F 0x3A +#define SMB358_STATUS_A 0x3B +#define SMB358_STATUS_B 0x3C +#define SMB358_STATUS_C 0x3D +#define SMB358_STATUS_D 0x3E +#define SMB358_STATUS_E 0x3F + +#define ENABLE_WRT_ACCESS 0x80 +#define SMB358_ENABLE_WRITE 1 +#define SMB358_DISABLE_WRITE 0 + +#define SMB358_ENABLE_CHARGER 0x02 + +ssize_t smb358_chg_show_attrs(struct device *dev, + struct device_attribute *attr, char *buf); + +ssize_t smb358_chg_store_attrs(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count); + +#define SMB358_CHARGER_ATTR(_name) \ +{ \ + .attr = {.name = #_name, .mode = 0664}, \ + .show = smb358_chg_show_attrs, \ + .store = smb358_chg_store_attrs, \ +} +#endif /* __SMB358_CHARGER_H */ diff --git a/include/linux/battery/charger/sprd27x3_charger4samsung.h b/include/linux/battery/charger/sprd27x3_charger4samsung.h new file mode 100755 index 00000000..425a9633 --- /dev/null +++ b/include/linux/battery/charger/sprd27x3_charger4samsung.h @@ -0,0 +1,124 @@ +/* + * sprd27x3_charger4samsung.h + * Samsung SPRD27X3 Charger Header + * + * Copyright (C) 2012 Samsung Electronics, Inc. + * + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __SPRD27X3_CHARGER4SAMSUNG_H +#define __SPRD27X3_CHARGER4SAMSUNG_H + +/* Slave address should be shifted to the right 1bit. + * R/W bit should NOT be included. + */ + +#define SPRDBAT_AUXADC_CAL_NO 0 +#define SPRDBAT_AUXADC_CAL_NV 1 +#define SPRDBAT_AUXADC_CAL_CHIP 2 + +#define SPRDBAT_CHG_END_NONE_BIT 0 +#define SPRDBAT_CHG_END_FULL_BIT (1 << 0) +#define SPRDBAT_CHG_END_OTP_OVERHEAT_BIT (1 << 1) +#define SPRDBAT_CHG_END_OTP_COLD_BIT (1 << 2) +#define SPRDBAT_CHG_END_TIMEOUT_BIT (1 << 3) +#define SPRDBAT_CHG_END_OVP_BIT (1 << 4) + +//#define SPRDBAT_AVERAGE_COUNT 3 + +#define SPRDBAT_AUXADC_CAL_TYPE_NO 0 +#define SPRDBAT_AUXADC_CAL_TYPE_NV 1 +#define SPRDBAT_AUXADC_CAL_TYPE_EFUSE 2 + +#define SPRDBAT_CCCV_MIN 0x00 +#define SPRDBAT_CCCV_MAX 0x3F +#define SPRDBAT_CCCV_DEFAULT 0x0 +#define ONE_CCCV_STEP_VOL 75 //7.5mV + +#ifdef CONFIG_MACH_VIVALTO +#define SPRDBAT_CHG_END_VOL_PURE (4350) +#elif defined(CONFIG_MACH_HIGGS) +#define SPRDBAT_CHG_END_VOL_PURE (4350) +#elif defined(CONFIG_MACH_YOUNG2) +#define SPRDBAT_CHG_END_VOL_PURE (4200) +#else +#define SPRDBAT_CHG_END_VOL_PURE (4200) +#endif +#define SPRDBAT_CHG_END_H (SPRDBAT_CHG_END_VOL_PURE + 25) +#define SPRDBAT_CHG_END_L (SPRDBAT_CHG_END_VOL_PURE - 10) +#define SPRDBAT_RECHG_VOL (SPRDBAT_CHG_END_VOL_PURE - 70) //recharge voltage + +#define SPRDBAT_CHG_OVP_LEVEL_MIN 5600 +#define SPRDBAT_CHG_OVP_LEVEL_MAX 9000 +#define SPRDBAT_OVP_STOP_VOL 6500 +#define SPRDBAT_OVP_RESTERT_VOL 5800 //reserved + +/*charge current type*/ +#define SPRDBAT_CHG_CUR_LEVEL_MIN 300 +#define SPRDBAT_CHG_CUR_LEVEL_MAX 2300 +#define SPRDBAT_SDP_CUR_LEVEL 500 //usb +#define SPRDBAT_DCP_CUR_LEVEL 700 //AC +#define SPRDBAT_CDP_CUR_LEVEL 700 //AC&USB + +#define SPRDBAT_CHG_END_CUR 70 + +#define SPRDBAT_OTP_HIGH_STOP 600 //60C +#define SPRDBAT_OTP_HIGH_RESTART (550) //55C +#define SPRDBAT_OTP_LOW_STOP -50 //-5C +#define SPRDBAT_OTP_LOW_RESTART 0 //0C + +#define SPRDBAT_CHG_NORMAL_TIMEOUT (6*60*60) /* set for charge over time, 6 hours */ +#define SPRDBAT_CHG_SPECIAL_TIMEOUT (90*60) /* when charge timeout, recharge timeout is 90min */ + +#define SPRDBAT_TRICKLE_CHG_TIME (1500) //reserved + +#define SPRDBAT_ADC_CHANNEL_VCHG ADC_CHANNEL_VCHGSEN + +#define SPRDBAT_ADC_CHANNEL_TEMP ADC_CHANNEL_3 +#define SPRDBAT_ADC_CHANNEL_TEMP_WPA ADC_CHANNEL_1 +#define SPRDBAT_ADC_CHANNEL_TEMP_DCXO ADC_CHANNEL_2 + +#define SPRDBAT_POLL_TIMER_NORMAL 60 +#define SPRDBAT_POLL_TIMER_TEMP 1 + +#define SPRDBAT_TEMP_TRIGGER_TIMES 2 + +#define SPRDBAT_CAPACITY_MONITOR_NORMAL (HZ*10) +#define SPRDBAT_CAPACITY_MONITOR_FAST (HZ*5) + +enum { + POWER_SUPPLY_PWR_RDY_FALSE = 0, + POWER_SUPPLY_PWR_RDY_TRUE, + POWER_SUPPLY_PWR_RDY_UNKNOWN, +}; + + +#if !defined(CONFIG_CHARGER_SM5414) +struct sec_chg_info { + bool dummy; +}; +#endif + +#if 0 +struct sprdbat_auxadc_cal { + uint16_t p0_vol; //4.2V + uint16_t p0_adc; + uint16_t p1_vol; //3.6V + uint16_t p1_adc; + uint16_t cal_type; +}; +#endif +#endif /* __SPRD27X3_CHARGER4SAMSUNG_H */ + + + diff --git a/include/linux/battery/fuelgauge/d2199_fuelgauge.h b/include/linux/battery/fuelgauge/d2199_fuelgauge.h new file mode 100644 index 00000000..81cc027d --- /dev/null +++ b/include/linux/battery/fuelgauge/d2199_fuelgauge.h @@ -0,0 +1,605 @@ +/* + * adc_fuelgauge.h + * Samsung ADC Fuel Gauge Header + * + * Copyright (C) 2012 Samsung Electronics, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __ADC_FUELGAUGE_H +#define __ADC_FUELGAUGE_H __FILE__ + +#include +#include +#include +#include + +/* Slave address should be shifted to the right 1bit. + * R/W bit should NOT be included. + */ +static const char __initdata d2199_battery_banner[] = \ + "D2199 Battery, (c) 2013 Dialog Semiconductor Ltd.\n"; + +/*************************************************************************** + Pre-definition +***************************************************************************/ +#define FALSE (0) +#define TRUE (1) + +#define ADC_RES_MASK_LSB (0x0F) +#define ADC_RES_MASK_MSB (0xF0) + +#if USED_BATTERY_CAPACITY == BAT_CAPACITY_1800MA + +#define ADC_VAL_100_PERCENT 3645 // About 4280mV +#define CV_START_ADC 3275 // About 4100mV +#define MAX_FULL_CHARGED_ADC 3788 // About 4350mV + +#define D2153_BAT_CHG_FRST_FULL_LVL 4310 // About EOC 160mA +#define D2153_BAT_CHG_BACK_FULL_LVL 4347 // 4340mV -> 4347mV + +#define FIRST_VOLTAGE_DROP_ADC 115 + +#define FIRST_VOLTAGE_DROP_LL_ADC 340 +#define FIRST_VOLTAGE_DROP_L_ADC 60 +#define FIRST_VOLTAGE_DROP_RL_ADC 25 + +#define CHARGE_OFFSET_KRNL_H 880 +#define CHARGE_OFFSET_KRNL_L 5 + +#define CHARGE_ADC_KRNL_H 1700 +#define CHARGE_ADC_KRNL_L 2050 +#define CHARGE_ADC_KRNL_F 2060 + +#define CHARGE_OFFSET_KRNL 77 +#define CHARGE_OFFSET_KRNL2 50 + +#define LAST_CHARGING_WEIGHT 80 // 900 +#define VBAT_3_4_VOLTAGE_ADC 1605 + +#elif USED_BATTERY_CAPACITY == BAT_CAPACITY_2100MA +#if defined(CONFIG_MACH_WILCOX) +#define ADC_VAL_100_PERCENT 3686 // About 4300mV +#elif defined(CONFIG_MACH_CS05) +#define ADC_VAL_100_PERCENT 3676 // About 4280mV +#else +#define ADC_VAL_100_PERCENT 3645 // About 4280mV +#endif + +#define CV_START_ADC 3275 // About 4100mV +#define MAX_FULL_CHARGED_ADC 3788 // About 4350mV + +#define D2153_BAT_CHG_FRST_FULL_LVL 4310 // About EOC 160mA +#define D2153_BAT_CHG_BACK_FULL_LVL 4340 // About EOC 50mA + +#if defined(CONFIG_MACH_WILCOX) || defined(CONFIG_MACH_CS05) +#define FIRST_VOLTAGE_DROP_ADC 145 // 130 -> 145 + +#define FIRST_VOLTAGE_DROP_LL_ADC 340 +#define FIRST_VOLTAGE_DROP_L_ADC 60 +#define FIRST_VOLTAGE_DROP_RL_ADC 25 + +#define CHARGE_OFFSET_KRNL_H 360 // 400 -> 360 +#define CHARGE_OFFSET_KRNL_L 160 // 170 -> 160 + +#define CHARGE_ADC_KRNL_H 1150 // 1155 -> 1150 +#define CHARGE_ADC_KRNL_L 2304 +#define CHARGE_ADC_KRNL_F 2305 + +#define CHARGE_OFFSET_KRNL 20 +#define CHARGE_OFFSET_KRNL2 104 // 94 -> 104 + +#define LAST_CHARGING_WEIGHT 124 +#else +#define FIRST_VOLTAGE_DROP_ADC 100 // 156 + +#define FIRST_VOLTAGE_DROP_LL_ADC 340 +#define FIRST_VOLTAGE_DROP_L_ADC 60 +#define FIRST_VOLTAGE_DROP_RL_ADC 25 + +#define CHARGE_OFFSET_KRNL_H 270 +#define CHARGE_OFFSET_KRNL_L 20 + +#define CHARGE_ADC_KRNL_H 1700 +#define CHARGE_ADC_KRNL_L 2050 +#define CHARGE_ADC_KRNL_F 2060 + +#define CHARGE_OFFSET_KRNL 20 +#define CHARGE_OFFSET_KRNL2 50 + +#define LAST_CHARGING_WEIGHT 55 +#endif +#define VBAT_3_4_VOLTAGE_ADC 1605 + +#else + +#define ADC_VAL_100_PERCENT 3445 +#define CV_START_ADC 3338 +#define MAX_FULL_CHARGED_ADC 3788 // About 4350mV + +#define D2153_BAT_CHG_FRST_FULL_LVL 4160 // About EOC 160mA +#define D2153_BAT_CHG_BACK_FULL_LVL 4185 // About EOC 60mA + +#define FIRST_VOLTAGE_DROP_ADC 165 + +#define FIRST_VOLTAGE_DROP_LL_ADC 340 +#define FIRST_VOLTAGE_DROP_L_ADC 60 +#define FIRST_VOLTAGE_DROP_RL_ADC 25 + +#define CHARGE_OFFSET_KRNL_H 880 +#define CHARGE_OFFSET_KRNL_L 5 + +#define CHARGE_ADC_KRNL_H 1700 +#define CHARGE_ADC_KRNL_L 2050 +#define CHARGE_ADC_KRNL_F 2060 + +#define CHARGE_OFFSET_KRNL 77 +#define CHARGE_OFFSET_KRNL2 50 + +#define LAST_CHARGING_WEIGHT 60 // 900 +#define VBAT_3_4_VOLTAGE_ADC 1605 + +#endif /* USED_BATTERY_CAPACITY == BAT_CAPACITY_????MA */ + +#define FULL_CAPACITY 1000 + +#define NORM_NUM 10000 +#define NORM_CHG_NUM 100000 + +#define DISCHARGE_SLEEP_OFFSET 55 // 45 +#define LAST_VOL_UP_PERCENT 75 + + +////////////////////////////////////////////////////////////////////////////// +// Static Variable Declaration +////////////////////////////////////////////////////////////////////////////// + +static struct sec_fuelgauge_info *gbat = NULL; +static u8 is_called_by_ticker = 0; +static u16 ACT_4P2V_ADC = 0; +static u16 ACT_3P4V_ADC = 0; + + +// This array is for setting ADC_CONT register about each channel. +static struct adc_cont_in_auto adc_cont_inven[D2199_ADC_CHANNEL_MAX - 1] = { + // VBAT_S channel + [D2199_ADC_VOLTAGE] = { + .adc_preset_val = 0, + .adc_cont_val = (D2199_ADC_AUTO_EN_MASK | D2199_ADC_MODE_MASK + | D2199_AUTO_VBAT_EN_MASK), + .adc_msb_res = D2199_VDD_RES_VBAT_RES_REG, + .adc_lsb_res = D2199_ADC_RES_AUTO1_REG, + .adc_lsb_mask = ADC_RES_MASK_LSB, + }, + // TEMP_1 channel + [D2199_ADC_TEMPERATURE_1] = { + .adc_preset_val = D2199_TEMP1_ISRC_EN_MASK, + .adc_cont_val = (D2199_ADC_AUTO_EN_MASK | D2199_ADC_MODE_MASK + | D2199_TEMP1_ISRC_EN_MASK), + .adc_msb_res = D2199_TBAT1_RES_TEMP1_RES_REG, + .adc_lsb_res = D2199_ADC_RES_AUTO1_REG, + .adc_lsb_mask = ADC_RES_MASK_MSB, + }, + // TEMP_2 channel + [D2199_ADC_TEMPERATURE_2] = { + .adc_preset_val = D2199_TEMP2_ISRC_EN_MASK, + .adc_cont_val = (D2199_ADC_AUTO_EN_MASK | D2199_ADC_MODE_MASK + | D2199_TEMP2_ISRC_EN_MASK), + .adc_msb_res = D2199_TBAT2_RES_TEMP2_RES_REG, + .adc_lsb_res = D2199_ADC_RES_AUTO3_REG, + .adc_lsb_mask = ADC_RES_MASK_LSB, + }, + // VF channel + [D2199_ADC_VF] = { + .adc_preset_val = D2199_AD4_ISRC_ENVF_ISRC_EN_MASK, + .adc_cont_val = (D2199_ADC_AUTO_EN_MASK | D2199_ADC_MODE_MASK + | D2199_AUTO_VF_EN_MASK + | D2199_AD4_ISRC_ENVF_ISRC_EN_MASK), + .adc_msb_res = D2199_ADCIN4_RES_VF_RES_REG, + .adc_lsb_res = D2199_ADC_RES_AUTO2_REG, + .adc_lsb_mask = ADC_RES_MASK_LSB, + }, + // AIN channel + [D2199_ADC_AIN] = { + .adc_preset_val = 0, + .adc_cont_val = (D2199_ADC_AUTO_EN_MASK | D2199_ADC_MODE_MASK + | D2199_AUTO_AIN_EN_MASK), + .adc_msb_res = D2199_ADCIN5_RES_AIN_RES_REG, + .adc_lsb_res = D2199_ADC_RES_AUTO2_REG, + .adc_lsb_mask = ADC_RES_MASK_MSB + }, +}; + +/* Table for compensation of charge offset in CC mode */ +static u16 initialize_charge_offset[] = { +// 500, 600, 700, 800, 900, 1000, 1100, 1200, + 18, 22, 26, 30, 34, 36, 40, 44, +}; + +static u16 initialize_charge_up_cc[] = { +// 500, 600, 700, 800, 900, 1000, 1100, 1200, + 45 +}; + +/* LUT for NCP15XW223 thermistor with 10uA current source selected */ +static struct adc2temp_lookuptbl adc2temp_lut = { + // Case of NCP03XH223 +#if defined(CONFIG_MACH_BAFFIN) || defined(CONFIG_MACH_BAFFINQ) + .adc = { // ADC-12 input value + 2516, 1890, 1551, 1218, 950, 911, 802, + 652, 505, 437, 362, 300, 252, 210, + 192, 175, 150, 128, 110, 100, 92, + 86, + }, + .temp = { // temperature (degree K) + C2K(-200), C2K(-150), C2K(-100), C2K(-50), C2K(0), C2K(20), C2K(50), + C2K(100), C2K(150), C2K(200), C2K(250), C2K(300), C2K(350), C2K(400), + C2K(430), C2K(450), C2K(500), C2K(550), C2K(600), C2K(630), C2K(650), + C2K(670), + }, +#elif defined(CONFIG_MACH_WILCOX) || defined(CONFIG_MACH_CS05) + #ifdef CONFIG_MACH_WILCOX_CMCC + //For Wilcox TD_SCDMA + .adc = { // ADC-12 input value + 2000, 1633, 1275, 1031, 831, 772, 685, + 554, 471, 388, 314, 268, 224, 196, + 180, 167, 148, 125, 107, 102, 97, + 83, + }, + #else + //For Wilcox CU and Baffin RD + .adc = { // ADC-12 input value + 2000, 1633, 1275, 1031, 831, 772, 685, + 554, 471, 388, 314, 268, 224, 189, + 171, 159, 136, 117, 100, 93, 88, + 75, + }, + #endif + .temp = { // temperature (degree K) + C2K(-200), C2K(-150), C2K(-100), C2K(-50), C2K(0), C2K(20), C2K(50), + C2K(100), C2K(150), C2K(200), C2K(250), C2K(300), C2K(350), C2K(400), + C2K(430), C2K(450), C2K(500), C2K(550), C2K(600), C2K(630), C2K(650), + C2K(700), + }, +#elif defined(CONFIG_MACH_CS02) + .adc = { // ADC-12 input value + 2091, 1601, 1246, 1012, 855, 661, 543, + 444, 370, 347, 337, 327, 317, 257, + 221, 183, 155, 135, 113, 99, 85, + 76, + }, + .temp = { // temperature (degree K) + C2K(-200), C2K(-150), C2K(-100), C2K(-50), C2K(0), C2K(50), C2K(100), + C2K(150), C2K(200), C2K(220), C2K(230), C2K(240), C2K(250), C2K(300), + C2K(350), C2K(400), C2K(450), C2K(500), C2K(550), C2K(600), C2K(650), + C2K(700), + }, +#else + .adc = { // ADC-12 input value + 1458, 1156, 859, 761, 614, 566, 510, + 418, 344, 290, 244, 207, 176, 145, + 130, 123, 107, 88, 76, 70, 66, + 63, + }, + .temp = { // temperature (degree K) + C2K(-200), C2K(-150), C2K(-100), C2K(-50), C2K(0), C2K(20), C2K(50), + C2K(100), C2K(150), C2K(200), C2K(250), C2K(300), C2K(350), C2K(400), + C2K(430), C2K(450), C2K(500), C2K(550), C2K(600), C2K(630), C2K(650), + C2K(670), + }, +#endif +}; + +static u16 temp_lut_length = (u16)sizeof(adc2temp_lut.adc)/sizeof(u16); + +// adc = (vbat-2500)/2000*2^12 +// vbat (mV) = 2500 + adc*2000/2^12 +static struct adc2vbat_lookuptbl adc2vbat_lut = { + .adc = {1843, 1946, 2148, 2253, 2458, 2662, 2867, 2683, 3072, 3482,}, // ADC-12 input value + .offset = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}, // charging mode ADC offset + .vbat = {3400, 3450, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200,}, // VBAT (mV) +}; + +#if USED_BATTERY_CAPACITY == BAT_CAPACITY_1800MA +// For CS02 Project +static struct adc2soc_lookuptbl adc2soc_lut = { + .adc_ht = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ high temp + .adc_rt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ room temp + .adc_rlt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0) + .adc_lt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0) + .adc_lmt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low mid temp(-10) + .adc_llt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low low temp(-20) + .soc = { 0, 10, 30, 50, 70, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,}, // SoC in % +}; + +//Discharging Weight(Room/Low/low low) +// latest 0.1C +//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 +// This is for 0.1C +//static u16 adc_weight_section_discharge_1c[] = { 5, 8, 10, 45, 90, 115, 43, 50, 75, 80, 100, 100, 100, 100, 145}; +static u16 adc_weight_section_discharge_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195}; +static u16 adc_weight_section_discharge_rlt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195}; +static u16 adc_weight_section_discharge_lt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195}; +static u16 adc_weight_section_discharge_lmt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195}; +static u16 adc_weight_section_discharge_llt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195}; + +// This is for 0.2C +//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 + //{ 40, 80, 150, 150, 120, 59, 18, 16, 21, 39, 36, 58, 73, 80, 125}; +static u16 adc_weight_section_discharge_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125}; +static u16 adc_weight_section_discharge_rlt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125}; +static u16 adc_weight_section_discharge_lt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125}; +static u16 adc_weight_section_discharge_lmt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125}; +static u16 adc_weight_section_discharge_llt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125}; + +//Charging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 +static u16 adc_weight_section_charge[] = {2950, 355, 265, 66, 45, 93, 32, 33, 42, 92, 97, 110, 120, 90, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_rlt[] = {2950, 355, 265, 66, 45, 93, 32, 33, 42, 92, 97, 110, 120, 90, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_lt[] = {2950, 355, 265, 66, 45, 93, 32, 33, 42, 92, 97, 110, 120, 90, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_lmt[] = {2950, 355, 265, 66, 45, 93, 32, 33, 42, 92, 97, 110, 120, 90, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_llt[] = {2950, 355, 265, 66, 45, 93, 32, 33, 42, 92, 97, 110, 120, 90, LAST_CHARGING_WEIGHT}; + +static struct diff_tbl dischg_diff_tbl = { + // 0, 2-1, 4-3, 6-5, 9-7,19-10,29-20,39-30,49-40 + {173, 173, 143, 8, 15, 54, 40, 37, 50}, // 0.1C + {314, 314, 314, 145, 145, 177, 209, 221, 216}, // 0.2C +}; + +static u16 fg_reset_drop_offset[] = {172-50, 98-40}; + +#elif USED_BATTERY_CAPACITY == BAT_CAPACITY_2100MA + +#if defined(CONFIG_MACH_WILCOX) || defined(CONFIG_MACH_CS05) +static struct adc2soc_lookuptbl adc2soc_lut = { + .adc_ht = {1843, 1891, 2170, 2314, 2395, 2438, 2573, 2623, 2666, 2746, 2898, 3057, 3246, 3466, ADC_VAL_100_PERCENT,}, // ADC input @ high temp + .adc_rt = {1843, 1891, 2170, 2314, 2395, 2438, 2573, 2623, 2666, 2746, 2898, 3057, 3246, 3466, ADC_VAL_100_PERCENT,}, // ADC input @ room temp + .adc_rlt = {1843, 1891, 2170, 2314, 2395, 2438, 2573, 2623, 2666, 2746, 2898, 3057, 3246, 3466, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0) + .adc_lt = {1843, 1891, 2170, 2314, 2395, 2438, 2573, 2623, 2666, 2746, 2898, 3057, 3246, 3466, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0) + .adc_lmt = {1843, 1891, 2170, 2314, 2395, 2438, 2573, 2623, 2666, 2746, 2898, 3057, 3246, 3466, ADC_VAL_100_PERCENT,}, // ADC input @ low mid temp(-10) + .adc_llt = {1843, 1891, 2170, 2314, 2395, 2438, 2573, 2623, 2666, 2746, 2898, 3057, 3246, 3466, ADC_VAL_100_PERCENT,}, // ADC input @ low low temp(-20) + .soc = { 0, 10, 30, 50, 70, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,}, // SoC in % +}; + +// These table are for 0.1C load currents. +// latest 0.1C +//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 +static u16 adc_weight_section_discharge_1c[] = { 41, 123, 84, 36, 18, 25, 12, 10, 19, 32, 41, 60, 82, 94, 303}; +static u16 adc_weight_section_discharge_rlt_1c[] = { 41, 123, 84, 36, 18, 25, 12, 10, 19, 32, 41, 60, 82, 94, 303}; +static u16 adc_weight_section_discharge_lt_1c[] = { 41, 123, 84, 36, 18, 25, 12, 10, 19, 32, 41, 60, 82, 94, 303}; +static u16 adc_weight_section_discharge_lmt_1c[] = { 41, 123, 84, 36, 18, 25, 12, 10, 19, 32, 41, 60, 82, 94, 303}; +static u16 adc_weight_section_discharge_llt_1c[] = { 41, 123, 84, 36, 18, 25, 12, 10, 19, 32, 41, 60, 82, 94, 303}; + +// These table are for 0.2C load currents. +//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 +static u16 adc_weight_section_discharge_2c[] = { 47, 141, 93, 59, 25, 33, 15, 12, 24, 43, 45, 65, 89, 95, 303}; +static u16 adc_weight_section_discharge_rlt_2c[] = { 47, 141, 93, 59, 25, 33, 15, 12, 24, 43, 45, 65, 89, 95, 303}; +static u16 adc_weight_section_discharge_lt_2c[] = { 47, 141, 93, 59, 25, 33, 15, 12, 24, 43, 45, 65, 89, 95, 303}; +static u16 adc_weight_section_discharge_lmt_2c[] = { 47, 141, 93, 59, 25, 33, 15, 12, 24, 43, 45, 65, 89, 95, 303}; +static u16 adc_weight_section_discharge_llt_2c[] = { 47, 141, 93, 59, 25, 33, 15, 12, 24, 43, 45, 65, 89, 95, 303}; + +#ifdef CONFIG_MACH_WILCOX_CMCC +// For Wilcox TDSCDMA +//Charging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 +static u16 adc_weight_section_charge[] = {2950, 954, 468, 317, 89, 73, 26, 22, 42, 79, 88, 106, 120, 115, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_rlt[] = {2950, 954, 468, 317, 89, 73, 26, 22, 42, 79, 88, 106, 120, 115, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_lt[] = {2950, 954, 468, 317, 89, 73, 26, 22, 42, 79, 88, 106, 120, 115, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_lmt[] = {2950, 954, 468, 317, 89, 73, 26, 22, 42, 79, 88, 106, 120, 115, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_llt[] = {2950, 954, 468, 317, 89, 73, 26, 22, 42, 79, 88, 106, 120, 115, LAST_CHARGING_WEIGHT}; +#else +// For Wilcox CU and Baffin RD +//Charging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 +static u16 adc_weight_section_charge[] = {2950, 954, 468, 325, 102, 94, 33, 30, 52, 101, 112, 132, 141, 115, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_rlt[] = {2950, 954, 468, 325, 102, 94, 33, 30, 52, 101, 112, 132, 141, 115, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_lt[] = {2950, 954, 468, 325, 102, 94, 33, 30, 52, 101, 112, 132, 141, 115, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_lmt[] = {2950, 954, 468, 325, 102, 94, 33, 30, 52, 101, 112, 132, 141, 115, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_llt[] = {2950, 954, 468, 325, 102, 94, 33, 30, 52, 101, 112, 132, 141, 115, LAST_CHARGING_WEIGHT}; +#endif + +static struct diff_tbl dischg_diff_tbl = { + // 0, 1-2, 3-4, 5-6, 7-9,10-19,20-29,30-39,40-49,50-59,60-69,70-79,80-89,90-99, 100 + {355, 277, 267, 264, 180, 117, 110, 117, 115, 115, 95, 79, 69, 30, 35}, // 0.1C + {710, 706, 513, 409, 350, 249, 212, 202, 197, 211, 206, 182, 155, 135, 164}, // 0.2C +}; + +static u16 fg_reset_drop_offset[] = {86, 86}; + +#else +// For BAFFIN-RD project +static struct adc2soc_lookuptbl adc2soc_lut = { + .adc_ht = {1843, 1911, 2206, 2375, 2395, 2415, 2567, 2623, 2670, 2755, 2921, 3069, 3263, 3490, ADC_VAL_100_PERCENT,}, // ADC input @ high temp + .adc_rt = {1843, 1911, 2206, 2375, 2395, 2415, 2567, 2623, 2670, 2755, 2921, 3069, 3263, 3490, ADC_VAL_100_PERCENT,}, // ADC input @ room temp + .adc_rlt = {1843, 1911, 2206, 2375, 2395, 2415, 2567, 2623, 2670, 2755, 2921, 3069, 3263, 3490, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0) + .adc_lt = {1843, 1911, 2206, 2375, 2395, 2415, 2567, 2623, 2670, 2755, 2921, 3069, 3263, 3490, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0) + .adc_lmt = {1843, 1911, 2206, 2375, 2395, 2415, 2567, 2623, 2670, 2755, 2921, 3069, 3263, 3490, ADC_VAL_100_PERCENT,}, // ADC input @ low mid temp(-10) + .adc_llt = {1843, 1911, 2206, 2375, 2395, 2415, 2567, 2623, 2670, 2755, 2921, 3069, 3263, 3490, ADC_VAL_100_PERCENT,}, // ADC input @ low low temp(-20) + .soc = { 0, 10, 30, 50, 70, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,}, // SoC in % +}; + +//Discharging Weight(Room/Low/low low) for 0.1C +//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 +//static u16 adc_weight_section_discharge_1c[] = { 50, 95, 75, 15, 15, 25, 10, 10, 17, 28, 32, 54, 75, 100, 295}; +static u16 adc_weight_section_discharge_1c[] = { 49, 40, 15, 10, 14, 23, 10, 10, 17, 28, 32, 54, 75, 100, 295}; +static u16 adc_weight_section_discharge_rlt_1c[] = { 49, 40, 15, 10, 14, 23, 10, 10, 17, 28, 32, 54, 75, 100, 295}; +static u16 adc_weight_section_discharge_lt_1c[] = { 49, 40, 15, 10, 14, 23, 10, 10, 17, 28, 32, 54, 75, 100, 295}; +static u16 adc_weight_section_discharge_lmt_1c[] = { 49, 40, 15, 10, 14, 23, 10, 10, 17, 28, 32, 54, 75, 100, 295}; +static u16 adc_weight_section_discharge_llt_1c[] = { 49, 40, 15, 10, 14, 23, 10, 10, 17, 28, 32, 54, 75, 100, 295}; + +//Discharging Weight(Room/Low/low low) for 0.2C +//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 +//static u16 adc_weight_section_discharge_2c[] = { 50, 245, 210, 24, 18, 40, 14, 12, 23, 38, 37, 54, 75, 75, 265}; +static u16 adc_weight_section_discharge_2c[] = { 50, 215, 201, 24, 19, 42, 15, 13, 24, 38, 37, 54, 75, 75, 265}; +static u16 adc_weight_section_discharge_rlt_2c[] = { 50, 215, 201, 24, 19, 42, 15, 13, 24, 38, 37, 54, 75, 75, 265}; +static u16 adc_weight_section_discharge_lt_2c[] = { 50, 215, 201, 24, 19, 42, 15, 13, 24, 38, 37, 54, 75, 75, 265}; +static u16 adc_weight_section_discharge_lmt_2c[] = { 50, 215, 201, 24, 19, 42, 15, 13, 24, 38, 37, 54, 75, 75, 265}; +static u16 adc_weight_section_discharge_llt_2c[] = { 50, 215, 201, 24, 19, 42, 15, 13, 24, 38, 37, 54, 75, 75, 265}; + +//Charging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 +//static u16 adc_weight_section_charge[] = {2800, 642, 620, 63, 53, 108, 40, 33, 58, 113, 107, 133, 142, 63, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge[] = {2800, 642, 620, 63, 53, 106, 37, 31, 54, 108, 102, 130, 147, 70, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_rlt[] = {2800, 642, 620, 63, 53, 106, 37, 31, 54, 108, 102, 130, 147, 70, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_lt[] = {2800, 642, 620, 63, 53, 106, 37, 31, 54, 108, 102, 130, 147, 70, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_lmt[] = {2800, 642, 620, 63, 53, 106, 37, 31, 54, 108, 102, 130, 147, 70, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_llt[] = {2800, 642, 620, 63, 53, 106, 37, 31, 54, 108, 102, 130, 147, 70, LAST_CHARGING_WEIGHT}; + +static struct diff_tbl dischg_diff_tbl = { + // 0, 1-2, 3-4, 5-6, 7-9,10-19,20-29,30-39,40-49,50-59,60-69,70-79,80-89,90-99, 100 + {400, 360, 230, 120, 120, 130, 110, 110, 110, 115, 100, 75, 60, 30, 20}, // 0.1C + {635, 465, 270, 245, 220, 245, 230, 225, 217, 245, 245, 213, 178, 153, 250}, // 0.2C +}; + +static u16 fg_reset_drop_offset[] = {172, 98}; + +#endif + +#else +static struct adc2soc_lookuptbl adc2soc_lut = { + .adc_ht = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ high temp + .adc_rt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ room temp + .adc_rlt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0) + .adc_lt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low temp(0) + .adc_lmt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low mid temp(-10) + .adc_llt = {1843, 1906, 2155, 2310, 2338, 2367, 2563, 2627, 2688, 2762, 2920, 3069, 3249, 3458, ADC_VAL_100_PERCENT,}, // ADC input @ low low temp(-20) + .soc = { 0, 10, 30, 50, 70, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,}, // SoC in % +}; + +//Discharging Weight(Room/Low/low low) +// latest 0.1C +//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 +// This is for 0.1C +//static u16 adc_weight_section_discharge_1c[] = { 5, 8, 10, 45, 90, 115, 43, 50, 75, 80, 100, 100, 100, 100, 145}; +static u16 adc_weight_section_discharge_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195}; +static u16 adc_weight_section_discharge_rlt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195}; +static u16 adc_weight_section_discharge_lt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195}; +static u16 adc_weight_section_discharge_lmt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195}; +static u16 adc_weight_section_discharge_llt_1c[] = {110, 160, 230, 280, 240, 101, 17, 13, 18, 33, 34, 68, 95, 125, 195}; + +// This is for 0.2C +//Discharging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 + //{ 40, 80, 150, 150, 120, 59, 18, 16, 21, 39, 36, 58, 73, 80, 125}; +static u16 adc_weight_section_discharge_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125}; +static u16 adc_weight_section_discharge_rlt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125}; +static u16 adc_weight_section_discharge_lt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125}; +static u16 adc_weight_section_discharge_lmt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125}; +static u16 adc_weight_section_discharge_llt_2c[] = {140, 180, 190, 150, 120, 105, 18, 16, 21, 39, 36, 58, 73, 80, 125}; + +//Charging Weight(Room/Low/low low) // 0, 1, 3, 5, 7, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 +//static u16 adc_weight_section_charge[] = {1000, 90, 110, 95, 68, 38, 14, 13, 15, 32, 35, 36, 40, 36, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge[] = {1000, 105, 143, 121, 78, 40, 18, 17, 20, 44, 44, 48, 53, 39, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_rlt[] = {1000, 105, 143, 121, 78, 40, 18, 17, 20, 44, 44, 48, 53, 39, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_lt[] = {1000, 105, 143, 121, 78, 40, 18, 17, 20, 44, 44, 48, 53, 39, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_lmt[] = {1000, 105, 143, 121, 78, 40, 18, 17, 20, 44, 44, 48, 53, 39, LAST_CHARGING_WEIGHT}; +static u16 adc_weight_section_charge_llt[] = {1000, 105, 143, 121, 78, 40, 18, 17, 20, 44, 44, 48, 53, 39, LAST_CHARGING_WEIGHT}; + +static struct diff_tbl dischg_diff_tbl = { + // 0, 2-1, 4-3, 6-5, 9-7,19-10,29-20,39-30,49-40 + {173, 173, 143, 8, 15, 54, 40, 37, 50}, // 0.1C + {314, 314, 314, 145, 145, 177, 209, 221, 216}, // 0.2C +}; + +static u16 fg_reset_drop_offset[] = {172, 98}; + +#endif /* USED_BATTERY_CAPACITY == BAT_CAPACITY_????MA */ + +static u16 adc2soc_lut_length = (u16)sizeof(adc2soc_lut.soc)/sizeof(u16); +static u16 adc2vbat_lut_length = (u16)sizeof(adc2vbat_lut.offset)/sizeof(u16); + +#define SEC_FUELGAUGE_I2C_SLAVEADDR (0x6D >> 1) + +#define ADC_HISTORY_SIZE 30 +enum { + ADC_CHANNEL_VOLTAGE_AVG = 0, + ADC_CHANNEL_VOLTAGE_OCV, + ADC_CHANNEL_NUM +}; + +/* typedef for MFD */ +#define sec_fuelgauge_dev_t struct d2199 +#define sec_fuelgauge_pdata_t struct d2199_platform_data + +struct adc_sample_data { + unsigned int cnt; + int total_adc; + int average_adc; + int adc_arr[ADC_HISTORY_SIZE]; + int index; +}; + +struct battery_data_t { + unsigned int adc_check_count; + unsigned int monitor_polling_time; + unsigned int channel_voltage; + unsigned int channel_current; + const sec_bat_adc_table_data_t *ocv2soc_table; + unsigned int ocv2soc_table_size; + const sec_bat_adc_table_data_t *adc2vcell_table; + unsigned int adc2vcell_table_size; + u8 *type_str; +}; + +struct sec_fg_info { + struct d2199 *pd2199; + u8 vdd_hwmon_level; + u32 current_level; + + // for voltage + u32 origin_volt_adc; + u32 current_volt_adc; + u32 average_volt_adc; + u32 current_voltage; + u32 average_voltage; + u32 sum_voltage_adc; + u8 reset_total_adc; + int sum_total_adc; + + // for temperature + u32 current_temp_adc; + u32 average_temp_adc; + int current_temperature; + int average_temperature; + u32 sum_temperature_adc; + + u32 soc; + u32 prev_soc; + + int battery_technology; + int battery_present; + u32 capacity; + + u16 average_vbat_init_adc; + u16 vbat_init_adc[3]; + + u16 vf_adc; + u32 vf_ohm; + u32 vf_lower; + u32 vf_upper; + + u32 voltage_adc[AVG_SIZE]; + u32 temperature_adc[AVG_SIZE]; + u8 voltage_idx; + u8 temperature_idx; + + u8 volt_adc_init_done; + u8 temp_adc_init_done; + struct wake_lock sleep_monitor_wakeup; + struct delayed_work monitor_volt_work; + struct delayed_work monitor_temp_work; + struct adc_man_res adc_res[D2199_ADC_CHANNEL_MAX]; + u8 virtual_battery_full; + int charging_current; + + u8 adc_mode; + struct mutex adclock; + + int (*d2199_read_adc)(struct sec_fuelgauge_info *fuelgauge, adc_channel channel); +}; + +#endif /* __ADC_FUELGAUGE_H */ diff --git a/include/linux/battery/fuelgauge/dummy_fuelgauge.h b/include/linux/battery/fuelgauge/dummy_fuelgauge.h new file mode 100644 index 00000000..41b92e68 --- /dev/null +++ b/include/linux/battery/fuelgauge/dummy_fuelgauge.h @@ -0,0 +1,312 @@ +/* + * Copyright (C) 2011 STMicroelectronics. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __STC3115_BATTERY_H_ +#define __STC3115_BATTERY_H_ + +#include + +#define GG_VERSION "2.00a" + +/*Function declaration*/ +int STC31xx_SetPowerSavingMode(void); +int STC31xx_StopPowerSavingMode(void); +int STC31xx_AlarmSet(void); +int STC31xx_AlarmStop(void); +int STC31xx_AlarmGet(void); +int STC31xx_AlarmClear(void); +int STC31xx_AlarmSetVoltageThreshold(int VoltThresh); +int STC31xx_AlarmSetSOCThreshold(int SOCThresh); +int STC31xx_RelaxTmrSet(int CurrentThreshold); + +extern int MainTrim(struct i2c_client *client); +/* ******************************************************************************** */ +/* STC311x DEVICE SELECTION */ +/* STC3115 version only */ +/* -------------------------------------------------------------------------------- */ +#define STC3115 +#define BATD_UC8 +/* ******************************************************************************** */ + + +/* Private define ------------------------------------------------------------*/ + + +/* ******************************************************************************** */ +/* SPECIAL FUNCTIONS */ +/* -------------------------------------------------------------------------------- */ +/* */ +/* define TEMPCOMP_SOC to enable SOC temperature compensation */ +#define TEMPCOMP_SOC + +/* ******************************************************************************** */ + + +/* ******************************************************************************** */ +/* INTERNAL PARAMETERS */ +/* TO BE ADJUSTED ACCORDING TO BATTERY/APPLICATION CHARACTERISTICS */ +/* -------------------------------------------------------------------------------- */ +/* */ +#define BATT_CHG_VOLTAGE 4250 /* min voltage at the end of the charge (mV) */ +#define BATT_MIN_VOLTAGE 3300 /* nearly empty battery detection level (mV) */ +#define MAX_HRSOC 51200 /* 100% in 1/512% units*/ +#define MAX_SOC 1000 /* 100% in 0.1% units */ +/* */ +#define CHG_MIN_CURRENT 200 /* min charge current in mA */ +#define CHG_END_CURRENT 20 /* end charge current in mA */ +#define APP_MIN_CURRENT (-5) /* minimum application current consumption in mA ( <0 !) */ +#define APP_MIN_VOLTAGE 3000 /* application cut-off voltage */ +#define TEMP_MIN_ADJ (-5) /* minimum temperature for gain adjustment */ + +#define VMTEMPTABLE { 85, 90, 100, 160, 320, 440, 840 } /* normalized VM_CNF at 60, 40, 25, 10, 0, -10C, -20C */ + +#define AVGFILTER 4 /* average filter constant */ + +/* ******************************************************************************** */ + +/* Private define ------------------------------------------------------------*/ + +#define STC31xx_SLAVE_ADDRESS 0xE0 /* STC31xx 8-bit address byte */ + +/*Address of the STC311x register --------------------------------------------*/ +#define STC311x_REG_MODE 0x00 /* Mode Register */ +#define STC311x_REG_CTRL 0x01 /* Control and Status Register */ +#define STC311x_REG_SOC 0x02 /* SOC Data (2 bytes) */ +#define STC311x REG_COUNTER 0x04 /* Number of Conversion (2 bytes) */ +#define STC311x_REG_CURRENT 0x06 /* Battery Current (2 bytes) */ +#define STC311x_REG_VOLTAGE 0x08 /* Battery Voltage (2 bytes) */ +#define STC311x_REG_TEMPERATURE 0x0A /* Temperature */ +#define STC311x_REG_CC_ADJ_HIGH 0x0B /* CC adjustement */ +#define STC311x_REG_VM_ADJ_HIGH 0x0C /* VM adjustement */ +#define STC311x_REG_CC_ADJ_LOW 0x19 /* CC adjustement */ +#define STC311x_REG_VM_ADJ_LOW 0x1A /* VM adjustement */ +#define STC311x_ACC_CC_ADJ_HIGH 0x1B /* CC accumulator */ +#define STC311x_ACC_CC_ADJ_LOW 0x1C /* CC accumulator */ +#define STC311x_ACC_VM_ADJ_HIGH 0x1D /* VM accumulator */ +#define STC311x_ACC_VM_ADJ_LOW 0x1E /* VM accumulator */ +#define STC311x_REG_OCV 0x0D /* Battery OCV (2 bytes) */ +#define STC311x_REG_CC_CNF 0x0F /* CC configuration (2 bytes) */ +#define STC311x_REG_VM_CNF 0x11 /* VM configuration (2 bytes) */ +#define STC311x_REG_ALARM_SOC 0x13 /* SOC alarm level */ +#define STC311x_REG_ALARM_VOLTAGE 0x14 /* Low voltage alarm level */ +#define STC311x_REG_CURRENT_THRES 0x15 /* Current threshold for relaxation */ +#define STC311x_REG_RELAX_COUNT 0x16 /* Voltage relaxation counter */ +#define STC311x_REG_RELAX_MAX 0x17 /* Voltage relaxation max count */ + +/*Bit mask definition*/ +#define STC311x_VMODE 0x01 /* Voltage mode bit mask */ +#define STC311x_ALM_ENA 0x08 /* Alarm enable bit mask */ +#define STC311x_GG_RUN 0x10 /* Alarm enable bit mask */ +#define STC311x_FORCE_CC 0x20 /* Force CC bit mask */ +#define STC311x_FORCE_VM 0x40 /* Force VM bit mask */ +#define STC311x_SOFTPOR 0x11 /* soft reset */ +#define STC311x_CLR_VM_ADJ 0x02 /* Clear VM ADJ register bit mask */ +#define STC311x_CLR_CC_ADJ 0x04 /* Clear CC ADJ register bit mask */ + +#define STC311x_REG_ID 0x18 /* Chip ID (1 byte) */ +#define STC311x_ID 0x13 /* STC3115 ID */ +#define STC311x_ID_2 0x14 /* STC3115 ID */ + +#define STC311x_REG_RAM 0x20 /* General Purpose RAM Registers */ +#define RAM_SIZE 16 /* Total RAM size of STC3115 in bytes */ + +#define STC311x_REG_OCVTAB 0x30 +#define OCVTAB_SIZE 16 /* OCVTAB size of STC3115 in bytes */ + +#define VCOUNT 4 /* counter value for 1st current/temp measurements */ + + +#define M_STAT 0x1010 /* GG_RUN & PORDET mask in STC311x_BattDataTypeDef status word */ +#define M_RST 0x1800 /* BATFAIL & PORDET mask */ +#define M_RUN 0x0010 /* GG_RUN mask in STC311x_BattDataTypeDef status word */ +#define M_GGVM 0x0400 /* GG_VM mask */ +#define M_BATFAIL 0x0800 /* BATFAIL mask*/ +#define M_VMOD 0x0001 /* VMODE mask */ + +#define OK 0 + +/* STC311x RAM test word */ +#define RAM_TSTWORD 0x53A9 + +/* Gas gauge states */ +#define GG_INIT 'I' +#define GG_RUNNING 'R' +#define GG_POWERDN 'D' + +#define VM_MODE 1 +#define CC_MODE 0 + +#define STC311x_VF_BATTERY_ON 200 +#define STC311x_VF_BATTERY_OFF 0 + +/* gas gauge structure definition ------------------------------------*/ + +#define NTEMP 7 +static const int TempTable[NTEMP] = {60, 40, 25, 10, 0, -10, -20} ; /* temperature table from 60C to -20C (descending order!) */ +static const int DefVMTempTable[NTEMP] = VMTEMPTABLE; + +/* Private variables ---------------------------------------------------------*/ + +/* #define CurrentFactor (24084/SENSERESISTOR) LSB=5.88uV/R= ~24084/R/4096 - convert to mA */ +#define VoltageFactor 9011 /* LSB=2.20mV ~9011/4096 - convert to mV */ + + +/* structure of the STC311x battery monitoring parameters */ +typedef struct { + int Voltage; /* battery voltage in mV */ + int Current; /* battery current in mA */ + int Temperature; /* battery temperature in 0.1C */ + int SOC; /* battery relative SOC (%) in 0.1% */ + int OCV; + int AvgSOC; + int AvgCurrent; + int AvgVoltage; + int AvgTemperature; + int ChargeValue; /* remaining capacity in mAh */ + int RemTime; /* battery remaining operating time during discharge (min) */ + int State; /* charge (>0)/discharge(<0) state */ + int CalStat; /* Internal status */ + /* -- parameters -- */ + int Vmode; /* 1=Voltage mode, 0=mixed mode */ + int Alm_SOC; /* SOC alm level */ + int Alm_Vbat; /* Vbat alm level */ + int CC_cnf; /* nominal CC_cnf */ + int VM_cnf; /* nominal VM cnf */ + int Cnom; /* nominal capacity in mAh */ + int Rsense; /* sense resistor */ + int RelaxCurrent; /* current for relaxation (< C/20) */ + int Adaptive; /* adaptive mode */ + int CapDerating[6]; /* capacity derating in 0.1%, for temp = 60, 40, 25, 10, 0, -10 C */ + int OCVOffset[16]; /* OCV curve adjustment */ + int OCVOffset2[16]; /* OCV curve adjustment */ + int ExternalTemperature; + int ForceExternalTemperature; +} GasGauge_DataTypeDef; + +/* structure of the STC311x battery monitoring data */ +typedef struct { + /* STC311x data */ + int STC_Status; /* status word */ + int Vmode; /* 1=Voltage mode, 0=mixed mode */ + int Voltage; /* voltage in mV */ + int Current; /* current in mA */ + int Temperature; /* temperature in 0.1C */ + int HRSOC; /* uncompensated SOC in 1/512% */ + int OCV; /* OCV in mV*/ + int ConvCounter; /* convertion counter */ + int RelaxTimer; /* current relax timer value */ + int CC_adj; /* CC adj */ + int VM_adj; /* VM adj */ + /* results & internals */ + int SOC; /* compensated SOC in 0.1% */ + int AvgSOC; /* in 0.1% */ + int AvgVoltage; + int AvgCurrent; + int AvgTemperature; + int AccSOC; + int AccVoltage; + int AccCurrent; + int AccTemperature; + int BattState; + int GG_Mode; /* 1=VM active, 0=CC active */ + int LastMode; + int LastSOC; + int LastTemperature; + int BattOnline; // BATD + int IDCode; + /* parameters */ + int Alm_SOC; /* SOC alm level in % */ + int Alm_Vbat; /* Vbat alm level in mV */ + int CC_cnf; /* nominal CC_cnf */ + int VM_cnf; /* nominal VM cnf */ + int Cnom; /* nominal capacity is mAh */ + int Rsense; /* sense resistor in milliOhms */ + int CurrentFactor; + int RelaxThreshold; /* current threshold for VM (mA) */ + int Adaptive; /* adaptive mode */ + int VM_TempTable[NTEMP]; + int CapacityDerating[NTEMP]; + char OCVOffset[OCVTAB_SIZE]; + char OCVOffset2[OCVTAB_SIZE]; +} STC311x_BattDataTypeDef; + +static STC311x_BattDataTypeDef BattData; /* STC311x data */ + +/* structure of the STC311x RAM registers for the Gas Gauge algorithm data */ +static union { + unsigned char db[RAM_SIZE]; /* last byte holds the CRC */ + struct { + short int TstWord; /* 0-1 */ + short int HRSOC; /* 2-3 SOC backup */ + short int CC_cnf; /* 4-5 current CC_cnf */ + short int VM_cnf; /* 6-7 current VM_cnf */ + char SOC; /* 8 SOC for trace (in %) */ + char GG_Status; /* 9 */ + /* bytes ..RAM_SIZE-2 are free, last byte RAM_SIZE-1 is the CRC */ + } reg; +} GG_Ram; + +int Capacity_Adjust; + +/* -------------------------------------------------------------------------------- */ +/* INTERNAL ANDROID DRIVER PARAMETERS */ +/* TO BE ADJUSTED ACCORDING TO BATTERY/APPLICATION CHARACTERISTICS */ +/* -------------------------------------------------------------------------------- */ + +#define STC3100_BATTERY_FULL 95 +#define STC311x_DELAY 1000 + +/* ******************************************************************************** */ + +/* ******************************************************************************** */ + +static struct i2c_client *sav_client; + +struct stc311x_chip { + struct i2c_client *client; + struct delayed_work work; + struct power_supply battery; + struct stc311x_platform_data *pdata; + + /* State Of Connect */ + int online; + /* battery SOC (capacity) */ + int batt_soc; + /* battery voltage */ + int batt_voltage; + /* Current */ + int batt_current; + /* State Of Charge */ + int status; + +}; + +struct sec_fg_info { + int (*battery_online)(void); + int (*charger_online)(void); + int (*charger_enable)(void); + int (*power_supply_register)(struct device *parent, struct power_supply *psy); + void (*power_supply_unregister)(struct power_supply *psy); + + int Vmode; /* 1=Voltage mode, 0=mixed mode */ + int Alm_SOC; /* SOC alm level %*/ + int Alm_Vbat; /* Vbat alm level mV*/ + int CC_cnf; /* nominal CC_cnf */ + int VM_cnf; /* nominal VM cnf */ + int Cnom; /* nominal capacity in mAh */ + int Rsense; /* sense resistor mOhms*/ + int RelaxCurrent; /* current for relaxation in mA (< C/20) */ + int Adaptive; /* 1=Adaptive mode enabled, 0=Adaptive mode disabled */ + int CapDerating[7]; /* capacity derating in 0.1%, for temp = 60, 40, 25, 10, 0, -10 °C,-20°C */ + int OCVOffset[16]; /* OCV curve adjustment */ + int OCVOffset2[16]; /* OCV curve adjustment */ + int (*ExternalTemperature) (void); /*External temperature fonction, return °C*/ + int ForceExternalTemperature; /* 1=External temperature, 0=STC3115 temperature */ +}; + +#endif diff --git a/include/linux/battery/fuelgauge/rt5033_fuelgauge.h b/include/linux/battery/fuelgauge/rt5033_fuelgauge.h new file mode 100644 index 00000000..0a56bdfd --- /dev/null +++ b/include/linux/battery/fuelgauge/rt5033_fuelgauge.h @@ -0,0 +1,173 @@ +/* + * drivers/battery/rt5033_fuelgauge.h + * + * Header of Richtek RT5033 Fuelgauge Driver + * + * Copyright (C) 2013 Richtek Technology Corp. + * Author: Patrick Chang + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + */ + +#ifndef RT5033_FUELGAUGE_H +#define RT5033_FUELGAUGE_H + +#include +#include + +#ifdef CONFIG_DEBUG_FS +#include +#endif /* #ifdef CONFIG_DEBUG_FS */ + +#define FG_DRIVER_VER "2.0.2S" + +/* Added by Patrick */ +#define VG_COMP_NR 4 + +typedef struct { + int data[VG_COMP_NR]; +} vg_comp_data_t; + +typedef struct { + union { + int x; + int voltage; + int soc; + }; + union { + int y; + int temperature; + }; + union { + int data[VG_COMP_NR]; + vg_comp_data_t vg_comp; + int z; + int offset; + }; +} data_point_t; + +typedef struct { + int voltNR; + int tempNR; + data_point_t *vg_comp_data; +} vg_comp_table_t; + +typedef struct { + int soc_voltNR; + int tempNR; + data_point_t *soc_offset_data; +} soc_offset_table_t; + + +enum { + OFFSET_CHARGING = 0, + OFFSET_DISCHARGING, + OFFSET_SPECIAL, + OFFSET_LOW_POWER, + OFFSET_NR, +}; + +enum { + VGCOMP_NORMAL = 0, + VGCOMP_IDLE, + VGCOMP_NR, +}; + + +struct battery_data_t { + const int offset_interpolation_order[2]; + const int vg_comp_interpolation_order[2]; + const vg_comp_table_t vg_comp[VGCOMP_NR]; + const soc_offset_table_t soc_offset[OFFSET_NR]; + /* crate idle threshold*/ + const int crate_idle_thres; + const int battery_type; /* 4200 or 4350 or 4400 */ +}; + +#ifdef CONFIG_DEBUG_FS +enum { + RT5033FG_OFFSET_CHARGING_SIZE = 0, + RT5033FG_OFFSET_CHARGING_DATA, + RT5033FG_OFFSET_DISCHARGING_SIZE, + RT5033FG_OFFSET_DISCHARGING_DATA, + RT5033FG_OFFSET_SPECIAL_SIZE, + RT5033FG_OFFSET_SPECIAL_DATA, + RT5033FG_OFFSET_LOW_POWER_SIZE, + RT5033FG_OFFSET_LOW_POWER_DATA, + RT5033FG_VGCOMP_NORMAL_SIZE, + RT5033FG_VGCOMP_NORMAL_DATA, + RT5033FG_VGCOMP_IDLE_SIZE, + RT5033FG_VGCOMP_IDLE_DATA, + RT5033FG_PARAM_LOCK, + RT5033FG_VGCOMP_IP_ORDER, + RT5033FG_OFFSET_IP_ORDER, + RT5033FG_CRATE_IDLE_THRES, + RT5033FG_DENTRY_NR, +}; + +#define RT5033_DBG_OUT_BUF_SIZE 2048 + +#endif /* CONFIG_DEBUG_FS */ + +struct sec_fg_info { + /* State Of Connect */ + int online; + /* battery SOC (capacity) */ + int batt_soc; + /* battery voltage */ + int batt_voltage; + /* battery AvgVoltage */ + int batt_avgvoltage; + /* battery OCV */ + int batt_ocv; + /* Current */ + int batt_current; + /* battery Avg Current */ + int batt_avgcurrent; + /* battery temperatue */ + u32 current_temp_adc; + /* crate idle threshold*/ + int crate_idle_thres; + + struct battery_data_t *comp_pdata; + + struct mutex param_lock; + /* copy from platform data / + * DTS or update by shell script */ + int vg_comp_interpolation_order[2]; + int offset_interpolation_order[2]; + vg_comp_table_t vg_comp[VGCOMP_NR]; + soc_offset_table_t soc_offset[OFFSET_NR]; + + struct mutex io_lock; + struct device *dev; + int32_t temperature;; /* 0.1 deg C*/ + /* register programming */ + int reg_addr; + u8 reg_data[2]; + uint32_t pre_soc; + uint32_t move_avg_offset_cnt; + uint32_t flag_full_charge : 1; /* 0 : no , 1 : yes*/ + uint32_t flag_chg_status : 1; /* 0 : discharging, 1: charging*/ + uint32_t offs_speci_case : 1; + uint32_t init_once : 1; + uint32_t volt_alert_flag : 1; /* 0 : nu-occur, 1: occur */ + uint32_t soc_alert_flag : 1; /* 0 : nu-occur, 1: occur */ + uint32_t bat_pres_flag : 1; /* 0 : removed, 1: inserted */ + uint32_t flag_once_full_soc : 1; + uint32_t entry_suspend_flag : 1; + int32_t irq_ctrl; + int battery_type; /* 4200 or 4350 or 4400*/ + +#ifdef CONFIG_DEBUG_FS + struct dentry *dir_dentry; + struct dentry *file_dentries[RT5033FG_DENTRY_NR]; + char dbg_out_buffer[RT5033_DBG_OUT_BUF_SIZE]; +#endif /* #ifdef CONFIG_DEBUG_FS */ +}; + + +#endif // RT5033_FUELGAUGE_H diff --git a/include/linux/battery/fuelgauge/rt5033_fuelgauge_impl.h b/include/linux/battery/fuelgauge/rt5033_fuelgauge_impl.h new file mode 100644 index 00000000..cfc0a42e --- /dev/null +++ b/include/linux/battery/fuelgauge/rt5033_fuelgauge_impl.h @@ -0,0 +1,96 @@ +/* + * drivers/battery/rt5033_fuelgauge-impl.h + * + * Header of Richtek RT5033 Fuelgauge Driver Implementation + * + * Copyright (C) 2013 Richtek Technology Corp. + * Author: Richtek Gauge Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + */ + +#ifndef RT5033_FUELGAUGE_IMPL_H +#define RT5033_FUELGAUGE_IMPL_H + +/* Definitions of RT5033 Fuelgauge Registers */ + +#define RT5033_OCV_MSB 0x00 +#define RT5033_OCV_LSB 0x01 +#define RT5033_VBAT_MSB 0x02 +#define RT5033_VBAT_LSB 0x03 +#define RT5033_SOC_MSB 0x04 +#define RT5033_SOC_LSB 0x05 +#define RT5033_CRATE 0x08 +#define RT5033_DEVICE_ID 0x09 +#define RT5033_AVG_VOLT_MSB 0x0A +#define RT5033_AVG_VOLT_LSB 0x0B +#define RT5033_CONFIG_MSB 0x0C +#define RT5033_CONFIG_LSB 0x0D +#define RT5033_FG_IRQ_CTRL 0x10 +#define RT5033_FG_IRQ_FLAG 0x11 +#define RT5033_VOLT_ALRT_TH 0x12 +#define RT5033_SOC_ALRT_TH 0x13 +#define RT5033_VGCOMP1 0x20 +#define RT5033_VGCOMP2 0x21 +#define RT5033_VGCOMP3 0x22 +#define RT5033_VGCOMP4 0x23 +#define RT5033_MFA_MSB 0xFE +#define RT5033_MFA_LSB 0xFF + +#define EOC_LOCK_TH 99 /* unit : % */ +#define VALRT_LOCK_TH 1 /* unit : % */ +#define SMOOTH_SOC_STEP 1 /* unit : % */ +#define CHG_IR_EXCEPT_SOC 10 /* unit : % */ +#define QUICK_ROUTINE_TIME 1 /* unit : sec */ +#define NORMAL_ROUTINE_TIME 30 /* unit : sec */ +#define MFA_CMD_EOC_SOC 0x8664 +#define MFA_CMD_VALRT_SOC 0x8600 +#define SOC_ALRT_TOP 12 +#define SOC_ALRT_HIGH 6 +#define SOC_ALRT_LOW 3 +#define SOC_ALRT_BOTTOM 1 +#define BAT_REMOVAL_SOC 50 +#define ROUNDUP_SOC_TH 5 +#define VALRT_LOCK_TH 1 +#define MFA_CMD_EXIT_HIB 0x7400 +#define MFA_CMD_ENTRY_HIB 0x74AA +#define FULL_SOC 100 + +#define VOLT_ALRT_TH 0 //disable /* unit : 20mV*/ +#define VALRT_SOC 0 /* unit : % */ + + +#define GAIN_RANGE1 -20 +#define GAIN_RANGE2 5 +#define GAIN_RANGE3 25 +#define GAIN_RANGE4 45 +#define GAIN_TABLE1_INDEX 1 +#define GAIN_TABLE2_INDEX 2 +#define GAIN_TABLE3_INDEX 3 +#define GAIN_TABLE4_INDEX 4 + +#define OFFS_THRES_DSG_N20 -20 +#define OFFS_THRES_CHG_25 25 +#define OFFS_THRES_DSG_25 25 +#define OFFS_TABLE1_INDEX 1 +#define OFFS_TABLE2_INDEX 2 +#define OFFS_TABLE3_INDEX 3 +#define OFFS_TABLE4_INDEX 4 + +#define LOOKUP_GAIN 1 +#define LOOKUP_OFFS 2 + +#define R5_TEMP 10 /* unit : oC */ +#define MFA_CMD_R5_DEFAULT 0x8501 +#define MFA_CMD_R5_LOW_TEMP 0x8503 + +#define ENABLE_SOC_OFFSET_COMP 0 +#define ENABLE_LOCK_SOC 0 +#define ENABLE_SMOOTH_SOC 0 +#define ENABLE_SOC_IRREVERSIBLE 0 + + +#endif // RT5033_FUELGAUGE_IMPL_H diff --git a/include/linux/battery/fuelgauge/sprd27x3_fuelgauge4samsung.h b/include/linux/battery/fuelgauge/sprd27x3_fuelgauge4samsung.h new file mode 100755 index 00000000..aa3af8cf --- /dev/null +++ b/include/linux/battery/fuelgauge/sprd27x3_fuelgauge4samsung.h @@ -0,0 +1,18 @@ + +#ifndef _SPRD27X3_FUELGAUGE4SAMSUNG_H_ +#define _SPRD27X3_FUELGAUGE4SAMSUNG_H_ + +#include +#include +#include +#include +#include "../power/sprd_2713_fgu.h" +#include "../power/sprd_battery.h" + + +struct battery_data_t { + struct sprd_battery_platform_data *pdata; +}; + +#endif + diff --git a/include/linux/battery/fuelgauge/stc3115_fuelgauge.h b/include/linux/battery/fuelgauge/stc3115_fuelgauge.h new file mode 100644 index 00000000..9df863ce --- /dev/null +++ b/include/linux/battery/fuelgauge/stc3115_fuelgauge.h @@ -0,0 +1,285 @@ +/* + * Copyright (C) 2011 STMicroelectronics. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __STC3115_BATTERY_H_ +#define __STC3115_BATTERY_H_ + +/* Slave address should be shifted to the right 1bit. + * R/W bit should NOT be included. + */ +#define GG_VERSION "2.00a" + +/* #define CurrentFactor (24084/SENSERESISTOR) LSB=5.88uV/R= ~24084/R/4096 - convert to mA */ +#define VoltageFactor 9011 /* LSB=2.20mV ~9011/4096 - convert to mV */ + +/* ******************************************************************************** */ +/* STC311x DEVICE SELECTION */ +/* STC3115 version only */ +/* -------------------------------------------------------------------------------- */ +#define STC3115 +#define BATD_UC8 +/* ******************************************************************************** */ + +/* Private define ------------------------------------------------------------*/ + + +/* ******************************************************************************** */ +/* SPECIAL FUNCTIONS */ +/* -------------------------------------------------------------------------------- */ +/* */ +/* define TEMPCOMP_SOC to enable SOC temperature compensation */ +#define TEMPCOMP_SOC + +/* ******************************************************************************** */ + + +/* ******************************************************************************** */ +/* INTERNAL PARAMETERS */ +/* TO BE ADJUSTED ACCORDING TO BATTERY/APPLICATION CHARACTERISTICS */ +/* -------------------------------------------------------------------------------- */ +/* */ +#define BATT_CHG_VOLTAGE 4100 /* min voltage at the end of the charge (mV) */ +#define BATT_MIN_VOLTAGE 3300 /* nearly empty battery detection level (mV) */ +#define MAX_HRSOC 51200 /* 100% in 1/512% units*/ +#define MAX_SOC 1000 /* 100% in 0.1% units */ +/* */ +#define CHG_MIN_CURRENT 200 /* min charge current in mA */ +#define CHG_END_CURRENT 20 /* end charge current in mA */ +#define APP_MIN_CURRENT (-5) /* minimum application current consumption in mA ( <0 !) */ +#define APP_MIN_VOLTAGE 3000 /* application cut-off voltage */ +#define TEMP_MIN_ADJ (-5) /* minimum temperature for gain adjustment */ + +#define VMTEMPTABLE { 85, 90, 100, 160, 320, 440, 840 } /* normalized VM_CNF at 60, 40, 25, 10, 0, -10C, -20C */ + +#define AVGFILTER 4 /* average filter constant */ + +/* ******************************************************************************** */ + + + +/* Private define ------------------------------------------------------------*/ + +#define STC31xx_SLAVE_ADDRESS (0xE0>>1) /* STC31xx 8-bit address byte */ + +/*Address of the STC311x register --------------------------------------------*/ +#define STC311x_REG_MODE 0x00 /* Mode Register */ +#define STC311x_REG_CTRL 0x01 /* Control and Status Register */ +#define STC311x_REG_SOC 0x02 /* SOC Data (2 bytes) */ +#define STC311x_REG_COUNTER 0x04 /* Number of Conversion (2 bytes) */ +#define STC311x_REG_CURRENT 0x06 /* Battery Current (2 bytes) */ +#define STC311x_REG_VOLTAGE 0x08 /* Battery Voltage (2 bytes) */ +#define STC311x_REG_TEMPERATURE 0x0A /* Temperature */ +#define STC311x_REG_CC_ADJ_HIGH 0x0B /* CC adjustement */ +#define STC311x_REG_VM_ADJ_HIGH 0x0C /* VM adjustement */ +#define STC311x_REG_CC_ADJ_LOW 0x19 /* CC adjustement */ +#define STC311x_REG_VM_ADJ_LOW 0x1A /* VM adjustement */ +#define STC311x_ACC_CC_ADJ_HIGH 0x1B /* CC accumulator */ +#define STC311x_ACC_CC_ADJ_LOW 0x1C /* CC accumulator */ +#define STC311x_ACC_VM_ADJ_HIGH 0x1D /* VM accumulator */ +#define STC311x_ACC_VM_ADJ_LOW 0x1E /* VM accumulator */ +#define STC311x_REG_OCV 0x0D /* Battery OCV (2 bytes) */ +#define STC311x_REG_CC_CNF 0x0F /* CC configuration (2 bytes) */ +#define STC311x_REG_VM_CNF 0x11 /* VM configuration (2 bytes) */ +#define STC311x_REG_ALARM_SOC 0x13 /* SOC alarm level */ +#define STC311x_REG_ALARM_VOLTAGE 0x14 /* Low voltage alarm level */ +#define STC311x_REG_CURRENT_THRES 0x15 /* Current threshold for relaxation */ +#define STC311x_REG_RELAX_COUNT 0x16 /* Voltage relaxation counter */ +#define STC311x_REG_RELAX_MAX 0x17 /* Voltage relaxation max count */ + +/*Bit mask definition*/ +#define STC311x_VMODE 0x01 /* Voltage mode bit mask */ +#define STC311x_ALM_ENA 0x08 /* Alarm enable bit mask */ +#define STC311x_GG_RUN 0x10 /* Alarm enable bit mask */ +#define STC311x_FORCE_CC 0x20 /* Force CC bit mask */ +#define STC311x_FORCE_VM 0x40 /* Force VM bit mask */ +#define STC311x_SOFTPOR 0x11 /* soft reset */ +#define STC311x_CLR_VM_ADJ 0x02 /* Clear VM ADJ register bit mask */ +#define STC311x_CLR_CC_ADJ 0x04 /* Clear CC ADJ register bit mask */ + +#define STC311x_REG_ID 0x18 /* Chip ID (1 byte) */ +#define STC311x_ID 0x13 /* STC3115 ID */ +#define STC311x_ID_2 0x14 /* STC3115 ID */ + +#define STC311x_REG_RAM 0x20 /* General Purpose RAM Registers */ +#define RAM_SIZE 16 /* Total RAM size of STC3115 in bytes */ + +#define STC311x_REG_OCVTAB 0x30 +#define OCVTAB_SIZE 16 /* OCVTAB size of STC3115 in bytes */ + +#define VCOUNT 4 /* counter value for 1st current/temp measurements */ + + +#define M_STAT 0x1010 /* GG_RUN & PORDET mask in STC311x_BattDataTypeDef status word */ +#define M_RST 0x1800 /* BATFAIL & PORDET mask */ +#define M_RUN 0x0010 /* GG_RUN mask in STC311x_BattDataTypeDef status word */ +#define M_GGVM 0x0400 /* GG_VM mask */ +#define M_BATFAIL 0x0800 /* BATFAIL mask*/ +#define M_VMOD 0x0001 /* VMODE mask */ + +#define OK 0 + +/* Battery charge state definition for BattState */ +#define BATT_CHARGING 3 +#define BATT_ENDCHARG 2 +#define BATT_FULCHARG 1 +#define BATT_IDLE 0 +#define BATT_DISCHARG (-1) +#define BATT_LOWBATT (-2) + +/* STC311x RAM test word */ +#define RAM_TSTWORD 0x53A9 + +/* Gas gauge states */ +#define GG_INIT 'I' +#define GG_RUNNING 'R' +#define GG_POWERDN 'D' + +#define VM_MODE 1 +#define CC_MODE 0 + +/* gas gauge structure definition ------------------------------------*/ + +/* Private constants ---------------------------------------------------------*/ + +#define NTEMP 7 +static const int TempTable[NTEMP] = {60, 40, 25, 10, 0, -10, -20} ; /* temperature table from 60C to -20C (descending order!) */ +static const int DefVMTempTable[NTEMP] = VMTEMPTABLE; + + +struct battery_data_t { + int Vmode; /* 1=Voltage mode, 0=mixed mode */ + int Alm_SOC; /* SOC alm level %*/ + int Alm_Vbat; /* Vbat alm level mV*/ + int CC_cnf; /* nominal CC_cnf */ + int VM_cnf; /* nominal VM cnf */ + int Cnom; /* nominal capacity in mAh */ + int Rsense; /* sense resistor mOhms*/ + int RelaxCurrent; /* current for relaxation in mA (< C/20) */ + int Adaptive; /* 1=Adaptive mode enabled, 0=Adaptive mode disabled */ + int CapDerating[7]; /* capacity derating in 0.1%, for temp = 60, 40, 25, 10, 0, -10 C,-20C */ + int OCVOffset[16]; /* OCV curve adjustment */ + int OCVOffset2[16]; /* OCV curve adjustment */ + int (*ExternalTemperature) (void); /*External temperature fonction, return C*/ + int ForceExternalTemperature; /* 1=External temperature, 0=STC3115 temperature */ +}; + +struct sec_fg_info { + /* State Of Connect */ + int online; + /* battery SOC (capacity) */ + int batt_soc; + /* battery voltage */ + int batt_voltage; + /* battery AvgVoltage */ + int batt_avgvoltage; + /* battery OCV */ + int batt_ocv; + /* Current */ + int batt_current; + /* battery Avg Current */ + int batt_avgcurrent; + /* battery temperatue */ + int temperature; +}; + +typedef struct { + /* STC311x data */ + int STC_Status; /* status word */ + int Vmode; /* 1=Voltage mode, 0=mixed mode */ + int Voltage; /* voltage in mV */ + int Current; /* current in mA */ + int Temperature; /* temperature in 0.1C */ + int HRSOC; /* uncompensated SOC in 1/512% */ + int OCV; /* OCV in mV*/ + int ConvCounter; /* convertion counter */ + int RelaxTimer; /* current relax timer value */ + int CC_adj; /* CC adj */ + int VM_adj; /* VM adj */ + /* results & internals */ + int SOC; /* compensated SOC in 0.1% */ + int AvgSOC; /* in 0.1% */ + int AvgVoltage; + int AvgCurrent; + int AvgTemperature; + int AccSOC; + int AccVoltage; + int AccCurrent; + int AccTemperature; + int BattState; + int GG_Mode; /* 1=VM active, 0=CC active */ + int LastMode; + int LastSOC; + int LastTemperature; + int BattOnline; // BATD + int IDCode; + /* parameters */ + int Alm_SOC; /* SOC alm level in % */ + int Alm_Vbat; /* Vbat alm level in mV */ + int CC_cnf; /* nominal CC_cnf */ + int VM_cnf; /* nominal VM cnf */ + int Cnom; /* nominal capacity is mAh */ + int Rsense; /* sense resistor in milliOhms */ + int CurrentFactor; + int RelaxThreshold; /* current threshold for VM (mA) */ + int Adaptive; /* adaptive mode */ + int VM_TempTable[NTEMP]; + int CapacityDerating[NTEMP]; + char OCVOffset[OCVTAB_SIZE]; + char OCVOffset2[OCVTAB_SIZE]; +} STC311x_BattDataTypeDef; + +static STC311x_BattDataTypeDef BattData; /* STC311x data */ + +/* structure of the STC311x battery monitoring parameters */ +typedef struct { + int Voltage; /* battery voltage in mV */ + int Current; /* battery current in mA */ + int Temperature; /* battery temperature in 0.1C */ + int SOC; /* battery relative SOC (%) in 0.1% */ + int OCV; + int AvgSOC; + int AvgCurrent; + int AvgVoltage; + int AvgTemperature; + int ChargeValue; /* remaining capacity in mAh */ + int RemTime; /* battery remaining operating time during discharge (min) */ + int State; /* charge (>0)/discharge(<0) state */ + int CalStat; /* Internal status */ + /* -- parameters -- */ + int Vmode; /* 1=Voltage mode, 0=mixed mode */ + int Alm_SOC; /* SOC alm level */ + int Alm_Vbat; /* Vbat alm level */ + int CC_cnf; /* nominal CC_cnf */ + int VM_cnf; /* nominal VM cnf */ + int Cnom; /* nominal capacity in mAh */ + int Rsense; /* sense resistor */ + int RelaxCurrent; /* current for relaxation (< C/20) */ + int Adaptive; /* adaptive mode */ + int CapDerating[6]; /* capacity derating in 0.1%, for temp = 60, 40, 25, 10, 0, -10 C */ + int OCVOffset[16]; /* OCV curve adjustment */ + int OCVOffset2[16]; /* OCV curve adjustment */ + int ExternalTemperature; + int ForceExternalTemperature; +} GasGauge_DataTypeDef; + + +/* structure of the STC311x RAM registers for the Gas Gauge algorithm data */ +static union { + unsigned char db[RAM_SIZE]; /* last byte holds the CRC */ + struct { + short int TstWord; /* 0-1 */ + short int HRSOC; /* 2-3 SOC backup */ + short int CC_cnf; /* 4-5 current CC_cnf */ + short int VM_cnf; /* 6-7 current VM_cnf */ + char SOC; /* 8 SOC for trace (in %) */ + char GG_Status; /* 9 */ + /* bytes ..RAM_SIZE-2 are free, last byte RAM_SIZE-1 is the CRC */ + } reg; +} GG_Ram; + +#endif /* __DUMMY_FUELGAUGE_H */ diff --git a/include/linux/battery/sec_adc.h b/include/linux/battery/sec_adc.h new file mode 100644 index 00000000..73743751 --- /dev/null +++ b/include/linux/battery/sec_adc.h @@ -0,0 +1,38 @@ +/* + * sec_adc.h + * Samsung Mobile Charger Header + * + * Copyright (C) 2012 Samsung Electronics, Inc. + * + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __SEC_ADC_H +#define __SEC_ADC_H __FILE__ + +#include +#include +#include + +#define VENDOR_UNKNOWN 0 +#define VENDOR_LSI 1 +#define VENDOR_QCOM 2 +#define VENDOR_SPRD 3 + +#endif /* __SEC_ADC_H */ + + + + + + + diff --git a/include/linux/battery/sec_battery.h b/include/linux/battery/sec_battery.h new file mode 100644 index 00000000..9e80ff06 --- /dev/null +++ b/include/linux/battery/sec_battery.h @@ -0,0 +1,305 @@ +/* + * sec_battery.h + * Samsung Mobile Battery Header + * + * + * Copyright (C) 2012 Samsung Electronics, Inc. + * + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __SEC_BATTERY_H +#define __SEC_BATTERY_H __FILE__ + +#include +#if defined(CONFIG_ANDROID_ALARM_ACTIVATED) +#include +#else +#include +#endif +#include +#include +#include +#include +#include + +#if defined(CONFIG_EXTCON) +#include +struct sec_battery_extcon_cable{ + struct extcon_specific_cable_nb extcon_nb; + struct notifier_block batt_nb; + int cable_index; +}; +#endif /* CONFIG_EXTCON */ + +#define ADC_CH_COUNT 10 +#define ADC_SAMPLE_COUNT 10 + +struct adc_sample_info { + unsigned int cnt; + int total_adc; + int average_adc; + int adc_arr[ADC_SAMPLE_COUNT]; + int index; +}; + +struct sec_battery_info { + struct device *dev; + sec_battery_platform_data_t *pdata; + /* power supply used in Android */ + struct power_supply psy_bat; + struct power_supply psy_usb; + struct power_supply psy_ac; + struct power_supply psy_wireless; + struct power_supply psy_ps; + unsigned int irq; + +#if defined(CONFIG_EXTCON) + struct sec_battery_extcon_cable extcon_cable_list[EXTCON_NONE]; +#endif /* CONFIG_EXTCON */ + + int status; + int health; + bool present; + + int voltage_now; /* cell voltage (mV) */ + int voltage_avg; /* average voltage (mV) */ + int voltage_ocv; /* open circuit voltage (mV) */ + int current_now; /* current (mA) */ + int current_avg; /* average current (mA) */ + int current_max; /* input current limit (mA) */ + int current_adc; + + unsigned int capacity; /* SOC (%) */ + + struct mutex adclock; + struct adc_sample_info adc_sample[ADC_CH_COUNT]; + + /* keep awake until monitor is done */ + struct wake_lock monitor_wake_lock; + struct workqueue_struct *monitor_wqueue; + struct delayed_work monitor_work; +#ifdef CONFIG_SAMSUNG_BATTERY_FACTORY + struct wake_lock lpm_wake_lock; +#endif + unsigned int polling_count; + unsigned int polling_time; + bool polling_in_sleep; + bool polling_short; + + struct delayed_work polling_work; + struct alarm polling_alarm; + ktime_t last_poll_time; + + /* event set */ + unsigned int event; + unsigned int event_wait; + struct alarm event_termination_alarm; + ktime_t last_event_time; + + /* battery check */ + unsigned int check_count; + /* ADC check */ + unsigned int check_adc_count; + unsigned int check_adc_value; + + /* time check */ + unsigned long charging_start_time; + unsigned long charging_passed_time; + unsigned long charging_next_time; + unsigned long charging_fullcharged_time; + + /* temperature check */ + int temperature; /* battery temperature */ + int temper_amb; /* target temperature */ + + int temp_adc; + int temp_ambient_adc; + + int temp_highlimit_threshold; + int temp_highlimit_recovery; + int temp_high_threshold; + int temp_high_recovery; + int temp_low_threshold; + int temp_low_recovery; + + unsigned int temp_highlimit_cnt; + unsigned int temp_high_cnt; + unsigned int temp_low_cnt; + unsigned int temp_recover_cnt; + + /* charging */ + unsigned int charging_mode; + bool is_recharging; + bool is_jig_on; + int cable_type; + int muic_cable_type; + int extended_cable_type; + struct wake_lock cable_wake_lock; + struct work_struct cable_work; + struct wake_lock vbus_wake_lock; + unsigned int full_check_cnt; + unsigned int recharge_check_cnt; + + /* wireless charging enable */ + int wc_enable; + int wc_status; + + int wire_status; + + /* wearable charging */ + int ps_enable; + int ps_status; + int ps_changed; + + /* test mode */ + int test_mode; + bool factory_mode; + bool slate_mode; + + int siop_level; +#if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST) + int stability_test; + int eng_not_full_status; +#endif +}; + +ssize_t sec_bat_show_attrs(struct device *dev, + struct device_attribute *attr, char *buf); + +ssize_t sec_bat_store_attrs(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count); + +#define SEC_BATTERY_ATTR(_name) \ +{ \ + .attr = {.name = #_name, .mode = 0664}, \ + .show = sec_bat_show_attrs, \ + .store = sec_bat_store_attrs, \ +} + +/* event check */ +#define EVENT_NONE (0) +#define EVENT_2G_CALL (0x1 << 0) +#define EVENT_3G_CALL (0x1 << 1) +#define EVENT_MUSIC (0x1 << 2) +#define EVENT_VIDEO (0x1 << 3) +#define EVENT_BROWSER (0x1 << 4) +#define EVENT_HOTSPOT (0x1 << 5) +#define EVENT_CAMERA (0x1 << 6) +#define EVENT_CAMCORDER (0x1 << 7) +#define EVENT_DATA_CALL (0x1 << 8) +#define EVENT_WIFI (0x1 << 9) +#define EVENT_WIBRO (0x1 << 10) +#define EVENT_LTE (0x1 << 11) +#define EVENT_LCD (0x1 << 12) +#define EVENT_GPS (0x1 << 13) + +#if 0 +enum { + POWER_SUPPLY_TYPE_WPC = 0xfff, + POWER_SUPPLY_TYPE_MISC, + POWER_SUPPLY_TYPE_CARDOCK, + POWER_SUPPLY_TYPE_UARTOFF, + POWER_SUPPLY_TYPE_WIRELESS, + POWER_SUPPLY_TYPE_LAN_HUB, + POWER_SUPPLY_TYPE_MHL_500, + POWER_SUPPLY_TYPE_MHL_900, + POWER_SUPPLY_TYPE_MHL_1500, + POWER_SUPPLY_TYPE_MHL_USB, + POWER_SUPPLY_TYPE_SMART_OTG, + POWER_SUPPLY_TYPE_SMART_NOTG, + POWER_SUPPLY_TYPE_POWER_SHARING +}; +#endif + +enum { + BATT_RESET_SOC = 0, + BATT_READ_RAW_SOC, + BATT_READ_ADJ_SOC, + BATT_TYPE, + BATT_VFOCV, + BATT_VOL_ADC, + BATT_VOL_ADC_CAL, + BATT_VOL_AVER, + BATT_VOL_ADC_AVER, + + BATT_CURRENT_UA_NOW, + BATT_CURRENT_UA_AVG, + + BATT_TEMP, + BATT_TEMP_ADC, + BATT_TEMP_AVER, + BATT_TEMP_ADC_AVER, + BATT_VF_ADC, + BATT_SLATE_MODE, + + BATT_LP_CHARGING, + SIOP_ACTIVATED, + SIOP_LEVEL, + BATT_CHARGING_SOURCE, + FG_REG_DUMP, + FG_RESET_CAP, + FG_CAPACITY, + AUTH, + CHG_CURRENT_ADC, + WC_ADC, + WC_STATUS, + WC_ENABLE, + FACTORY_MODE, + UPDATE, + TEST_MODE, + + BATT_EVENT_CALL, + BATT_EVENT_2G_CALL, + BATT_EVENT_TALK_GSM, + BATT_EVENT_3G_CALL, + BATT_EVENT_TALK_WCDMA, + BATT_EVENT_MUSIC, + BATT_EVENT_VIDEO, + BATT_EVENT_BROWSER, + BATT_EVENT_HOTSPOT, + BATT_EVENT_CAMERA, + BATT_EVENT_CAMCORDER, + BATT_EVENT_DATA_CALL, + BATT_EVENT_WIFI, + BATT_EVENT_WIBRO, + BATT_EVENT_LTE, + BATT_EVENT_LCD, + BATT_EVENT_GPS, + BATT_EVENT, +#if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST) + BATT_TEST_CHARGE_CURRENT, + BATT_STABILITY_TEST, +#endif +#if defined(CONFIG_SPRD_2713_POWER) + BATT_2713_BATTERY_VOLTAGE, + BATT_2713_BATTERY_ADC, +#endif +}; + +#ifdef CONFIG_OF +extern int adc_read(struct sec_battery_info *battery, int channel); +extern void board_battery_init(struct platform_device *pdev, struct sec_battery_info *battery); +extern void cable_initial_check(struct sec_battery_info *battery); +extern bool sec_bat_check_jig_status(void); +extern void adc_exit(struct sec_battery_info *battery); +extern int sec_bat_check_cable_callback(struct sec_battery_info *battery); +extern bool sec_bat_check_cable_result_callback(int cable_type); +extern bool sec_bat_check_callback(struct sec_battery_info *battery); + +/* set callback function pointer in platform_data object for DT + and link battery data*/ +extern void board_battery_init_link(sec_battery_platform_data_t *pdata); +#endif + +#endif /* __SEC_BATTERY_H */ diff --git a/include/linux/battery/sec_charger.h b/include/linux/battery/sec_charger.h new file mode 100755 index 00000000..4824b1a7 --- /dev/null +++ b/include/linux/battery/sec_charger.h @@ -0,0 +1,180 @@ +/* + * sec_charger.h + * Samsung Mobile Charger Header + * + * Copyright (C) 2012 Samsung Electronics, Inc. + * + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __SEC_CHARGER_H +#define __SEC_CHARGER_H __FILE__ + +#if defined(CONFIG_CHARGER_MFD) || \ + defined(CONFIG_CHARGER_SPRD4SAMSUNG27X3) && \ + !defined(CONFIG_CHARGER_SM5414) && \ + !defined(CONFIG_CHARGER_SMB328) +#define charger_variable charger +#define charger_variable_t struct sec_charger_info +#else +#define charger_variable (charger->client) +#define charger_variable_t struct i2c_client +#endif + +#include +#if defined(CONFIG_FUELGAUGE_SPRD4SAMSUNG27X3) || defined(CONFIG_CHARGER_SPRD4SAMSUNG27X3) +#include +#endif + +#if defined(CONFIG_CHARGER_DUMMY) || \ + defined(CONFIG_CHARGER_PM8917) +#include +#elif defined(CONFIG_CHARGER_MAX8903) +#include +#elif defined(CONFIG_CHARGER_SMB327) +#include +#elif defined(CONFIG_CHARGER_SMB328) +#include +#elif defined(CONFIG_CHARGER_SMB347) +#include +#elif defined(CONFIG_CHARGER_SMB358) +#include +#elif defined(CONFIG_CHARGER_BQ24157) +#include +#elif defined(CONFIG_CHARGER_BQ24190) || \ + defined(CONFIG_CHARGER_BQ24191) +#include +#elif defined(CONFIG_CHARGER_BQ24260) +#include +#elif defined(CONFIG_CHARGER_MAX77803) +#include +#elif defined(CONFIG_CHARGER_NCP1851) +#include +#elif defined(CONFIG_CHARGER_RT5033) +#include +#elif defined(CONFIG_CHARGER_RT9455) +#include +#elif defined(CONFIG_CHARGER_SM5414) +#include +#elif defined(CONFIG_CHARGER_SM5701) +#include +#endif + +#if defined(CONFIG_CHARGER_SM5414) +extern int sec_vf_adc_check(void); +#endif + +struct sec_charger_info { + struct i2c_client *client; + sec_battery_platform_data_t *pdata; + struct power_supply psy_chg; + struct delayed_work isr_work; + + struct workqueue_struct *wq; + struct delayed_work delayed_work; + + int cable_type; + int status; + bool is_charging; + int health; + /* HW-dedicated charger info structure + * used in individual charger file only + * (ex. dummy_charger.c) + */ +#if defined(CONFIG_BATTERY_SAMSUNG) && defined(CONFIG_CHARGER_BQ24157) + struct sec_chg_info info; +#endif + +#if defined(CONFIG_CHARGER_SM5414) + struct sec_chg_info sm5414_chg_inf; + bool is_fullcharged; +#endif + + /* charging current : + charging, - OTG */ + int charging_current; + int input_current_limit; + unsigned charging_current_max; + + /* register programming */ + int reg_addr; + int reg_data; + int irq_base; + int siop_level; + bool is_slow_charging; + struct delayed_work slow_work; +}; + +#if defined(CONFIG_CHARGER_SPRD4SAMSUNG27X3) && \ + !defined(CONFIG_CHARGER_SM5414) && \ + !defined(CONFIG_CHARGER_SMB328) +bool sec_hal_chg_init(charger_variable_t *); +bool sec_hal_chg_suspend(charger_variable_t *); +bool sec_hal_chg_resume(charger_variable_t *); +bool sec_hal_chg_get_property(charger_variable_t *, + enum power_supply_property, + union power_supply_propval *); +bool sec_hal_chg_set_property(charger_variable_t *, + enum power_supply_property, + const union power_supply_propval *); +#else +bool sec_hal_chg_init(struct i2c_client *); +bool sec_hal_chg_suspend(struct i2c_client *); +bool sec_hal_chg_resume(struct i2c_client *); +bool sec_hal_chg_shutdown(struct i2c_client *); +bool sec_hal_chg_get_property(struct i2c_client *, + enum power_supply_property, + union power_supply_propval *); +bool sec_hal_chg_set_property(struct i2c_client *, + enum power_supply_property, + const union power_supply_propval *); +#if defined(CONFIG_CHARGER_SM5414) + int sec_get_charging_health(struct i2c_client *client); +#endif +#endif + +ssize_t sec_hal_chg_show_attrs(struct device *dev, + const ptrdiff_t offset, char *buf); + +ssize_t sec_hal_chg_store_attrs(struct device *dev, + const ptrdiff_t offset, + const char *buf, size_t count); + +ssize_t sec_chg_show_attrs(struct device *dev, + struct device_attribute *attr, char *buf); + +ssize_t sec_chg_store_attrs(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count); + +#define SEC_CHARGER_ATTR(_name) \ +{ \ + .attr = {.name = #_name, .mode = 0664}, \ + .show = sec_chg_show_attrs, \ + .store = sec_chg_store_attrs, \ +} + +/* never declare static varibles in header files + static struct device_attribute sec_charger_attrs[] = { + SEC_CHARGER_ATTR(reg), + SEC_CHARGER_ATTR(data), + SEC_CHARGER_ATTR(regs), + };*/ + +enum { + CHG_REG = 0, + CHG_DATA, + CHG_REGS, +}; +#if defined(CONFIG_CHARGER_SMB358) +extern sec_battery_platform_data_t sec_battery_pdata; +#endif +#endif /* __SEC_CHARGER_H */ diff --git a/include/linux/battery/sec_charging_common.h b/include/linux/battery/sec_charging_common.h new file mode 100755 index 00000000..1192a5e8 --- /dev/null +++ b/include/linux/battery/sec_charging_common.h @@ -0,0 +1,653 @@ +/* + * sec_charging_common.h + * Samsung Mobile Charging Common Header + * + * Copyright (C) 2012 Samsung Electronics, Inc. + * + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __SEC_CHARGING_COMMON_H +#define __SEC_CHARGING_COMMON_H __FILE__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* definitions */ +#define SEC_SIZEOF_POWER_SUPPLY_TYPE 13 + +enum sec_battery_voltage_mode { + /* average voltage */ + SEC_BATTEY_VOLTAGE_AVERAGE = 0, + /* open circuit voltage */ + SEC_BATTEY_VOLTAGE_OCV, +}; + +enum sec_battery_current_mode { + /* uA */ + SEC_BATTEY_CURRENT_UA = 0, + /* mA */ + SEC_BATTEY_CURRENT_MA, +}; + +enum sec_battery_capacity_mode { + /* designed capacity */ + SEC_BATTEY_CAPACITY_DESIGNED = 0, + /* absolute capacity by fuel gauge */ + SEC_BATTEY_CAPACITY_ABSOLUTE, + /* temperary capacity in the time */ + SEC_BATTEY_CAPACITY_TEMPERARY, + /* current capacity now */ + SEC_BATTEY_CAPACITY_CURRENT, +}; + +/* ADC type */ +enum sec_battery_adc_type { + /* NOT using this ADC channel */ + SEC_BATTERY_ADC_TYPE_NONE = 0, + /* ADC in AP */ + SEC_BATTERY_ADC_TYPE_AP, + /* ADC by additional IC */ + SEC_BATTERY_ADC_TYPE_IC, + SEC_BATTERY_ADC_TYPE_NUM +}; + +enum sec_battery_adc_channel { + SEC_BAT_ADC_CHANNEL_CABLE_CHECK = 0, + SEC_BAT_ADC_CHANNEL_BAT_CHECK, + SEC_BAT_ADC_CHANNEL_TEMP, + SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT, + SEC_BAT_ADC_CHANNEL_FULL_CHECK, + SEC_BAT_ADC_CHANNEL_VOLTAGE_NOW, + SEC_BAT_ADC_CHANNEL_NUM +}; + +/* charging mode */ +enum sec_battery_charging_mode { + /* no charging */ + SEC_BATTERY_CHARGING_NONE = 0, + /* 1st charging */ + SEC_BATTERY_CHARGING_1ST, + /* 2nd charging */ + SEC_BATTERY_CHARGING_2ND, + /* recharging */ + SEC_BATTERY_CHARGING_RECHARGING, + /* abs charging*/ + SEC_BATTERY_CHARGING_ABS, +}; + +struct sec_bat_adc_api { + bool (*init)(struct platform_device *); + bool (*exit)(void); + int (*read)(unsigned int); +}; +#define sec_bat_adc_api_t struct sec_bat_adc_api + +/* monitor activation */ +enum sec_battery_polling_time_type { + /* same order with power supply status */ + SEC_BATTERY_POLLING_TIME_BASIC = 0, + SEC_BATTERY_POLLING_TIME_CHARGING, + SEC_BATTERY_POLLING_TIME_DISCHARGING, + SEC_BATTERY_POLLING_TIME_NOT_CHARGING, + SEC_BATTERY_POLLING_TIME_SLEEP, +}; + +enum sec_battery_monitor_polling { + /* polling work queue */ + SEC_BATTERY_MONITOR_WORKQUEUE, + /* alarm polling */ + SEC_BATTERY_MONITOR_ALARM, + /* timer polling (NOT USE) */ + SEC_BATTERY_MONITOR_TIMER, +}; +#define sec_battery_monitor_polling_t \ + enum sec_battery_monitor_polling + +/* full charged check : POWER_SUPPLY_PROP_STATUS */ +enum sec_battery_full_charged { + SEC_BATTERY_FULLCHARGED_NONE = 0, + /* current check by ADC */ + SEC_BATTERY_FULLCHARGED_ADC, + /* fuel gauge current check */ + SEC_BATTERY_FULLCHARGED_FG_CURRENT, + /* time check */ + SEC_BATTERY_FULLCHARGED_TIME, + /* SOC check */ + SEC_BATTERY_FULLCHARGED_SOC, + /* charger GPIO, NO additional full condition */ + SEC_BATTERY_FULLCHARGED_CHGGPIO, + /* charger interrupt, NO additional full condition */ + SEC_BATTERY_FULLCHARGED_CHGINT, + /* charger power supply property, NO additional full condition */ + SEC_BATTERY_FULLCHARGED_CHGPSY, +}; +#define sec_battery_full_charged_t \ + enum sec_battery_full_charged + +/* full check condition type (can be used overlapped) */ +#define sec_battery_full_condition_t unsigned int +/* SEC_BATTERY_FULL_CONDITION_NOTIMEFULL + * full-charged by absolute-timer only in high voltage + */ +#define SEC_BATTERY_FULL_CONDITION_NOTIMEFULL 1 +/* SEC_BATTERY_FULL_CONDITION_NOSLEEPINFULL + * do not set polling time as sleep polling time in full-charged + */ +#define SEC_BATTERY_FULL_CONDITION_NOSLEEPINFULL 2 +/* SEC_BATTERY_FULL_CONDITION_SOC + * use capacity for full-charged check + */ +#define SEC_BATTERY_FULL_CONDITION_SOC 4 +/* SEC_BATTERY_FULL_CONDITION_VCELL + * use VCELL for full-charged check + */ +#define SEC_BATTERY_FULL_CONDITION_VCELL 8 +/* SEC_BATTERY_FULL_CONDITION_AVGVCELL + * use average VCELL for full-charged check + */ +#define SEC_BATTERY_FULL_CONDITION_AVGVCELL 16 +/* SEC_BATTERY_FULL_CONDITION_OCV + * use OCV for full-charged check + */ +#define SEC_BATTERY_FULL_CONDITION_OCV 32 + +/* recharge check condition type (can be used overlapped) */ +#define sec_battery_recharge_condition_t unsigned int +/* SEC_BATTERY_RECHARGE_CONDITION_SOC + * use capacity for recharging check + */ +#define SEC_BATTERY_RECHARGE_CONDITION_SOC 1 +/* SEC_BATTERY_RECHARGE_CONDITION_AVGVCELL + * use average VCELL for recharging check + */ +#define SEC_BATTERY_RECHARGE_CONDITION_AVGVCELL 2 +/* SEC_BATTERY_RECHARGE_CONDITION_VCELL + * use VCELL for recharging check + */ +#define SEC_BATTERY_RECHARGE_CONDITION_VCELL 4 + +/* battery check : POWER_SUPPLY_PROP_PRESENT */ +enum sec_battery_check { + /* No Check for internal battery */ + SEC_BATTERY_CHECK_NONE, + /* by ADC */ + SEC_BATTERY_CHECK_ADC, + /* by callback function (battery certification by 1 wired)*/ + SEC_BATTERY_CHECK_CALLBACK, + /* by PMIC */ + SEC_BATTERY_CHECK_PMIC, + /* by fuel gauge */ + SEC_BATTERY_CHECK_FUELGAUGE, + /* by charger */ + SEC_BATTERY_CHECK_CHARGER, + /* by interrupt (use check_battery_callback() to check battery) */ + SEC_BATTERY_CHECK_INT, +}; +#define sec_battery_check_t \ + enum sec_battery_check + +/* OVP, UVLO check : POWER_SUPPLY_PROP_HEALTH */ +enum sec_battery_ovp_uvlo { + /* by callback function */ + SEC_BATTERY_OVP_UVLO_CALLBACK, + /* by PMIC polling */ + SEC_BATTERY_OVP_UVLO_PMICPOLLING, + /* by PMIC interrupt */ + SEC_BATTERY_OVP_UVLO_PMICINT, + /* by charger polling */ + SEC_BATTERY_OVP_UVLO_CHGPOLLING, + /* by charger interrupt */ + SEC_BATTERY_OVP_UVLO_CHGINT, +}; +#define sec_battery_ovp_uvlo_t \ + enum sec_battery_ovp_uvlo + +/* thermal source */ +enum sec_battery_thermal_source { + /* by fuel gauge */ + SEC_BATTERY_THERMAL_SOURCE_FG, + /* by external source */ + SEC_BATTERY_THERMAL_SOURCE_CALLBACK, + /* by ADC */ + SEC_BATTERY_THERMAL_SOURCE_ADC, +}; +#define sec_battery_thermal_source_t \ + enum sec_battery_thermal_source + +/* temperature check type */ +enum sec_battery_temp_check { + SEC_BATTERY_TEMP_CHECK_NONE = 0, /* no temperature check */ + SEC_BATTERY_TEMP_CHECK_ADC, /* by ADC value */ + SEC_BATTERY_TEMP_CHECK_TEMP, /* by temperature */ +}; + +#define sec_battery_temp_check_t \ + enum sec_battery_temp_check + +/* cable check (can be used overlapped) */ +#define sec_battery_cable_check_t unsigned int +/* SEC_BATTERY_CABLE_CHECK_NOUSBCHARGE + * for USB cable in tablet model, + * status is stuck into discharging, + * but internal charging logic is working + */ +#define SEC_BATTERY_CABLE_CHECK_NOUSBCHARGE 1 +/* SEC_BATTERY_CABLE_CHECK_NOINCOMPATIBLECHARGE + * for incompatible charger + * (Not compliant to USB specification, + * cable type is POWER_SUPPLY_TYPE_UNKNOWN), + * do NOT charge and show message to user + * (only for VZW) + */ +#define SEC_BATTERY_CABLE_CHECK_NOINCOMPATIBLECHARGE 2 +/* SEC_BATTERY_CABLE_CHECK_PSY + * check cable by power supply set_property + */ +#define SEC_BATTERY_CABLE_CHECK_PSY 4 +/* SEC_BATTERY_CABLE_CHECK_INT + * check cable by interrupt + */ +#define SEC_BATTERY_CABLE_CHECK_INT 8 +/* SEC_BATTERY_CABLE_CHECK_CHGINT + * check cable by charger interrupt + */ +#define SEC_BATTERY_CABLE_CHECK_CHGINT 16 +/* SEC_BATTERY_CABLE_CHECK_POLLING + * check cable by GPIO polling + */ +#define SEC_BATTERY_CABLE_CHECK_POLLING 32 + +/* check cable source (can be used overlapped) */ +#define sec_battery_cable_source_t unsigned int +/* SEC_BATTERY_CABLE_SOURCE_EXTERNAL + * already given by external argument + */ +#define SEC_BATTERY_CABLE_SOURCE_EXTERNAL 1 +/* SEC_BATTERY_CABLE_SOURCE_CALLBACK + * by callback (MUIC, USB switch) + */ +#define SEC_BATTERY_CABLE_SOURCE_CALLBACK 2 +/* SEC_BATTERY_CABLE_SOURCE_ADC + * by ADC + */ +#define SEC_BATTERY_CABLE_SOURCE_ADC 4 +/* SEC_BATTERY_CABLE_SOURCE_EXTENDED + * use extended cable type + */ +#define SEC_BATTERY_CABLE_SOURCE_EXTENDED 8 + +/* capacity calculation type (can be used overlapped) */ +#define sec_fuelgauge_capacity_type_t int +/* SEC_FUELGAUGE_CAPACITY_TYPE_RESET + * use capacity information to reset fuel gauge + * (only for driver algorithm, can NOT be set by user) + */ +#define SEC_FUELGAUGE_CAPACITY_TYPE_RESET (-1) +/* SEC_FUELGAUGE_CAPACITY_TYPE_RAW + * use capacity information from fuel gauge directly + */ +#define SEC_FUELGAUGE_CAPACITY_TYPE_RAW 1 +/* SEC_FUELGAUGE_CAPACITY_TYPE_SCALE + * rescale capacity by scaling, need min and max value for scaling + */ +#define SEC_FUELGAUGE_CAPACITY_TYPE_SCALE 2 +/* SEC_FUELGAUGE_CAPACITY_TYPE_DYNAMIC_SCALE + * change only maximum capacity dynamically + * to keep time for every SOC unit + */ +#define SEC_FUELGAUGE_CAPACITY_TYPE_DYNAMIC_SCALE 4 +/* SEC_FUELGAUGE_CAPACITY_TYPE_ATOMIC + * change capacity value by only -1 or +1 + * no sudden change of capacity + */ +#define SEC_FUELGAUGE_CAPACITY_TYPE_ATOMIC 8 +/* SEC_FUELGAUGE_CAPACITY_TYPE_SKIP_ABNORMAL + * skip current capacity value + * if it is abnormal value + */ +#define SEC_FUELGAUGE_CAPACITY_TYPE_SKIP_ABNORMAL 16 + +/* charger function settings (can be used overlapped) */ +#define sec_charger_functions_t unsigned int +/* SEC_CHARGER_NO_GRADUAL_CHARGING_CURRENT + * disable gradual charging current setting + * SUMMIT:AICL, MAXIM:regulation loop + */ +#define SEC_CHARGER_NO_GRADUAL_CHARGING_CURRENT 1 + +/* SEC_CHARGER_MINIMUM_SIOP_CHARGING_CURRENT + * charging current should be over than USB charging current + */ +#define SEC_CHARGER_MINIMUM_SIOP_CHARGING_CURRENT 2 + +/** + * struct sec_bat_adc_table_data - adc to temperature table for sec battery + * driver + * @adc: adc value + * @temperature: temperature(C) * 10 + */ +struct sec_bat_adc_table_data { +#ifdef CONFIG_OF + unsigned int adc; + unsigned int data; +#else + int adc; + int data; +#endif + int temperature; +}; +#define sec_bat_adc_table_data_t \ + struct sec_bat_adc_table_data + +struct sec_bat_adc_region { + int min; + int max; +}; +#define sec_bat_adc_region_t \ + struct sec_bat_adc_region + +struct sec_charging_current { +#ifdef CONFIG_OF + unsigned int input_current_limit; + unsigned int fast_charging_current; + unsigned int full_check_current_1st; + unsigned int full_check_current_2nd; +#else + int input_current_limit; + int fast_charging_current; + int full_check_current_1st; + int full_check_current_2nd; +#endif +}; +#define sec_charging_current_t \ + struct sec_charging_current + +struct sec_battery_info; + +struct sec_battery_platform_data { + /* NO NEED TO BE CHANGED */ + /* callback functions */ + void (*initial_check)(struct sec_battery_info *battery); + void (*monitor_additional_check)(void); + bool (*bat_gpio_init)(void); + bool (*fg_gpio_init)(void); + bool (*chg_gpio_init)(void); + bool (*is_lpm)(void); + bool (*check_jig_status)(void); + bool (*is_interrupt_cable_check_possible)(int); + int (*check_cable_callback)(struct sec_battery_info *battery); + int (*get_cable_from_extended_cable_type)(int); + bool (*cable_switch_check)(void); + bool (*cable_switch_normal)(void); + bool (*check_cable_result_callback)(int); + bool (*check_battery_callback)(struct sec_battery_info *battery); + bool (*check_battery_result_callback)(void); + int (*ovp_uvlo_callback)(void); + bool (*ovp_uvlo_result_callback)(int); + bool (*fuelalert_process)(bool); + bool (*get_temperature_callback)( + enum power_supply_property, + union power_supply_propval*); + void (*check_batt_id)(struct sec_battery_info *battery); + + /* ADC API for each ADC type */ + sec_bat_adc_api_t adc_api[SEC_BATTERY_ADC_TYPE_NUM]; + /* ADC region by power supply type + * ADC region should be exclusive + */ + sec_bat_adc_region_t *cable_adc_value; + /* charging current for type (0: not use) */ + sec_charging_current_t *charging_current; +#ifdef CONFIG_OF + unsigned int *polling_time; +#else + int *polling_time; +#endif + char *chip_vendor; + unsigned int temp_adc_type; + /* NO NEED TO BE CHANGED */ + + char *pmic_name; + + /* battery */ + char *vendor; + int technology; + int battery_type; + void *battery_data; + + int bat_gpio_ta_nconnected; + /* 1 : active high, 0 : active low */ + int bat_polarity_ta_nconnected; + int ta_irq; + int ta_irq_gpio; /* TA_INT(Vbus detecting) */ + unsigned long ta_irq_attr; + int bat_irq; + int bat_irq_gpio; /* BATT_INT(BAT_ID detecting) */ + unsigned long bat_irq_attr; + int jig_irq; + unsigned long jig_irq_attr; + sec_battery_cable_check_t cable_check_type; + sec_battery_cable_source_t cable_source_type; + + bool use_LED; /* use charging LED */ + + bool event_check; + /* sustaining event after deactivated (second) */ + unsigned int event_waiting_time; + + /* Monitor setting */ + sec_battery_monitor_polling_t polling_type; + /* for initial check */ + unsigned int monitor_initial_count; + + /* Battery check */ + sec_battery_check_t battery_check_type; + /* how many times do we need to check battery */ + unsigned int check_count; + /* ADC */ + /* battery check ADC maximum value */ + unsigned int check_adc_max; + /* battery check ADC minimum value */ + unsigned int check_adc_min; + + /* OVP/UVLO check */ + sec_battery_ovp_uvlo_t ovp_uvlo_check_type; + + sec_battery_thermal_source_t thermal_source; +#ifdef CONFIG_OF + sec_bat_adc_table_data_t *temp_adc_table; + sec_bat_adc_table_data_t *temp_amb_adc_table; +#else + const sec_bat_adc_table_data_t *temp_adc_table; + const sec_bat_adc_table_data_t *temp_amb_adc_table; +#endif + unsigned int temp_adc_table_size; + unsigned int temp_amb_adc_table_size; + + sec_battery_temp_check_t temp_check_type; + unsigned int temp_check_count; + unsigned int temp_adc_channel; + /* + * limit can be ADC value or Temperature + * depending on temp_check_type + * temperature should be temp x 10 (0.1 degree) + */ + int temp_highlimit_threshold_event; + int temp_highlimit_recovery_event; + int temp_high_threshold_event; + int temp_high_recovery_event; + int temp_low_threshold_event; + int temp_low_recovery_event; + int temp_highlimit_threshold_normal; + int temp_highlimit_recovery_normal; + int temp_high_threshold_normal; + int temp_high_recovery_normal; + int temp_low_threshold_normal; + int temp_low_recovery_normal; + int temp_highlimit_threshold_lpm; + int temp_highlimit_recovery_lpm; + int temp_high_threshold_lpm; + int temp_high_recovery_lpm; + int temp_low_threshold_lpm; + int temp_low_recovery_lpm; + + /* If these is NOT full check type or NONE full check type, + * it is skipped + */ + /* 1st full check */ + sec_battery_full_charged_t full_check_type; + /* 2nd full check */ + sec_battery_full_charged_t full_check_type_2nd; + unsigned int full_check_count; + int chg_gpio_full_check; + /* 1 : active high, 0 : active low */ + int chg_polarity_full_check; + sec_battery_full_condition_t full_condition_type; + unsigned int full_condition_soc; + unsigned int full_condition_vcell; + unsigned int full_condition_avgvcell; + unsigned int full_condition_ocv; + + unsigned int recharge_check_count; + sec_battery_recharge_condition_t recharge_condition_type; + unsigned int recharge_condition_soc; + unsigned int recharge_condition_avgvcell; + unsigned int recharge_condition_vcell; + + /* for absolute timer (second) */ + unsigned long charging_total_time; + /* for recharging timer (second) */ + unsigned long recharging_total_time; + /* reset charging for abnormal malfunction (0: not use) */ + unsigned long charging_reset_time; + + /* fuel gauge */ + char *fuelgauge_name; + int fg_irq; + unsigned long fg_irq_attr; + /* fuel alert SOC (-1: not use) */ + int fuel_alert_soc; + /* fuel alert can be repeated */ + bool repeated_fuelalert; + sec_fuelgauge_capacity_type_t capacity_calculation_type; + /* soc should be soc x 10 (0.1% degree) + * only for scaling + */ + int capacity_max; + int capacity_max_margin; + int capacity_min; + + int vf_adc; + + /* charger */ + char *charger_name; + + int vbus_ctrl_gpio; + int chg_gpio_en; + /* 1 : active high, 0 : active low */ + int chg_polarity_en; + int chg_gpio_curr_adj; + /* 1 : active high, 0 : active low */ + int chg_polarity_curr_adj; + int chg_gpio_status; + /* 1 : active high, 0 : active low */ + int chg_polarity_status; + int chg_irq; + unsigned long chg_irq_attr; + /* float voltage (mV) */ +#ifdef CONFIG_OF + unsigned int chg_float_voltage; +#else + int chg_float_voltage; +#endif + int chg_min_system_voltage; + sec_charger_functions_t chg_functions_setting; + + + int siop_level; + bool siop_activated; + + /* ADC setting */ + unsigned int adc_check_count; + /* ADC type for each channel */ + unsigned int adc_type[]; +}; +#define sec_battery_platform_data_t \ + struct sec_battery_platform_data + +static inline struct power_supply *get_power_supply_by_name(char *name) +{ + if (!name) + return (struct power_supply *)NULL; + else + return power_supply_get_by_name(name); +} + +#define psy_do_property(name, function, property, value) \ +{ \ + struct power_supply *psy; \ + int ret; \ + psy = get_power_supply_by_name((name)); \ + if (!psy) { \ + pr_err("%s: Fail to "#function" psy (%s)\n", \ + __func__, (name)); \ + value.intval = 0; \ + } else { \ + if (psy->function##_property != NULL) { \ + ret = psy->function##_property(psy, (property), &(value)); \ + if (ret < 0) { \ + pr_err("%s: Fail to "#name" "#function" (%d=>%d)\n", \ + __func__, (property), ret); \ + value.intval = 0; \ + } \ + } \ + } \ +} + +#ifndef CONFIG_OF +#define adc_init(pdev, pdata, channel) \ + (((pdata)->adc_api)[((((pdata)->adc_type[(channel)]) < \ + SEC_BATTERY_ADC_TYPE_NUM) ? ((pdata)->adc_type[(channel)]) : \ + SEC_BATTERY_ADC_TYPE_NONE)].init((pdev))) + +#define adc_exit(pdata, channel) \ + (((pdata)->adc_api)[((pdata)->adc_type[(channel)])].exit()) + +#define adc_read(pdata, channel) \ + (((pdata)->adc_api)[((pdata)->adc_type[(channel)])].read((channel))) +#endif + +#define get_battery_data(driver) \ + (((struct battery_data_t *)(driver)->pdata->battery_data) \ + [(driver)->pdata->battery_type]) + +#define GET_MAIN_CABLE_TYPE(extended) \ + ((extended >> ONLINE_TYPE_MAIN_SHIFT)&0xf) +#define GET_SUB_CABLE_TYPE(extended) \ + ((extended >> ONLINE_TYPE_SUB_SHIFT)&0xf) +#define GET_POWER_CABLE_TYPE(extended) \ + ((extended >> ONLINE_TYPE_PWR_SHIFT)&0xf) + +#endif /* __SEC_CHARGING_COMMON_H */ diff --git a/include/linux/battery/sec_fuelgauge.h b/include/linux/battery/sec_fuelgauge.h new file mode 100644 index 00000000..9edd84de --- /dev/null +++ b/include/linux/battery/sec_fuelgauge.h @@ -0,0 +1,143 @@ +/* + * sec_fuelgauge.h + * Samsung Mobile Fuel Gauge Header + * + * Copyright (C) 2012 Samsung Electronics, Inc. + * + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __SEC_FUELGAUGE_H +#define __SEC_FUELGAUGE_H __FILE__ + +#if defined(CONFIG_FUELGAUGE_MFD) || defined(CONFIG_FUELGAUGE_SPRD4SAMSUNG27X3) +#define fuelgauge_variable fuelgauge +#define fuelgauge_variable_t struct sec_fuelgauge_info +#else +#define fuelgauge_variable (fuelgauge->client) +#define fuelgauge_variable_t struct i2c_client +#endif + +#include + +#if defined(CONFIG_FUELGAUGE_DUMMY) || \ + defined(CONFIG_FUELGAUGE_PM8917) +#include +#elif defined(CONFIG_FUELGAUGE_MAX17042) +#include +#elif defined(CONFIG_FUELGAUGE_MAX17048) +#include +#elif defined(CONFIG_FUELGAUGE_MAX17050) +#include +#elif defined(CONFIG_FUELGAUGE_MAX77823) +#include +#elif defined(CONFIG_FUELGAUGE_RT5033) +#include +#else +struct sec_fg_info { + bool dummy; +}; +#endif + +#ifdef CONFIG_FUELGAUGE_SPRD4SAMSUNG27X3 +#include +#endif + +struct sec_fuelgauge_reg_data { + u8 reg_addr; + u8 reg_data1; + u8 reg_data2; +}; + +struct sec_fuelgauge_info { + struct i2c_client *client; + sec_battery_platform_data_t *pdata; + struct power_supply psy_fg; + struct delayed_work isr_work; + + int cable_type; + bool is_charging; + + /* HW-dedicated fuel guage info structure + * used in individual fuel gauge file only + * (ex. dummy_fuelgauge.c) + */ + struct sec_fg_info info; + + bool is_fuel_alerted; + struct wake_lock fuel_alert_wake_lock; + + unsigned int capacity_old; /* only for atomic calculation */ + unsigned int capacity_max; /* only for dynamic calculation */ + + bool initial_update_of_soc; + struct mutex fg_lock; + + /* register programming */ + int reg_addr; + u8 reg_data[2]; + + int fg_irq; +}; + +bool sec_hal_fg_init(fuelgauge_variable_t *); +bool sec_hal_fg_suspend(fuelgauge_variable_t *); +bool sec_hal_fg_resume(fuelgauge_variable_t *); +bool sec_hal_fg_fuelalert_init(fuelgauge_variable_t *, int); +bool sec_hal_fg_is_fuelalerted(fuelgauge_variable_t *); +bool sec_hal_fg_fuelalert_process(void *, bool); +bool sec_hal_fg_full_charged(fuelgauge_variable_t *); +bool sec_hal_fg_reset(fuelgauge_variable_t *); +bool sec_hal_fg_get_property(fuelgauge_variable_t *, + enum power_supply_property, + union power_supply_propval *); +bool sec_hal_fg_set_property(fuelgauge_variable_t *, + enum power_supply_property, + const union power_supply_propval *); + +ssize_t sec_hal_fg_show_attrs(struct device *dev, + const ptrdiff_t offset, char *buf); + +ssize_t sec_hal_fg_store_attrs(struct device *dev, + const ptrdiff_t offset, + const char *buf, size_t count); + +ssize_t sec_fg_show_attrs(struct device *dev, + struct device_attribute *attr, char *buf); + +ssize_t sec_fg_store_attrs(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count); + +#ifdef CONFIG_OF +#if defined(CONFIG_FUELGAUGE_MAX77823) +void board_fuelgauge_init(struct max77823_fuelgauge_data *fuelgauge); +#else +extern void board_fuelgauge_init(struct sec_fuelgauge_info *fuelgauge); +#endif +extern bool sec_bat_check_jig_status(void); +#endif + +#define SEC_FG_ATTR(_name) \ +{ \ + .attr = {.name = #_name, .mode = 0664}, \ + .show = sec_fg_show_attrs, \ + .store = sec_fg_store_attrs, \ +} + +enum { + FG_REG = 0, + FG_DATA, + FG_REGS, +}; + +#endif /* __SEC_FUELGAUGE_H */ -- cgit v1.3.1