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

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

Merge "leds: leds-qpnp-flash: detect open circuit fault in LED usage"

parents 3d9c48e0 be702573
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@
#define	FLASH_LED_CURRENT_READING_DELAY_MIN			5000
#define	FLASH_LED_CURRENT_READING_DELAY_MAX			5001
#define PMI8996_SUBTYPE						19
#define	FLASH_LED_OPEN_FAULT_DETECTED				0xC

#define FLASH_UNLOCK_SECURE					0xA5
#define FLASH_LED_TORCH_ENABLE					0x00
@@ -256,6 +257,7 @@ struct qpnp_flash_led {
	bool				charging_enabled;
	bool				strobe_debug;
	bool				dbg_feature_en;
	bool				open_fault;
};

static u8 qpnp_flash_led_ctrl_dbg_regs[] = {
@@ -1188,6 +1190,12 @@ static void qpnp_flash_led_work(struct work_struct *work)
	if (!brightness)
		goto turn_off;

	if (led->open_fault) {
		dev_err(&led->spmi_dev->dev, "Open fault detected\n");
		mutex_unlock(&led->flash_led_lock);
		return;
	}

	if (!flash_node->flash_on && flash_node->num_regulators > 0) {
		rc = flash_regulator_enable(led, flash_node, true);
		if (rc) {
@@ -1648,6 +1656,24 @@ static void qpnp_flash_led_work(struct work_struct *work)
	return;

turn_off:
	if (flash_node->type == TORCH) {
		/*
		 * Checking LED fault status detects hardware open fault.
		 * If fault occurs, all subsequent LED enablement requests
		 * will be rejected to protect hardware.
		 */
		rc = spmi_ext_register_readl(led->spmi_dev->ctrl,
			led->spmi_dev->sid,
			FLASH_LED_FAULT_STATUS(led->base), &val, 1);
		if (rc) {
			dev_err(&led->spmi_dev->dev,
				"Failed to read out fault status register\n");
			goto exit_flash_led_work;
		}

		led->open_fault = (val & FLASH_LED_OPEN_FAULT_DETECTED);
	}

	rc = qpnp_led_masked_write(led->spmi_dev,
			FLASH_LED_STROBE_CTRL(led->base),
			(flash_node->id == FLASH_LED_SWITCH ? FLASH_STROBE_MASK