11// SPDX-License-Identifier: GPL-2.0-only
22
3+ #include <linux/backlight.h>
34#include <linux/clk.h>
45#include <linux/of_clk.h>
56#include <linux/minmax.h>
@@ -243,6 +244,8 @@ struct simpledrm_device {
243244 struct drm_crtc crtc ;
244245 struct drm_encoder encoder ;
245246 struct drm_connector connector ;
247+ /* backlight */
248+ struct backlight_device * backlight ;
246249};
247250
248251static struct simpledrm_device * simpledrm_device_of_dev (struct drm_device * dev )
@@ -553,6 +556,26 @@ static enum drm_mode_status simpledrm_crtc_helper_mode_valid(struct drm_crtc *cr
553556 return drm_crtc_helper_mode_valid_fixed (crtc , mode , & sdev -> mode );
554557}
555558
559+ static void simpledrm_crtc_helper_atomic_enable (struct drm_crtc * crtc ,
560+ struct drm_atomic_state * state )
561+ {
562+ struct drm_device * dev = crtc -> dev ;
563+ struct simpledrm_device * sdev = simpledrm_device_of_dev (dev );
564+
565+ if (sdev -> backlight )
566+ backlight_enable (sdev -> backlight );
567+ }
568+
569+ static void simpledrm_crtc_helper_atomic_disable (struct drm_crtc * crtc ,
570+ struct drm_atomic_state * state )
571+ {
572+ struct drm_device * dev = crtc -> dev ;
573+ struct simpledrm_device * sdev = simpledrm_device_of_dev (dev );
574+
575+ if (sdev -> backlight )
576+ backlight_disable (sdev -> backlight );
577+ }
578+
556579/*
557580 * The CRTC is always enabled. Screen updates are performed by
558581 * the primary plane's atomic_update function. Disabling clears
@@ -561,6 +584,8 @@ static enum drm_mode_status simpledrm_crtc_helper_mode_valid(struct drm_crtc *cr
561584static const struct drm_crtc_helper_funcs simpledrm_crtc_helper_funcs = {
562585 .mode_valid = simpledrm_crtc_helper_mode_valid ,
563586 .atomic_check = drm_crtc_helper_atomic_check ,
587+ .atomic_enable = simpledrm_crtc_helper_atomic_enable ,
588+ .atomic_disable = simpledrm_crtc_helper_atomic_disable ,
564589};
565590
566591static const struct drm_crtc_funcs simpledrm_crtc_funcs = {
@@ -649,6 +674,10 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv,
649674 * Hardware settings
650675 */
651676
677+ sdev -> backlight = devm_of_find_backlight (& pdev -> dev );
678+ if (IS_ERR (sdev -> backlight ))
679+ sdev -> backlight = NULL ;
680+
652681 ret = simpledrm_device_init_clocks (sdev );
653682 if (ret )
654683 return ERR_PTR (ret );
0 commit comments