blob: 35cb384301ec08a9af8b6652183a31e83a80f3db [file] [log] [blame]
Patrick Rudolphd7dcc442017-07-25 17:40:36 +02001/*
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 <ec/lenovo/pmh7/pmh7.h>
22#include <console/console.h>
Patrick Rudolphd7dcc442017-07-25 17:40:36 +020023
24#include "hybrid_graphics.h"
25#include "chip.h"
26
27/*
28 * Returns the hybrid graphics presence and user's card preferences.
29 */
30void early_hybrid_graphics(bool *enable_igd, bool *enable_peg)
31{
32 const struct drivers_lenovo_hybrid_graphics_config *config;
33 const struct device *dev;
34 enum hybrid_graphics_req mode = HYBRID_GRAPHICS_DEFAULT_GPU;
35
36 /* TODO: Use generic device instead of dummy PNP device */
37 dev = dev_find_slot_pnp(HYBRID_GRAPHICS_PORT, HYBRID_GRAPHICS_DEVICE);
38
39 if (!dev || !dev->chip_info) {
40 printk(BIOS_ERR, "Hybrid graphics: ERROR\n");
41 *enable_igd = true;
42 *enable_peg = false;
43 return;
44 }
45
46 config = dev->chip_info;
47 if (get_gpio(config->detect_gpio) == DGPU_NOT_INSTALLED) {
48 printk(BIOS_DEBUG, "Hybrid graphics:"
49 " No discrete GPU present.\n");
50 *enable_igd = true;
51 *enable_peg = false;
52 return;
53 }
54
55 get_option(&mode, "hybrid_graphics_mode");
56
57 if (mode == HYBRID_GRAPHICS_DISCRETE) {
58 printk(BIOS_DEBUG, "Hybrid graphics:"
59 " Disabling integrated GPU.\n");
60
61 *enable_igd = false;
62 *enable_peg = true;
63 } else if (mode == HYBRID_GRAPHICS_INTEGRATED) {
64 printk(BIOS_DEBUG, "Hybrid graphics:"
65 " Disabling discrete GPU.\n");
66
67 *enable_igd = true;
68 *enable_peg = false;
69 } else {
70 printk(BIOS_DEBUG, "Hybrid graphics:"
71 " Activating Switchable (both GPUs).\n");
72
73 *enable_igd = true;
74 *enable_peg = true;
75 }
76
77 /*
Patrick Rudolphe07e3902017-11-04 20:13:22 +010078 * Need to do power handling here as we know there's a dGPU.
79 * Support GPIO and Thinker1.
Patrick Rudolphd7dcc442017-07-25 17:40:36 +020080 */
Patrick Rudolphe07e3902017-11-04 20:13:22 +010081 if (config->has_dgpu_power_gpio) {
82 if (*enable_peg)
83 set_gpio(config->dgpu_power_gpio,
84 !config->dgpu_power_off_lvl);
85 else
Patrick Rudolphd7dcc442017-07-25 17:40:36 +020086 set_gpio(config->dgpu_power_gpio,
87 config->dgpu_power_off_lvl);
Patrick Rudolphe07e3902017-11-04 20:13:22 +010088 } else if (config->has_thinker1) {
Evgeny Zinoviev384e9ae2018-08-30 02:18:48 +030089 bool power_en = pmh7_dgpu_power_state();
90 if (*enable_peg != power_en)
91 pmh7_dgpu_power_enable(!power_en);
Patrick Rudolphe07e3902017-11-04 20:13:22 +010092 } else {
93 printk(BIOS_ERR, "Hybrid graphics:"
94 " FIXME: dGPU power handling not implemented\n");
Patrick Rudolphd7dcc442017-07-25 17:40:36 +020095 }
96}