blob: 945ae2dfcd89604de78b5c5fdcc4917ca1ef9ac5 [file] [log] [blame]
Simon Glass30580fc2014-11-12 22:42:23 -07001/*
2 * From Coreboot
3 *
4 * Copyright (C) 2007-2010 coresystems GmbH
5 * Copyright (C) 2011 Google Inc
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#include <common.h>
Simon Glass061e9ea2016-01-17 16:11:15 -070011#include <dm.h>
Simon Glass30580fc2014-11-12 22:42:23 -070012#include <asm/io.h>
13#include <asm/pci.h>
14#include <asm/arch/pch.h>
15#include <asm/arch/sandybridge.h>
16
17static void sandybridge_setup_bars(pci_dev_t pch_dev, pci_dev_t lpc_dev)
18{
19 /* Setting up Southbridge. In the northbridge code. */
20 debug("Setting up static southbridge registers\n");
Simon Glass240d06d2015-03-05 12:25:15 -070021 x86_pci_write_config32(lpc_dev, PCH_RCBA_BASE, DEFAULT_RCBA | 1);
Simon Glass30580fc2014-11-12 22:42:23 -070022
Simon Glass240d06d2015-03-05 12:25:15 -070023 x86_pci_write_config32(lpc_dev, PMBASE, DEFAULT_PMBASE | 1);
24 x86_pci_write_config8(lpc_dev, ACPI_CNTL, 0x80); /* Enable ACPI BAR */
Simon Glass30580fc2014-11-12 22:42:23 -070025
26 debug("Disabling watchdog reboot\n");
27 setbits_le32(RCB_REG(GCS), 1 >> 5); /* No reset */
28 outw(1 << 11, DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
29
30 /* Set up all hardcoded northbridge BARs */
31 debug("Setting up static registers\n");
Simon Glass240d06d2015-03-05 12:25:15 -070032 x86_pci_write_config32(pch_dev, EPBAR, DEFAULT_EPBAR | 1);
33 x86_pci_write_config32(pch_dev, EPBAR + 4, (0LL + DEFAULT_EPBAR) >> 32);
34 x86_pci_write_config32(pch_dev, MCHBAR, DEFAULT_MCHBAR | 1);
35 x86_pci_write_config32(pch_dev, MCHBAR + 4,
36 (0LL + DEFAULT_MCHBAR) >> 32);
Simon Glass30580fc2014-11-12 22:42:23 -070037 /* 64MB - busses 0-63 */
Simon Glass240d06d2015-03-05 12:25:15 -070038 x86_pci_write_config32(pch_dev, PCIEXBAR, DEFAULT_PCIEXBAR | 5);
39 x86_pci_write_config32(pch_dev, PCIEXBAR + 4,
40 (0LL + DEFAULT_PCIEXBAR) >> 32);
41 x86_pci_write_config32(pch_dev, DMIBAR, DEFAULT_DMIBAR | 1);
42 x86_pci_write_config32(pch_dev, DMIBAR + 4,
43 (0LL + DEFAULT_DMIBAR) >> 32);
Simon Glass30580fc2014-11-12 22:42:23 -070044
45 /* Set C0000-FFFFF to access RAM on both reads and writes */
Simon Glass240d06d2015-03-05 12:25:15 -070046 x86_pci_write_config8(pch_dev, PAM0, 0x30);
47 x86_pci_write_config8(pch_dev, PAM1, 0x33);
48 x86_pci_write_config8(pch_dev, PAM2, 0x33);
49 x86_pci_write_config8(pch_dev, PAM3, 0x33);
50 x86_pci_write_config8(pch_dev, PAM4, 0x33);
51 x86_pci_write_config8(pch_dev, PAM5, 0x33);
52 x86_pci_write_config8(pch_dev, PAM6, 0x33);
Simon Glass30580fc2014-11-12 22:42:23 -070053}
54
55static void sandybridge_setup_graphics(pci_dev_t pch_dev, pci_dev_t video_dev)
56{
57 u32 reg32;
58 u16 reg16;
59 u8 reg8;
60
Simon Glass240d06d2015-03-05 12:25:15 -070061 reg16 = x86_pci_read_config16(video_dev, PCI_DEVICE_ID);
Simon Glass30580fc2014-11-12 22:42:23 -070062 switch (reg16) {
63 case 0x0102: /* GT1 Desktop */
64 case 0x0106: /* GT1 Mobile */
65 case 0x010a: /* GT1 Server */
66 case 0x0112: /* GT2 Desktop */
67 case 0x0116: /* GT2 Mobile */
68 case 0x0122: /* GT2 Desktop >=1.3GHz */
69 case 0x0126: /* GT2 Mobile >=1.3GHz */
70 case 0x0156: /* IvyBridge */
71 case 0x0166: /* IvyBridge */
72 break;
73 default:
74 debug("Graphics not supported by this CPU/chipset\n");
75 return;
76 }
77
78 debug("Initialising Graphics\n");
79
80 /* Setup IGD memory by setting GGC[7:3] = 1 for 32MB */
Simon Glass240d06d2015-03-05 12:25:15 -070081 reg16 = x86_pci_read_config16(pch_dev, GGC);
Simon Glass30580fc2014-11-12 22:42:23 -070082 reg16 &= ~0x00f8;
83 reg16 |= 1 << 3;
84 /* Program GTT memory by setting GGC[9:8] = 2MB */
85 reg16 &= ~0x0300;
86 reg16 |= 2 << 8;
87 /* Enable VGA decode */
88 reg16 &= ~0x0002;
Simon Glass240d06d2015-03-05 12:25:15 -070089 x86_pci_write_config16(pch_dev, GGC, reg16);
Simon Glass30580fc2014-11-12 22:42:23 -070090
91 /* Enable 256MB aperture */
Simon Glass240d06d2015-03-05 12:25:15 -070092 reg8 = x86_pci_read_config8(video_dev, MSAC);
Simon Glass30580fc2014-11-12 22:42:23 -070093 reg8 &= ~0x06;
94 reg8 |= 0x02;
Simon Glass240d06d2015-03-05 12:25:15 -070095 x86_pci_write_config8(video_dev, MSAC, reg8);
Simon Glass30580fc2014-11-12 22:42:23 -070096
97 /* Erratum workarounds */
98 reg32 = readl(MCHBAR_REG(0x5f00));
99 reg32 |= (1 << 9) | (1 << 10);
100 writel(reg32, MCHBAR_REG(0x5f00));
101
102 /* Enable SA Clock Gating */
103 reg32 = readl(MCHBAR_REG(0x5f00));
104 writel(reg32 | 1, MCHBAR_REG(0x5f00));
105
106 /* GPU RC6 workaround for sighting 366252 */
107 reg32 = readl(MCHBAR_REG(0x5d14));
108 reg32 |= (1 << 31);
109 writel(reg32, MCHBAR_REG(0x5d14));
110
111 /* VLW */
112 reg32 = readl(MCHBAR_REG(0x6120));
113 reg32 &= ~(1 << 0);
114 writel(reg32, MCHBAR_REG(0x6120));
115
116 reg32 = readl(MCHBAR_REG(0x5418));
117 reg32 |= (1 << 4) | (1 << 5);
118 writel(reg32, MCHBAR_REG(0x5418));
119}
120
121void sandybridge_early_init(int chipset_type)
122{
123 pci_dev_t pch_dev = PCH_DEV;
124 pci_dev_t video_dev = PCH_VIDEO_DEV;
125 pci_dev_t lpc_dev = PCH_LPC_DEV;
126 u32 capid0_a;
127 u8 reg8;
128
129 /* Device ID Override Enable should be done very early */
Simon Glass240d06d2015-03-05 12:25:15 -0700130 capid0_a = x86_pci_read_config32(pch_dev, 0xe4);
Simon Glass30580fc2014-11-12 22:42:23 -0700131 if (capid0_a & (1 << 10)) {
Simon Glass240d06d2015-03-05 12:25:15 -0700132 reg8 = x86_pci_read_config8(pch_dev, 0xf3);
Simon Glass30580fc2014-11-12 22:42:23 -0700133 reg8 &= ~7; /* Clear 2:0 */
134
135 if (chipset_type == SANDYBRIDGE_MOBILE)
136 reg8 |= 1; /* Set bit 0 */
137
Simon Glass240d06d2015-03-05 12:25:15 -0700138 x86_pci_write_config8(pch_dev, 0xf3, reg8);
Simon Glass30580fc2014-11-12 22:42:23 -0700139 }
140
141 /* Setup all BARs required for early PCIe and raminit */
142 sandybridge_setup_bars(pch_dev, lpc_dev);
143
144 /* Device Enable */
Simon Glass240d06d2015-03-05 12:25:15 -0700145 x86_pci_write_config32(pch_dev, DEVEN, DEVEN_HOST | DEVEN_IGD);
Simon Glass30580fc2014-11-12 22:42:23 -0700146
147 sandybridge_setup_graphics(pch_dev, video_dev);
148}
Simon Glass061e9ea2016-01-17 16:11:15 -0700149
150static int bd82x6x_northbridge_probe(struct udevice *dev)
151{
152 return 0;
153}
154
155static const struct udevice_id bd82x6x_northbridge_ids[] = {
156 { .compatible = "intel,bd82x6x-northbridge" },
157 { }
158};
159
160U_BOOT_DRIVER(bd82x6x_northbridge_drv) = {
161 .name = "bd82x6x_northbridge",
162 .id = UCLASS_NORTHBRIDGE,
163 .of_match = bd82x6x_northbridge_ids,
164 .probe = bd82x6x_northbridge_probe,
165};