Skip to content

Commit

Permalink
Synchronize codes for OnePlus 8T Oxygen OS 11.0.8.12.KB05AA and OnePl…
Browse files Browse the repository at this point in the history
…us 8 Oxygen OS 11.0.6.6.IN21AA and OnePlus 8 Pro Oxygen OS 11.0.6.6.IN11AA

1. Optimize charger experience.

Change-Id: I261cfc70b7f5f6c19f548035ff2a766cb1683f01
  • Loading branch information
YuHuang65 committed May 28, 2021
1 parent 2cb4675 commit 33a4946
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 34 deletions.
7 changes: 5 additions & 2 deletions arch/arm64/boot/dts/vendor/qcom/instantnoodlep.dtsi
Expand Up @@ -62,9 +62,12 @@

/* fod parameter*/
op,fastchg-fod-enable;
op,fastchg-match-q = /bits/ 8 <0x56>;
op,fastchg-fod-parm = /bits/ 8 <0xac 0x32 0xac 0x28 0xa0 0xba
op,fastchg-match-q-new = /bits/ 8 <0x56>;
op,fastchg-match-q = /bits/ 8 <0x44>;
op,fastchg-fod-parm-new = /bits/ 8 <0xac 0x32 0xac 0x28 0xa0 0xba
0x9a 0xd3 0x9a 0xce 0x9f 0xf6>;
op,fastchg-fod-parm = /bits/ 8 <0xac 0x32 0xac 0x28 0xa0 0x1e
0x9a 0x37 0x9a 0x32 0x9f 0xc4>;
op,fastchg-fod-parm-startup = /bits/ 8 <0xac 0x7f 0xac 0x28 0xa0 0x1e
0x9a 0x37 0x9a 0x32 0x9f 0xc4>;

Expand Down
16 changes: 9 additions & 7 deletions drivers/char/adsprpc.c
Expand Up @@ -3281,13 +3281,15 @@ static int fastrpc_internal_munmap(struct fastrpc_file *fl,
mutex_unlock(&fl->map_mutex);
if (err)
goto bail;
VERIFY(err, !fastrpc_munmap_on_dsp(fl, map->raddr,
map->phys, map->size, map->flags));
if (err)
goto bail;
mutex_lock(&fl->map_mutex);
fastrpc_mmap_free(map, 0);
mutex_unlock(&fl->map_mutex);
if (map) {
VERIFY(err, !fastrpc_munmap_on_dsp(fl, map->raddr,
map->phys, map->size, map->flags));
if (err)
goto bail;
mutex_lock(&fl->map_mutex);
fastrpc_mmap_free(map, 0);
mutex_unlock(&fl->map_mutex);
}
bail:
if (err && map) {
mutex_lock(&fl->map_mutex);
Expand Down
2 changes: 2 additions & 0 deletions drivers/oneplus/include/linux/oem/power/oem_external_fg.h
Expand Up @@ -50,6 +50,8 @@ 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_available_capacity)(void);
int (*get_batt_full_available_capacity_filtered)(void);
int (*get_batt_full_chg_capacity)(void);
int (*get_batt_health)(void);
int (*get_batt_bq_soc)(void);
Expand Down
88 changes: 84 additions & 4 deletions drivers/oneplus/power/supply/qcom/bq27541_fuelgauger.c
Expand Up @@ -886,6 +886,64 @@ static int bq27541_remaining_capacity(struct bq27541_device_info *di)
di->remain_pre = cap;
return cap;
}

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

if (atomic_read(&di->suspended) == 1)
return di->full_available_capacity_pre;
if (di->allow_reading || panel_flag1) {
#ifdef CONFIG_GAUGE_BQ27411
ret = bq27541_read(BQ27411_REG_FAC,
&cap, 0, di);
#else
ret = bq27541_read(BQ27541_REG_RM, &cap, 0, di);
#endif
if (ret) {
pr_err("error reading full_available_capacity.\n");
return ret;
}
if (panel_flag1)
panel_flag1 = 0;
} else {
return di->full_available_capacity_pre;
}

di->full_available_capacity_pre = cap;
return cap;
}


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

if (atomic_read(&di->suspended) == 1)
return di->full_available_capacity_filtered_pre;
if (di->allow_reading || panel_flag1) {
#ifdef CONFIG_GAUGE_BQ27411
ret = bq27541_read(BQ27411_REG_FCCF,
&cap, 0, di);
#else
ret = bq27541_read(BQ27541_REG_RM, &cap, 0, di);
#endif
if (ret) {
pr_err("error reading full_available_capacity_filtered_pre.\n");
return ret;
}
if (panel_flag1)
panel_flag1 = 0;
} else {
return di->full_available_capacity_filtered_pre;
}

di->full_available_capacity_filtered_pre = cap;
return cap;
}

static int bq27541_full_chg_capacity(struct bq27541_device_info *di)
{
int ret;
Expand All @@ -897,8 +955,12 @@ static int bq27541_full_chg_capacity(struct bq27541_device_info *di)

if (di->allow_reading || panel_flag2) {
#ifdef CONFIG_GAUGE_BQ27411
ret = bq27541_read(di->cmd_addr.reg_fcc,
&cap, 0, di);
if (di->batt_bq28z610)
ret = bq27541_read(BQ28Z610_REG_CHARGE_FULL_CAPACITY,
&cap, 0, di);
else
ret = bq27541_read(di->cmd_addr.reg_fcc,
&cap, 0, di);
#else
ret = bq27541_read(BQ27541_REG_FCC, &cap, 0, di);
#endif
Expand All @@ -923,8 +985,12 @@ static int bq27541_batt_health(struct bq27541_device_info *di)
int health = 0;

if (di->allow_reading) {
ret = bq27541_read(di->cmd_addr.reg_helth,
&health, 0, di);
if (di->batt_bq28z610)
ret = bq27541_read(BQ28Z610_REG_BATTERY_HEALTH,
&health, 0, di);
else
ret = bq27541_read(di->cmd_addr.reg_helth,
&health, 0, di);
if (ret) {
pr_err("error reading health\n");
return ret;
Expand All @@ -948,6 +1014,16 @@ static int bq27541_get_batt_remaining_capacity(void)
return bq27541_remaining_capacity(bq27541_di);
}

static int bq27541_get_batt_full_available_capacity(void)
{
return get_batt_full_available_capacity(bq27541_di);
}

static int bq27541_get_batt_full_available_capacity_filtered(void)
{
return get_batt_full_available_capacity_filtered(bq27541_di);
}

static int bq27541_get_batt_full_chg_capacity(void)
{
return bq27541_full_chg_capacity(bq27541_di);
Expand Down Expand Up @@ -1114,6 +1190,10 @@ 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_available_capacity
= bq27541_get_batt_full_available_capacity,
.get_batt_full_available_capacity_filtered
= bq27541_get_batt_full_available_capacity_filtered,
.get_batt_full_chg_capacity
= bq27541_get_batt_full_chg_capacity,
.get_batt_health = bq27541_get_batt_health,
Expand Down
10 changes: 8 additions & 2 deletions drivers/oneplus/power/supply/qcom/bq27541_fuelgauger.h
Expand Up @@ -51,11 +51,13 @@
#ifdef CONFIG_GAUGE_BQ27411
#define BQ27411_REG_TEMP 0x02
#define BQ27411_REG_VOLT 0x04
#define BQ27411_REG_RM 0x0A
#define BQ27411_REG_RM 0x0C
#define BQ27411_REG_FAC 0x0A
#define BQ27411_REG_AI 0x10
#define BQ27411_REG_SOC 0x1c
#define BQ27411_REG_HEALTH 0x20
#define BQ27411_REG_FCC 0x2E
#define BQ27411_REG_FCC 0xE
#define BQ27411_REG_FCCF 0x2E

#define CONTROL_CMD 0x00
#define CONTROL_STATUS 0x00
Expand Down Expand Up @@ -126,6 +128,8 @@
#define BQ28Z610_BALANCING_CONFIG_BIT BIT(28)

#define BQ28Z610_REG_TIME_TO_FULL 0x18
#define BQ28Z610_REG_CHARGE_FULL_CAPACITY 0x12
#define BQ28Z610_REG_BATTERY_HEALTH 0x2e
#endif

/* BQ27541 Control subcommands */
Expand Down Expand Up @@ -229,6 +233,8 @@ struct bq27541_device_info {
int current_pre;
int cap_pre;
int remain_pre;
int full_available_capacity_filtered_pre;
int full_available_capacity_pre;
int health_pre;
unsigned long rtc_resume_time;
unsigned long rtc_suspend_time;
Expand Down
50 changes: 42 additions & 8 deletions drivers/oneplus/power/supply/wlchg/op_wlchg_policy.c
Expand Up @@ -524,13 +524,27 @@ static int wireless_chg_init(struct op_chg_chip *chip)

chg_param->fastchg_fod_enable = of_property_read_bool(node, "op,fastchg-fod-enable");
if (chg_param->fastchg_fod_enable) {
rc = of_property_read_u8(node, "op,fastchg-match-q-new",
&chg_param->fastchg_match_q_new);
if (rc < 0) {
pr_err("op,fastchg-match-q-new reading failed, rc=%d\n", rc);
chg_param->fastchg_match_q_new = 0x56;
}

rc = of_property_read_u8(node, "op,fastchg-match-q",
&chg_param->fastchg_match_q);
if (rc < 0) {
pr_err("op,fastchg-match-q reading failed, rc=%d\n", rc);
chg_param->fastchg_match_q = 0x44;
}

rc = of_property_read_u8_array(node, "op,fastchg-fod-parm-new",
(u8 *)&chg_param->fastchg_fod_parm_new, FOD_PARM_LENGTH);
if (rc < 0) {
chg_param->fastchg_fod_enable = false;
pr_err("Read op,fastchg-fod-parm-new failed, rc=%d\n", rc);
}

rc = of_property_read_u8_array(node, "op,fastchg-fod-parm",
(u8 *)&chg_param->fastchg_fod_parm, FOD_PARM_LENGTH);
if (rc < 0) {
Expand Down Expand Up @@ -797,6 +811,7 @@ static void wlchg_reset_variables(struct op_chg_chip *chip)
chg_status->startup_fod_parm = false;
chg_status->adapter_type = ADAPTER_TYPE_UNKNOWN;
chg_status->charge_type = WPC_CHARGE_TYPE_DEFAULT;
chg_status->adapter_id = 0;
chg_status->send_msg_timer = jiffies;
chg_status->cep_ok_wait_timeout = jiffies;
chg_status->fastchg_retry_timer = jiffies;
Expand Down Expand Up @@ -1612,16 +1627,22 @@ static long wlchg_dev_ioctl(struct file *filp, unsigned int cmd,

switch (cmd) {
case WLCHG_NOTIFY_ADAPTER_TYPE:
chg_status->adapter_type = arg;
chg_status->adapter_type = arg & WPC_ADAPTER_TYPE_MASK;
chg_status->adapter_id = (arg & WPC_ADAPTER_ID_MASK) >> 3;
if (chip->wireless_psy != NULL)
power_supply_changed(chip->wireless_psy);
if (chg_status->adapter_type == ADAPTER_TYPE_FASTCHAGE_PD_65W)
chg_status->adapter_type = ADAPTER_TYPE_FASTCHAGE_WARP;
if (chip->chg_param.fastchg_fod_enable &&
(chg_status->adapter_type == ADAPTER_TYPE_FASTCHAGE_DASH ||
chg_status->adapter_type == ADAPTER_TYPE_FASTCHAGE_WARP))
wlchg_rx_set_match_q_parm(g_rx_chip, chip->chg_param.fastchg_match_q);
chg_info("adapter type is %d\n", chg_status->adapter_type);
chg_status->adapter_type == ADAPTER_TYPE_FASTCHAGE_WARP)) {
if (chg_status->adapter_id == 0x00 || chg_status->adapter_id == 0x01)
wlchg_rx_set_match_q_parm(g_rx_chip, chip->chg_param.fastchg_match_q);
else
wlchg_rx_set_match_q_parm(g_rx_chip, chip->chg_param.fastchg_match_q_new);
}
chg_info("adapter arg is 0x%02x, adapter type is %d, adapter id is %d\n",
arg, chg_status->adapter_type, chg_status->adapter_id);
break;
case WLCHG_NOTIFY_ADAPTER_TYPE_ERR:
chg_status->get_adapter_err = true;
Expand All @@ -1632,7 +1653,11 @@ static long wlchg_dev_ioctl(struct file *filp, unsigned int cmd,
chg_info("charge type is %d\n", arg);
if (chip->chg_param.fastchg_fod_enable &&
chg_status->charge_type == WPC_CHARGE_TYPE_FAST) {
wlchg_rx_set_fod_parm(g_rx_chip, chip->chg_param.fastchg_fod_parm);
if (chg_status->adapter_id == 0x00 || chg_status->adapter_id == 0x01)
wlchg_rx_set_fod_parm(g_rx_chip, chip->chg_param.fastchg_fod_parm);
else
wlchg_rx_set_fod_parm(g_rx_chip, chip->chg_param.fastchg_fod_parm_new);

chg_status->startup_fod_parm = false;
chg_info("write fastchg fod parm\n");
}
Expand Down Expand Up @@ -2959,7 +2984,10 @@ static int fastchg_startup_process(struct op_chg_chip *chip)
bq2597x_check_charge_enabled(exchgpump_bq, &cp2_is_enabled);
if (cp2_is_enabled) {
if (chip->chg_param.fastchg_fod_enable) {
wlchg_rx_set_fod_parm(g_rx_chip, chip->chg_param.fastchg_fod_parm);
if (chg_status->adapter_id == 0x00 || chg_status->adapter_id == 0x01)
wlchg_rx_set_fod_parm(g_rx_chip, chip->chg_param.fastchg_fod_parm);
else
wlchg_rx_set_fod_parm(g_rx_chip, chip->chg_param.fastchg_fod_parm_new);
chg_status->startup_fod_parm = false;
chg_info("write fastchg fod parm\n");
}
Expand Down Expand Up @@ -3140,7 +3168,10 @@ static int wlchg_charge_status_process(struct op_chg_chip *chip)
(chg_status->charge_type == WPC_CHARGE_TYPE_FAST) &&
chg_status->deviation_check_done) {
if (chip->chg_param.fastchg_fod_enable && chg_status->startup_fod_parm) {
wlchg_rx_set_fod_parm(g_rx_chip, chip->chg_param.fastchg_fod_parm);
if (chg_status->adapter_id == 0x00 || chg_status->adapter_id == 0x01)
wlchg_rx_set_fod_parm(g_rx_chip, chip->chg_param.fastchg_fod_parm);
else
wlchg_rx_set_fod_parm(g_rx_chip, chip->chg_param.fastchg_fod_parm_new);
chg_status->startup_fod_parm = false;
chg_info("write fastchg fod parm\n");
}
Expand Down Expand Up @@ -3541,7 +3572,10 @@ static int wlchg_charge_status_process(struct op_chg_chip *chip)
chg_err("<~WPC~> ..........WPC_CHG_STATUS_FAST_CHARGING_EXIT..........\n");
if (chip->chg_param.fastchg_fod_enable && chg_status->startup_fod_parm &&
chg_status->charge_type == WPC_CHARGE_TYPE_FAST) {
wlchg_rx_set_fod_parm(g_rx_chip, chip->chg_param.fastchg_fod_parm);
if (chg_status->adapter_id == 0x00 || chg_status->adapter_id == 0x01)
wlchg_rx_set_fod_parm(g_rx_chip, chip->chg_param.fastchg_fod_parm);
else
wlchg_rx_set_fod_parm(g_rx_chip, chip->chg_param.fastchg_fod_parm_new);
chg_status->startup_fod_parm = false;
chg_info("write fastchg fod parm\n");
}
Expand Down
5 changes: 5 additions & 0 deletions drivers/oneplus/power/supply/wlchg/op_wlchg_policy.h
Expand Up @@ -139,6 +139,8 @@
#define CHARGE_FULL_FAN_THREOD_HI 380

#define FASTCHG_CURR_ERR_MAX 5
#define WPC_ADAPTER_TYPE_MASK 0x07
#define WPC_ADAPTER_ID_MASK 0xF8

enum {
WPC_CHG_STATUS_DEFAULT,
Expand Down Expand Up @@ -239,6 +241,7 @@ struct wpc_data {
bool charge_done;
int adapter_type;
int charge_type;
int adapter_id;
int charge_voltage;
int charge_current;
enum WLCHG_TEMP_REGION_TYPE temp_region;
Expand Down Expand Up @@ -363,7 +366,9 @@ struct charge_param {
int epp_curr_step[EPP_CURR_STEP_MAX];
bool fastchg_fod_enable;
unsigned char fastchg_match_q;
unsigned char fastchg_match_q_new;
unsigned char fastchg_fod_parm[FOD_PARM_LENGTH];
unsigned char fastchg_fod_parm_new[FOD_PARM_LENGTH];
unsigned char fastchg_fod_parm_startup[FOD_PARM_LENGTH];
struct op_fastchg_ffc_step ffc_chg;
};
Expand Down
2 changes: 2 additions & 0 deletions drivers/power/supply/power_supply_sysfs.c
Expand Up @@ -344,6 +344,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(charge_full_design),
POWER_SUPPLY_ATTR(charge_empty_design),
POWER_SUPPLY_ATTR(charge_full),
POWER_SUPPLY_ATTR(full_available_capacity),
POWER_SUPPLY_ATTR(full_charge_capacity_filtered),
POWER_SUPPLY_ATTR(charge_empty),
POWER_SUPPLY_ATTR(charge_now),
POWER_SUPPLY_ATTR(charge_avg),
Expand Down
24 changes: 24 additions & 0 deletions drivers/power/supply/qcom/qpnp-fg-gen4.c
Expand Up @@ -4608,6 +4608,28 @@ static int fg_psy_get_property(struct power_supply *psy,
pval->intval = (int)temp;
}
break;
case POWER_SUPPLY_PROP_FULL_AVAILABLE_CAPACITY:
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_available_capacity)
pval->intval = external_fg->get_batt_full_available_capacity();
else {
rc = fg_gen4_get_learned_capacity(chip, &temp);
if (!rc)
pval->intval = (int)temp;
}
break;
case POWER_SUPPLY_PROP_CHARGE_FULL_CHARGE_CAPACITY_FILTERED:
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_available_capacity_filtered)
pval->intval = external_fg->get_batt_full_available_capacity_filtered();
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;
Expand Down Expand Up @@ -4918,6 +4940,8 @@ static enum power_supply_property fg_psy_props[] = {
POWER_SUPPLY_PROP_CHARGE_NOW_RAW,
POWER_SUPPLY_PROP_CHARGE_NOW,
POWER_SUPPLY_PROP_CHARGE_FULL,
POWER_SUPPLY_PROP_FULL_AVAILABLE_CAPACITY,
POWER_SUPPLY_PROP_CHARGE_FULL_CHARGE_CAPACITY_FILTERED,
POWER_SUPPLY_PROP_CHARGE_COUNTER,
POWER_SUPPLY_PROP_CHARGE_COUNTER_SHADOW,
POWER_SUPPLY_PROP_CYCLE_COUNTS,
Expand Down

0 comments on commit 33a4946

Please sign in to comment.