blob: 654d44b7dcf1935ee81989863f579a114184f3b5 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer8e073822012-04-04 00:07:22 +02002
Kyösti Mälkki13f66502019-03-03 08:01:05 +02003#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02004#include <device/pci_ops.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +02005#include <device/pci_def.h>
Patrick Rudolph72a90912019-03-24 17:35:55 +01006#include <southbridge/intel/common/rcba.h>
7#include <southbridge/intel/common/pmbase.h>
8
Stefan Reinauer8e073822012-04-04 00:07:22 +02009#include "pch.h"
10
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010011void early_usb_init(const struct southbridge_usb_port *portmap)
Stefan Reinauer8e073822012-04-04 00:07:22 +020012{
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070013 u32 reg32;
14 const u32 rcba_dump[8] = {
15 /* 3560 */ 0x024c8001, 0x000024a3, 0x00040002, 0x01000050,
16 /* 3570 */ 0x02000772, 0x16000f9f, 0x1800ff4f, 0x0001d630,
17 };
Vagiz Trakhanov216ad212017-09-28 14:54:52 +000018 const u32 currents[] = { 0x20000153, 0x20000f57, 0x2000055b, 0x20000f51,
19 0x2000094a, 0x2000035f, 0x20000f53, 0x20000357,
20 0x20000353 };
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070021 int i;
Stefan Reinauer8e073822012-04-04 00:07:22 +020022
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070023 /* Unlock registers. */
Patrick Rudolph72a90912019-03-24 17:35:55 +010024 write_pmbase16(UPRWC, read_pmbase16(UPRWC) | UPRWC_WR_EN);
Patrick Rudolph87b5ff02017-05-28 13:57:04 +020025
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070026 for (i = 0; i < 14; i++)
Patrick Rudolph4f8b1082019-07-14 11:54:58 +020027 RCBA32(USBIR0 + 4 * i) = currents[portmap[i].current];
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070028 for (i = 0; i < 10; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010029 RCBA32(0x3538 + 4 * i) = 0;
Stefan Reinauer8e073822012-04-04 00:07:22 +020030
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070031 for (i = 0; i < 8; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010032 RCBA32(0x3560 + 4 * i) = rcba_dump[i];
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070033 for (i = 0; i < 8; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010034 RCBA32(0x3580 + 4 * i) = 0;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070035 reg32 = 0;
36 for (i = 0; i < 14; i++)
37 if (!portmap[i].enabled)
38 reg32 |= (1 << i);
Patrick Rudolph72a90912019-03-24 17:35:55 +010039 RCBA32(USBPDO) = reg32;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070040 reg32 = 0;
41 for (i = 0; i < 8; i++)
42 if (portmap[i].enabled && portmap[i].oc_pin >= 0)
43 reg32 |= (1 << (i + 8 * portmap[i].oc_pin));
Patrick Rudolph72a90912019-03-24 17:35:55 +010044 RCBA32(USBOCM1) = reg32;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070045 reg32 = 0;
46 for (i = 8; i < 14; i++)
47 if (portmap[i].enabled && portmap[i].oc_pin >= 4)
48 reg32 |= (1 << (i - 8 + 8 * (portmap[i].oc_pin - 4)));
Patrick Rudolph72a90912019-03-24 17:35:55 +010049 RCBA32(USBOCM2) = reg32;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070050 for (i = 0; i < 22; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010051 RCBA32(0x35a8 + 4 * i) = 0;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070052
Patrick Rudolph72a90912019-03-24 17:35:55 +010053 pci_write_config32(PCH_XHCI_DEV, 0xe4, 0x00000000);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070054
55 /* Relock registers. */
Patrick Rudolph72a90912019-03-24 17:35:55 +010056 write_pmbase16(UPRWC, 0);
Stefan Reinauer8e073822012-04-04 00:07:22 +020057}