Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 Google, Inc |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 6 | #include <common.h> |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 8 | #include <errno.h> |
| 9 | #include <fdtdec.h> |
| 10 | #include <malloc.h> |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 11 | #include <pch.h> |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 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 | |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 19 | #define BIOS_CTRL 0xdc |
| 20 | |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 21 | void 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 Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 28 | reg16 = x86_pci_read_config16(dev, PCI_COMMAND); |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 29 | reg16 |= PCI_COMMAND_MASTER; |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 30 | x86_pci_write_config16(dev, PCI_COMMAND, reg16); |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 31 | |
| 32 | /* This device has no interrupt */ |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 33 | x86_pci_write_config8(dev, INTR, 0xff); |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 34 | |
| 35 | /* disable parity error response and SERR */ |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 36 | reg16 = x86_pci_read_config16(dev, BCTRL); |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 37 | reg16 &= ~(1 << 0); |
| 38 | reg16 &= ~(1 << 1); |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 39 | x86_pci_write_config16(dev, BCTRL, reg16); |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 40 | |
| 41 | /* Master Latency Count must be set to 0x04! */ |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 42 | reg8 = x86_pci_read_config8(dev, SMLT); |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 43 | reg8 &= 0x07; |
| 44 | reg8 |= (0x04 << 3); |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 45 | x86_pci_write_config8(dev, SMLT, reg8); |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 46 | |
| 47 | /* Will this improve throughput of bus masters? */ |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 48 | x86_pci_write_config8(dev, PCI_MIN_GNT, 0x06); |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 49 | |
| 50 | /* Clear errors in status registers */ |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 51 | reg16 = x86_pci_read_config16(dev, PSTS); |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 52 | /* reg16 |= 0xf900; */ |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 53 | x86_pci_write_config16(dev, PSTS, reg16); |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 54 | |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 55 | reg16 = x86_pci_read_config16(dev, SECSTS); |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 56 | /* reg16 |= 0xf900; */ |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 57 | x86_pci_write_config16(dev, SECSTS, reg16); |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 60 | static int bd82x6x_probe(struct udevice *dev) |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 61 | { |
Simon Glass | cd0adb3 | 2014-11-14 18:18:38 -0700 | [diff] [blame] | 62 | const void *blob = gd->fdt_blob; |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 63 | struct pci_controller *hose; |
Simon Glass | cf46d37 | 2014-11-24 21:18:16 -0700 | [diff] [blame] | 64 | struct x86_cpu_priv *cpu; |
Simon Glass | d90f8e1 | 2014-11-14 20:56:36 -0700 | [diff] [blame] | 65 | int sata_node, gma_node; |
| 66 | int ret; |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 67 | |
| 68 | hose = pci_bus_to_hose(0); |
| 69 | lpc_enable(PCH_LPC_DEV); |
| 70 | lpc_init(hose, PCH_LPC_DEV); |
Simon Glass | cd0adb3 | 2014-11-14 18:18:38 -0700 | [diff] [blame] | 71 | sata_node = fdtdec_next_compatible(blob, 0, |
| 72 | COMPAT_INTEL_PANTHERPOINT_AHCI); |
| 73 | if (sata_node < 0) { |
| 74 | debug("%s: Cannot find SATA node\n", __func__); |
| 75 | return -EINVAL; |
| 76 | } |
| 77 | bd82x6x_sata_init(PCH_SATA_DEV, blob, sata_node); |
Simon Glass | 194d757 | 2014-11-14 18:18:40 -0700 | [diff] [blame] | 78 | bd82x6x_usb_ehci_init(PCH_EHCI1_DEV); |
| 79 | bd82x6x_usb_ehci_init(PCH_EHCI2_DEV); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 80 | |
Simon Glass | cf46d37 | 2014-11-24 21:18:16 -0700 | [diff] [blame] | 81 | cpu = calloc(1, sizeof(*cpu)); |
| 82 | if (!cpu) |
| 83 | return -ENOMEM; |
| 84 | model_206ax_init(cpu); |
| 85 | |
Simon Glass | d90f8e1 | 2014-11-14 20:56:36 -0700 | [diff] [blame] | 86 | gma_node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_GMA); |
| 87 | if (gma_node < 0) { |
| 88 | debug("%s: Cannot find GMA node\n", __func__); |
| 89 | return -EINVAL; |
| 90 | } |
Simon Glass | 3523035 | 2015-11-29 13:17:55 -0700 | [diff] [blame] | 91 | ret = dm_pci_bus_find_bdf(PCH_VIDEO_DEV, &dev); |
| 92 | if (ret) |
| 93 | return ret; |
| 94 | ret = gma_func0_init(dev, blob, gma_node); |
Simon Glass | d90f8e1 | 2014-11-14 20:56:36 -0700 | [diff] [blame] | 95 | if (ret) |
| 96 | return ret; |
| 97 | |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 98 | return 0; |
| 99 | } |
| 100 | |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 101 | /* TODO(sjg@chromium.org): Move this to the PCH init() method */ |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 102 | int bd82x6x_init(void) |
| 103 | { |
Simon Glass | cd0adb3 | 2014-11-14 18:18:38 -0700 | [diff] [blame] | 104 | const void *blob = gd->fdt_blob; |
| 105 | int sata_node; |
| 106 | |
| 107 | sata_node = fdtdec_next_compatible(blob, 0, |
| 108 | COMPAT_INTEL_PANTHERPOINT_AHCI); |
| 109 | if (sata_node < 0) { |
| 110 | debug("%s: Cannot find SATA node\n", __func__); |
| 111 | return -EINVAL; |
| 112 | } |
| 113 | |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 114 | bd82x6x_pci_init(PCH_DEV); |
Simon Glass | cd0adb3 | 2014-11-14 18:18:38 -0700 | [diff] [blame] | 115 | bd82x6x_sata_enable(PCH_SATA_DEV, blob, sata_node); |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 116 | northbridge_enable(PCH_DEV); |
| 117 | northbridge_init(PCH_DEV); |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 118 | |
| 119 | return 0; |
| 120 | } |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 121 | |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 122 | static int bd82x6x_pch_get_sbase(struct udevice *dev, ulong *sbasep) |
| 123 | { |
| 124 | u32 rcba; |
| 125 | |
| 126 | dm_pci_read_config32(dev, PCH_RCBA, &rcba); |
| 127 | /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */ |
| 128 | rcba = rcba & 0xffffc000; |
| 129 | *sbasep = rcba + 0x3800; |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static enum pch_version bd82x6x_pch_get_version(struct udevice *dev) |
| 135 | { |
| 136 | return PCHV_9; |
| 137 | } |
| 138 | |
| 139 | static int bd82x6x_set_spi_protect(struct udevice *dev, bool protect) |
| 140 | { |
| 141 | uint8_t bios_cntl; |
| 142 | |
| 143 | /* Adjust the BIOS write protect and SMM BIOS Write Protect Disable */ |
| 144 | dm_pci_read_config8(dev, BIOS_CTRL, &bios_cntl); |
| 145 | if (protect) { |
| 146 | bios_cntl &= ~BIOS_CTRL_BIOSWE; |
| 147 | bios_cntl |= BIT(5); |
| 148 | } else { |
| 149 | bios_cntl |= BIOS_CTRL_BIOSWE; |
| 150 | bios_cntl &= ~BIT(5); |
| 151 | } |
| 152 | dm_pci_write_config8(dev, BIOS_CTRL, bios_cntl); |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | static const struct pch_ops bd82x6x_pch_ops = { |
| 158 | .get_sbase = bd82x6x_pch_get_sbase, |
| 159 | .get_version = bd82x6x_pch_get_version, |
| 160 | .set_spi_protect = bd82x6x_set_spi_protect, |
| 161 | }; |
| 162 | |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 163 | static const struct udevice_id bd82x6x_ids[] = { |
| 164 | { .compatible = "intel,bd82x6x" }, |
| 165 | { } |
| 166 | }; |
| 167 | |
| 168 | U_BOOT_DRIVER(bd82x6x_drv) = { |
| 169 | .name = "bd82x6x", |
| 170 | .id = UCLASS_PCH, |
| 171 | .of_match = bd82x6x_ids, |
| 172 | .probe = bd82x6x_probe, |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 173 | .ops = &bd82x6x_pch_ops, |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 174 | }; |