blob: d9057cb295cf75f5229c64100e08e51b4dc0f0d5 [file] [log] [blame]
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer54309d62009-01-20 22:53:10 +00004 * Copyright (C) 2008-2009 coresystems GmbH
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00005 *
Stefan Reinauera8e11682009-03-11 14:54:18 +00006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000010 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <console/console.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
Stefan Reinauerde3206a2010-02-22 06:09:43 +000025#include "i82801gx.h"
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000026
27static void pci_init(struct device *dev)
28{
29 u16 reg16;
Stefan Reinauera8e11682009-03-11 14:54:18 +000030 u8 reg8;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000031
Stefan Reinauera8e11682009-03-11 14:54:18 +000032 /* Enable Bus Master */
33 reg16 = pci_read_config16(dev, PCI_COMMAND);
34 reg16 |= PCI_COMMAND_MASTER;
35 pci_write_config16(dev, PCI_COMMAND, reg16);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000036
Stefan Reinauera8e11682009-03-11 14:54:18 +000037 /* This device has no interrupt */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000038 pci_write_config8(dev, INTR, 0xff);
Stefan Reinauera8e11682009-03-11 14:54:18 +000039
40 /* disable parity error response and SERR */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000041 reg16 = pci_read_config16(dev, BCTRL);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000042 reg16 &= ~(1 << 0);
Stefan Reinauera8e11682009-03-11 14:54:18 +000043 reg16 &= ~(1 << 1);
Stefan Reinauerde3206a2010-02-22 06:09:43 +000044 pci_write_config16(dev, BCTRL, reg16);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000045
Stefan Reinauera8e11682009-03-11 14:54:18 +000046 /* Master Latency Count must be set to 0x04! */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000047 reg8 = pci_read_config8(dev, SMLT);
Stefan Reinauera8e11682009-03-11 14:54:18 +000048 reg8 &= 0x07;
49 reg8 |= (0x04 << 3);
Stefan Reinauerde3206a2010-02-22 06:09:43 +000050 pci_write_config8(dev, SMLT, reg8);
Stefan Reinauer54309d62009-01-20 22:53:10 +000051
52 /* Will this improve throughput of bus masters? */
53 pci_write_config8(dev, PCI_MIN_GNT, 0x06);
Stefan Reinauera8e11682009-03-11 14:54:18 +000054
55 /* Clear errors in status registers */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000056 reg16 = pci_read_config16(dev, PSTS);
Stefan Reinauera8e11682009-03-11 14:54:18 +000057 //reg16 |= 0xf900;
Stefan Reinauerde3206a2010-02-22 06:09:43 +000058 pci_write_config16(dev, PSTS, reg16);
Stefan Reinauera8e11682009-03-11 14:54:18 +000059
Stefan Reinauerde3206a2010-02-22 06:09:43 +000060 reg16 = pci_read_config16(dev, SECSTS);
Stefan Reinauera8e11682009-03-11 14:54:18 +000061 // reg16 |= 0xf900;
Stefan Reinauerde3206a2010-02-22 06:09:43 +000062 pci_write_config16(dev, SECSTS, reg16);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000063}
64
Stefan Reinauera8e11682009-03-11 14:54:18 +000065#undef PCI_BRIDGE_UPDATE_COMMAND
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000066static void ich_pci_dev_enable_resources(struct device *dev)
67{
68 const struct pci_operations *ops;
69 uint16_t command;
70
71 /* Set the subsystem vendor and device id for mainboard devices */
72 ops = ops_pci(dev);
73 if (dev->on_mainboard && ops && ops->set_subsystem) {
74 printk_debug("%s subsystem <- %02x/%02x\n",
Stefan Reinauer109ab312009-08-12 16:08:05 +000075 dev_path(dev),
Stefan Reinauer08670622009-06-30 15:17:49 +000076 CONFIG_MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID,
77 CONFIG_MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID);
Stefan Reinauer109ab312009-08-12 16:08:05 +000078 ops->set_subsystem(dev,
Stefan Reinauer08670622009-06-30 15:17:49 +000079 CONFIG_MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID,
80 CONFIG_MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000081 }
82
Stefan Reinauera8e11682009-03-11 14:54:18 +000083 command = pci_read_config16(dev, PCI_COMMAND);
84 command |= dev->command;
Stefan Reinauer573f7d42009-07-21 21:50:34 +000085#ifdef PCI_BRIDGE_UPDATE_COMMAND
Stefan Reinauer109ab312009-08-12 16:08:05 +000086 /* If we write to PCI_COMMAND, on some systems
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000087 * this will cause the ROM and APICs not being visible
88 * anymore.
89 */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000090 printk_debug("%s cmd <- %02x\n", dev_path(dev), command);
91 pci_write_config16(dev, PCI_COMMAND, command);
Stefan Reinauera8e11682009-03-11 14:54:18 +000092#else
93 printk_debug("%s cmd <- %02x (NOT WRITTEN!)\n", dev_path(dev), command);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000094#endif
95}
96
97static void ich_pci_bus_enable_resources(struct device *dev)
98{
99 uint16_t ctrl;
100 /* enable IO in command register if there is VGA card
101 * connected with (even it does not claim IO resource)
102 */
103 if (dev->link[0].bridge_ctrl & PCI_BRIDGE_CTL_VGA)
104 dev->command |= PCI_COMMAND_IO;
105 ctrl = pci_read_config16(dev, PCI_BRIDGE_CONTROL);
106 ctrl |= dev->link[0].bridge_ctrl;
107 ctrl |= (PCI_BRIDGE_CTL_PARITY + PCI_BRIDGE_CTL_SERR); /* error check */
108 printk_debug("%s bridge ctrl <- %04x\n", dev_path(dev), ctrl);
109 pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl);
110
111 /* This is the reason we need our own pci_bus_enable_resources */
112 ich_pci_dev_enable_resources(dev);
113
114 enable_childrens_resources(dev);
115}
116
117static void set_subsystem(device_t dev, unsigned vendor, unsigned device)
118{
Stefan Reinauera8e11682009-03-11 14:54:18 +0000119 /* NOTE: This is not the default position! */
120 if (!vendor || !device) {
121 pci_write_config32(dev, 0x54,
122 pci_read_config32(dev, PCI_VENDOR_ID));
123 } else {
124 pci_write_config32(dev, 0x54,
125 ((device & 0xffff) << 16) | (vendor & 0xffff));
126 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000127}
128
129static struct pci_operations pci_ops = {
130 .set_subsystem = set_subsystem,
131};
132
133static struct device_operations device_ops = {
134 .read_resources = pci_bus_read_resources,
135 .set_resources = pci_dev_set_resources,
136 .enable_resources = ich_pci_bus_enable_resources,
137 .init = pci_init,
138 .scan_bus = pci_scan_bridge,
139 .ops_pci = &pci_ops,
140};
141
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000142/* Desktop */
Uwe Hermannbddc6932008-10-29 13:51:31 +0000143/* 82801BA/CA/DB/EB/ER/FB/FR/FW/FRW/GB/GR/GDH/HB/IB/6300ESB/i3100 */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000144static const struct pci_driver i82801g_pci __pci_driver = {
145 .ops = &device_ops,
Uwe Hermannbddc6932008-10-29 13:51:31 +0000146 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000147 .device = 0x244e,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000148};
149
150/* Mobile / Ultra Mobile */
Uwe Hermannbddc6932008-10-29 13:51:31 +0000151/* 82801BAM/CAM/DBL/DBM/FBM/GBM/GHM/GU/HBM/HEM */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000152static const struct pci_driver i82801gmu_pci __pci_driver = {
153 .ops = &device_ops,
Uwe Hermannbddc6932008-10-29 13:51:31 +0000154 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000155 .device = 0x2448,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000156};