Patrick Rudolph | d7dcc44 | 2017-07-25 17:40:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2017 Patrick Rudolph <siro@das-labor.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <types.h> |
| 17 | #include <option.h> |
| 18 | #include <device/device.h> |
| 19 | |
| 20 | #include <southbridge/intel/common/gpio.h> |
| 21 | #include <console/console.h> |
| 22 | #include "chip.h" |
| 23 | |
| 24 | /* |
| 25 | * Switch panel mux or backlight mux to active GPU. |
| 26 | * In case both GPUs are active switch panel mux to integrated. |
| 27 | */ |
| 28 | static void lenovo_hybrid_graphics_enable(struct device *dev) |
| 29 | { |
| 30 | const struct drivers_lenovo_hybrid_graphics_config *config; |
| 31 | enum hybrid_graphics_req mode = HYBRID_GRAPHICS_DEFAULT_GPU; |
| 32 | |
| 33 | /* Don't confuse anyone else and disable the fake device */ |
| 34 | dev->enabled = 0; |
| 35 | |
| 36 | config = dev->chip_info; |
| 37 | if (!config || (get_gpio(config->detect_gpio) == DGPU_NOT_INSTALLED)) { |
| 38 | printk(BIOS_DEBUG, "Hybrid graphics: Not installed\n"); |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | get_option(&mode, "hybrid_graphics_mode"); |
| 43 | |
| 44 | if (mode == HYBRID_GRAPHICS_DISCRETE) { |
| 45 | printk(BIOS_DEBUG, "Hybrid graphics:" |
| 46 | " Switching panel to discrete GPU.\n"); |
| 47 | |
| 48 | if (config->has_panel_hybrid_gpio) |
| 49 | set_gpio(config->panel_hybrid_gpio, |
| 50 | !config->panel_integrated_lvl); |
| 51 | |
| 52 | if (config->has_backlight_gpio) |
| 53 | set_gpio(config->backlight_gpio, |
| 54 | !config->backlight_integrated_lvl); |
| 55 | } else { |
| 56 | printk(BIOS_DEBUG, "Hybrid graphics:" |
| 57 | " Switching panel to integrated GPU.\n"); |
| 58 | |
| 59 | if (config->has_panel_hybrid_gpio) |
| 60 | set_gpio(config->panel_hybrid_gpio, |
| 61 | config->panel_integrated_lvl); |
| 62 | |
| 63 | if (config->has_backlight_gpio) |
| 64 | set_gpio(config->backlight_gpio, |
| 65 | config->backlight_integrated_lvl); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | struct chip_operations drivers_lenovo_hybrid_graphics_ops = { |
| 70 | CHIP_NAME("Lenovo hybrid graphics driver") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame^] | 71 | .enable_dev = lenovo_hybrid_graphics_enable |
Patrick Rudolph | d7dcc44 | 2017-07-25 17:40:36 +0200 | [diff] [blame] | 72 | }; |