1 // SPDX-License-Identifier: GPL-2.0+
3 * shmob_drm_backlight.c -- SH Mobile DRM Backlight
5 * Copyright (C) 2012 Renesas Electronics Corporation
7 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
10 #include <linux/backlight.h>
12 #include "shmob_drm_backlight.h"
13 #include "shmob_drm_crtc.h"
14 #include "shmob_drm_drv.h"
16 static int shmob_drm_backlight_update(struct backlight_device
*bdev
)
18 struct shmob_drm_connector
*scon
= bl_get_data(bdev
);
19 struct shmob_drm_device
*sdev
= scon
->connector
.dev
->dev_private
;
20 const struct shmob_drm_backlight_data
*bdata
= &sdev
->pdata
->backlight
;
21 int brightness
= bdev
->props
.brightness
;
23 if (bdev
->props
.power
!= FB_BLANK_UNBLANK
||
24 bdev
->props
.state
& BL_CORE_SUSPENDED
)
27 return bdata
->set_brightness(brightness
);
30 static int shmob_drm_backlight_get_brightness(struct backlight_device
*bdev
)
32 struct shmob_drm_connector
*scon
= bl_get_data(bdev
);
33 struct shmob_drm_device
*sdev
= scon
->connector
.dev
->dev_private
;
34 const struct shmob_drm_backlight_data
*bdata
= &sdev
->pdata
->backlight
;
36 return bdata
->get_brightness();
39 static const struct backlight_ops shmob_drm_backlight_ops
= {
40 .options
= BL_CORE_SUSPENDRESUME
,
41 .update_status
= shmob_drm_backlight_update
,
42 .get_brightness
= shmob_drm_backlight_get_brightness
,
45 void shmob_drm_backlight_dpms(struct shmob_drm_connector
*scon
, int mode
)
47 if (scon
->backlight
== NULL
)
50 scon
->backlight
->props
.power
= mode
== DRM_MODE_DPMS_ON
51 ? FB_BLANK_UNBLANK
: FB_BLANK_POWERDOWN
;
52 backlight_update_status(scon
->backlight
);
55 int shmob_drm_backlight_init(struct shmob_drm_connector
*scon
)
57 struct shmob_drm_device
*sdev
= scon
->connector
.dev
->dev_private
;
58 const struct shmob_drm_backlight_data
*bdata
= &sdev
->pdata
->backlight
;
59 struct drm_connector
*connector
= &scon
->connector
;
60 struct drm_device
*dev
= connector
->dev
;
61 struct backlight_device
*backlight
;
63 if (!bdata
->max_brightness
)
66 backlight
= backlight_device_register(bdata
->name
, dev
->dev
, scon
,
67 &shmob_drm_backlight_ops
, NULL
);
68 if (IS_ERR(backlight
)) {
69 dev_err(dev
->dev
, "unable to register backlight device: %ld\n",
71 return PTR_ERR(backlight
);
74 backlight
->props
.max_brightness
= bdata
->max_brightness
;
75 backlight
->props
.brightness
= bdata
->max_brightness
;
76 backlight
->props
.power
= FB_BLANK_POWERDOWN
;
77 backlight_update_status(backlight
);
79 scon
->backlight
= backlight
;
83 void shmob_drm_backlight_exit(struct shmob_drm_connector
*scon
)
85 backlight_device_unregister(scon
->backlight
);