blob: a2bbaa008332e75d9afe1bc0a81fb8830cb22a00 [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Damien Zammitf7060f12015-11-14 00:59:21 +11002
Damien Zammitf7060f12015-11-14 00:59:21 +11003#include <console/console.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02004#include <device/pci_ops.h>
Damien Zammitf7060f12015-11-14 00:59:21 +11005#include <device/pci_def.h>
Damien Zammitf7060f12015-11-14 00:59:21 +11006#include <northbridge/intel/pineview/pineview.h>
Damien Zammit51fdb922016-01-18 18:34:52 +11007#include <northbridge/intel/pineview/chip.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +02008#include <option.h>
Elyes HAOUAS51401c32019-05-15 21:09:30 +02009#include <types.h>
Damien Zammitf7060f12015-11-14 00:59:21 +110010
Angel Pons39ff7032020-03-09 21:39:44 +010011#define LPC_DEV PCI_DEV(0, 0x1f, 0)
Damien Zammitf7060f12015-11-14 00:59:21 +110012
Angel Pons39ff7032020-03-09 21:39:44 +010013#define CRCLK_PINEVIEW 0x02
14#define CDCLK_PINEVIEW 0x10
Damien Zammit51fdb922016-01-18 18:34:52 +110015
16static void early_graphics_setup(void)
Damien Zammitf7060f12015-11-14 00:59:21 +110017{
18 u8 reg8;
19 u16 reg16;
20 u32 reg32;
21
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030022 const struct device *d0f0 = pcidev_on_root(0, 0);
Damien Zammit51fdb922016-01-18 18:34:52 +110023 const struct northbridge_intel_pineview_config *config = d0f0->chip_info;
Damien Zammitf7060f12015-11-14 00:59:21 +110024
Angel Pons39ff7032020-03-09 21:39:44 +010025 pci_write_config8(HOST_BRIDGE, DEVEN, BOARD_DEVEN);
Arthur Heymans2a0e9982017-01-14 17:32:20 +010026
Angel Pons39ff7032020-03-09 21:39:44 +010027 /* Fetch VRAM size from CMOS option */
Arthur Heymans2a0e9982017-01-14 17:32:20 +010028 if (get_option(&reg8, "gfx_uma_size") != CB_SUCCESS)
29 reg8 = 0; /* 0 for 8MB */
Angel Pons39ff7032020-03-09 21:39:44 +010030
31 /* Ensure the setting is valid */
Arthur Heymans2a0e9982017-01-14 17:32:20 +010032 if (reg8 > 6)
33 reg8 = 0;
Angel Pons39ff7032020-03-09 21:39:44 +010034
Arthur Heymans2a0e9982017-01-14 17:32:20 +010035 /* Select 1M GTT */
Angel Pons39ff7032020-03-09 21:39:44 +010036 pci_write_config16(HOST_BRIDGE, GGC, (1 << 8) | ((reg8 + 3) << 4));
Damien Zammitf7060f12015-11-14 00:59:21 +110037
Damien Zammit51fdb922016-01-18 18:34:52 +110038 printk(BIOS_SPEW, "Set GFX clocks...");
Angel Pons0aeaee72021-03-26 17:57:46 +010039 reg16 = mchbar_read16(MCH_GCFGC);
40 mchbar_write16(MCH_GCFGC, reg16 | 1 << 9);
Damien Zammit51fdb922016-01-18 18:34:52 +110041 reg16 &= ~0x7f;
42 reg16 |= CDCLK_PINEVIEW | CRCLK_PINEVIEW;
43 reg16 &= ~(1 << 9);
Angel Pons0aeaee72021-03-26 17:57:46 +010044 mchbar_write16(MCH_GCFGC, reg16);
Damien Zammitf7060f12015-11-14 00:59:21 +110045
Damien Zammit51fdb922016-01-18 18:34:52 +110046 /* Graphics core */
Angel Pons0aeaee72021-03-26 17:57:46 +010047 reg8 = mchbar_read8(HPLLVCO);
Damien Zammit51fdb922016-01-18 18:34:52 +110048 reg8 &= 0x7;
Damien Zammitf7060f12015-11-14 00:59:21 +110049
Angel Pons39ff7032020-03-09 21:39:44 +010050 reg16 = pci_read_config16(GMCH_IGD, 0xcc) & ~0x1ff;
Damien Zammitf7060f12015-11-14 00:59:21 +110051
Damien Zammit51fdb922016-01-18 18:34:52 +110052 if (reg8 == 0x4) {
53 /* 2666MHz */
54 reg16 |= 0xad;
55 } else if (reg8 == 0) {
56 /* 3200MHz */
57 reg16 |= 0xa0;
58 } else if (reg8 == 1) {
59 /* 4000MHz */
60 reg16 |= 0xad;
61 }
Damien Zammitf7060f12015-11-14 00:59:21 +110062
Angel Pons39ff7032020-03-09 21:39:44 +010063 pci_write_config16(GMCH_IGD, 0xcc, reg16);
Damien Zammit51fdb922016-01-18 18:34:52 +110064
Angel Pons26766fd2020-06-08 12:38:19 +020065 pci_and_config8(GMCH_IGD, 0x62, ~0x3);
66 pci_or_config8(GMCH_IGD, 0x62, 2);
Damien Zammit51fdb922016-01-18 18:34:52 +110067
68 if (config->use_crt) {
69 /* Enable VGA */
Angel Pons0aeaee72021-03-26 17:57:46 +010070 mchbar_setbits32(DACGIOCTRL1, 1 << 15);
Damien Zammit51fdb922016-01-18 18:34:52 +110071 } else {
72 /* Disable VGA */
Angel Pons0aeaee72021-03-26 17:57:46 +010073 mchbar_clrbits32(DACGIOCTRL1, 1 << 15);
Damien Zammit51fdb922016-01-18 18:34:52 +110074 }
75
76 if (config->use_lvds) {
77 /* Enable LVDS */
Angel Pons0aeaee72021-03-26 17:57:46 +010078 reg32 = mchbar_read32(LVDSICR2);
Damien Zammit51fdb922016-01-18 18:34:52 +110079 reg32 &= ~0xf1000000;
Angel Pons39ff7032020-03-09 21:39:44 +010080 reg32 |= 0x90000000;
Angel Pons0aeaee72021-03-26 17:57:46 +010081 mchbar_write32(LVDSICR2, reg32);
82 mchbar_setbits32(IOCKTRR1, 1 << 9);
Damien Zammit51fdb922016-01-18 18:34:52 +110083 } else {
84 /* Disable LVDS */
Angel Pons0aeaee72021-03-26 17:57:46 +010085 mchbar_setbits32(DACGIOCTRL1, 3 << 25);
Damien Zammit51fdb922016-01-18 18:34:52 +110086 }
87
Angel Pons0aeaee72021-03-26 17:57:46 +010088 mchbar_write32(CICTRL, 0xc6db8b5f);
89 mchbar_write16(CISDCTRL, 0x024f);
Damien Zammit51fdb922016-01-18 18:34:52 +110090
Angel Pons0aeaee72021-03-26 17:57:46 +010091 mchbar_clrbits32(DACGIOCTRL1, 0xff);
92 mchbar_setbits32(DACGIOCTRL1, 1 << 5);
Damien Zammit51fdb922016-01-18 18:34:52 +110093
94 /* Legacy backlight control */
Angel Pons39ff7032020-03-09 21:39:44 +010095 pci_write_config8(GMCH_IGD, 0xf4, 0x4c);
Damien Zammit51fdb922016-01-18 18:34:52 +110096}
97
98static void early_misc_setup(void)
99{
Angel Pons0aeaee72021-03-26 17:57:46 +0100100 mchbar_read32(HIT0);
101 mchbar_write32(HIT0, 0x00021800);
102 dmibar_write32(0x2c, 0x86000040);
Damien Zammitf7060f12015-11-14 00:59:21 +1100103 pci_write_config32(PCI_DEV(0, 0x1e, 0), 0x18, 0x00020200);
104 pci_write_config32(PCI_DEV(0, 0x1e, 0), 0x18, 0x00000000);
Damien Zammitf7060f12015-11-14 00:59:21 +1100105
Damien Zammit51fdb922016-01-18 18:34:52 +1100106 early_graphics_setup();
Damien Zammitf7060f12015-11-14 00:59:21 +1100107
Angel Pons0aeaee72021-03-26 17:57:46 +0100108 mchbar_read32(HIT4);
109 mchbar_write32(HIT4, 0);
110 mchbar_read32(HIT4);
111 mchbar_write32(HIT4, 1 << 3);
Damien Zammitf7060f12015-11-14 00:59:21 +1100112
Angel Pons39ff7032020-03-09 21:39:44 +0100113 pci_write_config8(LPC_DEV, 0x08, 0x1d);
114 pci_write_config8(LPC_DEV, 0x08, 0x00);
Damien Zammitf7060f12015-11-14 00:59:21 +1100115 RCBA32(0x3410) = 0x00020465;
Arthur Heymans2437fe92019-10-04 13:59:29 +0200116
Damien Zammitf7060f12015-11-14 00:59:21 +1100117 pci_write_config32(PCI_DEV(0, 0x1d, 0), 0xca, 0x1);
118 pci_write_config32(PCI_DEV(0, 0x1d, 1), 0xca, 0x1);
119 pci_write_config32(PCI_DEV(0, 0x1d, 2), 0xca, 0x1);
120 pci_write_config32(PCI_DEV(0, 0x1d, 3), 0xca, 0x1);
121
Angel Pons39ff7032020-03-09 21:39:44 +0100122 RCBA32(0x3100) = 0x00042210;
Damien Zammitf7060f12015-11-14 00:59:21 +1100123 RCBA32(0x3108) = 0x10004321;
124 RCBA32(0x310c) = 0x00214321;
Angel Pons39ff7032020-03-09 21:39:44 +0100125 RCBA32(0x3110) = 1;
Damien Zammitf7060f12015-11-14 00:59:21 +1100126 RCBA32(0x3140) = 0x01460132;
127 RCBA32(0x3142) = 0x02370146;
128 RCBA32(0x3144) = 0x32010237;
129 RCBA32(0x3146) = 0x01463201;
Angel Pons39ff7032020-03-09 21:39:44 +0100130 RCBA32(0x3148) = 0x00000146;
Damien Zammit51fdb922016-01-18 18:34:52 +1100131}
132
133static void pineview_setup_bars(void)
134{
Damien Zammit51fdb922016-01-18 18:34:52 +1100135 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
Angel Pons39ff7032020-03-09 21:39:44 +0100136 pci_write_config8(HOST_BRIDGE, 0x08, 0x69);
Damien Zammit51fdb922016-01-18 18:34:52 +1100137
138 /* Set up all hardcoded northbridge BARs */
Angel Pons24b1d8a2021-01-20 12:00:31 +0100139 pci_write_config32(HOST_BRIDGE, EPBAR, CONFIG_FIXED_EPBAR_MMIO_BASE | 1);
140 pci_write_config32(HOST_BRIDGE, MCHBAR, CONFIG_FIXED_MCHBAR_MMIO_BASE | 1);
141 pci_write_config32(HOST_BRIDGE, DMIBAR, CONFIG_FIXED_DMIBAR_MMIO_BASE | 1);
Angel Pons39ff7032020-03-09 21:39:44 +0100142 pci_write_config32(HOST_BRIDGE, PMIOBAR, DEFAULT_PMIOBAR | 1);
Damien Zammitf7060f12015-11-14 00:59:21 +1100143
144 /* Set C0000-FFFFF to access RAM on both reads and writes */
Angel Pons39ff7032020-03-09 21:39:44 +0100145 pci_write_config8(HOST_BRIDGE, PAM0, 0x30);
146 pci_write_config8(HOST_BRIDGE, PAM1, 0x33);
147 pci_write_config8(HOST_BRIDGE, PAM2, 0x33);
148 pci_write_config8(HOST_BRIDGE, PAM3, 0x33);
149 pci_write_config8(HOST_BRIDGE, PAM4, 0x33);
150 pci_write_config8(HOST_BRIDGE, PAM5, 0x33);
151 pci_write_config8(HOST_BRIDGE, PAM6, 0x33);
Damien Zammitf7060f12015-11-14 00:59:21 +1100152
Damien Zammitf7060f12015-11-14 00:59:21 +1100153 printk(BIOS_DEBUG, " done.\n");
154}
155
Angel Pons39ff7032020-03-09 21:39:44 +0100156void pineview_early_init(void)
Damien Zammitf7060f12015-11-14 00:59:21 +1100157{
158 /* Print some chipset specific information */
159 printk(BIOS_DEBUG, "Intel Pineview northbridge\n");
160
161 /* Setup all BARs required for early PCIe and raminit */
162 pineview_setup_bars();
163
Angel Pons39ff7032020-03-09 21:39:44 +0100164 /* Miscellaneous setup */
Damien Zammit51fdb922016-01-18 18:34:52 +1100165 early_misc_setup();
166
Angel Pons39ff7032020-03-09 21:39:44 +0100167 /* Route port80 to LPC */
Damien Zammitf7060f12015-11-14 00:59:21 +1100168 RCBA32(GCS) &= (~0x04);
169 RCBA32(0x2010) |= (1 << 10);
170}