blob: a65b9b80b1ab9ef92f25199d781e53f21a05d35a [file] [log] [blame]
Jens Rottmannc1373852010-09-07 17:33:17 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007 Advanced Micro Devices, Inc.
5 * Copyright (C) 2010 LiPPERT Embedded Computers GmbH
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Jens Rottmannc1373852010-09-07 17:33:17 +000016 */
17
18/* Based on romstage.c from the SpaceRunner-LX mainboard. */
19
20#include <stdlib.h>
21#include <stdint.h>
22#include <spd.h>
23#include <device/pci_def.h>
24#include <arch/io.h>
25#include <device/pnp_def.h>
Jens Rottmannc1373852010-09-07 17:33:17 +000026#include <console/console.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110027#include <cpu/x86/bist.h>
28#include <cpu/x86/msr.h>
Jens Rottmannc1373852010-09-07 17:33:17 +000029#include <cpu/amd/lxdef.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110030#include <southbridge/amd/cs5536/cs5536.h>
stepan836ae292010-12-08 05:42:47 +000031#include "southbridge/amd/cs5536/early_smbus.c"
32#include "southbridge/amd/cs5536/early_setup.c"
Edward O'Callaghanf2920022014-04-27 00:41:50 +100033#include <superio/ite/common/ite.h>
34#include <superio/ite/it8712f/it8712f.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110035#include <northbridge/amd/lx/raminit.h>
Jens Rottmannc1373852010-09-07 17:33:17 +000036
Edward O'Callaghanf2920022014-04-27 00:41:50 +100037#define SERIAL_DEV PNP_DEV(0x2e, IT8712F_SP1)
38#define GPIO_DEV PNP_DEV(0x2e, IT8712F_GPIO)
39
Jens Rottmannc1373852010-09-07 17:33:17 +000040/* Bit0 enables Spread Spectrum, bit1 makes on-board CF slot act as IDE slave. */
41#if CONFIG_ONBOARD_IDE_SLAVE
42 #define SMC_CONFIG 0x03
43#else
44 #define SMC_CONFIG 0x01
45#endif
46
Jens Rottmannc1373852010-09-07 17:33:17 +000047static const unsigned char spdbytes[] = { // 4x Promos V58C2512164SA-J5I
48 0xFF, 0xFF, // only values used by Geode-LX raminit.c are set
49 [SPD_MEMORY_TYPE] = SPD_MEMORY_TYPE_SDRAM_DDR, // (Fundamental) memory type
50 [SPD_NUM_ROWS] = 0x0D, // Number of row address bits [13]
51 [SPD_NUM_COLUMNS] = 0x0A, // Number of column address bits [10]
52 [SPD_NUM_DIMM_BANKS] = 1, // Number of module rows (banks)
53 0xFF, 0xFF, 0xFF,
54 [SPD_MIN_CYCLE_TIME_AT_CAS_MAX] = 0x50, // SDRAM cycle time (highest CAS latency), RAS access time (tRAC) [5.0 ns in BCD]
55 0xFF, 0xFF,
56 [SPD_REFRESH] = 0x82, // Refresh rate/type [Self Refresh, 7.8 us]
57 [SPD_PRIMARY_SDRAM_WIDTH] = 64, // SDRAM width (primary SDRAM) [64 bits]
58 0xFF, 0xFF, 0xFF,
59 [SPD_NUM_BANKS_PER_SDRAM] = 4, // SDRAM device attributes, number of banks on SDRAM device
60 [SPD_ACCEPTABLE_CAS_LATENCIES] = 0x1C, // SDRAM device attributes, CAS latency [3, 2.5, 2]
61 0xFF, 0xFF,
62 [SPD_MODULE_ATTRIBUTES] = 0x20, // SDRAM module attributes [differential clk]
63 [SPD_DEVICE_ATTRIBUTES_GENERAL] = 0x40, // SDRAM device attributes, general [Concurrent AP]
64 [SPD_SDRAM_CYCLE_TIME_2ND] = 0x60, // SDRAM cycle time (2nd highest CAS latency) [6.0 ns in BCD]
65 0xFF,
66 [SPD_SDRAM_CYCLE_TIME_3RD] = 0x75, // SDRAM cycle time (3rd highest CAS latency) [7.5 ns in BCD]
67 0xFF,
68 [SPD_tRP] = 60, // Min. row precharge time [15 ns in units of 0.25 ns]
69 [SPD_tRRD] = 40, // Min. row active to row active [10 ns in units of 0.25 ns]
70 [SPD_tRCD] = 60, // Min. RAS to CAS delay [15 ns in units of 0.25 ns]
71 [SPD_tRAS] = 40, // Min. RAS pulse width = active to precharge delay [40 ns]
72 [SPD_BANK_DENSITY] = 0x40, // Density of each row on module [256 MB]
73 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
74 [SPD_tRFC] = 70 // SDRAM Device Minimum Auto Refresh to Active/Auto Refresh [70 ns]
75};
76
Christian Gmeinerc4e07bb2013-06-04 17:34:35 +020077int spd_read_byte(unsigned int device, unsigned int address)
Jens Rottmannc1373852010-09-07 17:33:17 +000078{
79 if (device != DIMM0)
80 return 0xFF; /* No DIMM1, don't even try. */
81
82#if CONFIG_DEBUG_SMBUS
Stefan Reinauer069f4762015-01-05 13:02:32 -080083 if (address >= sizeof(spdbytes) || spdbytes[address] == 0xFF)
84 printk(BIOS_ERR, "ERROR: spd_read_byte(DIMM0, 0x%02x) "
85 "returns 0xff\n", address);
Jens Rottmannc1373852010-09-07 17:33:17 +000086#endif
87
88 /* Fake SPD ROM value */
89 return (address < sizeof(spdbytes)) ? spdbytes[address] : 0xFF;
90}
91
92/* Send config data to System Management Controller via SMB. */
93static int smc_send_config(unsigned char config_data)
94{
95 if (smbus_check_stop_condition(SMBUS_IO_BASE))
96 return 1;
97 if (smbus_start_condition(SMBUS_IO_BASE))
98 return 2;
99 if (smbus_send_slave_address(SMBUS_IO_BASE, 0x50)) // SMC address
100 return 3;
101 if (smbus_send_command(SMBUS_IO_BASE, 0x28)) // set config data
102 return 4;
103 if (smbus_send_command(SMBUS_IO_BASE, 0x01)) // data length
104 return 5;
105 if (smbus_send_command(SMBUS_IO_BASE, config_data))
106 return 6;
107 smbus_stop_condition(SMBUS_IO_BASE);
108 return 0;
109}
110
Jens Rottmannc1373852010-09-07 17:33:17 +0000111#include "northbridge/amd/lx/pll_reset.c"
Jens Rottmannc1373852010-09-07 17:33:17 +0000112#include "lib/generic_sdram.c"
Kyösti Mälkki7916f4c2012-02-09 16:07:41 +0200113#include "cpu/amd/geode_lx/cpureginit.c"
114#include "cpu/amd/geode_lx/syspreinit.c"
115#include "cpu/amd/geode_lx/msrinit.c"
Jens Rottmannc1373852010-09-07 17:33:17 +0000116
117static const u16 sio_init_table[] = { // hi=data, lo=index
Jens Rottmannc1373852010-09-07 17:33:17 +0000118 0x072C, // VIN6 enabled, FAN4/5 disabled, VIN7,VIN3 internal
119 0x1423, // don't delay PoWeROK1/2
120 0x9072, // watchdog triggers PWROK, counts seconds
121#if !CONFIG_USE_WATCHDOG_ON_BOOT
122 0x0073, 0x0074, // disarm watchdog by changing 56 s timeout to 0
123#endif
124 0xBF25, 0x172A, 0xF326, // select GPIO function for most pins
125 0xFF27, 0xDF28, 0x2729, // (GP45=SUSB, GP23,22,16,15=SPI, GP13=PWROK1)
126 0x66B8, 0x0FB9, // enable pullups on SPI, RS485_EN, COM3_R/TX_EN
127 0x07C0, // enable Simple-I/O for GP12-10= RS485_EN2,1, LIVE_LED
128 0x03C1, // enable Simple-I/O for GP21-20= COM3_RX_EN,TX_EN
129 0xFFC2, // enable Simple-I/O for GP37-30
130 0x07C8, // config GP12-10 as output
131 0x03C9, // config GP21-20 as output
132 0x2DF5, // map Hw Monitor Thermal Output to GP55
133 0x08F8, // map GP LED Blinking 1 to GP10=LIVE_LED (deactivate Simple I/O to use)
134};
135
136/* Early mainboard specific GPIO setup. */
137static void mb_gpio_init(void)
138{
139 int i;
140
141 /* Init Super I/O WDT, GPIOs. Done early, WDT init may trigger reset! */
Jens Rottmannc1373852010-09-07 17:33:17 +0000142 for (i = 0; i < ARRAY_SIZE(sio_init_table); i++) {
Edward O'Callaghanf2920022014-04-27 00:41:50 +1000143 u16 reg = sio_init_table[i];
144 ite_reg_write(GPIO_DEV, (u8) reg, (reg >> 8));
Jens Rottmannc1373852010-09-07 17:33:17 +0000145 }
Jens Rottmannc1373852010-09-07 17:33:17 +0000146}
147
Aaron Durbina0a37272014-08-14 08:35:11 -0500148#include <cpu/intel/romstage.h>
Jens Rottmannc1373852010-09-07 17:33:17 +0000149void main(unsigned long bist)
150{
151 int err;
Jens Rottmannc1373852010-09-07 17:33:17 +0000152
153 static const struct mem_controller memctrl[] = {
Uwe Hermann6dc92f02010-11-21 11:36:03 +0000154 {.channel0 = {DIMM0, DIMM1}}
Jens Rottmannc1373852010-09-07 17:33:17 +0000155 };
156
157 SystemPreInit();
158 msr_init();
159
160 cs5536_early_setup();
161
162 /*
163 * Note: Must do this AFTER the early_setup! It is counting on some
164 * early MSR setup for CS5536.
165 */
Edward O'Callaghanf2920022014-04-27 00:41:50 +1000166 ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Jens Rottmannc1373852010-09-07 17:33:17 +0000167 mb_gpio_init();
Jens Rottmannc1373852010-09-07 17:33:17 +0000168 console_init();
169
170 /* Halt if there was a built in self test failure */
171 report_bist_failure(bist);
172
Patrick Georgi7dc28642012-07-13 19:06:22 +0200173 pll_reset();
Jens Rottmannc1373852010-09-07 17:33:17 +0000174
175 cpuRegInit(0, DIMM0, DIMM1, DRAM_TERMINATED);
176
177 /* bit1 = on-board IDE is slave, bit0 = Spread Spectrum */
178 if ((err = smc_send_config(SMC_CONFIG))) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800179 printk(BIOS_ERR, "ERROR %d sending config data to SMC\n", err);
Jens Rottmannc1373852010-09-07 17:33:17 +0000180 }
181
182 sdram_initialize(1, memctrl);
183
Jens Rottmannc1373852010-09-07 17:33:17 +0000184 /* Memory is setup. Return to cache_as_ram.inc and continue to boot. */
Jens Rottmannc1373852010-09-07 17:33:17 +0000185}