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) 2011 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <string.h> |
Kyösti Mälkki | ab72809 | 2014-05-03 16:47:52 +0300 | [diff] [blame] | 17 | #include <bootmode.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 18 | #include <arch/io.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 21 | #include <southbridge/intel/bd82x6x/pch.h> |
| 22 | #include "ec.h" |
| 23 | #include <ec/google/chromeec/ec.h> |
| 24 | |
| 25 | #ifndef __PRE_RAM__ |
| 26 | #include <boot/coreboot_tables.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 27 | |
| 28 | #define GPIO_COUNT 6 |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 29 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 30 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 31 | { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 32 | gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio)); |
| 33 | gpios->count = GPIO_COUNT; |
| 34 | |
| 35 | /* Write Protect: GPIO57 = PCH_SPI_WP_D */ |
| 36 | gpios->gpios[0].port = 57; |
| 37 | gpios->gpios[0].polarity = ACTIVE_HIGH; |
Patrick Georgi | 2f31ef1 | 2015-06-30 12:49:50 +0200 | [diff] [blame] | 38 | gpios->gpios[0].value = get_write_protect_state(); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 39 | strncpy((char *)gpios->gpios[0].name,"write protect", |
| 40 | GPIO_MAX_NAME_LENGTH); |
| 41 | /* Recovery: the "switch" comes from the EC */ |
| 42 | gpios->gpios[1].port = -1; /* Indicate that this is a pseudo GPIO */ |
| 43 | gpios->gpios[1].polarity = ACTIVE_HIGH; |
| 44 | gpios->gpios[1].value = get_recovery_mode_switch(); |
| 45 | strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH); |
| 46 | |
| 47 | /* Lid: the "switch" comes from the EC */ |
| 48 | gpios->gpios[2].port = -1; |
| 49 | gpios->gpios[2].polarity = ACTIVE_HIGH; |
| 50 | gpios->gpios[2].value = get_lid_switch(); |
| 51 | strncpy((char *)gpios->gpios[2].name,"lid", GPIO_MAX_NAME_LENGTH); |
| 52 | |
| 53 | /* Power Button: hard-coded as not pressed; we'll detect later presses |
| 54 | * via SMI. */ |
| 55 | gpios->gpios[3].port = -1; |
| 56 | gpios->gpios[3].polarity = ACTIVE_HIGH; |
| 57 | gpios->gpios[3].value = 0; |
| 58 | strncpy((char *)gpios->gpios[3].name,"power", GPIO_MAX_NAME_LENGTH); |
| 59 | |
| 60 | /* Developer: a tricky case on Link, there is no switch */ |
| 61 | gpios->gpios[4].port = -1; /* Indicate that this is a pseudo GPIO */ |
| 62 | gpios->gpios[4].polarity = ACTIVE_HIGH; |
| 63 | gpios->gpios[4].value = get_developer_mode_switch(); |
| 64 | strncpy((char *)gpios->gpios[4].name,"developer", GPIO_MAX_NAME_LENGTH); |
| 65 | |
| 66 | /* Did we load the VGA Option ROM? */ |
| 67 | gpios->gpios[5].port = -1; /* Indicate that this is a pseudo GPIO */ |
| 68 | gpios->gpios[5].polarity = ACTIVE_HIGH; |
Kyösti Mälkki | ab56b3b | 2013-11-28 16:44:51 +0200 | [diff] [blame] | 69 | gpios->gpios[5].value = gfx_get_init_done(); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 70 | strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH); |
| 71 | } |
| 72 | #endif |
| 73 | |
Patrick Georgi | 2f31ef1 | 2015-06-30 12:49:50 +0200 | [diff] [blame] | 74 | int get_write_protect_state(void) |
| 75 | { |
| 76 | device_t dev; |
| 77 | #ifdef __PRE_RAM__ |
| 78 | dev = PCI_DEV(0, 0x1f, 0); |
| 79 | #else |
| 80 | dev = dev_find_slot(0, PCI_DEVFN(0x1f, 0)); |
| 81 | #endif |
| 82 | u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe; |
| 83 | //u16 gen_pmcon_1 = pci_read_config32(dev, GEN_PMCON_1); |
| 84 | |
| 85 | if (!gpio_base) |
| 86 | return -1; |
| 87 | |
| 88 | u32 gp_lvl2 = inl(gpio_base + 0x38); |
| 89 | |
| 90 | return (gp_lvl2 >> (57 - 32)) & 1; |
| 91 | } |
| 92 | |
Patrick Georgi | 08b8785 | 2015-05-28 11:59:33 +0200 | [diff] [blame] | 93 | int get_lid_switch(void) |
| 94 | { |
| 95 | u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES); |
| 96 | |
| 97 | return !!(ec_switches & EC_SWITCH_LID_OPEN); |
| 98 | } |
| 99 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 100 | /* The dev-switch is virtual on Link (and so handled elsewhere). */ |
| 101 | int get_developer_mode_switch(void) |
| 102 | { |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | /* There are actually two recovery switches. One is the magic keyboard chord, |
| 107 | * the other is driven by Servo. */ |
| 108 | int get_recovery_mode_switch(void) |
| 109 | { |
| 110 | u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES); |
| 111 | u32 ec_events; |
| 112 | |
| 113 | /* If a switch is set, we don't need to look at events. */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 114 | if (ec_switches & (EC_SWITCH_DEDICATED_RECOVERY)) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 115 | return 1; |
| 116 | |
| 117 | /* Else check if the EC has posted the keyboard recovery event. */ |
| 118 | ec_events = google_chromeec_get_events_b(); |
| 119 | |
| 120 | return !!(ec_events & |
| 121 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
| 122 | } |