33 * Copyright (c) 2019, The Linux Foundation. All rights reserved.
44 */
55
6+ #include <linux/backlight.h>
67#include <linux/delay.h>
78#include <linux/module.h>
89#include <linux/property.h>
@@ -20,6 +21,8 @@ struct visionox_rm69299_panel_desc {
2021 const struct drm_display_mode * mode ;
2122 const u8 * init_seq ;
2223 unsigned int init_seq_len ;
24+ int max_brightness ;
25+ int initial_brightness ;
2326};
2427
2528struct visionox_rm69299 {
@@ -285,6 +288,63 @@ static const struct drm_panel_funcs visionox_rm69299_drm_funcs = {
285288 .get_modes = visionox_rm69299_get_modes ,
286289};
287290
291+ static int visionox_rm69299_bl_get_brightness (struct backlight_device * bl )
292+ {
293+ struct mipi_dsi_device * dsi = bl_get_data (bl );
294+ u16 brightness ;
295+ int ret ;
296+
297+ dsi -> mode_flags &= ~MIPI_DSI_MODE_LPM ;
298+
299+ ret = mipi_dsi_dcs_get_display_brightness (dsi , & brightness );
300+ if (ret < 0 )
301+ return ret ;
302+
303+ dsi -> mode_flags |= MIPI_DSI_MODE_LPM ;
304+
305+ return brightness ;
306+ }
307+
308+ static int visionox_rm69299_bl_update_status (struct backlight_device * bl )
309+ {
310+ struct mipi_dsi_device * dsi = bl_get_data (bl );
311+ u16 brightness = backlight_get_brightness (bl );
312+ int ret ;
313+
314+ dsi -> mode_flags &= ~MIPI_DSI_MODE_LPM ;
315+
316+ ret = mipi_dsi_dcs_set_display_brightness (dsi , brightness );
317+ if (ret < 0 )
318+ return ret ;
319+
320+ dsi -> mode_flags |= MIPI_DSI_MODE_LPM ;
321+
322+ return 0 ;
323+ }
324+
325+ static const struct backlight_ops visionox_rm69299_bl_ops = {
326+ .update_status = visionox_rm69299_bl_update_status ,
327+ .get_brightness = visionox_rm69299_bl_get_brightness ,
328+ };
329+
330+ static struct backlight_device *
331+ visionox_rm69299_create_backlight (struct visionox_rm69299 * ctx )
332+ {
333+ struct device * dev = & ctx -> dsi -> dev ;
334+ const struct backlight_properties props = {
335+ .type = BACKLIGHT_RAW ,
336+ .brightness = ctx -> desc -> initial_brightness ,
337+ .max_brightness = ctx -> desc -> max_brightness ,
338+ };
339+
340+ if (!ctx -> desc -> max_brightness )
341+ return 0 ;
342+
343+ return devm_backlight_device_register (dev , dev_name (dev ), dev , ctx -> dsi ,
344+ & visionox_rm69299_bl_ops ,
345+ & props );
346+ }
347+
288348static int visionox_rm69299_probe (struct mipi_dsi_device * dsi )
289349{
290350 struct device * dev = & dsi -> dev ;
@@ -316,6 +376,11 @@ static int visionox_rm69299_probe(struct mipi_dsi_device *dsi)
316376 return PTR_ERR (ctx -> reset_gpio );
317377 }
318378
379+ ctx -> panel .backlight = visionox_rm69299_create_backlight (ctx );
380+ if (IS_ERR (ctx -> panel .backlight ))
381+ return dev_err_probe (dev , PTR_ERR (ctx -> panel .backlight ),
382+ "Failed to create backlight\n" );
383+
319384 drm_panel_add (& ctx -> panel );
320385
321386 dsi -> lanes = 4 ;
@@ -353,6 +418,8 @@ const struct visionox_rm69299_panel_desc visionox_rm69299_shift_desc = {
353418 .mode = & visionox_rm69299_1080x2160_60hz ,
354419 .init_seq = (const u8 * )visionox_rm69299_1080x2160_60hz_init_seq ,
355420 .init_seq_len = ARRAY_SIZE (visionox_rm69299_1080x2160_60hz_init_seq ),
421+ .max_brightness = 255 ,
422+ .initial_brightness = 50 ,
356423};
357424
358425static const struct of_device_id visionox_rm69299_of_match [] = {
0 commit comments