blob: 8982f919ae6ab770dc64ed0bc60f5342f9e37ee2 [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>
Furquan Shaikhda01d942014-03-19 14:31:23 -070021#include <boot/coreboot_tables.h>
Vadim Bendeburyc6d30402014-08-01 17:36:45 -070022#include <console/console.h>
Deepa Dinamani2c041172014-05-15 17:14:12 -070023#include <device/device.h>
Vadim Bendeburyc6d30402014-08-01 17:36:45 -070024#include <delay.h>
25#include <string.h>
26
Julius Werner028cba92014-05-30 18:01:44 -070027#include <soc/qualcomm/ipq806x/include/clock.h>
Vadim Bendeburyf6ad8322014-06-24 07:26:03 -070028#include <soc/qualcomm/ipq806x/include/gpio.h>
Julius Werner028cba92014-05-30 18:01:44 -070029#include <soc/qualcomm/ipq806x/include/usb.h>
Deepa Dinamani2c041172014-05-15 17:14:12 -070030
31/* convenient shorthand (in MB) */
Julius Werner028cba92014-05-30 18:01:44 -070032#define DRAM_START (CONFIG_SYS_SDRAM_BASE / MiB)
Deepa Dinamani2c041172014-05-15 17:14:12 -070033#define DRAM_SIZE (CONFIG_DRAM_SIZE_MB)
34#define DRAM_END (DRAM_START + DRAM_SIZE)
35
36/* DMA memory for drivers */
Julius Werner028cba92014-05-30 18:01:44 -070037#define DMA_START (CONFIG_DRAM_DMA_START / MiB)
38#define DMA_SIZE (CONFIG_DRAM_DMA_SIZE / MiB)
39
Vadim Bendeburyf6ad8322014-06-24 07:26:03 -070040#define USB_ENABLE_GPIO 51
41
Julius Werner028cba92014-05-30 18:01:44 -070042static void setup_usb(void)
43{
Vadim Bendeburyf752d012014-07-10 15:24:18 -070044#if !CONFIG_BOARD_VARIANT_AP148
Vadim Bendeburyf6ad8322014-06-24 07:26:03 -070045 gpio_tlmm_config_set(USB_ENABLE_GPIO, FUNC_SEL_GPIO,
46 GPIO_PULL_UP, GPIO_10MA, GPIO_ENABLE);
Vadim Bendeburyd36ef6a2014-07-25 17:34:42 -070047 gpio_set_out_value(USB_ENABLE_GPIO, 1);
Vadim Bendeburyf752d012014-07-10 15:24:18 -070048#endif
Julius Werner028cba92014-05-30 18:01:44 -070049 usb_clock_config();
50
51 setup_usb_host1();
Julius Werner028cba92014-05-30 18:01:44 -070052}
Deepa Dinamani2c041172014-05-15 17:14:12 -070053
54static void setup_mmu(void)
55{
56 dcache_mmu_disable();
57
58 /* Map Device memory. */
59 mmu_config_range(0, DRAM_START, DCACHE_OFF);
60 /* Disable Page 0 for trapping NULL pointer references. */
61 mmu_disable_range(0, 1);
62 /* Map DRAM memory */
63 mmu_config_range(DRAM_START, DRAM_SIZE, DCACHE_WRITEBACK);
64 /* Map DMA memory */
Julius Werner028cba92014-05-30 18:01:44 -070065 mmu_config_range(DMA_START, DMA_SIZE, DCACHE_OFF);
Deepa Dinamani2c041172014-05-15 17:14:12 -070066
67 mmu_disable_range(DRAM_END, 4096 - DRAM_END);
68
69 mmu_init();
70
71 dcache_mmu_enable();
72}
Furquan Shaikhda01d942014-03-19 14:31:23 -070073
74static void mainboard_init(device_t dev)
75{
Deepa Dinamani2c041172014-05-15 17:14:12 -070076 setup_mmu();
Julius Werner028cba92014-05-30 18:01:44 -070077 setup_usb();
Furquan Shaikhda01d942014-03-19 14:31:23 -070078}
79
80static void mainboard_enable(device_t dev)
81{
82 dev->ops->init = &mainboard_init;
83}
84
85struct chip_operations mainboard_ops = {
86 .name = "storm",
87 .enable_dev = mainboard_enable,
88};
Julius Werner028cba92014-05-30 18:01:44 -070089
90void lb_board(struct lb_header *header)
91{
92 struct lb_range *dma;
93
94 dma = (struct lb_range *)lb_new_record(header);
95 dma->tag = LB_TAB_DMA;
96 dma->size = sizeof(*dma);
97 dma->range_start = CONFIG_DRAM_DMA_START;
98 dma->range_size = CONFIG_DRAM_DMA_SIZE;
99}
Vadim Bendeburyc6d30402014-08-01 17:36:45 -0700100
101static int read_gpio(gpio_t gpio_num)
102{
103 gpio_tlmm_config_set(gpio_num, GPIO_FUNC_DISABLE,
104 GPIO_NO_PULL, GPIO_2MA, GPIO_DISABLE);
105 udelay(10); /* Should be enough to settle. */
106 return gpio_get_in_value(gpio_num);
107}
108
109void fill_lb_gpios(struct lb_gpios *gpios)
110{
111 struct lb_gpio *gpio;
112 const int GPIO_COUNT = 5;
113
114 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
115 gpios->count = GPIO_COUNT;
116
117 gpio = gpios->gpios;
118 fill_lb_gpio(gpio++, 15, ACTIVE_LOW, "developer", read_gpio(15));
119 fill_lb_gpio(gpio++, 16, ACTIVE_LOW, "recovery", read_gpio(16));
120 fill_lb_gpio(gpio++, 17, ACTIVE_LOW, "write protect", read_gpio(17));
121 fill_lb_gpio(gpio++, -1, ACTIVE_LOW, "power", 1);
122 fill_lb_gpio(gpio++, -1, ACTIVE_LOW, "lid", 0);
123}