blob: ae27d854a30ed0747aec82b9aab87bce1a85f498 [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 */
Angel Pons88dcb312021-04-26 17:10:28 +020028 reg8 = get_uint_option("gfx_uma_size", 0); /* 0 for 8MB */
Angel Pons39ff7032020-03-09 21:39:44 +010029
30 /* Ensure the setting is valid */
Arthur Heymans2a0e9982017-01-14 17:32:20 +010031 if (reg8 > 6)
32 reg8 = 0;
Angel Pons39ff7032020-03-09 21:39:44 +010033
Arthur Heymans2a0e9982017-01-14 17:32:20 +010034 /* Select 1M GTT */
Angel Pons39ff7032020-03-09 21:39:44 +010035 pci_write_config16(HOST_BRIDGE, GGC, (1 << 8) | ((reg8 + 3) << 4));
Damien Zammitf7060f12015-11-14 00:59:21 +110036
Damien Zammit51fdb922016-01-18 18:34:52 +110037 printk(BIOS_SPEW, "Set GFX clocks...");
Angel Pons0aeaee72021-03-26 17:57:46 +010038 reg16 = mchbar_read16(MCH_GCFGC);
39 mchbar_write16(MCH_GCFGC, reg16 | 1 << 9);
Damien Zammit51fdb922016-01-18 18:34:52 +110040 reg16 &= ~0x7f;
41 reg16 |= CDCLK_PINEVIEW | CRCLK_PINEVIEW;
42 reg16 &= ~(1 << 9);
Angel Pons0aeaee72021-03-26 17:57:46 +010043 mchbar_write16(MCH_GCFGC, reg16);
Damien Zammitf7060f12015-11-14 00:59:21 +110044
Damien Zammit51fdb922016-01-18 18:34:52 +110045 /* Graphics core */
Angel Pons0aeaee72021-03-26 17:57:46 +010046 reg8 = mchbar_read8(HPLLVCO);
Damien Zammit51fdb922016-01-18 18:34:52 +110047 reg8 &= 0x7;
Damien Zammitf7060f12015-11-14 00:59:21 +110048
Angel Pons39ff7032020-03-09 21:39:44 +010049 reg16 = pci_read_config16(GMCH_IGD, 0xcc) & ~0x1ff;
Damien Zammitf7060f12015-11-14 00:59:21 +110050
Damien Zammit51fdb922016-01-18 18:34:52 +110051 if (reg8 == 0x4) {
52 /* 2666MHz */
53 reg16 |= 0xad;
54 } else if (reg8 == 0) {
55 /* 3200MHz */
56 reg16 |= 0xa0;
57 } else if (reg8 == 1) {
58 /* 4000MHz */
59 reg16 |= 0xad;
60 }
Damien Zammitf7060f12015-11-14 00:59:21 +110061
Angel Pons39ff7032020-03-09 21:39:44 +010062 pci_write_config16(GMCH_IGD, 0xcc, reg16);
Damien Zammit51fdb922016-01-18 18:34:52 +110063
Angel Pons26766fd2020-06-08 12:38:19 +020064 pci_and_config8(GMCH_IGD, 0x62, ~0x3);
65 pci_or_config8(GMCH_IGD, 0x62, 2);
Damien Zammit51fdb922016-01-18 18:34:52 +110066
67 if (config->use_crt) {
68 /* Enable VGA */
Angel Pons0aeaee72021-03-26 17:57:46 +010069 mchbar_setbits32(DACGIOCTRL1, 1 << 15);
Damien Zammit51fdb922016-01-18 18:34:52 +110070 } else {
71 /* Disable VGA */
Angel Pons0aeaee72021-03-26 17:57:46 +010072 mchbar_clrbits32(DACGIOCTRL1, 1 << 15);
Damien Zammit51fdb922016-01-18 18:34:52 +110073 }
74
75 if (config->use_lvds) {
76 /* Enable LVDS */
Angel Pons0aeaee72021-03-26 17:57:46 +010077 reg32 = mchbar_read32(LVDSICR2);
Damien Zammit51fdb922016-01-18 18:34:52 +110078 reg32 &= ~0xf1000000;
Angel Pons39ff7032020-03-09 21:39:44 +010079 reg32 |= 0x90000000;
Angel Pons0aeaee72021-03-26 17:57:46 +010080 mchbar_write32(LVDSICR2, reg32);
81 mchbar_setbits32(IOCKTRR1, 1 << 9);
Damien Zammit51fdb922016-01-18 18:34:52 +110082 } else {
83 /* Disable LVDS */
Angel Pons0aeaee72021-03-26 17:57:46 +010084 mchbar_setbits32(DACGIOCTRL1, 3 << 25);
Damien Zammit51fdb922016-01-18 18:34:52 +110085 }
86
Angel Pons0aeaee72021-03-26 17:57:46 +010087 mchbar_write32(CICTRL, 0xc6db8b5f);
88 mchbar_write16(CISDCTRL, 0x024f);
Damien Zammit51fdb922016-01-18 18:34:52 +110089
Angel Pons0aeaee72021-03-26 17:57:46 +010090 mchbar_clrbits32(DACGIOCTRL1, 0xff);
91 mchbar_setbits32(DACGIOCTRL1, 1 << 5);
Damien Zammit51fdb922016-01-18 18:34:52 +110092
93 /* Legacy backlight control */
Angel Pons39ff7032020-03-09 21:39:44 +010094 pci_write_config8(GMCH_IGD, 0xf4, 0x4c);
Damien Zammit51fdb922016-01-18 18:34:52 +110095}
96
97static void early_misc_setup(void)
98{
Angel Pons0aeaee72021-03-26 17:57:46 +010099 mchbar_read32(HIT0);
100 mchbar_write32(HIT0, 0x00021800);
101 dmibar_write32(0x2c, 0x86000040);
Damien Zammitf7060f12015-11-14 00:59:21 +1100102 pci_write_config32(PCI_DEV(0, 0x1e, 0), 0x18, 0x00020200);
103 pci_write_config32(PCI_DEV(0, 0x1e, 0), 0x18, 0x00000000);
Damien Zammitf7060f12015-11-14 00:59:21 +1100104
Damien Zammit51fdb922016-01-18 18:34:52 +1100105 early_graphics_setup();
Damien Zammitf7060f12015-11-14 00:59:21 +1100106
Angel Pons0aeaee72021-03-26 17:57:46 +0100107 mchbar_read32(HIT4);
108 mchbar_write32(HIT4, 0);
109 mchbar_read32(HIT4);
110 mchbar_write32(HIT4, 1 << 3);
Damien Zammitf7060f12015-11-14 00:59:21 +1100111
Angel Pons39ff7032020-03-09 21:39:44 +0100112 pci_write_config8(LPC_DEV, 0x08, 0x1d);
113 pci_write_config8(LPC_DEV, 0x08, 0x00);
Damien Zammitf7060f12015-11-14 00:59:21 +1100114 RCBA32(0x3410) = 0x00020465;
Arthur Heymans2437fe92019-10-04 13:59:29 +0200115
Damien Zammitf7060f12015-11-14 00:59:21 +1100116 pci_write_config32(PCI_DEV(0, 0x1d, 0), 0xca, 0x1);
117 pci_write_config32(PCI_DEV(0, 0x1d, 1), 0xca, 0x1);
118 pci_write_config32(PCI_DEV(0, 0x1d, 2), 0xca, 0x1);
119 pci_write_config32(PCI_DEV(0, 0x1d, 3), 0xca, 0x1);
120
Angel Pons39ff7032020-03-09 21:39:44 +0100121 RCBA32(0x3100) = 0x00042210;
Damien Zammitf7060f12015-11-14 00:59:21 +1100122 RCBA32(0x3108) = 0x10004321;
123 RCBA32(0x310c) = 0x00214321;
Angel Pons39ff7032020-03-09 21:39:44 +0100124 RCBA32(0x3110) = 1;
Damien Zammitf7060f12015-11-14 00:59:21 +1100125 RCBA32(0x3140) = 0x01460132;
126 RCBA32(0x3142) = 0x02370146;
127 RCBA32(0x3144) = 0x32010237;
128 RCBA32(0x3146) = 0x01463201;
Angel Pons39ff7032020-03-09 21:39:44 +0100129 RCBA32(0x3148) = 0x00000146;
Damien Zammit51fdb922016-01-18 18:34:52 +1100130}
131
132static void pineview_setup_bars(void)
133{
Damien Zammit51fdb922016-01-18 18:34:52 +1100134 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
Angel Pons39ff7032020-03-09 21:39:44 +0100135 pci_write_config8(HOST_BRIDGE, 0x08, 0x69);
Damien Zammit51fdb922016-01-18 18:34:52 +1100136
137 /* Set up all hardcoded northbridge BARs */
Angel Pons24b1d8a2021-01-20 12:00:31 +0100138 pci_write_config32(HOST_BRIDGE, EPBAR, CONFIG_FIXED_EPBAR_MMIO_BASE | 1);
139 pci_write_config32(HOST_BRIDGE, MCHBAR, CONFIG_FIXED_MCHBAR_MMIO_BASE | 1);
140 pci_write_config32(HOST_BRIDGE, DMIBAR, CONFIG_FIXED_DMIBAR_MMIO_BASE | 1);
Angel Pons39ff7032020-03-09 21:39:44 +0100141 pci_write_config32(HOST_BRIDGE, PMIOBAR, DEFAULT_PMIOBAR | 1);
Damien Zammitf7060f12015-11-14 00:59:21 +1100142
143 /* Set C0000-FFFFF to access RAM on both reads and writes */
Angel Pons39ff7032020-03-09 21:39:44 +0100144 pci_write_config8(HOST_BRIDGE, PAM0, 0x30);
145 pci_write_config8(HOST_BRIDGE, PAM1, 0x33);
146 pci_write_config8(HOST_BRIDGE, PAM2, 0x33);
147 pci_write_config8(HOST_BRIDGE, PAM3, 0x33);
148 pci_write_config8(HOST_BRIDGE, PAM4, 0x33);
149 pci_write_config8(HOST_BRIDGE, PAM5, 0x33);
150 pci_write_config8(HOST_BRIDGE, PAM6, 0x33);
Damien Zammitf7060f12015-11-14 00:59:21 +1100151
Damien Zammitf7060f12015-11-14 00:59:21 +1100152 printk(BIOS_DEBUG, " done.\n");
153}
154
Angel Pons39ff7032020-03-09 21:39:44 +0100155void pineview_early_init(void)
Damien Zammitf7060f12015-11-14 00:59:21 +1100156{
157 /* Print some chipset specific information */
158 printk(BIOS_DEBUG, "Intel Pineview northbridge\n");
159
160 /* Setup all BARs required for early PCIe and raminit */
161 pineview_setup_bars();
162
Angel Pons39ff7032020-03-09 21:39:44 +0100163 /* Miscellaneous setup */
Damien Zammit51fdb922016-01-18 18:34:52 +1100164 early_misc_setup();
165
Angel Pons39ff7032020-03-09 21:39:44 +0100166 /* Route port80 to LPC */
Damien Zammitf7060f12015-11-14 00:59:21 +1100167 RCBA32(GCS) &= (~0x04);
168 RCBA32(0x2010) |= (1 << 10);
169}