blob: 2c5c234ca27495766e01445ae8f251760b8e425b [file] [log] [blame]
Mohammed Habibulla05497d02013-10-24 16:44:06 -07001/*
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 Habibulla05497d02013-10-24 16:44:06 -070014 */
15
16#include <string.h>
Mohammed Habibulla05497d02013-10-24 16:44:06 -070017#include <arch/io.h>
Isaac Christensenbca446d2014-09-11 11:02:29 -060018#include <bootmode.h>
Mohammed Habibulla05497d02013-10-24 16:44:06 -070019#include <device/device.h>
20#include <device/pci.h>
21#include <southbridge/intel/lynxpoint/pch.h>
Matt DeVillierae141dd2014-07-13 18:51:28 -050022#include <vendorcode/google/chromeos/chromeos.h>
Mohammed Habibulla05497d02013-10-24 16:44:06 -070023
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 DeVillierae141dd2014-07-13 18:51:28 -050031#ifndef __PRE_RAM__
Isaac Christensenbca446d2014-09-11 11:02:29 -060032#include <boot/coreboot_tables.h>
33
34#define GPIO_COUNT 6
Mohammed Habibulla05497d02013-10-24 16:44:06 -070035
36void 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 Christensenbca446d2014-09-11 11:02:29 -060051 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "oprom", gfx_get_init_done());
Mohammed Habibulla05497d02013-10-24 16:44:06 -070052}
53#endif
54
55int 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
66int get_developer_mode_switch(void)
67{
68 return 0;
69}
70
71int 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 Christensenbca446d2014-09-11 11:02:29 -060083void init_bootmode_straps(void)
Mohammed Habibulla05497d02013-10-24 16:44:06 -070084{
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