zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Advanced Micro Devices, 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 Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 18 | */ |
Kyösti Mälkki | 1fd7508 | 2013-06-11 16:32:01 +0300 | [diff] [blame] | 19 | |
| 20 | // Use simple device model for this file even in ramstage |
| 21 | #define __SIMPLE_DEVICE__ |
| 22 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 23 | #include <stdint.h> |
| 24 | #include <arch/io.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 25 | #include <usbdebug.h> |
| 26 | #include <device/pci_def.h> |
| 27 | #include "hudson.h" |
| 28 | |
| 29 | #ifndef HUDSON_DEVN_BASE |
| 30 | #define HUDSON_DEVN_BASE 0 |
| 31 | #endif |
| 32 | |
Kyösti Mälkki | 021fa78 | 2013-08-16 06:34:04 +0300 | [diff] [blame] | 33 | #define DEBUGPORT_MISC_CONTROL 0x80 |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 34 | |
Kyösti Mälkki | 8101aa6 | 2013-08-15 16:27:06 +0300 | [diff] [blame^] | 35 | pci_devfn_t pci_ehci_dbg_dev(unsigned int hcd_idx) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 36 | { |
Kyösti Mälkki | 8101aa6 | 2013-08-15 16:27:06 +0300 | [diff] [blame^] | 37 | return PCI_DEV(0, HUDSON_DEVN_BASE + 0x12, 2); |
| 38 | } |
| 39 | |
| 40 | void pci_ehci_dbg_set_port(pci_devfn_t dev, unsigned int port) |
| 41 | { |
| 42 | u32 base_regs = pci_ehci_base_regs(dev); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 43 | u32 reg32; |
| 44 | |
| 45 | /* Write the port number to DEBUGPORT_MISC_CONTROL[31:28]. */ |
Kyösti Mälkki | 021fa78 | 2013-08-16 06:34:04 +0300 | [diff] [blame] | 46 | reg32 = read32(base_regs + DEBUGPORT_MISC_CONTROL); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 47 | reg32 &= ~(0xf << 28); |
| 48 | reg32 |= (port << 28); |
| 49 | reg32 |= (1 << 27); /* Enable Debug Port port number remapping. */ |
Kyösti Mälkki | 021fa78 | 2013-08-16 06:34:04 +0300 | [diff] [blame] | 50 | write32(base_regs + DEBUGPORT_MISC_CONTROL, reg32); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | |
Kyösti Mälkki | 8101aa6 | 2013-08-15 16:27:06 +0300 | [diff] [blame^] | 54 | void pci_ehci_dbg_enable(pci_devfn_t dev, unsigned long base) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 55 | { |
Zheng Bao | b01097e | 2012-12-14 15:58:15 +0800 | [diff] [blame] | 56 | /* Enable all of the USB controllers */ |
| 57 | outb(0xEF, PM_INDEX); |
| 58 | outb(0x7F, PM_DATA); |
| 59 | |
Kyösti Mälkki | 8101aa6 | 2013-08-15 16:27:06 +0300 | [diff] [blame^] | 60 | pci_write_config32(dev, EHCI_BAR_INDEX, base); |
| 61 | pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 62 | } |