blob: 97f27d03875b42c4bfcbde58c3510f60cf6519f5 [file] [log] [blame]
zbao246e84b2012-07-13 18:47:03 +08001/*
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>
26#include <pc80/mc146818rtc.h>
27#include <pc80/isa-dma.h>
28#include <bitops.h>
29#include <arch/io.h>
30#include "hudson.h"
31
32static 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);
zbaoef180e22012-08-02 19:03:44 +080070
71 rtc_check_update_cmos_date(RTC_HAS_ALTCENTURY);
zbao246e84b2012-07-13 18:47:03 +080072}
73
74static 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
104static void hudson_lpc_set_resources(struct device *dev)
105{
106 struct resource *res;
107
108 pci_dev_set_resources(dev);
109
110 /* Specical case. SPI Base Address. The SpiRomEnable should be set. */
111 res = find_resource(dev, 0xA0);
112 pci_write_config32(dev, 0xA0, res->base | 1 << 1);
113
114}
115
116/**
117 * @brief Enable resources for children devices
118 *
119 * @param dev the device whos children's resources are to be enabled
120 *
121 */
122static void hudson_lpc_enable_childrens_resources(device_t dev)
123{
124 printk(BIOS_DEBUG, "hudson_lpc_enable_childrens_resources\n");
125
126}
127
128static void hudson_lpc_enable_resources(device_t dev)
129{
130 pci_dev_enable_resources(dev);
131 hudson_lpc_enable_childrens_resources(dev);
132}
133
134static struct pci_operations lops_pci = {
135 .set_subsystem = pci_dev_set_subsystem,
136};
137
138static struct device_operations lpc_ops = {
139 .read_resources = hudson_lpc_read_resources,
140 .set_resources = hudson_lpc_set_resources,
141 .enable_resources = hudson_lpc_enable_resources,
142 .init = lpc_init,
143 .scan_bus = scan_static_bus,
144 .ops_pci = &lops_pci,
145};
146static const struct pci_driver lpc_driver __pci_driver = {
147 .ops = &lpc_ops,
148 .vendor = PCI_VENDOR_ID_AMD,
149 .device = PCI_DEVICE_ID_ATI_SB900_LPC,
150};