mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-09 05:39:54 -04:00
charging: optimize sgm41542 charging type detected
As in some case charging type detected error, so optimize sgm41542 charging type detected. Change-Id: Iad9608794ff0cf9116295037f6bacdfc1bdd619a Signed-off-by: mahj8 <mahj8@motorola.com> Reviewed-on: https://gerrit.mot.com/2154824 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Huosheng Liao <liaohs@motorola.com> Submit-Approved: Jira Key
This commit is contained in:
parent
a4e8e09997
commit
ffbae57032
3 changed files with 97 additions and 101 deletions
|
|
@ -2303,6 +2303,10 @@ static void bq2589x_charger_irq_workfunc(struct work_struct *work)
|
|||
int ret;
|
||||
bool reapsd_complete = false;
|
||||
|
||||
if (!bq->dpdm_enabled) {
|
||||
bq2589x_reuqest_dpdm(bq, true);
|
||||
}
|
||||
|
||||
ret = bq2589x_sync_state(bq, &state);
|
||||
if (ret < 0)
|
||||
return;
|
||||
|
|
@ -2321,11 +2325,6 @@ static void bq2589x_charger_irq_workfunc(struct work_struct *work)
|
|||
|
||||
bq->vbus_type = (status & BQ2589X_VBUS_STAT_MASK) >> BQ2589X_VBUS_STAT_SHIFT;
|
||||
|
||||
if (state.vbus_gd && (!bq->dpdm_enabled)) {
|
||||
dev_info(bq->dev, "BC1.2 detect is not done.\n");
|
||||
bq2589x_reuqest_dpdm(bq, true);
|
||||
}
|
||||
|
||||
if(state.vbus_gd && state.online
|
||||
&& (bq->typec_apsd_rerun_done == true)
|
||||
&& (bq->vbus_type != BQ2589X_VBUS_NONE)) {
|
||||
|
|
|
|||
|
|
@ -1093,17 +1093,10 @@ static int sgm4154x_charger_get_property(struct power_supply *psy,
|
|||
union power_supply_propval *val)
|
||||
{
|
||||
struct sgm4154x_device *sgm = power_supply_get_drvdata(psy);
|
||||
struct sgm4154x_state state;
|
||||
struct sgm4154x_state state = sgm->state;
|
||||
int chrg_status = 0;
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&sgm->lock);
|
||||
//ret = sgm4154x_get_state(sgm, &state);
|
||||
state = sgm->state;
|
||||
mutex_unlock(&sgm->lock);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
switch (psp) {
|
||||
case POWER_SUPPLY_PROP_STATUS:
|
||||
chrg_status = sgm4154x_get_charging_status(sgm);
|
||||
|
|
@ -1349,7 +1342,7 @@ static void sgm4154x_rerun_apsd_work_func(struct work_struct *work)
|
|||
if (rc < 0)
|
||||
dev_err(sgm->dev, "Couldn't to enable DPDM rc=%d\n", rc);
|
||||
|
||||
sgm->typec_apsd_rerun_status = MMI_APSD_RERUN_START;
|
||||
sgm->typec_apsd_rerun_done = true;
|
||||
sgm4154x_rerun_apsd(sgm);
|
||||
|
||||
while(check_count < 10) {
|
||||
|
|
@ -1362,10 +1355,10 @@ static void sgm4154x_rerun_apsd_work_func(struct work_struct *work)
|
|||
check_count ++;
|
||||
}
|
||||
|
||||
sgm->typec_apsd_rerun_status = MMI_APSD_RERUN_DONE;
|
||||
schedule_work(&sgm->charge_detect_work);
|
||||
}
|
||||
|
||||
/* for build
|
||||
static bool sgm4154x_dpdm_detect_is_done(struct sgm4154x_device * sgm)
|
||||
{
|
||||
int chrg_stat;
|
||||
|
|
@ -1378,7 +1371,7 @@ static bool sgm4154x_dpdm_detect_is_done(struct sgm4154x_device * sgm)
|
|||
|
||||
return (chrg_stat&SGM4154x_DPDM_ONGOING)?true:false;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
static void charger_monitor_work_func(struct work_struct *work)
|
||||
{
|
||||
|
|
@ -1415,22 +1408,6 @@ OUT:
|
|||
schedule_delayed_work(&sgm->charge_monitor_work, 10*HZ);
|
||||
}
|
||||
|
||||
static void sgm4154x_vbus_remove(struct sgm4154x_device * sgm)
|
||||
{
|
||||
dev_err(sgm->dev, "Vbus removed, disable charge\n");
|
||||
|
||||
#ifdef CONFIG_MMI_QC3P_TURBO_CHARGER
|
||||
sgm4154x_enable_termination(sgm->chg_dev, true);
|
||||
g_qc3p_detected = false;
|
||||
qc3p_update_policy(sgm);
|
||||
#endif
|
||||
sgm->pulse_cnt = 0;
|
||||
sgm->typec_apsd_rerun_status = MMI_APSD_RERUN_NO_START;
|
||||
sgm->chg_dev->noti.apsd_done = false;
|
||||
sgm->chg_dev->noti.hvdcp_done = false;
|
||||
sgm->real_charger_type = POWER_SUPPLY_TYPE_UNKNOWN;
|
||||
sgm4154x_request_dpdm(sgm, false);
|
||||
}
|
||||
#ifndef CONFIG_MMI_QC3P_TURBO_CHARGER
|
||||
static int sgm4154x_detected_qc30_hvdcp(struct sgm4154x_device *sgm, int *charger_type)
|
||||
{
|
||||
|
|
@ -1699,68 +1676,37 @@ static void mmi_start_hvdcp_detect(struct sgm4154x_device *sgm)
|
|||
}
|
||||
}
|
||||
|
||||
static void charger_detect_work_func(struct work_struct *work)
|
||||
static void sgm4154x_vbus_remove(struct sgm4154x_device * sgm)
|
||||
{
|
||||
struct sgm4154x_device * sgm = NULL;
|
||||
struct sgm4154x_state state;
|
||||
int ret;
|
||||
dev_err(sgm->dev, "Vbus removed, disable charge\n");
|
||||
|
||||
sgm = container_of(work, struct sgm4154x_device, charge_detect_work);
|
||||
if(sgm == NULL) {
|
||||
pr_err("Cann't get sgm4154x_device\n");
|
||||
goto err;
|
||||
}
|
||||
#ifdef CONFIG_MMI_QC3P_TURBO_CHARGER
|
||||
sgm4154x_enable_termination(sgm->chg_dev, true);
|
||||
g_qc3p_detected = false;
|
||||
qc3p_update_policy(sgm);
|
||||
#endif
|
||||
sgm->pulse_cnt = 0;
|
||||
sgm->typec_apsd_rerun_done = false;
|
||||
sgm->chg_dev->noti.apsd_done = false;
|
||||
sgm->chg_dev->noti.hvdcp_done = false;
|
||||
sgm->real_charger_type = POWER_SUPPLY_TYPE_UNKNOWN;
|
||||
sgm4154x_request_dpdm(sgm, false);
|
||||
charger_dev_notify(sgm->chg_dev);
|
||||
}
|
||||
|
||||
if (!sgm->charger_wakelock->active)
|
||||
__pm_stay_awake(sgm->charger_wakelock);
|
||||
|
||||
ret = sgm4154x_get_state(sgm, &state);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
mutex_lock(&sgm->lock);
|
||||
sgm->state = state;
|
||||
mutex_unlock(&sgm->lock);
|
||||
|
||||
if(!sgm->state.vbus_gd) {
|
||||
sgm4154x_vbus_remove(sgm);
|
||||
goto vbus_remove;
|
||||
}
|
||||
|
||||
if (sgm->real_charger_type != POWER_SUPPLY_TYPE_UNKNOWN) {
|
||||
dev_err(sgm->dev, "BC1.2 have already detected\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!state.online)
|
||||
{
|
||||
sgm4154x_request_dpdm(sgm, true);
|
||||
dev_err(sgm->dev, "BC1.2 detecte not done\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if(!sgm4154x_dpdm_detect_is_done(sgm)) {
|
||||
dev_err(sgm->dev, "DPDM detecte not done, disable charge\n");
|
||||
goto err;
|
||||
}
|
||||
static void sgm4154x_vbus_plugin(struct sgm4154x_device * sgm)
|
||||
{
|
||||
|
||||
#if defined(__SGM41542_CHIP_ID__)|| defined(__SGM41516D_CHIP_ID__)
|
||||
if (((sgm->state.chrg_type == SGM4154x_USB_SDP) ||
|
||||
(sgm->state.chrg_type == SGM4154x_NON_STANDARD) ||
|
||||
(sgm->state.chrg_type == SGM4154x_UNKNOWN))) {
|
||||
|
||||
if (sgm->typec_apsd_rerun_status == MMI_APSD_RERUN_NO_START) {
|
||||
down(&sgm->sem_dpdm);
|
||||
dev_err(sgm->dev, "rerun apsd for 0x%x\n", sgm->state.chrg_type);
|
||||
sgm->typec_apsd_rerun_status = MMI_APSD_RERUN_START;
|
||||
schedule_work(&sgm->rerun_apsd_work);
|
||||
up(&sgm->sem_dpdm);
|
||||
goto err;
|
||||
} else if (sgm->typec_apsd_rerun_status != MMI_APSD_RERUN_DONE) {
|
||||
dev_info(sgm->dev, "wait for rerun apsd done\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
(sgm->state.chrg_type == SGM4154x_UNKNOWN))
|
||||
&& (!sgm->typec_apsd_rerun_done)) {
|
||||
down(&sgm->sem_dpdm);
|
||||
dev_err(sgm->dev, "rerun apsd for 0x%x\n", sgm->state.chrg_type);
|
||||
schedule_work(&sgm->rerun_apsd_work);
|
||||
up(&sgm->sem_dpdm);
|
||||
return;
|
||||
}
|
||||
|
||||
switch(sgm->state.chrg_type) {
|
||||
|
|
@ -1791,7 +1737,7 @@ static void charger_detect_work_func(struct work_struct *work)
|
|||
|
||||
case SGM4154x_OTG_MODE:
|
||||
pr_err("SGM4154x OTG mode do nothing\n");
|
||||
goto err;
|
||||
return;
|
||||
|
||||
default:
|
||||
pr_err("SGM4154x charger type: default\n");
|
||||
|
|
@ -1800,14 +1746,62 @@ static void charger_detect_work_func(struct work_struct *work)
|
|||
|
||||
#endif
|
||||
|
||||
sgm4154x_dump_register(sgm);
|
||||
//notify charging policy to update charger type
|
||||
sgm->chg_dev->noti.apsd_done = true;
|
||||
sgm->typec_apsd_rerun_done = false;
|
||||
charger_dev_notify(sgm->chg_dev);
|
||||
return;
|
||||
}
|
||||
|
||||
vbus_remove:
|
||||
charger_dev_notify(sgm->chg_dev);
|
||||
static void charger_detect_work_func(struct work_struct *work)
|
||||
{
|
||||
struct sgm4154x_device * sgm = NULL;
|
||||
struct sgm4154x_state state;
|
||||
bool reapsd_complete = false;
|
||||
int ret;
|
||||
|
||||
sgm = container_of(work, struct sgm4154x_device, charge_detect_work);
|
||||
if(sgm == NULL) {
|
||||
pr_err("Cann't get sgm4154x_device\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!sgm->charger_wakelock->active)
|
||||
__pm_stay_awake(sgm->charger_wakelock);
|
||||
|
||||
if (!sgm->dpdm_enabled) {
|
||||
sgm4154x_request_dpdm(sgm, true);
|
||||
}
|
||||
|
||||
ret = sgm4154x_get_state(sgm, &state);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
mutex_lock(&sgm->lock);
|
||||
sgm->state = state;
|
||||
mutex_unlock(&sgm->lock);
|
||||
|
||||
if(sgm->state.vbus_gd && sgm->state.online
|
||||
&& (sgm->typec_apsd_rerun_done == true)
|
||||
&& (sgm->state.chrg_type != SGM4154x_USB_NONE)
|
||||
&& (sgm->state.chrg_type != SGM4154x_OTG_MODE)) {
|
||||
reapsd_complete = sgm4154x_is_rerun_apsd_done(sgm);
|
||||
}
|
||||
|
||||
if (((!sgm->state.vbus_gd) || (sgm->state.chrg_type == SGM4154x_OTG_MODE))
|
||||
&& (sgm->status & SGM4154X_STATUS_PLUGIN)) {
|
||||
|
||||
dev_info(sgm->dev, "%s:adapter removed\n", __func__);
|
||||
sgm->status &= ~SGM4154X_STATUS_PLUGIN;
|
||||
sgm4154x_vbus_remove(sgm);
|
||||
} else if ((sgm->state.chrg_type != SGM4154x_USB_NONE)
|
||||
&& (sgm->state.chrg_type != SGM4154x_OTG_MODE)
|
||||
&& (!(sgm->status & SGM4154X_STATUS_PLUGIN) || (reapsd_complete == true))
|
||||
&& sgm->state.online) {
|
||||
|
||||
dev_info(sgm->dev, "%s:adapter plugged in\n", __func__);
|
||||
sgm->status |= SGM4154X_STATUS_PLUGIN;
|
||||
sgm4154x_vbus_plugin(sgm);
|
||||
}
|
||||
|
||||
err:
|
||||
//release wakelock
|
||||
|
|
@ -2300,7 +2294,7 @@ static int sgm4154x_suspend_notifier(struct notifier_block *nb,
|
|||
case PM_POST_SUSPEND:
|
||||
pr_err("sgm4154x PM_RESUME \n");
|
||||
|
||||
schedule_delayed_work(&sgm->charge_monitor_work, 0);
|
||||
schedule_delayed_work(&sgm->charge_monitor_work, msecs_to_jiffies(500));
|
||||
|
||||
sgm->sgm4154x_suspend_flag = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@
|
|||
#include <linux/iio/consumer.h>
|
||||
|
||||
#define SGM4154x_MANUFACTURER "Texas Instruments"
|
||||
#define SGM4154X_STATUS_PLUGIN 0x0001
|
||||
#define SGM4154X_STATUS_PG 0x0002
|
||||
#define SGM4154X_STATUS_CHARGE_ENABLE 0x0004
|
||||
#define SGM4154X_STATUS_FAULT 0x0008
|
||||
#define SGM4154X_STATUS_EXIST 0x0100
|
||||
|
||||
//#define __SGM41541_CHIP_ID__
|
||||
#define __SGM41542_CHIP_ID__
|
||||
|
|
@ -110,10 +115,11 @@
|
|||
#define SGM4154x_PRECHRG BIT(3)
|
||||
#define SGM4154x_FAST_CHRG BIT(4)
|
||||
#define SGM4154x_TERM_CHRG (BIT(3)| BIT(4))
|
||||
#define SGM4154x_NOT_CHRGING 0
|
||||
|
||||
/* charge type */
|
||||
#define SGM4154x_VBUS_STAT_MASK GENMASK(7, 5)
|
||||
#define SGM4154x_NOT_CHRGING 0
|
||||
#define SGM4154x_USB_NONE 0
|
||||
#define SGM4154x_USB_SDP BIT(5)
|
||||
#define SGM4154x_USB_CDP BIT(6)
|
||||
#define SGM4154x_USB_DCP (BIT(5) | BIT(6))
|
||||
|
|
@ -227,12 +233,6 @@ enum {
|
|||
MMI_POWER_SUPPLY_DP_DM_DM_PULSE = 2,
|
||||
};
|
||||
|
||||
enum {
|
||||
MMI_APSD_RERUN_NO_START = 0,
|
||||
MMI_APSD_RERUN_START = 1,
|
||||
MMI_APSD_RERUN_DONE = 2,
|
||||
};
|
||||
|
||||
struct sgm4154x_iio {
|
||||
struct iio_channel *usbin_v_chan;
|
||||
};
|
||||
|
|
@ -311,6 +311,9 @@ struct sgm4154x_device {
|
|||
|
||||
struct sgm4154x_init_data init_data;
|
||||
struct sgm4154x_state state;
|
||||
|
||||
unsigned int status;
|
||||
|
||||
u32 watchdog_timer;
|
||||
const char *chg_dev_name;
|
||||
struct charger_device *chg_dev;
|
||||
|
|
@ -329,7 +332,7 @@ struct sgm4154x_device {
|
|||
struct regulator *otg_vbus_reg;
|
||||
struct mutex regulator_lock;
|
||||
bool dpdm_enabled;
|
||||
int typec_apsd_rerun_status;
|
||||
int typec_apsd_rerun_done;
|
||||
int real_charger_type;
|
||||
|
||||
struct work_struct rerun_apsd_work;
|
||||
|
|
|
|||
Loading…
Reference in a new issue