blob: 6973c6c805f004d5f620fa5b7d7a264eaa044ddc [file] [log] [blame]
Stefan Reinauer8e073822012-04-04 00:07:22 +02001/*
2 * This file is part of the coreboot project.
3 *
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -07004 * Copyright (C) 2014 Vladimir Serbinenko
Stefan Reinauer8e073822012-04-04 00:07:22 +02005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010018 * Foundation, Inc.
Stefan Reinauer8e073822012-04-04 00:07:22 +020019 */
20
21#include <arch/io.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020022#include <console/console.h>
23#include <device/pci_ids.h>
24#include <device/pci_def.h>
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070025#include "northbridge/intel/sandybridge/sandybridge.h" /* For DEFAULT_RCBABASE. */
Stefan Reinauer8e073822012-04-04 00:07:22 +020026#include "pch.h"
27
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070028void
29early_usb_init (const struct southbridge_usb_port *portmap)
Stefan Reinauer8e073822012-04-04 00:07:22 +020030{
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070031 u32 reg32;
32 const u32 rcba_dump[8] = {
33 /* 3560 */ 0x024c8001, 0x000024a3, 0x00040002, 0x01000050,
34 /* 3570 */ 0x02000772, 0x16000f9f, 0x1800ff4f, 0x0001d630,
35 };
36 const u32 currents[] = { 0x20000153, 0x20000f57, 0x2000055b, 0x20000f51, 0x2000094a, 0x2000035f };
37 int i;
38 /* Activate PMBAR. */
39 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
40 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE + 4, 0);
41 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */
Stefan Reinauer8e073822012-04-04 00:07:22 +020042
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070043 /* Unlock registers. */
44 outw (inw (DEFAULT_PMBASE | 0x003c) | 2, DEFAULT_PMBASE | 0x003c);
45 for (i = 0; i < 14; i++)
46 write32 (DEFAULT_RCBABASE + (0x3500 + 4 * i),
47 currents[portmap[i].current]);
48 for (i = 0; i < 10; i++)
49 write32 (DEFAULT_RCBABASE + (0x3538 + 4 * i), 0);
Stefan Reinauer8e073822012-04-04 00:07:22 +020050
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070051 for (i = 0; i < 8; i++)
52 write32 (DEFAULT_RCBABASE + (0x3560 + 4 * i), rcba_dump[i]);
53 for (i = 0; i < 8; i++)
54 write32 (DEFAULT_RCBABASE + (0x3580 + 4 * i), 0);
55 reg32 = 0;
56 for (i = 0; i < 14; i++)
57 if (!portmap[i].enabled)
58 reg32 |= (1 << i);
59 write32 (DEFAULT_RCBABASE + USBPDO, reg32);
60 reg32 = 0;
61 for (i = 0; i < 8; i++)
62 if (portmap[i].enabled && portmap[i].oc_pin >= 0)
63 reg32 |= (1 << (i + 8 * portmap[i].oc_pin));
64 write32 (DEFAULT_RCBABASE + USBOCM1, reg32);
65 reg32 = 0;
66 for (i = 8; i < 14; i++)
67 if (portmap[i].enabled && portmap[i].oc_pin >= 4)
68 reg32 |= (1 << (i - 8 + 8 * (portmap[i].oc_pin - 4)));
69 write32 (DEFAULT_RCBABASE + USBOCM2, reg32);
70 for (i = 0; i < 22; i++)
71 write32 (DEFAULT_RCBABASE + (0x35a8 + 4 * i), 0);
72
73 pcie_write_config32 (PCI_DEV (0, 0x14, 0), 0xe4, 0x00000000);
74
75 /* Relock registers. */
76 outw (0x0000, DEFAULT_PMBASE | 0x003c);
Stefan Reinauer8e073822012-04-04 00:07:22 +020077}