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