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. A WLED5 brightness write also only takes
effect once the module sync bit is toggled, which so far was done by
wled_update_status() alone. Toggle it in wled5_set_brightness() instead,
so that every caller of the callback gets the new value.

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

diff --git a/drivers/video/backlight/qcom-wled.c 
b/drivers/video/backlight/qcom-wled.c
index ca350f320e17..c5243a6d547e 100644
--- a/drivers/video/backlight/qcom-wled.c
+++ b/drivers/video/backlight/qcom-wled.c
@@ -269,6 +269,24 @@ static int wled4_set_brightness(struct wled *wled, u16 
brightness)
        return 0;
 }
 
+static int wled5_mod_sync_toggle(struct wled *wled)
+{
+       int rc;
+       u8 val;
+
+       rc = regmap_update_bits(wled->regmap,
+                               wled->sink_addr + WLED5_SINK_REG_MOD_SYNC_BIT,
+                               WLED5_SINK_REG_SYNC_MASK, 0);
+       if (rc < 0)
+               return rc;
+
+       val = (wled->cfg.mod_sel == MOD_A) ? WLED5_SINK_REG_SYNC_MOD_A_BIT :
+                                            WLED5_SINK_REG_SYNC_MOD_B_BIT;
+       return regmap_update_bits(wled->regmap,
+                                 wled->sink_addr + WLED5_SINK_REG_MOD_SYNC_BIT,
+                                 WLED5_SINK_REG_SYNC_MASK, val);
+}
+
 static int wled5_set_brightness(struct wled *wled, u16 brightness)
 {
        int rc, offset;
@@ -287,7 +305,10 @@ static int wled5_set_brightness(struct wled *wled, u16 
brightness)
 
        rc = regmap_bulk_write(wled->regmap, wled->sink_addr + offset,
                               &v, sizeof(v));
-       return rc;
+       if (rc < 0)
+               return rc;
+
+       return wled5_mod_sync_toggle(wled);
 }
 
 static int wled_read_brightness(struct wled *wled)
@@ -391,24 +412,6 @@ static int wled3_sync_toggle(struct wled *wled)
        return rc;
 }
 
-static int wled5_mod_sync_toggle(struct wled *wled)
-{
-       int rc;
-       u8 val;
-
-       rc = regmap_update_bits(wled->regmap,
-                               wled->sink_addr + WLED5_SINK_REG_MOD_SYNC_BIT,
-                               WLED5_SINK_REG_SYNC_MASK, 0);
-       if (rc < 0)
-               return rc;
-
-       val = (wled->cfg.mod_sel == MOD_A) ? WLED5_SINK_REG_SYNC_MOD_A_BIT :
-                                            WLED5_SINK_REG_SYNC_MOD_B_BIT;
-       return regmap_update_bits(wled->regmap,
-                                 wled->sink_addr + WLED5_SINK_REG_MOD_SYNC_BIT,
-                                 WLED5_SINK_REG_SYNC_MASK, val);
-}
-
 static int wled_ovp_fault_status(struct wled *wled, bool *fault_set)
 {
        int rc;
@@ -494,17 +497,6 @@ static int wled_update_status(struct backlight_device *bl)
                                dev_err(wled->dev, "wled sync failed rc:%d\n", 
rc);
                                goto unlock_mutex;
                        }
-               } else {
-                       /*
-                        * For WLED5 toggling the MOD_SYNC_BIT updates the
-                        * brightness
-                        */
-                       rc = wled5_mod_sync_toggle(wled);
-                       if (rc < 0) {
-                               dev_err(wled->dev, "wled mod sync failed 
rc:%d\n",
-                                       rc);
-                               goto unlock_mutex;
-                       }
                }
        }
 
@@ -651,7 +643,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->wled_set_brightness(wled, AUTO_DETECT_BRIGHTNESS);
        if (rc < 0) {
                dev_err(wled->dev, "Failed to set brightness for auto detection 
rc=%d\n",
                        rc);
@@ -791,7 +783,7 @@ static void wled_auto_string_detection(struct wled *wled)
        }
 
        /* Restore brightness */
-       rc = wled4_set_brightness(wled, wled->brightness);
+       rc = wled->wled_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