Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad470245 authored by Kavya Nunna's avatar Kavya Nunna
Browse files

power: supply: smb1351: Add support to make SMB1351 driver GKI complaint



Replace existing non standard power supply properties with standard power
supply properties to make the smb1351 driver GKI complaint.

Change-Id: Iec18b6f267c30739928d85fd10ca676b17102a11
Signed-off-by: default avatarKavya Nunna <knunna@codeaurora.org>
parent 858cd776
Loading
Loading
Loading
Loading
+68 −37
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2016-2020 The Linux Foundation. All rights reserved.
 * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
 */

#define pr_fmt(fmt) "%s: " fmt, __func__
@@ -8,7 +8,7 @@
#include <linux/i2c.h>
#include <linux/debugfs.h>
#include <linux/errno.h>
#include <linux/extcon.h>
#include <linux/extcon-provider.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
@@ -1135,8 +1135,7 @@ static int smb1351_hw_init(struct smb1351_charger *chip)
static enum power_supply_property smb1351_battery_properties[] = {
	POWER_SUPPLY_PROP_STATUS,
	POWER_SUPPLY_PROP_PRESENT,
	POWER_SUPPLY_PROP_CHARGING_ENABLED,
	POWER_SUPPLY_PROP_BATTERY_CHARGING_ENABLED,
	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
	POWER_SUPPLY_PROP_CHARGE_TYPE,
	POWER_SUPPLY_PROP_CAPACITY,
	POWER_SUPPLY_PROP_HEALTH,
@@ -1223,7 +1222,7 @@ static int smb1351_get_prop_charge_type(struct smb1351_charger *chip)
	if (reg == STATUS_FAST_CHARGING)
		return POWER_SUPPLY_CHARGE_TYPE_FAST;
	else if (reg == STATUS_TAPER_CHARGING)
		return POWER_SUPPLY_CHARGE_TYPE_TAPER;
		return POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE;
	else if (reg == STATUS_PRE_CHARGING)
		return POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
	else
@@ -1321,15 +1320,65 @@ static char *smb1351_usb_supplicants[] = {
	"bms",
};

static enum power_supply_usb_type smb1351_usb_psy_supported_types[] = {
	POWER_SUPPLY_USB_TYPE_UNKNOWN,
	POWER_SUPPLY_USB_TYPE_SDP,
	POWER_SUPPLY_USB_TYPE_DCP,
	POWER_SUPPLY_USB_TYPE_CDP,
	POWER_SUPPLY_USB_TYPE_ACA,
};

static enum power_supply_property smb1351_usb_properties[] = {
	POWER_SUPPLY_PROP_PRESENT,
	POWER_SUPPLY_PROP_ONLINE,
	POWER_SUPPLY_PROP_CURRENT_MAX,
	POWER_SUPPLY_PROP_TYPE,
	POWER_SUPPLY_PROP_REAL_TYPE,
	POWER_SUPPLY_PROP_SDP_CURRENT_MAX,
	POWER_SUPPLY_PROP_USB_TYPE,
	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
};

static void smb1351_update_desc_type(struct smb1351_charger *chip)
{
	switch (chip->charger_type) {
	case POWER_SUPPLY_TYPE_USB_CDP:
	case POWER_SUPPLY_TYPE_USB_DCP:
	case POWER_SUPPLY_TYPE_USB:
	case POWER_SUPPLY_TYPE_USB_ACA:
		chip->usb_psy_d.type = chip->charger_type;
		break;
	case POWER_SUPPLY_TYPE_USB_HVDCP:
		chip->usb_psy_d.type = POWER_SUPPLY_TYPE_USB_DCP;
		break;
	default:
		chip->usb_psy_d.type = POWER_SUPPLY_TYPE_USB;
		break;
	}
}

static void smb1351_get_usb_type(struct smb1351_charger *chip,
				union power_supply_propval *val)
{
	switch (chip->charger_type) {
	case POWER_SUPPLY_TYPE_USB_CDP:
		val->intval = POWER_SUPPLY_USB_TYPE_CDP;
		break;
	case POWER_SUPPLY_TYPE_USB_DCP:
		val->intval = POWER_SUPPLY_USB_TYPE_DCP;
		break;
	case POWER_SUPPLY_TYPE_USB:
		val->intval = POWER_SUPPLY_USB_TYPE_SDP;
		break;
	case POWER_SUPPLY_TYPE_USB_ACA:
		val->intval = POWER_SUPPLY_USB_TYPE_ACA;
		break;
	case POWER_SUPPLY_TYPE_USB_HVDCP:
		val->intval = POWER_SUPPLY_USB_TYPE_DCP;
		break;
	default:
		val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN;
		break;
	}
}

static int smb1351_usb_get_property(struct power_supply *psy,
		enum power_supply_property psp,
				  union power_supply_propval *val)
@@ -1338,7 +1387,7 @@ static int smb1351_usb_get_property(struct power_supply *psy,

	switch (psp) {
	case POWER_SUPPLY_PROP_CURRENT_MAX:
	case POWER_SUPPLY_PROP_SDP_CURRENT_MAX:
	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
		val->intval = chip->usb_psy_ma * 1000;
		break;
	case POWER_SUPPLY_PROP_PRESENT:
@@ -1347,16 +1396,8 @@ static int smb1351_usb_get_property(struct power_supply *psy,
	case POWER_SUPPLY_PROP_ONLINE:
		val->intval = chip->chg_present && !chip->usb_suspended_status;
		break;
	case POWER_SUPPLY_PROP_TYPE:
		val->intval = chip->charger_type;
		break;
	case POWER_SUPPLY_PROP_REAL_TYPE:
		if (chip->charger_type == POWER_SUPPLY_TYPE_USB_HVDCP)
			val->intval = POWER_SUPPLY_TYPE_USB_DCP;
		else if (chip->charger_type == POWER_SUPPLY_TYPE_UNKNOWN)
			val->intval = POWER_SUPPLY_TYPE_USB;
		else
			val->intval = chip->charger_type;
	case POWER_SUPPLY_PROP_USB_TYPE:
		smb1351_get_usb_type(chip, val);
		break;
	default:
		return -EINVAL;
@@ -1372,7 +1413,7 @@ static int smb1351_usb_set_property(struct power_supply *psy,

	switch (psp) {
	case POWER_SUPPLY_PROP_CURRENT_MAX:
	case POWER_SUPPLY_PROP_SDP_CURRENT_MAX:
	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
		chip->usb_psy_ma = val->intval / 1000;
		smb1351_enable_volatile_writes(chip);
		smb1351_set_usb_chg_current(chip, chip->usb_psy_ma);
@@ -1402,8 +1443,7 @@ static int smb1351_batt_property_is_writeable(struct power_supply *psy,
					enum power_supply_property psp)
{
	switch (psp) {
	case POWER_SUPPLY_PROP_CHARGING_ENABLED:
	case POWER_SUPPLY_PROP_BATTERY_CHARGING_ENABLED:
	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
	case POWER_SUPPLY_PROP_CAPACITY:
		return 1;
	default:
@@ -1456,12 +1496,9 @@ static int smb1351_battery_set_property(struct power_supply *psy,
			return -EINVAL;
		}
		break;
	case POWER_SUPPLY_PROP_CHARGING_ENABLED:
	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
		smb1351_usb_suspend(chip, USER, !val->intval);
		break;
	case POWER_SUPPLY_PROP_BATTERY_CHARGING_ENABLED:
		smb1351_battchg_disable(chip, USER, !val->intval);
		break;
	case POWER_SUPPLY_PROP_CAPACITY:
		chip->fake_battery_soc = val->intval;
		power_supply_changed(chip->batt_psy);
@@ -1489,12 +1526,9 @@ static int smb1351_battery_get_property(struct power_supply *psy,
	case POWER_SUPPLY_PROP_CAPACITY:
		val->intval = smb1351_get_prop_batt_capacity(chip);
		break;
	case POWER_SUPPLY_PROP_CHARGING_ENABLED:
	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
		val->intval = !chip->usb_suspended_status;
		break;
	case POWER_SUPPLY_PROP_BATTERY_CHARGING_ENABLED:
		val->intval = !chip->battchg_disabled_status;
		break;
	case POWER_SUPPLY_PROP_CHARGE_TYPE:
		val->intval = smb1351_get_prop_charge_type(chip);
		break;
@@ -1534,7 +1568,6 @@ 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);
@@ -1546,12 +1579,6 @@ static void smb1351_hvdcp_det_work(struct work_struct *work)
	}
	pr_debug("STATUS_7_REG = 0x%02X\n", reg);

	if (reg) {
		pr_debug("HVDCP detected; notifying USB PSY\n");
		pval.intval = POWER_SUPPLY_TYPE_USB_HVDCP;
		power_supply_set_property(chip->usb_psy,
			POWER_SUPPLY_PROP_TYPE, &pval);
	}
end:
	pm_relax(chip->dev);
}
@@ -1675,6 +1702,8 @@ static int smb1351_apsd_complete_handler(struct smb1351_charger *chip,
		smb1351_request_dpdm(chip, false);
	}

	smb1351_update_desc_type(chip);

	return 0;
}

@@ -2502,6 +2531,8 @@ static int smb1351_main_charger_probe(struct i2c_client *client,
	chip->usb_psy_d.get_property = smb1351_usb_get_property;
	chip->usb_psy_d.set_property = smb1351_usb_set_property;
	chip->usb_psy_d.properties = smb1351_usb_properties;
	chip->usb_psy_d.usb_types  = smb1351_usb_psy_supported_types,
	chip->usb_psy_d.num_usb_types = ARRAY_SIZE(smb1351_usb_psy_supported_types);
	chip->usb_psy_d.num_properties = ARRAY_SIZE(smb1351_usb_properties);
	chip->usb_psy_d.property_is_writeable = smb1351_usb_is_writeable;