coreboot-v3/southbridge/amd/cs5536/cs5536.c
<<
>>
Prefs
   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 <types.h>
  21#include <lib.h>
  22#include <console.h>
  23#include <device/pci.h>
  24#include <msr.h>
  25#include <amd_geodelx.h>
  26#include <legacy.h>
  27#include <device/pci_ids.h>
  28#include <statictree.h>
  29#include "cs5536.h"
  30
  31/* Master configuration register for bus masters */
  32static const struct msrinit SB_MASTER_CONF_TABLE[] = {
  33        {USB2_SB_GLD_MSR_CONF, {.hi = 0,.lo = 0x00008f000}},
  34        {ATA_SB_GLD_MSR_CONF,  {.hi = 0,.lo = 0x00048f000}},
  35        {AC97_SB_GLD_MSR_CONF, {.hi = 0,.lo = 0x00008f000}},
  36        {MDD_SB_GLD_MSR_CONF,  {.hi = 0,.lo = 0x00000f000}},
  37        {0, {0, 0}}
  38};
  39
  40/* CS5536 clock gating */
  41static const struct msrinit CS5536_CLOCK_GATING_TABLE[] = {
  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}},     /* SMBus clock gating errata (PBZ 2226 & SiBZ 3977) */
  46        {ATA_SB_GLD_MSR_PM,   {.hi = 0,.lo = 0x000000005}},
  47        {AC97_SB_GLD_MSR_PM,  {.hi = 0,.lo = 0x000000005}},
  48        {0, {0, 0}}
  49};
  50
  51struct acpi_init {
  52        u16 ioreg;
  53        u32 regdata;
  54};
  55
  56static const struct acpi_init acpi_init_table[] = {
  57        {ACPI_IO_BASE + 0x00,   0x01000000},
  58        {ACPI_IO_BASE + 0x08,   0x00000000},
  59        {ACPI_IO_BASE + 0x0C,   0x00000000},
  60        {ACPI_IO_BASE + 0x1C,   0x00000000},
  61        {ACPI_IO_BASE + 0x18,   0xFFFFFFFF},
  62        {ACPI_IO_BASE + 0x00,   0x0000FFFF},
  63        {PMS_IO_BASE + PM_SCLK, 0x00000E00},
  64        {PMS_IO_BASE + PM_SED,  0x00004601},
  65        {PMS_IO_BASE + PM_SIDD, 0x00008C02},
  66        {PMS_IO_BASE + PM_WKD,  0x000000A0},
  67        {PMS_IO_BASE + PM_WKXD, 0x000000A0},
  68        {0, 0}
  69};
  70
  71static const u32 FlashPort[] = {
  72        MDD_LBAR_FLSH0,
  73        MDD_LBAR_FLSH1,
  74        MDD_LBAR_FLSH2,
  75        MDD_LBAR_FLSH3
  76};
  77
  78/**
  79 * Hide unwanted virtual PCI device.
  80 *
  81 * @param vpci_devid The bus location of the device to be hidden.
  82 * bits  0 ->  1 zero
  83 * bits  2 ->  7 target dword within the target function 
  84 *               (zero if we're disabling entire pci devices)
  85 * bits  8 -> 10 target function of the device
  86 * bits 11 -> 15 target pci device
  87 * bits 16 -> 23 pci bus
  88 * bits 24 -> 30 reserved and set to zero
  89 * bit  31       triggers the config cycle
  90 */
  91void hide_vpci(u32 vpci_devid)
  92{
  93        printk(BIOS_DEBUG, "Hiding VPCI device: 0x%08X (%02x:%02x.%01x)\n",
  94                vpci_devid, (vpci_devid >> 16) & 0xff,
  95                (vpci_devid >> 11) & 0x1f, (vpci_devid >> 8) & 0x7);
  96        outl(vpci_devid + 0x7C, 0xCF8);
  97        outl(0xDEADBEEF, 0xCFC);
  98}
  99
 100/**
 101 * Power button setup.
 102 *
 103 * Setup GPIO24, it is the external signal for CS5536 vsb_work_aux which
 104 * controls all voltage rails except Vstandby & Vmem. We need to enable
 105 * OUT_AUX1 and OUTPUT_ENABLE in this order.
 106 *
 107 * @param sb The southbridge config structure. 
 108 * If GPIO24 is not enabled then soft-off will not work.
 109 */
 110static void cs5536_setup_power_button(struct southbridge_amd_cs5536_dts_config *sb )
 111{
 112        if (!sb->power_button)
 113                return;
 114        /* TODO: Should be a #define? */
 115        outl(0x40020000, PMS_IO_BASE + 0x40);
 116        outl(GPIOH_24_SET, GPIO_IO_BASE + GPIOH_OUT_AUX1_SELECT);
 117        outl(GPIOH_24_SET, GPIO_IO_BASE + GPIOH_OUTPUT_ENABLE);
 118}
 119
 120/**
 121 * Program ACPI LBAR and initialize ACPI registers.
 122 */
 123static void pm_chipset_init(void)
 124{
 125        outl(0x0E00, PMS_IO_BASE + 0x010);      /* 1ms */
 126
 127        /* Make sure bits[3:0]=0000b to clear the saved Sx state. */
 128        outl(0x00A0, PMS_IO_BASE + PM_WKXD);    /* 5ms */
 129
 130        outl(0x00A0, PMS_IO_BASE + PM_WKD);
 131
 132        /* 5ms, # of 3.57954MHz clock edges */
 133        outl(0x4601, PMS_IO_BASE + PM_SED);
 134
 135        /* 10ms, # of 3.57954MHz clock edges */
 136        outl(0x8C02, PMS_IO_BASE + PM_SIDD);
 137}
 138
 139/**
 140 * Flash LBARs need to be setup before VSA init so the PCI BARs have
 141 * correct size info. Call this routine only if flash needs to be
 142 * configured (don't call it if you want IDE).
 143 */
 144static void chipset_flash_setup(struct southbridge_amd_cs5536_dts_config *sb)
 145{
 146        int i;
 147        struct msr msr;
 148
 149        printk(BIOS_DEBUG, "chipset_flash_setup: Start\n");
 150        if (sb->enable_ide_nand_flash <= 4) {
 151                i = sb->enable_ide_nand_flash - 1;
 152                printk(BIOS_DEBUG, "Enable CS%d\n", i);
 153                /* We need to configure the memory/IO mask. */
 154                msr = rdmsr(FlashPort[i]);
 155                msr.hi = 0;     /* Start with "enabled" bit clear. */
 156                msr.hi |= 0x00000002; /* For FLASH_TYPE_NAND */
 157                msr.hi |= 0x00000004; /* For FLASH_IF_MEM */
 158                msr.hi |= FLASH_MEM_4K;
 159                printk(BIOS_DEBUG, "MSR(0x%08X, %08X_%08X)\n",
 160                       FlashPort[i], msr.hi, msr.lo);
 161                wrmsr(FlashPort[i], msr);
 162
 163                /* Now write-enable the device. */
 164                msr = rdmsr(MDD_NORF_CNTRL);
 165                msr.lo |= (1 << i);
 166                printk(BIOS_DEBUG, "MSR(0x%08X, %08X_%08X)\n",
 167                       MDD_NORF_CNTRL, msr.hi, msr.lo);
 168                wrmsr(MDD_NORF_CNTRL, msr);
 169        }
 170        printk(BIOS_DEBUG, "chipset_flash_setup: Finish\n");
 171}
 172
 173#define RTC_CENTURY     0x32
 174#define RTC_DOMA        0x3D
 175#define RTC_MONA        0x3E
 176
 177/**
 178 * Standard init function for the LPC bus.
 179 *
 180 * Sets up the "serial irq" interrupt, which is NOT the same as serial
 181 * interrupt, and also enables DMA from the LPC bus. Configures the PC clock,
 182 * enables RTC and ISA DMA.
 183 *
 184 * @param sb Southbridge config structure.
 185 */
 186static void lpc_init(struct southbridge_amd_cs5536_dts_config *sb)
 187{
 188        struct msr msr;
 189
 190        if (sb->lpc_serirq_enable) {
 191                msr.lo = sb->lpc_serirq_enable;
 192                msr.hi = 0;
 193                wrmsr(MDD_IRQM_LPC, msr);
 194                if (sb->lpc_serirq_polarity) {
 195                        msr.lo = sb->lpc_serirq_polarity << 16;
 196                        msr.lo |= (sb->lpc_serirq_mode << 6) | (1 << 7);        /* Enable */
 197                        msr.hi = 0;
 198                        wrmsr(MDD_LPC_SIRQ, msr);
 199                }
 200        }
 201
 202        /* Allow DMA from LPC. */
 203        msr = rdmsr(MDD_DMA_MAP);
 204        msr.lo = 0x7777;
 205        wrmsr(MDD_DMA_MAP, msr);
 206
 207        /* Enable the RTC/CMOS century byte at address 0x32. */
 208        msr = rdmsr(MDD_RTC_CENTURY_OFFSET);
 209        msr.lo = RTC_CENTURY;
 210        wrmsr(MDD_RTC_CENTURY_OFFSET, msr);
 211
 212        /* Enable the RTC/CMOS day of month and month alarms. */
 213        msr = rdmsr(MDD_RTC_DOMA_IND);
 214        msr.lo = RTC_DOMA;
 215        wrmsr(MDD_RTC_DOMA_IND, msr);
 216
 217        msr = rdmsr(MDD_RTC_MONA_IND);
 218        msr.lo = RTC_MONA;
 219        wrmsr(MDD_RTC_MONA_IND, msr);
 220
 221        rtc_init(0);
 222
 223        isa_dma_init();
 224}
 225
 226/**
 227 * Depending on settings in the config struct, enable COM1 or COM2 or both.
 228 *
 229 * If the enable is NOT set, the UARTs are explicitly disabled, which is
 230 * required if (e.g.) there is a Super I/O attached that does COM1 or COM2.
 231 *
 232 * @param sb Southbridge config structure.
 233 */
 234static void uarts_init(struct southbridge_amd_cs5536_dts_config *sb,
 235                        struct device *dev)
 236{
 237        struct msr msr;
 238        u16 addr = 0;
 239        u32 gpio_addr;
 240
 241        gpio_addr = pci_read_config32(dev, PCI_BASE_ADDRESS_1);
 242        gpio_addr &= ~1;        /* Clear I/O bit */
 243        printk(BIOS_DEBUG, "GPIO_ADDR: %08X\n", gpio_addr);
 244
 245        /* This could be extended to support IR modes. */
 246
 247        /* COM1 */
 248        if (sb->com1_enable) {
 249                printk(BIOS_SPEW, "uarts_init: enable COM1\n");
 250                /* Set the address. */
 251                switch (sb->com1_address) {
 252                case 0x3F8:
 253                        addr = 7;
 254                        break;
 255                case 0x3E8:
 256                        addr = 6;
 257                        break;
 258                case 0x2F8:
 259                        addr = 5;
 260                        break;
 261                case 0x2E8:
 262                        addr = 4;
 263                        break;
 264                }
 265                msr = rdmsr(MDD_LEG_IO);
 266                msr.lo |= addr << 16;
 267                wrmsr(MDD_LEG_IO, msr);
 268
 269                /* Set the IRQ. */
 270                msr = rdmsr(MDD_IRQM_YHIGH);
 271                msr.lo |= sb->com1_irq << 24;
 272                wrmsr(MDD_IRQM_YHIGH, msr);
 273
 274                /* GPIO8 - UART1_TX */
 275                /* Set: Output Enable (0x4) */
 276                outl(GPIOL_8_SET, gpio_addr + GPIOL_OUTPUT_ENABLE);
 277                /* Set: OUTAUX1 Select (0x10) */
 278                outl(GPIOL_8_SET, gpio_addr + GPIOL_OUT_AUX1_SELECT);
 279
 280                /* GPIO8 - UART1_RX */
 281                /* Set: Input Enable (0x20) */
 282                outl(GPIOL_9_SET, gpio_addr + GPIOL_INPUT_ENABLE);
 283                /* Set: INAUX1 Select (0x34) */
 284                outl(GPIOL_9_SET, gpio_addr + GPIOL_IN_AUX1_SELECT);
 285
 286                /* Set: GPIO 8 + 9 Pull Up (0x18) */
 287                outl(GPIOL_8_SET | GPIOL_9_SET,
 288                     gpio_addr + GPIOL_PULLUP_ENABLE);
 289
 290                /* Enable COM1.
 291                 *
 292                 * Bit 1 = device enable
 293                 * Bit 4 = allow access to the upper banks
 294                 */
 295                msr.lo = (1 << 4) | (1 << 1);
 296                msr.hi = 0;
 297                wrmsr(MDD_UART1_CONF, msr);
 298        } else {
 299                /* Reset and disable COM1. */
 300                printk(BIOS_SPEW, "uarts_init: disable COM1\n");
 301                msr = rdmsr(MDD_UART1_CONF);
 302                msr.lo = 1;                     /* Reset */
 303                wrmsr(MDD_UART1_CONF, msr);
 304                msr.lo = 0;                     /* Disabled */
 305                wrmsr(MDD_UART1_CONF, msr);
 306
 307                /* Disable the IRQ. */
 308                msr = rdmsr(MDD_LEG_IO);
 309                msr.lo &= ~(0xF << 16);
 310                wrmsr(MDD_LEG_IO, msr);
 311        }
 312
 313        /* COM2 */
 314        if (sb->com2_enable) {
 315                printk(BIOS_SPEW, "uarts_init: enable COM2\n");
 316                switch (sb->com2_address) {
 317                case 0x3F8:
 318                        addr = 7;
 319                        break;
 320                case 0x3E8:
 321                        addr = 6;
 322                        break;
 323                case 0x2F8:
 324                        addr = 5;
 325                        break;
 326                case 0x2E8:
 327                        addr = 4;
 328                        break;
 329                }
 330                msr = rdmsr(MDD_LEG_IO);
 331                msr.lo |= addr << 20;
 332                wrmsr(MDD_LEG_IO, msr);
 333                printk(BIOS_SPEW, "uarts_init: wrote COM2 address 0x%x\n", sb->com2_address);
 334
 335                /* Set the IRQ. */
 336                msr = rdmsr(MDD_IRQM_YHIGH);
 337                msr.lo |= sb->com2_irq << 28;
 338                wrmsr(MDD_IRQM_YHIGH, msr);
 339                printk(BIOS_SPEW, "uarts_init: set COM2 irq\n");
 340
 341                /* GPIO3 - UART2_RX */
 342                /* Set: Output Enable (0x4) */
 343                outl(GPIOL_3_SET, gpio_addr + GPIOL_OUTPUT_ENABLE);
 344                printk(BIOS_SPEW, "uarts_init: set output enable\n");
 345                /* Set: OUTAUX1 Select (0x10) */
 346                outl(GPIOL_3_SET, gpio_addr + GPIOL_OUT_AUX1_SELECT);
 347                printk(BIOS_SPEW, "uarts_init: set OUTAUX1\n");
 348
 349                /* GPIO4 - UART2_TX */
 350                /* Set: Input Enable (0x20) */
 351                outl(GPIOL_4_SET, gpio_addr + GPIOL_INPUT_ENABLE);
 352                printk(BIOS_SPEW, "uarts_init: set COM2 input enable\n");
 353                /* Set: INAUX1 Select (0x34) */
 354                /* this totally disables com2 for serial, leave it out until we can
 355                 * figure it out
 356                 */
 357//              outl(GPIOL_4_SET, gpio_addr + GPIOL_IN_AUX2_SELECT);
 358//              printk(BIOS_SPEW, "uarts_init: set INAUX2 for COM2\n");
 359
 360                /* Set: GPIO 3 + 4 Pull Up (0x18) */
 361                outl(GPIOL_3_SET | GPIOL_4_SET,
 362                     gpio_addr + GPIOL_PULLUP_ENABLE);
 363                printk(BIOS_SPEW, "uarts_init: set pullup COM2\n");
 364
 365                /* Enable COM2.
 366                 *
 367                 * Bit 1 = device enable
 368                 * Bit 4 = allow access to the upper banks
 369                 */
 370                msr.lo = (1 << 4) | (1 << 1);
 371                msr.hi = 0;
 372                wrmsr(MDD_UART2_CONF, msr);
 373                printk(BIOS_SPEW, "uarts_init: COM2 enabled\n");
 374        } else {
 375                printk(BIOS_SPEW, "uarts_init: disable COM2\n");
 376                /* Reset and disable COM2. */
 377                msr = rdmsr(MDD_UART2_CONF);
 378                msr.lo = 1;                     /* Reset */
 379                wrmsr(MDD_UART2_CONF, msr);
 380                msr.lo = 0;                     /* Disabled */
 381                wrmsr(MDD_UART2_CONF, msr);
 382
 383                /* Disable the IRQ. */
 384                msr = rdmsr(MDD_LEG_IO);
 385                msr.lo &= ~(0xF << 20);
 386                wrmsr(MDD_LEG_IO, msr);
 387        }
 388}
 389
 390#define HCCPARAMS               0x08
 391#define IPREG04         0xA0
 392#define USB_HCCPW_SET           (1 << 1)
 393#define UOCCAP                  0x00
 394#define APU_SET         (1 << 15)
 395#define UOCMUX                  0x04
 396#define PMUX_HOST               0x02
 397#define PMUX_DEVICE             0x03
 398#define PUEN_SET                (1 << 2)
 399#define UDCDEVCTL               0x404
 400#define UDC_SD_SET              (1 << 10)
 401#define UOCCTL                  0x0C
 402#define PADEN_SET               (1 << 7)
 403
 404/**
 405 * Depending on settings in the config struct, manage USB setup.
 406 *
 407 * @param sb Southbridge config structure.
 408 */
 409static void enable_USB_port4(struct southbridge_amd_cs5536_dts_config *sb)
 410{
 411        u8 *bar;
 412        struct msr msr;
 413        struct device *ehci_dev, *otg_dev, *udc_dev;
 414
 415        ehci_dev = dev_find_pci_device(PCI_VENDOR_ID_AMD,
 416                              PCI_DEVICE_ID_AMD_CS5536_EHCI, 0);
 417        if (ehci_dev) {
 418                /* Serial short detect enable */
 419                msr = rdmsr(USB2_SB_GLD_MSR_CONF);
 420                msr.hi |= USB2_UPPER_SSDEN_SET;
 421                wrmsr(USB2_SB_GLD_MSR_CONF, msr);
 422
 423                /* Write to clear diag register. */
 424                wrmsr(USB2_SB_GLD_MSR_DIAG, rdmsr(USB2_SB_GLD_MSR_DIAG));
 425
 426                bar = (u8 *) pci_read_config32(ehci_dev, PCI_BASE_ADDRESS_0);
 427
 428                /* Make HCCPARAMS writable. */
 429                writel(readl(bar + IPREG04) | USB_HCCPW_SET, bar + IPREG04);
 430
 431                /* EECP=50h, IST=01h, ASPC=1 */
 432                writel(0x00005012, bar + HCCPARAMS);
 433        }
 434
 435        otg_dev = dev_find_pci_device(PCI_VENDOR_ID_AMD,
 436                              PCI_DEVICE_ID_AMD_CS5536_OTG, 0);
 437        if (otg_dev) {
 438                bar = (u8 *) pci_read_config32(otg_dev, PCI_BASE_ADDRESS_0);
 439
 440                printk(BIOS_DEBUG, "UOCMUX is %x\n", readl(bar + UOCMUX));
 441
 442                writel(readl(bar + UOCMUX) & PUEN_SET, bar + UOCMUX);
 443
 444                /* Host or Device? */
 445                if (sb->enable_USBP4_device)
 446                        writel(readl(bar + UOCMUX) | PMUX_DEVICE, bar + UOCMUX);
 447                else
 448                        writel(readl(bar + UOCMUX) | PMUX_HOST, bar + UOCMUX);
 449
 450                /* Overcurrent configuration */
 451                printk(BIOS_DEBUG, "UOCCAP is %x\n", readl(bar + UOCCAP));
 452                if (sb->enable_USBP4_overcurrent)
 453                        writel(readl(bar + UOCCAP)
 454                               | sb->enable_USBP4_overcurrent, bar + UOCCAP);
 455                /* power control. see comment in the dts for these bits */
 456                if (sb->pph) {
 457                        writel((readl(bar + UOCCAP)
 458                                & ~0xff) | sb->pph, bar + UOCCAP);
 459                }
 460                printk(BIOS_DEBUG, "UOCCAP is %x\n", readl(bar + UOCCAP));
 461                printk(BIOS_DEBUG, "UOCMUX is %x\n", readl(bar + UOCMUX));
 462
 463        }
 464
 465        udc_dev = dev_find_pci_device(PCI_VENDOR_ID_AMD,
 466                                  PCI_DEVICE_ID_AMD_CS5536_UDC, 0);
 467        /* PBz#6466: If the UOC(OTG) device, port 4, is configured as a
 468         * device, then perform the following sequence:
 469         *  - Set SD bit in DEVCTRL udc register
 470         *  - Set PADEN (former OTGPADEN) bit in uoc register
 471         *  - Set APU bit in uoc register
 472         */
 473        if (sb->enable_USBP4_device) {
 474                if (udc_dev) {
 475                        bar = (u8 *)pci_read_config32(udc_dev, PCI_BASE_ADDRESS_0);
 476                        writel(readl(bar + UDCDEVCTL) | UDC_SD_SET,
 477                               bar + UDCDEVCTL);
 478                }
 479
 480                if (otg_dev) {
 481                        bar = (u8 *)pci_read_config32(otg_dev, PCI_BASE_ADDRESS_0);
 482                        writel(readl(bar + UOCCTL) | PADEN_SET, bar + UOCCTL);
 483                        writel(readl(bar + UOCCAP) | APU_SET, bar + UOCCAP);
 484                        printk(BIOS_DEBUG, "UOCCTL is %x\n", readl(bar + UOCCTL));
 485                }
 486        }
 487
 488        /* Disable virtual PCI UDC and OTG headers.  The kernel never
 489         * sees a header for this device.  It used to provide an OS
 490         * visible device, but that was defeatured.  There are still
 491         * some registers in the block that are useful for the firmware
 492         * to setup, but nothing that a kernel level driver would need
 493         * to consume.
 494         *
 495         * As you can see above, VSA does provide the header under
 496         * device ID PCI_DEVICE_ID_AMD_CS5536_OTG, but it is hidden
 497         * when 0xDEADBEEF is written to config space register 0x7C.
 498         */
 499        if (udc_dev)
 500                pci_write_config32(udc_dev, 0x7C, 0xDEADBEEF);
 501
 502        if (otg_dev)
 503                pci_write_config32(otg_dev, 0x7C, 0xDEADBEEF);
 504}
 505
 506/** 
 507 * This function initializes a lot of nasty bits needed for phase 2.
 508 *
 509 * Can this function run before vsm is set up, or is it required for vsm?
 510 * The order here is a little hard to figure out.
 511 *
 512 * This function is in an odd place. We need to see about moving it to
 513 * geodelx.c. But for now, let's get things working and put a #warning in.
 514 */
 515void chipsetinit(void)
 516{
 517        struct device *dev;
 518        struct msr msr;
 519        struct southbridge_amd_cs5536_dts_config *sb;
 520        const struct msrinit *csi;
 521
 522        post_code(P80_CHIPSET_INIT);
 523        dev = dev_find_pci_device(PCI_VENDOR_ID_AMD,
 524                              PCI_DEVICE_ID_AMD_CS5536_ISA, 0);
 525        if (!dev) {
 526                printk(BIOS_ERR, "%s: Could not find the south bridge!\n",
 527                       __func__);
 528                return;
 529        }
 530        sb = (struct southbridge_amd_cs5536_dts_config *)dev->device_configuration;
 531
 532#ifdef CONFIG_SUSPEND_TO_RAM
 533        if (!IsS3Resume())
 534#endif
 535        {
 536                const struct acpi_init *aci = acpi_init_table;
 537                for (; aci->ioreg; aci++) {
 538                        outl(aci->regdata, aci->ioreg);
 539                        inl(aci->ioreg);
 540                }
 541                pm_chipset_init();
 542        }
 543
 544        /* Set HD IRQ. */
 545        outl(GPIOL_2_SET, GPIO_IO_BASE + GPIOL_INPUT_ENABLE);
 546        outl(GPIOL_2_SET, GPIO_IO_BASE + GPIOL_IN_AUX1_SELECT);
 547
 548        /* Allow I/O reads and writes during a ATA DMA operation. This could
 549         * be done in the HD ROM but do it here for easier debugging.
 550         */
 551        msr = rdmsr(ATA_SB_GLD_MSR_ERR);
 552        msr.lo &= ~0x100;
 553        wrmsr(ATA_SB_GLD_MSR_ERR, msr);
 554
 555        /* Enable post primary IDE. */
 556        msr = rdmsr(GLPCI_SB_CTRL);
 557        msr.lo |= GLPCI_CRTL_PPIDE_SET;
 558        wrmsr(GLPCI_SB_CTRL, msr);
 559
 560        csi = SB_MASTER_CONF_TABLE;
 561        for (; csi->msrnum; csi++) {
 562                msr.lo = csi->msr.lo;
 563                msr.hi = csi->msr.hi;
 564                wrmsr(csi->msrnum, msr);
 565        }
 566
 567        /* Flash BAR size setup. */
 568        printk(BIOS_ERR, "%sDoing chipset_flash_setup()\n",
 569               sb->enable_ide_nand_flash != 0 ? "" : "Not ");
 570        if (sb->enable_ide_nand_flash != 0)
 571                chipset_flash_setup(sb);
 572
 573        /* Set up hardware clock gating. */
 574        /* TODO: Why the extra block here? Can it be removed? */
 575        {
 576                csi = CS5536_CLOCK_GATING_TABLE;
 577                for (; csi->msrnum; csi++) {
 578                        msr.lo = csi->msr.lo;
 579                        msr.hi = csi->msr.hi;
 580                        wrmsr(csi->msrnum, msr);
 581                }
 582        }
 583}
 584
 585#define IDE_CFG   0x40
 586        #define CHANEN  (1L <<  1)
 587        #define PWB     (1L << 14)
 588        #define CABLE   (1L << 16)
 589#define IDE_DTC   0x48
 590#define IDE_CAST  0x4C
 591#define IDE_ETC   0x50
 592
 593/**
 594 * Enables the IDE. This is code that is run if there is an ide device in the mainboard
 595 * device tree.
 596 * 
 597 * @param dev The device 
 598 */
 599static void ide_init(struct device *dev)
 600{
 601        u32 ide_cfg;
 602
 603        printk(BIOS_DEBUG, "cs5536_ide: %s\n", __func__);
 604        /* GPIO and IRQ setup are handled in the main chipset code. */
 605
 606        // Enable the channel and Post Write Buffer
 607        // NOTE: Only 32-bit writes to the data buffer are allowed when PWB is set
 608        ide_cfg = pci_read_config32(dev, IDE_CFG);
 609        ide_cfg |= CHANEN | PWB;
 610        pci_write_config32(dev, IDE_CFG, ide_cfg);
 611}
 612
 613/**
 614 * TODO.
 615 *
 616 * @param dev The device to use.
 617 */
 618static void southbridge_init(struct device *dev)
 619{
 620        int i;
 621        struct southbridge_amd_cs5536_dts_config *sb =
 622            (struct southbridge_amd_cs5536_dts_config *)dev->device_configuration;
 623
 624        /*
 625         * struct device *gpiodev;
 626         * unsigned short gpiobase = MDD_GPIO;
 627         */
 628
 629        printk(BIOS_ERR, "cs5536: %s\n", __func__);
 630
 631        setup_i8259();
 632        lpc_init(sb);
 633        uarts_init(sb, dev);
 634
 635        printk(BIOS_SPEW, "cs5536: done uarts_init\n");
 636        if (sb->enable_gpio_int_route) {
 637                printk(BIOS_SPEW, "cs5536: call vr_write\n");
 638                vr_write((VRC_MISCELLANEOUS << 8) + PCI_INT_AB,
 639                         (sb->enable_gpio_int_route & 0xFFFF));
 640                printk(BIOS_SPEW, "cs5536: done first call vr_write\n");
 641                vr_write((VRC_MISCELLANEOUS << 8) + PCI_INT_CD,
 642                         (sb->enable_gpio_int_route >> 16));
 643                printk(BIOS_SPEW, "cs5536: done second call vr_write\n");
 644        }
 645
 646        enable_USB_port4(sb);
 647
 648        /* disable unwanted virtual PCI devices */
 649        for (i = 0; 0 != sb->unwanted_vpci[i]; i++) {
 650                hide_vpci(sb->unwanted_vpci[i]);
 651        }
 652
 653        cs5536_setup_power_button(sb);
 654
 655        printk(BIOS_SPEW, "cs5536: %s() Exit\n", __func__);
 656}
 657
 658/**
 659 * A slightly different read resources.  We add fixed resources.
 660 *
 661 * @param dev The device to use.
 662 */
 663static void cs5536_read_resources(struct device *dev)
 664{
 665        /* This is a fixed IO resource for legacy decoding.  Its presence moves
 666         * other allocations out of this location. */
 667        struct resource *res;
 668        res = new_resource(dev, 0);
 669        res->base = 0x0UL;
 670        res->size = 0x1000UL;
 671        res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
 672                     IORESOURCE_STORED;
 673
 674        pci_dev_read_resources(dev);
 675}
 676
 677/**
 678 * A slightly different enable resources than the standard.
 679 * We grab control here as VSA has played in this chip as well.
 680 *
 681 * @param dev The device to use.
 682 */
 683static void cs5536_pci_dev_enable_resources(struct device *dev)
 684{
 685        printk(BIOS_SPEW, "cs5536: %s()\n", __func__);
 686        pci_dev_enable_resources(dev);
 687        enable_childrens_resources(dev);
 688        printk(BIOS_SPEW, "cs5536: %s() Exit\n", __func__);
 689}
 690
 691struct device_operations cs5536_ops = {
 692        .id = {.type = DEVICE_ID_PCI,
 693                {.pci = {.vendor = PCI_VENDOR_ID_AMD,
 694                         .device = PCI_DEVICE_ID_AMD_CS5536_ISA}}},
 695        .constructor             = default_device_constructor,
 696        .phase3_scan             = scan_static_bus,
 697        .phase4_read_resources   = cs5536_read_resources,
 698        .phase4_set_resources    = pci_set_resources,
 699        .phase5_enable_resources = cs5536_pci_dev_enable_resources,
 700        .phase6_init             = southbridge_init,
 701};
 702
 703struct device_operations cs5536_ide = {
 704        .id = {.type = DEVICE_ID_PCI,
 705                {.pci = {.vendor = PCI_VENDOR_ID_AMD,
 706                         .device = PCI_DEVICE_ID_AMD_CS5536_B0_IDE}}},
 707        .constructor             = default_device_constructor,
 708        .phase3_scan             = 0,
 709        .phase4_read_resources   = pci_dev_read_resources,
 710        .phase4_set_resources    = pci_set_resources,
 711        .phase5_enable_resources = pci_dev_enable_resources,
 712        .phase6_init             = ide_init,
 713        .ops_pci                 = &pci_dev_ops_pci,
 714};
 715
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.