Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | b5d00de | 2016-01-18 20:19:19 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014 Google, Inc |
Simon Glass | b5d00de | 2016-01-18 20:19:19 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 6 | #define LOG_CATEGORY UCLASS_PCH |
| 7 | |
Simon Glass | b5d00de | 2016-01-18 20:19:19 -0700 | [diff] [blame] | 8 | #include <common.h> |
| 9 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | b5d00de | 2016-01-18 20:19:19 -0700 | [diff] [blame] | 11 | #include <pch.h> |
| 12 | |
Bin Meng | fd2afdf | 2016-02-01 01:40:44 -0800 | [diff] [blame] | 13 | #define GPIO_BASE 0x48 |
Bin Meng | ac371d6 | 2016-02-01 01:40:46 -0800 | [diff] [blame] | 14 | #define IO_BASE 0x4c |
Simon Glass | b5d00de | 2016-01-18 20:19:19 -0700 | [diff] [blame] | 15 | #define SBASE_ADDR 0x54 |
| 16 | |
Bin Meng | 06d66af | 2016-02-01 01:40:42 -0800 | [diff] [blame] | 17 | static int pch9_get_spi_base(struct udevice *dev, ulong *sbasep) |
Simon Glass | b5d00de | 2016-01-18 20:19:19 -0700 | [diff] [blame] | 18 | { |
| 19 | uint32_t sbase_addr; |
| 20 | |
| 21 | dm_pci_read_config32(dev, SBASE_ADDR, &sbase_addr); |
| 22 | *sbasep = sbase_addr & 0xfffffe00; |
| 23 | |
| 24 | return 0; |
| 25 | } |
| 26 | |
Bin Meng | fd2afdf | 2016-02-01 01:40:44 -0800 | [diff] [blame] | 27 | static int pch9_get_gpio_base(struct udevice *dev, u32 *gbasep) |
| 28 | { |
| 29 | u32 base; |
| 30 | |
| 31 | /* |
| 32 | * GPIO_BASE moved to its current offset with ICH6, but prior to |
| 33 | * that it was unused (or undocumented). Check that it looks |
| 34 | * okay: not all ones or zeros. |
| 35 | * |
| 36 | * Note we don't need check bit0 here, because the Tunnel Creek |
| 37 | * GPIO base address register bit0 is reserved (read returns 0), |
| 38 | * while on the Ivybridge the bit0 is used to indicate it is an |
| 39 | * I/O space. |
| 40 | */ |
| 41 | dm_pci_read_config32(dev, GPIO_BASE, &base); |
| 42 | if (base == 0x00000000 || base == 0xffffffff) { |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 43 | log_debug("unexpected BASE value\n"); |
Bin Meng | fd2afdf | 2016-02-01 01:40:44 -0800 | [diff] [blame] | 44 | return -ENODEV; |
| 45 | } |
| 46 | |
| 47 | /* |
| 48 | * Okay, I guess we're looking at the right device. The actual |
| 49 | * GPIO registers are in the PCI device's I/O space, starting |
| 50 | * at the offset that we just read. Bit 0 indicates that it's |
| 51 | * an I/O address, not a memory address, so mask that off. |
| 52 | */ |
| 53 | *gbasep = base & 1 ? base & ~3 : base & ~15; |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
Bin Meng | ac371d6 | 2016-02-01 01:40:46 -0800 | [diff] [blame] | 58 | static int pch9_get_io_base(struct udevice *dev, u32 *iobasep) |
| 59 | { |
| 60 | u32 base; |
| 61 | |
| 62 | dm_pci_read_config32(dev, IO_BASE, &base); |
| 63 | if (base == 0x00000000 || base == 0xffffffff) { |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 64 | log_debug("unexpected BASE value\n"); |
Bin Meng | ac371d6 | 2016-02-01 01:40:46 -0800 | [diff] [blame] | 65 | return -ENODEV; |
| 66 | } |
| 67 | |
| 68 | *iobasep = base & 1 ? base & ~3 : base & ~15; |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
Simon Glass | b5d00de | 2016-01-18 20:19:19 -0700 | [diff] [blame] | 73 | static const struct pch_ops pch9_ops = { |
Bin Meng | 06d66af | 2016-02-01 01:40:42 -0800 | [diff] [blame] | 74 | .get_spi_base = pch9_get_spi_base, |
Bin Meng | fd2afdf | 2016-02-01 01:40:44 -0800 | [diff] [blame] | 75 | .get_gpio_base = pch9_get_gpio_base, |
Bin Meng | ac371d6 | 2016-02-01 01:40:46 -0800 | [diff] [blame] | 76 | .get_io_base = pch9_get_io_base, |
Simon Glass | b5d00de | 2016-01-18 20:19:19 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | static const struct udevice_id pch9_ids[] = { |
| 80 | { .compatible = "intel,pch9" }, |
| 81 | { } |
| 82 | }; |
| 83 | |
| 84 | U_BOOT_DRIVER(pch9_drv) = { |
| 85 | .name = "intel-pch9", |
| 86 | .id = UCLASS_PCH, |
| 87 | .of_match = pch9_ids, |
| 88 | .ops = &pch9_ops, |
| 89 | }; |