Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Patrick Rudolph | d7dcc44 | 2017-07-25 17:40:36 +0200 | [diff] [blame] | 3 | |
| 4 | #include <types.h> |
| 5 | #include <option.h> |
| 6 | #include <device/device.h> |
| 7 | |
| 8 | #include <southbridge/intel/common/gpio.h> |
| 9 | #include <ec/lenovo/pmh7/pmh7.h> |
| 10 | #include <console/console.h> |
Patrick Rudolph | d7dcc44 | 2017-07-25 17:40:36 +0200 | [diff] [blame] | 11 | |
| 12 | #include "hybrid_graphics.h" |
| 13 | #include "chip.h" |
| 14 | |
| 15 | /* |
| 16 | * Returns the hybrid graphics presence and user's card preferences. |
| 17 | */ |
| 18 | void early_hybrid_graphics(bool *enable_igd, bool *enable_peg) |
| 19 | { |
| 20 | const struct drivers_lenovo_hybrid_graphics_config *config; |
| 21 | const struct device *dev; |
| 22 | enum hybrid_graphics_req mode = HYBRID_GRAPHICS_DEFAULT_GPU; |
| 23 | |
| 24 | /* TODO: Use generic device instead of dummy PNP device */ |
| 25 | dev = dev_find_slot_pnp(HYBRID_GRAPHICS_PORT, HYBRID_GRAPHICS_DEVICE); |
| 26 | |
| 27 | if (!dev || !dev->chip_info) { |
| 28 | printk(BIOS_ERR, "Hybrid graphics: ERROR\n"); |
| 29 | *enable_igd = true; |
| 30 | *enable_peg = false; |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | config = dev->chip_info; |
| 35 | if (get_gpio(config->detect_gpio) == DGPU_NOT_INSTALLED) { |
| 36 | printk(BIOS_DEBUG, "Hybrid graphics:" |
| 37 | " No discrete GPU present.\n"); |
| 38 | *enable_igd = true; |
| 39 | *enable_peg = false; |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | get_option(&mode, "hybrid_graphics_mode"); |
| 44 | |
| 45 | if (mode == HYBRID_GRAPHICS_DISCRETE) { |
| 46 | printk(BIOS_DEBUG, "Hybrid graphics:" |
| 47 | " Disabling integrated GPU.\n"); |
| 48 | |
| 49 | *enable_igd = false; |
| 50 | *enable_peg = true; |
| 51 | } else if (mode == HYBRID_GRAPHICS_INTEGRATED) { |
| 52 | printk(BIOS_DEBUG, "Hybrid graphics:" |
| 53 | " Disabling discrete GPU.\n"); |
| 54 | |
| 55 | *enable_igd = true; |
| 56 | *enable_peg = false; |
| 57 | } else { |
| 58 | printk(BIOS_DEBUG, "Hybrid graphics:" |
| 59 | " Activating Switchable (both GPUs).\n"); |
| 60 | |
| 61 | *enable_igd = true; |
| 62 | *enable_peg = true; |
| 63 | } |
| 64 | |
| 65 | /* |
Patrick Rudolph | e07e390 | 2017-11-04 20:13:22 +0100 | [diff] [blame] | 66 | * Need to do power handling here as we know there's a dGPU. |
| 67 | * Support GPIO and Thinker1. |
Patrick Rudolph | d7dcc44 | 2017-07-25 17:40:36 +0200 | [diff] [blame] | 68 | */ |
Patrick Rudolph | e07e390 | 2017-11-04 20:13:22 +0100 | [diff] [blame] | 69 | if (config->has_dgpu_power_gpio) { |
| 70 | if (*enable_peg) |
| 71 | set_gpio(config->dgpu_power_gpio, |
| 72 | !config->dgpu_power_off_lvl); |
| 73 | else |
Patrick Rudolph | d7dcc44 | 2017-07-25 17:40:36 +0200 | [diff] [blame] | 74 | set_gpio(config->dgpu_power_gpio, |
| 75 | config->dgpu_power_off_lvl); |
Patrick Rudolph | e07e390 | 2017-11-04 20:13:22 +0100 | [diff] [blame] | 76 | } else if (config->has_thinker1) { |
Evgeny Zinoviev | 384e9ae | 2018-08-30 02:18:48 +0300 | [diff] [blame] | 77 | bool power_en = pmh7_dgpu_power_state(); |
| 78 | if (*enable_peg != power_en) |
| 79 | pmh7_dgpu_power_enable(!power_en); |
Patrick Rudolph | e07e390 | 2017-11-04 20:13:22 +0100 | [diff] [blame] | 80 | } else { |
| 81 | printk(BIOS_ERR, "Hybrid graphics:" |
| 82 | " FIXME: dGPU power handling not implemented\n"); |
Patrick Rudolph | d7dcc44 | 2017-07-25 17:40:36 +0200 | [diff] [blame] | 83 | } |
| 84 | } |