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 | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 21 | static int bd82x6x_probe(struct udevice *dev) |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 22 | { |
Simon Glass | cd0adb3 | 2014-11-14 18:18:38 -0700 | [diff] [blame] | 23 | const void *blob = gd->fdt_blob; |
Simon Glass | 39f3f8c | 2016-01-17 16:11:37 -0700 | [diff] [blame] | 24 | int gma_node; |
Simon Glass | d90f8e1 | 2014-11-14 20:56:36 -0700 | [diff] [blame] | 25 | int ret; |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 26 | |
Simon Glass | 044f1a0 | 2016-01-17 16:11:10 -0700 | [diff] [blame] | 27 | if (!(gd->flags & GD_FLG_RELOC)) |
| 28 | return 0; |
| 29 | |
Simon Glass | 39f3f8c | 2016-01-17 16:11:37 -0700 | [diff] [blame] | 30 | /* Cause the SATA device to do its init */ |
| 31 | uclass_first_device(UCLASS_DISK, &dev); |
| 32 | |
Simon Glass | 194d757 | 2014-11-14 18:18:40 -0700 | [diff] [blame] | 33 | bd82x6x_usb_ehci_init(PCH_EHCI1_DEV); |
| 34 | bd82x6x_usb_ehci_init(PCH_EHCI2_DEV); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 35 | |
Simon Glass | d90f8e1 | 2014-11-14 20:56:36 -0700 | [diff] [blame] | 36 | gma_node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_GMA); |
| 37 | if (gma_node < 0) { |
| 38 | debug("%s: Cannot find GMA node\n", __func__); |
| 39 | return -EINVAL; |
| 40 | } |
Simon Glass | 3523035 | 2015-11-29 13:17:55 -0700 | [diff] [blame] | 41 | ret = dm_pci_bus_find_bdf(PCH_VIDEO_DEV, &dev); |
| 42 | if (ret) |
| 43 | return ret; |
| 44 | ret = gma_func0_init(dev, blob, gma_node); |
Simon Glass | d90f8e1 | 2014-11-14 20:56:36 -0700 | [diff] [blame] | 45 | if (ret) |
| 46 | return ret; |
| 47 | |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 51 | static int bd82x6x_pch_get_sbase(struct udevice *dev, ulong *sbasep) |
| 52 | { |
| 53 | u32 rcba; |
| 54 | |
| 55 | dm_pci_read_config32(dev, PCH_RCBA, &rcba); |
| 56 | /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */ |
| 57 | rcba = rcba & 0xffffc000; |
| 58 | *sbasep = rcba + 0x3800; |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static enum pch_version bd82x6x_pch_get_version(struct udevice *dev) |
| 64 | { |
| 65 | return PCHV_9; |
| 66 | } |
| 67 | |
| 68 | static int bd82x6x_set_spi_protect(struct udevice *dev, bool protect) |
| 69 | { |
| 70 | uint8_t bios_cntl; |
| 71 | |
| 72 | /* Adjust the BIOS write protect and SMM BIOS Write Protect Disable */ |
| 73 | dm_pci_read_config8(dev, BIOS_CTRL, &bios_cntl); |
| 74 | if (protect) { |
| 75 | bios_cntl &= ~BIOS_CTRL_BIOSWE; |
| 76 | bios_cntl |= BIT(5); |
| 77 | } else { |
| 78 | bios_cntl |= BIOS_CTRL_BIOSWE; |
| 79 | bios_cntl &= ~BIT(5); |
| 80 | } |
| 81 | dm_pci_write_config8(dev, BIOS_CTRL, bios_cntl); |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static const struct pch_ops bd82x6x_pch_ops = { |
| 87 | .get_sbase = bd82x6x_pch_get_sbase, |
| 88 | .get_version = bd82x6x_pch_get_version, |
| 89 | .set_spi_protect = bd82x6x_set_spi_protect, |
| 90 | }; |
| 91 | |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 92 | static const struct udevice_id bd82x6x_ids[] = { |
| 93 | { .compatible = "intel,bd82x6x" }, |
| 94 | { } |
| 95 | }; |
| 96 | |
| 97 | U_BOOT_DRIVER(bd82x6x_drv) = { |
| 98 | .name = "bd82x6x", |
| 99 | .id = UCLASS_PCH, |
| 100 | .of_match = bd82x6x_ids, |
| 101 | .probe = bd82x6x_probe, |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 102 | .ops = &bd82x6x_pch_ops, |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 103 | }; |