blob: 9daafc5fd9bf3ad9b84535c817fd490d4ad98dca [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Stefan Reinauer4885daa2011-04-26 23:47:04 +000018 */
19
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020020#define __SIMPLE_DEVICE__
21
Stefan Reinauer4885daa2011-04-26 23:47:04 +000022#include <stdint.h>
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020023#include <stddef.h>
Stefan Reinauer4885daa2011-04-26 23:47:04 +000024#include <arch/io.h>
Stefan Reinauerfd4f4132013-06-19 12:25:44 -070025#include <arch/early_variables.h>
Kyösti Mälkkibbf6f3d2014-03-15 01:32:55 +020026#include <boot/coreboot_tables.h>
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +020027#include <console/uart.h>
Kyösti Mälkkibbf6f3d2014-03-15 01:32:55 +020028#include <device/pci.h>
Stefan Reinauer4885daa2011-04-26 23:47:04 +000029#include <device/pci_def.h>
30
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020031static unsigned int oxpcie_present CAR_GLOBAL;
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020032static ROMSTAGE_CONST u32 uart0_base = CONFIG_EARLY_PCI_MMIO_BASE + 0x1000;
33static ROMSTAGE_CONST u32 uart1_base = CONFIG_EARLY_PCI_MMIO_BASE + 0x2000;
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020034
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020035int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base)
Stefan Reinauer4885daa2011-04-26 23:47:04 +000036{
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020037 pci_devfn_t device = PCI_DEV(bus, dev, 0);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000038
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020039 u32 id = pci_read_config32(device, PCI_VENDOR_ID);
Stefan Reinauera6087d12011-05-09 15:19:29 -070040 switch (id) {
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020041 case 0xc1181415: /* e.g. Startech PEX1S1PMINI function 0 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070042 /* On this device function 0 is the parallel port, and
43 * function 3 is the serial port. So let's go look for
44 * the UART.
45 */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020046 device = PCI_DEV(bus, dev, 3);
47 id = pci_read_config32(device, PCI_VENDOR_ID);
Stefan Reinauera6087d12011-05-09 15:19:29 -070048 if (id != 0xc11b1415)
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020049 return -1;
Stefan Reinauera6087d12011-05-09 15:19:29 -070050 break;
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020051 case 0xc11b1415: /* e.g. Startech PEX1S1PMINI function 3 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070052 case 0xc1581415: /* e.g. Startech MPEX2S952 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070053 break;
Gabe Black4d04a712011-10-05 01:52:08 -070054 default:
55 /* No UART here. */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020056 return -1;
Stefan Reinauera6087d12011-05-09 15:19:29 -070057 }
58
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020059 /* Sanity-check, we assume fixed location. */
60 if (mmio_base != CONFIG_EARLY_PCI_MMIO_BASE)
61 return -1;
62
Stefan Reinauer4885daa2011-04-26 23:47:04 +000063 /* Setup base address on device */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020064 pci_write_config32(device, PCI_BASE_ADDRESS_0, mmio_base);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000065
66 /* Enable memory on device */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020067 u16 reg16 = pci_read_config16(device, PCI_COMMAND);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000068 reg16 |= PCI_COMMAND_MEMORY;
Stefan Reinauera6087d12011-05-09 15:19:29 -070069 pci_write_config16(device, PCI_COMMAND, reg16);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000070
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020071 car_set_var(oxpcie_present, 1);
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020072 return 0;
Stefan Reinauer4885daa2011-04-26 23:47:04 +000073}
74
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020075static int oxpcie_uart_active(void)
76{
77 return (car_get_var(oxpcie_present));
78}
79
Ronald G. Minnich2adb2972014-10-16 10:53:48 +000080uintptr_t uart_platform_base(int idx)
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020081{
82 if (idx == 0 && oxpcie_uart_active())
83 return uart0_base;
84 if (idx == 1 && oxpcie_uart_active())
85 return uart1_base;
86 return 0;
87}
88
89#ifndef __PRE_RAM__
90void oxford_remap(u32 new_base)
91{
92 uart0_base = new_base + 0x1000;
93 uart1_base = new_base + 0x2000;
94}
95
Kyösti Mälkkibbf6f3d2014-03-15 01:32:55 +020096void uart_fill_lb(void *data)
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020097{
Kyösti Mälkkibbf6f3d2014-03-15 01:32:55 +020098 struct lb_serial serial;
99 serial.type = LB_SERIAL_TYPE_MEMORY_MAPPED;
Kyösti Mälkki70342a72014-03-14 22:28:29 +0200100 serial.baseaddr = uart_platform_base(CONFIG_UART_FOR_CONSOLE);
Kyösti Mälkkibbf6f3d2014-03-15 01:32:55 +0200101 serial.baud = default_baudrate();
Vadim Bendebury9dccf1c2015-01-09 16:54:19 -0800102 serial.regwidth = 1;
Kyösti Mälkkibbf6f3d2014-03-15 01:32:55 +0200103 lb_add_serial(&serial, data);
104
105 lb_add_console(LB_TAG_CONSOLE_SERIAL8250MEM, data);
Kyösti Mälkki2b95da02014-02-15 10:19:23 +0200106}
Gabe Black4d04a712011-10-05 01:52:08 -0700107#endif
Kyösti Mälkki3ee16682014-02-17 19:37:52 +0200108
109unsigned int uart_platform_refclk(void)
110{
111 return 62500000;
112}