[PATCH v5 2/4] backlight: aat2870: Derive brightness steps from max current
From: Svyatoslav Ryhel
Date: Tue Oct 27 2026 - 07:42:20 EST
The AAT2870 allows only 32 steps of brightness, with this amount defined
by the maximum supported current. Remove the need for max_brightness by
calculating the allowed number of steps from the maximum current.
Reviewed-by: Daniel Thompson (RISCstar) <danielt@xxxxxxxxxx>
Signed-off-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx>
---
drivers/video/backlight/aat2870_bl.c | 35 +++++++++-------------------
1 file changed, 11 insertions(+), 24 deletions(-)
diff --git a/drivers/video/backlight/aat2870_bl.c b/drivers/video/backlight/aat2870_bl.c
index 8b790df1e842b..e85f2b4d81068 100644
--- a/drivers/video/backlight/aat2870_bl.c
+++ b/drivers/video/backlight/aat2870_bl.c
@@ -20,22 +20,9 @@ struct aat2870_bl_driver_data {
struct backlight_device *bd;
int channels;
- int max_current;
int brightness; /* current brightness */
};
-static inline int aat2870_brightness(struct aat2870_bl_driver_data *aat2870_bl,
- int brightness)
-{
- struct backlight_device *bd = aat2870_bl->bd;
- int val;
-
- val = brightness * (aat2870_bl->max_current - 1);
- val /= bd->props.max_brightness;
-
- return val;
-}
-
static inline int aat2870_bl_enable(struct aat2870_bl_driver_data *aat2870_bl)
{
struct aat2870_data *aat2870
@@ -69,10 +56,11 @@ static int aat2870_bl_update_status(struct backlight_device *bd)
dev_dbg(&bd->dev, "brightness=%d, power=%d, state=%d\n",
bd->props.brightness, bd->props.power, bd->props.state);
- ret = aat2870->write(aat2870, AAT2870_BLM,
- (u8)aat2870_brightness(aat2870_bl, brightness));
- if (ret < 0)
- return ret;
+ if (brightness) {
+ ret = aat2870->write(aat2870, AAT2870_BLM, (u8)brightness - 1);
+ if (ret < 0)
+ return ret;
+ }
if (brightness == 0) {
ret = aat2870_bl_disable(aat2870_bl);
@@ -145,15 +133,14 @@ static int aat2870_bl_probe(struct platform_device *pdev)
else
aat2870_bl->channels = AAT2870_BL_CH_ALL;
+ /*
+ * The maximum number of brightness steps is determined by the max current.
+ * The aat2870_current enum maps directly to the allowed brightness steps.
+ */
if (pdata->max_current > 0)
- aat2870_bl->max_current = pdata->max_current;
- else
- aat2870_bl->max_current = AAT2870_CURRENT_27_9;
-
- if (pdata->max_brightness > 0)
- bd->props.max_brightness = pdata->max_brightness;
+ bd->props.max_brightness = pdata->max_current;
else
- bd->props.max_brightness = 255;
+ bd->props.max_brightness = AAT2870_CURRENT_27_9;
aat2870_bl->brightness = 0;
bd->props.power = BACKLIGHT_POWER_ON;
--
2.53.0