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

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

Merge "leds: qti-flash: Fix LMH mitigation configuration"

parents 1fee8394 42bdecad
Loading
Loading
Loading
Loading
+120 −86
Original line number Diff line number Diff line
@@ -66,9 +66,8 @@
#define  FLASH_LED_ENABLE(id)			BIT(id)
#define  FLASH_LED_DISABLE			0

#define FLASH_LED_MITIGATION_SEL		0x63
#define  FLASH_LED_PREEMPTIVE_LMH_MASK	GENMASK(1, 0)
#define  FLASH_LED_LMH_MITIGATION_SW		0x2
#define FLASH_LED_MITIGATION_SW			0x65
#define  FLASH_LED_LMH_MITIGATION_SW_EN		BIT(0)

#define FLASH_LED_THERMAL_OTST2_CFG1		0x78
#define FLASH_LED_THERMAL_OTST1_CFG1		0x7A
@@ -86,9 +85,6 @@
#define IRES_DEFAULT_UA				IRES_12P5_UA
#define MAX_FLASH_CURRENT_MA			2000
#define IBATT_OCP_THRESH_DEFAULT_UA		4500000
#define FLASH_THERMAL_LEVELS		2
#define OTST1_IDX		0
#define OTST2_IDX		1
#define OTST1_CURR_LIM_MA			200
#define OTST2_CURR_LIM_MA			500
#define VLED_MAX_DEFAULT_UV			3500000
@@ -112,6 +108,12 @@ enum strobe_type {
	HW_STROBE,
};

enum thermal_levels {
	OTST1_IDX,
	OTST2_IDX,
	OTST_MAX,
};

struct flash_node_data {
	struct qti_flash_led		*led;
	struct led_classdev_flash	fdev;
@@ -151,7 +153,8 @@ struct flash_switch_data {
 * @snode:			Pointer for array of child switch devices
 * @batt_psy:			Pointer for battery power supply
 * @lock:			Spinlock to be used for critical section
 * @num_fnodes		: Number of flash/torch nodes defined in device tree
 * @num_fnodes:			Number of flash/torch nodes defined in device
 *				tree
 * @num_snodes:			Number of switch nodes defined in device tree
 * @hw_strobe_gpio:		Pointer for array of GPIOs for HW strobing
 * @all_ramp_up_done_irq:	IRQ number for all ramp up interrupt
@@ -162,7 +165,8 @@ struct flash_switch_data {
 * @base:			Base address of the flash LED module
 * @revision:			Revision of the flash LED module
 * @subtype:			Peripheral subtype of the flash LED module
 * @max_channels	: Maximum number of channels supported by flash module
 * @max_channels:		Maximum number of channels supported by flash
 *				module
 * @chan_en_map:		Bit map of individual channel enable
 * @module_en:			Flag used to enable/disable flash LED module
 * @trigger_lmh:		Flag to enable lmh mitigation
@@ -181,7 +185,7 @@ struct qti_flash_led {
	int				all_ramp_down_done_irq;
	int				led_fault_irq;
	int				max_current;
	int			thermal_derate_current[FLASH_THERMAL_LEVELS];
	int				thermal_derate_current[OTST_MAX];
	u16				base;
	u8				revision;
	u8				subtype;
@@ -312,6 +316,23 @@ static int qti_flash_led_module_control(struct qti_flash_led *led,
	return rc;
}

static int qti_flash_lmh_mitigation_config(struct qti_flash_led *led,
						bool enable)
{
	u8 val = enable ? FLASH_LED_LMH_MITIGATION_SW_EN : 0;
	int rc;

	rc = qti_flash_led_write(led, FLASH_LED_MITIGATION_SW, &val, 1);
	if (rc < 0)
		pr_err("Failed to %s LMH mitigation, rc=%d\n",
			enable ? "enable" : "disable", rc);
	else
		pr_debug("%s LMH mitigation\n",
			enable ? "enabled" : "disabled");

	return rc;
}

static int qti_flash_led_strobe(struct qti_flash_led *led,
				struct flash_switch_data *snode,
				u8 mask, u8 value)
@@ -338,6 +359,15 @@ static int qti_flash_led_strobe(struct qti_flash_led *led,
					HRTIMER_MODE_REL);
		}

		if (led->trigger_lmh) {
			rc = qti_flash_lmh_mitigation_config(led, true);
			if (rc < 0)
				return rc;

			/* Wait for LMH mitigation to take effect */
			udelay(500);
		}

		rc = qti_flash_led_masked_write(led, FLASH_EN_LED_CTRL,
				mask, value);
		if (rc < 0)
@@ -353,6 +383,14 @@ static int qti_flash_led_strobe(struct qti_flash_led *led,
		if (rc < 0)
			goto error;

		if (led->trigger_lmh) {
			rc = qti_flash_lmh_mitigation_config(led, false);
			if (rc < 0)
				return rc;

			led->trigger_lmh = false;
		}

		rc = qti_flash_led_module_control(led, enable);
		if (rc < 0)
			goto error;
@@ -865,13 +903,9 @@ static int qti_flash_led_calc_max_avail_current(
	vflash_vdip = VDIP_THRESH_DEFAULT_UV;

	if (!led->trigger_lmh) {
		rc = qti_flash_led_masked_write(led, FLASH_LED_MITIGATION_SEL,
			FLASH_LED_PREEMPTIVE_LMH_MASK,
			FLASH_LED_LMH_MITIGATION_SW);
		if (rc < 0) {
			pr_err("Failed to enable LMH mitigation, rc=%d\n", rc);
		rc = qti_flash_lmh_mitigation_config(led, true);
		if (rc < 0)
			return rc;
		}

		/* Wait for lmh mitigation to take effect */
		udelay(100);