blob: 7749d5f41a69fcbfe941b8a7fc41a07098a17c13 [file] [log] [blame]
Stefan Reinauer8e073822012-04-04 00:07:22 +02001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer8e073822012-04-04 00:07:22 +02004 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; version 2 of
8 * 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.
Stefan Reinauer8e073822012-04-04 00:07:22 +020014 */
15
Kyösti Mälkki13f66502019-03-03 08:01:05 +020016#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020017#include <device/pci_ops.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020018#include <device/pci_def.h>
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010019#include <northbridge/intel/sandybridge/sandybridge.h>
Patrick Rudolph72a90912019-03-24 17:35:55 +010020#include <southbridge/intel/common/rcba.h>
21#include <southbridge/intel/common/pmbase.h>
22
Stefan Reinauer8e073822012-04-04 00:07:22 +020023#include "pch.h"
24
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010025void early_usb_init(const struct southbridge_usb_port *portmap)
Stefan Reinauer8e073822012-04-04 00:07:22 +020026{
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070027 u32 reg32;
28 const u32 rcba_dump[8] = {
29 /* 3560 */ 0x024c8001, 0x000024a3, 0x00040002, 0x01000050,
30 /* 3570 */ 0x02000772, 0x16000f9f, 0x1800ff4f, 0x0001d630,
31 };
Vagiz Trakhanov216ad212017-09-28 14:54:52 +000032 const u32 currents[] = { 0x20000153, 0x20000f57, 0x2000055b, 0x20000f51,
33 0x2000094a, 0x2000035f, 0x20000f53, 0x20000357,
34 0x20000353 };
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070035 int i;
Stefan Reinauer8e073822012-04-04 00:07:22 +020036
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070037 /* Unlock registers. */
Patrick Rudolph72a90912019-03-24 17:35:55 +010038 write_pmbase16(UPRWC, read_pmbase16(UPRWC) | UPRWC_WR_EN);
Patrick Rudolph87b5ff02017-05-28 13:57:04 +020039
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070040 for (i = 0; i < 14; i++)
Patrick Rudolph4f8b1082019-07-14 11:54:58 +020041 RCBA32(USBIR0 + 4 * i) = currents[portmap[i].current];
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070042 for (i = 0; i < 10; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010043 RCBA32(0x3538 + 4 * i) = 0;
Stefan Reinauer8e073822012-04-04 00:07:22 +020044
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070045 for (i = 0; i < 8; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010046 RCBA32(0x3560 + 4 * i) = rcba_dump[i];
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070047 for (i = 0; i < 8; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010048 RCBA32(0x3580 + 4 * i) = 0;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070049 reg32 = 0;
50 for (i = 0; i < 14; i++)
51 if (!portmap[i].enabled)
52 reg32 |= (1 << i);
Patrick Rudolph72a90912019-03-24 17:35:55 +010053 RCBA32(USBPDO) = reg32;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070054 reg32 = 0;
55 for (i = 0; i < 8; i++)
56 if (portmap[i].enabled && portmap[i].oc_pin >= 0)
57 reg32 |= (1 << (i + 8 * portmap[i].oc_pin));
Patrick Rudolph72a90912019-03-24 17:35:55 +010058 RCBA32(USBOCM1) = reg32;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070059 reg32 = 0;
60 for (i = 8; i < 14; i++)
61 if (portmap[i].enabled && portmap[i].oc_pin >= 4)
62 reg32 |= (1 << (i - 8 + 8 * (portmap[i].oc_pin - 4)));
Patrick Rudolph72a90912019-03-24 17:35:55 +010063 RCBA32(USBOCM2) = reg32;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070064 for (i = 0; i < 22; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010065 RCBA32(0x35a8 + 4 * i) = 0;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070066
Patrick Rudolph72a90912019-03-24 17:35:55 +010067 pci_write_config32(PCH_XHCI_DEV, 0xe4, 0x00000000);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070068
69 /* Relock registers. */
Patrick Rudolph72a90912019-03-24 17:35:55 +010070 write_pmbase16(UPRWC, 0);
Stefan Reinauer8e073822012-04-04 00:07:22 +020071}