Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 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. |
| 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 | |
| 20 | #include <stddef.h> |
| 21 | #include <arch/io.h> |
| 22 | #include <cbfs.h> |
| 23 | #include <cbmem.h> |
| 24 | #include <console/console.h> |
| 25 | #include <device/pci_def.h> |
| 26 | #include <baytrail/gpio.h> |
| 27 | #include <baytrail/mrc_cache.h> |
| 28 | #include <baytrail/iomap.h> |
Aaron Durbin | 3ccb3ce | 2013-10-11 00:26:04 -0500 | [diff] [blame] | 29 | #include <baytrail/iosf.h> |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 30 | #include <baytrail/pci_devs.h> |
| 31 | #include <baytrail/romstage.h> |
| 32 | |
| 33 | |
| 34 | static void enable_smbus(void) |
| 35 | { |
| 36 | uint32_t reg; |
| 37 | const uint32_t smbus_dev = PCI_DEV(0, SMBUS_DEV, SMBUS_FUNC); |
| 38 | |
| 39 | /* SMBus I/O BAR */ |
| 40 | reg = SMBUS_BASE_ADDRESS | 2; |
| 41 | pci_write_config32(smbus_dev, PCI_BASE_ADDRESS_4, reg); |
| 42 | /* Enable decode of I/O space. */ |
| 43 | reg = pci_read_config16(smbus_dev, PCI_COMMAND); |
| 44 | reg |= 0x1; |
| 45 | pci_write_config16(smbus_dev, PCI_COMMAND, reg); |
| 46 | /* Enable Host Controller */ |
| 47 | reg = pci_read_config8(smbus_dev, 0x40); |
| 48 | reg |= 1; |
| 49 | pci_write_config8(smbus_dev, 0x40, reg); |
| 50 | |
| 51 | /* Configure pads to be used for SMBus */ |
| 52 | score_select_func(PCU_SMB_CLK_PAD, 1); |
| 53 | score_select_func(PCU_SMB_DATA_PAD, 1); |
| 54 | } |
| 55 | |
Aaron Durbin | 833ff35 | 2013-10-02 11:06:31 -0500 | [diff] [blame] | 56 | static void ABI_X86 send_to_console(unsigned char b) |
| 57 | { |
Kyösti Mälkki | 657e0be | 2014-02-04 19:03:57 +0200 | [diff] [blame^] | 58 | do_putchar(b); |
Aaron Durbin | 833ff35 | 2013-10-02 11:06:31 -0500 | [diff] [blame] | 59 | } |
| 60 | |
Aaron Durbin | 3ccb3ce | 2013-10-11 00:26:04 -0500 | [diff] [blame] | 61 | static void print_dram_info(void) |
| 62 | { |
| 63 | const int mrc_ver_reg = 0xf0; |
| 64 | const uint32_t soc_dev = PCI_DEV(0, SOC_DEV, SOC_FUNC); |
| 65 | uint32_t reg; |
| 66 | int num_channels; |
| 67 | int speed; |
| 68 | uint32_t ch0; |
| 69 | uint32_t ch1; |
| 70 | |
| 71 | reg = pci_read_config32(soc_dev, mrc_ver_reg); |
| 72 | |
| 73 | printk(BIOS_INFO, "MRC v%d.%02d\n", (reg >> 8) & 0xff, reg & 0xff); |
| 74 | |
| 75 | /* Number of channels enabled and DDR3 type. Determine number of |
| 76 | * channels by keying of the rank enable bits [3:0]. * */ |
| 77 | ch0 = iosf_dunit_ch0_read(DRP); |
| 78 | ch1 = iosf_dunit_ch1_read(DRP); |
| 79 | num_channels = 0; |
| 80 | if (ch0 & DRP_RANK_MASK) |
| 81 | num_channels++; |
| 82 | if (ch1 & DRP_RANK_MASK) |
| 83 | num_channels++; |
| 84 | |
| 85 | printk(BIOS_INFO, "%d channels of %sDDR3 @ ", num_channels, |
| 86 | (reg & (1 << 22)) ? "LP" : ""); |
| 87 | |
| 88 | /* DRAM frequency -- all channels run at same frequency. */ |
| 89 | reg = iosf_dunit_read(DTR0); |
| 90 | switch (reg & 0x3) { |
| 91 | case 0: |
| 92 | speed = 800; break; |
| 93 | case 1: |
| 94 | speed = 1066; break; |
| 95 | case 2: |
| 96 | speed = 1333; break; |
| 97 | case 3: |
| 98 | speed = 1600; break; |
| 99 | } |
| 100 | printk(BIOS_INFO, "%dMHz\n", speed); |
| 101 | } |
| 102 | |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 103 | void raminit(struct mrc_params *mp, int prev_sleep_state) |
| 104 | { |
| 105 | int ret; |
| 106 | mrc_wrapper_entry_t mrc_entry; |
| 107 | const struct mrc_saved_data *cache; |
| 108 | |
| 109 | /* Fill in default entries. */ |
| 110 | mp->version = MRC_PARAMS_VER; |
Aaron Durbin | 833ff35 | 2013-10-02 11:06:31 -0500 | [diff] [blame] | 111 | mp->console_out = &send_to_console; |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 112 | mp->prev_sleep_state = prev_sleep_state; |
| 113 | |
| 114 | if (!mrc_cache_get_current(&cache)) { |
| 115 | mp->saved_data_size = cache->size; |
| 116 | mp->saved_data = &cache->data[0]; |
| 117 | } else { |
| 118 | printk(BIOS_DEBUG, "No MRC cache found.\n"); |
| 119 | } |
| 120 | |
| 121 | mrc_entry = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, "mrc.bin", 0xab, |
| 122 | NULL); |
| 123 | |
| 124 | if (mrc_entry == NULL) { |
| 125 | printk(BIOS_DEBUG, "Couldn't find mrc.bin\n"); |
| 126 | return; |
| 127 | } |
| 128 | if (mp->mainboard.dram_info_location == DRAM_INFO_SPD_SMBUS) |
| 129 | enable_smbus(); |
| 130 | |
| 131 | ret = mrc_entry(mp); |
| 132 | |
Aaron Durbin | 3ccb3ce | 2013-10-11 00:26:04 -0500 | [diff] [blame] | 133 | print_dram_info(); |
| 134 | |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 135 | cbmem_initialize_empty(); |
| 136 | |
| 137 | printk(BIOS_DEBUG, "MRC Wrapper returned %d\n", ret); |
| 138 | printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", mp->data_to_save, |
| 139 | mp->data_to_save_size); |
| 140 | |
| 141 | if (mp->data_to_save != NULL && mp->data_to_save_size > 0) |
| 142 | mrc_cache_stash_data(mp->data_to_save, mp->data_to_save_size); |
| 143 | } |