blob: 2a212ceff13e9239eb08a1083533ba356da3f1de [file] [log] [blame]
Simon Glass81afac12016-01-18 20:19:19 -07001/*
2 * Copyright (C) 2014 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <pch.h>
10
Bin Mengec2af6f2016-02-01 01:40:44 -080011#define GPIO_BASE 0x48
Simon Glass81afac12016-01-18 20:19:19 -070012#define SBASE_ADDR 0x54
13
Bin Meng3e389d82016-02-01 01:40:42 -080014static int pch9_get_spi_base(struct udevice *dev, ulong *sbasep)
Simon Glass81afac12016-01-18 20:19:19 -070015{
16 uint32_t sbase_addr;
17
18 dm_pci_read_config32(dev, SBASE_ADDR, &sbase_addr);
19 *sbasep = sbase_addr & 0xfffffe00;
20
21 return 0;
22}
23
Bin Mengec2af6f2016-02-01 01:40:44 -080024static int pch9_get_gpio_base(struct udevice *dev, u32 *gbasep)
25{
26 u32 base;
27
28 /*
29 * GPIO_BASE moved to its current offset with ICH6, but prior to
30 * that it was unused (or undocumented). Check that it looks
31 * okay: not all ones or zeros.
32 *
33 * Note we don't need check bit0 here, because the Tunnel Creek
34 * GPIO base address register bit0 is reserved (read returns 0),
35 * while on the Ivybridge the bit0 is used to indicate it is an
36 * I/O space.
37 */
38 dm_pci_read_config32(dev, GPIO_BASE, &base);
39 if (base == 0x00000000 || base == 0xffffffff) {
40 debug("%s: unexpected BASE value\n", __func__);
41 return -ENODEV;
42 }
43
44 /*
45 * Okay, I guess we're looking at the right device. The actual
46 * GPIO registers are in the PCI device's I/O space, starting
47 * at the offset that we just read. Bit 0 indicates that it's
48 * an I/O address, not a memory address, so mask that off.
49 */
50 *gbasep = base & 1 ? base & ~3 : base & ~15;
51
52 return 0;
53}
54
Simon Glass81afac12016-01-18 20:19:19 -070055static const struct pch_ops pch9_ops = {
Bin Meng3e389d82016-02-01 01:40:42 -080056 .get_spi_base = pch9_get_spi_base,
Bin Mengec2af6f2016-02-01 01:40:44 -080057 .get_gpio_base = pch9_get_gpio_base,
Simon Glass81afac12016-01-18 20:19:19 -070058};
59
60static const struct udevice_id pch9_ids[] = {
61 { .compatible = "intel,pch9" },
62 { }
63};
64
65U_BOOT_DRIVER(pch9_drv) = {
66 .name = "intel-pch9",
67 .id = UCLASS_PCH,
68 .of_match = pch9_ids,
69 .ops = &pch9_ops,
70};