blob: 8462c2bc77bb888057a991fa3ab2bf81c91831e5 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03002
3// Use simple device model for this file even in ramstage
4#define __SIMPLE_DEVICE__
5
6#include <stdint.h>
7#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02008#include <device/mmio.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03009#include <device/pci_ehci.h>
10#include <device/pci_def.h>
11#include "hudson.h"
12
13#define DEBUGPORT_MISC_CONTROL 0x80
14
15pci_devfn_t pci_ehci_dbg_dev(unsigned int hcd_idx)
16{
Kyösti Mälkki6683e402017-07-30 13:23:32 +030017 /* Enable all of the USB controllers */
18 outb(0xEF, PM_INDEX);
19 outb(0x7F, PM_DATA);
20
Elyes HAOUASc021ffe2016-09-18 19:18:56 +020021 if (hcd_idx == 3)
Kyösti Mälkki55ed6722015-06-08 16:39:52 +030022 return PCI_DEV(0, 0x16, 0);
Elyes HAOUASc021ffe2016-09-18 19:18:56 +020023 else if (hcd_idx == 2)
Kyösti Mälkki55ed6722015-06-08 16:39:52 +030024 return PCI_DEV(0, 0x13, 0);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030025 else
Kyösti Mälkki55ed6722015-06-08 16:39:52 +030026 return PCI_DEV(0, 0x12, 0);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030027}
28
29void pci_ehci_dbg_set_port(pci_devfn_t dev, unsigned int port)
30{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080031 u8 *base_regs = pci_ehci_base_regs(dev);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030032 u32 reg32;
33
34 /* Write the port number to DEBUGPORT_MISC_CONTROL[31:28]. */
35 reg32 = read32(base_regs + DEBUGPORT_MISC_CONTROL);
36 reg32 &= ~(0xf << 28);
37 reg32 |= (port << 28);
38 reg32 |= (1 << 27); /* Enable Debug Port port number remapping. */
39 write32(base_regs + DEBUGPORT_MISC_CONTROL, reg32);
40}