blob: 17919af53a3ac4c758c3a4bb4008a074d56002ae [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.
Stefan Reinauer8e073822012-04-04 00:07:22 +020015 */
16
17#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020018#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020019#include <device/pci_ops.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020020#include <device/pci_def.h>
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010021#include <northbridge/intel/sandybridge/sandybridge.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020022#include "pch.h"
23
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010024void early_usb_init(const struct southbridge_usb_port *portmap)
Stefan Reinauer8e073822012-04-04 00:07:22 +020025{
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070026 u32 reg32;
27 const u32 rcba_dump[8] = {
28 /* 3560 */ 0x024c8001, 0x000024a3, 0x00040002, 0x01000050,
29 /* 3570 */ 0x02000772, 0x16000f9f, 0x1800ff4f, 0x0001d630,
30 };
Vagiz Trakhanov216ad212017-09-28 14:54:52 +000031 const u32 currents[] = { 0x20000153, 0x20000f57, 0x2000055b, 0x20000f51,
32 0x2000094a, 0x2000035f, 0x20000f53, 0x20000357,
33 0x20000353 };
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070034 int i;
35 /* Activate PMBAR. */
36 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
37 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE + 4, 0);
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010038 /* Enable ACPI BAR */
39 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */, 0x80);
Stefan Reinauer8e073822012-04-04 00:07:22 +020040
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070041 /* Unlock registers. */
Patrick Rudolph87b5ff02017-05-28 13:57:04 +020042 outw(inw(DEFAULT_PMBASE | UPRWC) | UPRWC_WR_EN,
43 DEFAULT_PMBASE | UPRWC);
44
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070045 for (i = 0; i < 14; i++)
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010046 write32(DEFAULT_RCBABASE + (0x3500 + 4 * i),
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070047 currents[portmap[i].current]);
48 for (i = 0; i < 10; i++)
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010049 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++)
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010052 write32(DEFAULT_RCBABASE + (0x3560 + 4 * i), rcba_dump[i]);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070053 for (i = 0; i < 8; i++)
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010054 write32(DEFAULT_RCBABASE + (0x3580 + 4 * i), 0);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070055 reg32 = 0;
56 for (i = 0; i < 14; i++)
57 if (!portmap[i].enabled)
58 reg32 |= (1 << i);
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010059 write32(DEFAULT_RCBABASE + USBPDO, reg32);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070060 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));
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010064 write32(DEFAULT_RCBABASE + USBOCM1, reg32);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070065 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)));
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010069 write32(DEFAULT_RCBABASE + USBOCM2, reg32);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070070 for (i = 0; i < 22; i++)
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010071 write32(DEFAULT_RCBABASE + (0x35a8 + 4 * i), 0);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070072
Elyes HAOUASf385e9d2018-11-01 19:13:08 +010073 pci_write_config32(PCI_DEV(0, 0x14, 0), 0xe4, 0x00000000);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -070074
75 /* Relock registers. */
Patrick Rudolph87b5ff02017-05-28 13:57:04 +020076 outw(0, DEFAULT_PMBASE | UPRWC);
Stefan Reinauer8e073822012-04-04 00:07:22 +020077}