Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Documentation/ABI/testing/sysfs-class-backlight-google-tg4c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
What: /sys/class/backlight/<backlight>/local_hbm_mode
Date: October 2026
KernelVersion: 7.3
Contact: W4HO <87742609+W4HO-ham@users.noreply.github.com>
Description:
(RW) Local high brightness mode of the Google TG4C panel
(Pixel 9a): a bright circle over the under-display
fingerprint sensor, which lights the finger for the sensor.
Write 1 to light it and 0 to turn it off; read gives the
current state. Writing 1 fails with EPERM if the
panel_google_tg4c module parameter allow_lhbm is off or the
brightness is 0, and with EBUSY unless the panel is on and
running at 120 Hz. The circle turns itself off
after local_hbm_max_timeout milliseconds, and when the panel
turns off or leaves 120 Hz.

What: /sys/class/backlight/<backlight>/local_hbm_max_timeout
Date: October 2026
KernelVersion: 7.3
Contact: W4HO <87742609+W4HO-ham@users.noreply.github.com>
Description:
(RO) How long, in milliseconds, local high brightness mode
stays on before the panel driver turns it off by itself.
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -8151,6 +8151,7 @@ F: include/drm/gud.h
DRM DRIVER FOR GOOGLE TG4C PANELS
M: W4HO <87742609+W4HO-ham@users.noreply.github.com>
S: Maintained
F: Documentation/ABI/testing/sysfs-class-backlight-google-tg4c
F: Documentation/devicetree/bindings/display/panel/google,tg4c.yaml
F: drivers/gpu/drm/panel/panel-google-tg4c.c

Expand Down
150 changes: 149 additions & 1 deletion drivers/gpu/drm/panel/panel-google-tg4c.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/workqueue.h>

#include <video/mipi_display.h>

Expand All @@ -31,6 +32,23 @@
*/
#define TG4C_MAX_BRIGHTNESS 3628
#define TG4C_DEFAULT_BRIGHTNESS 1829
#define TG4C_LHBM_TIMEOUT_MS 3000
/* Google's LHBM gamma set thresholds */
#define TG4C_LHBM_GAMMASET1 3628
#define TG4C_LHBM_GAMMASET2 2774
#define TG4C_LHBM_GAMMASET3 2186

/* local high brightness mode (the fingerprint circle): off unless allowed */
static bool allow_lhbm;
module_param(allow_lhbm, bool, 0644);
MODULE_PARM_DESC(allow_lhbm, "Allow local high brightness mode (the fingerprint circle); default off");

/*
* The circle's brightness, as Google's GPL panel-gs-tg4c.c sets it after its
* first-stage overdrive: on CMD2 page 2, the LHBM gamma set for the current
* brightness, with the panel's own per-band LHBM values left as they are.
*/
static const u8 tg4c_cmd2_page2[] = { 0xF0, 0x55, 0xAA, 0x52, 0x08, 0x02 };

struct tg4c {
struct drm_panel panel;
Expand All @@ -39,6 +57,11 @@ struct tg4c {
struct mutex lock;
/* out of sleep: commands and frames reach the panel */
bool awake;
bool display_on;
unsigned int hz; /* the rate last set: LHBM needs 120 */
bool lhbm;
struct delayed_work lhbm_off;
u16 brightness;
};

static inline struct tg4c *to_tg4c(struct drm_panel *panel)
Expand All @@ -54,6 +77,61 @@ static void tg4c_write_rate(struct mipi_dsi_multi_context *ctx, unsigned int hz)
mipi_dsi_dcs_write_seq_multi(ctx, 0x2f, 0x02);
}

/* lock held: Google's tg4c_set_local_hbm_gamma, on CMD2 page 2 */
static void tg4c_lhbm_prepare(struct tg4c *ctx, struct mipi_dsi_multi_context *dsi_ctx)
{
u16 br = ctx->brightness;

mipi_dsi_dcs_write_buffer_multi(dsi_ctx, tg4c_cmd2_page2, sizeof(tg4c_cmd2_page2));
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0x6f, 0x07);
if (br > TG4C_LHBM_GAMMASET1)
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0x87, 0x01);
else if (br > TG4C_LHBM_GAMMASET2)
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0x87, 0x02);
else if (br > TG4C_LHBM_GAMMASET3)
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0x87, 0x03);
else
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0x87, 0x04);
}

/* lock held */
static int tg4c_lhbm_set(struct tg4c *ctx, bool on)
{
struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi };

if (on == ctx->lhbm)
return 0;
if (on && (!ctx->awake || !ctx->display_on || ctx->hz != 120))
return -EBUSY;
if (on) {
tg4c_lhbm_prepare(ctx, &dsi_ctx);
mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x87, 0x05);
} else {
mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x87, 0x00);
}
if (dsi_ctx.accum_err)
return dsi_ctx.accum_err;
ctx->lhbm = on;
/* the timer is the current circle's: an earlier one must not end it */
if (on)
mod_delayed_work(system_wq, &ctx->lhbm_off,
msecs_to_jiffies(TG4C_LHBM_TIMEOUT_MS));
else
cancel_delayed_work(&ctx->lhbm_off);
return 0;
}

static void tg4c_lhbm_timeout(struct work_struct *work)
{
struct tg4c *ctx = container_of(to_delayed_work(work), struct tg4c, lhbm_off);

guard(mutex)(&ctx->lock);
if (ctx->awake)
tg4c_lhbm_set(ctx, false);
else
ctx->lhbm = false;
}

static int tg4c_prepare(struct drm_panel *panel)
{
struct tg4c *ctx = to_tg4c(panel);
Expand All @@ -66,8 +144,10 @@ static int tg4c_prepare(struct drm_panel *panel)
mipi_dsi_msleep(&dsi_ctx, 120);
/* the DSI host wakes the link at 60 Hz */
tg4c_write_rate(&dsi_ctx, 60);
if (!dsi_ctx.accum_err)
if (!dsi_ctx.accum_err) {
ctx->awake = true;
ctx->hz = 60;
}

return dsi_ctx.accum_err;
}
Expand All @@ -79,6 +159,8 @@ static int tg4c_enable(struct drm_panel *panel)

guard(mutex)(&ctx->lock);
mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
if (!dsi_ctx.accum_err)
ctx->display_on = true;

return dsi_ctx.accum_err;
}
Expand All @@ -89,8 +171,11 @@ static int tg4c_disable(struct drm_panel *panel)
struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi };

guard(mutex)(&ctx->lock);
tg4c_lhbm_set(ctx, false);
mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
mipi_dsi_msleep(&dsi_ctx, 100);
if (!dsi_ctx.accum_err)
ctx->display_on = false;

return dsi_ctx.accum_err;
}
Expand All @@ -101,6 +186,7 @@ static int tg4c_unprepare(struct drm_panel *panel)
struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi };

guard(mutex)(&ctx->lock);
ctx->lhbm = false; /* sleep ends it */
mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
mipi_dsi_msleep(&dsi_ctx, 120);
if (!dsi_ctx.accum_err)
Expand All @@ -120,7 +206,12 @@ static int tg4c_set_refresh_rate(struct drm_panel *panel, unsigned int hz)
guard(mutex)(&ctx->lock);
if (!ctx->awake)
return -ENODEV;
/* LHBM fails away from 120 Hz: end it first (Google's tg4c does too) */
if (hz != 120)
tg4c_lhbm_set(ctx, false);
tg4c_write_rate(&dsi_ctx, hz);
if (!dsi_ctx.accum_err)
ctx->hz = hz;

return dsi_ctx.accum_err;
}
Expand Down Expand Up @@ -178,6 +269,7 @@ static int tg4c_bl_update_status(struct backlight_device *bl)
u16 brightness = backlight_get_brightness(bl);

guard(mutex)(&ctx->lock);
ctx->brightness = brightness;
/* asleep: the level is kept and sent with the next update */
if (!ctx->awake)
return 0;
Expand All @@ -189,6 +281,49 @@ static const struct backlight_ops tg4c_bl_ops = {
.update_status = tg4c_bl_update_status,
};

static ssize_t local_hbm_mode_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct tg4c *ctx = bl_get_data(to_backlight_device(dev));

return sysfs_emit(buf, "%d\n", ctx->lhbm);
}

static ssize_t local_hbm_mode_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct backlight_device *bl = to_backlight_device(dev);
struct tg4c *ctx = bl_get_data(bl);
bool on;
int ret;

ret = kstrtobool(buf, &on);
if (ret)
return ret;
if (on && (!READ_ONCE(allow_lhbm) || !backlight_get_brightness(bl)))
return -EPERM;

guard(mutex)(&ctx->lock);
ret = tg4c_lhbm_set(ctx, on);
return ret ?: count;
}
static DEVICE_ATTR_RW(local_hbm_mode);

/* the circle turns itself off after this long (ms), as Google's panels report */
static ssize_t local_hbm_max_timeout_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%d\n", TG4C_LHBM_TIMEOUT_MS);
}
static DEVICE_ATTR_RO(local_hbm_max_timeout);

static struct attribute *tg4c_bl_attrs[] = {
&dev_attr_local_hbm_mode.attr,
&dev_attr_local_hbm_max_timeout.attr,
NULL
};
ATTRIBUTE_GROUPS(tg4c_bl);

static int tg4c_probe(struct mipi_dsi_device *dsi)
{
struct device *dev = &dsi->dev;
Expand All @@ -212,6 +347,9 @@ static int tg4c_probe(struct mipi_dsi_device *dsi)
return ret;

ctx->dsi = dsi;
ctx->hz = 60;
ctx->brightness = TG4C_DEFAULT_BRIGHTNESS;
INIT_DELAYED_WORK(&ctx->lhbm_off, tg4c_lhbm_timeout);
mipi_dsi_set_drvdata(dsi, ctx);

dsi->lanes = 4;
Expand All @@ -220,6 +358,7 @@ static int tg4c_probe(struct mipi_dsi_device *dsi)

/* the bootloader left it out of sleep with the display on */
ctx->awake = true;
ctx->display_on = true;
ctx->panel.prepared = true;
ctx->panel.enabled = true;
ctx->panel.prepare_prev_first = true;
Expand All @@ -229,11 +368,15 @@ static int tg4c_probe(struct mipi_dsi_device *dsi)
if (IS_ERR(bl))
return dev_err_probe(dev, PTR_ERR(bl), "failed to register backlight\n");
ctx->panel.backlight = bl;
ret = sysfs_create_groups(&bl->dev.kobj, tg4c_bl_groups);
if (ret)
return dev_err_probe(dev, ret, "LHBM attribute\n");

drm_panel_add(&ctx->panel);

ret = mipi_dsi_attach(dsi);
if (ret < 0) {
sysfs_remove_groups(&bl->dev.kobj, tg4c_bl_groups);
drm_panel_remove(&ctx->panel);
return dev_err_probe(dev, ret, "failed to attach to DSI host\n");
}
Expand All @@ -245,6 +388,11 @@ static void tg4c_remove(struct mipi_dsi_device *dsi)
{
struct tg4c *ctx = mipi_dsi_get_drvdata(dsi);

/* no new writes, then the circle off, then nothing can queue its timer */
sysfs_remove_groups(&ctx->panel.backlight->dev.kobj, tg4c_bl_groups);
scoped_guard(mutex, &ctx->lock)
tg4c_lhbm_set(ctx, false);
cancel_delayed_work_sync(&ctx->lhbm_off);
mipi_dsi_detach(dsi);
drm_panel_remove(&ctx->panel);
}
Expand Down