blob: 69aecb148ae491968a084d8187fdd8ae897f7838 [file] [log] [blame]
Furquan Shaikhda01d942014-03-19 14:31:23 -07001/*
2 * This file is part of the coreboot project.
3 *
Deepa Dinamani2c041172014-05-15 17:14:12 -07004 * Copyright 2014 Google Inc.
Furquan Shaikhda01d942014-03-19 14:31:23 -07005 *
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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
Deepa Dinamani2c041172014-05-15 17:14:12 -070020#include <arch/cache.h>
Vadim Bendebury1de971d2014-08-07 15:20:21 -070021#include <boardid.h>
Furquan Shaikhda01d942014-03-19 14:31:23 -070022#include <boot/coreboot_tables.h>
Vadim Bendeburyc6d30402014-08-01 17:36:45 -070023#include <console/console.h>
Vadim Bendeburyc6d30402014-08-01 17:36:45 -070024#include <delay.h>
Vadim Bendebury1de971d2014-08-07 15:20:21 -070025#include <device/device.h>
Julius Wernereaa9c452014-09-24 15:40:49 -070026#include <gpio.h>
Julius Werner73d1ed62014-10-20 13:20:49 -070027#include <soc/clock.h>
Julius Werner73d1ed62014-10-20 13:20:49 -070028#include <soc/usb.h>
Vadim Bendeburyc6d30402014-08-01 17:36:45 -070029#include <string.h>
Julius Wernerec5e5e02014-08-20 15:29:56 -070030#include <symbols.h>
Vadim Bendeburyc6d30402014-08-01 17:36:45 -070031
Vadim Bendebury103a07f2014-10-23 16:03:29 -070032#include <vendorcode/google/chromeos/chromeos.h>
33
Deepa Dinamani2c041172014-05-15 17:14:12 -070034/* convenient shorthand (in MB) */
Julius Wernerec5e5e02014-08-20 15:29:56 -070035#define DRAM_START ((uintptr_t)_dram / MiB)
Deepa Dinamani2c041172014-05-15 17:14:12 -070036#define DRAM_SIZE (CONFIG_DRAM_SIZE_MB)
37#define DRAM_END (DRAM_START + DRAM_SIZE)
38
39/* DMA memory for drivers */
Julius Wernerec5e5e02014-08-20 15:29:56 -070040#define DMA_START ((uintptr_t)_dma_coherent / MiB)
41#define DMA_SIZE (_dma_coherent_size / MiB)
Julius Werner028cba92014-05-30 18:01:44 -070042
Vadim Bendeburyf6ad8322014-06-24 07:26:03 -070043#define USB_ENABLE_GPIO 51
44
Julius Werner028cba92014-05-30 18:01:44 -070045static void setup_usb(void)
46{
Vadim Bendeburyf752d012014-07-10 15:24:18 -070047#if !CONFIG_BOARD_VARIANT_AP148
Vadim Bendeburyf6ad8322014-06-24 07:26:03 -070048 gpio_tlmm_config_set(USB_ENABLE_GPIO, FUNC_SEL_GPIO,
49 GPIO_PULL_UP, GPIO_10MA, GPIO_ENABLE);
Julius Wernereaa9c452014-09-24 15:40:49 -070050 gpio_set(USB_ENABLE_GPIO, 1);
Vadim Bendeburyf752d012014-07-10 15:24:18 -070051#endif
Julius Werner028cba92014-05-30 18:01:44 -070052 usb_clock_config();
53
54 setup_usb_host1();
Julius Werner028cba92014-05-30 18:01:44 -070055}
Deepa Dinamani2c041172014-05-15 17:14:12 -070056
57static void setup_mmu(void)
58{
59 dcache_mmu_disable();
60
61 /* Map Device memory. */
62 mmu_config_range(0, DRAM_START, DCACHE_OFF);
63 /* Disable Page 0 for trapping NULL pointer references. */
64 mmu_disable_range(0, 1);
65 /* Map DRAM memory */
66 mmu_config_range(DRAM_START, DRAM_SIZE, DCACHE_WRITEBACK);
67 /* Map DMA memory */
Julius Werner028cba92014-05-30 18:01:44 -070068 mmu_config_range(DMA_START, DMA_SIZE, DCACHE_OFF);
Deepa Dinamani2c041172014-05-15 17:14:12 -070069
70 mmu_disable_range(DRAM_END, 4096 - DRAM_END);
71
72 mmu_init();
73
74 dcache_mmu_enable();
75}
Furquan Shaikhda01d942014-03-19 14:31:23 -070076
Vadim Bendebury1de971d2014-08-07 15:20:21 -070077#define TPM_RESET_GPIO 22
78static void setup_tpm(void)
79{
Dan Ehrenberg644afa72014-10-24 13:22:05 -070080 if (board_id() != BOARD_ID_PROTO_0)
Vadim Bendebury1de971d2014-08-07 15:20:21 -070081 return; /* Only proto0 have TPM reset connected to GPIO22 */
82
83 gpio_tlmm_config_set(TPM_RESET_GPIO, FUNC_SEL_GPIO, GPIO_PULL_UP,
84 GPIO_4MA, GPIO_ENABLE);
85 /*
86 * Generate a reset pulse. The spec calls for 80 us minimum, let's
87 * make it twice as long. If the output was driven low originally, the
88 * reset pulse will be even longer.
89 */
Julius Wernereaa9c452014-09-24 15:40:49 -070090 gpio_set(TPM_RESET_GPIO, 0);
Vadim Bendebury1de971d2014-08-07 15:20:21 -070091 udelay(160);
Julius Wernereaa9c452014-09-24 15:40:49 -070092 gpio_set(TPM_RESET_GPIO, 1);
Vadim Bendebury1de971d2014-08-07 15:20:21 -070093}
94
Vadim Bendeburyc7bbc042014-09-08 14:34:09 -070095#define SW_RESET_GPIO 26
Vadim Bendeburya45d5d32014-10-22 12:14:29 -070096static void assert_sw_reset(void)
Vadim Bendeburyc7bbc042014-09-08 14:34:09 -070097{
Dan Ehrenberg644afa72014-10-24 13:22:05 -070098 if (board_id() == BOARD_ID_PROTO_0)
Vadim Bendeburyc7bbc042014-09-08 14:34:09 -070099 return;
100
Vadim Bendeburyf32ef132014-09-09 20:41:33 -0700101 /*
Vadim Bendeburya45d5d32014-10-22 12:14:29 -0700102 * only proto0.2 and later care about this. We want to keep the
103 * ethernet switch in reset, otherwise it comes up in default
104 * (bridging) mode.
Vadim Bendeburyf32ef132014-09-09 20:41:33 -0700105 */
Vadim Bendeburyc7bbc042014-09-08 14:34:09 -0700106 gpio_tlmm_config_set(SW_RESET_GPIO, FUNC_SEL_GPIO,
107 GPIO_PULL_UP, GPIO_4MA, GPIO_ENABLE);
108
Vadim Bendeburya45d5d32014-10-22 12:14:29 -0700109 gpio_set(SW_RESET_GPIO, 1);
Vadim Bendeburyc7bbc042014-09-08 14:34:09 -0700110}
111
Furquan Shaikhda01d942014-03-19 14:31:23 -0700112static void mainboard_init(device_t dev)
113{
Deepa Dinamani2c041172014-05-15 17:14:12 -0700114 setup_mmu();
Julius Werner028cba92014-05-30 18:01:44 -0700115 setup_usb();
Vadim Bendeburya45d5d32014-10-22 12:14:29 -0700116 assert_sw_reset();
Vadim Bendebury1de971d2014-08-07 15:20:21 -0700117 setup_tpm();
Dan Ehrenbergcb3b0c5a2014-10-23 17:46:39 -0700118 /* Functionally a 0-cost no-op if NAND is not present */
119 board_nand_init();
Vadim Bendebury103a07f2014-10-23 16:03:29 -0700120
121#if IS_ENABLED(CONFIG_CHROMEOS)
122 /* Copy WIFI calibration data into CBMEM. */
123 cbmem_add_vpd_calibration_data();
124#endif
Furquan Shaikhda01d942014-03-19 14:31:23 -0700125}
126
127static void mainboard_enable(device_t dev)
128{
129 dev->ops->init = &mainboard_init;
130}
131
132struct chip_operations mainboard_ops = {
133 .name = "storm",
134 .enable_dev = mainboard_enable,
135};
Julius Werner028cba92014-05-30 18:01:44 -0700136
137void lb_board(struct lb_header *header)
138{
139 struct lb_range *dma;
140
141 dma = (struct lb_range *)lb_new_record(header);
142 dma->tag = LB_TAB_DMA;
143 dma->size = sizeof(*dma);
Julius Wernerec5e5e02014-08-20 15:29:56 -0700144 dma->range_start = (uintptr_t)_dma_coherent;
145 dma->range_size = _dma_coherent_size;
Vadim Bendeburye9e0eec2014-10-16 13:26:59 -0700146
147#if IS_ENABLED(CONFIG_CHROMEOS)
148 /* Retrieve the switch interface MAC addressses. */
149 lb_table_add_macs_from_vpd(header);
150#endif
Julius Werner028cba92014-05-30 18:01:44 -0700151}
Vadim Bendeburyc6d30402014-08-01 17:36:45 -0700152
153static int read_gpio(gpio_t gpio_num)
154{
155 gpio_tlmm_config_set(gpio_num, GPIO_FUNC_DISABLE,
156 GPIO_NO_PULL, GPIO_2MA, GPIO_DISABLE);
157 udelay(10); /* Should be enough to settle. */
Julius Wernereaa9c452014-09-24 15:40:49 -0700158 return gpio_get(gpio_num);
Vadim Bendeburyc6d30402014-08-01 17:36:45 -0700159}
160
161void fill_lb_gpios(struct lb_gpios *gpios)
162{
163 struct lb_gpio *gpio;
164 const int GPIO_COUNT = 5;
165
166 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
167 gpios->count = GPIO_COUNT;
168
169 gpio = gpios->gpios;
170 fill_lb_gpio(gpio++, 15, ACTIVE_LOW, "developer", read_gpio(15));
171 fill_lb_gpio(gpio++, 16, ACTIVE_LOW, "recovery", read_gpio(16));
172 fill_lb_gpio(gpio++, 17, ACTIVE_LOW, "write protect", read_gpio(17));
173 fill_lb_gpio(gpio++, -1, ACTIVE_LOW, "power", 1);
174 fill_lb_gpio(gpio++, -1, ACTIVE_LOW, "lid", 0);
175}