zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2010 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 as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 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 <console/console.h> |
| 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
| 23 | #include <device/pnp.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | #include <device/pci_ops.h> |
Martin Roth | 3aef7b4 | 2012-12-05 15:50:32 -0700 | [diff] [blame^] | 26 | #include <device/pci_def.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 27 | #include <pc80/mc146818rtc.h> |
| 28 | #include <pc80/isa-dma.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 29 | #include <arch/io.h> |
| 30 | #include "hudson.h" |
| 31 | |
| 32 | static void lpc_init(device_t dev) |
| 33 | { |
| 34 | u8 byte; |
| 35 | u32 dword; |
| 36 | device_t sm_dev; |
| 37 | |
| 38 | /* Enable the LPC Controller */ |
| 39 | sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 40 | dword = pci_read_config32(sm_dev, 0x64); |
| 41 | dword |= 1 << 20; |
| 42 | pci_write_config32(sm_dev, 0x64, dword); |
| 43 | |
| 44 | /* Initialize isa dma */ |
| 45 | isa_dma_init(); |
| 46 | |
| 47 | /* Enable DMA transaction on the LPC bus */ |
| 48 | byte = pci_read_config8(dev, 0x40); |
| 49 | byte |= (1 << 2); |
| 50 | pci_write_config8(dev, 0x40, byte); |
| 51 | |
| 52 | /* Disable the timeout mechanism on LPC */ |
| 53 | byte = pci_read_config8(dev, 0x48); |
| 54 | byte &= ~(1 << 7); |
| 55 | pci_write_config8(dev, 0x48, byte); |
| 56 | |
| 57 | /* Disable LPC MSI Capability */ |
| 58 | byte = pci_read_config8(dev, 0x78); |
| 59 | byte &= ~(1 << 1); |
| 60 | byte &= ~(1 << 0); /* Keep the old way. i.e., when bus master/DMA cycle is going |
| 61 | on on LPC, it holds PCI grant, so no LPC slave cycle can |
| 62 | interrupt and visit LPC. */ |
| 63 | pci_write_config8(dev, 0x78, byte); |
| 64 | |
| 65 | /* bit0: Enable prefetch a cacheline (64 bytes) when Host reads code from SPI rom */ |
| 66 | /* bit3: Fix SPI_CS# timing issue when running at 66M. TODO:A12. */ |
| 67 | byte = pci_read_config8(dev, 0xBB); |
| 68 | byte |= 1 << 0 | 1 << 3; |
| 69 | pci_write_config8(dev, 0xBB, byte); |
zbao | ef180e2 | 2012-08-02 19:03:44 +0800 | [diff] [blame] | 70 | |
| 71 | rtc_check_update_cmos_date(RTC_HAS_ALTCENTURY); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static void hudson_lpc_read_resources(device_t dev) |
| 75 | { |
| 76 | struct resource *res; |
| 77 | |
| 78 | /* Get the normal pci resources of this device */ |
| 79 | pci_dev_read_resources(dev); /* We got one for APIC, or one more for TRAP */ |
| 80 | |
| 81 | pci_get_resource(dev, 0xA0); /* SPI ROM base address */ |
| 82 | |
| 83 | /* Add an extra subtractive resource for both memory and I/O. */ |
| 84 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); |
| 85 | res->base = 0; |
| 86 | res->size = 0x1000; |
| 87 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 88 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 89 | |
| 90 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); |
| 91 | res->base = 0xff800000; |
| 92 | res->size = 0x00800000; /* 8 MB for flash */ |
| 93 | res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 94 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 95 | |
| 96 | //res = new_resource(dev, 3); /* IOAPIC */ |
| 97 | //res->base = 0xfec00000; |
| 98 | //res->size = 0x00001000; |
| 99 | //res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 100 | |
| 101 | compact_resources(dev); |
| 102 | } |
| 103 | |
| 104 | static void hudson_lpc_set_resources(struct device *dev) |
| 105 | { |
| 106 | struct resource *res; |
| 107 | |
Martin Roth | 3aef7b4 | 2012-12-05 15:50:32 -0700 | [diff] [blame^] | 108 | /* Special case. SPI Base Address. The SpiRomEnable should STAY set. */ |
| 109 | res = find_resource(dev, SPIROM_BASE_ADDRESS_REGISTER); |
| 110 | res->base |= PCI_COMMAND_MEMORY; |
| 111 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 112 | pci_dev_set_resources(dev); |
| 113 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 114 | |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * @brief Enable resources for children devices |
| 119 | * |
| 120 | * @param dev the device whos children's resources are to be enabled |
| 121 | * |
| 122 | */ |
| 123 | static void hudson_lpc_enable_childrens_resources(device_t dev) |
| 124 | { |
| 125 | printk(BIOS_DEBUG, "hudson_lpc_enable_childrens_resources\n"); |
| 126 | |
| 127 | } |
| 128 | |
| 129 | static void hudson_lpc_enable_resources(device_t dev) |
| 130 | { |
| 131 | pci_dev_enable_resources(dev); |
| 132 | hudson_lpc_enable_childrens_resources(dev); |
| 133 | } |
| 134 | |
| 135 | static struct pci_operations lops_pci = { |
| 136 | .set_subsystem = pci_dev_set_subsystem, |
| 137 | }; |
| 138 | |
| 139 | static struct device_operations lpc_ops = { |
| 140 | .read_resources = hudson_lpc_read_resources, |
| 141 | .set_resources = hudson_lpc_set_resources, |
| 142 | .enable_resources = hudson_lpc_enable_resources, |
| 143 | .init = lpc_init, |
| 144 | .scan_bus = scan_static_bus, |
| 145 | .ops_pci = &lops_pci, |
| 146 | }; |
| 147 | static const struct pci_driver lpc_driver __pci_driver = { |
| 148 | .ops = &lpc_ops, |
| 149 | .vendor = PCI_VENDOR_ID_AMD, |
| 150 | .device = PCI_DEVICE_ID_ATI_SB900_LPC, |
| 151 | }; |