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

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

Merge "power: smb5: Fix ITERM thresholds configuration"

parents f3333b06 59edf872
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -1516,8 +1516,9 @@ static int smb5_configure_micro_usb(struct smb_charger *chg)

static int smb5_configure_iterm_thresholds_adc(struct smb5 *chip)
{
	u8 *buf;
	int rc = 0;
	int raw_hi_thresh, raw_lo_thresh;
	s16 raw_hi_thresh, raw_lo_thresh;
	struct smb_charger *chg = &chip->chg;

	if (chip->dt.term_current_thresh_hi_ma < -10000 ||
@@ -1531,12 +1532,15 @@ static int smb5_configure_iterm_thresholds_adc(struct smb5 *chip)
	/*
	 * Conversion:
	 *	raw (A) = (scaled_mA * ADC_CHG_TERM_MASK) / (10 * 1000)
	 * Note: raw needs to be converted to big-endian format.
	 */

	if (chip->dt.term_current_thresh_hi_ma) {
		raw_hi_thresh = ((chip->dt.term_current_thresh_hi_ma *
						ADC_CHG_TERM_MASK) / 10000);
		raw_hi_thresh = sign_extend32(raw_hi_thresh, 15);
		buf = (u8 *)&raw_hi_thresh;
		raw_hi_thresh = buf[1] | (buf[0] << 8);

		rc = smblib_batch_write(chg, CHGR_ADC_ITERM_UP_THD_MSB_REG,
				(u8 *)&raw_hi_thresh, 2);
@@ -1551,6 +1555,8 @@ static int smb5_configure_iterm_thresholds_adc(struct smb5 *chip)
		raw_lo_thresh = ((chip->dt.term_current_thresh_lo_ma *
					ADC_CHG_TERM_MASK) / 10000);
		raw_lo_thresh = sign_extend32(raw_lo_thresh, 15);
		buf = (u8 *)&raw_lo_thresh;
		raw_lo_thresh = buf[1] | (buf[0] << 8);

		rc = smblib_batch_write(chg, CHGR_ADC_ITERM_LO_THD_MSB_REG,
				(u8 *)&raw_lo_thresh, 2);
+3 −3
Original line number Diff line number Diff line
@@ -1561,7 +1561,7 @@ int smblib_get_prop_batt_iterm(struct smb_charger *chg,
		union power_supply_propval *val)
{
	int rc, temp;
	u8 stat;
	u8 stat, buf[2];

	/*
	 * Currently, only ADC comparator-based termination is supported,
@@ -1580,8 +1580,7 @@ int smblib_get_prop_batt_iterm(struct smb_charger *chg,
		return 0;
	}

	rc = smblib_batch_read(chg, CHGR_ADC_ITERM_UP_THD_MSB_REG,
			(u8 *)&temp, 2);
	rc = smblib_batch_read(chg, CHGR_ADC_ITERM_UP_THD_MSB_REG, buf, 2);

	if (rc < 0) {
		smblib_err(chg, "Couldn't read CHGR_ADC_ITERM_UP_THD_MSB_REG rc=%d\n",
@@ -1589,6 +1588,7 @@ int smblib_get_prop_batt_iterm(struct smb_charger *chg,
		return rc;
	}

	temp = buf[1] | (buf[0] << 8);
	temp = sign_extend32(temp, 15);
	temp = DIV_ROUND_CLOSEST(temp * 10000, ADC_CHG_TERM_MASK);
	val->intval = temp;