diff options
| author | Chun Zhang <chunz@codeaurora.org> | 2016-04-05 23:36:54 -0700 |
|---|---|---|
| committer | Kyle Yan <kyan@codeaurora.org> | 2016-07-11 18:56:22 -0700 |
| commit | 01d202d756900e3f0f88bf9b184dbcad6874b41b (patch) | |
| tree | 137cbf095c8dd5ed864458284d73622a7d7f02d9 | |
| parent | 9eb8b67fe9eef65412d630e0ab3d90300a601450 (diff) | |
leds: qpnp-flash-v2: add callback for max current query
Flash LED is a high energy aggregator from system as it is capable
to provide current up to 3750mA for illumination. Therefore, it
should be used with caution especially when battery state of charge
is low. Therefore, add a function which can be used by clients like
camera to query the flash current limit before using flash LED. This
protects the system from a possible UVLO condition.
CRs-Fixed: 964855
Change-Id: I17fa4f28cc151e3a3ad89d284995a3fa770bec68
Signed-off-by: Chun Zhang <chunz@codeaurora.org>
Signed-off-by: Devesh Jhunjhunwala <deveshj@codeaurora.org>
| -rw-r--r-- | drivers/leds/leds-qpnp-flash-v2.c | 45 | ||||
| -rw-r--r-- | include/linux/leds-qpnp-flash-v2.h | 5 |
2 files changed, 50 insertions, 0 deletions
diff --git a/drivers/leds/leds-qpnp-flash-v2.c b/drivers/leds/leds-qpnp-flash-v2.c index 2bd60ce13f83..95bda28713f8 100644 --- a/drivers/leds/leds-qpnp-flash-v2.c +++ b/drivers/leds/leds-qpnp-flash-v2.c @@ -193,6 +193,18 @@ static int qpnp_flash_led_hw_strobe_enable(struct flash_node_data *fnode, return rc; } +static int qpnp_flash_led_regulator_enable(struct qpnp_flash_led *led, + struct flash_switch_data *snode, bool on) +{ + return 0; +} + +static int qpnp_flash_led_get_max_avail_current(struct flash_switch_data *snode, + struct qpnp_flash_led *led) +{ + return 3750; +} + static void qpnp_flash_led_node_set(struct flash_node_data *fnode, int value) { int prgm_current_ma = value; @@ -342,6 +354,39 @@ leds_turn_off: return 0; } +int qpnp_flash_led_prepare(struct led_classdev *led_cdev, int options) +{ + struct flash_switch_data *snode = + container_of(led_cdev, struct flash_switch_data, cdev); + struct qpnp_flash_led *led = dev_get_drvdata(&snode->pdev->dev); + int rc, val = 0; + + if (!(options & (ENABLE_REGULATOR | QUERY_MAX_CURRENT))) { + dev_err(&led->pdev->dev, "Invalid options %d\n", options); + return -EINVAL; + } + + if (options & ENABLE_REGULATOR) { + rc = qpnp_flash_led_regulator_enable(led, snode, true); + if (rc < 0) { + dev_err(&led->pdev->dev, + "enable regulator failed, rc=%d\n", rc); + return rc; + } + } + + if (options & QUERY_MAX_CURRENT) { + val = qpnp_flash_led_get_max_avail_current(snode, led); + if (val < 0) { + dev_err(&led->pdev->dev, + "query max current failed, rc=%d\n", val); + return val; + } + } + + return val; +} + static void qpnp_flash_led_brightness_set(struct led_classdev *led_cdev, enum led_brightness value) { diff --git a/include/linux/leds-qpnp-flash-v2.h b/include/linux/leds-qpnp-flash-v2.h index c1e841689b55..38d3c9887354 100644 --- a/include/linux/leds-qpnp-flash-v2.h +++ b/include/linux/leds-qpnp-flash-v2.h @@ -16,6 +16,9 @@ #include <linux/leds.h> #include "leds.h" +#define ENABLE_REGULATOR BIT(0) +#define QUERY_MAX_CURRENT BIT(1) + /* * Configurations for each individual LED */ @@ -46,4 +49,6 @@ struct flash_switch_data { struct led_classdev cdev; }; +int qpnp_flash_led_prepare(struct led_classdev *led_cdev, int options); + #endif |
