From: Amit Barzilai <amit.barzilai22@gmail.com>
To: Javier Martinez Canillas <javierm@redhat.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
Amit Barzilai <amit.barzilai22@gmail.com>
Subject: [PATCH 1/2] drm/ssd130x: Scale ssd133x per-channel contrast by brightness on init
Date: Wed, 29 Jul 2026 08:30:53 +0300 [thread overview]
Message-ID: <20260729053054.29374-2-amit.barzilai22@gmail.com> (raw)
In-Reply-To: <20260729053054.29374-1-amit.barzilai22@gmail.com>
ssd133x_init() wrote the SSD133X_CONTRAST_A/B/C commands with magic hex
values (0x91/0x50/0x7d). These are a per-channel white-balance
calibration: the A/B/C channels drive sub-pixels whose OLED materials
differ in luminous efficiency, so the values set the white point at full
brightness.
Extract them into ssd133x_set_contrast(), which scales each channel by a
requested brightness via ssd130x_scale_contrast(), instead of writing the
calibration unconditionally. This makes the sequence readable, avoids
repetition, and is a prerequisite for wiring up an ssd133x backlight
controller that dims while preserving the white point.
Note this changes the ssd133x power-on brightness. Previously the init
wrote the calibration unscaled and ignored ssd130x->contrast, so the
panel always booted at full brightness. It now scales by the shared
default contrast of 127, i.e. half of MAX_CONTRAST (255). This is
intentional and matches ssd130x, whose contrast register also defaults
to 127 (mid-scale), so all families now power on at ~50% and report
props.brightness = 127 / max_brightness = 255 to userspace.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Amit Barzilai <amit.barzilai22@gmail.com>
---
drivers/gpu/drm/solomon/ssd130x.c | 43 ++++++++++++++++++++++++++++---
1 file changed, 39 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ssd130x.c
index 0940eae7a2e4..f49e5245b216 100644
--- a/drivers/gpu/drm/solomon/ssd130x.c
+++ b/drivers/gpu/drm/solomon/ssd130x.c
@@ -14,6 +14,7 @@
#include <linux/bits.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
+#include <linux/math.h>
#include <linux/property.h>
#include <linux/pwm.h>
#include <linux/regulator/consumer.h>
@@ -140,6 +141,11 @@
#define SSD133X_SET_PRECHARGE_VOLTAGE 0xbb
#define SSD133X_SET_VCOMH_VOLTAGE 0xbe
+/* ssd133x A/B/C channel contrast at full brightness (white balance) */
+#define SSD133X_DEFAULT_CONTRAST_A 0x91
+#define SSD133X_DEFAULT_CONTRAST_B 0x50
+#define SSD133X_DEFAULT_CONTRAST_C 0x7d
+
#define MAX_CONTRAST 255
const struct ssd130x_deviceinfo ssd130x_variants[] = {
@@ -582,12 +588,37 @@ static int ssd132x_init(struct ssd130x_device *ssd130x)
return ssd130x_run_cmd_seq(ssd130x, cmds);
}
-static int ssd133x_init(struct ssd130x_device *ssd130x)
+/* Scale a channel's white-balance calibration contrast by the requested brightness */
+static u8 ssd130x_scale_contrast(u8 calibration, u32 brightness)
+{
+ return DIV_ROUND_CLOSEST(calibration * brightness, MAX_CONTRAST);
+}
+
+/*
+ * The A/B/C contrast channels drive sub-pixels whose OLED materials differ
+ * in luminous efficiency, so the per-channel values are a white-balance
+ * calibration. Scale them by the requested brightness instead of
+ * overwriting them, to keep the white point while dimming.
+ */
+static int ssd133x_set_contrast(struct ssd130x_device *ssd130x, u32 brightness)
{
const u8 cmds[] = {
- 2, SSD133X_CONTRAST_A, 0x91,
- 2, SSD133X_CONTRAST_B, 0x50,
- 2, SSD133X_CONTRAST_C, 0x7d,
+ 2, SSD133X_CONTRAST_A,
+ ssd130x_scale_contrast(SSD133X_DEFAULT_CONTRAST_A, brightness),
+ 2, SSD133X_CONTRAST_B,
+ ssd130x_scale_contrast(SSD133X_DEFAULT_CONTRAST_B, brightness),
+ 2, SSD133X_CONTRAST_C,
+ ssd130x_scale_contrast(SSD133X_DEFAULT_CONTRAST_C, brightness),
+ 0,
+ };
+
+ return ssd130x_run_cmd_seq(ssd130x, cmds);
+}
+
+static int ssd133x_init(struct ssd130x_device *ssd130x)
+{
+ int ret;
+ const u8 cmds[] = {
2, SSD133X_SET_MASTER_CURRENT, 0x06,
3, SSD133X_SET_COL_RANGE, 0x00, ssd130x->width - 1,
3, SSD133X_SET_ROW_RANGE, 0x00, ssd130x->height - 1,
@@ -614,6 +645,10 @@ static int ssd133x_init(struct ssd130x_device *ssd130x)
0,
};
+ ret = ssd133x_set_contrast(ssd130x, ssd130x->contrast);
+ if (ret < 0)
+ return ret;
+
return ssd130x_run_cmd_seq(ssd130x, cmds);
}
--
2.55.0
next prev parent reply other threads:[~2026-07-29 5:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 5:30 [PATCH 0/2] drm/ssd130x: Wire up ssd133x backlight/dimming Amit Barzilai
2026-07-29 5:30 ` Amit Barzilai [this message]
2026-07-30 8:01 ` [PATCH 1/2] drm/ssd130x: Scale ssd133x per-channel contrast by brightness on init Javier Martinez Canillas
2026-07-29 5:30 ` [PATCH 2/2] drm/ssd130x: Add per-family update backlight logic Amit Barzilai
2026-07-30 8:07 ` Javier Martinez Canillas
2026-07-31 7:20 ` [PATCH 0/2] drm/ssd130x: Wire up ssd133x backlight/dimming Javier Martinez Canillas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260729053054.29374-2-amit.barzilai22@gmail.com \
--to=amit.barzilai22@gmail.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=javierm@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®