blob: 55de375c43c505ef516bc5e5615397757acc24a1 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Patrick Rudolphd7dcc442017-07-25 17:40:36 +02003
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 Rudolphd7dcc442017-07-25 17:40:36 +020011
12#include "hybrid_graphics.h"
13#include "chip.h"
14
15/*
16 * Returns the hybrid graphics presence and user's card preferences.
17 */
18void 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 Rudolphe07e3902017-11-04 20:13:22 +010066 * Need to do power handling here as we know there's a dGPU.
67 * Support GPIO and Thinker1.
Patrick Rudolphd7dcc442017-07-25 17:40:36 +020068 */
Patrick Rudolphe07e3902017-11-04 20:13:22 +010069 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 Rudolphd7dcc442017-07-25 17:40:36 +020074 set_gpio(config->dgpu_power_gpio,
75 config->dgpu_power_off_lvl);
Patrick Rudolphe07e3902017-11-04 20:13:22 +010076 } else if (config->has_thinker1) {
Evgeny Zinoviev384e9ae2018-08-30 02:18:48 +030077 bool power_en = pmh7_dgpu_power_state();
78 if (*enable_peg != power_en)
79 pmh7_dgpu_power_enable(!power_en);
Patrick Rudolphe07e3902017-11-04 20:13:22 +010080 } else {
81 printk(BIOS_ERR, "Hybrid graphics:"
82 " FIXME: dGPU power handling not implemented\n");
Patrick Rudolphd7dcc442017-07-25 17:40:36 +020083 }
84}