<p>Patrick Rudolph has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/20792">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">drvs/lenovo/hybrid_graphics: Add new hybrid graphics driver<br><br>Introduce a chip_driver that uses devicetree instead of Kconfig.<br><br>The new driver has the following advantages:<br><br>* No more wasted IGD GFX stolen memory<br>* Can be used by T500 series<br>* Is even run on devices that do not have a dGPU installed<br>* Can disable unused PEG port on devices without dGPU (and save power)<br>* Use devicetree instead of Kconfig options<br>* Support for multiple hybrid GPIO active levels<br>* Support for backlight control GPIO<br>* Support for _ROM on Optimus capable devices<br><br>The driver is split into romstage part and ramstage part.<br><br>Every mainboard has to call the driver in romstage to get the requested<br>GPU state. The mainboard code then has to toggle GPU power or disable the<br>IGD or PEG port.<br><br>The ramstage part does handle the hygrid graphics GPIO, including optional<br>backlight mux GPIO. Every GPIO can have it's own active level, as defined<br>in devicetree. Devices are no longer disabled in ramstage.<br><br>The existing hybrid graphics driver does the same configuration and should<br>not interfere with this commit until it has been removed.<br><br>Change-Id: Ie467f9a18b35ab3b8a523dbf51c5575db5b374a5<br>Signed-off-by: Patrick Rudolph <siro@das-labor.org><br>---<br>A src/drivers/lenovo/hybrid_graphics/Kconfig<br>A src/drivers/lenovo/hybrid_graphics/Makefile.inc<br>A src/drivers/lenovo/hybrid_graphics/chip.h<br>A src/drivers/lenovo/hybrid_graphics/hybrid_graphics.c<br>A src/drivers/lenovo/hybrid_graphics/hybrid_graphics.h<br>A src/drivers/lenovo/hybrid_graphics/romstage.c<br>6 files changed, 232 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/92/20792/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/src/drivers/lenovo/hybrid_graphics/Kconfig b/src/drivers/lenovo/hybrid_graphics/Kconfig<br>new file mode 100644<br>index 0000000..389dfb9<br>--- /dev/null<br>+++ b/src/drivers/lenovo/hybrid_graphics/Kconfig<br>@@ -0,0 +1,3 @@<br>+config DRIVERS_LENOVO_HYBRID_GRAPHICS<br>+ bool<br>+ default n<br>diff --git a/src/drivers/lenovo/hybrid_graphics/Makefile.inc b/src/drivers/lenovo/hybrid_graphics/Makefile.inc<br>new file mode 100644<br>index 0000000..d9e5079<br>--- /dev/null<br>+++ b/src/drivers/lenovo/hybrid_graphics/Makefile.inc<br>@@ -0,0 +1,15 @@<br>+#<br>+# This file is part of the coreboot project.<br>+#<br>+# This program is free software; you can redistribute it and/or modify<br>+# it under the terms of the GNU General Public License as published by<br>+# the Free Software Foundation; version 2 of the License.<br>+#<br>+# This program is distributed in the hope that it will be useful,<br>+# but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>+# GNU General Public License for more details.<br>+#<br>+<br>+ramstage-$(CONFIG_DRIVERS_LENOVO_HYBRID_GRAPHICS) += hybrid_graphics.c<br>+romstage-$(CONFIG_DRIVERS_LENOVO_HYBRID_GRAPHICS) += romstage.c<br>diff --git a/src/drivers/lenovo/hybrid_graphics/chip.h b/src/drivers/lenovo/hybrid_graphics/chip.h<br>new file mode 100644<br>index 0000000..d5ce74e<br>--- /dev/null<br>+++ b/src/drivers/lenovo/hybrid_graphics/chip.h<br>@@ -0,0 +1,46 @@<br>+/*<br>+ * This file is part of the coreboot project.<br>+ *<br>+ * Copyright (C) 2017 Patrick Rudolph <siro@das-labor.org><br>+ *<br>+ * This program is free software; you can redistribute it and/or modify<br>+ * it under the terms of the GNU General Public License as published by<br>+ * the Free Software Foundation; version 2 of the License.<br>+ *<br>+ * This program is distributed in the hope that it will be useful,<br>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>+ * GNU General Public License for more details.<br>+ */<br>+<br>+#ifndef _LENOVO_HYBRID_GRAPHICS_CHIP_H_<br>+#define _LENOVO_HYBRID_GRAPHICS_CHIP_H_<br>+<br>+#define HYBRID_GRAPHICS_PORT 0xff<br>+<br>+#define HYBRID_GRAPHICS_DEVICE 0xf<br>+<br>+enum hybrid_graphics_req {<br>+   HYBRID_GRAPHICS_INTEGRATED = 0,<br>+      HYBRID_GRAPHICS_DISCRETE = 1,<br>+        HYBRID_GRAPHICS_DUAL = 2<br>+};<br>+<br>+enum dgpu_detect_lvl {<br>+    DGPU_INSTALLED = 0,<br>+  DGPU_NOT_INSTALLED = 1,<br>+};<br>+<br>+struct drivers_lenovo_hybrid_graphics_config {<br>+     unsigned int detect_gpio;<br>+<br>+ unsigned int has_panel_hybrid_gpio;<br>+  unsigned int panel_hybrid_gpio;<br>+      unsigned int panel_integrated_lvl;<br>+<br>+        unsigned int has_backlight_gpio;<br>+     unsigned int backlight_gpio;<br>+ unsigned int backlight_integrated_lvl;<br>+};<br>+<br>+#endif /* _LENOVO_HYBRID_GRAPHICS_CHIP_H_ */<br>diff --git a/src/drivers/lenovo/hybrid_graphics/hybrid_graphics.c b/src/drivers/lenovo/hybrid_graphics/hybrid_graphics.c<br>new file mode 100644<br>index 0000000..ab13747<br>--- /dev/null<br>+++ b/src/drivers/lenovo/hybrid_graphics/hybrid_graphics.c<br>@@ -0,0 +1,73 @@<br>+/*<br>+ * This file is part of the coreboot project.<br>+ *<br>+ * Copyright (C) 2017 Patrick Rudolph <siro@das-labor.org><br>+ *<br>+ * This program is free software; you can redistribute it and/or modify<br>+ * it under the terms of the GNU General Public License as published by<br>+ * the Free Software Foundation; version 2 of the License.<br>+ *<br>+ * This program is distributed in the hope that it will be useful,<br>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>+ * GNU General Public License for more details.<br>+ */<br>+<br>+#include <types.h><br>+#include <option.h><br>+#include <device/device.h><br>+#include <device/pci_def.h><br>+<br>+#include <southbridge/intel/common/gpio.h><br>+#include <console/console.h><br>+#include "chip.h"<br>+<br>+/*<br>+ * Switch panel mux or backlight mux to active GPU.<br>+ * In case both GPUs are active switch panel mux to integrated.<br>+ */<br>+static void lenovo_hybrid_graphics_enable(struct device *dev)<br>+{<br>+   const struct drivers_lenovo_hybrid_graphics_config *config;<br>+  enum hybrid_graphics_req mode = HYBRID_GRAPHICS_INTEGRATED;<br>+<br>+       /* Don't confuse anyone else and disable the fake device */<br>+      dev->enabled = 0;<br>+<br>+      config = dev->chip_info;<br>+  if (!config || (get_gpio(config->detect_gpio) == DGPU_NOT_INSTALLED)) {<br>+           printk(BIOS_DEBUG, "Hybrid graphics: Not installed\n");<br>+            return;<br>+      }<br>+<br>+ get_option(&mode, "hybrid_graphics_mode");<br>+<br>+  if (mode == HYBRID_GRAPHICS_DISCRETE) {<br>+              printk(BIOS_DEBUG, "Hybrid graphics:"<br>+                     " Switching panel to discrete GPU.\n");<br>+<br>+          if (config->has_panel_hybrid_gpio)<br>+                        set_gpio(config->panel_hybrid_gpio,<br>+                                ~config->panel_integrated_lvl);<br>+<br>+               if (config->has_backlight_gpio)<br>+                   set_gpio(config->backlight_gpio,<br>+                           ~config->backlight_integrated_lvl);<br>+      } else {<br>+             printk(BIOS_DEBUG, "Hybrid graphics:"<br>+                     " Switching panel to integrated GPU.\n");<br>+<br>+                if (config->has_panel_hybrid_gpio)<br>+                        set_gpio(config->panel_hybrid_gpio,<br>+                                config->panel_integrated_lvl);<br>+<br>+                if (config->has_backlight_gpio)<br>+                   set_gpio(config->backlight_gpio,<br>+                           config->backlight_integrated_lvl);<br>+       }<br>+}<br>+<br>+struct chip_operations drivers_lenovo_hybrid_graphics_ops = {<br>+     CHIP_NAME("Lenovo hybrid graphics driver")<br>+ .enable_dev = &lenovo_hybrid_graphics_enable<br>+};<br>diff --git a/src/drivers/lenovo/hybrid_graphics/hybrid_graphics.h b/src/drivers/lenovo/hybrid_graphics/hybrid_graphics.h<br>new file mode 100644<br>index 0000000..b238440<br>--- /dev/null<br>+++ b/src/drivers/lenovo/hybrid_graphics/hybrid_graphics.h<br>@@ -0,0 +1,21 @@<br>+/*<br>+ * This file is part of the coreboot project.<br>+ *<br>+ * Copyright (C) 2017 Patrick Rudolph <siro@das-labor.org><br>+ *<br>+ * This program is free software; you can redistribute it and/or modify<br>+ * it under the terms of the GNU General Public License as published by<br>+ * the Free Software Foundation; version 2 of the License.<br>+ *<br>+ * This program is distributed in the hope that it will be useful,<br>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>+ * GNU General Public License for more details.<br>+ */<br>+<br>+#ifndef _DRIVERS_LENOVO_HYBRID_GRAPHICS_H_<br>+#define _DRIVERS_LENOVO_HYBRID_GRAPHICS_H_<br>+<br>+void early_hybrid_graphics(bool *enable_igd, bool *enable_peg);<br>+<br>+#endif /* _DRIVERS_LENOVO_HYBRID_GRAPHICS_CHIP_H_ */<br>diff --git a/src/drivers/lenovo/hybrid_graphics/romstage.c b/src/drivers/lenovo/hybrid_graphics/romstage.c<br>new file mode 100644<br>index 0000000..53eb4a0<br>--- /dev/null<br>+++ b/src/drivers/lenovo/hybrid_graphics/romstage.c<br>@@ -0,0 +1,74 @@<br>+/*<br>+ * This file is part of the coreboot project.<br>+ *<br>+ * Copyright (C) 2017 Patrick Rudolph <siro@das-labor.org><br>+ *<br>+ * This program is free software; you can redistribute it and/or modify<br>+ * it under the terms of the GNU General Public License as published by<br>+ * the Free Software Foundation; version 2 of the License.<br>+ *<br>+ * This program is distributed in the hope that it will be useful,<br>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>+ * GNU General Public License for more details.<br>+ */<br>+<br>+#include <types.h><br>+#include <option.h><br>+#include <device/device.h><br>+#include <device/pci_def.h><br>+<br>+#include <southbridge/intel/common/gpio.h><br>+#include <console/console.h><br>+#include "hybrid_graphics.h"<br>+#include "chip.h"<br>+<br>+/*<br>+ * Returns the hybrid graphics presence and user's card preferences.<br>+ */<br>+void early_hybrid_graphics(bool *enable_igd, bool *enable_peg)<br>+{<br>+      const struct drivers_lenovo_hybrid_graphics_config *config;<br>+  const struct device *dev;<br>+    enum hybrid_graphics_req mode = HYBRID_GRAPHICS_INTEGRATED;<br>+<br>+       dev = dev_find_slot_pnp(HYBRID_GRAPHICS_PORT, HYBRID_GRAPHICS_DEVICE);<br>+<br>+    if (!dev || !dev->chip_info) {<br>+            printk(BIOS_ERR, "Hybrid graphics: ERROR\n");<br>+              *enable_igd = true;<br>+          *enable_peg = false;<br>+         return;<br>+      }<br>+<br>+ config = dev->chip_info;<br>+  if (get_gpio(config->detect_gpio) == DGPU_NOT_INSTALLED) {<br>+                printk(BIOS_DEBUG, "Hybrid graphics:"<br>+                     " No discrete GPU present.\n");<br>+             *enable_igd = true;<br>+          *enable_peg = false;<br>+         return;<br>+      }<br>+<br>+ get_option(&mode, "hybrid_graphics_mode");<br>+<br>+  if (mode == HYBRID_GRAPHICS_DISCRETE) {<br>+              printk(BIOS_DEBUG, "Hybrid graphics:"<br>+                     " Disabling integrated GPU.\n");<br>+<br>+         *enable_igd = false;<br>+         *enable_peg = true;<br>+  } else if (mode == HYBRID_GRAPHICS_INTEGRATED) {<br>+             printk(BIOS_DEBUG, "Hybrid graphics:"<br>+                     " Disabling discrete GPU.\n");<br>+<br>+           *enable_igd = true;<br>+          *enable_peg = false;<br>+ } else {<br>+             printk(BIOS_DEBUG, "Hybrid graphics:"<br>+                     " Activating Switchable (both GPUs).\n");<br>+<br>+                *enable_igd = true;<br>+          *enable_peg = true;<br>+  }<br>+}<br></pre><p>To view, visit <a href="https://review.coreboot.org/20792">change 20792</a>. To unsubscribe, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/20792"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ie467f9a18b35ab3b8a523dbf51c5575db5b374a5 </div>
<div style="display:none"> Gerrit-Change-Number: 20792 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Patrick Rudolph <siro@das-labor.org> </div>