blob: 88bb784d2693ef579262d6bc7a1713e39a7ab20f [file] [log] [blame]
Lee Leahy1d14b3e2015-05-12 18:23:27 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2015 Google Inc.
5 * Copyright (C) 2015 Intel Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Lee Leahy1d14b3e2015-05-12 18:23:27 -070015 */
16
Lee Leahy1d14b3e2015-05-12 18:23:27 -070017#include <device/device.h>
18#include <device/pci.h>
19#include <device/pci_ids.h>
20#include <stdlib.h>
Aaron Durbine33a1722015-07-30 16:52:56 -050021#include <soc/iomap.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070022#include <soc/pci_devs.h>
23#include <soc/ramstage.h>
24
25static int pch_uart_is_debug(struct device *dev)
26{
Naveen Krishna Chatradhi5c56ce12015-07-15 16:02:25 +053027 return dev->path.pci.devfn == PCH_DEVFN_UART2;
Lee Leahy1d14b3e2015-05-12 18:23:27 -070028}
29
30static void pch_uart_read_resources(struct device *dev)
31{
32 pci_dev_read_resources(dev);
33
34 /* Set the configured UART base address for the debug port */
Aaron Durbine33a1722015-07-30 16:52:56 -050035 if (IS_ENABLED(CONFIG_UART_DEBUG) && pch_uart_is_debug(dev)) {
Lee Leahy1d14b3e2015-05-12 18:23:27 -070036 struct resource *res = find_resource(dev, PCI_BASE_ADDRESS_0);
Aaron Durbine33a1722015-07-30 16:52:56 -050037 /* Need to set the base and size for the resource allocator. */
38 res->base = UART_DEBUG_BASE_ADDRESS;
39 res->size = UART_DEBUG_BASE_SIZE;
Lee Leahy1d14b3e2015-05-12 18:23:27 -070040 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
41 IORESOURCE_FIXED;
42 }
43}
44
45static struct device_operations device_ops = {
46 .read_resources = &pch_uart_read_resources,
47 .set_resources = &pci_dev_set_resources,
48 .enable_resources = &pci_dev_enable_resources,
49 .ops_pci = &soc_pci_ops,
50};
51
52static const unsigned short pci_device_ids[] = {
53 0x9d27, /* UART0 */
54 0x9d28, /* UART1 */
55 0x9d66, /* UART2 */
Sooi, Li Chengc76e9982017-01-04 13:36:06 +080056 0xa127, /* KBL-H UART0 */
57 0xa128, /* KBL-H UART1 */
58 0xa166, /* KBL-H UART2 */
Lee Leahy1d14b3e2015-05-12 18:23:27 -070059 0
60};
61
62static const struct pci_driver pch_uart __pci_driver = {
63 .ops = &device_ops,
64 .vendor = PCI_VENDOR_ID_INTEL,
65 .devices = pci_device_ids,
66};