printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / southbridge / intel / i3100 / i3100_pciexp_portb.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 Arastra, 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 version 2 as
8  * published by the Free Software Foundation.
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
21 /* This code is based on src/northbridge/intel/e7520/pciexp_porta.c */
22
23 #include <console/console.h>
24 #include <device/device.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <device/pci_ops.h>
28 #include <device/pciexp.h>
29 #include <arch/io.h>
30 #include "chip.h"
31 #include <reset.h>
32
33 #define PCIE_LCTL 0x50
34 #define PCIE_LSTS 0x52
35
36 typedef struct northbridge_intel_i3100_config config_t;
37
38 static void pcie_init(struct device *dev)
39 {
40 }
41
42 static unsigned int pcie_scan_bridge(struct device *dev, unsigned int max)
43 {
44         u16 val;
45         u16 ctl;
46         int flag = 0;
47         do {
48                 val = pci_read_config16(dev, PCIE_LSTS);
49                 printk(BIOS_DEBUG, "pcie portb link status: %02x\n", val);
50                 if ((val & (1<<10)) && (!flag)) { /* training error */
51                         ctl = pci_read_config16(dev, PCIE_LCTL);
52                         pci_write_config16(dev, PCIE_LCTL, (ctl | (1<<5)));
53                         val = pci_read_config16(dev, PCIE_LSTS);
54                         printk(BIOS_DEBUG, "pcie portb reset link status: %02x\n", val);
55                         flag=1;
56                         hard_reset();
57                 }
58         } while (val & (3<<10));
59         return pciexp_scan_bridge(dev, max);
60 }
61
62 static struct device_operations pcie_ops  = {
63         .read_resources   = pci_bus_read_resources,
64         .set_resources    = pci_dev_set_resources,
65         .enable_resources = pci_bus_enable_resources,
66         .init             = pcie_init,
67         .scan_bus         = pcie_scan_bridge,
68         .reset_bus        = pci_bus_reset,
69         .ops_pci          = 0,
70 };
71
72 static const struct pci_driver pci_driver_0 __pci_driver = {
73         .ops    = &pcie_ops,
74         .vendor = PCI_VENDOR_ID_INTEL,
75         .device = PCI_DEVICE_ID_INTEL_3100_PCIE_PB0,
76 };
77
78 static const struct pci_driver pci_driver_1 __pci_driver = {
79         .ops    = &pcie_ops,
80         .vendor = PCI_VENDOR_ID_INTEL,
81         .device = PCI_DEVICE_ID_INTEL_3100_PCIE_PB1,
82 };
83
84 static const struct pci_driver pci_driver_2 __pci_driver = {
85         .ops    = &pcie_ops,
86         .vendor = PCI_VENDOR_ID_INTEL,
87         .device = PCI_DEVICE_ID_INTEL_3100_PCIE_PB2,
88 };
89
90 static const struct pci_driver pci_driver_3 __pci_driver = {
91         .ops    = &pcie_ops,
92         .vendor = PCI_VENDOR_ID_INTEL,
93         .device = PCI_DEVICE_ID_INTEL_3100_PCIE_PB3,
94 };