From 1a00e832874e00ef8fdf058156f872536771ec05 Mon Sep 17 00:00:00 2001 From: Guru Das Srinagesh Date: Tue, 7 Jul 2020 15:15:01 -0700 Subject: [PATCH 1/2] leds: qti-flash: Fix debug prints, read more than one byte Print the data instead of the pointer in qti_flash_led_write(), update the print in qti_flash_led_masked_write(), and fix qti_flash_led_read() so that it returns a pointer to more than one byte. Change-Id: Ic9cbc35a6552f8978ff9e36da2aafeec69885b9a Signed-off-by: Guru Das Srinagesh --- drivers/leds/leds-qti-flash.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/leds/leds-qti-flash.c b/drivers/leds/leds-qti-flash.c index cf7ef0c8a7d4..743a44e6598e 100644 --- a/drivers/leds/leds-qti-flash.c +++ b/drivers/leds/leds-qti-flash.c @@ -235,17 +235,14 @@ static int qti_flash_led_read(struct qti_flash_led *led, u16 offset, u8 *data, u8 len) { int rc; - u32 val; - rc = regmap_bulk_read(led->regmap, (led->base + offset), &val, len); - if (rc < 0) { + rc = regmap_bulk_read(led->regmap, (led->base + offset), data, len); + if (rc < 0) pr_err("Failed to read from 0x%04X rc = %d\n", (led->base + offset), rc); - } else { - pr_debug("Read 0x%02X from addr 0x%04X\n", val, + else + pr_debug("Read %*ph from addr %#x\n", len, data, (led->base + offset)); - *data = (u8)val; - } return rc; } @@ -261,7 +258,7 @@ static int qti_flash_led_write(struct qti_flash_led *led, u16 offset, pr_err("Failed to write to 0x%04X rc = %d\n", (led->base + offset), rc); else - pr_debug("Wrote 0x%02X to addr 0x%04X\n", data, + pr_debug("Wrote %*ph to addr %#x\n", len, data, (led->base + offset)); return rc; @@ -278,7 +275,7 @@ static int qti_flash_led_masked_write(struct qti_flash_led *led, pr_err("Failed to update bits from 0x%04X, rc = %d\n", (led->base + offset), rc); else - pr_debug("Wrote 0x%02X to addr 0x%04X\n", data, + pr_debug("Wrote %#x mask %#x to addr %#x\n", data, mask, (led->base + offset)); return rc; From ab808011adbe3cee19c5931ab7f920d1842e6fbb Mon Sep 17 00:00:00 2001 From: Guru Das Srinagesh Date: Tue, 7 Jul 2020 15:19:13 -0700 Subject: [PATCH 2/2] leds: qti-flash: Support zero duration for flash safety timer The minimum timeout that can be set is 10 ms due to the clamping being done in led_set_flash_timeout() in the flash LED class framework. Change the minimum to allow zero timeout to be set, and also disallow setting strobe in this case. Change-Id: Ic34057197c05daf640c2a7d21cbae8e4638319ee Signed-off-by: Guru Das Srinagesh --- drivers/leds/leds-qti-flash.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/leds/leds-qti-flash.c b/drivers/leds/leds-qti-flash.c index 743a44e6598e..ae49f5bf4c97 100644 --- a/drivers/leds/leds-qti-flash.c +++ b/drivers/leds/leds-qti-flash.c @@ -205,8 +205,7 @@ static const u32 flash_led_max_ires_values[MAX_IRES_LEVELS] = { static int timeout_to_code(u32 timeout) { - if (timeout < SAFETY_TIMER_MIN_TIMEOUT_MS || - timeout > SAFETY_TIMER_MAX_TIMEOUT_MS) + if (!timeout || timeout > SAFETY_TIMER_MAX_TIMEOUT_MS) return -EINVAL; return DIV_ROUND_CLOSEST(timeout, SAFETY_TIMER_STEP_SIZE) - 1; @@ -1120,6 +1119,11 @@ static int qti_flash_strobe_set(struct led_classdev_flash *fdev, if (state && !fnode->configured) return -EINVAL; + if (!fnode->duration) { + pr_debug("Safety time duration is zero, strobe not set\n"); + return -EINVAL; + } + mask = FLASH_LED_ENABLE(fnode->id); value = state ? FLASH_LED_ENABLE(fnode->id) : 0; @@ -1162,6 +1166,11 @@ static int qti_flash_timeout_set(struct led_classdev_flash *fdev, fnode = container_of(fdev, struct flash_node_data, fdev); led = fnode->led; + if (!timeout) { + fnode->duration = 0; + return 0; + } + timeout = timeout / 1000; rc = timeout_to_code(timeout); @@ -1504,7 +1513,7 @@ static int register_flash_device(struct qti_flash_led *led, setting->val = default_curr_ma; setting = &fnode->fdev.timeout; - setting->min = SAFETY_TIMER_MIN_TIMEOUT_MS * 1000; + setting->min = 0; setting->max = SAFETY_TIMER_MAX_TIMEOUT_MS * 1000; setting->step = SAFETY_TIMER_STEP_SIZE * 1000; setting->val = SAFETY_TIMER_DEFAULT_TIMEOUT_MS * 1000;