diff options
Diffstat (limited to 'drivers/platform')
-rw-r--r-- | drivers/platform/x86/apple-gmux.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c index 976efeb3f2ba..2b921dea10f4 100644 --- a/drivers/platform/x86/apple-gmux.c +++ b/drivers/platform/x86/apple-gmux.c | |||
@@ -3,6 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Copyright (C) Canonical Ltd. <seth.forshee@canonical.com> | 4 | * Copyright (C) Canonical Ltd. <seth.forshee@canonical.com> |
5 | * Copyright (C) 2010-2012 Andreas Heider <andreas@meetr.de> | 5 | * Copyright (C) 2010-2012 Andreas Heider <andreas@meetr.de> |
6 | * Copyright (C) 2015 Lukas Wunner <lukas@wunner.de> | ||
6 | * | 7 | * |
7 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License version 2 as | 9 | * it under the terms of the GNU General Public License version 2 as |
@@ -26,6 +27,24 @@ | |||
26 | #include <acpi/video.h> | 27 | #include <acpi/video.h> |
27 | #include <asm/io.h> | 28 | #include <asm/io.h> |
28 | 29 | ||
30 | /** | ||
31 | * DOC: Overview | ||
32 | * | ||
33 | * :1: http://www.latticesemi.com/en/Products/FPGAandCPLD/LatticeXP2.aspx | ||
34 | * :2: http://www.renesas.com/products/mpumcu/h8s/h8s2100/h8s2113/index.jsp | ||
35 | * | ||
36 | * gmux is a microcontroller built into the MacBook Pro to support dual GPUs: | ||
37 | * A {1}[Lattice XP2] on pre-retinas, a {2}[Renesas R4F2113] on retinas. | ||
38 | * | ||
39 | * (The MacPro6,1 2013 also has a gmux, however it is unclear why since it has | ||
40 | * dual GPUs but no built-in display.) | ||
41 | * | ||
42 | * gmux is connected to the LPC bus of the southbridge. Its I/O ports are | ||
43 | * accessed differently depending on the microcontroller: Driver functions | ||
44 | * to access a pre-retina gmux are infixed `_pio_`, those for a retina gmux | ||
45 | * are infixed `_index_`. | ||
46 | */ | ||
47 | |||
29 | struct apple_gmux_data { | 48 | struct apple_gmux_data { |
30 | unsigned long iostart; | 49 | unsigned long iostart; |
31 | unsigned long iolen; | 50 | unsigned long iolen; |
@@ -247,6 +266,20 @@ static bool gmux_is_indexed(struct apple_gmux_data *gmux_data) | |||
247 | return false; | 266 | return false; |
248 | } | 267 | } |
249 | 268 | ||
269 | /** | ||
270 | * DOC: Backlight control | ||
271 | * | ||
272 | * :3: http://www.ti.com/lit/ds/symlink/lp8543.pdf | ||
273 | * :4: http://www.ti.com/lit/ds/symlink/lp8545.pdf | ||
274 | * | ||
275 | * On single GPU MacBooks, the PWM signal for the backlight is generated by | ||
276 | * the GPU. On dual GPU MacBook Pros by contrast, either GPU may be suspended | ||
277 | * to conserve energy. Hence the PWM signal needs to be generated by a separate | ||
278 | * backlight driver which is controlled by gmux. The earliest generation | ||
279 | * MBP5 2008/09 uses a {3}[TI LP8543] backlight driver. All newer models | ||
280 | * use a {4}[TI LP8545]. | ||
281 | */ | ||
282 | |||
250 | static int gmux_get_brightness(struct backlight_device *bd) | 283 | static int gmux_get_brightness(struct backlight_device *bd) |
251 | { | 284 | { |
252 | struct apple_gmux_data *gmux_data = bl_get_data(bd); | 285 | struct apple_gmux_data *gmux_data = bl_get_data(bd); |
@@ -273,6 +306,68 @@ static const struct backlight_ops gmux_bl_ops = { | |||
273 | .update_status = gmux_update_status, | 306 | .update_status = gmux_update_status, |
274 | }; | 307 | }; |
275 | 308 | ||
309 | /** | ||
310 | * DOC: Graphics mux | ||
311 | * | ||
312 | * :5: http://pimg-fpiw.uspto.gov/fdd/07/870/086/0.pdf | ||
313 | * :6: http://www.nxp.com/documents/data_sheet/CBTL06141.pdf | ||
314 | * :7: http://www.ti.com/lit/ds/symlink/hd3ss212.pdf | ||
315 | * :8: https://www.pericom.com/assets/Datasheets/PI3VDP12412.pdf | ||
316 | * :9: http://www.ti.com/lit/ds/symlink/sn74lv4066a.pdf | ||
317 | * :10: http://pdf.datasheetarchive.com/indexerfiles/Datasheets-SW16/DSASW00308511.pdf | ||
318 | * :11: http://www.ti.com/lit/ds/symlink/ts3ds10224.pdf | ||
319 | * | ||
320 | * On pre-retinas, the LVDS outputs of both GPUs feed into gmux which muxes | ||
321 | * either of them to the panel. One of the tricks gmux has up its sleeve is | ||
322 | * to lengthen the blanking interval of its output during a switch to | ||
323 | * synchronize it with the GPU switched to. This allows for a flicker-free | ||
324 | * switch that is imperceptible by the user ({5}[US 8,687,007 B2]). | ||
325 | * | ||
326 | * On retinas, muxing is no longer done by gmux itself, but by a separate | ||
327 | * chip which is controlled by gmux. The chip is triple sourced, it is | ||
328 | * either an {6}[NXP CBTL06142], {7}[TI HD3SS212] or {8}[Pericom PI3VDP12412]. | ||
329 | * The panel is driven with eDP instead of LVDS since the pixel clock | ||
330 | * required for retina resolution exceeds LVDS' limits. | ||
331 | * | ||
332 | * Pre-retinas are able to switch the panel's DDC pins separately. | ||
333 | * This is handled by a {9}[TI SN74LV4066A] which is controlled by gmux. | ||
334 | * The inactive GPU can thus probe the panel's EDID without switching over | ||
335 | * the entire panel. Retinas lack this functionality as the chips used for | ||
336 | * eDP muxing are incapable of switching the AUX channel separately (see | ||
337 | * the linked data sheets, Pericom would be capable but this is unused). | ||
338 | * However the retina panel has the NO_AUX_HANDSHAKE_LINK_TRAINING bit set | ||
339 | * in its DPCD, allowing the inactive GPU to skip the AUX handshake and | ||
340 | * set up the output with link parameters pre-calibrated by the active GPU. | ||
341 | * | ||
342 | * The external DP port is only fully switchable on the first two unibody | ||
343 | * MacBook Pro generations, MBP5 2008/09 and MBP6 2010. This is done by an | ||
344 | * {6}[NXP CBTL06141] which is controlled by gmux. It's the predecessor of the | ||
345 | * eDP mux on retinas, the difference being support for 2.7 versus 5.4 Gbit/s. | ||
346 | * | ||
347 | * The following MacBook Pro generations replaced the external DP port with a | ||
348 | * combined DP/Thunderbolt port and lost the ability to switch it between GPUs, | ||
349 | * connecting it either to the discrete GPU or the Thunderbolt controller. | ||
350 | * Oddly enough, while the full port is no longer switchable, AUX and HPD | ||
351 | * are still switchable by way of an {10}[NXP CBTL03062] (on pre-retinas | ||
352 | * MBP8 2011 and MBP9 2012) or two {11}[TI TS3DS10224] (on retinas) under the | ||
353 | * control of gmux. Since the integrated GPU is missing the main link, | ||
354 | * external displays appear to it as phantoms which fail to link-train. | ||
355 | * | ||
356 | * gmux receives the HPD signal of all display connectors and sends an | ||
357 | * interrupt on hotplug. On generations which cannot switch external ports, | ||
358 | * the discrete GPU can then be woken to drive the newly connected display. | ||
359 | * The ability to switch AUX on these generations could be used to improve | ||
360 | * reliability of hotplug detection by having the integrated GPU poll the | ||
361 | * ports while the discrete GPU is asleep, but currently we do not make use | ||
362 | * of this feature. | ||
363 | * | ||
364 | * gmux' initial switch state on bootup is user configurable via the EFI | ||
365 | * variable `gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9` (5th byte, | ||
366 | * 1 = IGD, 0 = DIS). Based on this setting, the EFI firmware tells gmux to | ||
367 | * switch the panel and the external DP connector and allocates a framebuffer | ||
368 | * for the selected GPU. | ||
369 | */ | ||
370 | |||
276 | static int gmux_switchto(enum vga_switcheroo_client_id id) | 371 | static int gmux_switchto(enum vga_switcheroo_client_id id) |
277 | { | 372 | { |
278 | if (id == VGA_SWITCHEROO_IGD) { | 373 | if (id == VGA_SWITCHEROO_IGD) { |
@@ -288,6 +383,14 @@ static int gmux_switchto(enum vga_switcheroo_client_id id) | |||
288 | return 0; | 383 | return 0; |
289 | } | 384 | } |
290 | 385 | ||
386 | /** | ||
387 | * DOC: Power control | ||
388 | * | ||
389 | * gmux is able to cut power to the discrete GPU. It automatically takes care | ||
390 | * of the correct sequence to tear down and bring up the power rails for | ||
391 | * core voltage, VRAM and PCIe. | ||
392 | */ | ||
393 | |||
291 | static int gmux_set_discrete_state(struct apple_gmux_data *gmux_data, | 394 | static int gmux_set_discrete_state(struct apple_gmux_data *gmux_data, |
292 | enum vga_switcheroo_state state) | 395 | enum vga_switcheroo_state state) |
293 | { | 396 | { |
@@ -352,6 +455,16 @@ static const struct vga_switcheroo_handler gmux_handler = { | |||
352 | .get_client_id = gmux_get_client_id, | 455 | .get_client_id = gmux_get_client_id, |
353 | }; | 456 | }; |
354 | 457 | ||
458 | /** | ||
459 | * DOC: Interrupt | ||
460 | * | ||
461 | * gmux is also connected to a GPIO pin of the southbridge and thereby is able | ||
462 | * to trigger an ACPI GPE. On the MBP5 2008/09 it's GPIO pin 22 of the Nvidia | ||
463 | * MCP79, on all following generations it's GPIO pin 6 of the Intel PCH. | ||
464 | * The GPE merely signals that an interrupt occurred, the actual type of event | ||
465 | * is identified by reading a gmux register. | ||
466 | */ | ||
467 | |||
355 | static inline void gmux_disable_interrupts(struct apple_gmux_data *gmux_data) | 468 | static inline void gmux_disable_interrupts(struct apple_gmux_data *gmux_data) |
356 | { | 469 | { |
357 | gmux_write8(gmux_data, GMUX_PORT_INTERRUPT_ENABLE, | 470 | gmux_write8(gmux_data, GMUX_PORT_INTERRUPT_ENABLE, |