Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 1 | /* |
| 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 Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame] | 16 | #define __SIMPLE_DEVICE__ |
| 17 | |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 18 | #include <stdint.h> |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame] | 19 | #include <stddef.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 20 | #include <device/pci_ops.h> |
Stefan Reinauer | fd4f413 | 2013-06-19 12:25:44 -0700 | [diff] [blame] | 21 | #include <arch/early_variables.h> |
Kyösti Mälkki | bbf6f3d | 2014-03-15 01:32:55 +0200 | [diff] [blame] | 22 | #include <boot/coreboot_tables.h> |
Kyösti Mälkki | 1d7541f | 2014-02-17 21:34:42 +0200 | [diff] [blame] | 23 | #include <console/uart.h> |
Kyösti Mälkki | bbf6f3d | 2014-03-15 01:32:55 +0200 | [diff] [blame] | 24 | #include <device/pci.h> |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 25 | #include <device/pci_def.h> |
| 26 | |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame] | 27 | static unsigned int oxpcie_present CAR_GLOBAL; |
Aaron Durbin | e4d7abc | 2017-04-16 22:05:36 -0500 | [diff] [blame] | 28 | static DEVTREE_CONST u32 uart0_base = CONFIG_EARLY_PCI_MMIO_BASE + 0x1000; |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame] | 29 | |
Kyösti Mälkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 30 | int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base) |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 31 | { |
Kyösti Mälkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 32 | pci_devfn_t device = PCI_DEV(bus, dev, 0); |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 33 | |
Kyösti Mälkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 34 | u32 id = pci_read_config32(device, PCI_VENDOR_ID); |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 35 | switch (id) { |
Kyösti Mälkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 36 | case 0xc1181415: /* e.g. Startech PEX1S1PMINI function 0 */ |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 37 | /* 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älkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 41 | device = PCI_DEV(bus, dev, 3); |
| 42 | id = pci_read_config32(device, PCI_VENDOR_ID); |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 43 | if (id != 0xc11b1415) |
Kyösti Mälkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 44 | return -1; |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 45 | break; |
Kyösti Mälkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 46 | case 0xc11b1415: /* e.g. Startech PEX1S1PMINI function 3 */ |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 47 | case 0xc1581415: /* e.g. Startech MPEX2S952 */ |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 48 | break; |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 49 | default: |
| 50 | /* No UART here. */ |
Kyösti Mälkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 51 | return -1; |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Kyösti Mälkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 54 | /* Sanity-check, we assume fixed location. */ |
| 55 | if (mmio_base != CONFIG_EARLY_PCI_MMIO_BASE) |
| 56 | return -1; |
| 57 | |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 58 | /* Setup base address on device */ |
Kyösti Mälkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 59 | pci_write_config32(device, PCI_BASE_ADDRESS_0, mmio_base); |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 60 | |
| 61 | /* Enable memory on device */ |
Kyösti Mälkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 62 | u16 reg16 = pci_read_config16(device, PCI_COMMAND); |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 63 | reg16 |= PCI_COMMAND_MEMORY; |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 64 | pci_write_config16(device, PCI_COMMAND, reg16); |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 65 | |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame] | 66 | car_set_var(oxpcie_present, 1); |
Kyösti Mälkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 67 | return 0; |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame] | 70 | static int oxpcie_uart_active(void) |
| 71 | { |
| 72 | return (car_get_var(oxpcie_present)); |
| 73 | } |
| 74 | |
Ronald G. Minnich | 2adb297 | 2014-10-16 10:53:48 +0000 | [diff] [blame] | 75 | uintptr_t uart_platform_base(int idx) |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame] | 76 | { |
Kyösti Mälkki | e993ec7 | 2015-03-20 08:51:57 +0200 | [diff] [blame] | 77 | if ((idx >= 0) && (idx < 8) && oxpcie_uart_active()) |
| 78 | return uart0_base + idx * 0x200; |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame] | 82 | void oxford_remap(u32 new_base) |
| 83 | { |
Kyösti Mälkki | fb25f9f | 2018-12-26 20:15:58 +0200 | [diff] [blame] | 84 | #if ENV_RAMSTAGE |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame] | 85 | uart0_base = new_base + 0x1000; |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 86 | #endif |
Kyösti Mälkki | fb25f9f | 2018-12-26 20:15:58 +0200 | [diff] [blame] | 87 | } |
Kyösti Mälkki | 3ee1668 | 2014-02-17 19:37:52 +0200 | [diff] [blame] | 88 | |
| 89 | unsigned int uart_platform_refclk(void) |
| 90 | { |
| 91 | return 62500000; |
| 92 | } |