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

Commit 012018f2 authored by Zhenhua Huang's avatar Zhenhua Huang Committed by Fenglin Wu
Browse files

power: smb1360: Add an optional property to set OTG current threshold



Add an optional property to set the current draw from battery when
device working at OTG mode.

CRs-Fixed: 695044
Change-Id: I2167c7e58bfb6cb81741e3ea000197a9e1751fcf
Signed-off-by: default avatarZhenhua Huang <zhenhuah@codeaurora.org>
Signed-off-by: default avatarFenglin Wu <fenglinw@codeaurora.org>
parent ccc80175
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -97,6 +97,9 @@ Optional Properties:
				thermistor inside the battery. This value is
				16-bit float encoded value determined from the
				NTC-c1_coeff mapping.
- qcom,otg-batt-curr-limit	This property defines the current threshold draw
				from battery when device working at OTG mode.
				The possible values are: 350, 550, 950, 1500mA.

Example:
	i2c@f9967000 {
@@ -133,5 +136,7 @@ Example:
			qcom,fg-soc-max = <85>;
			qcom,fg-soc-min = <15>;
			qcom,thermal-mitigation = <1500 700 300 0>;

			qcom,otg-batt-curr-limit = <950>;
		};
	};
+26 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@
#define CHG_ITERM_200MA			0x7
#define RECHG_MV_MASK			SMB1360_MASK(6, 5)
#define RECHG_MV_SHIFT			5
#define OTG_CURRENT_MASK		SMB1360_MASK(4, 3)
#define OTG_CURRENT_SHIFT		3

#define CFG_BATT_CHG_ICL_REG		0x05
#define AC_INPUT_ICL_PIN_BIT		BIT(7)
@@ -240,6 +242,8 @@ enum {
	BATTERY_PROFILE_MAX,
};

static int otg_curr_ma[] = {350, 550, 950, 1500};

struct smb1360_otg_regulator {
	struct regulator_desc	rdesc;
	struct regulator_dev	*rdev;
@@ -269,6 +273,7 @@ struct smb1360_chip {
	unsigned int			thermal_levels;
	unsigned int			therm_lvl_sel;
	unsigned int			*thermal_mitigation;
	int				otg_batt_curr_limit;

	/* configuration data - fg */
	int				soc_max;
@@ -2992,6 +2997,22 @@ static int smb1360_hw_init(struct smb1360_chip *chip)
		}
	}

	/* USB OTG current limit configuration */
	if (chip->otg_batt_curr_limit != -EINVAL) {
		for (i = 0; i < ARRAY_SIZE(otg_curr_ma); i++) {
			if (otg_curr_ma[i] >= chip->otg_batt_curr_limit)
				break;
		}

		if (i == ARRAY_SIZE(otg_curr_ma))
			i = i - 1;

		rc = smb1360_masked_write(chip, CFG_BATT_CHG_REG,
						OTG_CURRENT_MASK,
					i << OTG_CURRENT_SHIFT);
		if (rc)
			pr_err("Couldn't set OTG current limit, rc = %d\n", rc);
	}

	rc = smb1360_fg_config(chip);
	if (rc < 0) {
@@ -3222,6 +3243,11 @@ static int smb_parse_dt(struct smb1360_chip *chip)
	if (rc < 0)
		chip->fg_cc_to_cv_mv = -EINVAL;

	rc = of_property_read_u32(node, "qcom,otg-batt-curr-limit",
					&chip->otg_batt_curr_limit);
	if (rc < 0)
		chip->otg_batt_curr_limit = -EINVAL;

	return 0;
}