blob: 5463d2bb901a7ae1152078fed2781dfd68044cc9 [file] [log] [blame]
zbao246e84b2012-07-13 18:47:03 +08001/*
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 Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
zbao246e84b2012-07-13 18:47:03 +080018 */
Kyösti Mälkki1fd75082013-06-11 16:32:01 +030019
20// Use simple device model for this file even in ramstage
21#define __SIMPLE_DEVICE__
22
zbao246e84b2012-07-13 18:47:03 +080023#include <stdint.h>
24#include <arch/io.h>
Kyösti Mälkkie2227a22014-02-05 13:02:55 +020025#include <device/pci_ehci.h>
zbao246e84b2012-07-13 18:47:03 +080026#include <device/pci_def.h>
27#include "hudson.h"
28
Kyösti Mälkki021fa782013-08-16 06:34:04 +030029#define DEBUGPORT_MISC_CONTROL 0x80
zbao246e84b2012-07-13 18:47:03 +080030
Kyösti Mälkki8101aa62013-08-15 16:27:06 +030031pci_devfn_t pci_ehci_dbg_dev(unsigned int hcd_idx)
zbao246e84b2012-07-13 18:47:03 +080032{
Kyösti Mälkkia1179ca2013-09-17 00:12:05 +030033 if (hcd_idx==3)
34 return PCI_DEV(0, 0x16, 2);
35 else if (hcd_idx==2)
36 return PCI_DEV(0, 0x13, 2);
37 else
38 return PCI_DEV(0, 0x12, 2);
Kyösti Mälkki8101aa62013-08-15 16:27:06 +030039}
40
41void pci_ehci_dbg_set_port(pci_devfn_t dev, unsigned int port)
42{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080043 u8 *base_regs = pci_ehci_base_regs(dev);
zbao246e84b2012-07-13 18:47:03 +080044 u32 reg32;
45
46 /* Write the port number to DEBUGPORT_MISC_CONTROL[31:28]. */
Kyösti Mälkki021fa782013-08-16 06:34:04 +030047 reg32 = read32(base_regs + DEBUGPORT_MISC_CONTROL);
zbao246e84b2012-07-13 18:47:03 +080048 reg32 &= ~(0xf << 28);
49 reg32 |= (port << 28);
50 reg32 |= (1 << 27); /* Enable Debug Port port number remapping. */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080051 write32(base_regs + (DEBUGPORT_MISC_CONTROL / sizeof(u32)), reg32);
zbao246e84b2012-07-13 18:47:03 +080052}
53
54
Kyösti Mälkki8101aa62013-08-15 16:27:06 +030055void pci_ehci_dbg_enable(pci_devfn_t dev, unsigned long base)
zbao246e84b2012-07-13 18:47:03 +080056{
Zheng Baob01097e2012-12-14 15:58:15 +080057 /* Enable all of the USB controllers */
58 outb(0xEF, PM_INDEX);
59 outb(0x7F, PM_DATA);
60
Kyösti Mälkki8101aa62013-08-15 16:27:06 +030061 pci_write_config32(dev, EHCI_BAR_INDEX, base);
62 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
zbao246e84b2012-07-13 18:47:03 +080063}