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/lxdef.h>
13 #include <cpu/x86/msr.h>
14 #include <cpu/x86/cache.h>
17 /* the structs in this file only set msr.lo. But ... that may not always be true */
24 /* Master Configuration Register for Bus Masters.*/
25 struct msrinit SB_MASTER_CONF_TABLE[] = {
26 {USB1_SB_GLD_MSR_CONF, {.hi=0,.lo=0x00008f000}}, /* NOTE: Must be 1st entry in table*/
27 {USB2_SB_GLD_MSR_CONF, {.hi=0,.lo=0x00008f000}},
28 {ATA_SB_GLD_MSR_CONF, {.hi=0,.lo=0x00048f000}},
29 {AC97_SB_GLD_MSR_CONF, {.hi=0,.lo=0x00008f000}},
30 {MDD_SB_GLD_MSR_CONF, {.hi=0,.lo=0x00000f000}},
31 /* GLPCI_SB_GLD_MSR_CONF, 0x0FFFFFFFF*/
32 /* GLCP_SB_GLD_MSR_CONF, 0x0FFFFFFFF*/
33 /* GLIU_SB_GLD_MSR_CONF, 0x0*/
37 /* 5535_A3 Clock Gating*/
38 struct msrinit CS5535_CLOCK_GATING_TABLE[] = {
39 { USB1_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
40 { USB2_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
41 { GLIU_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000004}},
42 { GLPCI_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
43 { GLCP_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000004}},
44 { MDD_SB_GLD_MSR_PM, {.hi=0,.lo=0x050554111}},
45 { ATA_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
46 { AC97_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
50 /* 5536 Clock Gating*/
51 struct msrinit CS5536_CLOCK_GATING_TABLE[] = {
53 { GLIU_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000004}},
54 { GLPCI_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
55 { GLCP_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000004}},
56 { MDD_SB_GLD_MSR_PM, {.hi=0,.lo=0x050554111}}, /* SMBus clock gating errata (PBZ 2226 & SiBZ 3977)*/
57 { ATA_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
58 { AC97_SB_GLD_MSR_PM, {.hi=0,.lo=0x000000005}},
64 unsigned long regdata;
68 struct acpiinit acpi_init_table[] = {
69 {ACPI_BASE+0x00, 0x01000000, 4},
70 {ACPI_BASE+0x08, 0, 4},
71 {ACPI_BASE+0x0C, 0, 4},
72 {ACPI_BASE+0x1C, 0, 4},
73 {ACPI_BASE+0x18, 0x0FFFFFFFF, 4},
74 {ACPI_BASE+0x00, 0x0000FFFF, 4},
76 {PM_SCLK, 0x000000E00, 4},
77 {PM_SED, 0x000004601, 4},
78 {PM_SIDD, 0x000008C02, 4},
79 {PM_WKD, 0x0000000A0, 4},
80 {PM_WKXD, 0x0000000A0, 4},
84 /* return 1 if we are a 5536-based system */
85 static int is_5536(void){
87 msr = rdmsr(GLIU_SB_GLD_MSR_CAP);
89 printk_debug("is_5536: msr.lo is 0x%x(==5 means 5536)\n", msr.lo&0xf);
90 return ((msr.lo&0xf) == 5);
92 /* ***************************************************************************/
96 /* * Program ACPI LBAR and initialize ACPI registers.*/
108 /* ***************************************************************************/
110 pmChipsetInit(void) {
111 unsigned long val = 0;
114 port = (PMLogic_BASE + 0x010);
115 val = 0x0E00 ; /* 1ms*/
119 /* Make sure bits[3:0]=0000b to clear the*/
121 port = (PMLogic_BASE + 0x034);
122 val = 0x0A0 ; /* 5ms*/
126 port = (PMLogic_BASE + 0x030);
130 port = (PMLogic_BASE + 0x014);
131 /* mov eax, 0x057642 ; 100ms, works*/
132 val = 0x04601 ; /* 5ms*/
136 port = (PMLogic_BASE + 0x020);
137 /* mov eax, 0x0AEC84 ; 200ms, works*/
138 val = 0x08C02 ; /* 10ms*/
141 /* GPIO24 OUT_AUX1 function is the external signal for 5535's vsb_working_aux*/
142 /* which is de-asserted when 5535 enters Standby(S3 or S5) state.*/
143 /* On Hawk, GPIO24 controls all voltage rails except Vmem and Vstandby. This means*/
144 /* GX2 will be fully de-powered if this control de-asserts in S3/S5.*/
146 /* GPIO24 is setup in preChipsetInit for two reasons*/
147 /* 1. GPIO24 at reset defaults to disabled, since this signal is vsb_work_aux on*/
148 /* Hawk it controls the FET's for all voltage rails except Vstanby & Vmem.*/
149 /* BIOS needs to enable GPIO24 as OUT_AUX1 & OUTPUT_EN early so it is driven*/
151 /* 2. Non-PM builds will require GPIO24 enabled for instant-off power button*/
154 /* GPIO11 OUT_AUX1 function is the external signal for 5535's slp_clk_n which is asserted*/
155 /* when 5535 enters Sleep(S1) state.*/
156 /* On Hawk, GPIO11 is connected to control input of external clock generator*/
157 /* for 14MHz, PCI, USB & LPC clocks.*/
158 /* Programming of GPIO11 will be done by VSA PM code. During VSA Init. BIOS writes*/
159 /* PM Core Virual Register indicating if S1 Clocks should be On or Off. This is based*/
160 /* on a Setup item. We do not want to leave GPIO11 enabled because of a Hawk board*/
161 /* problem. With GPIO11 enabled in S3, something is back-driving GPIO11 causing it to*/
162 /* float to 1.6-1.7V.*/
166 struct FLASH_DEVICE {
167 unsigned char fType; /* Flash type: NOR or NAND */
168 unsigned char fInterface; /* Flash interface: I/O or Memory */
169 unsigned long fMask; /* Flash size/mask */
172 struct FLASH_DEVICE FlashInitTable[] = {
173 { FLASH_TYPE_NAND, FLASH_IF_MEM, FLASH_MEM_4K }, /* CS0, or Flash Device 0 */
174 { FLASH_TYPE_NONE, 0, 0 }, /* CS1, or Flash Device 1 */
175 { FLASH_TYPE_NONE, 0, 0 }, /* CS2, or Flash Device 2 */
176 { FLASH_TYPE_NONE, 0, 0 }, /* CS3, or Flash Device 3 */
179 #define FlashInitTableLen (sizeof(FlashInitTable)/sizeof(FlashInitTable[0]))
181 uint32_t FlashPort[] = {
188 /***************************************************************************
192 * Flash LBARs need to be setup before VSA init so the PCI BARs have
193 * correct size info. Call this routine only if flash needs to be
194 * configured (don't call it if you want IDE).
200 **************************************************************************/
201 static void ChipsetFlashSetup(void)
207 printk_debug("ChipsetFlashSetup++\n");
208 for (i = 0; i < FlashInitTableLen; i++) {
209 if (FlashInitTable[i].fType != FLASH_TYPE_NONE) {
210 printk_debug("Enable CS%d\n", i);
211 /* we need to configure the memory/IO mask */
212 msr = rdmsr(FlashPort[i]);
213 msr.hi = 0; /* start with the "enabled" bit clear */
214 if (FlashInitTable[i].fType == FLASH_TYPE_NAND)
215 msr.hi |= 0x00000002;
217 msr.hi &= ~0x00000002;
218 if (FlashInitTable[i].fInterface == FLASH_IF_MEM)
219 msr.hi |= 0x00000004;
221 msr.hi &= ~0x00000004;
222 msr.hi |= FlashInitTable[i].fMask;
223 printk_debug("WRMSR(0x%08X, %08X_%08X)\n", FlashPort[i], msr.hi, msr.lo);
224 wrmsr(FlashPort[i], msr);
226 /* now write-enable the device */
227 msr = rdmsr(MDD_NORF_CNTRL);
229 printk_debug("WRMSR(0x%08X, %08X_%08X)\n", MDD_NORF_CNTRL, msr.hi, msr.lo);
230 wrmsr(MDD_NORF_CNTRL, msr);
232 /* update the number enabled */
237 /* enable the flash */
238 if (0 != numEnabled) {
239 msr = rdmsr(MDD_PIN_OPT);
240 msr.lo &= ~1; /* PIN_OPT_IDE */
241 printk_debug("WRMSR(0x%08X, %08X_%08X)\n", MDD_PIN_OPT, msr.hi, msr.lo);
242 wrmsr(MDD_PIN_OPT, msr);
244 printk_debug("ChipsetFlashSetup--\n");
250 /* ***************************************************************************/
252 /* * ChipsetGeodeLinkInit*/
253 /* * Handle chipset specific GeodeLink settings here. */
254 /* * Called from GeodeLink init code.*/
260 /* ***************************************************************************/
262 ChipsetGeodeLinkInit(void){
264 unsigned long msrnum;
265 unsigned long totalmem;
269 /* SWASIF for A1 DMA */
270 /* Set all memory to "just above systop" PCI so DMA will work*/
272 msrnum = MSR_SB_GLCP + 0x17;
274 if ((msr.lo&0xff) == 0x11)
277 totalmem = (sizeram() << 20) - 1;
279 totalmem = ~totalmem;
282 msr.hi = 0x20000000; /* Port 1 (PCI)*/
283 msrnum = MSR_SB_GLIU + 0x20; /* */;
288 chipsetinit (struct northbridge_amd_lx_config *nb){
292 unsigned long msrnum;
294 outb( P80_CHIPSET_INIT, 0x80);
295 ChipsetGeodeLinkInit();
297 /* we hope NEVER to be in linuxbios when S3 resumes
298 if (! IsS3Resume()) */
300 struct acpiinit *aci = acpi_init_table;
302 if (aci->iolen == 2) {
303 outw(aci->regdata, aci->ioreg);
306 outl(aci->regdata, aci->ioreg);
317 /* Setup USB. Need more details. #118.18*/
318 msrnum = MSR_SB_USB1 + 8;
322 msrnum = MSR_SB_USB2 + 8;
327 outl (GPIOL_2_SET, GPIOL_INPUT_ENABLE);
328 outl (GPIOL_2_SET, GPIOL_IN_AUX1_SELECT);
330 /* Allow IO read and writes during a ATA DMA operation.*/
331 /* This could be done in the HD rom but do it here for easier debugging.*/
333 msrnum = ATA_SB_GLD_MSR_ERR;
338 /* Enable Post Primary IDE.*/
339 msrnum = GLPCI_SB_CTRL;
341 msr.lo |= GLPCI_CRTL_PPIDE_SET;
345 /* Set up Master Configuration Register*/
346 /* If 5536, use same master config settings as 5535, except for OHCI MSRs*/
352 csi = &SB_MASTER_CONF_TABLE[i];
353 for(; csi->msrnum; csi++){
354 msr.lo = csi->msr.lo;
355 msr.hi = csi->msr.hi;
356 wrmsr(csi->msrnum, msr); // MSR - see table above
361 printk_err("%sDOING ChipsetFlashSetup()!!!!!!!!!!!!!!!!!!\n", nb->setupflash? " " : "NOT");
368 /* Set up Hardware Clock Gating*/
370 /* if (getnvram(TOKEN_SB_CLK_GATE) != TVALUE_DISABLE) */
373 csi = CS5536_CLOCK_GATING_TABLE;
375 csi = CS5535_CLOCK_GATING_TABLE;
377 for(; csi->msrnum; csi++){
378 msr.lo = csi->msr.lo;
379 msr.hi = csi->msr.hi;
380 wrmsr(csi->msrnum, msr); // MSR - see table above