Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
| 5 | * Copyright (C) 2011 Google Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <types.h> |
| 18 | #include <string.h> |
| 19 | #include <device/device.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 20 | #include <device/pci_def.h> |
| 21 | #include <device/pci_ops.h> |
| 22 | #include <console/console.h> |
Martin Roth | 356b519 | 2017-06-24 21:53:37 -0600 | [diff] [blame] | 23 | #if IS_ENABLED(CONFIG_VGA_ROM_RUN) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 24 | #include <x86emu/x86emu.h> |
| 25 | #endif |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 26 | #include <arch/acpi.h> |
| 27 | #include <arch/io.h> |
| 28 | #include <arch/interrupt.h> |
Stefan Reinauer | 3e4e303 | 2013-03-20 14:08:04 -0700 | [diff] [blame] | 29 | #include <boot/coreboot_tables.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 30 | #include "onboard.h" |
| 31 | #include "ec.h" |
| 32 | #include <southbridge/intel/bd82x6x/pch.h> |
Patrick Rudolph | e8e66f4 | 2016-02-06 17:42:42 +0100 | [diff] [blame] | 33 | #include <southbridge/intel/common/gpio.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 34 | #include <smbios.h> |
| 35 | #include <device/pci.h> |
| 36 | #include <ec/google/chromeec/ec.h> |
Aaron Durbin | b0f8151 | 2016-07-25 21:31:41 -0500 | [diff] [blame] | 37 | #include <vendorcode/google/chromeos/chromeos.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 38 | |
| 39 | /* placeholder for evenual link post. Not sure what we'll |
| 40 | * do but it will look nice |
| 41 | */ |
| 42 | void mainboard_post(u8 value) |
| 43 | { |
| 44 | /* |
| 45 | * What you DO NOT want to do: push every post to the EC backlight. |
| 46 | * it seems cute but in practice it looks like a hardware failure. |
| 47 | * I'm leaving this here so we don't make this mistake again later. |
| 48 | * And it seems to break the SMP startup. |
| 49 | * google_chromeec_post(value); |
| 50 | */ |
| 51 | } |
| 52 | |
Martin Roth | 356b519 | 2017-06-24 21:53:37 -0600 | [diff] [blame] | 53 | #if IS_ENABLED(CONFIG_VGA_ROM_RUN) |
Stefan Reinauer | fe8290d | 2013-04-23 15:00:02 -0700 | [diff] [blame] | 54 | static int int15_handler(void) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 55 | { |
Duncan Laurie | 1c05400 | 2013-05-10 13:50:09 -0700 | [diff] [blame] | 56 | int res = 0; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 57 | |
| 58 | printk(BIOS_DEBUG, "%s: INT15 function %04x!\n", |
Stefan Reinauer | fe8290d | 2013-04-23 15:00:02 -0700 | [diff] [blame] | 59 | __func__, X86_AX); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 60 | |
Elyes HAOUAS | 0ce41f1 | 2018-11-13 10:03:31 +0100 | [diff] [blame] | 61 | switch (X86_AX) { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 62 | case 0x5f34: |
| 63 | /* |
| 64 | * Set Panel Fitting Hook: |
| 65 | * bit 2 = Graphics Stretching |
| 66 | * bit 1 = Text Stretching |
| 67 | * bit 0 = Centering (do not set with bit1 or bit2) |
| 68 | * 0 = video bios default |
| 69 | */ |
Stefan Reinauer | fe8290d | 2013-04-23 15:00:02 -0700 | [diff] [blame] | 70 | X86_AX = 0x005f; |
| 71 | X86_CL = 0x00; /* Use video bios default */ |
Duncan Laurie | 1c05400 | 2013-05-10 13:50:09 -0700 | [diff] [blame] | 72 | res = 1; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 73 | break; |
| 74 | case 0x5f35: |
| 75 | /* |
| 76 | * Boot Display Device Hook: |
| 77 | * bit 0 = CRT |
| 78 | * bit 1 = TV (eDP) |
| 79 | * bit 2 = EFP |
| 80 | * bit 3 = LFP |
| 81 | * bit 4 = CRT2 |
| 82 | * bit 5 = TV2 (eDP) |
| 83 | * bit 6 = EFP2 |
| 84 | * bit 7 = LFP2 |
| 85 | */ |
Stefan Reinauer | fe8290d | 2013-04-23 15:00:02 -0700 | [diff] [blame] | 86 | X86_AX = 0x005f; |
| 87 | X86_CX = 0x0000; /* Use video bios default */ |
Duncan Laurie | 1c05400 | 2013-05-10 13:50:09 -0700 | [diff] [blame] | 88 | res = 1; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 89 | break; |
| 90 | case 0x5f51: |
| 91 | /* |
| 92 | * Hook to select active LFP configuration: |
| 93 | * 00h = No LVDS, VBIOS does not enable LVDS |
| 94 | * 01h = Int-LVDS, LFP driven by integrated LVDS decoder |
| 95 | * 02h = SVDO-LVDS, LFP driven by SVDO decoder |
| 96 | * 03h = eDP, LFP Driven by Int-DisplayPort encoder |
| 97 | */ |
Stefan Reinauer | fe8290d | 2013-04-23 15:00:02 -0700 | [diff] [blame] | 98 | X86_AX = 0x005f; |
| 99 | X86_CX = 0x0003; /* eDP */ |
Duncan Laurie | 1c05400 | 2013-05-10 13:50:09 -0700 | [diff] [blame] | 100 | res = 1; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 101 | break; |
| 102 | case 0x5f70: |
Stefan Reinauer | fe8290d | 2013-04-23 15:00:02 -0700 | [diff] [blame] | 103 | switch (X86_CH) { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 104 | case 0: |
| 105 | /* Get Mux */ |
Stefan Reinauer | fe8290d | 2013-04-23 15:00:02 -0700 | [diff] [blame] | 106 | X86_AX = 0x005f; |
| 107 | X86_CX = 0x0000; |
Duncan Laurie | 1c05400 | 2013-05-10 13:50:09 -0700 | [diff] [blame] | 108 | res = 1; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 109 | break; |
| 110 | case 1: |
| 111 | /* Set Mux */ |
Stefan Reinauer | fe8290d | 2013-04-23 15:00:02 -0700 | [diff] [blame] | 112 | X86_AX = 0x005f; |
| 113 | X86_CX = 0x0000; |
Duncan Laurie | 1c05400 | 2013-05-10 13:50:09 -0700 | [diff] [blame] | 114 | res = 1; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 115 | break; |
| 116 | case 2: |
| 117 | /* Get SG/Non-SG mode */ |
Stefan Reinauer | fe8290d | 2013-04-23 15:00:02 -0700 | [diff] [blame] | 118 | X86_AX = 0x005f; |
| 119 | X86_CX = 0x0000; |
Duncan Laurie | 1c05400 | 2013-05-10 13:50:09 -0700 | [diff] [blame] | 120 | res = 1; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 121 | break; |
| 122 | default: |
| 123 | /* Interrupt was not handled */ |
| 124 | printk(BIOS_DEBUG, "Unknown INT15 5f70 function: 0x%02x\n", |
Stefan Reinauer | fe8290d | 2013-04-23 15:00:02 -0700 | [diff] [blame] | 125 | X86_CH); |
Duncan Laurie | 1c05400 | 2013-05-10 13:50:09 -0700 | [diff] [blame] | 126 | break; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 127 | } |
| 128 | break; |
| 129 | case 0x5fac: |
Duncan Laurie | 1c05400 | 2013-05-10 13:50:09 -0700 | [diff] [blame] | 130 | res = 1; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 131 | break; |
| 132 | default: |
Stefan Reinauer | fe8290d | 2013-04-23 15:00:02 -0700 | [diff] [blame] | 133 | printk(BIOS_DEBUG, "Unknown INT15 function %04x!\n", X86_AX); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 134 | break; |
| 135 | } |
| 136 | return res; |
| 137 | } |
| 138 | #endif |
| 139 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 140 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 141 | |
Elyes HAOUAS | d129d43 | 2018-05-04 20:23:33 +0200 | [diff] [blame] | 142 | static void mainboard_init(struct device *dev) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 143 | { |
Karthikeyan Ramasubramanian | c80ff84 | 2018-09-17 16:19:34 -0600 | [diff] [blame] | 144 | uint32_t board_version = 0; |
| 145 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 146 | /* Initialize the Embedded Controller */ |
| 147 | link_ec_init(); |
| 148 | |
Karthikeyan Ramasubramanian | c80ff84 | 2018-09-17 16:19:34 -0600 | [diff] [blame] | 149 | google_chromeec_get_board_version(&board_version); |
| 150 | if (board_version == 0) { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 151 | /* If running on proto1 - enable reversion of gpio11. */ |
| 152 | u32 gpio_inv; |
| 153 | u16 gpio_base = pci_read_config16 |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 154 | (pcidev_on_root(0x1f, 0), GPIO_BASE) & |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 155 | 0xfffc; |
| 156 | u16 gpio_inv_addr = gpio_base + GPI_INV; |
| 157 | gpio_inv = inl(gpio_inv_addr); |
| 158 | outl(gpio_inv | (1 << 11), gpio_inv_addr); |
| 159 | } |
| 160 | } |
| 161 | |
Elyes HAOUAS | d129d43 | 2018-05-04 20:23:33 +0200 | [diff] [blame] | 162 | static int link_onboard_smbios_data(struct device *dev, int *handle, |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 163 | unsigned long *current) |
| 164 | { |
| 165 | int len = 0; |
| 166 | |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 167 | len += smbios_write_type41( |
| 168 | current, handle, |
Kyösti Mälkki | b9cd5ec | 2015-04-24 16:05:58 +0300 | [diff] [blame] | 169 | BOARD_LIGHTSENSOR_NAME, /* name */ |
| 170 | BOARD_LIGHTSENSOR_IRQ, /* instance */ |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 171 | 0, /* segment */ |
Kyösti Mälkki | b9cd5ec | 2015-04-24 16:05:58 +0300 | [diff] [blame] | 172 | BOARD_LIGHTSENSOR_I2C_ADDR, /* bus */ |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 173 | 0, /* device */ |
| 174 | 0); /* function */ |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 175 | |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 176 | len += smbios_write_type41( |
| 177 | current, handle, |
Kyösti Mälkki | b9cd5ec | 2015-04-24 16:05:58 +0300 | [diff] [blame] | 178 | BOARD_TRACKPAD_NAME, /* name */ |
| 179 | BOARD_TRACKPAD_IRQ, /* instance */ |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 180 | 0, /* segment */ |
Kyösti Mälkki | b9cd5ec | 2015-04-24 16:05:58 +0300 | [diff] [blame] | 181 | BOARD_TRACKPAD_I2C_ADDR, /* bus */ |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 182 | 0, /* device */ |
| 183 | 0); /* function */ |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 184 | |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 185 | len += smbios_write_type41( |
| 186 | current, handle, |
Kyösti Mälkki | b9cd5ec | 2015-04-24 16:05:58 +0300 | [diff] [blame] | 187 | BOARD_TOUCHSCREEN_NAME, /* name */ |
| 188 | BOARD_TOUCHSCREEN_IRQ, /* instance */ |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 189 | 0, /* segment */ |
Kyösti Mälkki | b9cd5ec | 2015-04-24 16:05:58 +0300 | [diff] [blame] | 190 | BOARD_TOUCHSCREEN_I2C_ADDR, /* bus */ |
Duncan Laurie | 21a7870 | 2013-05-23 14:17:05 -0700 | [diff] [blame] | 191 | 0, /* device */ |
| 192 | 0); /* function */ |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 193 | |
| 194 | return len; |
| 195 | } |
| 196 | |
| 197 | // mainboard_enable is executed as first thing after |
| 198 | // enumerate_buses(). |
| 199 | |
Elyes HAOUAS | d129d43 | 2018-05-04 20:23:33 +0200 | [diff] [blame] | 200 | static void mainboard_enable(struct device *dev) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 201 | { |
| 202 | dev->ops->init = mainboard_init; |
| 203 | dev->ops->get_smbios_data = link_onboard_smbios_data; |
Aaron Durbin | b0f8151 | 2016-07-25 21:31:41 -0500 | [diff] [blame] | 204 | dev->ops->acpi_inject_dsdt_generator = chromeos_dsdt_generator; |
Martin Roth | 356b519 | 2017-06-24 21:53:37 -0600 | [diff] [blame] | 205 | #if IS_ENABLED(CONFIG_VGA_ROM_RUN) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 206 | /* Install custom int15 handler for VGA OPROM */ |
Stefan Reinauer | fe8290d | 2013-04-23 15:00:02 -0700 | [diff] [blame] | 207 | mainboard_interrupt_handlers(0x15, &int15_handler); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 208 | #endif |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | struct chip_operations mainboard_ops = { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 212 | .enable_dev = mainboard_enable, |
| 213 | }; |