coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
romstage.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <types.h>
4 #include <option.h>
5 #include <device/device.h>
6 
8 #include <ec/lenovo/pmh7/pmh7.h>
9 #include <console/console.h>
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 {
20  const struct device *dev;
21  enum hybrid_graphics_req mode;
22 
23  /* TODO: Use generic device instead of dummy PNP 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 
42  mode = get_uint_option("hybrid_graphics_mode", HYBRID_GRAPHICS_DEFAULT_GPU);
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  /*
65  * Need to do power handling here as we know there's a dGPU.
66  * Support GPIO and Thinker1.
67  */
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
73  set_gpio(config->dgpu_power_gpio,
74  config->dgpu_power_off_lvl);
75  } else if (config->has_thinker1) {
76  bool power_en = pmh7_dgpu_power_state();
77  if (*enable_peg != power_en)
78  pmh7_dgpu_power_enable(!power_en);
79  } else {
80  printk(BIOS_ERR, "Hybrid graphics:"
81  " FIXME: dGPU power handling not implemented\n");
82  }
83 }
#define printk(level,...)
Definition: stdlib.h:16
DEVTREE_CONST struct device * dev_find_slot_pnp(u16 port, u16 device)
Given a PnP port and a device number, find the device structure.
Definition: device_const.c:331
#define HYBRID_GRAPHICS_PORT
Definition: chip.h:6
#define HYBRID_GRAPHICS_DEFAULT_GPU
Definition: chip.h:21
@ DGPU_NOT_INSTALLED
Definition: chip.h:18
hybrid_graphics_req
Definition: chip.h:10
@ HYBRID_GRAPHICS_DISCRETE
Definition: chip.h:12
@ HYBRID_GRAPHICS_INTEGRATED
Definition: chip.h:11
#define HYBRID_GRAPHICS_DEVICE
Definition: chip.h:8
void early_hybrid_graphics(bool *enable_igd, bool *enable_peg)
Definition: romstage.c:17
int get_gpio(int community_base, int pad0_offset)
Definition: gpio_support.c:148
static void enable_igd(const sysinfo_t *const sysinfo, const int no_peg)
Definition: igd.c:16
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
enum board_config config
Definition: memory.c:448
unsigned int get_uint_option(const char *name, const unsigned int fallback)
Definition: option.c:116
bool pmh7_dgpu_power_state(void)
Definition: pmh7.c:69
void pmh7_dgpu_power_enable(int onoff)
Definition: pmh7.c:54
void set_gpio(int gpio_num, int value)
Definition: gpio.c:125
Definition: device.h:107
DEVTREE_CONST void * chip_info
Definition: device.h:164