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

Commit 002feefb authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "power: qpnp-smbcharger: add voting logic for enabling/disabling HVDCP"

parents 67bf9025 3daaaa59
Loading
Loading
Loading
Loading
+49 −18
Original line number Diff line number Diff line
@@ -279,6 +279,7 @@ struct smbchg_chip {
	struct votable			*hw_aicl_rerun_disable_votable;
	struct votable			*hw_aicl_rerun_enable_indirect_votable;
	struct votable			*aicl_deglitch_short_votable;
	struct votable			*hvdcp_enable_votable;
};

enum qpnp_schg {
@@ -421,6 +422,12 @@ enum aicl_short_deglitch_voters {
	HVDCP_SHORT_DEGLITCH_VOTER,
	NUM_HW_SHORT_DEGLITCH_VOTERS,
};
enum hvdcp_voters {
	HVDCP_PMIC_VOTER,
	HVDCP_OTG_VOTER,
	HVDCP_PULSING_VOTER,
	NUM_HVDCP_VOTERS,
};
static int smbchg_debug_mask;
module_param_named(
	debug_mask, smbchg_debug_mask, int, S_IRUSR | S_IWUSR
@@ -2472,6 +2479,26 @@ static int dc_suspend_vote_cb(struct device *dev, int suspend,
	return rc;
}

#define HVDCP_EN_BIT			BIT(3)
static int smbchg_hvdcp_enable_cb(struct device *dev, int enable,
						int client, int last_enable,
						int last_client)
{
	int rc = 0;
	struct smbchg_chip *chip = dev_get_drvdata(dev);

	pr_err("smbchg_hvdcp_enable_cb  enable %d last_enable %d\n",
			enable, last_enable);
	rc = smbchg_sec_masked_write(chip,
				chip->usb_chgpth_base + CHGPTH_CFG,
				HVDCP_EN_BIT, enable ? HVDCP_EN_BIT : 0);
	if (rc < 0)
		dev_err(chip->dev, "Couldn't %s HVDCP rc=%d\n",
				enable ? "enable" : "disable", rc);

	return rc;
}

static int set_fastchg_current_vote_cb(struct device *dev,
						int fcc_ma,
						int client,
@@ -3836,7 +3863,6 @@ struct regulator_ops smbchg_otg_reg_ops = {
#define USBIN_ADAPTER_9V		0x3
#define USBIN_ADAPTER_5V_9V_CONT	0x2
#define USBIN_ADAPTER_5V_UNREGULATED_9V	0x5
#define HVDCP_EN_BIT			BIT(3)
static int smbchg_external_otg_regulator_enable(struct regulator_dev *rdev)
{
	int rc = 0;
@@ -3860,9 +3886,7 @@ static int smbchg_external_otg_regulator_enable(struct regulator_dev *rdev)
	 * allowance to 9V, so that the audio boost operating in reverse never
	 * gets detected as a valid input
	 */
	rc = smbchg_sec_masked_write(chip,
				chip->usb_chgpth_base + CHGPTH_CFG,
				HVDCP_EN_BIT, 0);
	rc = vote(chip->hvdcp_enable_votable, HVDCP_OTG_VOTER, true, 0);
	if (rc < 0) {
		dev_err(chip->dev, "Couldn't disable HVDCP rc=%d\n", rc);
		return rc;
@@ -3896,9 +3920,7 @@ static int smbchg_external_otg_regulator_disable(struct regulator_dev *rdev)
	 * value in order to allow normal USBs to be recognized as a valid
	 * input.
	 */
	rc = smbchg_sec_masked_write(chip,
				chip->usb_chgpth_base + CHGPTH_CFG,
				HVDCP_EN_BIT, HVDCP_EN_BIT);
	rc = vote(chip->hvdcp_enable_votable, HVDCP_OTG_VOTER, false, 1);
	if (rc < 0) {
		dev_err(chip->dev, "Couldn't enable HVDCP rc=%d\n", rc);
		return rc;
@@ -4636,9 +4658,7 @@ static void restore_from_hvdcp_detection(struct smbchg_chip *chip)
		pr_err("Couldn't configure HVDCP 9V rc=%d\n", rc);

	/* enable HVDCP */
	rc = smbchg_sec_masked_write(chip,
				chip->usb_chgpth_base + CHGPTH_CFG,
				HVDCP_EN_BIT, HVDCP_EN_BIT);
	rc = vote(chip->hvdcp_enable_votable, HVDCP_PULSING_VOTER, false, 1);
	if (rc < 0)
		pr_err("Couldn't enable HVDCP rc=%d\n", rc);

@@ -5189,8 +5209,7 @@ static int smbchg_prepare_for_pulsing(struct smbchg_chip *chip)

	/* disable HVDCP */
	pr_smb(PR_MISC, "Disable HVDCP\n");
	rc = smbchg_sec_masked_write(chip, chip->usb_chgpth_base + CHGPTH_CFG,
			HVDCP_EN_BIT, 0);
	rc = vote(chip->hvdcp_enable_votable, HVDCP_PULSING_VOTER, true, 0);
	if (rc < 0) {
		pr_err("Couldn't disable HVDCP rc=%d\n", rc);
		goto out;
@@ -5295,9 +5314,7 @@ static int smbchg_unprepare_for_pulsing(struct smbchg_chip *chip)

	/* enable HVDCP */
	pr_smb(PR_MISC, "Enable HVDCP\n");
	rc = smbchg_sec_masked_write(chip,
				chip->usb_chgpth_base + CHGPTH_CFG,
				HVDCP_EN_BIT, HVDCP_EN_BIT);
	rc = vote(chip->hvdcp_enable_votable, HVDCP_PULSING_VOTER, false, 1);
	if (rc < 0) {
		pr_err("Couldn't enable HVDCP rc=%d\n", rc);
		return rc;
@@ -6850,7 +6867,15 @@ static int smbchg_hw_init(struct smbchg_chip *chip)
			chip->revision[ANA_MAJOR], chip->revision[ANA_MINOR]);

	/* Setup 9V HVDCP */
	if (!chip->hvdcp_not_supported) {
	if (chip->hvdcp_not_supported) {
		rc = vote(chip->hvdcp_enable_votable, HVDCP_PMIC_VOTER,
				true, 0);
		if (rc < 0) {
			dev_err(chip->dev, "Couldn't disable HVDCP rc=%d\n",
					rc);
			return rc;
		}
	} else {
		rc = smbchg_sec_masked_write(chip,
				chip->usb_chgpth_base + CHGPTH_CFG,
				HVDCP_ADAPTER_SEL_MASK, HVDCP_9V);
@@ -8147,6 +8172,13 @@ static int smbchg_probe(struct spmi_device *spmi)
	if (IS_ERR(chip->aicl_deglitch_short_votable))
		return PTR_ERR(chip->aicl_deglitch_short_votable);

	chip->hvdcp_enable_votable = create_votable(&spmi->dev,
			"SMBCHG: hvdcp_enable",
			VOTE_MIN, NUM_HVDCP_VOTERS, 1,
			smbchg_hvdcp_enable_cb);
	if (IS_ERR(chip->hvdcp_enable_votable))
		return PTR_ERR(chip->hvdcp_enable_votable);

	INIT_WORK(&chip->usb_set_online_work, smbchg_usb_update_online_work);
	INIT_DELAYED_WORK(&chip->parallel_en_work,
			smbchg_parallel_usb_en_work);
@@ -8406,8 +8438,7 @@ static void smbchg_shutdown(struct spmi_device *spmi)

	/* disable HVDCP */
	pr_smb(PR_MISC, "Disable HVDCP\n");
	rc = smbchg_sec_masked_write(chip, chip->usb_chgpth_base + CHGPTH_CFG,
			HVDCP_EN_BIT, 0);
	rc = vote(chip->hvdcp_enable_votable, HVDCP_PMIC_VOTER, true, 0);
	if (rc < 0)
		pr_err("Couldn't disable HVDCP rc=%d\n", rc);