blob: c31ab110a29ab6eebb62779c223897ad12e24c09 [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>
Kyösti Mälkki383c4e72023-01-05 18:05:11 +02006#include <ec/ec.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -08007#include <console/console.h>
Julius Wernercd49cce2019-03-05 16:53:33 -08008#if CONFIG(VGA_ROM_RUN)
Stefan Reinauer49428d82013-02-21 15:48:37 -08009#include <x86emu/x86emu.h>
10#endif
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>
19
Julius Wernercd49cce2019-03-05 16:53:33 -080020#if CONFIG(VGA_ROM_RUN)
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070021static int int15_handler(void)
Stefan Reinauer49428d82013-02-21 15:48:37 -080022{
Duncan Laurie1c054002013-05-10 13:50:09 -070023 int res = 0;
Stefan Reinauer49428d82013-02-21 15:48:37 -080024
25 printk(BIOS_DEBUG, "%s: INT15 function %04x!\n",
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070026 __func__, X86_AX);
Stefan Reinauer49428d82013-02-21 15:48:37 -080027
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +010028 switch (X86_AX) {
Stefan Reinauer49428d82013-02-21 15:48:37 -080029 case 0x5f34:
30 /*
31 * Set Panel Fitting Hook:
32 * bit 2 = Graphics Stretching
33 * bit 1 = Text Stretching
34 * bit 0 = Centering (do not set with bit1 or bit2)
Elyes HAOUAS6dc9d032020-02-16 16:22:52 +010035 * 0 = video BIOS default
Stefan Reinauer49428d82013-02-21 15:48:37 -080036 */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070037 X86_AX = 0x005f;
Elyes HAOUAS6dc9d032020-02-16 16:22:52 +010038 X86_CL = 0x00; /* Use video BIOS default */
Duncan Laurie1c054002013-05-10 13:50:09 -070039 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080040 break;
41 case 0x5f35:
42 /*
43 * Boot Display Device Hook:
44 * bit 0 = CRT
45 * bit 1 = TV (eDP)
46 * bit 2 = EFP
47 * bit 3 = LFP
48 * bit 4 = CRT2
49 * bit 5 = TV2 (eDP)
50 * bit 6 = EFP2
51 * bit 7 = LFP2
52 */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070053 X86_AX = 0x005f;
Elyes HAOUAS6dc9d032020-02-16 16:22:52 +010054 X86_CX = 0x0000; /* Use video BIOS default */
Duncan Laurie1c054002013-05-10 13:50:09 -070055 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080056 break;
57 case 0x5f51:
58 /*
59 * Hook to select active LFP configuration:
60 * 00h = No LVDS, VBIOS does not enable LVDS
61 * 01h = Int-LVDS, LFP driven by integrated LVDS decoder
62 * 02h = SVDO-LVDS, LFP driven by SVDO decoder
63 * 03h = eDP, LFP Driven by Int-DisplayPort encoder
64 */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070065 X86_AX = 0x005f;
66 X86_CX = 0x0003; /* eDP */
Duncan Laurie1c054002013-05-10 13:50:09 -070067 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080068 break;
69 case 0x5f70:
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070070 switch (X86_CH) {
Stefan Reinauer49428d82013-02-21 15:48:37 -080071 case 0:
72 /* Get Mux */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070073 X86_AX = 0x005f;
74 X86_CX = 0x0000;
Duncan Laurie1c054002013-05-10 13:50:09 -070075 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080076 break;
77 case 1:
78 /* Set Mux */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070079 X86_AX = 0x005f;
80 X86_CX = 0x0000;
Duncan Laurie1c054002013-05-10 13:50:09 -070081 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080082 break;
83 case 2:
84 /* Get SG/Non-SG mode */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070085 X86_AX = 0x005f;
86 X86_CX = 0x0000;
Duncan Laurie1c054002013-05-10 13:50:09 -070087 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080088 break;
89 default:
90 /* Interrupt was not handled */
91 printk(BIOS_DEBUG, "Unknown INT15 5f70 function: 0x%02x\n",
Stefan Reinauerfe8290d2013-04-23 15:00:02 -070092 X86_CH);
Duncan Laurie1c054002013-05-10 13:50:09 -070093 break;
Stefan Reinauer49428d82013-02-21 15:48:37 -080094 }
95 break;
96 case 0x5fac:
Duncan Laurie1c054002013-05-10 13:50:09 -070097 res = 1;
Stefan Reinauer49428d82013-02-21 15:48:37 -080098 break;
99 default:
Stefan Reinauerfe8290d2013-04-23 15:00:02 -0700100 printk(BIOS_DEBUG, "Unknown INT15 function %04x!\n", X86_AX);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800101 break;
102 }
103 return res;
104}
105#endif
106
Elyes HAOUASd129d432018-05-04 20:23:33 +0200107static void mainboard_init(struct device *dev)
Stefan Reinauer49428d82013-02-21 15:48:37 -0800108{
Karthikeyan Ramasubramanianc80ff842018-09-17 16:19:34 -0600109 uint32_t board_version = 0;
110
Stefan Reinauer49428d82013-02-21 15:48:37 -0800111 /* Initialize the Embedded Controller */
Kyösti Mälkki383c4e72023-01-05 18:05:11 +0200112 mainboard_ec_init();
Stefan Reinauer49428d82013-02-21 15:48:37 -0800113
Karthikeyan Ramasubramanianc80ff842018-09-17 16:19:34 -0600114 google_chromeec_get_board_version(&board_version);
115 if (board_version == 0) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800116 /* If running on proto1 - enable reversion of gpio11. */
117 u32 gpio_inv;
118 u16 gpio_base = pci_read_config16
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300119 (pcidev_on_root(0x1f, 0), GPIO_BASE) &
Stefan Reinauer49428d82013-02-21 15:48:37 -0800120 0xfffc;
121 u16 gpio_inv_addr = gpio_base + GPI_INV;
122 gpio_inv = inl(gpio_inv_addr);
123 outl(gpio_inv | (1 << 11), gpio_inv_addr);
124 }
125}
126
Elyes HAOUASd129d432018-05-04 20:23:33 +0200127static int link_onboard_smbios_data(struct device *dev, int *handle,
Stefan Reinauer49428d82013-02-21 15:48:37 -0800128 unsigned long *current)
129{
130 int len = 0;
131
Duncan Laurie21a78702013-05-23 14:17:05 -0700132 len += smbios_write_type41(
133 current, handle,
Kyösti Mälkkib9cd5ec2015-04-24 16:05:58 +0300134 BOARD_LIGHTSENSOR_NAME, /* name */
135 BOARD_LIGHTSENSOR_IRQ, /* instance */
Duncan Laurie21a78702013-05-23 14:17:05 -0700136 0, /* segment */
Kyösti Mälkkib9cd5ec2015-04-24 16:05:58 +0300137 BOARD_LIGHTSENSOR_I2C_ADDR, /* bus */
Duncan Laurie21a78702013-05-23 14:17:05 -0700138 0, /* device */
Christian Waltere6afab12019-05-21 17:22:49 +0200139 0, /* function */
140 SMBIOS_DEVICE_TYPE_OTHER); /* device type */
Stefan Reinauer49428d82013-02-21 15:48:37 -0800141
Duncan Laurie21a78702013-05-23 14:17:05 -0700142 len += smbios_write_type41(
143 current, handle,
Kyösti Mälkkib9cd5ec2015-04-24 16:05:58 +0300144 BOARD_TRACKPAD_NAME, /* name */
145 BOARD_TRACKPAD_IRQ, /* instance */
Duncan Laurie21a78702013-05-23 14:17:05 -0700146 0, /* segment */
Kyösti Mälkkib9cd5ec2015-04-24 16:05:58 +0300147 BOARD_TRACKPAD_I2C_ADDR, /* bus */
Duncan Laurie21a78702013-05-23 14:17:05 -0700148 0, /* device */
Christian Waltere6afab12019-05-21 17:22:49 +0200149 0, /* function */
150 SMBIOS_DEVICE_TYPE_OTHER); /* device type */
Stefan Reinauer49428d82013-02-21 15:48:37 -0800151
Duncan Laurie21a78702013-05-23 14:17:05 -0700152 len += smbios_write_type41(
153 current, handle,
Kyösti Mälkkib9cd5ec2015-04-24 16:05:58 +0300154 BOARD_TOUCHSCREEN_NAME, /* name */
155 BOARD_TOUCHSCREEN_IRQ, /* instance */
Duncan Laurie21a78702013-05-23 14:17:05 -0700156 0, /* segment */
Kyösti Mälkkib9cd5ec2015-04-24 16:05:58 +0300157 BOARD_TOUCHSCREEN_I2C_ADDR, /* bus */
Duncan Laurie21a78702013-05-23 14:17:05 -0700158 0, /* device */
Christian Waltere6afab12019-05-21 17:22:49 +0200159 0, /* function */
160 SMBIOS_DEVICE_TYPE_OTHER); /* device type */
Stefan Reinauer49428d82013-02-21 15:48:37 -0800161
162 return len;
163}
164
Elyes HAOUASd129d432018-05-04 20:23:33 +0200165static void mainboard_enable(struct device *dev)
Stefan Reinauer49428d82013-02-21 15:48:37 -0800166{
167 dev->ops->init = mainboard_init;
168 dev->ops->get_smbios_data = link_onboard_smbios_data;
Julius Wernercd49cce2019-03-05 16:53:33 -0800169#if CONFIG(VGA_ROM_RUN)
Stefan Reinauer49428d82013-02-21 15:48:37 -0800170 /* Install custom int15 handler for VGA OPROM */
Stefan Reinauerfe8290d2013-04-23 15:00:02 -0700171 mainboard_interrupt_handlers(0x15, &int15_handler);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800172#endif
Stefan Reinauer49428d82013-02-21 15:48:37 -0800173}
174
175struct chip_operations mainboard_ops = {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800176 .enable_dev = mainboard_enable,
177};