blob: bf6dc9ffb7e09749852f50a7b89231c14bd71179 [file] [log] [blame]
Jens Rottmann36224b42010-09-10 21:51:34 +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 Rottmann36224b42010-09-10 21:51:34 +000016 */
17
18/* Based on romstage.c from the SpaceRunner-LX mainboard. */
19
20#include <stdlib.h>
21#include <stdint.h>
22#include <device/pci_def.h>
23#include <arch/io.h>
24#include <device/pnp_def.h>
Jens Rottmann36224b42010-09-10 21:51:34 +000025#include <console/console.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110026#include <cpu/x86/bist.h>
27#include <cpu/x86/msr.h>
Jens Rottmann36224b42010-09-10 21:51:34 +000028#include <cpu/amd/lxdef.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110029#include <southbridge/amd/cs5536/cs5536.h>
Patrick Georgi9bd9a902010-11-20 10:31:00 +000030#include <spd.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 Rottmann36224b42010-09-10 21:51:34 +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 Rottmann36224b42010-09-10 21:51:34 +000040/* Bit0 enables Spread Spectrum. */
41#define SMC_CONFIG 0x01
42
Christian Gmeinerc4e07bb2013-06-04 17:34:35 +020043int spd_read_byte(unsigned int device, unsigned int address)
Jens Rottmann36224b42010-09-10 21:51:34 +000044{
45 if (device != DIMM0)
46 return 0xFF; /* No DIMM1, don't even try. */
47
48 return smbus_read_byte(device, address);
49}
50
51#if !CONFIG_BOARD_OLD_REVISION
52/* Send config data to System Management Controller via SMB. */
53static int smc_send_config(unsigned char config_data)
54{
55 if (smbus_check_stop_condition(SMBUS_IO_BASE))
56 return 1;
57 if (smbus_start_condition(SMBUS_IO_BASE))
58 return 2;
59 if (smbus_send_slave_address(SMBUS_IO_BASE, 0x50)) // SMC address
60 return 3;
61 if (smbus_send_command(SMBUS_IO_BASE, 0x28)) // set config data
62 return 4;
63 if (smbus_send_command(SMBUS_IO_BASE, 0x01)) // data length
64 return 5;
65 if (smbus_send_command(SMBUS_IO_BASE, config_data))
66 return 6;
67 smbus_stop_condition(SMBUS_IO_BASE);
68 return 0;
69}
70#endif
71
Jens Rottmann36224b42010-09-10 21:51:34 +000072#include "northbridge/amd/lx/pll_reset.c"
Jens Rottmann36224b42010-09-10 21:51:34 +000073#include "lib/generic_sdram.c"
Kyösti Mälkki7916f4c2012-02-09 16:07:41 +020074#include "cpu/amd/geode_lx/cpureginit.c"
75#include "cpu/amd/geode_lx/syspreinit.c"
76#include "cpu/amd/geode_lx/msrinit.c"
Jens Rottmann36224b42010-09-10 21:51:34 +000077
78static const u16 sio_init_table[] = { // hi=data, lo=index
Jens Rottmann36224b42010-09-10 21:51:34 +000079 0x042C, // disable ATXPG; VIN6 enabled, FAN4/5 disabled, VIN7,VIN3 enabled
80 0x1423, // don't delay PoWeROK1/2
81 0x9072, // watchdog triggers PWROK, counts seconds
82#if !CONFIG_USE_WATCHDOG_ON_BOOT
83 0x0073, 0x0074, // disarm watchdog by changing 56 s timeout to 0
84#endif
85 0xBF25, 0x172A, 0xF326, // select GPIO function for most pins
86 0xBF27, 0xFF28, 0x2D29, // (GP36=FAN_CTL3 (PWM), GP23,22,16,15=SPI, GP13=PWROK1)
87 0x66B8, 0x0CB9, // enable pullups on SPI, RS485_EN
88 0x07C0, // enable Simple-I/O for GP12-10= RS485_EN2,1, WD_ACTIVE
89 0x06C8, // config GP12,11 as output, GP10 as input
90 0x2DF5, // map Hw Monitor Thermal Output to GP55
91#if CONFIG_BOARD_OLD_REVISION
92 0x1F2A, 0xC072, // switch GP13 to GPIO, WDT output from PWROK to KRST
93#endif
94};
95
96/* Early mainboard specific GPIO setup. */
97static void mb_gpio_init(void)
98{
99 int i;
100
101 /* Init Super I/O WDT, GPIOs. Done early, WDT init may trigger reset! */
Jens Rottmann36224b42010-09-10 21:51:34 +0000102 for (i = 0; i < ARRAY_SIZE(sio_init_table); i++) {
Edward O'Callaghanf2920022014-04-27 00:41:50 +1000103 u16 reg = sio_init_table[i];
104 ite_reg_write(GPIO_DEV, (u8) reg, (reg >> 8));
Jens Rottmann36224b42010-09-10 21:51:34 +0000105 }
Jens Rottmann36224b42010-09-10 21:51:34 +0000106}
107
Aaron Durbina0a37272014-08-14 08:35:11 -0500108#include <cpu/intel/romstage.h>
Jens Rottmann36224b42010-09-10 21:51:34 +0000109void main(unsigned long bist)
110{
Jens Rottmann36224b42010-09-10 21:51:34 +0000111
112 static const struct mem_controller memctrl[] = {
Uwe Hermann6dc92f02010-11-21 11:36:03 +0000113 {.channel0 = {DIMM0, DIMM1}}
Jens Rottmann36224b42010-09-10 21:51:34 +0000114 };
115
116 SystemPreInit();
117 msr_init();
118
119 cs5536_early_setup();
120
121 /*
122 * Note: Must do this AFTER the early_setup! It is counting on some
123 * early MSR setup for CS5536.
124 */
Edward O'Callaghanf2920022014-04-27 00:41:50 +1000125 ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Jens Rottmann36224b42010-09-10 21:51:34 +0000126 mb_gpio_init();
Jens Rottmann36224b42010-09-10 21:51:34 +0000127 console_init();
128
129 /* Halt if there was a built in self test failure */
130 report_bist_failure(bist);
131
Patrick Georgi7dc28642012-07-13 19:06:22 +0200132 pll_reset();
Jens Rottmann36224b42010-09-10 21:51:34 +0000133
134 cpuRegInit(0, DIMM0, DIMM1, DRAM_TERMINATED);
135
Peter Stuge51eafde2010-10-13 06:23:02 +0000136#if !CONFIG_BOARD_OLD_REVISION
Jens Rottmann36224b42010-09-10 21:51:34 +0000137 int err;
138 /* bit0 = Spread Spectrum */
139 if ((err = smc_send_config(SMC_CONFIG))) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800140 printk(BIOS_ERR, "ERROR %d sending config data to SMC\n", err);
Jens Rottmann36224b42010-09-10 21:51:34 +0000141 }
142#endif
143
144 sdram_initialize(1, memctrl);
145
Jens Rottmann36224b42010-09-10 21:51:34 +0000146 /* Memory is setup. Return to cache_as_ram.inc and continue to boot. */
Jens Rottmann36224b42010-09-10 21:51:34 +0000147}