Skip to content

Commit 1aba7bb

Browse files
committed
drm/simpledrm: Add backlight support
Allows devicetrees to link the simplefb node to a backlight device, and toggles power to the backlight when the display pipe is enabled/disabled. This is sufficient for basic DPMS style functionality in trivial devices. Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent 532039d commit 1aba7bb

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

drivers/gpu/drm/tiny/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ config DRM_SIMPLEDRM
8585
select APERTURE_HELPERS
8686
select DRM_GEM_SHMEM_HELPER
8787
select DRM_KMS_HELPER
88+
select BACKLIGHT_CLASS_DEVICE
8889
help
8990
DRM driver for simple platform-provided framebuffers.
9091

drivers/gpu/drm/tiny/simpledrm.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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

248251
static 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
561584
static 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

566591
static 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

Comments
 (0)