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

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

Merge "power: smb5: add minor fixes to SMB5 charger"

parents 4624f8d7 81e5cadc
Loading
Loading
Loading
Loading
+17 −11
Original line number Diff line number Diff line
@@ -239,6 +239,8 @@ static int smb5_chg_config_init(struct smb5 *chip)
		chg->param = smb5_pmi632_params;
		chg->use_extcon = true;
		chg->name = "pmi632_charger";
		/* PMI632 does not support PD */
		chg->pd_not_supported = true;
		chg->hw_max_icl_ua =
			(chip->dt.usb_icl_ua > 0) ? chip->dt.usb_icl_ua
						: PMI632_MAX_ICL_UA;
@@ -1377,9 +1379,7 @@ static int smb5_configure_typec(struct smb_charger *chg)
	int rc;

	/* disable apsd */
	rc = smblib_masked_write(chg, USBIN_OPTIONS_1_CFG_REG,
				HVDCP_EN_BIT | BC1P2_SRC_DETECT_BIT,
				0);
	rc = smblib_configure_hvdcp_apsd(chg, false);
	if (rc < 0) {
		dev_err(chg->dev, "Couldn't disable APSD rc=%d\n", rc);
		return rc;
@@ -1498,7 +1498,6 @@ static int smb5_init_hw(struct smb5 *chip)

	if (type) {
		chg->connector_type = POWER_SUPPLY_CONNECTOR_MICRO_USB;
		smblib_rerun_apsd_if_required(chg);
		rc = smb5_configure_micro_usb(chg);
	} else {
		chg->connector_type = POWER_SUPPLY_CONNECTOR_TYPEC;
@@ -1512,10 +1511,14 @@ static int smb5_init_hw(struct smb5 *chip)

	/*
	 * PMI632 based hw init:
	 * - Rerun APSD to ensure proper charger detection if device
	 *   boots with charger connected.
	 * - Initialize flash module for PMI632
	 */
	if (chg->smb_version == PMI632_SUBTYPE)
	if (chg->smb_version == PMI632_SUBTYPE) {
		schgm_flash_init(chg);
		smblib_rerun_apsd_if_required(chg);
	}

	/* vote 0mA on usb_icl for non battery platforms */
	vote(chg->usb_icl_votable,
@@ -1541,13 +1544,16 @@ static int smb5_init_hw(struct smb5 *chip)
	 * AICL configuration:
	 * start from min and AICL ADC disable, and enable aicl rerun
	 */
	if (chg->smb_version != PMI632_SUBTYPE) {
		rc = smblib_masked_write(chg, USBIN_AICL_OPTIONS_CFG_REG,
		USBIN_AICL_PERIODIC_RERUN_EN_BIT | USBIN_AICL_ADC_EN_BIT,
				USBIN_AICL_PERIODIC_RERUN_EN_BIT
				| USBIN_AICL_ADC_EN_BIT,
				USBIN_AICL_PERIODIC_RERUN_EN_BIT);
		if (rc < 0) {
		dev_err(chg->dev, "Couldn't configure AICL rc=%d\n", rc);
			dev_err(chg->dev, "Couldn't config AICL rc=%d\n", rc);
			return rc;
		}
	}

	rc = smblib_write(chg, AICL_RERUN_TIME_CFG_REG,
				AICL_RERUN_TIME_12S_VAL);
+42 −26
Original line number Diff line number Diff line
@@ -557,6 +557,23 @@ static int smblib_set_usb_pd_allowed_voltage(struct smb_charger *chg,
/********************
 * HELPER FUNCTIONS *
 ********************/
int smblib_configure_hvdcp_apsd(struct smb_charger *chg, bool enable)
{
	int rc;
	u8 mask = HVDCP_EN_BIT | BC1P2_SRC_DETECT_BIT;

	if (chg->pd_not_supported)
		return 0;

	rc = smblib_masked_write(chg, USBIN_OPTIONS_1_CFG_REG, mask,
						enable ? mask : 0);
	if (rc < 0)
		smblib_err(chg, "failed to write USBIN_OPTIONS_1_CFG rc=%d\n",
				rc);

	return rc;
}

static int smblib_request_dpdm(struct smb_charger *chg, bool enable)
{
	int rc = 0;
@@ -2436,15 +2453,13 @@ int smblib_set_prop_pd_active(struct smb_charger *chg,
		/* PD hard resets failed, rerun apsd */
		if (chg->ok_to_pd) {
			chg->ok_to_pd = false;
			rc = smblib_masked_write(chg, USBIN_OPTIONS_1_CFG_REG,
					HVDCP_EN_BIT | BC1P2_SRC_DETECT_BIT,
					HVDCP_EN_BIT | BC1P2_SRC_DETECT_BIT);
			rc = smblib_configure_hvdcp_apsd(chg, true);
			if (rc < 0) {
				dev_err(chg->dev,
					"Couldn't disable APSD rc=%d\n", rc);
					"Couldn't enable APSD rc=%d\n", rc);
				return rc;
			}
			smblib_rerun_apsd(chg);
			smblib_rerun_apsd_if_required(chg);
		}
	}

@@ -3131,7 +3146,7 @@ irqreturn_t usb_source_change_irq_handler(int irq, void *data)
		 * charger-mis-detection.
		 */
		chg->uusb_apsd_rerun_done = true;
		smblib_rerun_apsd(chg);
		smblib_rerun_apsd_if_required(chg);
		return IRQ_HANDLED;
	}

@@ -3178,7 +3193,8 @@ static void typec_sink_insertion(struct smb_charger *chg)
	}

	if (!chg->pr_swap_in_progress)
		chg->ok_to_pd = !(*chg->pd_disabled) || chg->early_usb_attach;
		chg->ok_to_pd = (!(*chg->pd_disabled) || chg->early_usb_attach)
					&& !chg->pd_not_supported;
}

static void typec_src_insertion(struct smb_charger *chg)
@@ -3197,24 +3213,28 @@ static void typec_src_insertion(struct smb_charger *chg)
	}

	chg->typec_legacy = stat & TYPEC_LEGACY_CABLE_STATUS_BIT;
	chg->ok_to_pd = !(chg->typec_legacy || *chg->pd_disabled)
						|| chg->early_usb_attach;
	chg->ok_to_pd = (!(chg->typec_legacy || *chg->pd_disabled)
			|| chg->early_usb_attach) && !chg->pd_not_supported;
	if (!chg->ok_to_pd) {
		rc = smblib_masked_write(chg, USBIN_OPTIONS_1_CFG_REG,
				HVDCP_EN_BIT | BC1P2_SRC_DETECT_BIT,
				HVDCP_EN_BIT | BC1P2_SRC_DETECT_BIT);
		rc = smblib_configure_hvdcp_apsd(chg, true);
		if (rc < 0) {
			dev_err(chg->dev,
				"Couldn't disable APSD rc=%d\n", rc);
				"Couldn't enable APSD rc=%d\n", rc);
			return;
		}
		smblib_rerun_apsd(chg);
		smblib_rerun_apsd_if_required(chg);
	}
}

static void typec_sink_removal(struct smb_charger *chg)
{
	vote(chg->usb_icl_votable, OTG_VOTER, false, 0);

	if (chg->use_extcon) {
		if (chg->otg_present)
			smblib_notify_usb_host(chg, false);
		chg->otg_present = false;
	}
}

static void typec_src_removal(struct smb_charger *chg)
@@ -3230,12 +3250,9 @@ static void typec_src_removal(struct smb_charger *chg)
			"Couldn't disable secondary charger rc=%d\n", rc);

	/* disable apsd */
	rc = smblib_masked_write(chg, USBIN_OPTIONS_1_CFG_REG,
				HVDCP_EN_BIT | BC1P2_SRC_DETECT_BIT,
				0);
	rc = smblib_configure_hvdcp_apsd(chg, false);
	if (rc < 0)
		smblib_err(chg,
			"Couldn't disable APSD rc=%d\n", rc);
		smblib_err(chg, "Couldn't disable APSD rc=%d\n", rc);

	smblib_update_usb_type(chg);

@@ -3292,13 +3309,9 @@ static void typec_src_removal(struct smb_charger *chg)
		smblib_err(chg, "Couldn't set USBIN_ADAPTER_ALLOW_5V_OR_9V_TO_12V rc=%d\n",
			rc);

	if (chg->use_extcon) {
		if (chg->otg_present)
			smblib_notify_usb_host(chg, false);
		else
	if (chg->use_extcon)
		smblib_notify_device_mode(chg, false);
	}
	chg->otg_present = false;

	chg->typec_legacy = false;
}

@@ -3629,6 +3642,9 @@ static void smblib_uusb_otg_work(struct work_struct *work)
	otg = !!(stat & U_USB_GROUND_NOVBUS_BIT);
	if (chg->otg_present != otg)
		smblib_notify_usb_host(chg, otg);
	else
		goto out;

	chg->otg_present = otg;
	if (!otg)
		chg->boost_current_ua = 0;
+2 −0
Original line number Diff line number Diff line
@@ -279,6 +279,7 @@ struct smb_charger {
	int			smb_version;
	int			otg_delay_ms;
	int			*weak_chg_icl_ua;
	bool			pd_not_supported;

	/* locks */
	struct mutex		lock;
@@ -554,6 +555,7 @@ int smblib_get_prop_pr_swap_in_progress(struct smb_charger *chg,
				union power_supply_propval *val);
int smblib_set_prop_pr_swap_in_progress(struct smb_charger *chg,
				const union power_supply_propval *val);
int smblib_configure_hvdcp_apsd(struct smb_charger *chg, bool enable);

int smblib_init(struct smb_charger *chg);
int smblib_deinit(struct smb_charger *chg);
+2 −2
Original line number Diff line number Diff line
@@ -283,7 +283,7 @@ enum {
#define U_USB_GROUND_BIT			BIT(4)

#define TYPE_C_MODE_CFG_REG			(TYPEC_BASE + 0x44)
#define TYPEC_POWER_ROLE_CMD_MASK		GENMASK(2, 0)
#define TYPEC_POWER_ROLE_CMD_MASK		GENMASK(2, 1)
#define EN_SRC_ONLY_BIT				BIT(2)
#define EN_SNK_ONLY_BIT				BIT(1)
#define TYPEC_DISABLE_CMD_BIT			BIT(0)
@@ -327,7 +327,7 @@ enum {
#define TYPEC_U_USB_CFG_REG			(TYPEC_BASE + 0x70)
#define EN_MICRO_USB_MODE_BIT			BIT(0)

#define TYPEC_MICRO_USB_MODE_REG		(TYPEC_BASE + 0x70)
#define TYPEC_MICRO_USB_MODE_REG		(TYPEC_BASE + 0x73)
#define MICRO_USB_MODE_ONLY_BIT			BIT(0)
/********************************
 *  MISC Peripheral Registers  *