leds: qpnp-flash-v2: Add support to control flash ramp time

Add device tree properties "qcom,ramp-up-step" and
"qcom,ramp-down-step", to configure the time steps for
flash ramp up and ramp down.

Change-Id: I80ff9394ab4af29398522a1abbaba991b67db918
Signed-off-by: Jishnu Prakash <jprakash@codeaurora.org>
This commit is contained in:
Jishnu Prakash 2021-04-08 14:50:54 +05:30
parent 601026c787
commit 0899964139

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
* Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
*/
#define pr_fmt(fmt) "flashv2: %s: " fmt, __func__
@ -86,6 +86,14 @@
#define FLASH_LED_REG_THERMAL_DEBOUNCE(base) (base + 0x5A)
#define FLASH_LED_THERMAL_DEBOUNCE_MASK GENMASK(1, 0)
#define FLASH_LED_REG_RGLR_RAMP_RATE(base) (base + 0x5B)
#define FLASH_LED_RAMP_UP_STEP_MASK GENMASK(6, 4)
#define FLASH_LED_RAMP_UP_STEP_SHIFT 4
#define FLASH_LED_RAMP_DOWN_STEP_MASK GENMASK(2, 0)
#define FLASH_LED_RAMP_STEP_MIN_NS 200
#define FLASH_LED_RAMP_STEP_MAX_NS 25600
#define FLASH_LED_RAMP_STEP_DEFAULT_NS 6400
#define FLASH_LED_REG_VPH_DROOP_THRESHOLD(base) (base + 0x61)
#define FLASH_LED_VPH_DROOP_HYSTERESIS_MASK GENMASK(5, 4)
#define FLASH_LED_VPH_DROOP_THRESHOLD_MASK GENMASK(2, 0)
@ -284,6 +292,8 @@ struct flash_led_platform_data {
int thermal_thrsh1;
int thermal_thrsh2;
int thermal_thrsh3;
int ramp_up_step;
int ramp_down_step;
int hw_strobe_option;
u32 led1n2_iclamp_low_ma;
u32 led1n2_iclamp_mid_ma;
@ -653,6 +663,15 @@ static int qpnp_flash_led_init_settings(struct qpnp_flash_led *led)
if (rc < 0)
return rc;
val = led->pdata->ramp_up_step << FLASH_LED_RAMP_UP_STEP_SHIFT;
val |= led->pdata->ramp_down_step;
rc = qpnp_flash_led_masked_write(led,
FLASH_LED_REG_RGLR_RAMP_RATE(led->base),
FLASH_LED_RAMP_UP_STEP_MASK | FLASH_LED_RAMP_DOWN_STEP_MASK,
val);
if (rc < 0)
return rc;
rc = qpnp_flash_led_masked_write(led,
FLASH_LED_REG_VPH_DROOP_DEBOUNCE(led->base),
FLASH_LED_VPH_DROOP_DEBOUNCE_MASK,
@ -2829,6 +2848,28 @@ static int qpnp_flash_led_parse_common_dt(struct qpnp_flash_led *led,
return rc;
}
val = FLASH_LED_RAMP_STEP_DEFAULT_NS;
rc = of_property_read_u32(node, "qcom,ramp-up-step", &val);
if (!rc && (val < FLASH_LED_RAMP_STEP_MIN_NS || val > FLASH_LED_RAMP_STEP_MAX_NS)) {
pr_err("Invalid ramp-up-step %d\n", val);
return -EINVAL;
} else if (rc && rc != -EINVAL) {
pr_err("Unable to read ramp-up-step, rc=%d\n", rc);
return rc;
}
led->pdata->ramp_up_step = ilog2(val / 100) - 1;
val = FLASH_LED_RAMP_STEP_DEFAULT_NS;
rc = of_property_read_u32(node, "qcom,ramp-down-step", &val);
if (!rc && (val < FLASH_LED_RAMP_STEP_MIN_NS || val > FLASH_LED_RAMP_STEP_MAX_NS)) {
pr_err("Invalid ramp-down-step %d\n", val);
return -EINVAL;
} else if (rc && rc != -EINVAL) {
pr_err("Unable to read ramp-down-step, rc=%d\n", rc);
return rc;
}
led->pdata->ramp_down_step = ilog2(val / 100) - 1;
rc = qpnp_flash_led_parse_battery_prop_dt(led, node);
if (rc < 0)
return rc;