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