Attachment 'radeon_backlight.patch'
Download 1 diff --git a/sys/dev/drm2/radeon/atombios_encoders.c b/sys/dev/drm2/radeon/atombios_encoders.c
2 index 3ee6fc55b32..72e1f266d49 100644
3 --- a/sys/dev/drm2/radeon/atombios_encoders.c
4 +++ b/sys/dev/drm2/radeon/atombios_encoders.c
5 @@ -134,8 +134,17 @@ atombios_set_backlight_level(struct radeon_encoder *radeon_encoder, u8 level)
6 }
7 }
8
9 -#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
10 +#if !defined(CONFIG_BACKLIGHT_CLASS_DEVICE) && !defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
11 +struct backlight_device {
12 + struct backlight_properties {
13 + int brightness;
14 + int max_brightness;
15 + } props;
16 + struct radeon_backlight_privdata pdata;
17 +};
18 +#endif
19
20 +#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE)
21 static u8 radeon_atom_bl_level(struct backlight_device *bd)
22 {
23 u8 level;
24 @@ -268,13 +277,83 @@ static void radeon_atom_backlight_exit(struct radeon_encoder *radeon_encoder)
25
26 #else /* !CONFIG_BACKLIGHT_CLASS_DEVICE */
27
28 +static int radeon_atom_backlight_get_brightness(struct backlight_device *bd)
29 +{
30 + struct radeon_encoder *radeon_encoder = bd->pdata.encoder;
31 + struct drm_device *dev = radeon_encoder->base.dev;
32 + struct radeon_device *rdev = dev->dev_private;
33 +
34 + return radeon_atom_get_backlight_level_from_reg(rdev);
35 +}
36 +
37 void radeon_atom_backlight_init(struct radeon_encoder *radeon_encoder,
38 struct drm_connector *drm_connector)
39 {
40 + struct drm_device *dev = radeon_encoder->base.dev;
41 + struct radeon_device *rdev = dev->dev_private;
42 + struct backlight_device *bd;
43 + struct radeon_encoder_atom_dig *dig;
44 + u8 backlight_level;
45 +
46 + if (!radeon_encoder->enc_priv) {
47 + return;
48 + }
49 +
50 + if (!rdev->is_atom_bios) {
51 + return;
52 + }
53 +
54 + if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU)) {
55 + return;
56 + }
57 +
58 + bd = malloc(sizeof(struct backlight_device), DRM_MEM_DRIVER, M_WAITOK);
59 + if (!bd) {
60 + DRM_ERROR("Backlight memory allocation failed (%zu bytes)\n", sizeof(struct backlight_device));
61 + return;
62 + }
63 +
64 + memset(&bd->props, 0, sizeof(bd->props));
65 + bd->props.max_brightness = RADEON_MAX_BL_LEVEL;
66 +
67 + bd->pdata.encoder = radeon_encoder;
68 +
69 + backlight_level = radeon_atom_get_backlight_level_from_reg(rdev);
70 +
71 + dig = radeon_encoder->enc_priv;
72 + dig->bl_dev = bd;
73 +
74 + bd->props.brightness = radeon_atom_backlight_get_brightness(bd);
75 +
76 + DRM_INFO("radeon atom DIG backlight initialized\n");
77 +
78 + return;
79 }
80
81 -static void radeon_atom_backlight_exit(struct radeon_encoder *encoder)
82 +static void radeon_atom_backlight_exit(struct radeon_encoder *radeon_encoder)
83 {
84 + struct drm_device *dev = radeon_encoder->base.dev;
85 + struct radeon_device *rdev = dev->dev_private;
86 + struct backlight_device *bd = NULL;
87 + struct radeon_encoder_atom_dig *dig;
88 +
89 + if (!radeon_encoder->enc_priv)
90 + return;
91 +
92 + if (!rdev->is_atom_bios)
93 + return;
94 +
95 + if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU))
96 + return;
97 +
98 + dig = radeon_encoder->enc_priv;
99 + bd = dig->bl_dev;
100 + dig->bl_dev = NULL;
101 +
102 + if (bd) {
103 + free(bd, DRM_MEM_DRIVER);
104 + DRM_INFO("radeon atom LVDS backlight unloaded\n");
105 + }
106 }
107
108 #endif
109 diff --git a/sys/dev/drm2/radeon/radeon_legacy_encoders.c b/sys/dev/drm2/radeon/radeon_legacy_encoders.c
110 index d0db92f93fa..9543a813b0d 100644
111 --- a/sys/dev/drm2/radeon/radeon_legacy_encoders.c
112 +++ b/sys/dev/drm2/radeon/radeon_legacy_encoders.c
113 @@ -483,13 +483,115 @@ static void radeon_legacy_backlight_exit(struct radeon_encoder *radeon_encoder)
114
115 #else /* !CONFIG_BACKLIGHT_CLASS_DEVICE */
116
117 -void radeon_legacy_backlight_init(struct radeon_encoder *encoder,
118 +struct backlight_device {
119 + struct backlight_properties {
120 + int brightness;
121 + int max_brightness;
122 + } props;
123 + struct radeon_backlight_privdata pdata;
124 +};
125 +
126 +static int radeon_legacy_backlight_get_brightness(struct backlight_device *bd)
127 +{
128 + struct radeon_encoder *radeon_encoder = bd->pdata.encoder;
129 + struct drm_device *dev = radeon_encoder->base.dev;
130 + struct radeon_device *rdev = dev->dev_private;
131 + uint8_t backlight_level;
132 +
133 + backlight_level = (RREG32(RADEON_LVDS_GEN_CNTL) >>
134 + RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff;
135 +
136 + return bd->pdata.negative ? RADEON_MAX_BL_LEVEL - backlight_level : backlight_level;
137 +}
138 +
139 +void radeon_legacy_backlight_init(struct radeon_encoder *radeon_encoder,
140 struct drm_connector *drm_connector)
141 {
142 + struct drm_device *dev = radeon_encoder->base.dev;
143 + struct radeon_device *rdev = dev->dev_private;
144 + struct backlight_device *bd;
145 + uint8_t backlight_level;
146 +
147 + if (!radeon_encoder->enc_priv)
148 + return;
149 +
150 +#ifdef CONFIG_PMAC_BACKLIGHT
151 + if (!pmac_has_backlight_type("ati") &&
152 + !pmac_has_backlight_type("mnca"))
153 + return;
154 +#endif
155 +
156 + bd = malloc(sizeof(struct backlight_device), DRM_MEM_DRIVER, M_WAITOK);
157 + if (!bd) {
158 + DRM_ERROR("Memory allocation failed\n");
159 + return;
160 + }
161 + bd->pdata.encoder = radeon_encoder;
162 +
163 + backlight_level = (RREG32(RADEON_LVDS_GEN_CNTL) >>
164 + RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff;
165 +
166 + /* First, try to detect backlight level sense based on the assumption
167 + * that firmware set it up at full brightness
168 + */
169 + if (backlight_level == 0)
170 + bd->pdata.negative = true;
171 + else if (backlight_level == 0xff)
172 + bd->pdata.negative = false;
173 + else {
174 + /* XXX hack... maybe some day we can figure out in what direction
175 + * backlight should work on a given panel?
176 + */
177 + bd->pdata.negative = (rdev->family != CHIP_RV200 &&
178 + rdev->family != CHIP_RV250 &&
179 + rdev->family != CHIP_RV280 &&
180 + rdev->family != CHIP_RV350);
181 +
182 +#ifdef CONFIG_PMAC_BACKLIGHT
183 + bd->pdata.negative = (bd->pdata.negative ||
184 + of_machine_is_compatible("PowerBook4,3") ||
185 + of_machine_is_compatible("PowerBook6,3") ||
186 + of_machine_is_compatible("PowerBook6,5"));
187 +#endif
188 + }
189 +
190 + if (rdev->is_atom_bios) {
191 + struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv;
192 + lvds->bl_dev = bd;
193 + } else {
194 + struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv;
195 + lvds->bl_dev = bd;
196 + }
197 +
198 + bd->props.brightness = radeon_legacy_backlight_get_brightness(bd);
199 +
200 + DRM_INFO("radeon legacy LVDS backlight initialized\n");
201 + return;
202 }
203
204 -static void radeon_legacy_backlight_exit(struct radeon_encoder *encoder)
205 +static void radeon_legacy_backlight_exit(struct radeon_encoder *radeon_encoder)
206 {
207 + struct drm_device *dev = radeon_encoder->base.dev;
208 + struct radeon_device *rdev = dev->dev_private;
209 + struct backlight_device *bd = NULL;
210 +
211 + if (!radeon_encoder->enc_priv)
212 + return;
213 +
214 + if (rdev->is_atom_bios) {
215 + struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv;
216 + bd = lvds->bl_dev;
217 + lvds->bl_dev = NULL;
218 + } else {
219 + struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv;
220 + bd = lvds->bl_dev;
221 + lvds->bl_dev = NULL;
222 + }
223 +
224 + if (bd) {
225 + free(bd, DRM_MEM_DRIVER);
226 + DRM_INFO("radeon legacy LVDS backlight unloaded\n");
227 + }
228 }
229
230 #endif
231 diff --git a/sys/dev/drm2/radeon/radeon_mode.h b/sys/dev/drm2/radeon/radeon_mode.h
232 index ac39bc3ee82..1eff5c5efd5 100644
233 --- a/sys/dev/drm2/radeon/radeon_mode.h
234 +++ b/sys/dev/drm2/radeon/radeon_mode.h
235 @@ -259,15 +259,11 @@ struct radeon_mode_info {
236
237 #define RADEON_MAX_BL_LEVEL 0xFF
238
239 -#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
240 -
241 struct radeon_backlight_privdata {
242 struct radeon_encoder *encoder;
243 uint8_t negative;
244 };
245
246 -#endif
247 -
248 #define MAX_H_CODE_TIMING_LEN 32
249 #define MAX_V_CODE_TIMING_LEN 32
250
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.