From d7dcc44eb97dcf99093e64b887b9dc2296a31d21 Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Tue, 25 Jul 2017 17:40:36 +0200 Subject: drvs/lenovo/hybrid_graphics: Add new hybrid graphics driver Introduce a chip_driver that uses devicetree instead of Kconfig. The new driver has the following advantages: * No more wasted IGD GFX stolen memory * Can be used by T500 series * Is even run on devices that do not have a dGPU installed * Can disable unused PEG port on devices without dGPU (and save power) * Use devicetree instead of Kconfig options * Support for multiple hybrid GPIO active levels * Support for backlight control GPIO * Support for _ROM on Optimus capable devices The driver is split into romstage part and ramstage part. Every mainboard has to call the driver in romstage to get the requested GPU state. The mainboard code then has to toggle GPU power or disable the IGD or PEG port. The ramstage part does handle the hygrid graphics GPIO, including optional backlight mux GPIO. Every GPIO can have it's own active level, as defined in devicetree. Devices are no longer disabled in ramstage. The existing hybrid graphics driver does the same configuration and should not interfere with this commit until it has been removed. Change-Id: Ie467f9a18b35ab3b8a523dbf51c5575db5b374a5 Signed-off-by: Patrick Rudolph Reviewed-on: https://review.coreboot.org/20792 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber Reviewed-by: Arthur Heymans --- .../lenovo/hybrid_graphics/hybrid_graphics.c | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/drivers/lenovo/hybrid_graphics/hybrid_graphics.c (limited to 'src/drivers/lenovo/hybrid_graphics/hybrid_graphics.c') diff --git a/src/drivers/lenovo/hybrid_graphics/hybrid_graphics.c b/src/drivers/lenovo/hybrid_graphics/hybrid_graphics.c new file mode 100644 index 0000000000..4fa5b81e8e --- /dev/null +++ b/src/drivers/lenovo/hybrid_graphics/hybrid_graphics.c @@ -0,0 +1,72 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2017 Patrick Rudolph + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +#include +#include +#include "chip.h" + +/* + * Switch panel mux or backlight mux to active GPU. + * In case both GPUs are active switch panel mux to integrated. + */ +static void lenovo_hybrid_graphics_enable(struct device *dev) +{ + const struct drivers_lenovo_hybrid_graphics_config *config; + enum hybrid_graphics_req mode = HYBRID_GRAPHICS_DEFAULT_GPU; + + /* Don't confuse anyone else and disable the fake device */ + dev->enabled = 0; + + config = dev->chip_info; + if (!config || (get_gpio(config->detect_gpio) == DGPU_NOT_INSTALLED)) { + printk(BIOS_DEBUG, "Hybrid graphics: Not installed\n"); + return; + } + + get_option(&mode, "hybrid_graphics_mode"); + + if (mode == HYBRID_GRAPHICS_DISCRETE) { + printk(BIOS_DEBUG, "Hybrid graphics:" + " Switching panel to discrete GPU.\n"); + + if (config->has_panel_hybrid_gpio) + set_gpio(config->panel_hybrid_gpio, + !config->panel_integrated_lvl); + + if (config->has_backlight_gpio) + set_gpio(config->backlight_gpio, + !config->backlight_integrated_lvl); + } else { + printk(BIOS_DEBUG, "Hybrid graphics:" + " Switching panel to integrated GPU.\n"); + + if (config->has_panel_hybrid_gpio) + set_gpio(config->panel_hybrid_gpio, + config->panel_integrated_lvl); + + if (config->has_backlight_gpio) + set_gpio(config->backlight_gpio, + config->backlight_integrated_lvl); + } +} + +struct chip_operations drivers_lenovo_hybrid_graphics_ops = { + CHIP_NAME("Lenovo hybrid graphics driver") + .enable_dev = &lenovo_hybrid_graphics_enable +}; -- cgit v1.2.3