blob: 7bca0bbc494bce84bd6cc082e3cdd177bcae233c [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"
Keith Huiee126342024-02-05 18:49:46 -050011#include "chip.h"
Stefan Reinauer8e073822012-04-04 00:07:22 +020012
Keith Huiee126342024-02-05 18:49:46 -050013void early_usb_init(void)
Stefan Reinauer8e073822012-04-04 00:07:22 +020014{
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070015 u32 reg32;
16 const u32 rcba_dump[8] = {
17 /* 3560 */ 0x024c8001, 0x000024a3, 0x00040002, 0x01000050,
18 /* 3570 */ 0x02000772, 0x16000f9f, 0x1800ff4f, 0x0001d630,
19 };
Keith Hui94625d22024-05-25 17:33:38 -040020 /* Care should be taken to limit this array to not more than 80 (0x50) entries.
21 * See below. */
Patrick Rudolpha48debd2023-10-31 16:50:05 +010022 const u32 currents[] = { USBIR_TXRX_GAIN_MOBILE_LOW, USBIR_TXRX_GAIN_DEFAULT,
23 USBIR_TXRX_GAIN_HIGH, 0x20000f51, 0x2000094a, 0x2000035f,
Keith Hui51a01bd2024-05-31 22:40:22 -040024 USBIR_TXRX_GAIN_DESKTOP6_LOW, USBIR_TXRX_GAIN_DESKTOP6_HIGH,
25 USBIR_TXRX_GAIN_DESKTOP7_LOW, USBIR_TXRX_GAIN_DESKTOP7_MED,
26 0x20000053, 0x2000055f, 0x20000f5f};
Keith Huiee126342024-02-05 18:49:46 -050027 const struct device *dev = pcidev_on_root(0x1d, 0);
28 const struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
29 const struct southbridge_usb_port *portmap = config->usb_port_config;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070030 int i;
Stefan Reinauer8e073822012-04-04 00:07:22 +020031
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070032 /* Unlock registers. */
Patrick Rudolph72a90912019-03-24 17:35:55 +010033 write_pmbase16(UPRWC, read_pmbase16(UPRWC) | UPRWC_WR_EN);
Patrick Rudolph87b5ff02017-05-28 13:57:04 +020034
Patrick Rudolphc943d6f2023-10-29 19:51:17 +010035 for (i = 0; i < 14; i++) {
Keith Hui94625d22024-05-25 17:33:38 -040036 /*
37 * If the value from devicetree is beyond the highest possible current map
38 * index, it is meant to go directly into (bottom 12 bits of) USBIRx.
39 */
40 if (portmap[i].current >= ARRAY_SIZE(currents)) {
41 RCBA32(USBIR0 + 4 * i) = 0x20000000 | (portmap[i].current & 0xfff);
42 continue;
43 }
Patrick Rudolpha48debd2023-10-31 16:50:05 +010044 if (portmap[i].enabled && !pch_is_mobile() &&
45 currents[portmap[i].current] == USBIR_TXRX_GAIN_MOBILE_LOW) {
Patrick Rudolphc943d6f2023-10-29 19:51:17 +010046 /*
47 * Note for developers: You can fix this by re-running autoport on
48 * vendor firmware and then updating portmap currents accordingly.
49 * If that is not possible, another option is to choose a non-zero
50 * current setting. In either case, please test all the USB ports.
51 */
Patrick Rudolpha48debd2023-10-31 16:50:05 +010052 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 +010053 __func__, i);
54
Patrick Rudolpha48debd2023-10-31 16:50:05 +010055 RCBA32(USBIR0 + 4 * i) = USBIR_TXRX_GAIN_DEFAULT;
Patrick Rudolphc943d6f2023-10-29 19:51:17 +010056 } else {
57 RCBA32(USBIR0 + 4 * i) = currents[portmap[i].current];
58 }
59 }
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070060 for (i = 0; i < 10; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010061 RCBA32(0x3538 + 4 * i) = 0;
Stefan Reinauer8e073822012-04-04 00:07:22 +020062
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070063 for (i = 0; i < 8; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010064 RCBA32(0x3560 + 4 * i) = rcba_dump[i];
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070065 for (i = 0; i < 8; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010066 RCBA32(0x3580 + 4 * i) = 0;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070067 reg32 = 0;
68 for (i = 0; i < 14; i++)
69 if (!portmap[i].enabled)
70 reg32 |= (1 << i);
Patrick Rudolph72a90912019-03-24 17:35:55 +010071 RCBA32(USBPDO) = reg32;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070072 reg32 = 0;
73 for (i = 0; i < 8; i++)
74 if (portmap[i].enabled && portmap[i].oc_pin >= 0)
75 reg32 |= (1 << (i + 8 * portmap[i].oc_pin));
Patrick Rudolph72a90912019-03-24 17:35:55 +010076 RCBA32(USBOCM1) = reg32;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070077 reg32 = 0;
78 for (i = 8; i < 14; i++)
79 if (portmap[i].enabled && portmap[i].oc_pin >= 4)
80 reg32 |= (1 << (i - 8 + 8 * (portmap[i].oc_pin - 4)));
Patrick Rudolph72a90912019-03-24 17:35:55 +010081 RCBA32(USBOCM2) = reg32;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070082 for (i = 0; i < 22; i++)
Patrick Rudolph72a90912019-03-24 17:35:55 +010083 RCBA32(0x35a8 + 4 * i) = 0;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070084
Patrick Rudolph72a90912019-03-24 17:35:55 +010085 pci_write_config32(PCH_XHCI_DEV, 0xe4, 0x00000000);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070086
87 /* Relock registers. */
Patrick Rudolph72a90912019-03-24 17:35:55 +010088 write_pmbase16(UPRWC, 0);
Stefan Reinauer8e073822012-04-04 00:07:22 +020089}