blob: 97ae98abdf7c3614012a981854501fe6d1053eb3 [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.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000015 */
16
17#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
Stefan Reinauerde3206a2010-02-22 06:09:43 +000021#include "i82801gx.h"
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000022
23static void pci_init(struct device *dev)
24{
25 u16 reg16;
Stefan Reinauera8e11682009-03-11 14:54:18 +000026 u8 reg8;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000027
Stefan Reinauera8e11682009-03-11 14:54:18 +000028 /* Enable Bus Master */
29 reg16 = pci_read_config16(dev, PCI_COMMAND);
30 reg16 |= PCI_COMMAND_MASTER;
31 pci_write_config16(dev, PCI_COMMAND, reg16);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000032
Stefan Reinauera8e11682009-03-11 14:54:18 +000033 /* This device has no interrupt */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000034 pci_write_config8(dev, INTR, 0xff);
Stefan Reinauera8e11682009-03-11 14:54:18 +000035
36 /* disable parity error response and SERR */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000037 reg16 = pci_read_config16(dev, BCTRL);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000038 reg16 &= ~(1 << 0);
Stefan Reinauera8e11682009-03-11 14:54:18 +000039 reg16 &= ~(1 << 1);
Stefan Reinauerde3206a2010-02-22 06:09:43 +000040 pci_write_config16(dev, BCTRL, reg16);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000041
Stefan Reinauera8e11682009-03-11 14:54:18 +000042 /* Master Latency Count must be set to 0x04! */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000043 reg8 = pci_read_config8(dev, SMLT);
Stefan Reinauera8e11682009-03-11 14:54:18 +000044 reg8 &= 0x07;
45 reg8 |= (0x04 << 3);
Stefan Reinauerde3206a2010-02-22 06:09:43 +000046 pci_write_config8(dev, SMLT, reg8);
Stefan Reinauer54309d62009-01-20 22:53:10 +000047
48 /* Will this improve throughput of bus masters? */
49 pci_write_config8(dev, PCI_MIN_GNT, 0x06);
Stefan Reinauera8e11682009-03-11 14:54:18 +000050
51 /* Clear errors in status registers */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000052 reg16 = pci_read_config16(dev, PSTS);
Stefan Reinauera8e11682009-03-11 14:54:18 +000053 //reg16 |= 0xf900;
Stefan Reinauerde3206a2010-02-22 06:09:43 +000054 pci_write_config16(dev, PSTS, reg16);
Stefan Reinauera8e11682009-03-11 14:54:18 +000055
Stefan Reinauerde3206a2010-02-22 06:09:43 +000056 reg16 = pci_read_config16(dev, SECSTS);
Stefan Reinauera8e11682009-03-11 14:54:18 +000057 // reg16 |= 0xf900;
Stefan Reinauerde3206a2010-02-22 06:09:43 +000058 pci_write_config16(dev, SECSTS, reg16);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000059}
60
61static void ich_pci_dev_enable_resources(struct device *dev)
62{
63 const struct pci_operations *ops;
64 uint16_t command;
65
66 /* Set the subsystem vendor and device id for mainboard devices */
67 ops = ops_pci(dev);
68 if (dev->on_mainboard && ops && ops->set_subsystem) {
Sven Schnelle91321022011-03-01 19:58:47 +000069 printk(BIOS_DEBUG, "%s subsystem <- %04x/%04x\n",
70 dev_path(dev), dev->subsystem_vendor,
71 dev->subsystem_device);
72 ops->set_subsystem(dev, dev->subsystem_vendor,
73 dev->subsystem_device);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000074 }
75
Stefan Reinauera8e11682009-03-11 14:54:18 +000076 command = pci_read_config16(dev, PCI_COMMAND);
77 command |= dev->command;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000078 printk(BIOS_DEBUG, "%s cmd <- %02x\n", dev_path(dev), command);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000079 pci_write_config16(dev, PCI_COMMAND, command);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000080}
81
82static void ich_pci_bus_enable_resources(struct device *dev)
83{
84 uint16_t ctrl;
85 /* enable IO in command register if there is VGA card
86 * connected with (even it does not claim IO resource)
87 */
Myles Watson894a3472010-06-09 22:41:35 +000088 if (dev->link_list->bridge_ctrl & PCI_BRIDGE_CTL_VGA)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000089 dev->command |= PCI_COMMAND_IO;
90 ctrl = pci_read_config16(dev, PCI_BRIDGE_CONTROL);
Myles Watson894a3472010-06-09 22:41:35 +000091 ctrl |= dev->link_list->bridge_ctrl;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000092 ctrl |= (PCI_BRIDGE_CTL_PARITY + PCI_BRIDGE_CTL_SERR); /* error check */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000093 printk(BIOS_DEBUG, "%s bridge ctrl <- %04x\n", dev_path(dev), ctrl);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000094 pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl);
95
96 /* This is the reason we need our own pci_bus_enable_resources */
97 ich_pci_dev_enable_resources(dev);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000098}
99
Elyes HAOUAS99667032018-05-13 12:47:28 +0200100static void set_subsystem(struct device *dev, unsigned int vendor,
101 unsigned int device)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000102{
Stefan Reinauera8e11682009-03-11 14:54:18 +0000103 /* NOTE: This is not the default position! */
104 if (!vendor || !device) {
105 pci_write_config32(dev, 0x54,
106 pci_read_config32(dev, PCI_VENDOR_ID));
107 } else {
108 pci_write_config32(dev, 0x54,
109 ((device & 0xffff) << 16) | (vendor & 0xffff));
110 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000111}
112
113static struct pci_operations pci_ops = {
114 .set_subsystem = set_subsystem,
115};
116
117static struct device_operations device_ops = {
118 .read_resources = pci_bus_read_resources,
119 .set_resources = pci_dev_set_resources,
120 .enable_resources = ich_pci_bus_enable_resources,
121 .init = pci_init,
122 .scan_bus = pci_scan_bridge,
123 .ops_pci = &pci_ops,
124};
125
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000126/* Desktop */
Uwe Hermannbddc6932008-10-29 13:51:31 +0000127/* 82801BA/CA/DB/EB/ER/FB/FR/FW/FRW/GB/GR/GDH/HB/IB/6300ESB/i3100 */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000128static const struct pci_driver i82801g_pci __pci_driver = {
129 .ops = &device_ops,
Uwe Hermannbddc6932008-10-29 13:51:31 +0000130 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000131 .device = 0x244e,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000132};
133
134/* Mobile / Ultra Mobile */
Uwe Hermannbddc6932008-10-29 13:51:31 +0000135/* 82801BAM/CAM/DBL/DBM/FBM/GBM/GHM/GU/HBM/HEM */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000136static const struct pci_driver i82801gmu_pci __pci_driver = {
137 .ops = &device_ops,
Uwe Hermannbddc6932008-10-29 13:51:31 +0000138 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000139 .device = 0x2448,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000140};