1 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_ids.h>
11 #include "northbridge.h"
12 #include <cpu/amd/gx2def.h>
13 #include <cpu/x86/msr.h>
14 #include <cpu/x86/cache.h>
15 #include "../../../southbridge/amd/cs5536/cs5536.h"
17 extern int sizeram(void);
18 /* the structs in this file only set msr.lo. But ... that may not always be true */
25 /* Master Configuration Register for Bus Masters.*/
26 struct msrinit SB_MASTER_CONF_TABLE[] = {
27 {USB1_SB_GLD_MSR_CONF, {.hi=0,.lo=0x00008f000}}, /* NOTE: Must be 1st entry in table*/
28 {USB2_SB_GLD_MSR_CONF, {.hi=0,.lo=0x00008f000}},
29 {ATA_SB_GLD_MSR_CONF, {.hi=0,.lo=0x00048f000}},
30 {AC97_SB_GLD_MSR_CONF, {.hi=0,.lo=0x00008f000}},
31 {MDD_SB_GLD_MSR_CONF, {.hi=0,.lo=0x00000f000}},
32 /* GLPCI_SB_GLD_MSR_CONF, 0x0FFFFFFFF*/
33 /* GLCP_SB_GLD_MSR_CONF, 0x0FFFFFFFF*/
34 /* GLIU_SB_GLD_MSR_CONF, 0x0*/
38 /* 5535_A3 Clock Gating*/
39 struct msrinit CS5535_CLOCK_GATING_TABLE[] = {
40 { USB1_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
41 { USB2_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
42 { GLIU_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000004}},
43 { GLPCI_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
44 { GLCP_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000004}},
45 { MDD_SB_GLD_MSR_PM, {.hi=0,.lo=0x050554111}},
46 { ATA_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
47 { AC97_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
51 /* 5536 Clock Gating*/
52 struct msrinit CS5536_CLOCK_GATING_TABLE[] = {
54 { GLIU_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000004}},
55 { GLPCI_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
56 { GLCP_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000004}},
57 { MDD_SB_GLD_MSR_PM, {.hi=0,.lo=0x050554111}}, /* SMBus clock gating errata (PBZ 2226 & SiBZ 3977)*/
58 { ATA_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
59 { AC97_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
65 unsigned long regdata;
69 struct acpiinit acpi_init_table[] = {
70 {ACPI_BASE+0x00, 0x01000000, 4},
71 {ACPI_BASE+0x08, 0, 4},
72 {ACPI_BASE+0x0C, 0, 4},
73 {ACPI_BASE+0x1C, 0, 4},
74 {ACPI_BASE+0x18, 0x0FFFFFFFF, 4},
75 {ACPI_BASE+0x00, 0x0000FFFF, 4},
77 {PM_SCLK, 0x000000E00, 4},
78 {PM_SED, 0x000004601, 4},
79 {PM_SIDD, 0x000008C02, 4},
80 {PM_WKD, 0x0000000A0, 4},
81 {PM_WKXD, 0x0000000A0, 4},
85 /* return 1 if we are a 5536-based system */
86 static int is_5536(void){
88 msr = rdmsr(GLIU_SB_GLD_MSR_CAP);
90 printk(BIOS_DEBUG, "is_5536: msr.lo is 0x%x(==5 means 5536)\n", msr.lo&0xf);
91 return ((msr.lo&0xf) == 5);
93 /* ***************************************************************************/
97 /* * Program ACPI LBAR and initialize ACPI registers.*/
109 /* ***************************************************************************/
111 pmChipsetInit(void) {
112 unsigned long val = 0;
115 port = (PMLogic_BASE + 0x010);
116 val = 0x0E00 ; /* 1ms*/
120 /* Make sure bits[3:0]=0000b to clear the*/
122 port = (PMLogic_BASE + 0x034);
123 val = 0x0A0 ; /* 5ms*/
127 port = (PMLogic_BASE + 0x030);
131 port = (PMLogic_BASE + 0x014);
132 /* mov eax, 0x057642 ; 100ms, works*/
133 val = 0x04601 ; /* 5ms*/
137 port = (PMLogic_BASE + 0x020);
138 /* mov eax, 0x0AEC84 ; 200ms, works*/
139 val = 0x08C02 ; /* 10ms*/
142 /* GPIO24 OUT_AUX1 function is the external signal for 5535's vsb_working_aux*/
143 /* which is de-asserted when 5535 enters Standby(S3 or S5) state.*/
144 /* On Hawk, GPIO24 controls all voltage rails except Vmem and Vstandby. This means*/
145 /* GX2 will be fully de-powered if this control de-asserts in S3/S5.*/
147 /* GPIO24 is setup in preChipsetInit for two reasons*/
148 /* 1. GPIO24 at reset defaults to disabled, since this signal is vsb_work_aux on*/
149 /* Hawk it controls the FET's for all voltage rails except Vstanby & Vmem.*/
150 /* BIOS needs to enable GPIO24 as OUT_AUX1 & OUTPUT_EN early so it is driven*/
152 /* 2. Non-PM builds will require GPIO24 enabled for instant-off power button*/
155 /* GPIO11 OUT_AUX1 function is the external signal for 5535's slp_clk_n which is asserted*/
156 /* when 5535 enters Sleep(S1) state.*/
157 /* On Hawk, GPIO11 is connected to control input of external clock generator*/
158 /* for 14MHz, PCI, USB & LPC clocks.*/
159 /* Programming of GPIO11 will be done by VSA PM code. During VSA Init. BIOS writes*/
160 /* PM Core Virual Register indicating if S1 Clocks should be On or Off. This is based*/
161 /* on a Setup item. We do not want to leave GPIO11 enabled because of a Hawk board*/
162 /* problem. With GPIO11 enabled in S3, something is back-driving GPIO11 causing it to*/
163 /* float to 1.6-1.7V.*/
167 struct FLASH_DEVICE {
168 unsigned char fType; /* Flash type: NOR or NAND */
169 unsigned char fInterface; /* Flash interface: I/O or Memory */
170 unsigned long fMask; /* Flash size/mask */
173 struct FLASH_DEVICE FlashInitTable[] = {
174 { FLASH_TYPE_NAND, FLASH_IF_MEM, FLASH_MEM_4K }, /* CS0, or Flash Device 0 */
175 { FLASH_TYPE_NONE, 0, 0 }, /* CS1, or Flash Device 1 */
176 { FLASH_TYPE_NONE, 0, 0 }, /* CS2, or Flash Device 2 */
177 { FLASH_TYPE_NONE, 0, 0 }, /* CS3, or Flash Device 3 */
180 #define FlashInitTableLen (ARRAY_SIZE(FlashInitTable))
182 uint32_t FlashPort[] = {
189 /***************************************************************************
193 * Flash LBARs need to be setup before VSA init so the PCI BARs have
194 * correct size info. Call this routine only if flash needs to be
195 * configured (don't call it if you want IDE).
201 **************************************************************************/
202 static void ChipsetFlashSetup(void)
208 printk(BIOS_DEBUG, "ChipsetFlashSetup++\n");
209 for (i = 0; i < FlashInitTableLen; i++) {
210 if (FlashInitTable[i].fType != FLASH_TYPE_NONE) {
211 printk(BIOS_DEBUG, "Enable CS%d\n", i);
212 /* we need to configure the memory/IO mask */
213 msr = rdmsr(FlashPort[i]);
214 msr.hi = 0; /* start with the "enabled" bit clear */
215 if (FlashInitTable[i].fType == FLASH_TYPE_NAND)
216 msr.hi |= 0x00000002;
218 msr.hi &= ~0x00000002;
219 if (FlashInitTable[i].fInterface == FLASH_IF_MEM)
220 msr.hi |= 0x00000004;
222 msr.hi &= ~0x00000004;
223 msr.hi |= FlashInitTable[i].fMask;
224 printk(BIOS_DEBUG, "WRMSR(0x%08X, %08X_%08X)\n", FlashPort[i], msr.hi, msr.lo);
225 wrmsr(FlashPort[i], msr);
227 /* now write-enable the device */
228 msr = rdmsr(MDD_NORF_CNTRL);
230 printk(BIOS_DEBUG, "WRMSR(0x%08X, %08X_%08X)\n", MDD_NORF_CNTRL, msr.hi, msr.lo);
231 wrmsr(MDD_NORF_CNTRL, msr);
233 /* update the number enabled */
238 /* enable the flash */
239 if (0 != numEnabled) {
240 msr = rdmsr(MDD_PIN_OPT);
241 msr.lo &= ~1; /* PIN_OPT_IDE */
242 printk(BIOS_DEBUG, "WRMSR(0x%08X, %08X_%08X)\n", MDD_PIN_OPT, msr.hi, msr.lo);
243 wrmsr(MDD_PIN_OPT, msr);
245 printk(BIOS_DEBUG, "ChipsetFlashSetup--\n");
251 /* ***************************************************************************/
253 /* * ChipsetGeodeLinkInit*/
254 /* * Handle chipset specific GeodeLink settings here. */
255 /* * Called from GeodeLink init code.*/
261 /* ***************************************************************************/
263 ChipsetGeodeLinkInit(void){
265 unsigned long msrnum;
266 unsigned long totalmem;
270 /* SWASIF for A1 DMA */
271 /* Set all memory to "just above systop" PCI so DMA will work*/
273 msrnum = MSR_SB_GLCP + 0x17;
275 if ((msr.lo&0xff) == 0x11)
278 totalmem = sizeram() << 20 - 1;
280 totalmem = ~totalmem;
283 msr.hi = 0x20000000; /* Port 1 (PCI)*/
284 msrnum = MSR_SB_GLIU + 0x20; /* */;
289 chipsetinit (struct northbridge_amd_gx2_config *nb){
293 unsigned long msrnum;
295 outb( P80_CHIPSET_INIT, 0x80);
296 ChipsetGeodeLinkInit();
298 /* we hope NEVER to be in coreboot when S3 resumes
299 if (! IsS3Resume()) */
301 struct acpiinit *aci = acpi_init_table;
303 if (aci->iolen == 2) {
304 outw(aci->regdata, aci->ioreg);
307 outl(aci->regdata, aci->ioreg);
318 /* Setup USB. Need more details. #118.18*/
319 msrnum = MSR_SB_USB1 + 8;
323 msrnum = MSR_SB_USB2 + 8;
328 outl (GPIOL_2_SET, GPIOL_INPUT_ENABLE);
329 outl (GPIOL_2_SET, GPIOL_IN_AUX1_SELECT);
331 /* Allow IO read and writes during a ATA DMA operation.*/
332 /* This could be done in the HD rom but do it here for easier debugging.*/
334 msrnum = ATA_SB_GLD_MSR_ERR;
339 /* Enable Post Primary IDE.*/
340 msrnum = GLPCI_SB_CTRL;
342 msr.lo |= GLPCI_CRTL_PPIDE_SET;
346 /* Set up Master Configuration Register*/
347 /* If 5536, use same master config settings as 5535, except for OHCI MSRs*/
353 csi = &SB_MASTER_CONF_TABLE[i];
354 for(; csi->msrnum; csi++){
355 msr.lo = csi->msr.lo;
356 msr.hi = csi->msr.hi;
357 wrmsr(csi->msrnum, msr); // MSR - see table above
362 printk(BIOS_ERR, "%sDOING ChipsetFlashSetup()!!!!!!!!!!!!!!!!!!\n", nb->setupflash? " " : "NOT");
369 /* Set up Hardware Clock Gating*/
371 /* if (getnvram(TOKEN_SB_CLK_GATE) != TVALUE_DISABLE) */
374 csi = CS5536_CLOCK_GATING_TABLE;
376 csi = CS5535_CLOCK_GATING_TABLE;
378 for(; csi->msrnum; csi++){
379 msr.lo = csi->msr.lo;
380 msr.hi = csi->msr.hi;
381 wrmsr(csi->msrnum, msr); // MSR - see table above