blob: 35bfeca37dd3e6b80e90ce4df744d11e74ef3d4a [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
Patrick Rudolphc943d6f2023-10-29 19:51:17 +01003#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02004#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +02006#include <device/pci_def.h>
Patrick Rudolph72a90912019-03-24 17:35:55 +01007#include <southbridge/intel/common/rcba.h>
8#include <southbridge/intel/common/pmbase.h>
9
Stefan Reinauer8e073822012-04-04 00:07:22 +020010#include "pch.h"
11
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010012void early_usb_init(const struct southbridge_usb_port *portmap)
Stefan Reinauer8e073822012-04-04 00:07:22 +020013{
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070014 u32 reg32;
15 const u32 rcba_dump[8] = {
16 /* 3560 */ 0x024c8001, 0x000024a3, 0x00040002, 0x01000050,
17 /* 3570 */ 0x02000772, 0x16000f9f, 0x1800ff4f, 0x0001d630,
18 };
Patrick Rudolpha48debd2023-10-31 16:50:05 +010019 const u32 currents[] = { USBIR_TXRX_GAIN_MOBILE_LOW, USBIR_TXRX_GAIN_DEFAULT,
20 USBIR_TXRX_GAIN_HIGH, 0x20000f51, 0x2000094a, 0x2000035f,
21 USBIR_TXRX_GAIN_DESKTOP_LOW, 0x20000357, 0x20000353 };
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070022 int i;
Stefan Reinauer8e073822012-04-04 00:07:22 +020023
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070024 /* Unlock registers. */
Patrick Rudolph72a90912019-03-24 17:35:55 +010025 write_pmbase16(UPRWC, read_pmbase16(UPRWC) | UPRWC_WR_EN);
Patrick Rudolph87b5ff02017-05-28 13:57:04 +020026
Patrick Rudolphc943d6f2023-10-29 19:51:17 +010027 for (i = 0; i < 14; i++) {
Patrick Rudolpha48debd2023-10-31 16:50:05 +010028 if (portmap[i].enabled && !pch_is_mobile() &&
29 currents[portmap[i].current] == USBIR_TXRX_GAIN_MOBILE_LOW) {
Patrick Rudolphc943d6f2023-10-29 19:51:17 +010030 /*
31 * Note for developers: You can fix this by re-running autoport on
32 * vendor firmware and then updating portmap currents accordingly.
33 * If that is not possible, another option is to choose a non-zero
34 * current setting. In either case, please test all the USB ports.
35 */
Patrick Rudolpha48debd2023-10-31 16:50:05 +010036 printk(BIOS_ERR, "%s: USB%02d: USBIR_TXRX_GAIN_MOBILE_LOW is an invalid setting for desktop!\n",
Patrick Rudolphc943d6f2023-10-29 19:51:17 +010037 __func__, i);
38
Patrick Rudolpha48debd2023-10-31 16:50:05 +010039 RCBA32(USBIR0 + 4 * i) = USBIR_TXRX_GAIN_DEFAULT;
Patrick Rudolphc943d6f2023-10-29 19:51:17 +010040 } else {
41 RCBA32(USBIR0 + 4 * i) = currents[portmap[i].current];
42 }
43 }
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070044 for (i = 0; i < 10; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010045 RCBA32(0x3538 + 4 * i) = 0;
Stefan Reinauer8e073822012-04-04 00:07:22 +020046
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070047 for (i = 0; i < 8; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010048 RCBA32(0x3560 + 4 * i) = rcba_dump[i];
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070049 for (i = 0; i < 8; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010050 RCBA32(0x3580 + 4 * i) = 0;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070051 reg32 = 0;
52 for (i = 0; i < 14; i++)
53 if (!portmap[i].enabled)
54 reg32 |= (1 << i);
Patrick Rudolph72a90912019-03-24 17:35:55 +010055 RCBA32(USBPDO) = reg32;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070056 reg32 = 0;
57 for (i = 0; i < 8; i++)
58 if (portmap[i].enabled && portmap[i].oc_pin >= 0)
59 reg32 |= (1 << (i + 8 * portmap[i].oc_pin));
Patrick Rudolph72a90912019-03-24 17:35:55 +010060 RCBA32(USBOCM1) = reg32;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070061 reg32 = 0;
62 for (i = 8; i < 14; i++)
63 if (portmap[i].enabled && portmap[i].oc_pin >= 4)
64 reg32 |= (1 << (i - 8 + 8 * (portmap[i].oc_pin - 4)));
Patrick Rudolph72a90912019-03-24 17:35:55 +010065 RCBA32(USBOCM2) = reg32;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070066 for (i = 0; i < 22; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010067 RCBA32(0x35a8 + 4 * i) = 0;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070068
Patrick Rudolph72a90912019-03-24 17:35:55 +010069 pci_write_config32(PCH_XHCI_DEV, 0xe4, 0x00000000);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070070
71 /* Relock registers. */
Patrick Rudolph72a90912019-03-24 17:35:55 +010072 write_pmbase16(UPRWC, 0);
Stefan Reinauer8e073822012-04-04 00:07:22 +020073}