blob: 45f531dd77b00609add791bbd0539874eacfcffc [file] [log] [blame]
Ronald G. Minnichcbc95f32007-09-09 19:43:31 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Ronald G. Minnichcbc95f32007-09-09 19:43:31 +00003 *
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.
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
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Ronald G. Minnichcbc95f32007-09-09 19:43:31 +000018 */
19
Ronald G. Minnich6226f132007-09-08 18:32:53 +000020#include <stdint.h>
Edwin Beasantf333ba02010-06-10 15:24:57 +000021#include <stdlib.h>
Ronald G. Minnich65bc4602007-10-26 14:57:46 +000022#include <spd.h>
Ronald G. Minnich6226f132007-09-08 18:32:53 +000023#include <device/pci_def.h>
24#include <arch/io.h>
25#include <device/pnp_def.h>
Patrick Georgi12584e22010-05-08 09:14:51 +000026#include <console/console.h>
Patrick Georgid0835952010-10-05 09:07:10 +000027#include <lib.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110028#include <cpu/x86/bist.h>
29#include <cpu/x86/msr.h>
Ronald G. Minnich6226f132007-09-08 18:32:53 +000030#include <cpu/amd/lxdef.h>
Kyösti Mälkki2458f422014-04-22 16:46:31 +030031#include <cpu/amd/car.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110032#include <southbridge/amd/cs5536/cs5536.h>
33#include <northbridge/amd/lx/raminit.h>
Ronald G. Minnich6226f132007-09-08 18:32:53 +000034
Ronald G. Minnich6226f132007-09-08 18:32:53 +000035#define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
36
Uwe Hermann8b942e72007-11-13 16:24:15 +000037/* The ALIX1.C has no SMBus; the setup is hard-wired. */
Uwe Hermann7b997052010-11-21 22:47:22 +000038static void cs5536_enable_smbus(void) { }
Ronald G. Minnich65bc4602007-10-26 14:57:46 +000039
stepan836ae292010-12-08 05:42:47 +000040#include "southbridge/amd/cs5536/early_setup.c"
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +100041#include <superio/winbond/common/winbond.h>
42#include <superio/winbond/w83627hf/w83627hf.h>
Ronald G. Minnich6226f132007-09-08 18:32:53 +000043
Uwe Hermann8b942e72007-11-13 16:24:15 +000044/* The part is a Hynix hy5du121622ctp-d43.
45 *
Ronald G. Minnich65bc4602007-10-26 14:57:46 +000046 * HY 5D U 12 16 2 2 C <blank> T <blank> P D43
47 * Hynix
48 * DDR SDRAM (5D)
49 * VDD 2.5 VDDQ 2.5 (U)
50 * 512M 8K REFRESH (12)
51 * x16 (16)
52 * 4banks (2)
53 * SSTL_2 (2)
54 * 4th GEN die (C)
55 * Normal Power Consumption (<blank> )
56 * TSOP (T)
57 * Single Die (<blank>)
58 * Lead Free (P)
59 * DDR400 3-3-3 (D43)
60 */
Uwe Hermann8b942e72007-11-13 16:24:15 +000061/* SPD array */
62static const u8 spdbytes[] = {
Ronald G. Minnich65bc4602007-10-26 14:57:46 +000063 [SPD_ACCEPTABLE_CAS_LATENCIES] = 0x10,
64 [SPD_BANK_DENSITY] = 0x40,
65 [SPD_DEVICE_ATTRIBUTES_GENERAL] = 0xff,
66 [SPD_MEMORY_TYPE] = 7,
Uwe Hermann8b942e72007-11-13 16:24:15 +000067 [SPD_MIN_CYCLE_TIME_AT_CAS_MAX] = 10, /* A guess for the tRAC value */
68 [SPD_MODULE_ATTRIBUTES] = 0xff, /* FIXME later when we figure out. */
Ronald G. Minnich65bc4602007-10-26 14:57:46 +000069 [SPD_NUM_BANKS_PER_SDRAM] = 4,
70 [SPD_PRIMARY_SDRAM_WIDTH] = 8,
Uwe Hermann8b942e72007-11-13 16:24:15 +000071 [SPD_NUM_DIMM_BANKS] = 1, /* ALIX1.C is 1 bank. */
Ronald G. Minnich65bc4602007-10-26 14:57:46 +000072 [SPD_NUM_COLUMNS] = 0xa,
73 [SPD_NUM_ROWS] = 3,
74 [SPD_REFRESH] = 0x3a,
75 [SPD_SDRAM_CYCLE_TIME_2ND] = 60,
76 [SPD_SDRAM_CYCLE_TIME_3RD] = 75,
77 [SPD_tRAS] = 40,
78 [SPD_tRCD] = 15,
79 [SPD_tRFC] = 70,
80 [SPD_tRP] = 15,
81 [SPD_tRRD] = 10,
82};
83
Christian Gmeinerc4e07bb2013-06-04 17:34:35 +020084int spd_read_byte(unsigned int device, unsigned int address)
Ronald G. Minnich6226f132007-09-08 18:32:53 +000085{
Stefan Reinauer069f4762015-01-05 13:02:32 -080086 printk(BIOS_DEBUG, "spd_read_byte dev %02x", device);
Ronald G. Minnich65bc4602007-10-26 14:57:46 +000087
Uwe Hermannd773fd32010-11-20 20:23:08 +000088 if (device != DIMM0) {
Stefan Reinauer069f4762015-01-05 13:02:32 -080089 printk(BIOS_DEBUG, " returns 0xff\n");
Ronald G. Minnich65bc4602007-10-26 14:57:46 +000090 return 0xff;
91 }
92
Stefan Reinauer069f4762015-01-05 13:02:32 -080093 printk(BIOS_DEBUG, " addr %02x returns %02x\n",
94 address, spdbytes[address]);
Uwe Hermann8b942e72007-11-13 16:24:15 +000095
Ronald G. Minnich65bc4602007-10-26 14:57:46 +000096 return spdbytes[address];
Ronald G. Minnich6226f132007-09-08 18:32:53 +000097}
98
Ronald G. Minnich6226f132007-09-08 18:32:53 +000099#include "northbridge/amd/lx/pll_reset.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +0000100#include "lib/generic_sdram.c"
Kyösti Mälkki7916f4c2012-02-09 16:07:41 +0200101#include "cpu/amd/geode_lx/cpureginit.c"
102#include "cpu/amd/geode_lx/syspreinit.c"
103#include "cpu/amd/geode_lx/msrinit.c"
Ronald G. Minnich6226f132007-09-08 18:32:53 +0000104
Aaron Durbina0a37272014-08-14 08:35:11 -0500105#include <cpu/intel/romstage.h>
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000106void main(unsigned long bist)
Ronald G. Minnich6226f132007-09-08 18:32:53 +0000107{
Ronald G. Minnich65bc4602007-10-26 14:57:46 +0000108 static const struct mem_controller memctrl[] = {
Uwe Hermannd773fd32010-11-20 20:23:08 +0000109 {.channel0 = {DIMM0}},
Ronald G. Minnich65bc4602007-10-26 14:57:46 +0000110 };
Uwe Hermann8b942e72007-11-13 16:24:15 +0000111
Ronald G. Minnich6226f132007-09-08 18:32:53 +0000112 SystemPreInit();
113 msr_init();
114
115 cs5536_early_setup();
116
Uwe Hermann8b942e72007-11-13 16:24:15 +0000117 /* NOTE: Must do this AFTER cs5536_early_setup()!
118 * It is counting on some early MSR setup for the CS5536.
Ronald G. Minnich6226f132007-09-08 18:32:53 +0000119 */
120 cs5536_disable_internal_uart();
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +1000121 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Ronald G. Minnich6226f132007-09-08 18:32:53 +0000122 console_init();
123
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000124 /* Halt if there was a built in self test failure */
125 report_bist_failure(bist);
126
Patrick Georgi7dc28642012-07-13 19:06:22 +0200127 pll_reset();
Ronald G. Minnich6226f132007-09-08 18:32:53 +0000128
Edwin Beasantf333ba02010-06-10 15:24:57 +0000129 cpuRegInit(0, DIMM0, DIMM1, DRAM_TERMINATED);
Ronald G. Minnich6226f132007-09-08 18:32:53 +0000130
131 sdram_initialize(1, memctrl);
132
Uwe Hermann8b942e72007-11-13 16:24:15 +0000133 /* Switch from Cache as RAM to real RAM.
134 *
135 * There are two ways we could think about this.
Ronald G. Minnich65bc4602007-10-26 14:57:46 +0000136 *
Stefan Reinauer38f147e2010-02-08 12:20:50 +0000137 * 1. If we are using the romstage.inc ROMCC way, the stack is
Ronald G. Minnich65bc4602007-10-26 14:57:46 +0000138 * going to be re-setup in the code following this code. Just
139 * wbinvd the stack to clear the cache tags. We don't care
140 * where the stack used to be.
Uwe Hermann8b942e72007-11-13 16:24:15 +0000141 *
Ronald G. Minnich65bc4602007-10-26 14:57:46 +0000142 * 2. This file is built as a normal .c -> .o and linked in
143 * etc. The stack might be used to return etc. That means we
144 * care about what is in the stack. If we are smart we set
145 * the CAR stack to the same location as the rest of
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000146 * coreboot. If that is the case we can just do a wbinvd.
Ronald G. Minnich65bc4602007-10-26 14:57:46 +0000147 * The stack will be written into real RAM that is now setup
148 * and we continue like nothing happened. If the stack is
149 * located somewhere other than where LB would like it, you
150 * need to write some code to do a copy from cache to RAM
151 *
Uwe Hermann8b942e72007-11-13 16:24:15 +0000152 * We use method 1 on Norwich and on this board too.
Ronald G. Minnich65bc4602007-10-26 14:57:46 +0000153 */
Stefan Reinauer0c781b22010-04-01 09:50:32 +0000154 post_code(0x02);
Stefan Reinauer069f4762015-01-05 13:02:32 -0800155 printk(BIOS_ERR, "POST 02\n");
Ronald G. Minnich6226f132007-09-08 18:32:53 +0000156 __asm__("wbinvd\n");
Stefan Reinauer069f4762015-01-05 13:02:32 -0800157 printk(BIOS_ERR, "Past wbinvd\n");
Uwe Hermann8b942e72007-11-13 16:24:15 +0000158
159 /* We are finding the return does not work on this board. Explicitly
160 * call the label that is after the call to us. This is gross, but
161 * sometimes at this level it is the only way out.
Ronald G. Minnich6226f132007-09-08 18:32:53 +0000162 */
Ronald G. Minnich6226f132007-09-08 18:32:53 +0000163 done_cache_as_ram_main();
164}