coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
mainboard.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <types.h>
4 #include <device/device.h>
5 #include <device/pci_ops.h>
6 #include <console/console.h>
7 #if CONFIG(VGA_ROM_RUN)
8 #include <x86emu/x86emu.h>
9 #endif
10 #include <arch/io.h>
11 #include <arch/interrupt.h>
12 #include "onboard.h"
13 #include "ec.h"
16 #include <smbios.h>
17 #include <ec/google/chromeec/ec.h>
18 
19 #if CONFIG(VGA_ROM_RUN)
20 static int int15_handler(void)
21 {
22  int res = 0;
23 
24  printk(BIOS_DEBUG, "%s: INT15 function %04x!\n",
25  __func__, X86_AX);
26 
27  switch (X86_AX) {
28  case 0x5f34:
29  /*
30  * Set Panel Fitting Hook:
31  * bit 2 = Graphics Stretching
32  * bit 1 = Text Stretching
33  * bit 0 = Centering (do not set with bit1 or bit2)
34  * 0 = video BIOS default
35  */
36  X86_AX = 0x005f;
37  X86_CL = 0x00; /* Use video BIOS default */
38  res = 1;
39  break;
40  case 0x5f35:
41  /*
42  * Boot Display Device Hook:
43  * bit 0 = CRT
44  * bit 1 = TV (eDP)
45  * bit 2 = EFP
46  * bit 3 = LFP
47  * bit 4 = CRT2
48  * bit 5 = TV2 (eDP)
49  * bit 6 = EFP2
50  * bit 7 = LFP2
51  */
52  X86_AX = 0x005f;
53  X86_CX = 0x0000; /* Use video BIOS default */
54  res = 1;
55  break;
56  case 0x5f51:
57  /*
58  * Hook to select active LFP configuration:
59  * 00h = No LVDS, VBIOS does not enable LVDS
60  * 01h = Int-LVDS, LFP driven by integrated LVDS decoder
61  * 02h = SVDO-LVDS, LFP driven by SVDO decoder
62  * 03h = eDP, LFP Driven by Int-DisplayPort encoder
63  */
64  X86_AX = 0x005f;
65  X86_CX = 0x0003; /* eDP */
66  res = 1;
67  break;
68  case 0x5f70:
69  switch (X86_CH) {
70  case 0:
71  /* Get Mux */
72  X86_AX = 0x005f;
73  X86_CX = 0x0000;
74  res = 1;
75  break;
76  case 1:
77  /* Set Mux */
78  X86_AX = 0x005f;
79  X86_CX = 0x0000;
80  res = 1;
81  break;
82  case 2:
83  /* Get SG/Non-SG mode */
84  X86_AX = 0x005f;
85  X86_CX = 0x0000;
86  res = 1;
87  break;
88  default:
89  /* Interrupt was not handled */
90  printk(BIOS_DEBUG, "Unknown INT15 5f70 function: 0x%02x\n",
91  X86_CH);
92  break;
93  }
94  break;
95  case 0x5fac:
96  res = 1;
97  break;
98  default:
99  printk(BIOS_DEBUG, "Unknown INT15 function %04x!\n", X86_AX);
100  break;
101  }
102  return res;
103 }
104 #endif
105 
106 static void mainboard_init(struct device *dev)
107 {
108  uint32_t board_version = 0;
109 
110  /* Initialize the Embedded Controller */
111  link_ec_init();
112 
113  google_chromeec_get_board_version(&board_version);
114  if (board_version == 0) {
115  /* If running on proto1 - enable reversion of gpio11. */
116  u32 gpio_inv;
117  u16 gpio_base = pci_read_config16
118  (pcidev_on_root(0x1f, 0), GPIO_BASE) &
119  0xfffc;
120  u16 gpio_inv_addr = gpio_base + GPI_INV;
121  gpio_inv = inl(gpio_inv_addr);
122  outl(gpio_inv | (1 << 11), gpio_inv_addr);
123  }
124 }
125 
126 static int link_onboard_smbios_data(struct device *dev, int *handle,
127  unsigned long *current)
128 {
129  int len = 0;
130 
131  len += smbios_write_type41(
132  current, handle,
133  BOARD_LIGHTSENSOR_NAME, /* name */
134  BOARD_LIGHTSENSOR_IRQ, /* instance */
135  0, /* segment */
136  BOARD_LIGHTSENSOR_I2C_ADDR, /* bus */
137  0, /* device */
138  0, /* function */
139  SMBIOS_DEVICE_TYPE_OTHER); /* device type */
140 
141  len += smbios_write_type41(
142  current, handle,
143  BOARD_TRACKPAD_NAME, /* name */
144  BOARD_TRACKPAD_IRQ, /* instance */
145  0, /* segment */
146  BOARD_TRACKPAD_I2C_ADDR, /* bus */
147  0, /* device */
148  0, /* function */
149  SMBIOS_DEVICE_TYPE_OTHER); /* device type */
150 
151  len += smbios_write_type41(
152  current, handle,
153  BOARD_TOUCHSCREEN_NAME, /* name */
154  BOARD_TOUCHSCREEN_IRQ, /* instance */
155  0, /* segment */
156  BOARD_TOUCHSCREEN_I2C_ADDR, /* bus */
157  0, /* device */
158  0, /* function */
159  SMBIOS_DEVICE_TYPE_OTHER); /* device type */
160 
161  return len;
162 }
163 
164 // mainboard_enable is executed as first thing after
165 // enumerate_buses().
166 
167 static void mainboard_enable(struct device *dev)
168 {
169  dev->ops->init = mainboard_init;
170  dev->ops->get_smbios_data = link_onboard_smbios_data;
171 #if CONFIG(VGA_ROM_RUN)
172  /* Install custom int15 handler for VGA OPROM */
174 #endif
175 }
176 
179 };
struct chip_operations mainboard_ops
Definition: mainboard.c:19
static void mainboard_interrupt_handlers(int intXX, int(*intXX_func)(void))
Definition: interrupt.h:14
int smbios_write_type41(unsigned long *current, int *handle, const char *name, u8 instance, u16 segment, u8 bus, u8 device, u8 function, u8 device_type)
Definition: smbios.c:1087
#define printk(level,...)
Definition: stdlib.h:16
u32 inl(u16 port)
void outl(u32 val, u16 port)
DEVTREE_CONST struct device * pcidev_on_root(uint8_t dev, uint8_t fn)
Definition: device_const.c:260
int google_chromeec_get_board_version(uint32_t *version)
google_chromeec_get_board_version() - Get the board version
Definition: ec.c:915
#define BOARD_TRACKPAD_NAME
Definition: onboard.h:6
#define BOARD_TRACKPAD_I2C_ADDR
Definition: onboard.h:10
#define BOARD_TRACKPAD_IRQ
Definition: onboard.h:7
#define BOARD_TOUCHSCREEN_IRQ
Definition: onboard.h:14
#define BOARD_TOUCHSCREEN_I2C_ADDR
Definition: onboard.h:17
#define BOARD_TOUCHSCREEN_NAME
Definition: onboard.h:13
static __always_inline u16 pci_read_config16(const struct device *dev, u16 reg)
Definition: pci_ops.h:52
@ SMBIOS_DEVICE_TYPE_OTHER
Definition: smbios.h:940
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define X86_CX
Definition: regs.h:343
#define X86_CH
Definition: regs.h:364
#define X86_AX
Definition: regs.h:341
#define X86_CL
Definition: regs.h:359
static int int15_handler(void)
Definition: int15.c:8
#define GPIO_BASE
Definition: lpc.h:21
#define GPI_INV
Definition: gpio.h:13
unsigned int uint32_t
Definition: stdint.h:14
uint32_t u32
Definition: stdint.h:51
uint16_t u16
Definition: stdint.h:48
void(* enable_dev)(struct device *dev)
Definition: device.h:24
void(* init)(struct device *dev)
Definition: device.h:42
Definition: device.h:107
struct device_operations * ops
Definition: device.h:143