blob: 56b19e37bbbee853a40cdeb605880ff27a70b3e1 [file] [log] [blame]
Simon Glass4e7a6ac2014-11-14 18:18:32 -07001/*
2 * Copyright (C) 2014 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <errno.h>
9#include <fdtdec.h>
10#include <malloc.h>
11#include <asm/lapic.h>
12#include <asm/pci.h>
13#include <asm/arch/bd82x6x.h>
14#include <asm/arch/model_206ax.h>
15#include <asm/arch/pch.h>
16#include <asm/arch/sandybridge.h>
17
18void bd82x6x_pci_init(pci_dev_t dev)
19{
20 u16 reg16;
21 u8 reg8;
22
23 debug("bd82x6x PCI init.\n");
24 /* Enable Bus Master */
Simon Glass31f57c22015-03-05 12:25:15 -070025 reg16 = x86_pci_read_config16(dev, PCI_COMMAND);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070026 reg16 |= PCI_COMMAND_MASTER;
Simon Glass31f57c22015-03-05 12:25:15 -070027 x86_pci_write_config16(dev, PCI_COMMAND, reg16);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070028
29 /* This device has no interrupt */
Simon Glass31f57c22015-03-05 12:25:15 -070030 x86_pci_write_config8(dev, INTR, 0xff);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070031
32 /* disable parity error response and SERR */
Simon Glass31f57c22015-03-05 12:25:15 -070033 reg16 = x86_pci_read_config16(dev, BCTRL);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070034 reg16 &= ~(1 << 0);
35 reg16 &= ~(1 << 1);
Simon Glass31f57c22015-03-05 12:25:15 -070036 x86_pci_write_config16(dev, BCTRL, reg16);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070037
38 /* Master Latency Count must be set to 0x04! */
Simon Glass31f57c22015-03-05 12:25:15 -070039 reg8 = x86_pci_read_config8(dev, SMLT);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070040 reg8 &= 0x07;
41 reg8 |= (0x04 << 3);
Simon Glass31f57c22015-03-05 12:25:15 -070042 x86_pci_write_config8(dev, SMLT, reg8);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070043
44 /* Will this improve throughput of bus masters? */
Simon Glass31f57c22015-03-05 12:25:15 -070045 x86_pci_write_config8(dev, PCI_MIN_GNT, 0x06);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070046
47 /* Clear errors in status registers */
Simon Glass31f57c22015-03-05 12:25:15 -070048 reg16 = x86_pci_read_config16(dev, PSTS);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070049 /* reg16 |= 0xf900; */
Simon Glass31f57c22015-03-05 12:25:15 -070050 x86_pci_write_config16(dev, PSTS, reg16);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070051
Simon Glass31f57c22015-03-05 12:25:15 -070052 reg16 = x86_pci_read_config16(dev, SECSTS);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070053 /* reg16 |= 0xf900; */
Simon Glass31f57c22015-03-05 12:25:15 -070054 x86_pci_write_config16(dev, SECSTS, reg16);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070055}
56
57#define PCI_BRIDGE_UPDATE_COMMAND
58void bd82x6x_pci_dev_enable_resources(pci_dev_t dev)
59{
60 uint16_t command;
61
Simon Glass31f57c22015-03-05 12:25:15 -070062 command = x86_pci_read_config16(dev, PCI_COMMAND);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070063 command |= PCI_COMMAND_IO;
64#ifdef PCI_BRIDGE_UPDATE_COMMAND
65 /*
66 * If we write to PCI_COMMAND, on some systems this will cause the
67 * ROM and APICs to become invisible.
68 */
69 debug("%x cmd <- %02x\n", dev, command);
Simon Glass31f57c22015-03-05 12:25:15 -070070 x86_pci_write_config16(dev, PCI_COMMAND, command);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070071#else
72 printf("%s cmd <- %02x (NOT WRITTEN!)\n", dev_path(dev), command);
73#endif
74}
75
76void bd82x6x_pci_bus_enable_resources(pci_dev_t dev)
77{
78 uint16_t ctrl;
79
Simon Glass31f57c22015-03-05 12:25:15 -070080 ctrl = x86_pci_read_config16(dev, PCI_BRIDGE_CONTROL);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070081 ctrl |= PCI_COMMAND_IO;
82 ctrl |= PCI_BRIDGE_CTL_VGA;
83 debug("%x bridge ctrl <- %04x\n", dev, ctrl);
Simon Glass31f57c22015-03-05 12:25:15 -070084 x86_pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl);
Simon Glass4e7a6ac2014-11-14 18:18:32 -070085
86 bd82x6x_pci_dev_enable_resources(dev);
87}
88
89int bd82x6x_init_pci_devices(void)
90{
Simon Glass3ac83932014-11-14 18:18:38 -070091 const void *blob = gd->fdt_blob;
Simon Glass72cd0852014-11-14 18:18:35 -070092 struct pci_controller *hose;
Simon Glassbb80be32014-11-24 21:18:16 -070093 struct x86_cpu_priv *cpu;
Simon Glasseffcf062014-11-14 20:56:36 -070094 int sata_node, gma_node;
95 int ret;
Simon Glass72cd0852014-11-14 18:18:35 -070096
97 hose = pci_bus_to_hose(0);
98 lpc_enable(PCH_LPC_DEV);
99 lpc_init(hose, PCH_LPC_DEV);
Simon Glass3ac83932014-11-14 18:18:38 -0700100 sata_node = fdtdec_next_compatible(blob, 0,
101 COMPAT_INTEL_PANTHERPOINT_AHCI);
102 if (sata_node < 0) {
103 debug("%s: Cannot find SATA node\n", __func__);
104 return -EINVAL;
105 }
106 bd82x6x_sata_init(PCH_SATA_DEV, blob, sata_node);
Simon Glass9baeca42014-11-14 18:18:40 -0700107 bd82x6x_usb_ehci_init(PCH_EHCI1_DEV);
108 bd82x6x_usb_ehci_init(PCH_EHCI2_DEV);
Simon Glass72cd0852014-11-14 18:18:35 -0700109
Simon Glassbb80be32014-11-24 21:18:16 -0700110 cpu = calloc(1, sizeof(*cpu));
111 if (!cpu)
112 return -ENOMEM;
113 model_206ax_init(cpu);
114
Simon Glasseffcf062014-11-14 20:56:36 -0700115 gma_node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_GMA);
116 if (gma_node < 0) {
117 debug("%s: Cannot find GMA node\n", __func__);
118 return -EINVAL;
119 }
120 ret = gma_func0_init(PCH_VIDEO_DEV, pci_bus_to_hose(0), blob,
121 gma_node);
122 if (ret)
123 return ret;
124
Simon Glass4e7a6ac2014-11-14 18:18:32 -0700125 return 0;
126}
127
128int bd82x6x_init(void)
129{
Simon Glass3ac83932014-11-14 18:18:38 -0700130 const void *blob = gd->fdt_blob;
131 int sata_node;
132
133 sata_node = fdtdec_next_compatible(blob, 0,
134 COMPAT_INTEL_PANTHERPOINT_AHCI);
135 if (sata_node < 0) {
136 debug("%s: Cannot find SATA node\n", __func__);
137 return -EINVAL;
138 }
139
Simon Glass4e7a6ac2014-11-14 18:18:32 -0700140 bd82x6x_pci_init(PCH_DEV);
Simon Glass3ac83932014-11-14 18:18:38 -0700141 bd82x6x_sata_enable(PCH_SATA_DEV, blob, sata_node);
Simon Glass24774272014-11-24 21:18:18 -0700142 northbridge_enable(PCH_DEV);
143 northbridge_init(PCH_DEV);
Simon Glass4e7a6ac2014-11-14 18:18:32 -0700144
145 return 0;
146}