Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Kyösti Mälkki | 1fd7508 | 2013-06-11 16:32:01 +0300 | [diff] [blame] | 3 | |
| 4 | // Use simple device model for this file even in ramstage |
| 5 | #define __SIMPLE_DEVICE__ |
| 6 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | #include <arch/io.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 9 | #include <device/mmio.h> |
Kyösti Mälkki | e2227a2 | 2014-02-05 13:02:55 +0200 | [diff] [blame] | 10 | #include <device/pci_ehci.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 11 | #include <device/pci_def.h> |
| 12 | #include "hudson.h" |
| 13 | |
Kyösti Mälkki | 021fa78 | 2013-08-16 06:34:04 +0300 | [diff] [blame] | 14 | #define DEBUGPORT_MISC_CONTROL 0x80 |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 15 | |
Kyösti Mälkki | 8101aa6 | 2013-08-15 16:27:06 +0300 | [diff] [blame] | 16 | pci_devfn_t pci_ehci_dbg_dev(unsigned int hcd_idx) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 17 | { |
Kyösti Mälkki | 6683e40 | 2017-07-30 13:23:32 +0300 | [diff] [blame] | 18 | /* Enable all of the USB controllers */ |
| 19 | outb(0xEF, PM_INDEX); |
| 20 | outb(0x7F, PM_DATA); |
| 21 | |
Elyes HAOUAS | c021ffe | 2016-09-18 19:18:56 +0200 | [diff] [blame] | 22 | if (hcd_idx == 3) |
Kyösti Mälkki | a1179ca | 2013-09-17 00:12:05 +0300 | [diff] [blame] | 23 | return PCI_DEV(0, 0x16, 2); |
Elyes HAOUAS | c021ffe | 2016-09-18 19:18:56 +0200 | [diff] [blame] | 24 | else if (hcd_idx == 2) |
Kyösti Mälkki | a1179ca | 2013-09-17 00:12:05 +0300 | [diff] [blame] | 25 | return PCI_DEV(0, 0x13, 2); |
| 26 | else |
| 27 | return PCI_DEV(0, 0x12, 2); |
Kyösti Mälkki | 8101aa6 | 2013-08-15 16:27:06 +0300 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | void pci_ehci_dbg_set_port(pci_devfn_t dev, unsigned int port) |
| 31 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 32 | u8 *base_regs = pci_ehci_base_regs(dev); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 33 | u32 reg32; |
| 34 | |
| 35 | /* Write the port number to DEBUGPORT_MISC_CONTROL[31:28]. */ |
Kyösti Mälkki | 021fa78 | 2013-08-16 06:34:04 +0300 | [diff] [blame] | 36 | reg32 = read32(base_regs + DEBUGPORT_MISC_CONTROL); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 37 | reg32 &= ~(0xf << 28); |
| 38 | reg32 |= (port << 28); |
| 39 | reg32 |= (1 << 27); /* Enable Debug Port port number remapping. */ |
Kevin Paul Herbert | 4104e6c | 2015-02-25 00:36:51 -0800 | [diff] [blame] | 40 | write32(base_regs + DEBUGPORT_MISC_CONTROL, reg32); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 41 | } |