Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/panel: visionox-rm69299: Add backlight support

The shift6mq's variant supports controlling the backlight via DSI
commands. Use that if a max_brightness is set in the device specific
data.

Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Guido Günther <agx@sigxcpu.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://lore.kernel.org/r/20250910-shift6mq-panel-v3-3-a7729911afb9@sigxcpu.org

authored by

Guido Günther and committed by
Neil Armstrong
7911d8ca 39144b61

+67
+67
drivers/gpu/drm/panel/panel-visionox-rm69299.c
··· 3 3 * Copyright (c) 2019, The Linux Foundation. All rights reserved. 4 4 */ 5 5 6 + #include <linux/backlight.h> 6 7 #include <linux/delay.h> 7 8 #include <linux/module.h> 8 9 #include <linux/property.h> ··· 21 20 const struct drm_display_mode *mode; 22 21 const u8 *init_seq; 23 22 unsigned int init_seq_len; 23 + int max_brightness; 24 + int initial_brightness; 24 25 }; 25 26 26 27 struct visionox_rm69299 { ··· 288 285 .get_modes = visionox_rm69299_get_modes, 289 286 }; 290 287 288 + static int visionox_rm69299_bl_get_brightness(struct backlight_device *bl) 289 + { 290 + struct mipi_dsi_device *dsi = bl_get_data(bl); 291 + u16 brightness; 292 + int ret; 293 + 294 + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; 295 + 296 + ret = mipi_dsi_dcs_get_display_brightness(dsi, &brightness); 297 + if (ret < 0) 298 + return ret; 299 + 300 + dsi->mode_flags |= MIPI_DSI_MODE_LPM; 301 + 302 + return brightness; 303 + } 304 + 305 + static int visionox_rm69299_bl_update_status(struct backlight_device *bl) 306 + { 307 + struct mipi_dsi_device *dsi = bl_get_data(bl); 308 + u16 brightness = backlight_get_brightness(bl); 309 + int ret; 310 + 311 + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; 312 + 313 + ret = mipi_dsi_dcs_set_display_brightness(dsi, brightness); 314 + if (ret < 0) 315 + return ret; 316 + 317 + dsi->mode_flags |= MIPI_DSI_MODE_LPM; 318 + 319 + return 0; 320 + } 321 + 322 + static const struct backlight_ops visionox_rm69299_bl_ops = { 323 + .update_status = visionox_rm69299_bl_update_status, 324 + .get_brightness = visionox_rm69299_bl_get_brightness, 325 + }; 326 + 327 + static struct backlight_device * 328 + visionox_rm69299_create_backlight(struct visionox_rm69299 *ctx) 329 + { 330 + struct device *dev = &ctx->dsi->dev; 331 + const struct backlight_properties props = { 332 + .type = BACKLIGHT_RAW, 333 + .brightness = ctx->desc->initial_brightness, 334 + .max_brightness = ctx->desc->max_brightness, 335 + }; 336 + 337 + if (!ctx->desc->max_brightness) 338 + return 0; 339 + 340 + return devm_backlight_device_register(dev, dev_name(dev), dev, ctx->dsi, 341 + &visionox_rm69299_bl_ops, 342 + &props); 343 + } 344 + 291 345 static int visionox_rm69299_probe(struct mipi_dsi_device *dsi) 292 346 { 293 347 struct device *dev = &dsi->dev; ··· 375 315 dev_err(dev, "cannot get reset gpio %ld\n", PTR_ERR(ctx->reset_gpio)); 376 316 return PTR_ERR(ctx->reset_gpio); 377 317 } 318 + 319 + ctx->panel.backlight = visionox_rm69299_create_backlight(ctx); 320 + if (IS_ERR(ctx->panel.backlight)) 321 + return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight), 322 + "Failed to create backlight\n"); 378 323 379 324 drm_panel_add(&ctx->panel); 380 325 ··· 418 353 .mode = &visionox_rm69299_1080x2160_60hz, 419 354 .init_seq = (const u8 *)visionox_rm69299_1080x2160_60hz_init_seq, 420 355 .init_seq_len = ARRAY_SIZE(visionox_rm69299_1080x2160_60hz_init_seq), 356 + .max_brightness = 255, 357 + .initial_brightness = 50, 421 358 }; 422 359 423 360 static const struct of_device_id visionox_rm69299_of_match[] = {