Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
Merge branch 'oneplus/SM8150_Q_10.0_Beta' of https://github.com/OnePl…
Browse files Browse the repository at this point in the history
…usOSS/android_kernel_oneplus_sm8150 into neutrino-msm-hotdogb-4.14

Release OP7Pro_O2_BETA_8/OP7_O2_BETA_8
HEAD: d1c7884 ("Synchronize codes for OP7Pro_O2_BETA_8 and OP7_O2_BETA_8")

Selectively merge Optimized Charging framework from OEM Beta source.

Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
  • Loading branch information
0ctobot committed May 2, 2020
2 parents 2b039c3 + d1c7884 commit 76b58e0
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 8 deletions.
3 changes: 3 additions & 0 deletions drivers/power/supply/power_supply_sysfs.c
Expand Up @@ -352,6 +352,9 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(temp_cold),
POWER_SUPPLY_ATTR(temp_hot),
POWER_SUPPLY_ATTR(system_temp_level),
POWER_SUPPLY_ATTR(battery_health),
POWER_SUPPLY_ATTR(op_disable_charge),
POWER_SUPPLY_ATTR(remaining_capacity),
POWER_SUPPLY_ATTR(resistance),
POWER_SUPPLY_ATTR(resistance_capacitive),
POWER_SUPPLY_ATTR(resistance_id),
Expand Down
58 changes: 56 additions & 2 deletions drivers/power/supply/qcom/bq27541_fuelgauger.c
Expand Up @@ -92,6 +92,7 @@
#define BQ27411_REG_AI 0x10
#define BQ27411_REG_SOC 0x1c
#define BQ27411_REG_HEALTH 0x20
#define BQ27411_REG_FCC 0xE

#define CONTROL_CMD 0x00
#define CONTROL_STATUS 0x00
Expand Down Expand Up @@ -229,6 +230,8 @@ struct bq27541_device_info {
int soc_pre;
int batt_vol_pre;
int current_pre;
int cap_pre;
int remain_pre;
int health_pre;
unsigned long rtc_resume_time;
unsigned long rtc_suspend_time;
Expand Down Expand Up @@ -260,7 +263,9 @@ struct bq27541_device_info {
};

#include <linux/workqueue.h>

/* add to update fg node value on panel event */
int panel_flag1;
int panel_flag2;
struct update_pre_capacity_data {
struct delayed_work work;
struct workqueue_struct *workqueue;
Expand Down Expand Up @@ -881,7 +886,11 @@ static int bq27541_remaining_capacity(struct bq27541_device_info *di)
int ret;
int cap = 0;

if (di->allow_reading) {
/* Add for get right soc when sleep long time */
if (atomic_read(&di->suspended) == 1)
return di->remain_pre;

if (di->allow_reading || panel_flag1) {
#ifdef CONFIG_GAUGE_BQ27411
/* david.liu@bsp, 20161004 Add BQ27411 support */
ret = bq27541_read(di->cmd_addr.reg_rm,
Expand All @@ -893,11 +902,48 @@ static int bq27541_remaining_capacity(struct bq27541_device_info *di)
pr_err("error reading capacity.\n");
return ret;
}
if (panel_flag1)
panel_flag1 = 0;
} else {
return di->remain_pre;
}

di->remain_pre = cap;
return cap;
}

static int bq27541_full_chg_capacity(struct bq27541_device_info *di)
{
int ret;
int cap = 0;

/* Add for get right soc when sleep long time */
if (atomic_read(&di->suspended) == 1)
return di->cap_pre;

if (di->allow_reading || panel_flag2) {
#ifdef CONFIG_GAUGE_BQ27411
/* david.liu@bsp, 20161004 Add BQ27411 support */
ret = bq27541_read(BQ27411_REG_FCC,
&cap, 0, di);
#else
ret = bq27541_read(BQ27541_REG_FCC, &cap, 0, di);
#endif
if (ret) {
pr_err("error reading full chg capacity.\n");
return ret;
}
if (panel_flag2)
panel_flag2 = 0;
} else {
return di->cap_pre;
}

di->cap_pre = cap;
return cap;
}


static int bq27541_batt_health(struct bq27541_device_info *di)
{
int ret;
Expand Down Expand Up @@ -929,6 +975,12 @@ static int bq27541_get_batt_remaining_capacity(void)
return bq27541_remaining_capacity(bq27541_di);
}

static int bq27541_get_batt_full_chg_capacity(void)
{
return bq27541_full_chg_capacity(bq27541_di);
}


static int bq27541_get_batt_health(void)
{
return bq27541_batt_health(bq27541_di);
Expand Down Expand Up @@ -1069,6 +1121,8 @@ static struct external_battery_gauge bq27541_batt_gauge = {
.is_battery_id_valid = bq27541_is_battery_id_valid,
.get_batt_remaining_capacity
= bq27541_get_batt_remaining_capacity,
.get_batt_full_chg_capacity
= bq27541_get_batt_full_chg_capacity,
.get_batt_health = bq27541_get_batt_health,
.get_batt_bq_soc = bq27541_get_batt_bq_soc,
#ifdef CONFIG_GAUGE_BQ27411
Expand Down
31 changes: 27 additions & 4 deletions drivers/power/supply/qcom/qpnp-fg-gen4.c
Expand Up @@ -4321,6 +4321,13 @@ static int fg_psy_get_property(struct power_supply *psy,
} else
pval->intval = -400;
break;
case POWER_SUPPLY_PROP_BATTERY_HEALTH:
if (fg->use_external_fg && external_fg
&& external_fg->get_batt_health)
pval->intval = external_fg->get_batt_health();
else
pval->intval = -1;
break;
case POWER_SUPPLY_PROP_RESISTANCE:
rc = fg_get_battery_resistance(fg, &pval->intval);
break;
Expand Down Expand Up @@ -4352,14 +4359,28 @@ static int fg_psy_get_property(struct power_supply *psy,
pval->intval = chip->cl->init_cap_uah;
break;
case POWER_SUPPLY_PROP_CHARGE_FULL:
rc = fg_gen4_get_learned_capacity(chip, &temp);
if (!rc)
pval->intval = (int)temp;
if (!get_extern_fg_regist_done() && get_extern_bq_present())
pval->intval = -EINVAL;
else if (fg->use_external_fg && external_fg && external_fg->get_batt_full_chg_capacity)
pval->intval = external_fg->get_batt_full_chg_capacity();
else {
rc = fg_gen4_get_learned_capacity(chip, &temp);
if (!rc)
pval->intval = (int)temp;
}
break;
case POWER_SUPPLY_PROP_REMAINING_CAPACITY:
if (!get_extern_fg_regist_done() && get_extern_bq_present())
pval->intval = DEFALUT_BATT_TEMP;
else if (fg->use_external_fg && external_fg && external_fg->get_batt_remaining_capacity)
pval->intval = external_fg->get_batt_remaining_capacity();
else
pval->intval = -EINVAL;
break;
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
rc = fg_gen4_get_nominal_capacity(chip, &temp);
if (!rc)
pval->intval = (int)temp;
pval->intval = -EINVAL;
break;
case POWER_SUPPLY_PROP_CHARGE_COUNTER:
rc = fg_gen4_get_charge_counter(chip, &pval->intval);
Expand Down Expand Up @@ -4621,6 +4642,8 @@ static enum power_supply_property fg_psy_props[] = {
/* @bsp, 2019/04/17 Battery & Charging porting */
POWER_SUPPLY_PROP_SET_ALLOW_READ_EXTERN_FG_IIC,
POWER_SUPPLY_PROP_BQ_SOC,
POWER_SUPPLY_PROP_BATTERY_HEALTH,
POWER_SUPPLY_PROP_REMAINING_CAPACITY,
};

static const struct power_supply_desc fg_psy_desc = {
Expand Down
15 changes: 15 additions & 0 deletions drivers/power/supply/qcom/qpnp-smb5.c
Expand Up @@ -2032,6 +2032,7 @@ static enum power_supply_property smb5_batt_props[] = {
POWER_SUPPLY_PROP_CHARGE_FULL,
POWER_SUPPLY_PROP_FORCE_RECHARGE,
POWER_SUPPLY_PROP_FCC_STEPPER_ENABLE,
POWER_SUPPLY_PROP_OP_DISABLE_CHARGE,
};

#define DEBUG_ACCESSORY_TEMP_DECIDEGC 250
Expand Down Expand Up @@ -2065,6 +2066,9 @@ static int smb5_batt_get_prop(struct power_supply *psy,
case POWER_SUPPLY_PROP_CAPACITY:
rc = smblib_get_prop_batt_capacity(chg, val);
break;
case POWER_SUPPLY_PROP_OP_DISABLE_CHARGE:
val->intval = chg->chg_disabled;
break;
/* @bsp, 2019/04/17 Battery & Charging porting */
case POWER_SUPPLY_PROP_CHARGE_NOW:
rc = smblib_get_prop_usb_voltage_now(chg, val);
Expand Down Expand Up @@ -2252,6 +2256,16 @@ static int smb5_batt_set_prop(struct power_supply *psy,
|| val->intval == 1500000 || val->intval == 1000000)
op_usb_icl_set(chg, val->intval);
break;
case POWER_SUPPLY_PROP_OP_DISABLE_CHARGE:
vote(chg->chg_disable_votable, FORCE_RECHARGE_VOTER,
(bool)val->intval, 0);
if (val->intval) {
switch_mode_to_normal();
op_set_fast_chg_allow(chg, false);
}
chg->chg_disabled = (bool)val->intval;
pr_info("user set disable chg %d\n", val->intval);
break;
case POWER_SUPPLY_PROP_CONNECT_DISABLE:
op_disconnect_vbus(chg, (bool)val->intval);
break;
Expand Down Expand Up @@ -2386,6 +2400,7 @@ static int smb5_batt_prop_is_writeable(struct power_supply *psy,
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMITED:
case POWER_SUPPLY_PROP_STEP_CHARGING_ENABLED:
case POWER_SUPPLY_PROP_DIE_HEALTH:
case POWER_SUPPLY_PROP_OP_DISABLE_CHARGE:
return 1;
default:
break;
Expand Down
24 changes: 22 additions & 2 deletions drivers/power/supply/qcom/smb5-lib.c
Expand Up @@ -7383,7 +7383,12 @@ static int op_charging_en(struct smb_charger *chg, bool en)
{
int rc;

pr_err("enable=%d\n", en);
pr_info("enable=%d\n", en);
if (chg->chg_disabled && en) {
pr_info("chg_disabled just return\n");
return 0;
}

rc = smblib_masked_write(chg, CHARGING_ENABLE_CMD_REG,
CHARGING_ENABLE_CMD_BIT,
en ? CHARGING_ENABLE_CMD_BIT : 0);
Expand Down Expand Up @@ -7445,6 +7450,8 @@ bool is_fastchg_allowed(struct smb_charger *chg)
low_temp_full = op_get_fast_low_temp_full(chg);
fw_updated = get_fastchg_firmware_updated_status(chg);

if (chg->chg_disabled)
return false;
if (!fw_updated)
return false;
if (chg->usb_enum_status)
Expand Down Expand Up @@ -7533,8 +7540,11 @@ static void op_handle_usb_removal(struct smb_charger *chg)
chg->recovery_boost_count = 0;
chg->ck_unplug_count = 0;
chg->count_run = 0;
chg->chg_disabled = 0;
vote(chg->fcc_votable,
DEFAULT_VOTER, true, SDP_CURRENT_UA);
vote(chg->chg_disable_votable,
FORCE_RECHARGE_VOTER, false, 0);
#ifdef CONFIG_FORCE_FAST_CHARGE
set_sdp_current(chg, USBIN_500MA);
chg->ffc_count = 0;
Expand Down Expand Up @@ -7992,7 +8002,10 @@ static void retrigger_dash_work(struct work_struct *work)
chg->ck_dash_count = 0;
return;
}

if (chg->chg_disabled) {
chg->ck_dash_count = 0;
return;
}
if (chg->pd_active) {
chg->ck_dash_count = 0;
pr_info("pd_active return retrigger_dash\n");
Expand Down Expand Up @@ -9018,6 +9031,9 @@ static int msm_drm_notifier_callback(struct notifier_block *self,
vote(chip->usb_icl_votable,
SW_ICL_MAX_VOTER, true, rp_ua);
}
/* add to update fg node value on panel event */
panel_flag1 = 1;
panel_flag2 = 1;
}

return 0;
Expand Down Expand Up @@ -9645,6 +9661,10 @@ static void op_heartbeat_work(struct work_struct *work)
power_supply_changed(chg->batt_psy);
chg->dash_on = get_prop_fast_chg_started(chg);
if (chg->dash_on) {
if (chg->chg_disabled) {
set_usb_switch(chg, false);
goto out;
}
switch_fast_chg(chg);
pr_debug("fast chg started, usb_switch=%d\n",
op_is_usb_switch_on(chg));
Expand Down
4 changes: 4 additions & 0 deletions drivers/power/supply/qcom/smb5-lib.h
Expand Up @@ -620,6 +620,7 @@ struct smb_charger {
bool disable_normal_chg_for_dash;
bool ship_mode;
bool dash_on;
bool chg_disabled;
bool chg_ovp;
bool is_power_changed;
bool recharge_pending;
Expand Down Expand Up @@ -821,6 +822,9 @@ extern bool get_prop_fast_chg_started(struct smb_charger *chg);
extern void mcu_en_gpio_set(int value);
extern void switch_mode_to_normal(void);
extern struct smb_charger *g_chg;
/* add to update fg node value on panel event */
extern int panel_flag1;
extern int panel_flag2;
void op_disconnect_vbus(struct smb_charger *chg, bool enable);

int smblib_read(struct smb_charger *chg, u16 addr, u8 *val);
Expand Down
1 change: 1 addition & 0 deletions include/linux/power/oem_external_fg.h
Expand Up @@ -37,6 +37,7 @@ struct external_battery_gauge {
bool (*is_usb_switch_on)(void);
int (*get_battery_status)(void);
int (*get_batt_remaining_capacity)(void);
int (*get_batt_full_chg_capacity)(void);
int (*get_batt_health)(void);
int (*get_batt_bq_soc)(void);
int (*monitor_for_recharging)(void);
Expand Down
3 changes: 3 additions & 0 deletions include/linux/power_supply.h
Expand Up @@ -275,6 +275,9 @@ enum power_supply_property {
POWER_SUPPLY_PROP_COLD_TEMP,
POWER_SUPPLY_PROP_HOT_TEMP,
POWER_SUPPLY_PROP_SYSTEM_TEMP_LEVEL,
POWER_SUPPLY_PROP_BATTERY_HEALTH,
POWER_SUPPLY_PROP_OP_DISABLE_CHARGE,
POWER_SUPPLY_PROP_REMAINING_CAPACITY,
POWER_SUPPLY_PROP_RESISTANCE,
POWER_SUPPLY_PROP_RESISTANCE_CAPACITIVE,
POWER_SUPPLY_PROP_RESISTANCE_ID, /* in Ohms */
Expand Down

0 comments on commit 76b58e0

Please sign in to comment.