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

Commit d5b4ca0d authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "power: supply: Add support for HVDCP_3P5"

parents 5dc8dbcc 6cb53e81
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ static const char * const power_supply_type_text[] = {
	"Unknown", "Battery", "UPS", "Mains", "USB",
	"USB_DCP", "USB_CDP", "USB_ACA", "USB_C",
	"USB_PD", "USB_PD_DRP", "BrickID",
	"USB_HVDCP", "USB_HVDCP_3", "Wireless", "USB_FLOAT",
	"USB_HVDCP", "USB_HVDCP_3", "USB_HVDCP_3P5", "Wireless", "USB_FLOAT",
	"BMS", "Parallel", "Main", "Wipower", "USB_C_UFP", "USB_C_DFP",
	"Charge_Pump",
};
@@ -408,6 +408,8 @@ static struct device_attribute power_supply_attrs[] = {
	POWER_SUPPLY_ATTR(comp_clamp_level),
	POWER_SUPPLY_ATTR(adapter_cc_mode),
	POWER_SUPPLY_ATTR(skin_health),
	POWER_SUPPLY_ATTR(apsd_rerun),
	POWER_SUPPLY_ATTR(apsd_timeout),
	/* Charge pump properties */
	POWER_SUPPLY_ATTR(cp_status1),
	POWER_SUPPLY_ATTR(cp_status2),
+14 −0
Original line number Diff line number Diff line
@@ -729,6 +729,8 @@ static enum power_supply_property smb5_usb_props[] = {
	POWER_SUPPLY_PROP_VOLTAGE_VPH,
	POWER_SUPPLY_PROP_THERM_ICL_LIMIT,
	POWER_SUPPLY_PROP_SKIN_HEALTH,
	POWER_SUPPLY_PROP_APSD_RERUN,
	POWER_SUPPLY_PROP_APSD_TIMEOUT,
};

static int smb5_usb_get_prop(struct power_supply *psy,
@@ -906,6 +908,12 @@ static int smb5_usb_get_prop(struct power_supply *psy,
	case POWER_SUPPLY_PROP_SKIN_HEALTH:
		val->intval = smblib_get_skin_temp_status(chg);
		break;
	case POWER_SUPPLY_PROP_APSD_RERUN:
		val->intval = 0;
		break;
	case POWER_SUPPLY_PROP_APSD_TIMEOUT:
		val->intval = chg->apsd_ext_timeout;
		break;
	default:
		pr_err("get prop %d is not supported in usb\n", psp);
		rc = -EINVAL;
@@ -995,6 +1003,11 @@ static int smb5_usb_set_prop(struct power_supply *psy,
	case POWER_SUPPLY_PROP_ADAPTER_CC_MODE:
		chg->adapter_cc_mode = val->intval;
		break;
	case POWER_SUPPLY_PROP_APSD_RERUN:
		del_timer_sync(&chg->apsd_timer);
		chg->apsd_ext_timeout = false;
		smblib_rerun_apsd(chg);
		break;
	default:
		pr_err("set prop %d is not supported\n", psp);
		rc = -EINVAL;
@@ -1013,6 +1026,7 @@ static int smb5_usb_prop_is_writeable(struct power_supply *psy,
	case POWER_SUPPLY_PROP_THERM_ICL_LIMIT:
	case POWER_SUPPLY_PROP_VOLTAGE_MAX_LIMIT:
	case POWER_SUPPLY_PROP_ADAPTER_CC_MODE:
	case POWER_SUPPLY_PROP_APSD_RERUN:
		return 1;
	default:
		break;
+43 −8
Original line number Diff line number Diff line
@@ -1026,7 +1026,7 @@ static int smblib_request_dpdm(struct smb_charger *chg, bool enable)
	return rc;
}

static void smblib_rerun_apsd(struct smb_charger *chg)
void smblib_rerun_apsd(struct smb_charger *chg)
{
	int rc;

@@ -1196,6 +1196,9 @@ static void smblib_uusb_removal(struct smb_charger *chg)
	chg->uusb_apsd_rerun_done = false;
	chg->chg_param.forced_main_fcc = 0;

	del_timer_sync(&chg->apsd_timer);
	chg->apsd_ext_timeout = false;

	/* write back the default FLOAT charger configuration */
	rc = smblib_masked_write(chg, USBIN_OPTIONS_2_CFG_REG,
				(u8)FLOAT_OPTIONS_MASK, chg->float_cfg);
@@ -5278,6 +5281,7 @@ static void smblib_handle_sdp_enumeration_done(struct smb_charger *chg,
		   rising ? "rising" : "falling");
}

#define APSD_EXTENDED_TIMEOUT_MS	400
/* triggers when HVDCP 3.0 authentication has finished */
static void smblib_handle_hvdcp_3p0_auth_done(struct smb_charger *chg,
					      bool rising)
@@ -5294,13 +5298,29 @@ static void smblib_handle_hvdcp_3p0_auth_done(struct smb_charger *chg,
	/* the APSD done handler will set the USB supply type */
	apsd_result = smblib_get_apsd_result(chg);

	if (apsd_result->bit & QC_3P0_BIT) {
		/* for QC3, switch to CP if present */
	if ((apsd_result->bit & QC_3P0_BIT) && chg->sec_cp_present) {
		rc = smblib_select_sec_charger(chg, POWER_SUPPLY_CHARGER_SEC_CP,
		if (chg->sec_cp_present) {
			rc = smblib_select_sec_charger(chg,
				POWER_SUPPLY_CHARGER_SEC_CP,
				POWER_SUPPLY_CP_HVDCP3, false);
			if (rc < 0)
				dev_err(chg->dev,
			"Couldn't enable secondary chargers  rc=%d\n", rc);
				"Couldn't enable secondary chargers  rc=%d\n",
					rc);
		}

		/* QC3.5 detection timeout */
		if (!chg->apsd_ext_timeout &&
				!timer_pending(&chg->apsd_timer)) {
			smblib_dbg(chg, PR_MISC,
				"APSD Extented timer started at %lld\n",
				jiffies_to_msecs(jiffies));

			mod_timer(&chg->apsd_timer,
				msecs_to_jiffies(APSD_EXTENDED_TIMEOUT_MS)
				+ jiffies);
		}
	}

	smblib_dbg(chg, PR_INTERRUPT, "IRQ: hvdcp-3p0-auth-done rising; %s detected\n",
@@ -5802,6 +5822,9 @@ static void typec_src_removal(struct smb_charger *chg)
		smblib_notify_device_mode(chg, false);

	chg->typec_legacy = false;

	del_timer_sync(&chg->apsd_timer);
	chg->apsd_ext_timeout = false;
}

static void typec_mode_unattached(struct smb_charger *chg)
@@ -6933,6 +6956,16 @@ static enum alarmtimer_restart chg_termination_alarm_cb(struct alarm *alarm,
	return ALARMTIMER_NORESTART;
}

static void apsd_timer_cb(unsigned long data)
{
	struct smb_charger *chg = (struct smb_charger *)data;

	smblib_dbg(chg, PR_MISC, "APSD Extented timer timeout at %lld\n",
			jiffies_to_msecs(jiffies));

	chg->apsd_ext_timeout = true;
}

static void jeita_update_work(struct work_struct *work)
{
	struct smb_charger *chg = container_of(work, struct smb_charger,
@@ -7471,6 +7504,7 @@ int smblib_init(struct smb_charger *chg)
					smblib_pr_swap_detach_work);
	INIT_DELAYED_WORK(&chg->pr_lock_clear_work,
					smblib_pr_lock_clear_work);
	setup_timer(&chg->apsd_timer, apsd_timer_cb, (unsigned long)chg);

	if (chg->wa_flags & CHG_TERMINATION_WA) {
		INIT_WORK(&chg->chg_termination_work,
@@ -7608,6 +7642,7 @@ int smblib_deinit(struct smb_charger *chg)
			alarm_cancel(&chg->chg_termination_alarm);
			cancel_work_sync(&chg->chg_termination_work);
		}
		del_timer_sync(&chg->apsd_timer);
		cancel_work_sync(&chg->bms_update_work);
		cancel_work_sync(&chg->jeita_update_work);
		cancel_work_sync(&chg->pl_update_work);
+5 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include <linux/alarmtimer.h>
#include <linux/ktime.h>
#include <linux/types.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/irqreturn.h>
#include <linux/regulator/driver.h>
@@ -474,6 +475,8 @@ struct smb_charger {
	struct alarm		chg_termination_alarm;
	struct alarm		dcin_aicl_alarm;

	struct timer_list	apsd_timer;

	struct charger_param	chg_param;
	/* secondary charger config */
	bool			sec_pl_present;
@@ -568,6 +571,7 @@ struct smb_charger {
	bool			hvdcp3_standalone_config;
	int			wls_icl_ua;
	bool			dpdm_enabled;
	bool			apsd_ext_timeout;

	/* workaround flag */
	u32			wa_flags;
@@ -774,6 +778,7 @@ int smblib_set_prop_rechg_soc_thresh(struct smb_charger *chg,
				const union power_supply_propval *val);
void smblib_suspend_on_debug_battery(struct smb_charger *chg);
int smblib_rerun_apsd_if_required(struct smb_charger *chg);
void smblib_rerun_apsd(struct smb_charger *chg);
int smblib_get_prop_fcc_delta(struct smb_charger *chg,
				union power_supply_propval *val);
int smblib_get_thermal_threshold(struct smb_charger *chg, u16 addr, int *val);
+5 −0
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ enum {
	POWER_SUPPLY_DP_DM_FORCE_5V = 13,
	POWER_SUPPLY_DP_DM_FORCE_9V = 14,
	POWER_SUPPLY_DP_DM_FORCE_12V = 15,
	POWER_SUPPLY_DP_DM_CONFIRMED_HVDCP3P5 = 16,
};

enum {
@@ -125,6 +126,7 @@ enum {
enum {
	POWER_SUPPLY_CP_NONE = 0,
	POWER_SUPPLY_CP_HVDCP3,
	POWER_SUPPLY_CP_HVDCP3P5,
	POWER_SUPPLY_CP_PPS,
	POWER_SUPPLY_CP_WIRELESS,
};
@@ -342,6 +344,8 @@ enum power_supply_property {
	POWER_SUPPLY_PROP_COMP_CLAMP_LEVEL,
	POWER_SUPPLY_PROP_ADAPTER_CC_MODE,
	POWER_SUPPLY_PROP_SKIN_HEALTH,
	POWER_SUPPLY_PROP_APSD_RERUN,
	POWER_SUPPLY_PROP_APSD_TIMEOUT,
	/* Charge pump properties */
	POWER_SUPPLY_PROP_CP_STATUS1,
	POWER_SUPPLY_PROP_CP_STATUS2,
@@ -380,6 +384,7 @@ enum power_supply_type {
	POWER_SUPPLY_TYPE_APPLE_BRICK_ID,	/* Apple Charging Method */
	POWER_SUPPLY_TYPE_USB_HVDCP,		/* High Voltage DCP */
	POWER_SUPPLY_TYPE_USB_HVDCP_3,		/* Efficient High Voltage DCP */
	POWER_SUPPLY_TYPE_USB_HVDCP_3P5,	/* Efficient High Voltage DCP */
	POWER_SUPPLY_TYPE_WIRELESS,		/* Accessory Charger Adapters */
	POWER_SUPPLY_TYPE_USB_FLOAT,		/* Floating charger */
	POWER_SUPPLY_TYPE_BMS,			/* Battery Monitor System */