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

Commit 169fd1f5 authored by Devesh Jhunjhunwala's avatar Devesh Jhunjhunwala Committed by Subbaraman Narayanamurthy
Browse files

leds: qpnp-flash-v2: Add support for preemptive charger mitigation



Add support to configure and trigger preemptive charger
mitigation in flash driver.

Change-Id: Iec92d2037fcc60446760182c9eda53918e6e094c
Signed-off-by: default avatarDevesh Jhunjhunwala <deveshj@codeaurora.org>
parent 889d937b
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -38,17 +38,23 @@ Optional properties:
				  Default value is 4500000 uA.
- qcom,rparasitic-uohm		: Integer property for flash current predictive mitigation indicating
				  parasitic component of battery resistance. Default value is 0 uOhm.
- qcom,lmh-ocv-threshold-uv	: Required property for flash current preemptive mitigation.
- qcom,lmh-ocv-threshold-uv	: Required property for flash current preemptive LMH mitigation.
				  Default value is 3700000 uV.
- qcom,lmh-rbatt-threshold-uohm	: Required property for flash current preemptive mitigation.
- qcom,lmh-rbatt-threshold-uohm	: Required property for flash current preemptive LMH mitigation.
				  Default value is 400000 uOhm.
- qcom,lmh-mitigation-sel	: Optional property to configure flash current preemptive mitigation.
- qcom,lmh-mitigation-sel	: Optional property to configure flash current preemptive LMH mitigation.
				  Accepted values are:
				  0: MITIGATION_DISABLED
				  1: MITIGATION_BY_ILED_THRESHOLD
				  2: MITIGATION_BY_SW
				  Default value is 2.
- qcom,lmh-level		: Optional property to configure flash current preemptive mitigation.
- qcom,chgr-mitigation-sel	: Optional property to configure flash current preemptive charger mitigation.
				  Accepted values are:
				  0: MITIGATION_DISABLED
				  1: MITIGATION_BY_ILED_THRESHOLD
				  2: MITIGATION_BY_SW
				  Default value is 2.
- qcom,lmh-level		: Optional property to configure flash current preemptive LMH mitigation.
				  Accepted values are 0, 1, and 3. Default value is 0.
- qcom,iled-thrsh-ma		: Optional property to configure the led current threshold at which HW
				  preemptive mitigation is triggered. Unit is mA. Default value is 1000.
+63 −5
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@
#define	FLASH_LED_ISC_WARMUP_DELAY_MASK		GENMASK(1, 0)
#define	FLASH_LED_CURRENT_DERATE_EN_MASK	GENMASK(2, 0)
#define	FLASH_LED_VPH_DROOP_DEBOUNCE_MASK	GENMASK(1, 0)
#define	FLASH_LED_CHGR_MITIGATION_SEL_MASK	GENMASK(5, 4)
#define	FLASH_LED_LMH_MITIGATION_SEL_MASK	GENMASK(1, 0)
#define	FLASH_LED_ILED_GRT_THRSH_MASK		GENMASK(5, 0)
#define	FLASH_LED_LMH_LEVEL_MASK		GENMASK(1, 0)
@@ -70,11 +71,11 @@
#define	FLASH_LED_VPH_DROOP_THRESHOLD_MASK	GENMASK(2, 0)
#define	FLASH_LED_THERMAL_THRSH_MASK		GENMASK(2, 0)
#define	FLASH_LED_THERMAL_OTST_MASK		GENMASK(2, 0)
#define	FLASH_LED_PREPARE_OPTIONS_MASK		GENMASK(2, 0)
#define	FLASH_LED_MOD_CTRL_MASK			BIT(7)
#define	FLASH_LED_HW_SW_STROBE_SEL_MASK		BIT(2)
#define	FLASH_LED_VPH_DROOP_FAULT_MASK		BIT(4)
#define	FLASH_LED_LMH_MITIGATION_EN_MASK	BIT(0)
#define	FLASH_LED_CHGR_MITIGATION_EN_MASK	BIT(4)

#define	VPH_DROOP_DEBOUNCE_US_TO_VAL(val_us)	(val_us / 8)
#define	VPH_DROOP_HYST_MV_TO_VAL(val_mv)	(val_mv / 25)
@@ -102,8 +103,11 @@
#define	FLASH_LED_LMH_LEVEL_DEFAULT		0
#define	FLASH_LED_LMH_MITIGATION_ENABLE		1
#define	FLASH_LED_LMH_MITIGATION_DISABLE	0
#define	FLASH_LED_LMH_MITIGATION_SEL_DEFAULT	2
#define	FLASH_LED_LMH_MITIGATION_SEL_MAX	2
#define	FLASH_LED_CHGR_MITIGATION_ENABLE	BIT(4)
#define	FLASH_LED_CHGR_MITIGATION_DISABLE	0
#define	FLASH_LED_MITIGATION_SEL_DEFAULT	2
#define	FLASH_LED_MITIGATION_SEL_MAX		2
#define	FLASH_LED_CHGR_MITIGATION_SEL_SHIFT	4
#define	FLASH_LED_MITIGATION_THRSH_DEFAULT	0xA
#define	FLASH_LED_MITIGATION_THRSH_MAX		0x1F
#define	FLASH_LED_LMH_OCV_THRESH_DEFAULT_UV	3700000
@@ -204,6 +208,7 @@ struct flash_led_platform_data {
	u8	vph_droop_hysteresis;
	u8	vph_droop_debounce;
	u8	lmh_mitigation_sel;
	u8	chgr_mitigation_sel;
	u8	lmh_level;
	u8	iled_thrsh_val;
	u8	hw_strobe_option;
@@ -228,6 +233,7 @@ struct qpnp_flash_led {
	int				enable;
	u16				base;
	bool				trigger_lmh;
	bool				trigger_chgr;
};

static int
@@ -357,6 +363,13 @@ static int qpnp_flash_led_init_settings(struct qpnp_flash_led *led)
	if (rc < 0)
		return rc;

	rc = qpnp_flash_led_masked_write(led,
			FLASH_LED_REG_MITIGATION_SEL(led->base),
			FLASH_LED_CHGR_MITIGATION_SEL_MASK,
			led->pdata->chgr_mitigation_sel);
	if (rc < 0)
		return rc;

	rc = qpnp_flash_led_masked_write(led,
			FLASH_LED_REG_LMH_LEVEL(led->base),
			FLASH_LED_LMH_LEVEL_MASK,
@@ -752,6 +765,18 @@ static int qpnp_flash_led_switch_disable(struct flash_switch_data *snode)
		}
	}

	if (!led->trigger_chgr) {
		rc = qpnp_flash_led_masked_write(led,
				FLASH_LED_REG_MITIGATION_SW(led->base),
				FLASH_LED_CHGR_MITIGATION_EN_MASK,
				FLASH_LED_CHGR_MITIGATION_DISABLE);
		if (rc < 0) {
			dev_err(&led->pdev->dev, "disable chgr mitigation failed, rc=%d\n",
				rc);
			return rc;
		}
	}

	led->enable--;
	if (led->enable == 0) {
		rc = qpnp_flash_led_masked_write(led,
@@ -905,6 +930,18 @@ static int qpnp_flash_led_switch_set(struct flash_switch_data *snode, bool on)
		}
	}

	if (led->trigger_chgr) {
		rc = qpnp_flash_led_masked_write(led,
				FLASH_LED_REG_MITIGATION_SW(led->base),
				FLASH_LED_CHGR_MITIGATION_EN_MASK,
				FLASH_LED_CHGR_MITIGATION_ENABLE);
		if (rc < 0) {
			dev_err(&led->pdev->dev, "trigger chgr mitigation failed, rc=%d\n",
				rc);
			return rc;
		}
	}

	rc = qpnp_flash_led_masked_write(led,
					FLASH_LED_EN_LED_CTRL(led->base),
					snode->led_mask, val);
@@ -964,6 +1001,10 @@ int qpnp_flash_led_prepare(struct led_trigger *trig, int options,
		*max_current = rc;
	}

	led->trigger_chgr = false;
	if (options & PRE_FLASH)
		led->trigger_chgr = true;

	return 0;
}

@@ -1662,7 +1703,7 @@ static int qpnp_flash_led_parse_common_dt(struct qpnp_flash_led *led,
		return rc;
	}

	led->pdata->lmh_mitigation_sel = FLASH_LED_LMH_MITIGATION_SEL_DEFAULT;
	led->pdata->lmh_mitigation_sel = FLASH_LED_MITIGATION_SEL_DEFAULT;
	rc = of_property_read_u32(node, "qcom,lmh-mitigation-sel", &val);
	if (!rc) {
		led->pdata->lmh_mitigation_sel = val;
@@ -1672,11 +1713,28 @@ static int qpnp_flash_led_parse_common_dt(struct qpnp_flash_led *led,
		return rc;
	}

	if (led->pdata->lmh_mitigation_sel > FLASH_LED_LMH_MITIGATION_SEL_MAX) {
	if (led->pdata->lmh_mitigation_sel > FLASH_LED_MITIGATION_SEL_MAX) {
		dev_err(&led->pdev->dev, "Invalid lmh_mitigation_sel specified\n");
		return -EINVAL;
	}

	led->pdata->chgr_mitigation_sel = FLASH_LED_MITIGATION_SEL_DEFAULT;
	rc = of_property_read_u32(node, "qcom,chgr-mitigation-sel", &val);
	if (!rc) {
		led->pdata->chgr_mitigation_sel = val;
	} else if (rc != -EINVAL) {
		dev_err(&led->pdev->dev, "Unable to parse chgr_mitigation_sel, rc=%d\n",
				rc);
		return rc;
	}

	if (led->pdata->chgr_mitigation_sel > FLASH_LED_MITIGATION_SEL_MAX) {
		dev_err(&led->pdev->dev, "Invalid chgr_mitigation_sel specified\n");
		return -EINVAL;
	}

	led->pdata->chgr_mitigation_sel <<= FLASH_LED_CHGR_MITIGATION_SEL_SHIFT;

	led->pdata->iled_thrsh_val = FLASH_LED_MITIGATION_THRSH_DEFAULT;
	rc = of_property_read_u32(node, "qcom,iled-thrsh-ma", &val);
	if (!rc) {
+3 −0
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@
#define ENABLE_REGULATOR	BIT(0)
#define DISABLE_REGULATOR	BIT(1)
#define QUERY_MAX_CURRENT	BIT(2)
#define PRE_FLASH		BIT(3)

#define FLASH_LED_PREPARE_OPTIONS_MASK	GENMASK(3, 0)

int qpnp_flash_led_prepare(struct led_trigger *trig, int options,
					int *max_current);