power_supply: use power_supply_set_property in lieu of internal apis

API's like
power_supply_set_supply_type
power_supply_set_online,
power_supply_set_present
power_supply_set_current_limit
power_supply_set_health_state
power_supply_set_supply_type
power_supply_set_dp_dm
can be replaced by using
power_supply_set_property introduced in the 4.4 kernel.

Update all such callsites to use power_supply_set_property.

Change-Id: I10df60c8012358b6773a8bd1802a26d9540ade9b
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>

Conflicts:
	drivers/power/qpnp-smbcharger.c
This commit is contained in:
Abhijeet Dharmapurikar 2016-01-22 15:34:11 -08:00 committed by Rohit Vaswani
parent 3cb222ef93
commit 2a65148ba7
4 changed files with 251 additions and 113 deletions

View file

@ -32,16 +32,20 @@ static irqreturn_t gpio_usbdetect_vbus_irq(int irq, void *data)
{
struct gpio_usbdetect *usb = data;
int vbus;
union power_supply_propval pval = {0,};
vbus = !!irq_read_line(irq);
if (vbus)
power_supply_set_supply_type(usb->usb_psy,
POWER_SUPPLY_TYPE_USB);
pval.intval = POWER_SUPPLY_TYPE_USB;
else
power_supply_set_supply_type(usb->usb_psy,
POWER_SUPPLY_TYPE_UNKNOWN);
pval.intval = POWER_SUPPLY_TYPE_UNKNOWN;
power_supply_set_present(usb->usb_psy, vbus);
power_supply_set_property(usb->usb_psy,
POWER_SUPPLY_PROP_TYPE, &pval);
pval.intval = vbus;
power_supply_set_property(usb->usb_psy, POWER_SUPPLY_PROP_PRESENT,
&pval);
return IRQ_HANDLED;
}

View file

@ -1480,6 +1480,7 @@ static void smbchg_usb_update_online_work(struct work_struct *work)
usb_set_online_work);
bool user_enabled = !get_client_vote(chip->usb_suspend_votable,
USER_EN_VOTER);
union power_supply_propval ret;
int online;
online = user_enabled && chip->usb_present && !chip->very_weak_charger;
@ -1487,7 +1488,9 @@ static void smbchg_usb_update_online_work(struct work_struct *work)
mutex_lock(&chip->usb_set_online_lock);
if (chip->usb_online != online) {
pr_smb(PR_MISC, "setting usb psy online = %d\n", online);
power_supply_set_online(chip->usb_psy, online);
ret.intval = online;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_ONLINE, &ret);
chip->usb_online = online;
}
mutex_unlock(&chip->usb_set_online_lock);
@ -1928,6 +1931,7 @@ static int smbchg_get_aicl_level_ma(struct smbchg_chip *chip)
static void smbchg_parallel_usb_disable(struct smbchg_chip *chip)
{
struct power_supply *parallel_psy = get_parallel_psy(chip);
union power_supply_propval pval = {0, };
if (!parallel_psy || !chip->parallel_charger_detected)
return;
@ -1936,9 +1940,13 @@ static void smbchg_parallel_usb_disable(struct smbchg_chip *chip)
taper_irq_en(chip, false);
chip->parallel.initial_aicl_ma = 0;
chip->parallel.current_max_ma = 0;
power_supply_set_current_limit(parallel_psy,
SUSPEND_CURRENT_MA * 1000);
power_supply_set_present(parallel_psy, false);
pval.intval = SUSPEND_CURRENT_MA * 1000;
power_supply_set_property(parallel_psy, POWER_SUPPLY_PROP_CURRENT_MAX,
&pval);
pval.intval = false;
power_supply_set_property(parallel_psy, POWER_SUPPLY_PROP_PRESENT,
&pval);
smbchg_set_fastchg_current_raw(chip,
get_effective_result_locked(chip->fcc_votable));
smbchg_set_usb_current_max(chip,
@ -2025,8 +2033,9 @@ static void smbchg_parallel_usb_enable(struct smbchg_chip *chip,
return;
pr_smb(PR_STATUS, "Attempting to enable parallel charger\n");
rc = power_supply_set_voltage_limit(parallel_psy, chip->vfloat_mv + 50);
pval.intval = chip->vfloat_mv + 50;
rc = power_supply_set_property(parallel_psy,
POWER_SUPPLY_PROP_VOLTAGE_MAX, &pval);
if (rc < 0) {
dev_err(chip->dev,
"Couldn't set Vflt on parallel psy rc: %d\n", rc);
@ -2037,9 +2046,15 @@ static void smbchg_parallel_usb_enable(struct smbchg_chip *chip,
new_parallel_cl_ma = total_current_ma
* (100 - smbchg_main_chg_icl_percent) / 100;
taper_irq_en(chip, true);
power_supply_set_present(parallel_psy, true);
power_supply_set_current_limit(parallel_psy,
new_parallel_cl_ma * 1000);
pval.intval = true;
power_supply_set_property(parallel_psy, POWER_SUPPLY_PROP_PRESENT,
&pval);
pval.intval = new_parallel_cl_ma * 1000;
power_supply_set_property(parallel_psy, POWER_SUPPLY_PROP_CURRENT_MAX,
&pval);
/* read back the real amount of current we are getting */
power_supply_get_property(parallel_psy,
POWER_SUPPLY_PROP_CURRENT_MAX, &pval);
@ -2936,6 +2951,7 @@ static int smbchg_float_voltage_comp_set(struct smbchg_chip *chip, int code)
static int smbchg_float_voltage_set(struct smbchg_chip *chip, int vfloat_mv)
{
struct power_supply *parallel_psy = get_parallel_psy(chip);
union power_supply_propval prop;
int rc, delta;
u8 temp;
@ -2966,8 +2982,9 @@ static int smbchg_float_voltage_set(struct smbchg_chip *chip, int vfloat_mv)
}
if (parallel_psy) {
rc = power_supply_set_voltage_limit(parallel_psy,
vfloat_mv + 50);
prop.intval = vfloat_mv + 50;
rc = power_supply_set_property(parallel_psy,
POWER_SUPPLY_PROP_VOLTAGE_MAX, &prop);
if (rc)
dev_err(chip->dev, "Couldn't set float voltage on parallel psy rc: %d\n",
rc);
@ -3873,17 +3890,15 @@ static void smbchg_chg_led_brightness_set(struct led_classdev *cdev,
{
struct smbchg_chip *chip = container_of(cdev,
struct smbchg_chip, led_cdev);
union power_supply_propval pval = {0, };
u8 reg;
int rc;
reg = (value > LED_OFF) ? CHG_LED_ON << CHG_LED_SHIFT :
CHG_LED_OFF << CHG_LED_SHIFT;
if (value > LED_OFF)
power_supply_set_hi_power_state(chip->bms_psy, 1);
else
power_supply_set_hi_power_state(chip->bms_psy, 0);
pval.intval = value > LED_OFF ? 1 : 0;
power_supply_set_property(chip->bms_psy, POWER_SUPPLY_PROP_HI_POWER,
&pval);
pr_smb(PR_STATUS,
"set the charger led brightness to value=%d\n",
value);
@ -3922,14 +3937,17 @@ led_brightness smbchg_chg_led_brightness_get(struct led_classdev *cdev)
static void smbchg_chg_led_blink_set(struct smbchg_chip *chip,
unsigned long blinking)
{
union power_supply_propval pval = {0, };
u8 reg;
int rc;
pval.intval = (blinking == 0) ? 0 : 1;
power_supply_set_property(chip->bms_psy, POWER_SUPPLY_PROP_HI_POWER,
&pval);
if (blinking == 0) {
reg = CHG_LED_OFF << CHG_LED_SHIFT;
power_supply_set_hi_power_state(chip->bms_psy, 0);
} else {
power_supply_set_hi_power_state(chip->bms_psy, 1);
if (blinking == 1)
reg = LED_BLINKING_PATTERN1 << CHG_LED_SHIFT;
else if (blinking == 2)
@ -4289,6 +4307,7 @@ static int smbchg_change_usb_supply_type(struct smbchg_chip *chip,
enum power_supply_type type)
{
int rc, current_limit_ma;
union power_supply_propval pval = {0, };
/*
* if the type is not unknown, set the type before changing ICL vote
@ -4327,8 +4346,11 @@ static int smbchg_change_usb_supply_type(struct smbchg_chip *chip,
goto out;
}
if (!chip->skip_usb_notification)
power_supply_set_supply_type(chip->usb_psy, type);
if (!chip->skip_usb_notification) {
pval.intval = type;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_TYPE, &pval);
}
/* otherwise if it is unknown, set type after the vote */
if (type == POWER_SUPPLY_TYPE_UNKNOWN)
@ -4415,6 +4437,7 @@ static int set_usb_psy_dp_dm(struct smbchg_chip *chip, int state)
{
int rc;
u8 reg;
union power_supply_propval pval = {0, };
/*
* ensure that we are not in the middle of an insertion where usbin_uv
@ -4428,7 +4451,9 @@ static int set_usb_psy_dp_dm(struct smbchg_chip *chip, int state)
state = POWER_SUPPLY_DP_DM_DPF_DMF;
}
pr_smb(PR_MISC, "setting usb psy dp dm = %d\n", state);
return power_supply_set_dp_dm(chip->usb_psy, state);
pval.intval = state;
return power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_DP_DM, &pval);
}
#define APSD_CFG 0xF5
@ -4507,6 +4532,7 @@ static int smbchg_restricted_charging(struct smbchg_chip *chip, bool enable)
static void handle_usb_removal(struct smbchg_chip *chip)
{
struct power_supply *parallel_psy = get_parallel_psy(chip);
union power_supply_propval pval = {0, };
int rc;
pr_smb(PR_STATUS, "triggered\n");
@ -4521,20 +4547,27 @@ static void handle_usb_removal(struct smbchg_chip *chip)
if (!chip->skip_usb_notification) {
pr_smb(PR_MISC, "setting usb psy present = %d\n",
chip->usb_present);
power_supply_set_present(chip->usb_psy, chip->usb_present);
pval.intval = chip->usb_present;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_PRESENT, &pval);
}
set_usb_psy_dp_dm(chip, POWER_SUPPLY_DP_DM_DPR_DMR);
schedule_work(&chip->usb_set_online_work);
pr_smb(PR_MISC, "setting usb psy health UNKNOWN\n");
rc = power_supply_set_health_state(chip->usb_psy,
POWER_SUPPLY_HEALTH_UNKNOWN);
pval.intval = POWER_SUPPLY_HEALTH_UNKNOWN;
rc = power_supply_set_property(chip->usb_psy, POWER_SUPPLY_PROP_HEALTH,
&pval);
if (rc < 0)
pr_smb(PR_STATUS,
"usb psy does not allow updating prop %d rc = %d\n",
POWER_SUPPLY_HEALTH_UNKNOWN, rc);
if (parallel_psy && chip->parallel_charger_detected)
power_supply_set_present(parallel_psy, false);
if (parallel_psy && chip->parallel_charger_detected) {
pval.intval = false;
power_supply_set_property(parallel_psy,
POWER_SUPPLY_PROP_PRESENT, &pval);
}
if (chip->parallel.avail && chip->aicl_done_irq
&& chip->enable_aicl_wake) {
disable_irq_wake(chip->aicl_done_irq);
@ -4586,6 +4619,7 @@ static bool is_usbin_uv_high(struct smbchg_chip *chip)
static void handle_usb_insertion(struct smbchg_chip *chip)
{
struct power_supply *parallel_psy = get_parallel_psy(chip);
union power_supply_propval pval = {0, };
enum power_supply_type usb_supply_type;
int rc;
char *usb_type_name = "null";
@ -4603,7 +4637,9 @@ static void handle_usb_insertion(struct smbchg_chip *chip)
if (!chip->skip_usb_notification) {
pr_smb(PR_MISC, "setting usb psy present = %d\n",
chip->usb_present);
power_supply_set_present(chip->usb_psy, chip->usb_present);
pval.intval = chip->usb_present;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_PRESENT, &pval);
}
/* Notify the USB psy if OV condition is not present */
@ -4616,10 +4652,12 @@ static void handle_usb_insertion(struct smbchg_chip *chip)
pr_smb(PR_MISC, "setting usb psy health %s\n",
chip->very_weak_charger
? "UNSPEC_FAILURE" : "GOOD");
rc = power_supply_set_health_state(chip->usb_psy,
chip->very_weak_charger
pval.intval = chip->very_weak_charger
? POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
: POWER_SUPPLY_HEALTH_GOOD);
: POWER_SUPPLY_HEALTH_GOOD;
rc = power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_HEALTH,
&pval);
if (rc < 0)
pr_smb(PR_STATUS,
"usb psy does not allow updating prop %d rc = %d\n",
@ -4635,7 +4673,9 @@ static void handle_usb_insertion(struct smbchg_chip *chip)
}
if (parallel_psy) {
rc = power_supply_set_present(parallel_psy, true);
pval.intval = true;
power_supply_set_property(parallel_psy,
POWER_SUPPLY_PROP_PRESENT, &pval);
chip->parallel_charger_detected = rc ? false : true;
if (rc)
pr_debug("parallel-charger absent rc=%d\n", rc);
@ -4745,6 +4785,7 @@ static void increment_aicl_count(struct smbchg_chip *chip)
u8 reg;
long elapsed_seconds;
unsigned long now_seconds;
union power_supply_propval pval = {0, };
pr_smb(PR_INTERRUPT, "aicl count c:%d dgltch:%d first:%ld\n",
chip->aicl_irq_count, chip->aicl_deglitch_short,
@ -4826,8 +4867,10 @@ static void increment_aicl_count(struct smbchg_chip *chip)
if (bad_charger) {
pr_smb(PR_MISC,
"setting usb psy health UNSPEC_FAILURE\n");
rc = power_supply_set_health_state(chip->usb_psy,
POWER_SUPPLY_HEALTH_UNSPEC_FAILURE);
pval.intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
rc = power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_HEALTH,
&pval);
if (rc)
pr_err("Couldn't set health on usb psy rc:%d\n",
rc);
@ -5499,17 +5542,22 @@ static void update_typec_capability_status(struct smbchg_chip *chip,
static void update_typec_otg_status(struct smbchg_chip *chip, int mode,
bool force)
{
union power_supply_propval pval = {0, };
pr_smb(PR_TYPEC, "typec mode = %d\n", mode);
if (mode == POWER_SUPPLY_TYPE_DFP) {
chip->typec_dfp = true;
power_supply_set_usb_otg(chip->usb_psy, chip->typec_dfp);
pval.intval = 1;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_USB_OTG, &pval);
/* update FG */
set_property_on_fg(chip, POWER_SUPPLY_PROP_STATUS,
get_prop_batt_status(chip));
} else if (force || chip->typec_dfp) {
chip->typec_dfp = false;
power_supply_set_usb_otg(chip->usb_psy, chip->typec_dfp);
pval.intval = 0;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_USB_OTG, &pval);
/* update FG */
set_property_on_fg(chip, POWER_SUPPLY_PROP_STATUS,
get_prop_batt_status(chip));
@ -6117,6 +6165,7 @@ static irqreturn_t usbin_ov_handler(int irq, void *_chip)
int rc;
u8 reg;
bool usb_present;
union power_supply_propval pval = {0, };
rc = smbchg_read(chip, &reg, chip->usb_chgpth_base + RT_STS, 1);
if (rc < 0) {
@ -6129,8 +6178,10 @@ static irqreturn_t usbin_ov_handler(int irq, void *_chip)
chip->usb_ov_det = true;
if (chip->usb_psy) {
pr_smb(PR_MISC, "setting usb psy health OV\n");
rc = power_supply_set_health_state(chip->usb_psy,
POWER_SUPPLY_HEALTH_OVERVOLTAGE);
pval.intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
rc = power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_HEALTH,
&pval);
if (rc)
pr_smb(PR_STATUS,
"usb psy does not allow updating prop %d rc = %d\n",
@ -6158,6 +6209,7 @@ static irqreturn_t usbin_uv_handler(int irq, void *_chip)
{
struct smbchg_chip *chip = _chip;
int aicl_level = smbchg_get_aicl_level_ma(chip);
union power_supply_propval pval = {0, };
int rc;
u8 reg;
@ -6179,8 +6231,9 @@ static irqreturn_t usbin_uv_handler(int irq, void *_chip)
*/
if (!(reg & USBIN_UV_BIT) && !(reg & USBIN_SRC_DET_BIT)) {
pr_smb(PR_MISC, "setting usb psy dp=f dm=f\n");
power_supply_set_dp_dm(chip->usb_psy,
POWER_SUPPLY_DP_DM_DPF_DMF);
pval.intval = POWER_SUPPLY_DP_DM_DPF_DMF;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_DP_DM, &pval);
}
if (reg & USBIN_UV_BIT)
@ -6224,8 +6277,9 @@ static irqreturn_t usbin_uv_handler(int irq, void *_chip)
rc);
}
pr_smb(PR_MISC, "setting usb psy health UNSPEC_FAILURE\n");
rc = power_supply_set_health_state(chip->usb_psy,
POWER_SUPPLY_HEALTH_UNSPEC_FAILURE);
pval.intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
rc = power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_HEALTH, &pval);
if (rc)
pr_err("Couldn't set health on usb psy rc:%d\n", rc);
schedule_work(&chip->usb_set_online_work);
@ -6381,6 +6435,7 @@ static irqreturn_t usbid_change_handler(int irq, void *_chip)
{
struct smbchg_chip *chip = _chip;
bool otg_present;
union power_supply_propval pval = {0, };
pr_smb(PR_INTERRUPT, "triggered\n");
@ -6388,7 +6443,9 @@ static irqreturn_t usbid_change_handler(int irq, void *_chip)
if (chip->usb_psy) {
pr_smb(PR_MISC, "setting usb psy OTG = %d\n",
otg_present ? 1 : 0);
power_supply_set_usb_otg(chip->usb_psy, otg_present ? 1 : 0);
pval.intval = otg_present ? 1 : 0;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_USB_OTG, &pval);
}
if (otg_present)
pr_smb(PR_STATUS, "OTG detected\n");
@ -6403,6 +6460,7 @@ static irqreturn_t usbid_change_handler(int irq, void *_chip)
static int determine_initial_status(struct smbchg_chip *chip)
{
union power_supply_propval type = {0, };
union power_supply_propval pval = {0, };
/*
* It is okay to read the interrupt status here since
@ -6429,8 +6487,9 @@ static int determine_initial_status(struct smbchg_chip *chip)
if (chip->usb_present) {
pr_smb(PR_MISC, "setting usb psy dp=f dm=f\n");
power_supply_set_dp_dm(chip->usb_psy,
POWER_SUPPLY_DP_DM_DPF_DMF);
pval.intval = POWER_SUPPLY_DP_DM_DPF_DMF;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_DP_DM, &pval);
handle_usb_insertion(chip);
} else {
handle_usb_removal(chip);
@ -7806,6 +7865,7 @@ static int smbchg_probe(struct platform_device *pdev)
struct power_supply *usb_psy, *typec_psy = NULL;
struct qpnp_vadc_chip *vadc_dev, *vchg_vadc_dev;
const char *typec_psy_name;
union power_supply_propval pval = {0, };
usb_psy = power_supply_get_by_name("usb");
if (!usb_psy) {
@ -8061,7 +8121,9 @@ static int smbchg_probe(struct platform_device *pdev)
if (!chip->skip_usb_notification) {
pr_smb(PR_MISC, "setting usb psy present = %d\n",
chip->usb_present);
power_supply_set_present(chip->usb_psy, chip->usb_present);
pval.intval = chip->usb_present;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_PRESENT, &pval);
}
rerun_hvdcp_det_if_necessary(chip);

View file

@ -1941,6 +1941,7 @@ static void smb1351_hvdcp_det_work(struct work_struct *work)
{
int rc;
u8 reg;
union power_supply_propval pval = {0, };
struct smb1351_charger *chip = container_of(work,
struct smb1351_charger,
hvdcp_det_work.work);
@ -1954,8 +1955,9 @@ static void smb1351_hvdcp_det_work(struct work_struct *work)
if (reg) {
pr_debug("HVDCP detected; notifying USB PSY\n");
power_supply_set_supply_type(chip->usb_psy,
POWER_SUPPLY_TYPE_USB_HVDCP);
pval.intval = POWER_SUPPLY_TYPE_USB_HVDCP;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_TYPE, &pval);
}
end:
pm_relax(chip->dev);
@ -2020,15 +2022,17 @@ static int smb1351_apsd_complete_handler(struct smb1351_charger *chip,
if (!chip->battery_missing && !chip->apsd_rerun) {
if (type == POWER_SUPPLY_TYPE_USB) {
pr_debug("Setting usb psy dp=f dm=f SDP and rerun\n");
power_supply_set_dp_dm(chip->usb_psy,
POWER_SUPPLY_DP_DM_DPF_DMF);
prop.intval = POWER_SUPPLY_DP_DM_DPF_DMF;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_DP_DM, &prop);
chip->apsd_rerun = true;
rerun_apsd(chip);
return 0;
}
pr_debug("Set usb psy dp=f dm=f DCP and no rerun\n");
power_supply_set_dp_dm(chip->usb_psy,
POWER_SUPPLY_DP_DM_DPF_DMF);
prop.intval = POWER_SUPPLY_DP_DM_DPF_DMF;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_DP_DM, &prop);
}
/*
* If defined force hvdcp 2p0 property,
@ -2049,26 +2053,35 @@ static int smb1351_apsd_complete_handler(struct smb1351_charger *chip,
msecs_to_jiffies(HVDCP_NOTIFY_MS));
}
power_supply_set_supply_type(chip->usb_psy, type);
prop.intval = type;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_TYPE, &prop);
/*
* SMB is now done sampling the D+/D- lines,
* indicate USB driver
*/
pr_debug("updating usb_psy present=%d\n", chip->chg_present);
power_supply_set_present(chip->usb_psy, chip->chg_present);
prop.intval = chip->chg_present;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_PRESENT,
&prop);
chip->apsd_rerun = false;
} else if (!chip->apsd_rerun) {
/* Handle Charger removal */
power_supply_get_property(chip->usb_psy,
POWER_SUPPLY_PROP_TYPE, &prop);
prop.intval = POWER_SUPPLY_TYPE_UNKNOWN;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_TYPE, &prop);
chip->chg_present = false;
power_supply_set_supply_type(chip->usb_psy,
POWER_SUPPLY_TYPE_UNKNOWN);
power_supply_set_present(chip->usb_psy,
chip->chg_present);
prop.intval = chip->chg_present;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_PRESENT,
&prop);
pr_debug("Set usb psy dm=r df=r\n");
power_supply_set_dp_dm(chip->usb_psy,
POWER_SUPPLY_DP_DM_DPR_DMR);
prop.intval = POWER_SUPPLY_DP_DM_DPR_DMR;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_DP_DM, &prop);
}
return 0;
@ -2116,6 +2129,8 @@ reschedule:
static int smb1351_usbin_uv_handler(struct smb1351_charger *chip, u8 status)
{
union power_supply_propval pval = {0, };
/* use this to detect USB insertion only if !apsd */
if (chip->disable_apsd) {
/*
@ -2126,18 +2141,27 @@ static int smb1351_usbin_uv_handler(struct smb1351_charger *chip, u8 status)
chip->chg_present = true;
pr_debug("updating usb_psy present=%d\n",
chip->chg_present);
power_supply_set_supply_type(chip->usb_psy,
POWER_SUPPLY_TYPE_USB);
power_supply_set_present(chip->usb_psy,
chip->chg_present);
pval.intval = POWER_SUPPLY_TYPE_USB;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_TYPE, &pval);
pval.intval = chip->chg_present;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_PRESENT,
&pval);
} else {
chip->chg_present = false;
power_supply_set_supply_type(chip->usb_psy,
POWER_SUPPLY_TYPE_UNKNOWN);
power_supply_set_present(chip->usb_psy, chip->
chg_present);
pval.intval = POWER_SUPPLY_TYPE_UNKNOWN;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_TYPE, &pval);
pr_debug("updating usb_psy present=%d\n",
chip->chg_present);
pval.intval = chip->chg_present;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_PRESENT,
&pval);
}
return 0;
}
@ -2158,9 +2182,9 @@ static int smb1351_usbin_uv_handler(struct smb1351_charger *chip, u8 status)
static int smb1351_usbin_ov_handler(struct smb1351_charger *chip, u8 status)
{
int health;
int rc;
u8 reg;
union power_supply_propval pval = {0, };
rc = smb1351_read_reg(chip, IRQ_E_REG, &reg);
if (rc)
@ -2169,9 +2193,15 @@ static int smb1351_usbin_ov_handler(struct smb1351_charger *chip, u8 status)
if (status != 0) {
chip->chg_present = false;
chip->usbin_ov = true;
power_supply_set_supply_type(chip->usb_psy,
POWER_SUPPLY_TYPE_UNKNOWN);
power_supply_set_present(chip->usb_psy, chip->chg_present);
pval.intval = POWER_SUPPLY_TYPE_UNKNOWN;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_TYPE, &pval);
pval.intval = chip->chg_present;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_PRESENT,
&pval);
} else {
chip->usbin_ov = false;
if (reg & IRQ_USBIN_UV_BIT)
@ -2181,10 +2211,11 @@ static int smb1351_usbin_ov_handler(struct smb1351_charger *chip, u8 status)
}
if (chip->usb_psy) {
health = status ? POWER_SUPPLY_HEALTH_OVERVOLTAGE
pval.intval = status ? POWER_SUPPLY_HEALTH_OVERVOLTAGE
: POWER_SUPPLY_HEALTH_GOOD;
power_supply_set_health_state(chip->usb_psy, health);
pr_debug("chip ov status is %d\n", health);
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_HEALTH, &pval);
pr_debug("chip ov status is %d\n", pval.intval);
}
pr_debug("chip->chg_present = %d\n", chip->chg_present);

View file

@ -2015,11 +2015,17 @@ static void smb135x_external_power_changed(struct power_supply *psy)
/* update online property */
rc = 0;
if (chip->usb_present && chip->chg_enabled && chip->usb_psy_ma != 0) {
if (prop.intval == 0)
rc = power_supply_set_online(chip->usb_psy, true);
if (prop.intval == 0) {
prop.intval = 1;
rc = power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_ONLINE, &prop);
}
} else {
if (prop.intval == 1)
rc = power_supply_set_online(chip->usb_psy, false);
if (prop.intval == 1) {
prop.intval = 0;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_ONLINE, &prop);
}
}
if (rc < 0)
dev_err(chip->dev, "could not set usb online, rc=%d\n", rc);
@ -2504,6 +2510,7 @@ static int power_ok_handler(struct smb135x_chg *chip, u8 rt_stat)
static int rid_handler(struct smb135x_chg *chip, u8 rt_stat)
{
bool usb_slave_present;
union power_supply_propval pval = {0, };
usb_slave_present = is_usb_slave_present(chip);
@ -2512,8 +2519,9 @@ static int rid_handler(struct smb135x_chg *chip, u8 rt_stat)
if (chip->usb_psy) {
pr_debug("setting usb psy usb_otg = %d\n",
chip->usb_slave_present);
power_supply_set_usb_otg(chip->usb_psy,
chip->usb_slave_present);
pval.intval = chip->usb_slave_present;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_USB_OTG, &pval);
}
}
return 0;
@ -2560,26 +2568,33 @@ static int otg_oc_handler(struct smb135x_chg *chip, u8 rt_stat)
static int handle_dc_removal(struct smb135x_chg *chip)
{
union power_supply_propval prop;
if (chip->dc_psy_type == POWER_SUPPLY_TYPE_WIRELESS) {
cancel_delayed_work_sync(&chip->wireless_insertion_work);
smb135x_path_suspend(chip, DC, CURRENT, true);
}
if (chip->dc_psy_type != -EINVAL)
power_supply_set_online(&chip->dc_psy, chip->dc_present);
if (chip->dc_psy_type != -EINVAL) {
prop.intval = chip->dc_present;
power_supply_set_property(&chip->dc_psy,
POWER_SUPPLY_PROP_ONLINE, &prop);
}
return 0;
}
#define DCIN_UNSUSPEND_DELAY_MS 1000
static int handle_dc_insertion(struct smb135x_chg *chip)
{
union power_supply_propval prop;
if (chip->dc_psy_type == POWER_SUPPLY_TYPE_WIRELESS)
schedule_delayed_work(&chip->wireless_insertion_work,
msecs_to_jiffies(DCIN_UNSUSPEND_DELAY_MS));
if (chip->dc_psy_type != -EINVAL)
power_supply_set_online(&chip->dc_psy,
chip->dc_present);
if (chip->dc_psy_type != -EINVAL) {
prop.intval = chip->dc_present;
power_supply_set_property(&chip->dc_psy,
POWER_SUPPLY_PROP_ONLINE, &prop);
}
return 0;
}
/**
@ -2642,18 +2657,28 @@ static int dcin_ov_handler(struct smb135x_chg *chip, u8 rt_stat)
static int handle_usb_removal(struct smb135x_chg *chip)
{
union power_supply_propval pval = {0,};
if (chip->usb_psy) {
cancel_delayed_work_sync(&chip->hvdcp_det_work);
pm_relax(chip->dev);
pr_debug("setting usb psy type = %d\n",
POWER_SUPPLY_TYPE_UNKNOWN);
power_supply_set_supply_type(chip->usb_psy,
POWER_SUPPLY_TYPE_UNKNOWN);
pval.intval = POWER_SUPPLY_TYPE_UNKNOWN;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_TYPE, &pval);
pr_debug("setting usb psy present = %d\n", chip->usb_present);
power_supply_set_present(chip->usb_psy, chip->usb_present);
pval.intval = chip->usb_present;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_PRESENT,
&pval);
pr_debug("Setting usb psy dp=r dm=r\n");
power_supply_set_dp_dm(chip->usb_psy,
POWER_SUPPLY_DP_DM_DPR_DMR);
pval.intval = POWER_SUPPLY_DP_DM_DPR_DMR;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_DP_DM,
&pval);
}
return 0;
}
@ -2691,6 +2716,7 @@ static void smb135x_hvdcp_det_work(struct work_struct *work)
u8 reg;
struct smb135x_chg *chip = container_of(work, struct smb135x_chg,
hvdcp_det_work.work);
union power_supply_propval pval = {0,};
rc = smb135x_read(chip, STATUS_7_REG, &reg);
if (rc) {
@ -2701,8 +2727,9 @@ static void smb135x_hvdcp_det_work(struct work_struct *work)
if (reg) {
pr_debug("HVDCP detected; notifying USB PSY\n");
power_supply_set_supply_type(chip->usb_psy,
POWER_SUPPLY_TYPE_USB_HVDCP);
pval.intval = POWER_SUPPLY_TYPE_USB_HVDCP;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_TYPE, &pval);
}
end:
pm_relax(chip->dev);
@ -2715,6 +2742,7 @@ static int handle_usb_insertion(struct smb135x_chg *chip)
int rc;
char *usb_type_name = "null";
enum power_supply_type usb_supply_type;
union power_supply_propval pval = {0,};
/* usb inserted */
rc = smb135x_read(chip, STATUS_5_REG, &reg);
@ -2738,16 +2766,20 @@ static int handle_usb_insertion(struct smb135x_chg *chip)
if (chip->batt_present && !chip->apsd_rerun && chip->usb_psy) {
if (usb_supply_type == POWER_SUPPLY_TYPE_USB) {
pr_debug("Setting usb psy dp=f dm=f SDP and rerun\n");
power_supply_set_dp_dm(chip->usb_psy,
POWER_SUPPLY_DP_DM_DPF_DMF);
pval.intval = POWER_SUPPLY_DP_DM_DPF_DMF;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_DP_DM,
&pval);
chip->apsd_rerun = true;
rerun_apsd(chip);
/* rising edge of src detect will happen in few mS */
return 0;
} else {
pr_debug("Set usb psy dp=f dm=f DCP and no rerun\n");
power_supply_set_dp_dm(chip->usb_psy,
POWER_SUPPLY_DP_DM_DPF_DMF);
pval.intval = POWER_SUPPLY_DP_DM_DPF_DMF;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_DP_DM,
&pval);
}
}
@ -2767,9 +2799,15 @@ static int handle_usb_insertion(struct smb135x_chg *chip)
rc);
}
pr_debug("setting usb psy type = %d\n", usb_supply_type);
power_supply_set_supply_type(chip->usb_psy, usb_supply_type);
pval.intval = usb_supply_type;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_TYPE, &pval);
pr_debug("setting usb psy present = %d\n", chip->usb_present);
power_supply_set_present(chip->usb_psy, chip->usb_present);
pval.intval = chip->usb_present;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_PRESENT,
&pval);
}
chip->apsd_rerun = false;
return 0;
@ -2795,12 +2833,12 @@ static int usbin_uv_handler(struct smb135x_chg *chip, u8 rt_stat)
static int usbin_ov_handler(struct smb135x_chg *chip, u8 rt_stat)
{
union power_supply_propval pval = {0, };
/*
* rt_stat indicates if usb is overvolted. If so usb_present
* should be marked removed
*/
bool usb_present = !rt_stat;
int health;
pr_debug("chip->usb_present = %d usb_present = %d\n",
chip->usb_present, usb_present);
@ -2815,9 +2853,10 @@ static int usbin_ov_handler(struct smb135x_chg *chip, u8 rt_stat)
}
if (chip->usb_psy) {
health = rt_stat ? POWER_SUPPLY_HEALTH_OVERVOLTAGE
pval.intval = rt_stat ? POWER_SUPPLY_HEALTH_OVERVOLTAGE
: POWER_SUPPLY_HEALTH_GOOD;
power_supply_set_health_state(chip->usb_psy, health);
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_HEALTH, &pval);
}
return 0;
@ -3377,6 +3416,7 @@ static void dump_regs(struct smb135x_chg *chip)
#endif
static int determine_initial_status(struct smb135x_chg *chip)
{
union power_supply_propval pval = {0, };
int rc;
u8 reg;
@ -3458,8 +3498,9 @@ static int determine_initial_status(struct smb135x_chg *chip)
if (chip->usb_psy && !chip->id_line_not_connected) {
pr_debug("setting usb psy usb_otg = %d\n",
chip->usb_slave_present);
power_supply_set_usb_otg(chip->usb_psy,
chip->usb_slave_present);
pval.intval = chip->usb_slave_present;
power_supply_set_property(chip->usb_psy,
POWER_SUPPLY_PROP_USB_OTG, &pval);
}
return 0;
}