Mohammed Habibulla | 05497d0 | 2013-10-24 16:44:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 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. |
Mohammed Habibulla | 05497d0 | 2013-10-24 16:44:06 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <string.h> |
Mohammed Habibulla | 05497d0 | 2013-10-24 16:44:06 -0700 | [diff] [blame] | 17 | #include <arch/io.h> |
Isaac Christensen | bca446d | 2014-09-11 11:02:29 -0600 | [diff] [blame] | 18 | #include <bootmode.h> |
Mohammed Habibulla | 05497d0 | 2013-10-24 16:44:06 -0700 | [diff] [blame] | 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <southbridge/intel/lynxpoint/pch.h> |
Matt DeVillier | ae141dd | 2014-07-13 18:51:28 -0500 | [diff] [blame] | 22 | #include <vendorcode/google/chromeos/chromeos.h> |
Mohammed Habibulla | 05497d0 | 2013-10-24 16:44:06 -0700 | [diff] [blame] | 23 | |
| 24 | #define GPIO_SPI_WP 58 |
| 25 | #define GPIO_REC_MODE 12 |
| 26 | |
| 27 | #define FLAG_SPI_WP 0 |
| 28 | #define FLAG_REC_MODE 1 |
| 29 | #define FLAG_DEV_MODE 2 |
| 30 | |
Matt DeVillier | ae141dd | 2014-07-13 18:51:28 -0500 | [diff] [blame] | 31 | #ifndef __PRE_RAM__ |
Isaac Christensen | bca446d | 2014-09-11 11:02:29 -0600 | [diff] [blame] | 32 | #include <boot/coreboot_tables.h> |
| 33 | |
| 34 | #define GPIO_COUNT 6 |
Mohammed Habibulla | 05497d0 | 2013-10-24 16:44:06 -0700 | [diff] [blame] | 35 | |
| 36 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 37 | { |
| 38 | struct lb_gpio *gpio; |
| 39 | |
| 40 | gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio)); |
| 41 | gpios->count = GPIO_COUNT; |
| 42 | |
| 43 | gpio = gpios->gpios; |
| 44 | fill_lb_gpio(gpio++, GPIO_SPI_WP, ACTIVE_HIGH, "write protect", 0); |
| 45 | fill_lb_gpio(gpio++, GPIO_REC_MODE, ACTIVE_LOW, "recovery", |
| 46 | get_recovery_mode_switch()); |
| 47 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "developer", |
| 48 | get_developer_mode_switch()); |
| 49 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "lid", 1); |
| 50 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "power", 0); |
Isaac Christensen | bca446d | 2014-09-11 11:02:29 -0600 | [diff] [blame] | 51 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "oprom", gfx_get_init_done()); |
Mohammed Habibulla | 05497d0 | 2013-10-24 16:44:06 -0700 | [diff] [blame] | 52 | } |
| 53 | #endif |
| 54 | |
| 55 | int get_write_protect_state(void) |
| 56 | { |
| 57 | device_t dev; |
| 58 | #ifdef __PRE_RAM__ |
| 59 | dev = PCI_DEV(0, 0x1f, 2); |
| 60 | #else |
| 61 | dev = dev_find_slot(0, PCI_DEVFN(0x1f, 2)); |
| 62 | #endif |
| 63 | return (pci_read_config32(dev, SATA_SP) >> FLAG_SPI_WP) & 1; |
| 64 | } |
| 65 | |
| 66 | int get_developer_mode_switch(void) |
| 67 | { |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | int get_recovery_mode_switch(void) |
| 72 | { |
| 73 | device_t dev; |
| 74 | #ifdef __PRE_RAM__ |
| 75 | dev = PCI_DEV(0, 0x1f, 2); |
| 76 | #else |
| 77 | dev = dev_find_slot(0, PCI_DEVFN(0x1f, 2)); |
| 78 | #endif |
| 79 | return (pci_read_config32(dev, SATA_SP) >> FLAG_REC_MODE) & 1; |
| 80 | } |
| 81 | |
| 82 | #ifdef __PRE_RAM__ |
Isaac Christensen | bca446d | 2014-09-11 11:02:29 -0600 | [diff] [blame] | 83 | void init_bootmode_straps(void) |
Mohammed Habibulla | 05497d0 | 2013-10-24 16:44:06 -0700 | [diff] [blame] | 84 | { |
| 85 | u32 flags = 0; |
| 86 | |
| 87 | /* Write Protect: GPIO58 = GPIO_SPI_WP, active high */ |
| 88 | if (get_gpio(GPIO_SPI_WP)) |
| 89 | flags |= (1 << FLAG_SPI_WP); |
| 90 | |
| 91 | /* Recovery: GPIO12 = RECOVERY_L, active low */ |
| 92 | if (!get_gpio(GPIO_REC_MODE)) |
| 93 | flags |= (1 << FLAG_REC_MODE); |
| 94 | |
| 95 | /* Developer: Virtual */ |
| 96 | |
| 97 | pci_write_config32(PCI_DEV(0, 0x1f, 2), SATA_SP, flags); |
| 98 | } |
| 99 | #endif |