2 * This file is part of the coreboot project.
4 * Copyright (C) 2007 Advanced Micro Devices, Inc.
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.
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.
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
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>
27 #include <pc80/isa-dma.h>
28 #include <pc80/mc146818rtc.h>
29 #include <cpu/x86/msr.h>
30 #include <cpu/amd/vr.h>
31 #include <cpu/amd/geode_post_code.h>
36 extern void setup_i8259(void);
43 /* Master Configuration Register for Bus Masters.*/
44 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}},
52 /* 5536 Clock Gating*/
53 struct msrinit CS5536_CLOCK_GATING_TABLE[] = {
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}},
69 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},
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 */
90 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 */
97 #define FlashInitTableLen (ARRAY_SIZE(FlashInitTable))
99 uint32_t FlashPort[] = {
106 /* ***************************************************************************/
110 /* * Program ACPI LBAR and initialize ACPI registers.*/
112 /* ***************************************************************************/
113 static void pmChipsetInit(void)
118 port = (PMS_IO_BASE + 0x010);
119 val = 0x0E00; /* 1ms */
123 /* Make sure bits[3:0]=0000b to clear the */
125 port = (PMS_IO_BASE + 0x034);
126 val = 0x0A0; /* 5ms */
130 port = (PMS_IO_BASE + 0x030);
134 port = (PMS_IO_BASE + 0x014);
135 val = 0x04601; /* 5ms, # of 3.57954MHz clock edges */
139 port = (PMS_IO_BASE + 0x020);
140 val = 0x08C02; /* 10ms, # of 3.57954MHz clock edges */
144 /***************************************************************************
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).
152 **************************************************************************/
153 static void ChipsetFlashSetup(void)
159 printk_debug("ChipsetFlashSetup: Start\n");
160 for (i = 0; i < FlashInitTableLen; i++) {
161 if (FlashInitTable[i].fType != FLASH_TYPE_NONE) {
162 printk_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;
169 msr.hi &= ~0x00000002;
170 if (FlashInitTable[i].fInterface == FLASH_IF_MEM)
171 msr.hi |= 0x00000004;
173 msr.hi &= ~0x00000004;
174 msr.hi |= FlashInitTable[i].fMask;
175 printk_debug("MSR(0x%08X, %08X_%08X)\n", FlashPort[i],
177 wrmsr(FlashPort[i], msr);
179 /* now write-enable the device */
180 msr = rdmsr(MDD_NORF_CNTRL);
182 printk_debug("MSR(0x%08X, %08X_%08X)\n", MDD_NORF_CNTRL,
184 wrmsr(MDD_NORF_CNTRL, msr);
186 /* update the number enabled */
191 printk_debug("ChipsetFlashSetup: Finish\n");
195 /* ***************************************************************************/
197 /* * enable_ide_nand_flash_header */
198 /* Run after VSA init to enable the flash PCI device header */
200 /* ***************************************************************************/
201 static void enable_ide_nand_flash_header()
203 /* Tell VSA to use FLASH PCI header. Not IDE header. */
204 outl(0x80007A40, 0xCF8);
205 outl(0xDEADBEEF, 0xCFC);
208 #define RTC_CENTURY 0x32
209 #define RTC_DOMA 0x3D
210 #define RTC_MONA 0x3E
212 static void lpc_init(struct southbridge_amd_cs5536_config *sb)
216 if (sb->lpc_serirq_enable) {
217 msr.lo = sb->lpc_serirq_enable;
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 */
224 wrmsr(MDD_LPC_SIRQ, msr);
228 /* Allow DMA from LPC */
229 msr = rdmsr(MDD_DMA_MAP);
231 wrmsr(MDD_DMA_MAP, msr);
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);
238 /* enable the RTC/CMOS day of month and month alarms */
239 msr = rdmsr(MDD_RTC_DOMA_IND);
241 wrmsr(MDD_RTC_DOMA_IND, msr);
243 msr = rdmsr(MDD_RTC_MONA_IND);
245 wrmsr(MDD_RTC_MONA_IND, msr);
252 static void uarts_init(struct southbridge_amd_cs5536_config *sb)
259 dev = dev_find_device(PCI_VENDOR_ID_AMD,
260 PCI_DEVICE_ID_AMD_CS5536_ISA, 0);
261 gpio_addr = pci_read_config32(dev, PCI_BASE_ADDRESS_1);
262 gpio_addr &= ~1; /* clear IO bit */
263 printk_debug("GPIO_ADDR: %08X\n", gpio_addr);
265 /* This could be extended to support IR modes */
268 if (sb->com1_enable) {
269 /* Set the address */
270 switch (sb->com1_address) {
287 msr = rdmsr(MDD_LEG_IO);
288 msr.lo |= addr << 16;
289 wrmsr(MDD_LEG_IO, msr);
292 msr = rdmsr(MDD_IRQM_YHIGH);
293 msr.lo |= sb->com1_irq << 24;
294 wrmsr(MDD_IRQM_YHIGH, msr);
296 /* GPIO8 - UART1_TX */
297 /* Set: Output Enable (0x4) */
298 outl(GPIOL_8_SET, gpio_addr + GPIOL_OUTPUT_ENABLE);
299 /* Set: OUTAUX1 Select (0x10) */
300 outl(GPIOL_8_SET, gpio_addr + GPIOL_OUT_AUX1_SELECT);
302 /* GPIO8 - UART1_RX */
303 /* Set: Input Enable (0x20) */
304 outl(GPIOL_9_SET, gpio_addr + GPIOL_INPUT_ENABLE);
305 /* Set: INAUX1 Select (0x34) */
306 outl(GPIOL_9_SET, gpio_addr + GPIOL_IN_AUX1_SELECT);
308 /* Set: GPIO 8 + 9 Pull Up (0x18) */
309 outl(GPIOL_8_SET | GPIOL_9_SET,
310 gpio_addr + GPIOL_PULLUP_ENABLE);
313 /* Bit 1 = device enable Bit 4 = allow access to the upper banks */
314 msr.lo = (1 << 4) | (1 << 1);
316 wrmsr(MDD_UART1_CONF, msr);
319 /* Reset and disable COM1 */
320 msr = rdmsr(MDD_UART1_CONF);
322 wrmsr(MDD_UART1_CONF, msr);
323 msr.lo = 0; // disabled
324 wrmsr(MDD_UART1_CONF, msr);
326 /* Disable the IRQ */
327 msr = rdmsr(MDD_LEG_IO);
328 msr.lo &= ~(0xF << 16);
329 wrmsr(MDD_LEG_IO, msr);
333 if (sb->com2_enable) {
334 switch (sb->com2_address) {
351 msr = rdmsr(MDD_LEG_IO);
352 msr.lo |= addr << 20;
353 wrmsr(MDD_LEG_IO, msr);
356 msr = rdmsr(MDD_IRQM_YHIGH);
357 msr.lo |= sb->com2_irq << 28;
358 wrmsr(MDD_IRQM_YHIGH, msr);
360 /* GPIO4 - UART2_RX */
361 /* Set: Output Enable (0x4) */
362 outl(GPIOL_4_SET, gpio_addr + GPIOL_OUTPUT_ENABLE);
363 /* Set: OUTAUX1 Select (0x10) */
364 outl(GPIOL_4_SET, gpio_addr + GPIOL_OUT_AUX1_SELECT);
366 /* GPIO3 - UART2_TX */
367 /* Set: Input Enable (0x20) */
368 outl(GPIOL_3_SET, gpio_addr + GPIOL_INPUT_ENABLE);
369 /* Set: INAUX1 Select (0x34) */
370 outl(GPIOL_3_SET, gpio_addr + GPIOL_IN_AUX1_SELECT);
372 /* Set: GPIO 3 and 4 Pull Up (0x18) */
373 outl(GPIOL_3_SET | GPIOL_4_SET,
374 gpio_addr + GPIOL_PULLUP_ENABLE);
377 /* Bit 1 = device enable Bit 4 = allow access to the upper banks */
378 msr.lo = (1 << 4) | (1 << 1);
380 wrmsr(MDD_UART2_CONF, msr);
383 /* Reset and disable COM2 */
384 msr = rdmsr(MDD_UART2_CONF);
386 wrmsr(MDD_UART2_CONF, msr);
387 msr.lo = 0; // disabled
388 wrmsr(MDD_UART2_CONF, msr);
390 /* Disable the IRQ */
391 msr = rdmsr(MDD_LEG_IO);
392 msr.lo &= ~(0xF << 20);
393 wrmsr(MDD_LEG_IO, msr);
397 #define HCCPARAMS 0x08
399 #define USB_HCCPW_SET (1 << 1)
401 #define APU_SET (1 << 15)
403 #define PMUX_HOST 0x02
404 #define PMUX_DEVICE 0x03
405 #define PUEN_SET (1 << 2)
406 #define UDCDEVCTL 0x404
407 #define UDC_SD_SET (1 << 10)
409 #define PADEN_SET (1 << 7)
411 static void enable_USB_port4(struct southbridge_amd_cs5536_config *sb)
417 dev = dev_find_device(PCI_VENDOR_ID_AMD,
418 PCI_DEVICE_ID_AMD_CS5536_EHCI, 0);
421 /* Serial Short Detect Enable */
422 msr = rdmsr(USB2_SB_GLD_MSR_CONF);
423 msr.hi |= USB2_UPPER_SSDEN_SET;
424 wrmsr(USB2_SB_GLD_MSR_CONF, msr);
426 /* write to clear diag register */
427 wrmsr(USB2_SB_GLD_MSR_DIAG, rdmsr(USB2_SB_GLD_MSR_DIAG));
429 bar = (uint8_t *) pci_read_config32(dev, PCI_BASE_ADDRESS_0);
431 /* Make HCCPARAMS writeable */
432 writel(readl(bar + IPREG04) | USB_HCCPW_SET, bar + IPREG04);
434 /* ; EECP=50h, IST=01h, ASPC=1 */
435 writel(0x00005012, bar + HCCPARAMS);
438 dev = dev_find_device(PCI_VENDOR_ID_AMD,
439 PCI_DEVICE_ID_AMD_CS5536_OTG, 0);
441 bar = (uint8_t *) pci_read_config32(dev, PCI_BASE_ADDRESS_0);
443 writel(readl(bar + UOCMUX) & PUEN_SET, bar + UOCMUX);
445 /* Host or Device? */
446 if (sb->enable_USBP4_device) {
447 writel(readl(bar + UOCMUX) | PMUX_DEVICE, bar + UOCMUX);
449 writel(readl(bar + UOCMUX) | PMUX_HOST, bar + UOCMUX);
452 /* Overcurrent configuration */
453 if (sb->enable_USBP4_overcurrent) {
454 writel(readl(bar + UOCCAP)
455 | sb->enable_USBP4_overcurrent, bar + UOCCAP);
459 /* PBz#6466: If the UOC(OTG) device, port 4, is configured as a device,
460 * then perform the following sequence:
462 * - set SD bit in DEVCTRL udc register
463 * - set PADEN (former OTGPADEN) bit in uoc register
464 * - set APU bit in uoc register */
465 if (sb->enable_USBP4_device) {
466 dev = dev_find_device(PCI_VENDOR_ID_AMD,
467 PCI_DEVICE_ID_AMD_CS5536_UDC, 0);
469 bar = (uint8_t *) pci_read_config32(dev,
471 writel(readl(bar + UDCDEVCTL) | UDC_SD_SET,
476 dev = dev_find_device(PCI_VENDOR_ID_AMD,
477 PCI_DEVICE_ID_AMD_CS5536_OTG, 0);
479 bar = (uint8_t *) pci_read_config32(dev,
481 writel(readl(bar + UOCCTL) | PADEN_SET, bar + UOCCTL);
482 writel(readl(bar + UOCCAP) | APU_SET, bar + UOCCAP);
486 /* Disable virtual PCI UDC and OTG headers */
487 dev = dev_find_device(PCI_VENDOR_ID_AMD,
488 PCI_DEVICE_ID_AMD_CS5536_UDC, 0);
490 pci_write_config32(dev, 0x7C, 0xDEADBEEF);
493 dev = dev_find_device(PCI_VENDOR_ID_AMD,
494 PCI_DEVICE_ID_AMD_CS5536_OTG, 0);
496 pci_write_config32(dev, 0x7C, 0xDEADBEEF);
500 /* ***************************************************************************/
503 /* Called from northbridge init (Pre-VSA). */
505 /* ***************************************************************************/
506 void chipsetinit(void)
511 struct southbridge_amd_cs5536_config *sb =
512 (struct southbridge_amd_cs5536_config *)dev->chip_info;
515 post_code(P80_CHIPSET_INIT);
517 /* we hope NEVER to be in coreboot when S3 resumes
518 if (! IsS3Resume()) */
520 struct acpiinit *aci = acpi_init_table;
521 for (; aci->ioreg; aci++) {
522 outl(aci->regdata, aci->ioreg);
530 outl(GPIOL_2_SET, GPIO_IO_BASE + GPIOL_INPUT_ENABLE);
531 outl(GPIOL_2_SET, GPIO_IO_BASE + GPIOL_IN_AUX1_SELECT);
533 /* Allow IO read and writes during a ATA DMA operation. */
534 /* This could be done in the HD rom but do it here for easier debugging. */
535 msrnum = ATA_SB_GLD_MSR_ERR;
540 /* Enable Post Primary IDE. */
541 msrnum = GLPCI_SB_CTRL;
543 msr.lo |= GLPCI_CRTL_PPIDE_SET;
546 csi = SB_MASTER_CONF_TABLE;
547 for (; csi->msrnum; csi++) {
548 msr.lo = csi->msr.lo;
549 msr.hi = csi->msr.hi;
550 wrmsr(csi->msrnum, msr); // MSR - see table above
553 /* Flash BAR size Setup */
554 printk_err("%sDoing ChipsetFlashSetup()\n",
555 sb->enable_ide_nand_flash == 1 ? "" : "Not ");
556 if (sb->enable_ide_nand_flash == 1)
560 /* Set up Hardware Clock Gating */
563 csi = CS5536_CLOCK_GATING_TABLE;
564 for (; csi->msrnum; csi++) {
565 msr.lo = csi->msr.lo;
566 msr.hi = csi->msr.hi;
567 wrmsr(csi->msrnum, msr); // MSR - see table above
572 static void southbridge_init(struct device *dev)
574 struct southbridge_amd_cs5536_config *sb =
575 (struct southbridge_amd_cs5536_config *)dev->chip_info;
578 * struct device *gpiodev;
579 * unsigned short gpiobase = MDD_GPIO;
582 printk_err("cs5536: %s\n", __func__);
587 if (sb->enable_gpio_int_route) {
588 vrWrite((VRC_MISCELLANEOUS << 8) + PCI_INT_AB,
589 (sb->enable_gpio_int_route & 0xFFFF));
590 vrWrite((VRC_MISCELLANEOUS << 8) + PCI_INT_CD,
591 (sb->enable_gpio_int_route >> 16));
594 printk_err("cs5536: %s: enable_ide_nand_flash is %d\n", __func__,
595 sb->enable_ide_nand_flash);
596 if (sb->enable_ide_nand_flash == 1) {
597 enable_ide_nand_flash_header();
600 enable_USB_port4(sb);
602 /* disable unwanted virtual PCI devices */
603 for (i = 0; (i < MAX_UNWANTED_VPCI) && (0 != sb->unwanted_vpci[i]); i++) {
604 printk_debug("Disabling VPCI device: 0x%08X\n",
605 sb->unwanted_vpci[i]);
606 outl(sb->unwanted_vpci[i] + 0x7C, 0xCF8);
607 outl(0xDEADBEEF, 0xCFC);
611 static void southbridge_enable(struct device *dev)
613 printk_err("cs5536: %s: dev is %p\n", __func__, dev);
617 static void cs5536_pci_dev_enable_resources(device_t dev)
619 printk_err("cs5536: %s()\n", __func__);
620 pci_dev_enable_resources(dev);
621 enable_childrens_resources(dev);
624 static struct device_operations southbridge_ops = {
625 .read_resources = pci_dev_read_resources,
626 .set_resources = pci_dev_set_resources,
627 .enable_resources = cs5536_pci_dev_enable_resources,
628 .init = southbridge_init,
629 // .enable = southbridge_enable,
630 .scan_bus = scan_static_bus,
633 static const struct pci_driver cs5536_pci_driver __pci_driver = {
634 .ops = &southbridge_ops,
635 .vendor = PCI_VENDOR_ID_AMD,
636 .device = PCI_DEVICE_ID_AMD_CS5536_ISA
639 struct chip_operations southbridge_amd_cs5536_ops = {
640 CHIP_NAME("AMD Geode CS5536 Southbridge")
641 /* This is only called when this device is listed in the
642 * static device tree.
644 .enable_dev = southbridge_enable,