blob: f44e3e8ba95be841e580152ab3e98e50b95f6730 [file] [log] [blame]
Stefan Reinauer4885daa2011-04-26 23:47:04 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Google Inc
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Stefan Reinauer4885daa2011-04-26 23:47:04 +000014 */
15
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020016#define __SIMPLE_DEVICE__
17
Stefan Reinauer4885daa2011-04-26 23:47:04 +000018#include <stdint.h>
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020019#include <stddef.h>
Stefan Reinauer4885daa2011-04-26 23:47:04 +000020#include <arch/io.h>
Stefan Reinauerfd4f4132013-06-19 12:25:44 -070021#include <arch/early_variables.h>
Kyösti Mälkkibbf6f3d2014-03-15 01:32:55 +020022#include <boot/coreboot_tables.h>
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +020023#include <console/uart.h>
Kyösti Mälkkibbf6f3d2014-03-15 01:32:55 +020024#include <device/pci.h>
Stefan Reinauer4885daa2011-04-26 23:47:04 +000025#include <device/pci_def.h>
26
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020027static unsigned int oxpcie_present CAR_GLOBAL;
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020028static ROMSTAGE_CONST u32 uart0_base = CONFIG_EARLY_PCI_MMIO_BASE + 0x1000;
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020029
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020030int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base)
Stefan Reinauer4885daa2011-04-26 23:47:04 +000031{
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020032 pci_devfn_t device = PCI_DEV(bus, dev, 0);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000033
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020034 u32 id = pci_read_config32(device, PCI_VENDOR_ID);
Stefan Reinauera6087d12011-05-09 15:19:29 -070035 switch (id) {
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020036 case 0xc1181415: /* e.g. Startech PEX1S1PMINI function 0 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070037 /* On this device function 0 is the parallel port, and
38 * function 3 is the serial port. So let's go look for
39 * the UART.
40 */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020041 device = PCI_DEV(bus, dev, 3);
42 id = pci_read_config32(device, PCI_VENDOR_ID);
Stefan Reinauera6087d12011-05-09 15:19:29 -070043 if (id != 0xc11b1415)
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020044 return -1;
Stefan Reinauera6087d12011-05-09 15:19:29 -070045 break;
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020046 case 0xc11b1415: /* e.g. Startech PEX1S1PMINI function 3 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070047 case 0xc1581415: /* e.g. Startech MPEX2S952 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070048 break;
Gabe Black4d04a712011-10-05 01:52:08 -070049 default:
50 /* No UART here. */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020051 return -1;
Stefan Reinauera6087d12011-05-09 15:19:29 -070052 }
53
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020054 /* Sanity-check, we assume fixed location. */
55 if (mmio_base != CONFIG_EARLY_PCI_MMIO_BASE)
56 return -1;
57
Stefan Reinauer4885daa2011-04-26 23:47:04 +000058 /* Setup base address on device */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020059 pci_write_config32(device, PCI_BASE_ADDRESS_0, mmio_base);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000060
61 /* Enable memory on device */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020062 u16 reg16 = pci_read_config16(device, PCI_COMMAND);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000063 reg16 |= PCI_COMMAND_MEMORY;
Stefan Reinauera6087d12011-05-09 15:19:29 -070064 pci_write_config16(device, PCI_COMMAND, reg16);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000065
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020066 car_set_var(oxpcie_present, 1);
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020067 return 0;
Stefan Reinauer4885daa2011-04-26 23:47:04 +000068}
69
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020070static int oxpcie_uart_active(void)
71{
72 return (car_get_var(oxpcie_present));
73}
74
Ronald G. Minnich2adb2972014-10-16 10:53:48 +000075uintptr_t uart_platform_base(int idx)
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020076{
Kyösti Mälkkie993ec72015-03-20 08:51:57 +020077 if ((idx >= 0) && (idx < 8) && oxpcie_uart_active())
78 return uart0_base + idx * 0x200;
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020079 return 0;
80}
81
82#ifndef __PRE_RAM__
83void oxford_remap(u32 new_base)
84{
85 uart0_base = new_base + 0x1000;
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020086}
Gabe Black4d04a712011-10-05 01:52:08 -070087#endif
Kyösti Mälkki3ee16682014-02-17 19:37:52 +020088
89unsigned int uart_platform_refclk(void)
90{
91 return 62500000;
92}