blob: 89744289a23c90d83710c59722e2db1eed8208c6 [file] [log] [blame]
Damien Zammitf7060f12015-11-14 00:59:21 +11001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2015 Damien Zammit <damien@zamaudio.com>
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; either version 2 of
9 * the License, or (at your option) any later version.
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.
15 */
16
17#include <stdint.h>
18#include <stdlib.h>
19#include <console/console.h>
20#include <arch/io.h>
21#include <device/pci_def.h>
Damien Zammit51fdb922016-01-18 18:34:52 +110022#include <device/pci.h>
Damien Zammitf7060f12015-11-14 00:59:21 +110023#include <halt.h>
24#include <string.h>
25#include <northbridge/intel/pineview/pineview.h>
Damien Zammit51fdb922016-01-18 18:34:52 +110026#include <northbridge/intel/pineview/chip.h>
Arthur Heymans2a0e9982017-01-14 17:32:20 +010027#include <pc80/mc146818rtc.h>
Damien Zammitf7060f12015-11-14 00:59:21 +110028
29#define LPC PCI_DEV(0, 0x1f, 0)
30#define D0F0 PCI_DEV(0, 0, 0)
31
Damien Zammit51fdb922016-01-18 18:34:52 +110032#define PCI_GCFC 0xf0
33#define MCH_GCFGC 0xc8c
34#define CRCLK_PINEVIEW 0x02
35#define CDCLK_PINEVIEW 0x10
36#define MCH_HPLLVCO 0xc38
37
38static void early_graphics_setup(void)
Damien Zammitf7060f12015-11-14 00:59:21 +110039{
40 u8 reg8;
41 u16 reg16;
42 u32 reg32;
43
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030044 const struct device *d0f0 = pcidev_on_root(0, 0);
Damien Zammit51fdb922016-01-18 18:34:52 +110045 const struct northbridge_intel_pineview_config *config = d0f0->chip_info;
Damien Zammitf7060f12015-11-14 00:59:21 +110046
Damien Zammit51fdb922016-01-18 18:34:52 +110047 pci_write_config8(D0F0, DEVEN, BOARD_DEVEN);
Arthur Heymans2a0e9982017-01-14 17:32:20 +010048
49 /* vram size from cmos option */
50 if (get_option(&reg8, "gfx_uma_size") != CB_SUCCESS)
51 reg8 = 0; /* 0 for 8MB */
52 /* make sure no invalid setting is used */
53 if (reg8 > 6)
54 reg8 = 0;
55 /* Select 1M GTT */
56 pci_write_config16(PCI_DEV(0, 0x00, 0), GGC, (1 << 8)
57 | ((reg8 + 3) << 4));
Damien Zammitf7060f12015-11-14 00:59:21 +110058
Damien Zammit51fdb922016-01-18 18:34:52 +110059 printk(BIOS_SPEW, "Set GFX clocks...");
60 reg16 = MCHBAR16(MCH_GCFGC);
61 MCHBAR16(MCH_GCFGC) = reg16 | (1 << 9);
62 reg16 &= ~0x7f;
63 reg16 |= CDCLK_PINEVIEW | CRCLK_PINEVIEW;
64 reg16 &= ~(1 << 9);
65 MCHBAR16(MCH_GCFGC) = reg16;
Damien Zammitf7060f12015-11-14 00:59:21 +110066
Damien Zammit51fdb922016-01-18 18:34:52 +110067 /* Graphics core */
68 reg8 = MCHBAR8(MCH_HPLLVCO);
69 reg8 &= 0x7;
Damien Zammitf7060f12015-11-14 00:59:21 +110070
Damien Zammit51fdb922016-01-18 18:34:52 +110071 reg16 = pci_read_config16(PCI_DEV(0,2,0), 0xcc) & ~0x1ff;
Damien Zammitf7060f12015-11-14 00:59:21 +110072
Damien Zammit51fdb922016-01-18 18:34:52 +110073 if (reg8 == 0x4) {
74 /* 2666MHz */
75 reg16 |= 0xad;
76 } else if (reg8 == 0) {
77 /* 3200MHz */
78 reg16 |= 0xa0;
79 } else if (reg8 == 1) {
80 /* 4000MHz */
81 reg16 |= 0xad;
82 }
Damien Zammitf7060f12015-11-14 00:59:21 +110083
Damien Zammit51fdb922016-01-18 18:34:52 +110084 pci_write_config16(PCI_DEV(0,2,0), 0xcc, reg16);
85
86 pci_write_config8(PCI_DEV(0,2,0), 0x62,
87 pci_read_config8(PCI_DEV(0,2,0), 0x62) & ~0x3);
88 pci_write_config8(PCI_DEV(0,2,0), 0x62,
89 pci_read_config8(PCI_DEV(0,2,0), 0x62) | 2);
90
91 if (config->use_crt) {
92 /* Enable VGA */
93 MCHBAR32(0xb08) = MCHBAR32(0xb08) | (1 << 15);
94 } else {
95 /* Disable VGA */
96 MCHBAR32(0xb08) = MCHBAR32(0xb08) & ~(1 << 15);
97 }
98
99 if (config->use_lvds) {
100 /* Enable LVDS */
101 reg32 = MCHBAR32(0x3004);
102 reg32 &= ~0xf1000000;
103 reg32 |= 0x90000000;
104 MCHBAR32(0x3004) = reg32;
105 MCHBAR32(0x3008) = MCHBAR32(0x3008) | (1 << 9);
106 } else {
107 /* Disable LVDS */
108 MCHBAR32(0xb08) = MCHBAR32(0xb08) | (3 << 25);
109 }
110
111 MCHBAR32(0xff4) = 0x0c6db8b5f;
112 MCHBAR16(0xff8) = 0x24f;
113
114 MCHBAR32(0xb08) = MCHBAR32(0xb08) & 0xffffff00;
115 MCHBAR32(0xb08) = MCHBAR32(0xb08) | (1 << 5);
116
117 /* Legacy backlight control */
118 pci_write_config8(PCI_DEV(0, 2, 0), 0xf4, 0x4c);
119}
120
121static void early_misc_setup(void)
122{
123 u32 reg32;
Damien Zammitf7060f12015-11-14 00:59:21 +1100124
125 reg32 = MCHBAR32(0x30);
126 MCHBAR32(0x30) = 0x21800;
127 DMIBAR32(0x2c) = 0x86000040;
Damien Zammitf7060f12015-11-14 00:59:21 +1100128 pci_write_config32(PCI_DEV(0, 0x1e, 0), 0x18, 0x00020200);
129 pci_write_config32(PCI_DEV(0, 0x1e, 0), 0x18, 0x00000000);
Damien Zammitf7060f12015-11-14 00:59:21 +1100130
Damien Zammit51fdb922016-01-18 18:34:52 +1100131 early_graphics_setup();
Damien Zammitf7060f12015-11-14 00:59:21 +1100132
Damien Zammitf7060f12015-11-14 00:59:21 +1100133 reg32 = MCHBAR32(0x40);
134 MCHBAR32(0x40) = 0x0;
135 reg32 = MCHBAR32(0x40);
136 MCHBAR32(0x40) = 0x8;
137
138 pci_write_config8(LPC, 0x8, 0x1d);
139 pci_write_config8(LPC, 0x8, 0x0);
140 RCBA32(0x3410) = 0x00020465;
141 RCBA32(0x88) = 0x0011d000;
142 RCBA32(0x1fc) = 0x60f;
143 RCBA32(0x1f4) = 0x86000040;
144 RCBA32(0x214) = 0x10030509;
145 RCBA32(0x218) = 0x00020504;
146 RCBA32(0x220) = 0xc5;
147 RCBA32(0x3430) = 0x1;
148 RCBA32(0x2027) = 0x38f6a70d;
149 RCBA16(0x3e08) = 0x0080;
150 RCBA16(0x3e48) = 0x0080;
151 RCBA32(0x3e0e) = 0x00000080;
152 RCBA32(0x3e4e) = 0x00000080;
153 RCBA32(0x2034) = 0xb24577cc;
154 RCBA32(0x1c) = 0x03128010;
155 RCBA32(0x2010) = 0x400;
156 RCBA32(0x3400) = 0x4;
157 RCBA32(0x2080) = 0x18006007;
158 RCBA32(0x20a0) = 0x18006007;
159 RCBA32(0x20c0) = 0x18006007;
160 RCBA32(0x20e0) = 0x18006007;
161
162 pci_write_config32(PCI_DEV(0, 0x1d, 0), 0xca, 0x1);
163 pci_write_config32(PCI_DEV(0, 0x1d, 1), 0xca, 0x1);
164 pci_write_config32(PCI_DEV(0, 0x1d, 2), 0xca, 0x1);
165 pci_write_config32(PCI_DEV(0, 0x1d, 3), 0xca, 0x1);
166
167 RCBA32(0x3100) = 0x42210;
168 RCBA32(0x3108) = 0x10004321;
169 RCBA32(0x310c) = 0x00214321;
170 RCBA32(0x3110) = 0x1;
171 RCBA32(0x3140) = 0x01460132;
172 RCBA32(0x3142) = 0x02370146;
173 RCBA32(0x3144) = 0x32010237;
174 RCBA32(0x3146) = 0x01463201;
175 RCBA32(0x3148) = 0x146;
Damien Zammit51fdb922016-01-18 18:34:52 +1100176}
177
178static void pineview_setup_bars(void)
179{
180 /* Setting up Southbridge. In the northbridge code. */
181 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
182 pci_write_config32(LPC, RCBA, (uintptr_t)DEFAULT_RCBA | 1);
183 pci_write_config32(LPC, PMBASE, DEFAULT_PMBASE | 1);
Elyes HAOUASa342f392018-10-17 10:56:26 +0200184 pci_write_config8(LPC, 0x44 /* ACPI_CNTL */, 0x80); /* Enable ACPI */
Damien Zammit51fdb922016-01-18 18:34:52 +1100185 pci_write_config32(LPC, GPIOBASE, DEFAULT_GPIOBASE | 1);
Elyes HAOUASa342f392018-10-17 10:56:26 +0200186 pci_write_config8(LPC, 0x4c /* GC */, 0x10); /* Enable GPIOs */
Damien Zammit51fdb922016-01-18 18:34:52 +1100187 pci_write_config32(LPC, 0x88, 0x007c0291);
188
189 pci_write_config32(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
190 printk(BIOS_DEBUG, " done.\n");
191
192 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
193 RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */
194 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
195 printk(BIOS_DEBUG, " done.\n");
196
197 /* Enable upper 128bytes of CMOS */
198 RCBA32(0x3400) = (1 << 2);
199
200 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
201 pci_write_config8(D0F0, 0x8, 0x69);
202
203 /* Set up all hardcoded northbridge BARs */
204 pci_write_config32(D0F0, EPBAR, DEFAULT_EPBAR | 1);
205 pci_write_config32(D0F0, MCHBAR, (uintptr_t)DEFAULT_MCHBAR | 1);
206 pci_write_config32(D0F0, DMIBAR, (uintptr_t)DEFAULT_DMIBAR | 1);
207 pci_write_config32(D0F0, PMIOBAR, (uintptr_t)0x400 | 1);
Damien Zammitf7060f12015-11-14 00:59:21 +1100208
209 /* Set C0000-FFFFF to access RAM on both reads and writes */
210 pci_write_config8(D0F0, PAM0, 0x30);
211 pci_write_config8(D0F0, PAM1, 0x33);
212 pci_write_config8(D0F0, PAM2, 0x33);
213 pci_write_config8(D0F0, PAM3, 0x33);
214 pci_write_config8(D0F0, PAM4, 0x33);
215 pci_write_config8(D0F0, PAM5, 0x33);
216 pci_write_config8(D0F0, PAM6, 0x33);
217
Damien Zammitf7060f12015-11-14 00:59:21 +1100218 printk(BIOS_DEBUG, " done.\n");
219}
220
221void pineview_early_initialization(void)
222{
223 /* Print some chipset specific information */
224 printk(BIOS_DEBUG, "Intel Pineview northbridge\n");
225
226 /* Setup all BARs required for early PCIe and raminit */
227 pineview_setup_bars();
228
Damien Zammit51fdb922016-01-18 18:34:52 +1100229 /* Miscellaneous set up */
230 early_misc_setup();
231
Damien Zammitf7060f12015-11-14 00:59:21 +1100232 /* Change port80 to LPC */
233 RCBA32(GCS) &= (~0x04);
234 RCBA32(0x2010) |= (1 << 10);
235}