summaryrefslogtreecommitdiff
path: root/src/drivers/lenovo/hybrid_graphics/hybrid_graphics.c
blob: 4fa5b81e8e7d1d6da08787d9ed7d06e463efc52c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 * This file is part of the coreboot project.
 *
 * Copyright (C) 2017 Patrick Rudolph <siro@das-labor.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <types.h>
#include <option.h>
#include <device/device.h>

#include <southbridge/intel/common/gpio.h>
#include <console/console.h>
#include "chip.h"

/*
 * Switch panel mux or backlight mux to active GPU.
 * In case both GPUs are active switch panel mux to integrated.
 */
static void lenovo_hybrid_graphics_enable(struct device *dev)
{
	const struct drivers_lenovo_hybrid_graphics_config *config;
	enum hybrid_graphics_req mode = HYBRID_GRAPHICS_DEFAULT_GPU;

	/* Don't confuse anyone else and disable the fake device */
	dev->enabled = 0;

	config = dev->chip_info;
	if (!config || (get_gpio(config->detect_gpio) == DGPU_NOT_INSTALLED)) {
		printk(BIOS_DEBUG, "Hybrid graphics: Not installed\n");
		return;
	}

	get_option(&mode, "hybrid_graphics_mode");

	if (mode == HYBRID_GRAPHICS_DISCRETE) {
		printk(BIOS_DEBUG, "Hybrid graphics:"
		       " Switching panel to discrete GPU.\n");

		if (config->has_panel_hybrid_gpio)
			set_gpio(config->panel_hybrid_gpio,
				 !config->panel_integrated_lvl);

		if (config->has_backlight_gpio)
			set_gpio(config->backlight_gpio,
				 !config->backlight_integrated_lvl);
	} else {
		printk(BIOS_DEBUG, "Hybrid graphics:"
		       " Switching panel to integrated GPU.\n");

		if (config->has_panel_hybrid_gpio)
			set_gpio(config->panel_hybrid_gpio,
				 config->panel_integrated_lvl);

		if (config->has_backlight_gpio)
			set_gpio(config->backlight_gpio,
				 config->backlight_integrated_lvl);
	}
}

struct chip_operations drivers_lenovo_hybrid_graphics_ops = {
	CHIP_NAME("Lenovo hybrid graphics driver")
	.enable_dev = &lenovo_hybrid_graphics_enable
};