coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
bootblock.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <bootblock_common.h>
4 #include <console/console.h>
5 #include <delay.h>
6 #include <gpio.h>
7 #include "include/ec.h"
8 #include "include/gpio.h"
9 
10 #define ADC_3V_10BIT_GRANULARITY_MAX (3005 / 1023)
11 #define PCB_VER_AD 1
12 #define MODEL_ID_AD 3
13 
14 #define DGPU_PRESENT GPP_A20 /* Active low */
15 #define DGPU_HOLD_RST GPP_B4 /* Active low */
16 #define DGPU_PWR_EN GPP_B21 /* Active low */
17 
18 /* TODO/NB: Detection is still unreliable. Is a wait required? */
19 static void board_detect(void)
20 {
21  printk(BIOS_DEBUG, "Mainboard: Detecting board SKU\n");
22 
24  printk(BIOS_DEBUG, "BoardId (raw) = 0x%x\n", data_buffer);
25  printk(BIOS_DEBUG, "BoardId: ");
26  /* Board by max millivoltage range (of 10-bit, 3.005 V ADC) */
27  if (data_buffer <= (1374 / ADC_3V_10BIT_GRANULARITY_MAX)) {
28  printk(BIOS_ERR, "Reserved?\n");
29  } else if (data_buffer <= (2017 / ADC_3V_10BIT_GRANULARITY_MAX)) {
30  printk(BIOS_DEBUG, "Aspire VN7-792G (Newgate-SLS_dGPU)\n");
31  printk(BIOS_CRIT, "WARNING: This board is unsupported!\n");
32  printk(BIOS_CRIT, "Damage may result from programming incorrect GPIO table!\n");
33  } else if (data_buffer <= (2259 / ADC_3V_10BIT_GRANULARITY_MAX)) {
34  printk(BIOS_DEBUG, "Aspire VN7-592G (Rayleigh-SLS_960M)\n");
35  printk(BIOS_CRIT, "WARNING: This board is unsupported!\n");
36  printk(BIOS_CRIT, "Damage may result from programming incorrect GPIO table!\n");
37  } else {
38  printk(BIOS_DEBUG, "Aspire VN7-572G (Rayleigh-SL_dGPU)\n");
39  }
40 
41  data_buffer = read_ec_adc_converter(PCB_VER_AD);
42  printk(BIOS_DEBUG, "PCB version (raw) = 0x%x\n", data_buffer);
43  printk(BIOS_DEBUG, "PCB version: ");
44  /* PCB by max millivoltage range (of 10-bit, 3.005 V ADC) */
45  if (data_buffer <= (2017 / ADC_3V_10BIT_GRANULARITY_MAX)) {
46  printk(BIOS_ERR, "Reserved?\n");
47  } else if (data_buffer <= (2259 / ADC_3V_10BIT_GRANULARITY_MAX)) {
48  printk(BIOS_DEBUG, "-1\n");
49  } else if (data_buffer <= (2493 / ADC_3V_10BIT_GRANULARITY_MAX)) {
50  printk(BIOS_DEBUG, "SC\n");
51  } else if (data_buffer <= (2759 / ADC_3V_10BIT_GRANULARITY_MAX)) {
52  printk(BIOS_DEBUG, "SB\n");
53  } else {
54  printk(BIOS_DEBUG, "SA\n");
55  }
56 }
57 
58 static void dgpu_power_on(void)
59 {
60  if (!gpio_get(DGPU_PRESENT)) {
61  printk(BIOS_DEBUG, "dGPU present, enable power...\n");
62  gpio_set(DGPU_HOLD_RST, 0); // Assert dGPU_HOLD_RST#
63  mdelay(2);
64  gpio_set(DGPU_PWR_EN, 0); // Assert dGPU_PWR_EN#
65  mdelay(7);
66  gpio_set(DGPU_HOLD_RST, 1); // Deassert dGPU_HOLD_RST#
67  mdelay(30);
68  } else {
69  printk(BIOS_DEBUG, "dGPU not present, disable power...\n");
70  gpio_set(DGPU_HOLD_RST, 0); // Assert dGPU_HOLD_RST#
71  gpio_set(DGPU_PWR_EN, 1); // Deassert dGPU_PWR_EN#
72  }
73 }
74 
76 {
77  /* NB: Relocated from _early_init() so that debug logging works.
78  * However, if we use this to ensure that the user flashed the correct
79  * (future) variant, this must occur before any GPIOs are programmed.
80  */
81  board_detect();
82  dgpu_power_on();
83 }
84 
86 {
88 }
#define printk(level,...)
Definition: stdlib.h:16
void mdelay(unsigned int msecs)
Definition: delay.c:2
int gpio_get(gpio_t gpio)
Definition: gpio.c:166
void gpio_set(gpio_t gpio, int value)
Definition: gpio.c:174
__weak void bootblock_mainboard_init(void)
Definition: bootblock.c:19
__weak void bootblock_mainboard_early_init(void)
Definition: bootblock.c:16
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_CRIT
BIOS_CRIT - Recovery unlikely.
Definition: loglevel.h:56
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
static void dgpu_power_on(void)
Definition: bootblock.c:58
#define PCB_VER_AD
Definition: bootblock.c:11
#define DGPU_PWR_EN
Definition: bootblock.c:16
#define DGPU_HOLD_RST
Definition: bootblock.c:15
#define DGPU_PRESENT
Definition: bootblock.c:14
#define ADC_3V_10BIT_GRANULARITY_MAX
Definition: bootblock.c:10
static void board_detect(void)
Definition: bootblock.c:19
#define MODEL_ID_AD
Definition: bootblock.c:12
uint16_t read_ec_adc_converter(uint8_t adc)
Definition: ec.c:69
void mainboard_config_stage_gpios(void)
Definition: gpio.c:371
unsigned short uint16_t
Definition: stdint.h:11