Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * |
| 6 | * 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. |
| 10 | * |
| 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 Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 20 | #include <device/pci_ops.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 21 | #include <device/pci_ids.h> |
| 22 | #include "pch.h" |
| 23 | |
| 24 | static void pci_init(struct device *dev) |
| 25 | { |
| 26 | u16 reg16; |
| 27 | u8 reg8; |
| 28 | |
| 29 | printk(BIOS_DEBUG, "PCI init.\n"); |
| 30 | /* Enable Bus Master */ |
| 31 | reg16 = pci_read_config16(dev, PCI_COMMAND); |
| 32 | reg16 |= PCI_COMMAND_MASTER; |
| 33 | pci_write_config16(dev, PCI_COMMAND, reg16); |
| 34 | |
| 35 | /* This device has no interrupt */ |
| 36 | pci_write_config8(dev, INTR, 0xff); |
| 37 | |
| 38 | /* disable parity error response and SERR */ |
| 39 | reg16 = pci_read_config16(dev, BCTRL); |
| 40 | reg16 &= ~(1 << 0); |
| 41 | reg16 &= ~(1 << 1); |
| 42 | pci_write_config16(dev, BCTRL, reg16); |
| 43 | |
| 44 | /* Master Latency Count must be set to 0x04! */ |
| 45 | reg8 = pci_read_config8(dev, SMLT); |
| 46 | reg8 &= 0x07; |
| 47 | reg8 |= (0x04 << 3); |
| 48 | pci_write_config8(dev, SMLT, reg8); |
| 49 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 50 | /* Clear errors in status registers */ |
| 51 | reg16 = pci_read_config16(dev, PSTS); |
| 52 | //reg16 |= 0xf900; |
| 53 | pci_write_config16(dev, PSTS, reg16); |
| 54 | |
| 55 | reg16 = pci_read_config16(dev, SECSTS); |
| 56 | // reg16 |= 0xf900; |
| 57 | pci_write_config16(dev, SECSTS, reg16); |
| 58 | } |
| 59 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 60 | static void ich_pci_dev_enable_resources(struct device *dev) |
| 61 | { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 62 | uint16_t command; |
| 63 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 64 | command = pci_read_config16(dev, PCI_COMMAND); |
| 65 | command |= dev->command; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 66 | printk(BIOS_DEBUG, "%s cmd <- %02x\n", dev_path(dev), command); |
| 67 | pci_write_config16(dev, PCI_COMMAND, command); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static void ich_pci_bus_enable_resources(struct device *dev) |
| 71 | { |
| 72 | uint16_t ctrl; |
| 73 | /* enable IO in command register if there is VGA card |
| 74 | * connected with (even it does not claim IO resource) |
| 75 | */ |
| 76 | if (dev->link_list->bridge_ctrl & PCI_BRIDGE_CTL_VGA) |
| 77 | dev->command |= PCI_COMMAND_IO; |
| 78 | ctrl = pci_read_config16(dev, PCI_BRIDGE_CONTROL); |
| 79 | ctrl |= dev->link_list->bridge_ctrl; |
Kyösti Mälkki | 382e216 | 2019-09-21 16:19:32 +0300 | [diff] [blame] | 80 | ctrl |= (PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR); /* error check */ |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 81 | printk(BIOS_DEBUG, "%s bridge ctrl <- %04x\n", dev_path(dev), ctrl); |
| 82 | pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl); |
| 83 | |
| 84 | /* This is the reason we need our own pci_bus_enable_resources */ |
| 85 | ich_pci_dev_enable_resources(dev); |
| 86 | } |
| 87 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 88 | static struct pci_operations pci_ops = { |
Kyösti Mälkki | dbd3132 | 2019-03-20 17:55:27 +0200 | [diff] [blame] | 89 | .set_subsystem = pci_dev_set_subsystem, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | static struct device_operations device_ops = { |
| 93 | .read_resources = pci_bus_read_resources, |
| 94 | .set_resources = pci_dev_set_resources, |
| 95 | .enable_resources = ich_pci_bus_enable_resources, |
| 96 | .init = pci_init, |
| 97 | .scan_bus = pci_scan_bridge, |
| 98 | .ops_pci = &pci_ops, |
| 99 | }; |
| 100 | |
| 101 | static const struct pci_driver pch_pci __pci_driver = { |
| 102 | .ops = &device_ops, |
| 103 | .vendor = PCI_VENDOR_ID_INTEL, |
| 104 | .device = 0x2448, |
| 105 | }; |