The string detection sets the test brightness through
wled4_set_brightness(). On WLED5 that writes to unrelated registers and
the detection runs with whatever brightness has been programmed before.

Use the per-version callback and latch the new value on WLED5.

Fixes: 62a1d3f623ac ("backlight: qcom-wled: Add support for WLED5 peripheral 
that is present on PM8150L PMICs")
Assisted-by: LLM
Signed-off-by: Dmitry Baryshkov <[email protected]>
---
 drivers/video/backlight/qcom-wled.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/video/backlight/qcom-wled.c 
b/drivers/video/backlight/qcom-wled.c
index f2e0430cccbc..6fbac6a4c29b 100644
--- a/drivers/video/backlight/qcom-wled.c
+++ b/drivers/video/backlight/qcom-wled.c
@@ -577,6 +577,17 @@ static irqreturn_t wled_short_irq_handler(int irq, void 
*_wled)
 
 #define AUTO_DETECT_BRIGHTNESS         200
 
+static int wled_auto_detect_set_brightness(struct wled *wled, u16 brightness)
+{
+       int rc;
+
+       rc = wled->wled_set_brightness(wled, brightness);
+       if (rc < 0 || wled->version < 5)
+               return rc;
+
+       return wled5_mod_sync_toggle(wled);
+}
+
 static void wled_auto_string_detection(struct wled *wled)
 {
        int rc = 0, i, j, delay_time_us;
@@ -603,7 +614,7 @@ static void wled_auto_string_detection(struct wled *wled)
        }
 
        /* Set low brightness across all sinks */
-       rc = wled4_set_brightness(wled, AUTO_DETECT_BRIGHTNESS);
+       rc = wled_auto_detect_set_brightness(wled, AUTO_DETECT_BRIGHTNESS);
        if (rc < 0) {
                dev_err(wled->dev, "Failed to set brightness for auto detection 
rc=%d\n",
                        rc);
@@ -743,7 +754,7 @@ static void wled_auto_string_detection(struct wled *wled)
        }
 
        /* Restore brightness */
-       rc = wled4_set_brightness(wled, wled->brightness);
+       rc = wled_auto_detect_set_brightness(wled, wled->brightness);
        if (rc < 0) {
                dev_err(wled->dev, "Failed to set brightness after auto 
detection rc=%d\n",
                        rc);

-- 
2.47.3

Reply via email to