]> git.sur5r.net Git - u-boot/blob - arch/x86/cpu/ivybridge/early_init.c
x86: ivybridge: Move LPC and PCH init into northbridge probe()
[u-boot] / arch / x86 / cpu / ivybridge / early_init.c
1 /*
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>
11 #include <dm.h>
12 #include <asm/io.h>
13 #include <asm/pci.h>
14 #include <asm/arch/pch.h>
15 #include <asm/arch/sandybridge.h>
16
17 static void sandybridge_setup_lpc_bars(pci_dev_t lpc_dev)
18 {
19         /* Setting up Southbridge. In the northbridge code. */
20         debug("Setting up static southbridge registers\n");
21         x86_pci_write_config32(lpc_dev, PCH_RCBA_BASE, DEFAULT_RCBA | 1);
22
23         x86_pci_write_config32(lpc_dev, PMBASE, DEFAULT_PMBASE | 1);
24         x86_pci_write_config8(lpc_dev, ACPI_CNTL, 0x80); /* Enable ACPI BAR */
25
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
31 static void sandybridge_setup_northbridge_bars(struct udevice *dev)
32 {
33         /* Set up all hardcoded northbridge BARs */
34         debug("Setting up static registers\n");
35         dm_pci_write_config32(dev, EPBAR, DEFAULT_EPBAR | 1);
36         dm_pci_write_config32(dev, EPBAR + 4, (0LL + DEFAULT_EPBAR) >> 32);
37         dm_pci_write_config32(dev, MCHBAR, DEFAULT_MCHBAR | 1);
38         dm_pci_write_config32(dev, MCHBAR + 4, (0LL + DEFAULT_MCHBAR) >> 32);
39         /* 64MB - busses 0-63 */
40         dm_pci_write_config32(dev, PCIEXBAR, DEFAULT_PCIEXBAR | 5);
41         dm_pci_write_config32(dev, PCIEXBAR + 4,
42                               (0LL + DEFAULT_PCIEXBAR) >> 32);
43         dm_pci_write_config32(dev, DMIBAR, DEFAULT_DMIBAR | 1);
44         dm_pci_write_config32(dev, DMIBAR + 4, (0LL + DEFAULT_DMIBAR) >> 32);
45
46         /* Set C0000-FFFFF to access RAM on both reads and writes */
47         dm_pci_write_config8(dev, PAM0, 0x30);
48         dm_pci_write_config8(dev, PAM1, 0x33);
49         dm_pci_write_config8(dev, PAM2, 0x33);
50         dm_pci_write_config8(dev, PAM3, 0x33);
51         dm_pci_write_config8(dev, PAM4, 0x33);
52         dm_pci_write_config8(dev, PAM5, 0x33);
53         dm_pci_write_config8(dev, PAM6, 0x33);
54 }
55
56 static void sandybridge_setup_graphics(pci_dev_t pch_dev, pci_dev_t video_dev)
57 {
58         u32 reg32;
59         u16 reg16;
60         u8 reg8;
61
62         reg16 = x86_pci_read_config16(video_dev, PCI_DEVICE_ID);
63         switch (reg16) {
64         case 0x0102: /* GT1 Desktop */
65         case 0x0106: /* GT1 Mobile */
66         case 0x010a: /* GT1 Server */
67         case 0x0112: /* GT2 Desktop */
68         case 0x0116: /* GT2 Mobile */
69         case 0x0122: /* GT2 Desktop >=1.3GHz */
70         case 0x0126: /* GT2 Mobile >=1.3GHz */
71         case 0x0156: /* IvyBridge */
72         case 0x0166: /* IvyBridge */
73                 break;
74         default:
75                 debug("Graphics not supported by this CPU/chipset\n");
76                 return;
77         }
78
79         debug("Initialising Graphics\n");
80
81         /* Setup IGD memory by setting GGC[7:3] = 1 for 32MB */
82         reg16 = x86_pci_read_config16(pch_dev, GGC);
83         reg16 &= ~0x00f8;
84         reg16 |= 1 << 3;
85         /* Program GTT memory by setting GGC[9:8] = 2MB */
86         reg16 &= ~0x0300;
87         reg16 |= 2 << 8;
88         /* Enable VGA decode */
89         reg16 &= ~0x0002;
90         x86_pci_write_config16(pch_dev, GGC, reg16);
91
92         /* Enable 256MB aperture */
93         reg8 = x86_pci_read_config8(video_dev, MSAC);
94         reg8 &= ~0x06;
95         reg8 |= 0x02;
96         x86_pci_write_config8(video_dev, MSAC, reg8);
97
98         /* Erratum workarounds */
99         reg32 = readl(MCHBAR_REG(0x5f00));
100         reg32 |= (1 << 9) | (1 << 10);
101         writel(reg32, MCHBAR_REG(0x5f00));
102
103         /* Enable SA Clock Gating */
104         reg32 = readl(MCHBAR_REG(0x5f00));
105         writel(reg32 | 1, MCHBAR_REG(0x5f00));
106
107         /* GPU RC6 workaround for sighting 366252 */
108         reg32 = readl(MCHBAR_REG(0x5d14));
109         reg32 |= (1 << 31);
110         writel(reg32, MCHBAR_REG(0x5d14));
111
112         /* VLW */
113         reg32 = readl(MCHBAR_REG(0x6120));
114         reg32 &= ~(1 << 0);
115         writel(reg32, MCHBAR_REG(0x6120));
116
117         reg32 = readl(MCHBAR_REG(0x5418));
118         reg32 |= (1 << 4) | (1 << 5);
119         writel(reg32, MCHBAR_REG(0x5418));
120 }
121
122 void sandybridge_early_init(int chipset_type)
123 {
124         pci_dev_t pch_dev = PCH_DEV;
125         pci_dev_t video_dev = PCH_VIDEO_DEV;
126
127         /* Device Enable */
128         x86_pci_write_config32(pch_dev, DEVEN, DEVEN_HOST | DEVEN_IGD);
129
130         sandybridge_setup_graphics(pch_dev, video_dev);
131 }
132
133 static int bd82x6x_northbridge_probe(struct udevice *dev)
134 {
135         const int chipset_type = SANDYBRIDGE_MOBILE;
136         u32 capid0_a;
137         u8 reg8;
138
139         if (gd->flags & GD_FLG_RELOC)
140                 return 0;
141
142         /* Device ID Override Enable should be done very early */
143         dm_pci_read_config32(dev, 0xe4, &capid0_a);
144         if (capid0_a & (1 << 10)) {
145                 dm_pci_read_config8(dev, 0xf3, &reg8);
146                 reg8 &= ~7; /* Clear 2:0 */
147
148                 if (chipset_type == SANDYBRIDGE_MOBILE)
149                         reg8 |= 1; /* Set bit 0 */
150
151                 dm_pci_write_config8(dev, 0xf3, reg8);
152         }
153
154         sandybridge_setup_lpc_bars(PCH_LPC_DEV);
155
156         sandybridge_setup_northbridge_bars(dev);
157
158         return 0;
159 }
160
161 static const struct udevice_id bd82x6x_northbridge_ids[] = {
162         { .compatible = "intel,bd82x6x-northbridge" },
163         { }
164 };
165
166 U_BOOT_DRIVER(bd82x6x_northbridge_drv) = {
167         .name           = "bd82x6x_northbridge",
168         .id             = UCLASS_NORTHBRIDGE,
169         .of_match       = bd82x6x_northbridge_ids,
170         .probe          = bd82x6x_northbridge_probe,
171 };