Ronald G. Minnich | cbc95f3 | 2007-09-09 19:43:31 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Ronald G. Minnich | cbc95f3 | 2007-09-09 19:43:31 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2007 Advanced Micro Devices, 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 version 2 as |
| 8 | * published by the Free Software Foundation. |
| 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. |
Ronald G. Minnich | cbc95f3 | 2007-09-09 19:43:31 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 16 | #include <stdint.h> |
Edwin Beasant | f333ba0 | 2010-06-10 15:24:57 +0000 | [diff] [blame] | 17 | #include <stdlib.h> |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 18 | #include <spd.h> |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 19 | #include <device/pci_def.h> |
| 20 | #include <arch/io.h> |
| 21 | #include <device/pnp_def.h> |
Patrick Georgi | 12584e2 | 2010-05-08 09:14:51 +0000 | [diff] [blame] | 22 | #include <console/console.h> |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 23 | #include <lib.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 24 | #include <cpu/x86/bist.h> |
| 25 | #include <cpu/x86/msr.h> |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 26 | #include <cpu/amd/lxdef.h> |
Kyösti Mälkki | 2458f42 | 2014-04-22 16:46:31 +0300 | [diff] [blame] | 27 | #include <cpu/amd/car.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 28 | #include <southbridge/amd/cs5536/cs5536.h> |
| 29 | #include <northbridge/amd/lx/raminit.h> |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 30 | |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 31 | #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1) |
| 32 | |
Uwe Hermann | 8b942e7 | 2007-11-13 16:24:15 +0000 | [diff] [blame] | 33 | /* The ALIX1.C has no SMBus; the setup is hard-wired. */ |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 34 | static void cs5536_enable_smbus(void) { } |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 35 | |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 36 | #include "southbridge/amd/cs5536/early_setup.c" |
Edward O'Callaghan | beb0f26 | 2014-04-29 13:09:50 +1000 | [diff] [blame] | 37 | #include <superio/winbond/common/winbond.h> |
| 38 | #include <superio/winbond/w83627hf/w83627hf.h> |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 39 | |
Uwe Hermann | 8b942e7 | 2007-11-13 16:24:15 +0000 | [diff] [blame] | 40 | /* The part is a Hynix hy5du121622ctp-d43. |
| 41 | * |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 42 | * HY 5D U 12 16 2 2 C <blank> T <blank> P D43 |
| 43 | * Hynix |
| 44 | * DDR SDRAM (5D) |
| 45 | * VDD 2.5 VDDQ 2.5 (U) |
| 46 | * 512M 8K REFRESH (12) |
| 47 | * x16 (16) |
| 48 | * 4banks (2) |
| 49 | * SSTL_2 (2) |
| 50 | * 4th GEN die (C) |
| 51 | * Normal Power Consumption (<blank> ) |
| 52 | * TSOP (T) |
| 53 | * Single Die (<blank>) |
| 54 | * Lead Free (P) |
| 55 | * DDR400 3-3-3 (D43) |
| 56 | */ |
Uwe Hermann | 8b942e7 | 2007-11-13 16:24:15 +0000 | [diff] [blame] | 57 | /* SPD array */ |
| 58 | static const u8 spdbytes[] = { |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 59 | [SPD_ACCEPTABLE_CAS_LATENCIES] = 0x10, |
| 60 | [SPD_BANK_DENSITY] = 0x40, |
| 61 | [SPD_DEVICE_ATTRIBUTES_GENERAL] = 0xff, |
| 62 | [SPD_MEMORY_TYPE] = 7, |
Uwe Hermann | 8b942e7 | 2007-11-13 16:24:15 +0000 | [diff] [blame] | 63 | [SPD_MIN_CYCLE_TIME_AT_CAS_MAX] = 10, /* A guess for the tRAC value */ |
| 64 | [SPD_MODULE_ATTRIBUTES] = 0xff, /* FIXME later when we figure out. */ |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 65 | [SPD_NUM_BANKS_PER_SDRAM] = 4, |
| 66 | [SPD_PRIMARY_SDRAM_WIDTH] = 8, |
Uwe Hermann | 8b942e7 | 2007-11-13 16:24:15 +0000 | [diff] [blame] | 67 | [SPD_NUM_DIMM_BANKS] = 1, /* ALIX1.C is 1 bank. */ |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 68 | [SPD_NUM_COLUMNS] = 0xa, |
| 69 | [SPD_NUM_ROWS] = 3, |
| 70 | [SPD_REFRESH] = 0x3a, |
| 71 | [SPD_SDRAM_CYCLE_TIME_2ND] = 60, |
| 72 | [SPD_SDRAM_CYCLE_TIME_3RD] = 75, |
| 73 | [SPD_tRAS] = 40, |
| 74 | [SPD_tRCD] = 15, |
| 75 | [SPD_tRFC] = 70, |
| 76 | [SPD_tRP] = 15, |
| 77 | [SPD_tRRD] = 10, |
| 78 | }; |
| 79 | |
Christian Gmeiner | c4e07bb | 2013-06-04 17:34:35 +0200 | [diff] [blame] | 80 | int spd_read_byte(unsigned int device, unsigned int address) |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 81 | { |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 82 | printk(BIOS_DEBUG, "spd_read_byte dev %02x", device); |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 83 | |
Uwe Hermann | d773fd3 | 2010-11-20 20:23:08 +0000 | [diff] [blame] | 84 | if (device != DIMM0) { |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 85 | printk(BIOS_DEBUG, " returns 0xff\n"); |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 86 | return 0xff; |
| 87 | } |
| 88 | |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 89 | printk(BIOS_DEBUG, " addr %02x returns %02x\n", |
| 90 | address, spdbytes[address]); |
Uwe Hermann | 8b942e7 | 2007-11-13 16:24:15 +0000 | [diff] [blame] | 91 | |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 92 | return spdbytes[address]; |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 95 | #include "northbridge/amd/lx/pll_reset.c" |
Stefan Reinauer | c13093b | 2009-09-23 18:51:03 +0000 | [diff] [blame] | 96 | #include "lib/generic_sdram.c" |
Kyösti Mälkki | 7916f4c | 2012-02-09 16:07:41 +0200 | [diff] [blame] | 97 | #include "cpu/amd/geode_lx/cpureginit.c" |
| 98 | #include "cpu/amd/geode_lx/syspreinit.c" |
| 99 | #include "cpu/amd/geode_lx/msrinit.c" |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 100 | |
Aaron Durbin | a0a3727 | 2014-08-14 08:35:11 -0500 | [diff] [blame] | 101 | #include <cpu/intel/romstage.h> |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 102 | void main(unsigned long bist) |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 103 | { |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 104 | static const struct mem_controller memctrl[] = { |
Uwe Hermann | d773fd3 | 2010-11-20 20:23:08 +0000 | [diff] [blame] | 105 | {.channel0 = {DIMM0}}, |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 106 | }; |
Uwe Hermann | 8b942e7 | 2007-11-13 16:24:15 +0000 | [diff] [blame] | 107 | |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 108 | SystemPreInit(); |
| 109 | msr_init(); |
| 110 | |
| 111 | cs5536_early_setup(); |
| 112 | |
Uwe Hermann | 8b942e7 | 2007-11-13 16:24:15 +0000 | [diff] [blame] | 113 | /* NOTE: Must do this AFTER cs5536_early_setup()! |
| 114 | * It is counting on some early MSR setup for the CS5536. |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 115 | */ |
| 116 | cs5536_disable_internal_uart(); |
Edward O'Callaghan | beb0f26 | 2014-04-29 13:09:50 +1000 | [diff] [blame] | 117 | winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 118 | console_init(); |
| 119 | |
Stefan Reinauer | 9839cbd | 2010-04-21 20:06:10 +0000 | [diff] [blame] | 120 | /* Halt if there was a built in self test failure */ |
| 121 | report_bist_failure(bist); |
| 122 | |
Patrick Georgi | 7dc2864 | 2012-07-13 19:06:22 +0200 | [diff] [blame] | 123 | pll_reset(); |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 124 | |
Edwin Beasant | f333ba0 | 2010-06-10 15:24:57 +0000 | [diff] [blame] | 125 | cpuRegInit(0, DIMM0, DIMM1, DRAM_TERMINATED); |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 126 | |
| 127 | sdram_initialize(1, memctrl); |
| 128 | |
Uwe Hermann | 8b942e7 | 2007-11-13 16:24:15 +0000 | [diff] [blame] | 129 | /* Switch from Cache as RAM to real RAM. |
| 130 | * |
| 131 | * There are two ways we could think about this. |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 132 | * |
Stefan Reinauer | 38f147e | 2010-02-08 12:20:50 +0000 | [diff] [blame] | 133 | * 1. If we are using the romstage.inc ROMCC way, the stack is |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 134 | * going to be re-setup in the code following this code. Just |
| 135 | * wbinvd the stack to clear the cache tags. We don't care |
| 136 | * where the stack used to be. |
Uwe Hermann | 8b942e7 | 2007-11-13 16:24:15 +0000 | [diff] [blame] | 137 | * |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 138 | * 2. This file is built as a normal .c -> .o and linked in |
| 139 | * etc. The stack might be used to return etc. That means we |
| 140 | * care about what is in the stack. If we are smart we set |
| 141 | * the CAR stack to the same location as the rest of |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 142 | * coreboot. If that is the case we can just do a wbinvd. |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 143 | * The stack will be written into real RAM that is now setup |
| 144 | * and we continue like nothing happened. If the stack is |
| 145 | * located somewhere other than where LB would like it, you |
| 146 | * need to write some code to do a copy from cache to RAM |
| 147 | * |
Uwe Hermann | 8b942e7 | 2007-11-13 16:24:15 +0000 | [diff] [blame] | 148 | * We use method 1 on Norwich and on this board too. |
Ronald G. Minnich | 65bc460 | 2007-10-26 14:57:46 +0000 | [diff] [blame] | 149 | */ |
Stefan Reinauer | 0c781b2 | 2010-04-01 09:50:32 +0000 | [diff] [blame] | 150 | post_code(0x02); |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 151 | printk(BIOS_ERR, "POST 02\n"); |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 152 | __asm__("wbinvd\n"); |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 153 | printk(BIOS_ERR, "Past wbinvd\n"); |
Uwe Hermann | 8b942e7 | 2007-11-13 16:24:15 +0000 | [diff] [blame] | 154 | |
| 155 | /* We are finding the return does not work on this board. Explicitly |
| 156 | * call the label that is after the call to us. This is gross, but |
| 157 | * sometimes at this level it is the only way out. |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 158 | */ |
Ronald G. Minnich | 6226f13 | 2007-09-08 18:32:53 +0000 | [diff] [blame] | 159 | done_cache_as_ram_main(); |
| 160 | } |