leds: leds-qpnp: Added in delay for flash LED operation
Flash LEDs require VIN_CHG to reach 5V to fire stabely. Adding delay
between flash enable and assert strobe when flash LEDs are turned on
and between flash strobe desert and module disable provides an improved
proformance. This also simplifies enable sequence so that the current
module enable sequence 0x00 to 0x80 before going to 0xE0 un-necessary.
CRs-Fixed: 539632, 548259
Change-Id: I26472c9ba445f3a311814ede8a821fa580f460b8
Signed-off-by: Chun Zhang <chunz@codeaurora.org>
diff --git a/drivers/leds/leds-qpnp.c b/drivers/leds/leds-qpnp.c
index ecab061..90a5da3 100644
--- a/drivers/leds/leds-qpnp.c
+++ b/drivers/leds/leds-qpnp.c
@@ -24,6 +24,7 @@
#include <linux/qpnp/pwm.h>
#include <linux/workqueue.h>
#include <linux/regulator/consumer.h>
+#include <linux/delay.h>
#define WLED_MOD_EN_REG(base, n) (base + 0x60 + n*0x10)
#define WLED_IDAC_DLY_REG(base, n) (WLED_MOD_EN_REG(base, n) + 0x01)
@@ -96,6 +97,7 @@
#define FLASH_LED_TORCH(base) (base + 0xE4)
#define FLASH_FAULT_DETECT(base) (base + 0x51)
#define FLASH_PERIPHERAL_SUBTYPE(base) (base + 0x05)
+#define FLASH_CURRENT_RAMP(base) (base + 0x54)
#define FLASH_MAX_LEVEL 0x4F
#define TORCH_MAX_LEVEL 0x0F
@@ -114,6 +116,7 @@
#define FLASH_HW_VREG_OK 0x40
#define FLASH_VREG_MASK 0xC0
#define FLASH_STARTUP_DLY_MASK 0x02
+#define FLASH_CURRENT_RAMP_MASK 0xBF
#define FLASH_ENABLE_ALL 0xE0
#define FLASH_ENABLE_MODULE 0x80
@@ -124,6 +127,7 @@
#define FLASH_ENABLE_LED_1 0xA0
#define FLASH_INIT_MASK 0xE0
#define FLASH_SELFCHECK_ENABLE 0x80
+#define FLASH_RAMP_STEP_27US 0xBF
#define FLASH_STROBE_SW 0xC0
#define FLASH_STROBE_HW 0x04
@@ -148,6 +152,9 @@
#define FLASH_SUBTYPE_DUAL 0x01
#define FLASH_SUBTYPE_SINGLE 0x02
+#define FLASH_RAMP_UP_DELAY_US 1000
+#define FLASH_RAMP_DN_DELAY_US 2160
+
#define LED_TRIGGER_DEFAULT "none"
#define RGB_LED_SRC_SEL(base) (base + 0x45)
@@ -840,22 +847,6 @@
rc);
goto error_flash_set;
}
-
- /*
- * Write 0x80 to MODULE_ENABLE before writing
- * 0xE0 in order to avoid a hardware bug caused
- * by register value going from 0x00 to 0xE0.
- */
- rc = qpnp_led_masked_write(led,
- FLASH_ENABLE_CONTROL(led->base),
- FLASH_ENABLE_MODULE_MASK,
- FLASH_ENABLE_MODULE);
- if (rc) {
- dev_err(&led->spmi_dev->dev,
- "Enable reg write failed(%d)\n",
- rc);
- return rc;
- }
}
rc = qpnp_led_masked_write(led,
@@ -972,22 +963,6 @@
goto error_flash_set;
}
- /*
- * Write 0x80 to MODULE_ENABLE before writing
- * 0xE0 in order to avoid a hardware bug caused
- * by register value going from 0x00 to 0xE0.
- */
- rc = qpnp_led_masked_write(led,
- FLASH_ENABLE_CONTROL(led->base),
- FLASH_ENABLE_MODULE_MASK,
- FLASH_ENABLE_MODULE);
- if (rc) {
- dev_err(&led->spmi_dev->dev,
- "Enable reg write failed(%d)\n",
- rc);
- goto error_flash_set;
- }
-
rc = qpnp_led_masked_write(led,
led->flash_cfg->current_addr,
FLASH_CURRENT_MASK,
@@ -1008,6 +983,11 @@
goto error_flash_set;
}
+ /*
+ * Add 1ms delay for bharger enter stable state
+ */
+ usleep(FLASH_RAMP_UP_DELAY_US);
+
if (!led->flash_cfg->strobe_type) {
rc = qpnp_led_masked_write(led,
FLASH_LED_STROBE_CTRL(led->base),
@@ -1088,6 +1068,12 @@
}
}
} else {
+ /*
+ * Disable module after ramp down complete for stable
+ * behavior
+ */
+ usleep(FLASH_RAMP_DN_DELAY_US);
+
rc = qpnp_led_masked_write(led,
FLASH_ENABLE_CONTROL(led->base),
led->flash_cfg->enable_module &
@@ -2168,7 +2154,7 @@
/* Disable flash LED module */
rc = qpnp_led_masked_write(led, FLASH_ENABLE_CONTROL(led->base),
- FLASH_ENABLE_MODULE_MASK, FLASH_DISABLE_ALL);
+ FLASH_ENABLE_MASK, FLASH_DISABLE_ALL);
if (rc) {
dev_err(&led->spmi_dev->dev,
"Enable reg write failed(%d)\n", rc);
@@ -2237,6 +2223,15 @@
return rc;
}
+ /* Set current ramp */
+ rc = qpnp_led_masked_write(led, FLASH_CURRENT_RAMP(led->base),
+ FLASH_CURRENT_RAMP_MASK, FLASH_RAMP_STEP_27US);
+ if (rc) {
+ dev_err(&led->spmi_dev->dev,
+ "Current ramp reg write failed(%d)\n", rc);
+ return rc;
+ }
+
led->flash_cfg->strobe_type = 0;
/* dump flash registers */