Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 The Chromium OS Authors. All rights reserved. |
| 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 | 6651da3 | 2012-04-27 23:16:30 +0200 | [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 | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 18 | #include <arch/io.h> |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 21 | #include <southbridge/intel/bd82x6x/pch.h> |
Patrick Rudolph | e8e66f4 | 2016-02-06 17:42:42 +0100 | [diff] [blame] | 22 | #include <southbridge/intel/common/gpio.h> |
Aaron Durbin | b0f8151 | 2016-07-25 21:31:41 -0500 | [diff] [blame] | 23 | #include <vendorcode/google/chromeos/chromeos.h> |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 24 | |
| 25 | #ifndef __PRE_RAM__ |
Stefan Reinauer | 3e4e303 | 2013-03-20 14:08:04 -0700 | [diff] [blame] | 26 | #include <boot/coreboot_tables.h> |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 27 | |
Duncan Laurie | c64947b | 2012-10-01 13:31:25 -0700 | [diff] [blame] | 28 | #define GPIO_COUNT 6 |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 29 | |
| 30 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 31 | { |
| 32 | device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0)); |
| 33 | u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 34 | |
| 35 | if (!gpio_base) |
| 36 | return; |
| 37 | |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 38 | u32 gp_lvl = inl(gpio_base + 0x0c); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 39 | u32 gp_lvl2 = inl(gpio_base + 0x38); |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 40 | /* u32 gp_lvl3 = inl(gpio_base + 0x48); */ |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 41 | |
| 42 | gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio)); |
| 43 | gpios->count = GPIO_COUNT; |
| 44 | |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 45 | /* Write Protect: GPIO48 */ |
| 46 | gpios->gpios[0].port = 48; |
| 47 | gpios->gpios[0].polarity = ACTIVE_LOW; |
| 48 | gpios->gpios[0].value = (gp_lvl2 >> (48-32)) & 1; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 49 | strncpy((char *)gpios->gpios[0].name,"write protect", |
| 50 | GPIO_MAX_NAME_LENGTH); |
| 51 | |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 52 | /* Recovery: GPIO22 */ |
| 53 | gpios->gpios[1].port = 22; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 54 | gpios->gpios[1].polarity = ACTIVE_LOW; |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 55 | gpios->gpios[1].value = (gp_lvl >> 22) & 1; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 56 | strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH); |
| 57 | |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 58 | /* Developer: GPIO57 */ |
| 59 | gpios->gpios[2].port = 57; |
Duncan Laurie | c64947b | 2012-10-01 13:31:25 -0700 | [diff] [blame] | 60 | gpios->gpios[2].polarity = ACTIVE_LOW; |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 61 | gpios->gpios[2].value = (gp_lvl2 >> (57-32)) & 1; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 62 | strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH); |
| 63 | |
| 64 | /* Hard code the lid switch GPIO to open. */ |
Duncan Laurie | c64947b | 2012-10-01 13:31:25 -0700 | [diff] [blame] | 65 | gpios->gpios[3].port = -1; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 66 | gpios->gpios[3].polarity = ACTIVE_HIGH; |
| 67 | gpios->gpios[3].value = 1; |
| 68 | strncpy((char *)gpios->gpios[3].name,"lid", GPIO_MAX_NAME_LENGTH); |
| 69 | |
| 70 | /* Power Button */ |
Duncan Laurie | c64947b | 2012-10-01 13:31:25 -0700 | [diff] [blame] | 71 | gpios->gpios[4].port = -1; |
| 72 | gpios->gpios[4].polarity = ACTIVE_HIGH; |
| 73 | gpios->gpios[4].value = 0; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 74 | strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH); |
Duncan Laurie | c64947b | 2012-10-01 13:31:25 -0700 | [diff] [blame] | 75 | |
| 76 | /* Did we load the VGA option ROM? */ |
| 77 | gpios->gpios[5].port = -1; |
| 78 | gpios->gpios[5].polarity = ACTIVE_HIGH; |
Kyösti Mälkki | ab56b3b | 2013-11-28 16:44:51 +0200 | [diff] [blame] | 79 | gpios->gpios[5].value = gfx_get_init_done(); |
Duncan Laurie | c64947b | 2012-10-01 13:31:25 -0700 | [diff] [blame] | 80 | strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 81 | } |
| 82 | #endif |
| 83 | |
| 84 | int get_developer_mode_switch(void) |
| 85 | { |
Patrick Rudolph | e8e66f4 | 2016-02-06 17:42:42 +0100 | [diff] [blame] | 86 | /* Developer: GPIO57, active high */ |
| 87 | return get_gpio(57); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | int get_recovery_mode_switch(void) |
| 91 | { |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 92 | /* Recovery: GPIO22, active low */ |
Patrick Rudolph | e8e66f4 | 2016-02-06 17:42:42 +0100 | [diff] [blame] | 93 | return !get_gpio(22); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 94 | } |
Aaron Durbin | b0f8151 | 2016-07-25 21:31:41 -0500 | [diff] [blame] | 95 | |
| 96 | static const struct cros_gpio cros_gpios[] = { |
| 97 | CROS_GPIO_REC_AL(22, CROS_GPIO_DEVICE_NAME), |
| 98 | CROS_GPIO_DEV_AH(57, CROS_GPIO_DEVICE_NAME), |
| 99 | CROS_GPIO_WP_AL(48, CROS_GPIO_DEVICE_NAME), |
| 100 | }; |
| 101 | |
| 102 | void mainboard_chromeos_acpi_generate(void) |
| 103 | { |
| 104 | chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios)); |
| 105 | } |