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