blob: 434dfd649f65853b3977e10f7c400a2346d6b150 [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 */
6
7#include <common.h>
Simon Glasse0e7b362015-03-05 12:25:33 -07008#include <dm.h>
Simon Glass17f1c402014-11-14 18:18:32 -07009#include <errno.h>
10#include <fdtdec.h>
11#include <malloc.h>
12#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
19void bd82x6x_pci_init(pci_dev_t dev)
20{
21 u16 reg16;
22 u8 reg8;
23
24 debug("bd82x6x PCI init.\n");
25 /* Enable Bus Master */
Simon Glass240d06d2015-03-05 12:25:15 -070026 reg16 = x86_pci_read_config16(dev, PCI_COMMAND);
Simon Glass17f1c402014-11-14 18:18:32 -070027 reg16 |= PCI_COMMAND_MASTER;
Simon Glass240d06d2015-03-05 12:25:15 -070028 x86_pci_write_config16(dev, PCI_COMMAND, reg16);
Simon Glass17f1c402014-11-14 18:18:32 -070029
30 /* This device has no interrupt */
Simon Glass240d06d2015-03-05 12:25:15 -070031 x86_pci_write_config8(dev, INTR, 0xff);
Simon Glass17f1c402014-11-14 18:18:32 -070032
33 /* disable parity error response and SERR */
Simon Glass240d06d2015-03-05 12:25:15 -070034 reg16 = x86_pci_read_config16(dev, BCTRL);
Simon Glass17f1c402014-11-14 18:18:32 -070035 reg16 &= ~(1 << 0);
36 reg16 &= ~(1 << 1);
Simon Glass240d06d2015-03-05 12:25:15 -070037 x86_pci_write_config16(dev, BCTRL, reg16);
Simon Glass17f1c402014-11-14 18:18:32 -070038
39 /* Master Latency Count must be set to 0x04! */
Simon Glass240d06d2015-03-05 12:25:15 -070040 reg8 = x86_pci_read_config8(dev, SMLT);
Simon Glass17f1c402014-11-14 18:18:32 -070041 reg8 &= 0x07;
42 reg8 |= (0x04 << 3);
Simon Glass240d06d2015-03-05 12:25:15 -070043 x86_pci_write_config8(dev, SMLT, reg8);
Simon Glass17f1c402014-11-14 18:18:32 -070044
45 /* Will this improve throughput of bus masters? */
Simon Glass240d06d2015-03-05 12:25:15 -070046 x86_pci_write_config8(dev, PCI_MIN_GNT, 0x06);
Simon Glass17f1c402014-11-14 18:18:32 -070047
48 /* Clear errors in status registers */
Simon Glass240d06d2015-03-05 12:25:15 -070049 reg16 = x86_pci_read_config16(dev, PSTS);
Simon Glass17f1c402014-11-14 18:18:32 -070050 /* reg16 |= 0xf900; */
Simon Glass240d06d2015-03-05 12:25:15 -070051 x86_pci_write_config16(dev, PSTS, reg16);
Simon Glass17f1c402014-11-14 18:18:32 -070052
Simon Glass240d06d2015-03-05 12:25:15 -070053 reg16 = x86_pci_read_config16(dev, SECSTS);
Simon Glass17f1c402014-11-14 18:18:32 -070054 /* reg16 |= 0xf900; */
Simon Glass240d06d2015-03-05 12:25:15 -070055 x86_pci_write_config16(dev, SECSTS, reg16);
Simon Glass17f1c402014-11-14 18:18:32 -070056}
57
Simon Glasse0e7b362015-03-05 12:25:33 -070058static int bd82x6x_probe(struct udevice *dev)
Simon Glass17f1c402014-11-14 18:18:32 -070059{
Simon Glasscd0adb32014-11-14 18:18:38 -070060 const void *blob = gd->fdt_blob;
Simon Glass06409c92014-11-14 18:18:35 -070061 struct pci_controller *hose;
Simon Glasscf46d372014-11-24 21:18:16 -070062 struct x86_cpu_priv *cpu;
Simon Glassd90f8e12014-11-14 20:56:36 -070063 int sata_node, gma_node;
64 int ret;
Simon Glass06409c92014-11-14 18:18:35 -070065
66 hose = pci_bus_to_hose(0);
67 lpc_enable(PCH_LPC_DEV);
68 lpc_init(hose, PCH_LPC_DEV);
Simon Glasscd0adb32014-11-14 18:18:38 -070069 sata_node = fdtdec_next_compatible(blob, 0,
70 COMPAT_INTEL_PANTHERPOINT_AHCI);
71 if (sata_node < 0) {
72 debug("%s: Cannot find SATA node\n", __func__);
73 return -EINVAL;
74 }
75 bd82x6x_sata_init(PCH_SATA_DEV, blob, sata_node);
Simon Glass194d7572014-11-14 18:18:40 -070076 bd82x6x_usb_ehci_init(PCH_EHCI1_DEV);
77 bd82x6x_usb_ehci_init(PCH_EHCI2_DEV);
Simon Glass06409c92014-11-14 18:18:35 -070078
Simon Glasscf46d372014-11-24 21:18:16 -070079 cpu = calloc(1, sizeof(*cpu));
80 if (!cpu)
81 return -ENOMEM;
82 model_206ax_init(cpu);
83
Simon Glassd90f8e12014-11-14 20:56:36 -070084 gma_node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_GMA);
85 if (gma_node < 0) {
86 debug("%s: Cannot find GMA node\n", __func__);
87 return -EINVAL;
88 }
Simon Glass35230352015-11-29 13:17:55 -070089 ret = dm_pci_bus_find_bdf(PCH_VIDEO_DEV, &dev);
90 if (ret)
91 return ret;
92 ret = gma_func0_init(dev, blob, gma_node);
Simon Glassd90f8e12014-11-14 20:56:36 -070093 if (ret)
94 return ret;
95
Simon Glass17f1c402014-11-14 18:18:32 -070096 return 0;
97}
98
99int bd82x6x_init(void)
100{
Simon Glasscd0adb32014-11-14 18:18:38 -0700101 const void *blob = gd->fdt_blob;
102 int sata_node;
103
104 sata_node = fdtdec_next_compatible(blob, 0,
105 COMPAT_INTEL_PANTHERPOINT_AHCI);
106 if (sata_node < 0) {
107 debug("%s: Cannot find SATA node\n", __func__);
108 return -EINVAL;
109 }
110
Simon Glass17f1c402014-11-14 18:18:32 -0700111 bd82x6x_pci_init(PCH_DEV);
Simon Glasscd0adb32014-11-14 18:18:38 -0700112 bd82x6x_sata_enable(PCH_SATA_DEV, blob, sata_node);
Simon Glass61612ed2014-11-24 21:18:18 -0700113 northbridge_enable(PCH_DEV);
114 northbridge_init(PCH_DEV);
Simon Glass17f1c402014-11-14 18:18:32 -0700115
116 return 0;
117}
Simon Glasse0e7b362015-03-05 12:25:33 -0700118
119static const struct udevice_id bd82x6x_ids[] = {
120 { .compatible = "intel,bd82x6x" },
121 { }
122};
123
124U_BOOT_DRIVER(bd82x6x_drv) = {
125 .name = "bd82x6x",
126 .id = UCLASS_PCH,
127 .of_match = bd82x6x_ids,
128 .probe = bd82x6x_probe,
129};