blob: 72f2ed4d712c929210450ff6d5383eaed899cbc5 [file] [log] [blame]
Simon Glass17f1c402014-11-14 18:18:32 -07001/*
2 * Copyright (C) 2014 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
Simon Glass17f1c402014-11-14 18:18:32 -07006#include <common.h>
Simon Glasse0e7b362015-03-05 12:25:33 -07007#include <dm.h>
Simon Glass17f1c402014-11-14 18:18:32 -07008#include <errno.h>
9#include <fdtdec.h>
10#include <malloc.h>
Simon Glass32761632016-01-18 20:19:21 -070011#include <pch.h>
Simon Glass17f1c402014-11-14 18:18:32 -070012#include <asm/lapic.h>
13#include <asm/pci.h>
14#include <asm/arch/bd82x6x.h>
15#include <asm/arch/model_206ax.h>
16#include <asm/arch/pch.h>
17#include <asm/arch/sandybridge.h>
18
Simon Glass32761632016-01-18 20:19:21 -070019#define BIOS_CTRL 0xdc
20
Simon Glass17f1c402014-11-14 18:18:32 -070021void bd82x6x_pci_init(pci_dev_t dev)
22{
23 u16 reg16;
24 u8 reg8;
25
26 debug("bd82x6x PCI init.\n");
27 /* Enable Bus Master */
Simon Glass240d06d2015-03-05 12:25:15 -070028 reg16 = x86_pci_read_config16(dev, PCI_COMMAND);
Simon Glass17f1c402014-11-14 18:18:32 -070029 reg16 |= PCI_COMMAND_MASTER;
Simon Glass240d06d2015-03-05 12:25:15 -070030 x86_pci_write_config16(dev, PCI_COMMAND, reg16);
Simon Glass17f1c402014-11-14 18:18:32 -070031
32 /* This device has no interrupt */
Simon Glass240d06d2015-03-05 12:25:15 -070033 x86_pci_write_config8(dev, INTR, 0xff);
Simon Glass17f1c402014-11-14 18:18:32 -070034
35 /* disable parity error response and SERR */
Simon Glass240d06d2015-03-05 12:25:15 -070036 reg16 = x86_pci_read_config16(dev, BCTRL);
Simon Glass17f1c402014-11-14 18:18:32 -070037 reg16 &= ~(1 << 0);
38 reg16 &= ~(1 << 1);
Simon Glass240d06d2015-03-05 12:25:15 -070039 x86_pci_write_config16(dev, BCTRL, reg16);
Simon Glass17f1c402014-11-14 18:18:32 -070040
41 /* Master Latency Count must be set to 0x04! */
Simon Glass240d06d2015-03-05 12:25:15 -070042 reg8 = x86_pci_read_config8(dev, SMLT);
Simon Glass17f1c402014-11-14 18:18:32 -070043 reg8 &= 0x07;
44 reg8 |= (0x04 << 3);
Simon Glass240d06d2015-03-05 12:25:15 -070045 x86_pci_write_config8(dev, SMLT, reg8);
Simon Glass17f1c402014-11-14 18:18:32 -070046
47 /* Will this improve throughput of bus masters? */
Simon Glass240d06d2015-03-05 12:25:15 -070048 x86_pci_write_config8(dev, PCI_MIN_GNT, 0x06);
Simon Glass17f1c402014-11-14 18:18:32 -070049
50 /* Clear errors in status registers */
Simon Glass240d06d2015-03-05 12:25:15 -070051 reg16 = x86_pci_read_config16(dev, PSTS);
Simon Glass17f1c402014-11-14 18:18:32 -070052 /* reg16 |= 0xf900; */
Simon Glass240d06d2015-03-05 12:25:15 -070053 x86_pci_write_config16(dev, PSTS, reg16);
Simon Glass17f1c402014-11-14 18:18:32 -070054
Simon Glass240d06d2015-03-05 12:25:15 -070055 reg16 = x86_pci_read_config16(dev, SECSTS);
Simon Glass17f1c402014-11-14 18:18:32 -070056 /* reg16 |= 0xf900; */
Simon Glass240d06d2015-03-05 12:25:15 -070057 x86_pci_write_config16(dev, SECSTS, reg16);
Simon Glass17f1c402014-11-14 18:18:32 -070058}
59
Simon Glasse0e7b362015-03-05 12:25:33 -070060static int bd82x6x_probe(struct udevice *dev)
Simon Glass17f1c402014-11-14 18:18:32 -070061{
Simon Glasscd0adb32014-11-14 18:18:38 -070062 const void *blob = gd->fdt_blob;
Simon Glass06409c92014-11-14 18:18:35 -070063 struct pci_controller *hose;
Simon Glasscf46d372014-11-24 21:18:16 -070064 struct x86_cpu_priv *cpu;
Simon Glassd90f8e12014-11-14 20:56:36 -070065 int sata_node, gma_node;
66 int ret;
Simon Glass06409c92014-11-14 18:18:35 -070067
Simon Glass044f1a02016-01-17 16:11:10 -070068 if (!(gd->flags & GD_FLG_RELOC))
69 return 0;
70
Simon Glass06409c92014-11-14 18:18:35 -070071 hose = pci_bus_to_hose(0);
72 lpc_enable(PCH_LPC_DEV);
73 lpc_init(hose, PCH_LPC_DEV);
Simon Glasscd0adb32014-11-14 18:18:38 -070074 sata_node = fdtdec_next_compatible(blob, 0,
75 COMPAT_INTEL_PANTHERPOINT_AHCI);
76 if (sata_node < 0) {
77 debug("%s: Cannot find SATA node\n", __func__);
78 return -EINVAL;
79 }
80 bd82x6x_sata_init(PCH_SATA_DEV, blob, sata_node);
Simon Glass194d7572014-11-14 18:18:40 -070081 bd82x6x_usb_ehci_init(PCH_EHCI1_DEV);
82 bd82x6x_usb_ehci_init(PCH_EHCI2_DEV);
Simon Glass06409c92014-11-14 18:18:35 -070083
Simon Glasscf46d372014-11-24 21:18:16 -070084 cpu = calloc(1, sizeof(*cpu));
85 if (!cpu)
86 return -ENOMEM;
87 model_206ax_init(cpu);
88
Simon Glassd90f8e12014-11-14 20:56:36 -070089 gma_node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_GMA);
90 if (gma_node < 0) {
91 debug("%s: Cannot find GMA node\n", __func__);
92 return -EINVAL;
93 }
Simon Glass35230352015-11-29 13:17:55 -070094 ret = dm_pci_bus_find_bdf(PCH_VIDEO_DEV, &dev);
95 if (ret)
96 return ret;
97 ret = gma_func0_init(dev, blob, gma_node);
Simon Glassd90f8e12014-11-14 20:56:36 -070098 if (ret)
99 return ret;
100
Simon Glass17f1c402014-11-14 18:18:32 -0700101 return 0;
102}
103
Simon Glass32761632016-01-18 20:19:21 -0700104/* TODO(sjg@chromium.org): Move this to the PCH init() method */
Simon Glass17f1c402014-11-14 18:18:32 -0700105int bd82x6x_init(void)
106{
Simon Glasscd0adb32014-11-14 18:18:38 -0700107 const void *blob = gd->fdt_blob;
108 int sata_node;
109
110 sata_node = fdtdec_next_compatible(blob, 0,
111 COMPAT_INTEL_PANTHERPOINT_AHCI);
112 if (sata_node < 0) {
113 debug("%s: Cannot find SATA node\n", __func__);
114 return -EINVAL;
115 }
116
Simon Glass17f1c402014-11-14 18:18:32 -0700117 bd82x6x_pci_init(PCH_DEV);
Simon Glasscd0adb32014-11-14 18:18:38 -0700118 bd82x6x_sata_enable(PCH_SATA_DEV, blob, sata_node);
Simon Glass61612ed2014-11-24 21:18:18 -0700119 northbridge_enable(PCH_DEV);
120 northbridge_init(PCH_DEV);
Simon Glass17f1c402014-11-14 18:18:32 -0700121
122 return 0;
123}
Simon Glasse0e7b362015-03-05 12:25:33 -0700124
Simon Glass32761632016-01-18 20:19:21 -0700125static int bd82x6x_pch_get_sbase(struct udevice *dev, ulong *sbasep)
126{
127 u32 rcba;
128
129 dm_pci_read_config32(dev, PCH_RCBA, &rcba);
130 /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */
131 rcba = rcba & 0xffffc000;
132 *sbasep = rcba + 0x3800;
133
134 return 0;
135}
136
137static enum pch_version bd82x6x_pch_get_version(struct udevice *dev)
138{
139 return PCHV_9;
140}
141
142static int bd82x6x_set_spi_protect(struct udevice *dev, bool protect)
143{
144 uint8_t bios_cntl;
145
146 /* Adjust the BIOS write protect and SMM BIOS Write Protect Disable */
147 dm_pci_read_config8(dev, BIOS_CTRL, &bios_cntl);
148 if (protect) {
149 bios_cntl &= ~BIOS_CTRL_BIOSWE;
150 bios_cntl |= BIT(5);
151 } else {
152 bios_cntl |= BIOS_CTRL_BIOSWE;
153 bios_cntl &= ~BIT(5);
154 }
155 dm_pci_write_config8(dev, BIOS_CTRL, bios_cntl);
156
157 return 0;
158}
159
160static const struct pch_ops bd82x6x_pch_ops = {
161 .get_sbase = bd82x6x_pch_get_sbase,
162 .get_version = bd82x6x_pch_get_version,
163 .set_spi_protect = bd82x6x_set_spi_protect,
164};
165
Simon Glasse0e7b362015-03-05 12:25:33 -0700166static const struct udevice_id bd82x6x_ids[] = {
167 { .compatible = "intel,bd82x6x" },
168 { }
169};
170
171U_BOOT_DRIVER(bd82x6x_drv) = {
172 .name = "bd82x6x",
173 .id = UCLASS_PCH,
174 .of_match = bd82x6x_ids,
175 .probe = bd82x6x_probe,
Simon Glass32761632016-01-18 20:19:21 -0700176 .ops = &bd82x6x_pch_ops,
Simon Glasse0e7b362015-03-05 12:25:33 -0700177};