We define IO_APIC_ADDR in <arch/ioapic.h>, let's use it.
[coreboot.git] / src / southbridge / amd / cs5536 / cs5536.c
1 /*
2  * This file is part of the coreboot project.
3  *
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
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #include <arch/io.h>
21 #include <arch/ioapic.h>
22 #include <device/device.h>
23 #include <device/pci.h>
24 #include <device/pci_ops.h>
25 #include <device/pci_ids.h>
26 #include <console/console.h>
27 #include <stdint.h>
28 #include <pc80/isa-dma.h>
29 #include <pc80/mc146818rtc.h>
30 #include <pc80/i8259.h>
31 #include <cpu/x86/msr.h>
32 #include <cpu/amd/vr.h>
33 #include <cpu/amd/geode_post_code.h>
34 #include <stdlib.h>
35 #include "chip.h"
36 #include "cs5536.h"
37
38 struct msrinit {
39         u32 msrnum;
40         msr_t msr;
41 };
42
43 /*      Master Configuration Register for Bus Masters.*/
44 static struct msrinit SB_MASTER_CONF_TABLE[] = {
45         {USB2_SB_GLD_MSR_CONF, {.hi = 0,.lo = 0x00008f000}},
46         {ATA_SB_GLD_MSR_CONF,  {.hi = 0,.lo = 0x00048f000}},
47         {AC97_SB_GLD_MSR_CONF, {.hi = 0,.lo = 0x00008f000}},
48         {MDD_SB_GLD_MSR_CONF,  {.hi = 0,.lo = 0x00000f000}},
49         {0, {0, 0}}
50 };
51
52 /*      5536 Clock Gating*/
53 static struct msrinit CS5536_CLOCK_GATING_TABLE[] = {
54         /* MSR            Setting*/
55         {GLIU_SB_GLD_MSR_PM,  {.hi = 0,.lo = 0x000000004}},
56         {GLPCI_SB_GLD_MSR_PM, {.hi = 0,.lo = 0x000000005}},
57         {GLCP_SB_GLD_MSR_PM,  {.hi = 0,.lo = 0x000000004}},
58         {MDD_SB_GLD_MSR_PM,   {.hi = 0,.lo = 0x050554111}},     /*  SMBus clock gating errata (PBZ 2226 & SiBZ 3977) */
59         {ATA_SB_GLD_MSR_PM,   {.hi = 0,.lo = 0x000000005}},
60         {AC97_SB_GLD_MSR_PM,  {.hi = 0,.lo = 0x000000005}},
61         {0, {0, 0}}
62 };
63
64 struct acpiinit {
65         u16 ioreg;
66         u32 regdata;
67 };
68
69 static struct acpiinit acpi_init_table[] = {
70         {ACPI_IO_BASE + 0x00, 0x01000000},
71         {ACPI_IO_BASE + 0x08, 0},
72         {ACPI_IO_BASE + 0x0C, 0},
73         {ACPI_IO_BASE + 0x1C, 0},
74         {ACPI_IO_BASE + 0x18, 0x0FFFFFFFF},
75         {ACPI_IO_BASE + 0x00, 0x0000FFFF},
76         {PMS_IO_BASE + PM_SCLK, 0x000000E00},
77         {PMS_IO_BASE + PM_SED, 0x000004601},
78         {PMS_IO_BASE + PM_SIDD, 0x000008C02},
79         {PMS_IO_BASE + PM_WKD, 0x0000000A0},
80         {PMS_IO_BASE + PM_WKXD, 0x0000000A0},
81         {0, 0}
82 };
83
84 struct FLASH_DEVICE {
85         unsigned char fType;    /* Flash type: NOR or NAND */
86         unsigned char fInterface;       /* Flash interface: I/O or Memory */
87         unsigned long fMask;    /* Flash size/mask */
88 };
89
90 static struct FLASH_DEVICE FlashInitTable[] = {
91         {FLASH_TYPE_NAND, FLASH_IF_MEM, FLASH_MEM_4K},  /* CS0, or Flash Device 0 */
92         {FLASH_TYPE_NONE, 0, 0},        /* CS1, or Flash Device 1 */
93         {FLASH_TYPE_NONE, 0, 0},        /* CS2, or Flash Device 2 */
94         {FLASH_TYPE_NONE, 0, 0},        /* CS3, or Flash Device 3 */
95 };
96
97 #define FlashInitTableLen (ARRAY_SIZE(FlashInitTable))
98
99 static u32 FlashPort[] = {
100         MDD_LBAR_FLSH0,
101         MDD_LBAR_FLSH1,
102         MDD_LBAR_FLSH2,
103         MDD_LBAR_FLSH3
104 };
105
106 /* ***************************************************************************/
107 /* **/
108 /* *    pmChipsetInit*/
109 /* **/
110 /* *    Program ACPI LBAR and initialize ACPI registers.*/
111 /* **/
112 /* ***************************************************************************/
113 static void pmChipsetInit(void)
114 {
115         u32 val = 0;
116         u16 port;
117
118         port = (PMS_IO_BASE + 0x010);
119         val = 0x0E00;           /*  1ms */
120         outl(val, port);
121
122         /*      PM_WKXD */
123         /*      Make sure bits[3:0]=0000b to clear the */
124         /*      saved Sx state */
125         port = (PMS_IO_BASE + 0x034);
126         val = 0x0A0;            /*  5ms */
127         outl(val, port);
128
129         /*      PM_WKD */
130         port = (PMS_IO_BASE + 0x030);
131         outl(val, port);
132
133         /*      PM_SED */
134         port = (PMS_IO_BASE + 0x014);
135         val = 0x04601;          /*  5ms, # of 3.57954MHz clock edges */
136         outl(val, port);
137
138         /*      PM_SIDD */
139         port = (PMS_IO_BASE + 0x020);
140         val = 0x08C02;          /*  10ms, # of 3.57954MHz clock edges */
141         outl(val, port);
142 }
143
144 /***************************************************************************
145  *
146  *      ChipsetFlashSetup
147  *
148  *      Flash LBARs need to be setup before VSA init so the PCI BARs have
149  *      correct size info.      Call this routine only if flash needs to be
150  *      configured (don't call it if you want IDE).
151  *
152  **************************************************************************/
153 static void ChipsetFlashSetup(void)
154 {
155         msr_t msr;
156         int i;
157         int numEnabled = 0;
158
159         printk(BIOS_DEBUG, "ChipsetFlashSetup: Start\n");
160         for (i = 0; i < FlashInitTableLen; i++) {
161                 if (FlashInitTable[i].fType != FLASH_TYPE_NONE) {
162                         printk(BIOS_DEBUG, "Enable CS%d\n", i);
163                         /* we need to configure the memory/IO mask */
164                         msr = rdmsr(FlashPort[i]);
165                         msr.hi = 0;     /* start with the "enabled" bit clear */
166                         if (FlashInitTable[i].fType == FLASH_TYPE_NAND)
167                                 msr.hi |= 0x00000002;
168                         else
169                                 msr.hi &= ~0x00000002;
170                         if (FlashInitTable[i].fInterface == FLASH_IF_MEM)
171                                 msr.hi |= 0x00000004;
172                         else
173                                 msr.hi &= ~0x00000004;
174                         msr.hi |= FlashInitTable[i].fMask;
175                         printk(BIOS_DEBUG, "MSR(0x%08X, %08X_%08X)\n", FlashPort[i],
176                                      msr.hi, msr.lo);
177                         wrmsr(FlashPort[i], msr);
178
179                         /* now write-enable the device */
180                         msr = rdmsr(MDD_NORF_CNTRL);
181                         msr.lo |= (1 << i);
182                         printk(BIOS_DEBUG, "MSR(0x%08X, %08X_%08X)\n", MDD_NORF_CNTRL,
183                                      msr.hi, msr.lo);
184                         wrmsr(MDD_NORF_CNTRL, msr);
185
186                         /* update the number enabled */
187                         numEnabled++;
188                 }
189         }
190
191         printk(BIOS_DEBUG, "ChipsetFlashSetup: Finish\n");
192
193 }
194
195 /* ***************************************************************************/
196 /* **/
197 /* *    enable_ide_nand_flash_header */
198 /*              Run after VSA init to enable the flash PCI device header */
199 /* **/
200 /* ***************************************************************************/
201 static void enable_ide_nand_flash_header(void)
202 {
203         /* Tell VSA to use FLASH PCI header. Not IDE header. */
204         outl(0x80007A40, 0xCF8);
205         outl(0xDEADBEEF, 0xCFC);
206 }
207
208 #define RTC_CENTURY 0x32
209 #define RTC_DOMA        0x3D
210 #define RTC_MONA        0x3E
211
212 static void lpc_init(struct southbridge_amd_cs5536_config *sb)
213 {
214         msr_t msr;
215
216         if (sb->lpc_serirq_enable) {
217                 msr.lo = sb->lpc_serirq_enable;
218                 msr.hi = 0;
219                 wrmsr(MDD_IRQM_LPC, msr);
220                 if (sb->lpc_serirq_polarity) {
221                         msr.lo = sb->lpc_serirq_polarity << 16;
222                         msr.lo |= (sb->lpc_serirq_mode << 6) | (1 << 7);        /* enable */
223                         msr.hi = 0;
224                         wrmsr(MDD_LPC_SIRQ, msr);
225                 }
226         }
227
228         /* Allow DMA from LPC */
229         msr = rdmsr(MDD_DMA_MAP);
230         msr.lo = 0x7777;
231         wrmsr(MDD_DMA_MAP, msr);
232
233         /* enable the RTC/CMOS century byte at address 32h */
234         msr = rdmsr(MDD_RTC_CENTURY_OFFSET);
235         msr.lo = RTC_CENTURY;
236         wrmsr(MDD_RTC_CENTURY_OFFSET, msr);
237
238         /* enable the RTC/CMOS day of month and month alarms */
239         msr = rdmsr(MDD_RTC_DOMA_IND);
240         msr.lo = RTC_DOMA;
241         wrmsr(MDD_RTC_DOMA_IND, msr);
242
243         msr = rdmsr(MDD_RTC_MONA_IND);
244         msr.lo = RTC_MONA;
245         wrmsr(MDD_RTC_MONA_IND, msr);
246
247         rtc_init(0);
248
249         isa_dma_init();
250 }
251
252
253 /**
254  * Depending on settings in the config struct, enable COM1 or COM2 or both.
255  *
256  * If the enable is NOT set, the UARTs are explicitly disabled, which is
257  * required if (e.g.) there is a Super I/O attached that does COM1 or COM2.
258  *
259  * @param sb Southbridge config structure.
260  */
261 static void uarts_init(struct southbridge_amd_cs5536_config *sb)
262 {
263         msr_t msr;
264         u16 addr = 0;
265         u32 gpio_addr;
266         device_t dev;
267
268         dev = dev_find_device(PCI_VENDOR_ID_AMD,
269                         PCI_DEVICE_ID_AMD_CS5536_ISA, 0);
270         gpio_addr = pci_read_config32(dev, PCI_BASE_ADDRESS_1);
271         gpio_addr &= ~1;        /* Clear I/O bit */
272         printk(BIOS_DEBUG, "GPIO_ADDR: %08X\n", gpio_addr);
273
274         /* This could be extended to support IR modes. */
275
276         /* COM1 */
277         if (sb->com1_enable) {
278                 printk(BIOS_SPEW, "uarts_init: enable COM1\n");
279                 /* Set the address. */
280                 switch (sb->com1_address) {
281                 case 0x3F8:
282                         addr = 7;
283                         break;
284                 case 0x3E8:
285                         addr = 6;
286                         break;
287                 case 0x2F8:
288                         addr = 5;
289                         break;
290                 case 0x2E8:
291                         addr = 4;
292                         break;
293                 }
294                 msr = rdmsr(MDD_LEG_IO);
295                 msr.lo |= addr << 16;
296                 wrmsr(MDD_LEG_IO, msr);
297
298                 /* Set the IRQ. */
299                 msr = rdmsr(MDD_IRQM_YHIGH);
300                 msr.lo |= sb->com1_irq << 24;
301                 wrmsr(MDD_IRQM_YHIGH, msr);
302
303                 /* GPIO8 - UART1_TX */
304                 /* Set: Output Enable (0x4) */
305                 outl(GPIOL_8_SET, gpio_addr + GPIOL_OUTPUT_ENABLE);
306                 /* Set: OUTAUX1 Select (0x10) */
307                 outl(GPIOL_8_SET, gpio_addr + GPIOL_OUT_AUX1_SELECT);
308
309                 /* GPIO9 - UART1_RX */
310                 /* Set: Input Enable   (0x20) */
311                 outl(GPIOL_9_SET, gpio_addr + GPIOL_INPUT_ENABLE);
312                 /* Set: INAUX1 Select (0x34) */
313                 outl(GPIOL_9_SET, gpio_addr + GPIOL_IN_AUX1_SELECT);
314
315                 /* Set: GPIO 8 + 9 Pull Up (0x18) */
316                 outl(GPIOL_8_SET | GPIOL_9_SET,
317                      gpio_addr + GPIOL_PULLUP_ENABLE);
318
319                 /* Enable COM1.
320                  *
321                  * Bit 1 = device enable
322                  * Bit 4 = allow access to the upper banks
323                  */
324                 msr.lo = (1 << 4) | (1 << 1);
325                 msr.hi = 0;
326                 wrmsr(MDD_UART1_CONF, msr);
327         } else {
328                 /* Reset and disable COM1. */
329                 printk(BIOS_SPEW, "uarts_init: disable COM1\n");
330                 msr = rdmsr(MDD_UART1_CONF);
331                 msr.lo = 1;                     /* Reset */
332                 wrmsr(MDD_UART1_CONF, msr);
333                 msr.lo = 0;                     /* Disabled */
334                 wrmsr(MDD_UART1_CONF, msr);
335
336                 /* Disable the IRQ. */
337                 msr = rdmsr(MDD_LEG_IO);
338                 msr.lo &= ~(0xF << 16);
339                 wrmsr(MDD_LEG_IO, msr);
340         }
341
342         /* COM2 */
343         if (sb->com2_enable) {
344                 printk(BIOS_SPEW, "uarts_init: enable COM2\n");
345                 switch (sb->com2_address) {
346                 case 0x3F8:
347                         addr = 7;
348                         break;
349                 case 0x3E8:
350                         addr = 6;
351                         break;
352                 case 0x2F8:
353                         addr = 5;
354                         break;
355                 case 0x2E8:
356                         addr = 4;
357                         break;
358                 }
359                 msr = rdmsr(MDD_LEG_IO);
360                 msr.lo |= addr << 20;
361                 wrmsr(MDD_LEG_IO, msr);
362                 printk(BIOS_SPEW, "uarts_init: wrote COM2 address 0x%x\n", sb->com2_address);
363
364                 /* Set the IRQ. */
365                 msr = rdmsr(MDD_IRQM_YHIGH);
366                 msr.lo |= sb->com2_irq << 28;
367                 wrmsr(MDD_IRQM_YHIGH, msr);
368                 printk(BIOS_SPEW, "uarts_init: set COM2 irq\n");
369
370                 /* GPIO3 - UART2_RX */
371                 /* Set: Input Enable (0x20) */
372                 outl(GPIOL_3_SET, gpio_addr + GPIOL_INPUT_ENABLE);
373                 /* Set: INAUX1 Select (0x34) */
374                 outl(GPIOL_3_SET, gpio_addr + GPIOL_IN_AUX1_SELECT);
375
376                 /* GPIO4 - UART2_TX */
377                 /* Set: Output Enable (0x4) */
378                 outl(GPIOL_4_SET, gpio_addr + GPIOL_OUTPUT_ENABLE);
379                 printk(BIOS_SPEW, "uarts_init: set output enable\n");
380                 /* Set: OUTAUX1 Select (0x10) */
381                 outl(GPIOL_4_SET, gpio_addr + GPIOL_OUT_AUX1_SELECT);
382                 printk(BIOS_SPEW, "uarts_init: set OUTAUX1\n");
383
384                 /* Set: GPIO 3 + 4 Pull Up (0x18) */
385                 outl(GPIOL_3_SET | GPIOL_4_SET,
386                      gpio_addr + GPIOL_PULLUP_ENABLE);
387                 printk(BIOS_SPEW, "uarts_init: set pullup COM2\n");
388
389                 /* Enable COM2.
390                  *
391                  * Bit 1 = device enable
392                  * Bit 4 = allow access to the upper banks
393                  */
394                 msr.lo = (1 << 4) | (1 << 1);
395                 msr.hi = 0;
396                 wrmsr(MDD_UART2_CONF, msr);
397                 printk(BIOS_SPEW, "uarts_init: COM2 enabled\n");
398         } else {
399                 printk(BIOS_SPEW, "uarts_init: disable COM2\n");
400                 /* Reset and disable COM2. */
401                 msr = rdmsr(MDD_UART2_CONF);
402                 msr.lo = 1;                     /* Reset */
403                 wrmsr(MDD_UART2_CONF, msr);
404                 msr.lo = 0;                     /* Disabled */
405                 wrmsr(MDD_UART2_CONF, msr);
406
407                 /* Disable the IRQ. */
408                 msr = rdmsr(MDD_LEG_IO);
409                 msr.lo &= ~(0xF << 20);
410                 wrmsr(MDD_LEG_IO, msr);
411         }
412 }
413
414
415 #define HCCPARAMS               0x08
416 #define IPREG04                 0xA0
417         #define USB_HCCPW_SET   (1 << 1)
418 #define UOCCAP                  0x00
419         #define APU_SET                 (1 << 15)
420 #define UOCMUX                  0x04
421 #define PMUX_HOST               0x02
422 #define PMUX_DEVICE             0x03
423         #define PUEN_SET                (1 << 2)
424 #define UDCDEVCTL               0x404
425         #define UDC_SD_SET              (1 << 10)
426 #define UOCCTL                  0x0C
427         #define PADEN_SET               (1 << 7)
428
429 static void enable_USB_port4(struct southbridge_amd_cs5536_config *sb)
430 {
431         u32 bar;
432         msr_t msr;
433         device_t dev;
434
435         dev = dev_find_device(PCI_VENDOR_ID_AMD,
436                         PCI_DEVICE_ID_AMD_CS5536_EHCI, 0);
437         if (dev) {
438
439                 /* Serial Short Detect Enable */
440                 msr = rdmsr(USB2_SB_GLD_MSR_CONF);
441                 msr.hi |= USB2_UPPER_SSDEN_SET;
442                 wrmsr(USB2_SB_GLD_MSR_CONF, msr);
443
444                 /* write to clear diag register */
445                 wrmsr(USB2_SB_GLD_MSR_DIAG, rdmsr(USB2_SB_GLD_MSR_DIAG));
446
447                 bar = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
448
449                 /* Make HCCPARAMS writeable */
450                 write32(bar + IPREG04, read32(bar + IPREG04) | USB_HCCPW_SET);
451
452                 /* ; EECP=50h, IST=01h, ASPC=1 */
453                 write32(bar + HCCPARAMS, 0x00005012);
454         }
455
456         dev = dev_find_device(PCI_VENDOR_ID_AMD,
457                         PCI_DEVICE_ID_AMD_CS5536_OTG, 0);
458         if (dev) {
459                 bar = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
460
461                 write32(bar + UOCMUX, read32(bar + UOCMUX) & PUEN_SET);
462
463                 /* Host or Device? */
464                 if (sb->enable_USBP4_device) {
465                         write32(bar + UOCMUX, read32(bar + UOCMUX) | PMUX_DEVICE);
466                 } else {
467                         write32(bar + UOCMUX, read32(bar + UOCMUX) | PMUX_HOST);
468                 }
469
470                 /* Overcurrent configuration */
471                 if (sb->enable_USBP4_overcurrent) {
472                         write32(bar + UOCCAP, read32(bar + UOCCAP)
473                                | sb->enable_USBP4_overcurrent);
474                 }
475         }
476
477         /* PBz#6466: If the UOC(OTG) device, port 4, is configured as a device,
478          *      then perform the following sequence:
479          *
480          * - set SD bit in DEVCTRL udc register
481          * - set PADEN (former OTGPADEN) bit in uoc register
482          * - set APU bit in uoc register */
483         if (sb->enable_USBP4_device) {
484                 dev = dev_find_device(PCI_VENDOR_ID_AMD,
485                                 PCI_DEVICE_ID_AMD_CS5536_UDC, 0);
486                 if (dev) {
487                         bar = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
488                         write32(bar + UDCDEVCTL,
489                                read32(bar + UDCDEVCTL) | UDC_SD_SET);
490
491                 }
492
493                 dev = dev_find_device(PCI_VENDOR_ID_AMD,
494                                 PCI_DEVICE_ID_AMD_CS5536_OTG, 0);
495                 if (dev) {
496                         bar = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
497                         write32(bar + UOCCTL, read32(bar + UOCCTL) | PADEN_SET);
498                         write32(bar + UOCCAP, read32(bar + UOCCAP) | APU_SET);
499                 }
500         }
501
502         /* Disable virtual PCI UDC and OTG headers */
503         dev = dev_find_device(PCI_VENDOR_ID_AMD,
504                         PCI_DEVICE_ID_AMD_CS5536_UDC, 0);
505         if (dev) {
506                 pci_write_config32(dev, 0x7C, 0xDEADBEEF);
507         }
508
509         dev = dev_find_device(PCI_VENDOR_ID_AMD,
510                         PCI_DEVICE_ID_AMD_CS5536_OTG, 0);
511         if (dev) {
512                 pci_write_config32(dev, 0x7C, 0xDEADBEEF);
513         }
514 }
515
516 /****************************************************************************
517  *
518  *      ChipsetInit
519  *
520  *      Called from northbridge init (Pre-VSA).
521  *
522  ****************************************************************************/
523 void chipsetinit(void)
524 {
525         device_t dev;
526         msr_t msr;
527         u32 msrnum;
528         struct southbridge_amd_cs5536_config *sb;
529         struct msrinit *csi;
530
531         dev = dev_find_slot(0, PCI_DEVFN(0xf, 0));
532
533         if (!dev) {
534                 printk(BIOS_ERR, "CS5536 not found.\n");
535                 return;
536         }
537
538         sb = (struct southbridge_amd_cs5536_config *)dev->chip_info;
539
540         if (!sb) {
541                 printk(BIOS_ERR, "CS5536 configuration not found.\n");
542                 return;
543         }
544
545         post_code(P80_CHIPSET_INIT);
546
547         /* we hope NEVER to be in coreboot when S3 resumes
548            if (! IsS3Resume()) */
549         {
550                 struct acpiinit *aci = acpi_init_table;
551                 for (; aci->ioreg; aci++) {
552                         outl(aci->regdata, aci->ioreg);
553                         inl(aci->ioreg);
554                 }
555
556                 pmChipsetInit();
557         }
558
559         /* set hd IRQ */
560         outl(GPIOL_2_SET, GPIO_IO_BASE + GPIOL_INPUT_ENABLE);
561         outl(GPIOL_2_SET, GPIO_IO_BASE + GPIOL_IN_AUX1_SELECT);
562
563         /*      Allow IO read and writes during a ATA DMA operation. */
564         /*       This could be done in the HD rom but do it here for easier debugging. */
565         msrnum = ATA_SB_GLD_MSR_ERR;
566         msr = rdmsr(msrnum);
567         msr.lo &= ~0x100;
568         wrmsr(msrnum, msr);
569
570         /*      Enable Post Primary IDE. */
571         msrnum = GLPCI_SB_CTRL;
572         msr = rdmsr(msrnum);
573         msr.lo |= GLPCI_CRTL_PPIDE_SET;
574         wrmsr(msrnum, msr);
575
576         csi = SB_MASTER_CONF_TABLE;
577         for (; csi->msrnum; csi++) {
578                 msr.lo = csi->msr.lo;
579                 msr.hi = csi->msr.hi;
580                 wrmsr(csi->msrnum, msr);        // MSR - see table above
581         }
582
583         /*      Flash BAR size Setup */
584         printk(BIOS_ERR, "%sDoing ChipsetFlashSetup()\n",
585                    sb->enable_ide_nand_flash == 1 ? "" : "Not ");
586         if (sb->enable_ide_nand_flash == 1)
587                 ChipsetFlashSetup();
588
589         /* */
590         /*      Set up Hardware Clock Gating */
591         /* */
592         {
593                 csi = CS5536_CLOCK_GATING_TABLE;
594                 for (; csi->msrnum; csi++) {
595                         msr.lo = csi->msr.lo;
596                         msr.hi = csi->msr.hi;
597                         wrmsr(csi->msrnum, msr);        // MSR - see table above
598                 }
599         }
600 }
601
602 static void southbridge_init(struct device *dev)
603 {
604         struct southbridge_amd_cs5536_config *sb =
605             (struct southbridge_amd_cs5536_config *)dev->chip_info;
606         int i;
607         /*
608          * struct device *gpiodev;
609          * unsigned short gpiobase = MDD_GPIO;
610          */
611
612         printk(BIOS_ERR, "cs5536: %s\n", __func__);
613
614         if (!sb) {
615                 printk(BIOS_ERR, "CS5536 configuration not found.\n");
616                 return;
617         }
618
619         setup_i8259();
620         lpc_init(sb);
621         uarts_init(sb);
622
623         if (sb->enable_gpio_int_route) {
624                 vrWrite((VRC_MISCELLANEOUS << 8) + PCI_INT_AB,
625                         (sb->enable_gpio_int_route & 0xFFFF));
626                 vrWrite((VRC_MISCELLANEOUS << 8) + PCI_INT_CD,
627                         (sb->enable_gpio_int_route >> 16));
628         }
629
630         printk(BIOS_ERR, "cs5536: %s: enable_ide_nand_flash is %d\n", __func__,
631                    sb->enable_ide_nand_flash);
632         if (sb->enable_ide_nand_flash == 1) {
633                 enable_ide_nand_flash_header();
634         }
635
636         enable_USB_port4(sb);
637
638         /* disable unwanted virtual PCI devices */
639         for (i = 0; (i < MAX_UNWANTED_VPCI) && (0 != sb->unwanted_vpci[i]); i++) {
640                 printk(BIOS_DEBUG, "Disabling VPCI device: 0x%08X\n",
641                              sb->unwanted_vpci[i]);
642                 outl(sb->unwanted_vpci[i] + 0x7C, 0xCF8);
643                 outl(0xDEADBEEF, 0xCFC);
644         }
645 }
646
647 static void cs5536_read_resources(device_t dev)
648 {
649         struct resource *res;
650
651         pci_dev_read_resources(dev);
652
653         res = new_resource(dev, 1);
654         res->base = 0x0UL;
655         res->size = 0x1000UL;
656         res->limit = 0xffffUL;
657         res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
658
659         res = new_resource(dev, 3); /* IOAPIC */
660         res->base = IO_APIC_ADDR;
661         res->size = 0x00001000;
662         res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
663 }
664
665 static void southbridge_enable(struct device *dev)
666 {
667         printk(BIOS_ERR, "cs5536: %s: dev is %p\n", __func__, dev);
668
669 }
670
671 static struct device_operations southbridge_ops = {
672         .read_resources = cs5536_read_resources,
673         .set_resources = pci_dev_set_resources,
674         .enable_resources = pci_dev_enable_resources,
675         .init = southbridge_init,
676 //      .enable                   = southbridge_enable,
677         .scan_bus = scan_static_bus,
678 };
679
680 static const struct pci_driver cs5536_pci_driver __pci_driver = {
681         .ops = &southbridge_ops,
682         .vendor = PCI_VENDOR_ID_AMD,
683         .device = PCI_DEVICE_ID_AMD_CS5536_ISA
684 };
685
686 struct chip_operations southbridge_amd_cs5536_ops = {
687         CHIP_NAME("AMD Geode CS5536 Southbridge")
688             /* This is only called when this device is listed in the
689              * static device tree.
690              */
691             .enable_dev = southbridge_enable,
692 };