.. | .. |
---|
37 | 37 | #include "nouveau_drv.h" |
---|
38 | 38 | #include "nouveau_reg.h" |
---|
39 | 39 | #include "nouveau_encoder.h" |
---|
| 40 | +#include "nouveau_connector.h" |
---|
40 | 41 | |
---|
41 | 42 | static struct ida bl_ida; |
---|
42 | 43 | #define BL_NAME_SIZE 15 // 12 for name + 2 for digits + 1 for '\0' |
---|
43 | 44 | |
---|
44 | | -struct backlight_connector { |
---|
45 | | - struct list_head head; |
---|
| 45 | +struct nouveau_backlight { |
---|
| 46 | + struct backlight_device *dev; |
---|
46 | 47 | int id; |
---|
47 | 48 | }; |
---|
48 | 49 | |
---|
49 | 50 | static bool |
---|
50 | | -nouveau_get_backlight_name(char backlight_name[BL_NAME_SIZE], struct backlight_connector |
---|
51 | | - *connector) |
---|
| 51 | +nouveau_get_backlight_name(char backlight_name[BL_NAME_SIZE], |
---|
| 52 | + struct nouveau_backlight *bl) |
---|
52 | 53 | { |
---|
53 | | - const int nb = ida_simple_get(&bl_ida, 0, 0, GFP_KERNEL); |
---|
54 | | - if (nb < 0 || nb >= 100) |
---|
| 54 | + const int nb = ida_alloc_max(&bl_ida, 99, GFP_KERNEL); |
---|
| 55 | + |
---|
| 56 | + if (nb < 0) |
---|
55 | 57 | return false; |
---|
56 | 58 | if (nb > 0) |
---|
57 | 59 | snprintf(backlight_name, BL_NAME_SIZE, "nv_backlight%d", nb); |
---|
58 | 60 | else |
---|
59 | 61 | snprintf(backlight_name, BL_NAME_SIZE, "nv_backlight"); |
---|
60 | | - connector->id = nb; |
---|
| 62 | + bl->id = nb; |
---|
61 | 63 | return true; |
---|
62 | 64 | } |
---|
63 | 65 | |
---|
64 | 66 | static int |
---|
65 | 67 | nv40_get_intensity(struct backlight_device *bd) |
---|
66 | 68 | { |
---|
67 | | - struct nouveau_drm *drm = bl_get_data(bd); |
---|
| 69 | + struct nouveau_encoder *nv_encoder = bl_get_data(bd); |
---|
| 70 | + struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev); |
---|
68 | 71 | struct nvif_object *device = &drm->client.device.object; |
---|
69 | 72 | int val = (nvif_rd32(device, NV40_PMC_BACKLIGHT) & |
---|
70 | | - NV40_PMC_BACKLIGHT_MASK) >> 16; |
---|
| 73 | + NV40_PMC_BACKLIGHT_MASK) >> 16; |
---|
71 | 74 | |
---|
72 | 75 | return val; |
---|
73 | 76 | } |
---|
.. | .. |
---|
75 | 78 | static int |
---|
76 | 79 | nv40_set_intensity(struct backlight_device *bd) |
---|
77 | 80 | { |
---|
78 | | - struct nouveau_drm *drm = bl_get_data(bd); |
---|
| 81 | + struct nouveau_encoder *nv_encoder = bl_get_data(bd); |
---|
| 82 | + struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev); |
---|
79 | 83 | struct nvif_object *device = &drm->client.device.object; |
---|
80 | 84 | int val = bd->props.brightness; |
---|
81 | 85 | int reg = nvif_rd32(device, NV40_PMC_BACKLIGHT); |
---|
82 | 86 | |
---|
83 | 87 | nvif_wr32(device, NV40_PMC_BACKLIGHT, |
---|
84 | | - (val << 16) | (reg & ~NV40_PMC_BACKLIGHT_MASK)); |
---|
| 88 | + (val << 16) | (reg & ~NV40_PMC_BACKLIGHT_MASK)); |
---|
85 | 89 | |
---|
86 | 90 | return 0; |
---|
87 | 91 | } |
---|
.. | .. |
---|
93 | 97 | }; |
---|
94 | 98 | |
---|
95 | 99 | static int |
---|
96 | | -nv40_backlight_init(struct drm_connector *connector) |
---|
| 100 | +nv40_backlight_init(struct nouveau_encoder *encoder, |
---|
| 101 | + struct backlight_properties *props, |
---|
| 102 | + const struct backlight_ops **ops) |
---|
97 | 103 | { |
---|
98 | | - struct nouveau_drm *drm = nouveau_drm(connector->dev); |
---|
| 104 | + struct nouveau_drm *drm = nouveau_drm(encoder->base.base.dev); |
---|
99 | 105 | struct nvif_object *device = &drm->client.device.object; |
---|
100 | | - struct backlight_properties props; |
---|
101 | | - struct backlight_device *bd; |
---|
102 | | - struct backlight_connector bl_connector; |
---|
103 | | - char backlight_name[BL_NAME_SIZE]; |
---|
104 | 106 | |
---|
105 | 107 | if (!(nvif_rd32(device, NV40_PMC_BACKLIGHT) & NV40_PMC_BACKLIGHT_MASK)) |
---|
106 | | - return 0; |
---|
| 108 | + return -ENODEV; |
---|
107 | 109 | |
---|
108 | | - memset(&props, 0, sizeof(struct backlight_properties)); |
---|
109 | | - props.type = BACKLIGHT_RAW; |
---|
110 | | - props.max_brightness = 31; |
---|
111 | | - if (!nouveau_get_backlight_name(backlight_name, &bl_connector)) { |
---|
112 | | - NV_ERROR(drm, "Failed to retrieve a unique name for the backlight interface\n"); |
---|
113 | | - return 0; |
---|
114 | | - } |
---|
115 | | - bd = backlight_device_register(backlight_name , connector->kdev, drm, |
---|
116 | | - &nv40_bl_ops, &props); |
---|
117 | | - |
---|
118 | | - if (IS_ERR(bd)) { |
---|
119 | | - if (bl_connector.id >= 0) |
---|
120 | | - ida_simple_remove(&bl_ida, bl_connector.id); |
---|
121 | | - return PTR_ERR(bd); |
---|
122 | | - } |
---|
123 | | - list_add(&bl_connector.head, &drm->bl_connectors); |
---|
124 | | - drm->backlight = bd; |
---|
125 | | - bd->props.brightness = nv40_get_intensity(bd); |
---|
126 | | - backlight_update_status(bd); |
---|
127 | | - |
---|
| 110 | + props->type = BACKLIGHT_RAW; |
---|
| 111 | + props->max_brightness = 31; |
---|
| 112 | + *ops = &nv40_bl_ops; |
---|
128 | 113 | return 0; |
---|
129 | 114 | } |
---|
130 | 115 | |
---|
.. | .. |
---|
154 | 139 | u32 val = (bd->props.brightness * div) / 100; |
---|
155 | 140 | |
---|
156 | 141 | nvif_wr32(device, NV50_PDISP_SOR_PWM_CTL(or), |
---|
157 | | - NV50_PDISP_SOR_PWM_CTL_NEW | val); |
---|
| 142 | + NV50_PDISP_SOR_PWM_CTL_NEW | val); |
---|
158 | 143 | return 0; |
---|
159 | 144 | } |
---|
160 | 145 | |
---|
.. | .. |
---|
194 | 179 | div = nvif_rd32(device, NV50_PDISP_SOR_PWM_DIV(or)); |
---|
195 | 180 | val = (bd->props.brightness * div) / 100; |
---|
196 | 181 | if (div) { |
---|
197 | | - nvif_wr32(device, NV50_PDISP_SOR_PWM_CTL(or), val | |
---|
198 | | - NV50_PDISP_SOR_PWM_CTL_NEW | |
---|
199 | | - NVA3_PDISP_SOR_PWM_CTL_UNK); |
---|
| 182 | + nvif_wr32(device, NV50_PDISP_SOR_PWM_CTL(or), |
---|
| 183 | + val | |
---|
| 184 | + NV50_PDISP_SOR_PWM_CTL_NEW | |
---|
| 185 | + NVA3_PDISP_SOR_PWM_CTL_UNK); |
---|
200 | 186 | return 0; |
---|
201 | 187 | } |
---|
202 | 188 | |
---|
.. | .. |
---|
210 | 196 | }; |
---|
211 | 197 | |
---|
212 | 198 | static int |
---|
213 | | -nv50_backlight_init(struct drm_connector *connector) |
---|
| 199 | +nv50_backlight_init(struct nouveau_encoder *nv_encoder, |
---|
| 200 | + struct backlight_properties *props, |
---|
| 201 | + const struct backlight_ops **ops) |
---|
214 | 202 | { |
---|
215 | | - struct nouveau_drm *drm = nouveau_drm(connector->dev); |
---|
| 203 | + struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev); |
---|
216 | 204 | struct nvif_object *device = &drm->client.device.object; |
---|
217 | | - struct nouveau_encoder *nv_encoder; |
---|
218 | | - struct backlight_properties props; |
---|
219 | | - struct backlight_device *bd; |
---|
220 | | - const struct backlight_ops *ops; |
---|
221 | | - struct backlight_connector bl_connector; |
---|
222 | | - char backlight_name[BL_NAME_SIZE]; |
---|
223 | | - |
---|
224 | | - nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS); |
---|
225 | | - if (!nv_encoder) { |
---|
226 | | - nv_encoder = find_encoder(connector, DCB_OUTPUT_DP); |
---|
227 | | - if (!nv_encoder) |
---|
228 | | - return -ENODEV; |
---|
229 | | - } |
---|
230 | 205 | |
---|
231 | 206 | if (!nvif_rd32(device, NV50_PDISP_SOR_PWM_CTL(ffs(nv_encoder->dcb->or) - 1))) |
---|
232 | | - return 0; |
---|
| 207 | + return -ENODEV; |
---|
233 | 208 | |
---|
234 | 209 | if (drm->client.device.info.chipset <= 0xa0 || |
---|
235 | 210 | drm->client.device.info.chipset == 0xaa || |
---|
236 | 211 | drm->client.device.info.chipset == 0xac) |
---|
237 | | - ops = &nv50_bl_ops; |
---|
| 212 | + *ops = &nv50_bl_ops; |
---|
238 | 213 | else |
---|
239 | | - ops = &nva3_bl_ops; |
---|
| 214 | + *ops = &nva3_bl_ops; |
---|
240 | 215 | |
---|
241 | | - memset(&props, 0, sizeof(struct backlight_properties)); |
---|
242 | | - props.type = BACKLIGHT_RAW; |
---|
243 | | - props.max_brightness = 100; |
---|
244 | | - if (!nouveau_get_backlight_name(backlight_name, &bl_connector)) { |
---|
245 | | - NV_ERROR(drm, "Failed to retrieve a unique name for the backlight interface\n"); |
---|
246 | | - return 0; |
---|
247 | | - } |
---|
248 | | - bd = backlight_device_register(backlight_name , connector->kdev, |
---|
249 | | - nv_encoder, ops, &props); |
---|
| 216 | + props->type = BACKLIGHT_RAW; |
---|
| 217 | + props->max_brightness = 100; |
---|
250 | 218 | |
---|
251 | | - if (IS_ERR(bd)) { |
---|
252 | | - if (bl_connector.id >= 0) |
---|
253 | | - ida_simple_remove(&bl_ida, bl_connector.id); |
---|
254 | | - return PTR_ERR(bd); |
---|
255 | | - } |
---|
256 | | - |
---|
257 | | - list_add(&bl_connector.head, &drm->bl_connectors); |
---|
258 | | - drm->backlight = bd; |
---|
259 | | - bd->props.brightness = bd->ops->get_brightness(bd); |
---|
260 | | - backlight_update_status(bd); |
---|
261 | 219 | return 0; |
---|
262 | 220 | } |
---|
263 | 221 | |
---|
264 | 222 | int |
---|
265 | | -nouveau_backlight_init(struct drm_device *dev) |
---|
| 223 | +nouveau_backlight_init(struct drm_connector *connector) |
---|
266 | 224 | { |
---|
267 | | - struct nouveau_drm *drm = nouveau_drm(dev); |
---|
| 225 | + struct nouveau_drm *drm = nouveau_drm(connector->dev); |
---|
| 226 | + struct nouveau_backlight *bl; |
---|
| 227 | + struct nouveau_encoder *nv_encoder = NULL; |
---|
268 | 228 | struct nvif_device *device = &drm->client.device; |
---|
269 | | - struct drm_connector *connector; |
---|
270 | | - struct drm_connector_list_iter conn_iter; |
---|
271 | | - |
---|
272 | | - INIT_LIST_HEAD(&drm->bl_connectors); |
---|
| 229 | + char backlight_name[BL_NAME_SIZE]; |
---|
| 230 | + struct backlight_properties props = {0}; |
---|
| 231 | + const struct backlight_ops *ops; |
---|
| 232 | + int ret; |
---|
273 | 233 | |
---|
274 | 234 | if (apple_gmux_present()) { |
---|
275 | | - NV_INFO(drm, "Apple GMUX detected: not registering Nouveau backlight interface\n"); |
---|
| 235 | + NV_INFO_ONCE(drm, "Apple GMUX detected: not registering Nouveau backlight interface\n"); |
---|
276 | 236 | return 0; |
---|
277 | 237 | } |
---|
278 | 238 | |
---|
279 | | - drm_connector_list_iter_begin(dev, &conn_iter); |
---|
280 | | - drm_for_each_connector_iter(connector, &conn_iter) { |
---|
281 | | - if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS && |
---|
282 | | - connector->connector_type != DRM_MODE_CONNECTOR_eDP) |
---|
283 | | - continue; |
---|
| 239 | + if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS) |
---|
| 240 | + nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS); |
---|
| 241 | + else if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) |
---|
| 242 | + nv_encoder = find_encoder(connector, DCB_OUTPUT_DP); |
---|
| 243 | + else |
---|
| 244 | + return 0; |
---|
284 | 245 | |
---|
285 | | - switch (device->info.family) { |
---|
286 | | - case NV_DEVICE_INFO_V0_CURIE: |
---|
287 | | - return nv40_backlight_init(connector); |
---|
288 | | - case NV_DEVICE_INFO_V0_TESLA: |
---|
289 | | - case NV_DEVICE_INFO_V0_FERMI: |
---|
290 | | - case NV_DEVICE_INFO_V0_KEPLER: |
---|
291 | | - case NV_DEVICE_INFO_V0_MAXWELL: |
---|
292 | | - return nv50_backlight_init(connector); |
---|
293 | | - default: |
---|
294 | | - break; |
---|
295 | | - } |
---|
| 246 | + if (!nv_encoder) |
---|
| 247 | + return 0; |
---|
| 248 | + |
---|
| 249 | + switch (device->info.family) { |
---|
| 250 | + case NV_DEVICE_INFO_V0_CURIE: |
---|
| 251 | + ret = nv40_backlight_init(nv_encoder, &props, &ops); |
---|
| 252 | + break; |
---|
| 253 | + case NV_DEVICE_INFO_V0_TESLA: |
---|
| 254 | + case NV_DEVICE_INFO_V0_FERMI: |
---|
| 255 | + case NV_DEVICE_INFO_V0_KEPLER: |
---|
| 256 | + case NV_DEVICE_INFO_V0_MAXWELL: |
---|
| 257 | + case NV_DEVICE_INFO_V0_PASCAL: |
---|
| 258 | + case NV_DEVICE_INFO_V0_VOLTA: |
---|
| 259 | + case NV_DEVICE_INFO_V0_TURING: |
---|
| 260 | + ret = nv50_backlight_init(nv_encoder, &props, &ops); |
---|
| 261 | + break; |
---|
| 262 | + default: |
---|
| 263 | + return 0; |
---|
296 | 264 | } |
---|
297 | | - drm_connector_list_iter_end(&conn_iter); |
---|
| 265 | + |
---|
| 266 | + if (ret == -ENODEV) |
---|
| 267 | + return 0; |
---|
| 268 | + else if (ret) |
---|
| 269 | + return ret; |
---|
| 270 | + |
---|
| 271 | + bl = kzalloc(sizeof(*bl), GFP_KERNEL); |
---|
| 272 | + if (!bl) |
---|
| 273 | + return -ENOMEM; |
---|
| 274 | + |
---|
| 275 | + if (!nouveau_get_backlight_name(backlight_name, bl)) { |
---|
| 276 | + NV_ERROR(drm, "Failed to retrieve a unique name for the backlight interface\n"); |
---|
| 277 | + goto fail_alloc; |
---|
| 278 | + } |
---|
| 279 | + |
---|
| 280 | + bl->dev = backlight_device_register(backlight_name, connector->kdev, |
---|
| 281 | + nv_encoder, ops, &props); |
---|
| 282 | + if (IS_ERR(bl->dev)) { |
---|
| 283 | + if (bl->id >= 0) |
---|
| 284 | + ida_free(&bl_ida, bl->id); |
---|
| 285 | + ret = PTR_ERR(bl->dev); |
---|
| 286 | + goto fail_alloc; |
---|
| 287 | + } |
---|
| 288 | + |
---|
| 289 | + nouveau_connector(connector)->backlight = bl; |
---|
| 290 | + bl->dev->props.brightness = bl->dev->ops->get_brightness(bl->dev); |
---|
| 291 | + backlight_update_status(bl->dev); |
---|
298 | 292 | |
---|
299 | 293 | return 0; |
---|
| 294 | + |
---|
| 295 | +fail_alloc: |
---|
| 296 | + kfree(bl); |
---|
| 297 | + return ret; |
---|
300 | 298 | } |
---|
301 | 299 | |
---|
302 | 300 | void |
---|
303 | | -nouveau_backlight_exit(struct drm_device *dev) |
---|
| 301 | +nouveau_backlight_fini(struct drm_connector *connector) |
---|
304 | 302 | { |
---|
305 | | - struct nouveau_drm *drm = nouveau_drm(dev); |
---|
306 | | - struct backlight_connector *connector; |
---|
| 303 | + struct nouveau_connector *nv_conn = nouveau_connector(connector); |
---|
| 304 | + struct nouveau_backlight *bl = nv_conn->backlight; |
---|
307 | 305 | |
---|
308 | | - list_for_each_entry(connector, &drm->bl_connectors, head) { |
---|
309 | | - if (connector->id >= 0) |
---|
310 | | - ida_simple_remove(&bl_ida, connector->id); |
---|
311 | | - } |
---|
| 306 | + if (!bl) |
---|
| 307 | + return; |
---|
312 | 308 | |
---|
313 | | - if (drm->backlight) { |
---|
314 | | - backlight_device_unregister(drm->backlight); |
---|
315 | | - drm->backlight = NULL; |
---|
316 | | - } |
---|
| 309 | + if (bl->id >= 0) |
---|
| 310 | + ida_free(&bl_ida, bl->id); |
---|
| 311 | + |
---|
| 312 | + backlight_device_unregister(bl->dev); |
---|
| 313 | + nv_conn->backlight = NULL; |
---|
| 314 | + kfree(bl); |
---|
317 | 315 | } |
---|
318 | 316 | |
---|
319 | 317 | void |
---|