blob: c4b621ac7a90a7aae3d54406ea62b437ce054c9d [file] [log] [blame]
Angel Ponsfeedf232020-04-05 13:22:01 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer49428d82013-02-21 15:48:37 -08002
3#include <types.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -08004#include <device/device.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -08005#include <device/pci_ops.h>
6#include <console/console.h>
Julius Wernercd49cce2019-03-05 16:53:33 -08007#if CONFIG(VGA_ROM_RUN)
Stefan Reinauer49428d82013-02-21 15:48:37 -08008#include <x86emu/x86emu.h>
9#endif
Furquan Shaikh76cedd22020-05-02 10:24:23 -070010#include <acpi/acpi.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080011#include <arch/io.h>
12#include <arch/interrupt.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080013#include "onboard.h"
14#include "ec.h"
15#include <southbridge/intel/bd82x6x/pch.h>
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010016#include <southbridge/intel/common/gpio.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080017#include <smbios.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080018#include <ec/google/chromeec/ec.h>
Aaron Durbinb0f81512016-07-25 21:31:41 -050019#include <vendorcode/google/chromeos/chromeos.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080020
Julius Wernercd49cce2019-03-05 16:53:33 -080021#if CONFIG(VGA_ROM_RUN)
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070022static int int15_handler(void)
Stefan Reinauer49428d82013-02-21 15:48:37 -080023{
Duncan Laurie1c054002013-05-10 13:50:09 -070024 int res = 0;
Stefan Reinauer49428d82013-02-21 15:48:37 -080025
26 printk(BIOS_DEBUG, "%s: INT15 function %04x!\n",
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070027 __func__, X86_AX);
Stefan Reinauer49428d82013-02-21 15:48:37 -080028
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +010029 switch (X86_AX) {
Stefan Reinauer49428d82013-02-21 15:48:37 -080030 case 0x5f34:
31 /*
32 * Set Panel Fitting Hook:
33 * bit 2 = Graphics Stretching
34 * bit 1 = Text Stretching
35 * bit 0 = Centering (do not set with bit1 or bit2)
Elyes HAOUAS6dc9d032020-02-16 16:22:52 +010036 * 0 = video BIOS default
Stefan Reinauer49428d82013-02-21 15:48:37 -080037 */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070038 X86_AX = 0x005f;
Elyes HAOUAS6dc9d032020-02-16 16:22:52 +010039 X86_CL = 0x00; /* Use video BIOS default */
Duncan Laurie1c054002013-05-10 13:50:09 -070040 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080041 break;
42 case 0x5f35:
43 /*
44 * Boot Display Device Hook:
45 * bit 0 = CRT
46 * bit 1 = TV (eDP)
47 * bit 2 = EFP
48 * bit 3 = LFP
49 * bit 4 = CRT2
50 * bit 5 = TV2 (eDP)
51 * bit 6 = EFP2
52 * bit 7 = LFP2
53 */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070054 X86_AX = 0x005f;
Elyes HAOUAS6dc9d032020-02-16 16:22:52 +010055 X86_CX = 0x0000; /* Use video BIOS default */
Duncan Laurie1c054002013-05-10 13:50:09 -070056 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080057 break;
58 case 0x5f51:
59 /*
60 * Hook to select active LFP configuration:
61 * 00h = No LVDS, VBIOS does not enable LVDS
62 * 01h = Int-LVDS, LFP driven by integrated LVDS decoder
63 * 02h = SVDO-LVDS, LFP driven by SVDO decoder
64 * 03h = eDP, LFP Driven by Int-DisplayPort encoder
65 */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070066 X86_AX = 0x005f;
67 X86_CX = 0x0003; /* eDP */
Duncan Laurie1c054002013-05-10 13:50:09 -070068 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080069 break;
70 case 0x5f70:
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070071 switch (X86_CH) {
Stefan Reinauer49428d82013-02-21 15:48:37 -080072 case 0:
73 /* Get Mux */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070074 X86_AX = 0x005f;
75 X86_CX = 0x0000;
Duncan Laurie1c054002013-05-10 13:50:09 -070076 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080077 break;
78 case 1:
79 /* Set Mux */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070080 X86_AX = 0x005f;
81 X86_CX = 0x0000;
Duncan Laurie1c054002013-05-10 13:50:09 -070082 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080083 break;
84 case 2:
85 /* Get SG/Non-SG mode */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070086 X86_AX = 0x005f;
87 X86_CX = 0x0000;
Duncan Laurie1c054002013-05-10 13:50:09 -070088 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080089 break;
90 default:
91 /* Interrupt was not handled */
92 printk(BIOS_DEBUG, "Unknown INT15 5f70 function: 0x%02x\n",
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070093 X86_CH);
Duncan Laurie1c054002013-05-10 13:50:09 -070094 break;
Stefan Reinauer49428d82013-02-21 15:48:37 -080095 }
96 break;
97 case 0x5fac:
Duncan Laurie1c054002013-05-10 13:50:09 -070098 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080099 break;
100 default:
Stefan Reinauerfe8290d2013-04-23 15:00:02 -0700101 printk(BIOS_DEBUG, "Unknown INT15 function %04x!\n", X86_AX);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800102 break;
103 }
104 return res;
105}
106#endif
107
Elyes HAOUASd129d432018-05-04 20:23:33 +0200108static void mainboard_init(struct device *dev)
Stefan Reinauer49428d82013-02-21 15:48:37 -0800109{
Karthikeyan Ramasubramanianc80ff842018-09-17 16:19:34 -0600110 uint32_t board_version = 0;
111
Stefan Reinauer49428d82013-02-21 15:48:37 -0800112 /* Initialize the Embedded Controller */
113 link_ec_init();
114
Karthikeyan Ramasubramanianc80ff842018-09-17 16:19:34 -0600115 google_chromeec_get_board_version(&board_version);
116 if (board_version == 0) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800117 /* If running on proto1 - enable reversion of gpio11. */
118 u32 gpio_inv;
119 u16 gpio_base = pci_read_config16
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300120 (pcidev_on_root(0x1f, 0), GPIO_BASE) &
Stefan Reinauer49428d82013-02-21 15:48:37 -0800121 0xfffc;
122 u16 gpio_inv_addr = gpio_base + GPI_INV;
123 gpio_inv = inl(gpio_inv_addr);
124 outl(gpio_inv | (1 << 11), gpio_inv_addr);
125 }
126}
127
Elyes HAOUASd129d432018-05-04 20:23:33 +0200128static int link_onboard_smbios_data(struct device *dev, int *handle,
Stefan Reinauer49428d82013-02-21 15:48:37 -0800129 unsigned long *current)
130{
131 int len = 0;
132
Duncan Laurie21a78702013-05-23 14:17:05 -0700133 len += smbios_write_type41(
134 current, handle,
Kyösti Mälkkib9cd5ec2015-04-24 16:05:58 +0300135 BOARD_LIGHTSENSOR_NAME, /* name */
136 BOARD_LIGHTSENSOR_IRQ, /* instance */
Duncan Laurie21a78702013-05-23 14:17:05 -0700137 0, /* segment */
Kyösti Mälkkib9cd5ec2015-04-24 16:05:58 +0300138 BOARD_LIGHTSENSOR_I2C_ADDR, /* bus */
Duncan Laurie21a78702013-05-23 14:17:05 -0700139 0, /* device */
Christian Waltere6afab12019-05-21 17:22:49 +0200140 0, /* function */
141 SMBIOS_DEVICE_TYPE_OTHER); /* device type */
Stefan Reinauer49428d82013-02-21 15:48:37 -0800142
Duncan Laurie21a78702013-05-23 14:17:05 -0700143 len += smbios_write_type41(
144 current, handle,
Kyösti Mälkkib9cd5ec2015-04-24 16:05:58 +0300145 BOARD_TRACKPAD_NAME, /* name */
146 BOARD_TRACKPAD_IRQ, /* instance */
Duncan Laurie21a78702013-05-23 14:17:05 -0700147 0, /* segment */
Kyösti Mälkkib9cd5ec2015-04-24 16:05:58 +0300148 BOARD_TRACKPAD_I2C_ADDR, /* bus */
Duncan Laurie21a78702013-05-23 14:17:05 -0700149 0, /* device */
Christian Waltere6afab12019-05-21 17:22:49 +0200150 0, /* function */
151 SMBIOS_DEVICE_TYPE_OTHER); /* device type */
Stefan Reinauer49428d82013-02-21 15:48:37 -0800152
Duncan Laurie21a78702013-05-23 14:17:05 -0700153 len += smbios_write_type41(
154 current, handle,
Kyösti Mälkkib9cd5ec2015-04-24 16:05:58 +0300155 BOARD_TOUCHSCREEN_NAME, /* name */
156 BOARD_TOUCHSCREEN_IRQ, /* instance */
Duncan Laurie21a78702013-05-23 14:17:05 -0700157 0, /* segment */
Kyösti Mälkkib9cd5ec2015-04-24 16:05:58 +0300158 BOARD_TOUCHSCREEN_I2C_ADDR, /* bus */
Duncan Laurie21a78702013-05-23 14:17:05 -0700159 0, /* device */
Christian Waltere6afab12019-05-21 17:22:49 +0200160 0, /* function */
161 SMBIOS_DEVICE_TYPE_OTHER); /* device type */
Stefan Reinauer49428d82013-02-21 15:48:37 -0800162
163 return len;
164}
165
166// mainboard_enable is executed as first thing after
167// enumerate_buses().
168
Elyes HAOUASd129d432018-05-04 20:23:33 +0200169static void mainboard_enable(struct device *dev)
Stefan Reinauer49428d82013-02-21 15:48:37 -0800170{
171 dev->ops->init = mainboard_init;
172 dev->ops->get_smbios_data = link_onboard_smbios_data;
Nico Huber68680dd2020-03-31 17:34:52 +0200173 dev->ops->acpi_inject_dsdt = chromeos_dsdt_generator;
Julius Wernercd49cce2019-03-05 16:53:33 -0800174#if CONFIG(VGA_ROM_RUN)
Stefan Reinauer49428d82013-02-21 15:48:37 -0800175 /* Install custom int15 handler for VGA OPROM */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -0700176 mainboard_interrupt_handlers(0x15, &int15_handler);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800177#endif
Stefan Reinauer49428d82013-02-21 15:48:37 -0800178}
179
180struct chip_operations mainboard_ops = {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800181 .enable_dev = mainboard_enable,
182};