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